Skip to content

Commit 09b0b49

Browse files
committed
Don't add BoundaryInfo for invalid side/edge nums
1 parent 30caa1f commit 09b0b49

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/mesh/boundary_info.C

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,9 @@ void BoundaryInfo::add_edge(const Elem * elem,
970970
// Only add BCs for level-0 elements.
971971
libmesh_assert_equal_to (elem->level(), 0);
972972

973+
// Only add BCs for edges that exist.
974+
libmesh_assert_less (edge, elem->n_edges());
975+
973976
libmesh_error_msg_if(id == invalid_id,
974977
"ERROR: You may not set a boundary ID of "
975978
<< invalid_id
@@ -1000,6 +1003,9 @@ void BoundaryInfo::add_edge(const Elem * elem,
10001003
// Only add BCs for level-0 elements.
10011004
libmesh_assert_equal_to (elem->level(), 0);
10021005

1006+
// Only add BCs for edges that exist.
1007+
libmesh_assert_less (edge, elem->n_edges());
1008+
10031009
// Don't add the same ID twice
10041010
auto bounds = _boundary_edge_id.equal_range(elem);
10051011

@@ -1145,6 +1151,10 @@ void BoundaryInfo::add_side(const Elem * elem,
11451151
const boundary_id_type id)
11461152
{
11471153
libmesh_assert(elem);
1154+
1155+
// Only add BCs for sides that exist.
1156+
libmesh_assert_less (side, elem->n_sides());
1157+
11481158
libmesh_error_msg_if(id == invalid_id, "ERROR: You may not set a boundary ID of "
11491159
<< invalid_id
11501160
<< "\n That is reserved for internal use.");
@@ -1191,6 +1201,9 @@ void BoundaryInfo::add_side(const Elem * elem,
11911201

11921202
libmesh_assert(elem);
11931203

1204+
// Only add BCs for sides that exist.
1205+
libmesh_assert_less (side, elem->n_sides());
1206+
11941207
#ifdef LIBMESH_ENABLE_AMR
11951208
// Users try to mark boundary on child elements
11961209
// If this happens, we will allow users to remove
@@ -1291,6 +1304,9 @@ void BoundaryInfo::edge_boundary_ids (const Elem * const elem,
12911304
// Clear out any previous contents
12921305
vec_to_fill.clear();
12931306

1307+
// Only query BCs for edges that exist.
1308+
libmesh_assert_less (edge, elem->n_edges());
1309+
12941310
// Only level-0 elements store BCs. If this is not a level-0
12951311
// element get its level-0 parent and infer the BCs.
12961312
const Elem * searched_elem = elem;
@@ -1355,6 +1371,9 @@ void BoundaryInfo::raw_edge_boundary_ids (const Elem * const elem,
13551371
{
13561372
libmesh_assert(elem);
13571373

1374+
// Only query BCs for edges that exist.
1375+
libmesh_assert_less (edge, elem->n_edges());
1376+
13581377
// Clear out any previous contents
13591378
vec_to_fill.clear();
13601379

@@ -1455,6 +1474,9 @@ void BoundaryInfo::boundary_ids (const Elem * const elem,
14551474
{
14561475
libmesh_assert(elem);
14571476

1477+
// Only query BCs for sides that exist.
1478+
libmesh_assert_less (side, elem->n_sides());
1479+
14581480
// Clear out any previous contents
14591481
vec_to_fill.clear();
14601482

@@ -1547,6 +1569,9 @@ void BoundaryInfo::raw_boundary_ids (const Elem * const elem,
15471569
{
15481570
libmesh_assert(elem);
15491571

1572+
// Only query BCs for sides that exist.
1573+
libmesh_assert_less (side, elem->n_sides());
1574+
15501575
// Clear out any previous contents
15511576
vec_to_fill.clear();
15521577

@@ -1632,6 +1657,9 @@ void BoundaryInfo::remove_edge (const Elem * elem,
16321657
{
16331658
libmesh_assert(elem);
16341659

1660+
// Only touch BCs for edges that exist.
1661+
libmesh_assert_less (edge, elem->n_edges());
1662+
16351663
// Only level 0 elements are stored in BoundaryInfo.
16361664
libmesh_assert_equal_to (elem->level(), 0);
16371665

@@ -1649,6 +1677,9 @@ void BoundaryInfo::remove_edge (const Elem * elem,
16491677
{
16501678
libmesh_assert(elem);
16511679

1680+
// Only touch BCs for edges that exist.
1681+
libmesh_assert_less (edge, elem->n_edges());
1682+
16521683
// Only level 0 elements are stored in BoundaryInfo.
16531684
libmesh_assert_equal_to (elem->level(), 0);
16541685

@@ -1701,6 +1732,9 @@ void BoundaryInfo::remove_side (const Elem * elem,
17011732
{
17021733
libmesh_assert(elem);
17031734

1735+
// Only touch BCs for sides that exist.
1736+
libmesh_assert_less (side, elem->n_sides());
1737+
17041738
// Erase (elem, side, *) entries from map.
17051739
erase_if(_boundary_side_id, elem,
17061740
[side](decltype(_boundary_side_id)::mapped_type & pr)
@@ -1715,6 +1749,9 @@ void BoundaryInfo::remove_side (const Elem * elem,
17151749
{
17161750
libmesh_assert(elem);
17171751

1752+
// Only touch BCs for sides that exist.
1753+
libmesh_assert_less (side, elem->n_sides());
1754+
17181755
#ifdef LIBMESH_ENABLE_AMR
17191756
// Here we have to stop and check if somebody tries to remove an ancestor's boundary ID
17201757
// through a child

0 commit comments

Comments
 (0)