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 37 of file BilinearInterpolation.h.

## ◆ BilinearInterpolation()

 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 14 of file BilinearInterpolation.C.

17  : _xAxis(x), _yAxis(y), _zSurface(z)
18 {
19 }
std::vector< Real > _xAxis
std::vector< Real > _yAxis
static PetscErrorCode Vec x
ColumnMajorMatrix _zSurface

## ◆ ~BilinearInterpolation()

 virtual BilinearInterpolation::~BilinearInterpolation ( )
virtualdefault

## ◆ getNeighborIndices()

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

Definition at line 22 of file BilinearInterpolation.C.

Referenced by sample().

26 {
27  int N = inArr.size();
28  if (x <= inArr[0])
29  {
30  lowerX = 0;
31  upperX = 0;
32  }
33  else if (x >= inArr[N - 1])
34  {
35  lowerX = N - 1;
36  upperX = N - 1;
37  }
38  else
39  {
40  for (int i = 1; i < N; ++i)
41  {
42  if (x < inArr[i])
43  {
44  lowerX = i - 1;
45  upperX = i;
46  break;
47  }
48  else if (x == inArr[i])
49  {
50  lowerX = i;
51  upperX = i;
52  break;
53  }
54  }
55  }
56 }
PetscInt N
static PetscErrorCode Vec x

## ◆ sample()

 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 59 of file BilinearInterpolation.C.

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

## ◆ _file_number

 int BilinearInterpolation::_file_number = 0
staticprivate

Definition at line 64 of file BilinearInterpolation.h.

## ◆ _xAxis

 std::vector BilinearInterpolation::_xAxis
private

Definition at line 61 of file BilinearInterpolation.h.

Referenced by sample().

## ◆ _yAxis

 std::vector BilinearInterpolation::_yAxis
private

Definition at line 62 of file BilinearInterpolation.h.

Referenced by sample().

## ◆ _zSurface

 ColumnMajorMatrix BilinearInterpolation::_zSurface
private

Definition at line 63 of file BilinearInterpolation.h.

Referenced by sample().

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