22 void top_dimension_cofaces_tuples_vertex(
25 std::vector<Tuple>& collection)
27 assert(mesh.is_valid(t_in));
30 collection.emplace_back(t);
32 if (mesh.is_boundary_edge(t)) {
38 if (t == t_in && !mesh.is_boundary_edge(t)) {
42 t = mesh.switch_edge(t_in);
44 if (mesh.is_boundary_edge(t)) {
50 collection.emplace_back(t);
52 if (mesh.is_boundary_edge(t)) {
58 void top_dimension_cofaces_tuples_edge(
61 std::vector<Tuple>& collection)
63 collection.emplace_back(t);
64 if (!mesh.is_boundary_edge(t)) {
65 collection.emplace_back(mesh.switch_face(t));
68 void top_dimension_cofaces_tuples_face(
71 std::vector<Tuple>& collection)
73 collection.emplace_back(t);
76 void top_dimension_cofaces_tuples_vertex(
79 std::vector<Tuple>& collection)
81 std::vector<int64_t> visited;
84 auto is_visited = [&visited](
const Tuple& t) ->
bool {
86 for (
const int64_t v : visited) {
91 visited.emplace_back(c);
95 std::vector<Tuple> q(200);
100 while (q_front != q_back) {
101 const Tuple t = q[q_front++];
108 collection.emplace_back(t);
110 if (q_back + 4 >= q.size()) {
111 q.resize(q.size() * 1.5);
119 const Tuple t2 = mesh.switch_face(t);
122 if (!mesh.is_boundary_face(t1)) {
123 const Tuple ts = mesh.switch_tetrahedron(t1);
126 if (!mesh.is_boundary_face(t2)) {
127 const Tuple ts = mesh.switch_tetrahedron(t2);
130 if (!mesh.is_boundary_face(t3)) {
131 const Tuple ts = mesh.switch_tetrahedron(t3);
136 void top_dimension_cofaces_tuples_edge(
139 std::vector<Tuple>& collection)
170 assert(mesh.is_valid(
input));
173 collection.emplace_back(t);
175 if (mesh.is_boundary_face(t)) {
179 }
while (t !=
input);
181 if (t ==
input && !mesh.is_boundary_face(t)) {
187 if (mesh.is_boundary_face(mesh.switch_face(t))) {
194 collection.emplace_back(t);
196 if (mesh.is_boundary_face(mesh.switch_face(t))) {
219 void top_dimension_cofaces_tuples_face(
222 std::vector<Tuple>& collection)
224 collection.emplace_back(
input);
225 if (!mesh.is_boundary_face(
input)) {
226 collection.emplace_back(mesh.switch_tetrahedron(
input));
229 void top_dimension_cofaces_tuples_tet(
232 std::vector<Tuple>& collection)
234 collection.emplace_back(t);
237 std::vector<Tuple> top_dimension_cofaces_tuples_vertex(
const TriMesh& mesh,
const Tuple& t)
239 std::vector<Tuple> collection;
240 top_dimension_cofaces_tuples_vertex(mesh, t, collection);
243 std::vector<Tuple> top_dimension_cofaces_tuples_edge(
const TriMesh& mesh,
const Tuple& t)
245 std::vector<Tuple> collection;
246 top_dimension_cofaces_tuples_edge(mesh, t, collection);
249 std::vector<Tuple> top_dimension_cofaces_tuples_face(
const TriMesh& mesh,
const Tuple& t)
251 std::vector<Tuple> collection;
252 top_dimension_cofaces_tuples_face(mesh, t, collection);
256 std::vector<Tuple> top_dimension_cofaces_tuples_vertex(
const TetMesh& mesh,
const Tuple&
input)
258 std::vector<Tuple> collection;
259 top_dimension_cofaces_tuples_vertex(mesh,
input, collection);
262 std::vector<Tuple> top_dimension_cofaces_tuples_edge(
const TetMesh& mesh,
const Tuple&
input)
264 std::vector<Tuple> collection;
265 top_dimension_cofaces_tuples_edge(mesh,
input, collection);
268 std::vector<Tuple> top_dimension_cofaces_tuples_face(
const TetMesh& mesh,
const Tuple&
input)
270 std::vector<Tuple> collection;
271 top_dimension_cofaces_tuples_face(mesh,
input, collection);
274 std::vector<Tuple> top_dimension_cofaces_tuples_tet(
const TetMesh& mesh,
const Tuple& t)
276 std::vector<Tuple> collection;
277 top_dimension_cofaces_tuples_tet(mesh, t, collection);
287 void top_dimension_cofaces_tuples_vertex(
290 SimplexCollection& collection)
292 assert(mesh.is_valid(t_in));
293 std::set<Tuple, wmtk::utils::TupleCellLessThan> touched_cells;
297 const Tuple t = q.front();
302 const auto [it, did_insert] = touched_cells.insert(t);
309 if (!mesh.is_boundary_edge(t)) {
310 q.push(mesh.switch_tuples(t, {PrimitiveType::Triangle, PrimitiveType::Edge}));
312 const Tuple t_other = mesh.switch_edge(t);
313 if (!mesh.is_boundary_edge(t_other)) {
314 q.push(mesh.switch_face(t_other));
318 void top_dimension_cofaces_tuples_edge(
321 SimplexCollection& collection)
324 if (!mesh.is_boundary_edge(t)) {
328 void top_dimension_cofaces_tuples_face(
331 SimplexCollection& collection)
336 void top_dimension_cofaces_tuples_vertex(
339 SimplexCollection& collection)
341 std::set<Tuple, wmtk::utils::TupleCellLessThan> touched_cells;
345 const Tuple t = q.front();
350 const auto& [it, was_inserted] = touched_cells.insert(t);
359 const Tuple t2 = mesh.switch_face(t);
362 if (!mesh.is_boundary_face(t1)) {
363 q.push(mesh.switch_tetrahedron(t1));
365 if (!mesh.is_boundary_face(t2)) {
366 q.push(mesh.switch_tetrahedron(t2));
368 if (!mesh.is_boundary_face(t3)) {
369 q.push(mesh.switch_tetrahedron(t3));
373 void top_dimension_cofaces_tuples_edge(
376 SimplexCollection& collection)
378 std::set<Tuple, wmtk::utils::TupleCellLessThan> touched_cells;
382 const Tuple t = q.front();
387 const auto& [it, was_inserted] = touched_cells.insert(t);
396 const Tuple t2 = mesh.switch_face(t);
398 if (!mesh.is_boundary_face(t1)) {
399 q.push(mesh.switch_tuples(t1, {PrimitiveType::Tetrahedron, PrimitiveType::Triangle}));
401 if (!mesh.is_boundary_face(t2)) {
402 q.push(mesh.switch_tetrahedron(t2));
407 void top_dimension_cofaces_tuples_face(
410 SimplexCollection& collection)
413 if (!mesh.is_boundary_face(
input)) {
417 void top_dimension_cofaces_tuples_tet(
420 SimplexCollection& collection)
431 const bool sort_and_clean)
433 const auto& m = simplex_collection.
mesh();
435 if (sort_and_clean) {
447 collection.
add(simplex);
459 "top_dimension_cofaces_tuples not implemented for Tetrahedron in PointMesh");
460 default: assert(
false);
break;
471 collection.
add(simplex);
478 collection.
add(simplex);
485 default: assert(
false);
break;
496 top_dimension_cofaces_tuples_vertex(mesh, simplex.
tuple(), collection);
500 top_dimension_cofaces_tuples_edge(mesh, simplex.
tuple(), collection);
504 top_dimension_cofaces_tuples_face(mesh, simplex.
tuple(), collection);
508 default: assert(
false);
break;
519 top_dimension_cofaces_tuples_vertex(mesh, simplex.
tuple(), collection);
523 top_dimension_cofaces_tuples_edge(mesh, simplex.
tuple(), collection);
527 top_dimension_cofaces_tuples_face(mesh, simplex.
tuple(), collection);
531 top_dimension_cofaces_tuples_tet(mesh, simplex.
tuple(), collection);
534 default: assert(
false);
break;
564 std::vector<Tuple>& collection)
568 collection.emplace_back(simplex.
tuple());
580 "top_dimension_cofaces_tuples not implemented for Tetrahedron in PointMesh");
581 default: assert(
false);
break;
587 std::vector<Tuple>& collection)
591 collection.emplace_back(simplex.
tuple());
598 collection.emplace_back(simplex.
tuple());
602 throw std::runtime_error(
603 "top_dimension_cofaces_tuples not implemented for Face in EdgeMesh");
607 default: assert(
false);
break;
614 std::vector<Tuple>& collection)
618 collection = top_dimension_cofaces_tuples_vertex(mesh, simplex.
tuple());
622 collection = top_dimension_cofaces_tuples_edge(mesh, simplex.
tuple());
626 collection = top_dimension_cofaces_tuples_face(mesh, simplex.
tuple());
630 default: assert(
false);
break;
637 std::vector<Tuple>& collection)
641 collection = top_dimension_cofaces_tuples_vertex(mesh, simplex.
tuple());
645 collection = top_dimension_cofaces_tuples_edge(mesh, simplex.
tuple());
649 collection = top_dimension_cofaces_tuples_face(mesh, simplex.
tuple());
653 collection = top_dimension_cofaces_tuples_tet(mesh, simplex.
tuple());
656 default: assert(
false);
break;
663 std::vector<Tuple>& tuples)
678 default: assert(
false);
692 if (sort_and_clean) {
708 if (sort_and_clean) {
724 if (sort_and_clean) {
733 std::vector<Tuple> collection;
741 std::vector<Tuple> collection;
748 std::vector<Tuple> collection;
755 std::vector<Tuple> collection;
773 throw std::runtime_error(
"unknown mesh type in top_dimension_cofaces_tuples");
Tuple switch_edge(const Tuple &tuple) const
bool is_boundary_vertex(const Tuple &tuple) const
PrimitiveType top_simplex_type() const
const Mesh & mesh() const
void add(const Simplex &simplex)
Add simplex to the collection.
void sort_and_clean()
Sort simplex vector and remove duplicates.
const Tuple & tuple() const
PrimitiveType primitive_type() const
static int64_t global_cid(const Tuple &t)
std::vector< Simplex > tuple_vector_to_homogeneous_simplex_vector(const Mesh &m, const std::vector< Tuple > &tups, PrimitiveType primitive)
void top_dimension_cofaces_tuples(const PointMesh &mesh, const Simplex &simplex, SimplexCollection &collection)
void top_dimension_cofaces(const Simplex &simplex, SimplexCollection &simplex_collection, const bool sort_and_clean)
Get all top dimension cofaces of the given simplex.
void log_and_throw_error(const std::string &msg)