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

Function vtk_mesh

python/dolfinx/plot.py:33–74  ·  view source on GitHub ↗

Create VTK mesh topology data for mesh entities. The vertex indices in the returned topology array are the indices for the associated entry in the mesh geometry. Args: msh: Mesh to extract data from. dim: Topological dimension of entities to extract. entities: E

(msh: mesh.Mesh, dim: int | None = None, entities=None)

Source from the content-addressed store, hash-verified

31
32@functools.singledispatch
33def vtk_mesh(msh: mesh.Mesh, dim: int | None = None, entities=None):
34 """Create VTK mesh topology data for mesh entities.
35
36 The vertex indices in the returned topology array are the indices
37 for the associated entry in the mesh geometry.
38
39 Args:
40 msh: Mesh to extract data from.
41 dim: Topological dimension of entities to extract.
42 entities: Entities to extract. Extract all if ``None``.
43
44 Returns:
45 Topology, type for each cell, and geometry in VTK-ready format.
46
47 """
48 if dim is None:
49 dim = msh.topology.dim
50
51 cell_type = _cpp.mesh.cell_entity_type(msh.topology.cell_type, dim, 0)
52 if cell_type == mesh.CellType.prism:
53 raise RuntimeError("Plotting of prism meshes not supported")
54
55 # Use all local cells if not supplied
56 if entities is None:
57 entities = np.arange(msh.topology.index_map(dim).size_local, dtype=np.int32)
58
59 geometry_entities = _cpp.mesh.entities_to_geometry(msh._cpp_object, dim, entities, False)
60
61 num_nodes_per_cell = geometry_entities.shape[1]
62 map_vtk = np.argsort(_cpp.io.perm_vtk(cell_type, num_nodes_per_cell))
63 vtk_topology = geometry_entities[:, map_vtk]
64
65 # Create mesh topology
66 topology = np.empty((len(entities), num_nodes_per_cell + 1), dtype=np.int32)
67 topology[:, 0] = num_nodes_per_cell
68 topology[:, 1:] = vtk_topology
69
70 # Array holding the cell type (shape) for each cell
71 vtk_type = _cpp.io.get_vtk_cell_type(cell_type, dim)
72 cell_types = np.full(len(entities), vtk_type)
73
74 return topology.reshape(-1), cell_types, msh.geometry.x
75
76
77@vtk_mesh.register

Callers 1

test_vtk_meshFunction · 0.90

Calls 3

perm_vtkMethod · 0.80
get_vtk_cell_typeMethod · 0.80
index_mapMethod · 0.45

Tested by 1

test_vtk_meshFunction · 0.72