From: Peter Munch Date: Wed, 21 Sep 2022 07:26:29 +0000 (+0200) Subject: Rename FPArrayComparator -> FloatingPointComparator X-Git-Tag: v9.5.0-rc1~935^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a159a39acd6fe07d9d7c13c153c6e9881524b286;p=dealii.git Rename FPArrayComparator -> FloatingPointComparator --- diff --git a/include/deal.II/base/floating_point_comparator.h b/include/deal.II/base/floating_point_comparator.h new file mode 100644 index 0000000000..f6d6e8277b --- /dev/null +++ b/include/deal.II/base/floating_point_comparator.h @@ -0,0 +1,203 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 1998 - 2022 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +#ifndef dealii_base_floating_point_copmerator_h +#define dealii_base_floating_point_copmerator_h + +#include + +#include +#include + + +DEAL_II_NAMESPACE_OPEN + +/** + * A class that is used to compare floating point arrays (e.g. std::vector, + * Tensor<1,dim>, etc.). The most common use case of this comparator + * is for detecting arrays with the same content for the sake of + * compression. The idea of this class is to consider two arrays as + * equal if they are the same within a given tolerance. We use this + * comparator class within a std::map<> of the given arrays. Note that this + * comparison operator does not satisfy all the mathematical properties one + * usually wants to have (consider e.g. the numbers a=0, b=0.1, c=0.2 with + * tolerance 0.15; the operator gives a +struct FloatingPointComparator +{ + using Number = typename dealii::internal::VectorizedArrayTrait< + VectorizedArrayType>::value_type; + static constexpr std::size_t width = + dealii::internal::VectorizedArrayTrait::width; + + FloatingPointComparator(const Number scaling); + + /** + * Compare two vectors of numbers (not necessarily of the same length), + * where vectors of different lengths are first sorted by their length and + * then by the entries. + */ + bool + operator()(const std::vector &v1, + const std::vector &v2) const; + + /** + * Compare two vectorized arrays (stored as tensors to avoid alignment + * issues). + */ + bool + operator()(const Tensor<1, width, Number> &t1, + const Tensor<1, width, Number> &t2) const; + + /** + * Compare two rank-1 tensors of vectorized arrays (stored as tensors to + * avoid alignment issues). + */ + template + bool + operator()(const Tensor<1, dim, Tensor<1, width, Number>> &t1, + const Tensor<1, dim, Tensor<1, width, Number>> &t2) const; + + /** + * Compare two rank-2 tensors of vectorized arrays (stored as tensors to + * avoid alignment issues). + */ + template + bool + operator()(const Tensor<2, dim, Tensor<1, width, Number>> &t1, + const Tensor<2, dim, Tensor<1, width, Number>> &t2) const; + + /** + * Compare two arrays of tensors. + */ + template + bool + operator()(const std::array, dim + 1> &t1, + const std::array, dim + 1> &t2) const; + + Number tolerance; +}; + + +/* ------------------------------------------------------------------ */ + + +template +FloatingPointComparator::FloatingPointComparator( + const Number scaling) + : tolerance(scaling * std::numeric_limits::epsilon() * 1024.) +{} + + + +template +bool +FloatingPointComparator::operator()( + const std::vector &v1, + const std::vector &v2) const +{ + const unsigned int s1 = v1.size(), s2 = v2.size(); + if (s1 < s2) + return true; + else if (s1 > s2) + return false; + else + for (unsigned int i = 0; i < s1; ++i) + if (v1[i] < v2[i] - tolerance) + return true; + else if (v1[i] > v2[i] + tolerance) + return false; + return false; +} + + + +template +bool +FloatingPointComparator::operator()( + const Tensor<1, width, Number> &t1, + const Tensor<1, width, Number> &t2) const +{ + for (unsigned int k = 0; k < width; ++k) + if (t1[k] < t2[k] - tolerance) + return true; + else if (t1[k] > t2[k] + tolerance) + return false; + return false; +} + + + +template +template +bool +FloatingPointComparator::operator()( + const Tensor<1, dim, Tensor<1, width, Number>> &t1, + const Tensor<1, dim, Tensor<1, width, Number>> &t2) const +{ + for (unsigned int d = 0; d < dim; ++d) + for (unsigned int k = 0; k < width; ++k) + if (t1[d][k] < t2[d][k] - tolerance) + return true; + else if (t1[d][k] > t2[d][k] + tolerance) + return false; + return false; +} + + + +template +template +bool +FloatingPointComparator::operator()( + const Tensor<2, dim, Tensor<1, width, Number>> &t1, + const Tensor<2, dim, Tensor<1, width, Number>> &t2) const +{ + for (unsigned int d = 0; d < dim; ++d) + for (unsigned int e = 0; e < dim; ++e) + for (unsigned int k = 0; k < width; ++k) + if (t1[d][e][k] < t2[d][e][k] - tolerance) + return true; + else if (t1[d][e][k] > t2[d][e][k] + tolerance) + return false; + return false; +} + + + +template +template +bool +FloatingPointComparator::operator()( + const std::array, dim + 1> &t1, + const std::array, dim + 1> &t2) const +{ + for (unsigned int i = 0; i < t1.size(); ++i) + for (unsigned int d = 0; d < dim; ++d) + for (unsigned int e = 0; e < dim; ++e) + if (t1[i][d][e] < t2[i][d][e] - tolerance) + return true; + else if (t1[i][d][e] > t2[i][d][e] + tolerance) + return false; + return false; +} + + +DEAL_II_NAMESPACE_CLOSE + +#endif diff --git a/include/deal.II/matrix_free/dof_info.h b/include/deal.II/matrix_free/dof_info.h index 1ea1adec85..f60288cff0 100644 --- a/include/deal.II/matrix_free/dof_info.h +++ b/include/deal.II/matrix_free/dof_info.h @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -44,9 +45,6 @@ namespace internal template class HangingNodes; - template - struct FPArrayComparator; - struct TaskInfo; } // namespace MatrixFreeFunctions } // namespace internal @@ -111,7 +109,7 @@ namespace internal std::pair, types::global_dof_index> next_constraint; std::map, types::global_dof_index, - FPArrayComparator>> + FloatingPointComparator>> constraints; }; diff --git a/include/deal.II/matrix_free/dof_info.templates.h b/include/deal.II/matrix_free/dof_info.templates.h index 8c3693d66a..47e964a92e 100644 --- a/include/deal.II/matrix_free/dof_info.templates.h +++ b/include/deal.II/matrix_free/dof_info.templates.h @@ -19,6 +19,7 @@ #include +#include #include #include @@ -28,7 +29,6 @@ #include #include -#include #include #include @@ -41,7 +41,7 @@ namespace internal { template ConstraintValues::ConstraintValues() - : constraints(FPArrayComparator>(1.)) + : constraints(FloatingPointComparator>(1.)) {} diff --git a/include/deal.II/matrix_free/mapping_info.h b/include/deal.II/matrix_free/mapping_info.h index 8efa107154..6113903f85 100644 --- a/include/deal.II/matrix_free/mapping_info.h +++ b/include/deal.II/matrix_free/mapping_info.h @@ -298,74 +298,6 @@ namespace internal }; - - /** - * A class that is used to compare floating point arrays (e.g. std::vectors, - * Tensor<1,dim>, etc.). The idea of this class is to consider two arrays as - * equal if they are the same within a given tolerance. We use this - * comparator class within a std::map<> of the given arrays. Note that this - * comparison operator does not satisfy all the mathematical properties one - * usually wants to have (consider e.g. the numbers a=0, b=0.1, c=0.2 with - * tolerance 0.15; the operator gives a - struct FPArrayComparator - { - using Number = typename dealii::internal::VectorizedArrayTrait< - VectorizedArrayType>::value_type; - static constexpr std::size_t width = - dealii::internal::VectorizedArrayTrait::width; - - FPArrayComparator(const Number scaling); - - /** - * Compare two vectors of numbers (not necessarily of the same length) - */ - bool - operator()(const std::vector &v1, - const std::vector &v2) const; - - /** - * Compare two vectorized arrays (stored as tensors to avoid alignment - * issues). - */ - bool - operator()(const Tensor<1, width, Number> &t1, - const Tensor<1, width, Number> &t2) const; - - /** - * Compare two rank-1 tensors of vectorized arrays (stored as tensors to - * avoid alignment issues). - */ - template - bool - operator()(const Tensor<1, dim, Tensor<1, width, Number>> &t1, - const Tensor<1, dim, Tensor<1, width, Number>> &t2) const; - - /** - * Compare two rank-2 tensors of vectorized arrays (stored as tensors to - * avoid alignment issues). - */ - template - bool - operator()(const Tensor<2, dim, Tensor<1, width, Number>> &t1, - const Tensor<2, dim, Tensor<1, width, Number>> &t2) const; - - /** - * Compare two arrays of tensors. - */ - template - bool - operator()(const std::array, dim + 1> &t1, - const std::array, dim + 1> &t2) const; - - Number tolerance; - }; - - - /* ------------------- inline functions ----------------------------- */ template diff --git a/include/deal.II/matrix_free/mapping_info.templates.h b/include/deal.II/matrix_free/mapping_info.templates.h index 57e777008f..75faac421c 100644 --- a/include/deal.II/matrix_free/mapping_info.templates.h +++ b/include/deal.II/matrix_free/mapping_info.templates.h @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -347,12 +348,12 @@ namespace internal struct CompressedCellData { CompressedCellData(const double expected_size) - : data(FPArrayComparator(expected_size)) + : data(FloatingPointComparator(expected_size)) {} std::map>, unsigned int, - FPArrayComparator> + FloatingPointComparator> data; }; @@ -1077,11 +1078,11 @@ namespace internal // first quadrature point on the cell - we use a relatively coarse // tolerance to account for some inaccuracies in the manifold // evaluation - const FPArrayComparator> comparator( + const FloatingPointComparator> comparator( 1e4 * jacobian_size); std::map, dim + 1>, unsigned int, - FPArrayComparator>> + FloatingPointComparator>> compressed_jacobians(comparator); unsigned int n_data_buckets = 0; @@ -1499,12 +1500,13 @@ namespace internal template struct CompressedFaceData { - // Constructor. As a scaling factor for the FPArrayComparator, we + // Constructor. As a scaling factor for the FloatingPointComparator, we // select the inverse of the Jacobian (not the Jacobian as in the // CompressedCellData) and add another factor of 512 to account for // some roundoff effects. CompressedFaceData(const Number jacobian_size) - : data(FPArrayComparator(512. / jacobian_size)) + : data(FloatingPointComparator(512. / + jacobian_size)) , jacobian_size(jacobian_size) {} @@ -1518,7 +1520,7 @@ namespace internal 2 * dim * dim + dim + 1, Tensor<1, VectorizedArrayType::size(), Number>>, unsigned int, - FPArrayComparator> + FloatingPointComparator> data; // Store the scaling factor @@ -3347,110 +3349,6 @@ namespace internal } } - - - /* ------------------------------------------------------------------ */ - - template - FPArrayComparator::FPArrayComparator( - const Number scaling) - : tolerance(scaling * std::numeric_limits::epsilon() * 1024.) - {} - - - - template - bool - FPArrayComparator::operator()( - const std::vector &v1, - const std::vector &v2) const - { - const unsigned int s1 = v1.size(), s2 = v2.size(); - if (s1 < s2) - return true; - else if (s1 > s2) - return false; - else - for (unsigned int i = 0; i < s1; ++i) - if (v1[i] < v2[i] - tolerance) - return true; - else if (v1[i] > v2[i] + tolerance) - return false; - return false; - } - - - - template - bool - FPArrayComparator::operator()( - const Tensor<1, width, Number> &t1, - const Tensor<1, width, Number> &t2) const - { - for (unsigned int k = 0; k < width; ++k) - if (t1[k] < t2[k] - tolerance) - return true; - else if (t1[k] > t2[k] + tolerance) - return false; - return false; - } - - - - template - template - bool - FPArrayComparator::operator()( - const Tensor<1, dim, Tensor<1, width, Number>> &t1, - const Tensor<1, dim, Tensor<1, width, Number>> &t2) const - { - for (unsigned int d = 0; d < dim; ++d) - for (unsigned int k = 0; k < width; ++k) - if (t1[d][k] < t2[d][k] - tolerance) - return true; - else if (t1[d][k] > t2[d][k] + tolerance) - return false; - return false; - } - - - - template - template - bool - FPArrayComparator::operator()( - const Tensor<2, dim, Tensor<1, width, Number>> &t1, - const Tensor<2, dim, Tensor<1, width, Number>> &t2) const - { - for (unsigned int d = 0; d < dim; ++d) - for (unsigned int e = 0; e < dim; ++e) - for (unsigned int k = 0; k < width; ++k) - if (t1[d][e][k] < t2[d][e][k] - tolerance) - return true; - else if (t1[d][e][k] > t2[d][e][k] + tolerance) - return false; - return false; - } - - - - template - template - bool - FPArrayComparator::operator()( - const std::array, dim + 1> &t1, - const std::array, dim + 1> &t2) const - { - for (unsigned int i = 0; i < t1.size(); ++i) - for (unsigned int d = 0; d < dim; ++d) - for (unsigned int e = 0; e < dim; ++e) - if (t1[i][d][e] < t2[i][d][e] - tolerance) - return true; - else if (t1[i][d][e] > t2[i][d][e] + tolerance) - return false; - return false; - } - } // namespace MatrixFreeFunctions } // end of namespace internal diff --git a/source/matrix_free/mapping_info.cc b/source/matrix_free/mapping_info.cc index 666353c281..36f78a1b41 100644 --- a/source/matrix_free/mapping_info.cc +++ b/source/matrix_free/mapping_info.cc @@ -29,38 +29,4 @@ DEAL_II_NAMESPACE_OPEN #endif #include "mapping_info.inst" -#if SPLIT_INSTANTIATIONS_INDEX == 0 - -template struct internal::MatrixFreeFunctions::FPArrayComparator; -template struct internal::MatrixFreeFunctions::FPArrayComparator; - -template struct internal::MatrixFreeFunctions::FPArrayComparator< - VectorizedArray>; -template struct internal::MatrixFreeFunctions::FPArrayComparator< - VectorizedArray>; - -# if (DEAL_II_VECTORIZATION_WIDTH_IN_BITS >= 128 && defined(__SSE2__)) || \ - (DEAL_II_VECTORIZATION_WIDTH_IN_BITS >= 128 && defined(__ALTIVEC__)) -template struct internal::MatrixFreeFunctions::FPArrayComparator< - VectorizedArray>; -template struct internal::MatrixFreeFunctions::FPArrayComparator< - VectorizedArray>; -# endif - -# if DEAL_II_VECTORIZATION_WIDTH_IN_BITS >= 256 && defined(__AVX__) -template struct internal::MatrixFreeFunctions::FPArrayComparator< - VectorizedArray>; -template struct internal::MatrixFreeFunctions::FPArrayComparator< - VectorizedArray>; -# endif - -# if DEAL_II_VECTORIZATION_WIDTH_IN_BITS >= 512 && defined(__AVX512F__) -template struct internal::MatrixFreeFunctions::FPArrayComparator< - VectorizedArray>; -template struct internal::MatrixFreeFunctions::FPArrayComparator< - VectorizedArray>; -# endif - -#endif - DEAL_II_NAMESPACE_CLOSE