From: Martin Kronbichler Date: Mon, 26 Sep 2022 10:04:27 +0000 (+0200) Subject: Restructure includes of FloatingPointComparator X-Git-Tag: v9.5.0-rc1~919^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74c69dcda6927121b517fe0da99384f5afed34c5;p=dealii.git Restructure includes of FloatingPointComparator --- diff --git a/include/deal.II/matrix_free/constraint_info.h b/include/deal.II/matrix_free/constraint_info.h index 91c735c36f..b11e18aeb4 100644 --- a/include/deal.II/matrix_free/constraint_info.h +++ b/include/deal.II/matrix_free/constraint_info.h @@ -20,6 +20,8 @@ #include +#include + #include #include #include @@ -33,6 +35,41 @@ namespace internal { namespace MatrixFreeFunctions { + /** + * A struct that takes entries describing a constraint and puts them into + * a sorted list where duplicates are filtered out + */ + template + struct ConstraintValues + { + ConstraintValues(); + + /** + * This function inserts some constrained entries to the collection of + * all values. It stores the (reordered) numbering of the dofs + * (according to the ordering that matches with the function) in + * new_indices, and returns the storage position the double array for + * access later on. + */ + template + unsigned short + insert_entries( + const std::vector> + &entries); + + std::vector> + constraint_entries; + std::vector constraint_indices; + + std::pair, types::global_dof_index> next_constraint; + std::map, + types::global_dof_index, + FloatingPointComparator> + constraints; + }; + + + /** * A helper class to apply constraints in matrix-free loops in * user code. It combines constraint related functionalties from @@ -131,6 +168,73 @@ namespace internal + // ------------------------- inline functions -------------------------- + + template + ConstraintValues::ConstraintValues() + : constraints(FloatingPointComparator( + 1. * std::numeric_limits::epsilon() * 1024.)) + {} + + + + template + template + unsigned short + ConstraintValues::insert_entries( + const std::vector> &entries) + { + next_constraint.first.resize(entries.size()); + if (entries.size() > 0) + { + constraint_indices.resize(entries.size()); + // Use assign so that values for nonmatching Number / number2 are + // converted: + constraint_entries.assign(entries.begin(), entries.end()); + std::sort(constraint_entries.begin(), + constraint_entries.end(), + [](const std::pair &p1, + const std::pair &p2) { + return p1.second < p2.second; + }); + for (types::global_dof_index j = 0; j < constraint_entries.size(); + j++) + { + // copy the indices of the constraint entries after sorting. + constraint_indices[j] = constraint_entries[j].first; + + // one_constraint takes the weights of the constraint + next_constraint.first[j] = constraint_entries[j].second; + } + } + + // check whether or not constraint is already in pool. the initial + // implementation computed a hash value based on the truncated array (to + // given accuracy around 1e-13) in order to easily detect different + // arrays and then made a fine-grained check when the hash values were + // equal. this was quite lengthy and now we use a std::map with a + // user-defined comparator to compare floating point arrays to a + // tolerance 1e-13. + types::global_dof_index insert_position = numbers::invalid_dof_index; + const auto position = constraints.find(next_constraint.first); + if (position != constraints.end()) + insert_position = position->second; + else + { + next_constraint.second = constraints.size(); + constraints.insert(next_constraint); + insert_position = next_constraint.second; + } + + // we want to store the result as a short variable, so we have to make + // sure that the result does not exceed the limits when casting. + Assert(insert_position < (1 << (8 * sizeof(unsigned short))), + ExcInternalError()); + return static_cast(insert_position); + } + + + template inline void ConstraintInfo::reinit( diff --git a/include/deal.II/matrix_free/dof_info.h b/include/deal.II/matrix_free/dof_info.h index f60288cff0..1e45a1bac8 100644 --- a/include/deal.II/matrix_free/dof_info.h +++ b/include/deal.II/matrix_free/dof_info.h @@ -21,7 +21,6 @@ #include #include -#include #include #include @@ -46,6 +45,9 @@ namespace internal class HangingNodes; struct TaskInfo; + + template + struct ConstraintValues; } // namespace MatrixFreeFunctions } // namespace internal @@ -80,39 +82,6 @@ namespace internal */ using compressed_constraint_kind = std::uint8_t; - /** - * A struct that takes entries describing a constraint and puts them into - * a sorted list where duplicates are filtered out - */ - template - struct ConstraintValues - { - ConstraintValues(); - - /** - * This function inserts some constrained entries to the collection of - * all values. It stores the (reordered) numbering of the dofs - * (according to the ordering that matches with the function) in - * new_indices, and returns the storage position the double array for - * access later on. - */ - template - unsigned short - insert_entries( - const std::vector> - &entries); - - std::vector> - constraint_entries; - std::vector constraint_indices; - - std::pair, types::global_dof_index> next_constraint; - std::map, - types::global_dof_index, - FloatingPointComparator>> - constraints; - }; - /** * The class that stores the indices of the degrees of freedom for all the * cells. Essentially, this is a smart number cache in the style of a diff --git a/include/deal.II/matrix_free/dof_info.templates.h b/include/deal.II/matrix_free/dof_info.templates.h index 7acb48b8b9..d3f84e0cdb 100644 --- a/include/deal.II/matrix_free/dof_info.templates.h +++ b/include/deal.II/matrix_free/dof_info.templates.h @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -39,73 +40,6 @@ namespace internal { namespace MatrixFreeFunctions { - template - ConstraintValues::ConstraintValues() - : constraints(FloatingPointComparator>( - 1. * std::numeric_limits::epsilon() * 1024.)) - {} - - - - template - template - unsigned short - ConstraintValues::insert_entries( - const std::vector> &entries) - { - next_constraint.first.resize(entries.size()); - if (entries.size() > 0) - { - constraint_indices.resize(entries.size()); - // Use assign so that values for nonmatching Number / number2 are - // converted: - constraint_entries.assign(entries.begin(), entries.end()); - std::sort(constraint_entries.begin(), - constraint_entries.end(), - [](const std::pair &p1, - const std::pair &p2) { - return p1.second < p2.second; - }); - for (types::global_dof_index j = 0; j < constraint_entries.size(); - j++) - { - // copy the indices of the constraint entries after sorting. - constraint_indices[j] = constraint_entries[j].first; - - // one_constraint takes the weights of the constraint - next_constraint.first[j] = constraint_entries[j].second; - } - } - - // check whether or not constraint is already in pool. the initial - // implementation computed a hash value based on the truncated array (to - // given accuracy around 1e-13) in order to easily detect different - // arrays and then made a fine-grained check when the hash values were - // equal. this was quite lengthy and now we use a std::map with a - // user-defined comparator to compare floating point arrays to a - // tolerance 1e-13. - types::global_dof_index insert_position = numbers::invalid_dof_index; - const auto position = constraints.find(next_constraint.first); - if (position != constraints.end()) - insert_position = position->second; - else - { - next_constraint.second = constraints.size(); - constraints.insert(next_constraint); - insert_position = next_constraint.second; - } - - // we want to store the result as a short variable, so we have to make - // sure that the result does not exceed the limits when casting. - Assert(insert_position < (1 << (8 * sizeof(unsigned short))), - ExcInternalError()); - return static_cast(insert_position); - } - - - - // ----------------- actual DoFInfo functions ----------------------------- - template void DoFInfo::read_dof_indices( diff --git a/include/deal.II/matrix_free/mapping_info.templates.h b/include/deal.II/matrix_free/mapping_info.templates.h index bb584128e9..62ffd3e98f 100644 --- a/include/deal.II/matrix_free/mapping_info.templates.h +++ b/include/deal.II/matrix_free/mapping_info.templates.h @@ -1081,8 +1081,8 @@ namespace internal // evaluation std::map, dim + 1>, unsigned int, - FloatingPointComparator>> - compressed_jacobians(FloatingPointComparator>( + FloatingPointComparator> + compressed_jacobians(FloatingPointComparator( 1e4 * jacobian_size * std::numeric_limits::epsilon() * 1024.)); diff --git a/include/deal.II/matrix_free/matrix_free.templates.h b/include/deal.II/matrix_free/matrix_free.templates.h index 1b43fc4d03..f5c1baf106 100644 --- a/include/deal.II/matrix_free/matrix_free.templates.h +++ b/include/deal.II/matrix_free/matrix_free.templates.h @@ -40,6 +40,7 @@ #include +#include #include #include #include diff --git a/source/matrix_free/dof_info.cc b/source/matrix_free/dof_info.cc index 6fe7abaebd..7ba077ef9e 100644 --- a/source/matrix_free/dof_info.cc +++ b/source/matrix_free/dof_info.cc @@ -1543,16 +1543,6 @@ namespace internal { namespace MatrixFreeFunctions { - template struct ConstraintValues; - - template unsigned short - ConstraintValues::insert_entries( - const std::vector> &); - template unsigned short - ConstraintValues::insert_entries( - const std::vector> &); - - template void DoFInfo::read_dof_indices( const std::vector &,