[petsc-users] Inquiry about resetting a petscsection for a dmplex

neil liu liufield at gmail.com
Fri Feb 28 21:56:45 CST 2025


Thanks a lot, Matt! It works well.

I have another question regarding future p-adaptivity. Will the section
support defining different DOFs for each face and edge? Maybe I should try
this.

Thanks,

Xiaodong


On Thu, Feb 27, 2025 at 9:16 PM Matthew Knepley <knepley at gmail.com> wrote:

> On Thu, Feb 27, 2025 at 6:12 PM neil liu <liufield at gmail.com> wrote:
>
>> Dear Pestc community,
>>
>> 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.
>>
>> 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.
>>
>> Did I miss something?
>>
>> When solving two systems like this on the same mesh, I recommend using
> DMClone(). What this does is create you a new
> 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?
>
>   Thanks,
>
>      Matt
>
>> Thanks,
>>
>>
>> Xiaodong
>>
>> PetscErrorCode DMManage::SetupSection(CaseInfo &objCaseInfo){
>> PetscSection s;
>> PetscInt edgeStart, edgeEnd, pStart, pEnd;
>> PetscInt cellStart, cellEnd;
>> PetscInt faceStart, faceEnd;
>>
>> PetscFunctionBeginUser;
>> DMPlexGetChart(dm, &pStart, &pEnd);
>> DMPlexGetHeightStratum(dm, 0, &cellStart, &cellEnd);
>> DMPlexGetHeightStratum(dm, 1, &faceStart, &faceEnd);
>> DMPlexGetHeightStratum(dm, 2, &edgeStart, &edgeEnd); /* edges */;
>> PetscSectionCreate(PetscObjectComm((PetscObject)dm), &s);
>> PetscSectionSetNumFields(s, 1);
>> PetscSectionSetFieldComponents(s, 0, 1);
>> if (objCaseInfo.getnumberDof_local() == 6){
>> PetscSectionSetChart(s, edgeStart, edgeEnd);
>> for (PetscInt edgeIndex = edgeStart; edgeIndex < edgeEnd; ++edgeIndex) {
>> PetscSectionSetDof(s, edgeIndex, objCaseInfo.numdofPerEdge);
>> PetscSectionSetFieldDof(s, edgeIndex, 0, 1);
>> }
>> }
>> else if(objCaseInfo.getnumberDof_local() == 20){
>> PetscSectionSetChart(s, faceStart, edgeEnd);
>> for (PetscInt faceIndex = faceStart; faceIndex < faceEnd; ++faceIndex) {
>> PetscSectionSetDof(s, faceIndex, objCaseInfo.numdofPerFace);
>> PetscSectionSetFieldDof(s, faceIndex, 0, 1);
>> }
>> //Test
>> for (PetscInt edgeIndex = edgeStart; edgeIndex < edgeEnd; ++edgeIndex) {
>> PetscSectionSetDof(s, edgeIndex, objCaseInfo.numdofPerEdge);
>> PetscSectionSetFieldDof(s, edgeIndex, 0, 1);
>> }
>> }
>> //
>> PetscSectionSetUp(s);
>> DMSetLocalSection(dm, s);
>> PetscSectionDestroy(&s);
>>
>> //Output map for check
>> ISLocalToGlobalMapping ltogm;
>> const PetscInt *g_idx;
>> DMGetLocalToGlobalMapping(dm, &ltogm);
>> ISLocalToGlobalMappingView(ltogm, PETSC_VIEWER_STDOUT_WORLD);
>> ISLocalToGlobalMappingGetIndices(ltogm, &g_idx);
>>
>> PetscFunctionReturn(PETSC_SUCCESS);
>> }
>>
>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZTmIg2QHRHk4rNyrPzO0mJpbo5uTsYN7umDaXzGGtb2o3qeMrQtB0zvmFa55nwwfw-UtpYaOFEvs3PMXfa-oIQ$ 
> <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZTmIg2QHRHk4rNyrPzO0mJpbo5uTsYN7umDaXzGGtb2o3qeMrQtB0zvmFa55nwwfw-UtpYaOFEvs3PPt7om-xg$ >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20250228/4e85ac95/attachment.html>


More information about the petsc-users mailing list