Convert netgen mesh to numpy arrays?

More
3 years 8 months 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 8 months 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 8 months ago - 3 years 8 months 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 8 months ago by christopher.
Time to create page: 0.106 seconds