Skip to content

Commit 309c9ec

Browse files
committed
Modify parallel packing for elements.
1 parent 8c63cc0 commit 309c9ec

File tree

7 files changed

+289
-203
lines changed

7 files changed

+289
-203
lines changed

include/mesh/boundary_info.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,13 @@ class BoundaryInfo : public ParallelObject
480480
unsigned int n_boundary_ids (const Elem * const elem,
481481
const unsigned short int side) const;
482482

483+
/**
484+
* \returns The number of raw (excludes ancestors) boundary ids associated with the \p side
485+
* side of element \p elem.
486+
*/
487+
unsigned int n_raw_boundary_ids (const Elem * const elem,
488+
const unsigned short int side) const;
489+
483490
/**
484491
* \returns The list of boundary ids associated with the \p side side of
485492
* element \p elem.
@@ -552,15 +559,15 @@ class BoundaryInfo : public ParallelObject
552559

553560
/**
554561
* Update parent's boundary id list so that this information is consistent with
555-
* its children elements
562+
* its children
556563
*
557564
* This is useful when `_children_on_boundary = true`, and is used when the
558565
* element is about to get coarsened i.e., in MeshRefinement::_coarsen_elements()
559566
*
560-
* Specifically, when coarsen a child element who is the last child on that
561-
* boundary, we remove that boundary on the parent's side accordingly.
562-
*
563-
* Otherwise, we add the parent's side to the boundary.
567+
* Specifically, when we coarsen an element whose children have different boundary ids.
568+
* In such scenarios, the parent will inherit the children's boundaries if at
569+
* least two of them own a boundary while sharing the side of the parent.
570+
* Otherwise, we delete the boundary from the children and the parent as well.
564571
*/
565572
void transfer_boundary_ids_to_parent(const Elem * const elem);
566573

@@ -954,8 +961,8 @@ class BoundaryInfo : public ParallelObject
954961
_boundary_side_id;
955962

956963
/*
957-
* Whether or not children elements are associated to any boundary
958-
* It is false by default. The flag will be turned on if add_side
964+
* Whether or not children elements are associated with any boundary
965+
* It is false by default. The flag will be turned on if `add_side`
959966
* function is called with a child element
960967
*/
961968
bool _children_on_boundary;

src/mesh/boundary_info.C

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,21 +1268,22 @@ void BoundaryInfo::boundary_ids (const Elem * const elem,
12681268
vec_to_fill.end())
12691269
vec_to_fill.push_back(pr.second.second);
12701270

1271+
// Loop over ancestors to check if they have boundary ids on the same side
12711272
while (searched_elem->parent() != nullptr)
12721273
{
1273-
const Elem * parent = searched_elem->parent();
1274-
if (parent->is_child_on_side(parent->which_child_am_i(searched_elem), side) == false)
1275-
return;
1276-
1277-
searched_elem = parent;
1278-
1279-
if (_children_on_boundary)
1280-
for (const auto & pr : as_range(_boundary_side_id.equal_range(searched_elem)))
1281-
// Here we need to check if the boundary id already exists
1282-
if (pr.second.first == side &&
1283-
std::find(vec_to_fill.begin(), vec_to_fill.end(), pr.second.second) ==
1284-
vec_to_fill.end())
1285-
vec_to_fill.push_back(pr.second.second);
1274+
const Elem * parent = searched_elem->parent();
1275+
if (parent->is_child_on_side(parent->which_child_am_i(searched_elem), side) == false)
1276+
return;
1277+
1278+
searched_elem = parent;
1279+
1280+
if (_children_on_boundary)
1281+
for (const auto & pr : as_range(_boundary_side_id.equal_range(searched_elem)))
1282+
// Here we need to check if the boundary id already exists
1283+
if (pr.second.first == side &&
1284+
std::find(vec_to_fill.begin(), vec_to_fill.end(), pr.second.second) ==
1285+
vec_to_fill.end())
1286+
vec_to_fill.push_back(pr.second.second);
12861287
}
12871288

12881289
return;
@@ -1296,11 +1297,11 @@ void BoundaryInfo::boundary_ids (const Elem * const elem,
12961297
else
12971298
while (searched_elem->parent() != nullptr)
12981299
{
1299-
const Elem * parent = searched_elem->parent();
1300-
if (parent->is_child_on_side(parent->which_child_am_i(searched_elem), side) == false)
1301-
return;
1300+
const Elem * parent = searched_elem->parent();
1301+
if (parent->is_child_on_side(parent->which_child_am_i(searched_elem), side) == false)
1302+
return;
13021303

1303-
searched_elem = parent;
1304+
searched_elem = parent;
13041305
}
13051306
}
13061307

@@ -1324,6 +1325,15 @@ unsigned int BoundaryInfo::n_boundary_ids (const Elem * const elem,
13241325
}
13251326

13261327

1328+
unsigned int BoundaryInfo::n_raw_boundary_ids (const Elem * const elem,
1329+
const unsigned short int side) const
1330+
{
1331+
std::vector<boundary_id_type> ids;
1332+
this->raw_boundary_ids(elem, side, ids);
1333+
return cast_int<unsigned int>(ids.size());
1334+
}
1335+
1336+
13271337

13281338
void BoundaryInfo::raw_boundary_ids (const Elem * const elem,
13291339
const unsigned short int side,
@@ -1499,9 +1509,6 @@ void BoundaryInfo::remove_side (const Elem * elem,
14991509
{
15001510
libmesh_assert(elem);
15011511

1502-
// Only level 0 elements unless the flag "_children_on_boundary" is on.
1503-
libmesh_assert(elem->level() == 0 || _children_on_boundary);
1504-
15051512
// Erase (elem, side, id) entries from map.
15061513
erase_if(_boundary_side_id, elem,
15071514
[side, id](decltype(_boundary_side_id)::mapped_type & pr)
@@ -1661,7 +1668,7 @@ unsigned int BoundaryInfo::side_with_boundary_id(const Elem * const elem,
16611668
p = parent;
16621669
}
16631670
#endif
1664-
// We're on that side of our top_parent; return it
1671+
// We're on that side of our top_parent; return it
16651672
if (!p)
16661673
return side;
16671674
}
@@ -1719,7 +1726,7 @@ BoundaryInfo::sides_with_boundary_id(const Elem * const elem,
17191726

17201727
const Elem * searched_elem = elem;
17211728
if (elem->level() != 0 && !_children_on_boundary)
1722-
searched_elem = elem->top_parent();
1729+
searched_elem = elem->top_parent();
17231730

17241731
// elem may have zero or multiple occurrences
17251732
for (const auto & pr : as_range(_boundary_side_id.equal_range(searched_elem)))
@@ -1737,10 +1744,10 @@ BoundaryInfo::sides_with_boundary_id(const Elem * const elem,
17371744
// If we're on this external boundary then we share this
17381745
// external boundary id
17391746
if (elem->neighbor_ptr(side) == nullptr)
1740-
{
1741-
returnval.push_back(side);
1742-
continue;
1743-
}
1747+
{
1748+
returnval.push_back(side);
1749+
continue;
1750+
}
17441751

17451752
// If we're on an internal boundary then we need to be sure
17461753
// it's the same internal boundary as our top_parent
@@ -2069,7 +2076,6 @@ BoundaryInfo::build_node_list_from_side_list()
20692076
// Need to loop over the sides of any possible children
20702077
std::vector<const Elem *> family;
20712078
#ifdef LIBMESH_ENABLE_AMR
2072-
// if (!elem->subactive())
20732079
elem->active_family_tree_by_side (family, id_pair.first);
20742080
#else
20752081
family.push_back(elem);
@@ -2432,8 +2438,7 @@ BoundaryInfo::build_active_side_list () const
24322438
// Loop over the sides of possible children
24332439
std::vector<const Elem *> family;
24342440
#ifdef LIBMESH_ENABLE_AMR
2435-
// if (!elem->subactive())
2436-
elem->active_family_tree_by_side(family, id_pair.first);
2441+
elem->active_family_tree_by_side(family, id_pair.first);
24372442
#else
24382443
family.push_back(elem);
24392444
#endif

src/mesh/mesh_refinement.C

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,6 @@ bool MeshRefinement::coarsen_elements ()
659659
if (_face_level_mismatch_limit)
660660
libmesh_assert(test_level_one(true));
661661
libmesh_assert(this->make_coarsening_compatible());
662-
663662
// FIXME: This won't pass unless we add a redundant find_neighbors()
664663
// call or replace find_neighbors() with on-the-fly neighbor updating
665664
// libmesh_assert(!this->eliminate_unrefined_patches());
@@ -706,8 +705,6 @@ bool MeshRefinement::refine_elements ()
706705
elem->set_refinement_flag(Elem::DO_NOTHING);
707706
}
708707

709-
710-
711708
// Parallel consistency has to come first, or coarsening
712709
// along processor boundaries might occasionally be falsely
713710
// prevented
@@ -736,6 +733,7 @@ bool MeshRefinement::refine_elements ()
736733
if (_face_level_mismatch_limit)
737734
libmesh_assert(test_level_one(true));
738735
libmesh_assert(this->make_refinement_compatible());
736+
739737
// FIXME: This won't pass unless we add a redundant find_neighbors()
740738
// call or replace find_neighbors() with on-the-fly neighbor updating
741739
// libmesh_assert(!this->eliminate_unrefined_patches());
@@ -1393,8 +1391,8 @@ bool MeshRefinement::_coarsen_elements ()
13931391
// with this element if we do not allow children to have boundary info
13941392
// otherwise we will have trouble in boundary info consistency among
13951393
// parent and children elements
1396-
if (!_mesh.get_boundary_info().is_children_on_boundary_side())
1397-
_mesh.get_boundary_info().remove (elem);
1394+
// if (!_mesh.get_boundary_info().is_children_on_boundary_side())
1395+
_mesh.get_boundary_info().remove (elem);
13981396

13991397
// Add this iterator to the _unused_elements
14001398
// data structure so we might fill it.
@@ -1406,8 +1404,6 @@ bool MeshRefinement::_coarsen_elements ()
14061404
// _mesh.delete_elem(elem);
14071405
}
14081406

1409-
1410-
14111407
// inactive elements flagged for coarsening
14121408
// will become active
14131409
else if (elem->refinement_flag() == Elem::COARSEN_INACTIVE)
@@ -1417,8 +1413,6 @@ bool MeshRefinement::_coarsen_elements ()
14171413

14181414
// the mesh has certainly changed
14191415
mesh_changed = true;
1420-
1421-
14221416
}
14231417
if (elem->p_refinement_flag() == Elem::COARSEN)
14241418
{
@@ -1433,7 +1427,6 @@ bool MeshRefinement::_coarsen_elements ()
14331427
elem->set_p_refinement_flag(Elem::DO_NOTHING);
14341428
}
14351429
}
1436-
14371430
}
14381431

14391432
this->comm().max(mesh_p_changed);
@@ -1460,8 +1453,6 @@ bool MeshRefinement::_coarsen_elements ()
14601453
#endif
14611454
}
14621455

1463-
1464-
14651456
// If p levels changed all we need to do is make sure that parent p
14661457
// levels changed in sync
14671458
if (mesh_p_changed && !_mesh.is_serial())
@@ -1470,8 +1461,6 @@ bool MeshRefinement::_coarsen_elements ()
14701461
}
14711462

14721463
return (mesh_changed || mesh_p_changed);
1473-
1474-
14751464
}
14761465

14771466

0 commit comments

Comments
 (0)