14#include <dolfinx/common/IndexMap.h>
15#include <dolfinx/common/log.h>
16#include <dolfinx/common/utils.h>
17#include <dolfinx/graph/AdjacencyList.h>
18#include <dolfinx/graph/partition.h>
19#include <dolfinx/io/cells.h>
49 template <std::convertible_to<std::vector<std::
int32_t>> U,
50 std::convertible_to<std::vector<T>> V>
53 _values(std::forward<V>(
values))
55 if (_indices.size() != _values.size())
57 throw std::runtime_error(
58 "Indices and values arrays must have same size.");
61 if (!std::is_sorted(_indices.begin(), _indices.end()))
62 throw std::runtime_error(
"MeshTag data is not sorted");
63 if (std::adjacent_find(_indices.begin(), _indices.end()) != _indices.end())
64 throw std::runtime_error(
"MeshTag data has duplicates");
86 std::vector<std::int32_t>
find(
const T value)
const
88 std::size_t n = std::count(_values.begin(), _values.end(), value);
89 std::vector<std::int32_t>
indices;
91 for (std::int32_t i = 0; i < _values.size(); ++i)
93 if (_values[i] == value)
101 std::span<const std::int32_t>
indices()
const {
return _indices; }
104 std::span<const T>
values()
const {
return _values; }
107 int dim()
const {
return _dim; }
110 std::shared_ptr<const Mesh>
mesh()
const {
return _mesh; }
113 std::string
name =
"mesh_tags";
117 std::shared_ptr<const Mesh> _mesh;
123 std::vector<std::int32_t> _indices;
126 std::vector<T> _values;
141 std::span<const T> values)
144 <<
"Building MeshTgas object from tagged entities (defined by vertices).";
150 const std::vector<std::int32_t> indices
152 if (indices.size() != values.size())
154 throw std::runtime_error(
155 "Duplicate mesh entities when building MeshTags object.");
162 auto it0 = std::lower_bound(indices_sorted.begin(), indices_sorted.end(), 0);
163 std::size_t pos0 = std::distance(indices_sorted.begin(), it0);
164 indices_sorted.erase(indices_sorted.begin(), it0);
165 values_sorted.erase(values_sorted.begin(),
166 std::next(values_sorted.begin(), pos0));
168 return MeshTags<T>(mesh, dim, std::move(indices_sorted),
169 std::move(values_sorted));
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:28
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:28
Mesh data structures and algorithms on meshes.
Definition: DofMap.h:31
MeshTags< T > create_meshtags(std::shared_ptr< const Mesh > mesh, int dim, const graph::AdjacencyList< std::int32_t > &entities, std::span< const T > values)
Create MeshTags from arrays.
Definition: MeshTags.h:139
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:1139