preCICE v3.1.2
Loading...
Searching...
No Matches
BoundingBoxTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <algorithm>
3#include <vector>
4#include "logging/Logger.hpp"
6#include "mesh/Vertex.hpp"
8#include "testing/Testing.hpp"
9
10using namespace precice;
11using namespace precice::mesh;
12
13BOOST_AUTO_TEST_SUITE(MeshTests)
14BOOST_AUTO_TEST_SUITE(BoundingBoxTests)
15
17{
18 PRECICE_TEST(1_rank);
19 { // 3D
20 Eigen::VectorXd boundMin(3);
21 boundMin << 1.0, 2.0, 3.0;
22 Eigen::VectorXd boundMax(3);
23 boundMax << 4.0, 5.0, 6.0;
24 BoundingBox bb(boundMin, boundMax);
25
26 BOOST_TEST(bb.getDimension() == 3);
27 BOOST_TEST(bb.minCorner() == boundMin);
28 BOOST_TEST(bb.maxCorner() == boundMax);
29 }
30 { // 2D
31 Eigen::VectorXd boundMin(2);
32 boundMin << 1.0, 2.0;
33 Eigen::VectorXd boundMax(2);
34 boundMax << 4.0, 5.0;
35 BoundingBox bb(boundMin, boundMax);
36
37 BOOST_TEST(bb.getDimension() == 2);
38 BOOST_TEST(bb.minCorner() == boundMin);
39 BOOST_TEST(bb.maxCorner() == boundMax);
40 }
41} // Constructor
42
43BOOST_AUTO_TEST_CASE(ExpandByBoundingBox)
44{
45 PRECICE_TEST(1_rank);
46 { // 3D
47 BoundingBox bb1({0.0, 1.0,
48 0.0, 1.0,
49 0.0, 1.0});
50 BoundingBox bb2({-1.0, 0.5,
51 2.0, 3.5,
52 0.0, 4.0});
53 bb1.expandBy(bb2);
54 std::vector<double> compareData = {-1.0, 1.0,
55 0.0, 3.5,
56 0.0, 4.0};
57 BOOST_TEST(bb1.dataVector() == compareData);
58 }
59 { // 2D
60 BoundingBox bb1({0.0, 2.0,
61 -1.0, 1.0});
62 BoundingBox bb2({-1.0, 0.5,
63 2.0, 3.5});
64 bb1.expandBy(bb2);
65 std::vector<double> compareData = {-1.0, 2.0,
66 -1.0, 3.5};
67 BOOST_TEST(bb1.dataVector() == compareData);
68 }
69} // ExpandByBoundingBox
70
71BOOST_AUTO_TEST_CASE(ExpandByVertex)
72{
73 PRECICE_TEST(1_rank);
74 { // 3D
75 BoundingBox bb({0.0, 1.0,
76 0.0, 1.0,
77 0.0, 1.0});
78 Vertex v1(Eigen::Vector3d(-1.0, 3.0, 0.5), 0);
79 bb.expandBy(v1);
80 std::vector<double> compareData = {-1.0, 1.0,
81 0.0, 3.0,
82 0.0, 1.0};
83 BOOST_TEST(bb.dataVector() == compareData);
84 }
85 { // 2D
86 BoundingBox bb({-2.0, 1.0,
87 2.0, 4.0});
88 Vertex v1(Eigen::Vector2d(-4.0, 2.0), 0);
89 bb.expandBy(v1);
90 std::vector<double> compareData = {-4.0, 1.0,
91 2.0, 4.0};
92 BOOST_TEST(bb.dataVector() == compareData);
93 }
94} // ExpandByVertex
95
96BOOST_AUTO_TEST_CASE(ExpandByRadius)
97{
98 PRECICE_TEST(1_rank);
99 { // 3D
100 BoundingBox bb({0.0, 1.0,
101 0.5, 2.0,
102 -1.0, 3.0});
103 double supportRadius = 1.0;
104 bb.expandBy(supportRadius);
105 std::vector<double> compareData = {-1.0, 2.0,
106 -0.5, 3.0,
107 -2.0, 4.0};
108 BOOST_TEST(bb.dataVector() == compareData);
109 }
110 { // 2D
111 BoundingBox bb({-2.0, 1.0,
112 0.5, 2.0});
113 double supportRadius = 1.0;
114 bb.expandBy(supportRadius);
115 std::vector<double> compareData = {-3.0, 2.0,
116 -0.5, 3.0};
117 BOOST_TEST(bb.dataVector() == compareData);
118 }
119} // ExpandByRadius
120
122{
123 PRECICE_TEST(1_rank);
124 { // 3D
125 BoundingBox bb1({-1.0, 1.0,
126 0.5, 2.0,
127 1.0, 1.5});
128 double safetyFactor = 2.0;
129 bb1.scaleBy(safetyFactor);
130 std::vector<double> compareData = {-5.0, 5.0,
131 -3.5, 6.0,
132 -3.0, 5.5};
133 BOOST_TEST(bb1.dataVector() == compareData);
134 }
135 { // 2D
136 BoundingBox bb1({-1.0, 1.0,
137 0.5, 2.0});
138 double safetyFactor = 2.0;
139 bb1.scaleBy(safetyFactor);
140 std::vector<double> compareData = {-5.0, 5.0,
141 -3.5, 6.0};
142 BOOST_TEST(bb1.dataVector() == compareData);
143 }
144} // Scaling
145
146BOOST_AUTO_TEST_CASE(CenterOfGravity)
147{
148 PRECICE_TEST(1_rank);
149 { // 3D
150 BoundingBox bb({0.0, 1.0,
151 -1.0, 3.0,
152 2.0, 4.0});
153
154 Eigen::Vector3d compareCOG(0.5, 1.0, 3.0);
155 BOOST_TEST(compareCOG == bb.center());
156 }
157 { // 2D
158 BoundingBox bb({0.0, 1.0,
159 -2.0, 5.0});
160
161 Eigen::Vector2d compareCOG(0.5, 1.5);
162 BOOST_TEST(compareCOG == bb.center());
163 }
164} // CenterOfGravity
165
167{
168 PRECICE_TEST(1_rank);
169 { // 3D
170 BoundingBox bb({0.0, 1.0,
171 -1.0, 3.0,
172 2.0, 4.0});
173
174 Eigen::Vector3d compareMin(0.0, -1.0, 2.0);
175 Eigen::Vector3d compareMax(1.0, 3.0, 4.0);
176 BOOST_TEST(compareMin == bb.minCorner());
177 BOOST_TEST(compareMax == bb.maxCorner());
178 }
179 { // 2D
180 BoundingBox bb({-1.0, 3.0,
181 2.0, 4.0});
182
183 Eigen::Vector2d compareMin(-1.0, 2.0);
184 Eigen::Vector2d compareMax(3.0, 4.0);
185 BOOST_TEST(compareMin == bb.minCorner());
186 BOOST_TEST(compareMax == bb.maxCorner());
187 }
188} // CenterOfGravity
189
191{
192 PRECICE_TEST(1_rank);
193 { // 3D
194 BoundingBox bb({0.0, 1.0,
195 -1.0, 3.0,
196 2.0, 4.0});
197
198 BOOST_TEST(bb.getEdgeLength(0) == 1.0);
199 BOOST_TEST(bb.getEdgeLength(1) == 4.0);
200 BOOST_TEST(bb.getEdgeLength(2) == 2.0);
201
202 BOOST_TEST(bb.longestEdgeLength() == 4.0);
203 }
204 { // 2D
205 BoundingBox bb({-1.0, 3.0,
206 2.0, 4.0});
207
208 BOOST_TEST(bb.getEdgeLength(0) == 4.0);
209 BOOST_TEST(bb.getEdgeLength(1) == 2.0);
210
211 BOOST_TEST(bb.longestEdgeLength() == 4.0);
212 }
213}
214
216{
217 PRECICE_TEST(1_rank);
218 { // 3D
219 BoundingBox bb({0.0, 1.0,
220 -1.0, 3.0,
221 2.0, 4.0});
222 {
223 std::vector<bool> deadAxis = {false, false, true};
224 double compareArea = 4.0;
225 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
226 }
227 {
228 std::vector<bool> deadAxis = {false, true, false};
229 double compareArea = 2.0;
230 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
231 }
232 {
233 std::vector<bool> deadAxis = {true, false, false};
234 double compareArea = 8.0;
235 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
236 }
237 {
238 std::vector<bool> deadAxis = {false, false, false};
239 double compareArea = 8.0;
240 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
241 }
242 }
243 { // 2D
244 BoundingBox bb({0.0, 1.0,
245 -1.0, 3.0});
246 {
247 std::vector<bool> deadAxis = {false, true};
248 double compareArea = 1.0;
249 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
250 }
251 {
252 std::vector<bool> deadAxis = {true, false};
253 double compareArea = 4.0;
254 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
255 }
256 {
257 std::vector<bool> deadAxis = {false, false};
258 double compareArea = 4.0;
259 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
260 }
261 }
262} // Area
263
265{
266 PRECICE_TEST(1_rank);
267 { // 3D
268 BoundingBox bb1({0.0, 1.0,
269 -1.0, 3.0,
270 2.0, 4.0});
271 BoundingBox bb2({-1.0, 0.5,
272 2.0, 5.0,
273 1.0, 3.0});
274 BoundingBox bb3({2.0, 5.0,
275 4.0, 5.0,
276 0.0, 1.0});
277
278 BOOST_TEST(bb1.overlapping(bb2));
279 BOOST_TEST(!bb1.overlapping(bb3));
280 }
281 { // 2D
282 BoundingBox bb1({0.0, 1.0,
283 -1.0, 3.0});
284 BoundingBox bb2({-1.0, 0.5,
285 2.0, 5.0});
286 BoundingBox bb3({2.0, 5.0,
287 4.0, 5.0});
288
289 BOOST_TEST(bb1.overlapping(bb2));
290 BOOST_TEST(!bb1.overlapping(bb3));
291 }
292} // Overalapping
293
295{
296 PRECICE_TEST(1_rank);
297 { // 3D
298 BoundingBox bb1({0.0, 1.0,
299 -1.0, 3.0,
300 2.0, 4.0});
301 BoundingBox bb2({0.0, 1.0,
302 -1.0, 3.0,
303 2.0, 4.0});
304 BoundingBox bb3({2.0, 5.0,
305 4.0, 5.0,
306 0.0, 1.0});
307
308 BOOST_TEST(bb1 == bb2);
309 BOOST_TEST(!(bb1 == bb3));
310 }
311 { // 2D
312 BoundingBox bb1({0.0, 1.0,
313 -1.0, 3.0});
314 BoundingBox bb2({0.0, 1.0,
315 -1.0, 3.0});
316 BoundingBox bb3({2.0, 5.0,
317 4.0, 5.0});
318
319 BOOST_TEST(bb1 == bb2);
320 BOOST_TEST(!(bb1 == bb3));
321 }
322} // Comparison
323
325{
326 PRECICE_TEST(1_rank);
327 { // 3D
328 BoundingBox bb({0.0, 1.0,
329 -1.0, 3.0,
330 2.0, 4.0});
331 Vertex v1(Eigen::Vector3d(0.2, 1.0, 3.0), 0);
332 Vertex v2(Eigen::Vector3d(1.2, -2.0, 5.0), 0);
333
334 BOOST_TEST(bb.contains(v1));
335 BOOST_TEST(!bb.contains(v2));
336 }
337 { // 2D
338 BoundingBox bb({0.0, 1.0,
339 -1.0, 3.0});
340 Vertex v1(Eigen::Vector2d(0.2, 1.0), 0);
341 Vertex v2(Eigen::Vector2d(1.2, -2.0), 0);
342
343 BOOST_TEST(bb.contains(v1));
344 BOOST_TEST(!bb.contains(v2));
345 }
346 { // 3D Point
347 BoundingBox bb({0.0, 0.0, 0.0, 0.0, 0.0, 0.0});
348 Vertex v1(Eigen::Vector3d(0.0, 0.0, 0.0), 0);
349 Vertex v2(Eigen::Vector3d(1.2, -2.0, 1.0), 0);
350
351 BOOST_TEST(bb.contains(v1));
352 BOOST_TEST(!bb.contains(v2));
353 }
354 { // 2D Point
355 BoundingBox bb({0.0, 0.0, 0.0, 0.0});
356 Vertex v1(Eigen::Vector2d(0.0, 0.0), 0);
357 Vertex v2(Eigen::Vector2d(1.2, -2.0), 0);
358
359 BOOST_TEST(bb.contains(v1));
360 BOOST_TEST(!bb.contains(v2));
361 }
362} // Contains
363
365{
366 PRECICE_TEST(1_rank);
367 { // 3D
368 BoundingBox bb1({0.0, 1.0,
369 -1.0, 3.0,
370 2.0, 4.0});
371 BoundingBox bb2(3);
372
373 BOOST_TEST(!bb1.isDefault());
374 BOOST_TEST(bb2.isDefault());
375 }
376 { // 2D
377 BoundingBox bb1({0.0, 1.0,
378 -1.0, 3.0});
379 BoundingBox bb2(2);
380
381 BOOST_TEST(!bb1.isDefault());
382 BOOST_TEST(bb2.isDefault());
383 }
384} // DefaultCase
385
387{
388 PRECICE_TEST(1_rank);
389 { // 3D
390 BoundingBox bb1({0.0, 1.0,
391 -1.0, 3.0,
392 2.0, 4.0});
393 BoundingBox bb2(3);
394 BoundingBox bb3({1.0, 1.0,
395 1.0, 1.0,
396 1.0, 1.0});
397 BOOST_TEST(!bb1.empty());
398 BOOST_TEST(bb2.empty());
399 BOOST_TEST(bb3.empty());
400 }
401 { // 2D
402 BoundingBox bb1({0.0, 1.0,
403 -1.0, 3.0});
404 BoundingBox bb2(2);
405 BoundingBox bb3({2.0, 2.0,
406 1.0, 1.0});
407 BOOST_TEST(!bb1.empty());
408 BOOST_TEST(bb2.empty());
409 BOOST_TEST(bb3.empty());
410 }
411} // EmptyCase
412
413BOOST_AUTO_TEST_SUITE_END() // BoundingBox
BOOST_AUTO_TEST_CASE(Constructor)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
An axis-aligned bounding box around a (partition of a) mesh.
Eigen::VectorXd maxCorner() const
the max corner of the bounding box
Eigen::VectorXd minCorner() const
the min corner of the bounding box
void expandBy(const BoundingBox &otherBB)
Expand bounding box using another bounding box.
int getDimension() const
Getter dimension of the bounding box.
void scaleBy(double safetyFactor)
Increase the size of bounding box by safety margin.
Vertex of a mesh.
Definition Vertex.hpp:16
provides Mesh, Data and primitives.
Main namespace of the precice library.