libMesh
point_locator_test.C
Go to the documentation of this file.
1 // Ignore unused parameter warnings coming from cppunit headers
2 #include <libmesh/ignore_warnings.h>
3 #include <cppunit/extensions/HelperMacros.h>
4 #include <cppunit/TestCase.h>
5 #include <libmesh/restore_warnings.h>
6 
7 #include <libmesh/mesh.h>
8 #include <libmesh/mesh_generation.h>
9 #include <libmesh/elem.h>
10 #include <libmesh/node.h>
11 
12 #include "test_comm.h"
13 
14 // THE CPPUNIT_TEST_SUITE_END macro expands to code that involves
15 // std::auto_ptr, which in turn produces -Wdeprecated-declarations
16 // warnings. These can be ignored in GCC as long as we wrap the
17 // offending code in appropriate pragmas. We can't get away with a
18 // single ignore_warnings.h inclusion at the beginning of this file,
19 // since the libmesh headers pull in a restore_warnings.h at some
20 // point. We also don't bother restoring warnings at the end of this
21 // file since it's not a header.
22 #include <libmesh/ignore_warnings.h>
23 
24 using namespace libMesh;
25 
26 
27 
28 class PointLocatorTest : public CppUnit::TestCase {
29 public:
30  CPPUNIT_TEST_SUITE( PointLocatorTest );
31 
32  CPPUNIT_TEST( testLocatorOnEdge3 );
33  CPPUNIT_TEST( testLocatorOnQuad9 );
34  CPPUNIT_TEST( testLocatorOnTri6 );
35  CPPUNIT_TEST( testLocatorOnHex27 );
36 
37  CPPUNIT_TEST_SUITE_END();
38 
39 private:
40 
41 public:
42  void setUp()
43  {}
44 
45  void tearDown()
46  {}
47 
48  void testLocator(const ElemType elem_type)
49  {
51 
52  const unsigned n_elem_per_side = 5;
53  const UniquePtr<Elem> test_elem = Elem::build(elem_type);
54  const Real ymax = test_elem->dim() > 1;
55  const Real zmax = test_elem->dim() > 2;
56  const unsigned int ny = ymax * n_elem_per_side;
57  const unsigned int nz = zmax * n_elem_per_side;
58 
60  n_elem_per_side,
61  ny,
62  nz,
63  0., 1.,
64  0., ymax,
65  0., zmax,
66  elem_type);
67 
69 
70  if (!mesh.is_serial())
71  locator->enable_out_of_mesh_mode();
72 
73  for (unsigned int i=0; i != n_elem_per_side+1; ++i)
74  {
75  for (unsigned int j=0; j != ny+1; ++j)
76  {
77  for (unsigned int k=0; k != nz+1; ++k)
78  {
79  const libMesh::Real h = libMesh::Real(1)/n_elem_per_side;
80  Point p(i*h, j*h, k*h);
81 
82  const Elem *elem = locator->operator()(p);
83 
84  bool found_elem = elem;
85  if (!mesh.is_serial())
86  mesh.comm().max(found_elem);
87 
88  CPPUNIT_ASSERT(found_elem);
89  if (elem)
90  {
91  CPPUNIT_ASSERT(elem->contains_point(p));
92  }
93 
94  const Node *node = locator->locate_node(p);
95 
96  bool found_node = node;
97  if (!mesh.is_serial())
98  mesh.comm().max(found_node);
99 
100  CPPUNIT_ASSERT(found_node);
101 
102  if (node)
103  {
104  CPPUNIT_ASSERT_DOUBLES_EQUAL((*node)(0), i*h,
106  CPPUNIT_ASSERT_DOUBLES_EQUAL((*node)(1), j*h,
107  TOLERANCE*TOLERANCE);
108  CPPUNIT_ASSERT_DOUBLES_EQUAL((*node)(2), k*h,
109  TOLERANCE*TOLERANCE);
110  }
111  }
112  }
113  }
114  }
115 
116 
117 
118  void testLocatorOnEdge3() { testLocator(EDGE3); }
119  void testLocatorOnQuad9() { testLocator(QUAD9); }
120  void testLocatorOnTri6() { testLocator(TRI6); }
121  void testLocatorOnHex27() { testLocator(HEX27); }
122 
123 };
124 
void testLocator(const ElemType elem_type)
CPPUNIT_TEST_SUITE_REGISTRATION(PointLocatorTest)
A Node is like a Point, but with more information.
Definition: node.h:52
static UniquePtr< Elem > build(const ElemType type, Elem *p=libmesh_nullptr)
Definition: elem.C:238
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
ElemType
Defines an enum for geometric element types.
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
MeshBase & mesh
static const Real TOLERANCE
The libMesh namespace provides an interface to certain functionality in the library.
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
virtual bool is_serial() const libmesh_override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Parallel::Communicator & comm() const
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
UniquePtr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:534
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
Definition: elem.C:2448