11#include <dolfinx/common/IndexMap.h>
12#include <dolfinx/common/log.h>
13#include <dolfinx/common/utils.h>
14#include <dolfinx/graph/AdjacencyList.h>
15#include <dolfinx/io/cells.h>
45 template <
typename U,
typename V>
46 requires std::is_convertible_v<std::remove_cvref_t<U>,
47 std::vector<std::int32_t>>
48 and std::is_convertible_v<std::remove_cvref_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 Topology>
topology()
const {
return _topology; }
113 std::string
name =
"mesh_tags";
117 std::shared_ptr<const Topology> _topology;
123 std::vector<std::int32_t> _indices;
126 std::vector<T> _values;
140 std::span<const T> values)
143 <<
"Building MeshTags object from tagged entities (defined by vertices).";
148 const std::vector<std::int32_t> indices
150 if (indices.size() != values.size())
152 throw std::runtime_error(
153 "Duplicate mesh entities when building MeshTags object.");
160 auto it0 = std::lower_bound(indices_sorted.begin(), indices_sorted.end(), 0);
161 std::size_t pos0 = std::distance(indices_sorted.begin(), it0);
162 indices_sorted.erase(indices_sorted.begin(), it0);
163 values_sorted.erase(values_sorted.begin(),
164 std::next(values_sorted.begin(), pos0));
166 return MeshTags<T>(topology, dim, std::move(indices_sorted),
167 std::move(values_sorted));
Definition AdjacencyList.h:28
const std::vector< T > & array() const
Return contiguous array of links for all nodes (const version)
Definition AdjacencyList.h:129
std::pair< std::vector< typename U::value_type >, std::vector< typename V::value_type > > sort_unique(const U &indices, const V &values)
Definition utils.h:28
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
MeshTags< T > create_meshtags(std::shared_ptr< const Topology > topology, int dim, const graph::AdjacencyList< std::int32_t > &entities, std::span< const T > values)
Create MeshTags from arrays.
Definition MeshTags.h:138
std::vector< std::int32_t > entities_to_index(const Topology &topology, int dim, std::span< const std::int32_t > entities)
Get entity indices for entities defined by their vertices.
Definition Topology.cpp:1430