Wildmeshing Toolkit
Loading...
Searching...
No Matches
test_simplicial_embedding.cpp
Go to the documentation of this file.
1#include <catch2/catch_test_macros.hpp>
2
3#include <tools/DEBUG_TetMesh.hpp>
4#include <tools/DEBUG_TriMesh.hpp>
5#include <tools/TetMesh_examples.hpp>
6#include <tools/TriMesh_examples.hpp>
7#include <wmtk/Mesh.hpp>
10
11using namespace wmtk;
12using namespace components;
13
14const std::filesystem::path data_dir = WMTK_DATA_DIR;
15
17 "simplicial_embedding_component_tri",
18 "[components][simplicial_embedding][trimesh][2D][scheduler]")
19{
20 tests::DEBUG_TriMesh m = wmtk::tests::hex_plus_two_with_position();
21
23 options.value = 1;
24 options.tag_attributes[PrimitiveType::Vertex] =
25 m.register_attribute<int64_t>("vertex_tag", wmtk::PrimitiveType::Vertex, 1);
26 options.tag_attributes[PrimitiveType::Edge] =
27 m.register_attribute<int64_t>("edge_tag", wmtk::PrimitiveType::Edge, 1);
28 options.tag_attributes[PrimitiveType::Triangle] =
29 m.register_attribute<int64_t>("face_tag", wmtk::PrimitiveType::Triangle, 1);
30 options.pass_through_attributes.emplace_back(
31 m.get_attribute_handle<double>("vertices", PrimitiveType::Vertex));
32
33 SECTION("points_in_2d_case")
34 {
35 // 0---1---2
36 // / \ / \ / \ .
37 // 3---4---5---6
38 // \ / \ / .
39 // 7---8
40 // set 0 1 4 5 6
41 {
42 const std::vector<Tuple>& vertex_tuples = m.get_all(wmtk::PrimitiveType::Vertex);
43 attribute::Accessor<int64_t> acc_vertex_tag =
44 m.create_accessor<int64_t>(options.tag_attributes[PrimitiveType::Vertex]);
45 acc_vertex_tag.scalar_attribute(vertex_tuples[0]) = options.value;
46 acc_vertex_tag.scalar_attribute(vertex_tuples[1]) = options.value;
47 acc_vertex_tag.scalar_attribute(vertex_tuples[4]) = options.value;
48 acc_vertex_tag.scalar_attribute(vertex_tuples[5]) = options.value;
49 acc_vertex_tag.scalar_attribute(vertex_tuples[6]) = options.value;
50 }
51
52 simplicial_embedding(m, options);
53
54 CHECK(m.get_all(PrimitiveType::Vertex).size() == 15);
55
56 if (false) {
58 data_dir / "simplicial_embedding_result_0d_case",
59 "vertices",
60 m,
61 true,
62 true,
63 true,
64 false);
65 m.serialize(writer);
66 }
67 }
68 SECTION("edges_in_2d_case")
69 {
70 // 0---1---2
71 // / \ / \ / \ .
72 // 3---4---5---6
73 // \ / \ / .
74 // 7---8
75 // set vertex 0 1 4 5 6 7
76 // set edge 4-5 5-1 1-4 4-7 7-3
77 {
78 const std::vector<Tuple>& vertex_tuples = m.get_all(wmtk::PrimitiveType::Vertex);
79 attribute::Accessor<int64_t> acc_vertex_tag =
80 m.create_accessor<int64_t>(options.tag_attributes[PrimitiveType::Vertex]);
81 acc_vertex_tag.scalar_attribute(vertex_tuples[0]) = options.value;
82 acc_vertex_tag.scalar_attribute(vertex_tuples[1]) = options.value;
83 acc_vertex_tag.scalar_attribute(vertex_tuples[3]) = options.value;
84 acc_vertex_tag.scalar_attribute(vertex_tuples[4]) = options.value;
85 acc_vertex_tag.scalar_attribute(vertex_tuples[5]) = options.value;
86 acc_vertex_tag.scalar_attribute(vertex_tuples[6]) = options.value;
87 acc_vertex_tag.scalar_attribute(vertex_tuples[7]) = options.value;
88 attribute::Accessor<int64_t> acc_edge_tag =
89 m.create_accessor<int64_t>(options.tag_attributes[PrimitiveType::Edge]);
90 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(4, 5, 2)) = options.value;
91 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(5, 1, 2)) = options.value;
92 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(1, 4, 2)) = options.value;
93 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(7, 4, 5)) = options.value;
94 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(7, 3, 5)) = options.value;
95 }
96
97 simplicial_embedding(m, options);
98
99 CHECK(m.get_all(PrimitiveType::Triangle).size() == 17);
100 CHECK(m.get_all(PrimitiveType::Vertex).size() == 15);
101
102 if (false) {
103 ParaviewWriter writer(
104 data_dir / "simplicial_embedding_result_1d_case",
105 "vertices",
106 m,
107 true,
108 true,
109 true,
110 false);
111 m.serialize(writer);
112 }
113 }
114}
115
117 "simplicial_embedding_component_tet",
118 "[components][simplicial_embedding][tetmesh][3D][scheduler][.]")
119{
120 using namespace tests_3d;
121 // 0 ---------- 4
122 // / \\ // \ .
123 // / \ \ // \ .
124 // / \ \ // \ .
125 // / \ \3 \ .
126 // 1 --------- 2/ -------- 5 tuple edge 2-3
127 // \ / /\ \ / .
128 // \ / / \\ / .
129 // \ // \\ / .
130 // \ // \ / .
131 // 6 -----------7
132 //
133 DEBUG_TetMesh m = six_cycle_tets();
134
136 options.value = 1;
137 options.tag_attributes[PrimitiveType::Vertex] =
138 m.register_attribute<int64_t>("vertex_tag", wmtk::PrimitiveType::Vertex, 1);
139 options.tag_attributes[PrimitiveType::Edge] =
140 m.register_attribute<int64_t>("edge_tag", wmtk::PrimitiveType::Edge, 1);
141 options.tag_attributes[PrimitiveType::Triangle] =
142 m.register_attribute<int64_t>("face_tag", wmtk::PrimitiveType::Triangle, 1);
143 options.pass_through_attributes.emplace_back(
144 m.get_attribute_handle<double>("vertices", PrimitiveType::Vertex));
145
146 SECTION("points_in_3d_case")
147 {
148 {
149 const std::vector<Tuple>& vertex_tuples = m.get_all(wmtk::PrimitiveType::Vertex);
150 attribute::Accessor<int64_t> acc_vertex_tag =
151 m.create_accessor<int64_t>(options.tag_attributes[PrimitiveType::Vertex]);
152 acc_vertex_tag.scalar_attribute(vertex_tuples[1]) = options.value;
153 acc_vertex_tag.scalar_attribute(vertex_tuples[2]) = options.value;
154 acc_vertex_tag.scalar_attribute(vertex_tuples[3]) = options.value;
155 }
156 simplicial_embedding(m, options);
157
158 CHECK(false); // TODO add real checks
159
160 if (false) {
161 ParaviewWriter writer(
162 data_dir / "simplicial_embedding_result_points_3d_case",
163 "vertices",
164 m,
165 true,
166 true,
167 true,
168 true);
169 m.serialize(writer);
170 }
171 }
172 SECTION("edges_in_3d_case")
173 {
174 {
175 const std::vector<Tuple>& vertex_tuples = m.get_all(wmtk::PrimitiveType::Vertex);
176 attribute::Accessor<int64_t> acc_vertex_tag =
177 m.create_accessor<int64_t>(options.tag_attributes[PrimitiveType::Vertex]);
178 acc_vertex_tag.scalar_attribute(vertex_tuples[0]) = options.value;
179 acc_vertex_tag.scalar_attribute(vertex_tuples[1]) = options.value;
180 acc_vertex_tag.scalar_attribute(vertex_tuples[2]) = options.value;
181 acc_vertex_tag.scalar_attribute(vertex_tuples[3]) = options.value;
182 acc_vertex_tag.scalar_attribute(vertex_tuples[5]) = options.value;
183 acc_vertex_tag.scalar_attribute(vertex_tuples[7]) = options.value;
184 attribute::Accessor<int64_t> acc_edge_tag =
185 m.create_accessor<int64_t>(options.tag_attributes[PrimitiveType::Edge]);
186 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(0, 1, 0)) = options.value;
187 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(0, 2, 0)) = options.value;
188 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(0, 3, 0)) = options.value;
189 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(1, 2, 0)) = options.value;
190 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(2, 3, 0)) = options.value;
191 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(3, 1, 0)) = options.value;
192 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(2, 5, 2)) = options.value;
193 }
194 simplicial_embedding(m, options);
195
196 CHECK(false); // TODO add real checks
197
198 if (false) {
199 ParaviewWriter writer(
200 data_dir / "simplicial_embedding_result_edges_3d_case",
201 "vertices",
202 m,
203 true,
204 true,
205 true,
206 true);
207 m.serialize(writer);
208 }
209 }
210}
A CachingAccessor that uses tuples for accessing attributes instead of indices.
Definition Accessor.hpp:28
T & scalar_attribute(const ArgType &t)
void simplicial_embedding(Mesh &mesh, const SimplicialEmbeddingOptions &options)
std::map< PrimitiveType, attribute::MeshAttributeHandle > tag_attributes
All simplex dimensions must have an int64_t scalar attribute where the tags are stored.
int64_t value
The value that should be simplicially embedded.
std::vector< attribute::MeshAttributeHandle > pass_through_attributes
Other attributes that should be processed with the default behavior.
const std::filesystem::path data_dir
TEST_CASE("simplicial_embedding_component_tri", "[components][simplicial_embedding][trimesh][2D][scheduler]")