<div dir="ltr"><div dir="ltr">On Thu, Feb 27, 2025 at 6:12 PM neil liu <<a href="mailto:liufield@gmail.com">liufield@gmail.com</a>> wrote:</div><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Dear Pestc community, <div><br></div><div>I am currently working on a 3D adaptive vector FEM solver. In my case, I need to solve two systems: one for the primal equation using a low-order discretization and another for the adjoint equation using a high-order discretization.</div><div><p>Afterward, I need to reset the section associated with the DMPlex. Whichever is set first—20 DOFs (second-order) or 6 DOFs (first-order)—the final mapping always follows that of the first-defined configuration.</p><p>Did I miss something?</p><p></p></div></div></blockquote><div>When solving two systems like this on the same mesh, I recommend using DMClone(). What this does is create you a new</div><div>DM with the same backend topology (Plex), but a different function space (Section). This is how I do everything internally in Plex. Does that make sense?</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><p>Thanks, </p><p><br></p><p>Xiaodong </p></div><div><br></div><div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">PetscErrorCode DMManage::SetupSection(CaseInfo &objCaseInfo){</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  PetscSection s;</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  PetscInt     edgeStart, edgeEnd, pStart, pEnd;</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  PetscInt     cellStart, cellEnd;</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  PetscInt     faceStart, faceEnd;</font></div><font color="#000000"><br style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"></font><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  PetscFunctionBeginUser;</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  DMPlexGetChart(dm, &pStart, &pEnd);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  DMPlexGetHeightStratum(dm, 0, &cellStart, &cellEnd);  </font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  DMPlexGetHeightStratum(dm, 1, &faceStart, &faceEnd);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  DMPlexGetHeightStratum(dm, 2, &edgeStart, &edgeEnd); /* edges */;</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  PetscSectionCreate(PetscObjectComm((PetscObject)dm), &s);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  PetscSectionSetNumFields(s, 1);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  PetscSectionSetFieldComponents(s, 0, 1);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  if (objCaseInfo.getnumberDof_local() == 6){</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">    PetscSectionSetChart(s, edgeStart, edgeEnd);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">    for (PetscInt edgeIndex = edgeStart; edgeIndex < edgeEnd; ++edgeIndex) {</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">      PetscSectionSetDof(s, edgeIndex, objCaseInfo.numdofPerEdge);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">      PetscSectionSetFieldDof(s, edgeIndex, 0, 1);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">    }</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  }</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  else if(objCaseInfo.getnumberDof_local() == 20){</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">    PetscSectionSetChart(s, faceStart, edgeEnd);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">    for (PetscInt faceIndex = faceStart; faceIndex < faceEnd; ++faceIndex) {</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">      PetscSectionSetDof(s, faceIndex, objCaseInfo.numdofPerFace);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">      PetscSectionSetFieldDof(s, faceIndex, 0, 1);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">    }  </font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">    //Test</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">    for (PetscInt edgeIndex = edgeStart; edgeIndex < edgeEnd; ++edgeIndex) {</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">      PetscSectionSetDof(s, edgeIndex, objCaseInfo.numdofPerEdge);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">      PetscSectionSetFieldDof(s, edgeIndex, 0, 1);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">    }</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  }</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  //</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  PetscSectionSetUp(s);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  DMSetLocalSection(dm, s);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  PetscSectionDestroy(&s);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000"><br></font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  //Output map for check</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  ISLocalToGlobalMapping ltogm;</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  const PetscInt        *g_idx;</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  DMGetLocalToGlobalMapping(dm, &ltogm);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  ISLocalToGlobalMappingView(ltogm, PETSC_VIEWER_STDOUT_WORLD); </font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">  ISLocalToGlobalMappingGetIndices(ltogm, &g_idx);</font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000"><br></font></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><span style="color:rgb(0,0,0)">  </span><span style="color:rgb(0,0,0)">PetscFunctionReturn</span><span style="color:rgb(0,0,0)">(PETSC_</span><span style="color:rgb(0,0,0)">SUCCESS);</span></div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px"><font color="#000000">}</font></div></div></div>
</blockquote></div><div><br clear="all"></div><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!ZoOMxv_X_kOSiYdGQlrrfxNqBqX-JwvUe4wg8Lmx9ICyyEgKROX7IMg4jQIW9310TtkewqWflxHLqyHojTxe$" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>