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>
45 const unsigned int n_elem_per_side = 5;
47 const unsigned int ymax =
dim > 1;
48 const unsigned int zmax =
dim > 2;
49 const unsigned int ny = ymax * n_elem_per_side;
50 const unsigned int nz = zmax * n_elem_per_side;
66#if defined(LIBMESH_ENABLE_EXCEPTIONS) && !defined(NDEBUG)
67 auto test_exception = [&locator, p]()
69 bool threw_desired_exception =
false;
71 locator->operator()(p);
74 std::regex msg_regex(
"out_of_mesh_mode");
75 CPPUNIT_ASSERT(std::regex_search(e.what(), msg_regex));
76 threw_desired_exception =
true;
79 CPPUNIT_ASSERT_MESSAGE(
"Unexpected exception type thrown",
false);
81 CPPUNIT_ASSERT(threw_desired_exception);
87 locator->enable_out_of_mesh_mode();
89 for (
unsigned int i=0; i != n_elem_per_side+1; ++i)
91 for (
unsigned int j=0; j != ny+1; ++j)
93 for (
unsigned int k=0; k != nz+1; ++k)
96 Point p(i*h, j*h, k*h);
98 const Elem *elem = locator->operator()(p);
100 bool found_elem = elem;
104 CPPUNIT_ASSERT(found_elem);
110 const Node *node = locator->locate_node(p);
112 bool found_node = node;
116 CPPUNIT_ASSERT(found_node);
120 LIBMESH_ASSERT_FP_EQUAL(i*h, (*node)(0),
123 LIBMESH_ASSERT_FP_EQUAL(j*h, (*node)(1),
126 LIBMESH_ASSERT_FP_EQUAL(k*h, (*node)(2),
135 locator->enable_out_of_mesh_mode();
136 const Elem *elem = locator->operator()(p);
137 CPPUNIT_ASSERT(!elem);
140 locator->disable_out_of_mesh_mode();
141#if defined(LIBMESH_ENABLE_EXCEPTIONS) && !defined(NDEBUG)
146 CPPUNIT_ASSERT(!locator->initialized());
149 CPPUNIT_ASSERT(locator->initialized());
151 locator->set_close_to_point_tol(1e-1);
153 const Elem *elem2 = locator->operator()(p2);
154 bool found_elem = elem2;
158 CPPUNIT_ASSERT(found_elem);
175 for (
auto & node :
mesh.node_ptr_range())
176 (*node)(2) += 3.1e-15;
183 locator->enable_out_of_mesh_mode();
188 Point p(0.53, 0.7, 0.0);
189 const Elem *elem = (*locator)(p);
191 bool found_elem = elem;
195 CPPUNIT_ASSERT(found_elem);
LIBMESH_CPPUNIT_TEST_SUITE(PointLocatorTest)
CPPUNIT_TEST(testLocatorOnEdge3)
CPPUNIT_TEST(testLocatorOnQuad9)
void testLocatorOnHex27()
void testLocator(const ElemType elem_type)
void testLocatorOnEdge3()
CPPUNIT_TEST(testLocatorOnTri6)
CPPUNIT_TEST(testLocatorOnHex27)
void testLocatorOnQuad9()
void max(const T &r, T &o, Request &req) const
This is the base class from which all geometric element types are derived.
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
static const unsigned int type_to_dim_map[INVALID_ELEM]
This array maps the integer representation of the ElemType enum to the geometric dimension of the ele...
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
virtual bool is_serial() const
std::unique_ptr< PointLocatorBase > sub_point_locator() const
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
A Node is like a Point, but with more information.
const Parallel::Communicator & comm() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
Communicator * TestCommWorld
The libMesh namespace provides an interface to certain functionality in the library.
ElemType
Defines an enum for geometric element types.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CPPUNIT_TEST_SUITE_REGISTRATION(PointLocatorTest)