ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ProblemBase Class Reference

#include <ERF_ProbCommon.H>

Collaboration diagram for ProblemBase:

Public Member Functions

virtual ~ProblemBase ()=default
 
virtual void erf_init_dens_hse_dry (amrex::MultiFab &, std::unique_ptr< amrex::MultiFab > &, std::unique_ptr< amrex::MultiFab > &, amrex::Geometry const &, const amrex::Vector< amrex::Real > &, bool, bool)
 
virtual void erf_init_const_dens_hse (amrex::MultiFab &)
 
virtual void erf_init_const_dens_and_th_hse (amrex::MultiFab &, amrex::MultiFab &, amrex::MultiFab &, amrex::MultiFab &, amrex::MultiFab &, amrex::Real)
 
virtual void erf_init_const_dens_and_linear_th_hse (amrex::MultiFab &, amrex::MultiFab &, amrex::MultiFab &, amrex::MultiFab &, amrex::MultiFab &, amrex::Real, std::unique_ptr< amrex::MultiFab > &)
 
virtual void erf_init_dens_hse_moist (amrex::MultiFab &, std::unique_ptr< amrex::MultiFab > &, amrex::Geometry const &)
 
virtual void init_custom_pert (const amrex::Box &, amrex::Array4< amrex::Real const > const &, amrex::Array4< amrex::Real > const &, amrex::Array4< amrex::Real > const &, amrex::Array4< amrex::Real > const &, amrex::Array4< amrex::Real const > const &, amrex::Array4< amrex::Real const > const &, amrex::GeometryData const &, amrex::Array4< amrex::Real const > const &, const SolverChoice &, const int)
 
virtual void init_custom_pert_vels (const amrex::Box &, const amrex::Box &, const amrex::Box &, amrex::Array4< amrex::Real > const &, amrex::Array4< amrex::Real > const &, amrex::Array4< amrex::Real > const &, amrex::Array4< amrex::Real const > const &, amrex::GeometryData const &, amrex::Array4< amrex::Real const > const &, amrex::Array4< amrex::Real const > const &, const SolverChoice &, const int)
 
virtual void update_rhotheta_sources (const double &, amrex::MultiFab *src, const amrex::Geometry &, std::unique_ptr< amrex::MultiFab > &)
 
virtual void update_rhoqt_sources (const double &, amrex::MultiFab *qsrc, const amrex::Geometry &, std::unique_ptr< amrex::MultiFab > &)
 
virtual void update_w_subsidence (const double &, amrex::Vector< amrex::Real > &wbar, amrex::Gpu::DeviceVector< amrex::Real > &d_wbar, const amrex::MultiFab &, const amrex::Geometry &geom, std::unique_ptr< amrex::MultiFab > &)
 
virtual void update_geostrophic_profile (const double &, amrex::Vector< amrex::Real > &u_geos, amrex::Gpu::DeviceVector< amrex::Real > &d_u_geos, amrex::Vector< amrex::Real > &v_geos, amrex::Gpu::DeviceVector< amrex::Real > &d_v_geos, const amrex::Geometry &geom, std::unique_ptr< amrex::MultiFab > &)
 
void init_buildings_surface (const amrex::Geometry &geom, amrex::FArrayBox &buildings_fab, const double &time)
 
void init_terrain_surface (const amrex::Geometry &geom, amrex::FArrayBox &terrain_fab, const double &time)
 
virtual bool terrain_is_specified ()
 
void read_custom_terrain (const std::string &fname, const bool is_usgs, const amrex::Geometry &geom, amrex::FArrayBox &terrain_fab, const double &)
 
virtual void init_custom_terrain (const amrex::Geometry &geom, amrex::FArrayBox &terrain_fab, const double &time)
 
virtual void erf_init_rayleigh (amrex::Vector< amrex::Vector< amrex::Real > > &, amrex::Geometry const &, std::unique_ptr< amrex::MultiFab > &, amrex::Real)
 

Protected Member Functions

void init_base_parms (amrex::Real rho_0, amrex::Real T_0)
 
std::string name ()
 

Protected Attributes

ProbParmDefaults base_parms
 

Detailed Description

Class to hold problem-specific routines

Constructor & Destructor Documentation

◆ ~ProblemBase()

virtual ProblemBase::~ProblemBase ( )
virtualdefault

Virtual destructor to avoid data leakage with derived class

Member Function Documentation

◆ erf_init_const_dens_and_linear_th_hse()

virtual void ProblemBase::erf_init_const_dens_and_linear_th_hse ( amrex::MultiFab &  ,
amrex::MultiFab &  ,
amrex::MultiFab &  ,
amrex::MultiFab &  ,
amrex::MultiFab &  ,
amrex::Real  ,
std::unique_ptr< amrex::MultiFab > &   
)
inlinevirtual
110  {
111  amrex::Error("Should never call this version of erf_init_const_dens_and_linear_th_hse for "+name()+" problem");
112  }
std::string name()
Definition: ERF_ProbCommon.H:1211
Here is the call graph for this function:

◆ erf_init_const_dens_and_th_hse()

virtual void ProblemBase::erf_init_const_dens_and_th_hse ( amrex::MultiFab &  ,
amrex::MultiFab &  ,
amrex::MultiFab &  ,
amrex::MultiFab &  ,
amrex::MultiFab &  ,
amrex::Real   
)
inlinevirtual
101  {
102  amrex::Error("Should never call this version of erf_init_const_dens_and_th_hse for "+name()+" problem");
103  }
Here is the call graph for this function:

◆ erf_init_const_dens_hse()

virtual void ProblemBase::erf_init_const_dens_hse ( amrex::MultiFab &  )
inlinevirtual
93  {
94  amrex::Error("Should never call this version of erf_init_const_dens_hse for "+name()+" problem");
95  }
Here is the call graph for this function:

◆ erf_init_dens_hse_dry()

virtual void ProblemBase::erf_init_dens_hse_dry ( amrex::MultiFab &  ,
std::unique_ptr< amrex::MultiFab > &  ,
std::unique_ptr< amrex::MultiFab > &  ,
amrex::Geometry const &  ,
const amrex::Vector< amrex::Real > &  ,
bool  ,
bool   
)
inlinevirtual

Function to initialize the hydrostatic reference density

Parameters
[out]rho_hsehydrostatic reference density
[in]z_phys_ndheight coordinate at nodes
[in]z_phys_ccheight coordinate at cell centers
[in]geomcontainer for geometric information
83  {
84  amrex::Print() << "Hydrostatically balanced density was NOT set"
85  << " -- an appropriate init_type should probably have been specified"
86  << " (e.g., input_sounding, WRFInput, or Metgrid)"
87  << std::endl;
88  amrex::Error("Should never call this version of erf_init_dens_hse_dry for "+name()+" problem");
89  }
Here is the call graph for this function:

◆ erf_init_dens_hse_moist()

virtual void ProblemBase::erf_init_dens_hse_moist ( amrex::MultiFab &  ,
std::unique_ptr< amrex::MultiFab > &  ,
amrex::Geometry const &   
)
inlinevirtual
118  {
119 
120  }

◆ erf_init_rayleigh()

virtual void ProblemBase::erf_init_rayleigh ( amrex::Vector< amrex::Vector< amrex::Real > > &  ,
amrex::Geometry const &  ,
std::unique_ptr< amrex::MultiFab > &  ,
amrex::Real   
)
inlinevirtual

Function to define the quantities needed to impose Rayleigh damping

Parameters
[out]rayleigh_ptrs= {strength of Rayleigh damping, reference values for xvel/yvel/zvel/theta used to define Rayleigh damping}
[in]geomcontainer for geometric information
[in]z_phys_ccheight coordinate at cell centers
1194  {
1195  // Default which does no harm
1196  }

◆ init_base_parms()

void ProblemBase::init_base_parms ( amrex::Real  rho_0,
amrex::Real  T_0 
)
inlineprotected

Function to update default base parameters, currently only used for init_type == InitType::Uniform

1206  {
1208  base_parms.T_0 = T_0;
1209  }
Real rho_0
Definition: ERF_InitCustomPert_ABL.H:18
Real T_0
Definition: ERF_InitCustomPert_ABL.H:19
ProbParmDefaults base_parms
Definition: ERF_ProbCommon.H:1200
amrex::Real T_0
Definition: ERF_ProbCommon.H:27
amrex::Real rho_0
Definition: ERF_ProbCommon.H:26

◆ init_buildings_surface()

void ProblemBase::init_buildings_surface ( const amrex::Geometry &  geom,
amrex::FArrayBox &  buildings_fab,
const double &  time 
)
inline

Function to perform custom initialization of buildings

Parameters
[in]geomcontainer for geometric information
[out]z_phys_ndheight coordinate at nodes
[in]timecurrent time
336  {
337  // Check if a valid text file exists for the buildings
338  std::string fname;
339  amrex::ParmParse pp("erf");
340  auto valid_fname = pp.queryAdd("buildings_file_name",fname);
341 
342  if (valid_fname) {
343  read_custom_terrain(fname,false,geom,buildings_fab,time);
344  } else {
345  init_my_custom_terrain(geom, buildings_fab, time);
346  }
347  }
ParmParse pp("prob")
void init_my_custom_terrain(const amrex::Geometry &geom, amrex::FArrayBox &terrain_fab, const double &time)
void read_custom_terrain(const std::string &fname, const bool is_usgs, const amrex::Geometry &geom, amrex::FArrayBox &terrain_fab, const double &)
Definition: ERF_ProbCommon.H:846
Here is the call graph for this function:

◆ init_custom_pert()

virtual void ProblemBase::init_custom_pert ( const amrex::Box &  ,
amrex::Array4< amrex::Real const > const &  ,
amrex::Array4< amrex::Real > const &  ,
amrex::Array4< amrex::Real > const &  ,
amrex::Array4< amrex::Real > const &  ,
amrex::Array4< amrex::Real const > const &  ,
amrex::Array4< amrex::Real const > const &  ,
amrex::GeometryData const &  ,
amrex::Array4< amrex::Real const > const &  ,
const SolverChoice ,
const int   
)
inlinevirtual

Function to perform custom initialization of a test problem

Parameters
[in]bxcell-centered box on which to initialize scalars
[out]statecell-centered variables to be filled in this routine
[out]r_hsehydrostatic reference density
[out]p_hsehydrostatic reference pressure
[in]z_ndheight coordinate at nodes
[in]z_ccheight coordinate at cell centers
[in]mf_mmap factor on cell centers
[in]mf_umap factor on x-faces
[in]mf_vmap factor on y-faces
[in]scSolverChoice structure that carries parameters
[in]levAMR level
148  {
149  amrex::Print() << "No perturbation to background fields supplied for "
150  << name() << " problem" << std::endl;
151  }
Here is the call graph for this function:

◆ init_custom_pert_vels()

virtual void ProblemBase::init_custom_pert_vels ( const amrex::Box &  ,
const amrex::Box &  ,
const amrex::Box &  ,
amrex::Array4< amrex::Real > const &  ,
amrex::Array4< amrex::Real > const &  ,
amrex::Array4< amrex::Real > const &  ,
amrex::Array4< amrex::Real const > const &  ,
amrex::GeometryData const &  ,
amrex::Array4< amrex::Real const > const &  ,
amrex::Array4< amrex::Real const > const &  ,
const SolverChoice ,
const int   
)
inlinevirtual

Function to perform custom initialization of the velocities

Parameters
[in]xbxbox on which to initialize x_vel_pert
[in]ybxbox on which to initialize y_vel_pert
[in]zbxbox on which to initialize z_vel_pert
[out]x_vel_pertx-component of velocity perturbation to be filled in this routine
[out]y_vel_perty-component of velocity perturbation to be filled in this routine
[out]z_vel_pertz-component of velocity perturbation to be filled in this routine
[in]z_ndheight coordinate at nodes
[in]mf_mmap factor on cell centers
[in]mf_umap factor on x-faces
[in]mf_vmap factor on y-faces
[in]scSolverChoice structure that carries parameters
[in]levAMR level
181  {
182  amrex::Print() << "No perturbation velocities supplied for " << name() << " problem" << std::endl;
183  }
Here is the call graph for this function:

◆ init_custom_terrain()

virtual void ProblemBase::init_custom_terrain ( const amrex::Geometry &  geom,
amrex::FArrayBox &  terrain_fab,
const double &  time 
)
inlinevirtual

Function to perform custom initialization of terrain

Note: Terrain functionality can also be used to provide grid stretching.

Parameters
[in]geomcontainer for geometric information
[out]terrain_mfheight coordinate at nodes
[in]timecurrent time
1155  {
1156  std::string custom_terrain_type = "None";
1157  amrex::ParmParse pp_prob("prob"); pp_prob.queryAdd("custom_terrain_type",custom_terrain_type);
1158 
1159  if (custom_terrain_type != "None")
1160  {
1161  amrex::Print() << "Calling custom terrain initialization" << std::endl;
1162  init_my_custom_terrain(geom,terrain_fab,time);
1163 
1164  } else {
1165  amrex::Print() << "Initializing flat terrain" << std::endl;
1166  terrain_fab.template setVal<amrex::RunOn::Device>(0);
1167 
1168  if (SolverChoice::mesh_type == MeshType::VariableDz) {
1169  SolverChoice::set_mesh_type(MeshType::StretchedDz);
1170  amrex::Print() << "Resetting mesh type to StretchedDz" << std::endl;
1171  }
1172  }
1173  }
ParmParse pp_prob("prob")
static MeshType mesh_type
Vertical mesh representation.
Definition: ERF_DataStruct.H:1958
static void set_mesh_type(MeshType new_mesh_type)
Override the globally selected mesh type.
Definition: ERF_DataStruct.H:1965
Here is the call graph for this function:

◆ init_terrain_surface()

void ProblemBase::init_terrain_surface ( const amrex::Geometry &  geom,
amrex::FArrayBox &  terrain_fab,
const double &  time 
)
inline

Function to perform custom initialization of terrain

Parameters
[in]geomcontainer for geometric information
[out]z_phys_ndheight coordinate at nodes
[in]timecurrent time
361  {
362  amrex::ParmParse pp("erf");
363 
364  // NetCDF terrain file takes priority
365  std::string fname_nc;
366  auto valid_fname_nc = pp.query("terrain_file_name_nc", fname_nc);
367 
368  std::string fname, fname_usgs;
369  auto valid_fname = pp.query("terrain_file_name", fname);
370  auto valid_fname_USGS = pp.query("terrain_file_name_USGS", fname_usgs);
371 
372  if (valid_fname_nc) {
373 #ifdef ERF_USE_NETCDF
374  read_terrain_netcdf(fname_nc, geom, terrain_fab, time);
375 #else
376  amrex::Abort("ERF must be compiled with NetCDF support to use terrain_file_name_nc");
377 #endif
378  } else if (valid_fname) {
379  read_custom_terrain(fname, false, geom, terrain_fab, time);
380 
381  } else if (valid_fname_USGS) {
382  read_custom_terrain(fname_usgs, true, geom, terrain_fab, time);
383 
384  } else {
385  init_my_custom_terrain (geom, terrain_fab, time);
386  }
387  }
Here is the call graph for this function:

◆ name()

std::string ProblemBase::name ( )
inlineprotected
1211  {
1212  std::string prob_name;
1213  amrex::ParmParse pp("erf");
1214  pp.get("prob_name",prob_name); return prob_name;
1215  }

Referenced by erf_init_const_dens_and_linear_th_hse(), erf_init_const_dens_and_th_hse(), erf_init_const_dens_hse(), erf_init_dens_hse_dry(), init_custom_pert(), init_custom_pert_vels(), update_geostrophic_profile(), update_rhoqt_sources(), update_rhotheta_sources(), and update_w_subsidence().

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

◆ read_custom_terrain()

void ProblemBase::read_custom_terrain ( const std::string &  fname,
const bool  is_usgs,
const amrex::Geometry &  geom,
amrex::FArrayBox &  terrain_fab,
const double &   
)
inline
851  {
852  amrex::Vector<amrex::Real> m_xterrain,m_yterrain,m_zterrain;
853 
854  int nx = 0; int ny = 0;
855 
856  if (amrex::ParallelDescriptor::IOProcessor()) {
857  // Read terrain file
858  amrex::Print()<<"Reading terrain file: "<< fname<< std::endl;
859  std::ifstream file(fname);
860 
861  if (!file.is_open()) {
862  amrex::Abort("Error: Could not open the file " + fname+ "\n");
863  }
864 
865  // Check if file is empty
866  if (file.peek() == std::ifstream::traits_type::eof()) {
867  amrex::Abort("Error: The file " + fname+ " is empty.\n");
868  }
869 
870  amrex::Real value1,value2,value3;
871 
872  if (is_usgs) {
873  amrex::Real lat_min, lon_min;
874 
875  file >> lon_min >> lat_min;
876  if(std::fabs(lon_min) > amrex::Real(180.0)) {
877  amrex::Error("The value of longitude for entry in the first line in " + fname
878  + " should not exceed amrex::Real(180.) It is " + std::to_string(lon_min));
879  }
880  if(std::fabs(lat_min) > amrex::Real(90.0)) {
881  amrex::Error("The value of latitude for entry in the first line in " + fname
882  + " should not exceed amrex::Real(90.) It is " + std::to_string(lat_min));
883  }
884 
885  file >> nx >> ny;
886 
887  int counter = 0;
888  while (file >> value1 >> value2 >> value3) {
889  m_xterrain.push_back(value1);
890  if(counter%nx==0) {
891  m_yterrain.push_back(value2);
892  }
893  m_zterrain.push_back(value3);
894  counter += 1;
895  }
896  AMREX_ASSERT(m_xterrain.size() == static_cast<long int>(nx*ny));
897  AMREX_ASSERT(m_yterrain.size() == static_cast<long int>(ny));
898  AMREX_ASSERT(m_zterrain.size() == static_cast<long int>(nx*ny));
899 
900  } else {
901  int cnt = 1;
902  nx = erf_get_single_value<int>(file,cnt); cnt++;
903  ny = erf_get_single_value<int>(file,cnt); cnt++;
904  amrex::Print()<<"Expecting " << nx << " values of x, " <<
905  ny << " values of y, and " <<
906  nx*ny << " values of z" << std::endl;
907  AMREX_ALWAYS_ASSERT(nx > 0);
908  AMREX_ALWAYS_ASSERT(ny > 0);
909  m_xterrain.resize(nx);
910  m_yterrain.resize(ny);
911  m_zterrain.resize(nx * ny);
912  for (int n = 0; n < nx; n++) {
913  m_xterrain[n] = erf_get_single_value<amrex::Real>(file,cnt);
914  cnt++;
915  }
916  for (int n = 0; n < ny; n++) {
917  m_yterrain[n] = erf_get_single_value<amrex::Real>(file,cnt);
918  cnt++;
919  }
920  for (int n = 0; n < nx * ny; n++) {
921  m_zterrain[n] = erf_get_single_value<amrex::Real>(file,cnt);
922  cnt++;
923  }
924  }
925 
926  // Close the file after reading
927  file.close();
928  }
929 
930  amrex::ParallelDescriptor::Bcast(&nx,1,amrex::ParallelDescriptor::IOProcessorNumber());
931  amrex::ParallelDescriptor::Bcast(&ny,1,amrex::ParallelDescriptor::IOProcessorNumber());
932 
933  AMREX_ALWAYS_ASSERT(nx > 0 && ny > 0);
934  if (is_usgs) {
935  // The usgs branch below always uses a full 2x2 stencil
937  "USGS terrain file must have at least two points in each direction");
938  }
939 
940  int nz = nx * ny;
941  int nx_vals = is_usgs ? (nx * ny) : nx;
942 
943  m_xterrain.resize(nx_vals);
944  m_yterrain.resize(ny);
945  m_zterrain.resize(nz);
946 
947  amrex::ParallelDescriptor::Bcast(m_xterrain.data(),nx_vals,amrex::ParallelDescriptor::IOProcessorNumber());
948  amrex::ParallelDescriptor::Bcast(m_yterrain.data(),ny,amrex::ParallelDescriptor::IOProcessorNumber());
949  amrex::ParallelDescriptor::Bcast(m_zterrain.data(),nz,amrex::ParallelDescriptor::IOProcessorNumber());
950 
951  // Copy data to the GPU
952  amrex::Gpu::DeviceVector<amrex::Real> d_xterrain(nx_vals),d_yterrain(ny),d_zterrain(nz);
953  amrex::Gpu::copy(amrex::Gpu::hostToDevice, m_xterrain.begin(), m_xterrain.end(), d_xterrain.begin());
954  amrex::Gpu::copy(amrex::Gpu::hostToDevice, m_yterrain.begin(), m_yterrain.end(), d_yterrain.begin());
955  amrex::Gpu::copy(amrex::Gpu::hostToDevice, m_zterrain.begin(), m_zterrain.end(), d_zterrain.begin());
956 
957  amrex::Real* d_xt = d_xterrain.data();
958  amrex::Real* d_yt = d_yterrain.data();
959  amrex::Real* d_zt = d_zterrain.data();
960 
961  auto dx = geom.CellSizeArray();
962  auto ProbLoArr = geom.ProbLoArray();
963 
964  int ilo = geom.Domain().smallEnd(0);
965  int jlo = geom.Domain().smallEnd(1);
966  int klo = geom.Domain().smallEnd(2);
967  int ihi = geom.Domain().bigEnd(0) + 1;
968  int jhi = geom.Domain().bigEnd(1) + 1;
969 
970  amrex::Box zbx = terrain_fab.box();
971  amrex::Array4<amrex::Real> const& z_arr = terrain_fab.array();
972 
973  amrex::ParallelFor(zbx, [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/)
974  {
975  // Clip indices for ghost cells
976  int ii = amrex::min(amrex::max(i,ilo),ihi);
977  int jj = amrex::min(amrex::max(j,jlo),jhi);
978 
979  // Location of nodes
980  amrex::Real x = ProbLoArr[0] + ii * dx[0] + amrex::Real(1e-3);
981  amrex::Real y = ProbLoArr[1] + jj * dx[1] + amrex::Real(1e-3);
982 
983  int ind11, ind12, ind21, ind22;
984  amrex::Real x1, x2, y1, y2;
985 
986  int iindex_terrain=-1;
987  int jindex_terrain=-1;
988  // *******************************************************************
989  // NOTE: usgs-format is contiguous in x
990  // *******************************************************************
991  if (is_usgs) {
992 
993  // NOTE: the searches below must distinguish "the node is below the first
994  // table value" (bracket index -1) from "no table value exceeds the
995  // node" (search never triggered), so we can not use the initial
996  // value of -1 as the not-found flag
997  bool jfound = false;
998  for (int it = 0; it < ny && !jfound; it++) {
999  if (d_yt[it] > y) {
1000  jindex_terrain = it-1; jfound = true;
1001  }
1002  }
1003  if (!jfound) {
1004  jindex_terrain = ny-1;
1005  }
1006  // Keep the 2x2 stencil inside the table
1007  jindex_terrain = amrex::min(amrex::max(jindex_terrain,0), ny-2);
1008 
1009  int gstart = (jindex_terrain )*nx;
1010  int gend = (jindex_terrain+1)*nx-1;
1011  bool ifound = false;
1012  for (int it = gstart; it <= gend && !ifound; it++) {
1013  if (d_xt[it] > x) {
1014  iindex_terrain = it-gstart-1; ifound = true;
1015  }
1016  }
1017  if (!ifound) {
1018  iindex_terrain = nx-1;
1019  }
1020  // Keep the 2x2 stencil inside the table
1021  iindex_terrain = amrex::min(amrex::max(iindex_terrain,0), nx-2);
1022 
1023  // Define the four values to interpolate between
1024  ind11 = jindex_terrain*nx + iindex_terrain; // (x1,y1)
1025  ind12 = ind11+nx; // (x1,y2)
1026  ind21 = ind11+1; // (x2,y1)
1027  ind22 = ind12+1; // (x2,y2)
1028 
1029  x1 = d_xt[ind11];
1030  x2 = d_xt[ind21];
1031  y1 = d_yt[jindex_terrain];
1032  y2 = d_yt[jindex_terrain+1];
1033 
1034  amrex::Real denom = (x2-x1)*(y2-y1);
1035 
1036  if (denom == amrex::Real(0.0)) {
1037  // Degenerate cell (repeated x or y in the table) -- use the corner value
1038  z_arr(i,j,klo) = d_zt[ind11];
1039  } else {
1040  amrex::Real w_11 = (x2-x)*(y2-y)/denom; // (x1,y1)
1041  amrex::Real w_12 = (x2-x)*(y-y1)/denom; // (x1,y2)
1042  amrex::Real w_21 = (x-x1)*(y2-y)/denom; // (x2,y1)
1043  amrex::Real w_22 = (x-x1)*(y-y1)/denom; // (x2,y2)
1044 
1045  // Do bilinear interpolation
1046  z_arr(i,j,klo) = w_11*d_zt[ind11] + w_12*d_zt[ind12] + w_21*d_zt[ind21] + w_22*d_zt[ind22];
1047  }
1048 
1049  } else {
1050 
1051  bool jfound = false;
1052  for (int it = 0; it < ny && !jfound; it++) {
1053  if (d_yt[it] > y) {
1054  jindex_terrain = it-1; jfound = true;
1055  }
1056  }
1057  if (!jfound) {
1058  // No table value exceeds y -- fall back to the last row
1059  jindex_terrain = ny-1;
1060  }
1061  jindex_terrain = amrex::max(jindex_terrain,0);
1062 
1063  bool ifound = false;
1064  for (int it = 0; it < nx && !ifound; it++) {
1065  if (d_xt[it] > x) {
1066  iindex_terrain = it-1; ifound = true;
1067  }
1068  }
1069  if (!ifound) {
1070  // No table value exceeds x -- fall back to the last column
1071  iindex_terrain = nx-1;
1072  }
1073  iindex_terrain = amrex::max(iindex_terrain,0);
1074 
1075  // NOTE: these must be clamped since the fallbacks above can leave
1076  // iindex_terrain = nx-1 (jindex_terrain = ny-1)
1077  int ip1 = amrex::min(iindex_terrain+1,nx-1);
1078  int jp1 = amrex::min(jindex_terrain+1,ny-1);
1079 
1080  // Define the four values to interpolate between
1081  x1 = d_xt[iindex_terrain];
1082  x2 = d_xt[ip1];
1083  y1 = d_yt[jindex_terrain];
1084  y2 = d_yt[jp1];
1085 
1086 #if 1
1087  // *******************************************************************
1088  // NOTE: this format is contiguous in y to match the AMR-Wind read
1089  // *******************************************************************
1090  ind11 = iindex_terrain * ny + jindex_terrain; // (x1,y1)
1091  ind21 = ip1 * ny + jindex_terrain; // (x2,y1)
1092 
1093  ind12 = iindex_terrain * ny + jp1; // (x1,y2)
1094  ind22 = ip1 * ny + jp1; // (x2,y2)
1095 #else
1096  // *******************************************************************
1097  // NOTE: this format is contiguous in x as an alternative
1098  // *******************************************************************
1099 
1100  ind11 = jindex_terrain * nx + iindex_terrain; // (x1,y1)
1101  ind12 = jp1 * nx + iindex_terrain; // (x1,y2)
1102 
1103  ind21 = jindex_terrain * nx + ip1; // (x2,y1)
1104  ind22 = jp1 * nx + ip1; // (x2,y2)
1105 #endif
1106 
1107  // Only interpolate in a direction if we have a non-degenerate interval there
1108  bool interp_x = (ip1 != iindex_terrain) && (x2 != x1);
1109  bool interp_y = (jp1 != jindex_terrain) && (y2 != y1);
1110 
1111  if (!interp_x && !interp_y)
1112  {
1113  z_arr(i,j,klo) = d_zt[ind11];
1114  }
1115  else if (interp_x && !interp_y)
1116  {
1117  amrex::Real w_11 = (x2-x); // (x1,y1)
1118  amrex::Real w_21 = (x-x1); // (x2,y1)
1119  amrex::Real denom = (x2-x1);
1120  z_arr(i,j,klo) = (w_11*d_zt[ind11] + w_21*d_zt[ind21])/denom;
1121  }
1122  else if (!interp_x && interp_y)
1123  {
1124  amrex::Real w_11 = (y2-y); // (x1,y1)
1125  amrex::Real w_12 = (y-y1); // (x1,y2)
1126  amrex::Real denom = (y2-y1);
1127  z_arr(i,j,klo) = (w_11*d_zt[ind11] + w_12*d_zt[ind12])/denom;
1128  }
1129  else
1130  {
1131  amrex::Real w_11 = (x2-x)*(y2-y); // (x1,y1)
1132  amrex::Real w_21 = (x-x1)*(y2-y); // (x2,y1)
1133  amrex::Real w_12 = (x2-x)*(y-y1); // (x1,y2)
1134  amrex::Real w_22 = (x-x1)*(y-y1); // (x2,y2)
1135  amrex::Real denom = (x2-x1)*(y2-y1);
1136  z_arr(i,j,klo) = (w_11*d_zt[ind11] + w_12*d_zt[ind12] + w_21*d_zt[ind21] + w_22*d_zt[ind22]) / denom;
1137  }
1138  } // usgs?
1139  });
1140  }
const int nx
Definition: ERF_InitCustomPertVels_CloudChamber.H:14
const int ny
Definition: ERF_InitCustomPertVels_CloudChamber.H:15
const int klo
Definition: ERF_InitCustomPert_ABL.H:75
const Real dx
Definition: ERF_InitCustomPert_ABL.H:44
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_cloud_chamber_config.active, "Cloud Chamber: initializer reached without a parsed configuration")
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

Referenced by init_buildings_surface(), and init_terrain_surface().

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

◆ terrain_is_specified()

virtual bool ProblemBase::terrain_is_specified ( )
inlinevirtual

Function to report whether the user has actually specified a terrain surface, i.e. whether init_terrain_surface will do anything other than return flat terrain.

This mirrors the source precedence in init_terrain_surface, and is deliberately kept next to it so that the two cannot drift apart. A problem that overrides the terrain unconditionally, rather than keying off prob.custom_terrain_type, should override this to return true.

400  {
401  amrex::ParmParse pp("erf");
402  std::string fname;
403  if (pp.query("terrain_file_name_nc", fname) ||
404  pp.query("terrain_file_name", fname) ||
405  pp.query("terrain_file_name_USGS", fname)) {
406  return true;
407  }
408 
409  std::string custom_terrain_type = "None";
410  amrex::ParmParse pp_prob("prob");
411  pp_prob.query("custom_terrain_type", custom_terrain_type);
412  return (custom_terrain_type != "None");
413  }
Here is the call graph for this function:

◆ update_geostrophic_profile()

virtual void ProblemBase::update_geostrophic_profile ( const double &  ,
amrex::Vector< amrex::Real > &  u_geos,
amrex::Gpu::DeviceVector< amrex::Real > &  d_u_geos,
amrex::Vector< amrex::Real > &  v_geos,
amrex::Gpu::DeviceVector< amrex::Real > &  d_v_geos,
const amrex::Geometry &  geom,
std::unique_ptr< amrex::MultiFab > &   
)
inlinevirtual

Function to update user-specified geostrophic wind profile.

Parameters
[in]timecurrent time
[out]u_geosgeostrophic wind profile
[out]v_geosgeostrophic wind profile
[in]geomcontainer for geometric information
[in]z_phys_ccheight coordinate at cell centers
304  {
305  if (u_geos.empty()) return;
306 
307  amrex::Warning("Geostrophic wind profile not defined for "+name()+" problem");
308 
309  const int khi = geom.Domain().bigEnd()[2];
310  // const amrex::Real* prob_lo = geom.ProbLo();
311  // const auto dx = geom.CellSize();
312  for (int k = 0; k <= khi; k++)
313  {
314  // const amrex::Real z_cc = prob_lo[2] + (k+myhalf)* dx[2];
315  // set RHS term of RhoTheta equation based on time, z_cc here
316  u_geos[k] = zero;
317  v_geos[k] = zero;
318  }
319 
320  // Copy from host version to device version
321  amrex::Gpu::copy(amrex::Gpu::hostToDevice, u_geos.begin(), u_geos.end(), d_u_geos.begin());
322  amrex::Gpu::copy(amrex::Gpu::hostToDevice, v_geos.begin(), v_geos.end(), d_v_geos.begin());
323  }
const int khi
Definition: ERF_InitCustomPert_Bubble.H:21
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:29
Here is the call graph for this function:

◆ update_rhoqt_sources()

virtual void ProblemBase::update_rhoqt_sources ( const double &  ,
amrex::MultiFab *  qsrc,
const amrex::Geometry &  ,
std::unique_ptr< amrex::MultiFab > &   
)
inlinevirtual

Function to update user-specified moisture source terms that can vary with time and height.

Parameters
[in]timecurrent time
[out]rhoqt_sourcemoisture forcing profile
[in]geomcontainer for geometric information
[in]z_phys_ccheight coordinate at cell centers
231  {
232  if (qsrc->empty()) return;
233 
234  amrex::Warning("Moisture forcing not defined for "+name()+" problem");
235  for ( amrex::MFIter mfi(*qsrc, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi )
236  {
237  const auto &box = mfi.tilebox();
238  const amrex::Array4<amrex::Real>& qsrc_arr = qsrc->array(mfi);
239  // src is a spatial function if erf.spatial_moisture_forcing = true
240  // otherwise, qsrc_arr is defined only in over Z (box x and y dimensions are 1)
241  ParallelFor(box, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
242  // const amrex::Real z_cc = prob_lo[2] + (k+myhalf)* dx[2];
243  // set RHS term of RhoQ1 equation based on time, z_cc here
244  qsrc_arr(i, j, k) = zero;
245  });
246  }
247  }
Here is the call graph for this function:

◆ update_rhotheta_sources()

virtual void ProblemBase::update_rhotheta_sources ( const double &  ,
amrex::MultiFab *  src,
const amrex::Geometry &  ,
std::unique_ptr< amrex::MultiFab > &   
)
inlinevirtual

Function to update user-specified temperature source terms that can vary with time and height.

Parameters
[in]timecurrent time
[out]rhotheta_sourceforcing profile
[in]geomcontainer for geometric information
[in]z_phys_ccheight coordinate at cell centers
199  {
200  if (src->empty()) return;
201 
202  amrex::Warning("Temperature forcing not defined for "+name()+" problem");
203  for ( amrex::MFIter mfi(*src, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi )
204  {
205  const auto &box = mfi.tilebox();
206  const amrex::Array4<amrex::Real>& src_arr = src->array(mfi);
207  // src is a spatial function if erf.spatial_rhotheta_forcing = true
208  // otherwise, qsrc_arr is defined only in over Z (box x and y dimensions are 1)
209  ParallelFor(box, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
210  // const amrex::Real z_cc = prob_lo[2] + (k+myhalf)* dx[2];
211  // set RHS term of RhoTheta equation based on time, z_cc here
212  src_arr(i, j, k) = zero;
213  });
214  }
215  }
Here is the call graph for this function:

◆ update_w_subsidence()

virtual void ProblemBase::update_w_subsidence ( const double &  ,
amrex::Vector< amrex::Real > &  wbar,
amrex::Gpu::DeviceVector< amrex::Real > &  d_wbar,
const amrex::MultiFab &  ,
const amrex::Geometry &  geom,
std::unique_ptr< amrex::MultiFab > &   
)
inlinevirtual

Function to update the vertical velocity profile, used to add subsidence source terms for x-mom, y-mom, rho*theta, rho*Q1, and rho*Q2.

TODO: Currently, this is only called by InitData, so there is no time dependence.

Parameters
[in]timecurrent time
[out]wbarw vel forcing profile
[in]geomcontainer for geometric information
[in]z_phys_ccheight coordinate at cell centers
268  {
269  if (wbar.empty()) return;
270 
271  amrex::Warning("Moisture forcing not defined for "+name()+" problem");
272 
273  const int khi = geom.Domain().bigEnd()[2];
274  // const amrex::Real* prob_lo = geom.ProbLo();
275  // const auto dx = geom.CellSize();
276  for (int k = 0; k <= khi; k++)
277  {
278  // const amrex::Real z_cc = prob_lo[2] + (k+myhalf)* dx[2];
279  // set vertical velocity profile based on time, z_cc here
280  wbar[k] = zero;
281  }
282 
283  // Copy from host version to device version
284  amrex::Gpu::copy(amrex::Gpu::hostToDevice, wbar.begin(), wbar.end(), d_wbar.begin());
285  }
@ wbar
Definition: ERF_DataStruct.H:179
Here is the call graph for this function:

Member Data Documentation

◆ base_parms

ProbParmDefaults ProblemBase::base_parms
protected

Referenced by init_base_parms().


The documentation for this class was generated from the following file: