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)
 
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
109  {
110  amrex::Error("Should never call this version of erf_init_const_dens_and_linear_th_hse for "+name()+" problem");
111  }
std::string name()
Definition: ERF_ProbCommon.H:1184
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
100  {
101  amrex::Error("Should never call this version of erf_init_const_dens_and_th_hse for "+name()+" problem");
102  }
Here is the call graph for this function:

◆ erf_init_const_dens_hse()

virtual void ProblemBase::erf_init_const_dens_hse ( amrex::MultiFab &  )
inlinevirtual
92  {
93  amrex::Error("Should never call this version of erf_init_const_dens_hse for "+name()+" problem");
94  }
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
82  {
83  amrex::Print() << "Hydrostatically balanced density was NOT set"
84  << " -- an appropriate init_type should probably have been specified"
85  << " (e.g., input_sounding, WRFInput, or Metgrid)"
86  << std::endl;
87  amrex::Error("Should never call this version of erf_init_dens_hse_dry for "+name()+" problem");
88  }
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
117  {
118 
119  }

◆ 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
1167  {
1168  // Default which does no harm
1169  }

◆ 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

1179  {
1181  base_parms.T_0 = T_0;
1182  }
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:1173
amrex::Real T_0
Definition: ERF_ProbCommon.H:26
amrex::Real rho_0
Definition: ERF_ProbCommon.H:25

◆ 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
335  {
336  // Check if a valid text file exists for the buildings
337  std::string fname;
338  amrex::ParmParse pp("erf");
339  auto valid_fname = pp.queryAdd("buildings_file_name",fname);
340 
341  if (valid_fname) {
342  read_custom_terrain(fname,false,geom,buildings_fab,time);
343  } else {
344  init_my_custom_terrain(geom, buildings_fab, time);
345  }
346  }
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:819
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
147  {
148  amrex::Print() << "No perturbation to background fields supplied for "
149  << name() << " problem" << std::endl;
150  }
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
180  {
181  amrex::Print() << "No perturbation velocities supplied for " << name() << " problem" << std::endl;
182  }
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
1128  {
1129  std::string custom_terrain_type = "None";
1130  amrex::ParmParse pp_prob("prob"); pp_prob.queryAdd("custom_terrain_type",custom_terrain_type);
1131 
1132  if (custom_terrain_type != "None")
1133  {
1134  amrex::Print() << "Calling custom terrain initialization" << std::endl;
1135  init_my_custom_terrain(geom,terrain_fab,time);
1136 
1137  } else {
1138  amrex::Print() << "Initializing flat terrain" << std::endl;
1139  terrain_fab.template setVal<amrex::RunOn::Device>(0);
1140 
1141  if (SolverChoice::mesh_type == MeshType::VariableDz) {
1142  SolverChoice::set_mesh_type(MeshType::StretchedDz);
1143  amrex::Print() << "Resetting mesh type to StretchedDz" << std::endl;
1144  }
1145  }
1146  }
ParmParse pp_prob("prob")
static MeshType mesh_type
Vertical mesh representation.
Definition: ERF_DataStruct.H:1848
static void set_mesh_type(MeshType new_mesh_type)
Override the globally selected mesh type.
Definition: ERF_DataStruct.H:1855
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
360  {
361  amrex::ParmParse pp("erf");
362 
363  // NetCDF terrain file takes priority
364  std::string fname_nc;
365  auto valid_fname_nc = pp.query("terrain_file_name_nc", fname_nc);
366 
367  std::string fname, fname_usgs;
368  auto valid_fname = pp.query("terrain_file_name", fname);
369  auto valid_fname_USGS = pp.query("terrain_file_name_USGS", fname_usgs);
370 
371  if (valid_fname_nc) {
372 #ifdef ERF_USE_NETCDF
373  read_terrain_netcdf(fname_nc, geom, terrain_fab, time);
374 #else
375  amrex::Abort("ERF must be compiled with NetCDF support to use terrain_file_name_nc");
376 #endif
377  } else if (valid_fname) {
378  read_custom_terrain(fname, false, geom, terrain_fab, time);
379 
380  } else if (valid_fname_USGS) {
381  read_custom_terrain(fname_usgs, true, geom, terrain_fab, time);
382 
383  } else {
384  init_my_custom_terrain (geom, terrain_fab, time);
385  }
386  }
Here is the call graph for this function:

◆ name()

std::string ProblemBase::name ( )
inlineprotected
1184  {
1185  std::string prob_name;
1186  amrex::ParmParse pp("erf");
1187  pp.get("prob_name",prob_name); return prob_name;
1188  }

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

◆ 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
303  {
304  if (u_geos.empty()) return;
305 
306  amrex::Warning("Geostrophic wind profile not defined for "+name()+" problem");
307 
308  const int khi = geom.Domain().bigEnd()[2];
309  // const amrex::Real* prob_lo = geom.ProbLo();
310  // const auto dx = geom.CellSize();
311  for (int k = 0; k <= khi; k++)
312  {
313  // const amrex::Real z_cc = prob_lo[2] + (k+myhalf)* dx[2];
314  // set RHS term of RhoTheta equation based on time, z_cc here
315  u_geos[k] = zero;
316  v_geos[k] = zero;
317  }
318 
319  // Copy from host version to device version
320  amrex::Gpu::copy(amrex::Gpu::hostToDevice, u_geos.begin(), u_geos.end(), d_u_geos.begin());
321  amrex::Gpu::copy(amrex::Gpu::hostToDevice, v_geos.begin(), v_geos.end(), d_v_geos.begin());
322  }
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
const int khi
Definition: ERF_InitCustomPert_Bubble.H:21
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
230  {
231  if (qsrc->empty()) return;
232 
233  amrex::Warning("Moisture forcing not defined for "+name()+" problem");
234  for ( amrex::MFIter mfi(*qsrc, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi )
235  {
236  const auto &box = mfi.tilebox();
237  const amrex::Array4<amrex::Real>& qsrc_arr = qsrc->array(mfi);
238  // src is a spatial function if erf.spatial_moisture_forcing = true
239  // otherwise, qsrc_arr is defined only in over Z (box x and y dimensions are 1)
240  ParallelFor(box, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
241  // const amrex::Real z_cc = prob_lo[2] + (k+myhalf)* dx[2];
242  // set RHS term of RhoQ1 equation based on time, z_cc here
243  qsrc_arr(i, j, k) = zero;
244  });
245  }
246  }
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
198  {
199  if (src->empty()) return;
200 
201  amrex::Warning("Temperature forcing not defined for "+name()+" problem");
202  for ( amrex::MFIter mfi(*src, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi )
203  {
204  const auto &box = mfi.tilebox();
205  const amrex::Array4<amrex::Real>& src_arr = src->array(mfi);
206  // src is a spatial function if erf.spatial_rhotheta_forcing = true
207  // otherwise, qsrc_arr is defined only in over Z (box x and y dimensions are 1)
208  ParallelFor(box, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
209  // const amrex::Real z_cc = prob_lo[2] + (k+myhalf)* dx[2];
210  // set RHS term of RhoTheta equation based on time, z_cc here
211  src_arr(i, j, k) = zero;
212  });
213  }
214  }
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
267  {
268  if (wbar.empty()) return;
269 
270  amrex::Warning("Moisture forcing not defined for "+name()+" problem");
271 
272  const int khi = geom.Domain().bigEnd()[2];
273  // const amrex::Real* prob_lo = geom.ProbLo();
274  // const auto dx = geom.CellSize();
275  for (int k = 0; k <= khi; k++)
276  {
277  // const amrex::Real z_cc = prob_lo[2] + (k+myhalf)* dx[2];
278  // set vertical velocity profile based on time, z_cc here
279  wbar[k] = zero;
280  }
281 
282  // Copy from host version to device version
283  amrex::Gpu::copy(amrex::Gpu::hostToDevice, wbar.begin(), wbar.end(), d_wbar.begin());
284  }
@ wbar
Definition: ERF_DataStruct.H:153
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: