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> 20 CPPUNIT_TEST( testLocatorOnEdge3 );
22 CPPUNIT_TEST( testLocatorOnQuad9 );
23 CPPUNIT_TEST( testLocatorOnTri6 );
26 CPPUNIT_TEST( testLocatorOnHex27 );
27 CPPUNIT_TEST( testPlanar );
30 CPPUNIT_TEST_SUITE_END();
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) 143 #endif // LIBMESH_ENABLE_EXCEPTIONS 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);
void testLocator(const ElemType elem_type)
ElemType
Defines an enum for geometric element types.
CPPUNIT_TEST_SUITE_REGISTRATION(PointLocatorTest)
A Node is like a Point, but with more information.
std::unique_ptr< PointLocatorBase > sub_point_locator() const
libMesh::Parallel::Communicator * TestCommWorld
static constexpr Real TOLERANCE
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...
This is the base class from which all geometric element types are derived.
const Parallel::Communicator & comm() const
void testLocatorOnHex27()
The libMesh namespace provides an interface to certain functionality in the library.
virtual bool is_serial() const
void testLocatorOnQuad9()
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
void testLocatorOnEdge3()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void max(const T &r, T &o, Request &req) const
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
A Point defines a location in LIBMESH_DIM dimensional Real space.