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

Matthew Knepley knepley at gmail.com
Sat Mar 1 16:03:36 CST 2025


On Fri, Feb 28, 2025 at 10:56 PM neil liu <liufield at gmail.com> wrote:

> 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.
>
> Yes, you can have different dofs for different faces and edges.

  Thanks,

     Matt

> 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!ZsBh5OX58KUe1Hyg6ZiMop1edd2nEbpUAOf1uhS0PzEB_PPE-5mD6KGpu2ng0rlcFokwYpolDtqm-ofYOxqQ$ 
>> <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZsBh5OX58KUe1Hyg6ZiMop1edd2nEbpUAOf1uhS0PzEB_PPE-5mD6KGpu2ng0rlcFokwYpolDtqm-jir4PBe$ >
>>
>

-- 
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!ZsBh5OX58KUe1Hyg6ZiMop1edd2nEbpUAOf1uhS0PzEB_PPE-5mD6KGpu2ng0rlcFokwYpolDtqm-ofYOxqQ$  <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZsBh5OX58KUe1Hyg6ZiMop1edd2nEbpUAOf1uhS0PzEB_PPE-5mD6KGpu2ng0rlcFokwYpolDtqm-jir4PBe$ >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20250301/a0325471/attachment.html>


More information about the petsc-users mailing list