From: Denis Davydov Date: Tue, 7 May 2019 15:07:27 +0000 (+0200) Subject: HSFC: move calculation of integer points into a stand-alone internal function X-Git-Tag: v9.1.0-rc1~92^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac670d67af3c54d8445dd88feec7fc776a1d3429;p=dealii.git HSFC: move calculation of integer points into a stand-alone internal function --- diff --git a/source/base/utilities.cc b/source/base/utilities.cc index c09874105d..17641f7175 100644 --- a/source/base/utilities.cc +++ b/source/base/utilities.cc @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -90,6 +91,46 @@ namespace Utilities } + namespace + { + template + std::vector> + inverse_Hilbert_space_filling_curve_effective( + const std::vector> &points, + const Point & bl, + const std::array & extents, + const std::bitset & valid_extents, + const int min_bits, + const Integer max_int) + { + std::vector> int_points(points.size()); + + static_assert(dim == effective_dim, "Not implemented yet"); + (void)valid_extents; + + for (unsigned int i = 0; i < points.size(); ++i) + { + // convert into integers: + for (unsigned int d = 0; d < dim; ++d) + { + const LongDouble v = (static_cast(points[i][d]) - + static_cast(bl[d])) / + extents[d]; + Assert(v >= 0. && v <= 1., ExcInternalError()); + int_points[i][d] = + static_cast(v * static_cast(max_int)); + } + } + + // note that we call this with "min_bits" + return inverse_Hilbert_space_filling_curve(int_points, + min_bits); + } + } // namespace template std::vector> @@ -116,13 +157,17 @@ namespace Utilities } std::array extents; + std::bitset valid_extents; for (unsigned int i = 0; i < dim; ++i) { extents[i] = static_cast(tr[i]) - static_cast(bl[i]); - Assert(extents[i] > 0., ExcMessage("Bounding box is degenerate.")); + valid_extents[i] = (extents[i] > 0.); } + Assert(valid_extents.any(), + ExcMessage("Bounding box is degenerate in all dimensions.")); + // make sure our conversion from fractional coordinates to // Integers work as expected, namely our cast (LongDouble)max_int const int min_bits = @@ -135,24 +180,12 @@ namespace Utilities std::numeric_limits::max() : (Integer(1) << min_bits) - 1); - std::vector> int_points(points.size()); - - for (unsigned int i = 0; i < points.size(); ++i) - { - // convert into integers: - for (unsigned int d = 0; d < dim; ++d) - { - const LongDouble v = (static_cast(points[i][d]) - - static_cast(bl[d])) / - extents[d]; - Assert(v >= 0. && v <= 1., ExcInternalError()); - int_points[i][d] = - static_cast(v * static_cast(max_int)); - } - } - - // note that we call this with "min_bits" - return inverse_Hilbert_space_filling_curve(int_points, min_bits); + return inverse_Hilbert_space_filling_curve_effective( + points, bl, extents, valid_extents, min_bits, max_int); }