ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ScalarDiffusion.H File Reference
#include <type_traits>
#include "AMReX_BCRec.H"
#include "AMReX_Box.H"
#include "AMReX_FArrayBox.H"
#include "AMReX_Gpu.H"
#include "ERF_DiffStruct.H"
#include "ERF_NumericalConstants.H"
#include "ERF_TerrainMetrics.H"
#include "ERF_TerrainImplicitMetric.H"
Include dependency graph for ERF_ScalarDiffusion.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ScalarDiffusionCoefficients
 
struct  ScalarDiffusionFieldViews
 
struct  ScalarDiffusionCoefficientMode
 
struct  ScalarDiffusionPrescribedFluxes
 
struct  ScalarDiffusionRawFluxDiagnostic
 
struct  ScalarDiffusionSurfaceFaces
 
struct  ScalarDiffusionFluxPolicy
 
struct  StretchedDiffusionBoundaryWeights
 

Typedefs

using ScalarDiffusionRefluxViews = amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM >
 

Functions

template<bool MultiplyMolecularByDensity, bool AddTurbulence>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFaceCoefficient (const amrex::Array4< const amrex::Real > &rho, const int rho_comp, const amrex::Array4< const amrex::Real > &mu_turb, const ScalarDiffusionCoefficients &coefficients, const int i, const int j, const int k, const int di, const int dj, const int dk, const int eddy_comp) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE StretchedDiffusionBoundaryWeights StretchedDiffusionDirichletWeights (const amrex::Real dz_near, const amrex::Real dz_next) noexcept
 
template<int Direction>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ScalarDiffusionLateralExtDir (const amrex::BCRec &bc, const amrex::Array4< const amrex::Real > &vel, const int i, const int j, const int k, const amrex::Dim3 &dom_lo, const amrex::Dim3 &dom_hi, bool &ext_lo, bool &ext_hi) noexcept
 
template<int Direction>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionHorizontalDelta (const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const int i, const int j, const int k, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
 
template<int Direction>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_N (const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const int i, const int j, const int k, const amrex::Real coeff, const amrex::Real inv_spacing, const amrex::Real map_numerator, const amrex::Real map_denominator, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real StretchedScalarGradient (const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const int i, const int j, const int k, const amrex::Real *dz, const int klo, const int khi, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
 
template<int Direction>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_S_Horizontal (const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const int i, const int j, const int k, const amrex::Real coeff, const amrex::Real inv_spacing, const amrex::Real face_map, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_Tx (const amrex::Real coeff, const amrex::Real face_map, const amrex::Real grad_xi, const amrex::Real h_xi, const amrex::Real grad_z) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_Ty (const amrex::Real coeff, const amrex::Real face_map, const amrex::Real grad_eta, const amrex::Real h_eta, const amrex::Real grad_z) noexcept
 
template<int Direction>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainFaceHeightSpacingInv (const amrex::Array4< const amrex::Real > &z_nd, const int i, const int j, const int k) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionFluxAtIFace (const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::Real coeff, const int i, const int j, const int k, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_ux, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionFluxAtJFace (const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::Real coeff, const int i, const int j, const int k, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_vy, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionFluxAtKFace (const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::Real coeff, const int i, const int j, const int kface, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionGz (const amrex::Real raw_Fz, const amrex::Real mx, const amrex::Real h_xi, const amrex::Real Fbar_x, const amrex::Real my, const amrex::Real h_eta, const amrex::Real Fbar_y) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionMappedTx (const amrex::Real raw_Fx, const amrex::Real h_zeta, const amrex::Real my) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionMappedTy (const amrex::Real raw_Fy, const amrex::Real h_zeta, const amrex::Real mx) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionMappedHorizontalTransfer (const amrex::Real raw_flux, const amrex::Real face_area) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionMappedVerticalTransfer (const amrex::Real raw_flux, const amrex::Real mx, const amrex::Real my) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionGzAtKFace (const int i, const int j, const int kface, const amrex::Box &domain, const amrex::Array4< const amrex::Real > &raw_xflux, const amrex::Array4< const amrex::Real > &raw_yflux, const amrex::Array4< const amrex::Real > &raw_zflux, const int flux_comp, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionMappedTransferAtKFace (const int i, const int j, const int kface, const amrex::Box &domain, const amrex::Array4< const amrex::Real > &raw_xflux, const amrex::Array4< const amrex::Real > &raw_yflux, const amrex::Array4< const amrex::Real > &raw_zflux, const int flux_comp, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const bool suppress_transfer=false) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionMappedFluxDivergence (const amrex::Real fx_hi, const amrex::Real fx_lo, const amrex::Real fy_hi, const amrex::Real fy_lo, const amrex::Real fz_hi, const amrex::Real fz_lo, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real dzeta_inv, const amrex::Real mx, const amrex::Real my, const amrex::Real detJ_cell) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionDivergence_T (const amrex::Real mapped_Fx_hi, const amrex::Real mapped_Fx_lo, const amrex::Real mapped_Fy_hi, const amrex::Real mapped_Fy_lo, const amrex::Real Gz_hi, const amrex::Real Gz_lo, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real dz_inv, const amrex::Real mfsq, const amrex::Real detJ_cell) noexcept
 
template<bool MultiplyMolecularByDensity, bool AddTurbulence>
void BuildScalarDiffusionFluxes_N_Impl (const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
 
void BuildScalarDiffusionFluxes_N (const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
 
template<bool MultiplyMolecularByDensity, bool AddTurbulence>
void BuildScalarDiffusionFluxes_S_Impl (const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real *dz, const int klo, const int khi, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
 
void BuildScalarDiffusionFluxes_S (const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real *dz, const int klo, const int khi, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
 
template<bool MultiplyMolecularByDensity, bool AddTurbulence>
void BuildScalarDiffusionFluxes_T_Impl (const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const ScalarDiffusionCoefficients &vertical_coefficients, const bool rotate, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
 
void BuildScalarDiffusionFluxes_T (const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const ScalarDiffusionCoefficients &vertical_coefficients, const bool rotate, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
 
void BuildScalarDiffusionFluxes_T (const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const bool rotate, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
 
void BuildScalarDiffusionMappedTransfers_N (const amrex::Box &bx, const amrex::Array4< const amrex::Real > &raw_x, const int raw_x_comp, const amrex::Array4< const amrex::Real > &raw_y, const int raw_y_comp, const amrex::Array4< const amrex::Real > &raw_z, const int raw_z_comp, const amrex::Array4< amrex::Real > &mapped_x, const int mapped_x_comp, const amrex::Array4< amrex::Real > &mapped_y, const int mapped_y_comp, const amrex::Array4< amrex::Real > &mapped_z, const int mapped_z_comp, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my)
 
void BuildScalarDiffusionMappedTransfers_S (const amrex::Box &bx, const amrex::Array4< const amrex::Real > &raw_x, const int raw_x_comp, const amrex::Array4< const amrex::Real > &raw_y, const int raw_y_comp, const amrex::Array4< const amrex::Real > &raw_z, const int raw_z_comp, const amrex::Array4< amrex::Real > &mapped_x, const int mapped_x_comp, const amrex::Array4< amrex::Real > &mapped_y, const int mapped_y_comp, const amrex::Array4< amrex::Real > &mapped_z, const int mapped_z_comp, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my)
 
void BuildScalarDiffusionMappedTransfers_T (const amrex::Box &bx, const amrex::Box &domain, const amrex::Array4< const amrex::Real > &raw_x, const amrex::Array4< const amrex::Real > &raw_y, const amrex::Array4< const amrex::Real > &raw_z, const int raw_flux_comp, const amrex::Array4< amrex::Real > &mapped_x, const int mapped_x_comp, const amrex::Array4< amrex::Real > &mapped_y, const int mapped_y_comp, const amrex::Array4< amrex::Real > &mapped_z, const int mapped_z_comp, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_vx, const bool suppress_lower_surface_z_transfer, const bool suppress_upper_z_transfer=false)
 
void ApplyScalarMappedFluxDivergence (const amrex::Box &bx, const amrex::Array4< const amrex::Real > &mapped_x, const int mapped_x_comp, const amrex::Array4< const amrex::Real > &mapped_y, const int mapped_y_comp, const amrex::Array4< const amrex::Real > &mapped_z, const int mapped_z_comp, const amrex::Array4< amrex::Real > &rhs, const int rhs_comp, const amrex::Array4< const amrex::Real > &detJ, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my)
 
void ApplyScalarDiffusionMappedDivergence_T (const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::Array4< const amrex::Real > &detJ, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_vx, const bool suppress_lower_z_flux, const bool suppress_upper_z_flux)
 
void ApplyScalarDiffusionFluxDivergence_N (const amrex::Box &bx, const amrex::Array4< const amrex::Real > &xflux, const amrex::Array4< const amrex::Real > &yflux, const amrex::Array4< const amrex::Real > &raw_Fz, const int flux_comp, const amrex::Array4< amrex::Real > &rhs, const int rhs_comp, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my)
 
void ApplyScalarDiffusionFluxDivergence_S (const amrex::Box &bx, const amrex::Array4< const amrex::Real > &xflux, const amrex::Array4< const amrex::Real > &yflux, const amrex::Array4< const amrex::Real > &raw_Fz, const int flux_comp, const amrex::Array4< amrex::Real > &rhs, const int rhs_comp, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real *dz)
 
template<bool MultiplyMolecularByDensity, bool AddTurbulence>
void SubtractTerrainMetricImplicitPart_T_Impl (const amrex::Box &zbx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionCoefficients &coefficients, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Real implicit_fac)
 
void SubtractTerrainMetricImplicitPart_T (const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Real implicit_fac)
 
void ScaleScalarDiffusionVerticalFlux (const amrex::Box &zbx, const amrex::Array4< amrex::Real > &raw_Fz, const int flux_comp, const amrex::Real explicit_fac)
 
void AddScalarDiffusionRefluxFluxes_N (const amrex::Box &bx, const amrex::Array4< const amrex::Real > &xflux, const amrex::Array4< const amrex::Real > &yflux, const amrex::Array4< const amrex::Real > &zflux, const int flux_comp, const ScalarDiffusionRefluxViews &reflux, const int state_comp, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my)
 
void AddScalarDiffusionRefluxFluxes_S (const amrex::Box &bx, const amrex::Array4< const amrex::Real > &xflux, const amrex::Array4< const amrex::Real > &yflux, const amrex::Array4< const amrex::Real > &zflux, const int flux_comp, const ScalarDiffusionRefluxViews &reflux, const int state_comp, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Real *dz, const amrex::Real dz_inv)
 
void AddScalarDiffusionRefluxFluxes_T (const amrex::Box &bx, const amrex::Box &domain, const amrex::Array4< const amrex::Real > &xflux, const amrex::Array4< const amrex::Real > &yflux, const amrex::Array4< const amrex::Real > &zflux, const int flux_comp, const ScalarDiffusionRefluxViews &reflux, const int state_comp, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vx, const bool suppress_lower_z_flux, const bool suppress_upper_z_flux)
 

Typedef Documentation

◆ ScalarDiffusionRefluxViews

using ScalarDiffusionRefluxViews = amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>

Face views into which the diffusive fluxes of each component are accumulated for refluxing, indexed by state component, in the convention of the advective fluxes the flux registers hold: a state update of -(m_x m_y / detJ) div F. Null when nothing is refluxed.

Function Documentation

◆ AddScalarDiffusionRefluxFluxes_N()

void AddScalarDiffusionRefluxFluxes_N ( const amrex::Box &  bx,
const amrex::Array4< const amrex::Real > &  xflux,
const amrex::Array4< const amrex::Real > &  yflux,
const amrex::Array4< const amrex::Real > &  zflux,
const int  flux_comp,
const ScalarDiffusionRefluxViews &  reflux,
const int  state_comp,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_my 
)
inline

Add the diffusive face fluxes of one component on a flat mesh to the reflux face views. ApplyScalarDiffusionFluxDivergence_N applies -(m^2 (dFx/dx + dFy/dy) + dFz/dz), so in the advective convention the fluxes are Fx, Fy and Fz / m^2 (m^2 is per column, so it is the same on both sides of a z face).

1769 {
1770  amrex::ParallelFor(amrex::surroundingNodes(bx, 0), amrex::surroundingNodes(bx, 1),
1771  amrex::surroundingNodes(bx, 2),
1772  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1773  reflux[0](i, j, k, state_comp) += xflux(i, j, k, flux_comp);
1774  },
1775  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1776  reflux[1](i, j, k, state_comp) += yflux(i, j, k, flux_comp);
1777  },
1778  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1779  reflux[2](i, j, k, state_comp) += zflux(i, j, k, flux_comp) / (mf_mx(i, j, 0) * mf_my(i, j, 0));
1780  });
1781 }
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);})

Referenced by DiffusionSrcForState_N().

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

◆ AddScalarDiffusionRefluxFluxes_S()

void AddScalarDiffusionRefluxFluxes_S ( const amrex::Box &  bx,
const amrex::Array4< const amrex::Real > &  xflux,
const amrex::Array4< const amrex::Real > &  yflux,
const amrex::Array4< const amrex::Real > &  zflux,
const int  flux_comp,
const ScalarDiffusionRefluxViews &  reflux,
const int  state_comp,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_my,
const amrex::Real *  dz,
const amrex::Real  dz_inv 
)
inline

As AddScalarDiffusionRefluxFluxes_N, on a vertically stretched mesh: there detJ = dz[k] / dz, and ApplyScalarDiffusionFluxDivergence_S applies -(m^2 (dFx/dx + dFy/dy) + dFz/dz[k]), so the fluxes are detJ Fx, detJ Fy and Fz / m^2.

1801 {
1802  amrex::ParallelFor(amrex::surroundingNodes(bx, 0), amrex::surroundingNodes(bx, 1),
1803  amrex::surroundingNodes(bx, 2),
1804  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1805  reflux[0](i, j, k, state_comp) += dz[k] * dz_inv * xflux(i, j, k, flux_comp);
1806  },
1807  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1808  reflux[1](i, j, k, state_comp) += dz[k] * dz_inv * yflux(i, j, k, flux_comp);
1809  },
1810  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1811  reflux[2](i, j, k, state_comp) += zflux(i, j, k, flux_comp) / (mf_mx(i, j, 0) * mf_my(i, j, 0));
1812  });
1813 }
@ dz
Definition: ERF_AdvanceWDM6.cpp:273

Referenced by DiffusionSrcForState_S().

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

◆ AddScalarDiffusionRefluxFluxes_T()

void AddScalarDiffusionRefluxFluxes_T ( const amrex::Box &  bx,
const amrex::Box &  domain,
const amrex::Array4< const amrex::Real > &  xflux,
const amrex::Array4< const amrex::Real > &  yflux,
const amrex::Array4< const amrex::Real > &  zflux,
const int  flux_comp,
const ScalarDiffusionRefluxViews &  reflux,
const int  state_comp,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::Array4< const amrex::Real > &  ax,
const amrex::Array4< const amrex::Real > &  ay,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_my,
const amrex::Array4< const amrex::Real > &  mf_uy,
const amrex::Array4< const amrex::Real > &  mf_vx,
const bool  suppress_lower_z_flux,
const bool  suppress_upper_z_flux 
)
inline

As AddScalarDiffusionRefluxFluxes_N, on a terrain-following mesh: ApplyScalarDiffusionMappedDivergence_T applies -(1/detJ)(m^2 (dTx/dx + dTy/dy) + dGz/dzeta) with the mapped transfers Tx, Ty and the vertical transfer Gz, so the fluxes are Tx, Ty and Gz / m^2. suppress_lower_z_flux and suppress_upper_z_flux must be what that divergence was given.

1842 {
1843  const int dom_klo = domain.smallEnd(2);
1844  const int dom_khi = domain.bigEnd(2);
1845  amrex::ParallelFor(amrex::surroundingNodes(bx, 0), amrex::surroundingNodes(bx, 1),
1846  amrex::surroundingNodes(bx, 2),
1847  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1848  reflux[0](i, j, k, state_comp) +=
1849  TerrainDiffusionMappedTx(xflux(i, j, k, flux_comp), ax(i, j, k), mf_uy(i, j, 0));
1850  },
1851  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1852  reflux[1](i, j, k, state_comp) +=
1853  TerrainDiffusionMappedTy(yflux(i, j, k, flux_comp), ay(i, j, k), mf_vx(i, j, 0));
1854  },
1855  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1856  const amrex::Real Gz = ((suppress_lower_z_flux && k == dom_klo) ||
1857  (suppress_upper_z_flux && k == dom_khi + 1))
1858  ? amrex::Real(0.0)
1859  : TerrainScalarDiffusionGzAtKFace(i, j, k, domain, xflux, yflux, zflux,
1860  flux_comp, z_nd, cellSizeInv,
1861  mf_mx, mf_my);
1862  reflux[2](i, j, k, state_comp) += Gz / (mf_mx(i, j, 0) * mf_my(i, j, 0));
1863  });
1864 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionMappedTy(const amrex::Real raw_Fy, const amrex::Real h_zeta, const amrex::Real mx) noexcept
Definition: ERF_ScalarDiffusion.H:595
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionGzAtKFace(const int i, const int j, const int kface, const amrex::Box &domain, const amrex::Array4< const amrex::Real > &raw_xflux, const amrex::Array4< const amrex::Real > &raw_yflux, const amrex::Array4< const amrex::Real > &raw_zflux, const int flux_comp, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my) noexcept
Definition: ERF_ScalarDiffusion.H:632
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionMappedTx(const amrex::Real raw_Fx, const amrex::Real h_zeta, const amrex::Real my) noexcept
Definition: ERF_ScalarDiffusion.H:586

Referenced by DiffusionSrcForState_T().

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

◆ ApplyScalarDiffusionFluxDivergence_N()

void ApplyScalarDiffusionFluxDivergence_N ( const amrex::Box &  bx,
const amrex::Array4< const amrex::Real > &  xflux,
const amrex::Array4< const amrex::Real > &  yflux,
const amrex::Array4< const amrex::Real > &  raw_Fz,
const int  flux_comp,
const amrex::Array4< amrex::Real > &  rhs,
const int  rhs_comp,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_my 
)
inline

Apply the conservative N-grid divergence to a separately selected RHS component. Face scratch is component-selected independently in each view.

1607 {
1608  const amrex::Real dx_inv = cellSizeInv[0];
1609  const amrex::Real dy_inv = cellSizeInv[1];
1610  const amrex::Real dz_inv = cellSizeInv[2];
1611  amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1612  const amrex::Real mfsq = mf_mx(i, j, 0) * mf_my(i, j, 0);
1613  rhs(i, j, k, rhs_comp) -=
1614  (xflux(i + 1, j, k, flux_comp) - xflux(i, j, k, flux_comp)) * dx_inv *
1615  mfsq +
1616  (yflux(i, j + 1, k, flux_comp) - yflux(i, j, k, flux_comp)) * dy_inv *
1617  mfsq +
1618  (raw_Fz(i, j, k + 1, flux_comp) - raw_Fz(i, j, k, flux_comp)) * dz_inv;
1619  });
1620 }

Referenced by DiffusionSrcForState_N().

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

◆ ApplyScalarDiffusionFluxDivergence_S()

void ApplyScalarDiffusionFluxDivergence_S ( const amrex::Box &  bx,
const amrex::Array4< const amrex::Real > &  xflux,
const amrex::Array4< const amrex::Real > &  yflux,
const amrex::Array4< const amrex::Real > &  raw_Fz,
const int  flux_comp,
const amrex::Array4< amrex::Real > &  rhs,
const int  rhs_comp,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_my,
const amrex::Real  dx_inv,
const amrex::Real  dy_inv,
const amrex::Real *  dz 
)
inline

S-grid conservative divergence; vertical cell width is the receiver's dz[k].

1638 {
1639  amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1640  const amrex::Real mfsq = mf_mx(i, j, 0) * mf_my(i, j, 0);
1641  const amrex::Real dzk_inv = amrex::Real(1.0) / dz[k];
1642  const amrex::Real stateContrib =
1643  (xflux(i + 1, j, k, flux_comp) - xflux(i, j, k, flux_comp)) * dx_inv *
1644  mfsq +
1645  (yflux(i, j + 1, k, flux_comp) - yflux(i, j, k, flux_comp)) * dy_inv *
1646  mfsq +
1647  (raw_Fz(i, j, k + 1, flux_comp) - raw_Fz(i, j, k, flux_comp)) * dzk_inv;
1648  rhs(i, j, k, rhs_comp) -= stateContrib;
1649  });
1650 }

Referenced by DiffusionSrcForState_S().

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

◆ ApplyScalarDiffusionMappedDivergence_T()

void ApplyScalarDiffusionMappedDivergence_T ( const amrex::Box &  bx,
const amrex::Box &  domain,
const ScalarDiffusionFieldViews &  field,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::Array4< const amrex::Real > &  ax,
const amrex::Array4< const amrex::Real > &  ay,
const amrex::Array4< const amrex::Real > &  detJ,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_uy,
const amrex::Array4< const amrex::Real > &  mf_my,
const amrex::Array4< const amrex::Real > &  mf_vx,
const bool  suppress_lower_z_flux,
const bool  suppress_upper_z_flux 
)
inline

Apply native terrain diffusion in one kernel, mapping each face inline.

1550 {
1551  using namespace amrex;
1552  const auto dom_lo = lbound(domain);
1553  const auto dom_hi = ubound(domain);
1554  const Real dx_inv = cellSizeInv[0];
1555  const Real dy_inv = cellSizeInv[1];
1556  const Real dz_inv = cellSizeInv[2];
1557  const Array4<const Real> xflux(field.xflux);
1558  const Array4<const Real> yflux(field.yflux);
1559  const Array4<const Real> zflux(field.zflux);
1560  const auto rhs = field.rhs;
1561  const int flux_comp = field.flux_comp;
1562  const int rhs_comp = field.rhs_comp;
1563 
1564  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1565  const Real mapped_Fx_lo = TerrainDiffusionMappedTx(
1566  xflux(i, j, k, flux_comp), ax(i, j, k), mf_uy(i, j, 0));
1567  const Real mapped_Fx_hi = TerrainDiffusionMappedTx(
1568  xflux(i + 1, j, k, flux_comp), ax(i + 1, j, k), mf_uy(i + 1, j, 0));
1569  const Real mapped_Fy_lo = TerrainDiffusionMappedTy(
1570  yflux(i, j, k, flux_comp), ay(i, j, k), mf_vx(i, j, 0));
1571  const Real mapped_Fy_hi = TerrainDiffusionMappedTy(
1572  yflux(i, j + 1, k, flux_comp), ay(i, j + 1, k), mf_vx(i, j + 1, 0));
1573  const Real Gz_lo = (suppress_lower_z_flux && k == dom_lo.z)
1574  ? Real(0.0)
1576  i, j, k, domain, xflux, yflux, zflux, flux_comp,
1577  z_nd, cellSizeInv, mf_mx, mf_my);
1578  const Real Gz_hi = (suppress_upper_z_flux && k == dom_hi.z)
1579  ? Real(0.0)
1581  i, j, k + 1, domain, xflux, yflux, zflux, flux_comp,
1582  z_nd, cellSizeInv, mf_mx, mf_my);
1583  const Real mfsq = mf_mx(i, j, 0) * mf_my(i, j, 0);
1584  const Real stateContrib = TerrainDiffusionDivergence_T(
1585  mapped_Fx_hi, mapped_Fx_lo, mapped_Fy_hi, mapped_Fy_lo, Gz_hi, Gz_lo,
1586  dx_inv, dy_inv, dz_inv, mfsq, detJ(i, j, k));
1587  rhs(i, j, k, rhs_comp) -= stateContrib;
1588  });
1589 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionDivergence_T(const amrex::Real mapped_Fx_hi, const amrex::Real mapped_Fx_lo, const amrex::Real mapped_Fy_hi, const amrex::Real mapped_Fy_lo, const amrex::Real Gz_hi, const amrex::Real Gz_lo, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real dz_inv, const amrex::Real mfsq, const amrex::Real detJ_cell) noexcept
Definition: ERF_ScalarDiffusion.H:757
Definition: ERF_ConsoleIO.cpp:17
amrex::Array4< amrex::Real > xflux
Definition: ERF_ScalarDiffusion.H:40
amrex::Array4< amrex::Real > rhs
Definition: ERF_ScalarDiffusion.H:44
int rhs_comp
Definition: ERF_ScalarDiffusion.H:45
amrex::Array4< amrex::Real > yflux
Definition: ERF_ScalarDiffusion.H:41
int flux_comp
Definition: ERF_ScalarDiffusion.H:43
amrex::Array4< amrex::Real > zflux
Definition: ERF_ScalarDiffusion.H:42

Referenced by DiffusionSrcForState_T().

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

◆ ApplyScalarMappedFluxDivergence()

void ApplyScalarMappedFluxDivergence ( const amrex::Box &  bx,
const amrex::Array4< const amrex::Real > &  mapped_x,
const int  mapped_x_comp,
const amrex::Array4< const amrex::Real > &  mapped_y,
const int  mapped_y_comp,
const amrex::Array4< const amrex::Real > &  mapped_z,
const int  mapped_z_comp,
const amrex::Array4< amrex::Real > &  rhs,
const int  rhs_comp,
const amrex::Array4< const amrex::Real > &  detJ,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_my 
)
inline

Add the divergence of caller-supplied mapped transfers to rhs. Inputs are only the accepted face arrays and the mapped cell geometry; in particular, this operation cannot reconstruct a raw or terrain diffusion candidate. The supplied face arrays and mapped-geometry convention are the same as ApplyScalarAdvectionFluxDivergence. This diffusion operation differs in RHS semantics: it accumulates -divergence into an existing RHS and leaves cells with nonpositive detJ unchanged, whereas advection assigns its output and zeroes such cells.

1514 {
1515  const amrex::Real dx_inv = cellSizeInv[0];
1516  const amrex::Real dy_inv = cellSizeInv[1];
1517  const amrex::Real dzeta_inv = cellSizeInv[2];
1519  bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1520  if (detJ(i, j, k) > amrex::Real(0.0)) {
1521  rhs(i, j, k, rhs_comp) -= ScalarDiffusionMappedFluxDivergence(
1522  mapped_x(i + 1, j, k, mapped_x_comp),
1523  mapped_x(i, j, k, mapped_x_comp),
1524  mapped_y(i, j + 1, k, mapped_y_comp),
1525  mapped_y(i, j, k, mapped_y_comp),
1526  mapped_z(i, j, k + 1, mapped_z_comp),
1527  mapped_z(i, j, k, mapped_z_comp), dx_inv, dy_inv, dzeta_inv,
1528  mf_mx(i, j, 0), mf_my(i, j, 0), detJ(i, j, k));
1529  }
1530  });
1531 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionMappedFluxDivergence(const amrex::Real fx_hi, const amrex::Real fx_lo, const amrex::Real fy_hi, const amrex::Real fy_lo, const amrex::Real fz_hi, const amrex::Real fz_lo, const amrex::Real dx_inv, const amrex::Real dy_inv, const amrex::Real dzeta_inv, const amrex::Real mx, const amrex::Real my, const amrex::Real detJ_cell) noexcept
Definition: ERF_ScalarDiffusion.H:733
Here is the call graph for this function:

◆ BuildScalarDiffusionFluxes_N()

void BuildScalarDiffusionFluxes_N ( const amrex::Box &  bx,
const amrex::Box &  domain,
const ScalarDiffusionFieldViews &  field,
const ScalarDiffusionFluxPolicy &  policy,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  u,
const amrex::Array4< const amrex::Real > &  v,
const amrex::Array4< const amrex::Real > &  mf_ux,
const amrex::Array4< const amrex::Real > &  mf_uy,
const amrex::Array4< const amrex::Real > &  mf_vx,
const amrex::Array4< const amrex::Real > &  mf_vy,
const amrex::BCRec *  bc_ptr,
const int  bc_comp 
)
inline

Build all native N-grid face fluxes for any intensive scalar field.

938 {
939  const auto mode = policy.coefficient_mode;
940  if (mode.molecular_is_kinematic) {
941  if (mode.add_turbulence) {
942  BuildScalarDiffusionFluxes_N_Impl<true, true>(
943  bx, domain, field, policy, cellSizeInv, u, v, mf_ux, mf_uy, mf_vx,
944  mf_vy, bc_ptr, bc_comp);
945  } else {
946  BuildScalarDiffusionFluxes_N_Impl<true, false>(
947  bx, domain, field, policy, cellSizeInv, u, v, mf_ux, mf_uy, mf_vx,
948  mf_vy, bc_ptr, bc_comp);
949  }
950  } else if (mode.add_turbulence) {
951  BuildScalarDiffusionFluxes_N_Impl<false, true>(
952  bx, domain, field, policy, cellSizeInv, u, v, mf_ux, mf_uy, mf_vx,
953  mf_vy, bc_ptr, bc_comp);
954  } else {
955  BuildScalarDiffusionFluxes_N_Impl<false, false>(
956  bx, domain, field, policy, cellSizeInv, u, v, mf_ux, mf_uy, mf_vx,
957  mf_vy, bc_ptr, bc_comp);
958  }
959 }
ScalarDiffusionCoefficientMode coefficient_mode
Definition: ERF_ScalarDiffusion.H:95

Referenced by erf_sbm::erf_detail_SBMTransport::add_high_order_mixing(), and DiffusionSrcForState_N().

Here is the caller graph for this function:

◆ BuildScalarDiffusionFluxes_N_Impl()

template<bool MultiplyMolecularByDensity, bool AddTurbulence>
void BuildScalarDiffusionFluxes_N_Impl ( const amrex::Box &  bx,
const amrex::Box &  domain,
const ScalarDiffusionFieldViews &  field,
const ScalarDiffusionFluxPolicy &  policy,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  u,
const amrex::Array4< const amrex::Real > &  v,
const amrex::Array4< const amrex::Real > &  mf_ux,
const amrex::Array4< const amrex::Real > &  mf_uy,
const amrex::Array4< const amrex::Real > &  mf_vx,
const amrex::Array4< const amrex::Real > &  mf_vy,
const amrex::BCRec *  bc_ptr,
const int  bc_comp 
)
inline

Component-explicit N-grid face construction. Boundary-condition selection, map factors, prescribed surface fluxes and raw-flux diagnostics are explicit inputs; this operation does not inspect native conserved-state identity.

799 {
800  using namespace amrex;
801  const auto dom_lo = lbound(domain);
802  const auto dom_hi = ubound(domain);
803  const Box xbx = surroundingNodes(bx, 0);
804  const Box ybx = surroundingNodes(bx, 1);
805  const Box zbx = surroundingNodes(bx, 2);
806  const Real dx_inv = cellSizeInv[0];
807  const Real dy_inv = cellSizeInv[1];
808  const Real dz_inv = cellSizeInv[2];
809  const auto coefficients = policy.coefficients;
810  const auto prescribed = policy.prescribed;
811  const auto diagnostic = policy.diagnostic;
812  const auto surface = policy.surface;
813  const int scalar_comp = field.scalar_comp;
814  const int rho_comp = field.rho_comp;
815  const int flux_comp = field.flux_comp;
816  const auto scalar = field.scalar;
817  const auto density = field.density;
818  const auto mu_turb = field.mu_turb;
819  const auto xflux = field.xflux;
820  const auto yflux = field.yflux;
821  const auto zflux = field.zflux;
822 
823  ParallelFor(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
824  const Real coeff = ScalarDiffusionFaceCoefficient<
825  MultiplyMolecularByDensity, AddTurbulence>(
826  density, rho_comp, mu_turb, coefficients, i, j, k, 1, 0, 0,
827  coefficients.eddy_h_comp);
828  bool ext_lo, ext_hi;
829  ScalarDiffusionLateralExtDir<0>(bc_ptr[bc_comp], u, i, j, k, dom_lo, dom_hi,
830  ext_lo, ext_hi);
831  const bool on_surface =
832  (surface.xlo && i == dom_lo.x) ||
833  (surface.xhi && i == dom_hi.x + 1);
834 
835  if (ext_lo) {
836  xflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<0>(
837  scalar, scalar_comp, i, j, k, coeff, dx_inv,
838  mf_ux(i, j, 0), mf_uy(i, j, 0), true, false);
839  } else if (ext_hi) {
840  xflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<0>(
841  scalar, scalar_comp, i, j, k, coeff, dx_inv,
842  mf_ux(i, j, 0), mf_uy(i, j, 0), false, true);
843  } else if (on_surface && prescribed.use_x_on_side) {
844  xflux(i, j, k, flux_comp) = prescribed.x(i, j, k, prescribed.x_comp);
845  } else {
846  xflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<0>(
847  scalar, scalar_comp, i, j, k, coeff, dx_inv,
848  mf_ux(i, j, 0), mf_uy(i, j, 0), false, false);
849  }
850  });
851 
852  ParallelFor(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
853  const Real coeff = ScalarDiffusionFaceCoefficient<
854  MultiplyMolecularByDensity, AddTurbulence>(
855  density, rho_comp, mu_turb, coefficients, i, j, k, 0, 1, 0,
856  coefficients.eddy_h_comp);
857  bool ext_lo, ext_hi;
858  ScalarDiffusionLateralExtDir<1>(bc_ptr[bc_comp], v, i, j, k, dom_lo, dom_hi,
859  ext_lo, ext_hi);
860  const bool on_surface =
861  (surface.ylo && j == dom_lo.y) ||
862  (surface.yhi && j == dom_hi.y + 1);
863 
864  if (ext_lo) {
865  yflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<1>(
866  scalar, scalar_comp, i, j, k, coeff, dy_inv,
867  mf_vy(i, j, 0), mf_vx(i, j, 0), true, false);
868  } else if (ext_hi) {
869  yflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<1>(
870  scalar, scalar_comp, i, j, k, coeff, dy_inv,
871  mf_vy(i, j, 0), mf_vx(i, j, 0), false, true);
872  } else if (on_surface && prescribed.use_y_on_side) {
873  yflux(i, j, k, flux_comp) = prescribed.y(i, j, k, prescribed.y_comp);
874  } else {
875  yflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<1>(
876  scalar, scalar_comp, i, j, k, coeff, dy_inv,
877  mf_vy(i, j, 0), mf_vx(i, j, 0), false, false);
878  }
879  });
880 
881  ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
882  const Real coeff = ScalarDiffusionFaceCoefficient<
883  MultiplyMolecularByDensity, AddTurbulence>(
884  density, rho_comp, mu_turb, coefficients, i, j, k, 0, 0, 1,
885  coefficients.eddy_v_comp);
886  const bool ext_lo =
887  ((bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir) ||
888  (bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir_prim)) &&
889  k == dom_lo.z;
890  const bool ext_hi =
891  ((bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir) ||
892  (bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir_prim)) &&
893  k == dom_hi.z + 1;
894  const bool on_surface =
895  (surface.zlo && k == dom_lo.z) ||
896  (surface.zhi && k == dom_hi.z + 1);
897 
898  if (ext_lo) {
899  zflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<2>(
900  scalar, scalar_comp, i, j, k, coeff, dz_inv, Real(1.0), Real(1.0),
901  true, false);
902  } else if (ext_hi) {
903  zflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<2>(
904  scalar, scalar_comp, i, j, k, coeff, dz_inv, Real(1.0), Real(1.0),
905  false, true);
906  } else if (on_surface && prescribed.use_z_on_side) {
907  zflux(i, j, k, flux_comp) = prescribed.z(i, j, k, prescribed.z_comp);
908  } else if (on_surface) {
909  zflux(i, j, k, flux_comp) = Real(0.0);
910  } else {
911  zflux(i, j, k, flux_comp) = ScalarDiffusionFlux_N<2>(
912  scalar, scalar_comp, i, j, k, coeff, dz_inv, Real(1.0), Real(1.0),
913  false, false);
914  }
915 
916  if (diagnostic.enabled && (diagnostic.write_on_surface || !on_surface)) {
917  diagnostic.z(i, j, k, diagnostic.z_comp) = zflux(i, j, k, flux_comp);
918  }
919  });
920 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFaceCoefficient(const amrex::Array4< const amrex::Real > &rho, const int rho_comp, const amrex::Array4< const amrex::Real > &mu_turb, const ScalarDiffusionCoefficients &coefficients, const int i, const int j, const int k, const int di, const int dj, const int dk, const int eddy_comp) noexcept
Definition: ERF_ScalarDiffusion.H:114
@ ext_dir
Definition: ERF_IndexDefines.H:317
@ ext_dir_prim
Definition: ERF_IndexDefines.H:320
@ prescribed
the prescribed land surface potential temperature (most.pot_surf_temp)
int rho_comp
Definition: ERF_ScalarDiffusion.H:38
amrex::Array4< const amrex::Real > scalar
Definition: ERF_ScalarDiffusion.H:35
amrex::Array4< const amrex::Real > density
Definition: ERF_ScalarDiffusion.H:37
int scalar_comp
Definition: ERF_ScalarDiffusion.H:36
amrex::Array4< const amrex::Real > mu_turb
Definition: ERF_ScalarDiffusion.H:39
ScalarDiffusionRawFluxDiagnostic diagnostic
Definition: ERF_ScalarDiffusion.H:97
ScalarDiffusionPrescribedFluxes prescribed
Definition: ERF_ScalarDiffusion.H:96
ScalarDiffusionSurfaceFaces surface
Definition: ERF_ScalarDiffusion.H:98
ScalarDiffusionCoefficients coefficients
Definition: ERF_ScalarDiffusion.H:94
Here is the call graph for this function:

◆ BuildScalarDiffusionFluxes_S()

void BuildScalarDiffusionFluxes_S ( const amrex::Box &  bx,
const amrex::Box &  domain,
const ScalarDiffusionFieldViews &  field,
const ScalarDiffusionFluxPolicy &  policy,
const amrex::Real  dx_inv,
const amrex::Real  dy_inv,
const amrex::Real *  dz,
const int  klo,
const int  khi,
const amrex::Array4< const amrex::Real > &  u,
const amrex::Array4< const amrex::Real > &  v,
const amrex::Array4< const amrex::Real > &  mf_ux,
const amrex::Array4< const amrex::Real > &  mf_uy,
const amrex::Array4< const amrex::Real > &  mf_vx,
const amrex::Array4< const amrex::Real > &  mf_vy,
const amrex::BCRec *  bc_ptr,
const int  bc_comp 
)
inline

Build and map-adjust all native S-grid face fluxes for an intensive field.

1102 {
1103  const auto mode = policy.coefficient_mode;
1104  if (mode.molecular_is_kinematic) {
1105  if (mode.add_turbulence) {
1106  BuildScalarDiffusionFluxes_S_Impl<true, true>(
1107  bx, domain, field, policy, dx_inv, dy_inv, dz, klo, khi, u, v,
1108  mf_ux, mf_uy, mf_vx, mf_vy, bc_ptr, bc_comp);
1109  } else {
1110  BuildScalarDiffusionFluxes_S_Impl<true, false>(
1111  bx, domain, field, policy, dx_inv, dy_inv, dz, klo, khi, u, v,
1112  mf_ux, mf_uy, mf_vx, mf_vy, bc_ptr, bc_comp);
1113  }
1114  } else if (mode.add_turbulence) {
1115  BuildScalarDiffusionFluxes_S_Impl<false, true>(
1116  bx, domain, field, policy, dx_inv, dy_inv, dz, klo, khi, u, v,
1117  mf_ux, mf_uy, mf_vx, mf_vy, bc_ptr, bc_comp);
1118  } else {
1119  BuildScalarDiffusionFluxes_S_Impl<false, false>(
1120  bx, domain, field, policy, dx_inv, dy_inv, dz, klo, khi, u, v,
1121  mf_ux, mf_uy, mf_vx, mf_vy, bc_ptr, bc_comp);
1122  }
1123 }
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
const int klo
Definition: ERF_InitCustomPert_KE.H:9

Referenced by erf_sbm::erf_detail_SBMTransport::add_high_order_mixing(), and DiffusionSrcForState_S().

Here is the caller graph for this function:

◆ BuildScalarDiffusionFluxes_S_Impl()

template<bool MultiplyMolecularByDensity, bool AddTurbulence>
void BuildScalarDiffusionFluxes_S_Impl ( const amrex::Box &  bx,
const amrex::Box &  domain,
const ScalarDiffusionFieldViews &  field,
const ScalarDiffusionFluxPolicy &  policy,
const amrex::Real  dx_inv,
const amrex::Real  dy_inv,
const amrex::Real *  dz,
const int  klo,
const int  khi,
const amrex::Array4< const amrex::Real > &  u,
const amrex::Array4< const amrex::Real > &  v,
const amrex::Array4< const amrex::Real > &  mf_ux,
const amrex::Array4< const amrex::Real > &  mf_uy,
const amrex::Array4< const amrex::Real > &  mf_vx,
const amrex::Array4< const amrex::Real > &  mf_vy,
const amrex::BCRec *  bc_ptr,
const int  bc_comp 
)
inline
981 {
982  using namespace amrex;
983  const auto dom_lo = lbound(domain);
984  const auto dom_hi = ubound(domain);
985  const Box xbx = surroundingNodes(bx, 0);
986  const Box ybx = surroundingNodes(bx, 1);
987  const Box zbx = surroundingNodes(bx, 2);
988  const auto coefficients = policy.coefficients;
989  const auto prescribed = policy.prescribed;
990  const auto diagnostic = policy.diagnostic;
991  const auto surface = policy.surface;
992  const int scalar_comp = field.scalar_comp;
993  const int rho_comp = field.rho_comp;
994  const int flux_comp = field.flux_comp;
995  const auto scalar = field.scalar;
996  const auto density = field.density;
997  const auto mu_turb = field.mu_turb;
998  const auto xflux = field.xflux;
999  const auto yflux = field.yflux;
1000  const auto zflux = field.zflux;
1001 
1002  ParallelFor(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1003  const Real coeff = ScalarDiffusionFaceCoefficient<
1004  MultiplyMolecularByDensity, AddTurbulence>(
1005  density, rho_comp, mu_turb, coefficients, i, j, k, 1, 0, 0,
1006  coefficients.eddy_h_comp);
1007  const bool on_surface =
1008  (surface.xlo && i == dom_lo.x) ||
1009  (surface.xhi && i == dom_hi.x + 1);
1010  bool ext_lo, ext_hi;
1011  ScalarDiffusionLateralExtDir<0>(bc_ptr[bc_comp], u, i, j, k, dom_lo, dom_hi,
1012  ext_lo, ext_hi);
1013  if (on_surface && prescribed.use_x_on_side) {
1014  xflux(i, j, k, flux_comp) = prescribed.x(i, j, k, prescribed.x_comp);
1015  } else {
1016  xflux(i, j, k, flux_comp) = ScalarDiffusionFlux_S_Horizontal<0>(
1017  scalar, scalar_comp, i, j, k, coeff, dx_inv, mf_ux(i, j, 0),
1018  ext_lo, ext_hi);
1019  }
1020  });
1021 
1022  ParallelFor(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1023  const Real coeff = ScalarDiffusionFaceCoefficient<
1024  MultiplyMolecularByDensity, AddTurbulence>(
1025  density, rho_comp, mu_turb, coefficients, i, j, k, 0, 1, 0,
1026  coefficients.eddy_h_comp);
1027  const bool on_surface =
1028  (surface.ylo && j == dom_lo.y) ||
1029  (surface.yhi && j == dom_hi.y + 1);
1030  bool ext_lo, ext_hi;
1031  ScalarDiffusionLateralExtDir<1>(bc_ptr[bc_comp], v, i, j, k, dom_lo, dom_hi,
1032  ext_lo, ext_hi);
1033  if (on_surface && prescribed.use_y_on_side) {
1034  yflux(i, j, k, flux_comp) = prescribed.y(i, j, k, prescribed.y_comp);
1035  } else {
1036  yflux(i, j, k, flux_comp) = ScalarDiffusionFlux_S_Horizontal<1>(
1037  scalar, scalar_comp, i, j, k, coeff, dy_inv, mf_vy(i, j, 0),
1038  ext_lo, ext_hi);
1039  }
1040  });
1041 
1042  ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1043  const Real coeff = ScalarDiffusionFaceCoefficient<
1044  MultiplyMolecularByDensity, AddTurbulence>(
1045  density, rho_comp, mu_turb, coefficients, i, j, k, 0, 0, 1,
1046  coefficients.eddy_v_comp);
1047  const bool ext_lo =
1048  ((bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir) ||
1049  (bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir_prim)) &&
1050  k == dom_lo.z;
1051  const bool ext_hi =
1052  ((bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir) ||
1053  (bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir_prim)) &&
1054  k == dom_hi.z + 1;
1055  const bool on_surface =
1056  (surface.zlo && k == dom_lo.z) ||
1057  (surface.zhi && k == dom_hi.z + 1);
1058  const Real grad = StretchedScalarGradient(
1059  scalar, scalar_comp, i, j, k, dz, klo, khi, ext_lo, ext_hi);
1060  if (on_surface && prescribed.use_z_on_side) {
1061  zflux(i, j, k, flux_comp) = prescribed.z(i, j, k, prescribed.z_comp);
1062  } else if (on_surface) {
1063  zflux(i, j, k, flux_comp) = Real(0.0);
1064  } else {
1065  zflux(i, j, k, flux_comp) = -coeff * grad;
1066  }
1067  if (diagnostic.enabled && (diagnostic.write_on_surface || !on_surface)) {
1068  diagnostic.z(i, j, k, diagnostic.z_comp) = zflux(i, j, k, flux_comp);
1069  }
1070  });
1071 
1072  // S-grid raw horizontal fluxes are adjusted in the same separate kernels as
1073  // the native implementation before scaling or applying divergence.
1074  ParallelFor(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1075  xflux(i, j, k, flux_comp) /= mf_uy(i, j, 0);
1076  });
1077  ParallelFor(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1078  yflux(i, j, k, flux_comp) /= mf_vx(i, j, 0);
1079  });
1080 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real StretchedScalarGradient(const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const int i, const int j, const int k, const amrex::Real *dz, const int klo, const int khi, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
Definition: ERF_ScalarDiffusion.H:303
Here is the call graph for this function:

◆ BuildScalarDiffusionFluxes_T() [1/2]

void BuildScalarDiffusionFluxes_T ( const amrex::Box &  bx,
const amrex::Box &  domain,
const ScalarDiffusionFieldViews &  field,
const ScalarDiffusionFluxPolicy &  policy,
const bool  rotate,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::Array4< const amrex::Real > &  z_cc,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  u,
const amrex::Array4< const amrex::Real > &  v,
const amrex::Array4< const amrex::Real > &  mf_ux,
const amrex::Array4< const amrex::Real > &  mf_vy,
const amrex::BCRec *  bc_ptr,
const int  bc_comp 
)
inline

As above, with policy.coefficients on every face.

1320 {
1321  BuildScalarDiffusionFluxes_T(bx, domain, field, policy, policy.coefficients,
1322  rotate, z_nd, z_cc, cellSizeInv, u, v, mf_ux, mf_vy,
1323  bc_ptr, bc_comp);
1324 }
void BuildScalarDiffusionFluxes_T(const amrex::Box &bx, const amrex::Box &domain, const ScalarDiffusionFieldViews &field, const ScalarDiffusionFluxPolicy &policy, const ScalarDiffusionCoefficients &vertical_coefficients, const bool rotate, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::BCRec *bc_ptr, const int bc_comp)
Definition: ERF_ScalarDiffusion.H:1263
Here is the call graph for this function:

◆ BuildScalarDiffusionFluxes_T() [2/2]

void BuildScalarDiffusionFluxes_T ( const amrex::Box &  bx,
const amrex::Box &  domain,
const ScalarDiffusionFieldViews &  field,
const ScalarDiffusionFluxPolicy &  policy,
const ScalarDiffusionCoefficients &  vertical_coefficients,
const bool  rotate,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::Array4< const amrex::Real > &  z_cc,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  u,
const amrex::Array4< const amrex::Real > &  v,
const amrex::Array4< const amrex::Real > &  mf_ux,
const amrex::Array4< const amrex::Real > &  mf_vy,
const amrex::BCRec *  bc_ptr,
const int  bc_comp 
)
inline

Build all native terrain-grid face fluxes, including the grown horizontal face regions needed by the mapped z-face transfer. The x and y faces read policy.coefficients and the z faces read vertical_coefficients (its molecular coefficient and eddy_v_comp). Each raw flux carries the coefficient of its own direction before the single terrain mapping, whose vertical transfer then combines both. A pass that gives every raw flux the vertical coefficient does not produce that transfer, even with K_v = 0.

1279 {
1280  const auto mode = policy.coefficient_mode;
1281  const auto& vertical = vertical_coefficients;
1282  if (mode.molecular_is_kinematic) {
1283  if (mode.add_turbulence) {
1284  BuildScalarDiffusionFluxes_T_Impl<true, true>(
1285  bx, domain, field, policy, vertical, rotate, z_nd, z_cc, cellSizeInv,
1286  u, v, mf_ux, mf_vy, bc_ptr, bc_comp);
1287  } else {
1288  BuildScalarDiffusionFluxes_T_Impl<true, false>(
1289  bx, domain, field, policy, vertical, rotate, z_nd, z_cc, cellSizeInv,
1290  u, v, mf_ux, mf_vy, bc_ptr, bc_comp);
1291  }
1292  } else if (mode.add_turbulence) {
1293  BuildScalarDiffusionFluxes_T_Impl<false, true>(
1294  bx, domain, field, policy, vertical, rotate, z_nd, z_cc, cellSizeInv,
1295  u, v, mf_ux, mf_vy, bc_ptr, bc_comp);
1296  } else {
1297  BuildScalarDiffusionFluxes_T_Impl<false, false>(
1298  bx, domain, field, policy, vertical, rotate, z_nd, z_cc, cellSizeInv,
1299  u, v, mf_ux, mf_vy, bc_ptr, bc_comp);
1300  }
1301 }

Referenced by erf_sbm::erf_detail_SBMTransport::build_terrain_high_order_mixing(), BuildScalarDiffusionFluxes_T(), and DiffusionSrcForState_T().

Here is the caller graph for this function:

◆ BuildScalarDiffusionFluxes_T_Impl()

template<bool MultiplyMolecularByDensity, bool AddTurbulence>
void BuildScalarDiffusionFluxes_T_Impl ( const amrex::Box &  bx,
const amrex::Box &  domain,
const ScalarDiffusionFieldViews &  field,
const ScalarDiffusionFluxPolicy &  policy,
const ScalarDiffusionCoefficients &  vertical_coefficients,
const bool  rotate,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::Array4< const amrex::Real > &  z_cc,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  u,
const amrex::Array4< const amrex::Real > &  v,
const amrex::Array4< const amrex::Real > &  mf_ux,
const amrex::Array4< const amrex::Real > &  mf_vy,
const amrex::BCRec *  bc_ptr,
const int  bc_comp 
)
inline
1143 {
1144  using namespace amrex;
1145  const auto dom_lo = lbound(domain);
1146  const auto dom_hi = ubound(domain);
1147  Box xbx = surroundingNodes(bx, 0);
1148  Box ybx = surroundingNodes(bx, 1);
1149  const Box zbx = surroundingNodes(bx, 2);
1150  if (xbx.smallEnd(2) != dom_lo.z) xbx.growLo(2, 1);
1151  if (ybx.smallEnd(2) != dom_lo.z) ybx.growLo(2, 1);
1152  if (xbx.bigEnd(2) != dom_hi.z) xbx.growHi(2, 1);
1153  if (ybx.bigEnd(2) != dom_hi.z) ybx.growHi(2, 1);
1154 
1155  const auto coefficients = policy.coefficients;
1156  const auto vertical = vertical_coefficients;
1157  const auto prescribed = policy.prescribed;
1158  const auto diagnostic = policy.diagnostic;
1159  const auto surface = policy.surface;
1160  const int scalar_comp = field.scalar_comp;
1161  const int rho_comp = field.rho_comp;
1162  const int flux_comp = field.flux_comp;
1163  const auto scalar = field.scalar;
1164  const auto density = field.density;
1165  const auto mu_turb = field.mu_turb;
1166  const auto xflux = field.xflux;
1167  const auto yflux = field.yflux;
1168  const auto zflux = field.zflux;
1169 
1170  ParallelFor(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1171  const Real coeff = ScalarDiffusionFaceCoefficient<
1172  MultiplyMolecularByDensity, AddTurbulence>(
1173  density, rho_comp, mu_turb, coefficients, i, j, k, 1, 0, 0,
1174  coefficients.eddy_h_comp);
1175  const bool on_side =
1176  (surface.xlo && i == dom_lo.x) ||
1177  (surface.xhi && i == dom_hi.x + 1);
1178  const bool on_bottom_z =
1179  surface.zlo && rotate && k == dom_lo.z;
1180 
1181  if (on_side && prescribed.use_x_on_side) {
1182  xflux(i, j, k, flux_comp) = prescribed.x(i, j, k, prescribed.x_comp);
1183  } else if (on_bottom_z && prescribed.use_x_on_bottom_z) {
1184  xflux(i, j, k, flux_comp) = prescribed.x(i, j, 0, prescribed.x_comp);
1185  } else {
1186  bool ext_lo, ext_hi;
1187  ScalarDiffusionLateralExtDir<0>(bc_ptr[bc_comp], u, i, j, k, dom_lo,
1188  dom_hi, ext_lo, ext_hi);
1189  xflux(i, j, k, flux_comp) = TerrainScalarDiffusionFluxAtIFace(
1190  scalar, scalar_comp, coeff, i, j, k, z_nd, z_cc, cellSizeInv, mf_ux,
1191  ext_lo, ext_hi);
1192  }
1193  });
1194 
1195  ParallelFor(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1196  const Real coeff = ScalarDiffusionFaceCoefficient<
1197  MultiplyMolecularByDensity, AddTurbulence>(
1198  density, rho_comp, mu_turb, coefficients, i, j, k, 0, 1, 0,
1199  coefficients.eddy_h_comp);
1200  const bool on_side =
1201  (surface.ylo && j == dom_lo.y) ||
1202  (surface.yhi && j == dom_hi.y + 1);
1203  const bool on_bottom_z =
1204  surface.zlo && rotate && k == dom_lo.z;
1205 
1206  if (on_side && prescribed.use_y_on_side) {
1207  yflux(i, j, k, flux_comp) = prescribed.y(i, j, k, prescribed.y_comp);
1208  } else if (on_bottom_z && prescribed.use_y_on_bottom_z) {
1209  yflux(i, j, k, flux_comp) = prescribed.y(i, j, 0, prescribed.y_comp);
1210  } else {
1211  bool ext_lo, ext_hi;
1212  ScalarDiffusionLateralExtDir<1>(bc_ptr[bc_comp], v, i, j, k, dom_lo,
1213  dom_hi, ext_lo, ext_hi);
1214  yflux(i, j, k, flux_comp) = TerrainScalarDiffusionFluxAtJFace(
1215  scalar, scalar_comp, coeff, i, j, k, z_nd, z_cc, cellSizeInv, mf_vy,
1216  ext_lo, ext_hi);
1217  }
1218  });
1219 
1220  ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1221  const Real coeff = ScalarDiffusionFaceCoefficient<
1222  MultiplyMolecularByDensity, AddTurbulence>(
1223  density, rho_comp, mu_turb, vertical, i, j, k, 0, 0, 1,
1224  vertical.eddy_v_comp);
1225  const bool ext_lo =
1226  ((bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir) ||
1227  (bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir_prim)) &&
1228  k == dom_lo.z;
1229  const bool ext_hi =
1230  ((bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir) ||
1231  (bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir_prim)) &&
1232  k == dom_hi.z + 1;
1233  const bool on_surface =
1234  (surface.zlo && k == dom_lo.z) ||
1235  (surface.zhi && k == dom_hi.z + 1);
1236 
1237  const Real raw_flux = TerrainScalarDiffusionFluxAtKFace(
1238  scalar, scalar_comp, coeff, i, j, k, z_nd, cellSizeInv, ext_lo, ext_hi);
1239 
1240  if (on_surface && prescribed.use_z_on_side) {
1241  zflux(i, j, k, flux_comp) = prescribed.z(i, j, k, prescribed.z_comp);
1242  } else if (on_surface) {
1243  zflux(i, j, k, flux_comp) = Real(0.0);
1244  } else {
1245  zflux(i, j, k, flux_comp) = raw_flux;
1246  }
1247  if (diagnostic.enabled && (diagnostic.write_on_surface || !on_surface)) {
1248  diagnostic.z(i, j, k, diagnostic.z_comp) = zflux(i, j, k, flux_comp);
1249  }
1250  });
1251 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionFluxAtJFace(const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::Real coeff, const int i, const int j, const int k, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_vy, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
Definition: ERF_ScalarDiffusion.H:468
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionFluxAtKFace(const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::Real coeff, const int i, const int j, const int kface, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
Definition: ERF_ScalarDiffusion.H:518
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionFluxAtIFace(const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::Real coeff, const int i, const int j, const int k, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_ux, const bool ext_dir_lo, const bool ext_dir_hi) noexcept
Definition: ERF_ScalarDiffusion.H:421
Here is the call graph for this function:

◆ BuildScalarDiffusionMappedTransfers_N()

void BuildScalarDiffusionMappedTransfers_N ( const amrex::Box &  bx,
const amrex::Array4< const amrex::Real > &  raw_x,
const int  raw_x_comp,
const amrex::Array4< const amrex::Real > &  raw_y,
const int  raw_y_comp,
const amrex::Array4< const amrex::Real > &  raw_z,
const int  raw_z_comp,
const amrex::Array4< amrex::Real > &  mapped_x,
const int  mapped_x_comp,
const amrex::Array4< amrex::Real > &  mapped_y,
const int  mapped_y_comp,
const amrex::Array4< amrex::Real > &  mapped_z,
const int  mapped_z_comp,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_my 
)
inline

Materialize the canonical N-grid face transfers. N-grid x/y builder outputs already carry their map-factor ratios; only the vertical flux is divided by the cell-centered horizontal map-factor product.

1348 {
1349  const amrex::Box xbx = amrex::surroundingNodes(bx, 0);
1350  const amrex::Box ybx = amrex::surroundingNodes(bx, 1);
1351  const amrex::Box zbx = amrex::surroundingNodes(bx, 2);
1353  xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1354  mapped_x(i, j, k, mapped_x_comp) =
1356  raw_x(i, j, k, raw_x_comp), amrex::Real(1.0));
1357  });
1359  ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1360  mapped_y(i, j, k, mapped_y_comp) =
1362  raw_y(i, j, k, raw_y_comp), amrex::Real(1.0));
1363  });
1365  zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1366  mapped_z(i, j, k, mapped_z_comp) =
1368  raw_z(i, j, k, raw_z_comp), mf_mx(i, j, 0), mf_my(i, j, 0));
1369  });
1370 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionMappedHorizontalTransfer(const amrex::Real raw_flux, const amrex::Real face_area) noexcept
Definition: ERF_ScalarDiffusion.H:609
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionMappedVerticalTransfer(const amrex::Real raw_flux, const amrex::Real mx, const amrex::Real my) noexcept
Definition: ERF_ScalarDiffusion.H:618

Referenced by erf_sbm::erf_detail_SBMTransport::add_high_order_mixing().

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

◆ BuildScalarDiffusionMappedTransfers_S()

void BuildScalarDiffusionMappedTransfers_S ( const amrex::Box &  bx,
const amrex::Array4< const amrex::Real > &  raw_x,
const int  raw_x_comp,
const amrex::Array4< const amrex::Real > &  raw_y,
const int  raw_y_comp,
const amrex::Array4< const amrex::Real > &  raw_z,
const int  raw_z_comp,
const amrex::Array4< amrex::Real > &  mapped_x,
const int  mapped_x_comp,
const amrex::Array4< amrex::Real > &  mapped_y,
const int  mapped_y_comp,
const amrex::Array4< amrex::Real > &  mapped_z,
const int  mapped_z_comp,
const amrex::Array4< const amrex::Real > &  ax,
const amrex::Array4< const amrex::Real > &  ay,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_my 
)
inline

Materialize the canonical S-grid face transfers. ax/ay restore the side Jacobian measure omitted by the native S-grid divergence; detJ and the computational z spacing are supplied separately to the mapped divergence.

1396 {
1397  const amrex::Box xbx = amrex::surroundingNodes(bx, 0);
1398  const amrex::Box ybx = amrex::surroundingNodes(bx, 1);
1399  const amrex::Box zbx = amrex::surroundingNodes(bx, 2);
1401  xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1402  mapped_x(i, j, k, mapped_x_comp) =
1404  raw_x(i, j, k, raw_x_comp), ax(i, j, k));
1405  });
1407  ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1408  mapped_y(i, j, k, mapped_y_comp) =
1410  raw_y(i, j, k, raw_y_comp), ay(i, j, k));
1411  });
1413  zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1414  mapped_z(i, j, k, mapped_z_comp) =
1416  raw_z(i, j, k, raw_z_comp), mf_mx(i, j, 0), mf_my(i, j, 0));
1417  });
1418 }

Referenced by erf_sbm::erf_detail_SBMTransport::add_high_order_mixing().

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

◆ BuildScalarDiffusionMappedTransfers_T()

void BuildScalarDiffusionMappedTransfers_T ( const amrex::Box &  bx,
const amrex::Box &  domain,
const amrex::Array4< const amrex::Real > &  raw_x,
const amrex::Array4< const amrex::Real > &  raw_y,
const amrex::Array4< const amrex::Real > &  raw_z,
const int  raw_flux_comp,
const amrex::Array4< amrex::Real > &  mapped_x,
const int  mapped_x_comp,
const amrex::Array4< amrex::Real > &  mapped_y,
const int  mapped_y_comp,
const amrex::Array4< amrex::Real > &  mapped_z,
const int  mapped_z_comp,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::Array4< const amrex::Real > &  ax,
const amrex::Array4< const amrex::Real > &  ay,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_uy,
const amrex::Array4< const amrex::Real > &  mf_my,
const amrex::Array4< const amrex::Real > &  mf_vx,
const bool  suppress_lower_surface_z_transfer,
const bool  suppress_upper_z_transfer = false 
)
inline

Materialize the canonical terrain-following transfers using ERF's existing face mappings and authoritative Gz construction. The lower suppression switch zeros the complete lower transfer, including terrain cross terms.

Corresponding directional inputs and outputs may alias in place, including the same component. The z transfer is launched first on AMReX's ordered execution stream so it reads raw x/y fluxes before the x/y mapping launches can overwrite them. Cross-direction aliasing is not supported.

For each interior z face mapped from bx, raw_x and raw_y must be valid at both kface and kface-1. Thus, if bx.smallEnd(2) is above the domain bottom, raw_x/raw_y must include bx.smallEnd(2)-1; if bx.bigEnd(2) is below the domain top, they must include bx.bigEnd(2)+1. No outside-domain layer is required at a physical bottom/top face because the Gz helper uses one-sided extrapolation. Raw candidates produced by BuildScalarDiffusionFluxes_T already provide this z coverage.

1462 {
1463  const amrex::Box xbx = amrex::surroundingNodes(bx, 0);
1464  const amrex::Box ybx = amrex::surroundingNodes(bx, 1);
1465  const amrex::Box zbx = amrex::surroundingNodes(bx, 2);
1466  const amrex::Array4<const amrex::Real> xflux(raw_x);
1467  const amrex::Array4<const amrex::Real> yflux(raw_y);
1468  const amrex::Array4<const amrex::Real> zflux(raw_z);
1470  zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1471  const bool suppress =
1472  (suppress_lower_surface_z_transfer && k == domain.smallEnd(2)) ||
1473  (suppress_upper_z_transfer && k == domain.bigEnd(2) + 1);
1474  mapped_z(i, j, k, mapped_z_comp) =
1476  i, j, k, domain, xflux, yflux, zflux, raw_flux_comp, z_nd,
1477  cellSizeInv, mf_mx, mf_my, suppress);
1478  });
1479  amrex::ParallelFor(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1480  mapped_x(i, j, k, mapped_x_comp) = TerrainDiffusionMappedTx(
1481  raw_x(i, j, k, raw_flux_comp), ax(i, j, k), mf_uy(i, j, 0));
1482  });
1483  amrex::ParallelFor(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1484  mapped_y(i, j, k, mapped_y_comp) = TerrainDiffusionMappedTy(
1485  raw_y(i, j, k, raw_flux_comp), ay(i, j, k), mf_vx(i, j, 0));
1486  });
1487 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionMappedTransferAtKFace(const int i, const int j, const int kface, const amrex::Box &domain, const amrex::Array4< const amrex::Real > &raw_xflux, const amrex::Array4< const amrex::Real > &raw_yflux, const amrex::Array4< const amrex::Real > &raw_zflux, const int flux_comp, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const bool suppress_transfer=false) noexcept
Definition: ERF_ScalarDiffusion.H:704

Referenced by erf_sbm::erf_detail_SBMTransport::build_terrain_high_order_mixing().

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

◆ ScalarDiffusionFaceCoefficient()

template<bool MultiplyMolecularByDensity, bool AddTurbulence>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFaceCoefficient ( const amrex::Array4< const amrex::Real > &  rho,
const int  rho_comp,
const amrex::Array4< const amrex::Real > &  mu_turb,
const ScalarDiffusionCoefficients &  coefficients,
const int  i,
const int  j,
const int  k,
const int  di,
const int  dj,
const int  dk,
const int  eddy_comp 
)
noexcept

Density-weighted face transport coefficient. The booleans are compile-time choices for ConstantAlpha/Constant/None and turbulent/no-turbulence modes; turbulent coefficients are already density weighted and are never multiplied by rho here.

rho_comp and the eddy component are independent of the scalar component.

126 {
127  amrex::Real coeff = coefficients.molecular_coeff;
128  if constexpr (MultiplyMolecularByDensity) {
129  coeff *= amrex::Real(0.5) *
130  (rho(i, j, k, rho_comp) + rho(i - di, j - dj, k - dk, rho_comp));
131  }
132  if constexpr (AddTurbulence) {
133  coeff += amrex::Real(0.5) * (mu_turb(i, j, k, eddy_comp) +
134  mu_turb(i - di, j - dj, k - dk, eddy_comp));
135  }
136  return coeff;
137 }
@ rho
Definition: ERF_Kessler.H:25
real(c_double), private di
Definition: ERF_module_mp_morr_two_moment.F90:203
amrex::Real molecular_coeff
Definition: ERF_ScalarDiffusion.H:25

Referenced by BuildScalarDiffusionFluxes_N_Impl(), BuildScalarDiffusionFluxes_S_Impl(), BuildScalarDiffusionFluxes_T_Impl(), erf_auxiliary::erf_detail_AuxiliaryDiffusion::fill_transmissibility(), and SubtractTerrainMetricImplicitPart_T_Impl().

Here is the caller graph for this function:

◆ ScalarDiffusionFlux_N()

template<int Direction>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_N ( const amrex::Array4< const amrex::Real > &  scalar,
const int  scalar_comp,
const int  i,
const int  j,
const int  k,
const amrex::Real  coeff,
const amrex::Real  inv_spacing,
const amrex::Real  map_numerator,
const amrex::Real  map_denominator,
const bool  ext_dir_lo,
const bool  ext_dir_hi 
)
noexcept

Compute the existing N-grid signed face flux, F^D=-K grad(chi). scalar_comp selects the intensive scalar and flux_comp is applied by the caller to its independent face-flux view. Horizontal map-factor numerator and denominator remain separate to preserve the native arithmetic association. Physical Dirichlet flags select the legacy one-sided stencil; ext_dir_upwind selection stays in the adapter.

270 {
271  static_assert(Direction >= 0 && Direction < 3);
272  amrex::Real grad;
273  if constexpr (Direction == 0 || Direction == 1) {
274  grad = ScalarDiffusionHorizontalDelta<Direction>(
275  scalar, scalar_comp, i, j, k, ext_dir_lo, ext_dir_hi);
276  } else {
277  if (ext_dir_lo) {
278  grad = -(amrex::Real(8.0) / amrex::Real(3.0)) *
279  scalar(i, j, k - 1, scalar_comp) +
280  amrex::Real(3.0) * scalar(i, j, k, scalar_comp) -
281  (amrex::Real(1.0) / amrex::Real(3.0)) *
282  scalar(i, j, k + 1, scalar_comp);
283  } else if (ext_dir_hi) {
284  grad =
285  (amrex::Real(8.0) / amrex::Real(3.0)) * scalar(i, j, k, scalar_comp) -
286  amrex::Real(3.0) * scalar(i, j, k - 1, scalar_comp) +
287  (amrex::Real(1.0) / amrex::Real(3.0)) *
288  scalar(i, j, k - 2, scalar_comp);
289  } else {
290  grad = scalar(i, j, k, scalar_comp) - scalar(i, j, k - 1, scalar_comp);
291  }
292  }
293  if constexpr (Direction == 2) {
294  return -coeff * grad * inv_spacing;
295  } else {
296  return -coeff * grad * inv_spacing * map_numerator / map_denominator;
297  }
298 }

◆ ScalarDiffusionFlux_S_Horizontal()

template<int Direction>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_S_Horizontal ( const amrex::Array4< const amrex::Real > &  scalar,
const int  scalar_comp,
const int  i,
const int  j,
const int  k,
const amrex::Real  coeff,
const amrex::Real  inv_spacing,
const amrex::Real  face_map,
const bool  ext_dir_lo,
const bool  ext_dir_hi 
)
noexcept

Existing S-grid horizontal raw flux before its separate map-factor adjustment kernel. The horizontal spacing is uniform, so an open domain face takes the N-grid one-sided stencil (ScalarDiffusionHorizontalDelta).

354 {
355  static_assert(Direction == 0 || Direction == 1);
356  const amrex::Real delta = ScalarDiffusionHorizontalDelta<Direction>(
357  scalar, scalar_comp, i, j, k, ext_dir_lo, ext_dir_hi);
358  const amrex::Real gradient = inv_spacing * delta;
359  return -coeff * face_map * gradient;
360 }

◆ ScalarDiffusionFlux_Tx()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_Tx ( const amrex::Real  coeff,
const amrex::Real  face_map,
const amrex::Real  grad_xi,
const amrex::Real  h_xi,
const amrex::Real  grad_z 
)
noexcept
369 {
370  return -coeff * face_map * (grad_xi - h_xi * grad_z);
371 }

Referenced by TerrainScalarDiffusionFluxAtIFace().

Here is the caller graph for this function:

◆ ScalarDiffusionFlux_Ty()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_Ty ( const amrex::Real  coeff,
const amrex::Real  face_map,
const amrex::Real  grad_eta,
const amrex::Real  h_eta,
const amrex::Real  grad_z 
)
noexcept
380 {
381  return -coeff * face_map * (grad_eta - h_eta * grad_z);
382 }

Referenced by TerrainScalarDiffusionFluxAtJFace().

Here is the caller graph for this function:

◆ ScalarDiffusionHorizontalDelta()

template<int Direction>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionHorizontalDelta ( const amrex::Array4< const amrex::Real > &  scalar,
const int  scalar_comp,
const int  i,
const int  j,
const int  k,
const bool  ext_dir_lo,
const bool  ext_dir_hi 
)
noexcept

The horizontal difference of the scalar at an x (Direction 0) or y (Direction 1) face: its gradient there times the cell size. At an open domain face (ext_dir_lo / ext_dir_hi, from ScalarDiffusionLateralExtDir) the ghost cell holds the face value, half a cell from the edge-cell center, and the (-8/3, 3, -1/3) stencil gives the gradient to the face to second order; elsewhere it is the two-point difference.

227 {
228  static_assert(Direction == 0 || Direction == 1);
229  constexpr int di = Direction == 0 ? 1 : 0;
230  constexpr int dj = Direction == 1 ? 1 : 0;
231  if (ext_dir_lo) {
232  return -(amrex::Real(8.0) / amrex::Real(3.0)) *
233  scalar(i - di, j - dj, k, scalar_comp) +
234  amrex::Real(3.0) * scalar(i, j, k, scalar_comp) -
235  (amrex::Real(1.0) / amrex::Real(3.0)) *
236  scalar(i + di, j + dj, k, scalar_comp);
237  }
238  if (ext_dir_hi) {
239  return
240  (amrex::Real(8.0) / amrex::Real(3.0)) * scalar(i, j, k, scalar_comp) -
241  amrex::Real(3.0) * scalar(i - di, j - dj, k, scalar_comp) +
242  (amrex::Real(1.0) / amrex::Real(3.0)) *
243  scalar(i - 2 * di, j - 2 * dj, k, scalar_comp);
244  }
245  return scalar(i, j, k, scalar_comp) - scalar(i - di, j - dj, k, scalar_comp);
246 }

◆ ScalarDiffusionLateralExtDir()

template<int Direction>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ScalarDiffusionLateralExtDir ( const amrex::BCRec &  bc,
const amrex::Array4< const amrex::Real > &  vel,
const int  i,
const int  j,
const int  k,
const amrex::Dim3 &  dom_lo,
const amrex::Dim3 &  dom_hi,
bool &  ext_lo,
bool &  ext_hi 
)
noexcept

Whether the x (Direction 0) or y (Direction 1) face at (i, j, k) is an open domain face whose diffusive flux takes the one-sided stencil against the face value held in the ghost cell: ext_dir, ext_dir_prim, or ext_dir_upwind where the face velocity vel points into the domain. The face index is tested first, so vel is read only on a domain face with ext_dir_upwind (a box away from the domain face holds no velocity there, and a caller whose BCs never use ext_dir_upwind may pass an empty array).

The stencil this selects assumes the ghost cell holds the scalar at the face point of the same cell row: on a terrain-fitted grid, at that row's height on the face. A ghost filled at another height (for example a profile interpolated to flat-grid levels while the boundary terrain is raised) gives a flux error at the face of order one that does not shrink with dx, about 8/3 times the error of the two-point difference (erf-model/ERF#5391).

183 {
184  static_assert(Direction == 0 || Direction == 1);
185  const int n = Direction == 0 ? i : j;
186  const int face_lo = Direction == 0 ? dom_lo.x : dom_lo.y;
187  const int face_hi = (Direction == 0 ? dom_hi.x : dom_hi.y) + 1;
188  ext_lo = false;
189  ext_hi = false;
190  if (n == face_lo) {
191  const int type = bc.lo(Direction);
192  if (type == ERFBCType::ext_dir || type == ERFBCType::ext_dir_prim) {
193  ext_lo = true;
194  } else if (type == ERFBCType::ext_dir_upwind) {
195  AMREX_ASSERT(vel.dataPtr() != nullptr);
196  ext_lo = vel(i, j, k) >= amrex::Real(0.0);
197  }
198  } else if (n == face_hi) {
199  const int type = bc.hi(Direction);
200  if (type == ERFBCType::ext_dir || type == ERFBCType::ext_dir_prim) {
201  ext_hi = true;
202  } else if (type == ERFBCType::ext_dir_upwind) {
203  AMREX_ASSERT(vel.dataPtr() != nullptr);
204  ext_hi = vel(i, j, k) <= amrex::Real(0.0);
205  }
206  }
207 }
@ ext_dir_upwind
Definition: ERF_IndexDefines.H:325
real(c_double), private bc
Definition: ERF_module_mp_morr_two_moment.F90:182

◆ ScalarDiffusionMappedFluxDivergence()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionMappedFluxDivergence ( const amrex::Real  fx_hi,
const amrex::Real  fx_lo,
const amrex::Real  fy_hi,
const amrex::Real  fy_lo,
const amrex::Real  fz_hi,
const amrex::Real  fz_lo,
const amrex::Real  dx_inv,
const amrex::Real  dy_inv,
const amrex::Real  dzeta_inv,
const amrex::Real  mx,
const amrex::Real  my,
const amrex::Real  detJ_cell 
)
noexcept

Return the positive geometry-weighted mapped flux divergence. For detJ_cell <= 0, return zero without dividing. The diffusion array wrapper subtracts this value from the existing RHS.

746 {
747  if (detJ_cell <= amrex::Real(0.0))
748  return amrex::Real(0.0);
749  const amrex::Real map_over_jacobian = (mx * my) / detJ_cell;
750  return map_over_jacobian *
751  ((fx_hi - fx_lo) * dx_inv + (fy_hi - fy_lo) * dy_inv +
752  (fz_hi - fz_lo) * dzeta_inv);
753 }

Referenced by ApplyScalarMappedFluxDivergence().

Here is the caller graph for this function:

◆ ScalarDiffusionMappedHorizontalTransfer()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionMappedHorizontalTransfer ( const amrex::Real  raw_flux,
const amrex::Real  face_area 
)
noexcept

Pointwise conversion to ERF's mapped conservative face-transfer convention. The transfer is an instantaneous rate and includes the supplied face-area measure; callers must not apply that measure again in the divergence.

612 {
613  return raw_flux * face_area;
614 }

Referenced by BuildScalarDiffusionMappedTransfers_N(), BuildScalarDiffusionMappedTransfers_S(), and erf_auxiliary::erf_detail_AuxiliaryDiffusion::fill_transmissibility().

Here is the caller graph for this function:

◆ ScalarDiffusionMappedVerticalTransfer()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionMappedVerticalTransfer ( const amrex::Real  raw_flux,
const amrex::Real  mx,
const amrex::Real  my 
)
noexcept

Convert a raw vertical diffusion flux to the mapped face-transfer space.

622 {
623  return raw_flux / (mx * my);
624 }

Referenced by BuildScalarDiffusionMappedTransfers_N(), BuildScalarDiffusionMappedTransfers_S(), and TerrainScalarDiffusionMappedTransferAtKFace().

Here is the caller graph for this function:

◆ ScaleScalarDiffusionVerticalFlux()

void ScaleScalarDiffusionVerticalFlux ( const amrex::Box &  zbx,
const amrex::Array4< amrex::Real > &  raw_Fz,
const int  flux_comp,
const amrex::Real  explicit_fac 
)
inline

Scale only raw F_z for the explicit integration fraction.

1738 {
1739  amrex::ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1740  raw_Fz(i, j, k, flux_comp) *= explicit_fac;
1741  });
1742 }

Referenced by DiffusionSrcForState_N(), DiffusionSrcForState_S(), and DiffusionSrcForState_T().

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

◆ StretchedDiffusionDirichletWeights()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE StretchedDiffusionBoundaryWeights StretchedDiffusionDirichletWeights ( const amrex::Real  dz_near,
const amrex::Real  dz_next 
)
noexcept
148 {
149  const amrex::Real f = dz_next / dz_near + amrex::Real(2.0);
150  const amrex::Real f2 = f * f;
151  const amrex::Real c3 = amrex::Real(2.0) / (f - f2);
152  return {-(amrex::Real(1.0) - f2) * c3, -f2 * c3, c3};
153 }

Referenced by StretchedScalarGradient().

Here is the caller graph for this function:

◆ StretchedScalarGradient()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real StretchedScalarGradient ( const amrex::Array4< const amrex::Real > &  scalar,
const int  scalar_comp,
const int  i,
const int  j,
const int  k,
const amrex::Real *  dz,
const int  klo,
const int  khi,
const bool  ext_dir_lo,
const bool  ext_dir_hi 
)
noexcept

Existing S-grid vertical-center gradient, including boundary and tile-edge spacing.

314 {
315  if (ext_dir_lo) {
316  const auto w = StretchedDiffusionDirichletWeights(dz[k], dz[k + 1]);
317  return (amrex::Real(1.0) / dz[k]) *
318  (w.c1 * scalar(i, j, k - 1, scalar_comp) +
319  w.c2 * scalar(i, j, k, scalar_comp) +
320  w.c3 * scalar(i, j, k + 1, scalar_comp));
321  }
322  if (ext_dir_hi) {
323  const auto w = StretchedDiffusionDirichletWeights(dz[k - 1], dz[k - 2]);
324  return (amrex::Real(1.0) / dz[k - 1]) *
325  (-(
326  w.c1 * scalar(i, j, k, scalar_comp) +
327  w.c2 * scalar(i, j, k - 1, scalar_comp) +
328  w.c3 * scalar(i, j, k - 2, scalar_comp)));
329  }
330  const amrex::Real inv = (k == klo) ? amrex::Real(1.0) / dz[k]
331  : (k == khi + 1)
332  ? amrex::Real(1.0) / dz[k - 1]
333  : amrex::Real(2.0) / (dz[k] + dz[k - 1]);
334  return inv *
335  (scalar(i, j, k, scalar_comp) - scalar(i, j, k - 1, scalar_comp));
336 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE StretchedDiffusionBoundaryWeights StretchedDiffusionDirichletWeights(const amrex::Real dz_near, const amrex::Real dz_next) noexcept
Definition: ERF_ScalarDiffusion.H:146

Referenced by BuildScalarDiffusionFluxes_S_Impl().

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

◆ SubtractTerrainMetricImplicitPart_T()

void SubtractTerrainMetricImplicitPart_T ( const amrex::Box &  bx,
const amrex::Box &  domain,
const ScalarDiffusionFieldViews &  field,
const ScalarDiffusionFluxPolicy &  policy,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_my,
const amrex::Real  implicit_fac 
)
inline

Dispatch SubtractTerrainMetricImplicitPart_T_Impl on the coefficient mode.

1711 {
1712  const amrex::Box zbx = amrex::surroundingNodes(bx, 2);
1713  const auto mode = policy.coefficient_mode;
1714  if (mode.molecular_is_kinematic) {
1715  if (mode.add_turbulence) {
1716  SubtractTerrainMetricImplicitPart_T_Impl<true, true>(
1717  zbx, domain, field, policy.coefficients, z_nd, cellSizeInv, mf_mx, mf_my, implicit_fac);
1718  } else {
1719  SubtractTerrainMetricImplicitPart_T_Impl<true, false>(
1720  zbx, domain, field, policy.coefficients, z_nd, cellSizeInv, mf_mx, mf_my, implicit_fac);
1721  }
1722  } else if (mode.add_turbulence) {
1723  SubtractTerrainMetricImplicitPart_T_Impl<false, true>(
1724  zbx, domain, field, policy.coefficients, z_nd, cellSizeInv, mf_mx, mf_my, implicit_fac);
1725  } else {
1726  SubtractTerrainMetricImplicitPart_T_Impl<false, false>(
1727  zbx, domain, field, policy.coefficients, z_nd, cellSizeInv, mf_mx, mf_my, implicit_fac);
1728  }
1729 }

Referenced by DiffusionSrcForState_T().

Here is the caller graph for this function:

◆ SubtractTerrainMetricImplicitPart_T_Impl()

template<bool MultiplyMolecularByDensity, bool AddTurbulence>
void SubtractTerrainMetricImplicitPart_T_Impl ( const amrex::Box &  zbx,
const amrex::Box &  domain,
const ScalarDiffusionFieldViews &  field,
const ScalarDiffusionCoefficients &  coefficients,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_my,
const amrex::Real  implicit_fac 
)
inline

erf.implicit_terrain_metric: the implicit vertical solve also takes the compact terrain-metric flux -K_h M_s dphi/dz (ERF_TerrainImplicitMetric.H) on the interior zeta faces, so add implicit_fac * K_h M_s dphi/dz to the explicit raw F_z there. K_h is the horizontal coefficient of the x/y fluxes, averaged to the z face; the bottom and top faces, which carry the boundary condition, are left alone.

1671 {
1672  using namespace amrex;
1673  const int dom_klo = domain.smallEnd(2);
1674  const int dom_khi = domain.bigEnd(2);
1675  const auto scalar = field.scalar;
1676  const auto density = field.density;
1677  const auto mu_turb = field.mu_turb;
1678  const auto zflux = field.zflux;
1679  const int scalar_comp = field.scalar_comp;
1680  const int rho_comp = field.rho_comp;
1681  const int flux_comp = field.flux_comp;
1682  ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1683  if (!TerrainMetricImplicitFace(k, dom_klo, dom_khi)) { return; }
1684  const Real kh = ScalarDiffusionFaceCoefficient<
1685  MultiplyMolecularByDensity, AddTurbulence>(
1686  density, rho_comp, mu_turb, coefficients, i, j, k, 0, 0, 1,
1687  coefficients.eddy_h_comp);
1688  const Real h_zeta = Compute_h_zeta_AtKface(i, j, k, cellSizeInv, z_nd);
1689  const Real grad_z = (cellSizeInv[2] / h_zeta) *
1690  (scalar(i, j, k, scalar_comp) - scalar(i, j, k - 1, scalar_comp));
1691  const Real metric = TerrainMetricScalarFactor(
1692  Compute_h_xi_AtKface(i, j, k, cellSizeInv, z_nd),
1693  Compute_h_eta_AtKface(i, j, k, cellSizeInv, z_nd),
1694  mf_mx(i, j, 0), mf_my(i, j, 0));
1695  zflux(i, j, k, flux_comp) += implicit_fac * kh * metric * grad_z;
1696  });
1697 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool TerrainMetricImplicitFace(const int kface, const int dom_lo, const int dom_hi) noexcept
Definition: ERF_TerrainImplicitMetric.H:72
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainMetricScalarFactor(const amrex::Real h_xi, const amrex::Real h_eta, const amrex::Real mx, const amrex::Real my) noexcept
Definition: ERF_TerrainImplicitMetric.H:56
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)
Definition: ERF_TerrainMetrics.H:445
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)
Definition: ERF_TerrainMetrics.H:468
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)
Definition: ERF_TerrainMetrics.H:421
int eddy_h_comp
Definition: ERF_ScalarDiffusion.H:26
Here is the call graph for this function:

◆ TerrainDiffusionDivergence_T()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionDivergence_T ( const amrex::Real  mapped_Fx_hi,
const amrex::Real  mapped_Fx_lo,
const amrex::Real  mapped_Fy_hi,
const amrex::Real  mapped_Fy_lo,
const amrex::Real  Gz_hi,
const amrex::Real  Gz_lo,
const amrex::Real  dx_inv,
const amrex::Real  dy_inv,
const amrex::Real  dz_inv,
const amrex::Real  mfsq,
const amrex::Real  detJ_cell 
)
noexcept

Native terrain divergence in the legacy arithmetic association.

769 {
770  amrex::Real stateContrib =
771  (mapped_Fx_hi - mapped_Fx_lo) * dx_inv * mfsq +
772  (mapped_Fy_hi - mapped_Fy_lo) * dy_inv * mfsq +
773  (Gz_hi - Gz_lo) * dz_inv;
774  stateContrib /= detJ_cell;
775  return stateContrib;
776 }

Referenced by ApplyScalarDiffusionMappedDivergence_T().

Here is the caller graph for this function:

◆ TerrainDiffusionGz()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionGz ( const amrex::Real  raw_Fz,
const amrex::Real  mx,
const amrex::Real  h_xi,
const amrex::Real  Fbar_x,
const amrex::Real  my,
const amrex::Real  h_eta,
const amrex::Real  Fbar_y 
)
noexcept

Raw terrain-coordinate F_z and its conservative transformed transfer are distinct quantities. G_z is the numerator F_z - m_x h_xi Fbar_x - m_y h_eta Fbar_y; T_z=G_z/(m_x m_y).

581 {
582  return raw_Fz - h_xi * mx * Fbar_x - h_eta * my * Fbar_y;
583 }

Referenced by TerrainScalarDiffusionGzAtKFace().

Here is the caller graph for this function:

◆ TerrainDiffusionMappedTx()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionMappedTx ( const amrex::Real  raw_Fx,
const amrex::Real  h_zeta,
const amrex::Real  my 
)
noexcept
590 {
591  return raw_Fx * h_zeta / my;
592 }

Referenced by AddScalarDiffusionRefluxFluxes_T(), ApplyScalarDiffusionMappedDivergence_T(), and BuildScalarDiffusionMappedTransfers_T().

Here is the caller graph for this function:

◆ TerrainDiffusionMappedTy()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionMappedTy ( const amrex::Real  raw_Fy,
const amrex::Real  h_zeta,
const amrex::Real  mx 
)
noexcept
599 {
600  return raw_Fy * h_zeta / mx;
601 }

Referenced by AddScalarDiffusionRefluxFluxes_T(), ApplyScalarDiffusionMappedDivergence_T(), and BuildScalarDiffusionMappedTransfers_T().

Here is the caller graph for this function:

◆ TerrainFaceHeightSpacingInv()

template<int Direction>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainFaceHeightSpacingInv ( const amrex::Array4< const amrex::Real > &  z_nd,
const int  i,
const int  j,
const int  k 
)
noexcept

1 / (z(k+1) - z(k-1)) on an x (Direction 0) or y (Direction 1) face, with z(kk) the height of the face center in cell row kk: the mean of the face's four nodes. The vertical derivative of the face trace at an open domain face is taken over this spacing, not over the ghost column's, which sits half a cell outside the face.

398 {
399  static_assert(Direction == 0 || Direction == 1);
400  constexpr int di = Direction == 1 ? 1 : 0;
401  constexpr int dj = Direction == 0 ? 1 : 0;
402  const auto z_face = [&] (const int kk) {
403  return amrex::Real(0.25) *
404  (z_nd(i, j, kk) + z_nd(i + di, j + dj, kk) +
405  z_nd(i, j, kk + 1) + z_nd(i + di, j + dj, kk + 1));
406  };
407  return amrex::Real(1.0) / (z_face(k + 1) - z_face(k - 1));
408 }

◆ TerrainScalarDiffusionFluxAtIFace()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionFluxAtIFace ( const amrex::Array4< const amrex::Real > &  scalar,
const int  scalar_comp,
const amrex::Real  coeff,
const int  i,
const int  j,
const int  k,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::Array4< const amrex::Real > &  z_cc,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  mf_ux,
const bool  ext_dir_lo,
const bool  ext_dir_hi 
)
noexcept

Terrain x-face raw diffusion flux, including ERF's x-face map factor. coeff is the already selected effective face coefficient. Prescribed surface flux replacement is boundary policy and is intentionally outside this geometry primitive. At an open domain face (ext_dir_lo / ext_dir_hi, from ScalarDiffusionLateralExtDir) the ghost column holds the face trace: the x derivative takes the one-sided stencil against it, and the vertical derivative in the cross term is the trace's own, over the face's own height spacing (TerrainFaceHeightSpacingInv).

434 {
435  const amrex::Real h_xi = Compute_h_xi_AtIface(i, j, k, cellSizeInv, z_nd);
436  const amrex::Real idz_hi =
437  amrex::Real(1.0) / (z_cc(i, j, k + 1) - z_cc(i, j, k - 1));
438  const amrex::Real idz_lo =
439  amrex::Real(1.0) / (z_cc(i - 1, j, k + 1) - z_cc(i - 1, j, k - 1));
440  // At an open domain face the ghost column holds the face trace, so the
441  // vertical derivative along the face is that trace's own, over the face's
442  // height spacing; elsewhere it is the average of the two columns.
443  amrex::Real grad_z;
444  if (ext_dir_lo) {
445  grad_z = (scalar(i - 1, j, k + 1, scalar_comp) -
446  scalar(i - 1, j, k - 1, scalar_comp)) *
447  TerrainFaceHeightSpacingInv<0>(z_nd, i, j, k);
448  } else if (ext_dir_hi) {
449  grad_z = (scalar(i, j, k + 1, scalar_comp) -
450  scalar(i, j, k - 1, scalar_comp)) *
451  TerrainFaceHeightSpacingInv<0>(z_nd, i, j, k);
452  } else {
453  grad_z =
454  amrex::Real(0.5) * (scalar(i, j, k + 1, scalar_comp) * idz_hi +
455  scalar(i - 1, j, k + 1, scalar_comp) * idz_lo -
456  scalar(i, j, k - 1, scalar_comp) * idz_hi -
457  scalar(i - 1, j, k - 1, scalar_comp) * idz_lo);
458  }
459  const amrex::Real grad_xi =
460  cellSizeInv[0] * ScalarDiffusionHorizontalDelta<0>(
461  scalar, scalar_comp, i, j, k, ext_dir_lo, ext_dir_hi);
462  return ScalarDiffusionFlux_Tx(coeff, mf_ux(i, j, 0), grad_xi, h_xi, grad_z);
463 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_Tx(const amrex::Real coeff, const amrex::Real face_map, const amrex::Real grad_xi, const amrex::Real h_xi, const amrex::Real grad_z) noexcept
Definition: ERF_ScalarDiffusion.H:363
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 BuildScalarDiffusionFluxes_T_Impl().

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

◆ TerrainScalarDiffusionFluxAtJFace()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionFluxAtJFace ( const amrex::Array4< const amrex::Real > &  scalar,
const int  scalar_comp,
const amrex::Real  coeff,
const int  i,
const int  j,
const int  k,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::Array4< const amrex::Real > &  z_cc,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  mf_vy,
const bool  ext_dir_lo,
const bool  ext_dir_hi 
)
noexcept

Terrain y-face raw diffusion flux, including ERF's y-face map factor; open domain faces as in TerrainScalarDiffusionFluxAtIFace.

481 {
482  const amrex::Real h_eta = Compute_h_eta_AtJface(i, j, k, cellSizeInv, z_nd);
483  const amrex::Real idz_hi =
484  amrex::Real(1.0) / (z_cc(i, j, k + 1) - z_cc(i, j, k - 1));
485  const amrex::Real idz_lo =
486  amrex::Real(1.0) / (z_cc(i, j - 1, k + 1) - z_cc(i, j - 1, k - 1));
487  // At an open domain face the ghost column holds the face trace, so the
488  // vertical derivative along the face is that trace's own, over the face's
489  // height spacing; elsewhere it is the average of the two columns.
490  amrex::Real grad_z;
491  if (ext_dir_lo) {
492  grad_z = (scalar(i, j - 1, k + 1, scalar_comp) -
493  scalar(i, j - 1, k - 1, scalar_comp)) *
494  TerrainFaceHeightSpacingInv<1>(z_nd, i, j, k);
495  } else if (ext_dir_hi) {
496  grad_z = (scalar(i, j, k + 1, scalar_comp) -
497  scalar(i, j, k - 1, scalar_comp)) *
498  TerrainFaceHeightSpacingInv<1>(z_nd, i, j, k);
499  } else {
500  grad_z =
501  amrex::Real(0.5) * (scalar(i, j, k + 1, scalar_comp) * idz_hi +
502  scalar(i, j - 1, k + 1, scalar_comp) * idz_lo -
503  scalar(i, j, k - 1, scalar_comp) * idz_hi -
504  scalar(i, j - 1, k - 1, scalar_comp) * idz_lo);
505  }
506  const amrex::Real grad_eta =
507  cellSizeInv[1] * ScalarDiffusionHorizontalDelta<1>(
508  scalar, scalar_comp, i, j, k, ext_dir_lo, ext_dir_hi);
509  return ScalarDiffusionFlux_Ty(coeff, mf_vy(i, j, 0), grad_eta, h_eta, grad_z);
510 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ScalarDiffusionFlux_Ty(const amrex::Real coeff, const amrex::Real face_map, const amrex::Real grad_eta, const amrex::Real h_eta, const amrex::Real grad_z) noexcept
Definition: ERF_ScalarDiffusion.H:374
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)
Definition: ERF_TerrainMetrics.H:397

Referenced by BuildScalarDiffusionFluxes_T_Impl().

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

◆ TerrainScalarDiffusionFluxAtKFace()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionFluxAtKFace ( const amrex::Array4< const amrex::Real > &  scalar,
const int  scalar_comp,
const amrex::Real  coeff,
const int  i,
const int  j,
const int  kface,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const bool  ext_dir_lo,
const bool  ext_dir_hi 
)
noexcept

Terrain raw vertical diffusion flux at one k face. Dirichlet boundary stencils are selected explicitly by the caller; surface-layer replacement remains separate boundary policy.

529 {
530  amrex::Real grad_z;
531  if (ext_dir_lo) {
532  const amrex::Real zm = Compute_Z_AtWFace(i, j, kface + 1, z_nd);
533  const amrex::Real dz0 = zm - Compute_Z_AtWFace(i, j, kface, z_nd);
534  const amrex::Real dz1 = Compute_Z_AtWFace(i, j, kface + 2, z_nd) - zm;
535  const amrex::Real idz0 = amrex::Real(1.0) / dz0;
536  const amrex::Real f = dz1 / dz0 + amrex::Real(2.0);
537  const amrex::Real f2 = f * f;
538  const amrex::Real c3 = amrex::Real(2.0) / (f - f2);
539  const amrex::Real c2 = -f2 * c3;
540  const amrex::Real c1 = -(amrex::Real(1.0) - f2) * c3;
541  grad_z = idz0 * (c1 * scalar(i, j, kface - 1, scalar_comp) +
542  c2 * scalar(i, j, kface, scalar_comp) +
543  c3 * scalar(i, j, kface + 1, scalar_comp));
544  } else if (ext_dir_hi) {
545  const amrex::Real zm = Compute_Z_AtWFace(i, j, kface - 1, z_nd);
546  const amrex::Real dz0 = Compute_Z_AtWFace(i, j, kface, z_nd) - zm;
547  const amrex::Real dz1 = zm - Compute_Z_AtWFace(i, j, kface - 2, z_nd);
548  const amrex::Real idz0 = amrex::Real(1.0) / dz0;
549  const amrex::Real f = dz1 / dz0 + amrex::Real(2.0);
550  const amrex::Real f2 = f * f;
551  const amrex::Real c3 = amrex::Real(2.0) / (f - f2);
552  const amrex::Real c2 = -f2 * c3;
553  const amrex::Real c1 = -(amrex::Real(1.0) - f2) * c3;
554  grad_z = idz0 * (-(
555  c1 * scalar(i, j, kface, scalar_comp) +
556  c2 * scalar(i, j, kface - 1, scalar_comp) +
557  c3 * scalar(i, j, kface - 2, scalar_comp)));
558  } else {
559  const amrex::Real h_zeta =
560  Compute_h_zeta_AtKface(i, j, kface, cellSizeInv, z_nd);
561  grad_z = (cellSizeInv[2] / h_zeta) * (scalar(i, j, kface, scalar_comp) -
562  scalar(i, j, kface - 1, scalar_comp));
563  }
564  return -coeff * grad_z;
565 }
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
real(c_double), parameter c2
Definition: ERF_module_model_constants.F90:35
real(c_double), private c1
Definition: ERF_module_mp_morr_two_moment.F90:212

Referenced by BuildScalarDiffusionFluxes_T_Impl().

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

◆ TerrainScalarDiffusionGzAtKFace()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionGzAtKFace ( const int  i,
const int  j,
const int  kface,
const amrex::Box &  domain,
const amrex::Array4< const amrex::Real > &  raw_xflux,
const amrex::Array4< const amrex::Real > &  raw_yflux,
const amrex::Array4< const amrex::Real > &  raw_zflux,
const int  flux_comp,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_my 
)
noexcept

Construct the native terrain numerator G_z at one vertical face. This helper owns x/y-face interpolation, physical-boundary extrapolation, and terrain cross terms; native divergence consumes G_z directly.

645 {
646  const int klo = domain.smallEnd(2);
647  const int khi = domain.bigEnd(2) + 1;
648  amrex::Real xbar, ybar;
649 
650  if (kface == klo) {
651  const amrex::Real xlo = myhalf * (raw_xflux(i, j, klo, flux_comp) +
652  raw_xflux(i + 1, j, klo, flux_comp));
653  const amrex::Real xhi = myhalf * (raw_xflux(i, j, klo + 1, flux_comp) +
654  raw_xflux(i + 1, j, klo + 1, flux_comp));
655  xbar = amrex::Real(1.5) * xlo - myhalf * xhi;
656  const amrex::Real ylo = myhalf * (raw_yflux(i, j, klo, flux_comp) +
657  raw_yflux(i, j + 1, klo, flux_comp));
658  const amrex::Real yhi = myhalf * (raw_yflux(i, j, klo + 1, flux_comp) +
659  raw_yflux(i, j + 1, klo + 1, flux_comp));
660  ybar = amrex::Real(1.5) * ylo - myhalf * yhi;
661  } else if (kface == khi) {
662  const amrex::Real xlo = myhalf * (raw_xflux(i, j, khi - 2, flux_comp) +
663  raw_xflux(i + 1, j, khi - 2, flux_comp));
664  const amrex::Real xhi = myhalf * (raw_xflux(i, j, khi - 1, flux_comp) +
665  raw_xflux(i + 1, j, khi - 1, flux_comp));
666  xbar = amrex::Real(1.5) * xhi - myhalf * xlo;
667  const amrex::Real ylo = myhalf * (raw_yflux(i, j, khi - 2, flux_comp) +
668  raw_yflux(i, j + 1, khi - 2, flux_comp));
669  const amrex::Real yhi = myhalf * (raw_yflux(i, j, khi - 1, flux_comp) +
670  raw_yflux(i, j + 1, khi - 1, flux_comp));
671  ybar = amrex::Real(1.5) * yhi - myhalf * ylo;
672  } else {
673  xbar = fourth * (raw_xflux(i, j, kface, flux_comp) +
674  raw_xflux(i + 1, j, kface, flux_comp) +
675  raw_xflux(i, j, kface - 1, flux_comp) +
676  raw_xflux(i + 1, j, kface - 1, flux_comp));
677  ybar = fourth * (raw_yflux(i, j, kface, flux_comp) +
678  raw_yflux(i, j + 1, kface, flux_comp) +
679  raw_yflux(i, j, kface - 1, flux_comp) +
680  raw_yflux(i, j + 1, kface - 1, flux_comp));
681  }
682 
683  const amrex::Real mx = mf_mx(i, j, 0);
684  const amrex::Real my = mf_my(i, j, 0);
685  const amrex::Real h_xi = Compute_h_xi_AtKface(i, j, kface, cellSizeInv, z_nd);
686  const amrex::Real h_eta =
687  Compute_h_eta_AtKface(i, j, kface, cellSizeInv, z_nd);
688  const amrex::Real Gz = TerrainDiffusionGz(
689  raw_zflux(i, j, kface, flux_comp), mx, h_xi, xbar, my, h_eta, ybar);
690  return Gz;
691 }
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainDiffusionGz(const amrex::Real raw_Fz, const amrex::Real mx, const amrex::Real h_xi, const amrex::Real Fbar_x, const amrex::Real my, const amrex::Real h_eta, const amrex::Real Fbar_y) noexcept
Definition: ERF_ScalarDiffusion.H:573

Referenced by AddScalarDiffusionRefluxFluxes_T(), ApplyScalarDiffusionMappedDivergence_T(), and TerrainScalarDiffusionMappedTransferAtKFace().

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

◆ TerrainScalarDiffusionMappedTransferAtKFace()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real TerrainScalarDiffusionMappedTransferAtKFace ( const int  i,
const int  j,
const int  kface,
const amrex::Box &  domain,
const amrex::Array4< const amrex::Real > &  raw_xflux,
const amrex::Array4< const amrex::Real > &  raw_yflux,
const amrex::Array4< const amrex::Real > &  raw_zflux,
const int  flux_comp,
const amrex::Array4< const amrex::Real > &  z_nd,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  cellSizeInv,
const amrex::Array4< const amrex::Real > &  mf_mx,
const amrex::Array4< const amrex::Real > &  mf_my,
const bool  suppress_transfer = false 
)
noexcept

Complete terrain vertical transfer at one k face. Terrain interpolation, boundary extrapolation and cross terms remain owned by the Gz helper above. Set suppress_transfer when the caller's resolved boundary policy suppresses the complete lower terrain-normal transfer.

At an interior k face, raw_xflux and raw_yflux must be valid at kface and kface-1. At the physical bottom or top face, the authoritative Gz helper uses one-sided extrapolation and needs no out-of-domain z layer.

718 {
719  if (suppress_transfer) return amrex::Real(0.0);
720  const amrex::Real Gz = TerrainScalarDiffusionGzAtKFace(
721  i, j, kface, domain, raw_xflux, raw_yflux, raw_zflux, flux_comp, z_nd,
722  cellSizeInv, mf_mx, mf_my);
724  Gz, mf_mx(i, j, 0), mf_my(i, j, 0));
725 }

Referenced by BuildScalarDiffusionMappedTransfers_T().

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