<div dir="ltr"><div dir="ltr">On Mon, Dec 6, 2021 at 6:06 PM Ferrand, Jesus A. <<a href="mailto:FERRANJ2@my.erau.edu">FERRANJ2@my.erau.edu</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 style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Dear PETSc Team:</div>
<div style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
I am a new PETSc user who is working on an FEA code and ran into an issue pertaining to DMPlex. </div>
<div style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
I have a gmsh mesh file that I import using "DMPlexCreateGmshFromFile()." I then fetch the XYZ coordinates of the nodes from this mesh using "DMGetCoordinatesLocal()." Deeper into the code, I have a call to "DMPlexGetTransitiveClosure()" inside a loop that
 scans the cells (I think you guys refer to it as "depth-3")</div></div></blockquote><div><br></div><div>It is more robust to use height 0 for cells.</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 style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)"> to reference nodes. Here's the catch: If I attempt to reference the array from the vector (Vec) in the call to "DMGetCoordinatesLocal()" by using something like "VecGetArray()," or "VecGetArrayRead(),"
 the call to "DMPlexGetTransitiveClosure()" errors-out with a segmentation fault. I need access to that vector's stored XYZ-data because I'm using my own finite element scripts. <span style="font-family:"Times New Roman",Times,serif;font-size:12pt">I
 have no clue as to why this is happening. Maybe it is a newbie mistake and I am forgetting to restore some memory?</span></div></div></blockquote><div><br></div><div>1) The First DMCreate() is unnecessary and leaks right now</div><div><br></div><div>2) PetscSectionDestroy(&s) after DMSetLocalSection()</div><div><br></div><div>3) Once you have set the section, you can use DMCreateGlobalVector() and DMCreateMatrix() instead of doing it by hand</div><div><br></div><div>4) DMPlexGetTransitiveClosure() has somewhat complicated memory management:</div><div><br></div><div>  a) The safest thing to do is initialize closure to NULL, and call Get/RestoreClosure() each iteration</div><div><br></div><div>  b) If you want to manage the memory yourself, then allocate closure[] coming in and every iteration reset size_closure to the array size on input</div><div><br></div><div>  c) You can combine these, so that you set closure to NULL on input, so that GetClosure() allocates the array for you. Then make the rest of your</div><div>       calls without changing size_closure and closure. Then after the loop ends call RestoreClosure() and it will deallocate.</div><div><br></div><div>Note that this looks like elasticity. SNES ex17 is my idea of doing elasticity :)</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 style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Code, error message, and gmsh files are attached.</div>
<div style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Your help is much appreciated.</div>
<div style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Machine Type: HP Laptop</div>
<div style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
C-compiler: Gnu C<br>
OS: Ubuntu 20.04</div>
<div style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
PETSc version: 3.16.0</div>
<div style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
MPI Implementation: MPICH</div>
<div>
<div id="gmail-m_7988526390838635448Signature">
<div>
<div style="font-family:"Times New Roman",Times,serif;font-size:12pt;color:rgb(0,0,0)">
</div>
<div></div>
<div></div>
<div id="gmail-m_7988526390838635448divtagdefaultwrapper" dir="ltr" style="font-size:12pt;font-family:Calibri,Helvetica,sans-serif;color:rgb(0,0,0)">
<p style="margin-top:0px;margin-bottom:0px"></p>
<div>
<p style="margin:0px 0px 10.66px"></p>
<div>
<p style="background:white;margin:0px 0px 11px;line-height:normal"><span style="margin:0px;color:black;font-family:"Times New Roman",Times,serif;font-size:12pt">Sincerely:</span></p>
<p style="background:white;margin:0px;line-height:normal"><span style="margin:0px;color:red;font-family:"Courier New",monospace;font-size:14pt"><b><span style="font-family:"Courier New",monospace">J.A. Ferrand</span></b></span><u><span style="margin:0px;color:red;font-family:"Swis721 BlkCn BT",sans-serif;font-size:12pt"></span></u></p>
<p style="background:white;margin:0px;line-height:normal"><span style="margin:0px;color:black;font-family:Courant;font-size:12pt">Embry-Riddle Aeronautical University - Daytona Beach FL</span></p>
<p style="background:white;margin:0px;line-height:normal"><span style="margin:0px;color:black;font-family:Courant;font-size:12pt">M.Sc. Aerospace Engineering | May 2022</span></p>
<p style="background:white;margin:0px;line-height:normal"><span style="margin:0px;color:black;font-family:Courant;font-size:12pt">B.Sc. Aerospace Engineering</span></p>
<p style="background:white;margin:0px;line-height:normal"><span style="margin:0px;color:black;font-family:Courant;font-size:12pt">B.Sc. Computational Mathematics</span></p>
<p style="background:white;margin:0px;line-height:normal"><span style="margin:0px;color:rgb(0,0,0);font-family:Courant;font-size:12pt"> </span></p>
<p style="background:white;margin:0px;line-height:normal"><span style="margin:0px;color:black;font-family:Courant;font-size:12pt"><span style="color:rgb(0,0,0);font-family:Courant;font-size:12pt;background-color:rgb(255,255,255);display:inline">Sigma
 Gamma Tau</span><span style="color:rgb(0,0,0);font-family:Courant;font-size:12pt;background-color:rgb(255,255,255);display:inline"> </span><br>
</span></p>
<p style="background:white;margin:0px;line-height:normal"><span style="margin:0px;color:rgb(0,0,0);font-family:Courant;font-size:12pt">Tau Beta Pi</span></p>
<p style="background:white;margin:0px;line-height:normal"><span style="margin:0px;color:black;font-family:Courant;font-size:12pt"><span style="margin:0px;color:rgb(0,0,0);font-family:Courant;font-size:12pt">Honors Program</span></span></p>
<p style="background:white;margin:0px;line-height:normal"><span style="margin:0px;color:black;font-family:Courant;font-size:12pt"> </span></p>
<p style="background:white;margin:0px;line-height:normal"><u><span style="margin:0px;color:black;font-family:Courant;font-size:12pt">Phone:</span></u><span style="margin:0px;color:black;font-family:Courant;font-size:12pt"> (386)-843-1829</span></p>
<p style="background:white;margin:0px;line-height:normal"><u><span style="margin:0px;color:black;font-family:Courant;font-size:12pt">Email(s):</span></u><span style="margin:0px;color:black;font-family:Courant;font-size:12pt"> <a href="mailto:ferranj2@my.erau.edu" target="_blank">ferranj2@my.erau.edu</a></span></p>
<p style="background:white;margin:0px;line-height:normal;text-indent:0.5in">
<span style="margin:0px;color:black;font-family:Courant;font-size:12pt"><span style="margin:0px">   
</span><a href="mailto:jesus.ferrand@gmail.com" target="_blank">jesus.ferrand@gmail.com</a></span></p>
</div>
</div>
</div>
</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>