<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 23/09/2024 17:16, Matthew Knepley
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CAMYG4GmOv3UH1uQrNfH+E3x6aHAOvMNaN1AQR4kDW2j=NS1Kug@mail.gmail.com">
      
      <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" moz-do-not-send="true" class="moz-txt-link-freetext">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!YwF8ebZtFAZdHXKPu98AWB7KPuScfxMu4dRoe8ZqVaPVoEO_nX_qJa-zS6pOWHnPUs2ME6GB7l_SlHBl8ypyOPOQXzbVSC9xXhd8tw$" moz-do-not-send="true" class="moz-txt-link-freetext">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!YwF8ebZtFAZdHXKPu98AWB7KPuScfxMu4dRoe8ZqVaPVoEO_nX_qJa-zS6pOWHnPUs2ME6GB7l_SlHBl8ypyOPOQXzbVSC8i-x5AVA$" moz-do-not-send="true" class="moz-txt-link-freetext">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>
      </div>
    </blockquote>
    <p>Yes! Thank you!</p>
    <p>Matteo<br>
    </p>
    <pre class="moz-signature" cols="72">
</pre>
  </body>
</html>