Skip to content

Commit 3c4e048

Browse files
committed
Add unit tests for orient_elements
1 parent 1fe0b9e commit 3c4e048

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

tests/geom/elem_test.C

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <libmesh/elem_side_builder.h>
77
#include <libmesh/mesh.h>
88
#include <libmesh/mesh_generation.h>
9+
#include <libmesh/mesh_modification.h>
910

1011
#include "libmesh_cppunit.h"
1112

@@ -398,6 +399,56 @@ public:
398399
}
399400
}
400401

402+
void test_orient_elements()
403+
{
404+
LOG_UNIT_TEST;
405+
406+
const Mesh old_mesh {*_mesh};
407+
408+
BoundaryInfo & boundary_info = _mesh->get_boundary_info();
409+
const BoundaryInfo & old_boundary_info = old_mesh.get_boundary_info();
410+
CPPUNIT_ASSERT(&boundary_info != &old_boundary_info);
411+
412+
for (const auto & elem : _mesh->active_local_element_ptr_range())
413+
{
414+
#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
415+
if (elem->infinite())
416+
continue;
417+
#endif
418+
if (elem->id()%2)
419+
elem->flip(&boundary_info);
420+
}
421+
422+
MeshTools::Modification::orient_elements(*_mesh);
423+
424+
// I should really create a MeshBase::operator==()...
425+
for (const auto & elem : _mesh->active_local_element_ptr_range())
426+
{
427+
const Elem & old_elem = old_mesh.elem_ref(elem->id());
428+
429+
// Elem::operator==() uses node ids to compare
430+
CPPUNIT_ASSERT(*elem == old_elem);
431+
432+
const unsigned int n_sides = elem->n_sides();
433+
for (auto s : make_range(n_sides))
434+
{
435+
std::vector<boundary_id_type> bcids, old_bcids;
436+
boundary_info.boundary_ids(elem, s, bcids);
437+
old_boundary_info.boundary_ids(&old_elem, s, old_bcids);
438+
CPPUNIT_ASSERT(bcids == old_bcids);
439+
440+
if (elem->neighbor_ptr(s))
441+
{
442+
CPPUNIT_ASSERT(old_elem.neighbor_ptr(s));
443+
CPPUNIT_ASSERT_EQUAL(elem->neighbor_ptr(s)->id(),
444+
old_elem.neighbor_ptr(s)->id());
445+
}
446+
else
447+
CPPUNIT_ASSERT(!old_elem.neighbor_ptr(s));
448+
}
449+
}
450+
}
451+
401452
void test_center_node_on_side()
402453
{
403454
LOG_UNIT_TEST;
@@ -466,6 +517,7 @@ public:
466517
CPPUNIT_TEST( test_permute ); \
467518
CPPUNIT_TEST( test_flip ); \
468519
CPPUNIT_TEST( test_orient ); \
520+
CPPUNIT_TEST( test_orient_elements ); \
469521
CPPUNIT_TEST( test_contains_point_node ); \
470522
CPPUNIT_TEST( test_center_node_on_side ); \
471523
CPPUNIT_TEST( test_side_type ); \

0 commit comments

Comments
 (0)