Debian Codegraph @

packages/stk/stk_unit_tests/stk_middle_mesh/test_quad_to_triangles.cpp

raw
1 #include "stk_middle_mesh/predicates/intersection_common.hpp"
2 #include "stk_middle_mesh/mesh.hpp"
3 #include "stk_middle_mesh/predicates/quad_to_triangles.hpp"
4 #include "gtest/gtest.h"
5
6 namespace stk {
7 namespace middle_mesh {
8 namespace impl {
9
10 using namespace predicates::impl;
11
12 namespace {
13
14 class QuadToTrianglesTester : public ::testing::Test
15 {
16 protected:
17 QuadToTrianglesTester()
18 {
19 mesh = mesh::make_empty_mesh();
20 verts[0] = mesh->create_vertex(0, 0, 0);
21 verts[1] = mesh->create_vertex(1, 0, 0);
22 verts[2] = mesh->create_vertex(1, 1, 0);
23 verts[3] = mesh->create_vertex(0, 1, 0);
24 el = mesh->create_quad_from_verts(verts[0], verts[1], verts[2], verts[3]);
25 quadToTriangles.set_triangles(el);
26 }
27
28 std::shared_ptr<mesh::Mesh> mesh;
29 mesh::MeshEntityPtr el;
30 std::array<mesh::MeshEntityPtr, 4> verts;
31 QuadToTriangles quadToTriangles;
32 };
33
34 void expect_near(const utils::Point& pt1, const utils::Point& pt2, double tol)
35 {
36 for (int i = 0; i < 3; ++i)
37 EXPECT_NEAR(pt1[i], pt2[i], tol);
38 }
39 } // namespace
40
41 TEST_F(QuadToTrianglesTester, Setup)
42 {
43 for (int i = 0; i < 4; ++i)
44 expect_near(verts[0]->get_point_orig(0), quadToTriangles.verts[0]->get_point_orig(0), 1e-13);
45
46 std::array<mesh::MeshEntityPtr, 3> el1Verts, el2Verts;
47 get_downward(quadToTriangles.el1, 0, el1Verts.data());
48 get_downward(quadToTriangles.el2, 0, el2Verts.data());
49 for (int i = 0; i < 3; ++i)
50 {
51 mesh::MeshEntityPtr vertFromMap = quadToTriangles.verts[quadToTriangles.VERTMAP_TRI1_TO_QUAD[i]];
52 mesh::MeshEntityPtr vertFromEl = el1Verts[i];
53 EXPECT_EQ(vertFromMap, vertFromEl);
54
55 vertFromMap = quadToTriangles.verts[quadToTriangles.VERTMAP_TRI2_TO_QUAD[i]];
56 vertFromEl = el2Verts[i];
57 EXPECT_EQ(vertFromMap, vertFromEl);
58 }
59 }
60
61 TEST_F(QuadToTrianglesTester, Vert1)
62 {
63 PointRecordForTriangle r1(PointClassification::Vert, 0, quadToTriangles.el1);
64 PointRecordForTriangle r2(PointClassification::Exterior, -1, quadToTriangles.el2);
65 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
66
67 EXPECT_EQ(r3.type, PointClassification::Vert);
68 EXPECT_EQ(r3.id, 0);
69 EXPECT_EQ(r3.el, el);
70 }
71
72 TEST_F(QuadToTrianglesTester, Vert2FirstEl)
73 {
74 PointRecordForTriangle r1(PointClassification::Vert, 1, quadToTriangles.el1);
75 PointRecordForTriangle r2(PointClassification::Exterior, -1, quadToTriangles.el2);
76 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
77
78 EXPECT_EQ(r3.type, PointClassification::Vert);
79 EXPECT_EQ(r3.id, 1);
80 EXPECT_EQ(r3.el, el);
81 }
82
83 TEST_F(QuadToTrianglesTester, Vert2SecondEl)
84 {
85 PointRecordForTriangle r1(PointClassification::Exterior, -1, quadToTriangles.el1);
86 PointRecordForTriangle r2(PointClassification::Vert, 2, quadToTriangles.el2);
87 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
88
89 EXPECT_EQ(r3.type, PointClassification::Vert);
90 EXPECT_EQ(r3.id, 1);
91 EXPECT_EQ(r3.el, el);
92 }
93
94 TEST_F(QuadToTrianglesTester, Vert3)
95 {
96 PointRecordForTriangle r1(PointClassification::Exterior, 0, quadToTriangles.el1);
97 PointRecordForTriangle r2(PointClassification::Vert, 0, quadToTriangles.el2);
98 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
99
100 EXPECT_EQ(r3.type, PointClassification::Vert);
101 EXPECT_EQ(r3.id, 2);
102 EXPECT_EQ(r3.el, el);
103 }
104
105 TEST_F(QuadToTrianglesTester, Vert4FirstEl)
106 {
107 PointRecordForTriangle r1(PointClassification::Vert, 2, quadToTriangles.el1);
108 PointRecordForTriangle r2(PointClassification::Exterior, -1, quadToTriangles.el2);
109 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
110
111 EXPECT_EQ(r3.type, PointClassification::Vert);
112 EXPECT_EQ(r3.id, 3);
113 EXPECT_EQ(r3.el, el);
114 }
115
116 TEST_F(QuadToTrianglesTester, Vert4SecondEl)
117 {
118 PointRecordForTriangle r1(PointClassification::Exterior, -1, quadToTriangles.el1);
119 PointRecordForTriangle r2(PointClassification::Vert, 1, quadToTriangles.el2);
120 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
121
122 EXPECT_EQ(r3.type, PointClassification::Vert);
123 EXPECT_EQ(r3.id, 3);
124 EXPECT_EQ(r3.el, el);
125 }
126
127 TEST_F(QuadToTrianglesTester, Edge1)
128 {
129 PointRecordForTriangle r1(PointClassification::Edge, 0, quadToTriangles.el1);
130 PointRecordForTriangle r2(PointClassification::Exterior, -1, quadToTriangles.el2);
131 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
132
133 EXPECT_EQ(r3.type, PointClassification::Edge);
134 EXPECT_EQ(r3.id, 0);
135 EXPECT_EQ(r3.el, el);
136 }
137
138 TEST_F(QuadToTrianglesTester, Edge2)
139 {
140 PointRecordForTriangle r1(PointClassification::Exterior, -1, quadToTriangles.el1);
141 PointRecordForTriangle r2(PointClassification::Edge, 2, quadToTriangles.el2);
142 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
143
144 EXPECT_EQ(r3.type, PointClassification::Edge);
145 EXPECT_EQ(r3.id, 1);
146 EXPECT_EQ(r3.el, el);
147 }
148
149 TEST_F(QuadToTrianglesTester, Edge3)
150 {
151 PointRecordForTriangle r1(PointClassification::Exterior, -1, quadToTriangles.el1);
152 PointRecordForTriangle r2(PointClassification::Edge, 0, quadToTriangles.el2);
153 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
154
155 EXPECT_EQ(r3.type, PointClassification::Edge);
156 EXPECT_EQ(r3.id, 2);
157 EXPECT_EQ(r3.el, el);
158 }
159
160 TEST_F(QuadToTrianglesTester, Edge4)
161 {
162 PointRecordForTriangle r1(PointClassification::Edge, 2, quadToTriangles.el1);
163 PointRecordForTriangle r2(PointClassification::Exterior, -1, quadToTriangles.el2);
164 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
165
166 EXPECT_EQ(r3.type, PointClassification::Edge);
167 EXPECT_EQ(r3.id, 3);
168 EXPECT_EQ(r3.el, el);
169 }
170
171 TEST_F(QuadToTrianglesTester, InteriorEdge1)
172 {
173 PointRecordForTriangle r1(PointClassification::Edge, 1, quadToTriangles.el1);
174 PointRecordForTriangle r2(PointClassification::Exterior, -1, quadToTriangles.el2);
175 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
176
177 EXPECT_EQ(r3.type, PointClassification::Interior);
178 EXPECT_EQ(r3.el, el);
179 }
180
181 TEST_F(QuadToTrianglesTester, InteriorEdge2)
182 {
183 PointRecordForTriangle r1(PointClassification::Exterior, -1, quadToTriangles.el1);
184 PointRecordForTriangle r2(PointClassification::Edge, 1, quadToTriangles.el2);
185 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
186
187 EXPECT_EQ(r3.type, PointClassification::Interior);
188 EXPECT_EQ(r3.el, el);
189 }
190
191 TEST_F(QuadToTrianglesTester, Interior1)
192 {
193 PointRecordForTriangle r1(PointClassification::Interior, -1, quadToTriangles.el1);
194 PointRecordForTriangle r2(PointClassification::Exterior, -1, quadToTriangles.el2);
195 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
196
197 EXPECT_EQ(r3.type, PointClassification::Interior);
198 EXPECT_EQ(r3.el, el);
199 }
200
201 TEST_F(QuadToTrianglesTester, Interior2)
202 {
203 PointRecordForTriangle r1(PointClassification::Exterior, -1, quadToTriangles.el1);
204 PointRecordForTriangle r2(PointClassification::Interior, -1, quadToTriangles.el2);
205 PointRecord r3 = quadToTriangles.get_quad_record(el, r1, r2);
206
207 EXPECT_EQ(r3.type, PointClassification::Interior);
208 EXPECT_EQ(r3.el, el);
209 }
210
211 TEST_F(QuadToTrianglesTester, RecordConsistency_El1Vert1)
212 {
213 PointRecordForTriangle r1(PointClassification::Vert, 1, quadToTriangles.el1);
214
215 std::vector<PointClassification> types = {PointClassification::Interior, PointClassification::Exterior,
216 PointClassification::Edge, PointClassification::Edge};
217 std::vector<int> ids = {-1, -1, 1, 2};
218
219 for (size_t i = 0; i < types.size(); ++i)
220 {
221 PointRecordForTriangle r2(types[i], ids[i], quadToTriangles.el2);
222 quadToTriangles.enforce_record_consistency(r1, r2);
223
224 EXPECT_EQ(r1.type, PointClassification::Vert);
225 EXPECT_EQ(r1.id, 1);
226 EXPECT_EQ(r1.el, quadToTriangles.el1);
227
228 EXPECT_EQ(r2.type, PointClassification::Vert);
229 EXPECT_EQ(r2.id, 2);
230 EXPECT_EQ(r2.el, quadToTriangles.el2);
231 }
232 }
233
234 TEST_F(QuadToTrianglesTester, RecordConsistency_El1Vert2)
235 {
236 PointRecordForTriangle r1(PointClassification::Vert, 2, quadToTriangles.el1);
237
238 std::vector<PointClassification> types = {PointClassification::Interior, PointClassification::Exterior,
239 PointClassification::Edge, PointClassification::Edge};
240 std::vector<int> ids = {-1, -1, 0, 1};
241
242 for (size_t i = 0; i < types.size(); ++i)
243 {
244 PointRecordForTriangle r2(types[i], ids[i], quadToTriangles.el2);
245 quadToTriangles.enforce_record_consistency(r1, r2);
246
247 EXPECT_EQ(r1.type, PointClassification::Vert);
248 EXPECT_EQ(r1.id, 2);
249 EXPECT_EQ(r1.el, quadToTriangles.el1);
250
251 EXPECT_EQ(r2.type, PointClassification::Vert);
252 EXPECT_EQ(r2.id, 1);
253 EXPECT_EQ(r2.el, quadToTriangles.el2);
254 }
255 }
256
257 TEST_F(QuadToTrianglesTester, RecordConsistency_El1Edge1)
258 {
259 PointRecordForTriangle r1(PointClassification::Edge, 1, quadToTriangles.el1);
260
261 std::vector<PointClassification> types = {PointClassification::Interior, PointClassification::Exterior};
262 std::vector<int> ids = {-1, -1};
263
264 for (size_t i = 0; i < types.size(); ++i)
265 {
266 PointRecordForTriangle r2(types[i], ids[i], quadToTriangles.el2);
267 quadToTriangles.enforce_record_consistency(r1, r2);
268
269 EXPECT_EQ(r1.type, PointClassification::Edge);
270 EXPECT_EQ(r1.id, 1);
271 EXPECT_EQ(r1.el, quadToTriangles.el1);
272
273 EXPECT_EQ(r2.type, PointClassification::Edge);
274 EXPECT_EQ(r2.id, 1);
275 EXPECT_EQ(r2.el, quadToTriangles.el2);
276 }
277 }
278
279 TEST_F(QuadToTrianglesTester, RecordConsistency_El2Vert1)
280 {
281 PointRecordForTriangle r2(PointClassification::Vert, 1, quadToTriangles.el2);
282
283 std::vector<PointClassification> types = {PointClassification::Interior, PointClassification::Exterior,
284 PointClassification::Edge, PointClassification::Edge};
285 std::vector<int> ids = {-1, -1, 1, 2};
286
287 for (size_t i = 0; i < types.size(); ++i)
288 {
289 PointRecordForTriangle r1(types[i], ids[i], quadToTriangles.el1);
290 quadToTriangles.enforce_record_consistency(r1, r2);
291
292 EXPECT_EQ(r1.type, PointClassification::Vert);
293 EXPECT_EQ(r1.id, 2);
294 EXPECT_EQ(r1.el, quadToTriangles.el1);
295
296 EXPECT_EQ(r2.type, PointClassification::Vert);
297 EXPECT_EQ(r2.id, 1);
298 EXPECT_EQ(r2.el, quadToTriangles.el2);
299 }
300 }
301
302 TEST_F(QuadToTrianglesTester, RecordConsistency_El2Vert2)
303 {
304 PointRecordForTriangle r2(PointClassification::Vert, 2, quadToTriangles.el2);
305
306 std::vector<PointClassification> types = {PointClassification::Interior, PointClassification::Exterior,
307 PointClassification::Edge, PointClassification::Edge};
308 std::vector<int> ids = {-1, -1, 0, 1};
309
310 for (size_t i = 0; i < types.size(); ++i)
311 {
312 PointRecordForTriangle r1(types[i], ids[i], quadToTriangles.el1);
313 quadToTriangles.enforce_record_consistency(r1, r2);
314
315 EXPECT_EQ(r1.type, PointClassification::Vert);
316 EXPECT_EQ(r1.id, 1);
317 EXPECT_EQ(r1.el, quadToTriangles.el1);
318
319 EXPECT_EQ(r2.type, PointClassification::Vert);
320 EXPECT_EQ(r2.id, 2);
321 EXPECT_EQ(r2.el, quadToTriangles.el2);
322 }
323 }
324
325 TEST_F(QuadToTrianglesTester, RecordConsistency_El2Edge1)
326 {
327 PointRecordForTriangle r2(PointClassification::Edge, 1, quadToTriangles.el2);
328
329 std::vector<PointClassification> types = {PointClassification::Interior, PointClassification::Exterior};
330 std::vector<int> ids = {-1, -1};
331
332 for (size_t i = 0; i < types.size(); ++i)
333 {
334 PointRecordForTriangle r1(types[i], ids[i], quadToTriangles.el1);
335 quadToTriangles.enforce_record_consistency(r1, r2);
336
337 EXPECT_EQ(r1.type, PointClassification::Edge);
338 EXPECT_EQ(r1.id, 1);
339 EXPECT_EQ(r1.el, quadToTriangles.el1);
340
341 EXPECT_EQ(r2.type, PointClassification::Edge);
342 EXPECT_EQ(r2.id, 1);
343 EXPECT_EQ(r2.el, quadToTriangles.el2);
344 }
345 }
346
347
348 TEST_F(QuadToTrianglesTester, QuadXiCoordinatesVert)
349 {
350 {
351 PointRecordForTriangle r1(PointClassification::Vert, 0, quadToTriangles.el1),
352 r2(PointClassification::Exterior, -1, quadToTriangles.el2);
353 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
354 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {0, 0}, 1e-13);
355 }
356
357 {
358 PointRecordForTriangle r1(PointClassification::Vert, 1, quadToTriangles.el1),
359 r2(PointClassification::Exterior, -1, quadToTriangles.el2);
360 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
361 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {1, 0}, 1e-13);
362 }
363
364 {
365 PointRecordForTriangle r1(PointClassification::Exterior, 0, quadToTriangles.el1),
366 r2(PointClassification::Vert, 2, quadToTriangles.el2);
367 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
368 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {1, 0}, 1e-13);
369 }
370
371 {
372 PointRecordForTriangle r1(PointClassification::Exterior, 0, quadToTriangles.el1),
373 r2(PointClassification::Vert, 0, quadToTriangles.el2);
374 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
375 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {1, 1}, 1e-13);
376 }
377
378 {
379 PointRecordForTriangle r1(PointClassification::Vert, 2, quadToTriangles.el1),
380 r2(PointClassification::Exterior, -1, quadToTriangles.el2);
381 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
382 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {0, 1}, 1e-13);
383 }
384
385 {
386 PointRecordForTriangle r1(PointClassification::Exterior, 0, quadToTriangles.el1),
387 r2(PointClassification::Vert, 1, quadToTriangles.el2);
388 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
389 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {0, 1}, 1e-13);
390 }
391 }
392
393 TEST_F(QuadToTrianglesTester, QuadXiCoordinatesEdges)
394 {
395 {
396 PointRecordForTriangle r1(PointClassification::Edge, 0, quadToTriangles.el1, {0.5, 0}),
397 r2(PointClassification::Exterior, -1, quadToTriangles.el2);
398 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
399 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {0.5, 0}, 1e-13);
400 }
401
402 {
403 PointRecordForTriangle r1(PointClassification::Exterior, -1, quadToTriangles.el1),
404 r2(PointClassification::Edge, 2, quadToTriangles.el2, {0, 0.5});
405 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
406 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {1, 0.5}, 1e-13);
407 }
408
409 {
410 PointRecordForTriangle r1(PointClassification::Exterior, -1, quadToTriangles.el1),
411 r2(PointClassification::Edge, 0, quadToTriangles.el2, {0.5, 0});
412 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
413 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {0.5, 1}, 1e-13);
414 }
415
416 {
417 PointRecordForTriangle r1(PointClassification::Edge, 2, quadToTriangles.el1, {0, 0.5}),
418 r2(PointClassification::Exterior, -1, quadToTriangles.el2);
419 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
420 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {0.0, 0.5}, 1e-13);
421 }
422 }
423
424 TEST_F(QuadToTrianglesTester, QuadXiCoordinatesInteriorEdge)
425 {
426 {
427 PointRecordForTriangle r1(PointClassification::Edge, 1, quadToTriangles.el1, {0.5, 0.5}),
428 r2(PointClassification::Exterior, -1, quadToTriangles.el2);
429 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
430 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {0.5, 0.5}, 1e-13);
431 }
432
433 {
434 PointRecordForTriangle r1(PointClassification::Exterior, -1, quadToTriangles.el1),
435 r2(PointClassification::Edge, 1, quadToTriangles.el2, {0.5, 0.5});
436 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
437 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {0.5, 0.5}, 1e-13);
438 }
439 }
440
441 TEST_F(QuadToTrianglesTester, QuadXiCoordinatesInterior)
442 {
443 {
444 PointRecordForTriangle r1(PointClassification::Interior, -1, quadToTriangles.el1, {0.25, 0.25}),
445 r2(PointClassification::Exterior, -1, quadToTriangles.el2);
446 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
447 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {0.25, 0.25}, 1e-13);
448 }
449
450 {
451 PointRecordForTriangle r1(PointClassification::Exterior, -1, quadToTriangles.el1),
452 r2(PointClassification::Interior, -1, quadToTriangles.el2, {0.25, 0.25});
453 PointRecord quadRecord = quadToTriangles.get_quad_record(el, r1, r2);
454 expect_near(quadToTriangles.get_quad_xi_coords(quadRecord), {0.75, 0.75}, 1e-13);
455 }
456 }
457
458 TEST_F(QuadToTrianglesTester, create_record_edge)
459 {
460 PointRecord record = quadToTriangles.create_record(el, 0, 0);
461 EXPECT_EQ(record.el, el);
462 EXPECT_EQ(record.type, PointClassification::Edge);
463 EXPECT_EQ(record.id, 0);
464 expect_near(quadToTriangles.get_quad_xi_coords(record), {0, 0}, 1e-13);
465
466 record = quadToTriangles.create_record(el, 0, 1);
467 EXPECT_EQ(record.el, el);
468 EXPECT_EQ(record.type, PointClassification::Edge);
469 EXPECT_EQ(record.id, 0);
470 expect_near(quadToTriangles.get_quad_xi_coords(record), {1, 0}, 1e-13);
471
472 record = quadToTriangles.create_record(el, 1, 0);
473 EXPECT_EQ(record.el, el);
474 EXPECT_EQ(record.type, PointClassification::Edge);
475 EXPECT_EQ(record.id, 1);
476 expect_near(quadToTriangles.get_quad_xi_coords(record), {1, 0}, 1e-13);
477
478 record = quadToTriangles.create_record(el, 1, 1);
479 EXPECT_EQ(record.el, el);
480 EXPECT_EQ(record.type, PointClassification::Edge);
481 EXPECT_EQ(record.id, 1);
482 expect_near(quadToTriangles.get_quad_xi_coords(record), {1, 1}, 1e-13);
483
484
485 record = quadToTriangles.create_record(el, 2, 0);
486 EXPECT_EQ(record.el, el);
487 EXPECT_EQ(record.type, PointClassification::Edge);
488 EXPECT_EQ(record.id, 2);
489 expect_near(quadToTriangles.get_quad_xi_coords(record), {1, 1}, 1e-13);
490
491 record = quadToTriangles.create_record(el, 2, 1);
492 EXPECT_EQ(record.el, el);
493 EXPECT_EQ(record.type, PointClassification::Edge);
494 EXPECT_EQ(record.id, 2);
495 expect_near(quadToTriangles.get_quad_xi_coords(record), {0, 1}, 1e-13);
496
497 record = quadToTriangles.create_record(el, 3, 0);
498 EXPECT_EQ(record.el, el);
499 EXPECT_EQ(record.type, PointClassification::Edge);
500 EXPECT_EQ(record.id, 3);
501 expect_near(quadToTriangles.get_quad_xi_coords(record), {0, 1}, 1e-13);
502
503 record = quadToTriangles.create_record(el, 3, 1);
504 EXPECT_EQ(record.el, el);
505 EXPECT_EQ(record.type, PointClassification::Edge);
506 EXPECT_EQ(record.id, 3);
507 expect_near(quadToTriangles.get_quad_xi_coords(record), {0, 0}, 1e-13);
508
509 }
510
511 TEST_F(QuadToTrianglesTester, create_record_vert)
512 {
513 PointRecord record = quadToTriangles.create_record(el, 0);
514 EXPECT_EQ(record.el, el);
515 EXPECT_EQ(record.type, PointClassification::Vert);
516 EXPECT_EQ(record.id, 0);
517 expect_near(quadToTriangles.get_quad_xi_coords(record), {0, 0}, 1e-13);
518
519 record = quadToTriangles.create_record(el, 1);
520 EXPECT_EQ(record.el, el);
521 EXPECT_EQ(record.type, PointClassification::Vert);
522 EXPECT_EQ(record.id, 1);
523 expect_near(quadToTriangles.get_quad_xi_coords(record), {1, 0}, 1e-13);
524
525 record = quadToTriangles.create_record(el, 2);
526 EXPECT_EQ(record.el, el);
527 EXPECT_EQ(record.type, PointClassification::Vert);
528 EXPECT_EQ(record.id, 2);
529 expect_near(quadToTriangles.get_quad_xi_coords(record), {1, 1}, 1e-13);
530
531 record = quadToTriangles.create_record(el, 3);
532 EXPECT_EQ(record.el, el);
533 EXPECT_EQ(record.type, PointClassification::Vert);
534 EXPECT_EQ(record.id, 3);
535 expect_near(quadToTriangles.get_quad_xi_coords(record), {0, 1}, 1e-13);
536 }
537
538
539 TEST(QuadToTriangles, classify_onto)
540 {
541 auto mesh = mesh::make_empty_mesh();
542 auto vert0 = mesh->create_vertex(0, 0, 0);
543 auto vert1 = mesh->create_vertex(1, 0, 0);
544 auto vert2 = mesh->create_vertex(1, 1, 0);
545 auto vert3 = mesh->create_vertex(0, 1, 0);
546 auto vert4 = mesh->create_vertex(0, -1, 0);
547 auto vert5 = mesh->create_vertex(1, -1, 0);
548 auto vert6 = mesh->create_vertex(2, 0, 0);
549 auto vert7 = mesh->create_vertex(2, 1, 0);
550 auto vert8 = mesh->create_vertex(1, 2, 0);
551 auto vert9 = mesh->create_vertex(0, 2, 0);
552 auto vert10 = mesh->create_vertex(-1, 1, 0);
553 auto vert11 = mesh->create_vertex(-1, 0, 0);
554 auto el0 = mesh->create_quad_from_verts(vert0, vert1, vert2, vert3);
555 auto el1 = mesh->create_quad_from_verts(vert0, vert4, vert5, vert1);
556 auto el2 = mesh->create_quad_from_verts(vert1, vert6, vert7, vert2);
557 auto el3 = mesh->create_quad_from_verts(vert3, vert2, vert8, vert9);
558 auto el4 = mesh->create_quad_from_verts(vert0, vert3, vert10, vert11);
559 QuadToTriangles quadToTriangles;
560 quadToTriangles.set_triangles(el0);
561
562 // vertex 1
563 {
564 quadToTriangles.set_triangles(el0);
565 PointRecord record1 = quadToTriangles.create_record(el0, 0);
566 PointRecord record2 = quadToTriangles.classify_onto(record1, el1);
567
568 EXPECT_EQ(record2.el, el1);
569 EXPECT_EQ(record2.type, PointClassification::Vert);
570 EXPECT_EQ(record2.id, 0);
571 quadToTriangles.set_triangles(el1);
572 expect_near(quadToTriangles.compute_xyz_coords(record2), {0, 0, 0}, 1e-13);
573 }
574
575 {
576 quadToTriangles.set_triangles(el0);
577 PointRecord record1 = quadToTriangles.create_record(el0, 0);
578 PointRecord record2 = quadToTriangles.classify_onto(record1, el4);
579
580 EXPECT_EQ(record2.el, el4);
581 EXPECT_EQ(record2.type, PointClassification::Vert);
582 EXPECT_EQ(record2.id, 0);
583 quadToTriangles.set_triangles(el4);
584 expect_near(quadToTriangles.compute_xyz_coords(record2), {0, 0, 0}, 1e-13);
585 }
586
587 // vertex 2
588 {
589 quadToTriangles.set_triangles(el0);
590 PointRecord record1 = quadToTriangles.create_record(el0, 1);
591 PointRecord record2 = quadToTriangles.classify_onto(record1, el1);
592
593 EXPECT_EQ(record2.el, el1);
594 EXPECT_EQ(record2.type, PointClassification::Vert);
595 EXPECT_EQ(record2.id, 3);
596 //quadToTriangles.compute_xyz_coords(record2)
597 quadToTriangles.set_triangles(el1);
598 expect_near(quadToTriangles.compute_xyz_coords(record2), {1, 0, 0}, 1e-13);
599 }
600
601 {
602 quadToTriangles.set_triangles(el0);
603 PointRecord record1 = quadToTriangles.create_record(el0, 1);
604 PointRecord record2 = quadToTriangles.classify_onto(record1, el2);
605
606 EXPECT_EQ(record2.el, el2);
607 EXPECT_EQ(record2.type, PointClassification::Vert);
608 EXPECT_EQ(record2.id, 0);
609 quadToTriangles.set_triangles(el2);
610 expect_near(quadToTriangles.compute_xyz_coords(record2), {1, 0, 0}, 1e-13);
611 }
612
613 // vertex 3
614 {
615 quadToTriangles.set_triangles(el0);
616 PointRecord record1 = quadToTriangles.create_record(el0, 2);
617 PointRecord record2 = quadToTriangles.classify_onto(record1, el2);
618
619 EXPECT_EQ(record2.el, el2);
620 EXPECT_EQ(record2.type, PointClassification::Vert);
621 EXPECT_EQ(record2.id, 3);
622 quadToTriangles.set_triangles(el2);
623 expect_near(quadToTriangles.compute_xyz_coords(record2), {1, 1, 0}, 1e-13);
624 }
625
626
627 {
628 quadToTriangles.set_triangles(el0);
629 PointRecord record1 = quadToTriangles.create_record(el0, 2);
630 PointRecord record2 = quadToTriangles.classify_onto(record1, el3);
631
632 EXPECT_EQ(record2.el, el3);
633 EXPECT_EQ(record2.type, PointClassification::Vert);
634 EXPECT_EQ(record2.id, 1);
635 quadToTriangles.set_triangles(el3);
636 expect_near(quadToTriangles.compute_xyz_coords(record2), {1, 1, 0}, 1e-13);
637 }
638
639 // vertex 4
640 {
641 quadToTriangles.set_triangles(el0);
642 PointRecord record1 = quadToTriangles.create_record(el0, 3);
643 PointRecord record2 = quadToTriangles.classify_onto(record1, el3);
644
645 EXPECT_EQ(record2.el, el3);
646 EXPECT_EQ(record2.type, PointClassification::Vert);
647 EXPECT_EQ(record2.id, 0);
648 quadToTriangles.set_triangles(el3);
649 expect_near(quadToTriangles.compute_xyz_coords(record2), {0, 1, 0}, 1e-13);
650 }
651
652 {
653 quadToTriangles.set_triangles(el0);
654 PointRecord record1 = quadToTriangles.create_record(el0, 3);
655 PointRecord record2 = quadToTriangles.classify_onto(record1, el4);
656
657 EXPECT_EQ(record2.el, el4);
658 EXPECT_EQ(record2.type, PointClassification::Vert);
659 EXPECT_EQ(record2.id, 1);
660 quadToTriangles.set_triangles(el4);
661 expect_near(quadToTriangles.compute_xyz_coords(record2), {0, 1, 0}, 1e-13);
662 }
663
664 // edge 0
665 {
666 quadToTriangles.set_triangles(el0);
667 PointRecord record1 = quadToTriangles.create_record(el0, 0, 0.25);
668 PointRecord record2 = quadToTriangles.classify_onto(record1, el1);
669
670 EXPECT_EQ(record2.el, el1);
671 EXPECT_EQ(record2.type, PointClassification::Edge);
672 EXPECT_EQ(record2.id, 3);
673 quadToTriangles.set_triangles(el1);
674 expect_near(quadToTriangles.compute_xyz_coords(record2), {0.25, 0, 0}, 1e-13);
675 }
676
677 // edge 1
678 {
679 quadToTriangles.set_triangles(el0);
680 PointRecord record1 = quadToTriangles.create_record(el0, 1, 0.25);
681 PointRecord record2 = quadToTriangles.classify_onto(record1, el2);
682
683 EXPECT_EQ(record2.el, el2);
684 EXPECT_EQ(record2.type, PointClassification::Edge);
685 EXPECT_EQ(record2.id, 3);
686 quadToTriangles.set_triangles(el2);
687 expect_near(quadToTriangles.compute_xyz_coords(record2), {1, 0.25, 0}, 1e-13);
688 }
689
690 // edge 2
691 {
692 quadToTriangles.set_triangles(el0);
693 PointRecord record1 = quadToTriangles.create_record(el0, 2, 0.25);
694 PointRecord record2 = quadToTriangles.classify_onto(record1, el3);
695
696 EXPECT_EQ(record2.el, el3);
697 EXPECT_EQ(record2.type, PointClassification::Edge);
698 EXPECT_EQ(record2.id, 0);
699 quadToTriangles.set_triangles(el3);
700 expect_near(quadToTriangles.compute_xyz_coords(record2), {0.75, 1, 0}, 1e-13);
701 }
702
703 // edge 3
704 {
705 quadToTriangles.set_triangles(el0);
706 PointRecord record1 = quadToTriangles.create_record(el0, 3, 0.25);
707 PointRecord record2 = quadToTriangles.classify_onto(record1, el4);
708
709 EXPECT_EQ(record2.el, el4);
710 EXPECT_EQ(record2.type, PointClassification::Edge);
711 EXPECT_EQ(record2.id, 0);
712 quadToTriangles.set_triangles(el4);
713 expect_near(quadToTriangles.compute_xyz_coords(record2), {0, 0.75, 0}, 1e-13);
714 }
715
716 }
717
718 TEST_F(QuadToTrianglesTester, compute_xyz_coords_exterior)
719 {
720 {
721 PointRecordForTriangle r1(PointClassification::Exterior, -1, quadToTriangles.el1, utils::Point(0.5, -0.5));
722 PointRecordForTriangle r2(PointClassification::Exterior, -1, quadToTriangles.el2, utils::Point(0.5, -1.5));
723 PointRecord record(PointClassification::Exterior, -1, el, r1, r2);
724 expect_near(quadToTriangles.compute_xyz_coords(record, true), {0.5, -0.5}, 1e-13);
725 }
726
727 {
728 PointRecordForTriangle r1(PointClassification::Exterior, -1, quadToTriangles.el1, utils::Point(0.5, 1.5));
729 PointRecordForTriangle r2(PointClassification::Exterior, -1, quadToTriangles.el2, utils::Point(0.5, -0.5));
730 PointRecord record(PointClassification::Exterior, -1, el, r1, r2);
731 expect_near(quadToTriangles.compute_xyz_coords(record, true), {0.5, 1.5}, 1e-13);
732 }
733 }
734
735
736
737 } // namespace impl
738 } // namespace middle_mesh
739 } // namespace stk