Wildmeshing Toolkit
Loading...
Searching...
No Matches
test_component_regular_space.cpp
Go to the documentation of this file.
1#include <catch2/catch_test_macros.hpp>
2
3#include <nlohmann/json.hpp>
4#include <tools/DEBUG_TetMesh.hpp>
5#include <tools/DEBUG_TriMesh.hpp>
6#include <tools/TetMesh_examples.hpp>
7#include <tools/TriMesh_examples.hpp>
8#include <wmtk/Mesh.hpp>
14
15using json = nlohmann::json;
16using namespace wmtk;
17
18const std::filesystem::path data_dir = WMTK_DATA_DIR;
19
20TEST_CASE("regular_space_file_reading", "[components][regular_space]")
21{
22 using namespace components::internal;
23
24 std::map<std::string, std::filesystem::path> files;
25 std::map<std::string, int64_t> tags_value;
26
27 json o = {
28 {"input", "input_mesh"},
29 {"output", "output_mesh"},
30 {"attributes", {{"edge_label", "edge_tag_name"}}},
31 {"values", json::array({2})},
32 {"pass_through", json::array({})}};
33
34 CHECK_NOTHROW(o.get<RegularSpaceOptions>());
35}
36
37TEST_CASE("regular_space_component_tri", "[components][regular_space][trimesh][2D][scheduler]")
38{
39 const int64_t tag_value = 1;
40 tests::DEBUG_TriMesh m = wmtk::tests::hex_plus_two_with_position();
41 wmtk::attribute::MeshAttributeHandle vertex_tag_handle =
42 m.register_attribute<int64_t>("vertex_tag", wmtk::PrimitiveType::Vertex, 1);
44 m.register_attribute<int64_t>("edge_tag", wmtk::PrimitiveType::Edge, 1);
46 m.register_attribute<int64_t>("face_tag", wmtk::PrimitiveType::Triangle, 1);
47
48 std::vector<wmtk::attribute::MeshAttributeHandle> label_attributes;
49 label_attributes.emplace_back(face_tag_handle);
50 label_attributes.emplace_back(edge_tag_handle);
51 label_attributes.emplace_back(vertex_tag_handle);
52
53 std::vector<int64_t> label_values = {tag_value, tag_value, tag_value};
54
55 std::vector<attribute::MeshAttributeHandle> pass_through_attributes;
56 pass_through_attributes.emplace_back(
57 m.get_attribute_handle<double>("vertices", PrimitiveType::Vertex));
58
59 SECTION("points_in_2d_case")
60 {
61 // 0---1---2
62 // / \ / \ / \ .
63 // 3---4---5---6
64 // \ / \ / .
65 // 7---8
66 // set 0 1 4 5 6
67 {
68 const std::vector<Tuple>& vertex_tuples = m.get_all(wmtk::PrimitiveType::Vertex);
69 attribute::Accessor<int64_t> acc_vertex_tag = m.create_accessor<int64_t>(vertex_tag_handle);
70 acc_vertex_tag.scalar_attribute(vertex_tuples[0]) = tag_value;
71 acc_vertex_tag.scalar_attribute(vertex_tuples[1]) = tag_value;
72 acc_vertex_tag.scalar_attribute(vertex_tuples[4]) = tag_value;
73 acc_vertex_tag.scalar_attribute(vertex_tuples[5]) = tag_value;
74 acc_vertex_tag.scalar_attribute(vertex_tuples[6]) = tag_value;
75 }
76
78 m,
79 label_attributes,
80 label_values,
81 pass_through_attributes);
82 rs.regularize_tags();
83
84 CHECK(m.get_all(PrimitiveType::Vertex).size() == 15);
85
86 if (false) {
88 data_dir / "regular_space_result_0d_case",
89 "vertices",
90 m,
91 true,
92 true,
93 true,
94 false);
95 m.serialize(writer);
96 }
97 }
98 SECTION("edges_in_2d_case")
99 {
100 // 0---1---2
101 // / \ / \ / \ .
102 // 3---4---5---6
103 // \ / \ / .
104 // 7---8
105 // set vertex 0 1 4 5 6 7
106 // set edge 4-5 5-1 1-4 4-7 7-3
107 {
108 const std::vector<Tuple>& vertex_tuples = m.get_all(wmtk::PrimitiveType::Vertex);
109 attribute::Accessor<int64_t> acc_vertex_tag = m.create_accessor<int64_t>(vertex_tag_handle);
110 acc_vertex_tag.scalar_attribute(vertex_tuples[0]) = tag_value;
111 acc_vertex_tag.scalar_attribute(vertex_tuples[1]) = tag_value;
112 acc_vertex_tag.scalar_attribute(vertex_tuples[3]) = tag_value;
113 acc_vertex_tag.scalar_attribute(vertex_tuples[4]) = tag_value;
114 acc_vertex_tag.scalar_attribute(vertex_tuples[5]) = tag_value;
115 acc_vertex_tag.scalar_attribute(vertex_tuples[6]) = tag_value;
116 acc_vertex_tag.scalar_attribute(vertex_tuples[7]) = tag_value;
117 attribute::Accessor<int64_t> acc_edge_tag = m.create_accessor<int64_t>(edge_tag_handle);
118 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(4, 5, 2)) = tag_value;
119 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(5, 1, 2)) = tag_value;
120 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(1, 4, 2)) = tag_value;
121 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(7, 4, 5)) = tag_value;
122 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(7, 3, 5)) = tag_value;
123 }
124
126 m,
127 label_attributes,
128 label_values,
129 pass_through_attributes);
130 rs.regularize_tags();
131
132 CHECK(m.get_all(PrimitiveType::Triangle).size() == 17);
133 CHECK(m.get_all(PrimitiveType::Vertex).size() == 15);
134
135 if (false) {
136 ParaviewWriter writer(
137 data_dir / "regular_space_result_1d_case",
138 "vertices",
139 m,
140 true,
141 true,
142 true,
143 false);
144 m.serialize(writer);
145 }
146 }
147}
148
149TEST_CASE("regular_space_component_tet", "[components][regular_space][tetmesh][3D][scheduler][.]")
150{
151 using namespace tests_3d;
152 // 0 ---------- 4
153 // / \\ // \ .
154 // / \ \ // \ .
155 // / \ \ // \ .
156 // / \ \3 \ .
157 // 1 --------- 2/ -------- 5 tuple edge 2-3
158 // \ / /\ \ / .
159 // \ / / \\ / .
160 // \ // \\ / .
161 // \ // \ / .
162 // 6 -----------7
163 //
164 DEBUG_TetMesh m = six_cycle_tets();
165 const int64_t tag_value = 1;
166 Eigen::MatrixXd V(8, 3);
167 V.row(0) << 0.5, 0.86, 0;
168 V.row(1) << 0, 0, 0;
169 V.row(2) << 1.0, 0, 1.0;
170 V.row(3) << 1.0, 0, -1.0;
171 V.row(4) << 1.5, 0.86, 0;
172 V.row(5) << 2, 0, 0;
173 V.row(6) << 0.5, -0.86, 0;
174 V.row(7) << 1.5, -0.86, 0;
175 wmtk::attribute::MeshAttributeHandle vertex_tag_handle =
176 m.register_attribute<int64_t>("vertex_tag", wmtk::PrimitiveType::Vertex, 1);
178 m.register_attribute<int64_t>("edge_tag", wmtk::PrimitiveType::Edge, 1);
179
180 std::vector<wmtk::attribute::MeshAttributeHandle> label_attributes;
181 label_attributes.emplace_back(edge_tag_handle);
182 label_attributes.emplace_back(vertex_tag_handle);
183
184 std::vector<int64_t> label_values = {tag_value, tag_value};
185
186 std::vector<attribute::MeshAttributeHandle> pass_through_attributes;
187 pass_through_attributes.emplace_back(
188 m.get_attribute_handle<double>("vertices", PrimitiveType::Vertex));
189
190 SECTION("points_in_3d_case")
191 {
192 {
193 const std::vector<Tuple>& vertex_tuples = m.get_all(wmtk::PrimitiveType::Vertex);
194 attribute::Accessor<int64_t> acc_vertex_tag = m.create_accessor<int64_t>(vertex_tag_handle);
195 acc_vertex_tag.scalar_attribute(vertex_tuples[1]) = tag_value;
196 acc_vertex_tag.scalar_attribute(vertex_tuples[2]) = tag_value;
197 acc_vertex_tag.scalar_attribute(vertex_tuples[3]) = tag_value;
198 }
200 m,
201 label_attributes,
202 label_values,
203 pass_through_attributes);
204 rs.regularize_tags();
205
206 CHECK(false); // TODO add real checks
207
208 if (false) {
209 ParaviewWriter writer(
210 data_dir / "regular_space_result_points_3d_case",
211 "vertices",
212 m,
213 true,
214 true,
215 true,
216 true);
217 m.serialize(writer);
218 }
219 }
220 SECTION("edges_in_3d_case")
221 {
222 {
223 const std::vector<Tuple>& vertex_tuples = m.get_all(wmtk::PrimitiveType::Vertex);
224 attribute::Accessor<int64_t> acc_vertex_tag = m.create_accessor<int64_t>(vertex_tag_handle);
225 acc_vertex_tag.scalar_attribute(vertex_tuples[0]) = tag_value;
226 acc_vertex_tag.scalar_attribute(vertex_tuples[1]) = tag_value;
227 acc_vertex_tag.scalar_attribute(vertex_tuples[2]) = tag_value;
228 acc_vertex_tag.scalar_attribute(vertex_tuples[3]) = tag_value;
229 acc_vertex_tag.scalar_attribute(vertex_tuples[5]) = tag_value;
230 acc_vertex_tag.scalar_attribute(vertex_tuples[7]) = tag_value;
231 attribute::Accessor<int64_t> acc_edge_tag = m.create_accessor<int64_t>(edge_tag_handle);
232 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(0, 1, 0)) = tag_value;
233 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(0, 2, 0)) = tag_value;
234 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(0, 3, 0)) = tag_value;
235 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(1, 2, 0)) = tag_value;
236 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(2, 3, 0)) = tag_value;
237 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(3, 1, 0)) = tag_value;
238 acc_edge_tag.scalar_attribute(m.edge_tuple_with_vs_and_t(2, 5, 2)) = tag_value;
239 }
241 m,
242 label_attributes,
243 label_values,
244 pass_through_attributes);
245 rs.regularize_tags();
246
247 CHECK(false); // TODO add real checks
248
249 if (false) {
250 ParaviewWriter writer(
251 data_dir / "regular_space_result_edges_3d_case",
252 "vertices",
253 m,
254 true,
255 true,
256 true,
257 true);
258 m.serialize(writer);
259 }
260 }
261}
A CachingAccessor that uses tuples for accessing attributes instead of indices.
Definition Accessor.hpp:28
T & scalar_attribute(const ArgType &t)
const std::filesystem::path data_dir
TEST_CASE("regular_space_file_reading", "[components][regular_space]")
nlohmann::json json
Definition input.cpp:9