SpECTRE  v2026.06.30
Loading...
Searching...
No Matches
intrp::UniformCardinalBSpline Class Reference

A cubic B-spline interpolant of uniformly spaced samples. More...

#include <UniformCardinalBSpline.hpp>

Public Member Functions

 UniformCardinalBSpline (std::vector< double > values, double start_time, double time_step)
 Construct from uniformly spaced samples.
double operator() (double time) const
 Evaluate the interpolant at time, clamped to the bounds()
const std::vector< double > & values () const
 The sampled function values.
double start_time () const
 The time of the first sample.
double time_step () const
 The spacing between samples.
std::array< double, 2 > bounds () const
 The first and last sample time.
void pup (PUP::er &p)

Detailed Description

A cubic B-spline interpolant of uniformly spaced samples.

Interpolates samples \(f_i = f(t_0 + i \Delta t)\), \(i = 0, \ldots, N-1\), with a cubic B-spline. The interpolation error decreases as \(\mathcal{O}(\Delta t^4)\) for smooth data. This class wraps boost::math::interpolators::cardinal_cubic_b_spline and adds:

  • Serialization: the samples, start time, and time step fully determine the interpolant, so it can be sent in a pup and rebuilt on the receiving side.
  • Clamped evaluation: evaluation is clamped to the bounds of the sampled interval, so times that fall outside the interval by roundoff evaluate to the boundary values instead of extrapolating the spline. Times outside the bounds beyond roundoff trigger an ASSERT in debug builds.

Here is an example how to use this class:

const intrp::UniformCardinalBSpline interpolant{
sample_function(function, start_time, time_step, num_samples),
start_time, time_step};
const double interpolated_value =
interpolant(0.5 * (start_time + end_time));
Note
Requires Boost 1.81 or newer at runtime because of an accuracy fix for the estimate of the derivative at the right endpoint in the Boost implementation, see https://github.com/boostorg/math/commit/4809e714d4806c07da3a3def0c4550daa0529b8d. The constructor raises an error for older Boost versions.

Constructor & Destructor Documentation

◆ UniformCardinalBSpline()

intrp::UniformCardinalBSpline::UniformCardinalBSpline ( std::vector< double > values,
double start_time,
double time_step )

Construct from uniformly spaced samples.

Parameters
valuesThe sampled function values \(f(t_0 + i \Delta t)\). At least 5 samples are required.
start_timeThe time \(t_0\) of the first sample.
time_stepThe (positive) spacing \(\Delta t\) between samples.

The documentation for this class was generated from the following file:
  • src/NumericalAlgorithms/Interpolation/UniformCardinalBSpline.hpp