1 #include <libmesh/mesh.h> 2 #include <libmesh/mesh_generation.h> 3 #include <libmesh/mesh_refinement.h> 4 #include <libmesh/remote_elem.h> 5 #include <libmesh/replicated_mesh.h> 6 #include <libmesh/boundary_info.h> 24 CPPUNIT_TEST( testMesh );
27 CPPUNIT_TEST_SUITE_END();
38 _mesh = std::make_unique<Mesh>(*TestCommWorld);
39 _all_boundary_mesh = std::make_unique<Mesh>(*TestCommWorld);
40 _left_boundary_mesh = std::make_unique<Mesh>(*TestCommWorld);
41 _internal_boundary_mesh = std::make_unique<Mesh>(*TestCommWorld);
44 0.2, 0.8, 0.2, 0.7,
QUAD9);
49 if (!_mesh->is_serial())
51 _mesh->skip_noncritical_partitioning(
true);
52 _left_boundary_mesh->skip_noncritical_partitioning(
true);
53 _all_boundary_mesh->skip_noncritical_partitioning(
true);
54 _internal_boundary_mesh->skip_noncritical_partitioning(
true);
75 for (
auto & elem : _mesh->active_element_ptr_range())
77 const Point c = elem->vertex_average();
78 if (c(0) < 0.6 && c(1) < 0.4)
79 elem->subdomain_id() = 1;
81 elem->subdomain_id() = 2;
85 _mesh->get_boundary_info().sync(*_all_boundary_mesh);
90 unsigned int parent_side_index_tag =
91 _all_boundary_mesh->get_elem_integer_index(
"parent_side_index");
93 for (
const auto & belem : _all_boundary_mesh->element_ptr_range())
96 belem->get_extra_integer(parent_side_index_tag);
99 (static_cast<dof_id_type>(belem->interior_parent()->which_side_am_i(belem)),
103 std::set<boundary_id_type> left_id, right_id;
111 _mesh->get_boundary_info().add_elements
112 (right_id, *_mesh,
false);
113 _mesh->prepare_for_use();
116 _mesh->get_boundary_info().sync(left_id, *_left_boundary_mesh);
128 for (
auto & elem : _mesh->active_element_ptr_range())
130 const Point c = elem->vertex_average();
131 if (c(0) < 0.6 && c(1) < 0.4)
140 if (c(0) < 0.75 && c(1) < 0.4)
142 if (c(0) < 0.6 && c(1) < 0.5)
150 std::set<boundary_id_type> requested_boundary_ids;
151 requested_boundary_ids.insert(bid);
152 std::set<subdomain_id_type> subdomains_relative_to;
153 subdomains_relative_to.insert(1);
154 _mesh->get_boundary_info().sync(requested_boundary_ids,
155 *_internal_boundary_mesh,
156 subdomains_relative_to);
174 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(20),
178 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(77),
182 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(16),
183 _all_boundary_mesh->n_elem());
186 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(32),
187 _all_boundary_mesh->n_nodes());
190 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(5),
191 _left_boundary_mesh->n_elem());
194 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(11),
195 _left_boundary_mesh->n_nodes());
198 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(4),
199 _internal_boundary_mesh->n_elem());
202 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(9),
203 _internal_boundary_mesh->n_nodes());
211 for (
const auto & elem : _mesh->active_element_ptr_range())
213 const Elem * pip = elem->
dim() < 2 ? elem->interior_parent() :
nullptr;
227 CPPUNIT_ASSERT_EQUAL(elem->type(),
EDGE3);
228 CPPUNIT_ASSERT_EQUAL(pip->
type(),
QUAD9);
229 CPPUNIT_ASSERT_EQUAL(pip->
level(), elem->level());
232 LIBMESH_ASSERT_FP_EQUAL(0.8, elem->vertex_average()(0),
237 CPPUNIT_ASSERT_EQUAL(elem->type(),
QUAD9);
241 for (
const auto & elem : _left_boundary_mesh->active_element_ptr_range())
243 CPPUNIT_ASSERT_EQUAL(elem->type(),
EDGE3);
257 CPPUNIT_ASSERT_EQUAL(pip->type(),
QUAD9);
258 CPPUNIT_ASSERT_EQUAL(pip->level(), elem->level());
261 LIBMESH_ASSERT_FP_EQUAL(0.2, elem->vertex_average()(0),
265 for (
const auto & elem : _left_boundary_mesh->active_element_ptr_range())
267 CPPUNIT_ASSERT_EQUAL(elem->type(),
EDGE3);
281 CPPUNIT_ASSERT_EQUAL(pip->type(),
QUAD9);
282 CPPUNIT_ASSERT_EQUAL(pip->level(), elem->level());
286 for (
const auto & elem : _internal_boundary_mesh->active_element_ptr_range())
288 CPPUNIT_ASSERT_EQUAL(elem->type(),
EDGE3);
293 CPPUNIT_ASSERT_EQUAL(static_cast<subdomain_id_type>(1),
294 elem->subdomain_id());
302 #ifdef LIBMESH_ENABLE_AMR 315 CPPUNIT_TEST( testMesh );
318 CPPUNIT_TEST_SUITE_END();
342 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(70),
343 _mesh->n_active_elem());
346 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(90),
350 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(273),
354 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(32),
355 _all_boundary_mesh->n_active_elem());
358 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(48),
359 _all_boundary_mesh->n_elem());
362 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(64),
363 _all_boundary_mesh->n_nodes());
366 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(10),
367 _left_boundary_mesh->n_active_elem());
370 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(15),
371 _left_boundary_mesh->n_elem());
374 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(21),
375 _left_boundary_mesh->n_nodes());
std::unique_ptr< Mesh > _internal_boundary_mesh
const Elem * interior_parent() const
libMesh::Parallel::Communicator * TestCommWorld
static constexpr Real TOLERANCE
This is the base class from which all geometric element types are derived.
processor_id_type rank() const
The libMesh namespace provides an interface to certain functionality in the library.
std::unique_ptr< Mesh > _mesh
Implements (adaptive) mesh refinement algorithms for a MeshBase.
The BoundaryInfo class contains information relevant to boundary conditions including storing faces...
std::unique_ptr< Mesh > _left_boundary_mesh
CPPUNIT_TEST_SUITE_REGISTRATION(BoundaryMeshTest)
unsigned int level() const
virtual unsigned short dim() const =0
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...
virtual ElemType type() const =0
A Point defines a location in LIBMESH_DIM dimensional Real space.
std::unique_ptr< Mesh > _all_boundary_mesh
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.
const RemoteElem * remote_elem