Skip to content

Commit 7f8bb48

Browse files
roystgnrjwpeterson
authored andcommitted
Assert sane constraint dof indices
This turned out to be a red herring in my search for a different bug, but it's not a bad thing to keep double-checking. Backported with the other commits from #2099 with the command. git cherry-pick e9297f1 33466d0 ae5cbc1 de07ffc Refs #2029.
1 parent 71d62b1 commit 7f8bb48

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/base/dof_map_constraints.C

+15-2
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,12 @@ void DofMap::add_constraint_row (const dof_id_type dof_number,
13581358
if (this->is_constrained_dof(dof_number))
13591359
libmesh_error_msg("ERROR: DOF " << dof_number << " was already constrained!");
13601360

1361+
libmesh_assert_less(dof_number, this->n_dofs());
1362+
#ifndef NDEBUG
1363+
for (const auto & pr : constraint_row)
1364+
libmesh_assert_less(pr.first, this->n_dofs());
1365+
#endif
1366+
13611367
// We don't get insert_or_assign until C++17 so we make do.
13621368
std::pair<DofConstraints::iterator, bool> it =
13631369
_dof_constraints.insert(std::make_pair(dof_number, constraint_row));
@@ -2954,7 +2960,10 @@ void DofMap::allgather_recursive_constraints(MeshBase & mesh)
29542960
{
29552961
DofConstraintRow & row = _dof_constraints[constrained];
29562962
for (auto & kv : pushed_keys_vals_to_me[i])
2957-
row[kv.first] = kv.second;
2963+
{
2964+
libmesh_assert_less(kv.first, this->n_dofs());
2965+
row[kv.first] = kv.second;
2966+
}
29582967

29592968
const Number primal_rhs = pushed_rhss_to_me[i][max_qoi_num];
29602969

@@ -3676,6 +3685,7 @@ void DofMap::scatter_constraints(MeshBase & mesh)
36763685
DofConstraintRow & row = _dof_constraints[constrained];
36773686
for (auto & key_val : keys_vals[i])
36783687
{
3688+
libmesh_assert_less(key_val.first, this->n_dofs());
36793689
row[key_val.first] = key_val.second;
36803690
}
36813691
if (ids_rhss[i].second != Number(0))
@@ -4172,7 +4182,10 @@ void DofMap::gather_constraints (MeshBase & /*mesh*/,
41724182
DofConstraintRow & row = _dof_constraints[constrained];
41734183
row.clear();
41744184
for (auto & pair : data[i])
4175-
row[pair.first] = pair.second;
4185+
{
4186+
libmesh_assert_less(pair.first, this->n_dofs());
4187+
row[pair.first] = pair.second;
4188+
}
41764189

41774190
// And prepare to check for more recursive constraints
41784191
unexpanded_dofs.insert(constrained);

0 commit comments

Comments
 (0)