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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (ContainsPointTest)
 The goal of this test is to verify proper operation of the contains_point method that is used extensively in the point locator. More...
 
 CPPUNIT_TEST (testContainsPointNodeElem)
 
 CPPUNIT_TEST (testContainsPointTri3)
 
 CPPUNIT_TEST (testContainsPointTet4)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testContainsPointNodeElem ()
 
void testContainsPointTri3 ()
 
void testContainsPointTet4 ()
 

Protected Member Functions

void containsPointTri3Helper (Point a_in, Point b_in, Point c_in, Point p)
 

Detailed Description

Definition at line 10 of file contains_point.C.

Member Function Documentation

◆ containsPointTri3Helper()

void ContainsPointTest::containsPointTri3Helper ( Point  a_in,
Point  b_in,
Point  c_in,
Point  p 
)
inlineprotected

Definition at line 138 of file contains_point.C.

References libMesh::Elem::build(), libMesh::TypeVector< T >::cross(), libMesh::TOLERANCE, libMesh::TRI3, and libMesh::TypeVector< T >::unit().

139  {
140  // vertices
141  Node a(a_in, 0);
142  Node b(b_in, 1);
143  Node c(c_in, 2);
144 
145  // Build the test Elem
146  std::unique_ptr<Elem> elem = Elem::build(TRI3);
147 
148  elem->set_node(0, &a);
149  elem->set_node(1, &b);
150  elem->set_node(2, &c);
151 
152  // helper vectors to span the tri and point out of plane
153  Point va(a-c);
154  Point vb(b-c);
155  Point oop(va.cross(vb));
156  Point oop_unit = oop.unit();
157 
158  // The centroid (equal to vertex average for Tri3) must be inside the element.
159  CPPUNIT_ASSERT (elem->contains_point(elem->vertex_average()));
160 
161  // triangle should contain all its vertices
162  CPPUNIT_ASSERT (elem->contains_point(a));
163  CPPUNIT_ASSERT (elem->contains_point(b));
164  CPPUNIT_ASSERT (elem->contains_point(c));
165 
166  // out of plane from the centroid, should *not* be in the element
167  CPPUNIT_ASSERT (!elem->contains_point(elem->vertex_average() + std::sqrt(TOLERANCE) * oop_unit));
168 
169  // These points should be outside the triangle
170  CPPUNIT_ASSERT (!elem->contains_point(a + va * TOLERANCE * 10));
171  CPPUNIT_ASSERT (!elem->contains_point(b + vb * TOLERANCE * 10));
172  CPPUNIT_ASSERT (!elem->contains_point(c - (va + vb) * TOLERANCE * 10));
173 
174  // Test the custom point
175  CPPUNIT_ASSERT (elem->contains_point(p));
176  }
A Node is like a Point, but with more information.
Definition: node.h:52
static constexpr Real TOLERANCE
TypeVector< T > unit() const
Definition: type_vector.h:1104
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

◆ CPPUNIT_TEST() [1/3]

ContainsPointTest::CPPUNIT_TEST ( testContainsPointNodeElem  )

◆ CPPUNIT_TEST() [2/3]

ContainsPointTest::CPPUNIT_TEST ( testContainsPointTri3  )

◆ CPPUNIT_TEST() [3/3]

ContainsPointTest::CPPUNIT_TEST ( testContainsPointTet4  )

◆ CPPUNIT_TEST_SUITE_END()

ContainsPointTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

ContainsPointTest::LIBMESH_CPPUNIT_TEST_SUITE ( ContainsPointTest  )

The goal of this test is to verify proper operation of the contains_point method that is used extensively in the point locator.

This test focuses on the specializes contains_point implementation in TRI3.

◆ setUp()

void ContainsPointTest::setUp ( )
inline

Definition at line 29 of file contains_point.C.

29 {}

◆ tearDown()

void ContainsPointTest::tearDown ( )
inline

Definition at line 31 of file contains_point.C.

31 {}

◆ testContainsPointNodeElem()

void ContainsPointTest::testContainsPointNodeElem ( )
inline

Definition at line 34 of file contains_point.C.

References libMesh::Elem::build(), libMesh::NODEELEM, and libMesh::Real.

35  {
36  Node node (1., 1., 1., /*id=*/0);
37  std::unique_ptr<Elem> elem = Elem::build(NODEELEM);
38  elem->set_node(0, &node);
39 
40  Real epsilon = 1.e-4;
41  CPPUNIT_ASSERT(elem->contains_point(Point(1.+epsilon/2, 1.-epsilon/2, 1+epsilon/2), /*tol=*/epsilon));
42  CPPUNIT_ASSERT(!elem->contains_point(Point(1.+epsilon/2, 1.-epsilon/2, 1+epsilon/2), /*tol=*/epsilon/2));
43  }
A Node is like a Point, but with more information.
Definition: node.h:52
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

◆ testContainsPointTet4()

void ContainsPointTest::testContainsPointTet4 ( )
inline

Definition at line 66 of file contains_point.C.

References libMesh::Elem::build(), libMesh::Real, libMesh::TET4, and libMesh::zero.

67  {
68  LOG_UNIT_TEST;
69 
70  // Construct unit Tet.
71  {
72  Node zero (0., 0., 0., 0);
73  Node one (1., 0., 0., 1);
74  Node two (0., 1., 0., 2);
75  Node three (0., 0., 1., 3);
76 
77  std::unique_ptr<Elem> elem = Elem::build(TET4);
78  elem->set_node(0, &zero);
79  elem->set_node(1, &one);
80  elem->set_node(2, &two);
81  elem->set_node(3, &three);
82 
83  // The centroid (equal to vertex average for Tet4) must be inside the element.
84  CPPUNIT_ASSERT (elem->contains_point(elem->vertex_average()));
85 
86  // The vertices must be contained in the element.
87  CPPUNIT_ASSERT (elem->contains_point(zero));
88  CPPUNIT_ASSERT (elem->contains_point(one));
89  CPPUNIT_ASSERT (elem->contains_point(two));
90  CPPUNIT_ASSERT (elem->contains_point(three));
91 
92  // Make sure that outside points are not contained.
93  CPPUNIT_ASSERT (!elem->contains_point(Point(.34, .34, .34)));
94  CPPUNIT_ASSERT (!elem->contains_point(Point(.33, .33, -.1)));
95  CPPUNIT_ASSERT (!elem->contains_point(Point(0., -.1, .5)));
96  }
97 
98 
99  // Construct a nearly degenerate (sliver) tet. A unit tet with
100  // nodes "one" and "two" moved to within a distance of epsilon
101  // from the origin.
102  {
103  Real epsilon = 1.e-4;
104 
105  Node zero (0., 0., 0., 0);
106  Node one (epsilon, 0., 0., 1);
107  Node two (0., epsilon, 0., 2);
108  Node three (0., 0., 1., 3);
109 
110  std::unique_ptr<Elem> elem = Elem::build(TET4);
111  elem->set_node(0, &zero);
112  elem->set_node(1, &one);
113  elem->set_node(2, &two);
114  elem->set_node(3, &three);
115 
116  // The centroid (equal to vertex average for Tet4) must be inside the element.
117  CPPUNIT_ASSERT (elem->contains_point(elem->vertex_average()));
118 
119  // The vertices must be contained in the element.
120  CPPUNIT_ASSERT (elem->contains_point(zero));
121  CPPUNIT_ASSERT (elem->contains_point(one));
122  CPPUNIT_ASSERT (elem->contains_point(two));
123  CPPUNIT_ASSERT (elem->contains_point(three));
124 
125  // Verify that a point which is on a mid-edge is contained in the element.
126  CPPUNIT_ASSERT (elem->contains_point(Point(epsilon/2, 0, 0.5)));
127 
128  // Make sure that "just barely" outside points are outside.
129  CPPUNIT_ASSERT (!elem->contains_point(Point(epsilon, epsilon, epsilon/2)));
130  CPPUNIT_ASSERT (!elem->contains_point(Point(epsilon/10, epsilon/10, 1.0)));
131  CPPUNIT_ASSERT (!elem->contains_point(Point(epsilon/2, -epsilon/10, 0.5)));
132  }
133  }
A Node is like a Point, but with more information.
Definition: node.h:52
const Number zero
.
Definition: libmesh.h:304
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

◆ testContainsPointTri3()

void ContainsPointTest::testContainsPointTri3 ( )
inline

Definition at line 46 of file contains_point.C.

47  {
48  LOG_UNIT_TEST;
49 
50  Point a(3,1,2), b(1,2,3), c(2,3,1);
51  containsPointTri3Helper(a, b, c, a);
52 
53  // Ben's 1st "small triangle" test case.
54  containsPointTri3Helper(a/5000, b/5000, c/5000, c/5000);
55 
56  // Ben's 2nd "small triangle" test case.
57  containsPointTri3Helper(Point(0.000808805, 0.0047284, 0.),
58  Point(0.0011453, 0.00472831, 0.),
59  Point(0.000982249, 0.00508037, 0.),
60  Point(0.001, 0.005, 0.));
61  }
void containsPointTri3Helper(Point a_in, Point b_in, Point c_in, Point p)
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

The documentation for this class was generated from the following file: