13 #include <dolfinx/common/IndexMap.h>
14 #include <dolfinx/common/log.h>
15 #include <dolfinx/common/utils.h>
16 #include <dolfinx/graph/AdjacencyList.h>
17 #include <dolfinx/graph/partition.h>
18 #include <dolfinx/io/cells.h>
46 template <
typename U,
typename V>
50 _values(std::forward<V>(
values))
52 if (_indices.size() != _values.size())
54 throw std::runtime_error(
55 "Indices and values arrays must have same size.");
58 if (!std::is_sorted(_indices.begin(), _indices.end()))
59 throw std::runtime_error(
"MeshTag data is not sorted");
60 if (std::adjacent_find(_indices.begin(), _indices.end()) != _indices.end())
61 throw std::runtime_error(
"MeshTag data has duplicates");
83 std::vector<std::int32_t>
find(
const T value)
const
85 int n = std::count(_values.begin(), _values.end(), value);
86 std::vector<std::int32_t>
indices(n);
88 for (std::int32_t i = 0; i < _values.size(); ++i)
90 if (_values[i] == value)
91 indices[counter++] = _indices[i];
98 const std::vector<std::int32_t>&
indices()
const {
return _indices; }
101 const std::vector<T>&
values()
const {
return _values; }
104 int dim()
const {
return _dim; }
107 std::shared_ptr<const Mesh>
mesh()
const {
return _mesh; }
110 std::string
name =
"mesh_tags";
114 std::shared_ptr<const Mesh> _mesh;
120 std::vector<std::int32_t> _indices;
123 std::vector<T> _values;
135 template <
typename T>
138 const std::span<const T>& values)
141 <<
"Building MeshTgas object from tagged entities (defined by vertices).";
147 const std::vector<std::int32_t> indices
149 if (indices.size() != values.size())
151 throw std::runtime_error(
152 "Duplicate mesh entities when building MeshTags object.");
159 auto it0 = std::lower_bound(indices_sorted.begin(), indices_sorted.end(), 0);
160 std::size_t pos0 = std::distance(indices_sorted.begin(), it0);
161 indices_sorted.erase(indices_sorted.begin(), it0);
162 values_sorted.erase(values_sorted.begin(),
163 std::next(values_sorted.begin(), pos0));
165 return MeshTags<T>(mesh, dim, std::move(indices_sorted),
166 std::move(values_sorted));
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:26
std::pair< std::vector< typename U::value_type >, std::vector< typename V::value_type > > sort_unique(const U &indices, const V &values)
Sort two arrays based on the values in array indices. Any duplicate indices and the corresponding val...
Definition: utils.h:39
Mesh data structures and algorithms on meshes.
Definition: DofMap.h:30
std::vector< std::int32_t > entities_to_index(const Topology &topology, int dim, const graph::AdjacencyList< std::int32_t > &entities)
Get entity indices for entities defined by their vertices.
Definition: Topology.cpp:1201
MeshTags< T > create_meshtags(const std::shared_ptr< const Mesh > &mesh, int dim, const graph::AdjacencyList< std::int32_t > &entities, const std::span< const T > &values)
Create MeshTags from arrays.
Definition: MeshTags.h:136