ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_Interpolation_1D.H File Reference
#include <AMReX_REAL.H>
#include "ERF_Constants.H"
Include dependency graph for ERF_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)
 
AMREX_FORCE_INLINE void expand_and_interpolate_1d (amrex::Vector< amrex::Real > &znew, const amrex::Vector< amrex::Real > &zorig, int refine_fac, bool destag=false)
 

Function Documentation

◆ expand_and_interpolate_1d()

AMREX_FORCE_INLINE void expand_and_interpolate_1d ( amrex::Vector< amrex::Real > &  znew,
const amrex::Vector< amrex::Real > &  zorig,
int  refine_fac,
bool  destag = false 
)
99 {
100  const int Nz = zorig.size();
101  const int Nz_refined = refine_fac*(Nz-1) + 1;
102  if (destag) {
103  AMREX_ALWAYS_ASSERT(znew.size() == Nz_refined-1);
104  } else {
105  AMREX_ALWAYS_ASSERT(znew.size() == Nz_refined);
106  }
107  amrex::Vector<amrex::Real> znew_stag(Nz_refined);
108  for (int k=0; k < Nz; ++k) {
109  znew_stag[refine_fac*k] = zorig[k];
110  }
111  if (refine_fac > 1) {
112  for (int k=0; k < Nz-1; ++k) {
113  amrex::Real z1 = zorig[k];
114  amrex::Real dz = zorig[k+1] - z1;
115  for (int koff=1; koff < refine_fac; ++koff) {
116  znew_stag[refine_fac*k + koff] = amrex::Real(koff)/refine_fac * dz + z1;
117  }
118  }
119  }
120  if (destag) {
121  for (int k=0; k < Nz_refined-1; ++k) {
122  znew[k] = myhalf*(znew_stag[k] + znew_stag[k+1]);
123  }
124  } else {
125  znew = znew_stag;
126  }
127 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ dz
Definition: ERF_AdvanceWDM6.cpp:273

Referenced by init_zlevels(), and ERF::setRayleighRefFromSounding().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

16 {
17  // We put this value here so beta_interp is initialized but the logic
18  // below is such that it will always be assigned some other value.
19  amrex::Real beta_interp = bogus_large_value;
20 
21  // A single point gives a constant: there is no second point to interpolate or
22  // extrapolate with
23  if (alpha_size == 1) {
24  return beta[0];
25  }
26 
27  // If the interpolation point already exists in the array,
28  // just return it
29  for (int i = 0; i < alpha_size; ++i) {
30  if (alpha[i] == alpha_interp) {
31  beta_interp = beta[i];
32  return beta_interp;
33  }
34  }
35 
36  // We didn't find an exact match for alpha_interp in alpha,
37  // so we need linear interpolation/extrapolation
38  amrex::Real alpha_min = alpha[0];
39  amrex::Real alpha_max = alpha[alpha_size-1];
40  if (alpha_interp >= alpha_min && alpha_interp <= alpha_max) //interpolate
41  {
42  for (int i = 0; i < alpha_size - 1; ++i)
43  {
44  if (alpha_interp >= alpha[i] && alpha_interp <= alpha[i + 1])
45  {
46  //y = y0 + (y1-y0)*(x-x0)/(x1-x0);
47  amrex::Real y0 = beta[i];
48  amrex::Real y1 = beta[i + 1];
49  amrex::Real x = alpha_interp;
50  amrex::Real x0 = alpha[i];
51  amrex::Real x1 = alpha[i + 1];
52  beta_interp = y0 + (y1 - y0)*(x - x0) / (x1 - x0);
53  return beta_interp;
54  }
55  }
56  }
57  else //extrapolate
58  {
59  // y = y0 + ((x - x0) / (x1 - x0)) * (y1 - y0)
60  int i = 0;
61  if (alpha_interp > alpha_max)
62  {
63  i = alpha_size-2;
64  }
65  else if (alpha_interp >= alpha_min)
66  {
67  amrex::Abort("interpolate_1d: we shouldn't be here!");
68  }
69 
70  amrex::Real y0 = beta[i];
71  amrex::Real y1 = beta[i + 1];
72  amrex::Real x = alpha_interp;
73  amrex::Real x0 = alpha[i];
74  amrex::Real x1 = alpha[i + 1];
75  beta_interp = y0 + ((x - x0) / (x1 - x0)) * (y1 - y0);
76  return beta_interp;
77  }
78 
79  return beta_interp;
80 }
constexpr amrex::Real bogus_large_value
Definition: ERF_Constants.H:19
@ beta
Definition: ERF_SLM.H:152
@ alpha
Definition: ERF_SLM.H:151

Referenced by Fitch::compute_power_output(), EWP::compute_power_output(), GeneralAD::compute_power_output(), SimpleAD::compute_power_output(), compute_source_terms_Fn_Ft(), ERF::init_Dirichlet_bc_data(), ERF::init_geo_wind_profile(), init_state_from_input_sounding(), init_state_from_input_sounding_hse(), init_velocities_from_input_sounding(), InputSpongeData::read_from_file(), InputSoundingData::read_from_file(), ERF::setRayleighRefFromSounding(), ERF::setSpongeRefFromSounding(), EWP::source_terms_cellcentered(), Fitch::source_terms_cellcentered(), and SimpleAD::source_terms_cellcentered().

Here is the caller graph for this function: