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