<div dir="ltr"><div dir="ltr">On Mon, May 19, 2025 at 6:57 PM Noam T. via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</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>Hello,</div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><br></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)">I am trying to build the connectivity matrix for a mesh; i.e. the indices of the nodes that compose each cell.</div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><br></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)">Example:</div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><br></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace">0-------1</span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace">|.\.....|  </span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace"><span>|...\...|</span> <br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace">|.....\.|<br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace">3</span><span style="font-family:Menlo,Consolas,"Courier New",monospace">-------2</span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace"><br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Arial,sans-serif">the matrix would look like  [ [0, 3, 2], [2, 1, 0] ] (possibly different ordering).<br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace"><br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Arial,sans-serif">One option is using </span><span style="font-family:Menlo,Consolas,"Courier New",monospace"><span style="font-family:Arial,sans-serif">DMPlexGetTransitiveClosure</span></span><span style="font-family:Arial,sans-serif">, and accessing the last elements in the output "points", which contain the vertex indices. </span><span style="font-family:Menlo,Consolas,"Courier New",monospace"><br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Arial,sans-serif">However, these indices are local per process (both for vertices and  cells). Is it possible to get the global indices?</span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace"><br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Arial,sans-serif">I tried a mapping, as in example 14f (</span><span style="font-family:Menlo,Consolas,"Courier New",monospace"><span><a rel="noreferrer nofollow noopener" href="https://urldefense.us/v3/__https://petsc.org/release/src/ksp/ksp/tutorials/ex14f.F90.html__;!!G_uCfscf7eWS!ezMKlDED-8WxXpg_Elxus7WhYkZzCA5OmmLe6vHZGFoj4se5S5RD5ZgTrC3TYErx8znYKebSW-s0H0mt1_MEMAzpmFDwr0PH$" target="_blank"><span style="font-family:Arial,sans-serif">https://petsc.org/release/src/ksp/ksp/tutorials/ex14f.F90.html</span></a></span></span><span style="font-family:Arial,sans-serif">)</span><span style="font-family:Menlo,Consolas,"Courier New",monospace"><br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace"><br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace">---</span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace">DM :: dm</span><span style="font-family:Menlo,Consolas,"Courier New",monospace"><br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace"><span><span style="font-family:Menlo,Consolas,"Courier New",monospace">ISLocalToGlobalMapping :: ltog_map</span></span></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace"><span><span style="font-family:Menlo,Consolas,"Courier New",monospace"><span><span>PetscInt, pointer :: ltog_idx(:)</span></span><br></span></span></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><br></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace">! ... </span><br></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace">! Create a dm from a mesh file</span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace">! ...</span><br></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace">DMGetLocalToGlobalMapping(dm,ltog_map,ierr)</span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace">ISLocalToGlobalMappingGetIndices(ltog_map, ltog_idx, ierr)</span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace">---</span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace"><br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Arial,sans-serif">but the returned array </span><span style="font-family:Menlo,Consolas,"Courier New",monospace">ltog</span><span style="font-family:Arial,sans-serif"> is empty (ISLocalToGlobalMappingGetSize() returns zero)</span><span style="font-family:Arial,sans-serif">.  Are there other functions calls needed before being able to create this mapping? Or is this mapping simply not usable in this case?<br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Menlo,Consolas,"Courier New",monospace"><br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Arial,sans-serif">Is there perhaps better/simpler way to get this connectivity?</span></div></blockquote><div><br></div><div>There are several ways you might do this. It helps to know what you are aiming for.</div><div><br></div><div>1) If you just want this output, it might be easier to just DMView() with the PETSC_VIEWER_HDF5_VIZ format, since that just outputs the cell-vertex topology and coordinates</div><div><br></div><div>2) You can call DMPlexUninterpolate() to produce a mesh with just cells and vertices, and output it in any format.</div><div><br></div><div>3) If you want it in memory, but still with global indices (I don't understand this use case), then you can use DMPlexCreatePointNumbering() for an overall global numbering, or DMPlexCreateCellNumbering() and DMPlexCreateVertexNumbering() for separate global numberings.</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 style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Arial,sans-serif">Thank you.</span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-family:Arial,sans-serif">Noam</span><span style="font-family:Menlo,Consolas,"Courier New",monospace"><br></span></div><div style="font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"><br></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!cZBA-cU24g0I7WDWgJbyMqwJKxk50DrkIGAu36vgS0MNYlEAzNA354o5U-YVkcur8NsRsoSXABuuOt6MQSJx$" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>