Skip to content

Commit 64d284f

Browse files
committed
Create _add_elements_from_sides helper
1 parent 23f9fbd commit 64d284f

2 files changed

Lines changed: 37 additions & 44 deletions

File tree

include/mesh/boundary_info.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,14 @@ class BoundaryInfo : public ParallelObject
977977
_elem_in_requested_subdomains(const Elem * elem,
978978
const std::set<subdomain_id_type> & subdomains_relative_to) const;
979979

980+
/**
981+
* Helper to add boundary elements from given \p sides_id_map
982+
*/
983+
void _add_elements_from_sides(
984+
UnstructuredMesh & boundary_mesh,
985+
const std::map<std::pair<dof_id_type, unsigned char>, dof_id_type> & side_id_map,
986+
bool store_parent_side_ids);
987+
980988
/**
981989
* A pointer to the Mesh this boundary info pertains to.
982990
*/

src/mesh/boundary_info.C

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,9 @@ void BoundaryInfo::sync (const std::set<boundary_id_type> & requested_boundary_i
573573
// Add the elements. When syncing a boundary mesh, we also store the
574574
// parent side ids in addition to the interior_parent pointers,
575575
// since this information is frequently needed on boundary meshes.
576-
this->add_elements(requested_boundary_ids,
577-
boundary_mesh,
578-
subdomains_relative_to,
579-
/*store_parent_side_ids=*/true);
576+
this->_add_elements_from_sides(boundary_mesh,
577+
side_id_map,
578+
/*store_parent_side_ids=*/true);
580579

581580
// The new elements are currently using the interior mesh's nodes;
582581
// we want them to use the boundary mesh's nodes instead.
@@ -704,10 +703,10 @@ void BoundaryInfo::add_elements(const std::set<boundary_id_type> & requested_bou
704703

705704

706705

707-
void BoundaryInfo::add_elements(const std::set<boundary_id_type> & requested_boundary_ids,
708-
UnstructuredMesh & boundary_mesh,
709-
const std::set<subdomain_id_type> & subdomains_relative_to,
710-
bool store_parent_side_ids)
706+
void BoundaryInfo::_add_elements_from_sides(
707+
UnstructuredMesh & boundary_mesh,
708+
const std::map<std::pair<dof_id_type, unsigned char>, dof_id_type> & side_id_map,
709+
bool store_parent_side_ids)
711710
{
712711
LOG_SCOPE("add_elements()", "BoundaryInfo");
713712

@@ -728,32 +727,6 @@ void BoundaryInfo::add_elements(const std::set<boundary_id_type> & requested_bou
728727
// this mesh
729728
boundary_mesh.set_interior_mesh(*_mesh);
730729

731-
std::map<std::pair<dof_id_type, unsigned char>, dof_id_type> side_id_map;
732-
this->_find_id_maps(requested_boundary_ids,
733-
0,
734-
nullptr,
735-
boundary_mesh.max_elem_id(),
736-
&side_id_map,
737-
subdomains_relative_to);
738-
739-
// We have to add sides *outside* any element loop, because if
740-
// boundary_mesh and _mesh are the same then those additions can
741-
// invalidate our element iterators. So we just use the element
742-
// loop to make a list of sides to add.
743-
typedef std::vector<std::pair<dof_id_type, unsigned char>>
744-
side_container;
745-
side_container sides_to_add;
746-
747-
for (const auto & elem : _mesh->element_ptr_range())
748-
{
749-
if (!this->_elem_in_requested_subdomains(elem))
750-
continue;
751-
752-
for (auto s : elem->side_index_range())
753-
if (this->_side_is_requested(elem, s, requested_boundary_ids))
754-
sides_to_add.emplace_back(elem->id(), s);
755-
}
756-
757730
#ifdef LIBMESH_ENABLE_UNIQUE_ID
758731
unique_id_type old_max_unique_id = boundary_mesh.parallel_max_unique_id();
759732
#endif
@@ -764,20 +737,13 @@ void BoundaryInfo::add_elements(const std::set<boundary_id_type> & requested_bou
764737
unsigned int parent_side_index_tag = store_parent_side_ids ?
765738
boundary_mesh.add_elem_integer("parent_side_index") : libMesh::invalid_uint;
766739

767-
for (const auto & [elem_id, s] : sides_to_add)
740+
for (const auto & [elem_side, new_side_id] : side_id_map)
768741
{
742+
const auto [elem_id, s] = elem_side;
769743
Elem * elem = _mesh->elem_ptr(elem_id);
770744

771745
std::unique_ptr<Elem> side = elem->build_side_ptr(s);
772-
773746
side->processor_id() = elem->processor_id();
774-
775-
const std::pair<dof_id_type, unsigned char> side_pair(elem_id, s);
776-
777-
libmesh_assert(side_id_map.count(side_pair));
778-
779-
const dof_id_type new_side_id = side_id_map[side_pair];
780-
781747
side->set_id(new_side_id);
782748

783749
#ifdef LIBMESH_ENABLE_UNIQUE_ID
@@ -803,7 +769,7 @@ void BoundaryInfo::add_elements(const std::set<boundary_id_type> & requested_bou
803769

804770
libmesh_assert(side_id_map.count(parent_side_pair));
805771

806-
Elem * side_parent = boundary_mesh.elem_ptr(side_id_map[parent_side_pair]);
772+
Elem * side_parent = boundary_mesh.elem_ptr(new_side_id);
807773

808774
libmesh_assert(side_parent);
809775

@@ -935,6 +901,25 @@ void BoundaryInfo::add_elements(const std::set<boundary_id_type> & requested_bou
935901

936902

937903

904+
void BoundaryInfo::add_elements(const std::set<boundary_id_type> & requested_boundary_ids,
905+
UnstructuredMesh & boundary_mesh,
906+
const std::set<subdomain_id_type> & subdomains_relative_to,
907+
bool store_parent_side_ids)
908+
{
909+
std::map<std::pair<dof_id_type, unsigned char>, dof_id_type> side_id_map;
910+
// First build side_id_map
911+
this->_find_id_maps(requested_boundary_ids,
912+
0,
913+
nullptr,
914+
boundary_mesh.max_elem_id(),
915+
&side_id_map,
916+
subdomains_relative_to);
917+
// Then add sides using it
918+
this->_add_elements_from_sides(boundary_mesh, side_id_map, store_parent_side_ids);
919+
}
920+
921+
922+
938923
void BoundaryInfo::add_node(const dof_id_type node_id,
939924
const boundary_id_type id)
940925
{

0 commit comments

Comments
 (0)