SpECTRE  v2022.09.02
intrp Namespace Reference

Contains classes and functions for interpolation. More...

Namespaces

namespace  Actions
 Holds Actions for Interpolator and InterpolationTarget.
 
namespace  callbacks
 Contains callback functions called by InterpolationTargets.
 
namespace  protocols
 Contains all protocols used in the interpolation framework.
 
namespace  Tags
 Tags for items held in the DataBox of InterpolationTarget or Interpolator.
 
namespace  Vars
 Data structures holding quantities that are interpolated by Interpolator for use by InterpolationTargets.
 

Classes

class  BarycentricRational
 A barycentric rational interpolation class. More...
 
class  BarycentricRationalSpanInterpolator
 Performs a barycentric interpolation with an order in a range fixed at construction; this class can be chosen via the options factory mechanism as a possible SpanInterpolator. More...
 
class  CubicSpanInterpolator
 Performs a cubic interpolation; this class can be chosen via the options factory mechanism as a possible SpanInterpolator. More...
 
class  CubicSpline
 A natural cubic spline interpolation class. More...
 
struct  InterpolationTarget
 ParallelComponent representing a set of points to be interpolated to and a function to call upon interpolation to those points. More...
 
struct  Interpolator
 ParallelComponent responsible for collecting data from Elements and interpolating it onto InterpolationTargets. More...
 
class  Irregular
 Interpolates a Variables onto an arbitrary set of points. More...
 
class  LinearLeastSquares
 A linear least squares solver class. More...
 
struct  LinearRegressionResult
 
class  LinearSpanInterpolator
 Performs a linear interpolation; this class can be chosen via the options factory mechanism as a possible SpanInterpolator More...
 
class  RegularGrid
 Interpolate data from a Mesh onto a regular grid of points. More...
 
class  SpanInterpolator
 Base class for interpolators so that the factory options mechanism can be used. More...
 
class  ZeroCrossingPredictor
 A class that predicts when a function crosses zero. More...
 

Enumerations

enum class  AngularOrdering { Strahlkorper , Cce }
 Label for the ordering of spherical harmonic points on a sphere. More...
 

Functions

template<size_t Dim>
bool operator!= (const Irregular< Dim > &lhs, const Irregular< Dim > &rhs)
 
template<typename T >
LinearRegressionResult linear_regression (const T &x_values, const T &y_values)
 A linear regression function. More...
 
template<size_t Degree>
void polynomial_interpolation (gsl::not_null< double * > y, gsl::not_null< double * > error_in_y, double target_x, const gsl::span< const double > &y_values, const gsl::span< const double > &x_values)
 Interpolate y_values to target_x from tabulated x_values using a polynomial interpolant of degree Degree. More...
 
double predicted_zero_crossing_value (const std::vector< double > &x_values, const std::vector< double > &y_values)
 Predicts the zero crossing of a function. More...
 
DataVector predicted_zero_crossing_value (const std::deque< double > &x_values, const std::deque< DataVector > &y_values)
 Predicts the zero crossing of multiple functions. More...
 
template<size_t Dim>
bool operator!= (const RegularGrid< Dim > &lhs, const RegularGrid< Dim > &rhs)
 
bool operator!= (const ZeroCrossingPredictor &, const ZeroCrossingPredictor &)
 
template<typename InterpolationTargetTag , typename Metavariables , typename DbTags >
void try_to_interpolate (const gsl::not_null< db::DataBox< DbTags > * > box, const gsl::not_null< Parallel::GlobalCache< Metavariables > * > cache, const typename InterpolationTargetTag::temporal_id::type &temporal_id)
 Check if we have enough information to interpolate. If so, do the interpolation and send data to the InterpolationTarget.
 
template<typename InterpolationTargetTag , size_t VolumeDim, typename Metavariables , typename... InterpolatorSourceVars>
void interpolate (const typename InterpolationTargetTag::temporal_id::type &temporal_id, const Mesh< VolumeDim > &mesh, Parallel::GlobalCache< Metavariables > &cache, const ElementId< VolumeDim > &array_index, const InterpolatorSourceVars &... interpolator_source_vars_input)
 
std::ostreamoperator<< (std::ostream &os, AngularOrdering ordering)
 

Detailed Description

Contains classes and functions for interpolation.

Enumeration Type Documentation

◆ AngularOrdering

enum class intrp::AngularOrdering
strong

Label for the ordering of spherical harmonic points on a sphere.

Details

Strahlkorper refers to points on a sphere ordered by SPHEREPACK because Strahlkorpers hold YlmSpherePacks internally. Cce refers to points on a sphere ordered by Libsharp because Cce uses Libsharp internally.

Function Documentation

◆ polynomial_interpolation()

template<size_t Degree>
void intrp::polynomial_interpolation ( gsl::not_null< double * >  y,
gsl::not_null< double * >  error_in_y,
double  target_x,
const gsl::span< const double > &  y_values,
const gsl::span< const double > &  x_values 
)

Interpolate y_values to target_x from tabulated x_values using a polynomial interpolant of degree Degree.

error_in_y is an estimate of the error of the interpolated value. Note that at least in the tests this is a significant overestimate of the errors (several orders of magnitude). However, this could be because in the test the polynomial can be represented exactly when all terms are present, but incurs significant errors when the largest degree term is omitted.

◆ predicted_zero_crossing_value() [1/2]

DataVector intrp::predicted_zero_crossing_value ( const std::deque< double > &  x_values,
const std::deque< DataVector > &  y_values 
)

Predicts the zero crossing of multiple functions.

For the ith element of the DataVector inside y_values, calls predicted_zero_crossing_value(x_values,y_values[:][i]), where we have used python-like notation.

◆ predicted_zero_crossing_value() [2/2]

double intrp::predicted_zero_crossing_value ( const std::vector< double > &  x_values,
const std::vector< double > &  y_values 
)

Predicts the zero crossing of a function.

Fits a linear function to a set of y_values at different x_values and uses the fit to predict what x_value the y_value zero will be crossed.

predicted_zero_crossing treats x=0 in a special way: All of the x_values must be non-positive; one of the x_values is typically (but is not required to be) zero. In typical usage, x is time, and x=0 is the current time, and we are interested in whether the function crosses zero in the past or in the future. If it cannot be determined (within the error bars of the fit) whether the zero crossing occurs for x < 0 versus x > 0, then we return zero. Otherwise we return the best-fit x for when the function crosses zero.

Details

We fit to a straight line: y = intercept + slope*x. So our best guess is that the function will cross zero at x_best_fit = -intercept/slope.

However, the data are assumed to be noisy. The fit gives us error bars for the slope and the intercept. Given the error bars, we can compute four limiting crossing values x0, x1, x2, and x3 by using the maximum and minimum possible values of slope and intercept. For example, if we assume slope<0 and intercept>0, then the earliest possible crossing consistent with the error bars is x3=(-intercept+delta_intercept)/(slope-delta_slope) and the latest possible crossing consistent with the error bars is x0=(-intercept-delta_intercept)/(slope+delta_slope).

We compute all four crossing values and demand that all of them are either at x>0 (i.e. in the future if x is time) or at x<0 (i.e. in the past if x is time). Otherwise we conclude that we cannot determine even the sign of the crossing value, so we return zero.