<div dir="ltr"><div dir="ltr">On Mon, Sep 23, 2024 at 5:33 AM Matteo Semplice via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear petsc,<br>
<br>
I need to hand-code a jacobian and I can't figure out how to <br>
translate the DMplex points/fields to matrix indices.<br>
<br>
My DMPlex has a section with m fields per cell (which makes for n>m dof <br>
per cell since some fields are vector). Say I want to insert an nxn <br>
block for the row corresponding to cell c and coloumn of its neighbour <br>
d. I guess that I should call either MatSetValues/MatSetValuesLocal or <br>
the blocked variants, but how do I find the row/col indices to pass in <br>
starting from the c/d dmplex points? And, while I am at it, which <br>
MatSetValues version standard/Local standard/blocked is best?<br>
<br>
I looked for a petsc example, but fails to find it: if there's one, can <br>
you just point me to it?<br></blockquote><div><br></div><div>1. In FEM, the main unit of indices is usually the closure, so we provide</div><div><br></div><div> <a href="https://urldefense.us/v3/__https://petsc.org/main/manualpages/DMPlex/DMPlexGetClosureIndices/__;!!G_uCfscf7eWS!fDvGoz5OloH7xryMIAIqyYsslt8U4HqegW7HeYDlwRPbkTloMU6k0kze8NlG7S2DxDuY2nUXRQcBIiuqLU1o$">https://petsc.org/main/manualpages/DMPlex/DMPlexGetClosureIndices/</a></div><div><br></div><div>which is what is used inside of</div><div><br></div><div> <a href="https://urldefense.us/v3/__https://petsc.org/main/manualpages/DMPlex/DMPlexMatSetClosure/__;!!G_uCfscf7eWS!fDvGoz5OloH7xryMIAIqyYsslt8U4HqegW7HeYDlwRPbkTloMU6k0kze8NlG7S2DxDuY2nUXRQcBIi82N3yY$">https://petsc.org/main/manualpages/DMPlex/DMPlexMatSetClosure/</a></div><div><br></div><div>2. These indices are calculated using the global section, so you can just</div><div><br></div><div> DMGetGlobalSection(dm, &gs);</div><div><br></div><div>and then use PetscSectionGetDof() and PetscSectionGetOffset(), knowing that</div><div>off-process values are encoded as -(off + 1), so you need to convert those.</div><div><br></div><div>Does this make sense?</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thanks in advance.<br>
<br>
Matteo Semplice<br>
<br>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!fDvGoz5OloH7xryMIAIqyYsslt8U4HqegW7HeYDlwRPbkTloMU6k0kze8NlG7S2DxDuY2nUXRQcBIpAwlPEi$" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>