TrilinearInterpolation Class Reference

This class interpolates a function of three values (f(x,y,z)). More...

#include <TrilinearInterpolation.h>

## Public Member Functions

TrilinearInterpolation (const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &z, const std::vector< Real > &data)
Constructor initializes data for interpolation. More...

virtual ~TrilinearInterpolation ()=default

Real sample (Real x, Real y, Real z) const
Interpolates for the desired (x,y,z) coordinate and returns the value based on the function values vector. More...

## Protected Member Functions

void getCornerIndices (const std::vector< Real > &v, Real x, int &lower, int &upper, Real &d) const
Finds the indices of the cube that point (x,y,z) is in. More...

Real getCornerValues (int x, int y, int z) const
Searches the function value vector for the value at a given corner coordinate from the getCornerIndices function. More...

## Protected Attributes

std::vector< Real > _x_axis
vector of x-values More...

std::vector< Real > _y_axis
vector of y-values More...

std::vector< Real > _z_axis
vector of z-values More...

std::vector< Real > _fxyz
vector of function values, f(x,y,z) More...

## Detailed Description

This class interpolates a function of three values (f(x,y,z)).

It takes 4 vectors for x, y, z, and function values, f(x,y,z). The vector of function values should be done in the following manner: Function values of constant x and y are written, corresponding with values in vector, z. Function values for the constant x, next y-value, corresponding with values in vector, z. After last y-value, function values for the next x, first y-value, corresponding with values in vector, z.

An example: f(1,4,7) = 10, f(1,4,8) = 11, f(1,4,9) = 12 f(1,5,7) = 13, f(1,5,8) = 14, f(1,5,9) = 15 f(1,6,7) = 16, f(1,6,8) = 17, f(1,6,9) = 18 f(2,4,7) = 20, f(2,4,8) = 21, f(2,4,9) = 22 f(2,5,7) = 23, f(2,5,8) = 24, f(2,5,9) = 25 f(2,6,7) = 26, f(2,6,8) = 27, f(2,6,9) = 28 f(3,4,7) = 30, f(3,4,8) = 31, f(3,4,9) = 32 f(3,5,7) = 33, f(3,5,8) = 34, f(3,5,9) = 35 f(3,6,7) = 36, f(3,6,8) = 37, f(3,6,9) = 38

x = {1, 2, 3}; y = {4, 5, 6}; z = {7, 8, 9}; fxyz = { // fxyz for x = 1 10, 11, 12, 13, 14, 15, 16, 17, 18, // fxyz for x = 2 20, 21, 22, 23, 24, 25, 26, 27, 28, // fxyz for x = 3 30, 31, 32, 33, 34, 35, 36, 37, 38 };

Definition at line 57 of file TrilinearInterpolation.h.

## ◆ TrilinearInterpolation()

 TrilinearInterpolation::TrilinearInterpolation ( const std::vector< Real > & x, const std::vector< Real > & y, const std::vector< Real > & z, const std::vector< Real > & data )

Constructor initializes data for interpolation.

Parameters
 x vector for x-coordinates y vector for y-coordinates z vector for z-coordinates data vector for function values formatted in the same manner as the example

Definition at line 13 of file TrilinearInterpolation.C.

17  : _x_axis(x), _y_axis(y), _z_axis(z), _fxyz(data)
18 {
19  if (_x_axis.size() < 1)
20  mooseError("x vector has zero elements. At least one element is required.");
21  if (_y_axis.size() < 1)
22  mooseError("y vector has zero elements. At least one element is required.");
23  if (_z_axis.size() < 1)
24  mooseError("z vector has zero elements. At least one element is required.");
25  if (_x_axis.size() * _y_axis.size() * _z_axis.size() != data.size())
26  mooseError("The size of data (",
27  data.size(),
28  ") does not match the supplied dimensions (",
29  _x_axis.size(),
30  ", ",
31  _y_axis.size(),
32  ", ",
33  _z_axis.size(),
34  ")");
35 }
std::vector< Real > _y_axis
vector of y-values
std::vector< Real > _x_axis
vector of x-values
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::vector< Real > _fxyz
vector of function values, f(x,y,z)
static PetscErrorCode Vec x
std::vector< Real > _z_axis
vector of z-values

## ◆ ~TrilinearInterpolation()

 virtual TrilinearInterpolation::~TrilinearInterpolation ( )
virtualdefault

## ◆ getCornerIndices()

 void TrilinearInterpolation::getCornerIndices ( const std::vector< Real > & v, Real x, int & lower, int & upper, Real & d ) const
protected

Finds the indices of the cube that point (x,y,z) is in.

Parameters
 [in] v vector to find lower and upper limits for the cube [in] x desired coordinate [out] lower lower limit for cube [out] upper upper limit for cube [out] d ratio of (x - lower) / (upper - lower)

Definition at line 38 of file TrilinearInterpolation.C.

Referenced by sample().

40 {
41  unsigned int N = v.size();
42  if (x < v[0])
43  {
44  lower = 0;
45  upper = 0;
46  }
47  else if (x >= v[N - 1])
48  {
49  lower = N - 1;
50  upper = N - 1;
51  }
52  else
53  {
54  for (unsigned int i = 0; i < N - 1; i++)
55  {
56  if (x > v[i] && x < v[i + 1])
57  {
58  lower = i;
59  upper = i + 1;
60  d = (x - v[lower]) / (v[upper] - v[lower]);
61  break;
62  }
63  else if (x == v[i])
64  {
65  lower = i;
66  upper = i;
67  break;
68  }
69  }
70  }
71 }
PetscInt N
static PetscErrorCode Vec x

## ◆ getCornerValues()

 Real TrilinearInterpolation::getCornerValues ( int x, int y, int z ) const
protected

Searches the function value vector for the value at a given corner coordinate from the getCornerIndices function.

Parameters
 x index for x-coordinate of corner y index for y-coordinate of corner z index for z-coordinate of corner
Returns
function value for the (x,y,z) coordinate

Definition at line 74 of file TrilinearInterpolation.C.

Referenced by sample().

75 {
76  int nY = _y_axis.size();
77  int nZ = _z_axis.size();
78
79  return _fxyz[x * nY * nZ + y * nZ + z];
80 }
std::vector< Real > _y_axis
vector of y-values
std::vector< Real > _fxyz
vector of function values, f(x,y,z)
static PetscErrorCode Vec x
std::vector< Real > _z_axis
vector of z-values

## ◆ sample()

 Real TrilinearInterpolation::sample ( Real x, Real y, Real z ) const

Interpolates for the desired (x,y,z) coordinate and returns the value based on the function values vector.

Parameters
 x desired x-coordinate y desired y-coordinate z desired z-coordinate
Returns
interpolated value at coordinate (x,y,z)

Definition at line 83 of file TrilinearInterpolation.C.

84 {
85  int x0 = 0;
86  int y0 = 0;
87  int z0 = 0;
88  int x1 = 0;
89  int y1 = 0;
90  int z1 = 0;
91  Real Dx = 0;
92  Real Dy = 0;
93  Real Dz = 0;
94
95  // find the the indices of the cube, which contains the point
96  getCornerIndices(_x_axis, x, x0, x1, Dx);
97  getCornerIndices(_y_axis, y, y0, y1, Dy);
98  getCornerIndices(_z_axis, z, z0, z1, Dz);
99
100  // find the corresponding function values for the corner indices
101  Real f000 = getCornerValues(x0, y0, z0);
102  Real f001 = getCornerValues(x0, y0, z1);
103  Real f010 = getCornerValues(x0, y1, z0);
104  Real f011 = getCornerValues(x0, y1, z1);
105  Real f100 = getCornerValues(x1, y0, z0);
106  Real f101 = getCornerValues(x1, y0, z1);
107  Real f110 = getCornerValues(x1, y1, z0);
108  Real f111 = getCornerValues(x1, y1, z1);
109
110  // interpolation
111  Real f00 = (f100 - f000) * Dx + f000;
112  Real f10 = (f110 - f010) * Dx + f010;
113  Real f01 = (f101 - f001) * Dx + f001;
114  Real f11 = (f111 - f011) * Dx + f011;
115  Real f0 = (f10 - f00) * Dy + f00;
116  Real f1 = (f11 - f01) * Dy + f01;
117
118  return (f1 - f0) * Dz + f0;
119 }
std::vector< Real > _y_axis
vector of y-values
Real getCornerValues(int x, int y, int z) const
Searches the function value vector for the value at a given corner coordinate from the getCornerIndic...
std::vector< Real > _x_axis
vector of x-values
static PetscErrorCode Vec x
void getCornerIndices(const std::vector< Real > &v, Real x, int &lower, int &upper, Real &d) const
Finds the indices of the cube that point (x,y,z) is in.
std::vector< Real > _z_axis
vector of z-values

## ◆ _fxyz

 std::vector TrilinearInterpolation::_fxyz
protected

vector of function values, f(x,y,z)

Definition at line 95 of file TrilinearInterpolation.h.

Referenced by getCornerValues().

## ◆ _x_axis

 std::vector TrilinearInterpolation::_x_axis
protected

vector of x-values

Definition at line 86 of file TrilinearInterpolation.h.

Referenced by sample(), and TrilinearInterpolation().

## ◆ _y_axis

 std::vector TrilinearInterpolation::_y_axis
protected

vector of y-values

Definition at line 89 of file TrilinearInterpolation.h.

Referenced by getCornerValues(), sample(), and TrilinearInterpolation().

## ◆ _z_axis

 std::vector TrilinearInterpolation::_z_axis
protected

vector of z-values

Definition at line 92 of file TrilinearInterpolation.h.

Referenced by getCornerValues(), sample(), and TrilinearInterpolation().

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