Wildmeshing Toolkit
LinkSingleDimensionIterable.cpp
Go to the documentation of this file.
2 
7 #include <wmtk/utils/Logger.hpp>
9 
10 namespace wmtk::simplex {
11 
12 
14  const Mesh& mesh,
15  const Simplex& simplex,
16  const PrimitiveType link_type)
17  : m_mesh(mesh)
18  , m_simplex(simplex)
19  , m_link_type(link_type)
20  , m_tdc_itrbl(mesh, simplex, link_type == PrimitiveType::Vertex)
21  , m_it_end(m_tdc_itrbl.end())
22 {}
23 
25  LinkSingleDimensionIterable& container,
26  const Tuple& t)
27  : m_container(container)
28  , m_it(container.m_tdc_itrbl, t)
29  , m_t(t)
30 {
31  if (m_t.is_null()) {
32  return;
33  }
34 
35  // check if link_type can exist
36  {
37  const Mesh& mesh = m_container.m_mesh;
38  const simplex::Simplex& simplex = m_container.m_simplex;
39  const PrimitiveType link_pt = m_container.m_link_type;
40  const int8_t m = mesh.top_cell_dimension();
41  const int8_t s = get_primitive_type_id(simplex.primitive_type());
42  const int8_t l = get_primitive_type_id(link_pt);
43  if (l >= m - s) {
44  logger().warn("Trying to retrieve simplices in the link that cannot exist!");
45  m_t = Tuple();
46  return;
47  }
48  }
49 
50  init();
51 }
52 
54 {
55  if (depth() == 3) {
56  return step_depth_3();
57  }
58 
59  ++m_it;
60  m_t = navigate_to_link(*m_it);
61  return *this;
62 }
63 
65 {
66  return m_t != *other;
67 }
68 
70 {
71  return m_t;
72 }
73 
75 {
76  return m_t;
77 }
78 
80 {
81  const Mesh& mesh = m_container.m_mesh;
82  const simplex::Simplex& simplex = m_container.m_simplex;
83  assert(mesh.top_cell_dimension() >= get_primitive_type_id(simplex.primitive_type()));
84  assert(mesh.top_cell_dimension() - get_primitive_type_id(simplex.primitive_type()) < 4);
85 
86  return mesh.top_cell_dimension() - get_primitive_type_id(simplex.primitive_type());
87 }
88 
90 {
91  return m_container.m_mesh.top_cell_dimension() - 1 ==
92  get_primitive_type_id(m_container.m_link_type);
93 }
94 
96 {
97  m_t = navigate_to_link(*m_it);
98 
99  if (depth() == 3) {
100  const Mesh& mesh = m_container.m_mesh;
101  const PrimitiveType& link_type = m_container.m_link_type;
102 
103  m_container.m_visited_link.is_visited(mesh.get_id_simplex(m_t, link_type));
104  }
105 }
106 
108 {
109  const Mesh& mesh = m_container.m_mesh;
110  const PrimitiveType& link_type = m_container.m_link_type;
111  auto& visited = m_container.m_visited_link;
112 
113  if (!is_link_d1()) {
115  ++m_edge_counter;
116 
117  while (!m_t.is_null()) {
118  for (; m_edge_counter < 3; ++m_edge_counter) {
119  if (!visited.is_visited(mesh.get_id_simplex(m_t, link_type))) {
120  return *this;
121  }
123  }
124 
125  // go to next cell
126  m_edge_counter = 0;
127  ++m_it;
128  m_t = navigate_to_link(*m_it);
129  }
130  } else {
131  ++m_it;
132  m_t = navigate_to_link(*m_it);
133  }
134  return *this;
135 }
136 
138 {
139  if (t.is_null()) {
140  return t;
141  }
142  // invert the simplex using SimplexDart
143  const Mesh& mesh = m_container.m_mesh;
144  // const PrimitiveType& mesh_pt = mesh.top_simplex_type();
145  // autogen::SimplexDart sd(mesh_pt);
146 
147  // switch (mesh.top_simplex_type()) {
148  // case PrimitiveType::Triangle: {
149  // const int8_t index_switch = sd.product(
150  // sd.primitive_as_index(PrimitiveType::Edge),
151  // sd.primitive_as_index(PrimitiveType::Vertex));
152  // m_t = autogen::local_switch_tuple(mesh_pt, m_t, index_switch);
153  // break;
154  // }
155  // default: log_and_throw_error("missing mesh navigation in link"); break;
156  // }
157 
158  {
159  /*
160  * Assume a tuple that contains the vertices (a,b,c,d) and the simplex is an edge, i.e.,
161  * (a,b). The link contains all the vertices that are not in the simplex. To get a tuple
162  * that represents all simplices of the link, we need to move (a,b) to the end of that
163  * tuple.
164  * (a,b,c,d) becomes (c,d,a,b) with the following permutations
165  * (a,b,c,d)
166  * switch edge: (a,c,b,d)
167  * switch face: (a,c,d,b)
168  * switch vert: (c,a,d,b)
169  * switch edge: (c,d,a,b)
170  *
171  * The following code implements these permutations.
172  */
173  const simplex::Simplex& simplex = m_container.m_simplex;
174  const PrimitiveType link_pt = m_container.m_link_type;
175  const int8_t m = mesh.top_cell_dimension();
176  const int8_t s = get_primitive_type_id(simplex.primitive_type());
177 
178  for (int8_t j = s; j > -1; --j) {
179  for (int8_t i = 0; i < m - s; ++i) {
180  t = mesh.switch_tuple(t, get_primitive_type_from_id(j + i));
181  }
182  }
183  }
184 
185  return t;
186 }
187 
188 } // namespace wmtk::simplex
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
Definition: Mesh.hpp:968
int64_t top_cell_dimension() const
Definition: Mesh.hpp:993
virtual Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const =0
switch the orientation of the Tuple of the given dimension
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
bool is_null() const
Checks if a tuple is "null". This merely implies the global index is -1.
Definition: Tuple.hxx:40
PrimitiveType primitive_type() const
Definition: Simplex.hpp:51
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.
spdlog::logger & logger()
Retrieves the current logger.
Definition: Logger.cpp:58