ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ComputeTurbulentViscosity.cpp File Reference
#include "ERF_SurfaceLayer.H"
#include "ERF_EddyViscosity.H"
#include "ERF_Diffusion.H"
#include "ERF_PBLModels.H"
#include "ERF_TileNoZ.H"
#include "ERF_TerrainMetrics.H"
#include "ERF_MoistUtils.H"
#include "ERF_RichardsonNumber.H"
Include dependency graph for ERF_ComputeTurbulentViscosity.cpp:

Functions

void ComputeTurbulentViscosityLES (Vector< std::unique_ptr< MultiFab >> &Tau_lev, const MultiFab &cons_in, MultiFab &eddyViscosity, MultiFab &Hfx1, MultiFab &Hfx2, MultiFab &Hfx3, MultiFab &Diss, const Geometry &geom, bool use_terrain_fitted_coords, Vector< std::unique_ptr< MultiFab >> &mapfac, const std::unique_ptr< MultiFab > &z_phys_nd, const TurbChoice &turbChoice, const Real const_grav, std::unique_ptr< SurfaceLayer > &, const MoistureComponentIndices &moisture_indices, const MultiFab *xvel, const MultiFab *yvel)
 
void ComputeTurbulentViscosityLES_EB (Vector< std::unique_ptr< MultiFab >> &Tau_lev, const MultiFab &cons_in, MultiFab &eddyViscosity, MultiFab &Hfx1, MultiFab &Hfx2, MultiFab &Hfx3, const Geometry &geom, Vector< std::unique_ptr< MultiFab >> &mapfac, const TurbChoice &turbChoice, const Real const_grav, [[maybe_unused]] const SolverChoice &solverChoice, std::unique_ptr< SurfaceLayer > &, const MoistureComponentIndices &moisture_indices, const eb_ &ebfact, const MultiFab *xvel, const MultiFab *yvel)
 
void ComputeTurbulentViscosityRANS (Vector< std::unique_ptr< MultiFab >> &, const MultiFab &cons_in, const MultiFab &wdist, MultiFab &eddyViscosity, MultiFab &Hfx1, MultiFab &Hfx2, MultiFab &Hfx3, MultiFab &Diss, const Geometry &geom, bool use_terrain_fitted_coords, Vector< std::unique_ptr< MultiFab >> &, const std::unique_ptr< MultiFab > &z_phys_nd, const TurbChoice &turbChoice, const Real const_grav, std::unique_ptr< SurfaceLayer > &SurfLayer, const MultiFab *z_0)
 
void ComputeTurbulentViscosity (double dt, const MultiFab &xvel, const MultiFab &yvel, Vector< std::unique_ptr< MultiFab >> &Tau_lev, MultiFab &cons_in, const MultiFab &wdist, MultiFab &eddyViscosity, MultiFab &Hfx1, MultiFab &Hfx2, MultiFab &Hfx3, MultiFab &Diss, const Geometry &geom, Vector< std::unique_ptr< MultiFab >> &mapfac, const std::unique_ptr< MultiFab > &z_phys_nd, const std::unique_ptr< MultiFab > &z_phys_cc, const SolverChoice &solverChoice, std::unique_ptr< SurfaceLayer > &SurfLayer, const MultiFab *z_0, const bool &use_terrain_fitted_coords, const bool &use_moisture, int level, const BCRec *bc_ptr, const eb_ &ebfact, bool vert_only, const MultiFab *qheating_rates)
 

Function Documentation

◆ ComputeTurbulentViscosity()

void ComputeTurbulentViscosity ( double  dt,
const MultiFab &  xvel,
const MultiFab &  yvel,
Vector< std::unique_ptr< MultiFab >> &  Tau_lev,
MultiFab &  cons_in,
const MultiFab &  wdist,
MultiFab &  eddyViscosity,
MultiFab &  Hfx1,
MultiFab &  Hfx2,
MultiFab &  Hfx3,
MultiFab &  Diss,
const Geometry &  geom,
Vector< std::unique_ptr< MultiFab >> &  mapfac,
const std::unique_ptr< MultiFab > &  z_phys_nd,
const std::unique_ptr< MultiFab > &  z_phys_cc,
const SolverChoice solverChoice,
std::unique_ptr< SurfaceLayer > &  SurfLayer,
const MultiFab *  z_0,
const bool &  use_terrain_fitted_coords,
const bool &  use_moisture,
int  level,
const BCRec *  bc_ptr,
const eb_ ebfact,
bool  vert_only,
const MultiFab *  qheating_rates 
)

Wrapper to compute turbulent viscosity with LES or PBL.

Parameters
[in]dttime step
[in]xvelvelocity in x-dir
[in]yvelvelocity in y-dir
[in]Tau_levstrain at this level
[in]cons_incell center conserved quantities
[in]wdistwall distance
[out]eddyViscosityturbulent viscosity
[out]Hfx1heat flux in x-dir
[out]Hfx2heat flux in y-dir
[out]Hfx3heat flux in z-dir
[out]Dissdissipation of turbulent kinetic energy
[in]geomproblem geometry
[in]mapfacmap factors
[in]z_phys_ndnodal physical z coordinates
[in]z_phys_cccell-centered physical z coordinates
[in]solverChoicecontainer with solver, diffusion, and turbulence parameters
[in]SurfLayeroptional surface-layer model
[in]z_0roughness length
[in]use_terrain_fitted_coordsflag for terrain-fitted coordinates
[in]use_moistureflag for moisture physics
[in]levelAMR level
[in]bc_ptrboundary condition records
[in]ebfactEB factories for cell- and face-centered variables
[in]vert_onlyflag for vertical components of eddyViscosity
[in]qheating_ratesradiation heating rates (SW, LW components)
831 {
832  BL_PROFILE_VAR("ComputeTurbulentViscosity()",ComputeTurbulentViscosity);
833  //
834  // In LES mode, the turbulent viscosity is isotropic (unless mix_isotropic is set to false), so
835  // the LES model sets both horizontal and vertical viscosities
836  //
837  // In PBL mode, the primary purpose of the PBL model is to control vertical transport, so the PBL model sets the vertical viscosity.
838  // Optionally, the PBL model can be run in conjunction with an LES model that sets the horizontal viscosity
839  // (this isn’t truly LES, but the model form is the same as Smagorinsky).
840  //
841  // ComputeTurbulentViscosityLES populates the LES viscosity for both horizontal and vertical components.
842  // ComputeTurbulentViscosityPBL computes the PBL viscosity just for the vertical component.
843  //
844 
845  TurbChoice turbChoice = solverChoice.turbChoice[level];
846  const Real const_grav = solverChoice.gravity;
847 
848  if (!SurfLayer) {
849  AMREX_ALWAYS_ASSERT(!vert_only);
850  }
851 
852  bool impose_phys_bcs = true;
853 
854  if (turbChoice.les_type != LESType::None) {
855  if (solverChoice.terrain_type == TerrainType::EB) {
857  cons_in, eddyViscosity,
858  Hfx1, Hfx2, Hfx3,
859  geom,
860  mapfac, turbChoice, const_grav,
861  solverChoice,
862  SurfLayer, solverChoice.moisture_indices,
863  ebfact, &xvel, &yvel);
864  } else {
866  cons_in, eddyViscosity,
867  Hfx1, Hfx2, Hfx3, Diss,
868  geom, use_terrain_fitted_coords,
869  mapfac, z_phys_nd, turbChoice, const_grav,
870  SurfLayer, solverChoice.moisture_indices,
871  &xvel, &yvel);
872  }
873  }
874 
875  if (turbChoice.rans_type != RANSType::None) {
877  cons_in, wdist,
878  eddyViscosity,
879  Hfx1, Hfx2, Hfx3, Diss,
880  geom, use_terrain_fitted_coords,
881  mapfac, z_phys_nd, turbChoice, const_grav,
882  SurfLayer, z_0);
883  }
884 
885  if (turbChoice.pbl_type == PBLType::MYJ) {
886  ComputeDiffusivityMYJ(dt, xvel, yvel, cons_in, eddyViscosity,
887  geom, turbChoice, SurfLayer,
888  use_terrain_fitted_coords, use_moisture,
889  level, bc_ptr, vert_only, z_phys_nd, z_phys_cc,
890  solverChoice.moisture_indices);
891  } else if (turbChoice.pbl_type == PBLType::MYNN25) {
892  ComputeDiffusivityMYNN25(xvel, yvel, cons_in, eddyViscosity,
893  geom, turbChoice, SurfLayer,
894  use_terrain_fitted_coords, use_moisture,
895  level, bc_ptr, vert_only, z_phys_nd, z_phys_cc,
896  solverChoice.moisture_indices);
897  } else if (turbChoice.pbl_type == PBLType::MYNNEDMF) {
898  ComputeDiffusivityMYNNEDMF(xvel, yvel, cons_in, eddyViscosity,
899  geom, turbChoice, SurfLayer,
900  use_terrain_fitted_coords, use_moisture,
901  level, bc_ptr, vert_only, z_phys_nd, z_phys_cc,
902  solverChoice.moisture_indices);
903  } else if (turbChoice.pbl_type == PBLType::YSU) {
904  ComputeDiffusivityYSU(xvel, yvel, cons_in, eddyViscosity,
905  geom, turbChoice, SurfLayer,
906  use_terrain_fitted_coords, use_moisture,
907  level, bc_ptr, vert_only, z_phys_nd, z_phys_cc,
908  solverChoice.moisture_indices);
909  } else if (turbChoice.pbl_type == PBLType::MRF) {
910  ComputeDiffusivityMRF(xvel, yvel, cons_in, eddyViscosity,
911  geom, turbChoice, SurfLayer,
912  use_terrain_fitted_coords, use_moisture,
913  level, bc_ptr, vert_only, z_phys_nd, z_phys_cc,
914  solverChoice.moisture_indices);
915  } else if (turbChoice.pbl_type == PBLType::YSUNew) {
916  ComputeDiffusivityYSUNew(xvel, yvel, cons_in, eddyViscosity,
917  geom, turbChoice, SurfLayer,
918  use_terrain_fitted_coords, use_moisture,
919  level, bc_ptr, vert_only, z_phys_nd, z_phys_cc,
920  solverChoice.moisture_indices,
921  qheating_rates);
922  } else if (turbChoice.uses_shoc_family()) {
923  // NOTE: Nothing to do here. The SHOC class handles setting the vertical
924  // components of eddyDiffs in slow RHS pre.
925  }
926 
927  //
928  // At all levels we need to fill values outside the physical boundary for the LES coeffs.
929  // In addition, for all cases, if at level > 0, we want to fill fine ghost cell values that
930  // overlie coarse grid cells (and that are not in another fine valid region) with
931  // extrapolated values from the interior, rather than interpolating from the coarser level,
932  // since we may be using a different turbulence model there.
933  //
934  // Note: here "covered" refers to "covered by valid region of another grid at this level"
935  // Note: here "physbnd" refers to "cells outside the domain if not periodic"
936  // Note: here "interior" refers to "valid cells, i.e. inside 'my' grid"
937  //
938  {
939  int is_covered = 0;
940  int is_notcovered = 1;
941  int is_physbnd = 2;
942  int is_interior = 3;
943  iMultiFab cc_mask(eddyViscosity.boxArray(),eddyViscosity.DistributionMap(),1,1);
944  cc_mask.BuildMask(geom.Domain(), geom.periodicity(), is_covered, is_notcovered, is_physbnd, is_interior);
945 
946  Box domain = geom.Domain();
947  for (int i = 0; i < AMREX_SPACEDIM; ++i) {
948  if (geom.isPeriodic(i)) {
949  domain.grow(i,1);
950  }
951  }
952 
953  eddyViscosity.FillBoundary(geom.periodicity());
954 
955  int ncomp = eddyViscosity.nComp();
956 
957 #ifdef _OPENMP
958 #pragma omp parallel if (Gpu::notInLaunchRegion())
959 #endif
960  for (MFIter mfi(eddyViscosity); mfi.isValid(); ++mfi)
961  {
962  Box vbx = mfi.validbox();
963 
964  Box planex_lo = mfi.growntilebox(1); planex_lo.setBig(0, vbx.smallEnd(0)-1);
965  Box planey_lo = mfi.growntilebox(1); planey_lo.setBig(1, vbx.smallEnd(1)-1);
966  Box planez_lo = mfi.growntilebox(1); planez_lo.setBig(2, vbx.smallEnd(2)-1);
967 
968  Box planex_hi = mfi.growntilebox(1); planex_hi.setSmall(0, vbx.bigEnd(0)+1);
969  Box planey_hi = mfi.growntilebox(1); planey_hi.setSmall(1, vbx.bigEnd(1)+1);
970  Box planez_hi = mfi.growntilebox(1); planez_hi.setSmall(2, vbx.bigEnd(2)+1);
971 
972  int i_lo = vbx.smallEnd(0); int i_hi = vbx.bigEnd(0);
973  int j_lo = vbx.smallEnd(1); int j_hi = vbx.bigEnd(1);
974  int k_lo = vbx.smallEnd(2); int k_hi = vbx.bigEnd(2);
975 
976  const Array4<Real>& mu_turb = eddyViscosity.array(mfi);
977  const Array4<int>& mask_arr = cc_mask.array(mfi);
978 
979  auto domlo = lbound(domain);
980  auto domhi = ubound(domain);
981 
982  ParallelFor(planex_lo, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
983  {
984  int lj = amrex::min(amrex::max(j, domlo.y), domhi.y);
985  int lk = amrex::min(amrex::max(k, domlo.z), domhi.z);
986  if ((mask_arr(i,j,k) == is_notcovered && mask_arr(i_lo,lj,lk) != is_notcovered) ||
987  (mask_arr(i,j,k) == is_physbnd && i < domlo.x && impose_phys_bcs)) {
988  for (int n = 0; n < ncomp; n++) {
989  mu_turb(i,j,k,n) = mu_turb(i_lo,lj,lk,n);
990  }
991  }
992  });
993  ParallelFor(planex_hi, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
994  {
995  int lj = amrex::min(amrex::max(j, domlo.y), domhi.y);
996  int lk = amrex::min(amrex::max(k, domlo.z), domhi.z);
997  if ((mask_arr(i,j,k) == is_notcovered && mask_arr(i_hi,lj,lk) != is_notcovered) ||
998  (mask_arr(i,j,k) == is_physbnd && i > domhi.x && impose_phys_bcs)) {
999  for (int n = 0; n < ncomp; n++) {
1000  mu_turb(i,j,k,n) = mu_turb(i_hi,lj,lk,n);
1001  }
1002  }
1003  });
1004  ParallelFor(planey_lo, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1005  {
1006  int lk = amrex::min(amrex::max(k, domlo.z), domhi.z);
1007  if ((mask_arr(i,j,k) == is_notcovered && mask_arr(i,j_lo,lk) != is_notcovered) ||
1008  (mask_arr(i,j,k) == is_physbnd && j < domlo.y && impose_phys_bcs)) {
1009  for (int n = 0; n < ncomp; n++) {
1010  mu_turb(i,j,k,n) = mu_turb(i,j_lo,lk,n);
1011  }
1012  }
1013  });
1014  ParallelFor(planey_hi, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1015  {
1016  int lk = amrex::min(amrex::max(k, domlo.z), domhi.z);
1017  if ((mask_arr(i,j,k) == is_notcovered && mask_arr(i,j_hi,lk) != is_notcovered)||
1018  (mask_arr(i,j,k) == is_physbnd && j > domhi.y && impose_phys_bcs)) {
1019  for (int n = 0; n < ncomp; n++) {
1020  mu_turb(i,j,k,n) = mu_turb(i,j_hi,lk,n);
1021  }
1022  }
1023  });
1024  ParallelFor(planez_lo, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1025  {
1026  if ((mask_arr(i,j,k) == is_notcovered && mask_arr(i,j,k_lo) != is_notcovered) ||
1027  (mask_arr(i,j,k) == is_physbnd && k < domlo.z && impose_phys_bcs)) {
1028  for (int n = 0; n < ncomp; n++) {
1029  mu_turb(i,j,k,n) = mu_turb(i,j,k_lo,n);
1030  }
1031  }
1032  });
1033  ParallelFor(planez_hi, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1034  {
1035  if ((mask_arr(i,j,k) == is_notcovered && mask_arr(i,j,k_hi) != is_notcovered) ||
1036  (mask_arr(i,j,k) == is_physbnd && k > domhi.z && impose_phys_bcs)) {
1037  for (int n = 0; n < ncomp; n++) {
1038  mu_turb(i,j,k,n) = mu_turb(i,j,k_hi,n);
1039  }
1040  }
1041  });
1042  } // mfi
1043 
1044  eddyViscosity.FillBoundary(geom.periodicity());
1045  }
1046 }
void ComputeDiffusivityMRF(const MultiFab &xvel, const MultiFab &yvel, const MultiFab &cons_in, MultiFab &eddyViscosity, const Geometry &geom, const TurbChoice &turbChoice, std::unique_ptr< SurfaceLayer > &SurfLayer, bool use_terrain_fitted_coords, bool use_moisture, int level, const BCRec *bc_ptr, bool, const std::unique_ptr< MultiFab > &z_phys_nd, const std::unique_ptr< MultiFab > &z_phys_cc, const MoistureComponentIndices &moisture_indices)
Definition: ERF_ComputeDiffusivityMRF.cpp:14
void ComputeDiffusivityMYJ(double dt, const MultiFab &xvel, const MultiFab &yvel, MultiFab &cons_in, MultiFab &eddyViscosity, const Geometry &geom, const TurbChoice &, std::unique_ptr< SurfaceLayer > &, bool use_terrain_fitted_coords, bool, int, const BCRec *bc_ptr, bool, const std::unique_ptr< MultiFab > &z_phys_nd, const std::unique_ptr< MultiFab > &z_phys_cc, const MoistureComponentIndices &moisture_indices)
Definition: ERF_ComputeDiffusivityMYJ.cpp:13
void ComputeDiffusivityMYNN25(const MultiFab &xvel, const MultiFab &yvel, const MultiFab &cons_in, MultiFab &eddyViscosity, const Geometry &geom, const TurbChoice &turbChoice, std::unique_ptr< SurfaceLayer > &SurfLayer, bool use_terrain_fitted_coords, bool use_moisture, int level, const BCRec *bc_ptr, bool, const std::unique_ptr< MultiFab > &z_phys_nd, const std::unique_ptr< MultiFab > &z_phys_cc, const MoistureComponentIndices &moisture_indices)
Definition: ERF_ComputeDiffusivityMYNN25.cpp:13
void ComputeDiffusivityMYNNEDMF(const MultiFab &xvel, const MultiFab &yvel, const MultiFab &cons_in, MultiFab &eddyViscosity, const Geometry &geom, const TurbChoice &turbChoice, std::unique_ptr< SurfaceLayer > &SurfLayer, bool use_terrain_fitted_coords, bool use_moisture, int level, const BCRec *bc_ptr, bool, const std::unique_ptr< MultiFab > &z_phys_nd, const std::unique_ptr< MultiFab > &z_phys_cc, const MoistureComponentIndices &moisture_indices)
Definition: ERF_ComputeDiffusivityMYNNEDMF.cpp:4177
void ComputeDiffusivityYSUNew(const MultiFab &xvel, const MultiFab &yvel, const MultiFab &cons_in, MultiFab &eddyViscosity, const Geometry &geom, const TurbChoice &turbChoice, std::unique_ptr< SurfaceLayer > &SurfLayer, bool use_terrain_fitted_coords, bool use_moisture, int level, const BCRec *bc_ptr, bool, const std::unique_ptr< MultiFab > &z_phys_nd, const std::unique_ptr< MultiFab > &z_phys_cc, const MoistureComponentIndices &moisture_indices, const MultiFab *qheating_rates)
Definition: ERF_ComputeDiffusivityYSUNew.cpp:17
void ComputeDiffusivityYSU(const MultiFab &xvel, const MultiFab &yvel, const MultiFab &cons_in, MultiFab &eddyViscosity, const Geometry &geom, const TurbChoice &turbChoice, std::unique_ptr< SurfaceLayer > &SurfLayer, bool use_terrain_fitted_coords, bool, int level, const BCRec *bc_ptr, bool, const std::unique_ptr< MultiFab > &z_phys_nd, const std::unique_ptr< MultiFab > &z_phys_cc, const MoistureComponentIndices &moisture_indices)
Definition: ERF_ComputeDiffusivityYSU.cpp:11
void ComputeTurbulentViscosityRANS(Vector< std::unique_ptr< MultiFab >> &, const MultiFab &cons_in, const MultiFab &wdist, MultiFab &eddyViscosity, MultiFab &Hfx1, MultiFab &Hfx2, MultiFab &Hfx3, MultiFab &Diss, const Geometry &geom, bool use_terrain_fitted_coords, Vector< std::unique_ptr< MultiFab >> &, const std::unique_ptr< MultiFab > &z_phys_nd, const TurbChoice &turbChoice, const Real const_grav, std::unique_ptr< SurfaceLayer > &SurfLayer, const MultiFab *z_0)
Definition: ERF_ComputeTurbulentViscosity.cpp:577
void ComputeTurbulentViscosityLES(Vector< std::unique_ptr< MultiFab >> &Tau_lev, const MultiFab &cons_in, MultiFab &eddyViscosity, MultiFab &Hfx1, MultiFab &Hfx2, MultiFab &Hfx3, MultiFab &Diss, const Geometry &geom, bool use_terrain_fitted_coords, Vector< std::unique_ptr< MultiFab >> &mapfac, const std::unique_ptr< MultiFab > &z_phys_nd, const TurbChoice &turbChoice, const Real const_grav, std::unique_ptr< SurfaceLayer > &, const MoistureComponentIndices &moisture_indices, const MultiFab *xvel, const MultiFab *yvel)
Definition: ERF_ComputeTurbulentViscosity.cpp:34
void ComputeTurbulentViscosityLES_EB(Vector< std::unique_ptr< MultiFab >> &Tau_lev, const MultiFab &cons_in, MultiFab &eddyViscosity, MultiFab &Hfx1, MultiFab &Hfx2, MultiFab &Hfx3, const Geometry &geom, Vector< std::unique_ptr< MultiFab >> &mapfac, const TurbChoice &turbChoice, const Real const_grav, [[maybe_unused]] const SolverChoice &solverChoice, std::unique_ptr< SurfaceLayer > &, const MoistureComponentIndices &moisture_indices, const eb_ &ebfact, const MultiFab *xvel, const MultiFab *yvel)
Definition: ERF_ComputeTurbulentViscosity.cpp:340
void ComputeTurbulentViscosity(double dt, const MultiFab &xvel, const MultiFab &yvel, Vector< std::unique_ptr< MultiFab >> &Tau_lev, MultiFab &cons_in, const MultiFab &wdist, MultiFab &eddyViscosity, MultiFab &Hfx1, MultiFab &Hfx2, MultiFab &Hfx3, MultiFab &Diss, const Geometry &geom, Vector< std::unique_ptr< MultiFab >> &mapfac, const std::unique_ptr< MultiFab > &z_phys_nd, const std::unique_ptr< MultiFab > &z_phys_cc, const SolverChoice &solverChoice, std::unique_ptr< SurfaceLayer > &SurfLayer, const MultiFab *z_0, const bool &use_terrain_fitted_coords, const bool &use_moisture, int level, const BCRec *bc_ptr, const eb_ &ebfact, bool vert_only, const MultiFab *qheating_rates)
Definition: ERF_ComputeTurbulentViscosity.cpp:810
const bool use_moisture
Definition: ERF_InitCustomPert_Bomex.H:14
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
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);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Real z_0
Definition: ERF_UpdateWSubsidence_Bomex.H:10
@ xvel
Definition: ERF_IndexDefines.H:177
@ yvel
Definition: ERF_IndexDefines.H:178
amrex::Vector< TurbChoice > turbChoice
Turbulence options for each AMR level.
Definition: ERF_DataStruct.H:1393
amrex::Real gravity
Effective gravitational acceleration.
Definition: ERF_DataStruct.H:1475
static TerrainType terrain_type
Terrain or immersed-boundary representation.
Definition: ERF_DataStruct.H:1368
MoistureComponentIndices moisture_indices
Conserved-state component indices for active moisture species.
Definition: ERF_DataStruct.H:1621
Definition: ERF_TurbStruct.H:114
RANSType rans_type
Selected RANS closure.
Definition: ERF_TurbStruct.H:599
bool uses_shoc_family() const noexcept
Query whether this level uses any SHOC-family PBL scheme.
Definition: ERF_TurbStruct.H:628
LESType les_type
Selected LES closure.
Definition: ERF_TurbStruct.H:557
PBLType pbl_type
Selected PBL closure.
Definition: ERF_TurbStruct.H:604

Referenced by ERF::advance_dycore().

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

◆ ComputeTurbulentViscosityLES()

void ComputeTurbulentViscosityLES ( Vector< std::unique_ptr< MultiFab >> &  Tau_lev,
const MultiFab &  cons_in,
MultiFab &  eddyViscosity,
MultiFab &  Hfx1,
MultiFab &  Hfx2,
MultiFab &  Hfx3,
MultiFab &  Diss,
const Geometry &  geom,
bool  use_terrain_fitted_coords,
Vector< std::unique_ptr< MultiFab >> &  mapfac,
const std::unique_ptr< MultiFab > &  z_phys_nd,
const TurbChoice turbChoice,
const Real  const_grav,
std::unique_ptr< SurfaceLayer > &  ,
const MoistureComponentIndices moisture_indices,
const MultiFab *  xvel,
const MultiFab *  yvel 
)

Function for computing the turbulent viscosity with LES.

Parameters
[in]Tau_levstrain at this level
[in]cons_incell center conserved quantities
[out]eddyViscosityturbulent viscosity
[out]Hfx1heat flux in x-dir
[out]Hfx2heat flux in y-dir
[out]Hfx3heat flux in z-dir
[out]Dissdissipation of turbulent kinetic energy
[in]geomproblem geometry
[in]use_terrain_fitted_coordsflag for terrain-fitted coordinates
[in]mapfacmap factors
[in]z_phys_ndnodal physical z coordinates
[in]turbChoicecontainer with turbulence parameters
[in]const_gravgravitational acceleration
[in]moisture_indicesmoisture component indices
[in]xvelx-direction velocity (for moist Ri correction)
[in]yvely-direction velocity (for moist Ri correction)
45 {
46  const GpuArray<Real, AMREX_SPACEDIM> cellSizeInv = geom.InvCellSizeArray();
47  const Box& domain = geom.Domain();
48 
49  Real inv_Pr_t = turbChoice.Pr_t_inv;
50  Real inv_Sc_t = turbChoice.Sc_t_inv;
51  Real inv_sigma_k = one / turbChoice.sigma_k;
52 
53  bool use_thetav_grad = (turbChoice.strat_type == StratType::thetav);
54  bool use_thetal_grad = (turbChoice.strat_type == StratType::thetal);
55 
56  bool isotropic = turbChoice.mix_isotropic;
57 
58  // SMAGORINSKY: Fill Kturb for momentum in horizontal and vertical
59  //***********************************************************************************
60  if (turbChoice.les_type == LESType::Smagorinsky)
61  {
62  Real Cs = turbChoice.Cs;
63  bool smag2d = turbChoice.smag2d;
64 
65  // Define variables required inside device lambdas (scalars only)
66  Real l_abs_g = const_grav;
67  Real l_Ri_crit = turbChoice.Ri_crit;
68  bool l_use_Ri_corr = turbChoice.use_Ri_correction;
69  bool l_has_xvel = (xvel != nullptr);
70  bool l_has_yvel = (yvel != nullptr);
71 
72 #ifdef _OPENMP
73 #pragma omp parallel if (Gpu::notInLaunchRegion())
74 #endif
75  for (MFIter mfi(eddyViscosity,TilingIfNotGPU()); mfi.isValid(); ++mfi)
76  {
77  Box bxcc = mfi.growntilebox(1) & domain;
78  const Array4<Real>& mu_turb = eddyViscosity.array(mfi);
79  const Array4<Real>& hfx_x = Hfx1.array(mfi);
80  const Array4<Real>& hfx_y = Hfx2.array(mfi);
81  const Array4<Real>& hfx_z = Hfx3.array(mfi);
82  const Array4<Real const >& cell_data = cons_in.array(mfi);
83  Array4<Real const> tau11 = Tau_lev[TauType::tau11]->array(mfi);
84  Array4<Real const> tau22 = Tau_lev[TauType::tau22]->array(mfi);
85  Array4<Real const> tau33 = Tau_lev[TauType::tau33]->array(mfi);
86  Array4<Real const> tau12 = Tau_lev[TauType::tau12]->array(mfi);
87  Array4<Real const> tau13 = Tau_lev[TauType::tau13]->array(mfi);
88  Array4<Real const> tau23 = Tau_lev[TauType::tau23]->array(mfi);
89  Array4<Real const> mf_u = mapfac[MapFacType::u_x]->const_array(mfi);
90  Array4<Real const> mf_v = mapfac[MapFacType::v_y]->const_array(mfi);
91  Array4<Real const> z_nd_arr = z_phys_nd->const_array(mfi);
92 
93  Array4<Real const> u_arr = (l_has_xvel) ? xvel->const_array(mfi) : Array4<Real const>{};
94  Array4<Real const> v_arr = (l_has_yvel) ? yvel->const_array(mfi) : Array4<Real const>{};
95 
96  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
97  {
98  // =====================================================================
99  // one STRAIN RATE MAGNITUDE CALCULATION
100  // =====================================================================
101  Real SmnSmn;
102  if (smag2d) {
103  SmnSmn = ComputeSmnSmn2D(i,j,k,tau11,tau22,tau12);
104  } else {
105  SmnSmn = ComputeSmnSmn(i,j,k,tau11,tau22,tau33,tau12,tau13,tau23);
106  }
107  Real strain_rate_magnitude = std::sqrt(two * SmnSmn);
108 
109  // =====================================================================
110  // two GRID SCALE CALCULATION (filter width Δ)
111  // =====================================================================
112  Real dxInv = cellSizeInv[0];
113  Real dyInv = cellSizeInv[1];
114  Real dzInv = cellSizeInv[2];
115  if (use_terrain_fitted_coords) {
116  dzInv /= Compute_h_zeta_AtCellCenter(i,j,k, cellSizeInv, z_nd_arr);
117  }
118 
119  Real Delta;
120  Real DeltaH;
121  if (isotropic) {
122  Real cellVolMsf = one / (dxInv * mf_u(i,j,0) * dyInv * mf_v(i,j,0) * dzInv);
123  Delta = std::cbrt(cellVolMsf);
124  DeltaH = Delta;
125  } else {
126  Delta = one / dzInv;
127  DeltaH = std::sqrt(one / (dxInv * mf_u(i,j,0) * dyInv * mf_v(i,j,0)));
128  }
129 
130  Real rho = cell_data(i, j, k, Rho_comp);
131  Real CsDeltaSqr_h = Cs * Cs * DeltaH * DeltaH;
132  Real CsDeltaSqr_v = Cs * Cs * Delta * Delta;
133 
134  Real nu_turb_base_h = CsDeltaSqr_h * strain_rate_magnitude;
135  Real nu_turb_base_v = CsDeltaSqr_v * strain_rate_magnitude;
136 
137  Real stability_factor = one;
138 
139  if (l_use_Ri_corr && l_has_xvel && l_has_yvel) {
140  Real N2 = ComputeN2(i, j, k, dzInv, l_abs_g, cell_data, moisture_indices);
141  Real S2_vert = ComputeVerticalShear2(i, j, k, dzInv, u_arr, v_arr);
142  Real Ri = ComputeRichardson(N2, S2_vert);
143  stability_factor = StabilityFunction(Ri, l_Ri_crit);
144  }
145 
146  if (isotropic) {
147  mu_turb(i, j, k, EddyDiff::Mom_h) = rho * nu_turb_base_h * stability_factor;
148  mu_turb(i, j, k, EddyDiff::Mom_v) = rho * nu_turb_base_v * stability_factor;
149  } else {
150  mu_turb(i, j, k, EddyDiff::Mom_h) = rho * nu_turb_base_h;
151  mu_turb(i, j, k, EddyDiff::Mom_v) = rho * nu_turb_base_v * stability_factor;
152  }
153 
154  Real dtheta_dz = myhalf * ( cell_data(i,j,k+1,RhoTheta_comp)/cell_data(i,j,k+1,Rho_comp)
155  - cell_data(i,j,k-1,RhoTheta_comp)/cell_data(i,j,k-1,Rho_comp) )*dzInv;
156 
157  hfx_x(i,j,k) = zero;
158  hfx_y(i,j,k) = zero;
159  hfx_z(i,j,k) = -inv_Pr_t * mu_turb(i,j,k,EddyDiff::Mom_v) * dtheta_dz;
160  });
161  }
162  }
163  // DEARDORFF: Fill Kturb for momentum in horizontal and vertical
164  //***********************************************************************************
165  else if (turbChoice.les_type == LESType::Deardorff)
166  {
167  const Real l_C_k = turbChoice.Ck;
168  const Real l_C_e = turbChoice.Ce;
169  const Real l_C_e_wall = turbChoice.Ce_wall;
170  const Real Ce_lcoeff = amrex::max(zero, l_C_e - Real(1.9)*l_C_k);
171  const Real l_abs_g = const_grav;
172 
173  const bool use_ref_theta = (turbChoice.theta_ref > 0);
174  const Real l_inv_theta0 = (use_ref_theta) ? one / turbChoice.theta_ref : one;
175 
176 #ifdef _OPENMP
177 #pragma omp parallel if (Gpu::notInLaunchRegion())
178 #endif
179  for ( MFIter mfi(eddyViscosity,TilingIfNotGPU()); mfi.isValid(); ++mfi)
180  {
181  Box bxcc = mfi.tilebox();
182 
183  const Array4<Real>& mu_turb = eddyViscosity.array(mfi);
184  const Array4<Real>& hfx_x = Hfx1.array(mfi);
185  const Array4<Real>& hfx_y = Hfx2.array(mfi);
186  const Array4<Real>& hfx_z = Hfx3.array(mfi);
187  const Array4<Real>& diss = Diss.array(mfi);
188 
189  const Array4<Real const > &cell_data = cons_in.array(mfi);
190 
191  Array4<Real const> mf_u = mapfac[MapFacType::u_x]->const_array(mfi);
192  Array4<Real const> mf_v = mapfac[MapFacType::v_y]->const_array(mfi);
193 
194  Array4<Real const> z_nd_arr = z_phys_nd->const_array(mfi);
195 
196  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
197  {
198  Real dxInv = cellSizeInv[0];
199  Real dyInv = cellSizeInv[1];
200  Real dzInv = cellSizeInv[2];
201  if (use_terrain_fitted_coords) {
202  // the terrain grid is only deformed in z for now
203  dzInv /= Compute_h_zeta_AtCellCenter(i,j,k, cellSizeInv, z_nd_arr);
204  }
205  Real Delta;
206  if (isotropic) {
207  Real cellVolMsf = one / (dxInv * mf_u(i,j,0) * dyInv * mf_v(i,j,0) * dzInv);
208  Delta = std::cbrt(cellVolMsf);
209  } else {
210  Delta = one / dzInv;
211  }
212 
213  Real dtheta_dz;
214  if (use_thetav_grad) {
215  dtheta_dz = myhalf * ( GetThetav(i, j, k+1, cell_data, moisture_indices)
216  -GetThetav(i, j, k-1, cell_data, moisture_indices) )*dzInv;
217  } else if (use_thetal_grad) {
218  dtheta_dz = myhalf * ( GetThetal(i, j, k+1, cell_data, moisture_indices)
219  -GetThetal(i, j, k-1, cell_data, moisture_indices) )*dzInv;
220  } else {
221  dtheta_dz = myhalf * ( cell_data(i, j, k+1, RhoTheta_comp) / cell_data(i, j, k+1, Rho_comp)
222  -cell_data(i, j, k-1, RhoTheta_comp) / cell_data(i, j, k-1, Rho_comp) )*dzInv;
223  }
224 
225  // Calculate stratification-dependent mixing length (Deardorff 1980, Eqn. 10a)
226  Real E = amrex::max(cell_data(i,j,k,RhoKE_comp)/cell_data(i,j,k,Rho_comp),Real(0.0));
227  Real stratification = l_abs_g * dtheta_dz * l_inv_theta0;
228  if (!use_ref_theta) {
229  // l_inv_theta0 == 1, divide by actual theta
230  stratification *= cell_data(i,j,k,Rho_comp) /
231  cell_data(i,j,k,RhoTheta_comp);
232  }
233 
234  // Following WRF, the stratification effects are applied to the vertical length scales
235  // in the case of anisotropic mixing
236  Real length;
238  if (stratification <= eps) {
239  length = Delta; // cbrt(dx*dy*dz) -or- dz
240  } else {
241  length = Real(0.76) * std::sqrt(E / amrex::max(stratification,eps));
242  // mixing length should be _reduced_ for stable stratification
243  length = amrex::min(length, Delta);
244  // following WRF, make sure the mixing length isn't too small
245  length = amrex::max(length, Real(0.001) * Delta);
246  }
247 
248  Real DeltaH = (isotropic) ? length : std::sqrt(one / (dxInv * mf_u(i,j,0) * dyInv * mf_v(i,j,0)));
249 
250  Real Pr_inv_v = (one + two*length/Delta);
251  Real Pr_inv_h = (isotropic) ? Pr_inv_v : inv_Pr_t;
252 
253  // Calculate eddy diffusivities
254  // K = rho * C_k * l * KE^(1/2)
255  mu_turb(i,j,k,EddyDiff::Mom_h) = cell_data(i,j,k,Rho_comp) * l_C_k * DeltaH * std::sqrt(E);
256  mu_turb(i,j,k,EddyDiff::Mom_v) = cell_data(i,j,k,Rho_comp) * l_C_k * length * std::sqrt(E);
257  // KH = (1 + 2*l/delta) * mu_turb
258  mu_turb(i,j,k,EddyDiff::Theta_h) = Pr_inv_h * mu_turb(i,j,k,EddyDiff::Mom_h);
259  mu_turb(i,j,k,EddyDiff::Theta_v) = Pr_inv_v * mu_turb(i,j,k,EddyDiff::Mom_v);
260  // Store lengthscale for TKE source terms
261  mu_turb(i,j,k,EddyDiff::Turb_lengthscale) = length;
262 
263  // Calculate SFS quantities
264  // - dissipation
265  Real Ce;
266  if ((l_C_e_wall > 0) && (k==0)) {
267  Ce = l_C_e_wall;
268  } else {
269  Ce = Real(1.9)*l_C_k + Ce_lcoeff*length / Delta;
270  }
271  diss(i,j,k) = cell_data(i,j,k,Rho_comp) * Ce * std::pow(E,Real(1.5)) / length;
272 
273  // - heat flux
274  // (Note: If using SurfaceLayer, the value at k=0 will
275  // be overwritten)
276  hfx_x(i,j,k) = zero;
277  hfx_y(i,j,k) = zero;
278  hfx_z(i,j,k) = -mu_turb(i,j,k,EddyDiff::Theta_v) * dtheta_dz; // (rho*w)' theta' [kg m^-2 s^-1 K]
279  });
280  }
281  }
282 
283  // Extrapolate Kturb in x/y, fill remaining elements (relevant to lev==0)
284  //***********************************************************************************
285  int ngc(1);
286  // EddyDiff mapping : Theta_h KE_h Scalar_h Q_h
287  Vector<Real> Factors = {inv_Pr_t, inv_sigma_k, inv_Sc_t, inv_Sc_t}; // alpha = mu/Pr
288  Gpu::AsyncVector<Real> d_Factors; d_Factors.resize(Factors.size());
289  Gpu::copy(Gpu::hostToDevice, Factors.begin(), Factors.end(), d_Factors.begin());
290  Real* fac_ptr = d_Factors.data();
291 
292  const bool use_KE = ( turbChoice.les_type == LESType::Deardorff );
293 
294 #ifdef _OPENMP
295 #pragma omp parallel if (Gpu::notInLaunchRegion())
296 #endif
297  for ( MFIter mfi(eddyViscosity,TilingIfNotGPU()); mfi.isValid(); ++mfi)
298  {
299  Box bxcc = mfi.tilebox();
300  Box planex = bxcc; planex.setSmall(0, 1); planex.setBig(0, ngc); planex.grow(1,1);
301  Box planey = bxcc; planey.setSmall(1, 1); planey.setBig(1, ngc); planey.grow(0,1);
302  bxcc.growLo(0,ngc); bxcc.growHi(0,ngc);
303  bxcc.growLo(1,ngc); bxcc.growHi(1,ngc);
304 
305  const Array4<Real>& mu_turb = eddyViscosity.array(mfi);
306 
307  for (auto n = 1; n < EddyDiff::Mom_v; ++n) {
308  int offset = EddyDiff::Mom_v;
309  switch (n)
310  {
311  case EddyDiff::KE_h:
312  if (use_KE) {
313  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
314  {
315  int indx = n;
316  int indx_v = indx + offset;
317  mu_turb(i,j,k,indx) = mu_turb(i,j,k,EddyDiff::Mom_h) * fac_ptr[indx-1];
318  mu_turb(i,j,k,indx_v) = mu_turb(i,j,k,EddyDiff::Mom_v) * fac_ptr[indx-1];
319  });
320  }
321  break;
322  default:
323  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
324  {
325  int indx = n;
326  int indx_v = indx + offset;
327 
328  // NOTE: Theta_h, Theta_v have already been set for Deardorff
329  if (!(indx_v == EddyDiff::Theta_v && use_KE)) {
330  mu_turb(i,j,k,indx) = mu_turb(i,j,k,EddyDiff::Mom_h) * fac_ptr[indx-1];
331  mu_turb(i,j,k,indx_v) = mu_turb(i,j,k,EddyDiff::Mom_v) * fac_ptr[indx-1];
332  }
333  });
334  break;
335  }
336  }
337  }
338 }
if(l_use_mynn &&start_comp<=RhoKE_comp &&end_comp >=RhoKE_comp)
Definition: ERF_AddQKESources.H:2
constexpr amrex::Real two
Definition: ERF_Constants.H:10
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
@ tau12
Definition: ERF_DataStruct.H:38
@ tau23
Definition: ERF_DataStruct.H:38
@ tau33
Definition: ERF_DataStruct.H:38
@ tau22
Definition: ERF_DataStruct.H:38
@ tau11
Definition: ERF_DataStruct.H:38
@ tau13
Definition: ERF_DataStruct.H:38
@ v_y
Definition: ERF_DataStruct.H:28
@ u_x
Definition: ERF_DataStruct.H:27
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeSmnSmn2D(int &i, int &j, int &k, const amrex::Array4< amrex::Real const > &tau11, const amrex::Array4< amrex::Real const > &tau22, const amrex::Array4< amrex::Real const > &tau12)
Definition: ERF_EddyViscosity.H:252
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeSmnSmn(int &i, int &j, int &k, const amrex::Array4< amrex::Real const > &tau11, const amrex::Array4< amrex::Real const > &tau22, const amrex::Array4< amrex::Real const > &tau33, const amrex::Array4< amrex::Real const > &tau12, const amrex::Array4< amrex::Real const > &tau13, const amrex::Array4< amrex::Real const > &tau23)
Definition: ERF_EddyViscosity.H:102
#define Rho_comp
Definition: ERF_IndexDefines.H:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define RhoKE_comp
Definition: ERF_IndexDefines.H:38
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:17
const Real length
Definition: ERF_InitCustomPert_AnelasticWallDiffusion.H:14
rho
Definition: ERF_InitCustomPert_Bubble.H:107
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real GetThetav(const int &i, const int &j, const int &k, const amrex::Array4< amrex::Real const > &cell_data, const MoistureComponentIndices &moisture_indices)
Definition: ERF_MoistUtils.H:72
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real GetThetal(const int &i, const int &j, const int &k, const amrex::Array4< amrex::Real const > &cell_data, const MoistureComponentIndices &moisture_indices)
Definition: ERF_MoistUtils.H:128
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:31
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real StabilityFunction(amrex::Real Ri, amrex::Real Ri_crit)
Definition: ERF_RichardsonNumber.H:419
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeVerticalShear2(int i, int j, int k, amrex::Real dzInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v)
Definition: ERF_RichardsonNumber.H:300
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeRichardson(amrex::Real N2_moist, amrex::Real S2_vert)
Definition: ERF_RichardsonNumber.H:403
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeN2(int i, int j, int k, amrex::Real dzInv, amrex::Real const_grav, const amrex::Array4< const amrex::Real > &cell_data, const MoistureComponentIndices &moisture_indices)
Definition: ERF_RichardsonNumber.H:130
AMREX_FORCE_INLINE AMREX_GPU_DEVICE amrex::Real Compute_h_zeta_AtCellCenter(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:55
@ Theta_v
Definition: ERF_IndexDefines.H:212
@ Turb_lengthscale
Definition: ERF_IndexDefines.H:216
@ Mom_h
Definition: ERF_IndexDefines.H:206
@ Mom_v
Definition: ERF_IndexDefines.H:211
@ Theta_h
Definition: ERF_IndexDefines.H:207
@ KE_h
Definition: ERF_IndexDefines.H:208
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
StratType strat_type
Thermodynamic variable used for stability stratification.
Definition: ERF_TurbStruct.H:590
amrex::Real Ce
Deardorff dissipation coefficient.
Definition: ERF_TurbStruct.H:572
amrex::Real sigma_k
TKE diffusivity coefficient denominator.
Definition: ERF_TurbStruct.H:585
bool use_Ri_correction
Whether Richardson-number correction is applied.
Definition: ERF_TurbStruct.H:595
amrex::Real Ck
Deardorff eddy-viscosity coefficient.
Definition: ERF_TurbStruct.H:574
amrex::Real Ce_wall
Wall value for the Deardorff dissipation coefficient.
Definition: ERF_TurbStruct.H:573
amrex::Real theta_ref
Reference potential temperature for stable stratification.
Definition: ERF_TurbStruct.H:588
amrex::Real Sc_t_inv
Inverse turbulent Schmidt number.
Definition: ERF_TurbStruct.H:565
bool mix_isotropic
Whether subgrid mixing uses isotropic length scales.
Definition: ERF_TurbStruct.H:593
amrex::Real Ri_crit
Critical Richardson number for stability correction.
Definition: ERF_TurbStruct.H:596
amrex::Real Cs
Smagorinsky model coefficient.
Definition: ERF_TurbStruct.H:568
amrex::Real Pr_t_inv
Inverse turbulent Prandtl number.
Definition: ERF_TurbStruct.H:561
bool smag2d
Whether the 2-D Smagorinsky formulation is used.
Definition: ERF_TurbStruct.H:569

Referenced by ComputeTurbulentViscosity().

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

◆ ComputeTurbulentViscosityLES_EB()

void ComputeTurbulentViscosityLES_EB ( Vector< std::unique_ptr< MultiFab >> &  Tau_lev,
const MultiFab &  cons_in,
MultiFab &  eddyViscosity,
MultiFab &  Hfx1,
MultiFab &  Hfx2,
MultiFab &  Hfx3,
const Geometry &  geom,
Vector< std::unique_ptr< MultiFab >> &  mapfac,
const TurbChoice turbChoice,
const Real  const_grav,
[[maybe_unused] ] const SolverChoice solverChoice,
std::unique_ptr< SurfaceLayer > &  ,
const MoistureComponentIndices moisture_indices,
const eb_ ebfact,
const MultiFab *  xvel,
const MultiFab *  yvel 
)
352 {
353  const GpuArray<Real, AMREX_SPACEDIM> cellSizeInv = geom.InvCellSizeArray();
354  Real dxInv = cellSizeInv[0];
355  Real dyInv = cellSizeInv[1];
356  Real dzInv = cellSizeInv[2];
357 
358  const Box& domain = geom.Domain();
359 
360  Real inv_Pr_t = turbChoice.Pr_t_inv;
361  Real inv_Sc_t = turbChoice.Sc_t_inv;
362  Real inv_sigma_k = one / turbChoice.sigma_k;
363 
364  bool isotropic = turbChoice.mix_isotropic;
365 
366  AMREX_ASSERT(turbChoice.les_type == LESType::Smagorinsky);
367 
368  // SMAGORINSKY: Fill Kturb for momentum in horizontal and vertical
369  //***********************************************************************************
370  if (turbChoice.les_type == LESType::Smagorinsky)
371  {
372  Real Cs = turbChoice.Cs;
373 
374  // Define variables required inside device lambdas (scalars only)
375  Real l_abs_g = const_grav;
376  Real l_Ri_crit = turbChoice.Ri_crit;
377  bool l_use_Ri_corr = turbChoice.use_Ri_correction;
378  bool l_has_xvel = (xvel != nullptr);
379  bool l_has_yvel = (yvel != nullptr);
380 
381 #ifdef _OPENMP
382 #pragma omp parallel if (Gpu::notInLaunchRegion())
383 #endif
384  for (MFIter mfi(eddyViscosity,TilingIfNotGPU()); mfi.isValid(); ++mfi)
385  {
386  Box bxcc = mfi.growntilebox(1) & domain;
387  const Array4<Real>& mu_turb = eddyViscosity.array(mfi);
388  const Array4<Real>& hfx_x = Hfx1.array(mfi);
389  const Array4<Real>& hfx_y = Hfx2.array(mfi);
390  const Array4<Real>& hfx_z = Hfx3.array(mfi);
391  const Array4<Real const >& cell_data = cons_in.array(mfi);
392  Array4<Real const> tau11 = Tau_lev[TauType::tau11]->array(mfi);
393  Array4<Real const> tau22 = Tau_lev[TauType::tau22]->array(mfi);
394  Array4<Real const> tau33 = Tau_lev[TauType::tau33]->array(mfi);
395  Array4<Real const> tau12 = Tau_lev[TauType::tau12]->array(mfi);
396  Array4<Real const> tau13 = Tau_lev[TauType::tau13]->array(mfi);
397  Array4<Real const> tau23 = Tau_lev[TauType::tau23]->array(mfi);
398  Array4<Real const> mf_u = mapfac[MapFacType::u_x]->const_array(mfi);
399  Array4<Real const> mf_v = mapfac[MapFacType::v_y]->const_array(mfi);
400 
401  Array4<Real const> u_arr = (l_has_xvel) ? xvel->const_array(mfi) : Array4<Real const>{};
402  Array4<Real const> v_arr = (l_has_yvel) ? yvel->const_array(mfi) : Array4<Real const>{};
403 
404  Array4<const EBCellFlag> c_cflag = (ebfact.get_const_factory())->getMultiEBCellFlagFab()[mfi].const_array();
405  Array4<const EBCellFlag> u_cflag = (ebfact.get_u_const_factory())->getMultiEBCellFlagFab()[mfi].const_array();
406  Array4<const EBCellFlag> v_cflag = (ebfact.get_v_const_factory())->getMultiEBCellFlagFab()[mfi].const_array();
407  Array4<const EBCellFlag> w_cflag = (ebfact.get_w_const_factory())->getMultiEBCellFlagFab()[mfi].const_array();
408  Array4<const Real > u_vfrac = (ebfact.get_u_const_factory())->getVolFrac().const_array(mfi);
409  Array4<const Real > v_vfrac = (ebfact.get_v_const_factory())->getVolFrac().const_array(mfi);
410 
411  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
412  {
413  if (!c_cflag(i,j,k).isCovered()) {
414  // =====================================================================
415  // 1. STRAIN RATE MAGNITUDE CALCULATION
416  // =====================================================================
417  Real SmnSmn = zero;
418  if (c_cflag(i,j,k).isRegular()) {
419  SmnSmn = ComputeSmnSmn(i,j,k,tau11,tau22,tau33,tau12,tau13,tau23);
420  } else if (c_cflag(i,j,k).isSingleValued()) {
421  SmnSmn = ComputeSmnSmn_EB(i,j,k,tau11,tau22,tau33,tau12,tau13,tau23,c_cflag,u_cflag,v_cflag,w_cflag);
422  }
423  Real strain_rate_magnitude = std::sqrt(two * SmnSmn);
424 
425  // =====================================================================
426  // 2. GRID SCALE CALCULATION (filter width Δ)
427  // =====================================================================
428  Real Delta;
429  Real DeltaH;
430  if (isotropic) {
431  Real cellVolMsf = one / (dxInv * mf_u(i,j,0) * dyInv * mf_v(i,j,0) * dzInv);
432  Delta = std::cbrt(cellVolMsf);
433  DeltaH = Delta;
434  } else {
435  Delta = one / dzInv;
436  DeltaH = std::sqrt(one / (dxInv * mf_u(i,j,0) * dyInv * mf_v(i,j,0)));
437  }
438 
439  Real rho = cell_data(i, j, k, Rho_comp);
440  Real CsDeltaSqr_h = Cs * Cs * DeltaH * DeltaH;
441  Real CsDeltaSqr_v = Cs * Cs * Delta * Delta;
442 
443  Real nu_turb_base_h = CsDeltaSqr_h * strain_rate_magnitude;
444  Real nu_turb_base_v = CsDeltaSqr_v * strain_rate_magnitude;
445 
446  Real stability_factor = one;
447 
448  if (l_use_Ri_corr && l_has_xvel && l_has_yvel) {
449  Real N2 = zero;
450  Real S2_vert = zero;
451  if (c_cflag(i,j,k).isRegular()) {
452  N2 = ComputeN2(i, j, k, dzInv, l_abs_g, cell_data, moisture_indices);
453  S2_vert = ComputeVerticalShear2(i, j, k, dzInv, u_arr, v_arr);
454  } else if (c_cflag(i,j,k).isSingleValued()) {
455  N2 = ComputeN2_EB(i, j, k, c_cflag, dzInv, l_abs_g, cell_data, moisture_indices);
456  S2_vert = ComputeVerticalShear2_EB(i, j, k, c_cflag, u_vfrac, v_vfrac, dzInv, u_arr, v_arr);
457  }
458  Real Ri = ComputeRichardson(N2, S2_vert);
459  stability_factor = StabilityFunction(Ri, l_Ri_crit);
460  }
461 
462  if (isotropic) {
463  mu_turb(i, j, k, EddyDiff::Mom_h) = rho * nu_turb_base_h * stability_factor;
464  mu_turb(i, j, k, EddyDiff::Mom_v) = rho * nu_turb_base_v * stability_factor;
465  } else {
466  mu_turb(i, j, k, EddyDiff::Mom_h) = rho * nu_turb_base_h;
467  mu_turb(i, j, k, EddyDiff::Mom_v) = rho * nu_turb_base_v * stability_factor;
468  }
469 
470  Real dtheta_dz = zero;
471 
472  if (c_cflag(i,j,k).isSingleValued() && c_cflag(i,j,k+1).isCovered()) {
473  amrex::Real theta = cell_data(i, j, k, RhoTheta_comp) / rho;
474  amrex::Real theta_km1 = cell_data(i,j,k-1,RhoTheta_comp)/cell_data(i,j,k-1,Rho_comp);
475  amrex::Real theta_km2 = cell_data(i,j,k-2,RhoTheta_comp)/cell_data(i,j,k-2,Rho_comp);
476  dtheta_dz = (three*theta - Real(4.)*theta_km1 + theta_km2) * myhalf * dzInv;
477  } else if (c_cflag(i,j,k).isSingleValued() && c_cflag(i,j,k-1).isCovered()) {
478  amrex::Real theta = cell_data(i, j, k, RhoTheta_comp) / rho;
479  amrex::Real theta_kp1 = cell_data(i,j,k+1,RhoTheta_comp)/cell_data(i,j,k+1,Rho_comp);
480  amrex::Real theta_kp2 = cell_data(i,j,k+2,RhoTheta_comp)/cell_data(i,j,k+2,Rho_comp);
481  dtheta_dz = (-theta_kp2 + Real(4.)*theta_kp1 - three*theta) * myhalf * dzInv;
482  } else if (!c_cflag(i,j,k).isCovered()) {
483  amrex::Real theta_km1 = cell_data(i,j,k-1,RhoTheta_comp)/cell_data(i,j,k-1,Rho_comp);
484  amrex::Real theta_kp1 = cell_data(i,j,k+1,RhoTheta_comp)/cell_data(i,j,k+1,Rho_comp);
485  dtheta_dz = myhalf * (theta_kp1 - theta_km1) * dzInv;
486  }
487 
488  hfx_x(i,j,k) = zero;
489  hfx_y(i,j,k) = zero;
490  hfx_z(i,j,k) = -inv_Pr_t * mu_turb(i,j,k,EddyDiff::Mom_v) * dtheta_dz;
491 
492  } else {
493 
494  hfx_x(i,j,k) = zero;
495  hfx_y(i,j,k) = zero;
496  hfx_z(i,j,k) = zero;
497  }// End of if not covered
498  });
499  }
500  }
501 
502  // Extrapolate Kturb in x/y, fill remaining elements (relevant to lev==0)
503  //***********************************************************************************
504  int ngc(1);
505  // EddyDiff mapping : Theta_h KE_h Scalar_h Q_h
506  Vector<Real> Factors = {inv_Pr_t, inv_sigma_k, inv_Sc_t, inv_Sc_t}; // alpha = mu/Pr
507  Gpu::AsyncVector<Real> d_Factors; d_Factors.resize(Factors.size());
508  Gpu::copy(Gpu::hostToDevice, Factors.begin(), Factors.end(), d_Factors.begin());
509  Real* fac_ptr = d_Factors.data();
510 
511  const bool use_KE = ( turbChoice.les_type == LESType::Deardorff );
512 
513 #ifdef _OPENMP
514 #pragma omp parallel if (Gpu::notInLaunchRegion())
515 #endif
516  for ( MFIter mfi(eddyViscosity,TilingIfNotGPU()); mfi.isValid(); ++mfi)
517  {
518  Box bxcc = mfi.tilebox();
519  Box planex = bxcc; planex.setSmall(0, 1); planex.setBig(0, ngc); planex.grow(1,1);
520  Box planey = bxcc; planey.setSmall(1, 1); planey.setBig(1, ngc); planey.grow(0,1);
521  bxcc.growLo(0,ngc); bxcc.growHi(0,ngc);
522  bxcc.growLo(1,ngc); bxcc.growHi(1,ngc);
523 
524  const Array4<Real>& mu_turb = eddyViscosity.array(mfi);
525 
526  for (auto n = 1; n < EddyDiff::Mom_v; ++n) {
527  int offset = EddyDiff::Mom_v;
528  switch (n)
529  {
530  case EddyDiff::KE_h:
531  if (use_KE) {
532  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
533  {
534  int indx = n;
535  int indx_v = indx + offset;
536  mu_turb(i,j,k,indx) = mu_turb(i,j,k,EddyDiff::Mom_h) * fac_ptr[indx-1];
537  mu_turb(i,j,k,indx_v) = mu_turb(i,j,k,EddyDiff::Mom_v) * fac_ptr[indx-1];
538  });
539  }
540  break;
541  default:
542  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
543  {
544  int indx = n;
545  int indx_v = indx + offset;
546 
547  // NOTE: Theta_h, Theta_v have already been set for Deardorff
548  if (!(indx_v == EddyDiff::Theta_v && use_KE)) {
549  mu_turb(i,j,k,indx) = mu_turb(i,j,k,EddyDiff::Mom_h) * fac_ptr[indx-1];
550  mu_turb(i,j,k,indx_v) = mu_turb(i,j,k,EddyDiff::Mom_v) * fac_ptr[indx-1];
551  }
552  });
553  break;
554  }
555  }
556  }
557 }
constexpr amrex::Real three
Definition: ERF_Constants.H:11
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeSmnSmn_EB(int &i, int &j, int &k, const amrex::Array4< amrex::Real const > &tau11, const amrex::Array4< amrex::Real const > &tau22, const amrex::Array4< amrex::Real const > &tau33, const amrex::Array4< amrex::Real const > &tau12, const amrex::Array4< amrex::Real const > &tau13, const amrex::Array4< amrex::Real const > &tau23, const amrex::Array4< const amrex::EBCellFlag > &c_cflag, const amrex::Array4< const amrex::EBCellFlag > &u_cflag, const amrex::Array4< const amrex::EBCellFlag > &v_cflag, const amrex::Array4< const amrex::EBCellFlag > &w_cflag)
Definition: ERF_EddyViscosity.H:147
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeVerticalShear2_EB(int i, int j, int k, const amrex::Array4< const amrex::EBCellFlag > &c_cflag, const amrex::Array4< const amrex::Real > &u_vfrac, const amrex::Array4< const amrex::Real > &v_vfrac, amrex::Real dzInv, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v)
Definition: ERF_RichardsonNumber.H:336
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeN2_EB(int i, int j, int k, const amrex::Array4< const amrex::EBCellFlag > &c_cflag, amrex::Real dzInv, amrex::Real const_grav, const amrex::Array4< const amrex::Real > &cell_data, const MoistureComponentIndices &moisture_indices)
Definition: ERF_RichardsonNumber.H:192
eb_aux_ const * get_w_const_factory() const noexcept
Return the ERF auxiliary z-face EB factory.
Definition: ERF_EB.H:123
const std::unique_ptr< amrex::EBFArrayBoxFactory > & get_const_factory() const noexcept
Return the cell-centered EB factory.
Definition: ERF_EB.H:102
eb_aux_ const * get_v_const_factory() const noexcept
Return the ERF auxiliary y-face EB factory.
Definition: ERF_EB.H:121
eb_aux_ const * get_u_const_factory() const noexcept
Return the ERF auxiliary x-face EB factory.
Definition: ERF_EB.H:119
@ theta
Definition: ERF_SLM.H:20

Referenced by ComputeTurbulentViscosity().

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

◆ ComputeTurbulentViscosityRANS()

void ComputeTurbulentViscosityRANS ( Vector< std::unique_ptr< MultiFab >> &  ,
const MultiFab &  cons_in,
const MultiFab &  wdist,
MultiFab &  eddyViscosity,
MultiFab &  Hfx1,
MultiFab &  Hfx2,
MultiFab &  Hfx3,
MultiFab &  Diss,
const Geometry &  geom,
bool  use_terrain_fitted_coords,
Vector< std::unique_ptr< MultiFab >> &  ,
const std::unique_ptr< MultiFab > &  z_phys_nd,
const TurbChoice turbChoice,
const Real  const_grav,
std::unique_ptr< SurfaceLayer > &  SurfLayer,
const MultiFab *  z_0 
)

Function for computing the eddy viscosity with RANS.

Parameters
[in]cons_incell center conserved quantities
[in]wdistwall distance
[out]eddyViscosityturbulent viscosity
[out]Hfx1heat flux in x-dir
[out]Hfx2heat flux in y-dir
[out]Hfx3heat flux in z-dir
[out]Dissdissipation of turbulent kinetic energy
[in]geomproblem geometry
[in]use_terrain_fitted_coordsflag for terrain-fitted coordinates
[in]z_phys_ndnodal physical z coordinates
[in]turbChoicecontainer with turbulence parameters
[in]const_gravgravitational acceleration
[in]SurfLayeroptional surface-layer model
[in]z_0roughness length
593 {
594  const GpuArray<Real, AMREX_SPACEDIM> cellSizeInv = geom.InvCellSizeArray();
595  const bool use_SurfLayer = (SurfLayer != nullptr);
596 
597  Real inv_Pr_t = turbChoice.Pr_t_inv;
598  Real inv_Sc_t = turbChoice.Sc_t_inv;
599  Real inv_sigma_k = one / turbChoice.sigma_k;
600 
601  // One-Equation k model (Axell & Liungman 2001, Environ Fluid Mech)
602  //***********************************************************************************
603  if (turbChoice.rans_type == RANSType::kEqn)
604  {
605  const Real Cmu0 = turbChoice.Cmu0;
606  const Real Cmu0_pow3 = Cmu0 * Cmu0 * Cmu0;
607  const Real inv_Cb_sq = one / (turbChoice.Cb * turbChoice.Cb);
608  const Real Rt_crit = turbChoice.Rt_crit;
609  const Real Rt_min = turbChoice.Rt_min;
610  const Real l_g_max = turbChoice.l_g_max;
611  const Real abs_g = const_grav;
612 
613  const bool use_ref_theta = (turbChoice.theta_ref > 0);
614  const Real inv_theta0 = (use_ref_theta) ? one / turbChoice.theta_ref : one;
615 
616 #ifdef _OPENMP
617 #pragma omp parallel if (Gpu::notInLaunchRegion())
618 #endif
619  for ( MFIter mfi(eddyViscosity,TilingIfNotGPU()); mfi.isValid(); ++mfi)
620  {
621  Box bxcc = mfi.tilebox();
622 
623  const Array4<Real const>& d_arr = wdist.const_array(mfi);
624  const Array4<Real const>& z0_arr = (use_SurfLayer) ? z_0->const_array(mfi) : Array4<Real const>{};
625 
626  const Array4<Real>& mu_turb = eddyViscosity.array(mfi);
627  const Array4<Real>& hfx_x = Hfx1.array(mfi);
628  const Array4<Real>& hfx_y = Hfx2.array(mfi);
629  const Array4<Real>& hfx_z = Hfx3.array(mfi);
630  const Array4<Real>& diss = Diss.array(mfi);
631 
632  const Array4<Real const>& cell_data = cons_in.array(mfi);
633 
634  const Array4<Real const>& z_nd_arr = z_phys_nd->const_array(mfi);
635 
636  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
637  {
639  Real tke = amrex::max(cell_data(i,j,k,RhoKE_comp)/cell_data(i,j,k,Rho_comp), eps);
640 
641  // Estimate stratification
642  Real dzInv = cellSizeInv[2];
643  if (use_terrain_fitted_coords) {
644  // the terrain grid is only deformed in z for now
645  dzInv /= Compute_h_zeta_AtCellCenter(i,j,k, cellSizeInv, z_nd_arr);
646  }
647  Real dtheta_dz = myhalf * ( cell_data(i,j,k+1,RhoTheta_comp)/cell_data(i,j,k+1,Rho_comp)
648  - cell_data(i,j,k-1,RhoTheta_comp)/cell_data(i,j,k-1,Rho_comp) )*dzInv;
649  Real N2 = abs_g * inv_theta0 * dtheta_dz; // Brunt–Väisälä frequency squared
650  if (!use_ref_theta) {
651  // inv_theta0 == 1, divide by actual theta
652  N2 *= cell_data(i,j,k,Rho_comp) /
653  cell_data(i,j,k,RhoTheta_comp);
654  }
655 
656  // Geometric length scale (AL01, Eqn. 22)
657  Real l_g = (z0_arr) ? KAPPA * (d_arr(i, j, k) + z0_arr(i, j, 0))
658  : KAPPA * d_arr(i, j, k);
659 
660  // Enforce a maximum value
661  l_g = l_g_max * l_g / (l_g_max + l_g);
662 
663  // Turbulent length scale
664  Real length, Rt;
665  if (std::abs(N2) <= eps) {
666  length = l_g;
667  } else if (N2 > eps) {
668  // Stable (AL01, Eqn. 26)
669  length = std::sqrt(one /
670  (one / (l_g * l_g) + inv_Cb_sq * N2 / tke));
671  } else {
672  Real diss0 = Cmu0_pow3 * std::pow(tke,Real(1.5)) / l_g; // approx
673  Rt = tke*tke * N2 / (diss0*diss0);
674 
675  // Unstable (AL01, Eqn. 28)
676  // - predict
677  length = l_g * std::sqrt(one - Cmu0_pow3*Cmu0_pow3 * inv_Cb_sq * Rt);
678  // - correct
679  diss0 = Cmu0_pow3 * std::pow(tke,Real(1.5)) / length;
680  Rt = tke*tke * N2 / (diss0*diss0);
681  length = l_g * std::sqrt(one - Cmu0_pow3*Cmu0_pow3 * inv_Cb_sq * Rt);
682  }
683  mu_turb(i, j, k, EddyDiff::Turb_lengthscale) = length;
684 
685  // Dissipation rate (AL01, Eqn. 19)
686  diss(i, j, k) = cell_data(i, j, k, Rho_comp) * Cmu0_pow3 * std::pow(tke,Real(1.5)) / length;
687 
688  // Turbulent Richardson number (AL01, Eqn. 29)
689  //Real Rt = tke*tke * N2 / (diss(i,j,k)*diss(i,j,k));
690  Rt = length*length * N2 / (tke * Cmu0_pow3 * Cmu0_pow3); // combined with Eqn. 19
691 
692  // Burchard & Petersen smoothing function
693  Rt = (Rt >= Rt_crit) ? Rt : std::max(Rt, Rt - (Rt - Rt_crit)*(Rt - Rt_crit) / (Rt + Rt_min - 2*Rt_crit));
694 
695  // Stability functions
696  // Note: These use the smoothed turbulent Richardson number
697  Real cmu = (Cmu0 + Real(0.108)*Rt)
698  / (one + Real(0.308)*Rt + Real(0.00837)*Rt*Rt); // (AL01, Eqn. 31)
699  Real cmu_prime = Cmu0 / (1 + Real(0.277)*Rt); // (AL01, Eqn. 32)
700 
701  // Calculate eddy diffusivities
702  // K = rho * nu_t = rho * c_mu * tke^(1/2) * length
703  Real nut = cmu * std::sqrt(tke) * length; // eddy viscosity
704  Real nut_prime = cmu_prime / cmu * nut; // eddy diffusivity
705  mu_turb(i, j, k, EddyDiff::Mom_h) = cell_data(i, j, k, Rho_comp) * nut;
706  mu_turb(i, j, k, EddyDiff::Mom_v) = mu_turb(i, j, k, EddyDiff::Mom_h);
707  mu_turb(i, j, k, EddyDiff::Theta_v) = cell_data(i, j, k, Rho_comp) * nut_prime;
708 
709  // Calculate heat flux
710  // - If using SurfaceLayer, the value at k=0 will be overwritten
711  hfx_x(i, j, k) = zero;
712  hfx_y(i, j, k) = zero;
713  // Note: buoyant production = g/theta0 * hfx == -nut_prime * N^2 (c.f. AL01 Eqn. 15)
714  // = nut_prime * g/theta0 * dtheta/dz
715  // ==> hfx = nut_prime * dtheta/dz
716  // Our convention is such that dtheta/dz < 0 gives a positive
717  // (upward) heat flux.
718  hfx_z(i, j, k) = -mu_turb(i, j, k, EddyDiff::Theta_v) * dtheta_dz; // (rho*w)' theta' [kg m^-2 s^-1 K]
719  });
720  }
721  }
722 
723  // Extrapolate Kturb in x/y, fill remaining elements (relevant to lev==0)
724  //***********************************************************************************
725  int ngc(1);
726  // EddyDiff mapping : Theta_h KE_h Scalar_h Q_h
727  Vector<Real> Factors = {inv_Pr_t, inv_sigma_k, inv_Sc_t, inv_Sc_t}; // alpha = mu/Pr
728  Gpu::AsyncVector<Real> d_Factors; d_Factors.resize(Factors.size());
729  Gpu::copy(Gpu::hostToDevice, Factors.begin(), Factors.end(), d_Factors.begin());
730  Real* fac_ptr = d_Factors.data();
731 
732  const bool use_KE = ( turbChoice.rans_type == RANSType::kEqn );
733 
734 #ifdef _OPENMP
735 #pragma omp parallel if (Gpu::notInLaunchRegion())
736 #endif
737  for ( MFIter mfi(eddyViscosity,TilingIfNotGPU()); mfi.isValid(); ++mfi)
738  {
739  Box bxcc = mfi.tilebox();
740  Box planex = bxcc; planex.setSmall(0, 1); planex.setBig(0, ngc); planex.grow(1,1);
741  Box planey = bxcc; planey.setSmall(1, 1); planey.setBig(1, ngc); planey.grow(0,1);
742  bxcc.growLo(0,ngc); bxcc.growHi(0,ngc);
743  bxcc.growLo(1,ngc); bxcc.growHi(1,ngc);
744 
745  const Array4<Real>& mu_turb = eddyViscosity.array(mfi);
746 
747  for (auto n = 1; n < EddyDiff::Mom_v; ++n) {
748  int offset = EddyDiff::Mom_v;
749  switch (n)
750  {
751  case EddyDiff::KE_h:
752  if (use_KE) {
753  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
754  {
755  int indx = n;
756  int indx_v = indx + offset;
757  mu_turb(i,j,k,indx) = mu_turb(i,j,k,EddyDiff::Mom_h) * fac_ptr[indx-1];
758  mu_turb(i,j,k,indx_v) = mu_turb(i,j,k,indx);
759  });
760  }
761  break;
762  default:
763  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
764  {
765  int indx = n;
766  int indx_v = indx + offset;
767 
768  mu_turb(i,j,k,indx) = mu_turb(i,j,k,EddyDiff::Mom_h) * fac_ptr[indx-1];
769 
770  // NOTE: Theta_v has already been set for Deardorff
771  if (!(indx_v == EddyDiff::Theta_v && use_KE)) {
772  mu_turb(i,j,k,indx_v) = mu_turb(i,j,k,indx);
773  }
774  });
775  break;
776  }
777  }
778  }
779 }
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:63
amrex::Real l_g_max
Maximum geometric length scale.
Definition: ERF_TurbStruct.H:581
amrex::Real Rt_min
Minimum turbulent Reynolds number.
Definition: ERF_TurbStruct.H:580
amrex::Real Cb
One-equation RANS buoyancy coefficient.
Definition: ERF_TurbStruct.H:578
amrex::Real Rt_crit
Critical turbulent Reynolds number.
Definition: ERF_TurbStruct.H:579
amrex::Real Cmu0
One-equation RANS Cmu0 coefficient.
Definition: ERF_TurbStruct.H:577

Referenced by ComputeTurbulentViscosity().

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