Wildmeshing Toolkit
Loading...
Searching...
No Matches
TopDimensionCofacesIterable.cpp
Go to the documentation of this file.
2
3namespace wmtk::simplex {
4
5
7 const Mesh& mesh,
8 const Simplex& simplex,
9 const bool retrieve_intermediate_tuple)
10 : m_mesh(mesh)
11 , m_simplex(simplex)
12 , m_retrieve_intermediate_tuple(retrieve_intermediate_tuple)
13{}
14
17 const Tuple& t)
18 : m_container(container)
19 , m_t(t)
20 , m_phase(IteratorPhase::Forward)
21{
22 if (m_t.is_null()) {
23 return;
24 }
25
26 init(depth());
27}
28
30{
31 switch (depth()) {
32 case 0: return step_depth_0();
33 case 1: return step_depth_1();
34 case 2: return step_depth_2();
35 case 3: return step_depth_3();
36 default: break;
37 }
38
39 assert(false); // unknown simplex or mesh type
40 m_t = Tuple();
41 return *this;
42}
43
45{
46 return m_t != other.m_t;
47}
48
53
55{
56 return m_t;
57}
58
60{
61 return get_primitive_type_from_id(m_container.m_mesh.top_cell_dimension() - depth);
62}
63
65{
66 const Mesh& mesh = m_container.m_mesh;
67 const simplex::Simplex& simplex = m_container.m_simplex;
68 assert(mesh.top_cell_dimension() >= get_primitive_type_id(simplex.primitive_type()));
69 assert(mesh.top_cell_dimension() - get_primitive_type_id(simplex.primitive_type()) < 4);
70
72}
73
75{
76 const Mesh& mesh = m_container.m_mesh;
77 const simplex::Simplex& simplex = m_container.m_simplex;
78 // No initialization necessary if simplex is d or d-1.
79
80 if (depth == 2) {
81 // d - 2 --> iteration
82
83 // check if forward or backward phase can be executed
84 if (mesh.is_boundary(pt(1), m_t)) {
86 }
87 } else if (depth == 3) {
88 // d - 3 --> BFS
89 m_container.m_visited.is_visited(m_t.global_cid());
90
91 add_neighbors_to_queue();
92 }
93}
94
100
102{
103 const Mesh& mesh = m_container.m_mesh;
104 const simplex::Simplex& simplex = m_container.m_simplex;
105
106 if (m_phase == IteratorPhase::End || mesh.is_boundary(pt(1), m_t)) {
107 m_t = Tuple();
108 return *this;
109 } else {
110 m_t = mesh.switch_tuple(m_t, pt(0));
111 m_phase = IteratorPhase::End;
112 return *this;
113 }
114}
115
117{
118 const Mesh& mesh = m_container.m_mesh;
119 const simplex::Simplex& simplex = m_container.m_simplex;
120
121 m_is_intermediate = false;
122
123 if (m_phase == IteratorPhase::Intermediate) {
124 // go to opposite of input
125 m_t = mesh.switch_tuple(simplex.tuple(), pt(1));
126 if (mesh.is_boundary(pt(1), m_t)) {
127 m_phase = IteratorPhase::End;
128 } else {
129 // switch to backward phase
130 m_phase = IteratorPhase::Backward;
131 }
132 if (m_container.m_retrieve_intermediate_tuple) {
133 m_is_intermediate = true;
134 return *this;
135 }
136 }
137
138 if (m_phase == IteratorPhase::End) {
139 m_t = Tuple();
140 return *this;
141 }
142
143 m_t = mesh.switch_tuples(m_t, {pt(0), pt(1)});
144
145 if (m_t == simplex.tuple()) {
146 m_t = Tuple();
147 return *this;
148 }
149
150 if (mesh.is_boundary(pt(1), m_t)) {
151 if (m_phase == IteratorPhase::Forward) {
153 } else {
154 m_phase = IteratorPhase::End;
155 }
156 }
157
158 return *this;
159}
160
162{
163 const Mesh& mesh = m_container.m_mesh;
164 auto& q = m_container.m_q;
165 auto& q_front = m_container.m_q_front;
166
167 if (q_front == q.size()) {
168 m_t = Tuple();
169 return *this;
170 }
171
172 m_t = q[q_front++];
173
174 add_neighbors_to_queue();
175
176
177 return *this;
178}
179
181{
182 const Mesh& mesh = m_container.m_mesh;
183 const simplex::Simplex& simplex = m_container.m_simplex;
184
186 assert(simplex.primitive_type() == PrimitiveType::Vertex);
187
188 Tuple t = m_t;
189 for (size_t i = 0; i < 3; ++i) {
190 if (!mesh.is_boundary(PrimitiveType::Triangle, t)) {
191 const Tuple neigh = mesh.switch_tuple(t, PrimitiveType::Tetrahedron);
192 const int64_t neigh_id = neigh.global_cid();
193
194 if (!m_container.m_visited.is_visited(neigh_id)) {
195 m_container.m_q.emplace_back(neigh);
196 }
197 }
199 }
200}
201
203{
204 return m_is_intermediate;
205}
206
207} // namespace wmtk::simplex
bool is_boundary(const simplex::Simplex &tuple) const
check if a simplex lies on a boundary or not
Definition Mesh.cpp:107
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
Definition Mesh.hpp:953
int64_t top_cell_dimension() const
Definition Mesh.hpp:978
virtual Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const =0
switch the orientation of the Tuple of the given dimension
PrimitiveType top_simplex_type() const
Definition Mesh.hpp:982
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
const Tuple & tuple() const
Definition Simplex.hpp:53
PrimitiveType primitive_type() const
Definition Simplex.hpp:51
Iterator & step_depth_1()
There are at max two d-simplices.
PrimitiveType pt(int64_t depth) const
Get the d - depth primitive type.
Iterator & step_depth_0()
Just return the simplex and stop.
int64_t depth()
Compute the depth from the mesh and the simplex type.
Iterator(TopDimensionCofacesIterable &container, const Tuple &t=Tuple())
void init(int64_t depth)
Depending on the depth, the iterator must be initialized differently.
Iterator & step_depth_2()
Iterate around simplex to find all d-simplices.
Iterator & step_depth_3()
Use breadth first search to find all d-simplices.
Iterating through the d-simplices of a mesh can be done in different ways, depending on the simplex d...
IteratorPhase
The IteratorPhase is only used for depth 1 and 2.
TopDimensionCofacesIterable(const Mesh &mesh, const Simplex &simplex, const bool retrieve_intermediate_tuple=false)
constexpr PrimitiveType get_primitive_type_from_id(int8_t id)
Get the primitive type corresponding to its unique integer id.
constexpr int8_t get_primitive_type_id(PrimitiveType t)
Get a unique integer id corresponding to each primitive type.