From: Wolfgang Bangerth Date: Wed, 11 Oct 2023 19:13:23 +0000 (-0600) Subject: Move a function to a .templates.h file. X-Git-Tag: relicensing~406^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=388a6bf4ee1f3853f906d6e6ce9bc3eb735dfdd5;p=dealii.git Move a function to a .templates.h file. --- diff --git a/include/deal.II/lac/affine_constraints.h b/include/deal.II/lac/affine_constraints.h index 4eb0e7fe68..59a195e44b 100644 --- a/include/deal.II/lac/affine_constraints.h +++ b/include/deal.II/lac/affine_constraints.h @@ -2294,75 +2294,6 @@ inline AffineConstraints::AffineConstraints( -template -inline void -AffineConstraints::add_constraint( - const size_type constrained_dof, - const ArrayView> &dependencies, - const number inhomogeneity) -{ - 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.")); - - // In debug mode, make sure that columns don't show up more than - // once. Do this by sorting an array of the column indices. Try to - // avoid memory allocation by using a vector type that allocates up - // to 25 entries on the stack -- this is enough for the constraints - // of Q4 elements in 3d, and so should cover the vast majority of - // cases. If we have a constraint with more dependencies, then - // that's just going to require a heap allocation. -#ifdef DEBUG - { - boost::container::small_vector column_indices; - column_indices.reserve(dependencies.size()); - for (const auto &d : dependencies) - column_indices.emplace_back(d.first); - std::sort(column_indices.begin(), column_indices.end()); - Assert(std::adjacent_find(column_indices.begin(), column_indices.end()) == - column_indices.end(), - ExcMessage( - "You are trying to insert a constraint that lists the same " - "degree of freedom more than once on the right hand side. This is " - "not allowed.")); - } -#endif - - - // 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(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.entries.reserve(dependencies.size()); - for (const auto &[column, weight] : dependencies) - { - Assert(column != constrained_dof, - ExcMessage("You cannot constrain a degree of freedom against " - "itself.")); - constraint.entries.emplace_back(column, weight); - } - constraint.inhomogeneity = inhomogeneity; - - // Record the new constraint in the cache: - lines_cache[line_index] = lines.size() - 1; -} - - - template inline void AffineConstraints::add_line(const size_type line_n) diff --git a/include/deal.II/lac/affine_constraints.templates.h b/include/deal.II/lac/affine_constraints.templates.h index 15494be76c..eb2029bd43 100644 --- a/include/deal.II/lac/affine_constraints.templates.h +++ b/include/deal.II/lac/affine_constraints.templates.h @@ -74,6 +74,75 @@ AffineConstraints::ConstraintLine::memory_consumption() const +template +void +AffineConstraints::add_constraint( + const size_type constrained_dof, + const ArrayView> &dependencies, + const number inhomogeneity) +{ + 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.")); + + // In debug mode, make sure that columns don't show up more than + // once. Do this by sorting an array of the column indices. Try to + // avoid memory allocation by using a vector type that allocates up + // to 25 entries on the stack -- this is enough for the constraints + // of Q4 elements in 3d, and so should cover the vast majority of + // cases. If we have a constraint with more dependencies, then + // that's just going to require a heap allocation. +#ifdef DEBUG + { + boost::container::small_vector column_indices; + column_indices.reserve(dependencies.size()); + for (const auto &d : dependencies) + column_indices.emplace_back(d.first); + std::sort(column_indices.begin(), column_indices.end()); + Assert(std::adjacent_find(column_indices.begin(), column_indices.end()) == + column_indices.end(), + ExcMessage( + "You are trying to insert a constraint that lists the same " + "degree of freedom more than once on the right hand side. This is " + "not allowed.")); + } +#endif + + + // 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(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.entries.reserve(dependencies.size()); + for (const auto &[column, weight] : dependencies) + { + Assert(column != constrained_dof, + ExcMessage("You cannot constrain a degree of freedom against " + "itself.")); + constraint.entries.emplace_back(column, weight); + } + constraint.inhomogeneity = inhomogeneity; + + // Record the new constraint in the cache: + lines_cache[line_index] = lines.size() - 1; +} + + + template typename AffineConstraints::LineRange AffineConstraints::get_lines() const