<div dir="ltr">Hi Noam,<div><br></div><div>I think you want <a href="https://urldefense.us/v3/__https://petsc.org/release/manualpages/DMPlex/DMPlexGetClosureIndices/__;!!G_uCfscf7eWS!f8v1_ty7e_mf4QhytGsCFXSd_APEy50GjoLrAL_o294K-EBz1Xa8kEDmeq3UmehbZvBL-u72r4GN6mjxAFf6Ljw$">https://petsc.org/release/manualpages/DMPlex/DMPlexGetClosureIndices/</a></div><div><br></div><div>Indices are ordered globally on the first process (0) first, the proc 1, etc., so the global index is the local index + "my start index". You can get this local start index in a number of ways, eg, <a href="https://urldefense.us/v3/__https://petsc.org/main/manualpages/Mat/MatGetOwnershipRange__;!!G_uCfscf7eWS!f8v1_ty7e_mf4QhytGsCFXSd_APEy50GjoLrAL_o294K-EBz1Xa8kEDmeq3UmehbZvBL-u72r4GN6mjxh3g3zew$">https://petsc.org/main/manualpages/Mat/MatGetOwnershipRange</a> if you have a scalar matrix from the DM/section.</div><div><br></div><div>Thanks, </div><div>Mark</div><div>ps, we are at the PETSc annual meeting this week, so may be slow to respond</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, May 19, 2025 at 6:58 PM Noam T. via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></div><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><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: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>