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

Function _

python/dolfinx/plot.py:78–132  ·  view source on GitHub ↗

Create VTK mesh topology based on the degree-of-freedom coordinates. This function supports visualisation when the degree of the finite element space is different from the geometric degree of the mesh. Note: This function supports Lagrange elements (continuous and disco

(V: fem.FunctionSpace, entities=None)

Source from the content-addressed store, hash-verified

76
77@vtk_mesh.register
78def _(V: fem.FunctionSpace, entities=None): # type: ignore
79 """Create VTK mesh topology based on the degree-of-freedom coordinates.
80
81 This function supports visualisation when the degree of the finite
82 element space is different from the geometric degree of the mesh.
83
84 Note:
85 This function supports Lagrange elements (continuous and
86 discontinuous) only.
87
88 Args:
89 V: Mesh to extract data from.
90 entities: Entities to extract. Extract all if ``None``.
91
92 Returns:
93 Topology, type for each cell, and geometry in VTK-ready format.
94 """
95 if V.ufl_element().family_name not in [
96 "Discontinuous Lagrange",
97 "Lagrange",
98 "DQ",
99 "Q",
100 "DP",
101 "P",
102 ]:
103 raise RuntimeError(
104 "Can only create meshes from continuous or discontinuous Lagrange"
105 "spaces, not {V.ufl_element().family_name}."
106 )
107
108 degree = V.ufl_element().degree
109 if degree == 0:
110 raise RuntimeError("Cannot create topology from cellwise constants.")
111
112 # Use all local cells if not supplied
113 msh = V.mesh
114 tdim = msh.topology.dim
115 if entities is None:
116 entities = range(msh.topology.index_map(tdim).size_local)
117
118 dofmap = V.dofmap
119 num_dofs_per_cell = V.dofmap.dof_layout.num_dofs
120 cell_type = msh.topology.cell_type
121 perm = np.argsort(_cpp.io.perm_vtk(cell_type, num_dofs_per_cell))
122
123 vtk_type = (
124 _first_order_vtk[cell_type] if degree == 1 else _cpp.io.get_vtk_cell_type(cell_type, tdim)
125 )
126 cell_types = np.full(len(entities), vtk_type)
127
128 topology = np.zeros((len(entities), num_dofs_per_cell + 1), dtype=np.int32)
129 topology[:, 0] = num_dofs_per_cell
130 dofmap_ = dofmap.list
131 topology[:, 1:] = dofmap_[entities][:, perm]
132 return topology.reshape(1, -1)[0], cell_types, V.tabulate_dof_coordinates()

Callers

nothing calls this directly

Calls 4

perm_vtkMethod · 0.80
get_vtk_cell_typeMethod · 0.80
index_mapMethod · 0.45

Tested by

no test coverage detected