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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (BoundaryMeshSubdomainTest)
 Tests the new_subdomain_ids parameter of add_elements(), which assigns subdomain IDs to newly-created lower-D elements.
 
 CPPUNIT_TEST (testDefaultSubdomain)
 
 CPPUNIT_TEST (testSingleSubdomain)
 
 CPPUNIT_TEST (testPerBoundarySubdomain)
 
 CPPUNIT_TEST_SUITE_END ()
 
void testDefaultSubdomain ()
 
void testSingleSubdomain ()
 
void testPerBoundarySubdomain ()
 

Detailed Description

Definition at line 510 of file boundary_mesh.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/3]

BoundaryMeshSubdomainTest::CPPUNIT_TEST ( testDefaultSubdomain  )

◆ CPPUNIT_TEST() [2/3]

BoundaryMeshSubdomainTest::CPPUNIT_TEST ( testPerBoundarySubdomain  )

◆ CPPUNIT_TEST() [3/3]

BoundaryMeshSubdomainTest::CPPUNIT_TEST ( testSingleSubdomain  )

◆ CPPUNIT_TEST_SUITE_END()

BoundaryMeshSubdomainTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

BoundaryMeshSubdomainTest::LIBMESH_CPPUNIT_TEST_SUITE ( BoundaryMeshSubdomainTest  )

Tests the new_subdomain_ids parameter of add_elements(), which assigns subdomain IDs to newly-created lower-D elements.

Three cases:

  1. Empty (default) - elements retain subdomain 0.
  2. Single ID - all new elements get that ID.
  3. Per-boundary - one-to-one with requested_boundary_ids (sorted).

Uses a 3x3 QUAD4 mesh. build_square() assigns: bottom=0, right=1, top=2, left=3.

◆ testDefaultSubdomain()

void BoundaryMeshSubdomainTest::testDefaultSubdomain ( )
inline

Definition at line 533 of file boundary_mesh.C.

534 {
535 LOG_UNIT_TEST;
536
537 Mesh mesh(*TestCommWorld);
538 MeshTools::Generation::build_square(mesh, 3, 3, 0., 1., 0., 1., QUAD4);
539
540 const BoundaryInfo & bi = mesh.get_boundary_info();
541 const auto & side_boundary_ids = bi.get_side_boundary_ids();
542
543 mesh.get_boundary_info().add_elements(side_boundary_ids, mesh);
545
546 for (const auto & elem : mesh.active_element_ptr_range())
547 if (elem->dim() < mesh.mesh_dimension())
548 CPPUNIT_ASSERT_EQUAL(static_cast<subdomain_id_type>(0), elem->subdomain_id());
549 }
unsigned int dim
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
void add_elements(const std::set< boundary_id_type > &requested_boundary_ids, UnstructuredMesh &boundary_mesh, bool store_parent_side_ids=false, const std::vector< subdomain_id_type > &new_subdomain_ids={})
Generates elements along the boundary of our _mesh, which use pre-existing nodes on the boundary_mesh...
const std::set< boundary_id_type > & get_side_boundary_ids() const
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition mesh_base.h:170
void complete_preparation()
Definition mesh_base.C:874
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
MeshBase & mesh
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 libMesh::BoundaryInfo::add_elements(), libMesh::MeshTools::Generation::build_square(), libMesh::MeshBase::complete_preparation(), libMesh::MeshBase::get_boundary_info(), libMesh::BoundaryInfo::get_side_boundary_ids(), mesh, libMesh::MeshBase::mesh_dimension(), libMesh::QUAD4, and TestCommWorld.

◆ testPerBoundarySubdomain()

void BoundaryMeshSubdomainTest::testPerBoundarySubdomain ( )
inline

Definition at line 579 of file boundary_mesh.C.

580 {
581 LOG_UNIT_TEST;
582
583 Mesh mesh(*TestCommWorld);
584 MeshTools::Generation::build_square(mesh, 3, 3, 0., 1., 0., 1., QUAD4);
585
586 const BoundaryInfo & bi = mesh.get_boundary_info();
587 const boundary_id_type right_id = bi.get_id_by_name("right");
588 const boundary_id_type top_id = bi.get_id_by_name("top");
589
590 // The set is iterated in sorted boundary_id order, so the subdomain_ids
591 // vector must be ordered accordingly.
592 const subdomain_id_type right_sid = 10;
593 const subdomain_id_type top_sid = 20;
594 std::set<boundary_id_type> ids = {right_id, top_id};
595 std::vector<subdomain_id_type> sids;
596 for (const auto id : ids)
597 sids.push_back(id == right_id ? right_sid : top_sid);
598
599 mesh.get_boundary_info().add_elements(ids, mesh, false, sids);
601
602 unsigned int n_right = 0, n_top = 0;
603 for (const auto & elem : mesh.active_element_ptr_range())
604 if (elem->dim() < mesh.mesh_dimension())
605 {
606 const Real cx = elem->vertex_average()(0);
607 if (cx > 0.9)
608 {
609 CPPUNIT_ASSERT_EQUAL(right_sid, elem->subdomain_id());
610 if (elem->processor_id() == mesh.processor_id())
611 ++n_right;
612 }
613 else
614 {
615 CPPUNIT_ASSERT_EQUAL(top_sid, elem->subdomain_id());
616 if (elem->processor_id() == mesh.processor_id())
617 ++n_top;
618 }
619 }
620
621 mesh.comm().sum(n_right);
622 mesh.comm().sum(n_top);
623 CPPUNIT_ASSERT_EQUAL(3u, n_right);
624 CPPUNIT_ASSERT_EQUAL(3u, n_top);
625 }
boundary_id_type get_id_by_name(std::string_view name) const
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
static const boundary_id_type right_id
int8_t boundary_id_type
Definition id_types.h:51
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const boundary_id_type top_id

References libMesh::BoundaryInfo::add_elements(), libMesh::MeshTools::Generation::build_square(), libMesh::ParallelObject::comm(), libMesh::MeshBase::complete_preparation(), libMesh::MeshBase::get_boundary_info(), libMesh::BoundaryInfo::get_id_by_name(), mesh, libMesh::MeshBase::mesh_dimension(), libMesh::ParallelObject::processor_id(), libMesh::QUAD4, libMesh::Real, right_id, libMesh::Parallel::Communicator::sum(), TestCommWorld, and top_id.

◆ testSingleSubdomain()

void BoundaryMeshSubdomainTest::testSingleSubdomain ( )
inline

Definition at line 551 of file boundary_mesh.C.

552 {
553 LOG_UNIT_TEST;
554
555 Mesh mesh(*TestCommWorld);
556 MeshTools::Generation::build_square(mesh, 3, 3, 0., 1., 0., 1., QUAD4);
557
558 const BoundaryInfo & bi = mesh.get_boundary_info();
559 const auto & side_boundary_ids = bi.get_side_boundary_ids();
560
561 const subdomain_id_type sid = 42;
562 mesh.get_boundary_info().add_elements(side_boundary_ids, mesh, false, {sid});
564
565 unsigned int n_lower = 0;
566 for (const auto & elem : mesh.active_element_ptr_range())
567 if (elem->dim() < mesh.mesh_dimension())
568 {
569 CPPUNIT_ASSERT_EQUAL(sid, elem->subdomain_id());
570 if (elem->processor_id() == mesh.processor_id())
571 ++n_lower;
572 }
573
574 // 3x3 quad mesh has 12 edges across its sides
575 mesh.comm().sum(n_lower);
576 CPPUNIT_ASSERT_EQUAL(12u, n_lower);
577 }

References libMesh::BoundaryInfo::add_elements(), libMesh::MeshTools::Generation::build_square(), libMesh::ParallelObject::comm(), libMesh::MeshBase::complete_preparation(), libMesh::MeshBase::get_boundary_info(), libMesh::BoundaryInfo::get_side_boundary_ids(), mesh, libMesh::MeshBase::mesh_dimension(), libMesh::ParallelObject::processor_id(), libMesh::QUAD4, libMesh::Parallel::Communicator::sum(), and TestCommWorld.


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