From: Wolfgang Bangerth Date: Wed, 4 Sep 2024 15:43:19 +0000 (-0600) Subject: Make a lambda function a proper function of its own. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9375be40e9c4be42b07b013336aaa81763b3948;p=dealii.git Make a lambda function a proper function of its own. --- diff --git a/include/deal.II/lac/affine_constraints.templates.h b/include/deal.II/lac/affine_constraints.templates.h index e17c8c4410..4388705982 100644 --- a/include/deal.II/lac/affine_constraints.templates.h +++ b/include/deal.II/lac/affine_constraints.templates.h @@ -296,6 +296,54 @@ AffineConstraints::is_consistent_in_parallel( namespace internal { + // A helper function that sorts and normalizes the constraints + // provided through the function's argument: + template + void + sort_and_make_unique( + std::vector::ConstraintLine> + &constraints) + { + using ConstraintLine = + typename dealii::AffineConstraints::ConstraintLine; + + if (constraints.empty()) + return; + + // First sort the array of constraints by their index: + std::sort(constraints.begin(), + constraints.end(), + [](const ConstraintLine &l1, const ConstraintLine &l2) { + return l1.index < l2.index; + }); + + // It is possible that two processes have computed constraints + // for the same DoF differently (for example, in parallel because + // they have visited different faces of the same cell because + // on different processes, different neighbor cells are artificial. + // + // This is ok, as long as after resolution of all chains of + // constraints we end up with the same constraint. But at this + // point, we just don't know yet. We deal with this by simply + // dropping constraints for DoFs for which there is a previous + // constraint in the list: + constraints.erase(std::unique(constraints.begin(), + constraints.end(), + [](const ConstraintLine &a, + const ConstraintLine &b) { + return (a.index == b.index); + }), + constraints.end()); + + // For those constraints that survive, sort the right hand side arrays: + for (ConstraintLine &entry : constraints) + std::sort(entry.entries.begin(), + entry.entries.end(), + [](const auto &l1, const auto &l2) { + return l1.first < l2.first; + }); + } + template std::vector::ConstraintLine> compute_locally_relevant_constraints( @@ -320,47 +368,6 @@ namespace internal [[maybe_unused]] const unsigned int my_rank = Utilities::MPI::this_mpi_process(mpi_communicator); - // First define a helper function that sorts and normalizes the constraints - // provided through the function's argument: - const auto sort_and_make_unique = - [](std::vector &constraints) { - if (constraints.empty()) - return; - - // First sort the array of constraints by their index: - std::sort(constraints.begin(), - constraints.end(), - [](const ConstraintLine &l1, const ConstraintLine &l2) { - return l1.index < l2.index; - }); - - // It is possible that two processes have computed constraints - // for the same DoF differently (for example, in parallel because - // they have visited different faces of the same cell because - // on different processes, different neighbor cells are artificial. - // - // This is ok, as long as after resolution of all chains of - // constraints we end up with the same constraint. But at this - // point, we just don't know yet. We deal with this by simply - // dropping constraints for DoFs for which there is a previous - // constraint in the list: - constraints.erase(std::unique(constraints.begin(), - constraints.end(), - [](const ConstraintLine &a, - const ConstraintLine &b) { - return (a.index == b.index); - }), - constraints.end()); - - // For those constraints that survive, sort the right hand side arrays: - for (ConstraintLine &entry : constraints) - std::sort(entry.entries.begin(), - entry.entries.end(), - [](const auto &l1, const auto &l2) { - return l1.first < l2.first; - }); - }; - // step 0: Collect the indices of constrained DoFs we know of: IndexSet my_constraint_indices(locally_owned_dofs.size()); { @@ -438,7 +445,7 @@ namespace internal constraints.begin(), constraints.end()); - sort_and_make_unique(locally_relevant_constraints); + sort_and_make_unique(locally_relevant_constraints); } // step 3: communicate constraints so that each process knows how the @@ -502,7 +509,7 @@ namespace internal constraints.begin(), constraints.end()); - sort_and_make_unique(locally_relevant_constraints); + sort_and_make_unique(locally_relevant_constraints); } #endif