[petsc-users] Question regarding
Aldo Bonfiglioli
aldo.bonfiglioli at unibas.it
Fri Mar 20 14:09:32 CDT 2026
Hi there,
I am (successfully) using the following piece of code to insert
elemental matrices into the "global" matrix "jac":
> !
> if( matrix_assembly )then
> !
> i = 0
> PetscCall(DMPlexGetTransitiveClosure(dm, cell, useCone,
> PETSC_NULL_INTEGER, p_points, ierr))
> !
> ! loop over the vertices of the cell
> !
> do j = vtxbgn, vtxend, 2 ! this is ndim-dependent
> i = i + 1
> point = p_points(j)
> PetscCall(PetscSectionGetDof(section, point, ndofs, ierr))
> PetscCall(PetscSectionGetOffset(section, point, offset,
> ierr))
> row(i) = offset/ndofs
> col(i) = offset/ndofs
> end do
> !
> do i = 1, nofvert
> do j = 1, nofvert
> dummy = transpose(eltmat(:, :, i, j))
> ir = row(i)
> ic = col(j)
> !
> !p_dummyisa1dviewofdummy
> !
> PetscCall(MatSetValuesBlockedLocal(jac, 2, [ir], 1, [ic], p_dummy,
> ADD_VALUES, ierr))
> end do
> end do
> !
> PetscCall(DMPlexRestoreTransitiveClosure(dm, cell, useCone,
> PETSC_NULL_INTEGER, p_points, ierr))
> !
> end if ! matrix_assembly
>
I would however be happy to replace all of the above with a single call to:
> PetscCall(DMPlexMatSetClosure(dm, PETSC_NULL_SECTION,
> PETSC_NULL_SECTION, jac, cell, values, ADD_VALUES, ierr ))
which I actually succeeded to do as long as ndofs = 1.
The question is:
how (in which order) should I "transfer" the entries of
eltmat(1:ndofs,1:ndofs,1:nofvert,1:nofvert) into the values array
required by DMPlexMatSetClosure ?
Thanks,
Aldo
--
Dr. Aldo Bonfiglioli
Associate professor of Fluid Mechanics
Dipartimento di Ingegneria
Universita' della Basilicata
V.le dell'Ateneo Lucano, 10 85100 Potenza ITALY
tel:+39.0971.205203 fax:+39.0971.205215
web:https://urldefense.us/v3/__http://docenti.unibas.it/site/home/docente.html?m=002423__;!!G_uCfscf7eWS!ZusjOf_nCidORTOchtNsX_xGJZNjiAXMKKmn4rDhnR-3Y6mFzMF9Z7f7iJFeGj6tgcBzT2L5gtfxO56AMvPr3pgXHaCPziR-QL4$
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20260320/bd73d5c4/attachment.html>
More information about the petsc-users
mailing list