Wildmeshing Toolkit
Loading...
Searching...
No Matches
Mesh.cpp
Go to the documentation of this file.
1#include "Mesh.hpp"
2#include <numeric>
3
7
8#include "EdgeMesh.hpp"
9#include "PointMesh.hpp"
10#include "TetMesh.hpp"
11#include "TriMesh.hpp"
12
13#include "Primitive.hpp"
14
15namespace wmtk {
16
17
18std::vector<Tuple> Mesh::get_all(PrimitiveType type) const
19{
20 return get_all(type, false);
21}
22
23std::vector<simplex::IdSimplex> Mesh::get_all_id_simplex(PrimitiveType type) const
24{
25 return get_all_id_simplex(type, false);
26}
27
29{
30 return simplex::IdSimplex(pt, id(tuple, pt));
31}
32
37
39{
40 const Tuple& t = tuple_from_id(s.primitive_type(), s.index());
41 return simplex::Simplex(*this, s.primitive_type(), t);
42}
43
48
49std::vector<simplex::IdSimplex> Mesh::get_all_id_simplex(
50 PrimitiveType type,
51 const bool include_deleted) const
52{
53 std::vector<simplex::IdSimplex> ret;
54
55 if (static_cast<int8_t>(type) > top_cell_dimension()) return ret;
56
57 const int64_t cap = capacity(type);
58
59 const attribute::FlagAccessor<> flag_accessor = get_flag_accessor(type);
60 const attribute::IndexFlagAccessor<>& flag_accessor_indices = flag_accessor.index_access();
61 ret.reserve(cap);
62 for (size_t index = 0; index < cap; ++index) {
63 if (flag_accessor_indices.is_active(index))
64 ret.emplace_back(simplex::IdSimplex(type, index));
65 else if (include_deleted)
66 ret.emplace_back();
67 }
68 return ret;
69}
70
71
72std::vector<Tuple> Mesh::get_all(PrimitiveType type, const bool include_deleted) const
73{
74 std::vector<Tuple> ret;
75
76 if (static_cast<int8_t>(type) > top_cell_dimension()) return ret;
77
78 const int64_t cap = capacity(type);
79
80 const attribute::FlagAccessor<> flag_accessor = get_flag_accessor(type);
81 const attribute::IndexFlagAccessor<>& flag_accessor_indices = flag_accessor.index_access();
82 ret.reserve(cap);
83 for (size_t index = 0; index < cap; ++index) {
84 if (flag_accessor_indices.is_active(index)) {
85 ret.emplace_back(tuple_from_id(type, index));
86 } else if (include_deleted) {
87 ret.emplace_back();
88 }
89 }
90 return ret;
91}
92
93void Mesh::serialize(MeshWriter& writer, const Mesh* local_root) const
94{
95 if (local_root == nullptr) {
97 } else {
98 writer.write_absolute_id(m_multi_mesh_manager.relative_id(*this, *local_root));
99 }
102
103 m_multi_mesh_manager.serialize(writer, local_root);
104}
105
106
108{
109 return is_boundary(s.primitive_type(), s.tuple());
110}
111
112
113bool Mesh::is_valid(const Tuple& tuple) const
114{
115 return !tuple.is_null() && !is_removed(tuple);
116}
117
118bool Mesh::is_removed(const Tuple& tuple) const
119{
120 return is_removed(tuple.global_cid());
121}
122bool Mesh::is_removed(const Tuple& t, PrimitiveType pt) const
123{
124 if (!is_removed(t)) {
125 return is_removed(id(t, pt), pt);
126 } else {
127 return false;
128 }
129}
131{
132 return simplex::NavigatableSimplex(pt, tuple_from_id(pt, gid), gid);
133}
134bool Mesh::is_removed(int64_t index) const
135{
136 return is_removed(index, top_simplex_type());
137}
138bool Mesh::is_removed(int64_t index, PrimitiveType pt) const
139{
140 const auto& flag_accessor = get_const_flag_accessor(pt);
141 return !flag_accessor.index_access().is_active(index);
142}
143
145{
146#if defined(WMTK_ENABLE_SIMPLEX_ID_CACHING)
147 if (!is_valid(s.tuple())) {
148 return false;
149 } else {
150 const int64_t id_tuple = id(s.tuple(), s.primitive_type());
151 return id_tuple == s.m_index;
152 }
153#else
154 return is_valid(s.tuple()) && !is_removed(s.tuple(), s.primitive_type());
155#endif
156}
157
158
173
174
176{
177 for (int64_t dim = 0; dim < m_attribute_manager.m_capacities.size(); ++dim) {
178 attribute::Accessor<char> flag_accessor = create_accessor<char>(m_flag_handles[dim]);
179 m_attribute_manager.m_capacities[dim] = flag_accessor.reserved_size();
180 }
181}
182
183bool Mesh::operator==(const Mesh& other) const
184{
186}
187
188
189std::vector<std::vector<int64_t>> Mesh::simplices_to_gids(
190 const std::vector<std::vector<simplex::Simplex>>& simplices) const
191{
192 std::vector<std::vector<int64_t>> gids;
193 gids.resize(simplices.size());
194 for (int i = 0; i < simplices.size(); ++i) {
195 auto simplices_i = simplices[i];
196 for (const auto& simplex : simplices_i) {
197 int64_t d = get_primitive_type_id(simplex.primitive_type());
198 assert(d < 3);
199 gids[d].emplace_back(id(simplex.tuple(), simplex.primitive_type()));
200 }
201 }
202 return gids;
203}
204
205
207 const Tuple& tuple,
208 const std::initializer_list<PrimitiveType>& op_sequence) const
209{
210 return switch_tuples<std::initializer_list<PrimitiveType>>(tuple, op_sequence);
211}
213 const Tuple& tuple,
214 const std::initializer_list<PrimitiveType>& op_sequence) const
215{
216 return switch_tuples_unsafe<std::initializer_list<PrimitiveType>>(tuple, op_sequence);
217}
218
219
224
225} // namespace wmtk
Tuple switch_tuples_unsafe(const Tuple &tuple, const ContainerType &op_sequence) const
Definition Mesh.hpp:996
simplex::Simplex get_simplex(const simplex::IdSimplex &s) const
Convert an IdSimplex into a Simplex.
Definition Mesh.cpp:38
void serialize(MeshWriter &writer, const Mesh *local_root=nullptr) const
Definition Mesh.cpp:93
std::vector< std::vector< int64_t > > simplices_to_gids(const std::vector< std::vector< simplex::Simplex > > &simplices) const
Definition Mesh.cpp:189
const attribute::Accessor< T, Mesh, D > create_const_accessor(const attribute::MeshAttributeHandle &handle) const
int64_t capacity(PrimitiveType type) const
read in the m_capacities return the upper bound for the number of entities of the given dimension
std::vector< TypedAttributeHandle< char > > m_flag_handles
0x1 == true = simplex is active (simplex exists) all flag default to 0
Definition Mesh.hpp:850
simplex::NavigatableSimplex simplex_from_id(const PrimitiveType type, const int64_t gid) const
Definition Mesh.cpp:130
int64_t id(const Tuple &tuple, PrimitiveType type) const
return the global id of the Tuple of the given dimension
Definition Mesh.hpp:1006
bool is_boundary(const simplex::Simplex &tuple) const
check if a simplex lies on a boundary or not
Definition Mesh.cpp:107
attribute::Accessor< T, Mesh, D > create_accessor(const attribute::MeshAttributeHandle &handle)
virtual Tuple tuple_from_id(const PrimitiveType type, const int64_t gid) const =0
internal function that returns the tuple of requested type, and has the global index cid
void assert_capacity_valid() const
Definition Mesh.cpp:220
std::vector< Tuple > get_all(PrimitiveType type) const
Generate a vector of Tuples from global vertex/edge/triangle/tetrahedron index.
Definition Mesh.cpp:18
multimesh::MultiMeshManager m_multi_mesh_manager
Definition Mesh.hpp:827
std::vector< simplex::IdSimplex > get_all_id_simplex(PrimitiveType type) const
Definition Mesh.cpp:23
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
Definition Mesh.hpp:953
virtual bool is_valid(const Tuple &tuple) const
check validity of tuple including its hash
Definition Mesh.cpp:113
void set_capacities_from_flags()
Definition Mesh.cpp:175
int64_t top_cell_dimension() const
Definition Mesh.hpp:978
bool operator==(const Mesh &other) const
Definition Mesh.cpp:183
simplex::IdSimplex get_id_simplex(const Tuple &tuple, PrimitiveType pt) const
Retrieve the IdSimplex that is represented by the tuple and primitive type.
Definition Mesh.cpp:28
PrimitiveType top_simplex_type() const
Definition Mesh.hpp:982
Tuple get_tuple_from_id_simplex(const simplex::IdSimplex &s) const
Definition Mesh.cpp:44
const attribute::FlagAccessor< Mesh > get_const_flag_accessor(PrimitiveType type) const
Definition Mesh.cpp:163
bool is_removed(const Tuple &tuple) const
Definition Mesh.cpp:118
const attribute::FlagAccessor< Mesh > get_flag_accessor(PrimitiveType type) const
Definition Mesh.cpp:159
attribute::AttributeManager m_attribute_manager
Definition Mesh.hpp:825
virtual void write_top_simplex_type(const PrimitiveType type)=0
virtual void write_absolute_id(const std::vector< int64_t > &id)=0
The Tuple is the basic navigation tool in our mesh data structure.
Definition Tuple.hpp:19
bool is_null() const
Checks if a tuple is "null". This merely implies the global index is -1.
Definition Tuple.hxx:41
int64_t global_cid() const
Definition Tuple.hxx:47
A CachingAccessor that uses tuples for accessing attributes instead of indices.
Definition Accessor.hpp:28
void serialize(MeshWriter &writer) const
const IndexBaseType & index_access() const
std::vector< int64_t > absolute_id() const
void serialize(MeshWriter &writer, const Mesh *local_root=nullptr) const
static std::vector< int64_t > relative_id(const std::vector< int64_t > &parent, const std::vector< int64_t > &child)
PrimitiveType primitive_type() const
Definition IdSimplex.hpp:23
int64_t index() const
Definition IdSimplex.hpp:30
const Tuple & tuple() const
Definition Simplex.hpp:53
PrimitiveType primitive_type() const
Definition Simplex.hpp:51
constexpr int8_t get_primitive_type_id(PrimitiveType t)
Get a unique integer id corresponding to each primitive type.