Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <complex> 7 : #include <cstddef> 8 : 9 : #include "NumericalAlgorithms/Interpolation/SpanInterpolator.hpp" 10 : #include "Options/String.hpp" 11 : #include "Utilities/Gsl.hpp" 12 : #include "Utilities/Serialization/CharmPupable.hpp" 13 : 14 : namespace intrp { 15 : 16 : /// \brief Performs a barycentric interpolation with an order in a range fixed 17 : /// at construction; this class can be chosen via the options factory mechanism 18 : /// as a possible `SpanInterpolator`. 19 : /// 20 : /// \details This will call a barycentric interpolation on a fixed minimum 21 : /// length, so that buffers that adjust length based on 22 : /// `required_points_before_and_after()` can be forced to use an interpolator of 23 : /// a target order. 24 1 : class BarycentricRationalSpanInterpolator : public SpanInterpolator { 25 : public: 26 0 : struct MinOrder { 27 0 : using type = size_t; 28 0 : static constexpr Options::String help = { 29 : "Order of barycentric interpolation"}; 30 0 : static type lower_bound() { return 1; } 31 : }; 32 : 33 0 : struct MaxOrder { 34 0 : using type = size_t; 35 0 : static constexpr Options::String help = { 36 : "Order of barycentric interpolation"}; 37 0 : static type upper_bound() { return 10; } 38 : }; 39 : 40 0 : using options = tmpl::list<MinOrder, MaxOrder>; 41 0 : static constexpr Options::String help = { 42 : "Barycentric interpolator of option-defined maximum and minimum order."}; 43 : 44 0 : explicit BarycentricRationalSpanInterpolator(CkMigrateMessage* /*unused*/) {} 45 : 46 0 : WRAPPED_PUPable_decl_template(BarycentricRationalSpanInterpolator); // NOLINT 47 : 48 : // clang-tidy: do not pass by non-const reference 49 0 : void pup(PUP::er& p) override { // NOLINT 50 : p | min_order_; 51 : p | max_order_; 52 : } 53 : 54 0 : BarycentricRationalSpanInterpolator() = default; 55 0 : BarycentricRationalSpanInterpolator( 56 : const BarycentricRationalSpanInterpolator&) = default; 57 0 : BarycentricRationalSpanInterpolator& operator=( 58 : const BarycentricRationalSpanInterpolator&) = default; 59 0 : BarycentricRationalSpanInterpolator(BarycentricRationalSpanInterpolator&&) = 60 : default; 61 0 : BarycentricRationalSpanInterpolator& operator=( 62 : BarycentricRationalSpanInterpolator&&) = default; 63 0 : ~BarycentricRationalSpanInterpolator() override = default; 64 : 65 0 : explicit BarycentricRationalSpanInterpolator(size_t min_order, 66 : size_t max_order); 67 : 68 1 : std::unique_ptr<SpanInterpolator> get_clone() const override { 69 : return std::make_unique<BarycentricRationalSpanInterpolator>(*this); 70 : } 71 : 72 : // to get the generic overload: 73 1 : using SpanInterpolator::interpolate; 74 : 75 1 : double interpolate(const gsl::span<const double>& source_points, 76 : const gsl::span<const double>& values, 77 : double target_point) const override; 78 : 79 1 : size_t required_number_of_points_before_and_after() const override { 80 : return min_order_ / 2 + 1; 81 : } 82 : 83 : private: 84 0 : size_t min_order_ = 1; 85 0 : size_t max_order_ = 10; 86 : }; 87 : } // namespace intrp