ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ERF_Interpolation_Bilinear.H File Reference
#include "ERF_DataStruct.H"
Include dependency graph for ERF_Interpolation_Bilinear.H:

Go to the source code of this file.

Functions

AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE int get_single_index (int i, int j, int k, int nx, int ny)
 
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE void bilinear_interpolation (const amrex::Real *xvec, const amrex::Real *yvec, const amrex::Real *zvec, const amrex::Real dxvec, const amrex::Real dyvec, const int nx, const int ny, const int nz, const amrex::Real x, const amrex::Real y, const amrex::Real z, const amrex::Real *varvec, amrex::Real &tmp_var)
 

Function Documentation

◆ bilinear_interpolation()

AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE void bilinear_interpolation ( const amrex::Real *  xvec,
const amrex::Real *  yvec,
const amrex::Real *  zvec,
const amrex::Real  dxvec,
const amrex::Real  dyvec,
const int  nx,
const int  ny,
const int  nz,
const amrex::Real  x,
const amrex::Real  y,
const amrex::Real  z,
const amrex::Real *  varvec,
amrex::Real &  tmp_var 
)
29 {
30  int iloc=-1, jloc=-1, kloc=-1;
31  for(int k=0;k<nz;k++){
32  if(zvec[k] > z){
33  kloc = k-1;
34  break;
35  }
36  else if (zvec[k] == z) {
37  kloc = k;
38  }
39 
40  }
41  iloc = std::floor((x-xvec[0])/dxvec);
42  jloc = std::floor((y-yvec[0])/dyvec);
43 
44  if(iloc > nx-1 or iloc < 0 or
45  jloc > ny-1 or iloc < 0 or
46  kloc > nz-1 or kloc < 0){
47  }
48 
49  amrex::Real xlo = xvec[0] + iloc*dxvec;
50  amrex::Real ylo = yvec[0] + jloc*dyvec;
51  amrex::Real zlo = zvec[kloc];
52 
53  amrex::Real w_x = (x - xlo)/dxvec;
54  amrex::Real w_y = (y - ylo)/dyvec;
55  amrex::Real w_z = (z - zlo)/(zvec[kloc+1] - zvec[kloc]);
56 
57  int ind0 = get_single_index(iloc,jloc,kloc,nx,ny);
58  int ind1 = get_single_index(iloc+1,jloc,kloc,nx,ny);
59  int ind2 = get_single_index(iloc+1,jloc+1,kloc,nx,ny);
60  int ind3 = get_single_index(iloc,jloc+1,kloc,nx,ny);
61  int ind4 = get_single_index(iloc,jloc,kloc+1,nx,ny);
62  int ind5 = get_single_index(iloc+1,jloc,kloc+1,nx,ny);
63  int ind6 = get_single_index(iloc+1,jloc+1,kloc+1,nx,ny);
64  int ind7 = get_single_index(iloc,jloc+1,kloc+1,nx,ny);
65 
66  tmp_var = (1-w_x)*(1-w_y)*(1-w_z)*varvec[ind0] + w_x*(1-w_y)*(1-w_z)*varvec[ind1] +
67  w_x*w_y*(1-w_z)*varvec[ind2] + (1-w_x)*w_y*(1-w_z)*varvec[ind3] +
68  (1-w_x)*(1-w_y)*w_z*varvec[ind4] + w_x*(1-w_y)*w_z*varvec[ind5] +
69  w_x*w_y*w_z*varvec[ind6] + (1-w_x)*w_y*w_z*varvec[ind7];
70 
71  //std::cout << "Variable value is " << tmp_var << "\n";
72 }
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE int get_single_index(int i, int j, int k, int nx, int ny)
Definition: ERF_Interpolation_Bilinear.H:13
Here is the call graph for this function:

◆ get_single_index()

AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE int get_single_index ( int  i,
int  j,
int  k,
int  nx,
int  ny 
)

Bilinear interpolation routines. There are different versions for different scenarios that take in a different argument list

15 {
16 
17  int si = k*nx*ny + j*nx + i;
18  return si;
19 }

Referenced by bilinear_interpolation().

Here is the caller graph for this function: