Wildmeshing Toolkit
Loading...
Searching...
No Matches
open_star.cpp
Go to the documentation of this file.
1#include "open_star.hpp"
2
3#include <wmtk/TetMesh.hpp>
4#include <wmtk/TriMesh.hpp>
6
7#include "faces.hpp"
9
10namespace wmtk::simplex {
11
12SimplexCollection open_star(const Mesh& mesh, const Simplex& simplex, const bool sort_and_clean)
13{
14 switch (mesh.top_simplex_type()) {
16 return open_star(static_cast<const TriMesh&>(mesh), simplex, sort_and_clean);
18 return open_star(static_cast<const TetMesh&>(mesh), simplex, sort_and_clean);
21 default: return open_star_slow(mesh, simplex, sort_and_clean); break;
22 }
23}
24
25SimplexCollection open_star(const TriMesh& mesh, const Simplex& simplex, const bool sort_and_clean)
26{
27 // make use of the fact that the top dimension coface tuples always contain the simplex itself
28 const std::vector<Tuple> cell_tuples = top_dimension_cofaces_tuples(mesh, simplex);
29
30 std::vector<Simplex> all_cofaces;
31 switch (simplex.primitive_type()) {
33 all_cofaces.reserve(cell_tuples.size() * 3 + 1);
34 for (const Tuple& t : cell_tuples) {
35 all_cofaces.emplace_back(Simplex::face(mesh, t));
36 all_cofaces.emplace_back(Simplex::edge(mesh, t));
37 all_cofaces.emplace_back(Simplex::edge(mesh, mesh.switch_edge(t)));
38 }
39 break;
41 all_cofaces.reserve(cell_tuples.size() + 1);
42 for (const Tuple& t : cell_tuples) {
43 all_cofaces.emplace_back(Simplex::face(mesh, t));
44 }
45 break;
46 case PrimitiveType::Triangle: all_cofaces.reserve(1); break;
48 default: break;
49 }
50 all_cofaces.emplace_back(simplex);
51
52 SimplexCollection collection(mesh, std::move(all_cofaces));
53
54
55 if (sort_and_clean) {
56 collection.sort_and_clean();
57 }
58
59 return collection;
60}
61
62SimplexCollection open_star(const TetMesh& mesh, const Simplex& simplex, const bool sort_and_clean)
63{
64 // make use of the fact that the top dimension coface tuples always contain the simplex itself
65 const std::vector<Tuple> cell_tuples = top_dimension_cofaces_tuples(mesh, simplex);
66
71
72 std::vector<Simplex> all_cofaces;
73 switch (simplex.primitive_type()) {
75 all_cofaces.reserve(cell_tuples.size() * 7 + 1);
76 for (Tuple t : cell_tuples) {
77 all_cofaces.emplace_back(Simplex::tetrahedron(mesh, t));
78 all_cofaces.emplace_back(Simplex::face(mesh, t));
79 all_cofaces.emplace_back(Simplex::edge(mesh, t));
80 t = mesh.switch_tuples(t, {PE, PF});
81 all_cofaces.emplace_back(Simplex::face(mesh, t));
82 all_cofaces.emplace_back(Simplex::edge(mesh, t));
83 t = mesh.switch_tuples(t, {PE, PF});
84 all_cofaces.emplace_back(Simplex::face(mesh, t));
85 all_cofaces.emplace_back(Simplex::edge(mesh, t));
86 }
87 break;
89 all_cofaces.reserve(cell_tuples.size() * 3 + 1);
90 for (const Tuple& t : cell_tuples) {
91 all_cofaces.emplace_back(Simplex::tetrahedron(mesh, t));
92 all_cofaces.emplace_back(Simplex::face(mesh, t));
93 all_cofaces.emplace_back(Simplex::face(mesh, mesh.switch_face(t)));
94 }
95 break;
97 all_cofaces.reserve(3);
98 assert(cell_tuples.size() <= 2);
99 for (const Tuple& t : cell_tuples) {
100 all_cofaces.emplace_back(Simplex::tetrahedron(mesh, t));
101 }
102 break;
103 case PrimitiveType::Tetrahedron: all_cofaces.reserve(1); break;
104 default: log_and_throw_error("Unknown primitive type in open_star."); break;
105 }
106 all_cofaces.emplace_back(simplex);
107
108 SimplexCollection collection(mesh, std::move(all_cofaces));
109
110
111 if (sort_and_clean) {
112 collection.sort_and_clean();
113 }
114
115 return collection;
116}
117
118SimplexCollection
119open_star_slow(const Mesh& mesh, const Simplex& simplex, const bool sort_and_clean)
120{
121 SimplexCollection collection(mesh);
122
123 collection.add(simplex);
124
125 const SimplexCollection top_dimension_cofaces_collection =
126 top_dimension_cofaces(mesh, simplex, false);
127
128 for (const Simplex& coface_cell : top_dimension_cofaces_collection.simplex_vector()) {
129 collection.add(coface_cell);
130
131 const SimplexCollection cell_boundary = faces(mesh, coface_cell);
132 for (const Simplex& boundary_simplex : cell_boundary.simplex_vector()) {
133 const SimplexCollection bdbd = faces(mesh, boundary_simplex);
134 if (bdbd.contains(simplex)) {
135 collection.add(boundary_simplex);
136 }
137 }
138 }
139
140 if (sort_and_clean) {
141 collection.sort_and_clean();
142 }
143
144 return collection;
145}
146
147} // namespace wmtk::simplex
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
Performs a sequence of switch_tuple operations in the order specified in op_sequence.
Definition MeshCRTP.hpp:136
PrimitiveType top_simplex_type() const
Definition Mesh.hpp:982
Tuple switch_face(const Tuple &tuple) const
Definition TetMesh.hpp:121
Tuple switch_edge(const Tuple &tuple) const
Definition TriMesh.hpp:117
The Tuple is the basic navigation tool in our mesh data structure.
Definition Tuple.hpp:19
void add(const Simplex &simplex)
Add simplex to the collection.
bool contains(const Simplex &simplex) const
Check if simplex is contained in collection.
const std::vector< Simplex > & simplex_vector() const
Return const reference to the simplex vector.
void sort_and_clean()
Sort simplex vector and remove duplicates.
static Simplex face(const Mesh &m, const Tuple &t)
Definition Simplex.hpp:63
static Simplex edge(const Mesh &m, const Tuple &t)
Definition Simplex.hpp:61
static Simplex tetrahedron(const Mesh &m, const Tuple &t)
Definition Simplex.hpp:68
PrimitiveType primitive_type() const
Definition Simplex.hpp:51
constexpr wmtk::PrimitiveType PT
constexpr wmtk::PrimitiveType PF
void top_dimension_cofaces_tuples(const PointMesh &mesh, const Simplex &simplex, SimplexCollection &collection)
SimplexCollection open_star(const Mesh &mesh, const Simplex &simplex, const bool sort_and_clean)
Definition open_star.cpp:12
void top_dimension_cofaces(const Simplex &simplex, SimplexCollection &simplex_collection, const bool sort_and_clean)
Get all top dimension cofaces of the given simplex.
SimplexCollection open_star_slow(const Mesh &mesh, const Simplex &simplex, const bool sort_and_clean)
SimplexCollection faces(const Mesh &mesh, const Simplex &simplex, const bool sort_and_clean)
Returns all faces of a simplex.
Definition faces.cpp:10
void log_and_throw_error(const std::string &msg)
Definition Logger.cpp:101
constexpr PrimitiveType PE
constexpr PrimitiveType PV