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.

Convert netgen mesh to numpy arrays?

More
3 years 2 weeks ago #3618 by rick42
Is there an efficient way to extract or convert a netgen mesh to numpy arrays in Python. I'm currently using the following
Code:
p = mesh.Points() vertices = np.empty(shape=(len(p), 3), dtype='float32') for i, p_i in enumerate(p): vertices[i] = list(p_i) pass faceels = mesh.Elements2D() faces = np.empty(shape=(len(faceels), 3), dtype='uint32') for i, el in enumerate(faceels): faces[i] = [p.nr-1 for p in el.points] pass

which isn't very efficient. Is there a better way?
More
3 years 2 weeks ago #3633 by rick42
Is there anyone who can comment on this (is it possible at all?), or point out something in the documentation (as I couldn't find anything about this)?
More
3 years 2 weeks ago - 3 years 2 weeks ago #3637 by christopher
Hm depends what you want to get from python with regards to efficiency, but you could write it more compact and more efficient like this:
Code:
from netgen.geom2d import unit_square mesh = unit_square.GenerateMesh(maxh=0.2) import numpy as np # verts = np.array([v.point for v in mesh.vertices]) verts = np.array([list(p) for p in mesh.Points()]) print(verts) els = np.array([el.vertices for el in mesh.Elements2D()]) print(els)
Last edit: 3 years 2 weeks ago by christopher.
Time to create page: 0.109 seconds