1 #include <libmesh/mesh.h> 2 #include <libmesh/mesh_generation.h> 3 #include <libmesh/boundary_info.h> 4 #include <libmesh/elem.h> 5 #include <libmesh/face_quad4_shell.h> 6 #include <libmesh/equation_systems.h> 7 #include <libmesh/zero_function.h> 8 #include <libmesh/dirichlet_boundaries.h> 9 #include <libmesh/dof_map.h> 10 #include <libmesh/parallel.h> 11 #include <libmesh/mesh_refinement.h> 27 CPPUNIT_TEST( testNameCopying );
30 CPPUNIT_TEST( testMesh );
31 CPPUNIT_TEST( testRenumber );
32 # ifdef LIBMESH_ENABLE_AMR 33 # ifdef LIBMESH_ENABLE_EXCEPTIONS 34 CPPUNIT_TEST( testBoundaryOnChildrenErrors );
36 CPPUNIT_TEST( testBoundaryOnChildrenElementsRefineCoarsen );
37 CPPUNIT_TEST( testBoundaryOnChildrenBoundaryIDs );
38 CPPUNIT_TEST( testBoundaryOnChildrenBoundarySides );
40 # ifdef LIBMESH_ENABLE_DIRICHLET 41 CPPUNIT_TEST( testShellFaceConstraints );
45 CPPUNIT_TEST( testEdgeBoundaryConditions );
48 CPPUNIT_TEST_SUITE_END();
76 #ifdef LIBMESH_ENABLE_DEPRECATED 77 std::vector<dof_id_type> element_id_list;
78 std::vector<unsigned short int> side_list;
79 std::vector<boundary_id_type> bc_id_list;
87 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(4), bi.
n_boundary_ids());
94 bool has_bcid = bc_ids.count(i);
96 CPPUNIT_ASSERT(has_bcid);
101 #ifdef LIBMESH_ENABLE_DEPRECATED 112 #ifdef LIBMESH_ENABLE_DEPRECATED 113 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(8), element_id_list.size());
115 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(8), bc_triples.size());
120 std::unique_ptr<MeshBase> mesh_clone =
mesh.
clone();
121 CPPUNIT_ASSERT(mesh_clone->get_boundary_info() ==
127 CPPUNIT_ASSERT(mesh_clone->get_boundary_info() !=
132 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(3), bi.
n_boundary_ids());
136 CPPUNIT_ASSERT(!bc_ids.count(0));
139 bool has_bcid = bc_ids.count(i);
141 CPPUNIT_ASSERT(has_bcid);
146 #ifdef LIBMESH_ENABLE_DEPRECATED 155 #ifdef LIBMESH_ENABLE_DEPRECATED 156 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(6), element_id_list.size());
158 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(6), bc_triples.size());
162 #ifdef LIBMESH_ENABLE_DEPRECATED 163 CPPUNIT_ASSERT(std::find(bc_id_list.begin(), bc_id_list.end(), 0) == bc_id_list.end());
165 typedef std::tuple<dof_id_type, unsigned short int, boundary_id_type> Tuple;
166 CPPUNIT_ASSERT(std::find_if(bc_triples.begin(), bc_triples.end(),
167 [](
const Tuple & t)->
bool {
return std::get<2>(t) == 0; }) == bc_triples.end());
172 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(3), bi.
n_boundary_ids());
180 #ifdef LIBMESH_ENABLE_DEPRECATED 185 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(0), bi.
n_boundary_ids());
186 #ifdef LIBMESH_ENABLE_DEPRECATED 187 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(0), element_id_list.size());
189 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(0), bc_triples.size());
208 #ifdef LIBMESH_ENABLE_DEPRECATED 209 std::vector<dof_id_type> element_id_list;
210 std::vector<unsigned short int> side_list;
211 std::vector<boundary_id_type> bc_id_list;
221 const std::map<boundary_id_type, std::string> expected_names =
222 {{4,
"bottom"}, {5,
"right"}, {6,
"left"}};
226 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(3), bi.
n_boundary_ids());
234 bool has_bcid = bc_ids.count(i);
236 CPPUNIT_ASSERT(!has_bcid);
240 bool has_bcid = bc_ids.count(i);
242 bool bad_name =
false;
247 bad_name = (current_name != libmesh_map_find(expected_names, i));
252 CPPUNIT_ASSERT(has_bcid);
256 CPPUNIT_ASSERT(!bad_name);
266 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(8), bc_triples.size());
275 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(0), bi.
n_boundary_ids());
276 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(0), bc_triples.size());
284 const unsigned int n_elem = 5;
285 const std::string mesh_filename =
"cube_mesh.xda";
299 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(0), bi.
n_edge_conds());
308 for (
const auto & elem :
mesh.element_ptr_range())
310 unsigned short side_max_x = 0, side_min_y = 0;
311 bool found_side_max_x =
false, found_side_min_y =
false;
313 for (
unsigned short side=0; side<elem->n_sides(); side++)
318 found_side_max_x =
true;
324 found_side_min_y =
true;
331 if (found_side_max_x && found_side_min_y)
332 for (
unsigned short e=0; e<elem->n_edges(); e++)
333 if (elem->is_edge_on_side(e, side_max_x) &&
334 elem->is_edge_on_side(e, side_min_y))
335 bi.
add_edge(elem, e, EDGE_BOUNDARY_ID);
344 std::unique_ptr<MeshBase> mesh_clone =
mesh.
clone();
345 CPPUNIT_ASSERT(mesh_clone->get_boundary_info() ==
384 CPPUNIT_ASSERT_EQUAL(bi2.get_sideset_name(0), std::string(
"zero"));
385 CPPUNIT_ASSERT_EQUAL(bi2.get_sideset_name(1), std::string(
"one"));
386 CPPUNIT_ASSERT_EQUAL(bi2.get_sideset_name(2), std::string(
"two"));
387 CPPUNIT_ASSERT_EQUAL(bi2.get_sideset_name(3), std::string(
"three"));
388 CPPUNIT_ASSERT_EQUAL(bi2.get_nodeset_name(0), std::string(
"ZERO"));
389 CPPUNIT_ASSERT_EQUAL(bi2.get_nodeset_name(1), std::string(
"ONE"));
393 CPPUNIT_ASSERT_EQUAL(bi3.get_sideset_name(0), std::string(
"zero"));
394 CPPUNIT_ASSERT_EQUAL(bi3.get_sideset_name(1), std::string(
"one"));
395 CPPUNIT_ASSERT_EQUAL(bi3.get_sideset_name(2), std::string(
"two"));
396 CPPUNIT_ASSERT_EQUAL(bi3.get_sideset_name(3), std::string(
"three"));
397 CPPUNIT_ASSERT_EQUAL(bi3.get_nodeset_name(0), std::string(
"ZERO"));
398 CPPUNIT_ASSERT_EQUAL(bi3.get_nodeset_name(1), std::string(
"ONE"));
401 #ifdef LIBMESH_ENABLE_DIRICHLET 453 std::unique_ptr<MeshBase> mesh_clone =
mesh.
clone();
454 CPPUNIT_ASSERT(mesh_clone->get_boundary_info() ==
460 System & system = es.add_system<
System> (
"SimpleSystem");
465 std::vector<unsigned int> variables;
466 variables.push_back(0);
467 std::set<boundary_id_type> shellface_ids;
468 shellface_ids.insert(20);
478 elem_bottom =
nullptr;
488 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(4), static_cast<std::size_t>(system.
n_constrained_dofs()));
495 std::vector<dof_id_type> dof_indices;
497 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(4), dof_indices.size());
499 for(
unsigned int i=0; i<dof_indices.size(); i++)
506 #endif // LIBMESH_ENABLE_DIRICHLET 508 #if LIBMESH_ENABLE_AMR 509 # if LIBMESH_ENABLE_EXCEPTIONS 520 auto mesh = std::make_unique<Mesh>(*TestCommWorld);
530 for (
auto & elem :
mesh->active_element_ptr_range())
539 bool threw_desired_exception =
false;
541 for (
auto & elem :
mesh->active_element_ptr_range())
543 const Point c = elem->vertex_average();
544 if (c(0) < 0.5 && c(1) > 0.5)
549 std::regex msg_regex(
"Trying to add boundary ID 3 which already exists on the ancestors");
550 CPPUNIT_ASSERT(std::regex_search(e.what(), msg_regex));
551 threw_desired_exception =
true;
557 CPPUNIT_ASSERT(threw_desired_exception);
559 threw_desired_exception =
false;
561 for (
auto & elem :
mesh->active_element_ptr_range())
563 const Point c = elem->vertex_average();
564 if (c(0) < 0.5 && c(1) > 0.5)
569 std::regex msg_regex(
"Trying to add boundary ID 3 which already exists on the ancestors");
570 CPPUNIT_ASSERT(std::regex_search(e.what(), msg_regex));
571 threw_desired_exception =
true;
578 CPPUNIT_ASSERT(threw_desired_exception);
582 threw_desired_exception =
false;
585 for (
auto & elem :
mesh->active_element_ptr_range())
587 const Point c = elem->vertex_average();
588 if (c(0) < 0.5 && c(1) > 0.5)
593 std::regex msg_regex(
"We cannot delete boundary ID 3 using a child because it is inherited from an ancestor");
594 CPPUNIT_ASSERT(std::regex_search(e.what(), msg_regex));
595 threw_desired_exception =
true;
602 CPPUNIT_ASSERT(threw_desired_exception);
604 # endif // LIBMESH_ENABLE_EXCEPTIONS 616 auto mesh = std::make_unique<Mesh>(*TestCommWorld);
625 for (
auto & elem :
mesh->active_element_ptr_range())
627 const Point c = elem->vertex_average();
630 elem->subdomain_id() = 1;
634 elem->subdomain_id() = 2;
643 for (
auto & elem :
mesh->active_element_ptr_range())
645 const Point c = elem->vertex_average();
646 if (c(0) < 1 && c(0) > 0.5)
652 unsigned int count = 0;
653 for (
auto & elem :
mesh->active_element_ptr_range())
659 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), count);
666 for (
auto & elem :
mesh->active_element_ptr_range())
668 const Point c = elem->vertex_average();
679 for (
auto & elem :
mesh->active_element_ptr_range())
681 const Point c = elem->vertex_average();
698 for (
auto & elem :
mesh->active_element_ptr_range())
700 const Point c = elem->vertex_average();
703 if (c(0) > 0.5 && c(0) < 1 && c(1) < 0.5)
713 for (
auto & elem :
mesh->active_element_ptr_range())
715 const Point c = elem->vertex_average();
734 auto mesh = std::make_unique<Mesh>(*TestCommWorld);
744 for (
auto & elem :
mesh->active_element_ptr_range())
752 for (
auto & elem :
mesh->active_element_ptr_range())
754 const Point c = elem->vertex_average();
755 if (c(0) < 0.5 && c(1) > 0.5)
762 for (
auto & elem :
mesh->active_element_ptr_range())
764 const Point c = elem->vertex_average();
765 if (c(0) < 0.5 && c(1) > 0.5)
767 std::vector<boundary_id_type> container;
770 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(2), container.size());
771 CPPUNIT_ASSERT_EQUAL(static_cast<boundary_id_type>(5), container[0]);
772 CPPUNIT_ASSERT_EQUAL(static_cast<boundary_id_type>(3), container[1]);
789 auto mesh = std::make_unique<Mesh>(*TestCommWorld);
800 for (
auto & elem :
mesh->active_element_ptr_range())
807 for (
auto & elem :
mesh->active_element_ptr_range())
809 const Point c = elem->vertex_average();
810 if (c(0) < 0.5 && c(1) < 0.5)
822 for (
auto & elem :
mesh->active_element_ptr_range())
824 const Point c = elem->vertex_average();
825 if (c(0) < 0.5 && c(0) > 0.25 && c(1) < 0.25)
834 for (
auto & elem :
mesh->active_element_ptr_range())
836 const Point c = elem->vertex_average();
837 if (c(0) < 0.5 && c(0) > 0.25 && c(1) < 0.25)
841 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), side_5);
842 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), side_6);
849 for (
auto & elem :
mesh->active_element_ptr_range())
851 const Point c = elem->vertex_average();
852 if (c(0) < 0.5 && c(0) > 0.25 && c(1) > 0.25 && c(1) < 0.5)
855 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned long>(2), sides.size());
856 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), sides[0]);
857 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), sides[1]);
861 #endif //LIBMESH_ENABLE_AMR void remove_id(boundary_id_type id, bool global=false)
Removes all entities (nodes, sides, edges, shellfaces) with boundary id id from their respective cont...
A class to stub for features that should be in libMesh, but haven't been written yet, to be thrown by "libmesh_not_implemented();".
void allow_children_on_boundary_side(const bool children_on_boundary)
Whether or not to allow directly setting boundary sides on child elements.
This is the EquationSystems class.
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
virtual Node *& set_node(const unsigned int i)
std::string & nodeset_name(boundary_id_type id)
bool has_boundary_id(const Node *const node, const boundary_id_type id) const
ConstFunction that simply returns 0.
std::vector< unsigned int > sides_with_boundary_id(const Elem *const elem, const boundary_id_type boundary_id) const
void testShellFaceConstraints()
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use...
std::size_t n_edge_conds() const
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
libMesh::Parallel::Communicator * TestCommWorld
bool refine_elements()
Only refines the user-requested elements.
std::size_t n_shellface_conds() const
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly ecreated (or read) mesh for use.
CPPUNIT_TEST_SUITE_REGISTRATION(BoundaryInfoTest)
unsigned int side_with_boundary_id(const Elem *const elem, const boundary_id_type boundary_id) const
This is the base class from which all geometric element types are derived.
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
const Parallel::Communicator & comm() const
void boundary_ids(const Node *node, std::vector< boundary_id_type > &vec_to_fill) const
Fills a user-provided std::vector with the boundary ids associated with Node node.
The libMesh namespace provides an interface to certain functionality in the library.
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
void renumber_id(boundary_id_type old_id, boundary_id_type new_id)
Changes all entities (nodes, sides, edges, shellfaces) with boundary id old_id to instead be labeled ...
virtual std::unique_ptr< MeshBase > clone() const =0
Virtual "copy constructor".
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
std::size_t n_boundary_ids() const
void build_side_list(std::vector< dof_id_type > &element_id_list, std::vector< unsigned short int > &side_list, std::vector< boundary_id_type > &bc_id_list) const
Creates a list of element numbers, sides, and ids for those sides.
bool coarsen_elements()
Only coarsens the user-requested elements.
void testBoundaryOnChildrenBoundaryIDs()
dof_id_type n_active_local_elem() const
virtual bool is_serial() const
void testEdgeBoundaryConditions()
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Manages consistently variables, degrees of freedom, and coefficient vectors.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
virtual dof_id_type max_elem_id() const =0
The BoundaryInfo class contains information relevant to boundary conditions including storing faces...
bool is_constrained_dof(const dof_id_type dof) const
void testBoundaryOnChildrenErrors()
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
std::string & sideset_name(boundary_id_type id)
virtual void write(const std::string &name) const =0
const std::set< boundary_id_type > & get_boundary_ids() const
void remove_side(const Elem *elem, const unsigned short int side)
Removes all boundary conditions associated with side side of element elem, if any exist...
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
void max(const T &r, T &o, Request &req) 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...
void add_shellface(const dof_id_type elem, const unsigned short int shellface, const boundary_id_type id)
Add shell face shellface of element number elem with boundary id id to the boundary information data ...
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
bool is_children_on_boundary_side() const
void testBoundaryOnChildrenBoundarySides()
virtual const Node * node_ptr(const dof_id_type i) const =0
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
processor_id_type processor_id() const
const DofMap & get_dof_map() const
processor_id_type processor_id() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
const Point & point(const unsigned int i) const
void testBoundaryOnChildrenElementsRefineCoarsen()
dof_id_type n_constrained_dofs() const
void add_edge(const dof_id_type elem, const unsigned short int edge, const boundary_id_type id)
Add edge edge of element number elem with boundary id id to the boundary information data structure...