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 const bool null = tuple.is_null();
116 if (null) {
117 logger().trace("Tuple was null and therefore invalid");
118 return false;
119 } else if (is_removed(tuple)) {
120 logger().trace("Tuple was removed and therefore invalid");
121 return false;
122 }
123 return true;
124}
125
126bool Mesh::is_removed(const Tuple& tuple) const
127{
128 return is_removed(tuple.global_cid());
129}
130bool Mesh::is_removed(const Tuple& t, PrimitiveType pt) const
131{
132 if (!is_removed(t)) {
133 return is_removed(id(t, pt), pt);
134 } else {
135 return false;
136 }
137}
139{
140 return simplex::NavigatableSimplex(pt, tuple_from_id(pt, gid), gid);
141}
142bool Mesh::is_removed(int64_t index) const
143{
144 return is_removed(index, top_simplex_type());
145}
146bool Mesh::is_removed(int64_t index, PrimitiveType pt) const
147{
148 const auto& flag_accessor = get_const_flag_accessor(pt);
149 return !flag_accessor.index_access().is_active(index);
150}
151
153{
154#if defined(WMTK_ENABLE_SIMPLEX_ID_CACHING)
155 if (!is_valid(s.tuple())) {
156 return false;
157 } else {
158 const int64_t id_tuple = id(s.tuple(), s.primitive_type());
159 return id_tuple == s.m_index;
160 }
161#else
162 return is_valid(s.tuple()) && !is_removed(s.tuple(), s.primitive_type());
163#endif
164}
165
180
181
183{
184 for (int64_t dim = 0; dim < m_attribute_manager.m_capacities.size(); ++dim) {
185 attribute::Accessor<char> flag_accessor = create_accessor<char>(m_flag_handles[dim]);
186 m_attribute_manager.m_capacities[dim] = flag_accessor.reserved_size();
187 }
188}
189
190bool Mesh::operator==(const Mesh& other) const
191{
193}
194
195
196std::vector<std::vector<int64_t>> Mesh::simplices_to_gids(
197 const std::vector<std::vector<simplex::Simplex>>& simplices) const
198{
199 std::vector<std::vector<int64_t>> gids;
200 gids.resize(simplices.size());
201 for (int i = 0; i < simplices.size(); ++i) {
202 auto simplices_i = simplices[i];
203 for (const auto& simplex : simplices_i) {
204 int64_t d = get_primitive_type_id(simplex.primitive_type());
205 assert(d < 3);
206 gids[d].emplace_back(id(simplex.tuple(), simplex.primitive_type()));
207 }
208 }
209 return gids;
210}
211
212
214 const Tuple& tuple,
215 const std::initializer_list<PrimitiveType>& op_sequence) const
216{
217 return switch_tuples<std::initializer_list<PrimitiveType>>(tuple, op_sequence);
218}
220 const Tuple& tuple,
221 const std::initializer_list<PrimitiveType>& op_sequence) const
222{
223 return switch_tuples_unsafe<std::initializer_list<PrimitiveType>>(tuple, op_sequence);
224}
225
226
231
232} // namespace wmtk
Tuple switch_tuples_unsafe(const Tuple &tuple, const ContainerType &op_sequence) const
Definition Mesh.hpp:994
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:196
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:852
simplex::NavigatableSimplex simplex_from_id(const PrimitiveType type, const int64_t gid) const
Definition Mesh.cpp:138
const attribute::Accessor< T, Mesh, attribute::CachingAttribute< T >, D > create_const_accessor(const attribute::MeshAttributeHandle &handle) const
int64_t id(const Tuple &tuple, PrimitiveType type) const
return the global id of the Tuple of the given dimension
Definition Mesh.hpp:1010
bool is_boundary(const simplex::Simplex &tuple) const
check if a simplex lies on a boundary or not
Definition Mesh.cpp:107
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:227
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:829
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:951
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:182
int64_t top_cell_dimension() const
Definition Mesh.hpp:976
bool operator==(const Mesh &other) const
Definition Mesh.cpp:190
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:980
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:170
attribute::Accessor< T, Mesh, attribute::CachingAttribute< T >, D > create_accessor(const attribute::MeshAttributeHandle &handle)
bool is_removed(const Tuple &tuple) const
Definition Mesh.cpp:126
const attribute::FlagAccessor< Mesh > get_flag_accessor(PrimitiveType type) const
Definition Mesh.cpp:166
attribute::AttributeManager m_attribute_manager
Definition Mesh.hpp:827
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
An Accessor that uses tuples for accessing attributes instead of indices.
Definition Accessor.hpp:44
auto reserved_size() const -> int64_t
Definition Accessor.hxx:141
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.
spdlog::logger & logger()
Retrieves the current logger.
Definition Logger.cpp:58