libMesh
Public Member Functions | List of all members
BBoxTest Class Reference
Inheritance diagram for BBoxTest:
[legend]

Public Member Functions

 CPPUNIT_TEST_SUITE (BBoxTest)
 
 CPPUNIT_TEST (test_one_degenerate)
 
 CPPUNIT_TEST (test_two_degenerate)
 
 CPPUNIT_TEST (test_no_degenerate)
 
 CPPUNIT_TEST (test_signed_distance)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void test_one_degenerate ()
 
void test_two_degenerate ()
 
void test_no_degenerate ()
 
void test_signed_distance ()
 

Detailed Description

Definition at line 10 of file bbox_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/4]

BBoxTest::CPPUNIT_TEST ( test_no_degenerate  )

◆ CPPUNIT_TEST() [2/4]

BBoxTest::CPPUNIT_TEST ( test_one_degenerate  )

◆ CPPUNIT_TEST() [3/4]

BBoxTest::CPPUNIT_TEST ( test_signed_distance  )

◆ CPPUNIT_TEST() [4/4]

BBoxTest::CPPUNIT_TEST ( test_two_degenerate  )

◆ CPPUNIT_TEST_SUITE()

BBoxTest::CPPUNIT_TEST_SUITE ( BBoxTest  )

◆ CPPUNIT_TEST_SUITE_END()

BBoxTest::CPPUNIT_TEST_SUITE_END ( )

◆ setUp()

void BBoxTest::setUp ( )
inline

Definition at line 23 of file bbox_test.C.

23 {}

◆ tearDown()

void BBoxTest::tearDown ( )
inline

Definition at line 25 of file bbox_test.C.

25 {}

◆ test_no_degenerate()

void BBoxTest::test_no_degenerate ( )
inline

Definition at line 149 of file bbox_test.C.

150  {
151  // The smallest number for which 1 and 1 + epsilon compare unequal.
152  const Real eps = std::numeric_limits<Real>::epsilon();
153 
154  // Non-degenerate + Non-degenerate BBox tests. These tests
155  // consider two initially unit-sized bounding boxes "stacked" in
156  // the x, y, and z directions with slight perturbations to bring
157  // them into intersection or not.
158  std::vector<Real>
159  mins = {1, 0, 0},
160  maxs = {2, 1, 1};
161 
162  // All tests use the same unit bounding box for base comparisons.
163  BoundingBox initial(Point(0.,0.,0.), Point(1.,1.,1.));
164 
165  // Make (position, expected-exact-intersection, expected-fuzzy-intersection) tuples
166  typedef std::tuple<Real, bool, bool> TestTuple;
167  std::vector<TestTuple> tests =
168  {
169  std::make_tuple(1., true, true), // on
170  std::make_tuple(1. + eps, false, true), // barely outside
171  std::make_tuple(1. - eps, true, true), // barely inside
172  std::make_tuple(1.5, false, false), // definitely outside
173  std::make_tuple(0.5, true, true) // definitely inside
174  };
175 
176  for (unsigned int dir = 0; dir < 3; ++dir)
177  {
178  // Debugging
179  // std::cout << "dir = " << dir
180  // << ", mins = " << mins[0] << ", " << mins[1] << ", " << mins[2]
181  // << ", maxs = " << maxs[0] << ", " << maxs[1] << ", " << maxs[2]
182  // << std::endl;
183 
184  const Point
185  min(Point(mins[0], mins[1], mins[2])),
186  max(Point(maxs[0], maxs[1], maxs[2]));
187 
188  // Create each degenerate comparison BoundingBox and make
189  // sure the expected intersection result is found.
190  for (const auto & t : tests)
191  {
192  // Create comparison bbox with perturbed minimum coordinate.
193  Point cmin = min, cmax = max;
194  cmin(dir) = std::get<0>(t);
195  BoundingBox comparison(cmin, cmax);
196 
197  // std::cout << "cmin = " << cmin << ", cmax = " << cmax << std::endl;
198 
199  // Exact tests
200  CPPUNIT_ASSERT(initial.intersects(comparison) == std::get<1>(t));
201  CPPUNIT_ASSERT(comparison.intersects(initial) == std::get<1>(t));
202 
203  // Fuzzy tests
204  CPPUNIT_ASSERT(initial.intersects(comparison, /*abstol=*/TOLERANCE) == std::get<2>(t));
205  CPPUNIT_ASSERT(comparison.intersects(initial, /*abstol=*/TOLERANCE) == std::get<2>(t));
206  }
207 
208  // Go to the next cyclic permutation of mins and maxs by
209  // rotating the last entry off the end and onto the front of
210  // the array.
211  std::rotate(mins.rbegin(), mins.rbegin()+1, mins.rend());
212  std::rotate(maxs.rbegin(), maxs.rbegin()+1, maxs.rend());
213  }
214  }

References libMesh::BoundingBox::intersects(), libMesh::Real, libMesh::MeshTools::Modification::rotate(), and libMesh::TOLERANCE.

◆ test_one_degenerate()

void BBoxTest::test_one_degenerate ( )
inline

Definition at line 27 of file bbox_test.C.

28  {
29  // Degenerate + Non-degenerate BBox tests: A unit square bounding
30  // box is intersected with the following degenerate (planar)
31  // bounding boxes:
32  // 1.) well inside the unit bbox
33  // 2.) just barely inside the unit bbox
34  // 3.) on the surface of the unit bbox
35  // 4.) just outside the surface of the unit bbox
36  // 5.) well outside the unit bbox
37  // For the "exact" intersection test: Tests 1-3 should return true, the rest false.
38  // For the "fuzzy" intersection test: Tests 1-4 should return true with large enough TOLERANCE, the rest false.
39 
40  // The smallest number for which 1 and 1 + epsilon compare unequal.
41  const Real eps = std::numeric_limits<Real>::epsilon();
42 
43  // Create unit square non-degenerate BBox for intersection testing.
44  const Point
45  min(0., 0., 0.),
46  max(1., 1., 1.);
47  BoundingBox non_degenerate(min, max);
48 
49  // Make (position, expected-exact-intersection, expected-fuzzy-intersection) tuples
50  typedef std::tuple<Real, bool, bool> TestTuple;
51  std::vector<TestTuple> tests =
52  {
53  std::make_tuple(0.5, true, true), // inside
54  std::make_tuple(1.0 - eps, true, true), // barely inside
55  std::make_tuple(1.0, true, true), // on
56  std::make_tuple(1.0 + eps, false, true), // barely outside
57  std::make_tuple(1.5, false, false) // outside
58  };
59 
60  for (unsigned int dir = 0; dir < 3; ++dir)
61  for (const auto & t : tests)
62  {
63  // Create degenerate bounding box
64  Point dmin = min, dmax = max;
65  dmin(dir) = dmax(dir) = std::get<0>(t);
66  BoundingBox degenerate(dmin, dmax);
67 
68  // std::cout << "degenerate.min() = " << degenerate.min() << std::endl;
69  // std::cout << "degenerate.max() = " << degenerate.max() << std::endl;
70 
71  // Exact tests
72  CPPUNIT_ASSERT(non_degenerate.intersects(degenerate) == std::get<1>(t));
73  CPPUNIT_ASSERT(degenerate.intersects(non_degenerate) == std::get<1>(t));
74 
75  // Fuzzy tests
76  CPPUNIT_ASSERT(non_degenerate.intersects(degenerate, /*abstol=*/TOLERANCE) == std::get<2>(t));
77  CPPUNIT_ASSERT(degenerate.intersects(non_degenerate, /*abstol=*/TOLERANCE) == std::get<2>(t));
78  }
79  }

References libMesh::BoundingBox::intersects(), libMesh::Real, and libMesh::TOLERANCE.

◆ test_signed_distance()

void BBoxTest::test_signed_distance ( )
inline

Definition at line 216 of file bbox_test.C.

217  {
218  // A "unit" size bounding box for making distance comparisons.
219  BoundingBox unit(Point(0.,0.,0.), Point(1.,1.,1.));
220 
221  // Test points inside the box
222  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(0.5, 0.5, 0.5)), -0.5, TOLERANCE * TOLERANCE);
223  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(0.5, 0.6, 0.5)), -0.4, TOLERANCE * TOLERANCE);
224  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(0.4, 0.5, 0.5)), -0.4, TOLERANCE * TOLERANCE);
225  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(0.1, 0.1, 0.1)), -0.1, TOLERANCE * TOLERANCE);
226 
227  // Test points on the box
228  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(1.0, 0.5, 0.5)), 0., TOLERANCE * TOLERANCE);
229  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(1.0, 0., 0.)), 0., TOLERANCE * TOLERANCE);
230 
231  // Test points outside the box
232  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(1.5, 0.5, 0.5)), 0.5, TOLERANCE * TOLERANCE); // right
233  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(-0.5, 0.5, 0.5)), 0.5, TOLERANCE * TOLERANCE); // left
234  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(0.5, 0.5, 1.5)), 0.5, TOLERANCE * TOLERANCE); // above
235  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(0.5, 0.5, -0.5)), 0.5, TOLERANCE * TOLERANCE); // below
236  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(0.5, -0.5, 0.5)), 0.5, TOLERANCE * TOLERANCE); // front
237  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(0.5, 1.5, 0.5)), 0.5, TOLERANCE * TOLERANCE); // back
238 
239  // Outside the box, closest to a corner.
240  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(2., 2., 2.)), std::sqrt(Real(3)), TOLERANCE * TOLERANCE); // Point along line (0,0,0) -> (1,1,1)
241  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(-1., -1., -1.)), std::sqrt(Real(3)), TOLERANCE * TOLERANCE); // Point along line (0,0,0) -> (1,1,1)
242  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(1.5, 1.5, -0.5)), std::sqrt(Real(3))/2., TOLERANCE * TOLERANCE); // Point along line (0.5,0.5,0.5) -> (1,1,0)
243  LIBMESH_ASSERT_FP_EQUAL(unit.signed_distance(Point(1.5, -0.5, -0.5)), std::sqrt(Real(3))/2., TOLERANCE * TOLERANCE); // Point along line (0.5,0.5,0.5) -> (1,0,0)
244  }

References libMesh::Real, libMesh::BoundingBox::signed_distance(), std::sqrt(), and libMesh::TOLERANCE.

◆ test_two_degenerate()

void BBoxTest::test_two_degenerate ( )
inline

Definition at line 81 of file bbox_test.C.

82  {
83  // Degenerate + Degenerate BBox tests: test intersections of unit
84  // square degenerate (planar) bounding boxes in the x, y, and z
85  // directions in the following cases:
86  // 1.) Comparison BBox right on top of the original BBox.
87  // 2.) Comparison BBox slightly to the "left" of the original BBox.
88  // 3.) Comparison BBox slightly to the "right" of the original BBox.
89  // 4.) Comparison BBox far away from the original BBox.
90 
91  // The smallest number for which 1 and 1 + epsilon compare unequal.
92  const Real eps = std::numeric_limits<Real>::epsilon();
93  // To test intersections of degenerate x, y, and z plane BBoxes,
94  // we start with an x-plane and then permute the entries of
95  // these vectors to subsequently test in the y and z directions.
96  std::vector<Real>
97  mins = {0.5, 0, 0},
98  maxs = {.5, 1, 1};
99 
100  // Make (position, expected-exact-intersection, expected-fuzzy-intersection) tuples
101  typedef std::tuple<Real, bool, bool> TestTuple;
102  std::vector<TestTuple> tests =
103  {
104  std::make_tuple(0.5, true, true), // on
105  std::make_tuple(0.5 - eps, false, true), // barely left
106  std::make_tuple(0.5 + eps, false, true), // barely right
107  std::make_tuple(1.0, false, false) // off
108  };
109 
110  for (unsigned int dir = 0; dir < 3; ++dir)
111  {
112  // Debugging
113  // std::cout << "dir = " << dir
114  // << ", mins = " << mins[0] << ", " << mins[1] << ", " << mins[2]
115  // << ", maxs = " << maxs[0] << ", " << maxs[1] << ", " << maxs[2]
116  // << std::endl;
117 
118  const Point
119  min(Point(mins[0], mins[1], mins[2])),
120  max(Point(maxs[0], maxs[1], maxs[2]));
121  BoundingBox initial(min, max);
122 
123  // Create each degenerate comparison BoundingBox and make
124  // sure the expected intersection result is found.
125  for (const auto & t : tests)
126  {
127  // Create comparison bbox
128  Point cmin = min, cmax = max;
129  cmin(dir) = cmax(dir) = std::get<0>(t);
130  BoundingBox comparison(cmin, cmax);
131 
132  // Exact tests
133  CPPUNIT_ASSERT(initial.intersects(comparison) == std::get<1>(t));
134  CPPUNIT_ASSERT(comparison.intersects(initial) == std::get<1>(t));
135 
136  // Fuzzy tests
137  CPPUNIT_ASSERT(initial.intersects(comparison, /*abstol=*/TOLERANCE) == std::get<2>(t));
138  CPPUNIT_ASSERT(comparison.intersects(initial, /*abstol=*/TOLERANCE) == std::get<2>(t));
139  }
140 
141  // Go to the next cyclic permutation of mins and maxs by
142  // rotating the last entry off the end and onto the front of
143  // the array.
144  std::rotate(mins.rbegin(), mins.rbegin()+1, mins.rend());
145  std::rotate(maxs.rbegin(), maxs.rbegin()+1, maxs.rend());
146  }
147  }

References libMesh::BoundingBox::intersects(), libMesh::Real, libMesh::MeshTools::Modification::rotate(), and libMesh::TOLERANCE.


The documentation for this class was generated from the following file:
libMesh::BoundingBox
Defines a Cartesian bounding box by the two corner extremum.
Definition: bounding_box.h:40
std::sqrt
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
libMesh::MeshTools::Modification::rotate
void rotate(MeshBase &mesh, const Real phi, const Real theta=0., const Real psi=0.)
Definition: mesh_modification.C:209
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121