libMesh
point_locator_test.C
Go to the documentation of this file.
1 #include <libmesh/mesh.h>
2 #include <libmesh/mesh_generation.h>
3 #include <libmesh/elem.h>
4 #include <libmesh/node.h>
5 #include <libmesh/parallel.h>
6 
7 #include "test_comm.h"
8 #include "libmesh_cppunit.h"
9 
10 
11 using namespace libMesh;
12 
13 
14 
15 class PointLocatorTest : public CppUnit::TestCase {
16 public:
17  CPPUNIT_TEST_SUITE( PointLocatorTest );
18 
19  CPPUNIT_TEST( testLocatorOnEdge3 );
20 #if LIBMESH_DIM > 1
21  CPPUNIT_TEST( testLocatorOnQuad9 );
22  CPPUNIT_TEST( testLocatorOnTri6 );
23 #endif
24 #if LIBMESH_DIM > 2
25  CPPUNIT_TEST( testLocatorOnHex27 );
26 #endif
27 
28  CPPUNIT_TEST_SUITE_END();
29 
30 private:
31 
32 public:
33  void setUp()
34  {}
35 
36  void tearDown()
37  {}
38 
39  void testLocator(const ElemType elem_type)
40  {
42 
43  const unsigned int n_elem_per_side = 5;
44  const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
45  const unsigned int ymax = test_elem->dim() > 1;
46  const unsigned int zmax = test_elem->dim() > 2;
47  const unsigned int ny = ymax * n_elem_per_side;
48  const unsigned int nz = zmax * n_elem_per_side;
49 
51  n_elem_per_side,
52  ny,
53  nz,
54  0., 1.,
55  0., ymax,
56  0., zmax,
57  elem_type);
58 
59  std::unique_ptr<PointLocatorBase> locator = mesh.sub_point_locator();
60 
61  if (!mesh.is_serial())
62  locator->enable_out_of_mesh_mode();
63 
64  for (unsigned int i=0; i != n_elem_per_side+1; ++i)
65  {
66  for (unsigned int j=0; j != ny+1; ++j)
67  {
68  for (unsigned int k=0; k != nz+1; ++k)
69  {
70  const libMesh::Real h = libMesh::Real(1)/n_elem_per_side;
71  Point p(i*h, j*h, k*h);
72 
73  const Elem *elem = locator->operator()(p);
74 
75  bool found_elem = elem;
76  if (!mesh.is_serial())
77  mesh.comm().max(found_elem);
78 
79  CPPUNIT_ASSERT(found_elem);
80  if (elem)
81  {
82  CPPUNIT_ASSERT(elem->contains_point(p));
83  }
84 
85  const Node *node = locator->locate_node(p);
86 
87  bool found_node = node;
88  if (!mesh.is_serial())
89  mesh.comm().max(found_node);
90 
91  CPPUNIT_ASSERT(found_node);
92 
93  if (node)
94  {
95  LIBMESH_ASSERT_FP_EQUAL((*node)(0), i*h,
97  if (LIBMESH_DIM > 1)
98  LIBMESH_ASSERT_FP_EQUAL((*node)(1), j*h,
100  if (LIBMESH_DIM > 2)
101  LIBMESH_ASSERT_FP_EQUAL((*node)(2), k*h,
103  }
104  }
105  }
106  }
107  }
108 
109 
110 
111  void testLocatorOnEdge3() { testLocator(EDGE3); }
112  void testLocatorOnQuad9() { testLocator(QUAD9); }
113  void testLocatorOnTri6() { testLocator(TRI6); }
114  void testLocatorOnHex27() { testLocator(HEX27); }
115 
116 };
117 
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
PointLocatorTest::setUp
void setUp()
Definition: point_locator_test.C:33
libMesh::MeshBase::is_serial
virtual bool is_serial() const
Definition: mesh_base.h:159
libMesh::Elem::contains_point
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
Definition: elem.C:2094
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::MeshTools::Generation::build_cube
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.
Definition: mesh_generation.C:298
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
PointLocatorTest::testLocatorOnQuad9
void testLocatorOnQuad9()
Definition: point_locator_test.C:112
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION(PointLocatorTest)
PointLocatorTest::testLocatorOnHex27
void testLocatorOnHex27()
Definition: point_locator_test.C:114
PointLocatorTest
Definition: point_locator_test.C:15
PointLocatorTest::tearDown
void tearDown()
Definition: point_locator_test.C:36
libMesh::HEX27
Definition: enum_elem_type.h:49
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::Node
A Node is like a Point, but with more information.
Definition: node.h:52
PointLocatorTest::testLocatorOnTri6
void testLocatorOnTri6()
Definition: point_locator_test.C:113
libMesh::TRI6
Definition: enum_elem_type.h:40
libMesh::MeshBase::sub_point_locator
std::unique_ptr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:672
libmesh_cppunit.h
PointLocatorTest::testLocatorOnEdge3
void testLocatorOnEdge3()
Definition: point_locator_test.C:111
libMesh::EDGE3
Definition: enum_elem_type.h:36
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::QUAD9
Definition: enum_elem_type.h:43
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
test_comm.h
PointLocatorTest::testLocator
void testLocator(const ElemType elem_type)
Definition: point_locator_test.C:39
libMesh::Elem::build
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition: elem.C:246
libMesh::ElemType
ElemType
Defines an enum for geometric element types.
Definition: enum_elem_type.h:33