- Thank you received: 0
Finding the coordinates of the vertices of an element
4 years 6 days ago #3342
by rgs
Finding the coordinates of the vertices of an element was created by rgs
Hello,
I am trying to find the coordinates of an element in netgen.
So far, I found that I can get a list of all elements in a mesh using "mesh.Elements3D()" and each item in the list seems to be the number of points in the element followed by the indices of the points. Each element has two properties "points" and "vertices", but they are again the indices of the points/vertices.
Is there a way to find the coordinates of the vertices of an element, or the coordinates of a point having a particular point index?
Thank you in advance!
I am trying to find the coordinates of an element in netgen.
So far, I found that I can get a list of all elements in a mesh using "mesh.Elements3D()" and each item in the list seems to be the number of points in the element followed by the indices of the points. Each element has two properties "points" and "vertices", but they are again the indices of the points/vertices.
Is there a way to find the coordinates of the vertices of an element, or the coordinates of a point having a particular point index?
Thank you in advance!
4 years 6 days ago #3344
by cwinters
Replied by cwinters on topic Finding the coordinates of the vertices of an element
Hi,
you can get the points of the mesh using "mesh.Points()" and use the indices of the points to get the coordinates.
Best,
Christoph
you can get the points of the mesh using "mesh.Points()" and use the indices of the points to get the coordinates.
Code:
from netgen.csg import unit_cube
mesh = unit_cube.GenerateMesh(maxh=0.5)
pnts = mesh.Points()
for i,el in enumerate(mesh.Elements3D()):
print("el = ",i)
for v in el.vertices:
print(pnts[v])
Best,
Christoph
The following user(s) said Thank You: rgs
4 years 6 days ago #3348
by rgs
Replied by rgs on topic Finding the coordinates of the vertices of an element
Hello Christoph,
Thank you for your quick reply.
Is it possible to find the index of a boundary if the coordinates or the index of a point on the boundary is known?
Thank you!
Rohit
Thank you for your quick reply.
Is it possible to find the index of a boundary if the coordinates or the index of a point on the boundary is known?
Thank you!
Rohit
4 years 5 days ago #3349
by cwinters
Replied by cwinters on topic Finding the coordinates of the vertices of an element
Hello Rohit,
you have to loop over the 2D elements. Then you can check the boundary index and you have number and coordinate of the point available.
If you are using NGSolve, you can also do this on the NGSolve mesh, which might be handier for you.
When you are solving problems with NGSolve, I would strongly recommend to name you boundaries and use these names when defining your problem. Something about boundaries in the docu .
Best,
Christoph
you have to loop over the 2D elements. Then you can check the boundary index and you have number and coordinate of the point available.
Code:
for i,el in enumerate(mesh.Elements2D()):
print("surface el = ",i)
print("surface index = ",el.index)
for v in el.vertices:
print(pnts[v])
If you are using NGSolve, you can also do this on the NGSolve mesh, which might be handier for you.
Code:
from ngsolve import *
mesh = Mesh(mesh) # convert to NGSolve mesh
for el in mesh.Elements(VOL):
print("el = ",el.nr)
for v in el.vertices:
print(mesh[v].point)
for el in mesh.Elements(BND):
print("surface el = ",el.nr)
print("surface index = ",el.index)
for v in el.vertices:
print(mesh[v].point)
When you are solving problems with NGSolve, I would strongly recommend to name you boundaries and use these names when defining your problem. Something about boundaries in the docu .
Best,
Christoph
The following user(s) said Thank You: rgs
4 years 5 days ago #3350
by rgs
Replied by rgs on topic Finding the coordinates of the vertices of an element
Hello Christoph,
thank you once again for your help and your quick reply. Everything is now working perfectly in my script.
Cheers,
Rohit
thank you once again for your help and your quick reply. Everything is now working perfectly in my script.
Cheers,
Rohit
Time to create page: 0.102 seconds