VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
GbTriFaceMesh3DDedupTest.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34
35#include <gmock/gmock.h>
36
37#include <cmath>
38
40
42{
43 GbTriFaceMesh3D mesh;
44 auto *nodes = mesh.getNodes();
45 auto *tris = mesh.getTriangles();
46 nodes->clear();
47 tris->clear();
48
49 auto addVertex = [&](float x, float y, float z) {
51 v.x = x;
52 v.y = y;
53 v.z = z;
54 nodes->push_back(v);
55 };
56
57 addVertex(0.0f, 0.0f, 0.0f); // 0
58 addVertex(1.0f, 0.0f, 0.0f); // 1
59 addVertex(0.0f, 1.0f, 0.0f); // 2
60 addVertex(0.0f, 0.0f, 0.0f); // 3 (duplicate)
61 addVertex(1.0f, 0.0f, 0.0f); // 4 (duplicate)
62 addVertex(2.0f, 0.0f, 0.0f); // 5 (colinear)
63
64 tris->emplace_back(0, 1, 2); // valid
65 tris->emplace_back(3, 4, 2); // duplicate vertices -> should map to (0,1,2)
66 tris->emplace_back(0, 0, 1); // duplicate index
67 tris->emplace_back(0, 1, 4); // becomes duplicate index after dedup
68 tris->emplace_back(0, 1, 5); // colinear
69
71
72 ASSERT_EQ(nodes->size(), 4u);
73 ASSERT_EQ(tris->size(), 2u);
74
75 for (auto &tri : *tris) {
76 EXPECT_NE(tri.getIndexVertex1(), tri.getIndexVertex2());
77 EXPECT_NE(tri.getIndexVertex1(), tri.getIndexVertex3());
78 EXPECT_NE(tri.getIndexVertex2(), tri.getIndexVertex3());
79 EXPECT_LT(tri.getIndexVertex1(), static_cast<int>(nodes->size()));
80 EXPECT_LT(tri.getIndexVertex2(), static_cast<int>(nodes->size()));
81 EXPECT_LT(tri.getIndexVertex3(), static_cast<int>(nodes->size()));
82
83 const double area = tri.getArea(*nodes);
84 EXPECT_GT(area, 1.0e-6);
85 }
86
87 {
89 auto *nodes2 = mesh2.getNodes();
90 auto *tris2 = mesh2.getTriangles();
91 nodes2->clear();
92 tris2->clear();
93
94 auto addVertex2 = [&](float x, float y, float z) {
96 v.x = x;
97 v.y = y;
98 v.z = z;
99 nodes2->push_back(v);
100 };
101
102 const float eps = 1.0e-7f;
103 addVertex2(0.0f, 0.0f, 0.0f); // 0
104 addVertex2(0.49f * eps, 0.0f, 0.0f); // 1 (merge with 0)
105 addVertex2(0.51f * eps, 0.0f, 0.0f); // 2 (distinct)
106 addVertex2(1.0f, 0.0f, 0.0f); // 3
107 addVertex2(0.0f, 1.0f, 0.0f); // 4
108
109 tris2->emplace_back(0, 3, 4);
110 tris2->emplace_back(1, 3, 4);
111 tris2->emplace_back(2, 3, 4);
112
113 mesh2.deleteRedundantNodes();
114
115 ASSERT_EQ(nodes2->size(), 4u);
116 ASSERT_EQ(tris2->size(), 3u);
117
118 const double expectedX = 0.51e-7;
119 bool foundDistinct = false;
120 for (const auto &node : *nodes2) {
121 if (std::abs(static_cast<double>(node.x) - expectedX) < 1.0e-10 &&
122 std::abs(static_cast<double>(node.y)) < 1.0e-12 &&
123 std::abs(static_cast<double>(node.z)) < 1.0e-12) {
124 foundDistinct = true;
125 break;
126 }
127 }
129 }
130
131 {
133 auto *nodes3 = mesh3.getNodes();
134 auto *tris3 = mesh3.getTriangles();
135 nodes3->clear();
136 tris3->clear();
137
138 auto addVertex3 = [&](float x, float y, float z) {
140 v.x = x;
141 v.y = y;
142 v.z = z;
143 nodes3->push_back(v);
144 };
145
146 const float height = 5.1e-8f;
147 addVertex3(0.0f, 0.0f, 0.0f); // 0
148 addVertex3(1.0e-4f, 0.0f, 0.0f); // 1 (below area threshold)
149 addVertex3(3.0e-2f, 0.0f, 0.0f); // 2 (above area threshold)
150 addVertex3(0.0f, height, 0.0f); // 3
151
152 tris3->emplace_back(0, 1, 3);
153 tris3->emplace_back(0, 2, 3);
154
155 mesh3.deleteRedundantNodes();
156
157 ASSERT_EQ(nodes3->size(), 4u);
158 ASSERT_EQ(tris3->size(), 1u);
159 const double area = (*tris3)[0].getArea(*nodes3);
160 EXPECT_GT(area, 1.0e-11);
161 }
162}
163
std::shared_ptr< T > SPtr
std::vector< Vertex > * getNodes()
std::vector< TriFace > * getTriangles()
@ z
Definition Axis.h:44
@ x
Definition Axis.h:42
@ y
Definition Axis.h:43
TEST(GbTriFaceMesh3DDedupTest, RemovesDuplicateVerticesAndDegenerateTriangles)