11#include <basix/mdspan.hpp>
14#include <dolfinx/common/IndexMap.h>
15#include <dolfinx/common/MPI.h>
16#include <dolfinx/common/sort.h>
17#include <dolfinx/fem/CoordinateElement.h>
18#include <dolfinx/fem/ElementDofLayout.h>
19#include <dolfinx/fem/dofmapbuilder.h>
20#include <dolfinx/graph/AdjacencyList.h>
21#include <dolfinx/graph/partition.h>
32template <std::
floating_po
int T>
50 template <
typename U,
typename V,
typename W>
51 requires std::is_convertible_v<std::remove_cvref_t<U>,
52 std::vector<std::int32_t>>
53 and std::is_convertible_v<std::remove_cvref_t<V>,
55 and std::is_convertible_v<std::remove_cvref_t<W>,
56 std::vector<std::int64_t>>
60 typename std::remove_reference_t<typename V::value_type>>& element,
63 _x(std::forward<V>(
x)),
66 assert(_x.size() % 3 == 0);
67 if (_x.size() / 3 != _input_global_indices.size())
68 throw std::runtime_error(
"Geometry size mis-match");
82 template <
typename V,
typename W>
83 requires std::is_convertible_v<std::remove_cvref_t<V>, std::vector<T>>
84 and std::is_convertible_v<std::remove_cvref_t<W>,
85 std::vector<std::int64_t>>
87 std::shared_ptr<const common::IndexMap>
index_map,
88 const std::vector<std::vector<std::int32_t>>& dofmaps,
90 typename std::remove_reference_t<typename V::value_type>>>& elements,
92 : _dim(
dim), _dofmaps(dofmaps), _index_map(
index_map), _cmaps(elements),
93 _x(std::forward<V>(
x)),
96 assert(_x.size() % 3 == 0);
97 if (_x.size() / 3 != _input_global_indices.size())
98 throw std::runtime_error(
"Geometry size mis-match");
117 int dim()
const {
return _dim; }
121 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
123 MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>
126 if (_dofmaps.size() != 1)
127 throw std::runtime_error(
"Multiple dofmaps");
129 int ndofs = _cmaps.front().dim();
130 return MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
132 MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>(
133 _dofmaps.front().data(), _dofmaps.front().size() / ndofs, ndofs);
140 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
142 MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>
145 if (i < 0 or i >= (
int)_dofmaps.size())
147 throw std::out_of_range(
"Cannot get dofmap:" + std::to_string(i)
150 int ndofs = _cmaps[i].dim();
152 return MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
154 MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>(
155 _dofmaps[i].data(), _dofmaps[i].size() / ndofs, ndofs);
160 std::shared_ptr<const common::IndexMap>
index_map()
const
169 std::span<const value_type>
x()
const {
return _x; }
176 std::span<value_type>
x() {
return _x; }
183 if (_cmaps.size() != 1)
184 throw std::runtime_error(
"Multiple cmaps.");
185 return _cmaps.front();
193 if (i < 0 or i >= (
int)_cmaps.size())
195 throw std::out_of_range(
"Cannot get cmap:" + std::to_string(i)
204 return _input_global_indices;
212 std::vector<std::vector<std::int32_t>> _dofmaps;
215 std::shared_ptr<const common::IndexMap> _index_map;
218 std::vector<fem::CoordinateElement<value_type>> _cmaps;
222 std::vector<value_type> _x;
225 std::vector<std::int64_t> _input_global_indices;
230template <
typename U,
typename V,
typename W>
231Geometry(std::shared_ptr<const common::IndexMap>, U,
233 typename std::remove_reference_t<typename V::value_type>>>&,
235 W) -> Geometry<typename std::remove_cvref_t<typename V::value_type>>;
263Geometry<typename std::remove_reference_t<typename U::value_type>>
267 std::remove_reference_t<typename U::value_type>>>& elements,
268 std::span<const std::int64_t> nodes, std::span<const std::int64_t> xdofs,
274 spdlog::info(
"Create Geometry (multiple)");
276 assert(std::ranges::is_sorted(nodes));
277 using T =
typename std::remove_reference_t<typename U::value_type>;
280 const int tdim = topology.
dim();
281 const std::size_t num_cell_types = topology.
entity_types(tdim).size();
282 if (elements.size() != num_cell_types)
283 throw std::runtime_error(
"Mismatch between topology and geometry.");
285 std::vector<fem::ElementDofLayout> dof_layouts;
286 for (
const auto& el : elements)
287 dof_layouts.push_back(el.create_dof_layout());
289 spdlog::info(
"Got {} dof layouts", dof_layouts.size());
292 auto [_dof_index_map, bs, dofmaps]
294 topology, dof_layouts, reorder_fn);
296 = std::make_shared<common::IndexMap>(std::move(_dof_index_map));
299 if (elements.front().needs_dof_permutations())
301 const std::int32_t num_cells
303 const std::vector<std::uint32_t>& cell_info
305 int d = elements.front().dim();
306 for (std::int32_t cell = 0; cell < num_cells; ++cell)
308 std::span dofs(dofmaps.front().data() + cell * d, d);
309 elements.front().permute_inv(dofs, cell_info[cell]);
313 spdlog::info(
"Calling compute_local_to_global");
320 spdlog::info(
"xdofs.size = {}", xdofs.size());
321 std::vector<std::int32_t> all_dofmaps;
323 for (
auto q : dofmaps)
325 s << q.size() <<
" ";
326 all_dofmaps.insert(all_dofmaps.end(), q.begin(), q.end());
328 spdlog::info(
"dofmap sizes = {}", s.str());
329 spdlog::info(
"all_dofmaps.size = {}", all_dofmaps.size());
330 spdlog::info(
"nodes.size = {}", nodes.size());
336 std::vector<std::int64_t> igi(nodes.size());
337 std::ranges::transform(l2l, igi.begin(),
338 [&nodes](
auto index) { return nodes[index]; });
341 assert(x.size() % dim == 0);
342 const std::size_t shape0 = x.size() / dim;
343 const std::size_t shape1 = dim;
344 std::vector<T> xg(3 * shape0, 0);
345 for (std::size_t i = 0; i < shape0; ++i)
347 std::copy_n(std::next(x.begin(), shape1 * l2l[i]), shape1,
348 std::next(xg.begin(), 3 * i));
351 spdlog::info(
"Creating geometry with {} dofmaps", dof_layouts.size());
353 return Geometry(dof_index_map, std::move(dofmaps), elements, std::move(xg),
354 dim, std::move(igi));
381Geometry<typename std::remove_reference_t<typename U::value_type>>
385 std::remove_reference_t<typename U::value_type>>& element,
386 std::span<const std::int64_t> nodes, std::span<const std::int64_t> xdofs,
392 assert(std::ranges::is_sorted(nodes));
393 using T =
typename std::remove_reference_t<typename U::value_type>;
398 auto [_dof_index_map, bs, dofmaps]
400 topology, {dof_layout}, reorder_fn);
402 = std::make_shared<common::IndexMap>(std::move(_dof_index_map));
405 if (element.needs_dof_permutations())
407 const std::int32_t num_cells
409 const std::vector<std::uint32_t>& cell_info
411 int d = element.dim();
412 for (std::int32_t cell = 0; cell < num_cells; ++cell)
414 std::span dofs(dofmaps.front().data() + cell * d, d);
415 element.permute_inv(dofs, cell_info[cell]);
428 std::vector<std::int64_t> igi(nodes.size());
429 std::ranges::transform(l2l, igi.begin(),
430 [&nodes](
auto index) { return nodes[index]; });
433 assert(x.size() % dim == 0);
434 const std::size_t shape0 = x.size() / dim;
435 const std::size_t shape1 = dim;
436 std::vector<T> xg(3 * shape0, 0);
437 for (std::size_t i = 0; i < shape0; ++i)
439 std::copy_n(std::next(x.cbegin(), shape1 * l2l[i]), shape1,
440 std::next(xg.begin(), 3 * i));
443 return Geometry(dof_index_map, std::move(dofmaps.front()), {element},
444 std::move(xg), dim, std::move(igi));
Definition ElementDofLayout.h:30
Definition topologycomputation.h:24
Geometry stores the geometry imposed on a mesh.
Definition Geometry.h:34
~Geometry()=default
Destructor.
std::span< value_type > x()
Access geometry degrees-of-freedom data (non-const version).
Definition Geometry.h:176
Geometry(std::shared_ptr< const common::IndexMap > index_map, const std::vector< std::vector< std::int32_t > > &dofmaps, const std::vector< fem::CoordinateElement< typename std::remove_reference_t< typename V::value_type > > > &elements, V &&x, int dim, W &&input_global_indices)
Constructor of object that holds mesh geometry data.
Definition Geometry.h:86
Geometry(std::shared_ptr< const common::IndexMap > index_map, U &&dofmap, const fem::CoordinateElement< typename std::remove_reference_t< typename V::value_type > > &element, V &&x, int dim, W &&input_global_indices)
Constructor of object that holds mesh geometry data.
Definition Geometry.h:57
MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan< const std::int32_t, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents< std::size_t, 2 > > dofmap(std::int32_t i) const
The dofmap associated with the ith coordinate map in the geometry.
Definition Geometry.h:143
std::shared_ptr< const common::IndexMap > index_map() const
Index map.
Definition Geometry.h:160
Geometry(Geometry &&)=default
Move constructor.
Geometry(const Geometry &)=default
Copy constructor.
const fem::CoordinateElement< value_type > & cmap() const
The element that describes the geometry map.
Definition Geometry.h:181
int dim() const
Return dimension of the Euclidean coordinate system.
Definition Geometry.h:117
Geometry & operator=(Geometry &&)=default
Move Assignment.
MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan< const std::int32_t, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents< std::size_t, 2 > > dofmap() const
DofMap for the geometry.
Definition Geometry.h:124
const fem::CoordinateElement< value_type > & cmap(std::int32_t i) const
The element that describe the ith geometry map.
Definition Geometry.h:191
const std::vector< std::int64_t > & input_global_indices() const
Global user indices.
Definition Geometry.h:202
std::span< const value_type > x() const
Access geometry degrees-of-freedom data (const version).
Definition Geometry.h:169
Geometry & operator=(const Geometry &)=delete
Copy Assignment.
T value_type
Value type.
Definition Geometry.h:37
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition Topology.h:44
std::shared_ptr< const common::IndexMap > index_map(int dim) const
Get the IndexMap that described the parallel distribution of the mesh entities.
Definition Topology.cpp:815
std::shared_ptr< const graph::AdjacencyList< std::int32_t > > connectivity(int d0, int d1) const
Return connectivity from entities of dimension d0 to entities of dimension d1. Assumes only one entit...
Definition Topology.cpp:931
const std::vector< std::uint32_t > & get_cell_permutation_info() const
Returns the permutation information.
Definition Topology.cpp:981
std::vector< CellType > entity_types(std::int8_t dim) const
Get the entity types in the topology for a given dimension.
Definition Topology.cpp:1023
int dim() const noexcept
Return the topological dimension of the mesh.
Definition Topology.cpp:794
std::tuple< common::IndexMap, int, std::vector< std::vector< std::int32_t > > > build_dofmap_data(MPI_Comm comm, const mesh::Topology &topology, const std::vector< ElementDofLayout > &element_dof_layouts, const std::function< std::vector< int >(const graph::AdjacencyList< std::int32_t > &)> &reorder_fn)
Definition dofmapbuilder.cpp:617
std::vector< std::int64_t > compute_local_to_global(std::span< const std::int64_t > global, std::span< const std::int32_t > local)
Definition partition.cpp:534
std::vector< std::int32_t > compute_local_to_local(std::span< const std::int64_t > local0_to_global, std::span< const std::int64_t > local1_to_global)
Compute a local0-to-local1 map from two local-to-global maps with common global indices.
Definition partition.cpp:556
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
Geometry< typename std::remove_reference_t< typename U::value_type > > create_geometry(const Topology &topology, const std::vector< fem::CoordinateElement< std::remove_reference_t< typename U::value_type > > > &elements, std::span< const std::int64_t > nodes, std::span< const std::int64_t > xdofs, const U &x, int dim, std::function< std::vector< int >(const graph::AdjacencyList< std::int32_t > &)> reorder_fn=nullptr)
Build Geometry from input data.
Definition Geometry.h:264