ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_MakeGradP.cpp File Reference
#include <AMReX_MultiFab.H>
#include <AMReX_ArrayLim.H>
#include "AMReX_BCRec.H"
#include "ERF.H"
#include "ERF_SrcHeaders.H"
#include "ERF_DataStruct.H"
#include "ERF_Utils.H"
#include "ERF_EB.H"
#include <ERF_EBSlopes.H>
Include dependency graph for ERF_MakeGradP.cpp:

Functions

AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real dqdz_cc (int i, int j, int k, int klo, int khi, const Array4< const Real > &q_arr, const Array4< const Real > &z_cc_arr)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real dqdz_cc_onesided (int i, int j, int k, int sgn, const Array4< const Real > &q_arr, const Array4< const Real > &z_cc_arr)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real nonhydro_residual_cc (int i, int j, int k, int klo, int khi, const Real grav, const Array4< const Real > &p_arr, const Array4< const Real > &rp_arr, const Array4< const Real > &z_cc_arr)
 
void make_gradp_pert (int level, const SolverChoice &solverChoice, const Geometry &geom, Vector< MultiFab > &S_data, const MultiFab &base_state, const MultiFab &qt, const MultiFab &z_phys_cc, Vector< std::unique_ptr< MultiFab >> &mapfac, const eb_ &ebfact, Vector< MultiFab > &gradp)
 
void compute_gradp (int lev, const MultiFab &p, const Geometry &geom, const MultiFab &z_phys_cc, Vector< std::unique_ptr< MultiFab >> &mapfac, const eb_ &ebfact, Vector< MultiFab > &gradp, const SolverChoice &solverChoice)
 Compute the full pressure gradient. More...
 
void compute_gradp_xy (const MultiFab &p, const Geometry &geom, const MultiFab &z_phys_cc, Vector< std::unique_ptr< MultiFab >> &mapfac, const eb_ &ebfact, Vector< MultiFab > &gradp, const SolverChoice &solverChoice)
 Compute the horizontal components of the pressure gradient. More...
 
void compute_gradp_z (const MultiFab &p, const Geometry &geom, const MultiFab &z_phys_cc, const eb_ &ebfact, Vector< MultiFab > &gradp, const SolverChoice &solverChoice, bool use_zcc)
 Compute the vertical component of the pressure gradient. More...
 
void compute_gradp_hse (const MultiFab &p, const MultiFab &rhopert, const Geometry &geom, const MultiFab &z_phys_cc, Vector< std::unique_ptr< MultiFab >> &mapfac, Vector< MultiFab > &gradp, const SolverChoice &solverChoice)
 Compute the horizontal components of the pressure gradient, carrying the hydrostatic part of the perturbational pressure to the height of the face along dp'/dz = -g rho' and only the non-hydrostatic remainder along a difference of p'. More...
 

Function Documentation

◆ compute_gradp()

void compute_gradp ( int  lev,
const MultiFab &  p,
const Geometry &  geom,
const MultiFab &  z_phys_cc,
Vector< std::unique_ptr< MultiFab >> &  mapfac,
const eb_ &  ebfact,
Vector< MultiFab > &  gradp,
const SolverChoice &  solverChoice 
)

Compute the full pressure gradient.

Parameters
[in]levLevel of refinement.
[in]pPressure field.
[in]geomGeometry container.
[in]z_phys_ccPhysical height on cell centers.
[in]mapfacMap factors.
[in]ebfactEB factory.
[out]gradpPressure gradient components.
[in]solverChoiceSolver options.
258 {
259  compute_gradp_xy(p,geom,z_phys_cc,mapfac,ebfact,gradp,solverChoice);
260  compute_gradp_z(p,geom,z_phys_cc,ebfact,gradp,solverChoice,solverChoice.zcc_vertical_metric(lev));
261 }
void compute_gradp_z(const MultiFab &p, const Geometry &geom, const MultiFab &z_phys_cc, const eb_ &ebfact, Vector< MultiFab > &gradp, const SolverChoice &solverChoice, bool use_zcc)
Compute the vertical component of the pressure gradient.
Definition: ERF_MakeGradP.cpp:569
void compute_gradp_xy(const MultiFab &p, const Geometry &geom, const MultiFab &z_phys_cc, Vector< std::unique_ptr< MultiFab >> &mapfac, const eb_ &ebfact, Vector< MultiFab > &gradp, const SolverChoice &solverChoice)
Compute the horizontal components of the pressure gradient.
Definition: ERF_MakeGradP.cpp:274
@ p
Definition: ERF_WSM6.H:303
bool zcc_vertical_metric(int lev) const noexcept
Definition: ERF_DataStruct.H:3267

Referenced by ERF::compute_max_pressure_gradient_diagnostic(), and ERF::FillPlot3DVars().

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

◆ compute_gradp_hse()

void compute_gradp_hse ( const MultiFab &  p,
const MultiFab &  rhopert,
const Geometry &  geom,
const MultiFab &  z_phys_cc,
Vector< std::unique_ptr< MultiFab >> &  mapfac,
Vector< MultiFab > &  gradp,
const SolverChoice &  solverChoice 
)

Compute the horizontal components of the pressure gradient, carrying the hydrostatic part of the perturbational pressure to the height of the face along dp'/dz = -g rho' and only the non-hydrostatic remainder along a difference of p'.

At an x-face (i,j,k) the two cell centers that straddle the face sit at different physical heights, so each must be carried a signed distance

dz_int = 1/2 ( z_cc(i,j,k) - z_cc(i-1,j,k) )

to reach the height of the face. ChainRule does this with a centered difference of p'. Over steep terrain in nearly hydrostatic flow that difference is dominated by its hydrostatic part, dp'/dz ~ -g rho', which is large compared with the horizontal gradient being sought, so its truncation error dominates the answer. Here we split

dp'/dz = -g rho' + r,    r = dp'/dz + g rho',

integrate the first term exactly over the segment and difference only r, so that

gpx = [p'(i,j,k) - p'(i-1,j,k)]/dx + met_h_xi * 1/2 * [(g rhot - r)(i,j,k) + (g rhot - r)(i-1,j,k)]

where met_h_xi = 2*dz_int/dx, rhot is rho' reconstructed linearly and evaluated at the midpoint of each of the two extrapolation segments, and r is formed in each column by nonhydro_residual_cc. Two properties follow:

  • On every w-face r is exactly gpz + buoyancy as the w-equation forms them (with buoyancy_type 1), so in a state that the w-equation sees as balanced r vanishes and gpx is the pure hydrostatic reconstruction: it vanishes identically whenever rho' is linear in z and p' is its hydrostatic integral, whatever the terrain slope.
  • Substituting the definition of r shows gpx equals the ChainRule stencil plus g * met_h_xi * (rhot - rhohat), with rhohat the Delta z-weighted average of rho' on the two adjacent w-faces. That correction vanishes as the mesh is refined, so unlike a purely hydrostatic reconstruction this remains consistent in strongly non-hydrostatic flow.

Note that the stencil needs no branch on the sign of dz_int, since the formula is symmetric under dz_int -> -dz_int, and that it reaches only to k-1 and k+1.

Parameters
[in]pPerturbational pressure field.
[in]rhopertPerturbational (moist) density field.
[in]geomGeometry container.
[in]z_phys_ccPhysical height on cell centers.
[in]mapfacMap factors.
[out]gradpPressure gradient components.
[in]solverChoiceSolver options.
757 {
758  const bool l_use_terrain_fitted_coords = (solverChoice.mesh_type != MeshType::ConstantDz);
759 
760  // Note this is the magnitude of gravity, i.e. it is positive
761  const Real l_grav = solverChoice.gravity;
762 
763  const Box domain = geom.Domain();
764  const int domain_klo = domain.smallEnd(2);
765  const int domain_khi = domain.bigEnd(2);
766 
767  const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
768 
769  for ( MFIter mfi(p); mfi.isValid(); ++mfi)
770  {
771  Box tbx = mfi.nodaltilebox(0);
772  Box tby = mfi.nodaltilebox(1);
773 
774  // Terrain metrics
775  const Array4<const Real>& z_cc_arr = z_phys_cc.const_array(mfi);
776 
777  const Array4<const Real>& p_arr = p.const_array(mfi);
778  const Array4<const Real>& rp_arr = rhopert.const_array(mfi);
779 
780  const Array4< Real>& gpx_arr = gradp[GpVars::gpx].array(mfi);
781  const Array4< Real>& gpy_arr = gradp[GpVars::gpy].array(mfi);
782 
783  const Array4<const Real>& mf_ux_arr = mapfac[MapFacType::u_x]->const_array(mfi);
784  const Array4<const Real>& mf_vy_arr = mapfac[MapFacType::v_y]->const_array(mfi);
785 
786  ParallelFor(tbx, tby,
787  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
788  {
789  // Gradient in computational coordinates; the map factor is applied below
790  Real gpx = dxInv[0] * (p_arr(i,j,k) - p_arr(i-1,j,k));
791 
792  if (l_use_terrain_fitted_coords) {
793  Real met_h_xi = (z_cc_arr(i,j,k) - z_cc_arr(i-1,j,k)) * dxInv[0];
794  Real dz_int = myhalf * (z_cc_arr(i,j,k) - z_cc_arr(i-1,j,k));
795 
796  // rho' at the midpoint of each of the two extrapolation segments
797  Real rp_hi = rp_arr(i ,j,k) - myhalf * dz_int * dqdz_cc(i ,j,k,domain_klo,domain_khi,rp_arr,z_cc_arr);
798  Real rp_lo = rp_arr(i-1,j,k) + myhalf * dz_int * dqdz_cc(i-1,j,k,domain_klo,domain_khi,rp_arr,z_cc_arr);
799 
800  // -dp'/dz in each column: the hydrostatic part plus the non-hydrostatic remainder
801  Real force_hi = l_grav * rp_hi - nonhydro_residual_cc(i ,j,k,domain_klo,domain_khi,l_grav,p_arr,rp_arr,z_cc_arr);
802  Real force_lo = l_grav * rp_lo - nonhydro_residual_cc(i-1,j,k,domain_klo,domain_khi,l_grav,p_arr,rp_arr,z_cc_arr);
803 
804  gpx += met_h_xi * myhalf * (force_hi + force_lo);
805  }
806  gpx_arr(i,j,k) = gpx;
807 
808  // Apply the map factor; the stored gradp carries it
809  gpx_arr(i,j,k) *= mf_ux_arr(i,j,0);
810  },
811  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
812  {
813  // Gradient in computational coordinates; the map factor is applied below
814  Real gpy = dxInv[1] * (p_arr(i,j,k) - p_arr(i,j-1,k));
815 
816  if (l_use_terrain_fitted_coords) {
817  Real met_h_eta = (z_cc_arr(i,j,k) - z_cc_arr(i,j-1,k)) * dxInv[1];
818  Real dz_int = myhalf * (z_cc_arr(i,j,k) - z_cc_arr(i,j-1,k));
819 
820  // rho' at the midpoint of each of the two extrapolation segments
821  Real rp_hi = rp_arr(i,j ,k) - myhalf * dz_int * dqdz_cc(i,j ,k,domain_klo,domain_khi,rp_arr,z_cc_arr);
822  Real rp_lo = rp_arr(i,j-1,k) + myhalf * dz_int * dqdz_cc(i,j-1,k,domain_klo,domain_khi,rp_arr,z_cc_arr);
823 
824  // -dp'/dz in each column: the hydrostatic part plus the non-hydrostatic remainder
825  Real force_hi = l_grav * rp_hi - nonhydro_residual_cc(i,j ,k,domain_klo,domain_khi,l_grav,p_arr,rp_arr,z_cc_arr);
826  Real force_lo = l_grav * rp_lo - nonhydro_residual_cc(i,j-1,k,domain_klo,domain_khi,l_grav,p_arr,rp_arr,z_cc_arr);
827 
828  gpy += met_h_eta * myhalf * (force_hi + force_lo);
829  }
830  gpy_arr(i,j,k) = gpy;
831 
832  // Apply the map factor; the stored gradp carries it
833  gpy_arr(i,j,k) *= mf_vy_arr(i,j,0);
834  });
835  } // mfi
836 }
@ v_y
Definition: ERF_DataStruct.H:41
@ u_x
Definition: ERF_DataStruct.H:40
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real dqdz_cc(int i, int j, int k, int klo, int khi, const Array4< const Real > &q_arr, const Array4< const Real > &z_cc_arr)
Definition: ERF_MakeGradP.cpp:30
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real nonhydro_residual_cc(int i, int j, int k, int klo, int khi, const Real grav, const Array4< const Real > &p_arr, const Array4< const Real > &rp_arr, const Array4< const Real > &z_cc_arr)
Definition: ERF_MakeGradP.cpp:90
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 myhalf
Definition: ERF_NumericalConstants.H:41
@ gpy
Definition: ERF_IndexDefines.H:242
@ gpx
Definition: ERF_IndexDefines.H:241
amrex::Real gravity
Effective gravitational acceleration.
Definition: ERF_DataStruct.H:3148
static MeshType mesh_type
Vertical mesh representation.
Definition: ERF_DataStruct.H:3004

Referenced by make_gradp_pert().

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

◆ compute_gradp_xy()

void compute_gradp_xy ( const MultiFab &  p,
const Geometry &  geom,
const MultiFab &  z_phys_cc,
Vector< std::unique_ptr< MultiFab >> &  mapfac,
const eb_ &  ebfact,
Vector< MultiFab > &  gradp,
const SolverChoice &  solverChoice 
)

Compute the horizontal components of the pressure gradient.

Parameters
[in]pPressure field.
[in]geomGeometry container.
[in]z_phys_ccPhysical height on cell centers.
[in]mapfacMap factors.
[in]ebfactEB factory.
[out]gradpPressure gradient components.
[in]solverChoiceSolver options.
281 {
282  const bool l_use_terrain_fitted_coords = (solverChoice.mesh_type != MeshType::ConstantDz);
283 
284  const Box domain = geom.Domain();
285  const int domain_klo = domain.smallEnd(2);
286  const int domain_khi = domain.bigEnd(2);
287 
288  // The second-order one-sided difference at the bottom and top (an option) needs three
289  // cells in the column
290  const bool l_three_point = solverChoice.gradp_2nd_order_bndry && (domain_khi - domain_klo >= 2);
291 
292  const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
293 
294  // *****************************************************************************
295  // Take gradient of relevant quantity (p0, pres, or pert_pres = pres - p0)
296  // *****************************************************************************
297  for ( MFIter mfi(p); mfi.isValid(); ++mfi)
298  {
299  Box tbx = mfi.nodaltilebox(0);
300  Box tby = mfi.nodaltilebox(1);
301 
302  // Terrain metrics
303  const Array4<const Real>& z_cc_arr = z_phys_cc.const_array(mfi);
304 
305  const Array4<const Real>& p_arr = p.const_array(mfi);
306 
307  const Array4< Real>& gpx_arr = gradp[GpVars::gpx].array(mfi);
308  const Array4< Real>& gpy_arr = gradp[GpVars::gpy].array(mfi);
309 
310  const Array4<const Real>& mf_ux_arr = mapfac[MapFacType::u_x]->const_array(mfi);
311  const Array4<const Real>& mf_vy_arr = mapfac[MapFacType::v_y]->const_array(mfi);
312 
313  if (solverChoice.terrain_type != TerrainType::EB) {
314 
315  ParallelFor(tbx, tby,
316  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
317  {
318  // Gradient in computational coordinates; the map factor is applied below
319  Real gpx = dxInv[0] * (p_arr(i,j,k) - p_arr(i-1,j,k));
320 
321  if (l_use_terrain_fitted_coords) {
322  Real met_h_xi = (z_cc_arr(i,j,k) - z_cc_arr(i-1,j,k)) * dxInv[0];
323 
324  Real dz_phys_hi, dz_phys_lo;
325  Real gpz_lo, gpz_hi;
326  // At the bottom and top, optionally a second-order one-sided difference,
327  // so that dp/dz is as accurate there as the centered difference is inside
328  // (with the two-point difference the error is first order and sits
329  // right at the ground)
330  if (k==domain_klo && l_three_point) {
331  gpz_hi = dqdz_cc_onesided(i,j,k, 1,p_arr,z_cc_arr);
332  gpz_lo = dqdz_cc_onesided(i-1,j,k, 1,p_arr,z_cc_arr);
333  } else if (k==domain_khi && l_three_point) {
334  gpz_hi = dqdz_cc_onesided(i,j,k,-1,p_arr,z_cc_arr);
335  gpz_lo = dqdz_cc_onesided(i-1,j,k,-1,p_arr,z_cc_arr);
336  } else if (k==domain_klo) {
337  dz_phys_hi = z_cc_arr(i ,j,k+1) - z_cc_arr(i ,j,k );
338  dz_phys_lo = z_cc_arr(i-1,j,k+1) - z_cc_arr(i-1,j,k );
339  gpz_hi = (p_arr(i ,j,k+1) - p_arr(i ,j,k )) / dz_phys_hi;
340  gpz_lo = (p_arr(i-1,j,k+1) - p_arr(i-1,j,k )) / dz_phys_lo;
341  } else if (k==domain_khi) {
342  dz_phys_hi = z_cc_arr(i ,j,k ) - z_cc_arr(i ,j,k-1);
343  dz_phys_lo = z_cc_arr(i-1,j,k ) - z_cc_arr(i-1,j,k-1);
344  gpz_hi = (p_arr(i ,j,k ) - p_arr(i ,j,k-1)) / dz_phys_hi;
345  gpz_lo = (p_arr(i-1,j,k ) - p_arr(i-1,j,k-1)) / dz_phys_lo;
346  } else {
347  dz_phys_hi = z_cc_arr(i ,j,k+1) - z_cc_arr(i ,j,k-1);
348  dz_phys_lo = z_cc_arr(i-1,j,k+1) - z_cc_arr(i-1,j,k-1);
349  gpz_hi = (p_arr(i ,j,k+1) - p_arr(i ,j,k-1)) / dz_phys_hi;
350  gpz_lo = (p_arr(i-1,j,k+1) - p_arr(i-1,j,k-1)) / dz_phys_lo;
351  }
352  Real gpx_metric = met_h_xi * myhalf * (gpz_hi + gpz_lo);
353  gpx -= gpx_metric;
354  }
355  gpx_arr(i,j,k) = gpx;
356 
357  // Apply the map factor; the stored gradp carries it
358  gpx_arr(i,j,k) *= mf_ux_arr(i,j,0);
359  },
360  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
361  {
362  // Gradient in computational coordinates; the map factor is applied below
363  Real gpy = dxInv[1] * (p_arr(i,j,k) - p_arr(i,j-1,k));
364 
365  if (l_use_terrain_fitted_coords) {
366  Real met_h_eta = (z_cc_arr(i,j,k) - z_cc_arr(i,j-1,k)) * dxInv[1];
367 
368  Real dz_phys_hi, dz_phys_lo;
369  Real gpz_lo, gpz_hi;
370  // At the bottom and top, optionally a second-order one-sided difference,
371  // so that dp/dz is as accurate there as the centered difference is inside
372  // (with the two-point difference the error is first order and sits
373  // right at the ground)
374  if (k==domain_klo && l_three_point) {
375  gpz_hi = dqdz_cc_onesided(i,j,k, 1,p_arr,z_cc_arr);
376  gpz_lo = dqdz_cc_onesided(i,j-1,k, 1,p_arr,z_cc_arr);
377  } else if (k==domain_khi && l_three_point) {
378  gpz_hi = dqdz_cc_onesided(i,j,k,-1,p_arr,z_cc_arr);
379  gpz_lo = dqdz_cc_onesided(i,j-1,k,-1,p_arr,z_cc_arr);
380  } else if (k==domain_klo) {
381  dz_phys_hi = z_cc_arr(i,j ,k+1) - z_cc_arr(i,j ,k );
382  dz_phys_lo = z_cc_arr(i,j-1,k+1) - z_cc_arr(i,j-1,k );
383  gpz_hi = (p_arr(i,j ,k+1) - p_arr(i,j ,k )) / dz_phys_hi;
384  gpz_lo = (p_arr(i,j-1,k+1) - p_arr(i,j-1,k )) / dz_phys_lo;
385  } else if (k==domain_khi) {
386  dz_phys_hi = z_cc_arr(i,j ,k ) - z_cc_arr(i,j ,k-1);
387  dz_phys_lo = z_cc_arr(i,j-1,k ) - z_cc_arr(i,j-1,k-1);
388  gpz_hi = (p_arr(i,j ,k ) - p_arr(i,j ,k-1)) / dz_phys_hi;
389  gpz_lo = (p_arr(i,j-1,k ) - p_arr(i,j-1,k-1)) / dz_phys_lo;
390  } else {
391  dz_phys_hi = z_cc_arr(i,j ,k+1) - z_cc_arr(i,j ,k-1);
392  dz_phys_lo = z_cc_arr(i,j-1,k+1) - z_cc_arr(i,j-1,k-1);
393  gpz_hi = (p_arr(i,j ,k+1) - p_arr(i,j ,k-1)) / dz_phys_hi;
394  gpz_lo = (p_arr(i,j-1,k+1) - p_arr(i,j-1,k-1)) / dz_phys_lo;
395  }
396  Real gpy_metric = met_h_eta * myhalf * (gpz_hi + gpz_lo);
397  gpy -= gpy_metric;
398  }
399  gpy_arr(i,j,k) = gpy;
400 
401  // Apply the map factor; the stored gradp carries it
402  gpy_arr(i,j,k) *= mf_vy_arr(i,j,0);
403  });
404 
405  // solverChoice.terrain_type == TerrainType::EB
406  } else {
407 
408  // Pressure gradients are fitted at the centroids of cut cells, if EB and Compressible.
409  // Least-Squares Fitting: Compute slope using 3x3x3 stencil
410 
411  const bool l_fitting = false;
412 
413  const Real* dx_arr = geom.CellSize();
414  const Real dx = dx_arr[0];
415  const Real dy = dx_arr[1];
416  const Real dz = dx_arr[2];
417 
418  // EB factory
419  Array4<const EBCellFlag> cellflg = (ebfact.get_const_factory())->getMultiEBCellFlagFab()[mfi].const_array();
420 
421  // EB u-factory
422  auto const* u_factory = ebfact.get_u_const_factory();
423  Array4<const EBCellFlag> u_cellflg = u_factory->getMultiEBCellFlagFab()[mfi].const_array();
424  Array4<const Real > u_volfrac = u_factory->getVolFrac().const_array(mfi);
425  bool u_is_cut = (u_factory->getMultiEBCellFlagFab()[mfi].getType() == FabType::singlevalued);
426  Array4<const Real > u_volcent = u_is_cut ? u_factory->getCentroid().const_array(mfi) : Array4<const Real>{};
427 
428  // EB v-factory
429  auto const* v_factory = ebfact.get_v_const_factory();
430  Array4<const EBCellFlag> v_cellflg = v_factory->getMultiEBCellFlagFab()[mfi].const_array();
431  Array4<const Real > v_volfrac = v_factory->getVolFrac().const_array(mfi);
432  bool v_is_cut = (v_factory->getMultiEBCellFlagFab()[mfi].getType() == FabType::singlevalued);
433  Array4<const Real > v_volcent = v_is_cut ? v_factory->getCentroid().const_array(mfi) : Array4<const Real>{};
434 
435  if (l_fitting) {
436 
437  ParallelFor(tbx, tby,
438  [=] AMREX_GPU_DEVICE(int i, int j, int k)
439  {
440  if (u_volfrac(i,j,k) > zero) {
441 
442  if (u_cellflg(i,j,k).isSingleValued()) {
443 
444  GpuArray<Real,AMREX_SPACEDIM> slopes;
445  slopes = erf_calc_slopes_eb_staggered(Vars::xvel, Vars::cons, dx, dy, dz, i, j, k, p_arr, u_volcent, u_cellflg);
446 
447  gpx_arr(i,j,k) = slopes[0];
448 
449  } else {
450  gpx_arr(i,j,k) = dxInv[0] * (p_arr(i,j,k) - p_arr(i-1,j,k));
451  }
452 
453  } else {
454  gpx_arr(i,j,k) = zero;
455  }
456  },
457  [=] AMREX_GPU_DEVICE(int i, int j, int k)
458  {
459  if (v_volfrac(i,j,k) > zero) {
460 
461  if (v_cellflg(i,j,k).isSingleValued()) {
462 
463  GpuArray<Real,AMREX_SPACEDIM> slopes;
464  slopes = erf_calc_slopes_eb_staggered(Vars::yvel, Vars::cons, dx, dy, dz, i, j, k, p_arr, v_volcent, v_cellflg);
465 
466  gpy_arr(i,j,k) = slopes[1];
467 
468  } else {
469  gpy_arr(i,j,k) = dxInv[1] * (p_arr(i,j,k) - p_arr(i,j-1,k));
470  }
471  } else {
472  gpy_arr(i,j,k) = zero;
473  }
474  });
475 
476  } else {
477 
478  // Simple calculation: assuming pressures at cell centers
479 
480  ParallelFor(tbx, tby,
481  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
482  {
483  if (u_volfrac(i,j,k) > zero) {
484 
485  if (cellflg(i,j,k).isCovered()) {
486  // Check if all donor cells on the low side are not covered
487  if (!cellflg(i-1,j,k).isCovered() && !cellflg(i-2,j,k).isCovered() && !cellflg(i-3,j,k).isCovered()) {
488  // Use three-point stencil (second-order accurate)
489  gpx_arr(i,j,k) = dxInv[0] * (p_arr(i-3,j,k) - three*p_arr(i-2,j,k) + two*p_arr(i-1,j,k));
490  } else {
491  // Fall back to one-sided two-point stencil (first-order)
492  gpx_arr(i,j,k) = dxInv[0] * (p_arr(i-1,j,k) - p_arr(i-2,j,k));
493  }
494  } else if (cellflg(i-1,j,k).isCovered()) {
495  // Check if all donor cells on the high side are not covered
496  if (!cellflg(i,j,k).isCovered() && !cellflg(i+1,j,k).isCovered() && !cellflg(i+2,j,k).isCovered()) {
497  // Use three-point stencil (second-order accurate)
498  gpx_arr(i,j,k) = dxInv[0] * (three*p_arr(i+1,j,k) - p_arr(i+2,j,k) - two*p_arr(i,j,k));
499  } else {
500  // Fall back to one-sided two-point stencil (first-order)
501  gpx_arr(i,j,k) = dxInv[0] * (p_arr(i+1,j,k) - p_arr(i,j,k));
502  }
503  } else {
504  gpx_arr(i,j,k) = dxInv[0] * (p_arr(i,j,k) - p_arr(i-1,j,k));
505  }
506  } else {
507  gpx_arr(i,j,k) = zero;
508  }
509  },
510  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
511  {
512  if (v_volfrac(i,j,k) > zero) {
513  if (cellflg(i,j,k).isCovered()) {
514  // Check if all donor cells on the low side are not covered
515  if (!cellflg(i,j-1,k).isCovered() && !cellflg(i,j-2,k).isCovered() && !cellflg(i,j-3,k).isCovered()) {
516  // Use three-point stencil (second-order accurate)
517  gpy_arr(i,j,k) = dxInv[1] * (p_arr(i,j-3,k) - three*p_arr(i,j-2,k) + two*p_arr(i,j-1,k));
518  } else {
519  // Fall back to one-sided two-point stencil (first-order)
520  gpy_arr(i,j,k) = dxInv[1] * (p_arr(i,j-1,k) - p_arr(i,j-2,k));
521  }
522  } else if (cellflg(i,j-1,k).isCovered()) {
523  // Check if all donor cells on the high side are not covered
524  if (!cellflg(i,j,k).isCovered() && !cellflg(i,j+1,k).isCovered() && !cellflg(i,j+2,k).isCovered()) {
525  // Use three-point stencil (second-order accurate)
526  gpy_arr(i,j,k) = dxInv[1] * (three*p_arr(i,j+1,k) - p_arr(i,j+2,k) - two*p_arr(i,j,k));
527  } else {
528  // Fall back to one-sided two-point stencil (first-order)
529  gpy_arr(i,j,k) = dxInv[1] * (p_arr(i,j+1,k) - p_arr(i,j,k));
530  }
531  } else {
532  gpy_arr(i,j,k) = dxInv[1] * (p_arr(i,j,k) - p_arr(i,j-1,k));
533  }
534  } else {
535  gpy_arr(i,j,k) = zero;
536  }
537  });
538 
539  } // l_fitting
540 
541  // Correct gradient with map factor, as in the non-EB branch
542  ParallelFor(tbx, tby,
543  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
544  {
545  gpx_arr(i,j,k) *= mf_ux_arr(i,j,0);
546  },
547  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
548  {
549  gpy_arr(i,j,k) *= mf_vy_arr(i,j,0);
550  });
551 
552  } // TerrainType::EB
553 
554  } // mfi
555 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > erf_calc_slopes_eb_staggered(int igrid_query, int igrid_data, amrex::Real dx, amrex::Real dy, amrex::Real dz, int i, int j, int k, amrex::Array4< amrex::Real const > const &state, amrex::Array4< amrex::Real const > const &ccent, amrex::Array4< amrex::EBCellFlag const > const &flag)
Compute centered least-squares slopes from cell data to a staggered query grid.
Definition: ERF_EBSlopes.H:156
const Real dy
Definition: ERF_InitCustomPert_ABL.H:101
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real dqdz_cc_onesided(int i, int j, int k, int sgn, const Array4< const Real > &q_arr, const Array4< const Real > &z_cc_arr)
Definition: ERF_MakeGradP.cpp:57
constexpr amrex::Real three
Definition: ERF_NumericalConstants.H:39
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
const std::unique_ptr< amrex::EBFArrayBoxFactory > & get_const_factory() const noexcept
Return the cell-centered EB factory.
Definition: ERF_EB.H:110
amrex::EBFArrayBoxFactory const * get_u_const_factory() const noexcept
Return the native AMReX x-face EB factory.
Definition: ERF_EB.H:132
amrex::EBFArrayBoxFactory const * get_v_const_factory() const noexcept
Return the native AMReX y-face EB factory.
Definition: ERF_EB.H:134
@ xvel
Definition: ERF_IndexDefines.H:232
@ cons
Definition: ERF_IndexDefines.H:231
@ yvel
Definition: ERF_IndexDefines.H:233
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
bool gradp_2nd_order_bndry
Whether ChainRule takes dp/dz at the bottom and top from a second-order one-sided difference.
Definition: ERF_DataStruct.H:3090
static TerrainType terrain_type
Terrain or immersed-boundary representation.
Definition: ERF_DataStruct.H:2989

Referenced by compute_gradp(), and make_gradp_pert().

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

◆ compute_gradp_z()

void compute_gradp_z ( const MultiFab &  p,
const Geometry &  geom,
const MultiFab &  z_phys_cc,
const eb_ &  ebfact,
Vector< MultiFab > &  gradp,
const SolverChoice &  solverChoice,
bool  use_zcc 
)

Compute the vertical component of the pressure gradient.

Parameters
[in]pPressure field.
[in]geomGeometry container.
[in]z_phys_ccPhysical height on cell centers.
[in]ebfactEB factory.
[out]gradpPressure gradient components.
[in]solverChoiceSolver options.
[in]use_zccUse the distance between the cell centers (z_phys_cc) rather than dz: SolverChoice::zcc_vertical_metric of the level
576 {
577  const bool l_use_terrain_fitted_coords = use_zcc;
578 
579  const Box domain = geom.Domain();
580  const int domain_klo = domain.smallEnd(2);
581  const int domain_khi = domain.bigEnd(2);
582 
583  const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
584 
585  // *****************************************************************************
586  // Take gradient of relevant quantity (p0, pres, or pert_pres = pres - p0)
587  // *****************************************************************************
588  for ( MFIter mfi(p); mfi.isValid(); ++mfi)
589  {
590  Box tbz = mfi.nodaltilebox(2);
591 
592  // We don't compute gpz on the bottom or top domain boundary
593  if (tbz.smallEnd(2) == domain_klo) {
594  tbz.growLo(2,-1);
595  }
596  if (tbz.bigEnd(2) == domain_khi+1) {
597  tbz.growHi(2,-1);
598  }
599 
600  // Terrain metrics
601  const Array4<const Real>& z_cc_arr = z_phys_cc.const_array(mfi);
602 
603  const Array4<const Real>& p_arr = p.const_array(mfi);
604 
605  const Array4< Real>& gpz_arr = gradp[GpVars::gpz].array(mfi);
606 
607  if (solverChoice.terrain_type != TerrainType::EB) {
608 
609  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
610  {
611  // The distance between the cell centers, which is what the hydrostatic base state and
612  // the fast vertical pressure gradient (make_fast_coeffs) use
613  gpz_arr(i,j,k) = (l_use_terrain_fitted_coords) ?
614  ( p_arr(i,j,k)-p_arr(i,j,k-1) ) / ( z_cc_arr(i,j,k)-z_cc_arr(i,j,k-1) ) :
615  dxInv[2] * ( p_arr(i,j,k)-p_arr(i,j,k-1) );
616  });
617 
618  } else {
619 
620  // Pressure gradients are fitted at the centroids of cut cells, if EB and Compressible.
621  // Least-Squares Fitting: Compute slope using 3x3x3 stencil
622 
623  const bool l_fitting = false;
624 
625  const Real* dx_arr = geom.CellSize();
626  const Real dx = dx_arr[0];
627  const Real dy = dx_arr[1];
628  const Real dz = dx_arr[2];
629 
630  // EB factory
631  Array4<const EBCellFlag> cellflg = (ebfact.get_const_factory())->getMultiEBCellFlagFab()[mfi].const_array();
632 
633  // EB w-factory
634  auto const* w_factory = ebfact.get_w_const_factory();
635  Array4<const EBCellFlag> w_cellflg = w_factory->getMultiEBCellFlagFab()[mfi].const_array();
636  Array4<const Real > w_volfrac = w_factory->getVolFrac().const_array(mfi);
637  bool w_is_cut = (w_factory->getMultiEBCellFlagFab()[mfi].getType() == FabType::singlevalued);
638  Array4<const Real > w_volcent = w_is_cut ? w_factory->getCentroid().const_array(mfi) : Array4<Real>{};
639 
640  if (l_fitting) {
641 
642  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k)
643  {
644  if (w_volfrac(i,j,k) > zero) {
645 
646  if (w_cellflg(i,j,k).isSingleValued()) {
647 
648  GpuArray<Real,AMREX_SPACEDIM> slopes;
649  slopes = erf_calc_slopes_eb_staggered(Vars::zvel, Vars::cons, dx, dy, dz, i, j, k, p_arr, w_volcent, w_cellflg);
650 
651  gpz_arr(i,j,k) = slopes[2];
652 
653  } else {
654  gpz_arr(i,j,k) = dxInv[2] * (p_arr(i,j,k) - p_arr(i,j,k-1));
655  }
656  } else {
657  gpz_arr(i,j,k) = zero;
658  }
659  });
660 
661  } else {
662 
663  // Simple calculation: assuming pressures at cell centers
664 
665  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
666  {
667  if (w_volfrac(i,j,k) > zero) {
668  if (cellflg(i,j,k).isCovered()) {
669  // Check if all donor cells on the low side are not covered
670  if (!cellflg(i,j,k-1).isCovered() && !cellflg(i,j,k-2).isCovered() && !cellflg(i,j,k-3).isCovered()) {
671  // Use three-point stencil (second-order accurate)
672  gpz_arr(i,j,k) = dxInv[2] * ( p_arr(i,j,k-3) - three*p_arr(i,j,k-2) + two*p_arr(i,j,k-1) );
673  } else {
674  // Fall back to one-sided two-point stencil (first-order)
675  gpz_arr(i,j,k) = dxInv[2] * ( p_arr(i,j,k-1) - p_arr(i,j,k-2) );
676  }
677  } else if (cellflg(i,j,k-1).isCovered()) {
678  // Check if all donor cells on the high side are not covered
679  if (!cellflg(i,j,k).isCovered() && !cellflg(i,j,k+1).isCovered() && !cellflg(i,j,k+2).isCovered()) {
680  // Use three-point stencil (second-order accurate)
681  gpz_arr(i,j,k) = dxInv[2] * ( three*p_arr(i,j,k+1) - p_arr(i,j,k+2) - two*p_arr(i,j,k) );
682  } else {
683  // Fall back to one-sided two-point stencil (first-order)
684  gpz_arr(i,j,k) = dxInv[2] * ( p_arr(i,j,k+1) - p_arr(i,j,k) );
685  }
686  } else {
687  gpz_arr(i,j,k) = dxInv[2] * ( p_arr(i,j,k)-p_arr(i,j,k-1) );
688  }
689  } else {
690  gpz_arr(i,j,k) = zero;
691  }
692  });
693 
694  } // l_fitting
695 
696  } // TerrainType::EB
697 
698  } // mfi
699 }
amrex::EBFArrayBoxFactory const * get_w_const_factory() const noexcept
Return the native AMReX z-face EB factory.
Definition: ERF_EB.H:136
@ gpz
Definition: ERF_IndexDefines.H:243
@ zvel
Definition: ERF_IndexDefines.H:234

Referenced by compute_gradp(), and make_gradp_pert().

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

◆ dqdz_cc()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real dqdz_cc ( int  i,
int  j,
int  k,
int  klo,
int  khi,
const Array4< const Real > &  q_arr,
const Array4< const Real > &  z_cc_arr 
)

Vertical derivative of a cell-centered quantity, taken with respect to physical height. Centered in the interior of the domain, one-sided at the bottom and top.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]klolowest k index of the domain
[in]khihighest k index of the domain
[in]q_arrcell-centered quantity to differentiate
[in]z_cc_arrphysical height at cell centers
Returns
dq/dz at (i,j,k)
34 {
35  int km = (k == klo) ? k : k-1;
36  int kp = (k == khi) ? k : k+1;
37  if (kp == km) { return zero; }
38  return (q_arr(i,j,kp) - q_arr(i,j,km)) / (z_cc_arr(i,j,kp) - z_cc_arr(i,j,km));
39 }
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
const int klo
Definition: ERF_InitCustomPert_KE.H:9
Real kp
Definition: ERF_InitCustomPert_MovingTerrain.H:9

Referenced by compute_gradp_hse().

Here is the caller graph for this function:

◆ dqdz_cc_onesided()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real dqdz_cc_onesided ( int  i,
int  j,
int  k,
int  sgn,
const Array4< const Real > &  q_arr,
const Array4< const Real > &  z_cc_arr 
)

Second-order one-sided vertical derivative of a cell-centered quantity at the bottom (sgn = 1) or top (sgn = -1) cell center, taken with respect to physical height from the quadratic through cells k, k+sgn and k+2*sgn.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index of the bottom or top cell
[in]sgn1 at the bottom of the domain, -1 at the top
[in]q_arrcell-centered quantity to differentiate
[in]z_cc_arrphysical height at cell centers
Returns
dq/dz at (i,j,k)
60 {
61  Real a = z_cc_arr(i,j,k+ sgn) - z_cc_arr(i,j,k);
62  Real b = z_cc_arr(i,j,k+2*sgn) - z_cc_arr(i,j,k);
63  return - (a + b) / (a * b) * q_arr(i,j,k )
64  + b / (a * (b - a)) * q_arr(i,j,k+ sgn)
65  - a / (b * (b - a)) * q_arr(i,j,k+2*sgn);
66 }

Referenced by compute_gradp_xy().

Here is the caller graph for this function:

◆ make_gradp_pert()

void make_gradp_pert ( int  level,
const SolverChoice &  solverChoice,
const Geometry &  geom,
Vector< MultiFab > &  S_data,
const MultiFab &  base_state,
const MultiFab &  qt,
const MultiFab &  z_phys_cc,
Vector< std::unique_ptr< MultiFab >> &  mapfac,
const eb_ &  ebfact,
Vector< MultiFab > &  gradp 
)

Function for computing the pressure gradient

Parameters
[in]levellevel of resolution
[in]geomgeometry container at this level
[in]S_datacurrent solution
[in]base_statebase state (r0, p0, pi0, th0, qv0)
[in]qttotal water mixing ratio (zero if there is no moisture)
[in]z_phys_ccz on cell centers
[in]d_bcrec_ptrBoundary Condition Record
[in]ebfactEB factory container at this level
[out]gradppressure gradient
132 {
133  const bool l_use_moisture = (solverChoice.moisture_type != MoistureType::None);
134  const bool l_eb_terrain = (solverChoice.terrain_type == TerrainType::EB);
135 
136  const bool l_use_pert_pres = (solverChoice.use_pert_pres_gradient);
137  //
138  // Note that we only recompute gradp if compressible;
139  // if anelastic or pseudo-incompressible then we have computed gradp in the projection
140  // and we can reuse it, no need to recompute it
141  //
142  if (solverChoice.compressibility_type[level] == CompressibilityType::FullyCompressible)
143  {
144  // HydrostaticHybrid carries the hydrostatic part of p' to the height of the lateral face
145  // along dp'/dz = -g rho', so it needs rho'.
146  //
147  // NOTE: this must be an always-assert rather than a debug-only one, because with
148  // EB we grow the boxes by more ghost cells than qt carries.
149  const bool l_need_rhopert = (solverChoice.gradp_type == GradpType::HydrostaticHybrid);
150  if (l_need_rhopert) {
151  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(solverChoice.terrain_type != TerrainType::EB,
152  "gradp_type HydrostaticHybrid is not implemented for EB");
153  }
154 
155  const int ngrow = (l_eb_terrain) ? 3 : 1;
156  MultiFab p(S_data[Vars::cons].boxArray(), S_data[Vars::cons].DistributionMap(), 1, ngrow);
157 
158  MultiFab rhopert;
159  if (l_need_rhopert) {
160  rhopert.define(S_data[Vars::cons].boxArray(), S_data[Vars::cons].DistributionMap(), 1, ngrow);
161  }
162 
163  // *****************************************************************************
164  // Compute pressure
165  // *****************************************************************************
166  for ( MFIter mfi(S_data[Vars::cons]); mfi.isValid(); ++mfi)
167  {
168  Box gbx = mfi.tilebox();
169  gbx.grow(IntVect(ngrow,ngrow,ngrow));
170 
171  if (gbx.smallEnd(2) < 0) gbx.setSmall(2,0);
172  const Array4<const Real>& cell_data = S_data[Vars::cons].array(mfi);
173  const Array4< Real>& pp_arr = p.array(mfi);
174  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
175  {
176  Real qv_for_p = (l_use_moisture) ? cell_data(i,j,k,RhoQ1_comp)/cell_data(i,j,k,Rho_comp) : zero;
177  pp_arr(i,j,k) = getPgivenRTh(cell_data(i,j,k,RhoTheta_comp),qv_for_p);
178  });
179  }
180 
181  // If we want to use the full pressure in the lateral gradients, call compute_gradp_xy here
182  if (solverChoice.gradp_type == GradpType::ChainRule && !l_use_pert_pres) {
183  compute_gradp_xy(p,geom,z_phys_cc,mapfac,ebfact,gradp,solverChoice);
184  }
185 
186  // *****************************************************************************
187  // Compute perturbational pressure -- and, if needed, perturbational density
188  //
189  // NOTE: rho' here is the same quantity that buoyancy_rhopert forms, i.e. the
190  // total (moist) density minus the total base-state density. Keeping the
191  // two definitions identical is what makes the hydrostatic reconstruction
192  // below consistent with the buoyancy term.
193  // *****************************************************************************
194  for ( MFIter mfi(S_data[Vars::cons]); mfi.isValid(); ++mfi)
195  {
196  Box gbx = mfi.tilebox();
197  gbx.grow(IntVect(ngrow,ngrow,ngrow));
198 
199  if (gbx.smallEnd(2) < 0) gbx.setSmall(2,0);
200  const Array4<const Real>& base_arr = base_state.const_array(mfi);
201  const Array4< Real>& pp_arr = p.array(mfi);
202  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
203  {
204  pp_arr(i,j,k) -= base_arr(i,j,k,BaseState::p0_comp);
205  });
206 
207  if (l_need_rhopert) {
208  const Array4<const Real>& cell_data = S_data[Vars::cons].const_array(mfi);
209  const Array4<const Real>& qt_arr = qt.const_array(mfi);
210  const Array4< Real>& rp_arr = rhopert.array(mfi);
211  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
212  {
213  Real qt_loc = (l_use_moisture) ? qt_arr(i,j,k) : zero;
214  rp_arr(i,j,k) = cell_data(i,j,k,Rho_comp) * (one + qt_loc)
215  - base_arr(i,j,k,BaseState::r0_comp)
216  * (one + base_arr(i,j,k,BaseState::qv0_comp));
217  });
218  }
219  }
220 
221  // If we want to use the perturbational pressure in the lateral gradients, call compute_gradp_xy here
222  if (solverChoice.gradp_type == GradpType::ChainRule && l_use_pert_pres) {
223  compute_gradp_xy(p,geom,z_phys_cc,mapfac,ebfact,gradp,solverChoice);
224  }
225 
226  // HydrostaticHybrid replaces the lateral gradients only; gpz is computed below
227  // exactly as it is for ChainRule
228  if (l_need_rhopert) {
229  compute_gradp_hse(p,rhopert,geom,z_phys_cc,mapfac,gradp,solverChoice);
230  }
231 
232  compute_gradp_z(p,geom,z_phys_cc,ebfact,gradp,solverChoice,
233  solverChoice.zcc_vertical_metric(level));
234 
235  } // FullyCompressible
236 }
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
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:78
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
void compute_gradp_hse(const MultiFab &p, const MultiFab &rhopert, const Geometry &geom, const MultiFab &z_phys_cc, Vector< std::unique_ptr< MultiFab >> &mapfac, Vector< MultiFab > &gradp, const SolverChoice &solverChoice)
Compute the horizontal components of the pressure gradient, carrying the hydrostatic part of the pert...
Definition: ERF_MakeGradP.cpp:750
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
@ qv0_comp
Definition: ERF_IndexDefines.H:113
@ p0_comp
Definition: ERF_IndexDefines.H:110
@ r0_comp
Definition: ERF_IndexDefines.H:109
@ None
Definition: ERF_LSM_Types.H:6
@ qt
Definition: ERF_Kessler.H:30
MoistureType moisture_type
Moisture or microphysics model.
Definition: ERF_DataStruct.H:3433
bool use_pert_pres_gradient
Whether momentum equations use perturbational pressure gradients.
Definition: ERF_DataStruct.H:3092
amrex::Vector< CompressibilityType > compressibility_type
Per-level compressibility (FullyCompressible, Anelastic or PseudoIncompressible).
Definition: ERF_DataStruct.H:3028
GradpType gradp_type
Terrain-fitted horizontal pressure-gradient formulation.
Definition: ERF_DataStruct.H:3088

Referenced by ERF::compute_max_buoyancy_gradp_diagnostic().

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

◆ nonhydro_residual_cc()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real nonhydro_residual_cc ( int  i,
int  j,
int  k,
int  klo,
int  khi,
const Real  grav,
const Array4< const Real > &  p_arr,
const Array4< const Real > &  rp_arr,
const Array4< const Real > &  z_cc_arr 
)

Non-hydrostatic residual of the vertical pressure gradient, dp'/dz + g rho', brought to the cell center. On each w-face this residual is exactly gpz + buoyancy as the dycore forms them (with buoyancy_rhopert), so it vanishes wherever the w-equation sees no net vertical force. In the interior the two face values are combined with the same Delta z weighting that the centered difference of ChainRule implies; at the bottom and top the single interior face is used.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]klolowest k index of the domain
[in]khihighest k index of the domain
[in]gravmagnitude of gravity
[in]p_arrperturbational pressure
[in]rp_arrperturbational density
[in]z_cc_arrphysical height at cell centers
Returns
dp'/dz + g rho' at (i,j,k)
96 {
97  int km = (k == klo) ? k : k-1;
98  int kp = (k == khi) ? k : k+1;
99  if (kp == km) { return zero; }
100  Real dz_lo = z_cc_arr(i,j,k ) - z_cc_arr(i,j,km);
101  Real dz_hi = z_cc_arr(i,j,kp) - z_cc_arr(i,j,k );
102  Real wtd_rhopert = dz_hi * (rp_arr(i,j,kp) + rp_arr(i,j,k ))
103  + dz_lo * (rp_arr(i,j,k ) + rp_arr(i,j,km));
104  return ( (p_arr(i,j,kp) - p_arr(i,j,km)) + myhalf * grav * wtd_rhopert )
105  / (z_cc_arr(i,j,kp) - z_cc_arr(i,j,km));
106 }

Referenced by compute_gradp_hse().

Here is the caller graph for this function: