ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_TerrainMetrics.H File Reference
#include <AMReX.H>
#include <AMReX_Geometry.H>
#include <AMReX_MultiFab.H>
#include <ERF_IndexDefines.H>
#include <cmath>
#include <ERF_NumericalConstants.H>
Include dependency graph for ERF_TerrainMetrics.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum class  FineTerrain { None , Interpolate , Transform }
 

Functions

void init_default_zphys (int lev, const amrex::Geometry &geom, amrex::MultiFab &z_phys_nd, amrex::MultiFab &z_phys_cc, amrex::Real z_offset=zero)
 
amrex::BoxArray join_boxes_stacked_in_z (const amrex::BoxArray &ba)
 
void init_zlevels (amrex::Vector< amrex::Vector< amrex::Real >> &zlevels_stag, amrex::Vector< amrex::Vector< amrex::Real >> &stretched_dz_h, amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real >> &stretched_dz_d, amrex::Vector< amrex::Geometry > const &geom, amrex::Vector< amrex::IntVect > const &ref_ratio, const amrex::Real grid_stretching_ratio, const amrex::Real dz0)
 
FineTerrain which_fine_terrain ()
 
void make_terrain_fitted_coords (int lev, const amrex::Geometry &geom, amrex::MultiFab &z_phys_nd, amrex::Vector< amrex::Real > const &z_levels_h, amrex::GpuArray< ERF_BC, AMREX_SPACEDIM *2 > &phys_bc_type, FineTerrain fine_terrain=FineTerrain::None, amrex::MultiFab const *z_phys_interp=nullptr, bool moving_mesh=false)
 
void validate_flat_terrain (int lev, const amrex::MultiFab &z_phys_nd, const amrex::Vector< amrex::Real > &z_levels_h)
 
void validate_flat_top (int lev, const amrex::Geometry &geom, const amrex::MultiFab &z_phys_nd)
 
void init_which_terrain_grid (int lev, const amrex::Geometry &geom, amrex::MultiFab &z_phys_nd, amrex::Vector< amrex::Real > const &z_levels_h, FineTerrain fine_terrain=FineTerrain::None, amrex::MultiFab const *z_phys_interp=nullptr)
 
void init_fine_terrain_grid (int lev, const amrex::Geometry &geom, amrex::MultiFab &z_phys_nd, amrex::Vector< amrex::Real > const &z_levels_h, FineTerrain fine_terrain, amrex::MultiFab const *z_phys_interp)
 
amrex::Real get_dzmin_terrain (amrex::MultiFab &z_phys_nd)
 
void update_stretched_dz (int lev, amrex::Vector< amrex::Vector< amrex::Real >> const &zlevels_stag, amrex::Vector< amrex::Vector< amrex::Real >> &stretched_dz_h, amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real >> &stretched_dz_d)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtCellCenter (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtCellCenter (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtCellCenter (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtIface (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtIface (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtIface (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtJface (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtJface (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtJface (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtKface (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtKface (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtKface (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtEdgeCenterK (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtEdgeCenterK (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtEdgeCenterK (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtEdgeCenterJ (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtEdgeCenterJ (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtEdgeCenterJ (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtEdgeCenterI (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtEdgeCenterI (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtEdgeCenterI (const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Z_AtCellCenter (const int &i, const int &j, const int &k, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Z_AtWFace (const int &i, const int &j, const int &k, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Zrel_AtCellCenter (const int &i, const int &j, const int &k, const amrex::Array4< const amrex::Real > &z_sfc_nd, const amrex::Array4< const amrex::Real > &z_nd)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real OmegaFromW (int &i, int &j, int &k, amrex::Real w, const amrex::Array4< const amrex::Real > &u_arr, const amrex::Array4< const amrex::Real > &v_arr, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real WFromOmega (int &i, int &j, int &k, amrex::Real omega, const amrex::Array4< const amrex::Real > &u_arr, const amrex::Array4< const amrex::Real > &v_arr, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void rotate_scalar_flux (const int &i, const int &j, const int &klo, const int &, const amrex::Real &flux, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv, const amrex::Array4< const amrex::Real > &zphys_arr, const amrex::Array4< amrex::Real > &phi1_arr, const amrex::Array4< amrex::Real > &phi2_arr, const amrex::Array4< amrex::Real > &phi3_arr)
 
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void rotate_stress_tensor (const int &i, const int &j, const int &klo, const int &, const amrex::Real &flux, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv, const amrex::Array4< const amrex::Real > &zphys_arr, const amrex::Array4< const amrex::Real > &u_arr, const amrex::Array4< const amrex::Real > &v_arr, const amrex::Array4< const amrex::Real > &w_arr, const amrex::Array4< amrex::Real > &, const amrex::Array4< amrex::Real > &, const amrex::Array4< amrex::Real > &, const amrex::Array4< amrex::Real > &, const amrex::Array4< amrex::Real > &, const amrex::Array4< amrex::Real > &tau13_arr, const amrex::Array4< amrex::Real > &tau31_arr, const amrex::Array4< amrex::Real > &tau23_arr, const amrex::Array4< amrex::Real > &tau32_arr)
 

Enumeration Type Documentation

◆ FineTerrain

enum FineTerrain
strong

How the terrain-fitted mesh on a fine level is built when erf.terrain_smoothing != 0.

The STF and Sullivan TF transformations are not defined on a level that does not reach the top of the domain, so on a fine level we instead start from the mesh interpolated from the coarse level. A caller that has done that interpolation – and, for Transform, has also written the fine-resolution terrain into the k=0 slab and saved the pre-overwrite field – says so by passing anything other than None. Every other caller keeps the historical behavior of aborting, because it has not prepared z_phys_nd in a way this path can use.

Enumerator
None 

caller has not prepared a fine mesh from the coarse level

Interpolate 

use the coordinates interpolated from the coarse level as-is

Transform 

add the fine terrain as a correction that decays with height

66  {
67  None, //!< caller has not prepared a fine mesh from the coarse level
68  Interpolate, //!< use the coordinates interpolated from the coarse level as-is
69  Transform //!< add the fine terrain as a correction that decays with height
70 };
@ Transform
add the fine terrain as a correction that decays with height
@ Interpolate
use the coordinates interpolated from the coarse level as-is
@ None
Definition: ERF_LSM_Types.H:6

Function Documentation

◆ Compute_h_eta_AtCellCenter()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtCellCenter ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the eta metric term at the cell center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Eta metric term.
255 {
256  amrex::Real dyInv = cellSizeInv[1];
257  amrex::Real met_h_eta = fourth * dyInv *
258  ( z_nd(i,j+1,k) + z_nd(i+1,j+1,k) + z_nd(i,j+1,k+1) + z_nd(i+1,j+1,k+1)
259  - z_nd(i,j ,k) - z_nd(i+1,j ,k) - z_nd(i,j ,k+1) - z_nd(i+1,j ,k+1) );
260  return met_h_eta;
261 }
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42

Referenced by Compute_InvDt_Compressible(), ComputeStrain_T(), ComputeStressConsVisc_T(), ComputeStressVarVisc_T(), ERF::FillPlot3DVars(), ERFPhysBCFunct_cons::impose_vertical_cons_bcs(), ERF::poisson_wall_dist(), rotate_scalar_flux(), MOSTAverage::set_norm_indices_T(), and MOSTAverage::set_norm_positions_T().

Here is the caller graph for this function:

◆ Compute_h_eta_AtEdgeCenterI()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtEdgeCenterI ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the eta metric term at the i-edge center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Eta metric term.
696 {
697  amrex::Real dyInv = cellSizeInv[1];
698  amrex::Real met_h_eta = fourth * dyInv *
699  ( z_nd(i+1,j+1,k) + z_nd(i,j+1,k)
700  - z_nd(i+1,j-1,k) - z_nd(i,j-1,k) );
701  return met_h_eta;
702 }

Referenced by ComputeStrain_T(), ComputeStressConsVisc_T(), and ComputeStressVarVisc_T().

Here is the caller graph for this function:

◆ Compute_h_eta_AtEdgeCenterJ()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtEdgeCenterJ ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the eta metric term at the j-edge center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Eta metric term.
624 {
625  amrex::Real dyInv = cellSizeInv[1];
626  amrex::Real met_h_eta = dyInv * ( z_nd(i,j+1,k) - z_nd(i,j,k) );
627  return met_h_eta;
628 }

Referenced by ComputeStressConsVisc_T(), and ComputeStressVarVisc_T().

Here is the caller graph for this function:

◆ Compute_h_eta_AtEdgeCenterK()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtEdgeCenterK ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the eta metric term at the k-edge center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Eta metric term.
548 {
549  amrex::Real dyInv = cellSizeInv[1];
550  amrex::Real met_h_eta = fourth * dyInv *
551  ( z_nd(i,j+1,k) + z_nd(i,j+1,k+1)
552  - z_nd(i,j-1,k) - z_nd(i,j-1,k+1) );
553  return met_h_eta;
554 }

Referenced by ComputeStrain_T().

Here is the caller graph for this function:

◆ Compute_h_eta_AtIface()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtIface ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the eta metric term at the i-face.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Eta metric term.
331 {
332  amrex::Real met_h_eta = myhalf * cellSizeInv[1] * ( (z_nd(i,j+1,k ) - z_nd(i,j,k ))
333  + (z_nd(i,j+1,k+1) - z_nd(i,j,k+1)) );
334  return met_h_eta;
335 }
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41

Referenced by ERFPhysBCFunct_u::impose_vertical_xvel_bcs(), rotate_stress_tensor(), and erf_sbm::erf_detail_SBMTransport::shared_metric_mismatch().

Here is the caller graph for this function:

◆ Compute_h_eta_AtJface()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtJface ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the eta metric term at the j-face.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Eta metric term.
400 {
401  amrex::Real met_h_eta = amrex::Real(0.125) * cellSizeInv[1] *
402  ( (z_nd(i ,j+1,k ) - z_nd(i ,j-1,k )) + (z_nd(i ,j+1,k+1) - z_nd(i ,j-1,k+1)) +
403  (z_nd(i+1,j+1,k ) - z_nd(i+1,j-1,k )) + (z_nd(i+1,j+1,k+1) - z_nd(i+1,j-1,k+1)) );
404  return met_h_eta;
405 }

Referenced by erf_substep_MT(), erf_substep_T(), ERFPhysBCFunct_v::impose_vertical_yvel_bcs(), ERF::poisson_wall_dist(), MOSTAverage::set_rotated_fields(), erf_sbm::erf_detail_SBMTransport::shared_metric_mismatch(), and TerrainScalarDiffusionFluxAtJFace().

Here is the caller graph for this function:

◆ Compute_h_eta_AtKface()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtKface ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the eta metric term at the k-face.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Eta metric term.
471 {
472  amrex::Real met_h_eta = myhalf * cellSizeInv[1] * ( (z_nd(i ,j+1,k) - z_nd(i ,j,k))
473  + (z_nd(i+1,j+1,k) - z_nd(i+1,j,k)) );
474  return met_h_eta;
475 }

Referenced by ERF::ComputeMaxTerrainSlope(), erf_auxiliary::erf_detail_AuxiliaryDiffusion::count_invalid_terrain_metric_reads(), make_fast_coeffs(), ERF::poisson_wall_dist(), SubtractTerrainMetricImplicitPart_T_Impl(), and TerrainScalarDiffusionGzAtKFace().

Here is the caller graph for this function:

◆ Compute_h_xi_AtCellCenter()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtCellCenter ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the xi metric term at the cell center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Xi metric term.
230 {
231  amrex::Real dxInv = cellSizeInv[0];
232  amrex::Real met_h_xi = fourth * dxInv *
233  ( z_nd(i+1,j,k) + z_nd(i+1,j+1,k) + z_nd(i+1,j,k+1) + z_nd(i+1,j+1,k+1)
234  - z_nd(i ,j,k) - z_nd(i ,j+1,k) - z_nd(i ,j,k+1) - z_nd(i ,j+1,k+1) );
235  return met_h_xi;
236 }
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16

Referenced by Compute_InvDt_Compressible(), ComputeStrain_T(), ComputeStressConsVisc_T(), ComputeStressVarVisc_T(), ERF::FillPlot3DVars(), ERFPhysBCFunct_cons::impose_vertical_cons_bcs(), ERF::poisson_wall_dist(), rotate_scalar_flux(), MOSTAverage::set_norm_indices_T(), and MOSTAverage::set_norm_positions_T().

Here is the caller graph for this function:

◆ Compute_h_xi_AtEdgeCenterI()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtEdgeCenterI ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the xi metric term at the i-edge center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Xi metric term.
673 {
674  amrex::Real dxInv = cellSizeInv[0];
675  amrex::Real met_h_xi = dxInv * ( z_nd(i+1,j,k) - z_nd(i,j,k) );
676  return met_h_xi;
677 }

Referenced by ComputeStressConsVisc_T(), and ComputeStressVarVisc_T().

Here is the caller graph for this function:

◆ Compute_h_xi_AtEdgeCenterJ()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtEdgeCenterJ ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the xi metric term at the j-edge center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Xi metric term.
599 {
600  amrex::Real dxInv = cellSizeInv[0];
601  amrex::Real met_h_xi = fourth * dxInv *
602  ( z_nd(i+1,j+1,k) + z_nd(i+1,j ,k)
603  - z_nd(i-1,j+1,k) - z_nd(i-1,j ,k) );
604  return met_h_xi;
605 }

Referenced by ComputeStrain_T(), ComputeStressConsVisc_T(), and ComputeStressVarVisc_T().

Here is the caller graph for this function:

◆ Compute_h_xi_AtEdgeCenterK()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtEdgeCenterK ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the xi metric term at the k-edge center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Xi metric term.
523 {
524  amrex::Real dxInv = cellSizeInv[0];
525  amrex::Real met_h_xi = fourth * dxInv *
526  ( z_nd(i+1,j,k) + z_nd(i+1,j,k+1)
527  - z_nd(i-1,j,k) - z_nd(i-1,j,k+1) );
528  return met_h_xi;
529 }

Referenced by ComputeStrain_T().

Here is the caller graph for this function:

◆ Compute_h_xi_AtIface()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtIface ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the xi metric term at the i-face.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Xi metric term.
307 {
308  amrex::Real met_h_xi = amrex::Real(0.125) * cellSizeInv[0] * (
309  (z_nd(i+1,j ,k ) - z_nd(i-1,j ,k )) + (z_nd(i+1,j ,k+1) - z_nd(i-1,j ,k+1)) +
310  (z_nd(i+1,j+1,k ) - z_nd(i-1,j+1,k )) + (z_nd(i+1,j+1,k+1) - z_nd(i-1,j+1,k+1)) );
311  return met_h_xi;
312 }

Referenced by erf_substep_MT(), erf_substep_T(), ERFPhysBCFunct_u::impose_vertical_xvel_bcs(), ERF::poisson_wall_dist(), rotate_stress_tensor(), MOSTAverage::set_rotated_fields(), erf_sbm::erf_detail_SBMTransport::shared_metric_mismatch(), and TerrainScalarDiffusionFluxAtIFace().

Here is the caller graph for this function:

◆ Compute_h_xi_AtJface()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtJface ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the xi metric term at the j-face.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Xi metric term.
377 {
378  amrex::Real met_h_xi = myhalf * cellSizeInv[0] * ( (z_nd(i+1,j,k ) - z_nd(i,j,k ))
379  + (z_nd(i+1,j,k+1) - z_nd(i,j,k+1)) );
380  return met_h_xi;
381 }

Referenced by ERFPhysBCFunct_v::impose_vertical_yvel_bcs(), and erf_sbm::erf_detail_SBMTransport::shared_metric_mismatch().

Here is the caller graph for this function:

◆ Compute_h_xi_AtKface()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtKface ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the xi metric term at the k-face.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Xi metric term.
448 {
449  amrex::Real met_h_xi = myhalf * cellSizeInv[0] * ( (z_nd(i+1,j ,k) - z_nd(i,j ,k))
450  + (z_nd(i+1,j+1,k) - z_nd(i,j+1,k)) );
451  return met_h_xi;
452 }

Referenced by ERF::ComputeMaxTerrainSlope(), erf_auxiliary::erf_detail_AuxiliaryDiffusion::count_invalid_terrain_metric_reads(), make_fast_coeffs(), ERF::poisson_wall_dist(), SubtractTerrainMetricImplicitPart_T_Impl(), and TerrainScalarDiffusionGzAtKFace().

Here is the caller graph for this function:

◆ Compute_h_zeta_AtCellCenter()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtCellCenter ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the zeta metric term at the cell center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Zeta metric term.
205 {
206  amrex::Real dzInv = cellSizeInv[2];
207  amrex::Real met_h_zeta = fourth * dzInv *
208  ( z_nd(i+1,j,k+1) + z_nd(i+1,j+1,k+1) + z_nd(i,j,k+1) + z_nd(i,j+1,k+1)
209  - z_nd(i+1,j,k ) - z_nd(i+1,j+1,k ) - z_nd(i,j,k ) - z_nd(i,j+1,k ) );
210  return met_h_zeta;
211 }

Referenced by Compute_InvDt_Anelastic(), Compute_InvDt_Compressible(), MOSTAverage::compute_region_averages(), ComputeDiffusivityMRF(), ComputeDiffusivityMYJ(), ComputeDiffusivityMYNN25(), ComputeDiffusivityMYNNEDMF(), ComputeDiffusivityYSU(), ComputeTurbulentViscosityLES(), ComputeTurbulentViscosityRANS(), ERF::estTimeStep(), ERF::FillPlot3DVars(), ERFPhysBCFunct_cons::impose_vertical_cons_bcs(), MOSTAverage::max_k_read(), and ERF::poisson_wall_dist().

Here is the caller graph for this function:

◆ Compute_h_zeta_AtEdgeCenterI()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtEdgeCenterI ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the zeta metric term at the i-edge center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Zeta metric term.
649 {
650  amrex::Real dzInv = cellSizeInv[2];
651  amrex::Real met_h_zeta = fourth * dzInv * ( z_nd(i,j,k+1) + z_nd(i+1,j,k+1)
652  - z_nd(i,j,k-1) - z_nd(i+1,j,k-1) );
653  return met_h_zeta;
654 }

Referenced by AdvectionSrcForMom_TF(), AdvectionSrcForZMom(), ComputeStrain_T(), ComputeStressConsVisc_T(), and ComputeStressVarVisc_T().

Here is the caller graph for this function:

◆ Compute_h_zeta_AtEdgeCenterJ()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtEdgeCenterJ ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the zeta metric term at the j-edge center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Zeta metric term.
575 {
576  amrex::Real dzInv = cellSizeInv[2];
577  amrex::Real met_h_zeta = fourth * dzInv * ( z_nd(i,j,k+1) + z_nd(i,j+1,k+1)
578  - z_nd(i,j,k-1) - z_nd(i,j+1,k-1) );
579  return met_h_zeta;
580 }

Referenced by AdvectionSrcForMom_TF(), AdvectionSrcForZMom(), ComputeStrain_T(), ComputeStressConsVisc_T(), and ComputeStressVarVisc_T().

Here is the caller graph for this function:

◆ Compute_h_zeta_AtEdgeCenterK()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtEdgeCenterK ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the zeta metric term at the k-edge center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Zeta metric term.
500 {
501  amrex::Real dzInv = cellSizeInv[2];
502  amrex::Real met_h_zeta = dzInv * (z_nd(i,j,k+1) - z_nd(i,j,k));
503  return met_h_zeta;
504 }

Referenced by AdvectionSrcForMom_TF(), AdvectionSrcForXMom(), AdvectionSrcForYMom(), ComputeStressConsVisc_T(), and ComputeStressVarVisc_T().

Here is the caller graph for this function:

◆ Compute_h_zeta_AtIface()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtIface ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the zeta metric term at the i-face.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Zeta metric term.
284 {
285  amrex::Real met_h_zeta = myhalf * cellSizeInv[2] * ( (z_nd(i,j ,k+1) - z_nd(i,j ,k))
286  + (z_nd(i,j+1,k+1) - z_nd(i,j+1,k)) );
287  return met_h_zeta;
288 }

Referenced by erf_make_tau_terms(), erf_slow_rhs_pre(), erf_substep_MT(), erf_substep_T(), ERFPhysBCFunct_u::impose_vertical_xvel_bcs(), ERF::poisson_wall_dist(), and rotate_stress_tensor().

Here is the caller graph for this function:

◆ Compute_h_zeta_AtJface()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtJface ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the zeta metric term at the j-face.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Zeta metric term.
354 {
355  amrex::Real met_h_zeta = myhalf * cellSizeInv[2] * ( (z_nd(i ,j,k+1) - z_nd(i ,j,k ))
356  + (z_nd(i+1,j,k+1) - z_nd(i+1,j,k )) );
357  return met_h_zeta;
358 }

Referenced by erf_make_tau_terms(), erf_slow_rhs_pre(), erf_substep_MT(), erf_substep_T(), ERFPhysBCFunct_v::impose_vertical_yvel_bcs(), and ERF::poisson_wall_dist().

Here is the caller graph for this function:

◆ Compute_h_zeta_AtKface()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtKface ( const int &  i,
const int &  j,
const int &  k,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the zeta metric term at the k-face.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]cellSizeInvInverse cell spacing.
[in]z_ndNodal physical height field.
Returns
Zeta metric term.
424 {
425  amrex::Real met_h_zeta = amrex::Real(0.125) * cellSizeInv[2] *
426  ( (z_nd(i ,j ,k+1) - z_nd(i ,j ,k-1)) + (z_nd(i+1,j ,k+1) - z_nd(i+1,j ,k-1)) +
427  (z_nd(i ,j+1,k+1) - z_nd(i ,j+1,k-1)) + (z_nd(i+1,j+1,k+1) - z_nd(i+1,j+1,k-1)) );
428  return met_h_zeta;
429 }

Referenced by erf_auxiliary::erf_detail_AuxiliaryDiffusion::count_invalid_terrain_metric_reads(), ImplicitDiffForStateLU_T(), ImplicitVerticalFluxForReflux_T(), ERF::poisson_wall_dist(), SubtractTerrainMetricImplicitPart_T_Impl(), and TerrainScalarDiffusionFluxAtKFace().

Here is the caller graph for this function:

◆ Compute_Z_AtCellCenter()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Z_AtCellCenter ( const int &  i,
const int &  j,
const int &  k,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the physical height at the cell center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]z_ndNodal physical height field.
Returns
Physical height at cell center.
719 {
720  const amrex::Real z_cc = amrex::Real(0.125)*( z_nd(i ,j ,k) + z_nd(i ,j ,k+1)
721  + z_nd(i+1,j ,k) + z_nd(i+1,j ,k+1)
722  + z_nd(i ,j+1,k) + z_nd(i ,j+1,k+1)
723  + z_nd(i+1,j+1,k) + z_nd(i+1,j+1,k+1));
724 
725  return z_cc;
726 }

Referenced by ERF::convert_legacy_surface_temperature(), sea_level_pressure_diagnostics::fill_sea_level_pressure(), SurfaceLayer::fill_tsurf_with_abs_surf_temp(), SurfaceLayer::fill_tsurf_with_coupled_sst(), SurfaceLayer::fill_tsurf_with_sfc_sst(), SurfaceLayer::fill_tsurf_with_skin_temperature(), SurfaceLayer::fill_tsurf_with_sst_and_tsk(), SurfaceLayer::get_lsm_tsurf(), ERFPhysBCFunct_cons::impose_vertical_cons_bcs(), SurfaceLayer::init_tke_from_ustar(), and plotfile2d::sampled_field_value().

Here is the caller graph for this function:

◆ Compute_Z_AtWFace()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Z_AtWFace ( const int &  i,
const int &  j,
const int &  k,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the physical height at the W-face.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]z_ndNodal physical height field.
Returns
Physical height at W-face.
743 {
744  const amrex::Real z_wf = fourth*( z_nd(i ,j ,k) + z_nd(i+1,j ,k)
745  + z_nd(i ,j+1,k) + z_nd(i+1,j+1,k) );
746 
747  return z_wf;
748 }

Referenced by ERF::convert_legacy_surface_temperature(), ERF::ErrorEst(), sea_level_pressure_diagnostics::fill_sea_level_pressure(), SurfaceLayer::fill_tsurf_with_abs_surf_temp(), SurfaceLayer::fill_tsurf_with_coupled_sst(), SurfaceLayer::fill_tsurf_with_sfc_sst(), SurfaceLayer::fill_tsurf_with_skin_temperature(), SurfaceLayer::fill_tsurf_with_sst_and_tsk(), ERF::FillPlot2DVars(), get_dzmin_terrain(), SurfaceLayer::get_lsm_tsurf(), OmegaFromW(), TerrainScalarDiffusionFluxAtKFace(), and WFromOmega().

Here is the caller graph for this function:

◆ Compute_Zrel_AtCellCenter()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Zrel_AtCellCenter ( const int &  i,
const int &  j,
const int &  k,
const amrex::Array4< const amrex::Real > &  z_sfc_nd,
const amrex::Array4< const amrex::Real > &  z_nd 
)

Compute the relative height above the terrain surface at the cell center.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]z_sfc_ndNodal physical height field of the surface.
[in]z_ndNodal physical height field.
Returns
Relative height at cell center.
767 {
768  const amrex::Real z_cc = amrex::Real(0.125)*( z_nd(i ,j ,k) + z_nd(i ,j ,k+1) +
769  + z_nd(i+1,j ,k) + z_nd(i+1,j ,k+1)
770  + z_nd(i ,j+1,k) + z_nd(i ,j+1,k+1)
771  + z_nd(i+1,j+1,k) + z_nd(i+1,j+1,k+1));
772  const amrex::Real z0_wf = fourth*( z_sfc_nd(i ,j ,0) + z_sfc_nd(i ,j+1,0)
773  + z_sfc_nd(i+1,j ,0) + z_sfc_nd(i+1,j+1,0));
774 
775  return (z_cc - z0_wf);
776 }

Referenced by ComputeDiffusivityMRF(), ComputeDiffusivityMYJ(), ComputeDiffusivityMYNN25(), ComputeDiffusivityMYNNEDMF(), ComputeDiffusivityYSU(), near_surface_diagnostics::fill(), ERF::FillPlot2DVars(), SLM::Init(), SLM::initialize_zrefxy(), Radiation::mf_to_kokkos_buffers(), Radiation::populateDatalogMF(), RadiationSimple::Run(), plotfile2d::sampled_field_value(), and NOAHMP::stage_forcing().

Here is the caller graph for this function:

◆ get_dzmin_terrain()

amrex::Real get_dzmin_terrain ( amrex::MultiFab &  z_phys_nd)

Compute the minimum vertical spacing with terrain.

Parameters
[in]z_phys_ndNodal physical height field.
Returns
Minimum vertical grid spacing.

◆ init_default_zphys()

void init_default_zphys ( int  lev,
const amrex::Geometry &  geom,
amrex::MultiFab &  z_phys_nd,
amrex::MultiFab &  z_phys_cc,
amrex::Real  z_offset = zero 
)

Routine to define default z_phys_nd and z_phys_cc

◆ init_fine_terrain_grid()

void init_fine_terrain_grid ( int  lev,
const amrex::Geometry &  geom,
amrex::MultiFab &  z_phys_nd,
amrex::Vector< amrex::Real > const &  z_levels_h,
FineTerrain  fine_terrain,
amrex::MultiFab const *  z_phys_interp 
)

Finish the terrain-fitted mesh on a fine level whose interior was set by interpolation from the coarse level (erf.terrain_smoothing != 0).

For FineTerrain::Transform this adds the fine-resolution terrain as a correction that decays linearly to zero at the top of the fine grids. For both modes it then fills the nodes outside the lateral domain boundary and the layer below the surface, which init_which_terrain_grid()'s BTF branch would otherwise have filled.

Parameters
[in]levLevel index.
[in]geomGeometry information.
[in,out]z_phys_ndNodal physical height field.
[in]z_levels_hHost z-levels.
[in]fine_terrainInterpolate or Transform.
[in]z_phys_interpMesh interpolated from the coarse level; see above.

◆ init_which_terrain_grid()

void init_which_terrain_grid ( int  lev,
const amrex::Geometry &  geom,
amrex::MultiFab &  z_phys_nd,
amrex::Vector< amrex::Real > const &  z_levels_h,
FineTerrain  fine_terrain = FineTerrain::None,
amrex::MultiFab const *  z_phys_interp = nullptr 
)

Initialize the terrain grid mapping.

Parameters
[in]levLevel index.
[in]geomGeometry information.
[out]z_phys_ndNodal physical height field.
[in]z_levels_hHost z-levels.
[in]fine_terrainHow a fine level with terrain_smoothing != 0 is to be built.
[in]z_phys_interpMesh interpolated from the coarse level; see above.

◆ init_zlevels()

void init_zlevels ( amrex::Vector< amrex::Vector< amrex::Real >> &  zlevels_stag,
amrex::Vector< amrex::Vector< amrex::Real >> &  stretched_dz_h,
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real >> &  stretched_dz_d,
amrex::Vector< amrex::Geometry > const &  geom,
amrex::Vector< amrex::IntVect > const &  ref_ratio,
const amrex::Real  grid_stretching_ratio,
const amrex::Real  dz0 
)

Utility routines for constructing terrain metric terms Initialize staggered z-levels and stretched vertical spacing.

Parameters
[out]zlevels_stagStaggered z-levels.
[out]stretched_dz_hHost stretched vertical spacing.
[out]stretched_dz_dDevice stretched vertical spacing.
[in]geomGeometry information.
[in]ref_ratioRefinement ratios.
[in]grid_stretching_ratioRatio for grid stretching; zero with a positive dz0 solves for the ratio that closes on the domain top.
[in]dz0Initial vertical spacing.

◆ join_boxes_stacked_in_z()

amrex::BoxArray join_boxes_stacked_in_z ( const amrex::BoxArray &  ba)

The cells of a (cell-centered) BoxArray as boxes that are never stacked on each other: wherever a box sits on the top face of another, the run of cells in z that the two belong to becomes a single box. Returns ba itself when no two boxes of ba are stacked.

Parameters
[in]bacell-centered BoxArray

◆ make_terrain_fitted_coords()

void make_terrain_fitted_coords ( int  lev,
const amrex::Geometry &  geom,
amrex::MultiFab &  z_phys_nd,
amrex::Vector< amrex::Real > const &  z_levels_h,
amrex::GpuArray< ERF_BC, AMREX_SPACEDIM *2 > &  phys_bc_type,
FineTerrain  fine_terrain = FineTerrain::None,
amrex::MultiFab const *  z_phys_interp = nullptr,
bool  moving_mesh = false 
)

Construct terrain-fitted coordinates.

Parameters
[in]levLevel index.
[in]geomGeometry information.
[out]z_phys_ndNodal physical height field.
[in]z_levels_hHost z-levels.
[in]phys_bc_typePhysical boundary condition types.
[in]fine_terrainHow a fine level with terrain_smoothing != 0 is to be built.
[in]z_phys_interpMesh interpolated from the coarse level before the fine terrain was written into the k=0 slab; required by, and only used for, FineTerrain::Transform.

◆ OmegaFromW()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real OmegaFromW ( int &  i,
int &  j,
int &  k,
amrex::Real  w,
const amrex::Array4< const amrex::Real > &  u_arr,
const amrex::Array4< const amrex::Real > &  v_arr,
const amrex::Array4< const amrex::Real > &  mf_ux,
const amrex::Array4< const amrex::Real > &  mf_vy,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  dxInv 
)

Compute the contravariant vertical velocity omega from w.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]wVertical velocity.
[in]u_arrX-velocity array.
[in]v_arrY-velocity array.
[in]mf_uxMap factor m_x at x-faces (u points).
[in]mf_vyMap factor m_y at y-faces (v points).
[in]z_ndNodal physical height field.
[in]dxInvInverse cell spacing.
Returns
Contravariant vertical velocity.
809 {
810  // This is dh/dxi at hi and lo edges
811  amrex::Real z_x_p2 = Compute_Z_AtWFace(i+2,j,k,z_nd);
812  amrex::Real z_x_p1 = Compute_Z_AtWFace(i+1,j,k,z_nd);
813  amrex::Real z_x_m1 = Compute_Z_AtWFace(i-1,j,k,z_nd);
814  amrex::Real z_x_m2 = Compute_Z_AtWFace(i-2,j,k,z_nd);
815  amrex::Real met_xi = (amrex::Real(1.0/amrex::Real(12.0))*(z_x_m2 - z_x_p2)
816  + amrex::Real(8.0/amrex::Real(12.0))*(z_x_p1 - z_x_m1)) * dxInv[0];
817 
818  // This is dh/deta at hi and lo edges
819  amrex::Real z_y_p2 = Compute_Z_AtWFace(i,j+2,k,z_nd);
820  amrex::Real z_y_p1 = Compute_Z_AtWFace(i,j+1,k,z_nd);
821  amrex::Real z_y_m1 = Compute_Z_AtWFace(i,j-1,k,z_nd);
822  amrex::Real z_y_m2 = Compute_Z_AtWFace(i,j-2,k,z_nd);
823  amrex::Real met_eta = (amrex::Real(1.0/amrex::Real(12.0))*(z_y_m2 - z_y_p2)
824  + amrex::Real(8.0/amrex::Real(12.0))*(z_y_p1 - z_y_m1)) * dxInv[1];
825 
826  // Use extrapolation instead of interpolation if at the bottom boundary
827  amrex::Real u_hi = (k == 0) ? amrex::Real(1.5) * u_arr(i+1,j ,k ) - myhalf * u_arr(i+1,j ,k+1) :
828  myhalf * ( u_arr(i+1,j ,k-1) + u_arr(i+1,j ,k ) );
829  amrex::Real u_lo = (k == 0) ? amrex::Real(1.5) * u_arr(i ,j ,k ) - myhalf * u_arr(i ,j ,k+1) :
830  myhalf * ( u_arr(i ,j ,k-1) + u_arr(i ,j ,k ) );
831  amrex::Real mf_ux_hi = mf_ux(i+1,j,0);
832  amrex::Real mf_ux_lo = mf_ux(i ,j,0);
833 
834  amrex::Real v_hi = (k == 0) ? amrex::Real(1.5) * v_arr(i ,j+1,k ) - myhalf * v_arr(i ,j+1,k+1) :
835  myhalf * ( v_arr(i ,j+1,k-1) + v_arr(i ,j+1,k ) );
836  amrex::Real v_lo = (k == 0) ? amrex::Real(1.5) * v_arr(i ,j ,k ) - myhalf * v_arr(i ,j ,k+1) :
837  myhalf * ( v_arr(i ,j ,k-1) + v_arr(i ,j ,k ) );
838  amrex::Real mf_vy_hi = mf_vy(i,j+1,0);
839  amrex::Real mf_vy_lo = mf_vy(i,j ,0);
840 
841  amrex::Real u_met = met_xi * myhalf * ( u_hi*mf_ux_hi + u_lo*mf_ux_lo );
842  amrex::Real v_met = met_eta * myhalf * ( v_hi*mf_vy_hi + v_lo*mf_vy_lo );
843 
844  amrex::Real omega = w - u_met - v_met;
845  return omega;
846 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Z_AtWFace(const int &i, const int &j, const int &k, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:741
@ omega
Definition: ERF_Morrison.H:57

Referenced by ERF::average_down_mass_flux(), ERF::cf_zface_coarse_at(), ERF::compute_tag_field(), erf_make_tau_terms(), erf_slow_rhs_pre(), erf_substep_MT(), erf_substep_T(), ERF::estTimeStep(), ERF::FillPlot3DVars(), and ERF::project_momenta().

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

◆ rotate_scalar_flux()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE void rotate_scalar_flux ( const int &  i,
const int &  j,
const int &  klo,
const int &  ,
const amrex::Real &  flux,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  dxInv,
const amrex::Array4< const amrex::Real > &  zphys_arr,
const amrex::Array4< amrex::Real > &  phi1_arr,
const amrex::Array4< amrex::Real > &  phi2_arr,
const amrex::Array4< amrex::Real > &  phi3_arr 
)

Rotate a scalar flux vector into terrain-following coordinates.

Parameters
[in]ix-index
[in]jy-index
[in]kloz-index
[in]fluxScalar flux value.
[in]dxInvInverse cell spacing.
[in]zphys_arrPhysical height field.
[out]phi1_arrRotated flux component 1.
[out]phi2_arrRotated flux component 2.
[out]phi3_arrRotated flux component 3.
1067 {
1068  amrex::Real h_xi = Compute_h_xi_AtCellCenter(i, j, klo, dxInv, zphys_arr);
1069  amrex::Real h_eta = Compute_h_eta_AtCellCenter(i, j, klo, dxInv, zphys_arr);
1070  amrex::Real InvNorm = one / std::sqrt(one + h_xi*h_xi + h_eta*h_eta);
1071  phi1_arr(i,j,klo) = -h_xi * flux * InvNorm;
1072  phi2_arr(i,j,klo) = -h_eta * flux * InvNorm;
1073  phi3_arr(i,j,klo) = flux * InvNorm;
1074 }
const int klo
Definition: ERF_InitCustomPert_KE.H:9
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtCellCenter(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:227
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtCellCenter(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:252

Referenced by SurfaceLayer::compute_SurfaceLayer_bcs().

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

◆ rotate_stress_tensor()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE void rotate_stress_tensor ( const int &  i,
const int &  j,
const int &  klo,
const int &  ,
const amrex::Real &  flux,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  dxInv,
const amrex::Array4< const amrex::Real > &  zphys_arr,
const amrex::Array4< const amrex::Real > &  u_arr,
const amrex::Array4< const amrex::Real > &  v_arr,
const amrex::Array4< const amrex::Real > &  w_arr,
const amrex::Array4< amrex::Real > &  ,
const amrex::Array4< amrex::Real > &  ,
const amrex::Array4< amrex::Real > &  ,
const amrex::Array4< amrex::Real > &  ,
const amrex::Array4< amrex::Real > &  ,
const amrex::Array4< amrex::Real > &  tau13_arr,
const amrex::Array4< amrex::Real > &  tau31_arr,
const amrex::Array4< amrex::Real > &  tau23_arr,
const amrex::Array4< amrex::Real > &  tau32_arr 
)

Rotate the stress tensor for the MOST model.

Parameters
[in]ix-index
[in]jy-index
[in]kloz-index
[in]fluxFlux value used for rotation.
[in]dxInvInverse cell spacing.
[in]zphys_arrPhysical height field.
[in]u_arrX-velocity array.
[in]v_arrY-velocity array.
[in]w_arrZ-velocity array.
[out]tau11_arrStress component tau11.
[out]tau22_arrStress component tau22.
[out]tau33_arrStress component tau33.
[out]tau12_arrStress component tau12.
[out]tau21_arrStress component tau21.
[out]tau13_arrStress component tau13.
[out]tau31_arrStress component tau31.
[out]tau23_arrStress component tau23.
[out]tau32_arrStress component tau32.
1120 {
1121  // Unit-normal vector
1122  amrex::Array1D<amrex::Real,0,2> n_hat;
1123 
1124  // Unit-tangent vectors
1125  amrex::Array1D<amrex::Real,0,2> u_t_hat;
1126 
1127  // Final basis vector for right-hand coord sys
1128  amrex::Array1D<amrex::Real,0,2> a_hat;
1129 
1130  // Rotation matrix
1131  amrex::Array2D<amrex::Real,0,2,0,2> R_mat;
1132 
1133  // Metric data
1134  amrex::Real h_xi = Compute_h_xi_AtIface(i, j, klo, dxInv, zphys_arr);
1135  amrex::Real h_eta = Compute_h_eta_AtIface(i, j, klo, dxInv, zphys_arr);
1136  amrex::Real h_zeta = Compute_h_zeta_AtIface(i, j, klo, dxInv, zphys_arr);
1137 
1138  // Populate the inward normal vector
1139  amrex::Real Inormn = one/std::sqrt(one + h_xi*h_xi + h_eta*h_eta);
1140  n_hat(0) = -Inormn*h_xi; n_hat(1) = -Inormn*h_eta; n_hat(2) = Inormn;
1141 
1142  // Populate the u_t vector (u_t = u - (u \cdot n)n)
1143  amrex::Real u = u_arr(i,j,klo);
1144  amrex::Real v = fourth * ( v_arr(i ,j,klo) + v_arr(i ,j+1,klo)
1145  + v_arr(i-1,j,klo) + v_arr(i-1,j+1,klo) );
1146  amrex::Real w = myhalf * ( w_arr(i ,j,klo) + w_arr(i-1,j ,klo) );
1147  amrex::Real u_dot_n = n_hat(0)*u + n_hat(1)*v + n_hat(2)*w;
1148  u_t_hat(0) = u - u_dot_n*n_hat(0);
1149  u_t_hat(1) = v - u_dot_n*n_hat(1);
1150  u_t_hat(2) = w - u_dot_n*n_hat(2);
1151  amrex::Real Norm_u_t = u_t_hat(0)*u_t_hat(0)
1152  + u_t_hat(1)*u_t_hat(1)
1153  + u_t_hat(2)*u_t_hat(2);
1154 
1155  // NOTE: the direction of the tangential velocity is undefined when that
1156  // velocity vanishes (a quiescent surface cell, or flow normal to the
1157  // terrain), so we cannot normalize. Leaving u_t_hat as the zero vector
1158  // is the only rotation-invariant choice, and it is the right limit for
1159  // a quiescent cell since the flux vanishes with the surface wind too.
1160  amrex::Real Inorm_u_t = (Norm_u_t > zero) ? one/std::sqrt(Norm_u_t) : zero;
1161  for (int icol(0); icol<3; ++icol) {
1162  u_t_hat(icol) *= Inorm_u_t;
1163  }
1164 
1165  // Populate the a_hat = n_hat X u_t_hat vector
1166  a_hat(0) = n_hat(1)*u_t_hat(2) - n_hat(2)*u_t_hat(1);
1167  a_hat(1) = -(n_hat(0)*u_t_hat(2) - n_hat(2)*u_t_hat(0));
1168  a_hat(2) = n_hat(0)*u_t_hat(1) - n_hat(1)*u_t_hat(0);
1169 
1170  // Copy column vectors into R_mat
1171  // NOTE: basis vectors form rows of R_mat
1172  int icol = 0;
1173  for (int jrow(0); jrow<3; ++jrow) {
1174  R_mat(icol,jrow) = u_t_hat(jrow);
1175  }
1176  icol = 1;
1177  for (int jrow(0); jrow<3; ++jrow) {
1178  R_mat(icol,jrow) = a_hat(jrow);
1179  }
1180  icol = 2;
1181  for (int jrow(0); jrow<3; ++jrow) {
1182  R_mat(icol,jrow) = n_hat(jrow);
1183  }
1184 
1185  // Body-fixed stresses
1186  amrex::Real T11 = two*R_mat(0,0)*R_mat(2,0)*flux;
1187  amrex::Real T22 = two*R_mat(0,1)*R_mat(2,1)*flux;
1188  //amrex::Real T33 = two*R_mat(0,2)*R_mat(2,2)*flux;
1189  amrex::Real T12 = (R_mat(0,0)*R_mat(2,1) + R_mat(2,0)*R_mat(0,1))*flux;
1190  amrex::Real T13 = (R_mat(0,0)*R_mat(2,2) + R_mat(0,2)*R_mat(2,0))*flux;
1191  amrex::Real T23 = (R_mat(0,2)*R_mat(2,1) + R_mat(0,1)*R_mat(2,2))*flux;
1192 
1193  // Populate the stress tensor (apply JT)
1194  // NOTE: We cannot set the stresses that do not live at the
1195  // bottom face --- e.g., tau11/22/33/12/21.
1196  tau13_arr(i,j,klo) = -h_xi*T11 - h_eta*T12 + T13;
1197  tau31_arr(i,j,klo) = h_zeta*T13;
1198 
1199  tau23_arr(i,j,klo) = -h_xi*T12 - h_eta*T22 + T23;
1200  tau32_arr(i,j,klo) = h_zeta*T23;
1201 }
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtIface(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:281
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_AtIface(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:328
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_AtIface(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:304

Referenced by SurfaceLayer::compute_SurfaceLayer_bcs().

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

◆ update_stretched_dz()

void update_stretched_dz ( int  lev,
amrex::Vector< amrex::Vector< amrex::Real >> const &  zlevels_stag,
amrex::Vector< amrex::Vector< amrex::Real >> &  stretched_dz_h,
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real >> &  stretched_dz_d 
)

Re-derive the stretched vertical spacing at one level from the nominal z-levels.

init_zlevels() fills both zlevels_stag and stretched_dz_* together, but zlevels_stag can be replaced after construction (init_from_wrfinput() does this when erf.avg_grid_faces_to_nodes = false, and restart reads it back from the checkpoint). Call this whenever zlevels_stag[lev] changes so that the cell heights never drift out of sync with the levels they are supposed to describe.

Parameters
[in]levLevel index.
[in]zlevels_stagStaggered z-levels (the source of truth).
[out]stretched_dz_hHost stretched vertical spacing.
[out]stretched_dz_dDevice stretched vertical spacing.

◆ validate_flat_terrain()

void validate_flat_terrain ( int  lev,
const amrex::MultiFab &  z_phys_nd,
const amrex::Vector< amrex::Real > &  z_levels_h 
)

Verify that a fitted mesh is horizontally flat and follows z_levels_h.

◆ validate_flat_top()

void validate_flat_top ( int  lev,
const amrex::Geometry &  geom,
const amrex::MultiFab &  z_phys_nd 
)

Abort unless z_phys_nd is the same at every node of the top of the domain.

◆ WFromOmega()

AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real WFromOmega ( int &  i,
int &  j,
int &  k,
amrex::Real  omega,
const amrex::Array4< const amrex::Real > &  u_arr,
const amrex::Array4< const amrex::Real > &  v_arr,
const amrex::Array4< const amrex::Real > &  mf_ux,
const amrex::Array4< const amrex::Real > &  mf_vy,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  dxInv 
)

Compute the vertical velocity w from the contravariant omega.

Parameters
[in]ix-index
[in]jy-index
[in]kz-index
[in]omegaContravariant vertical velocity.
[in]u_arrX-velocity array.
[in]v_arrY-velocity array.
[in]mf_uxMap factor m_x at x-faces (u points).
[in]mf_vyMap factor m_y at y-faces (v points).
[in]z_ndNodal physical height field.
[in]dxInvInverse cell spacing.
Returns
Vertical velocity w.
874 {
875  // This is dh/dxi at hi and lo edges
876  amrex::Real z_x_p2 = Compute_Z_AtWFace(i+2,j,k,z_nd);
877  amrex::Real z_x_p1 = Compute_Z_AtWFace(i+1,j,k,z_nd);
878  amrex::Real z_x_m1 = Compute_Z_AtWFace(i-1,j,k,z_nd);
879  amrex::Real z_x_m2 = Compute_Z_AtWFace(i-2,j,k,z_nd);
880  amrex::Real met_xi = (amrex::Real(1.0/amrex::Real(12.0))*(z_x_m2 - z_x_p2)
881  + amrex::Real(8.0/amrex::Real(12.0))*(z_x_p1 - z_x_m1)) * dxInv[0];
882 
883  // This is dh/deta at hi and lo edges
884  amrex::Real z_y_p2 = Compute_Z_AtWFace(i,j+2,k,z_nd);
885  amrex::Real z_y_p1 = Compute_Z_AtWFace(i,j+1,k,z_nd);
886  amrex::Real z_y_m1 = Compute_Z_AtWFace(i,j-1,k,z_nd);
887  amrex::Real z_y_m2 = Compute_Z_AtWFace(i,j-2,k,z_nd);
888  amrex::Real met_eta = (amrex::Real(1.0/amrex::Real(12.0))*(z_y_m2 - z_y_p2)
889  + amrex::Real(8.0/amrex::Real(12.0))*(z_y_p1 - z_y_m1)) * dxInv[1];
890 
891  // Use extrapolation instead of interpolation if at the bottom boundary
892  amrex::Real u_hi = (k == 0) ? amrex::Real(1.5) * u_arr(i+1,j ,k ) - myhalf * u_arr(i+1,j ,k+1) :
893  myhalf * ( u_arr(i+1,j ,k-1) + u_arr(i+1,j ,k ) );
894  amrex::Real u_lo = (k == 0) ? amrex::Real(1.5) * u_arr(i ,j ,k ) - myhalf * u_arr(i ,j ,k+1) :
895  myhalf * ( u_arr(i ,j ,k-1) + u_arr(i ,j ,k ) );
896  amrex::Real mf_ux_hi = mf_ux(i+1,j,0);
897  amrex::Real mf_ux_lo = mf_ux(i ,j,0);
898 
899  amrex::Real v_hi = (k == 0) ? amrex::Real(1.5) * v_arr(i ,j+1,k ) - myhalf * v_arr(i ,j+1,k+1) :
900  myhalf * ( v_arr(i ,j+1,k-1) + v_arr(i ,j+1,k ) );
901  amrex::Real v_lo = (k == 0) ? amrex::Real(1.5) * v_arr(i ,j ,k ) - myhalf * v_arr(i ,j ,k+1) :
902  myhalf * ( v_arr(i ,j ,k-1) + v_arr(i ,j ,k ) );
903  amrex::Real mf_vy_hi = mf_vy(i,j+1,0);
904  amrex::Real mf_vy_lo = mf_vy(i,j ,0);
905 
906  amrex::Real u_met = met_xi * myhalf * ( u_hi*mf_ux_hi + u_lo*mf_ux_lo );
907  amrex::Real v_met = met_eta * myhalf * ( v_hi*mf_vy_hi + v_lo*mf_vy_lo );
908 
909  amrex::Real w = omega + u_met + v_met;
910  return w;
911 }

Referenced by ERF::average_down_mass_flux(), erf_substep_MT(), ERF::FillSetMomentaCF(), if(), ERFPhysBCFunct_w::impose_lateral_zvel_bcs(), ERFPhysBCFunct_w::impose_vertical_zvel_bcs(), ParallelFor(), and ERF::project_momenta().

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

◆ which_fine_terrain()

FineTerrain which_fine_terrain ( )

Read erf.amr_terrain_refinement and translate it into a FineTerrain.

Aborts on any value other than "interpolate" or "transform" so that a typo cannot silently select a path that leaves the fine mesh untransformed.

Translate erf.amr_terrain_refinement into a FineTerrain.

547 {
548  ParmParse pp("erf");
549  std::string amr_terrain_refinement = "interpolate";
550  pp.query("amr_terrain_refinement", amr_terrain_refinement);
551 
552  if (amr_terrain_refinement == "interpolate") {
554  } else if (amr_terrain_refinement == "transform") {
555  return FineTerrain::Transform;
556  }
557 
558  Abort("erf.amr_terrain_refinement = " + amr_terrain_refinement +
559  " is not recognized; it must be \"interpolate\" or \"transform\"");
561 }
ParmParse pp("prob")

Referenced by ERF::build_zphys_nd().

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