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_state_from_input_sounding (const Box &bx, Array4< Real > const &state, GeometryData const &geomdata, Array4< const Real > const &z_cc_arr, Array4< const Real > const &z_nd_arr, const bool &l_moist, InputSoundingData const &inputSoundingData)
 
void init_state_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, Array4< Real > const &qv_hse_arr, GeometryData const &geomdata, Array4< const Real > const &z_cc_arr, Array4< const Real > const &z_nd_arr, const Real &l_gravity, const Real &l_rdOcp, const bool &l_moist, InputSoundingData const &inputSoundingData, const bool &l_isentropic, const int &ngz)
 
void init_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_state_from_input_sounding()

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

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

Parameters
[in]bxBox specifying the indices we are initializing
[out]stateArray4 specifying the state data we are to initialize
[in]geomdataGeometryData object specifying the domain geometry
[in]z_cc_arrArray4 specifying cell-centered terrain heights, if present
[in]z_nd_arrArray4 specifying node-centered terrain heights, if present
[in]l_moistWhether moisture variables should be initialized
[in]inputSoundingDataInputSoundingData object we are to initialize from

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
z_cc_arrArray4 specifying cell-centered terrain heights, if present
z_nd_arrArray4 specifying node-centered terrain heights, if present
l_moistWhether moisture variables should be initialized
inputSoundingDataInputSoundingData object we are to initialize from
388 {
389  const Real* z_inp_sound = inputSoundingData.z_inp_sound_d[0].dataPtr();
390  const Real* theta_inp_sound = inputSoundingData.theta_inp_sound_d[0].dataPtr();
391  const Real* qv_inp_sound = inputSoundingData.qv_inp_sound_d[0].dataPtr();
392  const int inp_sound_size = inputSoundingData.size(0);
393 
394  // Geometry
395  const Real* prob_lo = geomdata.ProbLo();
396  const Real* dx = geomdata.CellSize();
397  const Real z_lo = prob_lo[2];
398  const Real dz = dx[2];
399 
400  // The caller passes the cells to fill, ghost cells included
401  const Box& gbx = bx;
402 
403  // erf.input_sounding_theta_above_ground: theta measured from the column's own ground
404  const bool theta_above_ground = inputSoundingData.theta_above_ground && static_cast<bool>(z_nd_arr);
405  const int klo = geomdata.Domain().smallEnd(2);
406 
407  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
408  const Real z = (z_cc_arr) ? z_cc_arr(i,j,k) : z_lo + (k + myhalf) * dz;
409  const Real z_th = (theta_above_ground)
410  ? z - fourth * (z_nd_arr(i,j,klo) + z_nd_arr(i+1,j,klo) + z_nd_arr(i,j+1,klo) + z_nd_arr(i+1,j+1,klo))
411  : z;
412 
413  Real rho_0 = one;
414 
415  // Set the density
416  state(i, j, k, Rho_comp) = rho_0;
417 
418  // Initial Rho0*Theta0
419  state(i, j, k, RhoTheta_comp) = rho_0 * interpolate_1d(z_inp_sound, theta_inp_sound, z_th, inp_sound_size);
420 
421  // total nonprecipitating water (Q1) == water vapor (Qv), i.e., there is no cloud water or cloud ice
422  if (l_moist) {
423  state(i, j, k, RhoQ1_comp) = rho_0 * interpolate_1d(z_inp_sound, qv_inp_sound, z, inp_sound_size);
424  }
425  });
426 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:78
Real rho_0
Definition: ERF_InitCustomPert_ABL.H:18
const GpuArray< Real, AMREX_SPACEDIM > prob_lo
Definition: ERF_InitCustomPert_CloudChamber.H:34
const int klo
Definition: ERF_InitCustomPert_KE.H:9
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:15
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
@ dz
Definition: ERF_AdvanceWDM6.cpp:273

Referenced by ERF::init_from_input_sounding().

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

◆ init_state_from_input_sounding_hse()

void init_state_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,
Array4< Real > const &  qv_hse_arr,
GeometryData const &  geomdata,
Array4< const Real > const &  z_cc_arr,
Array4< const Real > const &  z_nd_arr,
const Real &  l_gravity,
const Real &  l_rdOcp,
const bool &  l_moist,
InputSoundingData const &  inputSoundingData,
const bool &  l_isentropic,
const int &  ngz 
)

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

Parameters
[in]bxBox specifying the indices we are initializing
[out]stateArray4 specifying the state data we are to initialize
[out]r_hse_arrArray4 specifying the density HSE base state data we are to initialize
[out]p_hse_arrArray4 specifying the pressure HSE base state data we are to initialize
[out]pi_hse_arrArray4 specifying the Exner pressure HSE base state data we are to initialize
[out]th_hse_arrArray4 specifying the base state potential temperature we are to initialize
[out]qv_hse_arrArray4 specifying the base state water vapor mixing ratio we are to initialize
[in]geomdataGeometryData object specifying the domain geometry
[in]z_cc_arrArray4 specifying cell-centered terrain heights, if present
[in]z_nd_arrArray4 specifying node-centered terrain heights, if present
[in]l_gravityGravity constant (retained for interface compatibility).
[in]l_rdOcpReal number specifying the Rhydberg constant ($R_d$) divided by specific heat at constant pressure ($c_p$)
[in]l_moistWhether moisture variables should be initialized
[in]inputSoundingDataInputSoundingData object we are to initialize from
[in]l_isentropicWhether to construct an isentropic HSE base state
[in]ngzNumber of vertical ghost cells to fill in HSE arrays

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
qv_hse_arrArray4 specifying the base state water vapor mixing ratio we are to initialize
geomdataGeometryData object specifying the domain geometry The unused gravity argument is retained for interface compatibility.
z_cc_arrArray4 specifying cell-centered terrain heights, if present
z_nd_arrArray4 specifying node-centered terrain heights, if present
l_rdOcpReal number specifying the Rhydberg constant ($R_d$) divided by specific heat at constant pressure ($c_p$)
l_moistWhether moisture variables should be initialized
inputSoundingDataInputSoundingData object we are to initialize from
l_isentropicWhether to construct an isentropic HSE base state
ngzNumber of vertical ghost cells to fill in HSE arrays
466 {
467  const Real* z_inp_sound = inputSoundingData.z_inp_sound_d[0].dataPtr();
468  const Real* rho_inp_sound = inputSoundingData.rho_inp_sound_d.dataPtr();
469  const Real* theta_inp_sound = inputSoundingData.theta_inp_sound_d[0].dataPtr();
470  const Real* qv_inp_sound = inputSoundingData.qv_inp_sound_d[0].dataPtr();
471  const int inp_sound_size = inputSoundingData.size(0);
472  const bool anel_assume_dry = inputSoundingData.assume_dry;
473 
474  // Geometry
475  const Real* prob_lo = geomdata.ProbLo();
476  const Real* dx = geomdata.CellSize();
477  const Real z_lo = prob_lo[2];
478  const Real dz = dx[2];
479 
480  int kbot = geomdata.Domain().smallEnd(2);
481  int ktop = geomdata.Domain().bigEnd(2);
482 
483  // The caller passes the cells to fill, ghost cells included
484  const Box& gbx = bx;
485 
486  // erf.input_sounding_theta_above_ground: theta measured from the column's own
487  // ground. rho*theta, and so the pressure, keeps the sounding's value at the
488  // physical height and rho follows from it; rebalance_columns then puts each
489  // column in hydrostatic balance with that theta.
490  const bool theta_above_ground = inputSoundingData.theta_above_ground && static_cast<bool>(z_nd_arr);
491 
492  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
493  const Real z = (z_cc_arr) ? z_cc_arr(i,j,k)
494  : z_lo + (k + myhalf) * dz;
495 
496  Real rho_k = interpolate_1d(z_inp_sound, rho_inp_sound, z, inp_sound_size);
497  Real rhoTh_k = rho_k * interpolate_1d(z_inp_sound, theta_inp_sound, z, inp_sound_size);
498  if (theta_above_ground) {
499  const Real z_ground = fourth * (z_nd_arr(i,j,kbot) + z_nd_arr(i+1,j,kbot) + z_nd_arr(i,j+1,kbot) + z_nd_arr(i+1,j+1,kbot));
500  rho_k = rhoTh_k / interpolate_1d(z_inp_sound, theta_inp_sound, z - z_ground, inp_sound_size);
501  }
502 
503  Real rho_k_base = rho_k;
504  if (l_isentropic) {
505  // `rho_inp_sound` previously calculated in calc_rho_p_isentropic()
506  // is in HSE and, when multiplied by the specified
507  // `theta_input_sound`, give p, T, and theta that are consistent
508  // with each other.
509  //
510  // Here, we do not require thermodynamic consistency between the
511  // initial base state rho and the prognostic variables. Instead,
512  // we calculate a `rho_hse` that is consistent with the isentropic
513  // (constant theta) assumption.
514  rho_k_base = rhoTh_k / theta_inp_sound[0];
515  }
516 
517  // Set the density
518  state(i, j, k, Rho_comp) = rho_k;
519 
520  // Initial Rho0*Theta0
521  state(i, j, k, RhoTheta_comp) = rhoTh_k;
522 
523  // Total nonprecipitating water (Q1) == water vapor (Qv), i.e., there
524  // is no cloud water or cloud ice
525  Real qv_k = zero;
526  if (l_moist) {
527  qv_k = interpolate_1d(z_inp_sound, qv_inp_sound, z, inp_sound_size);
528  state(i, j, k, RhoQ1_comp) = rho_k * qv_k;
529  }
530 
531  // Update hse quantities with values calculated from InputSoundingData.calc_rho_p()
532  if (anel_assume_dry) qv_k = 0;
533  r_hse_arr (i,j,k) = rho_k_base;
534  p_hse_arr (i,j,k) = getPgivenRTh(rhoTh_k, qv_k);
535  pi_hse_arr(i,j,k) = getExnergivenRTh(rhoTh_k, l_rdOcp, qv_k);
536  th_hse_arr(i,j,k) = getRhoThetagivenP(p_hse_arr(i,j,k), qv_k) / rho_k_base;
537  qv_hse_arr(i,j,k) = qv_k;
538 
539  if (l_isentropic) {
540 #if 0
541  if (i==0 && j==0) {
542  Print() << "HSE rho,p,T=pi*th,th at " << IntVect(i,j,k) << " : "
543  << r_hse_arr(i,j,k) << " "
544  << p_hse_arr(i,j,k) << " "
545  << pi_hse_arr(i,j,k)*th_hse_arr(i,j,k) << " "
546  << th_hse_arr(i,j,k)
547  << " with rho,rhotheta=" << rho_k << " " << rhoTh_k
548  << std::endl;
549  }
550 #endif
551  // If everything above is thermodynamically consistent, this should be constant
552  AMREX_ALWAYS_ASSERT(std::abs(th_hse_arr(i,j,k) - theta_inp_sound[0]) < 1e-12);
553  }
554 
555  // FOEXTRAP hse arrays
556  if (k==kbot)
557  {
558  for (int kk = 1; kk <= ngz; kk++) {
559  r_hse_arr(i, j, k-kk) = r_hse_arr(i,j,k);
560  p_hse_arr(i, j, k-kk) = p_hse_arr(i,j,k);
561  pi_hse_arr(i, j, k-kk) = pi_hse_arr(i,j,k);
562  th_hse_arr(i, j, k-kk) = th_hse_arr(i,j,k);
563  qv_hse_arr(i, j, k-kk) = qv_hse_arr(i,j,k);
564  }
565  }
566  else if (k==ktop)
567  {
568  for (int kk = 1; kk <= ngz; kk++) {
569  r_hse_arr(i, j, k+kk) = r_hse_arr(i,j,k);
570  p_hse_arr(i, j, k+kk) = p_hse_arr(i,j,k);
571  pi_hse_arr(i, j, k+kk) = pi_hse_arr(i,j,k);
572  th_hse_arr(i, j, k+kk) = th_hse_arr(i,j,k);
573  qv_hse_arr(i, j, k+kk) = qv_hse_arr(i,j,k);
574  }
575  }
576  });
577 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getRhoThetagivenP(const amrex::Real p, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:172
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getExnergivenRTh(const amrex::Real rhotheta, const amrex::Real rdOcp, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:156
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:81
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36

Referenced by ERF::build_base_state_from_input_sounding_on().

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

◆ init_velocities_from_input_sounding()

void init_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
[in]bxBox specifying the indices we are initializing
[out]x_velArray4 specifying the x-velocity data we are to initialize
[out]y_velArray4 specifying the y-velocity data we are to initialize
[out]z_velArray4 specifying the z-velocity data we are to initialize
[in]geomdataGeometryData object specifying the domain geometry
[in]z_nd_arrArray4 specifying node-centered terrain heights, if present
[in]inputSoundingDataInputSoundingData object we are to initialize from

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
z_nd_arrArray4 specifying node-centered terrain heights, if present
inputSoundingDataInputSoundingData object we are to initialize from
598 {
599  const Real* z_inp_sound = inputSoundingData.z_inp_sound_d[0].dataPtr();
600  const Real* U_inp_sound = inputSoundingData.U_inp_sound_d[0].dataPtr();
601  const Real* V_inp_sound = inputSoundingData.V_inp_sound_d[0].dataPtr();
602  const int inp_sound_size = inputSoundingData.size(0);
603 
604  // Geometry
605  const Real* prob_lo = geomdata.ProbLo();
606  const Real* dx = geomdata.CellSize();
607  const Real z_lo = prob_lo[2];
608  const Real dz = dx[2];
609 
610  // The caller passes the cells to fill, ghost cells included
611  const Box& gbx = bx;
612 
613  // Construct a box that is on x-faces
614  const Box& xbx = surroundingNodes(gbx,0);
615  // Construct a box that is on y-faces
616  const Box& ybx = surroundingNodes(gbx,1);
617  // Construct a box that is on z-faces
618  const Box& zbx = surroundingNodes(gbx,2);
619 
620  // erf.input_sounding_wind_above_ground: a terrain-fitted column starts with
621  // the sounding's wind profile measured from its own ground, as the Inflow
622  // faces apply a dirichlet_file profile by level
623  const bool above_ground = inputSoundingData.wind_above_ground && static_cast<bool>(z_nd_arr);
624  const int klo = geomdata.Domain().smallEnd(2);
625 
626  // Set the x,y,z-velocities
627  ParallelFor(xbx, ybx, zbx,
628  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
629  // Note that this is called on a box of x-faces
630  Real z = (z_nd_arr) ? fourth*( z_nd_arr(i,j ,k )
631  + z_nd_arr(i,j+1,k )
632  + z_nd_arr(i,j ,k+1)
633  + z_nd_arr(i,j+1,k+1))
634  : z_lo + (k + myhalf) * dz;
635  if (above_ground) { z -= myhalf * (z_nd_arr(i,j,klo) + z_nd_arr(i,j+1,klo)); }
636 
637  // Set the x-velocity
638  x_vel(i, j, k) = interpolate_1d(z_inp_sound, U_inp_sound, z, inp_sound_size);
639  },
640  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
641  // Note that this is called on a box of y-faces
642  Real z = (z_nd_arr) ? fourth*( z_nd_arr(i ,j,k )
643  + z_nd_arr(i+1,j,k )
644  + z_nd_arr(i ,j,k+1)
645  + z_nd_arr(i+1,j,k+1))
646  : z_lo + (k + myhalf) * dz;
647  if (above_ground) { z -= myhalf * (z_nd_arr(i,j,klo) + z_nd_arr(i+1,j,klo)); }
648 
649  // Set the y-velocity
650  y_vel(i, j, k) = interpolate_1d(z_inp_sound, V_inp_sound, z, inp_sound_size);
651  },
652  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
653  // Note that this is called on a box of z-faces
654  // Set the z-velocity
655  z_vel(i, j, k) = zero;
656  });
657 }

Referenced by ERF::init_from_input_sounding().

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