BarycentricRationalSpanInterpolator.hpp
1 // 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/Options.hpp"
12 #include "Utilities/Gsl.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.
25  public:
26  struct MinOrder {
27  using type = size_t;
28  static constexpr Options::String help = {
29  "Order of barycentric interpolation"};
30  static type lower_bound() noexcept { return 1; }
31  };
32 
33  struct MaxOrder {
34  using type = size_t;
35  static constexpr Options::String help = {
36  "Order of barycentric interpolation"};
37  static type upper_bound() noexcept { return 10; }
38  };
39 
40  using options = tmpl::list<MinOrder, MaxOrder>;
41  static constexpr Options::String help = {
42  "Barycentric interpolator of option-defined maximum and minimum order."};
43 
45  CkMigrateMessage* /*unused*/) noexcept {}
46 
47  WRAPPED_PUPable_decl_template(BarycentricRationalSpanInterpolator); // NOLINT
48 
49  // clang-tidy: do not pass by non-const reference
50  void pup(PUP::er& p) noexcept override { // NOLINT
51  p | min_order_;
52  p | max_order_;
53  }
54 
55  BarycentricRationalSpanInterpolator() = default;
56  BarycentricRationalSpanInterpolator(
57  const BarycentricRationalSpanInterpolator&) noexcept = default;
58  BarycentricRationalSpanInterpolator& operator=(
59  const BarycentricRationalSpanInterpolator&) noexcept = default;
60  BarycentricRationalSpanInterpolator(
61  BarycentricRationalSpanInterpolator&&) noexcept = default;
62  BarycentricRationalSpanInterpolator& operator=(
63  BarycentricRationalSpanInterpolator&&) noexcept = default;
64  ~BarycentricRationalSpanInterpolator() noexcept override = default;
65 
66  explicit BarycentricRationalSpanInterpolator(size_t min_order,
67  size_t max_order) noexcept;
68 
69  std::unique_ptr<SpanInterpolator> get_clone() const noexcept override {
70  return std::make_unique<BarycentricRationalSpanInterpolator>(*this);
71  }
72 
73  // to get the generic overload:
75 
76  double interpolate(const gsl::span<const double>& source_points,
77  const gsl::span<const double>& values,
78  double target_point) const noexcept override;
79 
80  size_t required_number_of_points_before_and_after() const noexcept override {
81  return min_order_ / 2 + 1;
82  }
83 
84  private:
85  size_t min_order_ = 1;
86  size_t max_order_ = 10;
87 };
88 } // namespace intrp
CharmPupable.hpp
intrp::SpanInterpolator
Base class for interpolators so that the factory options mechanism can be used.
Definition: SpanInterpolator.hpp:32
intrp::SpanInterpolator::interpolate
virtual double interpolate(const gsl::span< const double > &source_points, const gsl::span< const double > &values, double target_point) const noexcept=0
Perform the interpolation of function represented by values at source_points to the requested target_...
Options.hpp
intrp::BarycentricRationalSpanInterpolator::MinOrder
Definition: BarycentricRationalSpanInterpolator.hpp:26
intrp::BarycentricRationalSpanInterpolator::MaxOrder
Definition: BarycentricRationalSpanInterpolator.hpp:33
cstddef
gsl::span
Create a span/view on a range, which is cheap to copy (one pointer).
Definition: Gsl.hpp:292
intrp::BarycentricRationalSpanInterpolator::interpolate
double interpolate(const gsl::span< const double > &source_points, const gsl::span< const double > &values, double target_point) const noexcept override
Perform the interpolation of function represented by values at source_points to the requested target_...
Definition: BarycentricRationalSpanInterpolator.cpp:23
Gsl.hpp
intrp::BarycentricRationalSpanInterpolator::required_number_of_points_before_and_after
size_t required_number_of_points_before_and_after() const noexcept override
The number of domain points that should be both before and after the requested target point for best ...
Definition: BarycentricRationalSpanInterpolator.hpp:80
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
complex
intrp::BarycentricRationalSpanInterpolator
Performs a barycentric interpolation with an order in a range fixed at construction; this class can b...
Definition: BarycentricRationalSpanInterpolator.hpp:24
intrp::BarycentricRationalSpanInterpolator::get_clone
std::unique_ptr< SpanInterpolator > get_clone() const noexcept override
Produce a std::unique_ptr that points to a copy of *this`.
Definition: BarycentricRationalSpanInterpolator.hpp:69