ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
Interpolation_1D.H File Reference
#include <AMReX_REAL.H>
Include dependency graph for Interpolation_1D.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real interpolate_1d (const amrex::Real *alpha, const amrex::Real *beta, const amrex::Real alpha_interp, const int alpha_size)
 

Function Documentation

◆ interpolate_1d()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real interpolate_1d ( const amrex::Real *  alpha,
const amrex::Real *  beta,
const amrex::Real  alpha_interp,
const int  alpha_size 
)

Interpolates 1D array beta at the location alpha_interp in the array alpha requiring 1D arrays alpha and beta to be the same size alpha_size. This routine assumes the alpha data are monotonic from lowest to highest.

14 {
15  using namespace amrex;
16 
17  amrex::Real beta_interp;
18 
19  // If the interpolation point already exists in the array,
20  // just return it
21  for (int i = 0; i < alpha_size; ++i) {
22  if (alpha[i] == alpha_interp) {
23  beta_interp = beta[i];
24  return beta_interp;
25  }
26  }
27 
28  // We didn't find an exact match for alpha_interp in alpha,
29  // so we need linear interpolation/extrapolation
30  amrex::Real alpha_min = alpha[0];
31  amrex::Real alpha_max = alpha[alpha_size-1];
32  if (alpha_interp >= alpha_min && alpha_interp <= alpha_max) //interpolate
33  {
34  for (int i = 0; i < alpha_size; ++i)
35  {
36  if (alpha_interp >= alpha[i] && alpha_interp <= alpha[i + 1])
37  {
38  //y = y0 + (y1-y0)*(x-x0)/(x1-x0);
39  amrex::Real y0 = beta[i];
40  amrex::Real y1 = beta[i + 1];
41  amrex::Real x = alpha_interp;
42  amrex::Real x0 = alpha[i];
43  amrex::Real x1 = alpha[i + 1];
44  beta_interp = y0 + (y1 - y0)*(x - x0) / (x1 - x0);
45  }
46  }
47  }
48  else //extrapolate
49  {
50  // y = y0 + ((x - x0) / (x1 - x0)) * (y1 - y0)
51  int i = 0;
52  if (alpha_interp > alpha_max)
53  {
54  i = alpha_size-2;
55  }
56  else if (alpha_interp >= alpha_min)
57  {
58  amrex::Abort("interpolate_1d: we shouldn't be here!");
59  }
60 
61  amrex::Real y0 = beta[i];
62  amrex::Real y1 = beta[i + 1];
63  amrex::Real x = alpha_interp;
64  amrex::Real x0 = alpha[i];
65  amrex::Real x1 = alpha[i + 1];
66  beta_interp = y0 + ((x - x0) / (x1 - x0)) * (y1 - y0);
67  }
68 
69  return beta_interp;
70 }
Definition: console_io.cpp:12

Referenced by init_bx_scalars_from_input_sounding(), init_bx_scalars_from_input_sounding_hse(), init_bx_velocities_from_input_sounding(), InputSoundingData::read_from_file(), InputSpongeData::read_from_file(), ERF::setRayleighRefFromSounding(), and ERF::setSpongeRefFromSounding().

Here is the caller graph for this function: