Debian Codegraph @

packages/stk/stk_unit_tests/stk_middle_mesh/test_geo_classification.cpp

raw
1
2 #include "stk_middle_mesh/create_mesh.hpp"
3 #include "stk_middle_mesh/mesh.hpp"
4 #include "stk_middle_mesh/mesh_geo_classifier.hpp"
5 #include "gtest/gtest.h"
6
7 namespace stk {
8 namespace middle_mesh {
9 namespace impl {
10
11 using namespace mesh;
12 using namespace mesh::impl;
13 using namespace utils::impl;
14
15 namespace {
16 enum class GeoClassificationE
17 {
18 Vertex = 0,
19 Edge,
20 Face
21 };
22
23 GeoClassificationE get_geo_classification(const MeshSpec& spec, const utils::Point& pt)
24 {
25 double eps = 1e-12;
26 auto x = pt.get_x();
27 auto y = pt.get_y();
28 bool isXmin = std::abs(x - spec.xmin) < eps;
29 bool isXmax = std::abs(x - spec.xmax) < eps;
30 bool isYmin = std::abs(y - spec.ymin) < eps;
31 bool isYmax = std::abs(y - spec.ymax) < eps;
32
33 if ((isXmin && isYmin) || (isXmin && isYmax) || (isXmax && isYmin) || (isXmax && isYmax))
34 return GeoClassificationE::Vertex;
35 else if (isXmin || isXmax || isYmin || isYmax)
36 return GeoClassificationE::Edge;
37 else
38 return GeoClassificationE::Face;
39 }
40
41 } // namespace
42
43 TEST(GeoClassification, Square)
44 {
45 if (utils::impl::comm_size(MPI_COMM_WORLD) != 1)
46 GTEST_SKIP();
47
48 MeshSpec spec;
49 spec.numelX = 3;
50 spec.numelY = 4;
51 spec.xmin = 0;
52 spec.xmax = 1;
53 spec.ymin = 0;
54 spec.ymax = 1;
55
56 auto func = [&](const utils::Point& pt) { return pt; };
57
58 std::shared_ptr<Mesh> mesh = create_mesh(spec, func);
59
60 MeshGeoClassifier classifier;
61 classifier.classify(mesh);
62
63 // test the dimensions are correct
64 for (auto& v : mesh->get_vertices())
65 {
66 int dim = static_cast<int>(get_geo_classification(spec, v->get_point_orig(0)));
67 EXPECT_EQ(mesh->get_geo_class(v).dim, dim);
68 }
69
70 // check vert ids are unique
71 std::vector<MeshEntityPtr> verts;
72 for (auto& v : mesh->get_vertices())
73 if (mesh->get_geo_class(v).dim == 0)
74 verts.push_back(v);
75
76 for (auto& v1 : verts)
77 for (auto& v2 : verts)
78 if (v1 != v2)
79 {
80 EXPECT_FALSE(mesh->get_geo_class(v1).id == mesh->get_geo_class(v2).id);
81 }
82
83 // test edges
84 for (auto& edge : mesh->get_edges())
85 {
86 auto g = mesh->get_geo_class(edge);
87 if (edge->count_up() == 1)
88 {
89 auto pt1 = edge->get_down(0)->get_point_orig(0);
90 auto pt2 = edge->get_down(1)->get_point_orig(0);
91 auto pt = 0.5 * (pt1 + pt2);
92 double eps = 1e-13;
93 bool isXmin = std::abs(pt.x - spec.xmin) < eps;
94 bool isXmax = std::abs(pt.x - spec.xmax) < eps;
95 bool isYmin = std::abs(pt.y - spec.ymin) < eps;
96 bool isYmax = std::abs(pt.y - spec.ymax) < eps;
97
98 EXPECT_EQ(g.dim, 1);
99 if (isYmin)
100 EXPECT_EQ(g.id, 0);
101 else if (isXmax)
102 EXPECT_EQ(g.id, 1);
103 else if (isYmax)
104 EXPECT_EQ(g.id, 2);
105 else if (isXmin)
106 EXPECT_EQ(g.id, 3);
107 else
108 assert(false);
109 } else
110 {
111 EXPECT_EQ(g, GeoClassification(2, 0));
112 }
113 }
114 }
115
116 } // namespace impl
117 } // namespace middle_mesh
118 } // namespace stk