Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First stab at importing tracing routines #3432

Open
wants to merge 30 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
00e305b
Accept string_view for Xdr::data comments
roystgnr Nov 10, 2022
47d25a7
Xdr::data() no longer needs comment.c_str()
roystgnr Nov 10, 2022
3f27d80
Add Elem::n_vertices_per_side()
loganharbour Nov 8, 2022
09acf75
Add Elem::n_nodes_on_side
loganharbour Nov 9, 2022
0941b26
Add Elem::nodes_on_side_ptr
loganharbour Nov 9, 2022
1c1d5b0
Add Elem::n_nodes_on_edge
loganharbour Nov 9, 2022
c080d7e
Add Elem::nodes_on_edge_ptr
loganharbour Nov 9, 2022
c58be1e
Add ElemCorner
loganharbour Nov 14, 2022
ff7e024
Add IntersectionTools and within_segment
loganharbour Nov 14, 2022
4887954
Add IntersectionTools::collinear
loganharbour Nov 9, 2022
1dad25a
Add IntersectionTools::within_edge_on_side
loganharbour Nov 10, 2022
cf19f26
ElemCorner improvements
loganharbour Nov 14, 2022
0600a0f
Add test for ElemCorner::build_edge for 2D
loganharbour Nov 14, 2022
ba4c226
Fix spelling
loganharbour Nov 14, 2022
697438c
Correct assertion: we need _at least_ 3 nodes/edge
loganharbour Nov 14, 2022
55202ab
Make within_segment more robust with a relative tolerance
loganharbour Nov 14, 2022
13f2ec8
Update docstring to note relative tolerance
loganharbour Nov 14, 2022
0f0a476
Make collinear more robust with a relative tolerance
loganharbour Nov 14, 2022
5c29b5b
Make within_edge_on_side more robust with a relative tolerance
loganharbour Nov 14, 2022
c054c98
Add proxy version of ElemCorner::build_edge
loganharbour Nov 14, 2022
53ec530
Re-bootstrap
loganharbour Nov 14, 2022
08d51bb
Add IntersectionTools::within_edge
loganharbour Nov 14, 2022
c0bc3c1
Only test when quad is available
loganharbour Nov 14, 2022
7c4df98
Remove incorrect statement from doxygen
loganharbour Nov 14, 2022
663c05f
Run the within_edge cases over a variety of scales
loganharbour Nov 14, 2022
f6f8ba3
Run collinear tests over a variety of scales
loganharbour Nov 14, 2022
6fe2405
Run within_segment tests over a variety of scales
loganharbour Nov 14, 2022
889ffe8
Add IntersectionTools::at_vertex methods
loganharbour Nov 15, 2022
f6ed4b6
Add tolerance to docstring
loganharbour Nov 15, 2022
ae116d8
Add unit testing for ElemExtrema print and <<
loganharbour Nov 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions include/geom/intersection_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,30 @@ bool within_edge_on_side(const Elem & elem,
const bool linearize = false,
const Real tol = TOLERANCE);

/**
* \returns The index of the vertex that the given point is at
* on the given element, invalid otherwise
* @param elem The element
* @param p The point
* @param tol The relative tolerance used in point comparison
*/
unsigned short at_vertex(const Elem & elem,
const Point & p,
const Real tol = TOLERANCE);

/**
* \returns The index of the vertex that the given point is at
* on the given element on the given side, invalid otherwise
* @param elem The element
* @param p The point
* @param s The side
* @param tol The relative tolerance used in point comparison
*/
unsigned short at_vertex_on_side(const Elem & elem,
const Point & p,
const unsigned short s,
const Real tol = TOLERANCE);

namespace detail
{
/**
Expand Down
26 changes: 26 additions & 0 deletions src/geom/intersection_tools.C
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,32 @@ bool within_edge(const Elem & elem,
return false;
}

unsigned short at_vertex(const Elem & elem,
const Point & p,
const Real tol)
{
for (const auto v : elem.vertex_index_range())
if (elem.point(v).relative_fuzzy_equals(p, tol))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a proper relative tolerance. Here relative_fuzzy_equals will use p+elem.point(v) to compare against, which is likely to be way too big in some cases (a tiny element far from the origin) and is going to be effectively zero in other cases (a huge element with a vertex at the origin).

I'd normally use elem.hmax() as a scale here, but that might be too expensive for you? If so, it wouldn't be unreasonable to have something like Elem::cheap_scale() that returns something like an l1 norm (how do we not already have that for TypeVector...) of (elem.point(1)-elem.point(0)). Kind of arbitrary for anisotropic meshes but so is the choice of hmax() over hmin().

return v;
return Elem::invalid_vertex;
}

unsigned short at_vertex_on_side(const Elem & elem,
const Point & p,
const unsigned short s,
const Real tol)
{
libmesh_assert_less(s, elem.n_sides());
const unsigned int * side_node_map = elem.nodes_on_side_ptr(s);
for (const auto i : make_range(elem.n_vertices_on_side(s)))
{
const auto v = side_node_map[i];
if (elem.point(v).relative_fuzzy_equals(p, tol))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar tolerance issue here.

return v;
}
return Elem::invalid_vertex;
}

namespace detail
{
bool _within_edge(const Elem & elem,
Expand Down
50 changes: 48 additions & 2 deletions tests/geom/intersection_tools_test.C
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,56 @@ public:
}
}

void test_at_vertex()
{
LOG_UNIT_TEST;

// check locations at every node
for (const auto & mesh : _meshes)
for (const auto & elem : mesh->active_local_element_ptr_range())
for (const auto n : elem->node_index_range())
{
const auto & p = elem->point(n);
const auto is_vertex = elem->is_vertex(n);
const auto at_vertex = IntersectionTools::at_vertex(*elem, p);

if (is_vertex)
CPPUNIT_ASSERT_EQUAL(at_vertex, (unsigned short)n);
else
CPPUNIT_ASSERT_EQUAL(at_vertex, Elem::invalid_vertex);

for (const auto s : elem->side_index_range())
{
const auto at_vertex_on_side = IntersectionTools::at_vertex_on_side(*elem, p, s);
if (is_vertex && elem->is_node_on_side(n, s))
CPPUNIT_ASSERT_EQUAL(at_vertex_on_side, at_vertex);
else
CPPUNIT_ASSERT_EQUAL(at_vertex_on_side, Elem::invalid_vertex);
}
}

// check edge centroids
for (const auto & mesh : _meshes)
if (mesh->mesh_dimension() > 1)
for (const auto & elem : mesh->active_local_element_ptr_range())
for (const auto e : elem->edge_index_range())
{
const auto edge = elem->build_edge_ptr(e);
const auto at_vertex = IntersectionTools::at_vertex(*elem, edge->vertex_average());
CPPUNIT_ASSERT_EQUAL(at_vertex, Elem::invalid_vertex);
}

// check elem centroids
for (const auto & mesh : _meshes)
for (const auto & elem : mesh->active_local_element_ptr_range())
CPPUNIT_ASSERT_EQUAL(IntersectionTools::at_vertex(*elem, elem->centroid()), Elem::invalid_vertex);
}

};

#define MESHEDINTERSECTIONTOOLSTEST \
CPPUNIT_TEST( test_within_edge );
#define MESHEDINTERSECTIONTOOLSTEST \
CPPUNIT_TEST( test_within_edge ); \
CPPUNIT_TEST( test_at_vertex );

#define INSTANTIATE_MESHEDINTERSECTIONTOOLSTEST(elemtype) \
class MeshedIntersectionToolsTest_##elemtype : public MeshedIntersectionToolsTest<elemtype> { \
Expand Down