* @code
* constraints.add_constraint (42, {}, 0.0);
* @endcode
+ *
+ * It is not an error to call this function more than once on the same
+ * degree of freedom, but it is an error to call this function on a
+ * degree of freedom that has previously been constrained to either
+ * a different value than zero, or to a linear combination of degrees
+ * of freedom via the add_constraint() function.
*/
void
constrain_dof_to_zero(const size_type constrained_dof);
constraint.inhomogeneity = inhomogeneity;
// Record the new constraint in the cache:
+ Assert(lines_cache[line_index] == numbers::invalid_size_type,
+ ExcInternalError());
lines_cache[line_index] = lines.size() - 1;
}
const size_type constrained_dof)
{
Assert(sorted == false, ExcMatrixIsClosed());
- Assert(is_constrained(constrained_dof) == false,
- ExcMessage("You cannot add a constraint for a degree of freedom "
- "that is already constrained."));
// The following can happen when we compute with distributed meshes and dof
// handlers and we constrain a degree of freedom whose number we don't have
line_index + 1),
numbers::invalid_size_type);
- // Push a new line to the end of the list and fill it with the
- // provided information:
- ConstraintLine &constraint = lines.emplace_back();
- constraint.index = constrained_dof;
- constraint.inhomogeneity = 0.;
-
- // Record the new constraint in the cache:
- lines_cache[line_index] = lines.size() - 1;
+ // Let's check whether the DoF is already constrained. This is only allowed
+ // if it had previously been constrained to zero, and only then.
+ if (lines_cache[line_index] != numbers::invalid_size_type)
+ {
+ Assert(lines[lines_cache[line_index]].entries.empty() &&
+ (lines[lines_cache[line_index]].inhomogeneity == number(0.)),
+ ExcMessage("You cannot constrain a degree of freedom "
+ "to zero that is is already constrained to "
+ "something else."));
+ }
+ else
+ {
+ // Push a new line to the end of the list and fill it with the
+ // provided information:
+ ConstraintLine &constraint = lines.emplace_back();
+ constraint.index = constrained_dof;
+ constraint.inhomogeneity = 0.;
+
+ // Record the new constraint in the cache:
+ Assert(lines_cache[line_index] == numbers::invalid_size_type,
+ ExcInternalError());
+ lines_cache[line_index] = lines.size() - 1;
+ }
}