HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
TrilinearInterpolation.c File Reference

Compute coefficients for trilinear interpolation. More...

#include <mathfunctions.h>

Go to the source code of this file.

Functions

void TrilinearInterpCoeffs (double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, double x, double y, double z, double *coeffs)
 

Detailed Description

Compute coefficients for trilinear interpolation.

Author
Debojyoti Ghosh

Definition in file TrilinearInterpolation.c.

Function Documentation

◆ TrilinearInterpCoeffs()

void TrilinearInterpCoeffs ( double  xmin,
double  xmax,
double  ymin,
double  ymax,
double  zmin,
double  zmax,
double  x,
double  y,
double  z,
double *  coeffs 
)

This function computes the coefficients for a trilinear interpolation at a given point (x,y,z) inside a cube defined by [xmin,xmax] X [ymin,ymax] X [zmin,zmax]. The coefficients are stored in an array of size 8 with each element corresponding to a corner of the cube in the following order:
coeffs[0] => xmin,ymin,zmin
coeffs[1] => xmax,ymin,zmin
coeffs[2] => xmin,ymax,zmin
coeffs[3] => xmax,ymax,zmin
coeffs[4] => xmin,ymin,zmax
coeffs[5] => xmax,ymin,zmax
coeffs[6] => xmin,ymax,zmax
coeffs[7] => xmax,ymax,zmax

Parameters
xminx-coordinate of the lower-end
xmaxx-coordinate of the higher-end
yminy-coordinate of the lower-end
ymaxy-coordinate of the higher-end
zminz-coordinate of the lower-end
zmaxz-coordinate of the higher-end
xx-coordinate of the point to interpolate at
yy-coordinate of the point to interpolate at
zz-coordinate of the point to interpolate at
coeffsarray of size 8 (pre-allocated) to store the coefficients in

Definition at line 22 of file TrilinearInterpolation.c.

34 {
35  double vol_inv = 1 / ((xmax-xmin)*(ymax-ymin)*(zmax-zmin));
36  double tldx1 = x - xmin;
37  double tldx2 = xmax - x;
38  double tldy1 = y - ymin;
39  double tldy2 = ymax - y;
40  double tldz1 = z - zmin;
41  double tldz2 = zmax - z;
42 
43  coeffs[0] = tldz2 * tldy2 * tldx2 * vol_inv;
44  coeffs[1] = tldz2 * tldy2 * tldx1 * vol_inv;
45  coeffs[2] = tldz2 * tldy1 * tldx2 * vol_inv;
46  coeffs[3] = tldz2 * tldy1 * tldx1 * vol_inv;
47  coeffs[4] = tldz1 * tldy2 * tldx2 * vol_inv;
48  coeffs[5] = tldz1 * tldy2 * tldx1 * vol_inv;
49  coeffs[6] = tldz1 * tldy1 * tldx2 * vol_inv;
50  coeffs[7] = tldz1 * tldy1 * tldx1 * vol_inv;
51 
52  return;
53 }