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)
| 249 | |
| 250 | |
| 251 | def 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 | |
| 285 | def model_to_mesh( |