Skip to content

Commit 2fb0a7b

Browse files
authored
Merge pull request #3436 from jwpeterson/node_elem_contains_point
Add NodeElem contains_point() and close_to_point() implementations
2 parents f840c69 + 26c8450 commit 2fb0a7b

4 files changed

Lines changed: 47 additions & 2 deletions

File tree

include/geom/node_elem.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,24 @@ class NodeElem : public Elem
274274
return INVALID_ELEM;
275275
}
276276

277+
/**
278+
* \returns \p true if the point p is within a distance of "tol" from
279+
* the point representing this element, false otherwise.
280+
*
281+
* The tolerance "tol" is normally treated as a relative tolerance in
282+
* contains_point() checks, but in this case there is no relevant length
283+
* to use in determing a relative tolerance, so "tol" is treated as an
284+
* absolute tolerance. The NodeElem contains_point() and close_to_point()
285+
* implementations are identical, whereas they differ for other element
286+
* types.
287+
*/
288+
virtual bool contains_point(const Point & p, Real tol) const override;
289+
290+
/**
291+
* \returns this->contains_point(p, tol)
292+
*/
293+
virtual bool close_to_point(const Point & p, Real tol) const override;
294+
277295
protected:
278296

279297
/**

src/geom/node_elem.C

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ void NodeElem::connectivity(const unsigned int,
3939
libmesh_not_implemented();
4040
}
4141

42+
bool NodeElem::contains_point(const Point & p, Real tol) const
43+
{
44+
return (this->point(0) - p).norm() < tol;
45+
}
46+
47+
bool NodeElem::close_to_point(const Point & p, Real tol) const
48+
{
49+
return this->contains_point(p, tol);
50+
}
51+
4252
#ifdef LIBMESH_ENABLE_AMR
4353

4454
const Real NodeElem::_embedding_matrix[1][1][1] =

tests/mesh/contains_point.C

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public:
1818
LIBMESH_CPPUNIT_TEST_SUITE( ContainsPointTest );
1919

2020
#if LIBMESH_DIM > 2
21+
CPPUNIT_TEST( testContainsPointNodeElem );
2122
CPPUNIT_TEST( testContainsPointTri3 );
2223
CPPUNIT_TEST( testContainsPointTet4 );
2324
#endif
@@ -29,6 +30,18 @@ public:
2930

3031
void tearDown() {}
3132

33+
// NodeElem test
34+
void testContainsPointNodeElem()
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+
}
44+
3245
// TRI3 test
3346
void testContainsPointTri3()
3447
{

tests/mesh/mesh_input.C

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,11 +1226,15 @@ public:
12261226

12271227
CPPUNIT_ASSERT(elem->contains_point(physical_pt));
12281228

1229+
// We only want to find elements in the same block
12291230
std::set<subdomain_id_type> my_subdomain { elem->subdomain_id() };
12301231

1231-
const Elem * located_elem = (*locator)(physical_pt, &my_subdomain);
1232+
// We can *still* have overlapping NodeElem from a slit mesh
1233+
// input file; better check them all
1234+
std::set<const Elem * > located_elems;
1235+
(*locator)(physical_pt, located_elems, &my_subdomain);
12321236

1233-
CPPUNIT_ASSERT(located_elem == elem);
1237+
CPPUNIT_ASSERT(located_elems.count(elem));
12341238
}
12351239
}
12361240

0 commit comments

Comments
 (0)