* @code
* constraints.add_constraint (42, {}, 27.0);
* @endcode
+ * If you want to constrain a degree of freedom to zero, i.e.,
+ * require that
+ * @f[
+ * x_{42} = 0
+ * @f]
+ * you would call this function as follows:
+ * @code
+ * constraints.add_constraint (42, {}, 0.0);
+ * @endcode
+ * That said, this special case can be achieved in a more obvious way by
+ * calling
+ * @code
+ * constraints.constrain_dof_to_zero (42);
+ * @endcode
+ * instead.
*/
void
add_constraint(
const ArrayView<const std::pair<size_type, number>> &dependencies,
const number inhomogeneity = 0);
+ /**
+ * Constrain the given degree of freedom to be zero, i.e.,
+ * require a constraint like
+ * @f[
+ * x_{42} = 0.
+ * @f]
+ * Calling this function is equivalent to, but more readable than, saying
+ * @code
+ * constraints.add_constraint (42, {}, 0.0);
+ * @endcode
+ */
+ void
+ constrain_dof_to_zero(const size_type constrained_dof);
+
/**
* Add a new line to the matrix. If the line already exists, then the
* function simply returns without doing anything.
+template <typename number>
+void
+AffineConstraints<number>::constrain_dof_to_zero(
+ 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
+ // locally. if we don't abort here the program will try to allocate several
+ // terabytes of memory to resize the various arrays below :-)
+ Assert(constrained_dof != numbers::invalid_size_type, ExcInternalError());
+
+ // if necessary enlarge vector of existing entries for cache
+ const size_type line_index = calculate_line_index(constrained_dof);
+ if (line_index >= lines_cache.size())
+ lines_cache.resize(std::max(2 * static_cast<size_type>(lines_cache.size()),
+ 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;
+}
+
+
+
template <typename number>
typename AffineConstraints<number>::LineRange
AffineConstraints<number>::get_lines() const