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>
62 template <
typename U,
typename V,
typename W>
63 requires std::is_convertible_v<std::remove_cvref_t<U>,
64 std::vector<std::vector<std::int32_t>>>
65 and std::is_convertible_v<std::remove_cvref_t<V>,
67 and std::is_convertible_v<std::remove_cvref_t<W>,
68 std::vector<std::int64_t>>
70 std::shared_ptr<const common::IndexMap>
index_map, U&& dofmaps,
72 typename std::remove_reference_t<typename V::value_type>>>& elements,
74 : _dim(
dim), _dofmaps(std::forward<U>(dofmaps)),
75 _index_map(std::move(
index_map)), _cmaps(elements),
76 _x(std::forward<V>(
x)),
79 assert(_x.size() % 3 == 0);
80 if (_x.size() / 3 != _input_global_indices.size())
81 throw std::runtime_error(
"Geometry size mismatch.");
83 if (_dofmaps.size() != _cmaps.size())
85 throw std::runtime_error(
"Geometry number of dofmaps not equal to the "
86 "number of coordinate elements.");
108 int dim()
const {
return _dim; }
112 md::mdspan<const std::int32_t, md::dextents<std::size_t, 2>>
dofmap()
const
114 if (_dofmaps.size() != 1)
115 throw std::runtime_error(
"Multiple dofmaps");
125 md::mdspan<const std::int32_t, md::dextents<std::size_t, 2>>
128 std::size_t ndofs = _cmaps.at(i).dim();
129 return md::mdspan<const std::int32_t, md::dextents<std::size_t, 2>>(
130 _dofmaps.at(i).data(), _dofmaps.at(i).size() / ndofs, ndofs);
135 std::shared_ptr<const common::IndexMap>
index_map()
const
144 std::span<const value_type>
x()
const {
return _x; }
151 std::span<value_type>
x() {
return _x; }
160 = std::nullopt)
const
163 return _cmaps.at(*i);
164 else if (_cmaps.size() > 1)
165 throw std::runtime_error(
"Multiple cmaps.");
166 return _cmaps.front();
173 std::size_t
num_maps()
const {
return _cmaps.size(); }
178 return _input_global_indices;
186 std::vector<std::vector<std::int32_t>> _dofmaps;
189 std::shared_ptr<const common::IndexMap> _index_map;
192 std::vector<fem::CoordinateElement<value_type>> _cmaps;
196 std::vector<value_type> _x;
199 std::vector<std::int64_t> _input_global_indices;
204template <
typename U,
typename V,
typename W>
205Geometry(std::shared_ptr<const common::IndexMap>, U&&,
207 typename std::remove_reference_t<typename V::value_type>>>&,
209 -> Geometry<typename std::remove_cvref_t<typename V::value_type>>;
237Geometry<typename std::remove_reference_t<typename U::value_type>>
240 std::remove_reference_t<typename U::value_type>>>& elements,
241 std::span<const std::int64_t> nodes,
242 std::span<const std::int64_t> xdofs,
const U& x,
int dim,
243 const std::function<std::vector<int>(
247 spdlog::info(
"Create Geometry (multiple)");
249 assert(std::ranges::is_sorted(nodes));
250 using T =
typename std::remove_reference_t<typename U::value_type>;
253 const int tdim = topology.
dim();
254 const std::size_t num_cell_types = topology.
entity_types(tdim).size();
255 if (elements.size() != num_cell_types)
256 throw std::runtime_error(
"Mismatch between topology and geometry.");
258 std::vector<fem::ElementDofLayout> dof_layouts;
259 dof_layouts.reserve(elements.size());
260 for (
auto& el : elements)
261 dof_layouts.push_back(el.create_dof_layout());
263 spdlog::info(
"Got {} dof layouts", dof_layouts.size());
266 auto [_dof_index_map, bs, dofmaps]
268 topology, dof_layouts, reorder_fn);
270 = std::make_shared<common::IndexMap>(std::move(_dof_index_map));
273 if (elements.front().needs_dof_permutations())
275 const std::int32_t num_cells
277 const std::vector<std::uint32_t>& cell_info
279 int d = elements.front().dim();
280 for (std::int32_t cell = 0; cell < num_cells; ++cell)
282 std::span dofs(dofmaps.front().data() + cell * d, d);
283 elements.front().permute_inv(dofs, cell_info[cell]);
287 spdlog::info(
"Calling compute_local_to_global");
294 spdlog::info(
"xdofs.size = {}", xdofs.size());
295 std::vector<std::int32_t> all_dofmaps;
297 for (
auto q : dofmaps)
299 s << q.size() <<
" ";
300 all_dofmaps.insert(all_dofmaps.end(), q.begin(), q.end());
302 spdlog::info(
"dofmap sizes = {}", s.str());
303 spdlog::info(
"all_dofmaps.size = {}", all_dofmaps.size());
304 spdlog::info(
"nodes.size = {}", nodes.size());
310 std::vector<std::int64_t> igi(nodes.size());
311 std::ranges::transform(l2l, igi.begin(),
312 [&nodes](
auto index) { return nodes[index]; });
315 assert(x.size() % dim == 0);
316 const std::size_t shape0 = x.size() / dim;
317 const std::size_t shape1 = dim;
318 std::vector<T> xg(3 * shape0, 0);
319 for (std::size_t i = 0; i < shape0; ++i)
321 std::copy_n(std::next(x.begin(), shape1 * l2l[i]), shape1,
322 std::next(xg.begin(), 3 * i));
325 spdlog::info(
"Creating geometry with {} dofmaps", dof_layouts.size());
327 return Geometry(dof_index_map, std::move(dofmaps), elements, std::move(xg),
328 dim, std::move(igi));
Definition CoordinateElement.h:38
This class provides a static adjacency list data structure.
Definition AdjacencyList.h:38
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:151
md::mdspan< const std::int32_t, md::dextents< std::size_t, 2 > > dofmap(std::size_t i) const
Degree-of-freedom map associated with the ith coordinate map element in the geometry.
Definition Geometry.h:126
std::size_t num_maps() const
Number of coordinate maps and dofmaps (which must be the same) in the geometry, when consisting of di...
Definition Geometry.h:173
const fem::CoordinateElement< value_type > & cmap(std::optional< int > i=std::nullopt) const
The elements that describes the geometry map.
Definition Geometry.h:159
std::shared_ptr< const common::IndexMap > index_map() const
Index map for the geometry 'degrees-of-freedom'.
Definition Geometry.h:135
Geometry(Geometry &&)=default
Move constructor.
Geometry(const Geometry &)=default
Copy constructor.
int dim() const
Return dimension of the Euclidean coordinate system.
Definition Geometry.h:108
Geometry & operator=(Geometry &&)=default
Move assignment.
Geometry(std::shared_ptr< const common::IndexMap > index_map, U &&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:69
md::mdspan< const std::int32_t, md::dextents< std::size_t, 2 > > dofmap() const
DofMap for the geometry.
Definition Geometry.h:112
const std::vector< std::int64_t > & input_global_indices() const
Global user indices.
Definition Geometry.h:176
std::span< const value_type > x() const
Access geometry degrees-of-freedom data (const version).
Definition Geometry.h:144
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:49
const std::vector< std::uint32_t > & get_cell_permutation_info() const
Returns the permutation information.
Definition Topology.cpp:885
std::shared_ptr< const graph::AdjacencyList< std::int32_t > > connectivity(std::array< int, 2 > d0, std::array< int, 2 > d1) const
Get the connectivity from entities of topological dimension d0 to dimension d1.
Definition Topology.cpp:865
const std::vector< CellType > & entity_types(int dim) const
Entity types in the topology for a given dimension.
Definition Topology.cpp:808
int dim() const noexcept
Topological dimension of the mesh.
Definition Topology.cpp:803
std::vector< std::shared_ptr< const common::IndexMap > > index_maps(int dim) const
Get the index maps that described the parallel distribution of the mesh entities of a given topologic...
Definition Topology.cpp:831
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:643
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:542
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:564
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, const std::function< std::vector< int >(const graph::AdjacencyList< std::int32_t > &)> &reorder_fn=nullptr)
Build Geometry from input data.
Definition Geometry.h:238