On Mon, Sep 23, 2024 at 5:33 AM Matteo Semplice via petsc-users <petsc-users@mcs.anl.gov> wrote:
Dear petsc,
I need to hand-code a jacobian and I can't figure out how to
translate the DMplex points/fields to matrix indices.
My DMPlex has a section with m fields per cell (which makes for n>m dof
per cell since some fields are vector). Say I want to insert an nxn
block for the row corresponding to cell c and coloumn of its neighbour
d. I guess that I should call either MatSetValues/MatSetValuesLocal or
the blocked variants, but how do I find the row/col indices to pass in
starting from the c/d dmplex points? And, while I am at it, which
MatSetValues version standard/Local standard/blocked is best?
I looked for a petsc example, but fails to find it: if there's one, can
you just point me to it?
1. In FEM, the main unit of indices is usually the closure, so we provide
which is what is used inside of
2. These indices are calculated using the global section, so you can just
DMGetGlobalSection(dm, &gs);
and then use PetscSectionGetDof() and PetscSectionGetOffset(), knowing thatoff-process values are encoded as -(off + 1), so you need to convert those.
Does this make sense?
Yes! Thank you!
Matteo