Hello. I am a master's student in Mexico. I am currently working on a project in which we are implementing DMPlex in a code for electromagnetic modeling. Right now I am working on understanding the tool in C. But I'm stuck on something and that's why my next doubt: I am trying to get the coordinates of the nodes of a mesh in DMPlex. I already understood how the DAG is structured, how to obtain the nodes that make up some point. But the ordering of the nodes changes in DMPlex. So I need to know the coordinates of each node to compare them with my initial mesh and confirm that the same nodes form the same point in the software I am using as well as in the DMPlex DAG. It would be great if you could guide me a bit on how to do this or indicate which DMPlex examples would be good to review or which examples solve something similar to my situation. Thank you in advance. Regards.
Good Evening Miguel, I've successfully used the following to get the coordinates of all nodes/vertices from a DMPlex. The steps I use are as follow ----- CODE ------ Vec coordinates; // Define a Petsc vector to store the coordinates. PetscInt cdm; // Define a PetscInt to store coordinate dimension of DMPlex PetscInt *vSize; // PetscInt to store number of elements in vector (used below) PetscErrorCode ierr; ierr = DMGetCoordinateDM(dm, &cdm); CHKERRQ(ierr); // Get coordinate dimension of dm ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); // Populate Vector with (x, y, z) coordinates of all nodes/vectors in DM ierr = VecGetSize(coordinates, &vSize); // Get Number of elements in coordinates vector PetscScalar coords[vSize]; // Define array where the (x, y, z) values will be stored const PetscInt ix[vSize]; // Define array to store indices of coordinates you'd like to get values for // Load ix[] with indices of Vector coordinate[] you want values for. In your case, you would like all of them for (int ii = 0; ii < vSize; ++ii){ ix[ii] = ii; // Note: Petsc uses 0-based indexing } ierr = VecGetValues(coordinates, vSize, ix, coords); // Get (x, y, z) values from Vector coordinates and store in coords[] array. // All (x, y, z) coordinates for all nodes/vertices should now be in the coords[] array. // They are stored interlaced. i.e. (x_0, y_0, z_0, x_1, y_1, z_1, .... x_n-1, y_n-1, z_n-1) // Print out each nodes (x, y, z) coordinates to screen. I assuming 3 dimensions for (int ii = 0; ii < vSize; ii+3){ ierr = PetscPrintf(PETSC_COMM_SELF, " Node %d :: (x,y,z) = (%lf, %lf, %lf) \n", coords[ii], coords[ii+1],coords[ii+2]); } ---- END OF CODE ---- Please forgive any coding errors/typos that may be above but the technique should work. I don't claim that this is the most elegant solution. Good Luck -Brandon On Sat, Jul 24, 2021 at 9:58 AM Miguel Angel Tapia <[email protected]> wrote:
Hello. I am a master's student in Mexico. I am currently working on a project in which we are implementing DMPlex in a code for electromagnetic modeling. Right now I am working on understanding the tool in C. But I'm stuck on something and that's why my next doubt:
I am trying to get the coordinates of the nodes of a mesh in DMPlex. I already understood how the DAG is structured, how to obtain the nodes that make up some point. But the ordering of the nodes changes in DMPlex. So I need to know the coordinates of each node to compare them with my initial mesh and confirm that the same nodes form the same point in the software I am using as well as in the DMPlex DAG.
It would be great if you could guide me a bit on how to do this or indicate which DMPlex examples would be good to review or which examples solve something similar to my situation.
Thank you in advance. Regards.
This is a Matt question and I recall a question on getting the original node ordering recently, but I am not finding it. How is your Plex created? If you give it a mesh and don't distribute it the node ordering does not change. In that case you can use a simpler version Brandon's code: ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); Then use VecView. However, I don't understand what you are trying to do exactly. Are you just verifying that PLex has the correct coordinates? Mark On Sat, Jul 24, 2021 at 9:58 AM Miguel Angel Tapia <[email protected]> wrote:
Hello. I am a master's student in Mexico. I am currently working on a project in which we are implementing DMPlex in a code for electromagnetic modeling. Right now I am working on understanding the tool in C. But I'm stuck on something and that's why my next doubt:
I am trying to get the coordinates of the nodes of a mesh in DMPlex. I already understood how the DAG is structured, how to obtain the nodes that make up some point. But the ordering of the nodes changes in DMPlex. So I need to know the coordinates of each node to compare them with my initial mesh and confirm that the same nodes form the same point in the software I am using as well as in the DMPlex DAG.
It would be great if you could guide me a bit on how to do this or indicate which DMPlex examples would be good to review or which examples solve something similar to my situation.
Thank you in advance. Regards.
I'm really sorry, I should have explained it more specifically. This is the situation. I am using a very simple mesh to learn and test with DMPlex. My mesh has these nodes: 1 0 0 0 2 1 0 0 3 1 1 0 4 0 1 0 5 0 0 1 6 1 0 1 7 1 1 1 8 0 1 1 9 0.5 0.5 1 10 0.5 0 0.5 11 1 0.5 0.5 12 0.5 1 0.5 13 0 0.5 0.5 14 0.5 0.5 0 Executing in a single process these 14 nodes take values from 24 to 37. I would like to know how to obtain the coordinates through DMPlex. I know that using DMGetCoordinatesLocal I get the vector of all coordinates. But I would like to be more specific. For example, I choose point 2 of the DAG of the mesh that I am using, this point is formed by nodes 32, 33, 34 and 36 according to the order of the DAG. How can I know the coordinates of those specific nodes? And if I know those coordinates, I can see which points are from the original mesh and verify that they are the same in the software to which I want to implement DMPlex. Maybe this is very simple, but I am just learning the use of the tool and right now my job is to know if I can obtain the same results with DMPlex as the code I want to modify. ________________________________ De: Mark Adams <[email protected]> Enviado: domingo, 25 de julio de 2021 06:43 a. m. Para: Miguel Angel Tapia <[email protected]> CC: [email protected] <[email protected]> Asunto: Re: [petsc-users] DMPlex doubt This is a Matt question and I recall a question on getting the original node ordering recently, but I am not finding it. How is your Plex created? If you give it a mesh and don't distribute it the node ordering does not change. In that case you can use a simpler version Brandon's code: ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); Then use VecView. However, I don't understand what you are trying to do exactly. Are you just verifying that PLex has the correct coordinates? Mark On Sat, Jul 24, 2021 at 9:58 AM Miguel Angel Tapia <[email protected]<mailto:[email protected]>> wrote: Hello. I am a master's student in Mexico. I am currently working on a project in which we are implementing DMPlex in a code for electromagnetic modeling. Right now I am working on understanding the tool in C. But I'm stuck on something and that's why my next doubt: I am trying to get the coordinates of the nodes of a mesh in DMPlex. I already understood how the DAG is structured, how to obtain the nodes that make up some point. But the ordering of the nodes changes in DMPlex. So I need to know the coordinates of each node to compare them with my initial mesh and confirm that the same nodes form the same point in the software I am using as well as in the DMPlex DAG. It would be great if you could guide me a bit on how to do this or indicate which DMPlex examples would be good to review or which examples solve something similar to my situation. Thank you in advance. Regards.
By 'point 2' if you mean the nodes that touch a cells (c==2 below) you can use something like: PetscScalar *coef = NULL; Vec coords; PetscInt csize,Nv,d,nz; DM cdm; PetscSection cs; ierr = DMPlexGetHeightStratum(plex,0,&cStart,&cEnd);CHKERRQ(ierr); ierr = DMGetCoordinatesLocal(dm, &coords);CHKERRQ(ierr); ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); ierr = DMGetLocalSection(cdm, &cs);CHKERRQ(ierr); for (c = cStart; c < cEnd; c++) { ierr = DMPlexVecGetClosure(cdm, cs, coords, c, &csize, &coef);CHKERRQ(ierr); If you want indices and offsets use DMPlexGetClosureIndices ( https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMPLEX/DMPlexGe...) instead. I think you want the offsets. Mark On Sun, Jul 25, 2021 at 9:43 PM Miguel Angel Tapia <[email protected]> wrote:
I'm really sorry, I should have explained it more specifically.
This is the situation. I am using a very simple mesh to learn and test with DMPlex. My mesh has these nodes: 1 0 0 0 2 1 0 0 3 1 1 0 4 0 1 0 5 0 0 1 6 1 0 1 7 1 1 1 8 0 1 1 9 0.5 0.5 1 10 0.5 0 0.5 11 1 0.5 0.5 12 0.5 1 0.5 13 0 0.5 0.5 14 0.5 0.5 0
Executing in a single process these 14 nodes take values from 24 to 37. I would like to know how to obtain the coordinates through DMPlex. I know that using DMGetCoordinatesLocal I get the vector of all coordinates. But I would like to be more specific. For example, I choose point 2 of the DAG of the mesh that I am using, this point is formed by nodes 32, 33, 34 and 36 according to the order of the DAG. How can I know the coordinates of those specific nodes?
And if I know those coordinates, I can see which points are from the original mesh and verify that they are the same in the software to which I want to implement DMPlex. Maybe this is very simple, but I am just learning the use of the tool and right now my job is to know if I can obtain the same results with DMPlex as the code I want to modify. ------------------------------ *De:* Mark Adams <[email protected]> *Enviado:* domingo, 25 de julio de 2021 06:43 a. m. *Para:* Miguel Angel Tapia <[email protected]> *CC:* [email protected] <[email protected]> *Asunto:* Re: [petsc-users] DMPlex doubt
This is a Matt question and I recall a question on getting the original node ordering recently, but I am not finding it.
How is your Plex created? If you give it a mesh and don't distribute it the node ordering does not change. In that case you can use a simpler version Brandon's code: ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); Then use VecView.
However, I don't understand what you are trying to do exactly. Are you just verifying that PLex has the correct coordinates?
Mark
On Sat, Jul 24, 2021 at 9:58 AM Miguel Angel Tapia < [email protected]> wrote:
Hello. I am a master's student in Mexico. I am currently working on a project in which we are implementing DMPlex in a code for electromagnetic modeling. Right now I am working on understanding the tool in C. But I'm stuck on something and that's why my next doubt:
I am trying to get the coordinates of the nodes of a mesh in DMPlex. I already understood how the DAG is structured, how to obtain the nodes that make up some point. But the ordering of the nodes changes in DMPlex. So I need to know the coordinates of each node to compare them with my initial mesh and confirm that the same nodes form the same point in the software I am using as well as in the DMPlex DAG.
It would be great if you could guide me a bit on how to do this or indicate which DMPlex examples would be good to review or which examples solve something similar to my situation.
Thank you in advance. Regards.
participants (3)
-
Brandon Denton -
Mark Adams -
Miguel Angel Tapia