ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitFromInputSounding.cpp File Reference
#include <ERF.H>
#include <ERF_EOS.H>
#include <ERF_Constants.H>
#include <ERF_Utils.H>
#include <ERF_ProbCommon.H>
Include dependency graph for ERF_InitFromInputSounding.cpp:

Functions

void init_bx_scalars_from_input_sounding (const Box &bx, Array4< Real > const &state, GeometryData const &geomdata, Array4< const Real > const &z_cc_arr, const bool &l_moist, InputSoundingData const &inputSoundingData)
 
void init_bx_scalars_from_input_sounding_hse (const Box &bx, Array4< Real > const &state, Array4< Real > const &r_hse_arr, Array4< Real > const &p_hse_arr, Array4< Real > const &pi_hse_arr, Array4< Real > const &th_hse_arr, GeometryData const &geomdata, Array4< const Real > const &z_cc_arr, const Real &l_gravity, const Real &l_rdOcp, const bool &l_moist, InputSoundingData const &inputSoundingData)
 
void init_bx_velocities_from_input_sounding (const Box &bx, Array4< Real > const &x_vel, Array4< Real > const &y_vel, Array4< Real > const &z_vel, GeometryData const &geomdata, Array4< const Real > const &z_nd_arr, InputSoundingData const &inputSoundingData)
 

Function Documentation

◆ init_bx_scalars_from_input_sounding()

void init_bx_scalars_from_input_sounding ( const Box &  bx,
Array4< Real > const &  state,
GeometryData const &  geomdata,
Array4< const Real > const &  z_cc_arr,
const bool &  l_moist,
InputSoundingData const &  inputSoundingData 
)

Box level wrapper for initializing scalar data from input sounding data.

Parameters
bxBox specifying the indices we are initializing
stateArray4 specifying the state data we are to initialize
geomdataGeometryData object specifying the domain geometry
inputSoundingDataInputSoundingData object we are to initialize from
166 {
167  const Real* z_inp_sound = inputSoundingData.z_inp_sound_d[0].dataPtr();
168  const Real* theta_inp_sound = inputSoundingData.theta_inp_sound_d[0].dataPtr();
169  const Real* qv_inp_sound = inputSoundingData.qv_inp_sound_d[0].dataPtr();
170  const int inp_sound_size = inputSoundingData.size(0);
171 
172  // Geometry
173  const Real* prob_lo = geomdata.ProbLo();
174  const Real* dx = geomdata.CellSize();
175  const Real z_lo = prob_lo[2];
176  const Real dz = dx[2];
177 
178  // We want to set the lateral BC values, too
179  Box gbx = bx; // Copy constructor
180  gbx.grow(0,1); gbx.grow(1,1); // Grow by one in the lateral directions
181 
182  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
183  const Real z = (z_cc_arr) ? z_cc_arr(i,j,k)
184  : z_lo + (k + 0.5) * dz;
185 
186  Real rho_0 = 1.0;
187 
188  // Set the density
189  state(i, j, k, Rho_comp) = rho_0;
190 
191  // Initial Rho0*Theta0
192  state(i, j, k, RhoTheta_comp) = rho_0 * interpolate_1d(z_inp_sound, theta_inp_sound, z, inp_sound_size);
193 
194  // Initialize all scalars to 0.
195  for (int n = 0; n < NSCALARS; n++) {
196  state(i, j, k, RhoScalar_comp+n) = 0;
197  }
198 
199  // total nonprecipitating water (Q1) == water vapor (Qv), i.e., there is no cloud water or cloud ice
200  if (l_moist) {
201  state(i, j, k, RhoQ1_comp) = rho_0 * interpolate_1d(z_inp_sound, qv_inp_sound, z, inp_sound_size);
202  }
203  });
204 }
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:40
#define Rho_comp
Definition: ERF_IndexDefines.H:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define NSCALARS
Definition: ERF_IndexDefines.H:16
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:42
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)
Definition: ERF_Interpolation_1D.H:12

Referenced by ERF::init_from_input_sounding().

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

◆ init_bx_scalars_from_input_sounding_hse()

void init_bx_scalars_from_input_sounding_hse ( const Box &  bx,
Array4< Real > const &  state,
Array4< Real > const &  r_hse_arr,
Array4< Real > const &  p_hse_arr,
Array4< Real > const &  pi_hse_arr,
Array4< Real > const &  th_hse_arr,
GeometryData const &  geomdata,
Array4< const Real > const &  z_cc_arr,
const Real &  ,
const Real &  l_rdOcp,
const bool &  l_moist,
InputSoundingData const &  inputSoundingData 
)

Box level wrapper for initializing scalar and hydrostatic base state data from input sounding data.

Parameters
bxBox specifying the indices we are initializing
stateArray4 specifying the state data we are to initialize
r_hse_arrArray4 specifying the density HSE base state data we are to initialize
p_hse_arrArray4 specifying the pressure HSE base state data we are to initialize
pi_hse_arrArray4 specifying the Exner pressure HSE base state data we are to initialize
th_hse_arrArray4 specifying the base state potential temperature we are to initialize
geomdataGeometryData object specifying the domain geometry
l_gravityReal number specifying the gravitational acceleration constant
l_rdOcpReal number specifying the Rhydberg constant ($R_d$) divided by specific heat at constant pressure ($c_p$)
inputSoundingDataInputSoundingData object we are to initialize from
234 {
235  const Real* z_inp_sound = inputSoundingData.z_inp_sound_d[0].dataPtr();
236  const Real* rho_inp_sound = inputSoundingData.rho_inp_sound_d.dataPtr();
237  const Real* theta_inp_sound = inputSoundingData.theta_inp_sound_d[0].dataPtr();
238  const Real* qv_inp_sound = inputSoundingData.qv_inp_sound_d[0].dataPtr();
239  const int inp_sound_size = inputSoundingData.size(0);
240 
241  // Geometry
242  const Real* prob_lo = geomdata.ProbLo();
243  const Real* dx = geomdata.CellSize();
244  const Real z_lo = prob_lo[2];
245  const Real dz = dx[2];
246 
247  int kbot = geomdata.Domain().smallEnd(2);
248  int ktop = geomdata.Domain().bigEnd(2);
249 
250  // We want to set the lateral BC values, too
251  Box gbx = bx; // Copy constructor
252  gbx.grow(0,1); gbx.grow(1,1); // Grow by one in the lateral directions
253 
254  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
255  const Real z = (z_cc_arr) ? z_cc_arr(i,j,k)
256  : z_lo + (k + 0.5) * dz;
257 
258  Real rho_k, qv_k, rhoTh_k;
259 
260  // Set the density
261  rho_k = interpolate_1d(z_inp_sound, rho_inp_sound, z, inp_sound_size);
262  state(i, j, k, Rho_comp) = rho_k;
263 
264  // Initial Rho0*Theta0
265  rhoTh_k = rho_k * interpolate_1d(z_inp_sound, theta_inp_sound, z, inp_sound_size);
266  state(i, j, k, RhoTheta_comp) = rhoTh_k;
267 
268  // Initialize all scalars to 0.
269  for (int n = 0; n < NSCALARS; n++) {
270  state(i, j, k, RhoScalar_comp+n) = 0;
271  }
272 
273  // Update hse quantities with values calculated from InputSoundingData.calc_rho_p()
274  qv_k = (l_moist) ? interpolate_1d(z_inp_sound, qv_inp_sound, z, inp_sound_size) : 0.0;
275  r_hse_arr (i,j,k) = rho_k * (1.0 + qv_k);
276  p_hse_arr (i,j,k) = getPgivenRTh(rhoTh_k, qv_k);
277  pi_hse_arr(i,j,k) = getExnergivenRTh(rhoTh_k, l_rdOcp);
278  th_hse_arr(i,j,k) = getRhoThetagivenP(p_hse_arr(i,j,k)) / r_hse_arr(i,j,k);
279 
280  // TODO: we should be setting this to the number of ghost cells of base_state[lev]
281  // instead of hard-wiring it here!
282  int ng = 3;
283 
284  // FOEXTRAP hse arrays
285  if (k==kbot)
286  {
287  for (int kk = 1; kk <= ng; kk++) {
288  r_hse_arr(i, j, k-kk) = r_hse_arr(i,j,k);
289  p_hse_arr(i, j, k-kk) = p_hse_arr(i,j,k);
290  pi_hse_arr(i, j, k-kk) = pi_hse_arr(i,j,k);
291  th_hse_arr(i, j, k-kk) = th_hse_arr(i,j,k);
292  }
293  }
294  else if (k==ktop)
295  {
296  for (int kk = 1; kk <= ng; kk++) {
297  r_hse_arr(i, j, k+kk) = r_hse_arr(i,j,k);
298  p_hse_arr(i, j, k+kk) = p_hse_arr(i,j,k);
299  pi_hse_arr(i, j, k+kk) = pi_hse_arr(i,j,k);
300  th_hse_arr(i, j, k+kk) = th_hse_arr(i,j,k);
301  }
302  }
303 
304  // total nonprecipitating water (Q1) == water vapor (Qv), i.e., there
305  // is no cloud water or cloud ice
306  if (l_moist) {
307  state(i, j, k, RhoQ1_comp) = rho_k * qv_k;
308  }
309  });
310 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=0.)
Definition: ERF_EOS.H:84
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getExnergivenRTh(const amrex::Real rhotheta, const amrex::Real rdOcp, const amrex::Real qv=0.0)
Definition: ERF_EOS.H:159
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getRhoThetagivenP(const amrex::Real p, const amrex::Real qv=0.0)
Definition: ERF_EOS.H:175

Referenced by ERF::init_from_input_sounding().

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

◆ init_bx_velocities_from_input_sounding()

void init_bx_velocities_from_input_sounding ( const Box &  bx,
Array4< Real > const &  x_vel,
Array4< Real > const &  y_vel,
Array4< Real > const &  z_vel,
GeometryData const &  geomdata,
Array4< const Real > const &  z_nd_arr,
InputSoundingData const &  inputSoundingData 
)

Box level wrapper for initializing velocities from input sounding data.

Parameters
bxBox specifying the indices we are initializing
x_velArray4 specifying the x-velocity data we are to initialize
y_velArray4 specifying the y-velocity data we are to initialize
z_velArray4 specifying the z-velocity data we are to initialize
geomdataGeometryData object specifying the domain geometry
inputSoundingDataInputSoundingData object we are to initialize from
330 {
331  const Real* z_inp_sound = inputSoundingData.z_inp_sound_d[0].dataPtr();
332  const Real* U_inp_sound = inputSoundingData.U_inp_sound_d[0].dataPtr();
333  const Real* V_inp_sound = inputSoundingData.V_inp_sound_d[0].dataPtr();
334  const int inp_sound_size = inputSoundingData.size(0);
335 
336  // Geometry
337  const Real* prob_lo = geomdata.ProbLo();
338  const Real* dx = geomdata.CellSize();
339  const Real z_lo = prob_lo[2];
340  const Real dz = dx[2];
341 
342  // We want to set the lateral BC values, too
343  Box gbx = bx; // Copy constructor
344  gbx.grow(0,1); gbx.grow(1,1); // Grow by one in the lateral directions
345 
346  // Construct a box that is on x-faces
347  const Box& xbx = surroundingNodes(gbx,0);
348  // Construct a box that is on y-faces
349  const Box& ybx = surroundingNodes(gbx,1);
350  // Construct a box that is on z-faces
351  const Box& zbx = surroundingNodes(gbx,2);
352 
353  // Set the x,y,z-velocities
354  ParallelFor(xbx, ybx, zbx,
355  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
356  // Note that this is called on a box of x-faces
357  const Real z = (z_nd_arr) ? 0.25*( z_nd_arr(i,j ,k )
358  + z_nd_arr(i,j+1,k )
359  + z_nd_arr(i,j ,k+1)
360  + z_nd_arr(i,j+1,k+1))
361  : z_lo + (k + 0.5) * dz;
362 
363  // Set the x-velocity
364  x_vel(i, j, k) = interpolate_1d(z_inp_sound, U_inp_sound, z, inp_sound_size);
365  },
366  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
367  // Note that this is called on a box of y-faces
368  const Real z = (z_nd_arr) ? 0.25*( z_nd_arr(i ,j,k )
369  + z_nd_arr(i+1,j,k )
370  + z_nd_arr(i ,j,k+1)
371  + z_nd_arr(i+1,j,k+1))
372  : z_lo + (k + 0.5) * dz;
373 
374  // Set the y-velocity
375  y_vel(i, j, k) = interpolate_1d(z_inp_sound, V_inp_sound, z, inp_sound_size);
376  },
377  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
378  // Note that this is called on a box of z-faces
379  // Set the z-velocity
380  z_vel(i, j, k) = 0.0;
381  });
382 }

Referenced by ERF::init_from_input_sounding().

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