Hi,
I am trying to perform an assembly of finite element stiffness matrices using stdlib’s coo matrix format, like so:
function assembly() result(rslt)
use stdlib_sparse_kinds, only: COO_dp_type
bool :: rslt
integer :: el
integer :: dofs_el(3)
real(dp) :: K_el(3,3)
type(COO_dp_type) :: COO
call COO%malloc(5,5,17)
do el = 1, 2
call calcKel(el, dofs_el, K_el)
call COO%add(dofs_el, dofs_el, K_el)
end do
contains
subroutine calcKel(i, dofs, K)
integer, intent(in) :: i
integer, intent(out) :: dofs(3)
real(dp), intent(out) :: K(3,3)
select case(i)
case(1)
dofs = [1,2,3]
K(1,1) = -1._dp
K(1,2) = 2._dp
K(1,3) = 3._dp
K(2,1) = 2._dp
K(2,2) = 1._dp
K(2,3) = 1._dp
K(3,1) = 1._dp
K(3,2) = 1._dp
K(3,3) = 1._dp
case default
dofs = [3,4,5]
K(1,1) = 2._dp
K(1,2) = -1._dp
K(1,3) = 3._dp
K(2,1) = 1._dp
K(2,2) = 2._dp
K(2,3) = -1._dp
K(3,1) = 3._dp
K(3,2) = 2._dp
K(3,3) = 1._dp
end select
end subroutine
end function
I must be misunderstanding something, since I thought I could (1) allocate an empty global coo sparse matrix and (2) populate it by adding the element stiffness matrices in a do loop.
However, it seems that the coo matrix isn’t initialized correctly and hence cannot be used to add the element matrices.
Am I misunderstanding how the stdlib coo matrix should be used?
Also, can mpi be used with coo%add(), so that multiple processes are used in parallel for assembly?