libMesh
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
BoundaryOfRefinedMeshTest Class Reference
Inheritance diagram for BoundaryOfRefinedMeshTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (BoundaryOfRefinedMeshTest)
 The goal of this test is the same as the previous, but now we do a uniform refinement before synchronizing to the boundary mesh rather than after.
 
 CPPUNIT_TEST (testMesh)
 
 CPPUNIT_TEST (testBoundarySerialization)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void testMesh ()
 
void testBoundarySerialization ()
 
 LIBMESH_CPPUNIT_TEST_SUITE (BoundaryMeshTest)
 The goal of this test is to ensure that a 2D mesh generates boundary meshes correctly.
 
void sanityCheck ()
 

Protected Member Functions

void build_mesh ()
 
void sync_and_test_meshes ()
 

Protected Attributes

std::unique_ptr< UnstructuredMesh_mesh
 
std::unique_ptr< UnstructuredMesh_multi_boundary_mesh
 
std::unique_ptr< UnstructuredMesh_exterior_boundary_mesh
 
std::unique_ptr< UnstructuredMesh_left_boundary_mesh
 
std::unique_ptr< UnstructuredMesh_internal_boundary_mesh
 

Static Protected Attributes

static constexpr boundary_id_type bid1 = 5
 
static constexpr boundary_id_type bid2 = 6
 

Detailed Description

Definition at line 770 of file boundary_mesh.C.

Member Function Documentation

◆ build_mesh()

void BoundaryMeshTest::build_mesh ( )
inlineprotectedinherited

Definition at line 271 of file boundary_mesh.C.

272 {
273 _mesh = std::make_unique<Mesh>(*TestCommWorld);
274 _multi_boundary_mesh = std::make_unique<Mesh>(*TestCommWorld);
275 _exterior_boundary_mesh = std::make_unique<Mesh>(*TestCommWorld);
276
277 // We want to test Distributed->Replicated sync; this does that in
278 // some builds
279 _left_boundary_mesh = std::make_unique<ReplicatedMesh>(*TestCommWorld);
280
281 // We want to test Replicated->Distributed sync; this does that in
282 // other builds
283 _internal_boundary_mesh = std::make_unique<DistributedMesh>(*TestCommWorld);
284
286 0.2, 0.8, 0.2, 0.7, QUAD9);
287
288 // We'll need to skip most repartitioning with DistributedMesh for
289 // now; otherwise the boundary meshes' interior parents might get
290 // shuffled off to different processors.
291 if (!_mesh->is_serial())
292 {
293 _mesh->skip_noncritical_partitioning(true);
294 _left_boundary_mesh->skip_noncritical_partitioning(true);
295 _multi_boundary_mesh->skip_noncritical_partitioning(true);
296 _exterior_boundary_mesh->skip_noncritical_partitioning(true);
297 _internal_boundary_mesh->skip_noncritical_partitioning(true);
298 }
299
300 // Set subdomain ids for specific elements. This allows us to later
301 // build an internal sideset with respect to a given
302 // subdomain. The element subdomains look like:
303 // ___________________
304 // | 2 | 2 | 2 |
305 // |_____|_____|_____|
306 // | 2 | 2 | 2 |
307 // |_____|_____|_____|
308 // | 2 | 2 | 2 |
309 // |_____|_____|_____|
310 // | 1 | 1 | 2 |
311 // |_____|_____|_____|
312 // | 1 | 1 | 2 |
313 // |_____|_____|_____|
314 //
315 // and we will create an internal sideset along the border between
316 // subdomains 1 and 2.
317
318 for (auto & elem : _mesh->active_element_ptr_range())
319 {
320 const Point c = elem->vertex_average();
321 if (c(0) < 0.6 && c(1) < 0.4)
322 elem->subdomain_id() = 1;
323 else
324 elem->subdomain_id() = 2;
325 }
326
327 // To test the "relative to" feature, we add the same sides to the
328 // same sideset twice, from elements in subdomain 2 the second
329 // time. These should not show up in the BoundaryMesh, i.e. there
330 // should not be overlapped elems in the BoundaryMesh.
331 BoundaryInfo & bi = _mesh->get_boundary_info();
332
333 for (auto & elem : _mesh->active_element_ptr_range())
334 {
335 const Point c = elem->vertex_average();
336 if (c(0) < 0.6 && c(1) < 0.4)
337 {
338 if (c(0) > 0.4)
339 bi.add_side(elem, 1, bid1);
340 if (c(1) > 0.3)
341 bi.add_side(elem, 2, bid1);
342 }
343 else
344 {
345 if (c(0) < 0.75 && c(1) < 0.4)
346 bi.add_side(elem, 3, bid2);
347 if (c(0) < 0.6 && c(1) < 0.5)
348 bi.add_side(elem, 0, bid2);
349 }
350 }
351 }
std::unique_ptr< UnstructuredMesh > _multi_boundary_mesh
std::unique_ptr< UnstructuredMesh > _exterior_boundary_mesh
std::unique_ptr< UnstructuredMesh > _internal_boundary_mesh
std::unique_ptr< UnstructuredMesh > _mesh
static constexpr boundary_id_type bid2
static constexpr boundary_id_type bid1
std::unique_ptr< UnstructuredMesh > _left_boundary_mesh
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
Add side side of element number elem with boundary id id to the boundary information data structure.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.

References BoundaryMeshTest::_exterior_boundary_mesh, BoundaryMeshTest::_internal_boundary_mesh, BoundaryMeshTest::_left_boundary_mesh, BoundaryMeshTest::_mesh, BoundaryMeshTest::_multi_boundary_mesh, libMesh::BoundaryInfo::add_side(), BoundaryMeshTest::bid1, BoundaryMeshTest::bid2, libMesh::MeshTools::Generation::build_square(), libMesh::QUAD9, and TestCommWorld.

Referenced by BoundaryMeshTest::setUp(), BoundaryRefinedMeshTest::setUp(), and setUp().

◆ CPPUNIT_TEST() [1/2]

BoundaryOfRefinedMeshTest::CPPUNIT_TEST ( testBoundarySerialization  )

◆ CPPUNIT_TEST() [2/2]

BoundaryOfRefinedMeshTest::CPPUNIT_TEST ( testMesh  )

◆ CPPUNIT_TEST_SUITE_END()

BoundaryOfRefinedMeshTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE() [1/2]

BoundaryMeshTest::LIBMESH_CPPUNIT_TEST_SUITE ( BoundaryMeshTest  )
inherited

The goal of this test is to ensure that a 2D mesh generates boundary meshes correctly.

◆ LIBMESH_CPPUNIT_TEST_SUITE() [2/2]

BoundaryOfRefinedMeshTest::LIBMESH_CPPUNIT_TEST_SUITE ( BoundaryOfRefinedMeshTest  )

The goal of this test is the same as the previous, but now we do a uniform refinement before synchronizing to the boundary mesh rather than after.

◆ sanityCheck()

void BoundaryMeshTest::sanityCheck ( )
inlineinherited

Definition at line 479 of file boundary_mesh.C.

480 {
481 sanity_check_mesh(*_mesh, EDGE3, QUAD9, true);
482 sanity_check_mesh(*_multi_boundary_mesh, EDGE3, QUAD9, false);
483 sanity_check_mesh(*_exterior_boundary_mesh, EDGE3, QUAD9, false);
484 sanity_check_mesh(*_left_boundary_mesh, EDGE3, QUAD9, false);
485 sanity_check_mesh(*_internal_boundary_mesh, EDGE3, QUAD9, false);
486
487 for (const auto & elem : _left_boundary_mesh->active_element_ptr_range())
488 {
489 // We only added left edges here
490 LIBMESH_ASSERT_FP_EQUAL(0.2, elem->vertex_average()(0),
492 }
493
494 // Sanity check for the internal sideset mesh.
495 for (const auto & elem : _internal_boundary_mesh->active_element_ptr_range())
496 {
497 // All of the elements in the internal sideset mesh should
498 // have the same subdomain id as the parent Elems (i.e. 1)
499 // they came from.
500 CPPUNIT_ASSERT_EQUAL(static_cast<subdomain_id_type>(1),
501 elem->subdomain_id());
502 }
503 }
static constexpr Real TOLERANCE

References BoundaryMeshTest::_exterior_boundary_mesh, BoundaryMeshTest::_internal_boundary_mesh, BoundaryMeshTest::_left_boundary_mesh, BoundaryMeshTest::_mesh, BoundaryMeshTest::_multi_boundary_mesh, libMesh::EDGE3, libMesh::QUAD9, and libMesh::TOLERANCE.

Referenced by BoundaryMeshTest::testBoundarySerialization(), BoundaryRefinedMeshTest::testBoundarySerialization(), testBoundarySerialization(), BoundaryMeshTest::testMesh(), BoundaryRefinedMeshTest::testMesh(), and testMesh().

◆ setUp()

void BoundaryOfRefinedMeshTest::setUp ( )
inline

Definition at line 789 of file boundary_mesh.C.

790 {
791#if LIBMESH_DIM > 1
792 this->build_mesh();
793
794 // Refine interior mesh before creating boundary meshes
796
797 this->sync_and_test_meshes();
798#endif
799 }
void sync_and_test_meshes()
Implements (adaptive) mesh refinement algorithms for a MeshBase.
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.

References BoundaryMeshTest::build_mesh(), BoundaryMeshTest::sync_and_test_meshes(), and libMesh::MeshRefinement::uniformly_refine().

◆ sync_and_test_meshes()

void BoundaryMeshTest::sync_and_test_meshes ( )
inlineprotectedinherited

Definition at line 353 of file boundary_mesh.C.

354 {
355 // Get the border of the square
356 const std::set<boundary_id_type> exterior_boundaries {0, 1, 2, 3};
357 _mesh->get_boundary_info().sync(exterior_boundaries,
359 check_parent_side_index_tag(*_exterior_boundary_mesh);
360
361 // The mesh of all boundaries is, because of the two nodes each
362 // joining three edges where the internal boundary meets the
363 // external boundary, not a manifold mesh. We still have work to
364 // do to properly support non-manifold meshes, and
365 // find_neighbors() when preparing such a mesh is likely to fail,
366 // so we'll just do the best test we can here, requesting a set of
367 // three different boundaries. We drop the left and bottom
368 // boundaries because they have any T intersections with the
369 // interior boundaries, and we drop one of the interior boundaries
370 // because with both together we'd have 4 edges meeting at every
371 // interior boundary vertex.
372 const std::set<boundary_id_type> multi_boundaries {1, 2, 5};
373 _mesh->get_boundary_info().sync(multi_boundaries,
375 check_parent_side_index_tag(*_multi_boundary_mesh);
376
377 std::set<boundary_id_type> left_id, right_id;
378 left_id.insert(3);
379 right_id.insert(1);
380
381 // Add the right side of the square to the square; this should
382 // make it a mixed dimension mesh. We skip storing the parent
383 // side ids (which is the default) since they are not needed
384 // in this particular test.
385 _mesh->get_boundary_info().add_elements
386 (right_id, *_mesh, /*store_parent_side_ids=*/false);
387 _mesh->prepare_for_use();
388
389 // Add the left side of the square to its own boundary mesh.
390 _mesh->get_boundary_info().sync(left_id, *_left_boundary_mesh);
391 check_parent_side_index_tag(*_left_boundary_mesh);
392
393 // Create a BoundaryMesh from the internal sidesets relative to subdomain 1.
394 {
395 std::set<boundary_id_type> requested_boundary_ids {bid1, bid2};
396 std::set<subdomain_id_type> subdomains_relative_to;
397 subdomains_relative_to.insert(1);
398 _mesh->get_boundary_info().sync(requested_boundary_ids,
400 subdomains_relative_to);
401 check_parent_side_index_tag(*_internal_boundary_mesh);
402 }
403 }
static const boundary_id_type left_id
static const boundary_id_type right_id

References BoundaryMeshTest::_exterior_boundary_mesh, BoundaryMeshTest::_internal_boundary_mesh, BoundaryMeshTest::_left_boundary_mesh, BoundaryMeshTest::_mesh, BoundaryMeshTest::_multi_boundary_mesh, BoundaryMeshTest::bid1, BoundaryMeshTest::bid2, left_id, and right_id.

Referenced by BoundaryMeshTest::setUp(), BoundaryRefinedMeshTest::setUp(), and setUp().

◆ testBoundarySerialization()

void BoundaryOfRefinedMeshTest::testBoundarySerialization ( )
inline

Definition at line 871 of file boundary_mesh.C.

872 {
873 LOG_UNIT_TEST;
874
875 MeshSerializer internal_serializer(*_internal_boundary_mesh);
876
877 // There'd better be 2*4 active elements on the internal
878 // sideset mesh
879 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(8),
880 _internal_boundary_mesh->n_active_elem());
881
882 // Plus the original 4 now-inactive elements
883 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(12),
884 _internal_boundary_mesh->n_elem());
885
886 // There'd better be 2*2*4+1 nodes on the internal boundary
887 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(17),
888 _internal_boundary_mesh->n_nodes());
889
890 this->sanityCheck();
891 }
Temporarily serialize a DistributedMesh for non-distributed-mesh capable code paths.
uint8_t dof_id_type
Definition id_types.h:67

References BoundaryMeshTest::_internal_boundary_mesh, and BoundaryMeshTest::sanityCheck().

◆ testMesh()

void BoundaryOfRefinedMeshTest::testMesh ( )
inline

Definition at line 801 of file boundary_mesh.C.

802 {
803 LOG_UNIT_TEST;
804
805 // There'd better be 3*5*4 + 5*2 active elements in the interior
806 // plus right boundary
807 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(70),
808 _mesh->n_active_elem());
809
810 // Plus the original 20 now-inactive elements
811 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(90),
812 _mesh->n_elem());
813
814 // There'd better be 13*21 nodes in the interior
815 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(273),
816 _mesh->n_nodes());
817
818 // There'd better be 2*2*(3+5) active elements on the exterior boundary
819 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(32),
820 _exterior_boundary_mesh->n_active_elem());
821
822 // Plus the original 16 now-inactive elements
823 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(48),
824 _exterior_boundary_mesh->n_elem());
825
826 // There'd better be 2*2*2*(3+5) nodes on the exterior boundary
827 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(64),
828 _exterior_boundary_mesh->n_nodes());
829
830 // There'd better be 2*5 active elements on the left boundary
831 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(10),
832 _left_boundary_mesh->n_active_elem());
833
834 // Plus the original 5 now-inactive elements
835 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(15),
836 _left_boundary_mesh->n_elem());
837
838 // There'd better be 2*2*5+1 nodes on the left boundary
839 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(21),
840 _left_boundary_mesh->n_nodes());
841
842 // There'd better be 2*4 active elements on the internal
843 // sideset mesh
844 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(8),
845 _internal_boundary_mesh->n_active_elem());
846
847 // Plus the original 4 now-inactive elements
848 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(12),
849 _internal_boundary_mesh->n_elem());
850
851 // There'd better be 2*2*4+1 nodes on the one-sided internal boundary
852 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(17),
853 _internal_boundary_mesh->n_nodes());
854
855 // There'd better be 2*(3+5) + 2*4 active elements on the
856 // multi-boundary
857 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(24),
858 _multi_boundary_mesh->n_active_elem());
859
860 // Plus the original 12 now-inactive elements
861 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(36),
862 _multi_boundary_mesh->n_elem());
863
864 // There'd better be 2*2*2*(3+5) + 2*2*4-1 nodes on the total boundary
865 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(50),
866 _multi_boundary_mesh->n_nodes());
867
868 this->sanityCheck();
869 }

References BoundaryMeshTest::_exterior_boundary_mesh, BoundaryMeshTest::_internal_boundary_mesh, BoundaryMeshTest::_left_boundary_mesh, BoundaryMeshTest::_mesh, BoundaryMeshTest::_multi_boundary_mesh, and BoundaryMeshTest::sanityCheck().

Member Data Documentation

◆ _exterior_boundary_mesh

std::unique_ptr<UnstructuredMesh> BoundaryMeshTest::_exterior_boundary_mesh
protectedinherited

◆ _internal_boundary_mesh

std::unique_ptr<UnstructuredMesh> BoundaryMeshTest::_internal_boundary_mesh
protectedinherited

◆ _left_boundary_mesh

std::unique_ptr<UnstructuredMesh> BoundaryMeshTest::_left_boundary_mesh
protectedinherited

◆ _mesh

std::unique_ptr<UnstructuredMesh> BoundaryMeshTest::_mesh
protectedinherited

◆ _multi_boundary_mesh

std::unique_ptr<UnstructuredMesh> BoundaryMeshTest::_multi_boundary_mesh
protectedinherited

◆ bid1

constexpr boundary_id_type BoundaryMeshTest::bid1 = 5
staticconstexprprotectedinherited

◆ bid2

constexpr boundary_id_type BoundaryMeshTest::bid2 = 6
staticconstexprprotectedinherited

The documentation for this class was generated from the following file: