<div dir="ltr"><div dir="ltr">On Sun, Jul 24, 2022 at 8:46 AM Duan Junming 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">
<div dir="ltr">
<div id="gmail-m_-4079929664525374507divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:"Times New Roman",Times,serif" dir="ltr">
<p>Dear all,</p>
<p><br>
</p>
<p>I want to add more dofs to the coordinate DM to represent a curved mesh.</p>
<p>I first create a simple box mesh with one cell:</p>
<p><br>
</p>
<p></p>
<div> PetscCall(DMCreate(comm, &dm));</div>
<div> PetscCall(DMSetType(dm, DMPLEX));</div>
<div> dim = 2;</div>
<div> PetscInt n_faces[2] = {1, 1};</div>
<div> DMBoundaryType periodicity[2] = {DM_BOUNDARY_GHOSTED, DM_BOUNDARY_GHOSTED};</div>
<div> DMPlexCreateBoxMesh(comm, dim, PETSC_FALSE, n_faces, NULL, NULL, periodicity, PETSC_TRUE, &dm);</div>
<div><br>
</div>
<div>Then I add more dofs to cdm using section:</div>
<div><br>
</div>
<div>
<div> PetscCall(DMGetCoordinateDM(dm, &cdm));</div>
<div> PetscCall(DMGetLocalSection(cdm, &cs));</div>
<div> PetscCall(DMPlexGetChart(dm, &pStart, &pEnd));</div>
<div> PetscCall(PetscSectionSetChart(cs, pStart, pEnd));</div>
<div> degree = 3;</div>
<div> for(depth = 0; depth <= dim; ++ depth) {</div>
<div> PetscCall(DMPlexGetDepthStratum(cdm, depth, &pStart, &pEnd));</div>
<div> for(p = pStart; p < pEnd; ++p) {</div>
<div> <b>PetscCall(PetscSectionSetDof(cs, p, dim*PetscPowInt(degree-1, depth)));</b></div>
<div><b> PetscCall(PetscSectionSetFieldDof(cs, p, 0, dim*PetscPowInt(degree-1, depth)));</b></div>
<div> }</div>
<div> }</div>
<div> PetscCall(PetscSectionSetUp(cs));</div>
<div> PetscCall(DMSetUp(cdm));</div>
<div><br>
</div>
<div>Finally, I wish to get the vec to set the coordinates:</div>
<div><br>
</div>
<div>
<div> PetscCall(DMCreateLocalVector(cdm, &coordinates));</div>
<div> PetscScalar *pCoords = NULL;</div>
<div> PetscCall(DMPlexVecGetClosure(cdm, NULL, coordinates, 0, &pSize, &pCoords));</div>
<div> printf("pSize: %d\n", pSize);</div>
<div><br>
</div>
</div>
However, if I only use <b style="font-family:"Times New Roman",Times,serif,Times,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">PetscSectionSetDof</b>, the code reports
"<span>Section size 32 does not match Vec closure size 0</span>".</div>
<div>Instead, if I only use <b style="font-family:"Times New Roman",Times,serif,Times,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">
PetscSectionSetFieldDof</b>, the code crashes with "<span>Checking the memory for corruption."</span></div>
<div><span>It runs without error when I use both <b style="font-family:"Times New Roman",Times,serif,Times,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">
PetscSectionSetDof </b>and <b style="font-family:"Times New Roman",Times,serif,Times,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">
PetscSectionSetFieldDof</b>.</span></div>
<div><span><span style="font-family:"Times New Roman",Times,serif,Times,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px"><br>
</span></span></div>
<div><span><span style="font-family:"Times New Roman",Times,serif,Times,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">Maybe I have missed something, but c</span></span>ould
you help to explain why I should both functions <b>PetscSectionSetDof</b> and <b>
PetscSectionSetFieldDof?</b></div>
<div><span><span style="font-family:"Times New Roman",Times,serif,Times,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px"><span style="font-family:"Times New Roman",Times,serif,Times,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px"><span style="font-family:"Times New Roman",Times,serif,Times,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">It
is not straightforward that I should again set the dofs of the section after each field of the section has been set.</span></span></span></span></div></div></div></blockquote><div><br></div><div>This is the intended behavior, and how we use it internally. The use of fields is optional in order to allow Section to be as lightweight</div><div>as possible. We do not enforce consistency between the field and overall sizes.</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"><div dir="ltr"><div id="gmail-m_-4079929664525374507divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:"Times New Roman",Times,serif" dir="ltr">
<div>I can also see that <b style="font-family:"Times New Roman",Times,serif,Times,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">PetscSectionSetFieldDof </b>call
<span style="font-family:"Times New Roman",Times,serif,Times,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">
<b>PetscSectionSetDof </b>on the specific field of the section,</span></div>
<div><span>and cs->field[0] doesn't share the same address as cs itself.</span></div>
<div><span><br>
</span></div>
<div><span>Thanks in advance!</span></div>
<div>Junming</div>
<div><span><br>
</span></div>
<br>
<p></p>
<div id="gmail-m_-4079929664525374507Signature">
<div id="gmail-m_-4079929664525374507divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif,Times,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<p style="font-family:Calibri,Helvetica,sans-serif;font-size:16px"><span style="font-family:"Times New Roman",Times,serif;font-size:12pt"></span></p>
</div>
</div>
</div>
</div>
</blockquote></div><br clear="all"><div><br></div>-- <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="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>