www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BicubicInterpolation Class Reference

This class interpolates tabulated data with a bicubic function. More...

#include <BicubicInterpolation.h>

Public Member Functions

 BicubicInterpolation (const std::vector< Real > &x1, const std::vector< Real > &x2, const std::vector< std::vector< Real >> &y)
 
virtual ~BicubicInterpolation ()=default
 
void errorCheck ()
 Sanity checks on input data. More...
 
Real sample (Real x1, Real x2)
 Samples value at point (x1, x2) More...
 
void sampleValueAndDerivatives (Real x1, Real x2, Real &y, Real &dy1, Real &dy2)
 Samples value and first derivatives at point (x1, x2) Use this function for speed when computing both value and derivatives, as it minimizes the amount of time spent locating the point in the tabulated data. More...
 
Real sampleDerivative (Real x1, Real x2, unsigned int deriv_var)
 Samples first derivative at point (x1, x2) More...
 
Real sample2ndDerivative (Real x1, Real x2, unsigned int deriv_var)
 Samples second derivative at point (x1, x2) More...
 
void precomputeCoefficients ()
 Precompute all of the coefficients for the bicubic interpolation to avoid calculating them repeatedly. More...
 

Protected Member Functions

void findInterval (const std::vector< Real > &x, Real xi, unsigned int &klo, unsigned int &khi, Real &xs)
 Find the indices of the dependent values axis which bracket the point xi. More...
 
void tableDerivatives (std::vector< std::vector< Real >> &dy_dx1, std::vector< std::vector< Real >> &dy_dx2, std::vector< std::vector< Real >> &d2y_dx1x2)
 Provides the values of the first derivatives in each direction at all points in the table of data, as well as the mixed second derivative. More...
 

Protected Attributes

std::vector< Real > _x1
 Independent values in the x1 direction. More...
 
std::vector< Real > _x2
 Independent values in the x2 direction. More...
 
std::vector< std::vector< Real > > _y
 The dependent values at (x1, x2) points. More...
 
std::vector< std::vector< std::vector< std::vector< Real > > > > _bicubic_coeffs
 Matrix of precomputed coefficients There are four coefficients in each direction at each dependent value. More...
 
const std::vector< std::vector< int > > _wt
 Matrix used to calculate bicubic interpolation coefficients (from Numerical Recipes) More...
 

Detailed Description

This class interpolates tabulated data with a bicubic function.

In order to minimize the computational expense of each sample, the coefficients at each point in the tabulated data are computed once in advance, and then accessed during the interpolation.

As a result, this bicubic interpolation can be much faster than the bicubic spline interpolation method in BicubicSplineInterpolation.

Adapted from Numerical Recipes in C (section 3.6). The terminology used is consistent with that used in Numerical Recipes, where moving over a column corresponds to moving over the x1 coord. Likewise, moving over a row means moving over the x2 coord.

Definition at line 29 of file BicubicInterpolation.h.

Constructor & Destructor Documentation

◆ BicubicInterpolation()

BicubicInterpolation::BicubicInterpolation ( const std::vector< Real > &  x1,
const std::vector< Real > &  x2,
const std::vector< std::vector< Real >> &  y 
)

Definition at line 15 of file BicubicInterpolation.C.

18  : _x1(x1), _x2(x2), _y(y)
19 {
20  errorCheck();
21 
22  // Resize the vector of coefficients
23  auto m = _x1.size();
24  auto n = _x2.size();
25 
26  _bicubic_coeffs.resize(m - 1);
27  for (auto i = beginIndex(_bicubic_coeffs); i < _bicubic_coeffs.size(); ++i)
28  {
29  _bicubic_coeffs[i].resize(n - 1);
30  for (auto j = beginIndex(_bicubic_coeffs[i]); j < _bicubic_coeffs[i].size(); ++j)
31  {
32  _bicubic_coeffs[i][j].resize(4);
33  for (unsigned int k = 0; k < 4; ++k)
34  _bicubic_coeffs[i][j][k].resize(4);
35  }
36  }
37 
38  // Precompute the coefficients
40 }
void precomputeCoefficients()
Precompute all of the coefficients for the bicubic interpolation to avoid calculating them repeatedly...
std::vector< Real > _x2
Independent values in the x2 direction.
std::vector< std::vector< Real > > _y
The dependent values at (x1, x2) points.
std::vector< std::vector< std::vector< std::vector< Real > > > > _bicubic_coeffs
Matrix of precomputed coefficients There are four coefficients in each direction at each dependent va...
PetscInt m
PetscInt n
void errorCheck()
Sanity checks on input data.
std::vector< Real > _x1
Independent values in the x1 direction.

◆ ~BicubicInterpolation()

virtual BicubicInterpolation::~BicubicInterpolation ( )
virtualdefault

Member Function Documentation

◆ errorCheck()

void BicubicInterpolation::errorCheck ( )

Sanity checks on input data.

Definition at line 347 of file BicubicInterpolation.C.

Referenced by BicubicInterpolation().

348 {
349  auto m = _x1.size(), n = _x2.size();
350 
351  if (_y.size() != m)
352  mooseError("y row dimension does not match the size of x1 in BicubicInterpolation");
353  else
354  for (auto i = beginIndex(_y); i < _y.size(); ++i)
355  if (_y[i].size() != n)
356  mooseError("y column dimension does not match the size of x2 in BicubicInterpolation");
357 }
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 > _x2
Independent values in the x2 direction.
std::vector< std::vector< Real > > _y
The dependent values at (x1, x2) points.
PetscInt m
PetscInt n
std::vector< Real > _x1
Independent values in the x1 direction.

◆ findInterval()

void BicubicInterpolation::findInterval ( const std::vector< Real > &  x,
Real  xi,
unsigned int &  klo,
unsigned int &  khi,
Real &  xs 
)
protected

Find the indices of the dependent values axis which bracket the point xi.

Definition at line 320 of file BicubicInterpolation.C.

Referenced by sample(), sample2ndDerivative(), sampleDerivative(), and sampleValueAndDerivatives().

322 {
323  // Find the indices that bracket the point xi
324  klo = 0;
325  mooseAssert(x.size() >= 2,
326  "There must be at least two points in the table in BicubicInterpolation");
327 
328  khi = x.size() - 1;
329  while (khi - klo > 1)
330  {
331  unsigned int kmid = (khi + klo) / 2;
332  if (x[kmid] > xi)
333  khi = kmid;
334  else
335  klo = kmid;
336  }
337 
338  // Now find the scaled position, normalized to [0,1]
339  Real d = x[khi] - x[klo];
340  xs = xi - x[klo];
341 
342  if (!MooseUtils::absoluteFuzzyEqual(d, 0.0))
343  xs /= d;
344 }
static PetscErrorCode Vec x
bool absoluteFuzzyEqual(const libMesh::Real &var1, const libMesh::Real &var2, const libMesh::Real &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.

◆ precomputeCoefficients()

void BicubicInterpolation::precomputeCoefficients ( )

Precompute all of the coefficients for the bicubic interpolation to avoid calculating them repeatedly.

Definition at line 191 of file BicubicInterpolation.C.

Referenced by BicubicInterpolation().

192 {
193  // Calculate the first derivatives in each direction at each point, and the
194  // mixed second derivative
195  std::vector<std::vector<Real>> dy_dx1, dy_dx2, d2y_dx1x2;
196  tableDerivatives(dy_dx1, dy_dx2, d2y_dx1x2);
197 
198  // Now solve for the coefficients at each point in the grid
199  for (auto i = beginIndex(_bicubic_coeffs); i < _bicubic_coeffs.size(); ++i)
200  for (auto j = beginIndex(_bicubic_coeffs); j < _bicubic_coeffs[i].size(); ++j)
201  {
202  // Distance between corner points in each direction
203  const Real d1 = _x1[i + 1] - _x1[i];
204  const Real d2 = _x2[j + 1] - _x2[j];
205 
206  // Values of function and derivatives of the four corner points
207  std::vector<Real> y = {_y[i][j], _y[i + 1][j], _y[i + 1][j + 1], _y[i][j + 1]};
208  std::vector<Real> y1 = {
209  dy_dx1[i][j], dy_dx1[i + 1][j], dy_dx1[i + 1][j + 1], dy_dx1[i][j + 1]};
210  std::vector<Real> y2 = {
211  dy_dx2[i][j], dy_dx2[i + 1][j], dy_dx2[i + 1][j + 1], dy_dx2[i][j + 1]};
212  std::vector<Real> y12 = {
213  d2y_dx1x2[i][j], d2y_dx1x2[i + 1][j], d2y_dx1x2[i + 1][j + 1], d2y_dx1x2[i][j + 1]};
214 
215  std::vector<Real> cl(16), x(16);
216  Real xx;
217  unsigned int count = 0;
218 
219  // Temporary vector used in the matrix multiplication
220  for (unsigned int k = 0; k < 4; ++k)
221  {
222  x[k] = y[k];
223  x[k + 4] = y1[k] * d1;
224  x[k + 8] = y2[k] * d2;
225  x[k + 12] = y12[k] * d1 * d2;
226  }
227 
228  // Multiply by the matrix of constants
229  for (unsigned int k = 0; k < 16; ++k)
230  {
231  xx = 0.0;
232  for (unsigned int q = 0; q < 16; ++q)
233  xx += _wt[k][q] * x[q];
234 
235  cl[k] = xx;
236  }
237 
238  // Unpack results into coefficient table
239  for (unsigned int k = 0; k < 4; ++k)
240  for (unsigned int q = 0; q < 4; ++q)
241  {
242  _bicubic_coeffs[i][j][k][q] = cl[count];
243  count++;
244  }
245  }
246 }
const std::vector< std::vector< int > > _wt
Matrix used to calculate bicubic interpolation coefficients (from Numerical Recipes) ...
std::vector< Real > _x2
Independent values in the x2 direction.
std::vector< std::vector< Real > > _y
The dependent values at (x1, x2) points.
static PetscErrorCode Vec x
std::vector< std::vector< std::vector< std::vector< Real > > > > _bicubic_coeffs
Matrix of precomputed coefficients There are four coefficients in each direction at each dependent va...
std::vector< Real > _x1
Independent values in the x1 direction.
void tableDerivatives(std::vector< std::vector< Real >> &dy_dx1, std::vector< std::vector< Real >> &dy_dx2, std::vector< std::vector< Real >> &d2y_dx1x2)
Provides the values of the first derivatives in each direction at all points in the table of data...

◆ sample()

Real BicubicInterpolation::sample ( Real  x1,
Real  x2 
)

Samples value at point (x1, x2)

Definition at line 43 of file BicubicInterpolation.C.

44 {
45  unsigned int x1l, x1u, x2l, x2u;
46  Real t, u;
47  findInterval(_x1, x1, x1l, x1u, t);
48  findInterval(_x2, x2, x2l, x2u, u);
49 
50  Real sample = 0.0;
51  for (unsigned int i = 0; i < 4; ++i)
52  for (unsigned int j = 0; j < 4; ++j)
53  sample += _bicubic_coeffs[x1l][x2l][i][j] * MathUtils::pow(t, i) * MathUtils::pow(u, j);
54 
55  return sample;
56 }
Real sample(Real x1, Real x2)
Samples value at point (x1, x2)
std::vector< Real > _x2
Independent values in the x2 direction.
std::vector< std::vector< std::vector< std::vector< Real > > > > _bicubic_coeffs
Matrix of precomputed coefficients There are four coefficients in each direction at each dependent va...
Real pow(Real x, int e)
Definition: MathUtils.C:211
void findInterval(const std::vector< Real > &x, Real xi, unsigned int &klo, unsigned int &khi, Real &xs)
Find the indices of the dependent values axis which bracket the point xi.
std::vector< Real > _x1
Independent values in the x1 direction.

◆ sample2ndDerivative()

Real BicubicInterpolation::sample2ndDerivative ( Real  x1,
Real  x2,
unsigned int  deriv_var 
)

Samples second derivative at point (x1, x2)

Definition at line 107 of file BicubicInterpolation.C.

108 {
109  unsigned int x1l, x1u, x2l, x2u;
110  Real t, u;
111  findInterval(_x1, x1, x1l, x1u, t);
112  findInterval(_x2, x2, x2l, x2u, u);
113 
114  // Take derivative along x1 axis
115  // Note: sum from i = 2 as the first two terms are zero
116  if (deriv_var == 1)
117  {
118  Real sample_deriv = 0.0;
119  for (unsigned int i = 2; i < 4; ++i)
120  for (unsigned int j = 0; j < 4; ++j)
121  sample_deriv += i * (i - 1) * _bicubic_coeffs[x1l][x2l][i][j] * MathUtils::pow(t, i - 2) *
122  MathUtils::pow(u, j);
123 
124  Real d = _x1[x1u] - _x1[x1l];
125 
126  if (!MooseUtils::absoluteFuzzyEqual(d, 0.0))
127  sample_deriv /= (d * d);
128 
129  return sample_deriv;
130  }
131 
132  // Take derivative along x2 axis
133  // Note: sum from j = 2 as the first two terms are zero
134  else if (deriv_var == 2)
135  {
136  Real sample_deriv = 0.0;
137  for (unsigned int i = 0; i < 4; ++i)
138  for (unsigned int j = 2; j < 4; ++j)
139  sample_deriv += j * (j - 1) * _bicubic_coeffs[x1l][x2l][i][j] * MathUtils::pow(t, i) *
140  MathUtils::pow(u, j - 2);
141 
142  Real d = _x2[x2u] - _x2[x2l];
143 
144  if (!MooseUtils::absoluteFuzzyEqual(d, 0.0))
145  sample_deriv /= (d * d);
146 
147  return sample_deriv;
148  }
149 
150  else
151  mooseError("deriv_var must be either 1 or 2 in BicubicInterpolation");
152 }
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 > _x2
Independent values in the x2 direction.
std::vector< std::vector< std::vector< std::vector< Real > > > > _bicubic_coeffs
Matrix of precomputed coefficients There are four coefficients in each direction at each dependent va...
Real pow(Real x, int e)
Definition: MathUtils.C:211
bool absoluteFuzzyEqual(const libMesh::Real &var1, const libMesh::Real &var2, const libMesh::Real &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
void findInterval(const std::vector< Real > &x, Real xi, unsigned int &klo, unsigned int &khi, Real &xs)
Find the indices of the dependent values axis which bracket the point xi.
std::vector< Real > _x1
Independent values in the x1 direction.

◆ sampleDerivative()

Real BicubicInterpolation::sampleDerivative ( Real  x1,
Real  x2,
unsigned int  deriv_var 
)

Samples first derivative at point (x1, x2)

Definition at line 59 of file BicubicInterpolation.C.

60 {
61  unsigned int x1l, x1u, x2l, x2u;
62  Real t, u;
63  findInterval(_x1, x1, x1l, x1u, t);
64  findInterval(_x2, x2, x2l, x2u, u);
65 
66  // Take derivative along x1 axis
67  // Note: sum from i = 1 as the first term is zero
68  if (deriv_var == 1)
69  {
70  Real sample_deriv = 0.0;
71  for (unsigned int i = 1; i < 4; ++i)
72  for (unsigned int j = 0; j < 4; ++j)
73  sample_deriv +=
74  i * _bicubic_coeffs[x1l][x2l][i][j] * MathUtils::pow(t, i - 1) * MathUtils::pow(u, j);
75 
76  Real d = _x1[x1u] - _x1[x1l];
77 
78  if (!MooseUtils::absoluteFuzzyEqual(d, 0.0))
79  sample_deriv /= d;
80 
81  return sample_deriv;
82  }
83 
84  // Take derivative along x2 axis
85  // Note: sum from j = 1 as the first term is zero
86  else if (deriv_var == 2)
87  {
88  Real sample_deriv = 0.0;
89  for (unsigned int i = 0; i < 4; ++i)
90  for (unsigned int j = 1; j < 4; ++j)
91  sample_deriv +=
92  j * _bicubic_coeffs[x1l][x2l][i][j] * MathUtils::pow(t, i) * MathUtils::pow(u, j - 1);
93 
94  Real d = _x2[x2u] - _x2[x2l];
95 
96  if (!MooseUtils::absoluteFuzzyEqual(d, 0.0))
97  sample_deriv /= d;
98 
99  return sample_deriv;
100  }
101 
102  else
103  mooseError("deriv_var must be either 1 or 2 in BicubicInterpolation");
104 }
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 > _x2
Independent values in the x2 direction.
std::vector< std::vector< std::vector< std::vector< Real > > > > _bicubic_coeffs
Matrix of precomputed coefficients There are four coefficients in each direction at each dependent va...
Real pow(Real x, int e)
Definition: MathUtils.C:211
bool absoluteFuzzyEqual(const libMesh::Real &var1, const libMesh::Real &var2, const libMesh::Real &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
void findInterval(const std::vector< Real > &x, Real xi, unsigned int &klo, unsigned int &khi, Real &xs)
Find the indices of the dependent values axis which bracket the point xi.
std::vector< Real > _x1
Independent values in the x1 direction.

◆ sampleValueAndDerivatives()

void BicubicInterpolation::sampleValueAndDerivatives ( Real  x1,
Real  x2,
Real &  y,
Real &  dy1,
Real &  dy2 
)

Samples value and first derivatives at point (x1, x2) Use this function for speed when computing both value and derivatives, as it minimizes the amount of time spent locating the point in the tabulated data.

Definition at line 155 of file BicubicInterpolation.C.

156 {
157  unsigned int x1l, x1u, x2l, x2u;
158  Real t, u;
159  findInterval(_x1, x1, x1l, x1u, t);
160  findInterval(_x2, x2, x2l, x2u, u);
161 
162  y = 0.0;
163  for (unsigned int i = 0; i < 4; ++i)
164  for (unsigned int j = 0; j < 4; ++j)
165  y += _bicubic_coeffs[x1l][x2l][i][j] * MathUtils::pow(t, i) * MathUtils::pow(u, j);
166 
167  // Note: sum from i = 1 as the first term is zero
168  dy1 = 0.0;
169  for (unsigned int i = 1; i < 4; ++i)
170  for (unsigned int j = 0; j < 4; ++j)
171  dy1 += i * _bicubic_coeffs[x1l][x2l][i][j] * MathUtils::pow(t, i - 1) * MathUtils::pow(u, j);
172 
173  // Note: sum from j = 1 as the first term is zero
174  dy2 = 0.0;
175  for (unsigned int i = 0; i < 4; ++i)
176  for (unsigned int j = 1; j < 4; ++j)
177  dy2 += j * _bicubic_coeffs[x1l][x2l][i][j] * MathUtils::pow(t, i) * MathUtils::pow(u, j - 1);
178 
179  Real d1 = _x1[x1u] - _x1[x1l];
180 
181  if (!MooseUtils::absoluteFuzzyEqual(d1, 0.0))
182  dy1 /= d1;
183 
184  Real d2 = _x2[x2u] - _x2[x2l];
185 
186  if (!MooseUtils::absoluteFuzzyEqual(d2, 0.0))
187  dy2 /= d2;
188 }
std::vector< Real > _x2
Independent values in the x2 direction.
std::vector< std::vector< std::vector< std::vector< Real > > > > _bicubic_coeffs
Matrix of precomputed coefficients There are four coefficients in each direction at each dependent va...
Real pow(Real x, int e)
Definition: MathUtils.C:211
bool absoluteFuzzyEqual(const libMesh::Real &var1, const libMesh::Real &var2, const libMesh::Real &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
void findInterval(const std::vector< Real > &x, Real xi, unsigned int &klo, unsigned int &khi, Real &xs)
Find the indices of the dependent values axis which bracket the point xi.
std::vector< Real > _x1
Independent values in the x1 direction.

◆ tableDerivatives()

void BicubicInterpolation::tableDerivatives ( std::vector< std::vector< Real >> &  dy_dx1,
std::vector< std::vector< Real >> &  dy_dx2,
std::vector< std::vector< Real >> &  d2y_dx1x2 
)
protected

Provides the values of the first derivatives in each direction at all points in the table of data, as well as the mixed second derivative.

This is implemented using finite differencing, but could be supplied through other means (such as by sampling with cubic splines)

Definition at line 249 of file BicubicInterpolation.C.

Referenced by precomputeCoefficients().

252 {
253  auto m = _x1.size(), n = _x2.size();
254  dy_dx1.resize(m);
255  dy_dx2.resize(m);
256  d2y_dx1x2.resize(m);
257 
258  for (auto i = beginIndex(_x1); i < m; ++i)
259  {
260  dy_dx1[i].resize(n);
261  dy_dx2[i].resize(n);
262  d2y_dx1x2[i].resize(n);
263  }
264 
265  // Central difference calculations of derivatives
266  for (auto i = beginIndex(_y); i < m; ++i)
267  for (auto j = beginIndex(_y[i]); j < n; ++j)
268  {
269  // Derivative wrt x1
270  if (i == 0)
271  {
272  dy_dx1[i][j] = (_y[i + 1][j] - _y[i][j]) / (_x1[i + 1] - _x1[i]);
273  }
274  else if (i == m - 1)
275  dy_dx1[i][j] = (_y[i][j] - _y[i - 1][j]) / (_x1[i] - _x1[i - 1]);
276  else
277  dy_dx1[i][j] = (_y[i + 1][j] - _y[i - 1][j]) / (_x1[i + 1] - _x1[i - 1]);
278 
279  // Derivative wrt x2
280  if (j == 0)
281  dy_dx2[i][j] = (_y[i][j + 1] - _y[i][j]) / (_x2[j + 1] - _x2[j]);
282  else if (j == n - 1)
283  dy_dx2[i][j] = (_y[i][j] - _y[i][j - 1]) / (_x2[j] - _x2[j - 1]);
284  else
285  dy_dx2[i][j] = (_y[i][j + 1] - _y[i][j - 1]) / (_x2[j + 1] - _x2[j - 1]);
286 
287  // Mixed derivative d2y/dx1x2
288  if (i == 0 && j == 0)
289  d2y_dx1x2[i][j] = (_y[i + 1][j + 1] - _y[i + 1][j] - _y[i][j + 1] + _y[i][j]) /
290  (_x1[i + 1] - _x1[i]) / (_x2[j + 1] - _x2[j]);
291  else if (i == 0 && j == n - 1)
292  d2y_dx1x2[i][j] = (_y[i + 1][j] - _y[i + 1][j - 1] - _y[i][j] + _y[i][j - 1]) /
293  (_x1[i + 1] - _x1[i]) / (_x2[j] - _x2[j - 1]);
294  else if (i == m - 1 && j == 0)
295  d2y_dx1x2[i][j] = (_y[i][j + 1] - _y[i][j] - _y[i - 1][j + 1] + _y[i - 1][j]) /
296  (_x1[i] - _x1[i - 1]) / (_x2[j + 1] - _x2[j]);
297  else if (i == m - 1 && j == n - 1)
298  d2y_dx1x2[i][j] = (_y[i][j] - _y[i][j - 1] - _y[i - 1][j] + _y[i - 1][j - 1]) /
299  (_x1[i] - _x1[i - 1]) / (_x2[j] - _x2[j - 1]);
300  else if (i == 0)
301  d2y_dx1x2[i][j] = (_y[i + 1][j + 1] - _y[i + 1][j - 1] - _y[i][j + 1] + _y[i][j - 1]) /
302  (_x1[i + 1] - _x1[i]) / (_x2[j + 1] - _x2[j - 1]);
303  else if (i == m - 1)
304  d2y_dx1x2[i][j] = (_y[i][j + 1] - _y[i][j - 1] - _y[i - 1][j + 1] + _y[i - 1][j - 1]) /
305  (_x1[i] - _x1[i - 1]) / (_x2[j + 1] - _x2[j - 1]);
306  else if (j == 0)
307  d2y_dx1x2[i][j] = (_y[i + 1][j + 1] - _y[i + 1][j] - _y[i - 1][j + 1] + _y[i - 1][j]) /
308  (_x1[i + 1] - _x1[i - 1]) / (_x2[j + 1] - _x2[j]);
309  else if (j == n - 1)
310  d2y_dx1x2[i][j] = (_y[i + 1][j] - _y[i + 1][j - 1] - _y[i - 1][j] + _y[i - 1][j - 1]) /
311  (_x1[i + 1] - _x1[i - 1]) / (_x2[j] - _x2[j - 1]);
312  else
313  d2y_dx1x2[i][j] =
314  (_y[i + 1][j + 1] - _y[i + 1][j - 1] - _y[i - 1][j + 1] + _y[i - 1][j - 1]) /
315  (_x1[i + 1] - _x1[i - 1]) / (_x2[j + 1] - _x2[j - 1]);
316  }
317 }
std::vector< Real > _x2
Independent values in the x2 direction.
std::vector< std::vector< Real > > _y
The dependent values at (x1, x2) points.
PetscInt m
PetscInt n
std::vector< Real > _x1
Independent values in the x1 direction.

Member Data Documentation

◆ _bicubic_coeffs

std::vector<std::vector<std::vector<std::vector<Real> > > > BicubicInterpolation::_bicubic_coeffs
protected

Matrix of precomputed coefficients There are four coefficients in each direction at each dependent value.

Definition at line 98 of file BicubicInterpolation.h.

Referenced by BicubicInterpolation(), precomputeCoefficients(), sample(), sample2ndDerivative(), sampleDerivative(), and sampleValueAndDerivatives().

◆ _wt

const std::vector<std::vector<int> > BicubicInterpolation::_wt
protected
Initial value:
{
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{-3, 0, 0, 3, 0, 0, 0, 0, -2, 0, 0, -1, 0, 0, 0, 0},
{2, 0, 0, -2, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, -3, 0, 0, 3, 0, 0, 0, 0, -2, 0, 0, -1},
{0, 0, 0, 0, 2, 0, 0, -2, 0, 0, 0, 0, 1, 0, 0, 1},
{-3, 3, 0, 0, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, -3, 3, 0, 0, -2, -1, 0, 0},
{9, -9, 9, -9, 6, 3, -3, -6, 6, -6, -3, 3, 4, 2, 1, 2},
{-6, 6, -6, 6, -4, -2, 2, 4, -3, 3, 3, -3, -2, -1, -1, -2},
{2, -2, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 2, -2, 0, 0, 1, 1, 0, 0},
{-6, 6, -6, 6, -3, -3, 3, 3, -4, 4, 2, -2, -2, -2, -1, -1},
{4, -4, 4, -4, 2, 2, -2, -2, 2, -2, -2, 2, 1, 1, 1, 1}}

Matrix used to calculate bicubic interpolation coefficients (from Numerical Recipes)

Definition at line 102 of file BicubicInterpolation.h.

Referenced by precomputeCoefficients().

◆ _x1

std::vector<Real> BicubicInterpolation::_x1
protected

◆ _x2

std::vector<Real> BicubicInterpolation::_x2
protected

◆ _y

std::vector<std::vector<Real> > BicubicInterpolation::_y
protected

The dependent values at (x1, x2) points.

Definition at line 94 of file BicubicInterpolation.h.

Referenced by errorCheck(), precomputeCoefficients(), and tableDerivatives().


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