PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
Public Member Functions | Private Member Functions | Private Attributes | List of all members
pism::Interpolation Class Reference

#include <interpolation.hh>

Public Member Functions

 Interpolation (InterpolationType type, const std::vector< double > &input_x, const std::vector< double > &output_x)
 
 Interpolation (InterpolationType type, const double *input_x, unsigned int input_x_size, const double *output_x, unsigned int output_x_size)
 
const std::vector< int > & left () const
 
const std::vector< int > & right () const
 
const std::vector< double > & alpha () const
 
int left (size_t j) const
 
int right (size_t j) const
 
double alpha (size_t j) const
 
int n_output () const
 
std::vector< double > interpolate (const std::vector< double > &input_values) const
 Return interpolated values (on the output grid) given input_values on the input grid. More...
 
void interpolate (const double *input, double *output) const
 

Private Member Functions

void init_linear (const double *input_x, unsigned int input_x_size, const double *output_x, unsigned int output_x_size)
 
void init_nearest (const double *input_x, unsigned int input_x_size, const double *output_x, unsigned int output_x_size)
 
void init_piecewise_constant (const double *input_x, unsigned int input_x_size, const double *output_x, unsigned int output_x_size)
 

Private Attributes

std::vector< int > m_left
 Interpolation indexes. More...
 
std::vector< int > m_right
 
std::vector< double > m_alpha
 Interpolation weights. More...
 

Detailed Description

Class encapsulating linear and piece-wise constant interpolation indexes and weights.

Most library interpolation routines (GSL's, for example) assume that we are working with a fixed function given on an input grid; these libraries support evaluating this function at arbitrary points. In this case an interpolation routine may use values on the input grid to create an interpolant, but has no knowledge of an "output grid."

In PISM we have a slightly different situation: we need to transfer several gridded functions between two fixed grids, so we can use both grids to compute interpolation weights, but cannot use values on the input grid.

If a point on the output grid is outside the interval defined by the input grid this code uses constant extrapolation.

This class isolates the code computing interpolation weights so that we can use these 1D weights in a 2D or 3D regridding code. This avoids code duplication: in bilinear (trilinear) interpolation X and Y (and Z) grid dimensions are treated the same. This also makes it possible to test the code computing interpolation weights in isolation.

We provide getters left(), right() and alpha().

Here left[i] is the index in the input grid (x_input) such that

input_x[left[i]] < output_x[i]
const std::vector< int > & left() const

similar for right[i]:

input_x[right[i]] >= output_x[i]
const std::vector< int > & right() const

When output_x[i] is outside the input interval left[i] and right[i] are adjusted so that the interpolation formula below corresponds to constant extrapolation.

alpha[i] is the linear interpolation weight used like this:

const int
L = m_left[k],
R = m_right[k];
const double Alpha = m_alpha[k];
result[k] = input_values[L] + Alpha * (input_values[R] - input_values[L]);
std::vector< double > m_alpha
Interpolation weights.
std::vector< int > m_left
Interpolation indexes.
std::vector< int > m_right
static const double L
Definition: exactTestL.cc:40
static const double k
Definition: exactTestP.cc:42

Piecewise constant 1D interpolation used for time-dependent forcing (fluxes that should be interpreted as piecewise-constant to simplify accounting of mass conservation).

Here input_x defines left end-points of intervals, For example, [0, 1] defines two intervals: [0, 1) and [1, x_e). Here the value x_e is irrelevant because we use constant extrapolation for points outside the interval covered by input data.

Definition at line 81 of file interpolation.hh.


The documentation for this class was generated from the following files: