BarycentricRationalSpanInterpolator.hpp
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 OptionString help = {"Order of barycentric interpolation"};
29  static type lower_bound() noexcept { return 1; }
30  };
31
32  struct MaxOrder {
33  using type = size_t;
34  static constexpr OptionString help = {"Order of barycentric interpolation"};
35  static type upper_bound() noexcept { return 10; }
36  };
37
38  using options = tmpl::list<MinOrder, MaxOrder>;
39  static constexpr OptionString help = {
40  "Barycentric interpolator of option-defined maximum and minimum order."};
41
43  CkMigrateMessage* /*unused*/) noexcept {}
44
46
47  // clang-tidy: do not pass by non-const reference
48  void pup(PUP::er& p) noexcept override { // NOLINT
49  p | min_order_;
50  p | max_order_;
51  }
52
55  const BarycentricRationalSpanInterpolator&) noexcept = default;
57  const BarycentricRationalSpanInterpolator&) noexcept = default;
59  BarycentricRationalSpanInterpolator&&) noexcept = default;
61  BarycentricRationalSpanInterpolator&&) noexcept = default;
62  ~BarycentricRationalSpanInterpolator() noexcept override = default;
63
64  explicit BarycentricRationalSpanInterpolator(size_t min_order,
65  size_t max_order) noexcept;
66
67  std::unique_ptr<SpanInterpolator> get_clone() const noexcept override {
68  return std::make_unique<BarycentricRationalSpanInterpolator>(*this);
69  }
70
71  // to get the generic overload:
73
74  double interpolate(const gsl::span<const double>& source_points,
75  const gsl::span<const double>& values,
76  double target_point) const noexcept override;
77
78  size_t required_number_of_points_before_and_after() const noexcept override {
79  return min_order_ / 2 + 1;
80  }
81
82  private:
83  size_t min_order_ = 1;
84  size_t max_order_ = 10;
85 };
86 } // namespace intrp
Base class for interpolators so that the factory options mechanism can be used.
Definition: SpanInterpolator.hpp:32
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_...
Definition: BarycentricRationalSpanInterpolator.hpp:26
Defines classes and functions for making classes creatable from input files.
Definition: BarycentricRationalSpanInterpolator.hpp:32
Defines macros to allow serialization of abstract template base classes.
Create a span/view on a range, which is cheap to copy (one pointer).
Definition: Gsl.hpp:291
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:29
std::unique_ptr< SpanInterpolator > get_clone() const noexcept override
Produce a std::unique_ptr that points to a copy of *this`.
Definition: BarycentricRationalSpanInterpolator.hpp:67
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
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:78
Performs a barycentric interpolation with an order in a range fixed at construction; this class can b...
Definition: BarycentricRationalSpanInterpolator.hpp:24
Defines functions and classes from the GSL.