Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Finding the coordinates of the vertices of an element

More
3 years 5 months ago #3342 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!
More
3 years 5 months ago #3344 by cwinters
Hi,

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
More
3 years 5 months ago #3348 by rgs
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
More
3 years 5 months ago #3349 by cwinters
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.
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
More
3 years 5 months ago #3350 by rgs
Hello Christoph,

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.179 seconds