1#include <libmesh/distributed_mesh.h>
2#include <libmesh/mesh.h>
3#include <libmesh/mesh_generation.h>
4#include <libmesh/mesh_refinement.h>
5#include <libmesh/mesh_serializer.h>
6#include <libmesh/remote_elem.h>
7#include <libmesh/replicated_mesh.h>
8#include <libmesh/boundary_info.h>
9#include <libmesh/mesh_tools.h>
26 const unsigned int parent_side_index_tag =
29 for (
const auto & belem : boundary_mesh.element_ptr_range())
32 belem->get_extra_integer(parent_side_index_tag);
36 (
static_cast<dof_id_type>(belem->interior_parent()->which_side_am_i(belem)),
48 for (
const auto & elem :
mesh.active_element_ptr_range())
50 const Elem * pip = elem->
dim() < interior_dim ?
51 elem->interior_parent() :
nullptr;
57 CPPUNIT_ASSERT(elem->processor_id() !=
TestCommWorld->rank());
66 CPPUNIT_ASSERT_EQUAL(elem->type(), boundary_type);
67 CPPUNIT_ASSERT_EQUAL(pip->
type(), interior_type);
68 CPPUNIT_ASSERT_EQUAL(pip->
level(), elem->level());
74 CPPUNIT_ASSERT(is_mixed);
75 CPPUNIT_ASSERT_EQUAL(elem->type(), interior_type);
99 std::unique_ptr<UnstructuredMesh>
_mesh;
118 for (
auto & elem :
_mesh->active_element_ptr_range())
120 const Point c = elem->vertex_average();
128 if (!
_mesh->is_serial())
130 _mesh->skip_noncritical_partitioning(
true);
139 const std::set<boundary_id_type> exterior_boundaries {0, 1};
141 _mesh->get_boundary_info().sync(exterior_boundaries,
145 _mesh->get_boundary_info().sync(exterior_boundaries,
149 const std::set<boundary_id_type> interior_boundaries {2};
150 _mesh->get_boundary_info().sync(interior_boundaries,
158 std::set<boundary_id_type>
right_id;
161 _mesh->get_boundary_info().add_elements
163 _mesh->prepare_for_use();
260 std::unique_ptr<UnstructuredMesh>
_mesh;
286 0.2, 0.8, 0.2, 0.7,
QUAD9);
291 if (!
_mesh->is_serial())
293 _mesh->skip_noncritical_partitioning(
true);
318 for (
auto & elem :
_mesh->active_element_ptr_range())
320 const Point c = elem->vertex_average();
321 if (c(0) < 0.6 && c(1) < 0.4)
322 elem->subdomain_id() = 1;
324 elem->subdomain_id() = 2;
333 for (
auto & elem :
_mesh->active_element_ptr_range())
335 const Point c = elem->vertex_average();
336 if (c(0) < 0.6 && c(1) < 0.4)
345 if (c(0) < 0.75 && c(1) < 0.4)
347 if (c(0) < 0.6 && c(1) < 0.5)
356 const std::set<boundary_id_type> exterior_boundaries {0, 1, 2, 3};
357 _mesh->get_boundary_info().sync(exterior_boundaries,
372 const std::set<boundary_id_type> multi_boundaries {1, 2, 5};
373 _mesh->get_boundary_info().sync(multi_boundaries,
385 _mesh->get_boundary_info().add_elements
387 _mesh->prepare_for_use();
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);
490 LIBMESH_ASSERT_FP_EQUAL(0.2, elem->vertex_average()(0),
501 elem->subdomain_id());
546 for (
const auto & elem :
mesh.active_element_ptr_range())
565 unsigned int n_lower = 0;
566 for (
const auto & elem :
mesh.active_element_ptr_range())
569 CPPUNIT_ASSERT_EQUAL(sid, elem->subdomain_id());
576 CPPUNIT_ASSERT_EQUAL(12u, n_lower);
595 std::vector<subdomain_id_type> sids;
596 for (
const auto id : ids)
597 sids.push_back(
id ==
right_id ? right_sid : top_sid);
602 unsigned int n_right = 0, n_top = 0;
603 for (
const auto & elem :
mesh.active_element_ptr_range())
606 const Real cx = elem->vertex_average()(0);
609 CPPUNIT_ASSERT_EQUAL(right_sid, elem->subdomain_id());
615 CPPUNIT_ASSERT_EQUAL(top_sid, elem->subdomain_id());
623 CPPUNIT_ASSERT_EQUAL(3u, n_right);
624 CPPUNIT_ASSERT_EQUAL(3u, n_top);
631#ifdef LIBMESH_ENABLE_AMR
677 _mesh->n_active_elem());
684 CPPUNIT_ASSERT_EQUAL(
static_cast<dof_id_type>(273),
808 _mesh->n_active_elem());
815 CPPUNIT_ASSERT_EQUAL(
static_cast<dof_id_type>(273),
LIBMESH_CPPUNIT_TEST_SUITE(BoundaryMesh0DTest)
The goal of this test is to ensure that a 1D mesh generates boundary meshes correctly.
std::unique_ptr< UnstructuredMesh > _replicated_boundary_mesh
std::unique_ptr< UnstructuredMesh > _mesh
std::unique_ptr< UnstructuredMesh > _distributed_boundary_mesh
std::unique_ptr< UnstructuredMesh > _interior_node_mesh
void sync_and_test_meshes()
void testBoundarySerialization()
CPPUNIT_TEST(testPerBoundarySubdomain)
void testSingleSubdomain()
CPPUNIT_TEST(testSingleSubdomain)
void testPerBoundarySubdomain()
CPPUNIT_TEST(testDefaultSubdomain)
void testDefaultSubdomain()
LIBMESH_CPPUNIT_TEST_SUITE(BoundaryMeshSubdomainTest)
Tests the new_subdomain_ids parameter of add_elements(), which assigns subdomain IDs to newly-created...
void sync_and_test_meshes()
void testBoundarySerialization()
std::unique_ptr< UnstructuredMesh > _multi_boundary_mesh
std::unique_ptr< UnstructuredMesh > _exterior_boundary_mesh
std::unique_ptr< UnstructuredMesh > _internal_boundary_mesh
CPPUNIT_TEST(testBoundarySerialization)
std::unique_ptr< UnstructuredMesh > _mesh
static constexpr boundary_id_type bid2
static constexpr boundary_id_type bid1
LIBMESH_CPPUNIT_TEST_SUITE(BoundaryMeshTest)
The goal of this test is to ensure that a 2D mesh generates boundary meshes correctly.
std::unique_ptr< UnstructuredMesh > _left_boundary_mesh
CPPUNIT_TEST(testBoundarySerialization)
LIBMESH_CPPUNIT_TEST_SUITE(BoundaryOfRefinedMeshTest)
The goal of this test is the same as the previous, but now we do a uniform refinement before synchron...
void testBoundarySerialization()
CPPUNIT_TEST(testBoundarySerialization)
LIBMESH_CPPUNIT_TEST_SUITE(BoundaryRefinedMeshTest)
The goal of this test is the same as the previous, but now we do a uniform refinement and make sure t...
void testBoundarySerialization()
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...
boundary_id_type get_id_by_name(std::string_view name) const
const std::set< boundary_id_type > & get_side_boundary_ids() const
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.
This is the base class from which all geometric element types are derived.
virtual unsigned short dim() const =0
static const unsigned int type_to_dim_map[INVALID_ELEM]
This array maps the integer representation of the ElemType enum to the geometric dimension of the ele...
unsigned int level() const
virtual ElemType type() const =0
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
unsigned int mesh_dimension() const
void complete_preparation()
unsigned int get_elem_integer_index(std::string_view name) const
Implements (adaptive) mesh refinement algorithms for a MeshBase.
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.
Temporarily serialize a DistributedMesh for non-distributed-mesh capable code paths.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
The UnstructuredMesh class is derived from the MeshBase class.
static const boundary_id_type left_id
static const boundary_id_type right_id
Communicator * TestCommWorld
The libMesh namespace provides an interface to certain functionality in the library.
ElemType
Defines an enum for geometric element types.
const RemoteElem * remote_elem
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const boundary_id_type top_id
CPPUNIT_TEST_SUITE_REGISTRATION(BoundaryMesh0DTest)