13#include <basix/mdspan.hpp>
16#include <dolfinx/common/IndexMap.h>
18#include <dolfinx/fem/FiniteElement.h>
19#include <dolfinx/fem/FunctionSpace.h>
20#include <dolfinx/mesh/Geometry.h>
21#include <dolfinx/mesh/Mesh.h>
22#include <dolfinx/mesh/Topology.h>
31template <std::
floating_po
int T>
38template <std::
floating_po
int T>
58std::tuple<std::vector<T>, std::array<std::size_t, 2>,
59 std::vector<std::int64_t>, std::vector<std::uint8_t>>
64 auto topology = mesh->topology();
66 const std::size_t gdim = mesh->geometry().dim();
67 const int tdim = topology->dim();
70 auto dofmap = V.dofmap();
72 auto map_dofs = dofmap->index_map;
74 const int index_map_bs = dofmap->index_map_bs();
75 const int dofmap_bs = dofmap->bs();
78 auto element = V.element();
80 const int e_bs = element->block_size();
81 const std::size_t scalar_dofs = element->space_dimension() / e_bs;
82 const std::size_t num_nodes
83 = index_map_bs * (map_dofs->size_local() + map_dofs->num_ghosts())
88 const auto [X, Xshape] = element->interpolation_points();
89 const fem::CoordinateElement<T>& cmap = mesh->geometry().cmaps().front();
92 auto dofmap_x = mesh->geometry().dofmaps().front();
93 std::span<const T> x_g = mesh->geometry().x();
94 const std::size_t num_dofs_g = cmap.dim();
96 std::span<const std::uint32_t> cell_info;
97 if (element->needs_dof_transformations())
99 mesh->topology_mutable()->create_entity_permutations();
100 cell_info = std::span(mesh->topology()->get_cell_permutation_info());
103 using mdspan2_t = md::mdspan<T, md::dextents<std::size_t, 2>>;
104 using cmdspan4_t = md::mdspan<T, md::dextents<std::size_t, 4>>;
107 const std::array<std::size_t, 4> phi_shape
108 = cmap.tabulate_shape(0, Xshape[0]);
109 std::vector<T> phi_b(
110 std::reduce(phi_shape.begin(), phi_shape.end(), 1, std::multiplies{}));
111 cmdspan4_t phi_full(phi_b.data(), phi_shape);
112 cmap.tabulate(0, X, Xshape, phi_b);
113 auto phi = md::submdspan(phi_full, 0, md::full_extent, md::full_extent, 0);
116 auto map = topology->index_map(tdim);
118 const std::int32_t num_cells = map->size_local() + map->num_ghosts();
119 std::vector<T> x_b(scalar_dofs * gdim);
120 mdspan2_t x(x_b.data(), scalar_dofs, gdim);
121 std::vector<T> coordinate_dofs_b(num_dofs_g * gdim);
122 mdspan2_t coordinate_dofs(coordinate_dofs_b.data(), num_dofs_g, gdim);
124 std::vector<T> coords(num_nodes * 3, 0.0);
125 std::array<std::size_t, 2> cshape = {num_nodes, 3};
130 auto apply_dof_transformation
132 for (std::int32_t c = 0; c < num_cells; ++c)
135 for (std::size_t i = 0; i < dofmap_x.extent(1); ++i)
136 for (std::size_t j = 0; j < gdim; ++j)
137 coordinate_dofs(i, j) = x_g[3 * dofmap_x(c, i) + j];
140 cmap.push_forward(x, coordinate_dofs, phi);
141 if (apply_dof_transformation)
143 apply_dof_transformation(
144 x_b, std::span(cell_info.data(), cell_info.size()), c, x.extent(1));
148 auto dofs = dofmap->cell_dofs(c);
149 for (std::size_t i = 0; i < dofs.size(); ++i)
151 std::int32_t dof = dofs[i];
152 for (std::size_t j = 0; j < gdim; ++j)
153 coords[3 * dof + j] = x(i, j);
158 std::vector<std::int64_t> x_id(num_nodes);
159 std::array<std::int64_t, 2> range = map_dofs->local_range();
160 std::int32_t size_local = range[1] - range[0];
161 std::iota(x_id.begin(), std::next(x_id.begin(), size_local), range[0]);
162 std::span ghosts = map_dofs->ghosts();
163 std::ranges::copy(ghosts, std::next(x_id.begin(), size_local));
166 std::vector<std::uint8_t> id_ghost(num_nodes, 0);
167 std::fill(std::next(id_ghost.begin(), size_local), id_ghost.end(), 1);
169 return {std::move(coords), cshape, std::move(x_id), std::move(id_ghost)};
174template <std::
floating_po
int T>
175bool is_cellwise(
const fem::FiniteElement<T>& e)
177 return e.space_dimension() / e.block_size() == 1;
197std::tuple<std::vector<T>, std::array<std::size_t, 2>,
198 std::vector<std::int64_t>, std::vector<std::uint8_t>,
199 std::vector<std::int64_t>, std::array<std::size_t, 2>>
204 auto topology =
mesh->topology();
206 const int tdim = topology->dim();
210 throw std::runtime_error(
"Can't create VTK mesh from a mixed element");
212 const auto [x, xshape, x_id, x_ghost]
213 = impl::tabulate_lagrange_dof_coordinates(V);
214 auto map = topology->index_map(tdim);
215 const std::size_t num_cells = map->size_local() + map->num_ghosts();
220 const int element_block_size = V.
element()->block_size();
221 const std::uint32_t num_nodes
222 = V.
element()->space_dimension() / element_block_size;
228 std::array<std::size_t, 2> shape = {num_cells, num_nodes};
229 std::vector<std::int64_t> vtk_topology(shape[0] * shape[1]);
230 for (std::size_t c = 0; c < shape[0]; ++c)
232 auto dofs = dofmap->cell_dofs(c);
233 for (std::size_t i = 0; i < dofs.size(); ++i)
234 vtk_topology[c * shape[1] + i] = dofs[vtkmap[i]];
237 return {std::move(x),
241 std::move(vtk_topology),
259std::pair<std::vector<std::int64_t>, std::array<std::size_t, 2>>
261 md::mdspan<
const std::int32_t, md::dextents<std::size_t, 2>> dofmap_x,
Degree-of-freedom map representations and tools.
This class represents a finite element function space defined by a mesh, a finite element,...
Definition FunctionSpace.h:35
std::shared_ptr< const DofMap > dofmap() const
The dofmap.
Definition FunctionSpace.h:396
std::shared_ptr< const mesh::Mesh< geometry_type > > mesh() const
The mesh.
Definition FunctionSpace.h:371
std::shared_ptr< const FiniteElement< geometry_type > > element() const
The finite element.
Definition FunctionSpace.h:377
Geometry stores the geometry imposed on a mesh.
Definition Geometry.h:37
Finite element method functionality.
Definition assemble_expression_impl.h:24
@ standard
Standard.
Definition FiniteElement.h:29
FunctionSpace(U mesh, V element, W dofmap) -> FunctionSpace< typename std::remove_cvref< typename U::element_type >::type::geometry_type::value_type >
Type deduction.
std::vector< std::uint16_t > perm_vtk(mesh::CellType type, int num_nodes)
Permutation array to map from VTK to DOLFINx node ordering.
Definition cells.cpp:534
std::vector< std::uint16_t > transpose(std::span< const std::uint16_t > map)
Compute the transpose of a re-ordering map.
Definition cells.cpp:688
Support for file IO.
Definition ADIOS2Writers.h:43
std::tuple< std::vector< T >, std::array< std::size_t, 2 >, std::vector< std::int64_t >, std::vector< std::uint8_t >, std::vector< std::int64_t >, std::array< std::size_t, 2 > > vtk_mesh_from_space(const fem::FunctionSpace< T > &V)
Given a FunctionSpace, create a topology and geometry based on the dof coordinates.
Definition vtk_utils.h:200
std::pair< std::vector< std::int64_t >, std::array< std::size_t, 2 > > extract_vtk_connectivity(md::mdspan< const std::int32_t, md::dextents< std::size_t, 2 > > dofmap_x, mesh::CellType cell_type)
Extract the cell topology (connectivity) in VTK ordering for all cells the mesh. The 'topology' inclu...
Definition vtk_utils.cpp:23
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
CellType
Cell type identifier.
Definition cell_types.h:22
Top-level namespace.
Definition defines.h:12