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 "DataStructures/ComplexModalVector.hpp"
10 : #include "DataStructures/DataVector.hpp"
11 : #include "DataStructures/ModalVector.hpp"
12 : #include "Options/String.hpp"
13 : #include "Utilities/Gsl.hpp"
14 : #include "Utilities/Serialization/CharmPupable.hpp"
15 :
16 : namespace intrp {
17 :
18 : class LinearSpanInterpolator;
19 : class CubicSpanInterpolator;
20 : class BarycentricRationalSpanInterpolator;
21 :
22 : /// \brief Base class for interpolators so that the factory options
23 : /// mechanism can be used.
24 : ///
25 : /// \details The virtual functions in this class demand only that the real
26 : /// `interpolate` function, `get_clone` function, and
27 : /// `required_number_of_points_before_and_after` function be overridden in the
28 : /// derived class. The `interpolate` for complex values can just be used from
29 : /// this base class, which calls the real version for each component. If it is
30 : /// possible to make a specialized complex version that avoids allocations, that
31 : /// is probably more efficient.
32 1 : class SpanInterpolator : public PUP::able {
33 : public:
34 0 : using creatable_classes =
35 : tmpl::list<LinearSpanInterpolator, CubicSpanInterpolator,
36 : BarycentricRationalSpanInterpolator>;
37 :
38 0 : WRAPPED_PUPable_abstract(SpanInterpolator); // NOLINT
39 :
40 : /// Produce a `std::unique_ptr` that points to a copy of `*this``
41 1 : virtual std::unique_ptr<SpanInterpolator> get_clone() const = 0;
42 :
43 : /// Perform the interpolation of function represented by `values` at
44 : /// `source_points` to the requested `target_point`, returning the
45 : /// interpolation result.
46 1 : virtual double interpolate(const gsl::span<const double>& source_points,
47 : const gsl::span<const double>& values,
48 : double target_point) const = 0;
49 :
50 : /// Perform the interpolation of function represented by complex `values` at
51 : /// `source_points` to the requested `target_point`, returning the
52 : /// (complex) interpolation result.
53 1 : std::complex<double> interpolate(
54 : const gsl::span<const double>& source_points,
55 : const gsl::span<const std::complex<double>>& values,
56 : double target_point) const;
57 :
58 : /// Evaluate the derivative of the interpolant of the function represented by
59 : /// `values` at `source_points`, evaluated at the requested `target_point`.
60 1 : virtual double derivative(const gsl::span<const double>& source_points,
61 : const gsl::span<const double>& values,
62 : double target_point) const = 0;
63 :
64 : /// Evaluate the derivative of the interpolant of the function represented by
65 : /// complex `values` at `source_points`, evaluated at the requested
66 : /// `target_point`. This generic implementation calls the real version on the
67 : /// real and imaginary parts separately; derived classes should override it
68 : /// when a specialized complex implementation that avoids the split is more
69 : /// efficient.
70 1 : virtual std::complex<double> derivative(
71 : const gsl::span<const double>& source_points,
72 : const gsl::span<const std::complex<double>>& values,
73 : double target_point) const;
74 :
75 : /// The number of domain points that should be both before and after the
76 : /// requested target point for best interpolation. For instance, for a linear
77 : /// interpolator, this function would return `1` to request that the target is
78 : /// between the two domain points passed to `source_points`.
79 1 : virtual size_t required_number_of_points_before_and_after() const = 0;
80 : };
81 : } // namespace intrp
|