DOLFINx 0.10.0.0
DOLFINx C++ interface
Loading...
Searching...
No Matches
EntityMap.h
1// Copyright (C) 2025 Jørgen S. Dokken and Joseph P. Dean
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#include "Topology.h"
10#include <concepts>
11#include <dolfinx/common/IndexMap.h>
12#include <span>
13#include <vector>
14
15namespace dolfinx::mesh
16{
20{
21public:
34 template <typename U>
35 requires std::is_convertible_v<std::remove_cvref_t<U>,
36 std::vector<std::int32_t>>
37 EntityMap(std::shared_ptr<const Topology> topology,
38 std::shared_ptr<const Topology> sub_topology, int dim,
40 : _dim(dim), _topology(topology),
41 _sub_topology_to_topology(std::forward<U>(sub_topology_to_topology)),
42 _sub_topology(sub_topology)
43 {
44 auto e_imap = sub_topology->index_map(_dim);
45 if (!e_imap)
46 {
47 throw std::runtime_error(
48 "No index map for entities, call `Topology::create_entities("
49 + std::to_string(_dim) + ")");
50 }
51
52 std::size_t num_ents = e_imap->size_local() + e_imap->num_ghosts();
53 if (num_ents != _sub_topology_to_topology.size())
54 {
55 throw std::runtime_error(
56 "Size mismatch between `sub_topology_to_topology` and index map.");
57 }
58 }
59
61 EntityMap(const EntityMap& map) = default;
62
64 EntityMap(EntityMap&& map) = default;
65
66 // Destructor
67 ~EntityMap() = default;
68
72 std::size_t dim() const;
73
76 std::shared_ptr<const Topology> topology() const;
77
80 std::shared_ptr<const Topology> sub_topology() const;
81
102 std::vector<std::int32_t>
103 sub_topology_to_topology(std::span<const std::int32_t> entities,
104 bool inverse) const;
105
106private:
107 // Dimension of the entities
108 std::size_t _dim;
109
110 // A topology
111 std::shared_ptr<const Topology> _topology;
112
113 // A list of `_dim`-dimensional entities in _topology, where
114 // `_sub_topology_to_topology[i]` is the index in `_topology` of the
115 // `i`th entity in `_sub_topology`
116 std::vector<std::int32_t> _sub_topology_to_topology;
117
118 // A second topology, consisting of a subset of entities in
119 // `_topology`
120 std::shared_ptr<const Topology> _sub_topology;
121};
122} // namespace dolfinx::mesh
std::vector< std::int32_t > sub_topology_to_topology(std::span< const std::int32_t > entities, bool inverse) const
Map entities between the sub-topology and the parent topology.
Definition EntityMap.cpp:30
EntityMap(EntityMap &&map)=default
Move constructor.
std::size_t dim() const
Get the topological dimension of the entities related by this EntityMap.
Definition EntityMap.cpp:17
EntityMap(std::shared_ptr< const Topology > topology, std::shared_ptr< const Topology > sub_topology, int dim, U &&sub_topology_to_topology)
Constructor of a bidirectional map relating entities of dimension dim in topology and sub_topology.
Definition EntityMap.h:37
EntityMap(const EntityMap &map)=default
Copy constructor.
std::shared_ptr< const Topology > sub_topology() const
Get the sub-topology.
Definition EntityMap.cpp:24
std::shared_ptr< const Topology > topology() const
Get the (parent) topology.
Definition EntityMap.cpp:19
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32