MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / extract_geometry

Function extract_geometry

python/dolfinx/io/gmsh.py:251–282  ·  view source on GitHub ↗

Extract the mesh geometry from a Gmsh model. Returns an array of shape ``(num_nodes, 3)``, where the i-th row corresponds to the i-th node in the mesh. Args: model: Gmsh model name: Name of the Gmsh model. If not set the current model will be used. Retu

(model, name: str | None = None)

Source from the content-addressed store, hash-verified

249
250
251def extract_geometry(model, name: str | None = None) -> npt.NDArray[np.float64]:
252 """Extract the mesh geometry from a Gmsh model.
253
254 Returns an array of shape ``(num_nodes, 3)``, where the i-th row
255 corresponds to the i-th node in the mesh.
256
257 Args:
258 model: Gmsh model
259 name: Name of the Gmsh model. If not set the current
260 model will be used.
261
262 Returns:
263 The mesh geometry as an array of shape ``(num_nodes, 3)``.
264
265 """
266 if name is not None:
267 model.setCurrent(name)
268
269 # Get the unique tag and coordinates for nodes in mesh
270 indices, points, _ = model.mesh.getNodes()
271 points = points.reshape(-1, 3)
272
273 # Gmsh indices starts at 1. We therefore subtract one to use
274 # zero-based numbering
275 indices -= 1
276
277 # In some cases, Gmsh does not return the points in the same
278 # order as their unique node index. We therefore sort nodes in
279 # geometry according to the unique index
280 perm_sort = np.argsort(indices)
281 assert np.all(indices[perm_sort] == np.arange(len(indices)))
282 return points[perm_sort]
283
284
285def model_to_mesh(

Callers 1

model_to_meshFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected