ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ERF_MakeBuoyancy.cpp File Reference
#include <AMReX_MultiFab.H>
#include <AMReX_ArrayLim.H>
#include <AMReX_GpuContainers.H>
#include <ERF_Constants.H>
#include <ERF_EOS.H>
#include <ERF_IndexDefines.H>
#include <ERF_PlaneAverage.H>
#include <ERF_SrcHeaders.H>
#include <ERF_BuoyancyUtils.H>
Include dependency graph for ERF_MakeBuoyancy.cpp:

Functions

void make_buoyancy (Vector< MultiFab > &S_data, const MultiFab &S_prim, MultiFab &buoyancy, const amrex::Geometry geom, const SolverChoice &solverChoice, const MultiFab &base_state, const int n_qstate, const int anelastic)
 

Function Documentation

◆ make_buoyancy()

void make_buoyancy ( Vector< MultiFab > &  S_data,
const MultiFab &  S_prim,
MultiFab &  buoyancy,
const amrex::Geometry  geom,
const SolverChoice solverChoice,
const MultiFab &  base_state,
const int  n_qstate,
const int  anelastic 
)

Function for computing the buoyancy term to be used in the evolution equation for the z-component of momentum in the slow integrator. There are three options for how buoyancy is computed (two are the same in the absence of moisture).

Parameters
[in]S_datacurrent solution
[in]S_primprimitive variables (i.e. conserved variables divided by density)
[out]buoyancybuoyancy term computed here
[in]qmoistmoisture variables (in order: qv, qc, qi, ...)
[in]qv_dlateral average of cloud vapor
[in]qc_dlateral average of cloud vapor
[in]qd_dlateral average of cloud vapor
[in]geomContainer for geometric information
[in]solverChoiceContainer for solver parameters
[in]r0Reference (hydrostatically stratified) density
[in]n_qstateNumber of moist variables used by the current model
40 {
41  BL_PROFILE("make_buoyancy()");
42 
43  const Array<Real,AMREX_SPACEDIM> grav{0.0, 0.0, -solverChoice.gravity};
44  const GpuArray<Real,AMREX_SPACEDIM> grav_gpu{grav[0], grav[1], grav[2]};
45 
46  const int klo = geom.Domain().smallEnd()[2];
47  const int khi = geom.Domain().bigEnd()[2] + 1;
48 
49  Real rd_over_cp = solverChoice.rdOcp;
50  Real rv_over_rd = R_v/R_d;
51 
52  MultiFab r0 (base_state, make_alias, BaseState::r0_comp , 1);
53  MultiFab p0 (base_state, make_alias, BaseState::p0_comp , 1);
54  MultiFab th0(base_state, make_alias, BaseState::th0_comp, 1);
55  MultiFab qv0(base_state, make_alias, BaseState::qv0_comp, 1);
56 
57 #ifdef _OPENMP
58 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
59 #endif
60  for ( MFIter mfi(buoyancy,TilingIfNotGPU()); mfi.isValid(); ++mfi)
61  {
62  Box tbz = mfi.tilebox();
63 
64  // We don't compute a source term for z-momentum on the bottom or top boundary
65  if (tbz.smallEnd(2) == klo) tbz.growLo(2,-1);
66  if (tbz.bigEnd(2) == khi) tbz.growHi(2,-1);
67 
68  const Array4<const Real> & cell_data = S_data[IntVars::cons].array(mfi);
69  const Array4<const Real> & cell_prim = S_prim.array(mfi);
70  const Array4< Real> & buoyancy_fab = buoyancy.array(mfi);
71 
72  // Base state density and pressure
73  const Array4<const Real>& r0_arr = r0.const_array(mfi);
74  const Array4<const Real>& p0_arr = p0.const_array(mfi);
75  const Array4<const Real>& th0_arr = th0.const_array(mfi);
76  const Array4<const Real>& qv0_arr = qv0.const_array(mfi);
77 
78  if ( anelastic && (solverChoice.moisture_type == MoistureType::None) )
79  {
80  // ******************************************************************************************
81  // Dry anelastic
82  // ******************************************************************************************
83  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
84  {
85  //
86  // Return -rho0 g (thetaprime / theta0)
87  //
88  buoyancy_fab(i, j, k) = buoyancy_dry_anelastic(i,j,k,grav_gpu[2],
89  r0_arr,th0_arr,cell_data);
90  });
91  }
92  else if ( anelastic && (solverChoice.moisture_type != MoistureType::None) )
93  {
94  // ******************************************************************************************
95  // Moist anelastic
96  // ******************************************************************************************
97  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
98  {
99  //
100  // Return -rho0 g (thetaprime / theta0)
101  //
102  buoyancy_fab(i, j, k) = buoyancy_moist_anelastic(i,j,k,grav_gpu[2],rv_over_rd,
103  r0_arr,th0_arr,qv0_arr,cell_data);
104  });
105  }
106  else if ( !anelastic && (solverChoice.moisture_type == MoistureType::None) )
107  {
108  // ******************************************************************************************
109  // Dry compressible
110  // ******************************************************************************************
111  int n_q_dry = 0;
112  if (solverChoice.buoyancy_type == 1) {
113 
114  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
115  {
116  //
117  // Return -rho0 g (thetaprime / theta0)
118  //
119  buoyancy_fab(i, j, k) = buoyancy_rhopert(i,j,k,n_q_dry,grav_gpu[2],
120  r0_arr,cell_data);
121  });
122  }
123  else if (solverChoice.buoyancy_type == 2 || solverChoice.buoyancy_type == 3)
124  {
125  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
126  {
127  //
128  // Return -rho0 g (Tprime / T0)
129  //
130  buoyancy_fab(i, j, k) = buoyancy_dry_Tpert(i,j,k,grav_gpu[2],rd_over_cp,
131  r0_arr,p0_arr,th0_arr,cell_data);
132  });
133  }
134  else if (solverChoice.buoyancy_type == 4)
135  {
136  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
137  {
138  //
139  // Return -rho0 g (Theta_prime / Theta_0)
140  //
141  buoyancy_fab(i, j, k) = buoyancy_dry_Thpert(i,j,k,grav_gpu[2],
142  r0_arr,th0_arr,cell_data);
143  });
144  } // buoyancy_type for dry compressible
145  }
146  else // if ( !anelastic && (solverChoice.moisture_type != MoistureType::None) )
147  {
148  // ******************************************************************************************
149  // Moist compressible
150  // ******************************************************************************************
151 
152  if ( (solverChoice.moisture_type == MoistureType::Kessler_NoRain) ||
153  (solverChoice.moisture_type == MoistureType::SAM) ||
154  (solverChoice.moisture_type == MoistureType::SAM_NoPrecip_NoIce) )
155  {
156  AMREX_ALWAYS_ASSERT(solverChoice.buoyancy_type == 1);
157  }
158 
159  if (solverChoice.buoyancy_type == 1)
160  {
161  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
162  {
163  buoyancy_fab(i, j, k) = buoyancy_rhopert(i,j,k,n_qstate,grav_gpu[2],
164  r0_arr,cell_data);
165  });
166  }
167  else if (solverChoice.buoyancy_type == 2 || solverChoice.buoyancy_type == 3)
168  {
169 
170  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
171  {
172  buoyancy_fab(i, j, k) = buoyancy_moist_Tpert(i,j,k,n_qstate,grav_gpu[2],rd_over_cp,
173  r0_arr,th0_arr,qv0_arr,p0_arr,
174  cell_prim,cell_data);
175  });
176  }
177  else if (solverChoice.buoyancy_type == 4)
178  {
179  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
180  {
181  buoyancy_fab(i, j, k) = buoyancy_moist_Thpert(i,j,k,n_qstate,grav_gpu[2],
182  r0_arr,th0_arr,qv0_arr,cell_prim);
183  });
184  }
185  } // moist compressible
186  } // mfi
187 }
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real buoyancy_rhopert(int &i, int &j, int &k, const int &n_qstate, amrex::Real const &grav_gpu, const amrex::Array4< const amrex::Real > &r0_arr, const amrex::Array4< const amrex::Real > &cell_data)
Definition: ERF_BuoyancyUtils.H:69
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real buoyancy_dry_anelastic(int &i, int &j, int &k, amrex::Real const &grav_gpu, const amrex::Array4< const amrex::Real > &r0_arr, const amrex::Array4< const amrex::Real > &th0_arr, const amrex::Array4< const amrex::Real > &cell_data)
Definition: ERF_BuoyancyUtils.H:10
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real buoyancy_dry_Thpert(int &i, int &j, int &k, amrex::Real const &grav_gpu, const amrex::Array4< const amrex::Real > &r0_arr, const amrex::Array4< const amrex::Real > &th0_arr, const amrex::Array4< const amrex::Real > &cell_prim)
Definition: ERF_BuoyancyUtils.H:113
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real buoyancy_moist_Thpert(int &i, int &j, int &k, const int &n_qstate, amrex::Real const &grav_gpu, const amrex::Array4< const amrex::Real > &r0_arr, const amrex::Array4< const amrex::Real > &th0_arr, const amrex::Array4< const amrex::Real > &qv0_arr, const amrex::Array4< const amrex::Real > &cell_prim)
Definition: ERF_BuoyancyUtils.H:171
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real buoyancy_dry_Tpert(int &i, int &j, int &k, amrex::Real const &grav_gpu, amrex::Real const &rd_over_cp, const amrex::Array4< const amrex::Real > &r0_arr, const amrex::Array4< const amrex::Real > &p0_arr, const amrex::Array4< const amrex::Real > &th0_arr, const amrex::Array4< const amrex::Real > &cell_data)
Definition: ERF_BuoyancyUtils.H:87
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real buoyancy_moist_Tpert(int &i, int &j, int &k, const int &n_qstate, amrex::Real const &grav_gpu, amrex::Real const &rd_over_cp, const amrex::Array4< const amrex::Real > &r0_arr, const amrex::Array4< const amrex::Real > &th0_arr, const amrex::Array4< const amrex::Real > &qv0_arr, const amrex::Array4< const amrex::Real > &p0_arr, const amrex::Array4< const amrex::Real > &cell_prim, const amrex::Array4< const amrex::Real > &cell_data)
Definition: ERF_BuoyancyUtils.H:131
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real buoyancy_moist_anelastic(int &i, int &j, int &k, amrex::Real const &grav_gpu, amrex::Real const &rv_over_rd, const amrex::Array4< const amrex::Real > &r0_arr, const amrex::Array4< const amrex::Real > &th0_arr, const amrex::Array4< const amrex::Real > &qv0_arr, const amrex::Array4< const amrex::Real > &cell_data)
Definition: ERF_BuoyancyUtils.H:30
constexpr amrex::Real R_v
Definition: ERF_Constants.H:11
constexpr amrex::Real R_d
Definition: ERF_Constants.H:10
@ qv0_comp
Definition: ERF_IndexDefines.H:67
@ p0_comp
Definition: ERF_IndexDefines.H:64
@ th0_comp
Definition: ERF_IndexDefines.H:66
@ r0_comp
Definition: ERF_IndexDefines.H:63
@ cons
Definition: ERF_IndexDefines.H:150
amrex::Real rdOcp
Definition: ERF_DataStruct.H:711
amrex::Real gravity
Definition: ERF_DataStruct.H:709
MoistureType moisture_type
Definition: ERF_DataStruct.H:759
int buoyancy_type
Definition: ERF_DataStruct.H:690

Referenced by make_mom_sources().

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