www.mooseframework.org
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
BilinearInterpolation Class Reference

This class applies the Least Squares algorithm to a set of points to provide a smooth curve for sampling values. More...

#include <BilinearInterpolation.h>

Public Member Functions

 BilinearInterpolation (const std::vector< Real > &XAXIS, const std::vector< Real > &YAXIS, const ColumnMajorMatrix &ZSURFACE)
 Constructor, Takes two vectors of points for which to apply the fit. More...
 
virtual ~BilinearInterpolation ()=default
 
Real sample (Real xcoord, Real ycoord)
 This function will take an independent variable input and will return the dependent variable based on the generated fit. More...
 
void getNeighborIndices (const std::vector< Real > &inArr, Real x, int &lowerX, int &upperX)
 

Private Attributes

std::vector< Real > _xAxis
 
std::vector< Real > _yAxis
 
ColumnMajorMatrix _zSurface
 

Static Private Attributes

static int _file_number = 0
 

Detailed Description

This class applies the Least Squares algorithm to a set of points to provide a smooth curve for sampling values.

BilinearInterpolation is designed to linearly interpolate a function of two values e.g. z(x,y). Supply Bilinearlinear with a vector of x and a vector of y and a ColumnMajorMatrix of function values, z, that correspond to the values in the vectors x and y...and also a sample point (xcoord and ycoord), and BilinearInterpolation will return the value of the function at the sample point. A simple example:

x = [1 2], y = [1 2],

z = [1 2] [3 4]

with xcoord = 1.5 and ycoord = 1.5 returns a value of 2.5.

Definition at line 42 of file BilinearInterpolation.h.

Constructor & Destructor Documentation

BilinearInterpolation::BilinearInterpolation ( const std::vector< Real > &  XAXIS,
const std::vector< Real > &  YAXIS,
const ColumnMajorMatrix ZSURFACE 
)

Constructor, Takes two vectors of points for which to apply the fit.

One should be of the independent variable while the other should be of the dependent variable. These values should correspond to one and other in the same position.

Definition at line 19 of file BilinearInterpolation.C.

22  : _xAxis(x), _yAxis(y), _zSurface(z)
23 {
24 }
std::vector< Real > _xAxis
std::vector< Real > _yAxis
static PetscErrorCode Vec x
ColumnMajorMatrix _zSurface
virtual BilinearInterpolation::~BilinearInterpolation ( )
virtualdefault

Member Function Documentation

void BilinearInterpolation::getNeighborIndices ( const std::vector< Real > &  inArr,
Real  x,
int &  lowerX,
int &  upperX 
)

Definition at line 27 of file BilinearInterpolation.C.

Referenced by sample().

31 {
32  int N = inArr.size();
33  if (x <= inArr[0])
34  {
35  lowerX = 0;
36  upperX = 0;
37  }
38  else if (x >= inArr[N - 1])
39  {
40  lowerX = N - 1;
41  upperX = N - 1;
42  }
43  else
44  {
45  for (int i = 1; i < N; ++i)
46  {
47  if (x < inArr[i])
48  {
49  lowerX = i - 1;
50  upperX = i;
51  break;
52  }
53  else if (x == inArr[i])
54  {
55  lowerX = i;
56  upperX = i;
57  break;
58  }
59  }
60  }
61 }
PetscInt N
static PetscErrorCode Vec x
Real BilinearInterpolation::sample ( Real  xcoord,
Real  ycoord 
)

This function will take an independent variable input and will return the dependent variable based on the generated fit.

Definition at line 64 of file BilinearInterpolation.C.

65 {
66  // first find 4 neighboring points
67  int lx = 0; // index of x coordinate of adjacent grid point to left of P
68  int ux = 0; // index of x coordinate of adjacent grid point to right of P
69  getNeighborIndices(_xAxis, xcoord, lx, ux);
70 
71  int ly = 0; // index of y coordinate of adjacent grid point below P
72  int uy = 0; // index of y coordinate of adjacent grid point above P
73  getNeighborIndices(_yAxis, ycoord, ly, uy);
74 
75  Real fQ11 = _zSurface(ly, lx);
76  Real fQ21 = _zSurface(ly, ux);
77  Real fQ12 = _zSurface(uy, lx);
78  Real fQ22 = _zSurface(uy, ux);
79 
80  // if point exactly found on a node do not interpolate
81  if ((lx == ux) && (ly == uy))
82  return fQ11;
83 
84  Real x = xcoord;
85  Real y = ycoord;
86  Real x1 = _xAxis[lx];
87  Real x2 = _xAxis[ux];
88  Real y1 = _yAxis[ly];
89  Real y2 = _yAxis[uy];
90 
91  // if xcoord lies exactly on an xAxis node do linear interpolation
92  if (lx == ux)
93  return fQ11 + (fQ12 - fQ11) * (y - y1) / (y2 - y1);
94 
95  // if ycoord lies exactly on an yAxis node do linear interpolation
96 
97  if (ly == uy)
98  return fQ11 + (fQ21 - fQ11) * (x - x1) / (x2 - x1);
99 
100  Real fxy = fQ11 * (x2 - x) * (y2 - y);
101  fxy += fQ21 * (x - x1) * (y2 - y);
102  fxy += fQ12 * (x2 - x) * (y - y1);
103  fxy += fQ22 * (x - x1) * (y - y1);
104  fxy /= ((x2 - x1) * (y2 - y1));
105 
106  return fxy;
107 }
void getNeighborIndices(const std::vector< Real > &inArr, Real x, int &lowerX, int &upperX)
std::vector< Real > _xAxis
std::vector< Real > _yAxis
static PetscErrorCode Vec x
ColumnMajorMatrix _zSurface

Member Data Documentation

int BilinearInterpolation::_file_number = 0
staticprivate

Definition at line 69 of file BilinearInterpolation.h.

std::vector<Real> BilinearInterpolation::_xAxis
private

Definition at line 66 of file BilinearInterpolation.h.

Referenced by sample().

std::vector<Real> BilinearInterpolation::_yAxis
private

Definition at line 67 of file BilinearInterpolation.h.

Referenced by sample().

ColumnMajorMatrix BilinearInterpolation::_zSurface
private

Definition at line 68 of file BilinearInterpolation.h.

Referenced by sample().


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