ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ERF Class Reference

#include <ERF.H>

Inheritance diagram for ERF:
Collaboration diagram for ERF:

Public Member Functions

 ERF ()
 
 ~ERF () override
 
void ERF_shared ()
 
 ERF (ERF &&) noexcept=delete
 
ERFoperator= (ERF &&other) noexcept=delete
 
 ERF (const ERF &other)=delete
 
ERFoperator= (const ERF &other)=delete
 
void Evolve ()
 
void ErrorEst (int lev, amrex::TagBoxArray &tags, amrex::Real time, int ngrow) override
 
void HurricaneTracker (int lev, const amrex::MultiFab &U_new, const amrex::MultiFab &V_new, const amrex::MultiFab &W_new, const amrex::Real velmag_threshold, const bool is_track_io, amrex::TagBoxArray *tags=nullptr)
 
std::string MakeVTKFilename (int nstep)
 
void WriteVTKPolyline (const std::string &filename, amrex::Vector< std::array< amrex::Real, 2 >> &points_xy)
 
void InitData ()
 
void InitData_pre ()
 
void InitData_post ()
 
void WriteMyEBSurface ()
 
void compute_divergence (int lev, amrex::MultiFab &rhs, amrex::Array< amrex::MultiFab const *, AMREX_SPACEDIM > rho0_u_const, amrex::Geometry const &geom_at_lev)
 
void project_velocity (int lev, amrex::Real dt)
 
void project_momenta (int lev, amrex::Real dt, amrex::Vector< amrex::MultiFab > &vars)
 
void project_velocity_tb (int lev, amrex::Real dt, amrex::Vector< amrex::MultiFab > &vars)
 
void poisson_wall_dist (int lev)
 
void solve_with_EB_mlmg (int lev, amrex::Vector< amrex::MultiFab > &rhs, amrex::Vector< amrex::MultiFab > &p, amrex::Vector< amrex::Array< amrex::MultiFab, AMREX_SPACEDIM >> &fluxes)
 
void solve_with_gmres (int lev, amrex::Vector< amrex::MultiFab > &rhs, amrex::Vector< amrex::MultiFab > &p, amrex::Vector< amrex::Array< amrex::MultiFab, AMREX_SPACEDIM >> &fluxes)
 
void solve_with_mlmg (int lev, amrex::Vector< amrex::MultiFab > &rhs, amrex::Vector< amrex::MultiFab > &p, amrex::Vector< amrex::Array< amrex::MultiFab, AMREX_SPACEDIM >> &fluxes)
 
void ImposeBCsOnPhi (int lev, amrex::MultiFab &phi)
 
amrex::Array< amrex::LinOpBCType, AMREX_SPACEDIM > get_projection_bc (amrex::Orientation::Side side) const noexcept
 
bool projection_has_dirichlet (amrex::Array< amrex::LinOpBCType, AMREX_SPACEDIM > bcs) const
 
void init_only (int lev, amrex::Real time)
 
void restart ()
 
bool writeNow (const amrex::Real cur_time, const amrex::Real dt, const int nstep, const int plot_int, const amrex::Real plot_per)
 
void post_timestep (int nstep, amrex::Real time, amrex::Real dt_lev)
 
void sum_integrated_quantities (amrex::Real time)
 
void sum_derived_quantities (amrex::Real time)
 
void sum_energy_quantities (amrex::Real time)
 
void write_1D_profiles (amrex::Real time)
 
void write_1D_profiles_stag (amrex::Real time)
 
amrex::Real cloud_fraction (amrex::Real time)
 
void FillBdyCCVels (amrex::Vector< amrex::MultiFab > &mf_cc_vel, int levc=0)
 
void sample_points (int lev, amrex::Real time, amrex::IntVect cell, amrex::MultiFab &mf)
 
void sample_lines (int lev, amrex::Real time, amrex::IntVect cell, amrex::MultiFab &mf)
 
void derive_diag_profiles (amrex::Real time, amrex::Gpu::HostVector< amrex::Real > &h_avg_u, amrex::Gpu::HostVector< amrex::Real > &h_avg_v, amrex::Gpu::HostVector< amrex::Real > &h_avg_w, amrex::Gpu::HostVector< amrex::Real > &h_avg_rho, amrex::Gpu::HostVector< amrex::Real > &h_avg_th, amrex::Gpu::HostVector< amrex::Real > &h_avg_ksgs, amrex::Gpu::HostVector< amrex::Real > &h_avg_Kmv, amrex::Gpu::HostVector< amrex::Real > &h_avg_Khv, amrex::Gpu::HostVector< amrex::Real > &h_avg_qv, amrex::Gpu::HostVector< amrex::Real > &h_avg_qc, amrex::Gpu::HostVector< amrex::Real > &h_avg_qr, amrex::Gpu::HostVector< amrex::Real > &h_avg_wqv, amrex::Gpu::HostVector< amrex::Real > &h_avg_wqc, amrex::Gpu::HostVector< amrex::Real > &h_avg_wqr, amrex::Gpu::HostVector< amrex::Real > &h_avg_qi, amrex::Gpu::HostVector< amrex::Real > &h_avg_qs, amrex::Gpu::HostVector< amrex::Real > &h_avg_qg, amrex::Gpu::HostVector< amrex::Real > &h_avg_uu, amrex::Gpu::HostVector< amrex::Real > &h_avg_uv, amrex::Gpu::HostVector< amrex::Real > &h_avg_uw, amrex::Gpu::HostVector< amrex::Real > &h_avg_vv, amrex::Gpu::HostVector< amrex::Real > &h_avg_vw, amrex::Gpu::HostVector< amrex::Real > &h_avg_ww, amrex::Gpu::HostVector< amrex::Real > &h_avg_uth, amrex::Gpu::HostVector< amrex::Real > &h_avg_vth, amrex::Gpu::HostVector< amrex::Real > &h_avg_wth, amrex::Gpu::HostVector< amrex::Real > &h_avg_thth, amrex::Gpu::HostVector< amrex::Real > &h_avg_ku, amrex::Gpu::HostVector< amrex::Real > &h_avg_kv, amrex::Gpu::HostVector< amrex::Real > &h_avg_kw, amrex::Gpu::HostVector< amrex::Real > &h_avg_p, amrex::Gpu::HostVector< amrex::Real > &h_avg_pu, amrex::Gpu::HostVector< amrex::Real > &h_avg_pv, amrex::Gpu::HostVector< amrex::Real > &h_avg_pw, amrex::Gpu::HostVector< amrex::Real > &h_avg_wthv)
 
void derive_diag_profiles_stag (amrex::Real time, amrex::Gpu::HostVector< amrex::Real > &h_avg_u, amrex::Gpu::HostVector< amrex::Real > &h_avg_v, amrex::Gpu::HostVector< amrex::Real > &h_avg_w, amrex::Gpu::HostVector< amrex::Real > &h_avg_rho, amrex::Gpu::HostVector< amrex::Real > &h_avg_th, amrex::Gpu::HostVector< amrex::Real > &h_avg_ksgs, amrex::Gpu::HostVector< amrex::Real > &h_avg_Kmv, amrex::Gpu::HostVector< amrex::Real > &h_avg_Khv, amrex::Gpu::HostVector< amrex::Real > &h_avg_qv, amrex::Gpu::HostVector< amrex::Real > &h_avg_qc, amrex::Gpu::HostVector< amrex::Real > &h_avg_qr, amrex::Gpu::HostVector< amrex::Real > &h_avg_wqv, amrex::Gpu::HostVector< amrex::Real > &h_avg_wqc, amrex::Gpu::HostVector< amrex::Real > &h_avg_wqr, amrex::Gpu::HostVector< amrex::Real > &h_avg_qi, amrex::Gpu::HostVector< amrex::Real > &h_avg_qs, amrex::Gpu::HostVector< amrex::Real > &h_avg_qg, amrex::Gpu::HostVector< amrex::Real > &h_avg_uu, amrex::Gpu::HostVector< amrex::Real > &h_avg_uv, amrex::Gpu::HostVector< amrex::Real > &h_avg_uw, amrex::Gpu::HostVector< amrex::Real > &h_avg_vv, amrex::Gpu::HostVector< amrex::Real > &h_avg_vw, amrex::Gpu::HostVector< amrex::Real > &h_avg_ww, amrex::Gpu::HostVector< amrex::Real > &h_avg_uth, amrex::Gpu::HostVector< amrex::Real > &h_avg_vth, amrex::Gpu::HostVector< amrex::Real > &h_avg_wth, amrex::Gpu::HostVector< amrex::Real > &h_avg_thth, amrex::Gpu::HostVector< amrex::Real > &h_avg_ku, amrex::Gpu::HostVector< amrex::Real > &h_avg_kv, amrex::Gpu::HostVector< amrex::Real > &h_avg_kw, amrex::Gpu::HostVector< amrex::Real > &h_avg_p, amrex::Gpu::HostVector< amrex::Real > &h_avg_pu, amrex::Gpu::HostVector< amrex::Real > &h_avg_pv, amrex::Gpu::HostVector< amrex::Real > &h_avg_pw, amrex::Gpu::HostVector< amrex::Real > &h_avg_wthv)
 
void derive_stress_profiles (amrex::Gpu::HostVector< amrex::Real > &h_avg_tau11, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau12, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau13, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau22, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau23, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau33, amrex::Gpu::HostVector< amrex::Real > &h_avg_hfx3, amrex::Gpu::HostVector< amrex::Real > &h_avg_q1fx3, amrex::Gpu::HostVector< amrex::Real > &h_avg_q2fx3, amrex::Gpu::HostVector< amrex::Real > &h_avg_diss)
 
void derive_stress_profiles_stag (amrex::Gpu::HostVector< amrex::Real > &h_avg_tau11, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau12, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau13, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau22, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau23, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau33, amrex::Gpu::HostVector< amrex::Real > &h_avg_hfx3, amrex::Gpu::HostVector< amrex::Real > &h_avg_q1fx3, amrex::Gpu::HostVector< amrex::Real > &h_avg_q2fx3, amrex::Gpu::HostVector< amrex::Real > &h_avg_diss)
 
amrex::Real volWgtSumMF (int lev, const amrex::MultiFab &mf, int comp, bool finemask)
 
void MakeNewLevelFromCoarse (int lev, amrex::Real time, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm) override
 
void RemakeLevel (int lev, amrex::Real time, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm) override
 
void ClearLevel (int lev) override
 
void MakeNewLevelFromScratch (int lev, amrex::Real time, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm) override
 
amrex::Real estTimeStep (int lev, long &dt_fast_ratio) const
 
void advance_dycore (int level, amrex::Vector< amrex::MultiFab > &state_old, amrex::Vector< amrex::MultiFab > &state_new, amrex::MultiFab &xvel_old, amrex::MultiFab &yvel_old, amrex::MultiFab &zvel_old, amrex::MultiFab &xvel_new, amrex::MultiFab &yvel_new, amrex::MultiFab &zvel_new, amrex::MultiFab &source, amrex::MultiFab &xmom_src, amrex::MultiFab &ymom_src, amrex::MultiFab &zmom_src, amrex::MultiFab &buoyancy, amrex::Geometry fine_geom, amrex::Real dt, amrex::Real time)
 
void advance_microphysics (int lev, amrex::MultiFab &cons_in, const amrex::Real &dt_advance, const int &iteration, const amrex::Real &time)
 
void advance_lsm (int lev, amrex::MultiFab &cons_in, amrex::MultiFab &xvel_in, amrex::MultiFab &yvel_in, const amrex::Real &dt_advance)
 
void advance_radiation (int lev, amrex::MultiFab &cons_in, const amrex::Real &dt_advance)
 
amrex::MultiFab & build_fine_mask (int lev)
 
void MakeHorizontalAverages ()
 
void MakeDiagnosticAverage (amrex::Vector< amrex::Real > &h_havg, amrex::MultiFab &S, int n)
 
void derive_upwp (amrex::Vector< amrex::Real > &h_havg)
 
void WritePlotFile (int which, PlotFileType plotfile_type, amrex::Vector< std::string > plot_var_names)
 
void WriteSubvolume ()
 
void WriteMultiLevelPlotfileWithTerrain (const std::string &plotfilename, int nlevels, const amrex::Vector< const amrex::MultiFab * > &mf, const amrex::Vector< const amrex::MultiFab * > &mf_nd, const amrex::Vector< std::string > &varnames, const amrex::Vector< amrex::Geometry > &my_geom, amrex::Real time, const amrex::Vector< int > &level_steps, const amrex::Vector< amrex::IntVect > &my_ref_ratio, const std::string &versionName="HyperCLaw-V1.1", const std::string &levelPrefix="Level_", const std::string &mfPrefix="Cell", const amrex::Vector< std::string > &extra_dirs=amrex::Vector< std::string >()) const
 
void WriteGenericPlotfileHeaderWithTerrain (std::ostream &HeaderFile, int nlevels, const amrex::Vector< amrex::BoxArray > &bArray, const amrex::Vector< std::string > &varnames, const amrex::Vector< amrex::Geometry > &my_geom, amrex::Real time, const amrex::Vector< int > &level_steps, const amrex::Vector< amrex::IntVect > &my_ref_ratio, const std::string &versionName, const std::string &levelPrefix, const std::string &mfPrefix) const
 
void erf_enforce_hse (int lev, amrex::MultiFab &dens, amrex::MultiFab &pres, amrex::MultiFab &pi, amrex::MultiFab &th, amrex::MultiFab &qv, std::unique_ptr< amrex::MultiFab > &z_cc)
 
void init_from_input_sounding (int lev)
 
void input_sponge (int lev)
 
void init_from_hse (int lev)
 
void init_thin_body (int lev, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm)
 
void fill_from_bndryregs (const amrex::Vector< amrex::MultiFab * > &mfs, amrex::Real time)
 
void MakeEBGeometry ()
 
void make_eb_box ()
 
void make_eb_regular ()
 
void AverageDownTo (int crse_lev, int scomp, int ncomp)
 
void WriteCheckpointFile () const
 
void ReadCheckpointFile ()
 
void ReadCheckpointFileSurfaceLayer ()
 
void init_zphys (int lev, amrex::Real time)
 
void remake_zphys (int lev, amrex::Real time, std::unique_ptr< amrex::MultiFab > &temp_zphys_nd)
 
void update_terrain_arrays (int lev)
 
void writeJobInfo (const std::string &dir) const
 

Static Public Member Functions

static bool is_it_time_for_action (int nstep, amrex::Real time, amrex::Real dt, int action_interval, amrex::Real action_per)
 
static void writeBuildInfo (std::ostream &os)
 
static void print_banner (MPI_Comm, std::ostream &)
 
static void print_usage (MPI_Comm, std::ostream &)
 
static void print_error (MPI_Comm, const std::string &msg)
 
static void print_summary (std::ostream &)
 
static void print_tpls (std::ostream &)
 

Public Attributes

amrex::Vector< std::array< amrex::Real, 2 > > hurricane_track_xy
 
std::string pp_prefix {"erf"}
 

Private Member Functions

void ReadParameters ()
 
void ParameterSanityChecks ()
 
void AverageDown ()
 
void update_diffusive_arrays (int lev, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm)
 
void Construct_ERFFillPatchers (int lev)
 
void Define_ERFFillPatchers (int lev)
 
void init1DArrays ()
 
void init_bcs ()
 
void init_custom (int lev)
 
void init_uniform (int lev)
 
void init_stuff (int lev, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm, amrex::Vector< amrex::MultiFab > &lev_new, amrex::Vector< amrex::MultiFab > &lev_old, amrex::MultiFab &tmp_base_state, std::unique_ptr< amrex::MultiFab > &tmp_zphys_nd)
 
void turbPert_update (const int lev, const amrex::Real dt)
 
void turbPert_amplitude (const int lev)
 
void initialize_integrator (int lev, amrex::MultiFab &cons_mf, amrex::MultiFab &vel_mf)
 
void make_physbcs (int lev)
 
void initializeMicrophysics (const int &)
 
void FillPatch (int lev, amrex::Real time, const amrex::Vector< amrex::MultiFab * > &mfs_vel, bool cons_only=false)
 
void FillPatch (int lev, amrex::Real time, const amrex::Vector< amrex::MultiFab * > &mfs_vel, const amrex::Vector< amrex::MultiFab * > &mfs_mom, const amrex::MultiFab &old_base_state, const amrex::MultiFab &new_base_state, bool fillset=true, bool cons_only=false)
 
void FillIntermediatePatch (int lev, amrex::Real time, const amrex::Vector< amrex::MultiFab * > &mfs_vel, const amrex::Vector< amrex::MultiFab * > &mfs_mom, int ng_cons, int ng_vel, bool cons_only, int icomp_cons, int ncomp_cons)
 
void FillCoarsePatch (int lev, amrex::Real time)
 
void timeStep (int lev, amrex::Real time, int iteration)
 
void Advance (int lev, amrex::Real time, amrex::Real dt_lev, int iteration, int ncycle)
 
void initHSE ()
 Initialize HSE. More...
 
void initHSE (int lev)
 
void initRayleigh ()
 Initialize Rayleigh damping profiles. More...
 
void initSponge ()
 Initialize sponge profiles. More...
 
void setRayleighRefFromSounding (bool restarting)
 Set Rayleigh mean profiles from input sounding. More...
 
void setSpongeRefFromSounding (bool restarting)
 Set sponge mean profiles from input sounding. More...
 
void ComputeDt (int step=-1)
 
std::string PlotFileName (int lev) const
 
void setPlotVariables (const std::string &pp_plot_var_names, amrex::Vector< std::string > &plot_var_names)
 
void appendPlotVariables (const std::string &pp_plot_var_names, amrex::Vector< std::string > &plot_var_names)
 
void init_Dirichlet_bc_data (const std::string input_file)
 
void InitializeFromFile ()
 
void InitializeLevelFromData (int lev, const amrex::MultiFab &initial_data)
 
void post_update (amrex::MultiFab &state_mf, amrex::Real time, const amrex::Geometry &geom)
 
void fill_rhs (amrex::MultiFab &rhs_mf, const amrex::MultiFab &state_mf, amrex::Real time, const amrex::Geometry &geom)
 
void init_geo_wind_profile (const std::string input_file, amrex::Vector< amrex::Real > &u_geos, amrex::Gpu::DeviceVector< amrex::Real > &u_geos_d, amrex::Vector< amrex::Real > &v_geos, amrex::Gpu::DeviceVector< amrex::Real > &v_geos_d, const amrex::Geometry &lgeom, const amrex::Vector< amrex::Real > &zlev_stag)
 
void refinement_criteria_setup ()
 
AMREX_FORCE_INLINE amrex::YAFluxRegister * getAdvFluxReg (int lev)
 
AMREX_FORCE_INLINE std::ostream & DataLog (int i)
 
AMREX_FORCE_INLINE std::ostream & DerDataLog (int i)
 
AMREX_FORCE_INLINE int NumDataLogs () noexcept
 
AMREX_FORCE_INLINE int NumDerDataLogs () noexcept
 
AMREX_FORCE_INLINE std::ostream & SamplePointLog (int i)
 
AMREX_FORCE_INLINE int NumSamplePointLogs () noexcept
 
AMREX_FORCE_INLINE std::ostream & SampleLineLog (int i)
 
AMREX_FORCE_INLINE int NumSampleLineLogs () noexcept
 
amrex::IntVect & SamplePoint (int i)
 
AMREX_FORCE_INLINE int NumSamplePoints () noexcept
 
amrex::IntVect & SampleLine (int i)
 
AMREX_FORCE_INLINE int NumSampleLines () noexcept
 
void setRecordDataInfo (int i, const std::string &filename)
 
void setRecordDerDataInfo (int i, const std::string &filename)
 
void setRecordEnergyDataInfo (int i, const std::string &filename)
 
void setRecordSamplePointInfo (int i, int lev, amrex::IntVect &cell, const std::string &filename)
 
void setRecordSampleLineInfo (int i, int lev, amrex::IntVect &cell, const std::string &filename)
 
std::string DataLogName (int i) const noexcept
 The filename of the ith datalog file. More...
 
std::string DerDataLogName (int i) const noexcept
 
std::string SamplePointLogName (int i) const noexcept
 The filename of the ith sampleptlog file. More...
 
std::string SampleLineLogName (int i) const noexcept
 The filename of the ith samplelinelog file. More...
 
eb_ const & get_eb (int lev) const noexcept
 
amrex::EBFArrayBoxFactory const & EBFactory (int lev) const noexcept
 

Static Private Member Functions

static amrex::Vector< std::string > PlotFileVarNames (amrex::Vector< std::string > plot_var_names)
 
static void GotoNextLine (std::istream &is)
 
static AMREX_FORCE_INLINE int ComputeGhostCells (const SolverChoice &sc)
 
static amrex::Real getCPUTime ()
 
static int nghost_eb_basic ()
 
static int nghost_eb_volume ()
 
static int nghost_eb_full ()
 

Private Attributes

amrex::Vector< std::unique_ptr< amrex::MultiFab > > sinPhi_m
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > cosPhi_m
 
InputSoundingData input_sounding_data
 
InputSpongeData input_sponge_data
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > xvel_bc_data
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > yvel_bc_data
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > zvel_bc_data
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > th_bc_data
 
std::unique_ptr< ProblemBaseprob = nullptr
 
amrex::Vector< int > num_boxes_at_level
 
amrex::Vector< int > num_files_at_level
 
amrex::Vector< amrex::Vector< amrex::Box > > boxes_at_level
 
amrex::Vector< int > istep
 
amrex::Vector< int > nsubsteps
 
amrex::Vector< amrex::Real > t_new
 
amrex::Vector< amrex::Real > t_old
 
amrex::Vector< amrex::Real > dt
 
amrex::Vector< long > dt_mri_ratio
 
amrex::Vector< amrex::Vector< amrex::MultiFab > > vars_new
 
amrex::Vector< amrex::Vector< amrex::MultiFab > > vars_old
 
amrex::Vector< amrex::Vector< amrex::MultiFab > > gradp
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vel_t_avg
 
amrex::Vector< amrex::Real > t_avg_cnt
 
amrex::Vector< std::unique_ptr< MRISplitIntegrator< amrex::Vector< amrex::MultiFab > > > > mri_integrator_mem
 
amrex::Vector< amrex::MultiFab > pp_inc
 
amrex::Vector< std::unique_ptr< ERFPhysBCFunct_cons > > physbcs_cons
 
amrex::Vector< std::unique_ptr< ERFPhysBCFunct_u > > physbcs_u
 
amrex::Vector< std::unique_ptr< ERFPhysBCFunct_v > > physbcs_v
 
amrex::Vector< std::unique_ptr< ERFPhysBCFunct_w > > physbcs_w
 
amrex::Vector< std::unique_ptr< ERFPhysBCFunct_base > > physbcs_base
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Theta_prim
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Qv_prim
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Qr_prim
 
amrex::Vector< amrex::MultiFab > rU_old
 
amrex::Vector< amrex::MultiFab > rU_new
 
amrex::Vector< amrex::MultiFab > rV_old
 
amrex::Vector< amrex::MultiFab > rV_new
 
amrex::Vector< amrex::MultiFab > rW_old
 
amrex::Vector< amrex::MultiFab > rW_new
 
amrex::Vector< amrex::MultiFab > zmom_crse_rhs
 
std::unique_ptr< Microphysicsmicro
 
amrex::Vector< amrex::Vector< amrex::MultiFab * > > qmoist
 
LandSurface lsm
 
amrex::Vector< amrex::Vector< amrex::MultiFab * > > lsm_data
 
amrex::Vector< amrex::Vector< amrex::MultiFab * > > lsm_flux
 
amrex::Vector< std::unique_ptr< IRadiation > > rad
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > qheating_rates
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > sw_lw_fluxes
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > solar_zenith
 
bool plot_rad = false
 
int rad_datalog_int = -1
 
int cf_width {0}
 
int cf_set_width {0}
 
amrex::Vector< ERFFillPatcherFPr_c
 
amrex::Vector< ERFFillPatcherFPr_u
 
amrex::Vector< ERFFillPatcherFPr_v
 
amrex::Vector< ERFFillPatcherFPr_w
 
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > Tau
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > eddyDiffs_lev
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SmnSmn_lev
 
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > sst_lev
 
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > tsk_lev
 
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::iMultiFab > > > lmask_lev
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_hfx1_lev
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_hfx2_lev
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_hfx3_lev
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_diss_lev
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_q1fx1_lev
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_q1fx2_lev
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_q1fx3_lev
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_q2fx3_lev
 
amrex::Vector< amrex::Vector< amrex::Real > > zlevels_stag
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > z_phys_nd
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > z_phys_cc
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > detJ_cc
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > ax
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > ay
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > az
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > z_phys_nd_src
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > z_phys_cc_src
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > detJ_cc_src
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > ax_src
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > ay_src
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > az_src
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > z_phys_nd_new
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > detJ_cc_new
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > z_t_rk
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > terrain_blanking
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > walldist
 
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > mapfac
 
amrex::Vector< amrex::Vector< amrex::Real > > stretched_dz_h
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > stretched_dz_d
 
amrex::Vector< amrex::MultiFab > base_state
 
amrex::Vector< amrex::MultiFab > base_state_new
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Hwave
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Lwave
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Hwave_onegrid
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Lwave_onegrid
 
bool finished_wave = false
 
amrex::Vector< amrex::YAFluxRegister * > advflux_reg
 
amrex::Vector< amrex::BCRec > domain_bcs_type
 
amrex::Gpu::DeviceVector< amrex::BCRec > domain_bcs_type_d
 
amrex::Array< std::string, 2 *AMREX_SPACEDIM > domain_bc_type
 
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_maxm_bc_extdir_vals
 
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_maxm_bc_neumann_vals
 
amrex::GpuArray< ERF_BC, AMREX_SPACEDIM *2 > phys_bc_type
 
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > xflux_imask
 
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > yflux_imask
 
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > zflux_imask
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > thin_xforce
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > thin_yforce
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > thin_zforce
 
int last_plot_file_step_1
 
int last_plot_file_step_2
 
int last_subvol
 
int last_check_file_step
 
int plot_file_on_restart = 1
 
const int datwidth = 14
 
const int datprecision = 6
 
const int timeprecision = 13
 
int max_step = std::numeric_limits<int>::max()
 
amrex::Real start_time = 0.0
 
amrex::Real stop_time = std::numeric_limits<amrex::Real>::max()
 
bool use_datetime = false
 
const std::string datetime_format = "%Y-%m-%d %H:%M:%S"
 
std::string restart_chkfile = ""
 
amrex::Vector< amrex::Real > fixed_dt
 
amrex::Vector< amrex::Real > fixed_fast_dt
 
int regrid_int = -1
 
bool regrid_level_0_on_restart = false
 
std::string plot_file_1 {"plt_1_"}
 
std::string plot_file_2 {"plt_2_"}
 
std::string subvol_file {"subvol"}
 
bool m_expand_plotvars_to_unif_rr = false
 
int m_plot_int_1 = -1
 
int m_plot_int_2 = -1
 
int m_subvol_int = -1
 
amrex::Real m_plot_per_1 = -1.0
 
amrex::Real m_plot_per_2 = -1.0
 
amrex::Real m_subvol_per = -1.0
 
bool m_plot_face_vels = false
 
bool plot_lsm = false
 
int profile_int = -1
 
bool destag_profiles = true
 
std::string check_file {"chk"}
 
int m_check_int = -1
 
amrex::Real m_check_per = -1.0
 
amrex::Vector< std::string > plot_var_names_1
 
amrex::Vector< std::string > plot_var_names_2
 
const amrex::Vector< std::string > cons_names
 
const amrex::Vector< std::string > derived_names
 
TurbulentPerturbation turbPert
 
int real_width {0}
 
int real_set_width {0}
 
bool metgrid_debug_quiescent {false}
 
bool metgrid_debug_isothermal {false}
 
bool metgrid_debug_dry {false}
 
bool metgrid_debug_psfc {false}
 
bool metgrid_debug_msf {false}
 
bool metgrid_interp_theta {false}
 
bool metgrid_basic_linear {false}
 
bool metgrid_use_below_sfc {true}
 
bool metgrid_use_sfc {true}
 
bool metgrid_retain_sfc {false}
 
amrex::Real metgrid_proximity {500.0}
 
int metgrid_order {2}
 
int metgrid_force_sfc_k {6}
 
amrex::Vector< amrex::BoxArray > ba1d
 
amrex::Vector< amrex::BoxArray > ba2d
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > mf_C1H
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > mf_C2H
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > mf_MUB
 
amrex::Vector< amrex::Vector< amrex::Real > > h_rhotheta_src
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > d_rhotheta_src
 
amrex::Vector< amrex::Vector< amrex::Real > > h_rhoqt_src
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > d_rhoqt_src
 
amrex::Vector< amrex::Vector< amrex::Real > > h_w_subsid
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > d_w_subsid
 
amrex::Vector< amrex::Vector< amrex::Real > > h_u_geos
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > d_u_geos
 
amrex::Vector< amrex::Vector< amrex::Real > > h_v_geos
 
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > d_v_geos
 
amrex::Vector< amrex::Vector< amrex::Vector< amrex::Real > > > h_rayleigh_ptrs
 
amrex::Vector< amrex::Vector< amrex::Vector< amrex::Real > > > h_sponge_ptrs
 
amrex::Vector< amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > > d_rayleigh_ptrs
 
amrex::Vector< amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > > d_sponge_ptrs
 
amrex::Vector< amrex::Real > h_havg_density
 
amrex::Vector< amrex::Real > h_havg_temperature
 
amrex::Vector< amrex::Real > h_havg_pressure
 
amrex::Vector< amrex::Real > h_havg_qv
 
amrex::Vector< amrex::Real > h_havg_qc
 
amrex::Gpu::DeviceVector< amrex::Real > d_havg_density
 
amrex::Gpu::DeviceVector< amrex::Real > d_havg_temperature
 
amrex::Gpu::DeviceVector< amrex::Real > d_havg_pressure
 
amrex::Gpu::DeviceVector< amrex::Real > d_havg_qv
 
amrex::Gpu::DeviceVector< amrex::Real > d_havg_qc
 
std::unique_ptr< WriteBndryPlanesm_w2d = nullptr
 
std::unique_ptr< ReadBndryPlanesm_r2d = nullptr
 
std::unique_ptr< SurfaceLayerm_SurfaceLayer = nullptr
 
amrex::Vector< std::unique_ptr< ForestDrag > > m_forest_drag
 
amrex::MultiFab fine_mask
 
amrex::Vector< amrex::Real > dz_min
 
int sampler_interval = -1
 
amrex::Real sampler_per = -1.0
 
std::unique_ptr< SampleDatadata_sampler = nullptr
 
amrex::Vector< std::unique_ptr< std::fstream > > datalog
 
amrex::Vector< std::unique_ptr< std::fstream > > der_datalog
 
amrex::Vector< std::unique_ptr< std::fstream > > tot_e_datalog
 
amrex::Vector< std::string > datalogname
 
amrex::Vector< std::string > der_datalogname
 
amrex::Vector< std::string > tot_e_datalogname
 
amrex::Vector< std::unique_ptr< std::fstream > > sampleptlog
 
amrex::Vector< std::string > sampleptlogname
 
amrex::Vector< amrex::IntVect > samplepoint
 
amrex::Vector< std::unique_ptr< std::fstream > > samplelinelog
 
amrex::Vector< std::string > samplelinelogname
 
amrex::Vector< amrex::IntVect > sampleline
 
amrex::Vector< std::unique_ptr< eb_ > > eb
 

Static Private Attributes

static amrex::Real cfl = 0.8
 
static amrex::Real sub_cfl = 1.0
 
static amrex::Real init_shrink = 1.0
 
static amrex::Real change_max = 1.1
 
static amrex::Real dt_max_initial = 2.0e100
 
static amrex::Real dt_max = 1e9
 
static int fixed_mri_dt_ratio = 0
 
static SolverChoice solverChoice
 
static int verbose = 0
 
static int mg_verbose = 0
 
static bool use_fft = false
 
static int sum_interval = -1
 
static int pert_interval = -1
 
static amrex::Real sum_per = -1.0
 
static PlotFileType plotfile_type_1 = PlotFileType::None
 
static PlotFileType plotfile_type_2 = PlotFileType::None
 
static StateInterpType interpolation_type
 
static std::string sponge_type
 
static amrex::Vector< amrex::Vector< std::string > > nc_init_file = {{""}}
 
static std::string nc_bdy_file
 
static std::string nc_low_file
 
static bool init_sounding_ideal = false
 
static int output_1d_column = 0
 
static int column_interval = -1
 
static amrex::Real column_per = -1.0
 
static amrex::Real column_loc_x = 0.0
 
static amrex::Real column_loc_y = 0.0
 
static std::string column_file_name = "column_data.nc"
 
static int output_bndry_planes = 0
 
static int bndry_output_planes_interval = -1
 
static amrex::Real bndry_output_planes_per = -1.0
 
static amrex::Real bndry_output_planes_start_time = 0.0
 
static int input_bndry_planes = 0
 
static int ng_dens_hse
 
static int ng_pres_hse
 
static amrex::Vector< amrex::AMRErrorTag > ref_tags
 
static amrex::Real startCPUTime = 0.0
 
static amrex::Real previousCPUTimeUsed = 0.0
 

Detailed Description

Main class in ERF code, instantiated from main.cpp

Constructor & Destructor Documentation

◆ ERF() [1/3]

ERF::ERF ( )
93 {
94  int fix_random_seed = 0;
95  ParmParse pp("erf"); pp.query("fix_random_seed", fix_random_seed);
96  // Note that the value of 1024UL is not significant -- the point here is just to set the
97  // same seed for all MPI processes for the purpose of regression testing
98  if (fix_random_seed) {
99  Print() << "Fixing the random seed" << std::endl;
100  InitRandom(1024UL);
101  }
102 
103  ERF_shared();
104 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:219
void ERF_shared()
Definition: ERF.cpp:107
Here is the call graph for this function:

◆ ~ERF()

ERF::~ERF ( )
overridedefault

◆ ERF() [2/3]

ERF::ERF ( ERF &&  )
deletenoexcept

◆ ERF() [3/3]

ERF::ERF ( const ERF other)
delete

Member Function Documentation

◆ Advance()

void ERF::Advance ( int  lev,
amrex::Real  time,
amrex::Real  dt_lev,
int  iteration,
int  ncycle 
)
private
24 {
25  BL_PROFILE("ERF::Advance()");
26 
27  // We must swap the pointers so the previous step's "new" is now this step's "old"
28  std::swap(vars_old[lev], vars_new[lev]);
29 
30  MultiFab& S_old = vars_old[lev][Vars::cons];
31  MultiFab& S_new = vars_new[lev][Vars::cons];
32 
33  MultiFab& U_old = vars_old[lev][Vars::xvel];
34  MultiFab& V_old = vars_old[lev][Vars::yvel];
35  MultiFab& W_old = vars_old[lev][Vars::zvel];
36 
37  MultiFab& U_new = vars_new[lev][Vars::xvel];
38  MultiFab& V_new = vars_new[lev][Vars::yvel];
39  MultiFab& W_new = vars_new[lev][Vars::zvel];
40 
41  // We need to set these because otherwise in the first call to erf_advance we may
42  // read uninitialized data on ghost values in setting the bc's on the velocities
43  U_new.setVal(1.e34,U_new.nGrowVect());
44  V_new.setVal(1.e34,V_new.nGrowVect());
45  W_new.setVal(1.e34,W_new.nGrowVect());
46 
47  // Do error checking for negative (rho theta) here
48  if (solverChoice.anelastic[lev] != 1) {
50  }
51 
52  //
53  // NOTE: the momenta here are not fillpatched (they are only used as scratch space)
54  // If lev == 0 we have already FillPatched this in ERF::TimeStep
55  //
56  if (lev > 0) {
57  FillPatch(lev, time, {&S_old, &U_old, &V_old, &W_old},
58  {&S_old, &rU_old[lev], &rV_old[lev], &rW_old[lev]},
59  base_state[lev], base_state[lev]);
60  }
61 
62  //
63  // So we must convert the fillpatched to momenta, including the ghost values
64  //
65  VelocityToMomentum(U_old, rU_old[lev].nGrowVect(),
66  V_old, rV_old[lev].nGrowVect(),
67  W_old, rW_old[lev].nGrowVect(),
68  S_old, rU_old[lev], rV_old[lev], rW_old[lev],
69  Geom(lev).Domain(),
71 
72  // Update the inflow perturbation update time and amplitude
73  if (solverChoice.pert_type == PerturbationType::Source ||
74  solverChoice.pert_type == PerturbationType::Direct ||
75  solverChoice.pert_type == PerturbationType::CPM)
76  {
77  turbPert.calc_tpi_update(lev, dt_lev, U_old, V_old, S_old);
78  }
79 
80  // If PerturbationType::Direct or CPM is selected, directly add the computed perturbation
81  // on the conserved field
82  if (solverChoice.pert_type == PerturbationType::Direct ||
83  solverChoice.pert_type == PerturbationType::CPM)
84  {
85  auto m_ixtype = S_old.boxArray().ixType(); // Conserved term
86  for (MFIter mfi(S_old,TileNoZ()); mfi.isValid(); ++mfi) {
87  Box bx = mfi.tilebox();
88  const Array4<Real> &cell_data = S_old.array(mfi);
89  const Array4<const Real> &pert_cell = turbPert.pb_cell[lev].array(mfi);
90  turbPert.apply_tpi(lev, bx, RhoTheta_comp, m_ixtype, cell_data, pert_cell);
91  }
92  }
93 
94  // configure SurfaceLayer params if needed
95  if (phys_bc_type[Orientation(Direction::z,Orientation::low)] == ERF_BC::surface_layer) {
96  if (m_SurfaceLayer) {
97  IntVect ng = Theta_prim[lev]->nGrowVect();
98  MultiFab::Copy( *Theta_prim[lev], S_old, RhoTheta_comp, 0, 1, ng);
99  MultiFab::Divide(*Theta_prim[lev], S_old, Rho_comp , 0, 1, ng);
100  if (solverChoice.moisture_type != MoistureType::None) {
101  ng = Qv_prim[lev]->nGrowVect();
102 
103  MultiFab::Copy( *Qv_prim[lev], S_old, RhoQ1_comp, 0, 1, ng);
104  MultiFab::Divide(*Qv_prim[lev], S_old, Rho_comp , 0, 1, ng);
105 
106  if (solverChoice.RhoQr_comp > -1) {
107  MultiFab::Copy( *Qr_prim[lev], S_old, solverChoice.RhoQr_comp, 0, 1, ng);
108  MultiFab::Divide(*Qr_prim[lev], S_old, Rho_comp , 0, 1, ng);
109  } else {
110  Qr_prim[lev]->setVal(0.0);
111  }
112  }
113  // NOTE: std::swap above causes the field ptrs to be out of date.
114  // Reassign the field ptrs for MAC avg computation.
115  m_SurfaceLayer->update_mac_ptrs(lev, vars_old, Theta_prim, Qv_prim, Qr_prim);
116  m_SurfaceLayer->update_pblh(lev, vars_old, z_phys_cc[lev].get(),
120  m_SurfaceLayer->update_fluxes(lev, time);
121  }
122  }
123 
124 #if defined(ERF_USE_WINDFARM)
125  if (solverChoice.windfarm_type != WindFarmType::None) {
126  advance_windfarm(Geom(lev), dt_lev, S_old,
127  U_old, V_old, W_old, vars_windfarm[lev],
128  Nturb[lev], SMark[lev], time);
129  }
130 
131 #endif
132 
133  const BoxArray& ba = S_old.boxArray();
134  const DistributionMapping& dm = S_old.DistributionMap();
135 
136  int nvars = S_old.nComp();
137 
138  // Source array for conserved cell-centered quantities -- this will be filled
139  // in the call to make_sources in ERF_TI_slow_rhs_pre.H
140  MultiFab cc_source(ba,dm,nvars,1); cc_source.setVal(0.0);
141 
142  // Source arrays for momenta -- these will be filled
143  // in the call to make_mom_sources in ERF_TI_slow_rhs_pre.H
144  BoxArray ba_x(ba); ba_x.surroundingNodes(0);
145  MultiFab xmom_source(ba_x,dm,1,1); xmom_source.setVal(0.0);
146 
147  BoxArray ba_y(ba); ba_y.surroundingNodes(1);
148  MultiFab ymom_source(ba_y,dm,1,1); ymom_source.setVal(0.0);
149 
150  BoxArray ba_z(ba); ba_z.surroundingNodes(2);
151  MultiFab zmom_source(ba_z,dm,1,1); zmom_source.setVal(0.0);
152  MultiFab buoyancy(ba_z,dm,1,1); buoyancy.setVal(0.0);
153 
154  amrex::Vector<MultiFab> state_old;
155  amrex::Vector<MultiFab> state_new;
156 
157  // **************************************************************************************
158  // Here we define state_old and state_new which are to be advanced
159  // **************************************************************************************
160  // Initial solution
161  // Note that "old" and "new" here are relative to each RK stage.
162  state_old.push_back(MultiFab(S_old , amrex::make_alias, 0, nvars)); // cons
163  state_old.push_back(MultiFab(rU_old[lev], amrex::make_alias, 0, 1)); // xmom
164  state_old.push_back(MultiFab(rV_old[lev], amrex::make_alias, 0, 1)); // ymom
165  state_old.push_back(MultiFab(rW_old[lev], amrex::make_alias, 0, 1)); // zmom
166 
167  // Final solution
168  // state_new at the end of the last RK stage holds the t^{n+1} data
169  state_new.push_back(MultiFab(S_new , amrex::make_alias, 0, nvars)); // cons
170  state_new.push_back(MultiFab(rU_new[lev], amrex::make_alias, 0, 1)); // xmom
171  state_new.push_back(MultiFab(rV_new[lev], amrex::make_alias, 0, 1)); // ymom
172  state_new.push_back(MultiFab(rW_new[lev], amrex::make_alias, 0, 1)); // zmom
173 
174  // **************************************************************************************
175  // Update the dycore
176  // **************************************************************************************
177  advance_dycore(lev, state_old, state_new,
178  U_old, V_old, W_old,
179  U_new, V_new, W_new,
180  cc_source, xmom_source, ymom_source, zmom_source, buoyancy,
181  Geom(lev), dt_lev, time);
182 
183  // **************************************************************************************
184  // Update the microphysics (moisture)
185  // **************************************************************************************
186  advance_microphysics(lev, S_new, dt_lev, iteration, time);
187 
188  // **************************************************************************************
189  // Update the land surface model
190  // **************************************************************************************
191  advance_lsm(lev, S_new, U_new, V_new, dt_lev);
192 
193  // **************************************************************************************
194  // Update the radiation
195  // **************************************************************************************
196  advance_radiation(lev, S_new, dt_lev);
197 
198 #ifdef ERF_USE_PARTICLES
199  // **************************************************************************************
200  // Update the particle positions
201  // **************************************************************************************
202  evolveTracers( lev, dt_lev, vars_new, z_phys_nd );
203 #endif
204 
205  // ***********************************************************************************************
206  // Impose domain boundary conditions here so that in FillPatching the fine data we won't
207  // need to re-fill these
208  // ***********************************************************************************************
209  if (lev < finest_level) {
210  IntVect ngvect_vels = vars_new[lev][Vars::xvel].nGrowVect();
212  0,vars_new[lev][Vars::cons].nComp(),
213  vars_new[lev][Vars::cons].nGrowVect(),time,BCVars::cons_bc,true);
214  (*physbcs_u[lev])(vars_new[lev][Vars::xvel], vars_new[lev][Vars::xvel], vars_new[lev][Vars::yvel],
215  ngvect_vels,time,BCVars::xvel_bc,true);
216  (*physbcs_v[lev])(vars_new[lev][Vars::yvel], vars_new[lev][Vars::xvel], vars_new[lev][Vars::yvel],
217  ngvect_vels,time,BCVars::yvel_bc,true);
218  (*physbcs_w[lev])(vars_new[lev][Vars::zvel], vars_new[lev][Vars::xvel], vars_new[lev][Vars::yvel],
219  ngvect_vels,time,BCVars::zvel_bc,true);
220  }
221 
222  // **************************************************************************************
223  // Register old and new coarse data if we are at a level less than the finest level
224  // **************************************************************************************
225  if (lev < finest_level)
226  {
227  if (cf_width > 0) {
228  // We must fill the ghost cells of these so that the parallel copy works correctly
229  state_old[IntVars::cons].FillBoundary(geom[lev].periodicity());
230  state_new[IntVars::cons].FillBoundary(geom[lev].periodicity());
231  FPr_c[lev].RegisterCoarseData({&state_old[IntVars::cons], &state_new[IntVars::cons]},
232  {time, time + dt_lev});
233  }
234 
235  if (cf_width >= 0) {
236  // We must fill the ghost cells of these so that the parallel copy works correctly
237  state_old[IntVars::xmom].FillBoundary(geom[lev].periodicity());
238  state_new[IntVars::xmom].FillBoundary(geom[lev].periodicity());
239  FPr_u[lev].RegisterCoarseData({&state_old[IntVars::xmom], &state_new[IntVars::xmom]},
240  {time, time + dt_lev});
241 
242  state_old[IntVars::ymom].FillBoundary(geom[lev].periodicity());
243  state_new[IntVars::ymom].FillBoundary(geom[lev].periodicity());
244  FPr_v[lev].RegisterCoarseData({&state_old[IntVars::ymom], &state_new[IntVars::ymom]},
245  {time, time + dt_lev});
246 
247  state_old[IntVars::zmom].FillBoundary(geom[lev].periodicity());
248  state_new[IntVars::zmom].FillBoundary(geom[lev].periodicity());
249  FPr_w[lev].RegisterCoarseData({&state_old[IntVars::zmom], &state_new[IntVars::zmom]},
250  {time, time + dt_lev});
251  }
252 
253  //
254  // Now create a MultiFab that holds (S_new - S_old) / dt from the coarse level interpolated
255  // on to the coarse/fine boundary at the fine resolution
256  //
257  Interpolater* mapper_f = &face_cons_linear_interp;
258 
259  // PhysBCFunctNoOp null_bc;
260  // MultiFab tempx(vars_new[lev+1][Vars::xvel].boxArray(),vars_new[lev+1][Vars::xvel].DistributionMap(),1,0);
261  // tempx.setVal(0.0);
262  // xmom_crse_rhs[lev+1].setVal(0.0);
263  // FPr_u[lev].FillSet(tempx , time , null_bc, domain_bcs_type);
264  // FPr_u[lev].FillSet(xmom_crse_rhs[lev+1], time+dt_lev, null_bc, domain_bcs_type);
265  // MultiFab::Subtract(xmom_crse_rhs[lev+1],tempx,0,0,1,IntVect{0});
266  // xmom_crse_rhs[lev+1].mult(1.0/dt_lev,0,1,0);
267 
268  // MultiFab tempy(vars_new[lev+1][Vars::yvel].boxArray(),vars_new[lev+1][Vars::yvel].DistributionMap(),1,0);
269  // tempy.setVal(0.0);
270  // ymom_crse_rhs[lev+1].setVal(0.0);
271  // FPr_v[lev].FillSet(tempy , time , null_bc, domain_bcs_type);
272  // FPr_v[lev].FillSet(ymom_crse_rhs[lev+1], time+dt_lev, null_bc, domain_bcs_type);
273  // MultiFab::Subtract(ymom_crse_rhs[lev+1],tempy,0,0,1,IntVect{0});
274  // ymom_crse_rhs[lev+1].mult(1.0/dt_lev,0,1,0);
275 
276  MultiFab temp_state(zmom_crse_rhs[lev+1].boxArray(),zmom_crse_rhs[lev+1].DistributionMap(),1,0);
277  InterpFromCoarseLevel(temp_state, IntVect{0}, IntVect{0}, state_old[IntVars::zmom], 0, 0, 1,
278  geom[lev], geom[lev+1], refRatio(lev), mapper_f, domain_bcs_type, BCVars::zvel_bc);
279  InterpFromCoarseLevel(zmom_crse_rhs[lev+1], IntVect{0}, IntVect{0}, state_new[IntVars::zmom], 0, 0, 1,
280  geom[lev], geom[lev+1], refRatio(lev), mapper_f, domain_bcs_type, BCVars::zvel_bc);
281  MultiFab::Subtract(zmom_crse_rhs[lev+1],temp_state,0,0,1,IntVect{0});
282  zmom_crse_rhs[lev+1].mult(1.0/dt_lev,0,1,0);
283  }
284 
285  // ***********************************************************************************************
286  // Update the time averaged velocities if they are requested
287  // ***********************************************************************************************
289  Time_Avg_Vel_atCC(dt[lev], t_avg_cnt[lev], vel_t_avg[lev].get(), U_new, V_new, W_new);
290  }
291 }
void check_for_negative_theta(amrex::MultiFab &S_old)
Definition: ERF_Advance.cpp:294
@ nvars
Definition: ERF_DataStruct.H:87
#define Rho_comp
Definition: ERF_IndexDefines.H:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:42
@ surface_layer
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
void Time_Avg_Vel_atCC(const Real &dt, Real &t_avg_cnt, MultiFab *vel_t_avg, MultiFab &xvel, MultiFab &yvel, MultiFab &zvel)
Definition: ERF_TimeAvgVel.cpp:9
void VelocityToMomentum(const amrex::MultiFab &xvel_in, const amrex::IntVect &xvel_ngrow, const amrex::MultiFab &yvel_in, const amrex::IntVect &yvel_ngrow, const amrex::MultiFab &zvel_in, const amrex::IntVect &zvel_ngrow, const amrex::MultiFab &cons_in, amrex::MultiFab &xmom_out, amrex::MultiFab &ymom_out, amrex::MultiFab &zmom_out, const amrex::Box &domain, const amrex::Vector< amrex::BCRec > &domain_bcs_type_h)
amrex::Vector< amrex::MultiFab > rU_new
Definition: ERF.H:735
amrex::Vector< ERFFillPatcher > FPr_u
Definition: ERF.H:779
amrex::Vector< amrex::Vector< amrex::MultiFab > > vars_new
Definition: ERF.H:707
amrex::Vector< ERFFillPatcher > FPr_v
Definition: ERF.H:780
amrex::Vector< std::unique_ptr< ERFPhysBCFunct_cons > > physbcs_cons
Definition: ERF.H:722
amrex::Vector< std::unique_ptr< amrex::MultiFab > > z_phys_cc
Definition: ERF.H:804
static SolverChoice solverChoice
Definition: ERF.H:992
amrex::Vector< ERFFillPatcher > FPr_c
Definition: ERF.H:778
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vel_t_avg
Definition: ERF.H:714
amrex::Vector< std::unique_ptr< ERFPhysBCFunct_w > > physbcs_w
Definition: ERF.H:725
amrex::Vector< amrex::MultiFab > base_state
Definition: ERF.H:835
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Qv_prim
Definition: ERF.H:730
amrex::Vector< amrex::MultiFab > rV_new
Definition: ERF.H:737
amrex::Vector< amrex::BCRec > domain_bcs_type
Definition: ERF.H:851
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Qr_prim
Definition: ERF.H:731
amrex::Vector< std::unique_ptr< ERFPhysBCFunct_u > > physbcs_u
Definition: ERF.H:723
amrex::Vector< amrex::Real > t_avg_cnt
Definition: ERF.H:715
amrex::Vector< amrex::MultiFab > rU_old
Definition: ERF.H:734
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Theta_prim
Definition: ERF.H:729
amrex::Vector< std::unique_ptr< ERFPhysBCFunct_v > > physbcs_v
Definition: ERF.H:724
amrex::Vector< std::unique_ptr< amrex::MultiFab > > z_phys_nd
Definition: ERF.H:803
void advance_dycore(int level, amrex::Vector< amrex::MultiFab > &state_old, amrex::Vector< amrex::MultiFab > &state_new, amrex::MultiFab &xvel_old, amrex::MultiFab &yvel_old, amrex::MultiFab &zvel_old, amrex::MultiFab &xvel_new, amrex::MultiFab &yvel_new, amrex::MultiFab &zvel_new, amrex::MultiFab &source, amrex::MultiFab &xmom_src, amrex::MultiFab &ymom_src, amrex::MultiFab &zmom_src, amrex::MultiFab &buoyancy, amrex::Geometry fine_geom, amrex::Real dt, amrex::Real time)
Definition: ERF_AdvanceDycore.cpp:38
amrex::Vector< amrex::MultiFab > rW_new
Definition: ERF.H:739
amrex::Vector< amrex::MultiFab > zmom_crse_rhs
Definition: ERF.H:743
void advance_lsm(int lev, amrex::MultiFab &cons_in, amrex::MultiFab &xvel_in, amrex::MultiFab &yvel_in, const amrex::Real &dt_advance)
Definition: ERF_AdvanceLSM.cpp:5
TurbulentPerturbation turbPert
Definition: ERF.H:995
amrex::Vector< amrex::MultiFab > rW_old
Definition: ERF.H:738
std::unique_ptr< SurfaceLayer > m_SurfaceLayer
Definition: ERF.H:1154
amrex::Vector< ERFFillPatcher > FPr_w
Definition: ERF.H:781
amrex::Vector< amrex::Real > dt
Definition: ERF.H:701
void advance_radiation(int lev, amrex::MultiFab &cons_in, const amrex::Real &dt_advance)
Definition: ERF_AdvanceRadiation.cpp:5
void advance_microphysics(int lev, amrex::MultiFab &cons_in, const amrex::Real &dt_advance, const int &iteration, const amrex::Real &time)
Definition: ERF_AdvanceMicrophysics.cpp:5
int cf_width
Definition: ERF.H:776
amrex::GpuArray< ERF_BC, AMREX_SPACEDIM *2 > phys_bc_type
Definition: ERF.H:864
amrex::Vector< amrex::MultiFab > rV_old
Definition: ERF.H:736
amrex::Vector< amrex::Vector< amrex::MultiFab > > vars_old
Definition: ERF.H:708
void FillPatch(int lev, amrex::Real time, const amrex::Vector< amrex::MultiFab * > &mfs_vel, bool cons_only=false)
@ zvel_bc
Definition: ERF_IndexDefines.H:89
@ yvel_bc
Definition: ERF_IndexDefines.H:88
@ cons_bc
Definition: ERF_IndexDefines.H:76
@ xvel_bc
Definition: ERF_IndexDefines.H:87
@ ymom
Definition: ERF_IndexDefines.H:160
@ cons
Definition: ERF_IndexDefines.H:158
@ zmom
Definition: ERF_IndexDefines.H:161
@ xmom
Definition: ERF_IndexDefines.H:159
@ ng
Definition: ERF_Morrison.H:48
@ xvel
Definition: ERF_IndexDefines.H:141
@ cons
Definition: ERF_IndexDefines.H:140
@ zvel
Definition: ERF_IndexDefines.H:143
@ yvel
Definition: ERF_IndexDefines.H:142
int RhoQr_comp
Definition: ERF_DataStruct.H:825
int RhoQc_comp
Definition: ERF_DataStruct.H:819
int RhoQv_comp
Definition: ERF_DataStruct.H:818
amrex::Vector< int > anelastic
Definition: ERF_DataStruct.H:719
MoistureType moisture_type
Definition: ERF_DataStruct.H:799
PerturbationType pert_type
Definition: ERF_DataStruct.H:786
WindFarmType windfarm_type
Definition: ERF_DataStruct.H:800
bool time_avg_vel
Definition: ERF_DataStruct.H:783
amrex::Vector< amrex::MultiFab > pb_cell
Definition: ERF_TurbPertStruct.H:647
void calc_tpi_update(const int lev, const amrex::Real dt, amrex::MultiFab &mf_xvel, amrex::MultiFab &mf_yvel, amrex::MultiFab &mf_cons)
Definition: ERF_TurbPertStruct.H:223
void apply_tpi(const int &lev, const amrex::Box &vbx, const int &comp, const amrex::IndexType &m_ixtype, const amrex::Array4< amrex::Real > &src_arr, const amrex::Array4< amrex::Real const > &pert_cell)
Definition: ERF_TurbPertStruct.H:324
Here is the call graph for this function:

◆ advance_dycore()

void ERF::advance_dycore ( int  level,
amrex::Vector< amrex::MultiFab > &  state_old,
amrex::Vector< amrex::MultiFab > &  state_new,
amrex::MultiFab &  xvel_old,
amrex::MultiFab &  yvel_old,
amrex::MultiFab &  zvel_old,
amrex::MultiFab &  xvel_new,
amrex::MultiFab &  yvel_new,
amrex::MultiFab &  zvel_new,
amrex::MultiFab &  source,
amrex::MultiFab &  xmom_src,
amrex::MultiFab &  ymom_src,
amrex::MultiFab &  zmom_src,
amrex::MultiFab &  buoyancy,
amrex::Geometry  fine_geom,
amrex::Real  dt,
amrex::Real  time 
)

Function that advances the solution at one level for a single time step – this sets up the multirate time integrator and calls the integrator's advance function

Parameters
[in]levellevel of refinement (coarsest level is 0)
[in]state_oldold-time conserved variables
[in]state_newnew-time conserved variables
[in]xvel_oldold-time x-component of velocity
[in]yvel_oldold-time y-component of velocity
[in]zvel_oldold-time z-component of velocity
[in]xvel_newnew-time x-component of velocity
[in]yvel_newnew-time y-component of velocity
[in]zvel_newnew-time z-component of velocity
[in]cc_srcsource term for conserved variables
[in]xmom_srcsource term for x-momenta
[in]ymom_srcsource term for y-momenta
[in]zmom_srcsource term for z-momenta
[in]fine_geomcontainer for geometry information at current level
[in]dt_advancetime step for this time advance
[in]old_timeold time for this time advance
48 {
49  BL_PROFILE_VAR("erf_advance_dycore()",erf_advance_dycore);
50 
51  const Box& domain = fine_geom.Domain();
52 
56 
57  MultiFab r_hse (base_state[level], make_alias, BaseState::r0_comp , 1);
58  MultiFab p_hse (base_state[level], make_alias, BaseState::p0_comp , 1);
59  MultiFab pi_hse(base_state[level], make_alias, BaseState::pi0_comp, 1);
60 
61  // These pointers are used in the MRI utility functions
62  MultiFab* r0 = &r_hse;
63  MultiFab* p0 = &p_hse;
64  MultiFab* pi0 = &pi_hse;
65 
66  Real* dptr_rhotheta_src = solverChoice.custom_rhotheta_forcing ? d_rhotheta_src[level].data() : nullptr;
67  Real* dptr_rhoqt_src = solverChoice.custom_moisture_forcing ? d_rhoqt_src[level].data() : nullptr;
68  Real* dptr_wbar_sub = solverChoice.custom_w_subsidence ? d_w_subsid[level].data() : nullptr;
69 
70  // Turbulent Perturbation Pointer
71  //Real* dptr_rhotheta_src = solverChoice.pert_type ? d_rhotheta_src[level].data() : nullptr;
72 
73  Vector<Real*> d_rayleigh_ptrs_at_lev;
74  d_rayleigh_ptrs_at_lev.resize(Rayleigh::nvars);
75  d_rayleigh_ptrs_at_lev[Rayleigh::ubar] = solverChoice.rayleigh_damp_U ? d_rayleigh_ptrs[level][Rayleigh::ubar].data() : nullptr;
76  d_rayleigh_ptrs_at_lev[Rayleigh::vbar] = solverChoice.rayleigh_damp_V ? d_rayleigh_ptrs[level][Rayleigh::vbar].data() : nullptr;
77  d_rayleigh_ptrs_at_lev[Rayleigh::wbar] = solverChoice.rayleigh_damp_W ? d_rayleigh_ptrs[level][Rayleigh::wbar].data() : nullptr;
78  d_rayleigh_ptrs_at_lev[Rayleigh::thetabar] = solverChoice.rayleigh_damp_T ? d_rayleigh_ptrs[level][Rayleigh::thetabar].data() : nullptr;
79 
80  Vector<Real*> d_sponge_ptrs_at_lev;
81  if(sc.sponge_type=="input_sponge")
82  {
83  d_sponge_ptrs_at_lev.resize(Sponge::nvars_sponge);
84  d_sponge_ptrs_at_lev[Sponge::ubar_sponge] = d_sponge_ptrs[level][Sponge::ubar_sponge].data();
85  d_sponge_ptrs_at_lev[Sponge::vbar_sponge] = d_sponge_ptrs[level][Sponge::vbar_sponge].data();
86  }
87 
88  bool l_use_terrain_fitted_coords = (solverChoice.mesh_type != MeshType::ConstantDz);
89  bool l_use_kturb = tc.use_kturb;
90  bool l_use_diff = ( (dc.molec_diff_type != MolecDiffType::None) ||
91  l_use_kturb );
92  bool l_use_moisture = ( solverChoice.moisture_type != MoistureType::None );
93  bool l_implicit_substepping = ( solverChoice.substepping_type[level] == SubsteppingType::Implicit );
94 
95  const bool use_SurfLayer = (m_SurfaceLayer != nullptr);
96  const FArrayBox* z_0 = (use_SurfLayer) ? m_SurfaceLayer->get_z0(level) : nullptr;
97 
98  const BoxArray& ba = state_old[IntVars::cons].boxArray();
99  const BoxArray& ba_z = zvel_old.boxArray();
100  const DistributionMapping& dm = state_old[IntVars::cons].DistributionMap();
101 
102  int num_prim = state_old[IntVars::cons].nComp() - 1;
103 
104  MultiFab S_prim (ba , dm, num_prim, state_old[IntVars::cons].nGrowVect());
105  MultiFab pi_stage (ba , dm, 1, state_old[IntVars::cons].nGrowVect());
106  MultiFab fast_coeffs(ba_z, dm, 5, 0);
107  MultiFab* eddyDiffs = eddyDiffs_lev[level].get();
108  MultiFab* SmnSmn = SmnSmn_lev[level].get();
109 
110  // **************************************************************************************
111  // Compute strain for use in slow RHS and Smagorinsky model
112  // **************************************************************************************
113  {
114  BL_PROFILE("erf_advance_strain");
115  if (l_use_diff) {
116 
117  const BCRec* bc_ptr_h = domain_bcs_type.data();
118  const GpuArray<Real, AMREX_SPACEDIM> dxInv = fine_geom.InvCellSizeArray();
119 
120 #ifdef _OPENMP
121 #pragma omp parallel if (Gpu::notInLaunchRegion())
122 #endif
123  for ( MFIter mfi(state_new[IntVars::cons],TileNoZ()); mfi.isValid(); ++mfi)
124  {
125  Box bxcc = mfi.growntilebox(IntVect(1,1,0));
126  Box tbxxy = mfi.tilebox(IntVect(1,1,0),IntVect(1,1,0));
127  Box tbxxz = mfi.tilebox(IntVect(1,0,1),IntVect(1,1,0));
128  Box tbxyz = mfi.tilebox(IntVect(0,1,1),IntVect(1,1,0));
129 
130  if (bxcc.smallEnd(2) != domain.smallEnd(2)) {
131  bxcc.growLo(2,1);
132  tbxxy.growLo(2,1);
133  tbxxz.growLo(2,1);
134  tbxyz.growLo(2,1);
135  }
136 
137  if (bxcc.bigEnd(2) != domain.bigEnd(2)) {
138  bxcc.growHi(2,1);
139  tbxxy.growHi(2,1);
140  tbxxz.growHi(2,1);
141  tbxyz.growHi(2,1);
142  }
143 
144  const Array4<const Real> & u = xvel_old.array(mfi);
145  const Array4<const Real> & v = yvel_old.array(mfi);
146  const Array4<const Real> & w = zvel_old.array(mfi);
147 
148  Array4<Real> tau11 = Tau[level][TauType::tau11].get()->array(mfi);
149  Array4<Real> tau22 = Tau[level][TauType::tau22].get()->array(mfi);
150  Array4<Real> tau33 = Tau[level][TauType::tau33].get()->array(mfi);
151  Array4<Real> tau12 = Tau[level][TauType::tau12].get()->array(mfi);
152  Array4<Real> tau13 = Tau[level][TauType::tau13].get()->array(mfi);
153  Array4<Real> tau23 = Tau[level][TauType::tau23].get()->array(mfi);
154 
155  Array4<Real> tau21 = l_use_terrain_fitted_coords ? Tau[level][TauType::tau21].get()->array(mfi) : Array4<Real>{};
156  Array4<Real> tau31 = l_use_terrain_fitted_coords ? Tau[level][TauType::tau31].get()->array(mfi) : Array4<Real>{};
157  Array4<Real> tau32 = l_use_terrain_fitted_coords ? Tau[level][TauType::tau32].get()->array(mfi) : Array4<Real>{};
158  const Array4<const Real>& z_nd = z_phys_nd[level]->const_array(mfi);
159 
160  const Array4<const Real> mf_mx = mapfac[level][MapFacType::m_x]->const_array(mfi);
161  const Array4<const Real> mf_ux = mapfac[level][MapFacType::u_x]->const_array(mfi);
162  const Array4<const Real> mf_vx = mapfac[level][MapFacType::v_x]->const_array(mfi);
163  const Array4<const Real> mf_my = mapfac[level][MapFacType::m_y]->const_array(mfi);
164  const Array4<const Real> mf_uy = mapfac[level][MapFacType::u_y]->const_array(mfi);
165  const Array4<const Real> mf_vy = mapfac[level][MapFacType::v_y]->const_array(mfi);
166 
167  if (solverChoice.mesh_type == MeshType::StretchedDz) {
168  ComputeStrain_S(bxcc, tbxxy, tbxxz, tbxyz, domain,
169  u, v, w,
170  tau11, tau22, tau33,
171  tau12, tau21,
172  tau13, tau31,
173  tau23, tau32,
174  stretched_dz_d[level], dxInv,
175  mf_mx, mf_ux, mf_vx, mf_my, mf_uy, mf_vy, bc_ptr_h);
176  } else if (l_use_terrain_fitted_coords) {
177  ComputeStrain_T(bxcc, tbxxy, tbxxz, tbxyz, domain,
178  u, v, w,
179  tau11, tau22, tau33,
180  tau12, tau21,
181  tau13, tau31,
182  tau23, tau32,
183  z_nd, detJ_cc[level]->const_array(mfi), dxInv,
184  mf_mx, mf_ux, mf_vx, mf_my, mf_uy, mf_vy, bc_ptr_h);
185  } else {
186  ComputeStrain_N(bxcc, tbxxy, tbxxz, tbxyz, domain,
187  u, v, w,
188  tau11, tau22, tau33,
189  tau12, tau13, tau23,
190  dxInv,
191  mf_mx, mf_ux, mf_vx, mf_my, mf_uy, mf_vy, bc_ptr_h);
192  }
193  } // mfi
194  } // l_use_diff
195  } // profile
196 
197 #include "ERF_TI_utils.H"
198 
199  // Additional SFS quantities, calculated once per timestep
200  MultiFab* Hfx1 = SFS_hfx1_lev[level].get();
201  MultiFab* Hfx2 = SFS_hfx2_lev[level].get();
202  MultiFab* Hfx3 = SFS_hfx3_lev[level].get();
203  MultiFab* Q1fx1 = SFS_q1fx1_lev[level].get();
204  MultiFab* Q1fx2 = SFS_q1fx2_lev[level].get();
205  MultiFab* Q1fx3 = SFS_q1fx3_lev[level].get();
206  MultiFab* Q2fx3 = SFS_q2fx3_lev[level].get();
207  MultiFab* Diss = SFS_diss_lev[level].get();
208 
209  // *************************************************************************
210  // Calculate cell-centered eddy viscosity & diffusivities
211  //
212  // Notes -- we fill all the data in ghost cells before calling this so
213  // that we can fill the eddy viscosity in the ghost regions and
214  // not have to call a boundary filler on this data itself
215  //
216  // LES - updates both horizontal and vertical eddy viscosity components
217  // PBL - only updates vertical eddy viscosity components so horizontal
218  // components come from the LES model or are left as zero.
219  // *************************************************************************
220  if (l_use_kturb)
221  {
222  // NOTE: state_new transfers to state_old for PBL (due to ptr swap in advance)
223  const BCRec* bc_ptr_h = domain_bcs_type.data();
224  ComputeTurbulentViscosity(xvel_old, yvel_old,Tau[level],
225  state_old[IntVars::cons],
226  *walldist[level].get(),
227  *eddyDiffs, *Hfx1, *Hfx2, *Hfx3, *Diss, // to be updated
228  fine_geom, mapfac[level],
229  z_phys_nd[level], solverChoice,
230  m_SurfaceLayer, z_0, l_use_terrain_fitted_coords,
231  l_use_moisture, level, bc_ptr_h);
232  }
233 
234  // ***********************************************************************************************
235  // Update user-defined source terms -- these are defined once per time step (not per RK stage)
236  // ***********************************************************************************************
238  prob->update_rhotheta_sources(old_time,
239  h_rhotheta_src[level], d_rhotheta_src[level],
240  fine_geom, z_phys_cc[level]);
241  }
242 
244  prob->update_rhoqt_sources(old_time,
245  h_rhoqt_src[level], d_rhoqt_src[level],
246  fine_geom, z_phys_cc[level]);
247  }
248 
250  prob->update_geostrophic_profile(old_time,
251  h_u_geos[level], d_u_geos[level],
252  h_v_geos[level], d_v_geos[level],
253  fine_geom, z_phys_cc[level]);
254  }
255 
257  prob->update_w_subsidence(old_time,
258  h_w_subsid[level], d_w_subsid[level],
259  fine_geom, z_phys_nd[level]);
260  }
261 
262  // ***********************************************************************************************
263  // Convert old velocity available on faces to old momentum on faces to be used in time integration
264  // ***********************************************************************************************
265  MultiFab density(state_old[IntVars::cons], make_alias, Rho_comp, 1);
266 
267  //
268  // This is an optimization since we won't need more than one ghost
269  // cell of momentum in the integrator if not using numerical diffusion
270  //
271  IntVect ngu = (!solverChoice.use_num_diff) ? IntVect(1,1,1) : xvel_old.nGrowVect();
272  IntVect ngv = (!solverChoice.use_num_diff) ? IntVect(1,1,1) : yvel_old.nGrowVect();
273  IntVect ngw = (!solverChoice.use_num_diff) ? IntVect(1,1,0) : zvel_old.nGrowVect();
274 
275  VelocityToMomentum(xvel_old, ngu, yvel_old, ngv, zvel_old, ngw, density,
276  state_old[IntVars::xmom],
277  state_old[IntVars::ymom],
278  state_old[IntVars::zmom],
279  domain, domain_bcs_type);
280 
281  MultiFab::Copy(xvel_new,xvel_old,0,0,1,xvel_old.nGrowVect());
282  MultiFab::Copy(yvel_new,yvel_old,0,0,1,yvel_old.nGrowVect());
283  MultiFab::Copy(zvel_new,zvel_old,0,0,1,zvel_old.nGrowVect());
284 
285  bool fast_only = false;
286  bool vel_and_mom_synced = true;
287 
288  apply_bcs(state_old, old_time,
289  state_old[IntVars::cons].nGrow(), state_old[IntVars::xmom].nGrow(),
290  fast_only, vel_and_mom_synced);
291  cons_to_prim(state_old[IntVars::cons], state_old[IntVars::cons].nGrow());
292 
293  // ***********************************************************************************************
294  // Define a new MultiFab that holds q_total and fill it by summing the moisture components --
295  // to be used in buoyancy calculation and as part of the inertial weighting in the
296  // ***********************************************************************************************
297  MultiFab qt(grids[level], dmap[level], 1, 1);
298  qt.setVal(0.0);
299 
300 #include "ERF_TI_no_substep_fun.H"
301 #include "ERF_TI_substep_fun.H"
302 #include "ERF_TI_slow_rhs_pre.H"
303 #include "ERF_TI_slow_rhs_post.H"
304 
305  // ***************************************************************************************
306  // Setup the integrator and integrate for a single timestep
307  // **************************************************************************************
308  MRISplitIntegrator<Vector<MultiFab> >& mri_integrator = *mri_integrator_mem[level];
309 
310  // Define rhs and 'post update' utility function that is called after calculating
311  // any state data (e.g. at RK stages or at the end of a timestep)
312  mri_integrator.set_slow_rhs_pre(slow_rhs_fun_pre);
313  mri_integrator.set_slow_rhs_post(slow_rhs_fun_post);
314 
315  mri_integrator.set_fast_rhs(fast_rhs_fun);
317  mri_integrator.set_no_substep(no_substep_fun);
318 
319  mri_integrator.advance(state_old, state_new, old_time, dt_advance);
320 
321  if (verbose) Print() << "Done with advance_dycore at level " << level << std::endl;
322 }
void ComputeStrain_N(Box bxcc, Box tbxxy, Box tbxxz, Box tbxyz, Box domain, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, Array4< Real > &tau11, Array4< Real > &tau22, Array4< Real > &tau33, Array4< Real > &tau12, Array4< Real > &tau13, Array4< Real > &tau23, const GpuArray< Real, AMREX_SPACEDIM > &dxInv, const Array4< const Real > &mf_mx, const Array4< const Real > &mf_ux, const Array4< const Real > &mf_vx, const Array4< const Real > &mf_my, const Array4< const Real > &mf_uy, const Array4< const Real > &mf_vy, const BCRec *bc_ptr)
Definition: ERF_ComputeStrain_N.cpp:28
void ComputeStrain_S(Box bxcc, Box tbxxy, Box tbxxz, Box tbxyz, Box domain, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, Array4< Real > &tau11, Array4< Real > &tau22, Array4< Real > &tau33, Array4< Real > &tau12, Array4< Real > &tau21, Array4< Real > &tau13, Array4< Real > &tau31, Array4< Real > &tau23, Array4< Real > &tau32, const Gpu::DeviceVector< Real > &stretched_dz_d, const GpuArray< Real, AMREX_SPACEDIM > &dxInv, const Array4< const Real > &mf_mx, const Array4< const Real > &mf_ux, const Array4< const Real > &mf_vx, const Array4< const Real > &mf_my, const Array4< const Real > &mf_uy, const Array4< const Real > &mf_vy, const BCRec *bc_ptr)
Definition: ERF_ComputeStrain_S.cpp:36
void ComputeStrain_T(Box bxcc, Box tbxxy, Box tbxxz, Box tbxyz, Box domain, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, Array4< Real > &tau11, Array4< Real > &tau22, Array4< Real > &tau33, Array4< Real > &tau12, Array4< Real > &tau21, Array4< Real > &tau13, Array4< Real > &tau31, Array4< Real > &tau23, Array4< Real > &tau32, const Array4< const Real > &z_nd, const Array4< const Real > &detJ, const GpuArray< Real, AMREX_SPACEDIM > &dxInv, const Array4< const Real > &mf_mx, const Array4< const Real > &mf_ux, const Array4< const Real > &mf_vx, const Array4< const Real > &mf_my, const Array4< const Real > &mf_uy, const Array4< const Real > &mf_vy, const BCRec *bc_ptr)
Definition: ERF_ComputeStrain_T.cpp:36
void ComputeTurbulentViscosity(const MultiFab &xvel, const MultiFab &yvel, Vector< std::unique_ptr< MultiFab >> &Tau_lev, const 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 SolverChoice &solverChoice, std::unique_ptr< SurfaceLayer > &SurfLayer, const FArrayBox *z_0, const bool &use_terrain_fitted_coords, const bool &use_moisture, int level, const BCRec *bc_ptr, bool vert_only)
Definition: ERF_ComputeTurbulentViscosity.cpp:516
@ tau12
Definition: ERF_DataStruct.H:30
@ tau23
Definition: ERF_DataStruct.H:30
@ tau33
Definition: ERF_DataStruct.H:30
@ tau22
Definition: ERF_DataStruct.H:30
@ tau11
Definition: ERF_DataStruct.H:30
@ tau32
Definition: ERF_DataStruct.H:30
@ tau31
Definition: ERF_DataStruct.H:30
@ tau21
Definition: ERF_DataStruct.H:30
@ tau13
Definition: ERF_DataStruct.H:30
@ ubar
Definition: ERF_DataStruct.H:87
@ wbar
Definition: ERF_DataStruct.H:87
@ vbar
Definition: ERF_DataStruct.H:87
@ thetabar
Definition: ERF_DataStruct.H:87
@ nvars_sponge
Definition: ERF_DataStruct.H:92
@ vbar_sponge
Definition: ERF_DataStruct.H:92
@ ubar_sponge
Definition: ERF_DataStruct.H:92
@ v_x
Definition: ERF_DataStruct.H:22
@ u_y
Definition: ERF_DataStruct.H:23
@ v_y
Definition: ERF_DataStruct.H:23
@ m_y
Definition: ERF_DataStruct.H:23
@ u_x
Definition: ERF_DataStruct.H:22
@ m_x
Definition: ERF_DataStruct.H:22
auto no_substep_fun
Definition: ERF_TI_no_substep_fun.H:4
auto slow_rhs_fun_post
Definition: ERF_TI_slow_rhs_post.H:3
auto slow_rhs_fun_pre
Definition: ERF_TI_slow_rhs_pre.H:6
auto fast_rhs_fun
Definition: ERF_TI_substep_fun.H:6
auto apply_bcs
Definition: ERF_TI_utils.H:71
auto cons_to_prim
Definition: ERF_TI_utils.H:4
amrex::Vector< std::unique_ptr< amrex::MultiFab > > walldist
Definition: ERF.H:827
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > mapfac
Definition: ERF.H:830
amrex::Vector< std::unique_ptr< MRISplitIntegrator< amrex::Vector< amrex::MultiFab > > > > mri_integrator_mem
Definition: ERF.H:717
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > d_rhotheta_src
Definition: ERF.H:1103
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_q1fx3_lev
Definition: ERF.H:796
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_hfx3_lev
Definition: ERF.H:794
amrex::Vector< amrex::Vector< amrex::Real > > h_w_subsid
Definition: ERF.H:1108
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_hfx1_lev
Definition: ERF.H:794
amrex::Vector< std::unique_ptr< amrex::MultiFab > > detJ_cc
Definition: ERF.H:806
amrex::Vector< std::unique_ptr< amrex::MultiFab > > eddyDiffs_lev
Definition: ERF.H:785
amrex::Vector< amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > > d_sponge_ptrs
Definition: ERF.H:1136
amrex::Vector< amrex::Vector< amrex::Real > > h_rhoqt_src
Definition: ERF.H:1105
amrex::Vector< long > dt_mri_ratio
Definition: ERF.H:702
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > Tau
Definition: ERF.H:784
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_q2fx3_lev
Definition: ERF.H:797
static int verbose
Definition: ERF.H:1027
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_q1fx2_lev
Definition: ERF.H:796
std::unique_ptr< ProblemBase > prob
Definition: ERF.H:689
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > stretched_dz_d
Definition: ERF.H:833
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_diss_lev
Definition: ERF.H:795
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > d_v_geos
Definition: ERF.H:1115
amrex::Vector< amrex::Vector< amrex::Real > > h_v_geos
Definition: ERF.H:1114
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > d_rhoqt_src
Definition: ERF.H:1106
amrex::Vector< amrex::Vector< amrex::Real > > h_rhotheta_src
Definition: ERF.H:1102
amrex::Vector< amrex::Vector< amrex::Real > > h_u_geos
Definition: ERF.H:1111
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SmnSmn_lev
Definition: ERF.H:786
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > d_u_geos
Definition: ERF.H:1112
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > d_w_subsid
Definition: ERF.H:1109
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_hfx2_lev
Definition: ERF.H:794
static int fixed_mri_dt_ratio
Definition: ERF.H:915
amrex::Vector< amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > > d_rayleigh_ptrs
Definition: ERF.H:1133
amrex::Vector< std::unique_ptr< amrex::MultiFab > > SFS_q1fx1_lev
Definition: ERF.H:796
Definition: ERF_MRI.H:16
void set_slow_rhs_pre(std::function< void(T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)> F)
Definition: ERF_MRI.H:133
void set_no_substep(std::function< void(T &, T &, T &, amrex::Real, amrex::Real, int)> F)
Definition: ERF_MRI.H:159
void set_fast_rhs(std::function< void(int, int, int, T &, const T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const amrex::Real)> F)
Definition: ERF_MRI.H:142
void set_slow_fast_timestep_ratio(const int timestep_ratio=1)
Definition: ERF_MRI.H:149
amrex::Real advance(T &S_old, T &S_new, amrex::Real time, const amrex::Real time_step)
Definition: ERF_MRI.H:169
void set_slow_rhs_post(std::function< void(T &, T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)> F)
Definition: ERF_MRI.H:137
@ pi0_comp
Definition: ERF_IndexDefines.H:65
@ p0_comp
Definition: ERF_IndexDefines.H:64
@ r0_comp
Definition: ERF_IndexDefines.H:63
@ qt
Definition: ERF_Kessler.H:27
real(c_double), parameter p0
Definition: ERF_module_model_constants.F90:40
Definition: ERF_DiffStruct.H:19
MolecDiffType molec_diff_type
Definition: ERF_DiffStruct.H:81
bool rayleigh_damp_T
Definition: ERF_DataStruct.H:738
static MeshType mesh_type
Definition: ERF_DataStruct.H:703
bool rayleigh_damp_V
Definition: ERF_DataStruct.H:736
DiffChoice diffChoice
Definition: ERF_DataStruct.H:712
bool custom_rhotheta_forcing
Definition: ERF_DataStruct.H:769
bool custom_w_subsidence
Definition: ERF_DataStruct.H:771
bool rayleigh_damp_U
Definition: ERF_DataStruct.H:735
bool custom_geostrophic_profile
Definition: ERF_DataStruct.H:772
amrex::Vector< SubsteppingType > substepping_type
Definition: ERF_DataStruct.H:718
bool use_num_diff
Definition: ERF_DataStruct.H:789
bool custom_moisture_forcing
Definition: ERF_DataStruct.H:770
amrex::Vector< TurbChoice > turbChoice
Definition: ERF_DataStruct.H:714
bool rayleigh_damp_W
Definition: ERF_DataStruct.H:737
SpongeChoice spongeChoice
Definition: ERF_DataStruct.H:713
Definition: ERF_SpongeStruct.H:15
std::string sponge_type
Definition: ERF_SpongeStruct.H:58
Definition: ERF_TurbStruct.H:39
bool use_kturb
Definition: ERF_TurbStruct.H:360
Here is the call graph for this function:

◆ advance_lsm()

void ERF::advance_lsm ( int  lev,
amrex::MultiFab &  cons_in,
amrex::MultiFab &  xvel_in,
amrex::MultiFab &  yvel_in,
const amrex::Real &  dt_advance 
)
10 {
11  if (solverChoice.lsm_type != LandSurfaceType::None) {
12  if (solverChoice.lsm_type == LandSurfaceType::NOAH) {
13  lsm.Advance(lev, cons_in, xvel_in, yvel_in, SFS_hfx3_lev[lev].get(), SFS_q1fx3_lev[lev].get(), dt_advance, istep[lev]);
14  } else {
15  lsm.Advance(lev, dt_advance);
16  }
17  }
18 }
LandSurface lsm
Definition: ERF.H:761
amrex::Vector< int > istep
Definition: ERF.H:695
void Advance(const int &lev, amrex::MultiFab &cons_in, amrex::MultiFab &xvel_in, amrex::MultiFab &yvel_in, amrex::MultiFab *hfx3_out, amrex::MultiFab *qfx3_out, const amrex::Real &dt_advance, const int &nstep)
Definition: ERF_LandSurface.H:52
LandSurfaceType lsm_type
Definition: ERF_DataStruct.H:802

◆ advance_microphysics()

void ERF::advance_microphysics ( int  lev,
amrex::MultiFab &  cons_in,
const amrex::Real &  dt_advance,
const int &  iteration,
const amrex::Real &  time 
)
10 {
11  if (solverChoice.moisture_type != MoistureType::None) {
12  micro->Update_Micro_Vars_Lev(lev, cons);
13  micro->Advance(lev, dt_advance, iteration, time, solverChoice, vars_new, z_phys_nd, phys_bc_type);
14  micro->Update_State_Vars_Lev(lev, cons);
15  }
16 }
std::unique_ptr< Microphysics > micro
Definition: ERF.H:745

◆ advance_radiation()

void ERF::advance_radiation ( int  lev,
amrex::MultiFab &  cons_in,
const amrex::Real &  dt_advance 
)
8 {
9  if (solverChoice.rad_type != RadiationType::None) {
10  // TODO: Address issue with lev>0 not spanning all z?
11  if (lev == 0) {
12 #ifdef ERF_USE_NETCDF
13  MultiFab *lat_ptr = lat_m[lev].get();
14  MultiFab *lon_ptr = lon_m[lev].get();
15 #else
16  MultiFab *lat_ptr = nullptr;
17  MultiFab *lon_ptr = nullptr;
18 #endif
19  rad[lev]->Run(lev, istep[lev], t_new[lev], dt_advance,
20  cons.boxArray(), geom[lev], &(cons),
21  sw_lw_fluxes[lev].get() , solar_zenith[lev].get(),
22  qheating_rates[lev].get(), z_phys_nd[lev].get() ,
23  lat_ptr, lon_ptr);
24  /*
25  // TODO: fix this - can't use set_lsm_inputs with IRadiation::Run()
26  if (solverChoice.lsm_type == LandSurfaceType::SLM) {
27  rad[lev]->set_lsm_inputs(lsm.get_model_lev<SLM>(lev));
28  }
29  */
30  }
31  }
32 }
amrex::Vector< std::unique_ptr< amrex::MultiFab > > sw_lw_fluxes
Definition: ERF.H:769
amrex::Vector< std::unique_ptr< IRadiation > > rad
Definition: ERF.H:765
amrex::Vector< amrex::Real > t_new
Definition: ERF.H:699
amrex::Vector< std::unique_ptr< amrex::MultiFab > > solar_zenith
Definition: ERF.H:770
amrex::Vector< std::unique_ptr< amrex::MultiFab > > qheating_rates
Definition: ERF.H:766
RadiationType rad_type
Definition: ERF_DataStruct.H:803

◆ appendPlotVariables()

void ERF::appendPlotVariables ( const std::string &  pp_plot_var_names,
amrex::Vector< std::string > &  plot_var_names 
)
private
183 {
184  ParmParse pp(pp_prefix);
185 
186  Vector<std::string> plot_var_names(0);
187  if (pp.contains(pp_plot_var_names.c_str())) {
188  std::string nm;
189  int nPltVars = pp.countval(pp_plot_var_names.c_str());
190  for (int i = 0; i < nPltVars; i++) {
191  pp.get(pp_plot_var_names.c_str(), nm, i);
192  // Add the named variable to our list of plot variables
193  // if it is not already in the list
194  if (!containerHasElement(plot_var_names, nm)) {
195  plot_var_names.push_back(nm);
196  }
197  }
198  }
199 
200  Vector<std::string> tmp_plot_names(0);
201 #ifdef ERF_USE_PARTICLES
202  Vector<std::string> particle_mesh_plot_names;
203  particleData.GetMeshPlotVarNames( particle_mesh_plot_names );
204  for (int i = 0; i < particle_mesh_plot_names.size(); i++) {
205  std::string tmp(particle_mesh_plot_names[i]);
206  if (containerHasElement(plot_var_names, tmp) ) {
207  tmp_plot_names.push_back(tmp);
208  }
209  }
210 #endif
211 
212  {
213  Vector<std::string> microphysics_plot_names;
214  micro->GetPlotVarNames(microphysics_plot_names);
215  if (microphysics_plot_names.size() > 0) {
216  static bool first_call = true;
217  if (first_call) {
218  Print() << getEnumNameString(solverChoice.moisture_type)
219  << ": the following additional variables are available to plot:\n";
220  for (int i = 0; i < microphysics_plot_names.size(); i++) {
221  Print() << " " << microphysics_plot_names[i] << "\n";
222  }
223  first_call = false;
224  }
225  for (auto& plot_name : microphysics_plot_names) {
226  if (containerHasElement(plot_var_names, plot_name)) {
227  tmp_plot_names.push_back(plot_name);
228  }
229  }
230  }
231  }
232 
233  for (int i = 0; i < tmp_plot_names.size(); i++) {
234  a_plot_var_names.push_back( tmp_plot_names[i] );
235  }
236 
237  // Finally, check to see if we found all the requested variables
238  for (const auto& plot_name : plot_var_names) {
239  if (!containerHasElement(a_plot_var_names, plot_name)) {
240  if (amrex::ParallelDescriptor::IOProcessor()) {
241  Warning("\nWARNING: Requested to plot variable '" + plot_name + "' but it is not available");
242  }
243  }
244  }
245 }
bool containerHasElement(const V &iterable, const T &query)
Definition: ERF_Container.H:5
std::string pp_prefix
Definition: ERF.H:443
Here is the call graph for this function:

◆ AverageDown()

void ERF::AverageDown ( )
private
17 {
18  AMREX_ALWAYS_ASSERT(solverChoice.coupling_type == CouplingType::TwoWay);
19 
20  int src_comp, num_comp;
21  for (int lev = finest_level-1; lev >= 0; --lev)
22  {
23  // If anelastic we don't average down rho because rho == rho0.
24  if (solverChoice.anelastic[lev]) {
25  src_comp = 1;
26  } else {
27  src_comp = 0;
28  }
29  num_comp = vars_new[0][Vars::cons].nComp() - src_comp;
30  AverageDownTo(lev,src_comp,num_comp);
31  }
32 }
void AverageDownTo(int crse_lev, int scomp, int ncomp)
Definition: ERF_AverageDown.cpp:36
CouplingType coupling_type
Definition: ERF_DataStruct.H:798

◆ AverageDownTo()

void ERF::AverageDownTo ( int  crse_lev,
int  scomp,
int  ncomp 
)
37 {
38  if (solverChoice.anelastic[crse_lev]) {
39  AMREX_ALWAYS_ASSERT(scomp == 1);
40  } else {
41  AMREX_ALWAYS_ASSERT(scomp == 0);
42  }
43 
44  AMREX_ALWAYS_ASSERT(ncomp == vars_new[crse_lev][Vars::cons].nComp() - scomp);
45  AMREX_ALWAYS_ASSERT(solverChoice.coupling_type == CouplingType::TwoWay);
46 
47  // ******************************************************************************************
48  // First do cell-centered quantities
49  // The quantity that is conserved is not (rho S), but rather (rho S / m^2) where
50  // m is the map scale factor at cell centers
51  // Here we pre-divide (rho S) by m^2 before average down
52  // ******************************************************************************************
53  for (int lev = crse_lev; lev <= crse_lev+1; lev++) {
54  for (MFIter mfi(vars_new[lev][Vars::cons], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
55  const Box& bx = mfi.tilebox();
56  const Array4< Real> cons_arr = vars_new[lev][Vars::cons].array(mfi);
57  const Array4<const Real> mfx_arr = mapfac[lev][MapFacType::m_x]->const_array(mfi);
58  const Array4<const Real> mfy_arr = mapfac[lev][MapFacType::m_y]->const_array(mfi);
59  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
60  const Array4<const Real> detJ_arr = detJ_cc[lev]->const_array(mfi);
61  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
62  {
63  cons_arr(i,j,k,scomp+n) *= detJ_arr(i,j,k) / (mfx_arr(i,j,0)*mfy_arr(i,j,0));
64  });
65  } else {
66  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
67  {
68  cons_arr(i,j,k,scomp+n) /= (mfx_arr(i,j,0)*mfy_arr(i,j,0));
69  });
70  }
71  } // mfi
72  } // lev
73 
74  int fine_lev = crse_lev+1;
75 
76  if (interpolation_type == StateInterpType::Perturbational) {
77  // Make the fine rho and (rho theta) be perturbational
78  MultiFab::Divide(vars_new[fine_lev][Vars::cons],vars_new[fine_lev][Vars::cons],
79  Rho_comp,RhoTheta_comp,1,IntVect{0});
80  MultiFab::Subtract(vars_new[fine_lev][Vars::cons],base_state[fine_lev],
81  BaseState::r0_comp,Rho_comp,1,IntVect{0});
82  MultiFab::Subtract(vars_new[fine_lev][Vars::cons],base_state[fine_lev],
83  BaseState::th0_comp,RhoTheta_comp,1,IntVect{0});
84 
85  // Make the crse rho and (rho theta) be perturbational
86  MultiFab::Divide(vars_new[crse_lev][Vars::cons],vars_new[crse_lev][Vars::cons],
87  Rho_comp,RhoTheta_comp,1,IntVect{0});
88  MultiFab::Subtract(vars_new[crse_lev][Vars::cons],base_state[crse_lev],
89  BaseState::r0_comp,Rho_comp,1,IntVect{0});
90  MultiFab::Subtract(vars_new[crse_lev][Vars::cons],base_state[crse_lev],
91  BaseState::th0_comp,RhoTheta_comp,1,IntVect{0});
92  }
93 
94  average_down(vars_new[crse_lev+1][Vars::cons],vars_new[crse_lev ][Vars::cons],
95  scomp, ncomp, refRatio(crse_lev));
96 
97  if (interpolation_type == StateInterpType::Perturbational) {
98  // Restore the fine data to what it was
99  MultiFab::Add(vars_new[fine_lev][Vars::cons],base_state[fine_lev],
100  BaseState::r0_comp,Rho_comp,1,IntVect{0});
101  MultiFab::Add(vars_new[fine_lev][Vars::cons],base_state[fine_lev],
102  BaseState::th0_comp,RhoTheta_comp,1,IntVect{0});
103  MultiFab::Multiply(vars_new[fine_lev][Vars::cons],vars_new[fine_lev][Vars::cons],
104  Rho_comp,RhoTheta_comp,1,IntVect{0});
105 
106  // Make the crse data be full values not perturbational
107  MultiFab::Add(vars_new[crse_lev][Vars::cons],base_state[crse_lev],
108  BaseState::r0_comp,Rho_comp,1,IntVect{0});
109  MultiFab::Add(vars_new[crse_lev][Vars::cons],base_state[crse_lev],
110  BaseState::th0_comp,RhoTheta_comp,1,IntVect{0});
111  MultiFab::Multiply(vars_new[crse_lev][Vars::cons],vars_new[crse_lev][Vars::cons],
112  Rho_comp,RhoTheta_comp,1,IntVect{0});
113  }
114 
115  vars_new[crse_lev][Vars::cons].FillBoundary(geom[crse_lev].periodicity());
116 
117  // Here we multiply (rho S) by m^2 after average down
118  for (int lev = crse_lev; lev <= crse_lev+1; lev++) {
119  for (MFIter mfi(vars_new[lev][Vars::cons], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
120  const Box& bx = mfi.tilebox();
121  const Array4< Real> cons_arr = vars_new[lev][Vars::cons].array(mfi);
122  const Array4<const Real> mfx_arr = mapfac[lev][MapFacType::m_x]->const_array(mfi);
123  const Array4<const Real> mfy_arr = mapfac[lev][MapFacType::m_y]->const_array(mfi);
124  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
125  const Array4<const Real> detJ_arr = detJ_cc[lev]->const_array(mfi);
126  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
127  {
128  cons_arr(i,j,k,scomp+n) *= detJ_arr(i,j,k) / (mfx_arr(i,j,0)*mfy_arr(i,j,0));
129  });
130  } else {
131  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
132  {
133  cons_arr(i,j,k,scomp+n) /= (mfx_arr(i,j,0)*mfy_arr(i,j,0));
134  });
135  }
136  } // mfi
137  } // lev
138 
139  // ******************************************************************************************
140  // Now average down momenta.
141  // Note that vars_new holds velocities not momenta, but we want to do conservative
142  // averaging so we first convert to momentum, then average down, then convert
143  // back to velocities -- only on the valid region
144  // ******************************************************************************************
145  for (int lev = crse_lev; lev <= crse_lev+1; lev++)
146  {
147  // FillBoundary for density so we can go back and forth between velocity and momentum
148  vars_new[lev][Vars::cons].FillBoundary(geom[lev].periodicity());
149 
150  VelocityToMomentum(vars_new[lev][Vars::xvel], IntVect(0,0,0),
151  vars_new[lev][Vars::yvel], IntVect(0,0,0),
152  vars_new[lev][Vars::zvel], IntVect(0,0,0),
153  vars_new[lev][Vars::cons],
154  rU_new[lev],
155  rV_new[lev],
156  rW_new[lev],
157  Geom(lev).Domain(),
159  }
160 
161  average_down_faces(rU_new[crse_lev+1], rU_new[crse_lev], refRatio(crse_lev), geom[crse_lev]);
162  average_down_faces(rV_new[crse_lev+1], rV_new[crse_lev], refRatio(crse_lev), geom[crse_lev]);
163  average_down_faces(rW_new[crse_lev+1], rW_new[crse_lev], refRatio(crse_lev), geom[crse_lev]);
164 
165  for (int lev = crse_lev; lev <= crse_lev+1; lev++) {
167  vars_new[lev][Vars::yvel],
168  vars_new[lev][Vars::zvel],
169  vars_new[lev][Vars::cons],
170  rU_new[lev],
171  rV_new[lev],
172  rW_new[lev],
173  Geom(lev).Domain(),
175  }
176 }
void MomentumToVelocity(MultiFab &xvel, MultiFab &yvel, MultiFab &zvel, const MultiFab &density, const MultiFab &xmom_in, const MultiFab &ymom_in, const MultiFab &zmom_in, const Box &domain, const Vector< BCRec > &domain_bcs_type_h)
Definition: ERF_MomentumToVelocity.cpp:25
static StateInterpType interpolation_type
Definition: ERF.H:1040
@ th0_comp
Definition: ERF_IndexDefines.H:66
Here is the call graph for this function:

◆ build_fine_mask()

MultiFab & ERF::build_fine_mask ( int  level)

Helper function for constructing a fine mask, that is, a MultiFab masking coarser data at a lower level by zeroing out covered cells in the fine mask MultiFab we compute.

Parameters
levelFine level index which masks underlying coarser data
692 {
693  // Mask for zeroing covered cells
694  AMREX_ASSERT(level > 0);
695 
696  const BoxArray& cba = grids[level-1];
697  const DistributionMapping& cdm = dmap[level-1];
698 
699  // TODO -- we should make a vector of these a member of ERF class
700  fine_mask.define(cba, cdm, 1, 0, MFInfo());
701  fine_mask.setVal(1.0);
702 
703  BoxArray fba = grids[level];
704  iMultiFab ifine_mask = makeFineMask(cba, cdm, fba, ref_ratio[level-1], 1, 0);
705 
706  const auto fma = fine_mask.arrays();
707  const auto ifma = ifine_mask.arrays();
708  ParallelFor(fine_mask, [=] AMREX_GPU_DEVICE(int bno, int i, int j, int k) noexcept
709  {
710  fma[bno](i,j,k) = ifma[bno](i,j,k);
711  });
712 
713  return fine_mask;
714 }
amrex::MultiFab fine_mask
Definition: ERF.H:1166

◆ ClearLevel()

void ERF::ClearLevel ( int  lev)
override
568 {
569  for (int var_idx = 0; var_idx < Vars::NumTypes; ++var_idx) {
570  vars_new[lev][var_idx].clear();
571  vars_old[lev][var_idx].clear();
572  }
573 
574  base_state[lev].clear();
575 
576  rU_new[lev].clear();
577  rU_old[lev].clear();
578  rV_new[lev].clear();
579  rV_old[lev].clear();
580  rW_new[lev].clear();
581  rW_old[lev].clear();
582 
583  if (lev > 0) {
584  zmom_crse_rhs[lev].clear();
585  }
586 
588  pp_inc[lev].clear();
589  }
590 
591  // Clears the integrator memory
592  mri_integrator_mem[lev].reset();
593 
594  // Clears the physical boundary condition routines
595  physbcs_cons[lev].reset();
596  physbcs_u[lev].reset();
597  physbcs_v[lev].reset();
598  physbcs_w[lev].reset();
599  physbcs_base[lev].reset();
600 
601  // Clears the flux register array
602  advflux_reg[lev]->reset();
603 }
amrex::Vector< amrex::MultiFab > pp_inc
Definition: ERF.H:719
amrex::Vector< amrex::YAFluxRegister * > advflux_reg
Definition: ERF.H:846
amrex::Vector< std::unique_ptr< ERFPhysBCFunct_base > > physbcs_base
Definition: ERF.H:726
@ NumTypes
Definition: ERF_IndexDefines.H:144
bool project_initial_velocity
Definition: ERF_DataStruct.H:761

◆ cloud_fraction()

Real ERF::cloud_fraction ( amrex::Real  time)
422 {
423  BL_PROFILE("ERF::cloud_fraction()");
424 
425  int lev = 0;
426  // This holds all of qc
427  MultiFab qc(vars_new[lev][Vars::cons],make_alias,RhoQ2_comp,1);
428 
429  int direction = 2; // z-direction
430  Box const& domain = geom[lev].Domain();
431 
432  auto const& qc_arr = qc.const_arrays();
433 
434  // qc_2d is an BaseFab<int> holding the max value over the column
435  auto qc_2d = ReduceToPlane<ReduceOpMax,int>(direction, domain, qc,
436  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) -> int
437  {
438  if (qc_arr[box_no](i,j,k) > 0) {
439  return 1;
440  } else {
441  return 0;
442  }
443  });
444 
445  auto* p = qc_2d.dataPtr();
446 
447  Long numpts = qc_2d.numPts();
448 
449  AMREX_ASSERT(numpts < Long(std::numeric_limits<int>::max));
450 
451 #if 1
452  if (ParallelDescriptor::UseGpuAwareMpi()) {
453  ParallelDescriptor::ReduceIntMax(p,static_cast<int>(numpts));
454  } else {
455  Gpu::PinnedVector<int> hv(numpts);
456  Gpu::copyAsync(Gpu::deviceToHost, p, p+numpts, hv.data());
457  Gpu::streamSynchronize();
458  ParallelDescriptor::ReduceIntMax(hv.data(),static_cast<int>(numpts));
459  Gpu::copyAsync(Gpu::hostToDevice, hv.data(), hv.data()+numpts, p);
460  }
461 
462  // Sum over component 0
463  Long num_cloudy = qc_2d.template sum<RunOn::Device>(0);
464 
465 #else
466  //
467  // We need this if we allow domain decomposition in the vertical
468  // but for now we leave it commented out
469  //
470  Long num_cloudy = Reduce::Sum<Long>(numpts,
471  [=] AMREX_GPU_DEVICE (Long i) -> Long {
472  if (p[i] == 1) {
473  return 1;
474  } else {
475  return 0;
476  }
477  });
478  ParallelDescriptor::ReduceLongSum(num_cloudy);
479 #endif
480 
481  Real num_total = qc_2d.box().d_numPts();
482 
483  Real cloud_frac = num_cloudy / num_total;
484 
485  return cloud_frac;
486 }
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:43
@ qc
Definition: ERF_SatAdj.H:36

◆ compute_divergence()

void ERF::compute_divergence ( int  lev,
amrex::MultiFab &  rhs,
amrex::Array< amrex::MultiFab const *, AMREX_SPACEDIM >  rho0_u_const,
amrex::Geometry const &  geom_at_lev 
)

Project the single-level velocity field to enforce incompressibility Note that the level may or may not be level 0.

11 {
12  BL_PROFILE("ERF::compute_divergence()");
13 
14  auto dxInv = geom_at_lev.InvCellSizeArray();
15 
16  // ****************************************************************************
17  // Compute divergence which will form RHS
18  // Note that we replace "rho0w" with the contravariant momentum, Omega
19  // ****************************************************************************
20  if (solverChoice.terrain_type == TerrainType::EB)
21  {
22  bool already_on_centroids = true;
23  EB_computeDivergence(rhs, rho0_u_const, geom_at_lev, already_on_centroids);
24  }
25  else if (SolverChoice::mesh_type == MeshType::ConstantDz)
26  {
27  computeDivergence(rhs, rho0_u_const, geom_at_lev);
28  }
29  else
30  {
31  for ( MFIter mfi(rhs,TilingIfNotGPU()); mfi.isValid(); ++mfi)
32  {
33  Box bx = mfi.tilebox();
34  const Array4<Real const>& rho0u_arr = rho0_u_const[0]->const_array(mfi);
35  const Array4<Real const>& rho0v_arr = rho0_u_const[1]->const_array(mfi);
36  const Array4<Real const>& rho0w_arr = rho0_u_const[2]->const_array(mfi);
37  const Array4<Real >& rhs_arr = rhs.array(mfi);
38 
39  const Array4<Real const>& mf_mx = mapfac[lev][MapFacType::m_x]->const_array(mfi);
40  const Array4<Real const>& mf_my = mapfac[lev][MapFacType::m_y]->const_array(mfi);
41 
42  if (SolverChoice::mesh_type == MeshType::StretchedDz) {
43  Real* stretched_dz_d_ptr = stretched_dz_d[lev].data();
44  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
45  Real dz = stretched_dz_d_ptr[k];
46  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
47  rhs_arr(i,j,k) = mfsq * ( (rho0u_arr(i+1,j ,k ) - rho0u_arr(i,j,k)) * dxInv[0]
48  +(rho0v_arr(i ,j+1,k ) - rho0v_arr(i,j,k)) * dxInv[1]
49  +(rho0w_arr(i ,j ,k+1) - rho0w_arr(i,j,k)) / dz );
50  });
51  } else {
52 
53  //
54  // Note we compute the divergence using "rho0w" == Omega
55  //
56  const Array4<Real const>& ax_arr = ax[lev]->const_array(mfi);
57  const Array4<Real const>& ay_arr = ay[lev]->const_array(mfi);
58  const Array4<Real const>& dJ_arr = detJ_cc[lev]->const_array(mfi);
59  //
60  // az == 1 for terrain-fitted coordinates
61  //
62  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
63  {
64  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
65  rhs_arr(i,j,k) = mfsq * ( (ax_arr(i+1,j,k)*rho0u_arr(i+1,j,k) - ax_arr(i,j,k)*rho0u_arr(i,j,k)) * dxInv[0]
66  +(ay_arr(i,j+1,k)*rho0v_arr(i,j+1,k) - ay_arr(i,j,k)*rho0v_arr(i,j,k)) * dxInv[1]
67  +( rho0w_arr(i,j,k+1) - rho0w_arr(i,j,k)) * dxInv[2] ) / dJ_arr(i,j,k);
68  });
69  }
70  } // mfi
71  }
72 }
amrex::Vector< std::unique_ptr< amrex::MultiFab > > ax
Definition: ERF.H:807
amrex::Vector< std::unique_ptr< amrex::MultiFab > > ay
Definition: ERF.H:808
static TerrainType terrain_type
Definition: ERF_DataStruct.H:697

◆ ComputeDt()

void ERF::ComputeDt ( int  step = -1)
private

Function that calls estTimeStep for each level

12 {
13  Vector<Real> dt_tmp(finest_level+1);
14 
15  for (int lev = 0; lev <= finest_level; ++lev)
16  {
17  dt_tmp[lev] = estTimeStep(lev, dt_mri_ratio[lev]);
18  }
19 
20  ParallelDescriptor::ReduceRealMin(&dt_tmp[0], dt_tmp.size());
21 
22  Real dt_0 = dt_tmp[0];
23  int n_factor = 1;
24  for (int lev = 0; lev <= finest_level; ++lev) {
25  dt_tmp[lev] = amrex::min(dt_tmp[lev], change_max*dt[lev]);
26  n_factor *= nsubsteps[lev];
27  dt_0 = amrex::min(dt_0, n_factor*dt_tmp[lev]);
28  if (step == 0){
29  dt_0 *= init_shrink;
30  if (verbose && init_shrink != 1.0) {
31  Print() << "Timestep 0: shrink initial dt at level " << lev << " by " << init_shrink << std::endl;
32  }
33  }
34  }
35  // Limit dt's by the value of stop_time.
36  const Real eps = 1.e-3*dt_0;
37  if (t_new[0] + dt_0 > stop_time - eps) {
38  dt_0 = stop_time - t_new[0];
39  }
40 
41  dt[0] = dt_0;
42  for (int lev = 1; lev <= finest_level; ++lev) {
43  dt[lev] = dt[lev-1] / nsubsteps[lev];
44  }
45 }
amrex::Real stop_time
Definition: ERF.H:896
amrex::Real estTimeStep(int lev, long &dt_fast_ratio) const
Definition: ERF_ComputeTimestep.cpp:54
amrex::Vector< int > nsubsteps
Definition: ERF.H:696
static amrex::Real init_shrink
Definition: ERF.H:907
static amrex::Real change_max
Definition: ERF.H:908

◆ ComputeGhostCells()

static AMREX_FORCE_INLINE int ERF::ComputeGhostCells ( const SolverChoice sc)
inlinestaticprivate
1173  {
1174  int ngrow = 0;
1175 
1176  if (sc.use_num_diff)
1177  {
1178  ngrow = 3;
1179  } else {
1180  if (
1187  { ngrow = 3; }
1188  else if (
1195  { ngrow = 3; }
1196  else if (
1205  { ngrow = 3; }
1206  else if (
1215  { ngrow = 4; }
1216  else
1217  {
1218  if (sc.terrain_type == TerrainType::EB){
1219  ngrow = 3;
1220  } else {
1221  ngrow = 2;
1222  }
1223  }
1224  }
1225 
1226  return ngrow;
1227  }
@ Centered_6th
AdvType moistscal_horiz_adv_type
Definition: ERF_AdvStruct.H:343
AdvType dycore_vert_adv_type
Definition: ERF_AdvStruct.H:340
AdvType moistscal_vert_adv_type
Definition: ERF_AdvStruct.H:344
AdvType dryscal_horiz_adv_type
Definition: ERF_AdvStruct.H:341
AdvType dycore_horiz_adv_type
Definition: ERF_AdvStruct.H:339
AdvType dryscal_vert_adv_type
Definition: ERF_AdvStruct.H:342
AdvChoice advChoice
Definition: ERF_DataStruct.H:711

◆ Construct_ERFFillPatchers()

void ERF::Construct_ERFFillPatchers ( int  lev)
private
2117 {
2118  auto& fine_new = vars_new[lev];
2119  auto& crse_new = vars_new[lev-1];
2120  auto& ba_fine = fine_new[Vars::cons].boxArray();
2121  auto& ba_crse = crse_new[Vars::cons].boxArray();
2122  auto& dm_fine = fine_new[Vars::cons].DistributionMap();
2123  auto& dm_crse = crse_new[Vars::cons].DistributionMap();
2124 
2125  int ncomp = vars_new[lev][Vars::cons].nComp();
2126 
2127  FPr_c.emplace_back(ba_fine, dm_fine, geom[lev] ,
2128  ba_crse, dm_crse, geom[lev-1],
2129  -cf_width, -cf_set_width, ncomp, &cell_cons_interp);
2130  FPr_u.emplace_back(convert(ba_fine, IntVect(1,0,0)), dm_fine, geom[lev] ,
2131  convert(ba_crse, IntVect(1,0,0)), dm_crse, geom[lev-1],
2132  -cf_width, -cf_set_width, 1, &face_cons_linear_interp);
2133  FPr_v.emplace_back(convert(ba_fine, IntVect(0,1,0)), dm_fine, geom[lev] ,
2134  convert(ba_crse, IntVect(0,1,0)), dm_crse, geom[lev-1],
2135  -cf_width, -cf_set_width, 1, &face_cons_linear_interp);
2136  FPr_w.emplace_back(convert(ba_fine, IntVect(0,0,1)), dm_fine, geom[lev] ,
2137  convert(ba_crse, IntVect(0,0,1)), dm_crse, geom[lev-1],
2138  -cf_width, -cf_set_width, 1, &face_cons_linear_interp);
2139 }
int cf_set_width
Definition: ERF.H:777

◆ DataLog()

AMREX_FORCE_INLINE std::ostream& ERF::DataLog ( int  i)
inlineprivate
1238  {
1239  return *datalog[i];
1240  }
amrex::Vector< std::unique_ptr< std::fstream > > datalog
Definition: ERF.H:1414

◆ DataLogName()

std::string ERF::DataLogName ( int  i) const
inlineprivatenoexcept

The filename of the ith datalog file.

1430 { return datalogname[i]; }
amrex::Vector< std::string > datalogname
Definition: ERF.H:1417

◆ Define_ERFFillPatchers()

void ERF::Define_ERFFillPatchers ( int  lev)
private
2143 {
2144  auto& fine_new = vars_new[lev];
2145  auto& crse_new = vars_new[lev-1];
2146  auto& ba_fine = fine_new[Vars::cons].boxArray();
2147  auto& ba_crse = crse_new[Vars::cons].boxArray();
2148  auto& dm_fine = fine_new[Vars::cons].DistributionMap();
2149  auto& dm_crse = crse_new[Vars::cons].DistributionMap();
2150 
2151  int ncomp = fine_new[Vars::cons].nComp();
2152 
2153  FPr_c[lev-1].Define(ba_fine, dm_fine, geom[lev] ,
2154  ba_crse, dm_crse, geom[lev-1],
2155  -cf_width, -cf_set_width, ncomp, &cell_cons_interp);
2156  FPr_u[lev-1].Define(convert(ba_fine, IntVect(1,0,0)), dm_fine, geom[lev] ,
2157  convert(ba_crse, IntVect(1,0,0)), dm_crse, geom[lev-1],
2158  -cf_width, -cf_set_width, 1, &face_cons_linear_interp);
2159  FPr_v[lev-1].Define(convert(ba_fine, IntVect(0,1,0)), dm_fine, geom[lev] ,
2160  convert(ba_crse, IntVect(0,1,0)), dm_crse, geom[lev-1],
2161  -cf_width, -cf_set_width, 1, &face_cons_linear_interp);
2162  FPr_w[lev-1].Define(convert(ba_fine, IntVect(0,0,1)), dm_fine, geom[lev] ,
2163  convert(ba_crse, IntVect(0,0,1)), dm_crse, geom[lev-1],
2164  -cf_width, -cf_set_width, 1, &face_cons_linear_interp);
2165 }

◆ DerDataLog()

AMREX_FORCE_INLINE std::ostream& ERF::DerDataLog ( int  i)
inlineprivate
1245  {
1246  return *der_datalog[i];
1247  }
amrex::Vector< std::unique_ptr< std::fstream > > der_datalog
Definition: ERF.H:1415

◆ DerDataLogName()

std::string ERF::DerDataLogName ( int  i) const
inlineprivatenoexcept
1431 { return der_datalogname[i]; }
amrex::Vector< std::string > der_datalogname
Definition: ERF.H:1418

◆ derive_diag_profiles()

void ERF::derive_diag_profiles ( amrex::Real  time,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_u,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_v,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_w,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_rho,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_th,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_ksgs,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_Kmv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_Khv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_qv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_qc,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_qr,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_wqv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_wqc,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_wqr,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_qi,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_qs,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_qg,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_uu,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_uv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_uw,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_vv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_vw,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_ww,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_uth,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_vth,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_wth,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_thth,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_ku,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_kv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_kw,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_p,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_pu,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_pv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_pw,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_wthv 
)

Computes the profiles for diagnostic quantities.

Parameters
h_avg_uProfile for x-velocity on Host
h_avg_vProfile for y-velocity on Host
h_avg_wProfile for z-velocity on Host
h_avg_rhoProfile for density on Host
h_avg_thProfile for potential temperature on Host
h_avg_ksgsProfile for Kinetic Energy on Host
h_avg_uuProfile for x-velocity squared on Host
h_avg_uvProfile for x-velocity * y-velocity on Host
h_avg_uwProfile for x-velocity * z-velocity on Host
h_avg_vvProfile for y-velocity squared on Host
h_avg_vwProfile for y-velocity * z-velocity on Host
h_avg_wwProfile for z-velocity squared on Host
h_avg_uthProfile for x-velocity * potential temperature on Host
h_avg_uiuiuProfile for u_i*u_i*u triple product on Host
h_avg_uiuivProfile for u_i*u_i*v triple product on Host
h_avg_uiuiwProfile for u_i*u_i*w triple product on Host
h_avg_pProfile for pressure perturbation on Host
h_avg_puProfile for pressure perturbation * x-velocity on Host
h_avg_pvProfile for pressure perturbation * y-velocity on Host
h_avg_pwProfile for pressure perturbation * z-velocity on Host
205 {
206  // We assume that this is always called at level 0
207  int lev = 0;
208 
209  bool l_use_kturb = solverChoice.turbChoice[lev].use_kturb;
210  bool l_use_KE = solverChoice.turbChoice[lev].use_tke;
211  // This will hold rho, theta, ksgs, Kmh, Kmv, uu, uv, uw, vv, vw, ww, uth, vth, wth,
212  // 0 1 2 3 4 5 6 7 8 9 10 11 12 13
213  // thth, uiuiu, uiuiv, uiuiw, p, pu, pv, pw, qv, qc, qr, wqv, wqc, wqr,
214  // 14 15 16 17 18 19 20 21 22 23 24 25 26 27
215  // qi, qs, qg, wthv
216  // 28 29 30 31
217  MultiFab mf_out(grids[lev], dmap[lev], 32, 0);
218 
219  MultiFab mf_vels(grids[lev], dmap[lev], AMREX_SPACEDIM, 0);
220 
221  MultiFab u_cc(mf_vels, make_alias, 0, 1); // u at cell centers
222  MultiFab v_cc(mf_vels, make_alias, 1, 1); // v at cell centers
223  MultiFab w_cc(mf_vels, make_alias, 2, 1); // w at cell centers
224 
225  average_face_to_cellcenter(mf_vels,0,
226  Array<const MultiFab*,3>{&vars_new[lev][Vars::xvel],&vars_new[lev][Vars::yvel],&vars_new[lev][Vars::zvel]});
227 
228  int zdir = 2;
229  auto domain = geom[0].Domain();
230 
231  // Sum in the horizontal plane
232  h_avg_u = sumToLine(mf_vels ,0,1,domain,zdir);
233  h_avg_v = sumToLine(mf_vels ,1,1,domain,zdir);
234  h_avg_w = sumToLine(mf_vels ,2,1,domain,zdir);
235 
236  int hu_size = h_avg_u.size();
237 
238  // Divide by the total number of cells we are averaging over
239  Real area_z = static_cast<Real>(domain.length(0)*domain.length(1));
240  for (int k = 0; k < hu_size; ++k) {
241  h_avg_u[k] /= area_z; h_avg_v[k] /= area_z; h_avg_w[k] /= area_z;
242  }
243 
244  Gpu::DeviceVector<Real> d_avg_u(hu_size, Real(0.0));
245  Gpu::DeviceVector<Real> d_avg_v(hu_size, Real(0.0));
246  Gpu::DeviceVector<Real> d_avg_w(hu_size, Real(0.0));
247 
248 #if 0
249  auto* avg_u_ptr = d_avg_u.data();
250  auto* avg_v_ptr = d_avg_v.data();
251  auto* avg_w_ptr = d_avg_w.data();
252 #endif
253 
254  Gpu::copy(Gpu::hostToDevice, h_avg_u.begin(), h_avg_u.end(), d_avg_u.begin());
255  Gpu::copy(Gpu::hostToDevice, h_avg_v.begin(), h_avg_v.end(), d_avg_v.begin());
256  Gpu::copy(Gpu::hostToDevice, h_avg_w.begin(), h_avg_w.end(), d_avg_w.begin());
257 
258  int nvars = vars_new[lev][Vars::cons].nComp();
259  MultiFab mf_cons(vars_new[lev][Vars::cons], make_alias, 0, nvars);
260 
261  MultiFab p_hse (base_state[lev], make_alias, BaseState::p0_comp, 1);
262 
263  bool use_moisture = (solverChoice.moisture_type != MoistureType::None);
264 
265  for ( MFIter mfi(mf_cons,TilingIfNotGPU()); mfi.isValid(); ++mfi)
266  {
267  const Box& bx = mfi.tilebox();
268  const Array4<Real>& fab_arr = mf_out.array(mfi);
269  const Array4<Real>& u_cc_arr = u_cc.array(mfi);
270  const Array4<Real>& v_cc_arr = v_cc.array(mfi);
271  const Array4<Real>& w_cc_arr = w_cc.array(mfi);
272  const Array4<Real>& cons_arr = mf_cons.array(mfi);
273  const Array4<Real>& p0_arr = p_hse.array(mfi);
274  const Array4<const Real>& eta_arr = (l_use_kturb) ? eddyDiffs_lev[lev]->const_array(mfi) :
275  Array4<const Real>{};
276 
277  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
278  {
279  Real theta = cons_arr(i,j,k,RhoTheta_comp) / cons_arr(i,j,k,Rho_comp);
280  fab_arr(i, j, k, 0) = cons_arr(i,j,k,Rho_comp);
281  fab_arr(i, j, k, 1) = theta;
282  Real ksgs = 0.0;
283  if (l_use_KE) {
284  ksgs = cons_arr(i,j,k,RhoKE_comp) / cons_arr(i,j,k,Rho_comp);
285  }
286  fab_arr(i, j, k, 2) = ksgs;
287 #if 1
288  if (l_use_kturb) {
289  fab_arr(i, j, k, 3) = eta_arr(i,j,k,EddyDiff::Mom_v); // Kmv
290  fab_arr(i, j, k, 4) = eta_arr(i,j,k,EddyDiff::Theta_v); // Khv
291  } else {
292  fab_arr(i, j, k, 3) = 0.0;
293  fab_arr(i, j, k, 4) = 0.0;
294  }
295 #else
296  // Here we hijack the "Kturb" variable name to print out the resolved kinetic energy
297  Real upert = u_cc_arr(i,j,k) - avg_u_ptr[k];
298  Real vpert = v_cc_arr(i,j,k) - avg_v_ptr[k];
299  Real wpert = w_cc_arr(i,j,k) - avg_w_ptr[k];
300  fab_arr(i, j, k, 3) = 0.5 * (upert*upert + vpert*vpert + wpert*wpert);
301 #endif
302  fab_arr(i, j, k, 5) = u_cc_arr(i,j,k) * u_cc_arr(i,j,k); // u*u
303  fab_arr(i, j, k, 6) = u_cc_arr(i,j,k) * v_cc_arr(i,j,k); // u*v
304  fab_arr(i, j, k, 7) = u_cc_arr(i,j,k) * w_cc_arr(i,j,k); // u*w
305  fab_arr(i, j, k, 8) = v_cc_arr(i,j,k) * v_cc_arr(i,j,k); // v*v
306  fab_arr(i, j, k, 9) = v_cc_arr(i,j,k) * w_cc_arr(i,j,k); // v*w
307  fab_arr(i, j, k,10) = w_cc_arr(i,j,k) * w_cc_arr(i,j,k); // w*w
308  fab_arr(i, j, k,11) = u_cc_arr(i,j,k) * theta; // u*th
309  fab_arr(i, j, k,12) = v_cc_arr(i,j,k) * theta; // v*th
310  fab_arr(i, j, k,13) = w_cc_arr(i,j,k) * theta; // w*th
311  fab_arr(i, j, k,14) = theta * theta; // th*th
312 
313  // if the number of fields is changed above, then be sure to update
314  // the following def!
315  Real uiui = fab_arr(i,j,k,5) + fab_arr(i,j,k,8) + fab_arr(i,j,k,10);
316  fab_arr(i, j, k,15) = uiui * u_cc_arr(i,j,k); // (ui*ui)*u
317  fab_arr(i, j, k,16) = uiui * v_cc_arr(i,j,k); // (ui*ui)*v
318  fab_arr(i, j, k,17) = uiui * w_cc_arr(i,j,k); // (ui*ui)*w
319 
320  if (!use_moisture) {
321  Real p = getPgivenRTh(cons_arr(i, j, k, RhoTheta_comp));
322  p -= p0_arr(i,j,k);
323  fab_arr(i, j, k,18) = p; // p
324  fab_arr(i, j, k,19) = p * u_cc_arr(i,j,k); // p*u
325  fab_arr(i, j, k,20) = p * v_cc_arr(i,j,k); // p*v
326  fab_arr(i, j, k,21) = p * w_cc_arr(i,j,k); // p*w
327  fab_arr(i, j, k,22) = 0.; // qv
328  fab_arr(i, j, k,23) = 0.; // qc
329  fab_arr(i, j, k,24) = 0.; // qr
330  fab_arr(i, j, k,25) = 0.; // w*qv
331  fab_arr(i, j, k,26) = 0.; // w*qc
332  fab_arr(i, j, k,27) = 0.; // w*qr
333  fab_arr(i, j, k,28) = 0.; // qi
334  fab_arr(i, j, k,29) = 0.; // qs
335  fab_arr(i, j, k,30) = 0.; // qg
336  fab_arr(i, j, k,31) = 0.; // w*thv
337  }
338  });
339  } // mfi
340 
341  if (use_moisture)
342  {
343  int n_qstate_moist = micro->Get_Qstate_Moist_Size();
344 
345  for ( MFIter mfi(mf_cons,TilingIfNotGPU()); mfi.isValid(); ++mfi)
346  {
347  const Box& bx = mfi.tilebox();
348  const Array4<Real>& fab_arr = mf_out.array(mfi);
349  const Array4<Real>& cons_arr = mf_cons.array(mfi);
350  const Array4<Real>& u_cc_arr = u_cc.array(mfi);
351  const Array4<Real>& v_cc_arr = v_cc.array(mfi);
352  const Array4<Real>& w_cc_arr = w_cc.array(mfi);
353  const Array4<Real>& p0_arr = p_hse.array(mfi);
354 
355  int rhoqr_comp = solverChoice.RhoQr_comp;
356 
357  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
358  {
359  Real qv = cons_arr(i,j,k,RhoQ1_comp) / cons_arr(i,j,k,Rho_comp);
360  Real qc = cons_arr(i,j,k,RhoQ2_comp) / cons_arr(i,j,k,Rho_comp);
361  Real qr = (rhoqr_comp > -1) ? cons_arr(i,j,k,rhoqr_comp) / cons_arr(i,j,k,Rho_comp) :
362  Real(0.0);
363  Real p = getPgivenRTh(cons_arr(i, j, k, RhoTheta_comp), qv);
364 
365  p -= p0_arr(i,j,k);
366  fab_arr(i, j, k,18) = p; // p
367  fab_arr(i, j, k,19) = p * u_cc_arr(i,j,k); // p*u
368  fab_arr(i, j, k,20) = p * v_cc_arr(i,j,k); // p*v
369  fab_arr(i, j, k,21) = p * w_cc_arr(i,j,k); // p*w
370  fab_arr(i, j, k,22) = qv; // qv
371  fab_arr(i, j, k,23) = qc; // qc
372  fab_arr(i, j, k,24) = qr; // qr
373  fab_arr(i, j, k,25) = w_cc_arr(i,j,k) * qv; // w*qv
374  fab_arr(i, j, k,26) = w_cc_arr(i,j,k) * qc; // w*qc
375  fab_arr(i, j, k,27) = w_cc_arr(i,j,k) * qr; // w*qr
376  if (n_qstate_moist > 3) {
377  fab_arr(i, j, k,28) = cons_arr(i,j,k,RhoQ3_comp) / cons_arr(i,j,k,Rho_comp); // qi
378  fab_arr(i, j, k,29) = cons_arr(i,j,k,RhoQ5_comp) / cons_arr(i,j,k,Rho_comp); // qs
379  fab_arr(i, j, k,30) = cons_arr(i,j,k,RhoQ6_comp) / cons_arr(i,j,k,Rho_comp); // qg
380  } else {
381  fab_arr(i, j, k,28) = 0.0; // qi
382  fab_arr(i, j, k,29) = 0.0; // qs
383  fab_arr(i, j, k,30) = 0.0; // qg
384  }
385  Real ql = qc + qr;
386  Real theta = cons_arr(i,j,k,RhoTheta_comp) / cons_arr(i,j,k,Rho_comp);
387  Real thv = theta * (1 + 0.61*qv - ql);
388  fab_arr(i, j, k,31) = w_cc_arr(i,j,k) * thv; // w*thv
389  });
390  } // mfi
391  } // use_moisture
392 
393  h_avg_rho = sumToLine(mf_out, 0,1,domain,zdir);
394  h_avg_th = sumToLine(mf_out, 1,1,domain,zdir);
395  h_avg_ksgs = sumToLine(mf_out, 2,1,domain,zdir);
396  h_avg_Kmv = sumToLine(mf_out, 3,1,domain,zdir);
397  h_avg_Khv = sumToLine(mf_out, 4,1,domain,zdir);
398  h_avg_uu = sumToLine(mf_out, 5,1,domain,zdir);
399  h_avg_uv = sumToLine(mf_out, 6,1,domain,zdir);
400  h_avg_uw = sumToLine(mf_out, 7,1,domain,zdir);
401  h_avg_vv = sumToLine(mf_out, 8,1,domain,zdir);
402  h_avg_vw = sumToLine(mf_out, 9,1,domain,zdir);
403  h_avg_ww = sumToLine(mf_out,10,1,domain,zdir);
404  h_avg_uth = sumToLine(mf_out,11,1,domain,zdir);
405  h_avg_vth = sumToLine(mf_out,12,1,domain,zdir);
406  h_avg_wth = sumToLine(mf_out,13,1,domain,zdir);
407  h_avg_thth = sumToLine(mf_out,14,1,domain,zdir);
408  h_avg_uiuiu = sumToLine(mf_out,15,1,domain,zdir);
409  h_avg_uiuiv = sumToLine(mf_out,16,1,domain,zdir);
410  h_avg_uiuiw = sumToLine(mf_out,17,1,domain,zdir);
411  h_avg_p = sumToLine(mf_out,18,1,domain,zdir);
412  h_avg_pu = sumToLine(mf_out,19,1,domain,zdir);
413  h_avg_pv = sumToLine(mf_out,20,1,domain,zdir);
414  h_avg_pw = sumToLine(mf_out,21,1,domain,zdir);
415  h_avg_qv = sumToLine(mf_out,22,1,domain,zdir);
416  h_avg_qc = sumToLine(mf_out,23,1,domain,zdir);
417  h_avg_qr = sumToLine(mf_out,24,1,domain,zdir);
418  h_avg_wqv = sumToLine(mf_out,25,1,domain,zdir);
419  h_avg_wqc = sumToLine(mf_out,26,1,domain,zdir);
420  h_avg_wqr = sumToLine(mf_out,27,1,domain,zdir);
421  h_avg_qi = sumToLine(mf_out,28,1,domain,zdir);
422  h_avg_qs = sumToLine(mf_out,29,1,domain,zdir);
423  h_avg_qg = sumToLine(mf_out,30,1,domain,zdir);
424  h_avg_wthv = sumToLine(mf_out,31,1,domain,zdir);
425 
426  // Divide by the total number of cells we are averaging over
427  int h_avg_u_size = static_cast<int>(h_avg_u.size());
428  for (int k = 0; k < h_avg_u_size; ++k) {
429  h_avg_rho[k] /= area_z;
430  h_avg_ksgs[k] /= area_z;
431  h_avg_Kmv[k] /= area_z;
432  h_avg_Khv[k] /= area_z;
433  h_avg_th[k] /= area_z;
434  h_avg_thth[k] /= area_z;
435  h_avg_uu[k] /= area_z;
436  h_avg_uv[k] /= area_z;
437  h_avg_uw[k] /= area_z;
438  h_avg_vv[k] /= area_z;
439  h_avg_vw[k] /= area_z;
440  h_avg_ww[k] /= area_z;
441  h_avg_uth[k] /= area_z;
442  h_avg_vth[k] /= area_z;
443  h_avg_wth[k] /= area_z;
444  h_avg_uiuiu[k] /= area_z;
445  h_avg_uiuiv[k] /= area_z;
446  h_avg_uiuiw[k] /= area_z;
447  h_avg_p[k] /= area_z;
448  h_avg_pu[k] /= area_z;
449  h_avg_pv[k] /= area_z;
450  h_avg_pw[k] /= area_z;
451  h_avg_qv[k] /= area_z;
452  h_avg_qc[k] /= area_z;
453  h_avg_qr[k] /= area_z;
454  h_avg_wqv[k] /= area_z;
455  h_avg_wqc[k] /= area_z;
456  h_avg_wqr[k] /= area_z;
457  h_avg_qi[k] /= area_z;
458  h_avg_qs[k] /= area_z;
459  h_avg_qg[k] /= area_z;
460  h_avg_wthv[k] /= area_z;
461  }
462 
463 #if 0
464  // Here we print the integrated total kinetic energy as computed in the 1D profile above
465  Real sum = 0.;
466  Real dz = geom[0].ProbHi(2) / static_cast<Real>(h_avg_u_size);
467  for (int k = 0; k < h_avg_u_size; ++k) {
468  sum += h_avg_kturb[k] * h_avg_rho[k] * dz;
469  }
470  amrex::Print() << "ITKE " << time << " " << sum << " using " << h_avg_u_size << " " << dz << std::endl;
471 #endif
472 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=0.)
Definition: ERF_EOS.H:84
#define RhoQ3_comp
Definition: ERF_IndexDefines.H:44
#define RhoQ6_comp
Definition: ERF_IndexDefines.H:47
#define RhoQ5_comp
Definition: ERF_IndexDefines.H:46
#define RhoKE_comp
Definition: ERF_IndexDefines.H:38
@ Theta_v
Definition: ERF_IndexDefines.H:176
@ Mom_v
Definition: ERF_IndexDefines.H:175
@ theta
Definition: ERF_MM5.H:20
@ qv
Definition: ERF_Kessler.H:28
Here is the call graph for this function:

◆ derive_diag_profiles_stag()

void ERF::derive_diag_profiles_stag ( amrex::Real  time,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_u,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_v,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_w,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_rho,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_th,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_ksgs,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_Kmv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_Khv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_qv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_qc,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_qr,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_wqv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_wqc,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_wqr,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_qi,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_qs,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_qg,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_uu,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_uv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_uw,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_vv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_vw,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_ww,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_uth,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_vth,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_wth,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_thth,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_ku,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_kv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_kw,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_p,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_pu,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_pv,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_pw,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_wthv 
)

Computes the profiles for diagnostic quantities at staggered heights.

Parameters
h_avg_uProfile for x-velocity on Host
h_avg_vProfile for y-velocity on Host
h_avg_wProfile for z-velocity on Host
h_avg_rhoProfile for density on Host
h_avg_thProfile for potential temperature on Host
h_avg_ksgsProfile for Kinetic Energy on Host
h_avg_uuProfile for x-velocity squared on Host
h_avg_uvProfile for x-velocity * y-velocity on Host
h_avg_uwProfile for x-velocity * z-velocity on Host
h_avg_vvProfile for y-velocity squared on Host
h_avg_vwProfile for y-velocity * z-velocity on Host
h_avg_wwProfile for z-velocity squared on Host
h_avg_uthProfile for x-velocity * potential temperature on Host
h_avg_uiuiuProfile for u_i*u_i*u triple product on Host
h_avg_uiuivProfile for u_i*u_i*v triple product on Host
h_avg_uiuiwProfile for u_i*u_i*w triple product on Host
h_avg_pProfile for pressure perturbation on Host
h_avg_puProfile for pressure perturbation * x-velocity on Host
h_avg_pvProfile for pressure perturbation * y-velocity on Host
h_avg_pwProfile for pressure perturbation * z-velocity on Host
311 {
312  // We assume that this is always called at level 0
313  int lev = 0;
314 
315  bool l_use_kturb = solverChoice.turbChoice[lev].use_kturb;
316  bool l_use_KE = solverChoice.turbChoice[lev].use_tke;
317  // Note: "uiui" == u_i*u_i = u*u + v*v + w*w
318  // This will hold rho, theta, ksgs, Kmh, Kmv, uu, uv, vv, uth, vth,
319  // indices: 0 1 2 3 4 5 6 7 8 9
320  // thth, uiuiu, uiuiv, p, pu, pv, qv, qc, qr, qi, qs, qg
321  // 10 11 12 13 14 15 16 17 18 19 20 21
322  MultiFab mf_out(grids[lev], dmap[lev], 22, 0);
323 
324  // This will hold uw, vw, ww, wth, uiuiw, pw, wqv, wqc, wqr, wthv
325  // indices: 0 1 2 3 4 5 6 7 8 9
326  MultiFab mf_out_stag(convert(grids[lev], IntVect(0,0,1)), dmap[lev], 10, 0);
327 
328  // This is only used to average u and v; w is not averaged to cell centers
329  MultiFab mf_vels(grids[lev], dmap[lev], 2, 0);
330 
331  MultiFab u_cc(mf_vels, make_alias, 0, 1); // u at cell centers
332  MultiFab v_cc(mf_vels, make_alias, 1, 1); // v at cell centers
333  MultiFab w_fc(vars_new[lev][Vars::zvel], make_alias, 0, 1); // w at face centers (staggered)
334 
335  int zdir = 2;
336  auto domain = geom[0].Domain();
337  Box stag_domain = domain;
338  stag_domain.convert(IntVect(0,0,1));
339 
340  int nvars = vars_new[lev][Vars::cons].nComp();
341  MultiFab mf_cons(vars_new[lev][Vars::cons], make_alias, 0, nvars);
342 
343  MultiFab p_hse (base_state[lev], make_alias, BaseState::p0_comp, 1);
344 
345  bool use_moisture = (solverChoice.moisture_type != MoistureType::None);
346 
347  for ( MFIter mfi(mf_cons,TilingIfNotGPU()); mfi.isValid(); ++mfi)
348  {
349  const Box& bx = mfi.tilebox();
350  const Array4<Real>& fab_arr = mf_out.array(mfi);
351  const Array4<Real>& fab_arr_stag = mf_out_stag.array(mfi);
352  const Array4<Real>& u_arr = vars_new[lev][Vars::xvel].array(mfi);
353  const Array4<Real>& v_arr = vars_new[lev][Vars::yvel].array(mfi);
354  const Array4<Real>& u_cc_arr = u_cc.array(mfi);
355  const Array4<Real>& v_cc_arr = v_cc.array(mfi);
356  const Array4<Real>& w_fc_arr = w_fc.array(mfi);
357  const Array4<Real>& cons_arr = mf_cons.array(mfi);
358  const Array4<Real>& p0_arr = p_hse.array(mfi);
359  const Array4<const Real>& eta_arr = (l_use_kturb) ? eddyDiffs_lev[lev]->const_array(mfi) :
360  Array4<const Real>{};
361 
362  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
363  {
364  u_cc_arr(i,j,k) = 0.5 * (u_arr(i,j,k) + u_arr(i+1,j ,k));
365  v_cc_arr(i,j,k) = 0.5 * (v_arr(i,j,k) + v_arr(i ,j+1,k));
366 
367  Real theta = cons_arr(i,j,k,RhoTheta_comp) / cons_arr(i,j,k,Rho_comp);
368  fab_arr(i, j, k, 0) = cons_arr(i,j,k,Rho_comp);
369  fab_arr(i, j, k, 1) = theta;
370  Real ksgs = 0.0;
371  if (l_use_KE) {
372  ksgs = cons_arr(i,j,k,RhoKE_comp) / cons_arr(i,j,k,Rho_comp);
373  }
374  fab_arr(i, j, k, 2) = ksgs;
375  if (l_use_kturb) {
376  fab_arr(i, j, k, 3) = eta_arr(i,j,k,EddyDiff::Mom_v); // Kmv
377  fab_arr(i, j, k, 4) = eta_arr(i,j,k,EddyDiff::Theta_v); // Khv
378  } else {
379  fab_arr(i, j, k, 3) = 0.0;
380  fab_arr(i, j, k, 4) = 0.0;
381  }
382  fab_arr(i, j, k, 5) = u_cc_arr(i,j,k) * u_cc_arr(i,j,k); // u*u
383  fab_arr(i, j, k, 6) = u_cc_arr(i,j,k) * v_cc_arr(i,j,k); // u*v
384  fab_arr(i, j, k, 7) = v_cc_arr(i,j,k) * v_cc_arr(i,j,k); // v*v
385  fab_arr(i, j, k, 8) = u_cc_arr(i,j,k) * theta; // u*th
386  fab_arr(i, j, k, 9) = v_cc_arr(i,j,k) * theta; // v*th
387  fab_arr(i, j, k,10) = theta * theta; // th*th
388 
389  Real wcc = 0.5 * (w_fc_arr(i,j,k) + w_fc_arr(i,j,k+1));
390 
391  // if the number of fields is changed above, then be sure to update
392  // the following def!
393  Real uiui = fab_arr(i,j,k,5) + fab_arr(i,j,k,7) + wcc*wcc;
394  fab_arr(i, j, k,11) = uiui * u_cc_arr(i,j,k); // (ui*ui)*u
395  fab_arr(i, j, k,12) = uiui * v_cc_arr(i,j,k); // (ui*ui)*v
396 
397  if (!use_moisture) {
398  Real p = getPgivenRTh(cons_arr(i, j, k, RhoTheta_comp));
399  p -= p0_arr(i,j,k);
400  fab_arr(i, j, k,13) = p; // p
401  fab_arr(i, j, k,14) = p * u_cc_arr(i,j,k); // p*u
402  fab_arr(i, j, k,15) = p * v_cc_arr(i,j,k); // p*v
403  fab_arr(i, j, k,16) = 0.; // qv
404  fab_arr(i, j, k,17) = 0.; // qc
405  fab_arr(i, j, k,18) = 0.; // qr
406  fab_arr(i, j, k,19) = 0.; // qi
407  fab_arr(i, j, k,20) = 0.; // qs
408  fab_arr(i, j, k,21) = 0.; // qg
409  }
410  });
411 
412  const Box& zbx = mfi.tilebox(IntVect(0,0,1));
413  ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
414  {
415  // average to z faces (first to cell centers, then in z)
416  Real uface = 0.25 * ( u_arr(i ,j,k) + u_arr(i ,j,k-1)
417  + u_arr(i+1,j,k) + u_arr(i+1,j,k-1));
418  Real vface = 0.25 * ( v_arr(i,j ,k) + v_arr(i,j ,k-1)
419  + v_arr(i,j+1,k) + v_arr(i,j+1,k-1));
420  Real theta0 = cons_arr(i,j,k ,RhoTheta_comp) / cons_arr(i,j,k ,Rho_comp);
421  Real theta1 = cons_arr(i,j,k-1,RhoTheta_comp) / cons_arr(i,j,k-1,Rho_comp);
422  Real thface = 0.5*(theta0 + theta1);
423  fab_arr_stag(i,j,k,0) = uface * w_fc_arr(i,j,k); // u*w
424  fab_arr_stag(i,j,k,1) = vface * w_fc_arr(i,j,k); // v*w
425  fab_arr_stag(i,j,k,2) = w_fc_arr(i,j,k) * w_fc_arr(i,j,k); // w*w
426  fab_arr_stag(i,j,k,3) = thface * w_fc_arr(i,j,k); // th*w
427  Real uiui = uface*uface + vface*vface + fab_arr_stag(i,j,k,2);
428  fab_arr_stag(i,j,k,4) = uiui * w_fc_arr(i,j,k); // (ui*ui)*w
429  if (!use_moisture) {
430  Real p0 = getPgivenRTh(cons_arr(i, j, k , RhoTheta_comp)) - p0_arr(i,j,k );
431  Real p1 = getPgivenRTh(cons_arr(i, j, k-1, RhoTheta_comp)) - p0_arr(i,j,k-1);
432  Real pface = 0.5 * (p0 + p1);
433  fab_arr_stag(i,j,k,5) = pface * w_fc_arr(i,j,k); // p*w
434  fab_arr_stag(i,j,k,6) = 0.; // w*qv
435  fab_arr_stag(i,j,k,7) = 0.; // w*qc
436  fab_arr_stag(i,j,k,8) = 0.; // w*qr
437  fab_arr_stag(i,j,k,9) = 0.; // w*thv
438  }
439  });
440 
441  } // mfi
442 
443  if (use_moisture)
444  {
445  int n_qstate_moist = micro->Get_Qstate_Moist_Size();
446 
447  for ( MFIter mfi(mf_cons,TilingIfNotGPU()); mfi.isValid(); ++mfi)
448  {
449  const Box& bx = mfi.tilebox();
450  const Array4<Real>& fab_arr = mf_out.array(mfi);
451  const Array4<Real>& fab_arr_stag = mf_out_stag.array(mfi);
452  const Array4<Real>& cons_arr = mf_cons.array(mfi);
453  const Array4<Real>& u_cc_arr = u_cc.array(mfi);
454  const Array4<Real>& v_cc_arr = v_cc.array(mfi);
455  const Array4<Real>& w_fc_arr = w_fc.array(mfi);
456  const Array4<Real>& p0_arr = p_hse.array(mfi);
457 
458  int rhoqr_comp = solverChoice.RhoQr_comp;
459 
460  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
461  {
462  Real qv = cons_arr(i,j,k,RhoQ1_comp) / cons_arr(i,j,k,Rho_comp);
463  Real qc = cons_arr(i,j,k,RhoQ2_comp) / cons_arr(i,j,k,Rho_comp);
464  Real qr = (rhoqr_comp > -1) ? cons_arr(i,j,k,rhoqr_comp) / cons_arr(i,j,k,Rho_comp) :
465  Real(0.0);
466  Real p = getPgivenRTh(cons_arr(i, j, k, RhoTheta_comp), qv);
467 
468  p -= p0_arr(i,j,k);
469  fab_arr(i, j, k,13) = p; // p
470  fab_arr(i, j, k,14) = p * u_cc_arr(i,j,k); // p*u
471  fab_arr(i, j, k,15) = p * v_cc_arr(i,j,k); // p*v
472  fab_arr(i, j, k,16) = qv; // qv
473  fab_arr(i, j, k,17) = qc; // qc
474  fab_arr(i, j, k,18) = qr; // qr
475  if (n_qstate_moist > 3) { // SAM model
476  fab_arr(i, j, k,19) = cons_arr(i,j,k,RhoQ3_comp) / cons_arr(i,j,k,Rho_comp); // qi
477  fab_arr(i, j, k,20) = cons_arr(i,j,k,RhoQ5_comp) / cons_arr(i,j,k,Rho_comp); // qs
478  fab_arr(i, j, k,21) = cons_arr(i,j,k,RhoQ6_comp) / cons_arr(i,j,k,Rho_comp); // qg
479  } else {
480  fab_arr(i, j, k,19) = 0.0; // qi
481  fab_arr(i, j, k,20) = 0.0; // qs
482  fab_arr(i, j, k,21) = 0.0; // qg
483  }
484  });
485 
486  const Box& zbx = mfi.tilebox(IntVect(0,0,1));
487  ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
488  {
489  Real qv0 = cons_arr(i,j,k ,RhoQ1_comp) / cons_arr(i,j,k ,Rho_comp);
490  Real qv1 = cons_arr(i,j,k-1,RhoQ1_comp) / cons_arr(i,j,k-1,Rho_comp);
491  Real qc0 = cons_arr(i,j,k ,RhoQ2_comp) / cons_arr(i,j,k ,Rho_comp);
492  Real qc1 = cons_arr(i,j,k-1,RhoQ2_comp) / cons_arr(i,j,k-1,Rho_comp);
493  Real qr0 = (rhoqr_comp > -1) ? cons_arr(i,j,k ,RhoQ3_comp) / cons_arr(i,j,k ,Rho_comp) :
494  Real(0.0);
495  Real qr1 = (rhoqr_comp > -1) ? cons_arr(i,j,k-1,RhoQ3_comp) / cons_arr(i,j,k-1,Rho_comp) :
496  Real(0.0);
497  Real qvface = 0.5 * (qv0 + qv1);
498  Real qcface = 0.5 * (qc0 + qc1);
499  Real qrface = 0.5 * (qr0 + qr1);
500 
501  Real p0 = getPgivenRTh(cons_arr(i, j, k , RhoTheta_comp), qv0) - p0_arr(i,j,k );
502  Real p1 = getPgivenRTh(cons_arr(i, j, k-1, RhoTheta_comp), qv1) - p0_arr(i,j,k-1);
503  Real pface = 0.5 * (p0 + p1);
504 
505  Real theta0 = cons_arr(i,j,k ,RhoTheta_comp) / cons_arr(i,j,k ,Rho_comp);
506  Real theta1 = cons_arr(i,j,k-1,RhoTheta_comp) / cons_arr(i,j,k-1,Rho_comp);
507  Real thface = 0.5*(theta0 + theta1);
508  Real ql = qcface + qrface;
509  Real thv = thface * (1 + 0.61*qvface - ql);
510 
511  fab_arr_stag(i,j,k,5) = pface * w_fc_arr(i,j,k); // p*w
512  fab_arr_stag(i,j,k,6) = qvface * w_fc_arr(i,j,k); // w*qv
513  fab_arr_stag(i,j,k,7) = qcface * w_fc_arr(i,j,k); // w*qc
514  fab_arr_stag(i,j,k,8) = qrface * w_fc_arr(i,j,k); // w*qr
515  fab_arr_stag(i,j,k,9) = thv * w_fc_arr(i,j,k); // w*thv
516  });
517  } // mfi
518  } // use_moisture
519 
520  // Sum in the horizontal plane
521  h_avg_u = sumToLine(u_cc,0,1, domain,zdir);
522  h_avg_v = sumToLine(v_cc,0,1, domain,zdir);
523  h_avg_w = sumToLine(w_fc,0,1,stag_domain,zdir);
524 
525  h_avg_rho = sumToLine(mf_out, 0,1,domain,zdir);
526  h_avg_th = sumToLine(mf_out, 1,1,domain,zdir);
527  h_avg_ksgs = sumToLine(mf_out, 2,1,domain,zdir);
528  h_avg_Kmv = sumToLine(mf_out, 3,1,domain,zdir);
529  h_avg_Khv = sumToLine(mf_out, 4,1,domain,zdir);
530  h_avg_uu = sumToLine(mf_out, 5,1,domain,zdir);
531  h_avg_uv = sumToLine(mf_out, 6,1,domain,zdir);
532  h_avg_vv = sumToLine(mf_out, 7,1,domain,zdir);
533  h_avg_uth = sumToLine(mf_out, 8,1,domain,zdir);
534  h_avg_vth = sumToLine(mf_out, 9,1,domain,zdir);
535  h_avg_thth = sumToLine(mf_out,10,1,domain,zdir);
536  h_avg_uiuiu = sumToLine(mf_out,11,1,domain,zdir);
537  h_avg_uiuiv = sumToLine(mf_out,12,1,domain,zdir);
538  h_avg_p = sumToLine(mf_out,13,1,domain,zdir);
539  h_avg_pu = sumToLine(mf_out,14,1,domain,zdir);
540  h_avg_pv = sumToLine(mf_out,15,1,domain,zdir);
541  h_avg_qv = sumToLine(mf_out,16,1,domain,zdir);
542  h_avg_qc = sumToLine(mf_out,17,1,domain,zdir);
543  h_avg_qr = sumToLine(mf_out,18,1,domain,zdir);
544  h_avg_qi = sumToLine(mf_out,19,1,domain,zdir);
545  h_avg_qs = sumToLine(mf_out,20,1,domain,zdir);
546  h_avg_qg = sumToLine(mf_out,21,1,domain,zdir);
547 
548  h_avg_uw = sumToLine(mf_out_stag,0,1,stag_domain,zdir);
549  h_avg_vw = sumToLine(mf_out_stag,1,1,stag_domain,zdir);
550  h_avg_ww = sumToLine(mf_out_stag,2,1,stag_domain,zdir);
551  h_avg_wth = sumToLine(mf_out_stag,3,1,stag_domain,zdir);
552  h_avg_uiuiw = sumToLine(mf_out_stag,4,1,stag_domain,zdir);
553  h_avg_pw = sumToLine(mf_out_stag,5,1,stag_domain,zdir);
554  h_avg_wqv = sumToLine(mf_out_stag,6,1,stag_domain,zdir);
555  h_avg_wqc = sumToLine(mf_out_stag,7,1,stag_domain,zdir);
556  h_avg_wqr = sumToLine(mf_out_stag,8,1,stag_domain,zdir);
557  h_avg_wthv = sumToLine(mf_out_stag,9,1,stag_domain,zdir);
558 
559  // Divide by the total number of cells we are averaging over
560  Real area_z = static_cast<Real>(domain.length(0)*domain.length(1));
561  int unstag_size = h_avg_w.size() - 1; // _un_staggered heights
562  for (int k = 0; k < unstag_size; ++k) {
563  h_avg_u[k] /= area_z;
564  h_avg_v[k] /= area_z;
565  h_avg_rho[k] /= area_z;
566  h_avg_ksgs[k] /= area_z;
567  h_avg_Kmv[k] /= area_z;
568  h_avg_Khv[k] /= area_z;
569  h_avg_th[k] /= area_z;
570  h_avg_thth[k] /= area_z;
571  h_avg_uu[k] /= area_z;
572  h_avg_uv[k] /= area_z;
573  h_avg_vv[k] /= area_z;
574  h_avg_uth[k] /= area_z;
575  h_avg_vth[k] /= area_z;
576  h_avg_uiuiu[k] /= area_z;
577  h_avg_uiuiv[k] /= area_z;
578  h_avg_p[k] /= area_z;
579  h_avg_pu[k] /= area_z;
580  h_avg_pv[k] /= area_z;
581  h_avg_qv[k] /= area_z;
582  h_avg_qc[k] /= area_z;
583  h_avg_qr[k] /= area_z;
584  h_avg_qi[k] /= area_z;
585  h_avg_qs[k] /= area_z;
586  h_avg_qg[k] /= area_z;
587  }
588 
589  for (int k = 0; k < unstag_size+1; ++k) { // staggered heights
590  h_avg_w[k] /= area_z;
591  h_avg_uw[k] /= area_z;
592  h_avg_vw[k] /= area_z;
593  h_avg_ww[k] /= area_z;
594  h_avg_wth[k] /= area_z;
595  h_avg_uiuiw[k] /= area_z;
596  h_avg_pw[k] /= area_z;
597  h_avg_wqv[k] /= area_z;
598  h_avg_wqc[k] /= area_z;
599  h_avg_wqr[k] /= area_z;
600  h_avg_wthv[k] /= area_z;
601  }
602 }
const Box zbx
Definition: ERF_DiffSetup.H:23
Here is the call graph for this function:

◆ derive_stress_profiles()

void ERF::derive_stress_profiles ( amrex::Gpu::HostVector< amrex::Real > &  h_avg_tau11,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_tau12,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_tau13,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_tau22,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_tau23,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_tau33,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_hfx3,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_q1fx3,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_q2fx3,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_diss 
)
480 {
481  int lev = 0;
482 
483  // This will hold the stress tensor components
484  MultiFab mf_out(grids[lev], dmap[lev], 10, 0);
485 
486  MultiFab mf_rho(vars_new[lev][Vars::cons], make_alias, 0, 1);
487 
488  bool l_use_moist = ( solverChoice.moisture_type != MoistureType::None );
489 
490  for ( MFIter mfi(mf_out,TilingIfNotGPU()); mfi.isValid(); ++mfi)
491  {
492  const Box& bx = mfi.tilebox();
493  const Array4<Real>& fab_arr = mf_out.array(mfi);
494 
495  const Array4<const Real>& rho_arr = mf_rho.const_array(mfi);
496 
497  // NOTE: These are from the last RK stage...
498  const Array4<const Real>& tau11_arr = Tau[lev][TauType::tau11]->const_array(mfi);
499  const Array4<const Real>& tau12_arr = Tau[lev][TauType::tau12]->const_array(mfi);
500  const Array4<const Real>& tau13_arr = Tau[lev][TauType::tau13]->const_array(mfi);
501  const Array4<const Real>& tau22_arr = Tau[lev][TauType::tau22]->const_array(mfi);
502  const Array4<const Real>& tau23_arr = Tau[lev][TauType::tau23]->const_array(mfi);
503  const Array4<const Real>& tau33_arr = Tau[lev][TauType::tau33]->const_array(mfi);
504 
505  // These should be re-calculated during ERF_slow_rhs_post
506  // -- just vertical SFS kinematic heat flux for now
507  //const Array4<const Real>& hfx1_arr = SFS_hfx1_lev[lev]->const_array(mfi);
508  //const Array4<const Real>& hfx2_arr = SFS_hfx2_lev[lev]->const_array(mfi);
509  const Array4<const Real>& hfx3_arr = SFS_hfx3_lev[lev]->const_array(mfi);
510  const Array4<const Real>& q1fx3_arr = (l_use_moist) ? SFS_q1fx3_lev[lev]->const_array(mfi) :
511  Array4<const Real>{};
512  const Array4<const Real>& q2fx3_arr = (l_use_moist) ? SFS_q2fx3_lev[lev]->const_array(mfi) :
513  Array4<const Real>{};
514  const Array4<const Real>& diss_arr = SFS_diss_lev[lev]->const_array(mfi);
515 
516  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
517  {
518  // rho averaging should follow Diffusion/ERF_ComputeStress_*.cpp
519  fab_arr(i, j, k, 0) = tau11_arr(i,j,k) / rho_arr(i,j,k);
520  fab_arr(i, j, k, 1) = ( tau12_arr(i,j ,k) + tau12_arr(i+1,j ,k)
521  + tau12_arr(i,j+1,k) + tau12_arr(i+1,j+1,k) )
522  / ( rho_arr(i,j ,k) + rho_arr(i+1,j ,k)
523  + rho_arr(i,j+1,k) + rho_arr(i+1,j+1,k) );
524  fab_arr(i, j, k, 2) = ( tau13_arr(i,j,k ) + tau13_arr(i+1,j,k )
525  + tau13_arr(i,j,k+1) + tau13_arr(i+1,j,k+1) )
526  / ( rho_arr(i,j,k ) + rho_arr(i+1,j,k )
527  + rho_arr(i,j,k+1) + rho_arr(i+1,j,k+1) );
528  fab_arr(i, j, k, 3) = tau22_arr(i,j,k) / rho_arr(i,j,k);
529  fab_arr(i, j, k, 4) = ( tau23_arr(i,j,k ) + tau23_arr(i,j+1,k )
530  + tau23_arr(i,j,k+1) + tau23_arr(i,j+1,k+1) )
531  / ( rho_arr(i,j,k ) + rho_arr(i,j+1,k )
532  + rho_arr(i,j,k+1) + rho_arr(i,j+1,k+1) );
533  fab_arr(i, j, k, 5) = tau33_arr(i,j,k) / rho_arr(i,j,k);
534  fab_arr(i, j, k, 6) = 0.5 * ( hfx3_arr(i,j,k) + hfx3_arr(i,j,k+1) ) / rho_arr(i,j,k);
535  fab_arr(i, j, k, 7) = (l_use_moist) ? 0.5 * ( q1fx3_arr(i,j,k) + q1fx3_arr(i,j,k+1) ) / rho_arr(i,j,k) : 0.0;
536  fab_arr(i, j, k, 8) = (l_use_moist) ? 0.5 * ( q2fx3_arr(i,j,k) + q2fx3_arr(i,j,k+1) ) / rho_arr(i,j,k) : 0.0;
537  fab_arr(i, j, k, 9) = diss_arr(i,j,k) / rho_arr(i,j,k);
538  });
539  }
540 
541  int zdir = 2;
542  auto domain = geom[0].Domain();
543 
544  h_avg_tau11 = sumToLine(mf_out,0,1,domain,zdir);
545  h_avg_tau12 = sumToLine(mf_out,1,1,domain,zdir);
546  h_avg_tau13 = sumToLine(mf_out,2,1,domain,zdir);
547  h_avg_tau22 = sumToLine(mf_out,3,1,domain,zdir);
548  h_avg_tau23 = sumToLine(mf_out,4,1,domain,zdir);
549  h_avg_tau33 = sumToLine(mf_out,5,1,domain,zdir);
550  h_avg_hfx3 = sumToLine(mf_out,6,1,domain,zdir);
551  h_avg_q1fx3 = sumToLine(mf_out,7,1,domain,zdir);
552  h_avg_q2fx3 = sumToLine(mf_out,8,1,domain,zdir);
553  h_avg_diss = sumToLine(mf_out,9,1,domain,zdir);
554 
555  int ht_size = h_avg_tau11.size();
556 
557  // Divide by the total number of cells we are averaging over
558  Real area_z = static_cast<Real>(domain.length(0)*domain.length(1));
559  for (int k = 0; k < ht_size; ++k) {
560  h_avg_tau11[k] /= area_z;
561  h_avg_tau12[k] /= area_z;
562  h_avg_tau13[k] /= area_z;
563  h_avg_tau22[k] /= area_z;
564  h_avg_tau23[k] /= area_z;
565  h_avg_tau33[k] /= area_z;
566  h_avg_hfx3[k] /= area_z;
567  h_avg_q1fx3[k] /= area_z;
568  h_avg_q2fx3[k] /= area_z;
569  h_avg_diss[k] /= area_z;
570  }
571 }

◆ derive_stress_profiles_stag()

void ERF::derive_stress_profiles_stag ( amrex::Gpu::HostVector< amrex::Real > &  h_avg_tau11,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_tau12,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_tau13,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_tau22,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_tau23,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_tau33,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_hfx3,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_q1fx3,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_q2fx3,
amrex::Gpu::HostVector< amrex::Real > &  h_avg_diss 
)
610 {
611  int lev = 0;
612 
613  // This will hold the stress tensor components
614  MultiFab mf_out(grids[lev], dmap[lev], 10, 0);
615 
616  // This will hold Tau13 and Tau23
617  MultiFab mf_out_stag(convert(grids[lev], IntVect(0,0,1)), dmap[lev], 5, 0);
618 
619  MultiFab mf_rho(vars_new[lev][Vars::cons], make_alias, 0, 1);
620 
621  bool l_use_moist = ( solverChoice.moisture_type != MoistureType::None );
622 
623  for ( MFIter mfi(mf_out,TilingIfNotGPU()); mfi.isValid(); ++mfi)
624  {
625  const Box& bx = mfi.tilebox();
626  const Array4<Real>& fab_arr = mf_out.array(mfi);
627  const Array4<Real>& fab_arr_stag = mf_out_stag.array(mfi);
628 
629  const Array4<const Real>& rho_arr = mf_rho.const_array(mfi);
630 
631  // NOTE: These are from the last RK stage...
632  const Array4<const Real>& tau11_arr = Tau[lev][TauType::tau11]->const_array(mfi);
633  const Array4<const Real>& tau12_arr = Tau[lev][TauType::tau12]->const_array(mfi);
634  const Array4<const Real>& tau13_arr = Tau[lev][TauType::tau13]->const_array(mfi);
635  const Array4<const Real>& tau22_arr = Tau[lev][TauType::tau22]->const_array(mfi);
636  const Array4<const Real>& tau23_arr = Tau[lev][TauType::tau23]->const_array(mfi);
637  const Array4<const Real>& tau33_arr = Tau[lev][TauType::tau33]->const_array(mfi);
638 
639  // These should be re-calculated during ERF_slow_rhs_post
640  // -- just vertical SFS kinematic heat flux for now
641  //const Array4<const Real>& hfx1_arr = SFS_hfx1_lev[lev]->const_array(mfi);
642  //const Array4<const Real>& hfx2_arr = SFS_hfx2_lev[lev]->const_array(mfi);
643  const Array4<const Real>& hfx3_arr = SFS_hfx3_lev[lev]->const_array(mfi);
644  const Array4<const Real>& q1fx3_arr = (l_use_moist) ? SFS_q1fx3_lev[lev]->const_array(mfi) :
645  Array4<const Real>{};
646  const Array4<const Real>& q2fx3_arr = (l_use_moist) ? SFS_q2fx3_lev[lev]->const_array(mfi) :
647  Array4<const Real>{};
648  const Array4<const Real>& diss_arr = SFS_diss_lev[lev]->const_array(mfi);
649 
650  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
651  {
652  // rho averaging should follow Diffusion/ERF_ComputeStress_*.cpp
653  fab_arr(i, j, k, 0) = tau11_arr(i,j,k) / rho_arr(i,j,k);
654  fab_arr(i, j, k, 1) = ( tau12_arr(i,j ,k) + tau12_arr(i+1,j ,k)
655  + tau12_arr(i,j+1,k) + tau12_arr(i+1,j+1,k) )
656  / ( rho_arr(i,j ,k) + rho_arr(i+1,j ,k)
657  + rho_arr(i,j+1,k) + rho_arr(i+1,j+1,k) );
658  fab_arr(i, j, k, 3) = tau22_arr(i,j,k) / rho_arr(i,j,k);
659  fab_arr(i, j, k, 5) = tau33_arr(i,j,k) / rho_arr(i,j,k);
660  fab_arr(i, j, k, 9) = diss_arr(i,j,k) / rho_arr(i,j,k);
661  });
662 
663  const Box& zbx = mfi.tilebox(IntVect(0,0,1));
664  ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
665  {
666  Real rho_face = 0.5 * (rho_arr(i,j,k-1) + rho_arr(i,j,k));
667  // average from edge to face center
668  fab_arr_stag(i,j,k,0) = 0.5*(tau13_arr(i,j,k) + tau13_arr(i+1,j ,k)) / rho_face;
669  fab_arr_stag(i,j,k,1) = 0.5*(tau23_arr(i,j,k) + tau23_arr(i ,j+1,k)) / rho_face;
670 
671  fab_arr_stag(i,j,k,2) = hfx3_arr(i,j,k) / rho_face;
672  fab_arr_stag(i,j,k,3) = (l_use_moist) ? q1fx3_arr(i,j,k) / rho_face : 0.0;
673  fab_arr_stag(i,j,k,4) = (l_use_moist) ? q2fx3_arr(i,j,k) / rho_face : 0.0;
674  });
675  }
676 
677  int zdir = 2;
678  auto domain = geom[0].Domain();
679  Box stag_domain = domain;
680  stag_domain.convert(IntVect(0,0,1));
681 
682  h_avg_tau11 = sumToLine(mf_out,0,1,domain,zdir);
683  h_avg_tau12 = sumToLine(mf_out,1,1,domain,zdir);
684 // h_avg_tau13 = sumToLine(mf_out,2,1,domain,zdir);
685  h_avg_tau22 = sumToLine(mf_out,3,1,domain,zdir);
686 // h_avg_tau23 = sumToLine(mf_out,4,1,domain,zdir);
687  h_avg_tau33 = sumToLine(mf_out,5,1,domain,zdir);
688 // h_avg_hfx3 = sumToLine(mf_out,6,1,domain,zdir);
689 // h_avg_q1fx3 = sumToLine(mf_out,7,1,domain,zdir);
690 // h_avg_q2fx3 = sumToLine(mf_out,8,1,domain,zdir);
691  h_avg_diss = sumToLine(mf_out,9,1,domain,zdir);
692 
693  h_avg_tau13 = sumToLine(mf_out_stag,0,1,stag_domain,zdir);
694  h_avg_tau23 = sumToLine(mf_out_stag,1,1,stag_domain,zdir);
695  h_avg_hfx3 = sumToLine(mf_out_stag,2,1,stag_domain,zdir);
696  h_avg_q1fx3 = sumToLine(mf_out_stag,3,1,stag_domain,zdir);
697  h_avg_q2fx3 = sumToLine(mf_out_stag,4,1,stag_domain,zdir);
698 
699  int ht_size = h_avg_tau11.size(); // _un_staggered
700 
701  // Divide by the total number of cells we are averaging over
702  Real area_z = static_cast<Real>(domain.length(0)*domain.length(1));
703  for (int k = 0; k < ht_size; ++k) {
704  h_avg_tau11[k] /= area_z;
705  h_avg_tau12[k] /= area_z;
706  h_avg_tau13[k] /= area_z;
707  h_avg_tau22[k] /= area_z;
708  h_avg_tau23[k] /= area_z;
709  h_avg_tau33[k] /= area_z;
710  h_avg_hfx3[k] /= area_z;
711  h_avg_q1fx3[k] /= area_z;
712  h_avg_q2fx3[k] /= area_z;
713  h_avg_diss[k] /= area_z;
714  }
715  // staggered heights
716  h_avg_tau13[ht_size] /= area_z;
717  h_avg_tau23[ht_size] /= area_z;
718  h_avg_hfx3[ht_size] /= area_z;
719  h_avg_q1fx3[ht_size] /= area_z;
720  h_avg_q2fx3[ht_size] /= area_z;
721 }

◆ derive_upwp()

void ERF::derive_upwp ( amrex::Vector< amrex::Real > &  h_havg)

◆ EBFactory()

amrex::EBFArrayBoxFactory const& ERF::EBFactory ( int  lev) const
inlineprivatenoexcept
1448  {
1449  return *(eb[lev]->get_const_factory());
1450  }
amrex::Vector< std::unique_ptr< eb_ > > eb
Definition: ERF.H:1440

Referenced by WriteMyEBSurface().

Here is the caller graph for this function:

◆ erf_enforce_hse()

void ERF::erf_enforce_hse ( int  lev,
amrex::MultiFab &  dens,
amrex::MultiFab &  pres,
amrex::MultiFab &  pi,
amrex::MultiFab &  th,
amrex::MultiFab &  qv,
std::unique_ptr< amrex::MultiFab > &  z_cc 
)

Enforces hydrostatic equilibrium when using terrain.

Parameters
[in]levInteger specifying the current level
[out]densMultiFab storing base state density
[out]presMultiFab storing base state pressure
[out]piMultiFab storing base state Exner function
[in]z_ccPointer to MultiFab storing cell centered z-coordinates
164 {
165  Real l_gravity = solverChoice.gravity;
166  bool l_use_terrain = (solverChoice.mesh_type != MeshType::ConstantDz);
167 
168  const auto geomdata = geom[lev].data();
169  const Real dz = geomdata.CellSize(2);
170 
171  for ( MFIter mfi(dens, TileNoZ()); mfi.isValid(); ++mfi )
172  {
173  // Create a flat box with same horizontal extent but only one cell in vertical
174  const Box& tbz = mfi.nodaltilebox(2);
175  int klo = tbz.smallEnd(2);
176  int khi = tbz.bigEnd(2);
177 
178  // Note we only grow by 1 because that is how big z_cc is.
179  Box b2d = tbz; // Copy constructor
180  b2d.grow(0,1);
181  b2d.grow(1,1);
182  b2d.setRange(2,0);
183 
184  // Intersect this box with the domain
185  Box zdomain = convert(geom[lev].Domain(),tbz.ixType());
186  b2d &= zdomain;
187 
188  // We integrate to the first cell (and below) by using rho in this cell
189  // If gravity == 0 this is constant pressure
190  // If gravity != 0, hence this is a wall, this gives gp0 = dens[0] * gravity
191  // (dens_hse*gravity would also be dens[0]*gravity because we use foextrap for rho at k = -1)
192  // Note ng_pres_hse = 1
193 
194  // We start by assuming pressure on the ground is p_0 (in ERF_Constants.H)
195  // Note that gravity is positive
196 
197  Array4<Real> rho_arr = dens.array(mfi);
198  Array4<Real> pres_arr = pres.array(mfi);
199  Array4<Real> pi_arr = pi.array(mfi);
200  Array4<Real> th_arr = theta.array(mfi);
201  Array4<Real> zcc_arr;
202  if (l_use_terrain) {
203  zcc_arr = z_cc->array(mfi);
204  }
205 
206  const Real rdOcp = solverChoice.rdOcp;
207 
208  ParallelFor(b2d, [=] AMREX_GPU_DEVICE (int i, int j, int)
209  {
210  // Set value at surface from Newton iteration for rho
211  if (klo == 0)
212  {
213  // Physical height of the terrain at cell center
214  Real hz;
215  if (l_use_terrain) {
216  hz = zcc_arr(i,j,klo);
217  } else {
218  hz = 0.5*dz;
219  }
220 
221  pres_arr(i,j,klo) = p_0 - hz * rho_arr(i,j,klo) * l_gravity;
222  pi_arr(i,j,klo) = getExnergivenP(pres_arr(i,j,klo), rdOcp);
223  th_arr(i,j,klo) = getRhoThetagivenP(pres_arr(i,j,klo)) / rho_arr(i,j,klo);
224 
225  //
226  // Set ghost cell with dz and rho at boundary
227  // (We will set the rest of the ghost cells in the boundary condition routine)
228  //
229  pres_arr(i,j,klo-1) = p_0 + hz * rho_arr(i,j,klo) * l_gravity;
230  pi_arr(i,j,klo-1) = getExnergivenP(pres_arr(i,j,klo-1), rdOcp);
231  th_arr(i,j,klo-1) = getRhoThetagivenP(pres_arr(i,j,klo-1)) / rho_arr(i,j,klo-1);
232 
233  } else {
234 
235  // If level > 0 and klo > 0, we need to use the value of pres_arr(i,j,klo-1) which was
236  // filled from FillPatch-ing it.
237  Real dz_loc;
238  if (l_use_terrain) {
239  dz_loc = (zcc_arr(i,j,klo) - zcc_arr(i,j,klo-1));
240  } else {
241  dz_loc = dz;
242  }
243 
244  Real dens_interp = 0.5*(rho_arr(i,j,klo) + rho_arr(i,j,klo-1));
245  pres_arr(i,j,klo) = pres_arr(i,j,klo-1) - dz_loc * dens_interp * l_gravity;
246 
247  pi_arr(i,j,klo ) = getExnergivenP(pres_arr(i,j,klo ), rdOcp);
248  th_arr(i,j,klo ) = getRhoThetagivenP(pres_arr(i,j,klo )) / rho_arr(i,j,klo );
249 
250  pi_arr(i,j,klo-1) = getExnergivenP(pres_arr(i,j,klo-1), rdOcp);
251  th_arr(i,j,klo-1) = getRhoThetagivenP(pres_arr(i,j,klo-1)) / rho_arr(i,j,klo-1);
252  }
253 
254  Real dens_interp;
255  if (l_use_terrain) {
256  for (int k = klo+1; k <= khi; k++) {
257  Real dz_loc = (zcc_arr(i,j,k) - zcc_arr(i,j,k-1));
258  dens_interp = 0.5*(rho_arr(i,j,k) + rho_arr(i,j,k-1));
259  pres_arr(i,j,k) = pres_arr(i,j,k-1) - dz_loc * dens_interp * l_gravity;
260  pi_arr(i,j,k) = getExnergivenP(pres_arr(i,j,k), rdOcp);
261  th_arr(i,j,k) = getRhoThetagivenP(pres_arr(i,j,k)) / rho_arr(i,j,k);
262  }
263  } else {
264  for (int k = klo+1; k <= khi; k++) {
265  dens_interp = 0.5*(rho_arr(i,j,k) + rho_arr(i,j,k-1));
266  pres_arr(i,j,k) = pres_arr(i,j,k-1) - dz * dens_interp * l_gravity;
267  pi_arr(i,j,k) = getExnergivenP(pres_arr(i,j,k), rdOcp);
268  th_arr(i,j,k) = getRhoThetagivenP(pres_arr(i,j,k)) / rho_arr(i,j,k);
269  }
270  }
271  });
272 
273  } // mfi
274 
275  dens.FillBoundary(geom[lev].periodicity());
276  pres.FillBoundary(geom[lev].periodicity());
277  pi.FillBoundary(geom[lev].periodicity());
278  theta.FillBoundary(geom[lev].periodicity());
279  qv.FillBoundary(geom[lev].periodicity());
280 }
constexpr amrex::Real p_0
Definition: ERF_Constants.H:18
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getRhoThetagivenP(const amrex::Real p, const amrex::Real qv=0.0)
Definition: ERF_EOS.H:175
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getExnergivenP(const amrex::Real P, const amrex::Real rdOcp)
Definition: ERF_EOS.H:144
@ pres
Definition: ERF_Kessler.H:25
real(c_double), parameter, private pi
Definition: ERF_module_mp_morr_two_moment.F90:100
amrex::Real rdOcp
Definition: ERF_DataStruct.H:754
amrex::Real gravity
Definition: ERF_DataStruct.H:752
Here is the call graph for this function:

◆ ERF_shared()

void ERF::ERF_shared ( )
108 {
109  if (ParallelDescriptor::IOProcessor()) {
110  const char* erf_hash = buildInfoGetGitHash(1);
111  const char* amrex_hash = buildInfoGetGitHash(2);
112  const char* buildgithash = buildInfoGetBuildGitHash();
113  const char* buildgitname = buildInfoGetBuildGitName();
114 
115  if (strlen(erf_hash) > 0) {
116  Print() << "\n"
117  << "ERF git hash: " << erf_hash << "\n";
118  }
119  if (strlen(amrex_hash) > 0) {
120  Print() << "AMReX git hash: " << amrex_hash << "\n";
121  }
122  if (strlen(buildgithash) > 0) {
123  Print() << buildgitname << " git hash: " << buildgithash << "\n";
124  }
125 
126  Print() << "\n";
127  }
128 
129  int nlevs_max = max_level + 1;
130 
131 #ifdef ERF_USE_WINDFARM
132  Nturb.resize(nlevs_max);
133  vars_windfarm.resize(nlevs_max);
134  SMark.resize(nlevs_max);
135 #endif
136 
137  qheating_rates.resize(nlevs_max);
138  sw_lw_fluxes.resize(nlevs_max);
139  solar_zenith.resize(nlevs_max);
140 
141  // NOTE: size lsm before readparams (chooses the model at all levels)
142  lsm.ReSize(nlevs_max);
143  lsm_data.resize(nlevs_max);
144  lsm_flux.resize(nlevs_max);
145 
146  // NOTE: size canopy model before readparams (if file exists, we construct)
147  m_forest_drag.resize(nlevs_max);
148  for (int lev = 0; lev <= max_level; ++lev) { m_forest_drag[lev] = nullptr;}
149 
150  ReadParameters();
151  initializeMicrophysics(nlevs_max);
152 
153 #ifdef ERF_USE_WINDFARM
154  initializeWindFarm(nlevs_max);
155 #endif
156 
157  rad.resize(nlevs_max);
158  for (int lev = 0; lev <= max_level; ++lev) {
159  if (solverChoice.rad_type == RadiationType::RRTMGP) {
160 #ifdef ERF_USE_RRTMGP
161  rad[lev] = std::make_unique<Radiation>(lev, solverChoice);
162  // pass radiation datalog frequency to model - RRTMGP needs to know when to save data for profiles
163  rad[lev]->setDataLogFrequency(rad_datalog_int);
164 #endif
165  } else if (solverChoice.rad_type != RadiationType::None) {
166  Abort("Don't know this radiation model!");
167  }
168  }
169 
170  const std::string& pv1 = "plot_vars_1"; setPlotVariables(pv1,plot_var_names_1);
171  const std::string& pv2 = "plot_vars_2"; setPlotVariables(pv2,plot_var_names_2);
172 
173  // This is only used when we have mesh_type == MeshType::StretchedDz
174  stretched_dz_h.resize(nlevs_max);
175  stretched_dz_d.resize(nlevs_max);
176 
177  // Initialize staggered vertical levels for grid stretching or terrain, and
178  // to simplify Rayleigh damping layer calculations.
179  zlevels_stag.resize(max_level+1);
183  geom,
184  refRatio(),
187  solverChoice.dz0);
188 
189  if (SolverChoice::mesh_type == MeshType::StretchedDz ||
190  SolverChoice::mesh_type == MeshType::VariableDz) {
191  int nz = geom[0].Domain().length(2) + 1; // staggered
192  if (std::fabs(zlevels_stag[0][nz-1]-geom[0].ProbHi(2)) > 1.0e-4) {
193  Print() << "Note: prob_hi[2]=" << geom[0].ProbHi(2)
194  << " does not match highest requested z level " << zlevels_stag[0][nz-1]
195  << std::endl;
196  }
197  if (std::fabs(zlevels_stag[0][0]-geom[0].ProbLo(2)) > 1.0e-4) {
198  Print() << "Note: prob_lo[2]=" << geom[0].ProbLo(2)
199  << " does not match lowest requested level " << zlevels_stag[0][0]
200  << std::endl;
201  }
202 
203  // Redefine the problem domain here?
204  }
205 
206  prob = amrex_probinit(geom[0].ProbLo(),geom[0].ProbHi());
207 
208  // Geometry on all levels has been defined already.
209 
210  // No valid BoxArray and DistributionMapping have been defined.
211  // But the arrays for them have been resized.
212 
213  istep.resize(nlevs_max, 0);
214  nsubsteps.resize(nlevs_max, 1);
215  for (int lev = 1; lev <= max_level; ++lev) {
216  nsubsteps[lev] = MaxRefRatio(lev-1);
217  }
218 
219  t_new.resize(nlevs_max, 0.0);
220  t_old.resize(nlevs_max, -1.e100);
221  dt.resize(nlevs_max, std::min(1.e100,dt_max_initial));
222  dt_mri_ratio.resize(nlevs_max, 1);
223 
224  vars_new.resize(nlevs_max);
225  vars_old.resize(nlevs_max);
226  gradp.resize(nlevs_max);
227 
228  // We resize this regardless in order to pass it without error
229  pp_inc.resize(nlevs_max);
230 
231  rU_new.resize(nlevs_max);
232  rV_new.resize(nlevs_max);
233  rW_new.resize(nlevs_max);
234 
235  rU_old.resize(nlevs_max);
236  rV_old.resize(nlevs_max);
237  rW_old.resize(nlevs_max);
238 
239  // xmom_crse_rhs.resize(nlevs_max);
240  // ymom_crse_rhs.resize(nlevs_max);
241  zmom_crse_rhs.resize(nlevs_max);
242 
243  for (int lev = 0; lev < nlevs_max; ++lev) {
244  vars_new[lev].resize(Vars::NumTypes);
245  vars_old[lev].resize(Vars::NumTypes);
246  gradp[lev].resize(AMREX_SPACEDIM);
247  }
248 
249  // Time integrator
250  mri_integrator_mem.resize(nlevs_max);
251 
252  // Physical boundary conditions
253  physbcs_cons.resize(nlevs_max);
254  physbcs_u.resize(nlevs_max);
255  physbcs_v.resize(nlevs_max);
256  physbcs_w.resize(nlevs_max);
257  physbcs_base.resize(nlevs_max);
258 
259  // Planes to hold Dirichlet values at boundaries
260  xvel_bc_data.resize(nlevs_max);
261  yvel_bc_data.resize(nlevs_max);
262  zvel_bc_data.resize(nlevs_max);
263  th_bc_data.resize(nlevs_max);
264 
265  advflux_reg.resize(nlevs_max);
266 
267  // Stresses
268  Tau.resize(nlevs_max);
269  SFS_hfx1_lev.resize(nlevs_max); SFS_hfx2_lev.resize(nlevs_max); SFS_hfx3_lev.resize(nlevs_max);
270  SFS_diss_lev.resize(nlevs_max);
271  SFS_q1fx1_lev.resize(nlevs_max); SFS_q1fx2_lev.resize(nlevs_max); SFS_q1fx3_lev.resize(nlevs_max);
272  SFS_q2fx3_lev.resize(nlevs_max);
273  eddyDiffs_lev.resize(nlevs_max);
274  SmnSmn_lev.resize(nlevs_max);
275 
276  // Sea surface temps
277  sst_lev.resize(nlevs_max);
278  tsk_lev.resize(nlevs_max);
279  lmask_lev.resize(nlevs_max);
280 
281  // Metric terms
282  z_phys_nd.resize(nlevs_max);
283  z_phys_cc.resize(nlevs_max);
284  detJ_cc.resize(nlevs_max);
285  ax.resize(nlevs_max);
286  ay.resize(nlevs_max);
287  az.resize(nlevs_max);
288 
289  z_phys_nd_new.resize(nlevs_max);
290  detJ_cc_new.resize(nlevs_max);
291 
292  z_phys_nd_src.resize(nlevs_max);
293  z_phys_cc_src.resize(nlevs_max);
294  detJ_cc_src.resize(nlevs_max);
295  ax_src.resize(nlevs_max);
296  ay_src.resize(nlevs_max);
297  az_src.resize(nlevs_max);
298 
299  z_t_rk.resize(nlevs_max);
300 
301  terrain_blanking.resize(nlevs_max);
302 
303  // Wall distance
304  walldist.resize(nlevs_max);
305 
306  // BoxArrays to make MultiFabs needed to convert WRFBdy data
307  ba1d.resize(nlevs_max);
308  ba2d.resize(nlevs_max);
309 
310  // MultiFabs needed to convert WRFBdy data
311  mf_C1H.resize(nlevs_max);
312  mf_C2H.resize(nlevs_max);
313  mf_MUB.resize(nlevs_max);
314 
315  // Map factors
316  mapfac.resize(nlevs_max);
317 
318  // Thin immersed body
319  xflux_imask.resize(nlevs_max);
320  yflux_imask.resize(nlevs_max);
321  zflux_imask.resize(nlevs_max);
322  //overset_imask.resize(nlevs_max);
323  thin_xforce.resize(nlevs_max);
324  thin_yforce.resize(nlevs_max);
325  thin_zforce.resize(nlevs_max);
326 
327  // Base state
328  base_state.resize(nlevs_max);
329  base_state_new.resize(nlevs_max);
330 
331  // Wave coupling data
332  Hwave.resize(nlevs_max);
333  Lwave.resize(nlevs_max);
334  for (int lev = 0; lev < max_level; ++lev)
335  {
336  Hwave[lev] = nullptr;
337  Lwave[lev] = nullptr;
338  }
339  Hwave_onegrid.resize(nlevs_max);
340  Lwave_onegrid.resize(nlevs_max);
341  for (int lev = 0; lev < max_level; ++lev)
342  {
343  Hwave_onegrid[lev] = nullptr;
344  Lwave_onegrid[lev] = nullptr;
345  }
346 
347  // Theta prim for MOST
348  Theta_prim.resize(nlevs_max);
349 
350  // Qv prim for MOST
351  Qv_prim.resize(nlevs_max);
352 
353  // Qr prim for MOST
354  Qr_prim.resize(nlevs_max);
355 
356  // Time averaged velocity field
357  vel_t_avg.resize(nlevs_max);
358  t_avg_cnt.resize(nlevs_max);
359 
360 #ifdef ERF_USE_NETCDF
361  // Size lat long arrays if using netcdf
362  lat_m.resize(nlevs_max);
363  lon_m.resize(nlevs_max);
364  for (int lev = 0; lev < max_level; ++lev) {
365  lat_m[lev] = nullptr;
366  lon_m[lev] = nullptr;
367  }
368 #endif
369 
370  // Variable coriolis
371  sinPhi_m.resize(nlevs_max);
372  cosPhi_m.resize(nlevs_max);
373  for (int lev = 0; lev < max_level; ++lev) {
374  sinPhi_m[lev] = nullptr;
375  cosPhi_m[lev] = nullptr;
376  }
377 
378  // Initialize tagging criteria for mesh refinement
380 
381  for (int lev = 0; lev < max_level; ++lev)
382  {
383  Print() << "Refinement ratio at level " << lev+1 << " set to be " <<
384  ref_ratio[lev][0] << " " << ref_ratio[lev][1] << " " << ref_ratio[lev][2] << std::endl;
385  }
386 
387  // We will create each of these in MakeNewLevelFromScratch
388  eb.resize(max_level+1);
389  for (int lev = 0; lev < max_level + 1; lev++){
390  eb[lev] = std::make_unique<eb_>();
391  }
392 
393  //
394  // Construct the EB data structures and store in a separate class
395  //
396  // This is needed before initializing level MultiFabs
397  if ( solverChoice.terrain_type == TerrainType::EB ||
398  solverChoice.terrain_type == TerrainType::ImmersedForcing)
399  {
400  Box terrain_bx(surroundingNodes(geom[max_level].Domain())); terrain_bx.grow(3);
401  FArrayBox terrain_fab(makeSlab(terrain_bx,2,0),1);
402  Real dummy_time = 0.0;
403  prob->init_terrain_surface(geom[max_level], terrain_fab, dummy_time);
404  TerrainIF ebterrain(terrain_fab, geom[max_level], stretched_dz_d[max_level]);
405  auto gshop = EB2::makeShop(ebterrain);
406  bool build_coarse_level_by_coarsening(false);
407  // Note this just needs to be an integer > number of V-cycles one might use
408  int max_coarsening_level = ( solverChoice.terrain_type == TerrainType::EB &&
410  solverChoice.anelastic[0] == 1) ) ? 100 : 0;
411  amrex::EB2::Build(gshop, geom[max_level], max_level, max_coarsening_level, build_coarse_level_by_coarsening);
412  }
413 }
void init_zlevels(Vector< Vector< Real >> &zlevels_stag, Vector< Vector< Real >> &stretched_dz_h, Vector< Gpu::DeviceVector< Real >> &stretched_dz_d, Vector< Geometry > const &geom, Vector< IntVect > const &ref_ratio, const Real grid_stretching_ratio, const Real zsurf, const Real dz0)
Definition: ERF_InitZLevels.cpp:11
std::unique_ptr< ProblemBase > amrex_probinit(const amrex_real *problo, const amrex_real *probhi) AMREX_ATTRIBUTE_WEAK
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Hwave_onegrid
Definition: ERF.H:841
amrex::Vector< std::unique_ptr< amrex::MultiFab > > thin_yforce
Definition: ERF.H:874
void setPlotVariables(const std::string &pp_plot_var_names, amrex::Vector< std::string > &plot_var_names)
Definition: ERF_Plotfile.cpp:22
amrex::Vector< amrex::BoxArray > ba2d
Definition: ERF.H:1076
amrex::Vector< amrex::Vector< amrex::MultiFab > > gradp
Definition: ERF.H:711
void ReadParameters()
Definition: ERF.cpp:1589
amrex::Vector< std::unique_ptr< amrex::MultiFab > > z_phys_nd_src
Definition: ERF.H:811
amrex::Vector< amrex::MultiFab > base_state_new
Definition: ERF.H:836
amrex::Vector< std::unique_ptr< amrex::MultiFab > > az
Definition: ERF.H:809
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::iMultiFab > > > lmask_lev
Definition: ERF.H:791
amrex::Vector< std::unique_ptr< amrex::MultiFab > > terrain_blanking
Definition: ERF.H:824
amrex::Vector< std::unique_ptr< amrex::MultiFab > > z_phys_nd_new
Definition: ERF.H:818
amrex::Vector< std::unique_ptr< amrex::MultiFab > > thin_zforce
Definition: ERF.H:875
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > sst_lev
Definition: ERF.H:789
amrex::Vector< std::unique_ptr< amrex::MultiFab > > thin_xforce
Definition: ERF.H:873
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > th_bc_data
Definition: ERF.H:666
amrex::Vector< std::string > plot_var_names_1
Definition: ERF.H:949
amrex::Vector< amrex::Real > t_old
Definition: ERF.H:700
amrex::Vector< std::unique_ptr< amrex::MultiFab > > z_t_rk
Definition: ERF.H:821
amrex::Vector< std::string > plot_var_names_2
Definition: ERF.H:950
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Lwave_onegrid
Definition: ERF.H:842
amrex::Vector< std::unique_ptr< amrex::MultiFab > > mf_C1H
Definition: ERF.H:1077
amrex::Vector< std::unique_ptr< ForestDrag > > m_forest_drag
Definition: ERF.H:1155
amrex::Vector< amrex::BoxArray > ba1d
Definition: ERF.H:1075
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > xvel_bc_data
Definition: ERF.H:663
int rad_datalog_int
Definition: ERF.H:773
amrex::Vector< std::unique_ptr< amrex::MultiFab > > detJ_cc_src
Definition: ERF.H:813
amrex::Vector< std::unique_ptr< amrex::MultiFab > > ay_src
Definition: ERF.H:815
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > yflux_imask
Definition: ERF.H:868
amrex::Vector< amrex::Vector< amrex::MultiFab * > > lsm_flux
Definition: ERF.H:763
void refinement_criteria_setup()
Definition: ERF_Tagging.cpp:165
amrex::Vector< std::unique_ptr< amrex::MultiFab > > sinPhi_m
Definition: ERF.H:654
amrex::Vector< std::unique_ptr< amrex::MultiFab > > ax_src
Definition: ERF.H:814
amrex::Vector< std::unique_ptr< amrex::MultiFab > > z_phys_cc_src
Definition: ERF.H:812
amrex::Vector< amrex::Vector< amrex::Real > > zlevels_stag
Definition: ERF.H:800
amrex::Vector< amrex::Vector< amrex::MultiFab * > > lsm_data
Definition: ERF.H:762
amrex::Vector< amrex::Vector< amrex::Real > > stretched_dz_h
Definition: ERF.H:832
amrex::Vector< std::unique_ptr< amrex::MultiFab > > az_src
Definition: ERF.H:816
amrex::Vector< std::unique_ptr< amrex::MultiFab > > mf_C2H
Definition: ERF.H:1078
static amrex::Real dt_max_initial
Definition: ERF.H:909
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Lwave
Definition: ERF.H:840
amrex::Vector< std::unique_ptr< amrex::MultiFab > > cosPhi_m
Definition: ERF.H:654
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > zflux_imask
Definition: ERF.H:869
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > zvel_bc_data
Definition: ERF.H:665
amrex::Vector< std::unique_ptr< amrex::MultiFab > > detJ_cc_new
Definition: ERF.H:819
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > yvel_bc_data
Definition: ERF.H:664
amrex::Vector< std::unique_ptr< amrex::MultiFab > > mf_MUB
Definition: ERF.H:1079
amrex::Vector< std::unique_ptr< amrex::MultiFab > > Hwave
Definition: ERF.H:839
amrex::Vector< std::unique_ptr< amrex::iMultiFab > > xflux_imask
Definition: ERF.H:867
amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab > > > tsk_lev
Definition: ERF.H:790
void initializeMicrophysics(const int &)
Definition: ERF.cpp:1391
void ReSize(const int &nlev)
Definition: ERF_LandSurface.H:24
Definition: ERF_EBIFTerrain.H:14
const char * buildInfoGetGitHash(int i)
amrex::Real dz0
Definition: ERF_DataStruct.H:759
amrex::Real grid_stretching_ratio
Definition: ERF_DataStruct.H:757
amrex::Real zsurf
Definition: ERF_DataStruct.H:758
Here is the call graph for this function:

◆ ErrorEst()

void ERF::ErrorEst ( int  lev,
amrex::TagBoxArray &  tags,
amrex::Real  time,
int  ngrow 
)
override

Function to tag cells for refinement – this overrides the pure virtual function in AmrCore

Parameters
[in]levclevel of refinement at which we tag cells (0 is coarsest level)
[out]tagsarray of tagged cells
[in]timecurrent time
16 {
17  const int clearval = TagBox::CLEAR;
18  const int tagval = TagBox::SET;
19 
20  //
21  // Make sure the ghost cells of the level we are tagging at are filled
22  // in case we take differences that require them
23  // NOTE: We are Fillpatching only the cell-centered variables here
24  //
25  MultiFab& S_new = vars_new[levc][Vars::cons];
26  MultiFab& U_new = vars_new[levc][Vars::xvel];
27  MultiFab& V_new = vars_new[levc][Vars::yvel];
28  MultiFab& W_new = vars_new[levc][Vars::zvel];
29  //
30  if (levc == 0) {
31  FillPatch(levc, time, {&S_new, &U_new, &V_new, &W_new});
32  } else {
33  FillPatch(levc, time, {&S_new, &U_new, &V_new, &W_new},
34  {&S_new, &rU_new[levc], &rV_new[levc], &rW_new[levc]},
35  base_state[levc], base_state[levc],
36  false, true);
37  }
38 
39  for (int j=0; j < ref_tags.size(); ++j)
40  {
41  //
42  // This mf must have ghost cells because we may take differences between adjacent values
43  //
44  std::unique_ptr<MultiFab> mf = std::make_unique<MultiFab>(grids[levc], dmap[levc], 1, 1);
45 
46  // This allows dynamic refinement based on the value of the density
47  if (ref_tags[j].Field() == "density")
48  {
49  MultiFab::Copy(*mf,vars_new[levc][Vars::cons],Rho_comp,0,1,1);
50 
51  // This allows dynamic refinement based on the value of qv
52  } else if ( ref_tags[j].Field() == "qv" ) {
53  MultiFab::Copy( *mf, vars_new[levc][Vars::cons], RhoQ1_comp, 0, 1, 1);
54  MultiFab::Divide(*mf, vars_new[levc][Vars::cons], Rho_comp, 0, 1, 1);
55 
56 
57  // This allows dynamic refinement based on the value of qc
58  } else if (ref_tags[j].Field() == "qc" ) {
59  MultiFab::Copy( *mf, vars_new[levc][Vars::cons], RhoQ2_comp, 0, 1, 1);
60  MultiFab::Divide(*mf, vars_new[levc][Vars::cons], Rho_comp, 0, 1, 1);
61 
62  // This allows dynamic refinement based on the value of the z-component of vorticity
63  } else if (ref_tags[j].Field() == "vorticity" ) {
64  Vector<MultiFab> mf_cc_vel(1);
65  mf_cc_vel[0].define(grids[levc], dmap[levc], AMREX_SPACEDIM, IntVect(1,1,1));
66  average_face_to_cellcenter(mf_cc_vel[0],0,Array<const MultiFab*,3>{&U_new, &V_new, &W_new});
67 
68  // Impose bc's at domain boundaries at all levels
69  FillBdyCCVels(mf_cc_vel,levc);
70 
71  mf->setVal(0.);
72 
73  for (MFIter mfi(*mf, TilingIfNotGPU()); mfi.isValid(); ++mfi)
74  {
75  const Box& bx = mfi.tilebox();
76  auto& dfab = (*mf)[mfi];
77  auto& sfab = mf_cc_vel[0][mfi];
78  derived::erf_dervortz(bx, dfab, 0, 1, sfab, Geom(levc), time, nullptr, levc);
79  }
80 
81  // This allows dynamic refinement based on the value of the scalar/theta
82  } else if ( (ref_tags[j].Field() == "scalar" ) ||
83  (ref_tags[j].Field() == "theta" ) )
84  {
85  for (MFIter mfi(*mf, TilingIfNotGPU()); mfi.isValid(); ++mfi)
86  {
87  const Box& bx = mfi.growntilebox();
88  auto& dfab = (*mf)[mfi];
89  auto& sfab = vars_new[levc][Vars::cons][mfi];
90  if (ref_tags[j].Field() == "scalar") {
91  derived::erf_derscalar(bx, dfab, 0, 1, sfab, Geom(levc), time, nullptr, levc);
92  } else if (ref_tags[j].Field() == "theta") {
93  derived::erf_dertheta(bx, dfab, 0, 1, sfab, Geom(levc), time, nullptr, levc);
94  }
95  } // mfi
96  // This allows dynamic refinement based on the value of the density
97  } else if ( (SolverChoice::terrain_type == TerrainType::ImmersedForcing) &&
98  (ref_tags[j].Field() == "terrain_blanking") )
99  {
100  MultiFab::Copy(*mf,*terrain_blanking[levc],0,0,1,1);
101  } else if (ref_tags[j].Field() == "velmag") {
102  mf->setVal(0.0);
103  ParmParse pp(pp_prefix);
104  Vector<std::string> refinement_indicators;
105  pp.queryarr("refinement_indicators",refinement_indicators,0,pp.countval("refinement_indicators"));
106  Real velmag_threshold = 1e10;
107  for (int i=0; i<refinement_indicators.size(); ++i)
108  {
109  if(refinement_indicators[i]=="hurricane_tracker"){
110  std::string ref_prefix = pp_prefix + "." + refinement_indicators[i];
111  ParmParse ppr(ref_prefix);
112  ppr.get("value_greater",velmag_threshold);
113  break;
114  }
115  }
116  HurricaneTracker(levc, U_new, V_new, W_new, velmag_threshold, false, &tags);
117 #ifdef ERF_USE_PARTICLES
118  } else {
119  //
120  // This allows dynamic refinement based on the number of particles per cell
121  //
122  // Note that we must count all the particles in levels both at and above the current,
123  // since otherwise, e.g., if the particles are all at level 1, counting particles at
124  // level 0 will not trigger refinement when regridding so level 1 will disappear,
125  // then come back at the next regridding
126  //
127  const auto& particles_namelist( particleData.getNames() );
128  mf->setVal(0.0);
129  for (ParticlesNamesVector::size_type i = 0; i < particles_namelist.size(); i++)
130  {
131  std::string tmp_string(particles_namelist[i]+"_count");
132  IntVect rr = IntVect::TheUnitVector();
133  if (ref_tags[j].Field() == tmp_string) {
134  for (int lev = levc; lev <= finest_level; lev++)
135  {
136  MultiFab temp_dat(grids[lev], dmap[lev], 1, 0); temp_dat.setVal(0);
137  particleData[particles_namelist[i]]->IncrementWithTotal(temp_dat, lev);
138 
139  MultiFab temp_dat_crse(grids[levc], dmap[levc], 1, 0); temp_dat_crse.setVal(0);
140 
141  if (lev == levc) {
142  MultiFab::Copy(*mf, temp_dat, 0, 0, 1, 0);
143  } else {
144  for (int d = 0; d < AMREX_SPACEDIM; d++) {
145  rr[d] *= ref_ratio[levc][d];
146  }
147  average_down(temp_dat, temp_dat_crse, 0, 1, rr);
148  MultiFab::Add(*mf, temp_dat_crse, 0, 0, 1, 0);
149  }
150  }
151  }
152  }
153 #endif
154  }
155 
156  ref_tags[j](tags,mf.get(),clearval,tagval,time,levc,geom[levc]);
157  } // loop over j
158 }
void FillBdyCCVels(amrex::Vector< amrex::MultiFab > &mf_cc_vel, int levc=0)
Definition: ERF_FillBdyCCVels.cpp:11
void HurricaneTracker(int lev, const amrex::MultiFab &U_new, const amrex::MultiFab &V_new, const amrex::MultiFab &W_new, const amrex::Real velmag_threshold, const bool is_track_io, amrex::TagBoxArray *tags=nullptr)
Definition: ERF_Tagging.cpp:391
static amrex::Vector< amrex::AMRErrorTag > ref_tags
Definition: ERF.H:1160
void erf_derscalar(const Box &bx, FArrayBox &derfab, int, int, const FArrayBox &datfab, const Geometry &, Real, const int *, const int)
Definition: ERF_Derive.cpp:165
void erf_dervortz(const amrex::Box &bx, amrex::FArrayBox &derfab, int dcomp, int ncomp, const amrex::FArrayBox &datfab, const amrex::Geometry &geomdata, amrex::Real, const int *, const int)
Definition: ERF_Derive.cpp:256
void erf_dertheta(const Box &bx, FArrayBox &derfab, int, int, const FArrayBox &datfab, const Geometry &, Real, const int *, const int)
Definition: ERF_Derive.cpp:144
real(c_double), private rr
Definition: ERF_module_mp_morr_two_moment.F90:223
Here is the call graph for this function:

◆ estTimeStep()

Real ERF::estTimeStep ( int  level,
long &  dt_fast_ratio 
) const

Function that calls estTimeStep for each level

Parameters
[in]levellevel of refinement (coarsest level i 0)
[out]dt_fast_ratioratio of slow to fast time step
55 {
56  BL_PROFILE("ERF::estTimeStep()");
57 
58  Real estdt_comp = 1.e20;
59  Real estdt_lowM = 1.e20;
60 
61  // We intentionally use the level 0 domain to compute whether to use this direction in the dt calculation
62  const int nxc = geom[0].Domain().length(0);
63  const int nyc = geom[0].Domain().length(1);
64 
65  auto const dxinv = geom[level].InvCellSizeArray();
66  auto const dzinv = 1.0 / dz_min[level];
67 
68  MultiFab const& S_new = vars_new[level][Vars::cons];
69 
70  MultiFab ccvel(grids[level],dmap[level],3,0);
71 
72  average_face_to_cellcenter(ccvel,0,
73  Array<const MultiFab*,3>{&vars_new[level][Vars::xvel],
74  &vars_new[level][Vars::yvel],
75  &vars_new[level][Vars::zvel]});
76 
77  int l_implicit_substepping = (solverChoice.substepping_type[level] == SubsteppingType::Implicit);
78  int l_anelastic = solverChoice.anelastic[level];
79 
80  Real estdt_comp_inv;
81 
82  if (solverChoice.terrain_type == TerrainType::EB)
83  {
84  const eb_& eb_lev = get_eb(level);
85  const MultiFab& detJ = (eb_lev.get_const_factory())->getVolFrac();
86 
87  estdt_comp_inv = ReduceMax(S_new, ccvel, detJ, 0,
88  [=] AMREX_GPU_HOST_DEVICE (Box const& b,
89  Array4<Real const> const& s,
90  Array4<Real const> const& u,
91  Array4<Real const> const& vf) -> Real
92  {
93  Real new_comp_dt = -1.e100;
94  amrex::Loop(b, [=,&new_comp_dt] (int i, int j, int k) noexcept
95  {
96  if (vf(i,j,k) > 0.)
97  {
98  const Real rho = s(i, j, k, Rho_comp);
99  const Real rhotheta = s(i, j, k, RhoTheta_comp);
100 
101  // NOTE: even when moisture is present,
102  // we only use the partial pressure of the dry air
103  // to compute the soundspeed
104  Real pressure = getPgivenRTh(rhotheta);
105  Real c = std::sqrt(Gamma * pressure / rho);
106 
107  // If we are doing implicit acoustic substepping, then the z-direction does not contribute
108  // to the computation of the time step
109  if (l_implicit_substepping) {
110  if ((nxc > 1) && (nyc==1)) {
111  // 2-D in x-z
112  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,0))+c)*dxinv[0]), new_comp_dt);
113  } else if ((nyc > 1) && (nxc==1)) {
114  // 2-D in y-z
115  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,1))+c)*dxinv[1]), new_comp_dt);
116  } else {
117  // 3-D or SCM
118  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,0))+c)*dxinv[0]),
119  ((amrex::Math::abs(u(i,j,k,1))+c)*dxinv[1]), new_comp_dt);
120  }
121 
122  // If we are not doing implicit acoustic substepping, then the z-direction contributes
123  // to the computation of the time step
124  } else {
125  if (nxc > 1 && nyc > 1) {
126  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,0))+c)*dxinv[0]),
127  ((amrex::Math::abs(u(i,j,k,1))+c)*dxinv[1]),
128  ((amrex::Math::abs(u(i,j,k,2))+c)*dzinv ), new_comp_dt);
129  } else if (nxc > 1) {
130  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,0))+c)*dxinv[0]),
131  ((amrex::Math::abs(u(i,j,k,2))+c)*dzinv ), new_comp_dt);
132  } else if (nyc > 1) {
133  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,1))+c)*dxinv[1]),
134  ((amrex::Math::abs(u(i,j,k,2))+c)*dzinv ), new_comp_dt);
135  } else {
136  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,2))+c)*dzinv ), new_comp_dt);
137  }
138 
139  }
140  }
141  });
142  return new_comp_dt;
143  });
144 
145  } else {
146  estdt_comp_inv = ReduceMax(S_new, ccvel, 0,
147  [=] AMREX_GPU_HOST_DEVICE (Box const& b,
148  Array4<Real const> const& s,
149  Array4<Real const> const& u) -> Real
150  {
151  Real new_comp_dt = -1.e100;
152  amrex::Loop(b, [=,&new_comp_dt] (int i, int j, int k) noexcept
153  {
154  {
155  const Real rho = s(i, j, k, Rho_comp);
156  const Real rhotheta = s(i, j, k, RhoTheta_comp);
157 
158  // NOTE: even when moisture is present,
159  // we only use the partial pressure of the dry air
160  // to compute the soundspeed
161  Real pressure = getPgivenRTh(rhotheta);
162  Real c = std::sqrt(Gamma * pressure / rho);
163 
164  // If we are doing implicit acoustic substepping, then the z-direction does not contribute
165  // to the computation of the time step
166  if (l_implicit_substepping) {
167  if ((nxc > 1) && (nyc==1)) {
168  // 2-D in x-z
169  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,0))+c)*dxinv[0]), new_comp_dt);
170  } else if ((nyc > 1) && (nxc==1)) {
171  // 2-D in y-z
172  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,1))+c)*dxinv[1]), new_comp_dt);
173  } else {
174  // 3-D or SCM
175  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,0))+c)*dxinv[0]),
176  ((amrex::Math::abs(u(i,j,k,1))+c)*dxinv[1]), new_comp_dt);
177  }
178 
179  // If we are not doing implicit acoustic substepping, then the z-direction contributes
180  // to the computation of the time step
181  } else {
182  if (nxc > 1 && nyc > 1) {
183  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,0))+c)*dxinv[0]),
184  ((amrex::Math::abs(u(i,j,k,1))+c)*dxinv[1]),
185  ((amrex::Math::abs(u(i,j,k,2))+c)*dzinv ), new_comp_dt);
186  } else if (nxc > 1) {
187  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,0))+c)*dxinv[0]),
188  ((amrex::Math::abs(u(i,j,k,2))+c)*dzinv ), new_comp_dt);
189  } else if (nyc > 1) {
190  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,1))+c)*dxinv[1]),
191  ((amrex::Math::abs(u(i,j,k,2))+c)*dzinv ), new_comp_dt);
192  } else {
193  new_comp_dt = amrex::max(((amrex::Math::abs(u(i,j,k,2))+c)*dzinv ), new_comp_dt);
194  }
195 
196  }
197  }
198  });
199  return new_comp_dt;
200  });
201  } // not EB
202 
203  ParallelDescriptor::ReduceRealMax(estdt_comp_inv);
204  estdt_comp = cfl / estdt_comp_inv;
205 
206  Real estdt_lowM_inv = ReduceMax(ccvel, 0,
207  [=] AMREX_GPU_HOST_DEVICE (Box const& b,
208  Array4<Real const> const& u) -> Real
209  {
210  Real new_lm_dt = -1.e100;
211  Loop(b, [=,&new_lm_dt] (int i, int j, int k) noexcept
212  {
213  new_lm_dt = amrex::max(((amrex::Math::abs(u(i,j,k,0)))*dxinv[0]),
214  ((amrex::Math::abs(u(i,j,k,1)))*dxinv[1]),
215  ((amrex::Math::abs(u(i,j,k,2)))*dxinv[2]), new_lm_dt);
216  });
217  return new_lm_dt;
218  });
219 
220  ParallelDescriptor::ReduceRealMax(estdt_lowM_inv);
221  if (estdt_lowM_inv > 0.0_rt)
222  estdt_lowM = cfl / estdt_lowM_inv;
223 
224  if (verbose) {
225  if (fixed_dt[level] <= 0.0) {
226  Print() << "Using cfl = " << cfl << " and dx/dy/dz_min = " <<
227  1.0/dxinv[0] << " " << 1.0/dxinv[1] << " " << dz_min[level] << std::endl;
228  Print() << "Compressible dt at level " << level << ": " << estdt_comp << std::endl;
229  if (estdt_lowM_inv > 0.0_rt) {
230  Print() << "Anelastic dt at level " << level << ": " << estdt_lowM << std::endl;
231  } else {
232  Print() << "Anelastic dt at level " << level << ": undefined " << std::endl;
233  }
234  }
235 
236  if (fixed_dt[level] > 0.0) {
237  Print() << "Based on cfl of 1.0 " << std::endl;
238  Print() << "Compressible dt at level " << level << " would be: " << estdt_comp/cfl << std::endl;
239  if (estdt_lowM_inv > 0.0_rt) {
240  Print() << "Anelastic dt at level " << level << " would be: " << estdt_lowM/cfl << std::endl;
241  } else {
242  Print() << "Anelastic dt at level " << level << " would be undefined " << std::endl;
243  }
244  Print() << "Fixed dt at level " << level << " is: " << fixed_dt[level] << std::endl;
245  if (fixed_fast_dt[level] > 0.0) {
246  Print() << "Fixed fast dt at level " << level << " is: " << fixed_fast_dt[level] << std::endl;
247  }
248  }
249  }
250 
251  if (solverChoice.substepping_type[level] != SubsteppingType::None) {
252  if (fixed_dt[level] > 0. && fixed_fast_dt[level] > 0.) {
253  dt_fast_ratio = static_cast<long>( fixed_dt[level] / fixed_fast_dt[level] );
254  } else if (fixed_dt[level] > 0.) {
255  // Max CFL_c = 1.0 for substeps by default, but we enforce a min of 4 substeps
256  auto dt_sub_max = (estdt_comp/cfl * sub_cfl);
257  dt_fast_ratio = static_cast<long>( std::max(fixed_dt[level]/dt_sub_max,4.) );
258  } else {
259  // auto dt_sub_max = (estdt_comp/cfl * sub_cfl);
260  // dt_fast_ratio = static_cast<long>( std::max(estdt_comp/dt_sub_max,4.) );
261  dt_fast_ratio = static_cast<long>( std::max(cfl / sub_cfl, 4.) );
262  }
263 
264  // Force time step ratio to be an even value
266  if ( dt_fast_ratio%2 != 0) dt_fast_ratio += 1;
267  } else {
268  if ( dt_fast_ratio%6 != 0) {
269  Print() << "mri_dt_ratio = " << dt_fast_ratio
270  << " not divisible by 6 for N/3 substeps in stage 1" << std::endl;
271  dt_fast_ratio = static_cast<int>(std::ceil(dt_fast_ratio/6.0) * 6);
272  }
273  }
274 
275  if (verbose) {
276  Print() << "smallest even ratio is: " << dt_fast_ratio << std::endl;
277  }
278  } // if substepping, either explicit or implicit
279 
280  if (fixed_dt[level] > 0.0) {
281  return fixed_dt[level];
282  } else {
283  // Anelastic (substepping is not allowed)
284  if (l_anelastic) {
285 
286  // Make sure that timestep is less than the dt_max
287  estdt_lowM = amrex::min(estdt_lowM, dt_max);
288 
289  // On the first timestep enforce dt_max_initial
290  if(istep[level] == 0){
291  return amrex::min(dt_max_initial, estdt_lowM);
292  }
293  else{
294  return estdt_lowM;
295  }
296 
297 
298  // Compressible with or without substepping
299  } else {
300  return estdt_comp;
301  }
302  }
303 }
constexpr amrex::Real Gamma
Definition: ERF_Constants.H:19
amrex::Vector< amrex::Real > dz_min
Definition: ERF.H:1168
eb_ const & get_eb(int lev) const noexcept
Definition: ERF.H:1442
amrex::Vector< amrex::Real > fixed_dt
Definition: ERF.H:913
static amrex::Real dt_max
Definition: ERF.H:910
amrex::Vector< amrex::Real > fixed_fast_dt
Definition: ERF.H:914
static amrex::Real cfl
Definition: ERF.H:905
static amrex::Real sub_cfl
Definition: ERF.H:906
Definition: ERF_EB.H:13
const std::unique_ptr< amrex::EBFArrayBoxFactory > & get_const_factory() const noexcept
Definition: ERF_EB.H:40
@ rho
Definition: ERF_Kessler.H:22
int force_stage1_single_substep
Definition: ERF_DataStruct.H:716
Here is the call graph for this function:

◆ Evolve()

void ERF::Evolve ( )
420 {
421  BL_PROFILE_VAR("ERF::Evolve()", evolve);
422 
423  Real cur_time = t_new[0];
424 
425  // Take one coarse timestep by calling timeStep -- which recursively calls timeStep
426  // for finer levels (with or without subcycling)
427  for (int step = istep[0]; step < max_step && cur_time < stop_time; ++step)
428  {
429  if (use_datetime) {
430  Print() << "\n" << getTimestamp(cur_time, datetime_format)
431  << " (" << cur_time-start_time << " s elapsed)"
432  << std::endl;
433  }
434  Print() << "\nCoarse STEP " << step+1 << " starts ..." << std::endl;
435 
436  ComputeDt(step);
437 
438  // Make sure we have read enough of the boundary plane data to make it through this timestep
439  if (input_bndry_planes)
440  {
441  m_r2d->read_input_files(cur_time,dt[0],m_bc_extdir_vals);
442  }
443 
444  int lev = 0;
445  int iteration = 1;
446  timeStep(lev, cur_time, iteration);
447 
448  cur_time += dt[0];
449 
450  Print() << "Coarse STEP " << step+1 << " ends." << " TIME = " << cur_time
451  << " DT = " << dt[0] << std::endl;
452 
453  post_timestep(step, cur_time, dt[0]);
454 
455  if (writeNow(cur_time, dt[0], step+1, m_plot_int_1, m_plot_per_1)) {
456  last_plot_file_step_1 = step+1;
458  }
459  if (writeNow(cur_time, dt[0], step+1, m_plot_int_2, m_plot_per_2)) {
460  last_plot_file_step_2 = step+1;
462  }
463  if (writeNow(cur_time, dt[0], step+1, m_subvol_int, m_subvol_per)) {
464  last_subvol = step+1;
465  WriteSubvolume();
466  }
467 
468  if (writeNow(cur_time, dt[0], step+1, m_check_int, m_check_per)) {
469  last_check_file_step = step+1;
471  }
472 
473 #ifdef AMREX_MEM_PROFILING
474  {
475  std::ostringstream ss;
476  ss << "[STEP " << step+1 << "]";
477  MemProfiler::report(ss.str());
478  }
479 #endif
480 
481  if (cur_time >= stop_time - 1.e-6*dt[0]) break;
482  }
483 
484  // Write plotfiles at final time
485  if ( (m_plot_int_1 > 0 || m_plot_per_1 > 0.) && istep[0] > last_plot_file_step_1 ) {
487  }
488  if ( (m_plot_int_2 > 0 || m_plot_per_2 > 0.) && istep[0] > last_plot_file_step_2) {
490  }
491  if ( (m_subvol_int > 0 || m_subvol_per > 0.) && istep[0] > last_subvol) {
492  WriteSubvolume();
493  }
494 
495  if ( (m_check_int > 0 || m_check_per > 0.) && istep[0] > last_check_file_step) {
497  }
498 
499  BL_PROFILE_VAR_STOP(evolve);
500 }
AMREX_FORCE_INLINE std::string getTimestamp(const amrex::Real epoch_real, const std::string &datetime_format)
Definition: ERF_EpochTime.H:35
int last_check_file_step
Definition: ERF.H:881
int max_step
Definition: ERF.H:894
int last_plot_file_step_2
Definition: ERF.H:878
static PlotFileType plotfile_type_1
Definition: ERF.H:1037
int m_subvol_int
Definition: ERF.H:932
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max > m_bc_extdir_vals
Definition: ERF.H:858
amrex::Real m_plot_per_1
Definition: ERF.H:933
void WriteSubvolume()
Definition: ERF_WriteSubvolume.cpp:9
int m_plot_int_1
Definition: ERF.H:930
void post_timestep(int nstep, amrex::Real time, amrex::Real dt_lev)
Definition: ERF.cpp:504
amrex::Real m_subvol_per
Definition: ERF.H:935
amrex::Real m_check_per
Definition: ERF.H:947
int m_check_int
Definition: ERF.H:946
int last_plot_file_step_1
Definition: ERF.H:877
static int input_bndry_planes
Definition: ERF.H:1096
int last_subvol
Definition: ERF.H:879
const std::string datetime_format
Definition: ERF.H:899
bool use_datetime
Definition: ERF.H:898
static PlotFileType plotfile_type_2
Definition: ERF.H:1038
void WritePlotFile(int which, PlotFileType plotfile_type, amrex::Vector< std::string > plot_var_names)
Definition: ERF_Plotfile.cpp:261
amrex::Real start_time
Definition: ERF.H:895
void ComputeDt(int step=-1)
Definition: ERF_ComputeTimestep.cpp:11
void WriteCheckpointFile() const
Definition: ERF_Checkpoint.cpp:26
int m_plot_int_2
Definition: ERF.H:931
std::unique_ptr< ReadBndryPlanes > m_r2d
Definition: ERF.H:1153
bool writeNow(const amrex::Real cur_time, const amrex::Real dt, const int nstep, const int plot_int, const amrex::Real plot_per)
Definition: ERF.cpp:2193
void timeStep(int lev, amrex::Real time, int iteration)
Definition: ERF_TimeStep.cpp:17
amrex::Real m_plot_per_2
Definition: ERF.H:934

Referenced by main().

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

◆ fill_from_bndryregs()

void ERF::fill_from_bndryregs ( const amrex::Vector< amrex::MultiFab * > &  mfs,
amrex::Real  time 
)
14 {
15  //
16  // We now assume that if we read in on one face, we read in on all faces
17  //
18  AMREX_ALWAYS_ASSERT(m_r2d);
19 
20  int lev = 0;
21  const Box& domain = geom[lev].Domain();
22 
23  const auto& dom_lo = lbound(domain);
24  const auto& dom_hi = ubound(domain);
25 
26  Vector<std::unique_ptr<PlaneVector>>& bndry_data = m_r2d->interp_in_time(time);
27 
28  const BCRec* bc_ptr = domain_bcs_type_d.data();
29 
30  // xlo: ori = 0
31  // ylo: ori = 1
32  // zlo: ori = 2
33  // xhi: ori = 3
34  // yhi: ori = 4
35  // zhi: ori = 5
36  const auto& bdatxlo = (*bndry_data[0])[lev].const_array();
37  const auto& bdatylo = (*bndry_data[1])[lev].const_array();
38  const auto& bdatxhi = (*bndry_data[3])[lev].const_array();
39  const auto& bdatyhi = (*bndry_data[4])[lev].const_array();
40 
41  int bccomp;
42 
43  for (int var_idx = 0; var_idx < Vars::NumTypes; ++var_idx)
44  {
45  MultiFab& mf = *mfs[var_idx];
46  const int icomp = 0;
47  const int ncomp = mf.nComp();
48 
49  if (var_idx == Vars::xvel) {
50  bccomp = BCVars::xvel_bc;
51  } else if (var_idx == Vars::yvel) {
52  bccomp = BCVars::yvel_bc;
53  } else if (var_idx == Vars::zvel) {
54  bccomp = BCVars::zvel_bc;
55  } else if (var_idx == Vars::cons) {
56  bccomp = BCVars::cons_bc;
57  }
58 
59 #ifdef AMREX_USE_OMP
60 #pragma omp parallel if (Gpu::notInLaunchRegion())
61 #endif
62  for (MFIter mfi(mf); mfi.isValid(); ++mfi)
63  {
64  const Array4<Real>& dest_arr = mf.array(mfi);
65  Box bx = mfi.growntilebox();
66 
67  // x-faces
68  {
69  Box bx_xlo(bx); bx_xlo.setBig(0,dom_lo.x-1);
70  if (var_idx == Vars::xvel) bx_xlo.setBig(0,dom_lo.x);
71 
72  Box bx_xhi(bx); bx_xhi.setSmall(0,dom_hi.x+1);
73  if (var_idx == Vars::xvel) bx_xhi.setSmall(0,dom_hi.x);
74 
75  ParallelFor(
76  bx_xlo, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
77  int bc_comp = (icomp+n >= RhoScalar_comp && icomp+n < RhoScalar_comp+NSCALARS) ?
78  BCVars::RhoScalar_bc_comp : icomp+n;
79  if (bc_ptr[bc_comp].lo(0) == ERFBCType::ext_dir_ingested) {
80  int jb = std::min(std::max(j,dom_lo.y),dom_hi.y);
81  int kb = std::min(std::max(k,dom_lo.z),dom_hi.z);
82  dest_arr(i,j,k,icomp+n) = bdatxlo(dom_lo.x-1,jb,kb,bccomp+n);
83  }
84  },
85  bx_xhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
86  int bc_comp = (icomp+n >= RhoScalar_comp && icomp+n < RhoScalar_comp+NSCALARS) ?
87  BCVars::RhoScalar_bc_comp : icomp+n;
88  if (bc_ptr[bc_comp].hi(0) == ERFBCType::ext_dir_ingested) {
89  int jb = std::min(std::max(j,dom_lo.y),dom_hi.y);
90  int kb = std::min(std::max(k,dom_lo.z),dom_hi.z);
91  dest_arr(i,j,k,icomp+n) = bdatxhi(dom_hi.x+1,jb,kb,bccomp+n);
92  }
93  }
94  );
95  } // x-faces
96 
97  // y-faces
98  {
99  Box bx_ylo(bx); bx_ylo.setBig (1,dom_lo.y-1);
100  if (var_idx == Vars::yvel) bx_ylo.setBig(1,dom_lo.y);
101 
102  Box bx_yhi(bx); bx_yhi.setSmall(1,dom_hi.y+1);
103  if (var_idx == Vars::yvel) bx_yhi.setSmall(1,dom_hi.y);
104 
105  ParallelFor(
106  bx_ylo, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
107  int bc_comp = (icomp+n >= RhoScalar_comp && icomp+n < RhoScalar_comp+NSCALARS) ?
108  BCVars::RhoScalar_bc_comp : icomp+n;
109  if (bc_ptr[bc_comp].lo(1) == ERFBCType::ext_dir_ingested) {
110  int ib = std::min(std::max(i,dom_lo.x),dom_hi.x);
111  int kb = std::min(std::max(k,dom_lo.z),dom_hi.z);
112  dest_arr(i,j,k,icomp+n) = bdatylo(ib,dom_lo.y-1,kb,bccomp+n);
113  }
114  },
115  bx_yhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
116  int bc_comp = (icomp+n >= RhoScalar_comp && icomp+n < RhoScalar_comp+NSCALARS) ?
117  BCVars::RhoScalar_bc_comp : icomp+n;
118  if (bc_ptr[bc_comp].hi(1) == ERFBCType::ext_dir_ingested) {
119  int ib = std::min(std::max(i,dom_lo.x),dom_hi.x);
120  int kb = std::min(std::max(k,dom_lo.z),dom_hi.z);
121  dest_arr(i,j,k,icomp+n) = bdatyhi(ib,dom_hi.y+1,kb,bccomp+n);
122  }
123  }
124  );
125  } // y-faces
126  } // mf
127  } // var_idx
128 }
const auto & dom_hi
Definition: ERF_DiffSetup.H:10
const auto & dom_lo
Definition: ERF_DiffSetup.H:9
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:40
#define NSCALARS
Definition: ERF_IndexDefines.H:16
amrex::Gpu::DeviceVector< amrex::BCRec > domain_bcs_type_d
Definition: ERF.H:852
@ RhoScalar_bc_comp
Definition: ERF_IndexDefines.H:80
@ ext_dir_ingested
Definition: ERF_IndexDefines.H:212

◆ fill_rhs()

void ERF::fill_rhs ( amrex::MultiFab &  rhs_mf,
const amrex::MultiFab &  state_mf,
amrex::Real  time,
const amrex::Geometry &  geom 
)
private

◆ FillBdyCCVels()

void ERF::FillBdyCCVels ( amrex::Vector< amrex::MultiFab > &  mf_cc_vel,
int  levc = 0 
)
12 {
13  // Impose bc's at domain boundaries
14  for (int ilev(0); ilev < mf_cc_vel.size(); ++ilev)
15  {
16  int lev = ilev + levc;
17  Box domain(Geom(lev).Domain());
18 
19  int ihi = domain.bigEnd(0);
20  int jhi = domain.bigEnd(1);
21  int khi = domain.bigEnd(2);
22 
23  // Impose periodicity first
24  mf_cc_vel[lev].FillBoundary(geom[lev].periodicity());
25 
26  int jper = (Geom(lev).isPeriodic(1));
27  int kper = (Geom(lev).isPeriodic(2));
28 
29  for (MFIter mfi(mf_cc_vel[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi)
30  {
31  const Box& bx = mfi.tilebox();
32  const Array4<Real>& vel_arr = mf_cc_vel[lev].array(mfi);
33 
34  if (!Geom(lev).isPeriodic(0)) {
35  // Low-x side
36  if (bx.smallEnd(0) <= domain.smallEnd(0)) {
37  Real multn = ( (phys_bc_type[0] == ERF_BC::slip_wall ) ||
39  (phys_bc_type[0] == ERF_BC::symmetry ) ) ? -1. : 1.;
40  Real multt = (phys_bc_type[0] == ERF_BC::no_slip_wall) ? -1. : 1.;
41  Box gbx(bx); gbx.grow(1,jper); gbx.grow(2,kper);
42  ParallelFor(makeSlab(gbx,0,0), [=] AMREX_GPU_DEVICE(int , int j, int k) noexcept
43  {
44  vel_arr(-1,j,k,0) = multn*vel_arr(0,j,k,0); // u
45  vel_arr(-1,j,k,1) = multt*vel_arr(0,j,k,1); // v
46  vel_arr(-1,j,k,2) = multt*vel_arr(0,j,k,2); // w
47  });
48  }
49 
50  // High-x side
51  if (bx.bigEnd(0) >= domain.bigEnd(0)) {
52  Real multn = ( (phys_bc_type[3] == ERF_BC::slip_wall ) ||
54  (phys_bc_type[3] == ERF_BC::symmetry ) ) ? -1. : 1.;
55  Real multt = (phys_bc_type[3] == ERF_BC::no_slip_wall) ? -1. : 1.;
56  Box gbx(bx); gbx.grow(1,jper); gbx.grow(2,kper);
57  ParallelFor(makeSlab(gbx,0,0), [=] AMREX_GPU_DEVICE(int , int j, int k) noexcept
58  {
59  vel_arr(ihi+1,j,k,0) = multn*vel_arr(ihi,j,k,0); // u
60  vel_arr(ihi+1,j,k,1) = multt*vel_arr(ihi,j,k,1); // v
61  vel_arr(ihi+1,j,k,2) = multt*vel_arr(ihi,j,k,2); // w
62  });
63  }
64  } // !periodic
65 
66  if (!Geom(lev).isPeriodic(1)) {
67  // Low-y side
68  if (bx.smallEnd(1) <= domain.smallEnd(1)) {
69  Real multn = ( (phys_bc_type[1] == ERF_BC::slip_wall ) ||
71  (phys_bc_type[1] == ERF_BC::symmetry ) ) ? -1. : 1.;
72  Real multt = (phys_bc_type[1] == ERF_BC::no_slip_wall) ? -1. : 1.;
73  Box gbx(bx); gbx.grow(0,1); gbx.grow(2,kper);
74  ParallelFor(makeSlab(gbx,1,0), [=] AMREX_GPU_DEVICE(int i, int , int k) noexcept
75  {
76  vel_arr(i,-1,k,0) = multt*vel_arr(i,0,k,0); // u
77  vel_arr(i,-1,k,1) = multn*vel_arr(i,0,k,1); // u
78  vel_arr(i,-1,k,2) = multt*vel_arr(i,0,k,2); // w
79  });
80  }
81 
82  // High-y side
83  if (bx.bigEnd(1) >= domain.bigEnd(1)) {
84  Real multn = ( (phys_bc_type[4] == ERF_BC::slip_wall ) ||
86  (phys_bc_type[4] == ERF_BC::symmetry ) ) ? -1. : 1.;
87  Real multt = (phys_bc_type[4] == ERF_BC::no_slip_wall) ? -1. : 1.;
88  Box gbx(bx); gbx.grow(0,1); gbx.grow(2,kper);
89  ParallelFor(makeSlab(gbx,1,0), [=] AMREX_GPU_DEVICE(int i, int , int k) noexcept
90  {
91  vel_arr(i,jhi+1,k,0) = multt*vel_arr(i,jhi,k,0); // u
92  vel_arr(i,jhi+1,k,1) = multn*vel_arr(i,jhi,k,1); // v
93  vel_arr(i,jhi+1,k,2) = multt*vel_arr(i,jhi,k,2); // w
94  });
95  }
96  } // !periodic
97 
98  if (!Geom(lev).isPeriodic(2)) {
99  // Low-z side
100  if (bx.smallEnd(2) <= domain.smallEnd(2)) {
101  Real multn = ( (phys_bc_type[2] == ERF_BC::slip_wall ) ||
103  (phys_bc_type[2] == ERF_BC::symmetry ) ) ? -1. : 1.;
104  Real multt = (phys_bc_type[2] == ERF_BC::no_slip_wall) ? -1. : 1.;
105  Box gbx(bx); gbx.grow(0,1); gbx.grow(1,1);
106  ParallelFor(makeSlab(gbx,2,0), [=] AMREX_GPU_DEVICE(int i, int j, int) noexcept
107  {
108  vel_arr(i,j,-1,0) = multt*vel_arr(i,j,0,0); // u
109  vel_arr(i,j,-1,1) = multt*vel_arr(i,j,0,1); // v
110  vel_arr(i,j,-1,2) = multn*vel_arr(i,j,0,2); // w
111  });
112  }
113 
114  // High-z side
115  if (bx.bigEnd(2) >= domain.bigEnd(2)) {
116  Real multn = ( (phys_bc_type[5] == ERF_BC::slip_wall ) ||
118  (phys_bc_type[5] == ERF_BC::symmetry ) ) ? -1. : 1.;
119  Real multt = (phys_bc_type[5] == ERF_BC::no_slip_wall) ? -1. : 1.;
120  Box gbx(bx); gbx.grow(0,1); gbx.grow(1,1);
121  ParallelFor(makeSlab(gbx,2,0), [=] AMREX_GPU_DEVICE(int i, int j, int) noexcept
122  {
123  vel_arr(i,j,khi+1,0) = multt*vel_arr(i,j,khi,0); // u
124  vel_arr(i,j,khi+1,1) = multt*vel_arr(i,j,khi,1); // v
125  vel_arr(i,j,khi+1,2) = multn*vel_arr(i,j,khi,2); // w
126  });
127  }
128  } // !periodic
129  } // MFIter
130 
131  // Impose periodicity again
132  mf_cc_vel[lev].FillBoundary(geom[lev].periodicity());
133  } // lev
134 }
@ no_slip_wall

◆ FillCoarsePatch()

void ERF::FillCoarsePatch ( int  lev,
amrex::Real  time 
)
private
22 {
23  BL_PROFILE_VAR("FillCoarsePatch()",FillCoarsePatch);
24  AMREX_ASSERT(lev > 0);
25 
26  //
27  //****************************************************************************************************************
28  // First fill velocities and density at the COARSE level so we can convert velocity to momenta at the COARSE level
29  //****************************************************************************************************************
30  //
31  bool cons_only = false;
32  if (lev == 1) {
33  FillPatch(lev-1, time, {&vars_new[lev-1][Vars::cons], &vars_new[lev-1][Vars::xvel],
34  &vars_new[lev-1][Vars::yvel], &vars_new[lev-1][Vars::zvel]},
35  cons_only);
36  } else {
37  FillPatch(lev-1, time, {&vars_new[lev-1][Vars::cons], &vars_new[lev-1][Vars::xvel],
38  &vars_new[lev-1][Vars::yvel], &vars_new[lev-1][Vars::zvel]},
39  {&vars_new[lev-1][Vars::cons],
40  &rU_new[lev-1], &rV_new[lev-1], &rW_new[lev-1]},
41  base_state[lev-1], base_state[lev-1],
42  false, cons_only);
43  }
44 
45  //
46  // ************************************************
47  // Convert velocity to momentum at the COARSE level
48  // ************************************************
49  //
50  VelocityToMomentum(vars_new[lev-1][Vars::xvel], IntVect{0},
51  vars_new[lev-1][Vars::yvel], IntVect{0},
52  vars_new[lev-1][Vars::zvel], IntVect{0},
53  vars_new[lev-1][Vars::cons],
54  rU_new[lev-1],
55  rV_new[lev-1],
56  rW_new[lev-1],
57  Geom(lev).Domain(),
59  //
60  // *****************************************************************
61  // Interpolate all cell-centered variables from coarse to fine level
62  // *****************************************************************
63  //
64  Interpolater* mapper_c = &cell_cons_interp;
65  Interpolater* mapper_f = &face_cons_linear_interp;
66 
67  //
68  //************************************************************************************************
69  // Interpolate cell-centered data from coarse to fine level
70  // with InterpFromCoarseLevel which ASSUMES that all ghost cells have already been filled
71  // ************************************************************************************************
72  IntVect ngvect_cons = vars_new[lev][Vars::cons].nGrowVect();
73  int ncomp_cons = vars_new[lev][Vars::cons].nComp();
74 
75  InterpFromCoarseLevel(vars_new[lev ][Vars::cons], ngvect_cons, IntVect(0,0,0),
76  vars_new[lev-1][Vars::cons], 0, 0, ncomp_cons,
77  geom[lev-1], geom[lev],
78  refRatio(lev-1), mapper_c, domain_bcs_type, BCVars::cons_bc);
79 
80  // ***************************************************************************
81  // Physical bc's for cell centered variables at domain boundary
82  // ***************************************************************************
84  0,ncomp_cons,ngvect_cons,time,BCVars::cons_bc,true);
85 
86  //
87  //************************************************************************************************
88  // Interpolate x-momentum from coarse to fine level
89  // with InterpFromCoarseLevel which ASSUMES that all ghost cells have already been filled
90  // ************************************************************************************************
91  //
92  InterpFromCoarseLevel(rU_new[lev], IntVect{0}, IntVect{0}, rU_new[lev-1], 0, 0, 1,
93  geom[lev-1], geom[lev],
94  refRatio(lev-1), mapper_f, domain_bcs_type, BCVars::xvel_bc);
95 
96  //
97  //************************************************************************************************
98  // Interpolate y-momentum from coarse to fine level
99  // with InterpFromCoarseLevel which ASSUMES that all ghost cells have already been filled
100  // ************************************************************************************************
101  //
102  InterpFromCoarseLevel(rV_new[lev], IntVect{0}, IntVect{0}, rV_new[lev-1], 0, 0, 1,
103  geom[lev-1], geom[lev],
104  refRatio(lev-1), mapper_f, domain_bcs_type, BCVars::yvel_bc);
105 
106  //************************************************************************************************
107  // Interpolate z-momentum from coarse to fine level
108  // with InterpFromCoarseLevel which ASSUMES that all ghost cells have already been filled
109  // ************************************************************************************************
110  InterpFromCoarseLevel(rW_new[lev], IntVect{0}, IntVect{0}, rW_new[lev-1], 0, 0, 1,
111  geom[lev-1], geom[lev],
112  refRatio(lev-1), mapper_f, domain_bcs_type, BCVars::zvel_bc);
113  //
114  // *********************************************************
115  // After interpolation of momentum, convert back to velocity
116  // *********************************************************
117  //
118  for (int which_lev = lev-1; which_lev <= lev; which_lev++)
119  {
121  vars_new[which_lev][Vars::yvel],
122  vars_new[which_lev][Vars::zvel],
123  vars_new[which_lev][Vars::cons],
124  rU_new[which_lev],
125  rV_new[which_lev],
126  rW_new[which_lev],
127  Geom(lev).Domain(),
129  }
130 
131  // ***************************************************************************
132  // Physical bc's at domain boundary
133  // ***************************************************************************
134  IntVect ngvect_vels = vars_new[lev][Vars::xvel].nGrowVect();
135 
137  ngvect_vels,time,BCVars::xvel_bc,true);
139  ngvect_vels,time,BCVars::yvel_bc,true);
141  ngvect_vels,time,BCVars::zvel_bc,true);
142 
143  // ***************************************************************************
144  // Since lev > 0 here we don't worry about m_r2d or wrfbdy data
145  // ***************************************************************************
146 }
void FillCoarsePatch(int lev, amrex::Real time)
Definition: ERF_FillCoarsePatch.cpp:21
Here is the call graph for this function:

◆ FillIntermediatePatch()

void ERF::FillIntermediatePatch ( int  lev,
amrex::Real  time,
const amrex::Vector< amrex::MultiFab * > &  mfs_vel,
const amrex::Vector< amrex::MultiFab * > &  mfs_mom,
int  ng_cons,
int  ng_vel,
bool  cons_only,
int  icomp_cons,
int  ncomp_cons 
)
private
33 {
34  BL_PROFILE_VAR("FillIntermediatePatch()",FillIntermediatePatch);
35  Interpolater* mapper;
36 
37  PhysBCFunctNoOp null_bc;
38 
39  //
40  // ***************************************************************************
41  // The first thing we do is interpolate the momenta on the "valid" faces of
42  // the fine grids (where the interface is coarse/fine not fine/fine) -- this
43  // will not be over-written by interpolation below because the FillPatch
44  // operators see these as valid faces. But we must have these interpolated
45  // values in the fine data before we call FillPatchTwoLevels.
46  //
47  // Also -- note that we might be filling values by interpolation at physical boundaries
48  // here but that's ok because we will overwrite those values when we impose
49  // the physical bc's below
50  // ***************************************************************************
51  if (lev>0) {
52  if (cf_set_width > 0) {
53  // We note that mfs_vel[Vars::cons] and mfs_mom[Vars::cons] are in fact the same pointer
54  FPr_c[lev-1].FillSet(*mfs_vel[Vars::cons], time, null_bc, domain_bcs_type);
55  }
56  if ( !cons_only && (cf_set_width >= 0) ) {
57  FPr_u[lev-1].FillSet(*mfs_mom[IntVars::xmom], time, null_bc, domain_bcs_type);
58  FPr_v[lev-1].FillSet(*mfs_mom[IntVars::ymom], time, null_bc, domain_bcs_type);
59  FPr_w[lev-1].FillSet(*mfs_mom[IntVars::zmom], time, null_bc, domain_bcs_type);
60  }
61  }
62 
63  // amrex::Print() << "LEVEL " << lev << " CONS ONLY " << cons_only <<
64  // " ICOMP NCOMP " << icomp_cons << " " << ncomp_cons << " NGHOST " << ng_cons << std::endl;
65 
66  if (!cons_only) {
67  AMREX_ALWAYS_ASSERT(mfs_mom.size() == IntVars::NumTypes);
68  AMREX_ALWAYS_ASSERT(mfs_vel.size() == Vars::NumTypes);
69  }
70 
71  // Enforce no penetration for thin immersed body
72  if (!cons_only) {
73  // Enforce no penetration for thin immersed body
74  if (xflux_imask[lev]) {
75  ApplyMask(*mfs_mom[IntVars::xmom], *xflux_imask[lev]);
76  }
77  if (yflux_imask[lev]) {
78  ApplyMask(*mfs_mom[IntVars::ymom], *yflux_imask[lev]);
79  }
80  if (zflux_imask[lev]) {
81  ApplyMask(*mfs_mom[IntVars::zmom], *zflux_imask[lev]);
82  }
83  }
84 
85  //
86  // We now start working on conserved quantities + VELOCITY
87  //
88  if (lev == 0)
89  {
90  // We don't do anything here because we will call the physbcs routines below,
91  // which calls FillBoundary and fills other domain boundary conditions
92  // Physical boundaries will be filled below
93 
94  if (!cons_only)
95  {
96  // ***************************************************************************
97  // We always come in to this call with updated momenta but we need to create updated velocity
98  // in order to impose the rest of the bc's
99  // ***************************************************************************
100  // This only fills VALID region of velocity
101  MomentumToVelocity(*mfs_vel[Vars::xvel], *mfs_vel[Vars::yvel], *mfs_vel[Vars::zvel],
102  *mfs_vel[Vars::cons],
103  *mfs_mom[IntVars::xmom], *mfs_mom[IntVars::ymom], *mfs_mom[IntVars::zmom],
104  Geom(lev).Domain(), domain_bcs_type);
105  }
106  }
107  else
108  {
109  //
110  // We must fill a temporary then copy it back so we don't double add/subtract
111  //
112  MultiFab mf(mfs_vel[Vars::cons]->boxArray(),mfs_vel[Vars::cons]->DistributionMap(),
113  mfs_vel[Vars::cons]->nComp() ,mfs_vel[Vars::cons]->nGrowVect());
114  //
115  // Set all components to 1.789e19, then copy just the density from *mfs_vel[Vars::cons]
116  //
117  mf.setVal(1.789e19);
118  MultiFab::Copy(mf,*mfs_vel[Vars::cons],Rho_comp,Rho_comp,1,mf.nGrowVect());
119 
120  Vector<MultiFab*> fmf = {mfs_vel[Vars::cons],mfs_vel[Vars::cons]};
121  Vector<MultiFab*> cmf = {&vars_old[lev-1][Vars::cons], &vars_new[lev-1][Vars::cons]};
122  Vector<Real> ctime = {t_old[lev-1], t_new[lev-1]};
123  Vector<Real> ftime = {time,time};
124 
125  // Impose physical bc's on fine data (note time and 0 are not used)
126  bool do_fb = true; bool do_terrain_adjustment = false;
127  (*physbcs_cons[lev])(*mfs_vel[Vars::cons],*mfs_vel[Vars::xvel],*mfs_vel[Vars::yvel],
128  icomp_cons,ncomp_cons,IntVect{ng_cons},time,BCVars::cons_bc,
129  do_fb, do_terrain_adjustment);
130 
131  if ( (icomp_cons+ncomp_cons > 1) && (interpolation_type == StateInterpType::Perturbational) )
132  {
133  // Divide (rho theta) by rho to get theta
134  MultiFab::Divide(*mfs_vel[Vars::cons],*mfs_vel[Vars::cons],Rho_comp,RhoTheta_comp,1,IntVect{0});
135 
136  // Subtract theta_0 from theta
137  MultiFab::Subtract(*mfs_vel[Vars::cons],base_state[lev],BaseState::th0_comp,RhoTheta_comp,1,IntVect{0});
138 
139  if (!amrex::almostEqual(time,ctime[1])) {
140  MultiFab::Divide(vars_old[lev-1][Vars::cons], vars_old[lev-1][Vars::cons],
141  Rho_comp,RhoTheta_comp,1,vars_old[lev-1][Vars::cons].nGrowVect());
142  MultiFab::Subtract(vars_old[lev-1][Vars::cons], base_state[lev-1],
143  BaseState::th0_comp,RhoTheta_comp,1,vars_old[lev-1][Vars::cons].nGrowVect());
144  }
145  if (!amrex::almostEqual(time,ctime[0])) {
146  MultiFab::Divide(vars_new[lev-1][Vars::cons], vars_new[lev-1][Vars::cons],
147  Rho_comp,RhoTheta_comp,1,vars_new[lev-1][Vars::cons].nGrowVect());
148  MultiFab::Subtract(vars_new[lev-1][Vars::cons], base_state[lev-1],
149  BaseState::th0_comp,RhoTheta_comp,1,vars_new[lev-1][Vars::cons].nGrowVect());
150  }
151  }
152 
153  // Subtract rho_0 from rho before we interpolate -- note we only subtract
154  // on valid region of mf since the ghost cells will be filled below
155  if (icomp_cons == 0 && (interpolation_type == StateInterpType::Perturbational))
156  {
157  MultiFab::Subtract(*mfs_vel[Vars::cons],base_state[lev],BaseState::r0_comp,Rho_comp,1,IntVect{0});
158 
159  if (!amrex::almostEqual(time,ctime[1])) {
160  MultiFab::Subtract(vars_old[lev-1][Vars::cons], base_state[lev-1],
161  BaseState::r0_comp,Rho_comp,1,vars_old[lev-1][Vars::cons].nGrowVect());
162  }
163  if (!amrex::almostEqual(time,ctime[0])) {
164  MultiFab::Subtract(vars_new[lev-1][Vars::cons], base_state[lev-1],
165  BaseState::r0_comp,Rho_comp,1,vars_new[lev-1][Vars::cons].nGrowVect());
166  }
167  }
168 
169  // Call FillPatchTwoLevels which ASSUMES that all ghost cells have already been filled
170  mapper = &cell_cons_interp;
171  FillPatchTwoLevels(mf, IntVect{ng_cons}, IntVect(0,0,0),
172  time, cmf, ctime, fmf, ftime,
173  icomp_cons, icomp_cons, ncomp_cons, geom[lev-1], geom[lev],
174  refRatio(lev-1), mapper, domain_bcs_type,
175  icomp_cons);
176 
177  if (icomp_cons == 0 && (interpolation_type == StateInterpType::Perturbational))
178  {
179  // Restore the coarse values to what they were
180  if (!amrex::almostEqual(time,ctime[1])) {
181  MultiFab::Add(vars_old[lev-1][Vars::cons], base_state[lev-1],
182  BaseState::r0_comp,Rho_comp,1,vars_old[lev-1][Vars::cons].nGrowVect());
183  }
184  if (!amrex::almostEqual(time,ctime[0])) {
185  MultiFab::Add(vars_new[lev-1][Vars::cons], base_state[lev-1],
186  BaseState::r0_comp,Rho_comp,1,vars_new[lev-1][Vars::cons].nGrowVect());
187  }
188 
189  // Set values in the cells outside the domain boundary so that we can do the Add
190  // without worrying about uninitialized values outside the domain -- these
191  // will be filled in the physbcs call
192  mf.setDomainBndry(1.234e20,Rho_comp,1,geom[lev]);
193 
194  // Add rho_0 back to rho after we interpolate -- on all the valid + ghost region
195  MultiFab::Add(mf, base_state[lev],BaseState::r0_comp,Rho_comp,1,IntVect{ng_cons});
196  }
197 
198  if ( (icomp_cons+ncomp_cons > 1) && (interpolation_type == StateInterpType::Perturbational) )
199  {
200  // Add theta_0 to theta
201  if (!amrex::almostEqual(time,ctime[1])) {
202  MultiFab::Add(vars_old[lev-1][Vars::cons], base_state[lev-1],
203  BaseState::th0_comp,RhoTheta_comp,1,vars_old[lev-1][Vars::cons].nGrowVect());
204  MultiFab::Multiply(vars_old[lev-1][Vars::cons], vars_old[lev-1][Vars::cons],
205  Rho_comp,RhoTheta_comp,1,vars_old[lev-1][Vars::cons].nGrowVect());
206  }
207  if (!amrex::almostEqual(time,ctime[0])) {
208  MultiFab::Add(vars_new[lev-1][Vars::cons], base_state[lev-1],
209  BaseState::th0_comp,RhoTheta_comp,1,vars_new[lev-1][Vars::cons].nGrowVect());
210  MultiFab::Multiply(vars_new[lev-1][Vars::cons], vars_new[lev-1][Vars::cons],
211  Rho_comp,RhoTheta_comp,1,vars_new[lev-1][Vars::cons].nGrowVect());
212  }
213 
214  // Multiply theta by rho to get (rho theta)
215  MultiFab::Multiply(*mfs_vel[Vars::cons],*mfs_vel[Vars::cons],Rho_comp,RhoTheta_comp,1,IntVect{0});
216 
217  // Add theta_0 to theta
218  MultiFab::Add(*mfs_vel[Vars::cons],base_state[lev],BaseState::th0_comp,RhoTheta_comp,1,IntVect{0});
219 
220  // Add theta_0 back to theta
221  MultiFab::Add(mf,base_state[lev],BaseState::th0_comp,RhoTheta_comp,1,IntVect{ng_cons});
222 
223  // Multiply (theta) by rho to get (rho theta)
224  MultiFab::Multiply(mf,mf,Rho_comp,RhoTheta_comp,1,IntVect{ng_cons});
225  }
226 
227  // Make sure to only copy back the components we worked on
228  MultiFab::Copy(*mfs_vel[Vars::cons],mf,icomp_cons,icomp_cons,ncomp_cons,IntVect{ng_cons});
229 
230  // *****************************************************************************************
231 
232  if (!cons_only)
233  {
234  // ***************************************************************************
235  // We always come in to this call with updated momenta but we need to create updated velocity
236  // in order to impose the rest of the bc's
237  // ***************************************************************************
238  // This only fills VALID region of velocity
239  MomentumToVelocity(*mfs_vel[Vars::xvel], *mfs_vel[Vars::yvel], *mfs_vel[Vars::zvel],
240  *mfs_vel[Vars::cons],
241  *mfs_mom[IntVars::xmom], *mfs_mom[IntVars::ymom], *mfs_mom[IntVars::zmom],
242  Geom(lev).Domain(), domain_bcs_type);
243 
244  mapper = &face_cons_linear_interp;
245 
246  //
247  // NOTE: All interpolation here happens on velocities not momenta;
248  // note we only do the interpolation and FillBoundary here,
249  // physical bc's are imposed later
250  //
251  // NOTE: This will only fill velocity from coarse grid *outside* the fine grids
252  // unlike the FillSet calls above which filled momenta on the coarse/fine bdy
253  //
254 
255  MultiFab& mfu = *mfs_vel[Vars::xvel];
256 
257  fmf = {&mfu,&mfu};
258  cmf = {&vars_old[lev-1][Vars::xvel], &vars_new[lev-1][Vars::xvel]};
259 
260  // Call FillPatchTwoLevels which ASSUMES that all ghost cells have already been filled
261  FillPatchTwoLevels(mfu, IntVect{ng_vel}, IntVect(0,0,0),
262  time, cmf, ctime, fmf, ftime,
263  0, 0, 1, geom[lev-1], geom[lev],
264  refRatio(lev-1), mapper, domain_bcs_type,
266 
267  // *****************************************************************************************
268 
269  MultiFab& mfv = *mfs_vel[Vars::yvel];
270 
271  fmf = {&mfv,&mfv};
272  cmf = {&vars_old[lev-1][Vars::yvel], &vars_new[lev-1][Vars::yvel]};
273 
274  // Call FillPatchTwoLevels which ASSUMES that all ghost cells have already been filled
275  FillPatchTwoLevels(mfv, IntVect{ng_vel}, IntVect(0,0,0),
276  time, cmf, ctime, fmf, ftime,
277  0, 0, 1, geom[lev-1], geom[lev],
278  refRatio(lev-1), mapper, domain_bcs_type,
280 
281  // *****************************************************************************************
282 
283  MultiFab& mfw = *mfs_vel[Vars::zvel];
284 
285  fmf = {&mfw,&mfw};
286  cmf = {&vars_old[lev-1][Vars::zvel], &vars_new[lev-1][Vars::zvel]};
287 
288  // Call FillPatchTwoLevels which ASSUMES that all ghost cells have already been filled
289  FillPatchTwoLevels(mfw, IntVect{ng_vel}, IntVect(0,0,0),
290  time, cmf, ctime, fmf, ftime,
291  0, 0, 1, geom[lev-1], geom[lev],
292  refRatio(lev-1), mapper, domain_bcs_type,
294  } // !cons_only
295  } // lev > 0
296 
297  // ***************************************************************************
298  // Physical bc's at domain boundary
299  // ***************************************************************************
300  IntVect ngvect_cons = IntVect(ng_cons,ng_cons,ng_cons);
301  IntVect ngvect_vels = IntVect(ng_vel ,ng_vel ,ng_vel);
302 
303  bool do_fb = true;
304 
305 #ifdef ERF_USE_NETCDF
306  // We call this here because it is an ERF routine
307  if (solverChoice.use_real_bcs && (lev==0)) {
308  fill_from_realbdy(mfs_vel,time,cons_only,icomp_cons,ncomp_cons,ngvect_cons,ngvect_vels);
309  do_fb = false;
310  }
311 #endif
312 
313  if (m_r2d) fill_from_bndryregs(mfs_vel,time);
314 
315  // We call this even if use_real_bcs is true because these will fill the vertical bcs
316  (*physbcs_cons[lev])(*mfs_vel[Vars::cons],*mfs_vel[Vars::xvel],*mfs_vel[Vars::yvel],
317  icomp_cons,ncomp_cons,ngvect_cons,time,BCVars::cons_bc, do_fb);
318  if (!cons_only) {
319  (*physbcs_u[lev])(*mfs_vel[Vars::xvel],*mfs_vel[Vars::xvel],*mfs_vel[Vars::yvel],
320  ngvect_vels,time,BCVars::xvel_bc, do_fb);
321  (*physbcs_v[lev])(*mfs_vel[Vars::yvel],*mfs_vel[Vars::xvel],*mfs_vel[Vars::yvel],
322  ngvect_vels,time,BCVars::yvel_bc, do_fb);
323  (*physbcs_w[lev])(*mfs_vel[Vars::zvel],*mfs_vel[Vars::xvel],*mfs_vel[Vars::yvel],
324  ngvect_vels,time,BCVars::zvel_bc, do_fb);
325  }
326  // ***************************************************************************
327 
328  // We always come in to this call with momenta so we need to leave with momenta!
329  // We need to make sure we convert back on all ghost cells/faces because this is
330  // how velocity from fine-fine copies (as well as physical and interpolated bcs) will be filled
331  if (!cons_only)
332  {
333  IntVect ngu = (!solverChoice.use_num_diff) ? IntVect(1,1,1) : mfs_vel[Vars::xvel]->nGrowVect();
334  IntVect ngv = (!solverChoice.use_num_diff) ? IntVect(1,1,1) : mfs_vel[Vars::yvel]->nGrowVect();
335  IntVect ngw = (!solverChoice.use_num_diff) ? IntVect(1,1,0) : mfs_vel[Vars::zvel]->nGrowVect();
336 
337  VelocityToMomentum(*mfs_vel[Vars::xvel], ngu,
338  *mfs_vel[Vars::yvel], ngv,
339  *mfs_vel[Vars::zvel], ngw,
340  *mfs_vel[Vars::cons],
341  *mfs_mom[IntVars::xmom], *mfs_mom[IntVars::ymom], *mfs_mom[IntVars::zmom],
342  Geom(lev).Domain(),
344  }
345 
346  // NOTE: There are not FillBoundary calls here for the following reasons:
347  // Removal of the FillBoundary (FB) calls has bee completed for the following reasons:
348  //
349  // 1. physbc_cons is called before VelocityToMomentum and a FB is completed in that functor.
350  // Therefore, the conserved CC vars have their inter-rank ghost cells filled and then their
351  // domain ghost cells filled from the BC operations. We should not call FB on this MF again.
352  //
353  // 2. physbc_u/v/w is also called before VelocityToMomentum and a FB is completed those functors.
354  // Furthermore, VelocityToMomentum operates on a growntilebox so we exit that routine with momentum
355  // filled everywhere---i.e., physbc_u/v/w fills velocity ghost cells (inter-rank and domain)
356  // and then V2M does the conversion to momenta everywhere; so there is again no need to do a FB on momenta.
357 }
AMREX_GPU_HOST AMREX_FORCE_INLINE void ApplyMask(amrex::MultiFab &dst, const amrex::iMultiFab &imask, const int nghost=0)
Definition: ERF_Utils.H:387
void fill_from_bndryregs(const amrex::Vector< amrex::MultiFab * > &mfs, amrex::Real time)
Definition: ERF_BoundaryConditionsBndryReg.cpp:13
void FillIntermediatePatch(int lev, amrex::Real time, const amrex::Vector< amrex::MultiFab * > &mfs_vel, const amrex::Vector< amrex::MultiFab * > &mfs_mom, int ng_cons, int ng_vel, bool cons_only, int icomp_cons, int ncomp_cons)
Definition: ERF_FillIntermediatePatch.cpp:28
@ NumTypes
Definition: ERF_IndexDefines.H:162
static bool use_real_bcs
Definition: ERF_DataStruct.H:700
Here is the call graph for this function:

◆ FillPatch() [1/2]

void ERF::FillPatch ( int  lev,
amrex::Real  time,
const amrex::Vector< amrex::MultiFab * > &  mfs_vel,
bool  cons_only = false 
)
private

◆ FillPatch() [2/2]

void ERF::FillPatch ( int  lev,
amrex::Real  time,
const amrex::Vector< amrex::MultiFab * > &  mfs_vel,
const amrex::Vector< amrex::MultiFab * > &  mfs_mom,
const amrex::MultiFab &  old_base_state,
const amrex::MultiFab &  new_base_state,
bool  fillset = true,
bool  cons_only = false 
)
private

◆ get_eb()

eb_ const& ERF::get_eb ( int  lev) const
inlineprivatenoexcept
1442  {
1443  AMREX_ASSERT(lev >= 0 && lev < eb.size() && eb[lev] != nullptr);
1444  return *eb[lev];
1445  }

◆ get_projection_bc()

Array< LinOpBCType, AMREX_SPACEDIM > ERF::get_projection_bc ( amrex::Orientation::Side  side) const
noexcept
18 {
19  amrex::Array<amrex::LinOpBCType,AMREX_SPACEDIM> r;
20  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
21  if (geom[0].isPeriodic(dir)) {
22  r[dir] = LinOpBCType::Periodic;
23  } else {
24  auto bc_type = domain_bc_type[Orientation(dir,side)];
25  if (bc_type == "Outflow") {
26  r[dir] = LinOpBCType::Dirichlet;
27  } else
28  {
29  r[dir] = LinOpBCType::Neumann;
30  }
31  }
32  }
33  return r;
34 }
amrex::Array< std::string, 2 *AMREX_SPACEDIM > domain_bc_type
Definition: ERF.H:855

◆ getAdvFluxReg()

AMREX_FORCE_INLINE amrex::YAFluxRegister* ERF::getAdvFluxReg ( int  lev)
inlineprivate
1231  {
1232  return advflux_reg[lev];
1233  }

◆ getCPUTime()

static amrex::Real ERF::getCPUTime ( )
inlinestaticprivate
1323  {
1324  int numCores = amrex::ParallelDescriptor::NProcs();
1325 #ifdef _OPENMP
1326  numCores = numCores * omp_get_max_threads();
1327 #endif
1328 
1329  amrex::Real T =
1330  numCores * (amrex::ParallelDescriptor::second() - startCPUTime) +
1332 
1333  return T;
1334  }
static amrex::Real previousCPUTimeUsed
Definition: ERF.H:1319
static amrex::Real startCPUTime
Definition: ERF.H:1318
@ T
Definition: ERF_IndexDefines.H:110

◆ GotoNextLine()

void ERF::GotoNextLine ( std::istream &  is)
staticprivate

Utility to skip to next line in Header file input stream.

17 {
18  constexpr std::streamsize bl_ignore_max { 100000 };
19  is.ignore(bl_ignore_max, '\n');
20 }

◆ HurricaneTracker()

void ERF::HurricaneTracker ( int  lev,
const amrex::MultiFab &  U_new,
const amrex::MultiFab &  V_new,
const amrex::MultiFab &  W_new,
const amrex::Real  velmag_threshold,
const bool  is_track_io,
amrex::TagBoxArray *  tags = nullptr 
)
398 {
399  const auto dx = geom[levc].CellSizeArray();
400  const auto prob_lo = geom[levc].ProbLoArray();
401 
402  const int ncomp = AMREX_SPACEDIM; // Number of components (3 for 3D)
403 
404  Gpu::DeviceVector<Real> d_coords(3, 0.0); // Initialize to -1
405  Real* d_coords_ptr = d_coords.data(); // Get pointer to device vector
406  Gpu::DeviceVector<int> d_found(1,0);
407  int* d_found_ptr = d_found.data();
408 
409  MultiFab mf_cc_vel(grids[levc], dmap[levc], AMREX_SPACEDIM, IntVect(0,0,0));
410  average_face_to_cellcenter(mf_cc_vel,0,{AMREX_D_DECL(&U_new,&V_new,&W_new)},0);
411 
412  // Loop through MultiFab using MFIter
413  for (MFIter mfi(mf_cc_vel); mfi.isValid(); ++mfi) {
414  const Box& box = mfi.validbox(); // Get the valid box for the current MFIter
415  const Array4<const Real>& vel_arr = mf_cc_vel.const_array(mfi); // Get the array for this MFIter
416 
417  // ParallelFor loop to check velocity magnitudes on the GPU
418  amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
419  // Access velocity components using ncomp
420  Real magnitude = 0.0; // Initialize magnitude
421 
422  for (int comp = 0; comp < ncomp; ++comp) {
423  Real vel = vel_arr(i, j, k, comp); // Access the component for each (i, j, k)
424  magnitude += vel * vel; // Sum the square of the components
425  }
426 
427  magnitude = std::sqrt(magnitude)*3.6; // Calculate magnitude
428  Real x = prob_lo[0] + (i + 0.5) * dx[0];
429  Real y = prob_lo[1] + (j + 0.5) * dx[1];
430  Real z = prob_lo[2] + (k + 0.5) * dx[2];
431 
432  // Check if magnitude exceeds threshold
433  if (z < 2.0e3 && magnitude > velmag_threshold) {
434  // Use atomic operations to set found flag and store coordinates
435  Gpu::Atomic::Add(&d_found_ptr[0], 1); // Mark as found
436 
437  // Store coordinates
438  Gpu::Atomic::Add(&d_coords_ptr[0],x); // Store x index
439  Gpu::Atomic::Add(&d_coords_ptr[1],y); // Store x index
440  Gpu::Atomic::Add(&d_coords_ptr[2],z); // Store x index
441  }
442  });
443  }
444 
445  // Synchronize to ensure all threads complete their execution
446  amrex::Gpu::streamSynchronize(); // Wait for all GPU threads to finish
447 
448  Vector<int> h_found(1,0);
449  Gpu::copy(Gpu::deviceToHost, d_found.begin(), d_found.end(), h_found.begin());
450  ParallelAllReduce::Sum(h_found.data(),
451  h_found.size(),
452  ParallelContext::CommunicatorAll());
453 
454  Real eye_x, eye_y;
455  // Broadcast coordinates if found
456  if (h_found[0] > 0) {
457  Vector<Real> h_coords(3,-1e10);
458  Gpu::copy(Gpu::deviceToHost, d_coords.begin(), d_coords.end(), h_coords.begin());
459 
460  ParallelAllReduce::Sum(h_coords.data(),
461  h_coords.size(),
462  ParallelContext::CommunicatorAll());
463 
464  eye_x = h_coords[0]/h_found[0];
465  eye_y = h_coords[1]/h_found[0];
466 
467  // Data structure to hold the hurricane track for I/O
468  if (amrex::ParallelDescriptor::IOProcessor() and is_track_io) {
469  hurricane_track_xy.push_back({eye_x, eye_y});
470  }
471 
472  if(is_track_io) {
473  return;
474  }
475 
476  Real rad_tag = 3e5*std::pow(2, max_level-1-levc);
477 
478  for (MFIter mfi(*tags); mfi.isValid(); ++mfi) {
479  TagBox& tag = (*tags)[mfi];
480  auto tag_arr = tag.array(); // Get device-accessible array
481 
482  const Box& tile_box = mfi.tilebox(); // The box for this tile
483 
484  ParallelFor(tile_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
485  // Compute cell center coordinates
486  Real x = prob_lo[0] + (i + 0.5) * dx[0];
487  Real y = prob_lo[1] + (j + 0.5) * dx[1];
488 
489  Real dist = std::sqrt((x - eye_x)*(x - eye_x) + (y - eye_y)*(y - eye_y));
490 
491  if (dist < rad_tag) {
492  tag_arr(i,j,k) = TagBox::SET;
493  }
494  });
495  }
496  }
497 }
amrex::Vector< std::array< amrex::Real, 2 > > hurricane_track_xy
Definition: ERF.H:144

◆ ImposeBCsOnPhi()

void ERF::ImposeBCsOnPhi ( int  lev,
amrex::MultiFab &  phi 
)

Impose bc's on the pressure that comes out of the solve

13 {
14  BL_PROFILE("ERF::ImposeBCsOnPhi()");
15 
16  auto const dom_lo = lbound(geom[lev].Domain());
17  auto const dom_hi = ubound(geom[lev].Domain());
18 
19  phi.FillBoundary(geom[lev].periodicity());
20 
21  // ****************************************************************************
22  // Impose bc's on pprime
23  // ****************************************************************************
24 #ifdef _OPENMP
25 #pragma omp parallel if (Gpu::notInLaunchRegion())
26 #endif
27  for (MFIter mfi(phi,TilingIfNotGPU()); mfi.isValid(); ++mfi)
28  {
29  Array4<Real> const& pp_arr = phi.array(mfi);
30  Box const& bx = mfi.tilebox();
31  auto const bx_lo = lbound(bx);
32  auto const bx_hi = ubound(bx);
33 
34  if (bx_lo.x == dom_lo.x) {
35  auto bc_type = domain_bc_type[Orientation(0,Orientation::low)];
36  if (bc_type == "Outflow" || bc_type == "Open") {
37  ParallelFor(makeSlab(bx,0,dom_lo.x), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
38  {
39  pp_arr(i-1,j,k) = -pp_arr(i,j,k);
40  });
41  } else {
42  ParallelFor(makeSlab(bx,0,dom_lo.x), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
43  {
44  pp_arr(i-1,j,k) = pp_arr(i,j,k);
45  });
46  }
47  }
48  if (bx_hi.x == dom_hi.x) {
49  auto bc_type = domain_bc_type[Orientation(0,Orientation::high)];
50  if (bc_type == "Outflow" || bc_type == "Open") {
51  ParallelFor(makeSlab(bx,0,dom_hi.x), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
52  {
53  pp_arr(i+1,j,k) = -pp_arr(i,j,k);
54  });
55  } else {
56  ParallelFor(makeSlab(bx,0,dom_hi.x), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
57  {
58  pp_arr(i+1,j,k) = pp_arr(i,j,k);
59  });
60  }
61  }
62 
63  if (bx_lo.y == dom_lo.y) {
64  auto bc_type = domain_bc_type[Orientation(1,Orientation::low)];
65  Box ybx(bx); ybx.grow(0,1); // Grow in x-dir because we have filled that above
66  if (bc_type == "Outflow" || bc_type == "Open") {
67  ParallelFor(makeSlab(ybx,1,dom_lo.y), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
68  {
69  pp_arr(i,j-1,k) = -pp_arr(i,j,k);
70  });
71  } else {
72  ParallelFor(makeSlab(ybx,1,dom_lo.y), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
73  {
74  pp_arr(i,j-1,k) = pp_arr(i,j,k);
75  });
76  }
77  }
78  if (bx_hi.y == dom_hi.y) {
79  auto bc_type = domain_bc_type[Orientation(1,Orientation::high)];
80  Box ybx(bx); ybx.grow(0,1); // Grow in x-dir because we have filled that above
81  if (bc_type == "Outflow" || bc_type == "Open") {
82  ParallelFor(makeSlab(ybx,1,dom_hi.y), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
83  {
84  pp_arr(i,j+1,k) = -pp_arr(i,j,k);
85  });
86  } else {
87  ParallelFor(makeSlab(ybx,1,dom_hi.y), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
88  {
89  pp_arr(i,j+1,k) = pp_arr(i,j,k);
90  });
91  }
92  }
93 
94  Box zbx(bx); zbx.grow(0,1); zbx.grow(1,1); // Grow in x-dir and y-dir because we have filled that above
95  if (bx_lo.z == dom_lo.z) {
96  ParallelFor(makeSlab(zbx,2,dom_lo.z), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
97  {
98  pp_arr(i,j,k-1) = pp_arr(i,j,k);
99  });
100  }
101  if (bx_hi.z == dom_hi.z) {
102  ParallelFor(makeSlab(zbx,2,dom_hi.z), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
103  {
104  pp_arr(i,j,k+1) = pp_arr(i,j,k);
105  });
106  }
107  } // mfi
108 
109  // Now overwrite with periodic fill outside domain and fine-fine fill inside
110  phi.FillBoundary(geom[lev].periodicity());
111 }
const Box ybx
Definition: ERF_DiffSetup.H:22

◆ init1DArrays()

void ERF::init1DArrays ( )
private

◆ init_bcs()

void ERF::init_bcs ( )
private

Initializes data structures in the ERF class that specify which boundary conditions we are implementing on each face of the domain.

This function also maps the selected boundary condition types (e.g. Outflow, Inflow, InflowOutflow, Periodic, Dirichlet, ...) to the specific implementation needed for each variable.

Stores this information in both host and device vectors so it is available for GPU kernels.

21 {
22  bool rho_read = false;
23  bool read_prim_theta = true;
24  Vector<Real> cons_dir_init(NBCVAR_max,0.0);
25  cons_dir_init[BCVars::Rho_bc_comp] = 1.0;
26  cons_dir_init[BCVars::RhoTheta_bc_comp] = -1.0;
27  auto f = [this,&rho_read,&read_prim_theta] (std::string const& bcid, Orientation ori)
28  {
29  // These are simply defaults for Dirichlet faces -- they should be over-written below
31  m_bc_extdir_vals[BCVars::RhoTheta_bc_comp][ori] = -1.0; // It is important to set this negative
32  // because the sign is tested on below
33  for (int n = BCVars::RhoKE_bc_comp; n < BCVars::xvel_bc; n++) {
34  m_bc_extdir_vals[n][ori] = 0.0;
35  }
36 
37  m_bc_extdir_vals[BCVars::xvel_bc][ori] = 0.0; // default
40 
41  // These are simply defaults for Neumann gradients -- they should be over-written below
44 
53 
57 
58  std::string pp_text = pp_prefix + "." + bcid;
59  ParmParse pp(pp_text);
60 
61  std::string bc_type_in;
62  if (pp.query("type", bc_type_in) <= 0)
63  {
64  pp_text = bcid;
65  pp = ParmParse(pp_text);
66  pp.query("type", bc_type_in);
67  }
68 
69  std::string bc_type = amrex::toLower(bc_type_in);
70 
71  if (bc_type == "symmetry")
72  {
73  // Print() << bcid << " set to symmetry.\n";
75  domain_bc_type[ori] = "Symmetry";
76  }
77  else if (bc_type == "outflow")
78  {
79  // Print() << bcid << " set to outflow.\n";
81  domain_bc_type[ori] = "Outflow";
82  }
83  else if (bc_type == "open")
84  {
85  // Print() << bcid << " set to open.\n";
86  AMREX_ASSERT_WITH_MESSAGE((ori.coordDir() != 2), "Open boundary not valid on zlo or zhi!");
88  domain_bc_type[ori] = "Open";
89  }
90  else if (bc_type == "ho_outflow")
91  {
93  domain_bc_type[ori] = "HO_Outflow";
94  }
95 
96  else if (bc_type == "inflow" || bc_type == "inflow_outflow")
97  {
98  if (bc_type == "inflow") {
99  // Print() << bcid << " set to inflow.\n";
101  domain_bc_type[ori] = "Inflow";
102  } else {
103  // Print() << bcid << " set to inflow_outflow.\n";
105  domain_bc_type[ori] = "InflowOutflow";
106  }
107 
108  std::vector<Real> v;
109  if (input_bndry_planes && m_r2d->ingested_velocity()) {
113  } else {
114  // Test for input data file if at xlo face
115  std::string dirichlet_file;
116  auto file_exists = pp.query("dirichlet_file", dirichlet_file);
117  if (file_exists) {
118  pp.query("read_prim_theta", read_prim_theta);
119  init_Dirichlet_bc_data(dirichlet_file);
120  } else {
121  pp.getarr("velocity", v, 0, AMREX_SPACEDIM);
122  m_bc_extdir_vals[BCVars::xvel_bc][ori] = v[0];
123  m_bc_extdir_vals[BCVars::yvel_bc][ori] = v[1];
124  m_bc_extdir_vals[BCVars::zvel_bc][ori] = v[2];
125  }
126  }
127 
128  Real rho_in = 0.;
129  if (input_bndry_planes && m_r2d->ingested_density()) {
131  } else {
132  if (!pp.query("density", rho_in)) {
133  amrex::Print() << "Using interior values to set conserved vars" << std::endl;
134  }
135  m_bc_extdir_vals[BCVars::Rho_bc_comp][ori] = rho_in;
136  }
137 
138  bool th_read = (th_bc_data[0].data()!=nullptr);
139  Real theta_in = 0.;
140  if (input_bndry_planes && m_r2d->ingested_theta()) {
142  } else if (!th_read) {
143  if (rho_in > 0) {
144  pp.get("theta", theta_in);
145  }
146  m_bc_extdir_vals[BCVars::RhoTheta_bc_comp][ori] = rho_in*theta_in;
147  }
148 
149  Real scalar_in = 0.;
150  if (input_bndry_planes && m_r2d->ingested_scalar()) {
152  } else {
153  if (pp.query("scalar", scalar_in))
154  m_bc_extdir_vals[BCVars::RhoScalar_bc_comp][ori] = rho_in*scalar_in;
155  }
156 
157  if (solverChoice.moisture_type != MoistureType::None) {
158  Real qv_in = 0.;
159  if (input_bndry_planes && m_r2d->ingested_q1()) {
161  } else {
162  if (pp.query("qv", qv_in))
163  m_bc_extdir_vals[BCVars::RhoQ1_bc_comp][ori] = rho_in*qv_in;
164  }
165  Real qc_in = 0.;
166  if (input_bndry_planes && m_r2d->ingested_q2()) {
168  } else {
169  if (pp.query("qc", qc_in))
170  m_bc_extdir_vals[BCVars::RhoQ2_bc_comp][ori] = rho_in*qc_in;
171  }
172  }
173 
174  Real KE_in = 0.;
175  if (input_bndry_planes && m_r2d->ingested_KE()) {
177  } else {
178  if (pp.query("KE", KE_in))
179  m_bc_extdir_vals[BCVars::RhoKE_bc_comp][ori] = rho_in*KE_in;
180  }
181  }
182  else if (bc_type == "noslipwall")
183  {
184  // Print() << bcid <<" set to no-slip wall.\n";
186  domain_bc_type[ori] = "NoSlipWall";
187 
188  std::vector<Real> v;
189 
190  // The values of m_bc_extdir_vals default to 0.
191  // But if we find "velocity" in the inputs file, use those values instead.
192  if (pp.queryarr("velocity", v, 0, AMREX_SPACEDIM))
193  {
194  v[ori.coordDir()] = 0.0;
195  m_bc_extdir_vals[BCVars::xvel_bc][ori] = v[0];
196  m_bc_extdir_vals[BCVars::yvel_bc][ori] = v[1];
197  m_bc_extdir_vals[BCVars::zvel_bc][ori] = v[2];
198  }
199 
200  Real rho_in;
201  rho_read = pp.query("density", rho_in);
202  if (rho_read)
203  {
204  m_bc_extdir_vals[BCVars::Rho_bc_comp][ori] = rho_in;
205  }
206 
207  Real theta_in;
208  if (pp.query("theta", theta_in))
209  {
211  }
212 
213  Real theta_grad_in;
214  if (pp.query("theta_grad", theta_grad_in))
215  {
216  m_bc_neumann_vals[BCVars::RhoTheta_bc_comp][ori] = theta_grad_in;
217  }
218 
219  Real qv_in;
220  if (pp.query("qv", qv_in))
221  {
223  }
224  }
225  else if (bc_type == "slipwall")
226  {
227  // Print() << bcid <<" set to slip wall.\n";
228 
230  domain_bc_type[ori] = "SlipWall";
231 
232  Real rho_in;
233  rho_read = pp.query("density", rho_in);
234  if (rho_read)
235  {
236  m_bc_extdir_vals[BCVars::Rho_bc_comp][ori] = rho_in;
237  }
238 
239  Real theta_in;
240  if (pp.query("theta", theta_in))
241  {
243  }
244 
245  Real rho_grad_in;
246  if (pp.query("density_grad", rho_grad_in))
247  {
248  m_bc_neumann_vals[BCVars::Rho_bc_comp][ori] = rho_grad_in;
249  }
250 
251  Real theta_grad_in;
252  if (pp.query("theta_grad", theta_grad_in))
253  {
254  m_bc_neumann_vals[BCVars::RhoTheta_bc_comp][ori] = theta_grad_in;
255  }
256  }
257  else if (bc_type == "surface_layer")
258  {
260  domain_bc_type[ori] = "surface_layer";
261  }
262  else
263  {
265  }
266 
267  if (geom[0].isPeriodic(ori.coordDir())) {
268  domain_bc_type[ori] = "Periodic";
269  if (phys_bc_type[ori] == ERF_BC::undefined)
270  {
272  } else {
273  Abort("Wrong BC type for periodic boundary");
274  }
275  }
276 
277  if (phys_bc_type[ori] == ERF_BC::undefined)
278  {
279  Print() << "BC Type specified for face " << bcid << " is " << bc_type_in << std::endl;
280  Abort("This BC type is unknown");
281  }
282  };
283 
284  f("xlo", Orientation(Direction::x,Orientation::low));
285  f("xhi", Orientation(Direction::x,Orientation::high));
286  f("ylo", Orientation(Direction::y,Orientation::low));
287  f("yhi", Orientation(Direction::y,Orientation::high));
288  f("zlo", Orientation(Direction::z,Orientation::low));
289  f("zhi", Orientation(Direction::z,Orientation::high));
290 
291  // *****************************************************************************
292  //
293  // Here we translate the physical boundary conditions -- one type per face --
294  // into logical boundary conditions for each velocity component
295  //
296  // *****************************************************************************
297  {
298  domain_bcs_type.resize(AMREX_SPACEDIM+NBCVAR_max);
299  domain_bcs_type_d.resize(AMREX_SPACEDIM+NBCVAR_max);
300 
301  for (OrientationIter oit; oit; ++oit) {
302  Orientation ori = oit();
303  int dir = ori.coordDir();
304  Orientation::Side side = ori.faceDir();
305  auto const bct = phys_bc_type[ori];
306  if ( bct == ERF_BC::symmetry )
307  {
308  if (side == Orientation::low) {
309  for (int i = 0; i < AMREX_SPACEDIM; i++) {
311  }
313  } else {
314  for (int i = 0; i < AMREX_SPACEDIM; i++) {
316  }
318  }
319  }
320  else if (bct == ERF_BC::outflow or bct == ERF_BC::ho_outflow )
321  {
322  if (side == Orientation::low) {
323  for (int i = 0; i < AMREX_SPACEDIM; i++) {
325  }
326  if (!solverChoice.anelastic[0]) {
328  }
329  } else {
330  for (int i = 0; i < AMREX_SPACEDIM; i++) {
332  }
333  if (!solverChoice.anelastic[0]) {
335  }
336  }
337  }
338  else if (bct == ERF_BC::open)
339  {
340  if (side == Orientation::low) {
341  for (int i = 0; i < AMREX_SPACEDIM; i++)
343  } else {
344  for (int i = 0; i < AMREX_SPACEDIM; i++)
346  }
347  }
348  else if (bct == ERF_BC::inflow)
349  {
350  if (side == Orientation::low) {
351  for (int i = 0; i < AMREX_SPACEDIM; i++) {
353  if (input_bndry_planes && dir < 2 && m_r2d->ingested_velocity()) {
355  }
356  }
357  } else {
358  for (int i = 0; i < AMREX_SPACEDIM; i++) {
360  if (input_bndry_planes && dir < 2 && m_r2d->ingested_velocity()) {
362  }
363  }
364  }
365  }
366  else if (bct == ERF_BC::inflow_outflow)
367  {
368  if (side == Orientation::low) {
369  for (int i = 0; i < AMREX_SPACEDIM; i++) {
371  }
372  } else {
373  for (int i = 0; i < AMREX_SPACEDIM; i++) {
375  }
376  }
377  }
378  else if (bct == ERF_BC::no_slip_wall)
379  {
380  if (side == Orientation::low) {
381  for (int i = 0; i < AMREX_SPACEDIM; i++) {
383  }
384  } else {
385  for (int i = 0; i < AMREX_SPACEDIM; i++) {
387  }
388  }
389  }
390  else if (bct == ERF_BC::slip_wall)
391  {
392  if (side == Orientation::low) {
393  for (int i = 0; i < AMREX_SPACEDIM; i++) {
395  }
396  // Only normal direction has ext_dir
398 
399  } else {
400  for (int i = 0; i < AMREX_SPACEDIM; i++) {
402  }
403  // Only normal direction has ext_dir
405  }
406  }
407  else if (bct == ERF_BC::periodic)
408  {
409  if (side == Orientation::low) {
410  for (int i = 0; i < AMREX_SPACEDIM; i++) {
412  }
413  } else {
414  for (int i = 0; i < AMREX_SPACEDIM; i++) {
416  }
417  }
418  }
419  else if ( bct == ERF_BC::surface_layer )
420  {
421  AMREX_ALWAYS_ASSERT(dir == 2 && side == Orientation::low);
425  }
426  }
427  }
428 
429  // *****************************************************************************
430  //
431  // Here we translate the physical boundary conditions -- one type per face --
432  // into logical boundary conditions for each cell-centered variable
433  // (including the base state variables)
434  // NOTE: all "scalars" share the same type of boundary condition
435  //
436  // *****************************************************************************
437  {
438  for (OrientationIter oit; oit; ++oit) {
439  Orientation ori = oit();
440  int dir = ori.coordDir();
441  Orientation::Side side = ori.faceDir();
442  auto const bct = phys_bc_type[ori];
443  if ( bct == ERF_BC::symmetry )
444  {
445  if (side == Orientation::low) {
446  for (int i = 0; i < NBCVAR_max; i++) {
448  }
449  } else {
450  for (int i = 0; i < NBCVAR_max; i++) {
452  }
453  }
454  }
455  else if ( bct == ERF_BC::outflow )
456  {
457  if (side == Orientation::low) {
458  for (int i = 0; i < NBCVAR_max; i++) {
460  }
461  } else {
462  for (int i = 0; i < NBCVAR_max; i++) {
464  }
465  }
466  }
467  else if ( bct == ERF_BC::ho_outflow )
468  {
469  if (side == Orientation::low) {
470  for (int i = 0; i < NBCVAR_max; i++) {
472  }
473  } else {
474  for (int i = 0; i < NBCVAR_max; i++) {
476  }
477  }
478  }
479  else if ( bct == ERF_BC::open )
480  {
481  if (side == Orientation::low) {
482  for (int i = 0; i < NBCVAR_max; i++)
484  } else {
485  for (int i = 0; i < NBCVAR_max; i++)
487  }
488  }
489  else if ( bct == ERF_BC::no_slip_wall )
490  {
491  if (side == Orientation::low) {
492  for (int i = 0; i < NBCVAR_max; i++) {
494  if (m_bc_extdir_vals[BCVars::cons_bc+i][ori] != cons_dir_init[BCVars::cons_bc+i]) {
495  if (rho_read) {
497  } else {
499  }
500  }
501  }
502  if (std::abs(m_bc_neumann_vals[BCVars::RhoTheta_bc_comp][ori]) > 0.) {
504  }
505  } else {
506  for (int i = 0; i < NBCVAR_max; i++) {
508  if (m_bc_extdir_vals[BCVars::cons_bc+i][ori] != cons_dir_init[BCVars::cons_bc+i]) {
509  if (rho_read) {
511  } else {
513  }
514  }
515  }
516  if (std::abs(m_bc_neumann_vals[BCVars::RhoTheta_bc_comp][ori]) > 0.) {
518  }
519  }
520  }
521  else if (bct == ERF_BC::slip_wall)
522  {
523  if (side == Orientation::low) {
524  for (int i = 0; i < NBCVAR_max; i++) {
526  if (m_bc_extdir_vals[BCVars::cons_bc+i][ori] != cons_dir_init[BCVars::cons_bc+i]) {
527  if (rho_read) {
529  } else {
531  }
532  }
533  }
534  if (std::abs(m_bc_neumann_vals[BCVars::RhoTheta_bc_comp][ori]) > 0.) {
536  }
537  if (std::abs(m_bc_neumann_vals[BCVars::Rho_bc_comp][ori]) > 0.) {
539  }
540  } else {
541  for (int i = 0; i < NBCVAR_max; i++) {
543  if (m_bc_extdir_vals[BCVars::cons_bc+i][ori] != cons_dir_init[BCVars::cons_bc+i]) {
544  if (rho_read) {
546  } else {
548  }
549  }
550  }
551  if (std::abs(m_bc_neumann_vals[BCVars::RhoTheta_bc_comp][ori]) > 0.) {
553  }
554  if (std::abs(m_bc_neumann_vals[BCVars::Rho_bc_comp][ori]) > 0.) {
556  }
557  }
558  }
559  else if (bct == ERF_BC::inflow)
560  {
561  if (side == Orientation::low) {
562  for (int i = 0; i < NBCVAR_max; i++) {
564  if ((BCVars::cons_bc+i == RhoTheta_comp) &&
565  (th_bc_data[0].data() != nullptr))
566  {
567  if (read_prim_theta) domain_bcs_type[BCVars::cons_bc+i].setLo(dir, ERFBCType::ext_dir_prim);
568  }
569  else if (input_bndry_planes && dir < 2 && (
570  ( (BCVars::cons_bc+i == BCVars::Rho_bc_comp) && m_r2d->ingested_density()) ||
571  ( (BCVars::cons_bc+i == BCVars::RhoTheta_bc_comp) && m_r2d->ingested_theta() ) ||
572  ( (BCVars::cons_bc+i == BCVars::RhoKE_bc_comp) && m_r2d->ingested_KE() ) ||
573  ( (BCVars::cons_bc+i == BCVars::RhoScalar_bc_comp) && m_r2d->ingested_scalar() ) ||
574  ( (BCVars::cons_bc+i == BCVars::RhoQ1_bc_comp) && m_r2d->ingested_q1() ) ||
575  ( (BCVars::cons_bc+i == BCVars::RhoQ2_bc_comp) && m_r2d->ingested_q2() )) )
576  {
578  }
579  else if (m_bc_extdir_vals[BCVars::Rho_bc_comp][ori] == 0) {
581  }
582  }
583  } else {
584  for (int i = 0; i < NBCVAR_max; i++) {
586  if ((BCVars::cons_bc+i == RhoTheta_comp) &&
587  (th_bc_data[0].data() != nullptr))
588  {
589  if (read_prim_theta) domain_bcs_type[BCVars::cons_bc+i].setHi(dir, ERFBCType::ext_dir_prim);
590  }
591  else if (input_bndry_planes && dir < 2 && (
592  ( (BCVars::cons_bc+i == BCVars::Rho_bc_comp) && m_r2d->ingested_density()) ||
593  ( (BCVars::cons_bc+i == BCVars::RhoTheta_bc_comp) && m_r2d->ingested_theta() ) ||
594  ( (BCVars::cons_bc+i == BCVars::RhoKE_bc_comp) && m_r2d->ingested_KE() ) ||
595  ( (BCVars::cons_bc+i == BCVars::RhoScalar_bc_comp) && m_r2d->ingested_scalar() ) ||
596  ( (BCVars::cons_bc+i == BCVars::RhoQ1_bc_comp) && m_r2d->ingested_q1() ) ||
597  ( (BCVars::cons_bc+i == BCVars::RhoQ2_bc_comp) && m_r2d->ingested_q2() )
598  ) )
599  {
601  }
602  else if (m_bc_extdir_vals[BCVars::Rho_bc_comp][ori] == 0) {
604  }
605  }
606  }
607  }
608  else if (bct == ERF_BC::inflow_outflow )
609  {
610  if (side == Orientation::low) {
611  for (int i = 0; i < NBCVAR_max; i++) {
613  if (m_bc_extdir_vals[BCVars::Rho_bc_comp][ori] == 0) {
615  }
616  }
617  } else {
618  for (int i = 0; i < NBCVAR_max; i++) {
620  if (m_bc_extdir_vals[BCVars::Rho_bc_comp][ori] == 0) {
622  }
623  }
624  }
625  }
626  else if (bct == ERF_BC::periodic)
627  {
628  if (side == Orientation::low) {
629  for (int i = 0; i < NBCVAR_max; i++) {
631  }
632  } else {
633  for (int i = 0; i < NBCVAR_max; i++) {
635  }
636  }
637  }
638  else if ( bct == ERF_BC::surface_layer )
639  {
640  AMREX_ALWAYS_ASSERT(dir == 2 && side == Orientation::low);
641  for (int i = 0; i < NBCVAR_max; i++) {
643  }
644  }
645  }
646  }
647 
648  // NOTE: Gpu:copy is a wrapper to htod_memcpy (GPU) or memcpy (CPU) and is a blocking comm
649  Gpu::copy(Gpu::hostToDevice, domain_bcs_type.begin(), domain_bcs_type.end(), domain_bcs_type_d.begin());
650 }
#define NBCVAR_max
Definition: ERF_IndexDefines.H:29
@ ho_outflow
@ inflow_outflow
void init_Dirichlet_bc_data(const std::string input_file)
Definition: ERF_InitBCs.cpp:652
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max > m_bc_neumann_vals
Definition: ERF.H:861
@ RhoQ6_bc_comp
Definition: ERF_IndexDefines.H:86
@ RhoQ1_bc_comp
Definition: ERF_IndexDefines.H:81
@ RhoQ4_bc_comp
Definition: ERF_IndexDefines.H:84
@ RhoKE_bc_comp
Definition: ERF_IndexDefines.H:79
@ RhoQ3_bc_comp
Definition: ERF_IndexDefines.H:83
@ RhoTheta_bc_comp
Definition: ERF_IndexDefines.H:78
@ RhoQ2_bc_comp
Definition: ERF_IndexDefines.H:82
@ Rho_bc_comp
Definition: ERF_IndexDefines.H:77
@ RhoQ5_bc_comp
Definition: ERF_IndexDefines.H:85
@ neumann
Definition: ERF_IndexDefines.H:213
@ open
Definition: ERF_IndexDefines.H:215
@ reflect_odd
Definition: ERF_IndexDefines.H:205
@ hoextrap
Definition: ERF_IndexDefines.H:216
@ foextrap
Definition: ERF_IndexDefines.H:208
@ ext_dir
Definition: ERF_IndexDefines.H:209
@ ext_dir_prim
Definition: ERF_IndexDefines.H:211
@ ext_dir_upwind
Definition: ERF_IndexDefines.H:217
@ int_dir
Definition: ERF_IndexDefines.H:206
@ neumann_int
Definition: ERF_IndexDefines.H:214
@ reflect_even
Definition: ERF_IndexDefines.H:207
Here is the call graph for this function:

◆ init_custom()

void ERF::init_custom ( int  lev)
private

Wrapper for custom problem-specific initialization routines that can be defined by the user as they set up a new problem in ERF. This wrapper handles all the overhead of defining the perturbation as well as initializing the random seed if needed.

This wrapper calls a user function to customize initialization on a per-Fab level inside an MFIter loop, so all the MultiFab operations are hidden from the user.

Parameters
levInteger specifying the current level
27 {
28  auto& lev_new = vars_new[lev];
29 
30  MultiFab r_hse(base_state[lev], make_alias, BaseState::r0_comp, 1);
31  MultiFab p_hse(base_state[lev], make_alias, BaseState::p0_comp, 1);
32 
33  MultiFab cons_pert(lev_new[Vars::cons].boxArray(), lev_new[Vars::cons].DistributionMap(),
34  lev_new[Vars::cons].nComp() , lev_new[Vars::cons].nGrow());
35  MultiFab xvel_pert(lev_new[Vars::xvel].boxArray(), lev_new[Vars::xvel].DistributionMap(), 1, lev_new[Vars::xvel].nGrowVect());
36  MultiFab yvel_pert(lev_new[Vars::yvel].boxArray(), lev_new[Vars::yvel].DistributionMap(), 1, lev_new[Vars::yvel].nGrowVect());
37  MultiFab zvel_pert(lev_new[Vars::zvel].boxArray(), lev_new[Vars::zvel].DistributionMap(), 1, lev_new[Vars::zvel].nGrowVect());
38 
39  // Default all perturbations to zero
40  cons_pert.setVal(0.);
41  xvel_pert.setVal(0.);
42  yvel_pert.setVal(0.);
43  zvel_pert.setVal(0.);
44 
45 #ifdef _OPENMP
46 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
47 #endif
48  for (MFIter mfi(lev_new[Vars::cons], TileNoZ()); mfi.isValid(); ++mfi)
49  {
50  const Box &bx = mfi.tilebox();
51  const Box &xbx = mfi.tilebox(IntVect(1,0,0));
52  const Box &ybx = mfi.tilebox(IntVect(0,1,0));
53  const Box &zbx = mfi.tilebox(IntVect(0,0,1));
54 
55  const auto &cons_pert_arr = cons_pert.array(mfi);
56  const auto &xvel_pert_arr = xvel_pert.array(mfi);
57  const auto &yvel_pert_arr = yvel_pert.array(mfi);
58  const auto &zvel_pert_arr = zvel_pert.array(mfi);
59 
60  Array4<Real const> cons_arr = lev_new[Vars::cons].const_array(mfi);
61  Array4<Real const> z_nd_arr = (z_phys_nd[lev]) ? z_phys_nd[lev]->const_array(mfi) : Array4<Real const>{};
62  Array4<Real const> z_cc_arr = (z_phys_cc[lev]) ? z_phys_cc[lev]->const_array(mfi) : Array4<Real const>{};
63 
64  // Here we arbitrarily choose the x-oriented map factor -- this should be generalized
65  Array4<Real const> mf_m = mapfac[lev][MapFacType::m_x]->const_array(mfi);
66  Array4<Real const> mf_u = mapfac[lev][MapFacType::u_x]->const_array(mfi);
67  Array4<Real const> mf_v = mapfac[lev][MapFacType::v_y]->const_array(mfi);
68 
69  Array4<Real> r_hse_arr = r_hse.array(mfi);
70  Array4<Real> p_hse_arr = p_hse.array(mfi);
71 
72  prob->init_custom_pert(bx, xbx, ybx, zbx, cons_arr, cons_pert_arr,
73  xvel_pert_arr, yvel_pert_arr, zvel_pert_arr,
74  r_hse_arr, p_hse_arr, z_nd_arr, z_cc_arr,
75  geom[lev].data(), mf_m, mf_u, mf_v,
76  solverChoice);
77  } //mfi
78 
79  // Add problem-specific perturbation to background flow if not doing anelastic with fixed-in-time density
81  MultiFab::Add(lev_new[Vars::cons], cons_pert, Rho_comp, Rho_comp, 1, cons_pert.nGrow());
82  }
83  MultiFab::Add(lev_new[Vars::cons], cons_pert, RhoTheta_comp, RhoTheta_comp, 1, cons_pert.nGrow());
84  MultiFab::Add(lev_new[Vars::cons], cons_pert, RhoScalar_comp,RhoScalar_comp,NSCALARS, cons_pert.nGrow());
85 
86  // RhoKE is relevant if using Deardorff with LES, k-equation for RANS, or MYNN with PBL
87  if (solverChoice.turbChoice[lev].use_tke) {
88  MultiFab::Add(lev_new[Vars::cons], cons_pert, RhoKE_comp, RhoKE_comp, 1, cons_pert.nGrow());
89  }
90 
91  if (solverChoice.moisture_type != MoistureType::None) {
92  int qstate_size = micro->Get_Qstate_Size();
93  for (int q_offset(0); q_offset<qstate_size; ++q_offset) {
94  int q_idx = RhoQ1_comp+q_offset;
95  MultiFab::Add(lev_new[Vars::cons], cons_pert, q_idx, q_idx, 1, cons_pert.nGrow());
96  }
97  }
98 
99  MultiFab::Add(lev_new[Vars::xvel], xvel_pert, 0, 0, 1, xvel_pert.nGrowVect());
100  MultiFab::Add(lev_new[Vars::yvel], yvel_pert, 0, 0, 1, yvel_pert.nGrowVect());
101  MultiFab::Add(lev_new[Vars::zvel], zvel_pert, 0, 0, 1, zvel_pert.nGrowVect());
102 }
const Box xbx
Definition: ERF_DiffSetup.H:21
bool fixed_density
Definition: ERF_DataStruct.H:721
Here is the call graph for this function:

◆ init_Dirichlet_bc_data()

void ERF::init_Dirichlet_bc_data ( const std::string  input_file)
private
653 {
654  const bool use_terrain = (solverChoice.terrain_type != TerrainType::None);
655 
656  // Read the dirichlet_input file
657  Print() << "dirichlet_input file location : " << input_file << std::endl;
658  std::ifstream input_reader(input_file);
659  if (!input_reader.is_open()) {
660  amrex::Abort("Error opening the dirichlet_input file.\n");
661  }
662 
663  Print() << "Successfully opened the dirichlet_input file. Now reading... " << std::endl;
664  std::string line;
665 
666  // Size of Ninp (number of z points in input file)
667  Vector<Real> z_inp_tmp, u_inp_tmp, v_inp_tmp, w_inp_tmp, th_inp_tmp;
668 
669  // Top and bot for domain
670  const int klo = geom[0].Domain().smallEnd()[2];
671  const int khi = geom[0].Domain().bigEnd()[2];
672  const Real zbot = (use_terrain) ? zlevels_stag[0][klo] : geom[0].ProbLo(2);
673  const Real ztop = (use_terrain) ? zlevels_stag[0][khi+1] : geom[0].ProbHi(2);
674 
675  // Flag if theta input
676  Real th_init = -300.0;
677  bool th_read{false};
678 
679  // Add surface
680  z_inp_tmp.push_back(zbot); // height above sea level [m]
681  u_inp_tmp.push_back(0.);
682  v_inp_tmp.push_back(0.);
683  w_inp_tmp.push_back(0.);
684  th_inp_tmp.push_back(th_init);
685 
686  // Read the vertical profile at each given height
687  Real z, u, v, w, th;
688  while(std::getline(input_reader, line)) {
689  std::istringstream iss_z(line);
690 
691  Vector<Real> rval_v;
692  Real rval;
693  while (iss_z >> rval) {
694  rval_v.push_back(rval);
695  }
696  z = rval_v[0];
697  u = rval_v[1];
698  v = rval_v[2];
699  w = rval_v[3];
700 
701  // Format without theta
702  if (rval_v.size() == 4) {
703  if (z == zbot) {
704  u_inp_tmp[0] = u;
705  v_inp_tmp[0] = v;
706  w_inp_tmp[0] = w;
707  } else {
708  AMREX_ALWAYS_ASSERT(z > z_inp_tmp[z_inp_tmp.size()-1]); // sounding is increasing in height
709  z_inp_tmp.push_back(z);
710  u_inp_tmp.push_back(u);
711  v_inp_tmp.push_back(v);
712  w_inp_tmp.push_back(w);
713  if (z >= ztop) break;
714  }
715  } else if (rval_v.size() == 5) {
716  th_read = true;
717  th = rval_v[4];
718  if (z == zbot) {
719  u_inp_tmp[0] = u;
720  v_inp_tmp[0] = v;
721  w_inp_tmp[0] = w;
722  th_inp_tmp[0] = th;
723  } else {
724  AMREX_ALWAYS_ASSERT(z > z_inp_tmp[z_inp_tmp.size()-1]); // sounding is increasing in height
725  z_inp_tmp.push_back(z);
726  u_inp_tmp.push_back(u);
727  v_inp_tmp.push_back(v);
728  w_inp_tmp.push_back(w);
729  th_inp_tmp.push_back(th);
730  if (z >= ztop) break;
731  }
732  } else {
733  Abort("Unknown inflow file format!");
734  }
735  }
736 
737  // Ensure we set a reasonable theta surface
738  if (th_read) {
739  if (th_inp_tmp[0] == th_init) {
740  Real slope = (th_inp_tmp[2] - th_inp_tmp[1]) / (z_inp_tmp[2] - z_inp_tmp[1]);
741  Real dz = z_inp_tmp[0] - z_inp_tmp[1];
742  th_inp_tmp[0] = slope * dz + th_inp_tmp[1];
743  }
744  }
745 
746  amrex::Print() << "Successfully read and interpolated the dirichlet_input file..." << std::endl;
747  input_reader.close();
748 
749  for (int lev = 0; lev <= max_level; lev++) {
750 
751  const int Nz = geom[lev].Domain().size()[2];
752  const Real dz = geom[lev].CellSize()[2];
753 
754  // Size of Nz (domain grid)
755  Vector<Real> zcc_inp(Nz );
756  Vector<Real> znd_inp(Nz+1);
757  Vector<Real> u_inp(Nz ); xvel_bc_data[lev].resize(Nz ,0.0);
758  Vector<Real> v_inp(Nz ); yvel_bc_data[lev].resize(Nz ,0.0);
759  Vector<Real> w_inp(Nz+1); zvel_bc_data[lev].resize(Nz+1,0.0);
760  Vector<Real> th_inp;
761  if (th_read) {
762  th_inp.resize(Nz);
763  th_bc_data[lev].resize(Nz, 0.0);
764  }
765 
766  // At this point, we have an input from zbot up to
767  // z_inp_tmp[N-1] >= ztop. Now, interpolate to grid level 0 heights
768  const int Ninp = z_inp_tmp.size();
769  for (int k(0); k<Nz; ++k) {
770  zcc_inp[k] = (use_terrain) ? 0.5 * (zlevels_stag[lev][k] + zlevels_stag[lev][k+1])
771  : zbot + (k + 0.5) * dz;
772  znd_inp[k] = (use_terrain) ? zlevels_stag[lev][k+1] : zbot + (k) * dz;
773  u_inp[k] = interpolate_1d(z_inp_tmp.dataPtr(), u_inp_tmp.dataPtr(), zcc_inp[k], Ninp);
774  v_inp[k] = interpolate_1d(z_inp_tmp.dataPtr(), v_inp_tmp.dataPtr(), zcc_inp[k], Ninp);
775  w_inp[k] = interpolate_1d(z_inp_tmp.dataPtr(), w_inp_tmp.dataPtr(), znd_inp[k], Ninp);
776  if (th_read) {
777  th_inp[k] = interpolate_1d(z_inp_tmp.dataPtr(), th_inp_tmp.dataPtr(), zcc_inp[k], Ninp);
778  }
779  }
780  znd_inp[Nz] = ztop;
781  w_inp[Nz] = interpolate_1d(z_inp_tmp.dataPtr(), w_inp_tmp.dataPtr(), ztop, Ninp);
782 
783  // Copy host data to the device
784  Gpu::copy(Gpu::hostToDevice, u_inp.begin(), u_inp.end(), xvel_bc_data[lev].begin());
785  Gpu::copy(Gpu::hostToDevice, v_inp.begin(), v_inp.end(), yvel_bc_data[lev].begin());
786  Gpu::copy(Gpu::hostToDevice, w_inp.begin(), w_inp.end(), zvel_bc_data[lev].begin());
787  if (th_read) {
788  Gpu::copy(Gpu::hostToDevice, th_inp.begin(), th_inp.end(), th_bc_data[lev].begin());
789  }
790 
791  // NOTE: These device vectors are passed to the PhysBC constructors when that
792  // class is instantiated in ERF_MakeNewArrays.cpp.
793  } // lev
794 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real interpolate_1d(const amrex::Real *alpha, const amrex::Real *beta, const amrex::Real alpha_interp, const int alpha_size)
Definition: ERF_Interpolation_1D.H:12
Here is the call graph for this function:

◆ init_from_hse()

void ERF::init_from_hse ( int  lev)

Initialize the background flow to have the calculated HSE density and rho*theta calculated from the HSE pressure. In general, the hydrostatically balanced density and pressure (r_hse and p_hse from base_state) used here may be calculated through a solver path such as:

ERF::initHSE(lev)

  • call prob->erf_init_dens_hse(...)
    • call Problem::init_isentropic_hse(...), to simultaneously calculate r_hse and p_hse with Newton iteration – assuming constant theta
    • save r_hse
  • call ERF::enforce_hse(...), calculates p_hse from saved r_hse (redundant, but needed because p_hse is not necessarily calculated by the Problem implementation) and pi_hse and th_hse – note: this pressure does not exactly match the p_hse from before because what is calculated by init_isentropic_hse comes from the EOS whereas what is calculated here comes from the hydro- static equation
Parameters
levInteger specifying the current level
33 {
34  auto& lev_new = vars_new[lev];
35 
36  MultiFab r_hse(base_state[lev], make_alias, BaseState::r0_comp, 1);
37  MultiFab p_hse(base_state[lev], make_alias, BaseState::p0_comp, 1);
38 
39 #ifdef _OPENMP
40 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
41 #endif
42  for (MFIter mfi(lev_new[Vars::cons], TileNoZ()); mfi.isValid(); ++mfi)
43  {
44  const Box &gbx = mfi.growntilebox(1);
45  const Array4<Real >& cons_arr = lev_new[Vars::cons].array(mfi);
46  const Array4<Real const>& r_hse_arr = r_hse.const_array(mfi);
47  const Array4<Real const>& p_hse_arr = p_hse.const_array(mfi);
48 
49  ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
50  {
51  cons_arr(i,j,k,Rho_comp) = r_hse_arr(i,j,k);
52  cons_arr(i,j,k,RhoTheta_comp) = getRhoThetagivenP(p_hse_arr(i,j,k));
53  });
54  } //mfi
55 }
Here is the call graph for this function:

◆ init_from_input_sounding()

void ERF::init_from_input_sounding ( int  lev)

High level wrapper for initializing scalar and velocity level data from input sounding data.

Parameters
levInteger specifying the current level
52 {
53  // We only want to read the file once -- here we fill one FArrayBox (per variable) that spans the domain
54  if (lev == 0) {
56  Error("input_sounding file name must be provided via input");
57  }
58 
60 
61  // this will interpolate the input profiles to the nominal height levels
62  // (ranging from 0 to the domain top)
63  for (int n = 0; n < input_sounding_data.n_sounding_files; n++) {
65  }
66 
67  // this will calculate the hydrostatically balanced density and pressure
68  // profiles following WRF ideal.exe
70 
71  } else {
72  //
73  // We need to do this interp from coarse level in order to set the values of
74  // the base state inside the domain but outside of the fine region
75  //
76  base_state[lev-1].FillBoundary(geom[lev-1].periodicity());
77  //
78  // NOTE: this interpolater assumes that ALL ghost cells of the coarse MultiFab
79  // have been pre-filled - this includes ghost cells both inside and outside
80  // the domain
81  //
82  InterpFromCoarseLevel(base_state[lev], base_state[lev].nGrowVect(),
83  IntVect(0,0,0), // do not fill ghost cells outside the domain
84  base_state[lev-1], 0, 0, base_state[lev].nComp(),
85  geom[lev-1], geom[lev],
86  refRatio(lev-1), &cell_cons_interp,
88 
89  // We need to do this here because the interpolation above may leave corners unfilled
90  // when the corners need to be filled by, for example, reflection of the fine ghost
91  // cell outside the fine region but inide the domain.
92  (*physbcs_base[lev])(base_state[lev],0,base_state[lev].nComp(),base_state[lev].nGrowVect());
93  }
94 
95  auto& lev_new = vars_new[lev];
96 
97  // update if init_sounding_ideal == true
98  MultiFab r_hse (base_state[lev], make_alias, BaseState::r0_comp, 1);
99  MultiFab p_hse (base_state[lev], make_alias, BaseState::p0_comp, 1);
100  MultiFab pi_hse(base_state[lev], make_alias, BaseState::pi0_comp, 1);
101  MultiFab th_hse(base_state[lev], make_alias, BaseState::th0_comp, 1);
102  MultiFab qv_hse(base_state[lev], make_alias, BaseState::qv0_comp, 1);
103 
104  const Real l_gravity = solverChoice.gravity;
105  const Real l_rdOcp = solverChoice.rdOcp;
106  const bool l_moist = (solverChoice.moisture_type != MoistureType::None);
107 
108 #ifdef _OPENMP
109 #pragma omp parallel if (Gpu::notInLaunchRegion())
110 #endif
111  for (MFIter mfi(lev_new[Vars::cons], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
112  const Box &bx = mfi.tilebox();
113  const auto &cons_arr = lev_new[Vars::cons].array(mfi);
114  const auto &xvel_arr = lev_new[Vars::xvel].array(mfi);
115  const auto &yvel_arr = lev_new[Vars::yvel].array(mfi);
116  const auto &zvel_arr = lev_new[Vars::zvel].array(mfi);
117  Array4<Real> r_hse_arr = r_hse.array(mfi);
118  Array4<Real> p_hse_arr = p_hse.array(mfi);
119  Array4<Real> pi_hse_arr = pi_hse.array(mfi);
120  Array4<Real> th_hse_arr = th_hse.array(mfi);
121  Array4<Real> qv_hse_arr = qv_hse.array(mfi);
122 
123  Array4<Real const> z_cc_arr = (z_phys_cc[lev]) ? z_phys_cc[lev]->const_array(mfi) : Array4<Real const>{};
124  Array4<Real const> z_nd_arr = (z_phys_nd[lev]) ? z_phys_nd[lev]->const_array(mfi) : Array4<Real const>{};
125 
127  {
128  // HSE will be initialized here, interpolated from values previously
129  // calculated by calc_rho_p()
131  bx, cons_arr,
132  r_hse_arr, p_hse_arr, pi_hse_arr, th_hse_arr, qv_hse_arr,
133  geom[lev].data(), z_cc_arr,
134  l_gravity, l_rdOcp, l_moist, input_sounding_data);
135  }
136  else
137  {
138  // HSE will be calculated later with call to initHSE
140  bx, cons_arr,
141  geom[lev].data(), z_cc_arr,
142  l_moist, input_sounding_data);
143  }
144 
146  bx, xvel_arr, yvel_arr, zvel_arr,
147  geom[lev].data(), z_nd_arr,
149 
150  } //mfi
151 }
void init_bx_scalars_from_input_sounding_hse(const Box &bx, Array4< Real > const &state, Array4< Real > const &r_hse_arr, Array4< Real > const &p_hse_arr, Array4< Real > const &pi_hse_arr, Array4< Real > const &th_hse_arr, Array4< Real > const &qv_hse_arr, GeometryData const &geomdata, Array4< const Real > const &z_cc_arr, const Real &l_gravity, const Real &l_rdOcp, const bool &l_moist, InputSoundingData const &inputSoundingData)
Definition: ERF_InitFromInputSounding.cpp:225
void init_bx_scalars_from_input_sounding(const Box &bx, Array4< Real > const &state, GeometryData const &geomdata, Array4< const Real > const &z_cc_arr, const bool &l_moist, InputSoundingData const &inputSoundingData)
Definition: ERF_InitFromInputSounding.cpp:163
void init_bx_velocities_from_input_sounding(const Box &bx, Array4< Real > const &x_vel, Array4< Real > const &y_vel, Array4< Real > const &z_vel, GeometryData const &geomdata, Array4< const Real > const &z_nd_arr, InputSoundingData const &inputSoundingData)
Definition: ERF_InitFromInputSounding.cpp:330
static bool init_sounding_ideal
Definition: ERF.H:1058
InputSoundingData input_sounding_data
Definition: ERF.H:657
@ rho0_bc_comp
Definition: ERF_IndexDefines.H:98
@ qv0_comp
Definition: ERF_IndexDefines.H:67
void resize_arrays()
Definition: ERF_InputSoundingData.H:60
int n_sounding_files
Definition: ERF_InputSoundingData.H:316
void read_from_file(const amrex::Geometry &geom, const amrex::Vector< amrex::Real > &zlevels_stag, int itime)
Definition: ERF_InputSoundingData.H:77
amrex::Vector< std::string > input_sounding_file
Definition: ERF_InputSoundingData.H:314
void calc_rho_p(int itime)
Definition: ERF_InputSoundingData.H:176
Here is the call graph for this function:

◆ init_geo_wind_profile()

void ERF::init_geo_wind_profile ( const std::string  input_file,
amrex::Vector< amrex::Real > &  u_geos,
amrex::Gpu::DeviceVector< amrex::Real > &  u_geos_d,
amrex::Vector< amrex::Real > &  v_geos,
amrex::Gpu::DeviceVector< amrex::Real > &  v_geos_d,
const amrex::Geometry &  lgeom,
const amrex::Vector< amrex::Real > &  zlev_stag 
)
private
17 {
18  const int klo = 0;
19  const int khi = lgeom.Domain().bigEnd()[AMREX_SPACEDIM-1];
20  const amrex::Real dz = lgeom.CellSize()[AMREX_SPACEDIM-1];
21 
22  const bool grid_stretch = (zlev_stag.size() > 0);
23  const Real zbot = (grid_stretch) ? zlev_stag[klo] : lgeom.ProbLo(AMREX_SPACEDIM-1);
24  const Real ztop = (grid_stretch) ? zlev_stag[khi+1] : lgeom.ProbHi(AMREX_SPACEDIM-1);
25 
26  amrex::Print() << "Reading geostrophic wind profile from " << input_file << std::endl;
27  std::ifstream profile_reader(input_file);
28  if(!profile_reader.is_open()) {
29  amrex::Error("Error opening the abl_geo_wind_table\n");
30  }
31 
32  // First, read the input data into temp vectors
33  std::string line;
34  Vector<Real> z_inp, Ug_inp, Vg_inp;
35  Real z, Ug, Vg;
36  amrex::Print() << "z Ug Vg" << std::endl;
37  while(std::getline(profile_reader, line)) {
38  std::istringstream iss(line);
39  iss >> z >> Ug >> Vg;
40  amrex::Print() << z << " " << Ug << " " << Vg << std::endl;
41  z_inp.push_back(z);
42  Ug_inp.push_back(Ug);
43  Vg_inp.push_back(Vg);
44  if (z >= ztop) break;
45  }
46 
47  const int Ninp = z_inp.size();
48  AMREX_ALWAYS_ASSERT(z_inp[0] <= zbot);
49  AMREX_ALWAYS_ASSERT(z_inp[Ninp-1] >= ztop);
50 
51  // Now, interpolate vectors to the cell centers
52  for (int k = 0; k <= khi; k++) {
53  z = (grid_stretch) ? 0.5 * (zlev_stag[k] + zlev_stag[k+1])
54  : zbot + (k + 0.5) * dz;
55  u_geos[k] = interpolate_1d(z_inp.dataPtr(), Ug_inp.dataPtr(), z, Ninp);
56  v_geos[k] = interpolate_1d(z_inp.dataPtr(), Vg_inp.dataPtr(), z, Ninp);
57  }
58 
59  // Copy from host version to device version
60  Gpu::copy(Gpu::hostToDevice, u_geos.begin(), u_geos.end(), u_geos_d.begin());
61  Gpu::copy(Gpu::hostToDevice, v_geos.begin(), v_geos.end(), v_geos_d.begin());
62 
63  profile_reader.close();
64 }
Here is the call graph for this function:

◆ init_only()

void ERF::init_only ( int  lev,
amrex::Real  time 
)
1465 {
1466  t_new[lev] = time;
1467  t_old[lev] = time - 1.e200;
1468 
1469  auto& lev_new = vars_new[lev];
1470  auto& lev_old = vars_old[lev];
1471 
1472  // Loop over grids at this level to initialize our grid data
1473  lev_new[Vars::cons].setVal(0.0); lev_old[Vars::cons].setVal(0.0);
1474  lev_new[Vars::xvel].setVal(0.0); lev_old[Vars::xvel].setVal(0.0);
1475  lev_new[Vars::yvel].setVal(0.0); lev_old[Vars::yvel].setVal(0.0);
1476  lev_new[Vars::zvel].setVal(0.0); lev_old[Vars::zvel].setVal(0.0);
1477 
1478  // Initialize background flow (optional)
1479  if (solverChoice.init_type == InitType::Input_Sounding) {
1480  // The base state is initialized by integrating vertically through the
1481  // input sounding, if the init_sounding_ideal flag is set; otherwise
1482  // it is set by initHSE()
1483 
1484  // The physbc's need the terrain but are needed for initHSE
1485  // We have already made the terrain in the call to init_zphys
1486  // in MakeNewLevelFromScratch
1487  make_physbcs(lev);
1488 
1489  // Now init the base state and the data itself
1491 
1492  if (init_sounding_ideal) {
1493  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(solverChoice.use_gravity,
1494  "Gravity should be on to be consistent with sounding initialization.");
1495  } else {
1496  initHSE();
1497  }
1498 
1499 #ifdef ERF_USE_NETCDF
1500  }
1501  else if (solverChoice.init_type == InitType::WRFInput)
1502  {
1503  // The base state is initialized from WRF wrfinput data, output by
1504  // ideal.exe or real.exe
1505  init_from_wrfinput(lev, *mf_C1H[lev], *mf_C2H[lev], *mf_MUB[lev]);
1506  if (lev==0) {
1507  if ((start_time > 0) && (start_time != t_new[lev])) {
1508  Print() << "Ignoring specified start_time="
1509  << std::setprecision(timeprecision) << start_time
1510  << std::endl;
1511  }
1512  start_time = t_new[lev];
1513  }
1514  use_datetime = true;
1515 
1516  // The physbc's need the terrain but are needed for initHSE
1517  if (!solverChoice.use_real_bcs) {
1518  make_physbcs(lev);
1519  }
1520  }
1521  else if (solverChoice.init_type == InitType::NCFile)
1522  {
1523  // The state is initialized by reading from a Netcdf file
1524  init_from_ncfile(lev);
1525 
1526  // The physbc's need the terrain but are needed for initHSE
1527  make_physbcs(lev);
1528  }
1529  else if (solverChoice.init_type == InitType::Metgrid)
1530  {
1531  // The base state is initialized from data output by WPS metgrid;
1532  // we will rebalance after interpolation
1533  init_from_metgrid(lev);
1534 #endif
1535  } else if (solverChoice.init_type == InitType::Uniform) {
1536  // Initialize a uniform background field and base state based on the
1537  // problem-specified reference density and temperature
1538 
1539  // The physbc's need the terrain but are needed for initHSE
1540  make_physbcs(lev);
1541 
1542  init_uniform(lev);
1543  initHSE(lev);
1544  } else {
1545  // No background flow initialization specified, initialize the
1546  // background field to be equal to the base state, calculated from the
1547  // problem-specific erf_init_dens_hse
1548 
1549  // The bc's need the terrain but are needed for initHSE
1550  make_physbcs(lev);
1551 
1552  // We will initialize the state from the background state so must set that first
1553  initHSE(lev);
1554  init_from_hse(lev);
1555  }
1556 
1557  // Add problem-specific flow features
1558  //
1559  // Notes:
1560  // - This calls init_custom_pert that is defined for each problem
1561  // - This may modify the base state
1562  // - The fields set by init_custom_pert are **perturbations** to the
1563  // background flow set based on init_type
1564  if (solverChoice.init_type != InitType::NCFile) {
1565  init_custom(lev);
1566  }
1567 
1568  // Ensure that the face-based data are the same on both sides of a periodic domain.
1569  // The data associated with the lower grid ID is considered the correct value.
1570  lev_new[Vars::xvel].OverrideSync(geom[lev].periodicity());
1571  lev_new[Vars::yvel].OverrideSync(geom[lev].periodicity());
1572  lev_new[Vars::zvel].OverrideSync(geom[lev].periodicity());
1573 
1574  if(solverChoice.spongeChoice.sponge_type == "input_sponge"){
1575  input_sponge(lev);
1576  }
1577 
1578  // Initialize turbulent perturbation
1579  if (solverChoice.pert_type == PerturbationType::Source ||
1580  solverChoice.pert_type == PerturbationType::Direct ||
1581  solverChoice.pert_type == PerturbationType::CPM) {
1582  turbPert_update(lev, 0.);
1583  turbPert_amplitude(lev);
1584  }
1585 }
const int timeprecision
Definition: ERF.H:887
void init_from_input_sounding(int lev)
Definition: ERF_InitFromInputSounding.cpp:51
void init_custom(int lev)
Definition: ERF_InitCustom.cpp:26
void init_from_hse(int lev)
Definition: ERF_InitFromHSE.cpp:32
void initHSE()
Initialize HSE.
Definition: ERF_Init1D.cpp:142
void turbPert_update(const int lev, const amrex::Real dt)
Definition: ERF_InitTurbPert.cpp:12
void input_sponge(int lev)
Definition: ERF_InitSponge.cpp:17
void make_physbcs(int lev)
Definition: ERF_MakeNewArrays.cpp:652
void init_uniform(int lev)
Definition: ERF_InitUniform.cpp:17
void turbPert_amplitude(const int lev)
Definition: ERF_InitTurbPert.cpp:32
bool use_gravity
Definition: ERF_DataStruct.H:731
static InitType init_type
Definition: ERF_DataStruct.H:694

◆ init_stuff()

void ERF::init_stuff ( int  lev,
const amrex::BoxArray &  ba,
const amrex::DistributionMapping &  dm,
amrex::Vector< amrex::MultiFab > &  lev_new,
amrex::Vector< amrex::MultiFab > &  lev_old,
amrex::MultiFab &  tmp_base_state,
std::unique_ptr< amrex::MultiFab > &  tmp_zphys_nd 
)
private
28 {
29  // ********************************************************************************************
30  // Base state holds r_0, pres_0, pi_0, th_0 (in that order)
31  //
32  // Here is where we set 3 ghost cells for the base state!
33  //
34  // ********************************************************************************************
35  tmp_base_state.define(ba,dm,BaseState::num_comps,3);
36  tmp_base_state.setVal(0.);
37 
38  if (solverChoice.terrain_type == TerrainType::MovingFittedMesh) {
39  base_state_new[lev].define(ba,dm,BaseState::num_comps,base_state[lev].nGrowVect());
40  base_state_new[lev].setVal(0.);
41  }
42 
43  // ********************************************************************************************
44  // Allocate terrain arrays
45  // ********************************************************************************************
46 
47  BoxArray ba_nd(ba);
48  ba_nd.surroundingNodes();
49 
50  // NOTE: this is where we actually allocate z_phys_nd -- but here it's called "tmp_zphys_nd"
51  // We need this to be one greater than the ghost cells to handle levels > 0
52 
53  int ngrow = ComputeGhostCells(solverChoice) + 2;
54  tmp_zphys_nd = std::make_unique<MultiFab>(ba_nd,dm,1,IntVect(ngrow,ngrow,ngrow));
55 
56  z_phys_cc[lev] = std::make_unique<MultiFab>(ba,dm,1,1);
57  init_default_zphys(lev, geom[lev], *tmp_zphys_nd, *z_phys_cc[lev]);
58 
59  if (solverChoice.terrain_type == TerrainType::MovingFittedMesh)
60  {
61  detJ_cc_new[lev] = std::make_unique<MultiFab>(ba,dm,1,1);
62  detJ_cc_src[lev] = std::make_unique<MultiFab>(ba,dm,1,1);
63 
64  ax_src[lev] = std::make_unique<MultiFab>(convert(ba,IntVect(1,0,0)),dm,1,1);
65  ay_src[lev] = std::make_unique<MultiFab>(convert(ba,IntVect(0,1,0)),dm,1,1);
66  az_src[lev] = std::make_unique<MultiFab>(convert(ba,IntVect(0,0,1)),dm,1,1);
67 
68  z_t_rk[lev] = std::make_unique<MultiFab>( convert(ba, IntVect(0,0,1)), dm, 1, 1 );
69 
70  z_phys_nd_new[lev] = std::make_unique<MultiFab>(ba_nd,dm,1,IntVect(ngrow,ngrow,ngrow));
71  z_phys_nd_src[lev] = std::make_unique<MultiFab>(ba_nd,dm,1,IntVect(ngrow,ngrow,ngrow));
72  z_phys_cc_src[lev] = std::make_unique<MultiFab>(ba,dm,1,1);
73  }
74  else
75  {
76  z_phys_nd_new[lev] = nullptr;
77  detJ_cc_new[lev] = nullptr;
78 
79  z_phys_nd_src[lev] = nullptr;
80  z_phys_cc_src[lev] = nullptr;
81  detJ_cc_src[lev] = nullptr;
82 
83  z_t_rk[lev] = nullptr;
84  }
85 
86  if (SolverChoice::terrain_type == TerrainType::ImmersedForcing)
87  {
88  terrain_blanking[lev] = std::make_unique<MultiFab>(ba,dm,1,ngrow);
89  terrain_blanking[lev]->setVal(1.0);
90  }
91 
92  // We use these area arrays regardless of terrain, EB or none of the above
93  detJ_cc[lev] = std::make_unique<MultiFab>(ba,dm,1,1);
94  ax[lev] = std::make_unique<MultiFab>(convert(ba,IntVect(1,0,0)),dm,1,1);
95  ay[lev] = std::make_unique<MultiFab>(convert(ba,IntVect(0,1,0)),dm,1,1);
96  az[lev] = std::make_unique<MultiFab>(convert(ba,IntVect(0,0,1)),dm,1,1);
97 
98  detJ_cc[lev]->setVal(1.0);
99  ax[lev]->setVal(1.0);
100  ay[lev]->setVal(1.0);
101  az[lev]->setVal(1.0);
102 
103  // ********************************************************************************************
104  // Create wall distance array for RANS modeling
105  // ********************************************************************************************
106  if (solverChoice.turbChoice[lev].rans_type != RANSType::None) {
107  walldist[lev] = std::make_unique<MultiFab>(ba,dm,1,1);
108  walldist[lev]->setVal(1e23);
109  } else {
110  walldist[lev] = nullptr;
111  }
112 
113  // ********************************************************************************************
114  // These are the persistent containers for the old and new data
115  // ********************************************************************************************
116  int ncomp;
117  if (lev > 0) {
118  ncomp = vars_new[lev-1][Vars::cons].nComp();
119  } else {
120  int n_qstate = micro->Get_Qstate_Size();
121  ncomp = NDRY + NSCALARS + n_qstate;
122  }
123 
124  // ********************************************************************************************
125  // The number of ghost cells for density must be 1 greater than that for velocity
126  // so that we can go back in forth between velocity and momentum on all faces
127  // ********************************************************************************************
128  int ngrow_state = ComputeGhostCells(solverChoice) + 1;
129  int ngrow_vels = ComputeGhostCells(solverChoice);
130 
131  // ********************************************************************************************
132  // New solution data containers
133  // ********************************************************************************************
134  lev_new[Vars::cons].define(ba, dm, ncomp, ngrow_state);
135  lev_old[Vars::cons].define(ba, dm, ncomp, ngrow_state);
136 
137  lev_new[Vars::xvel].define(convert(ba, IntVect(1,0,0)), dm, 1, ngrow_vels);
138  lev_old[Vars::xvel].define(convert(ba, IntVect(1,0,0)), dm, 1, ngrow_vels);
139 
140  lev_new[Vars::yvel].define(convert(ba, IntVect(0,1,0)), dm, 1, ngrow_vels);
141  lev_old[Vars::yvel].define(convert(ba, IntVect(0,1,0)), dm, 1, ngrow_vels);
142 
143  gradp[lev][GpVars::gpx].define(convert(ba, IntVect(1,0,0)), dm, 1, 1); gradp[lev][GpVars::gpx].setVal(0.);
144  gradp[lev][GpVars::gpy].define(convert(ba, IntVect(0,1,0)), dm, 1, 1); gradp[lev][GpVars::gpy].setVal(0.);
145  gradp[lev][GpVars::gpz].define(convert(ba, IntVect(0,0,1)), dm, 1, 1); gradp[lev][GpVars::gpz].setVal(0.);
146 
147  // Note that we need the ghost cells in the z-direction if we are doing any
148  // kind of domain decomposition in the vertical (at level 0 or above)
149  lev_new[Vars::zvel].define(convert(ba, IntVect(0,0,1)), dm, 1, ngrow_vels);
150  lev_old[Vars::zvel].define(convert(ba, IntVect(0,0,1)), dm, 1, ngrow_vels);
151 
153  pp_inc[lev].define(ba, dm, 1, 1);
154  pp_inc[lev].setVal(0.0);
155  }
156 
157  // ********************************************************************************************
158  // These are just used for scratch in the time integrator but we might as well define them here
159  // ********************************************************************************************
160  rU_old[lev].define(convert(ba, IntVect(1,0,0)), dm, 1, ngrow_vels);
161  rU_new[lev].define(convert(ba, IntVect(1,0,0)), dm, 1, ngrow_vels);
162 
163  rV_old[lev].define(convert(ba, IntVect(0,1,0)), dm, 1, ngrow_vels);
164  rV_new[lev].define(convert(ba, IntVect(0,1,0)), dm, 1, ngrow_vels);
165 
166  rW_old[lev].define(convert(ba, IntVect(0,0,1)), dm, 1, ngrow_vels);
167  rW_new[lev].define(convert(ba, IntVect(0,0,1)), dm, 1, ngrow_vels);
168 
169  if (lev > 0) {
170  //xmom_crse_rhs[lev].define(convert(ba, IntVect(1,0,0)), dm, 1, IntVect{0});
171  //ymom_crse_rhs[lev].define(convert(ba, IntVect(0,1,0)), dm, 1, IntVect{0});
172  zmom_crse_rhs[lev].define(convert(ba, IntVect(0,0,1)), dm, 1, IntVect{0});
173  }
174 
175  // We do this here just so they won't be undefined in the initial FillPatch
176  rU_old[lev].setVal(1.2e21);
177  rV_old[lev].setVal(3.4e22);
178  rW_old[lev].setVal(5.6e23);
179  rU_new[lev].setVal(1.2e21);
180  rV_new[lev].setVal(3.4e22);
181  rW_new[lev].setVal(5.6e23);
182 
183  // ********************************************************************************************
184  // These are just time averaged fields for diagnostics
185  // ********************************************************************************************
186 
187  // NOTE: We are not completing a fillpach call on the time averaged data;
188  // which would copy on intersection and interpolate from coarse.
189  // Therefore, we are restarting the averaging when the ba changes,
190  // this may give poor statistics for dynamic mesh refinement.
191  vel_t_avg[lev] = nullptr;
193  vel_t_avg[lev] = std::make_unique<MultiFab>(ba, dm, 4, 0); // Each vel comp and the mag
194  vel_t_avg[lev]->setVal(0.0);
195  t_avg_cnt[lev] = 0.0;
196  }
197 
198  // ********************************************************************************************
199  // Initialize flux registers whenever we create/re-create a level
200  // ********************************************************************************************
201  if (solverChoice.coupling_type == CouplingType::TwoWay) {
202  if (lev == 0) {
203  advflux_reg[0] = nullptr;
204  } else {
205  int ncomp_reflux = vars_new[0][Vars::cons].nComp();
206  advflux_reg[lev] = new YAFluxRegister(ba , grids[lev-1],
207  dm , dmap[lev-1],
208  geom[lev], geom[lev-1],
209  ref_ratio[lev-1], lev, ncomp_reflux);
210  }
211  }
212 
213  // ********************************************************************************************
214  // Define Theta_prim storage if using surface_layer BC
215  // ********************************************************************************************
216  if (phys_bc_type[Orientation(Direction::z,Orientation::low)] == ERF_BC::surface_layer) {
217  Theta_prim[lev] = std::make_unique<MultiFab>(ba,dm,1,IntVect(ngrow_state,ngrow_state,1));
218  if (solverChoice.moisture_type != MoistureType::None) {
219  Qv_prim[lev] = std::make_unique<MultiFab>(ba,dm,1,IntVect(ngrow_state,ngrow_state,1));
220  Qr_prim[lev] = std::make_unique<MultiFab>(ba,dm,1,IntVect(ngrow_state,ngrow_state,1));
221  } else {
222  Qv_prim[lev] = nullptr;
223  Qr_prim[lev] = nullptr;
224  }
225  } else {
226  Theta_prim[lev] = nullptr;
227  Qv_prim[lev] = nullptr;
228  Qr_prim[lev] = nullptr;
229  }
230 
231  // ********************************************************************************************
232  // Map factors
233  // ********************************************************************************************
234  BoxList bl2d_mf = ba.boxList();
235  for (auto& b : bl2d_mf) {
236  b.setRange(2,0);
237  }
238  BoxArray ba2d_mf(std::move(bl2d_mf));
239 
240  mapfac[lev].resize(MapFacType::num);
241  mapfac[lev][MapFacType::m_x] = std::make_unique<MultiFab>(ba2d_mf,dm,1,3);
242  mapfac[lev][MapFacType::u_x] = std::make_unique<MultiFab>(convert(ba2d_mf,IntVect(1,0,0)),dm,1,3);
243  mapfac[lev][MapFacType::v_x] = std::make_unique<MultiFab>(convert(ba2d_mf,IntVect(0,1,0)),dm,1,3);
244 
245 #if 0
246  // For now we comment this out to avoid CI failures but we will need to re-enable
247  // this if using non-conformal mappings
249  mapfac[lev][MapFacType::m_y] = std::make_unique<MultiFab>(ba2d_mf,dm,1,3);
250  }
252  mapfac[lev][MapFacType::u_y] = std::make_unique<MultiFab>(convert(ba2d_mf,IntVect(1,0,0)),dm,1,3);
253  }
255  mapfac[lev][MapFacType::v_y] = std::make_unique<MultiFab>(convert(ba2d_mf,IntVect(0,1,0)),dm,1,3);
256  }
257 #endif
258 
260  for (int i = 0; i < 3; i++) {
261  mapfac[lev][i]->setVal(0.5);
262  }
263  for (int i = 3; i < mapfac[lev].size(); i++) {
264  mapfac[lev][i]->setVal(0.25);
265  }
266  } else {
267  for (int i = 0; i < mapfac[lev].size(); i++) {
268  mapfac[lev][i]->setVal(1.0);
269  }
270  }
271 
272  // ********************************************************************************************
273  // Build 1D BA and 2D BA
274  // ********************************************************************************************
275  BoxList bl1d = ba.boxList();
276  for (auto& b : bl1d) {
277  b.setRange(0,0);
278  b.setRange(1,0);
279  }
280  ba1d[lev] = BoxArray(std::move(bl1d));
281 
282  // Build 2D BA
283  BoxList bl2d = ba.boxList();
284  for (auto& b : bl2d) {
285  b.setRange(2,0);
286  }
287  ba2d[lev] = BoxArray(std::move(bl2d));
288 
289  IntVect ng = vars_new[lev][Vars::cons].nGrowVect();
290 
291  mf_C1H[lev] = std::make_unique<MultiFab>(ba1d[lev],dm,1,ng);
292  mf_C2H[lev] = std::make_unique<MultiFab>(ba1d[lev],dm,1,ng);
293  mf_MUB[lev] = std::make_unique<MultiFab>(ba2d[lev],dm,1,ng);
294 
295  //*********************************************************
296  // Variables for Fitch model for windfarm parametrization
297  //*********************************************************
298 #if defined(ERF_USE_WINDFARM)
299  if (solverChoice.windfarm_type == WindFarmType::Fitch){
300  vars_windfarm[lev].define(ba, dm, 5, ngrow_state); // V, dVabsdt, dudt, dvdt, dTKEdt
301  }
302  if (solverChoice.windfarm_type == WindFarmType::EWP){
303  vars_windfarm[lev].define(ba, dm, 3, ngrow_state); // dudt, dvdt, dTKEdt
304  }
305  if (solverChoice.windfarm_type == WindFarmType::SimpleAD) {
306  vars_windfarm[lev].define(ba, dm, 2, ngrow_state);// dudt, dvdt
307  }
308  if (solverChoice.windfarm_type == WindFarmType::GeneralAD) {
309  vars_windfarm[lev].define(ba, dm, 3, ngrow_state);// dudt, dvdt, dwdt
310  }
311  Nturb[lev].define(ba, dm, 1, ngrow_state); // Number of turbines in a cell
312  SMark[lev].define(ba, dm, 2, 1); // Free stream velocity/source term
313  // sampling marker in a cell - 2 components
314 #endif
315 
316 
317 #ifdef ERF_USE_WW3_COUPLING
318  // create a new BoxArray and DistributionMapping for a MultiFab with 1 box
319  BoxArray ba_onegrid(geom[lev].Domain());
320  BoxList bl2d_onegrid = ba_onegrid.boxList();
321  for (auto& b : bl2d_onegrid) {
322  b.setRange(2,0);
323  }
324  BoxArray ba2d_onegrid(std::move(bl2d_onegrid));
325  Vector<int> pmap;
326  pmap.resize(1);
327  pmap[0]=0;
328  DistributionMapping dm_onegrid(ba2d_onegrid);
329  dm_onegrid.define(pmap);
330 
331  Hwave_onegrid[lev] = std::make_unique<MultiFab>(ba2d_onegrid,dm_onegrid,1,IntVect(1,1,0));
332  Lwave_onegrid[lev] = std::make_unique<MultiFab>(ba2d_onegrid,dm_onegrid,1,IntVect(1,1,0));
333 
334  BoxList bl2d_wave = ba.boxList();
335  for (auto& b : bl2d_wave) {
336  b.setRange(2,0);
337  }
338  BoxArray ba2d_wave(std::move(bl2d_wave));
339 
340  Hwave[lev] = std::make_unique<MultiFab>(ba2d_wave,dm,1,IntVect(3,3,0));
341  Lwave[lev] = std::make_unique<MultiFab>(ba2d_wave,dm,1,IntVect(3,3,0));
342 
343  std::cout<<ba_onegrid<<std::endl;
344  std::cout<<ba2d_onegrid<<std::endl;
345  std::cout<<dm_onegrid<<std::endl;
346 #endif
347 
348 
349  //*********************************************************
350  // Radiation heating source terms
351  //*********************************************************
352  if (solverChoice.rad_type != RadiationType::None || solverChoice.lsm_type != LandSurfaceType::None)
353  {
354  qheating_rates[lev] = std::make_unique<MultiFab>(ba, dm, 2, ngrow_state);
355  qheating_rates[lev]->setVal(0.);
356  }
357 
358  //*********************************************************
359  // Radiation fluxes for coupling to LSM
360  //*********************************************************
361 
362  // NOTE: Finer levels do not need to coincide with the bottom domain boundary
363  // at k=0. We make slabs here with the kmin for a given box. Therefore,
364  // care must be taken before applying these fluxes to an LSM model. For
365 
366  // Radiative fluxes for LSM
367  if (solverChoice.lsm_type != LandSurfaceType::None &&
368  solverChoice.rad_type != RadiationType::None)
369  {
370  BoxList m_bl = ba.boxList();
371  for (auto& b : m_bl) {
372  int kmin = b.smallEnd(2);
373  b.setRange(2,kmin);
374  }
375  BoxArray m_ba(std::move(m_bl));
376 
377  sw_lw_fluxes[lev] = std::make_unique<MultiFab>(m_ba, dm, 5, ngrow_state); // SW direct (2), SW diffuse (2), LW
378  solar_zenith[lev] = std::make_unique<MultiFab>(m_ba, dm, 2, ngrow_state);
379 
380  sw_lw_fluxes[lev]->setVal(0.);
381  solar_zenith[lev]->setVal(0.);
382  }
383 
384  //*********************************************************
385  // Turbulent perturbation region initialization
386  //*********************************************************
387  if (solverChoice.pert_type == PerturbationType::Source ||
388  solverChoice.pert_type == PerturbationType::Direct ||
389  solverChoice.pert_type == PerturbationType::CPM)
390  {
391  amrex::Box bnd_bx = ba.minimalBox();
393  turbPert.init_tpi(lev, bnd_bx.smallEnd(), bnd_bx.bigEnd(), geom[lev].CellSizeArray(),
394  ba, dm, ngrow_state, pp_prefix, refRatio(), max_level);
395  }
396 
397  //
398  // Define the land mask here and set it to all land by default
399  // NOTE: the logic below will BREAK if we have any grids not touching the bottom boundary
400  //
401  {
402  lmask_lev[lev].resize(1);
403  auto ngv = lev_new[Vars::cons].nGrowVect(); ngv[2] = 0;
404  BoxList bl2d_mask = ba.boxList();
405  for (auto& b : bl2d_mask) {
406  b.setRange(2,0);
407  }
408  BoxArray ba2d_mask(std::move(bl2d_mask));
409  lmask_lev[lev][0] = std::make_unique<iMultiFab>(ba2d_mask,dm,1,ngv);
410  lmask_lev[lev][0]->setVal(1);
411  lmask_lev[lev][0]->FillBoundary(geom[lev].periodicity());
412  }
413 
414  // Read in tables needed for windfarm simulations
415  // fill in Nturb multifab - number of turbines in each mesh cell
416  // write out the vtk files for wind turbine location and/or
417  // actuator disks
418  #ifdef ERF_USE_WINDFARM
419  //init_windfarm(lev);
420  #endif
421 }
@ num
Definition: ERF_DataStruct.H:22
#define NDRY
Definition: ERF_IndexDefines.H:13
void init_default_zphys(int, const Geometry &geom, MultiFab &z_phys_nd, MultiFab &z_phys_cc)
Definition: ERF_TerrainMetrics.cpp:15
static AMREX_FORCE_INLINE int ComputeGhostCells(const SolverChoice &sc)
Definition: ERF.H:1172
@ num_comps
Definition: ERF_IndexDefines.H:68
@ gpz
Definition: ERF_IndexDefines.H:152
@ gpy
Definition: ERF_IndexDefines.H:151
@ gpx
Definition: ERF_IndexDefines.H:150
bool test_mapfactor
Definition: ERF_DataStruct.H:726
void init_tpi_type(const PerturbationType &pert_type)
Definition: ERF_TurbPertStruct.H:28
void init_tpi(const int lev, const amrex::IntVect &valid_box_lo, const amrex::IntVect &valid_box_hi, const amrex::GpuArray< amrex::Real, 3 > dx, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm, const int ngrow_state, std::string pp_prefix, const amrex::Vector< amrex::IntVect > refRatio, const int max_level)
Definition: ERF_TurbPertStruct.H:45
Here is the call graph for this function:

◆ init_thin_body()

void ERF::init_thin_body ( int  lev,
const amrex::BoxArray &  ba,
const amrex::DistributionMapping &  dm 
)
607 {
608  //********************************************************************************************
609  // Thin immersed body
610  // *******************************************************************************************
611 #if 0
612  if ((solverChoice.advChoice.zero_xflux.size() > 0) ||
613  (solverChoice.advChoice.zero_yflux.size() > 0) ||
614  (solverChoice.advChoice.zero_zflux.size() > 0))
615  {
616  overset_imask[lev] = std::make_unique<iMultiFab>(ba,dm,1,0);
617  overset_imask[lev]->setVal(1); // == value is unknown (to be solved)
618  }
619 #endif
620 
621  if (solverChoice.advChoice.zero_xflux.size() > 0) {
622  amrex::Print() << "Setting up thin immersed body for "
623  << solverChoice.advChoice.zero_xflux.size() << " xfaces" << std::endl;
624  BoxArray ba_xf(ba);
625  ba_xf.surroundingNodes(0);
626  thin_xforce[lev] = std::make_unique<MultiFab>(ba_xf,dm,1,0);
627  thin_xforce[lev]->setVal(0.0);
628  xflux_imask[lev] = std::make_unique<iMultiFab>(ba_xf,dm,1,0);
629  xflux_imask[lev]->setVal(1);
630  for ( MFIter mfi(*xflux_imask[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
631  {
632  Array4<int> const& imask_arr = xflux_imask[lev]->array(mfi);
633  //Array4<int> const& imask_cell_arr = overset_imask[lev]->array(mfi);
634  Box xbx = mfi.nodaltilebox(0);
635  for (int iv=0; iv < solverChoice.advChoice.zero_xflux.size(); ++iv) {
636  const auto& faceidx = solverChoice.advChoice.zero_xflux[iv];
637  if ((faceidx[0] >= xbx.smallEnd(0)) && (faceidx[0] <= xbx.bigEnd(0)) &&
638  (faceidx[1] >= xbx.smallEnd(1)) && (faceidx[1] <= xbx.bigEnd(1)) &&
639  (faceidx[2] >= xbx.smallEnd(2)) && (faceidx[2] <= xbx.bigEnd(2)))
640  {
641  imask_arr(faceidx[0],faceidx[1],faceidx[2]) = 0;
642  //imask_cell_arr(faceidx[0],faceidx[1],faceidx[2]) = 0;
643  //imask_cell_arr(faceidx[0]-1,faceidx[1],faceidx[2]) = 0;
644  amrex::AllPrint() << " mask xface at " << faceidx << std::endl;
645  }
646  }
647  }
648  } else {
649  thin_xforce[lev] = nullptr;
650  xflux_imask[lev] = nullptr;
651  }
652 
653  if (solverChoice.advChoice.zero_yflux.size() > 0) {
654  amrex::Print() << "Setting up thin immersed body for "
655  << solverChoice.advChoice.zero_yflux.size() << " yfaces" << std::endl;
656  BoxArray ba_yf(ba);
657  ba_yf.surroundingNodes(1);
658  thin_yforce[lev] = std::make_unique<MultiFab>(ba_yf,dm,1,0);
659  thin_yforce[lev]->setVal(0.0);
660  yflux_imask[lev] = std::make_unique<iMultiFab>(ba_yf,dm,1,0);
661  yflux_imask[lev]->setVal(1);
662  for ( MFIter mfi(*yflux_imask[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
663  {
664  Array4<int> const& imask_arr = yflux_imask[lev]->array(mfi);
665  //Array4<int> const& imask_cell_arr = overset_imask[lev]->array(mfi);
666  Box ybx = mfi.nodaltilebox(1);
667  for (int iv=0; iv < solverChoice.advChoice.zero_yflux.size(); ++iv) {
668  const auto& faceidx = solverChoice.advChoice.zero_yflux[iv];
669  if ((faceidx[0] >= ybx.smallEnd(0)) && (faceidx[0] <= ybx.bigEnd(0)) &&
670  (faceidx[1] >= ybx.smallEnd(1)) && (faceidx[1] <= ybx.bigEnd(1)) &&
671  (faceidx[2] >= ybx.smallEnd(2)) && (faceidx[2] <= ybx.bigEnd(2)))
672  {
673  imask_arr(faceidx[0],faceidx[1],faceidx[2]) = 0;
674  //imask_cell_arr(faceidx[0],faceidx[1],faceidx[2]) = 0;
675  //imask_cell_arr(faceidx[0],faceidx[1]-1,faceidx[2]) = 0;
676  amrex::AllPrint() << " mask yface at " << faceidx << std::endl;
677  }
678  }
679  }
680  } else {
681  thin_yforce[lev] = nullptr;
682  yflux_imask[lev] = nullptr;
683  }
684 
685  if (solverChoice.advChoice.zero_zflux.size() > 0) {
686  amrex::Print() << "Setting up thin immersed body for "
687  << solverChoice.advChoice.zero_zflux.size() << " zfaces" << std::endl;
688  BoxArray ba_zf(ba);
689  ba_zf.surroundingNodes(2);
690  thin_zforce[lev] = std::make_unique<MultiFab>(ba_zf,dm,1,0);
691  thin_zforce[lev]->setVal(0.0);
692  zflux_imask[lev] = std::make_unique<iMultiFab>(ba_zf,dm,1,0);
693  zflux_imask[lev]->setVal(1);
694  for ( MFIter mfi(*zflux_imask[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi )
695  {
696  Array4<int> const& imask_arr = zflux_imask[lev]->array(mfi);
697  //Array4<int> const& imask_cell_arr = overset_imask[lev]->array(mfi);
698  Box zbx = mfi.nodaltilebox(2);
699  for (int iv=0; iv < solverChoice.advChoice.zero_zflux.size(); ++iv) {
700  const auto& faceidx = solverChoice.advChoice.zero_zflux[iv];
701  if ((faceidx[0] >= zbx.smallEnd(0)) && (faceidx[0] <= zbx.bigEnd(0)) &&
702  (faceidx[1] >= zbx.smallEnd(1)) && (faceidx[1] <= zbx.bigEnd(1)) &&
703  (faceidx[2] >= zbx.smallEnd(2)) && (faceidx[2] <= zbx.bigEnd(2)))
704  {
705  imask_arr(faceidx[0],faceidx[1],faceidx[2]) = 0;
706  //imask_cell_arr(faceidx[0],faceidx[1],faceidx[2]) = 0;
707  //imask_cell_arr(faceidx[0],faceidx[1],faceidx[2]-1) = 0;
708  amrex::AllPrint() << " mask zface at " << faceidx << std::endl;
709  }
710  }
711  }
712  } else {
713  thin_zforce[lev] = nullptr;
714  zflux_imask[lev] = nullptr;
715  }
716 }
amrex::Vector< amrex::IntVect > zero_yflux
Definition: ERF_AdvStruct.H:358
amrex::Vector< amrex::IntVect > zero_xflux
Definition: ERF_AdvStruct.H:357
amrex::Vector< amrex::IntVect > zero_zflux
Definition: ERF_AdvStruct.H:359

◆ init_uniform()

void ERF::init_uniform ( int  lev)
private

Use problem-specific reference density and temperature to set the background state to a uniform value.

Parameters
levInteger specifying the current level
18 {
19  auto& lev_new = vars_new[lev];
20  for (MFIter mfi(lev_new[Vars::cons], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
21  const Box &gbx = mfi.growntilebox(1);
22  const auto &cons_arr = lev_new[Vars::cons].array(mfi);
23  prob->init_uniform(gbx, cons_arr);
24  }
25 }

◆ init_zphys()

void ERF::init_zphys ( int  lev,
amrex::Real  time 
)
515 {
516  if (solverChoice.init_type != InitType::WRFInput && solverChoice.init_type != InitType::Metgrid)
517  {
518  if (lev > 0) {
519  //
520  // First interpolate from coarser level if there is one
521  // NOTE: this interpolater assumes that ALL ghost cells of the coarse MultiFab
522  // have been pre-filled - this includes ghost cells both inside and outside
523  // the domain
524  //
525  InterpFromCoarseLevel(*z_phys_nd[lev], z_phys_nd[lev]->nGrowVect(),
526  IntVect(0,0,0), // do not fill ghost cells outside the domain
527  *z_phys_nd[lev-1], 0, 0, 1,
528  geom[lev-1], geom[lev],
529  refRatio(lev-1), &node_bilinear_interp,
531  }
532 
533  int ngrow = ComputeGhostCells(solverChoice) + 2;
534  Box bx(surroundingNodes(Geom(lev).Domain())); bx.grow(ngrow);
535  FArrayBox terrain_fab(makeSlab(bx,2,0),1);
536 
537  //
538  // If we are using fitted mesh then we use the surface as defined above
539  // If we are not using fitted mesh but are using z_levels, we still need z_phys (for now)
540  // but we need to use a flat terrain for the mesh itself (the EB data has already been made
541  // from the correct terrain)
542  //
543  if (solverChoice.terrain_type != TerrainType::StaticFittedMesh &&
544  solverChoice.terrain_type != TerrainType::MovingFittedMesh) {
545  terrain_fab.template setVal<RunOn::Device>(0.0);
546  } else {
547  //
548  // Fill the values of the terrain height at k=0 only
549  //
550  prob->init_terrain_surface(geom[lev],terrain_fab,time);
551  }
552 
553  for (MFIter mfi(*z_phys_nd[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
554  {
555  Box isect = terrain_fab.box() & (*z_phys_nd[lev])[mfi].box();
556  if (!isect.isEmpty()) {
557  (*z_phys_nd[lev])[mfi].template copy<RunOn::Device>(terrain_fab,isect,0,isect,0,1);
558  }
559  }
560 
562 
563  z_phys_nd[lev]->FillBoundary(geom[lev].periodicity());
564 
565  if (solverChoice.terrain_type == TerrainType::ImmersedForcing) {
566  terrain_blanking[lev]->setVal(1.0);
567  MultiFab::Subtract(*terrain_blanking[lev], EBFactory(lev).getVolFrac(), 0, 0, 1, ngrow);
568  terrain_blanking[lev]->FillBoundary(geom[lev].periodicity());
569  }
570 
571  if (lev == 0) {
572  Real zmax = z_phys_nd[0]->max(0,0,false);
573  Real rel_diff = (zmax - zlevels_stag[0][zlevels_stag[0].size()-1]) / zmax;
574  if (rel_diff < 1.e-8) {
575  amrex::Print() << "max of zphys_nd " << zmax << std::endl;
576  amrex::Print() << "max of zlevels " << zlevels_stag[0][zlevels_stag[0].size()-1] << std::endl;
577  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(rel_diff < 1.e-8, "Terrain is taller than domain top!");
578  }
579  } // lev == 0
580 
581  } // init_type
582 }
void make_terrain_fitted_coords(int lev, const Geometry &geom, MultiFab &z_phys_nd, Vector< Real > const &z_levels_h, GpuArray< ERF_BC, AMREX_SPACEDIM *2 > &phys_bc_type)
Definition: ERF_TerrainMetrics.cpp:46
amrex::EBFArrayBoxFactory const & EBFactory(int lev) const noexcept
Definition: ERF.H:1448
Here is the call graph for this function:

◆ InitData()

void ERF::InitData ( )
690 {
691  BL_PROFILE_VAR("ERF::InitData()", InitData);
692  InitData_pre();
693  InitData_post();
694  BL_PROFILE_VAR_STOP(InitData);
695 }
void InitData_pre()
Definition: ERF.cpp:698
void InitData_post()
Definition: ERF.cpp:758
void InitData()
Definition: ERF.cpp:689

Referenced by main().

Here is the caller graph for this function:

◆ InitData_post()

void ERF::InitData_post ( )
759 {
760  if (restart_chkfile.empty()) {
761  //
762  // Make sure that detJ and z_phys_cc are the average of the data on a finer level if there is one
763  //
764  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
765  for (int crse_lev = finest_level-1; crse_lev >= 0; crse_lev--) {
766  average_down( *detJ_cc[crse_lev+1], *detJ_cc[crse_lev], 0, 1, refRatio(crse_lev));
767  average_down(*z_phys_cc[crse_lev+1], *z_phys_cc[crse_lev], 0, 1, refRatio(crse_lev));
768  }
769  }
770 
771  if (solverChoice.coupling_type == CouplingType::TwoWay) {
772  AverageDown();
773  }
774 
776  {
777  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(finest_level == 0,
778  "Thin immersed body with refinement not currently supported.");
779  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
780  amrex::Print() << "NOTE: Thin immersed body with non-constant dz has not been tested." << std::endl;
781  }
782  }
783 
784 #ifdef ERF_USE_PARTICLES
785  if (Microphysics::modelType(solverChoice.moisture_type) == MoistureModelType::Lagrangian) {
786  for (int lev = 0; lev <= finest_level; lev++) {
787  dynamic_cast<LagrangianMicrophysics&>(*micro).initParticles(z_phys_nd[lev]);
788  }
789  }
790 #endif
791 
792  } else { // Restart from a checkpoint
793 
794  restart();
795 
796  // Create the physbc objects for {cons, u, v, w, base state}
797  // We fill the additional base state ghost cells just in case we have read the old format
798  for (int lev(0); lev <= finest_level; ++lev) {
799  make_physbcs(lev);
800  (*physbcs_base[lev])(base_state[lev],0,base_state[lev].nComp(),base_state[lev].nGrowVect());
801  }
802 
804  for (int lev(0); lev <= finest_level; ++lev) {
805  m_forest_drag[lev]->define_drag_field(grids[lev], dmap[lev], geom[lev],
806  z_phys_cc[lev].get(), z_phys_nd[lev].get());
807  }
808  }
809 
810 #ifdef ERF_USE_NETCDF
811  //
812  // Create the needed bdy_data_xlo etc ... since we don't read it in from checkpoint any more
813  //
815 
816  bdy_time_interval = read_times_from_wrfbdy(nc_bdy_file,
817  bdy_data_xlo,bdy_data_xhi,bdy_data_ylo,bdy_data_yhi,
818  start_bdy_time);
819  Real dT = bdy_time_interval;
820 
821  Real time_since_start_old = t_new[0] - start_bdy_time;
822  int n_time_old = static_cast<int>(time_since_start_old / dT);
823 
824  // I don't think this works if lev > 0 ...?
825  AMREX_ALWAYS_ASSERT(finest_level == 0);
826  int lev = 0;
827  bool use_moist = (solverChoice.moisture_type != MoistureType::None);
828  for (int itime = n_time_old; itime < n_time_old+3; itime++)
829  {
830  read_from_wrfbdy(itime,nc_bdy_file,geom[0].Domain(),
831  bdy_data_xlo,bdy_data_xhi,bdy_data_ylo,bdy_data_yhi,
832  real_width);
833  convert_all_wrfbdy_data(itime, geom[0].Domain(), bdy_data_xlo, bdy_data_xhi, bdy_data_ylo, bdy_data_yhi,
834  *mf_MUB[lev], *mf_C1H[lev], *mf_C2H[lev],
836  geom[lev], use_moist);
837  } // itime
838  } // use_real_bcs && lev == 0
839 #endif
840  } // end restart
841 
842 #ifdef ERF_USE_PARTICLES
843  /* If using a Lagrangian microphysics model, its particle container has now been
844  constructed and initialized (calls to micro->Init). So, add its pointer to
845  ERF::particleData and remove its name from list of unallocated particle containers. */
846  if (Microphysics::modelType(solverChoice.moisture_type) == MoistureModelType::Lagrangian) {
847  const auto& pc_name( dynamic_cast<LagrangianMicrophysics&>(*micro).getName() );
848  const auto& pc_ptr( dynamic_cast<LagrangianMicrophysics&>(*micro).getParticleContainer() );
849  particleData.pushBack(pc_name, pc_ptr);
850  particleData.getNamesUnalloc().remove(pc_name);
851  }
852 #endif
853 
854  if (input_bndry_planes) {
855  // Read the "time.dat" file to know what data is available
856  m_r2d->read_time_file();
857 
858  // We haven't populated dt yet, set to 0 to ensure assert doesn't crash
859  Real dt_dummy = 0.0;
860  m_r2d->read_input_files(t_new[0],dt_dummy,m_bc_extdir_vals);
861  }
862 
864  {
865  h_rhotheta_src.resize(max_level+1, Vector<Real>(0));
866  d_rhotheta_src.resize(max_level+1, Gpu::DeviceVector<Real>(0));
867  for (int lev = 0; lev <= finest_level; lev++) {
868  const int domlen = geom[lev].Domain().length(2);
869  h_rhotheta_src[lev].resize(domlen, 0.0_rt);
870  d_rhotheta_src[lev].resize(domlen, 0.0_rt);
871  prob->update_rhotheta_sources(t_new[0],
872  h_rhotheta_src[lev], d_rhotheta_src[lev],
873  geom[lev], z_phys_cc[lev]);
874  }
875  }
876 
878  {
879  h_u_geos.resize(max_level+1, Vector<Real>(0));
880  d_u_geos.resize(max_level+1, Gpu::DeviceVector<Real>(0));
881  h_v_geos.resize(max_level+1, Vector<Real>(0));
882  d_v_geos.resize(max_level+1, Gpu::DeviceVector<Real>(0));
883  for (int lev = 0; lev <= finest_level; lev++) {
884  const int domlen = geom[lev].Domain().length(2);
885  h_u_geos[lev].resize(domlen, 0.0_rt);
886  d_u_geos[lev].resize(domlen, 0.0_rt);
887  h_v_geos[lev].resize(domlen, 0.0_rt);
888  d_v_geos[lev].resize(domlen, 0.0_rt);
890  prob->update_geostrophic_profile(t_new[0],
891  h_u_geos[lev], d_u_geos[lev],
892  h_v_geos[lev], d_v_geos[lev],
893  geom[lev], z_phys_cc[lev]);
894  } else {
895  if (SolverChoice::mesh_type == MeshType::VariableDz) {
896  amrex::Print() << "Note: 1-D geostrophic wind profile input is not defined for real terrain" << std::endl;
897  }
899  h_u_geos[lev], d_u_geos[lev],
900  h_v_geos[lev], d_v_geos[lev],
901  geom[lev],
902  zlevels_stag[0]);
903  }
904  }
905  }
906 
908  {
909  h_rhoqt_src.resize(max_level+1, Vector<Real>(0));
910  d_rhoqt_src.resize(max_level+1, Gpu::DeviceVector<Real>(0));
911  for (int lev = 0; lev <= finest_level; lev++) {
912  const int domlen = geom[lev].Domain().length(2);
913  h_rhoqt_src[lev].resize(domlen, 0.0_rt);
914  d_rhoqt_src[lev].resize(domlen, 0.0_rt);
915  prob->update_rhoqt_sources(t_new[0],
916  h_rhoqt_src[lev], d_rhoqt_src[lev],
917  geom[lev], z_phys_cc[lev]);
918  }
919  }
920 
922  {
923  h_w_subsid.resize(max_level+1, Vector<Real>(0));
924  d_w_subsid.resize(max_level+1, Gpu::DeviceVector<Real>(0));
925  for (int lev = 0; lev <= finest_level; lev++) {
926  const int domlen = geom[lev].Domain().length(2) + 1; // lives on z-faces
927  h_w_subsid[lev].resize(domlen, 0.0_rt);
928  d_w_subsid[lev].resize(domlen, 0.0_rt);
929  prob->update_w_subsidence(t_new[0],
930  h_w_subsid[lev], d_w_subsid[lev],
931  geom[lev], z_phys_nd[lev]);
932  }
933  }
934 
937  {
938  initRayleigh();
939  if (solverChoice.init_type == InitType::Input_Sounding)
940  {
941  // Overwrite ubar, vbar, and thetabar with input profiles;
942  // wbar is assumed to be 0. Note: the tau coefficient set by
943  // prob->erf_init_rayleigh() is still used
944  bool restarting = (!restart_chkfile.empty());
945  setRayleighRefFromSounding(restarting);
946  }
947  }
948 
949  // Read in sponge data from input file
950  if(solverChoice.spongeChoice.sponge_type == "input_sponge")
951  {
952  initSponge();
953  bool restarting = (!restart_chkfile.empty());
954  setSpongeRefFromSounding(restarting);
955  }
956 
957  if (solverChoice.pert_type == PerturbationType::Source ||
958  solverChoice.pert_type == PerturbationType::Direct ||
959  solverChoice.pert_type == PerturbationType::CPM) {
960  if (is_it_time_for_action(istep[0], t_new[0], dt[0], pert_interval, -1.)) {
961  turbPert.debug(t_new[0]);
962  }
963  }
964 
965  // We only write the file at level 0 for now
967  {
968  // Create the WriteBndryPlanes object so we can handle writing of boundary plane data
969  m_w2d = std::make_unique<WriteBndryPlanes>(grids,geom);
970 
971  Real time = 0.;
972  if (time >= bndry_output_planes_start_time) {
973  bool is_moist = (micro->Get_Qstate_Moist_Size() > 0);
974  m_w2d->write_planes(0, time, vars_new, is_moist);
975  }
976  }
977 
978  //
979  // If we are starting from scratch, we have the option to project the initial velocity field
980  // regardless of how we initialized.
981  // pp_inc is used as scratch space here; we zero it out after the projection
982  //
983  if (restart_chkfile == "")
984  {
986  Real dummy_dt = 1.0;
987  if (verbose > 0) {
988  amrex::Print() << "Projecting initial velocity field" << std::endl;
989  }
990  for (int lev = 0; lev <= finest_level; ++lev)
991  {
992  project_velocity(lev, dummy_dt);
993  pp_inc[lev].setVal(0.);
994  gradp[lev][GpVars::gpx].setVal(0.);
995  gradp[lev][GpVars::gpy].setVal(0.);
996  gradp[lev][GpVars::gpz].setVal(0.);
997  }
998  }
999  }
1000 
1001  // Copy from new into old just in case
1002  for (int lev = 0; lev <= finest_level; ++lev)
1003  {
1004  auto& lev_new = vars_new[lev];
1005  auto& lev_old = vars_old[lev];
1006 
1007  // ***************************************************************************
1008  // Physical bc's at domain boundary
1009  // ***************************************************************************
1010  IntVect ngvect_cons = vars_new[lev][Vars::cons].nGrowVect();
1011  IntVect ngvect_vels = vars_new[lev][Vars::xvel].nGrowVect();
1012 
1013  int ncomp_cons = lev_new[Vars::cons].nComp();
1014  bool do_fb = true;
1015 
1016 #ifdef ERF_USE_NETCDF
1017  // We call this here because it is an ERF routine
1018  if (solverChoice.use_real_bcs && (lev==0)) {
1019  int icomp_cons = 0;
1020  bool cons_only = false;
1021  Vector<MultiFab*> mfs_vec = {&lev_new[Vars::cons],&lev_new[Vars::xvel],
1022  &lev_new[Vars::yvel],&lev_new[Vars::zvel]};
1023  fill_from_realbdy(mfs_vec,t_new[lev],cons_only,icomp_cons,
1024  ncomp_cons,ngvect_cons,ngvect_vels);
1025  do_fb = false;
1026  }
1027 #endif
1028 
1029  (*physbcs_cons[lev])(lev_new[Vars::cons],lev_new[Vars::xvel],lev_new[Vars::yvel],0,ncomp_cons,
1030  ngvect_cons,t_new[lev],BCVars::cons_bc,do_fb);
1031  ( *physbcs_u[lev])(lev_new[Vars::xvel],lev_new[Vars::xvel],lev_new[Vars::yvel],
1032  ngvect_vels,t_new[lev],BCVars::xvel_bc,do_fb);
1033  ( *physbcs_v[lev])(lev_new[Vars::yvel],lev_new[Vars::xvel],lev_new[Vars::yvel],
1034  ngvect_vels,t_new[lev],BCVars::yvel_bc,do_fb);
1035  ( *physbcs_w[lev])(lev_new[Vars::zvel],lev_new[Vars::xvel],lev_new[Vars::yvel],
1036  ngvect_vels,t_new[lev],BCVars::zvel_bc,do_fb);
1037 
1038  MultiFab::Copy(lev_old[Vars::cons],lev_new[Vars::cons],0,0,ncomp_cons,lev_new[Vars::cons].nGrowVect());
1039  MultiFab::Copy(lev_old[Vars::xvel],lev_new[Vars::xvel],0,0, 1,lev_new[Vars::xvel].nGrowVect());
1040  MultiFab::Copy(lev_old[Vars::yvel],lev_new[Vars::yvel],0,0, 1,lev_new[Vars::yvel].nGrowVect());
1041  MultiFab::Copy(lev_old[Vars::zvel],lev_new[Vars::zvel],0,0, 1,lev_new[Vars::zvel].nGrowVect());
1042  }
1043 
1044  // Compute the minimum dz in the domain at each level (to be used for setting the timestep)
1045  dz_min.resize(max_level+1);
1046  for (int lev = 0; lev <= finest_level; ++lev)
1047  {
1048  dz_min[lev] = geom[lev].CellSize(2);
1049  if ( SolverChoice::mesh_type != MeshType::ConstantDz ) {
1050  dz_min[lev] *= (*detJ_cc[lev]).min(0);
1051  }
1052  }
1053 
1054  ComputeDt();
1055 
1056  // Fill ghost cells/faces
1057  for (int lev = 0; lev <= finest_level; ++lev)
1058  {
1059  if (lev > 0 && cf_width >= 0) {
1061  }
1062 
1063  auto& lev_new = vars_new[lev];
1064 
1065  //
1066  // Fill boundary conditions -- not sure why we need this here
1067  //
1068  bool fillset = false;
1069  if (lev == 0) {
1070  FillPatch(lev, t_new[lev],
1071  {&lev_new[Vars::cons],&lev_new[Vars::xvel],&lev_new[Vars::yvel],&lev_new[Vars::zvel]});
1072  } else {
1073  FillPatch(lev, t_new[lev],
1074  {&lev_new[Vars::cons],&lev_new[Vars::xvel],&lev_new[Vars::yvel],&lev_new[Vars::zvel]},
1075  {&lev_new[Vars::cons],&rU_new[lev],&rV_new[lev],&rW_new[lev]},
1076  base_state[lev], base_state[lev],
1077  fillset);
1078  }
1079 
1080  //
1081  // We do this here to make sure level (lev-1) boundary conditions are filled
1082  // before we interpolate to level (lev) ghost cells
1083  //
1084  if (lev < finest_level) {
1085  auto& lev_old = vars_old[lev];
1086  MultiFab::Copy(lev_old[Vars::cons],lev_new[Vars::cons],0,0,lev_old[Vars::cons].nComp(),lev_old[Vars::cons].nGrowVect());
1087  MultiFab::Copy(lev_old[Vars::xvel],lev_new[Vars::xvel],0,0,lev_old[Vars::xvel].nComp(),lev_old[Vars::xvel].nGrowVect());
1088  MultiFab::Copy(lev_old[Vars::yvel],lev_new[Vars::yvel],0,0,lev_old[Vars::yvel].nComp(),lev_old[Vars::yvel].nGrowVect());
1089  MultiFab::Copy(lev_old[Vars::zvel],lev_new[Vars::zvel],0,0,lev_old[Vars::zvel].nComp(),lev_old[Vars::zvel].nGrowVect());
1090  }
1091 
1092  //
1093  // We fill the ghost cell values of the base state in case it wasn't done in the initialization
1094  //
1095  base_state[lev].FillBoundary(geom[lev].periodicity());
1096 
1097  // For moving terrain only
1098  if (solverChoice.terrain_type == TerrainType::MovingFittedMesh) {
1099  MultiFab::Copy(base_state_new[lev],base_state[lev],0,0,BaseState::num_comps,base_state[lev].nGrowVect());
1100  base_state_new[lev].FillBoundary(geom[lev].periodicity());
1101  }
1102 
1103  }
1104 
1105  // Allow idealized cases over water, used to set lmask
1106  ParmParse pp("erf");
1107  int is_land;
1108  for (int lev = 0; lev <= finest_level; ++lev)
1109  {
1110  if (pp.query("is_land", is_land, lev)) {
1111  if (is_land == 1) {
1112  amrex::Print() << "Level " << lev << " is land" << std::endl;
1113  } else if (is_land == 0) {
1114  amrex::Print() << "Level " << lev << " is water" << std::endl;
1115  } else {
1116  Error("is_land should be 0 or 1");
1117  }
1118  lmask_lev[lev][0]->setVal(is_land);
1119  lmask_lev[lev][0]->FillBoundary(geom[lev].periodicity());
1120  }
1121  }
1122 
1123 #ifdef ERF_USE_WW3_COUPLING
1124  int my_lev = 0;
1125  amrex::Print() << " About to call send_to_ww3 from ERF.cpp" << std::endl;
1126  send_to_ww3(my_lev);
1127  amrex::Print() << " About to call read_waves from ERF.cpp" << std::endl;
1128  read_waves(my_lev);
1129  // send_to_ww3(my_lev);
1130 #endif
1131 
1132  // Configure SurfaceLayer params if used
1133  // NOTE: we must set up the MOST routine after calling FillPatch
1134  // in order to have lateral ghost cells filled (MOST + terrain interp).
1135  if (phys_bc_type[Orientation(Direction::z,Orientation::low)] == ERF_BC::surface_layer)
1136  {
1137  bool rotate = solverChoice.use_rotate_surface_flux;
1138  if (rotate) {
1139  Print() << "Using surface layer model with stress rotations" << std::endl;
1140  }
1141 
1142  //
1143  // This constructor will make the ABLMost object but not allocate the arrays at each level.
1144  //
1145  m_SurfaceLayer = std::make_unique<SurfaceLayer>(geom, rotate, pp_prefix, Qv_prim,
1147 #ifdef ERF_USE_NETCDF
1148  ,start_bdy_time, bdy_time_interval
1149 #endif
1150  );
1151  // This call will allocate the arrays at each level. If we regrid later, either changing
1152  // the number of level sor just the grids at each existing level, we will call an update routine
1153  // to redefine the internal arrays in m_SurfaceLayer.
1154  int nlevs = geom.size();
1155  for (int lev = 0; lev < nlevs; lev++)
1156  {
1157  Vector<MultiFab*> mfv_old = {&vars_old[lev][Vars::cons], &vars_old[lev][Vars::xvel],
1158  &vars_old[lev][Vars::yvel], &vars_old[lev][Vars::zvel]};
1159  m_SurfaceLayer->make_SurfaceLayer_at_level(lev,nlevs,
1160  mfv_old, Theta_prim[lev], Qv_prim[lev],
1161  Qr_prim[lev], z_phys_nd[lev],
1162  Hwave[lev].get(),Lwave[lev].get(),eddyDiffs_lev[lev].get(),
1163  lsm_data[lev], lsm_flux[lev], sst_lev[lev],
1164  tsk_lev[lev], lmask_lev[lev]);
1165  }
1166 
1167 
1168  if (restart_chkfile != "") {
1169  // Update surface fields if needed (and available)
1171  }
1172 
1173  // We now configure ABLMost params here so that we can print the averages at t=0
1174  // Note we don't fill ghost cells here because this is just for diagnostics
1175  for (int lev = 0; lev <= finest_level; ++lev)
1176  {
1177  Real time = t_new[lev];
1178  IntVect ng = Theta_prim[lev]->nGrowVect();
1179 
1180  MultiFab::Copy( *Theta_prim[lev], vars_new[lev][Vars::cons], RhoTheta_comp, 0, 1, ng);
1181  MultiFab::Divide(*Theta_prim[lev], vars_new[lev][Vars::cons], Rho_comp, 0, 1, ng);
1182 
1183  if (solverChoice.moisture_type != MoistureType::None) {
1184  ng = Qv_prim[lev]->nGrowVect();
1185 
1186  MultiFab::Copy( *Qv_prim[lev], vars_new[lev][Vars::cons], RhoQ1_comp, 0, 1, ng);
1187  MultiFab::Divide(*Qv_prim[lev], vars_new[lev][Vars::cons], Rho_comp, 0, 1, ng);
1188 
1189  int rhoqr_comp = solverChoice.RhoQr_comp;
1190  if (rhoqr_comp > -1) {
1191  MultiFab::Copy( *Qr_prim[lev], vars_new[lev][Vars::cons], rhoqr_comp, 0, 1, ng);
1192  MultiFab::Divide(*Qr_prim[lev], vars_new[lev][Vars::cons], Rho_comp, 0, 1, ng);
1193  } else {
1194  Qr_prim[lev]->setVal(0.0);
1195  }
1196  }
1197  m_SurfaceLayer->update_mac_ptrs(lev, vars_new, Theta_prim, Qv_prim, Qr_prim);
1198 
1199  if (restart_chkfile == "") {
1200  // Only do this if starting from scratch; if restarting, then
1201  // we don't want to call update_fluxes multiple times because
1202  // it will change u* and theta* from their previous values
1203  m_SurfaceLayer->update_pblh(lev, vars_new, z_phys_cc[lev].get(),
1207  m_SurfaceLayer->update_fluxes(lev, time);
1208  }
1209  }
1210  } // end if (phys_bc_type[Orientation(Direction::z,Orientation::low)] == ERF_BC::surface_layer)
1211 
1212  // Update micro vars before first plot file
1213  if (solverChoice.moisture_type != MoistureType::None) {
1214  for (int lev = 0; lev <= finest_level; ++lev) micro->Update_Micro_Vars_Lev(lev, vars_new[lev][Vars::cons]);
1215  }
1216 
1217  // Fill time averaged velocities before first plot file
1218  if (solverChoice.time_avg_vel) {
1219  for (int lev = 0; lev <= finest_level; ++lev) {
1220  Time_Avg_Vel_atCC(dt[lev], t_avg_cnt[lev], vel_t_avg[lev].get(),
1221  vars_new[lev][Vars::xvel],
1222  vars_new[lev][Vars::yvel],
1223  vars_new[lev][Vars::zvel]);
1224  }
1225  }
1226 
1227  // check for additional plotting variables that are available after particle containers
1228  // are setup.
1229  const std::string& pv1 = "plot_vars_1"; appendPlotVariables(pv1,plot_var_names_1);
1230  const std::string& pv2 = "plot_vars_2"; appendPlotVariables(pv2,plot_var_names_2);
1231 
1232  if ( restart_chkfile.empty() && (m_check_int > 0 || m_check_per > 0.) )
1233  {
1236  }
1237 
1238  if ( (restart_chkfile.empty()) ||
1239  (!restart_chkfile.empty() && plot_file_on_restart) )
1240  {
1241  if (m_plot_int_1 > 0 || m_plot_per_1 > 0.)
1242  {
1245  }
1246  if (m_plot_int_2 > 0 || m_plot_per_2 > 0.)
1247  {
1250  }
1251  if (m_subvol_int > 0 || m_subvol_per > 0.) {
1252  WriteSubvolume();
1253  last_subvol = istep[0];
1254  }
1255  }
1256 
1257  // Set these up here because we need to know which MPI rank "cell" is on...
1258  if (pp.contains("data_log"))
1259  {
1260  int num_datalogs = pp.countval("data_log");
1261  datalog.resize(num_datalogs);
1262  datalogname.resize(num_datalogs);
1263  pp.queryarr("data_log",datalogname,0,num_datalogs);
1264  for (int i = 0; i < num_datalogs; i++) {
1266  }
1267  }
1268 
1269  if (pp.contains("der_data_log"))
1270  {
1271  int num_der_datalogs = pp.countval("der_data_log");
1272  der_datalog.resize(num_der_datalogs);
1273  der_datalogname.resize(num_der_datalogs);
1274  pp.queryarr("der_data_log",der_datalogname,0,num_der_datalogs);
1275  for (int i = 0; i < num_der_datalogs; i++) {
1277  }
1278  }
1279 
1280  if (pp.contains("energy_data_log"))
1281  {
1282  int num_energy_datalogs = pp.countval("energy_data_log");
1283  tot_e_datalog.resize(num_energy_datalogs);
1284  tot_e_datalogname.resize(num_energy_datalogs);
1285  pp.queryarr("energy_data_log",tot_e_datalogname,0,num_energy_datalogs);
1286  for (int i = 0; i < num_energy_datalogs; i++) {
1288  }
1289  }
1290 
1291  if (solverChoice.rad_type != RadiationType::None)
1292  {
1293  // Create data log for radiation model if requested
1294  rad[0]->setupDataLog();
1295  }
1296 
1297 
1298  if (restart_chkfile.empty() && profile_int > 0) {
1299  if (destag_profiles) {
1300  // all variables cell-centered
1302  } else {
1303  // some variables staggered
1305  }
1306  }
1307 
1308  if (pp.contains("sample_point_log") && pp.contains("sample_point"))
1309  {
1310  int lev = 0;
1311 
1312  int num_samplepts = pp.countval("sample_point") / AMREX_SPACEDIM;
1313  if (num_samplepts > 0) {
1314  Vector<int> index; index.resize(num_samplepts*AMREX_SPACEDIM);
1315  samplepoint.resize(num_samplepts);
1316 
1317  pp.queryarr("sample_point",index,0,num_samplepts*AMREX_SPACEDIM);
1318  for (int i = 0; i < num_samplepts; i++) {
1319  IntVect iv(index[AMREX_SPACEDIM*i+0],index[AMREX_SPACEDIM*i+1],index[AMREX_SPACEDIM*i+2]);
1320  samplepoint[i] = iv;
1321  }
1322  }
1323 
1324  int num_sampleptlogs = pp.countval("sample_point_log");
1325  AMREX_ALWAYS_ASSERT(num_sampleptlogs == num_samplepts);
1326  if (num_sampleptlogs > 0) {
1327  sampleptlog.resize(num_sampleptlogs);
1328  sampleptlogname.resize(num_sampleptlogs);
1329  pp.queryarr("sample_point_log",sampleptlogname,0,num_sampleptlogs);
1330 
1331  for (int i = 0; i < num_sampleptlogs; i++) {
1333  }
1334  }
1335 
1336  }
1337 
1338  if (pp.contains("sample_line_log") && pp.contains("sample_line"))
1339  {
1340  int lev = 0;
1341 
1342  int num_samplelines = pp.countval("sample_line") / AMREX_SPACEDIM;
1343  if (num_samplelines > 0) {
1344  Vector<int> index; index.resize(num_samplelines*AMREX_SPACEDIM);
1345  sampleline.resize(num_samplelines);
1346 
1347  pp.queryarr("sample_line",index,0,num_samplelines*AMREX_SPACEDIM);
1348  for (int i = 0; i < num_samplelines; i++) {
1349  IntVect iv(index[AMREX_SPACEDIM*i+0],index[AMREX_SPACEDIM*i+1],index[AMREX_SPACEDIM*i+2]);
1350  sampleline[i] = iv;
1351  }
1352  }
1353 
1354  int num_samplelinelogs = pp.countval("sample_line_log");
1355  AMREX_ALWAYS_ASSERT(num_samplelinelogs == num_samplelines);
1356  if (num_samplelinelogs > 0) {
1357  samplelinelog.resize(num_samplelinelogs);
1358  samplelinelogname.resize(num_samplelinelogs);
1359  pp.queryarr("sample_line_log",samplelinelogname,0,num_samplelinelogs);
1360 
1361  for (int i = 0; i < num_samplelinelogs; i++) {
1363  }
1364  }
1365 
1366  }
1367 
1372  }
1373 
1374  // Create object to do line and plane sampling if needed
1375  bool do_line = false; bool do_plane = false;
1376  pp.query("do_line_sampling",do_line); pp.query("do_plane_sampling",do_plane);
1377  if (do_line || do_plane) { data_sampler = std::make_unique<SampleData>(do_line, do_plane); }
1378 
1379  if ( solverChoice.terrain_type == TerrainType::EB ||
1380  solverChoice.terrain_type == TerrainType::ImmersedForcing)
1381  {
1382  bool write_eb_surface = false;
1383  pp.query("write_eb_surface", write_eb_surface);
1384  if (write_eb_surface) WriteMyEBSurface();
1385  }
1386 
1387 }
void initRayleigh()
Initialize Rayleigh damping profiles.
Definition: ERF_InitRayleigh.cpp:14
amrex::Vector< std::string > samplelinelogname
Definition: ERF.H:1426
void setRayleighRefFromSounding(bool restarting)
Set Rayleigh mean profiles from input sounding.
Definition: ERF_InitRayleigh.cpp:55
amrex::Vector< amrex::IntVect > sampleline
Definition: ERF.H:1427
static amrex::Real sum_per
Definition: ERF.H:1034
void setRecordDataInfo(int i, const std::string &filename)
Definition: ERF.H:1336
void WriteMyEBSurface()
Definition: ERF_EBWriteSurface.cpp:5
void write_1D_profiles_stag(amrex::Real time)
Definition: ERF_Write1DProfiles_stag.cpp:25
void sum_energy_quantities(amrex::Real time)
Definition: ERF_WriteScalarProfiles.cpp:288
amrex::Vector< std::unique_ptr< std::fstream > > samplelinelog
Definition: ERF.H:1425
static int sum_interval
Definition: ERF.H:1032
static int pert_interval
Definition: ERF.H:1033
void restart()
Definition: ERF.cpp:1426
void write_1D_profiles(amrex::Real time)
Definition: ERF_Write1DProfiles.cpp:17
int profile_int
Definition: ERF.H:941
bool destag_profiles
Definition: ERF.H:942
void appendPlotVariables(const std::string &pp_plot_var_names, amrex::Vector< std::string > &plot_var_names)
Definition: ERF_Plotfile.cpp:182
amrex::Vector< std::string > tot_e_datalogname
Definition: ERF.H:1419
static int output_bndry_planes
Definition: ERF.H:1090
static std::string nc_bdy_file
Definition: ERF.H:1049
void AverageDown()
Definition: ERF_AverageDown.cpp:16
std::unique_ptr< SampleData > data_sampler
Definition: ERF.H:1412
static amrex::Real bndry_output_planes_start_time
Definition: ERF.H:1093
void project_velocity(int lev, amrex::Real dt)
Definition: ERF_PoissonSolve.cpp:10
std::string restart_chkfile
Definition: ERF.H:902
amrex::Vector< std::string > sampleptlogname
Definition: ERF.H:1422
void sum_derived_quantities(amrex::Real time)
Definition: ERF_WriteScalarProfiles.cpp:169
void sum_integrated_quantities(amrex::Real time)
Definition: ERF_WriteScalarProfiles.cpp:15
void setRecordDerDataInfo(int i, const std::string &filename)
Definition: ERF.H:1349
amrex::Vector< std::unique_ptr< std::fstream > > sampleptlog
Definition: ERF.H:1421
std::unique_ptr< WriteBndryPlanes > m_w2d
Definition: ERF.H:1152
void init_geo_wind_profile(const std::string input_file, amrex::Vector< amrex::Real > &u_geos, amrex::Gpu::DeviceVector< amrex::Real > &u_geos_d, amrex::Vector< amrex::Real > &v_geos, amrex::Gpu::DeviceVector< amrex::Real > &v_geos_d, const amrex::Geometry &lgeom, const amrex::Vector< amrex::Real > &zlev_stag)
Definition: ERF_InitGeowind.cpp:10
void initSponge()
Initialize sponge profiles.
Definition: ERF_InitSponge.cpp:35
amrex::Vector< std::unique_ptr< std::fstream > > tot_e_datalog
Definition: ERF.H:1416
int real_width
Definition: ERF.H:1050
void setRecordEnergyDataInfo(int i, const std::string &filename)
Definition: ERF.H:1362
static bool is_it_time_for_action(int nstep, amrex::Real time, amrex::Real dt, int action_interval, amrex::Real action_per)
Definition: ERF_WriteScalarProfiles.cpp:728
int plot_file_on_restart
Definition: ERF.H:882
void Construct_ERFFillPatchers(int lev)
Definition: ERF.cpp:2116
void setRecordSampleLineInfo(int i, int lev, amrex::IntVect &cell, const std::string &filename)
Definition: ERF.H:1392
void setSpongeRefFromSounding(bool restarting)
Set sponge mean profiles from input sounding.
Definition: ERF_InitSponge.cpp:65
amrex::Vector< amrex::IntVect > samplepoint
Definition: ERF.H:1423
void setRecordSamplePointInfo(int i, int lev, amrex::IntVect &cell, const std::string &filename)
Definition: ERF.H:1375
void ReadCheckpointFileSurfaceLayer()
Definition: ERF_Checkpoint.cpp:957
static MoistureModelType modelType(const MoistureType a_moisture_type)
query if a specified moisture model is Eulerian or Lagrangian
Definition: ERF_Microphysics.H:86
bool have_zero_flux_faces
Definition: ERF_AdvStruct.H:360
bool have_geo_wind_profile
Definition: ERF_DataStruct.H:809
std::string abl_geo_wind_table
Definition: ERF_DataStruct.H:808
bool use_rotate_surface_flux
Definition: ERF_DataStruct.H:780
bool do_forest_drag
Definition: ERF_DataStruct.H:835
void debug(amrex::Real)
Definition: ERF_TurbPertStruct.H:620
Here is the call graph for this function:

◆ InitData_pre()

void ERF::InitData_pre ( )
699 {
700  // Initialize the start time for our CPU-time tracker
701  startCPUTime = ParallelDescriptor::second();
702 
703  // Create the ReadBndryPlanes object so we can read boundary plane data
704  // m_r2d is used by init_bcs so we must instantiate this class before
705  if (input_bndry_planes) {
706  Print() << "Defining r2d for the first time " << std::endl;
707  m_r2d = std::make_unique<ReadBndryPlanes>(geom[0], solverChoice.rdOcp);
708  }
709 
713 
714  if (restart_chkfile.empty()) {
715  // start simulation from the beginning
716 
717  const Real time = start_time;
718  InitFromScratch(time);
719  } else {
720  // For initialization this is done in init_only; it is done here for restart
721  init_bcs();
722  }
723 
724  // Verify solver choices
725  for (int lev(0); lev <= max_level; ++lev) {
726  // BC compatibility
727  if ( ( (solverChoice.turbChoice[lev].pbl_type == PBLType::MYNN25) ||
728  (solverChoice.turbChoice[lev].pbl_type == PBLType::MYNNEDMF) ||
729  (solverChoice.turbChoice[lev].pbl_type == PBLType::YSU) ||
730  (solverChoice.turbChoice[lev].pbl_type == PBLType::MRF)
731  ) &&
732  phys_bc_type[Orientation(Direction::z,Orientation::low)] != ERF_BC::surface_layer ) {
733  Abort("MYNN2.5/MYNNEDMF/YSU/MRF PBL Model requires MOST at lower boundary");
734  }
735  if ( (solverChoice.turbChoice[lev].les_type == LESType::Deardorff) &&
736  (solverChoice.turbChoice[lev].Ce_wall > 0) &&
737  (phys_bc_type[Orientation(Direction::z,Orientation::low)] != ERF_BC::surface_layer) &&
738  (phys_bc_type[Orientation(Direction::z,Orientation::low)] != ERF_BC::slip_wall) &&
739  (phys_bc_type[Orientation(Direction::z,Orientation::low)] != ERF_BC::no_slip_wall) )
740  {
741  Warning("Deardorff LES assumes wall at zlo when applying Ce_wall");
742  }
743 
744  // mesoscale diffusion
745  if ((geom[lev].CellSize(0) > 2000.) || (geom[lev].CellSize(1) > 2000.))
746  {
747  if ( (solverChoice.turbChoice[lev].les_type == LESType::Smagorinsky) &&
748  (!solverChoice.turbChoice[lev].smag2d)) {
749  Warning("Should use 2-D Smagorinsky for mesoscale resolution");
750  } else if (solverChoice.turbChoice[lev].les_type == LESType::Deardorff) {
751  Warning("Should not use Deardorff LES for mesoscale resolution");
752  }
753  }
754  }
755 }
void init_bcs()
Definition: ERF_InitBCs.cpp:20

◆ initHSE() [1/2]

void ERF::initHSE ( )
private

Initialize HSE.

143 {
144  AMREX_ALWAYS_ASSERT(!init_sounding_ideal);
145  for (int lev = 0; lev <= finest_level; lev++)
146  {
147  initHSE(lev);
148  }
149 }

◆ initHSE() [2/2]

void ERF::initHSE ( int  lev)
private

Initialize density and pressure base state in hydrostatic equilibrium.

21 {
22  // This integrates up through column to update p_hse, pi_hse, th_hse;
23  // r_hse is not const b/c FillBoundary is called at the end for r_hse and p_hse
24 
25  MultiFab r_hse (base_state[lev], make_alias, BaseState::r0_comp, 1);
26  MultiFab p_hse (base_state[lev], make_alias, BaseState::p0_comp, 1);
27  MultiFab pi_hse(base_state[lev], make_alias, BaseState::pi0_comp, 1);
28  MultiFab th_hse(base_state[lev], make_alias, BaseState::th0_comp, 1);
29  MultiFab qv_hse(base_state[lev], make_alias, BaseState::qv0_comp, 1);
30 
31  bool all_boxes_touch_bottom = true;
32  Box domain(geom[lev].Domain());
33 
34  int icomp = 0; int ncomp = BaseState::num_comps;
35 
36  if (lev == 0) {
37  BoxArray ba(base_state[lev].boxArray());
38  for (int i = 0; i < ba.size(); i++) {
39  if (ba[i].smallEnd(2) != domain.smallEnd(2)) {
40  all_boxes_touch_bottom = false;
41  }
42  }
43  }
44  else
45  {
46  //
47  // We need to do this interp from coarse level in order to set the values of
48  // the base state inside the domain but outside of the fine region
49  //
50  base_state[lev-1].FillBoundary(geom[lev-1].periodicity());
51  //
52  // NOTE: this interpolater assumes that ALL ghost cells of the coarse MultiFab
53  // have been pre-filled - this includes ghost cells both inside and outside
54  // the domain
55  //
56  InterpFromCoarseLevel(base_state[lev], base_state[lev].nGrowVect(),
57  IntVect(0,0,0), // do not fill ghost cells outside the domain
58  base_state[lev-1], icomp, icomp, ncomp,
59  geom[lev-1], geom[lev],
60  refRatio(lev-1), &cell_cons_interp,
62 
63  // We need to do this here because the interpolation above may leave corners unfilled
64  // when the corners need to be filled by, for example, reflection of the fine ghost
65  // cell outside the fine region but inide the domain.
66  (*physbcs_base[lev])(base_state[lev],icomp,ncomp,base_state[lev].nGrowVect());
67  }
68 
69  if (all_boxes_touch_bottom || lev > 0) {
70 
71  // Initial r_hse may or may not be in HSE -- defined in ERF_Prob.cpp
73  prob->erf_init_dens_hse_moist(r_hse, z_phys_nd[lev], geom[lev]);
74  } else {
75  prob->erf_init_dens_hse(r_hse, z_phys_nd[lev], z_phys_cc[lev], geom[lev]);
76  }
77 
78  erf_enforce_hse(lev, r_hse, p_hse, pi_hse, th_hse, qv_hse, z_phys_cc[lev]);
79 
80  //
81  // Impose physical bc's on the base state
82  //
83  (*physbcs_base[lev])(base_state[lev],0,base_state[lev].nComp(),base_state[lev].nGrowVect());
84 
85  } else {
86 
87  BoxArray ba_new(domain);
88 
89  ChopGrids2D(ba_new, domain, ParallelDescriptor::NProcs());
90 
91  DistributionMapping dm_new(ba_new);
92 
93  MultiFab new_base_state(ba_new, dm_new, BaseState::num_comps, base_state[lev].nGrowVect());
94  new_base_state.ParallelCopy(base_state[lev],0,0,base_state[lev].nComp(),
95  base_state[lev].nGrowVect(),base_state[lev].nGrowVect());
96 
97  MultiFab new_r_hse (new_base_state, make_alias, BaseState::r0_comp, 1);
98  MultiFab new_p_hse (new_base_state, make_alias, BaseState::p0_comp, 1);
99  MultiFab new_pi_hse(new_base_state, make_alias, BaseState::pi0_comp, 1);
100  MultiFab new_th_hse(new_base_state, make_alias, BaseState::th0_comp, 1);
101  MultiFab new_qv_hse(new_base_state, make_alias, BaseState::qv0_comp, 1);
102 
103  std::unique_ptr<MultiFab> new_z_phys_cc;
104  std::unique_ptr<MultiFab> new_z_phys_nd;
105  if (solverChoice.mesh_type != MeshType::ConstantDz) {
106  new_z_phys_cc = std::make_unique<MultiFab>(ba_new,dm_new,1,1);
107  new_z_phys_cc->ParallelCopy(*z_phys_cc[lev],0,0,1,1,1);
108 
109  BoxArray ba_new_nd(ba_new);
110  ba_new_nd.surroundingNodes();
111  new_z_phys_nd = std::make_unique<MultiFab>(ba_new_nd,dm_new,1,1);
112  new_z_phys_nd->ParallelCopy(*z_phys_nd[lev],0,0,1,1,1);
113  }
114 
115  // Initial r_hse may or may not be in HSE -- defined in ERF_Prob.cpp
117  prob->erf_init_dens_hse_moist(new_r_hse, new_z_phys_nd, geom[lev]);
118  } else {
119  prob->erf_init_dens_hse(new_r_hse, new_z_phys_nd, new_z_phys_cc, geom[lev]);
120  }
121 
122  erf_enforce_hse(lev, new_r_hse, new_p_hse, new_pi_hse, new_th_hse, new_qv_hse, new_z_phys_cc);
123 
124  //
125  // Impose physical bc's on the base state
126  //
127  (*physbcs_base[lev])(new_base_state,0,new_base_state.nComp(),new_base_state.nGrowVect());
128 
129  // Now copy back into the original arrays
130  base_state[lev].ParallelCopy(new_base_state,0,0,base_state[lev].nComp(),
131  base_state[lev].nGrowVect(),base_state[lev].nGrowVect());
132  }
133 
134  //
135  // Impose physical bc's on the base state -- the values outside the fine region
136  // but inside the domain have already been filled in the call above to InterpFromCoarseLevel
137  //
138  (*physbcs_base[lev])(base_state[lev],0,base_state[lev].nComp(),base_state[lev].nGrowVect());
139 }
void ChopGrids2D(BoxArray &ba, const Box &domain, int target_size)
Definition: ERF_ChopGrids.cpp:21
void erf_enforce_hse(int lev, amrex::MultiFab &dens, amrex::MultiFab &pres, amrex::MultiFab &pi, amrex::MultiFab &th, amrex::MultiFab &qv, std::unique_ptr< amrex::MultiFab > &z_cc)
Definition: ERF_Init1D.cpp:161
bool use_moist_background
Definition: ERF_DataStruct.H:817
Here is the call graph for this function:

◆ initialize_integrator()

void ERF::initialize_integrator ( int  lev,
amrex::MultiFab &  cons_mf,
amrex::MultiFab &  vel_mf 
)
private
631 {
632  const BoxArray& ba(cons_mf.boxArray());
633  const DistributionMapping& dm(cons_mf.DistributionMap());
634 
635  int ncomp_cons = cons_mf.nComp();
636 
637  // Initialize the integrator memory
638  Vector<MultiFab> int_state; // integration state data structure example
639  int_state.push_back(MultiFab(cons_mf, make_alias, 0, ncomp_cons)); // cons
640  int_state.push_back(MultiFab(convert(ba,IntVect(1,0,0)), dm, 1, vel_mf.nGrow())); // xmom
641  int_state.push_back(MultiFab(convert(ba,IntVect(0,1,0)), dm, 1, vel_mf.nGrow())); // ymom
642  int_state.push_back(MultiFab(convert(ba,IntVect(0,0,1)), dm, 1, vel_mf.nGrow())); // zmom
643 
644  mri_integrator_mem[lev] = std::make_unique<MRISplitIntegrator<Vector<MultiFab> > >(int_state);
645  mri_integrator_mem[lev]->setNoSubstepping((solverChoice.substepping_type[lev] == SubsteppingType::None));
646  mri_integrator_mem[lev]->setAnelastic(solverChoice.anelastic[lev]);
647  mri_integrator_mem[lev]->setNcompCons(ncomp_cons);
648  mri_integrator_mem[lev]->setForceFirstStageSingleSubstep(solverChoice.force_stage1_single_substep);
649 }

◆ InitializeFromFile()

void ERF::InitializeFromFile ( )
private

◆ InitializeLevelFromData()

void ERF::InitializeLevelFromData ( int  lev,
const amrex::MultiFab &  initial_data 
)
private

◆ initializeMicrophysics()

void ERF::initializeMicrophysics ( const int &  a_nlevsmax)
private
Parameters
a_nlevsmaxnumber of AMR levels
1392 {
1393  if (Microphysics::modelType(solverChoice.moisture_type) == MoistureModelType::Eulerian) {
1394 
1395  micro = std::make_unique<EulerianMicrophysics>(a_nlevsmax, solverChoice.moisture_type);
1396 
1397  } else if (Microphysics::modelType(solverChoice.moisture_type) == MoistureModelType::Lagrangian) {
1398 #ifdef ERF_USE_PARTICLES
1399 
1400  micro = std::make_unique<LagrangianMicrophysics>(a_nlevsmax, solverChoice.moisture_type);
1401  /* Lagrangian microphysics models will have a particle container; it needs to be added
1402  to ERF::particleData */
1403  const auto& pc_name( dynamic_cast<LagrangianMicrophysics&>(*micro).getName() );
1404  /* The particle container has not yet been constructed and initialized, so just add
1405  its name here for now (so that functions to set plotting variables can see it). */
1406  particleData.addName( pc_name );
1407 
1408 #else
1409  Abort("Lagrangian microphysics can be used when compiled with ERF_USE_PARTICLES");
1410 #endif
1411  }
1412 
1413  qmoist.resize(a_nlevsmax);
1414  return;
1415 }
amrex::Vector< amrex::Vector< amrex::MultiFab * > > qmoist
Definition: ERF.H:746
Here is the call graph for this function:

◆ initRayleigh()

void ERF::initRayleigh ( )
private

Initialize Rayleigh damping profiles.

Initialization function for host and device vectors used to store averaged quantities when calculating the effects of Rayleigh Damping.

15 {
16  const int khi = geom[0].Domain().bigEnd(2);
17  solverChoice.rayleigh_ztop = (solverChoice.terrain_type == TerrainType::None) ? geom[0].ProbHi(2) : zlevels_stag[0][khi+1];
18 
19  h_rayleigh_ptrs.resize(max_level+1);
20  d_rayleigh_ptrs.resize(max_level+1);
21 
22  for (int lev = 0; lev <= finest_level; lev++)
23  {
24  // These have 4 components: ubar, vbar, wbar, thetabar
25  h_rayleigh_ptrs[lev].resize(Rayleigh::nvars);
26  d_rayleigh_ptrs[lev].resize(Rayleigh::nvars);
27 
28  const int zlen_rayleigh = geom[lev].Domain().length(2);
29 
30  // Allocate space for these 1D vectors
31  for (int n = 0; n < Rayleigh::nvars; n++) {
32  h_rayleigh_ptrs[lev][n].resize(zlen_rayleigh, 0.0_rt);
33  d_rayleigh_ptrs[lev][n].resize(zlen_rayleigh, 0.0_rt);
34  }
35 
36  // Init the host vectors
37  prob->erf_init_rayleigh(h_rayleigh_ptrs[lev], geom[lev], z_phys_nd[lev], solverChoice.rayleigh_zdamp);
38 
39  // Copy from host vectors to device vectors
40  for (int n = 0; n < Rayleigh::nvars; n++) {
41  Gpu::copy(Gpu::hostToDevice, h_rayleigh_ptrs[lev][n].begin(), h_rayleigh_ptrs[lev][n].end(),
42  d_rayleigh_ptrs[lev][n].begin());
43  }
44  }
45 }
amrex::Vector< amrex::Vector< amrex::Vector< amrex::Real > > > h_rayleigh_ptrs
Definition: ERF.H:1127
amrex::Real rayleigh_zdamp
Definition: ERF_DataStruct.H:740
amrex::Real rayleigh_ztop
Definition: ERF_DataStruct.H:741

◆ initSponge()

void ERF::initSponge ( )
private

Initialize sponge profiles.

Initialization function for host and device vectors used to store the effects of sponge Damping.

36 {
37  h_sponge_ptrs.resize(max_level+1);
38  d_sponge_ptrs.resize(max_level+1);
39 
40  for (int lev = 0; lev <= finest_level; lev++)
41  {
42  // These have 2 components: ubar, vbar
45 
46  const int zlen_sponge = geom[lev].Domain().length(2);
47 
48  // Allocate space for these 1D vectors
49  for (int n = 0; n < Sponge::nvars_sponge; n++) {
50  h_sponge_ptrs[lev][n].resize(zlen_sponge, 0.0_rt);
51  d_sponge_ptrs[lev][n].resize(zlen_sponge, 0.0_rt);
52  }
53 
54  }
55 }
amrex::Vector< amrex::Vector< amrex::Vector< amrex::Real > > > h_sponge_ptrs
Definition: ERF.H:1130

◆ input_sponge()

void ERF::input_sponge ( int  lev)

High level wrapper for sponge x and y velocities level data from input sponge data.

Parameters
levInteger specifying the current level
18 {
19  // We only want to read the file once
20  if (lev == 0) {
22  Error("input_sounding file name must be provided via input");
23 
24  // this will interpolate the input profiles to the nominal height levels
25  // (ranging from 0 to the domain top)
27  }
28 }
InputSpongeData input_sponge_data
Definition: ERF.H:660
void read_from_file(const amrex::Geometry &geom, const amrex::Vector< amrex::Real > &zlevels_stag)
Definition: ERF_InputSpongeData.H:28
std::string input_sponge_file
Definition: ERF_InputSpongeData.H:111

◆ is_it_time_for_action()

bool ERF::is_it_time_for_action ( int  nstep,
amrex::Real  time,
amrex::Real  dt,
int  action_interval,
amrex::Real  action_per 
)
static

Helper function which uses the current step number, time, and timestep to determine whether it is time to take an action specified at every interval of timesteps.

Parameters
nstepTimestep number
timeCurrent time
dtlevTimestep for the current level
action_intervalInterval in number of timesteps for taking action
action_perInterval in simulation time for taking action
729 {
730  bool int_test = (action_interval > 0 && nstep % action_interval == 0);
731 
732  bool per_test = false;
733  if (action_per > 0.0) {
734  const int num_per_old = static_cast<int>(amrex::Math::floor((time - dtlev) / action_per));
735  const int num_per_new = static_cast<int>(amrex::Math::floor((time) / action_per));
736 
737  if (num_per_old != num_per_new) {
738  per_test = true;
739  }
740  }
741 
742  return int_test || per_test;
743 }

◆ make_eb_box()

void ERF::make_eb_box ( )

◆ make_eb_regular()

void ERF::make_eb_regular ( )

◆ make_physbcs()

void ERF::make_physbcs ( int  lev)
private
653 {
654  if (SolverChoice::mesh_type == MeshType::VariableDz) {
655  AMREX_ALWAYS_ASSERT(z_phys_nd[lev] != nullptr);
656  }
657 
658  physbcs_cons[lev] = std::make_unique<ERFPhysBCFunct_cons> (lev, geom[lev], domain_bcs_type, domain_bcs_type_d,
660  z_phys_nd[lev], solverChoice.use_real_bcs, th_bc_data[lev].data());
661  physbcs_u[lev] = std::make_unique<ERFPhysBCFunct_u> (lev, geom[lev], domain_bcs_type, domain_bcs_type_d,
663  z_phys_nd[lev], solverChoice.use_real_bcs, xvel_bc_data[lev].data());
664  physbcs_v[lev] = std::make_unique<ERFPhysBCFunct_v> (lev, geom[lev], domain_bcs_type, domain_bcs_type_d,
666  z_phys_nd[lev], solverChoice.use_real_bcs, yvel_bc_data[lev].data());
667  physbcs_w[lev] = std::make_unique<ERFPhysBCFunct_w> (lev, geom[lev], domain_bcs_type, domain_bcs_type_d,
670  solverChoice.use_real_bcs, zvel_bc_data[lev].data());
671  physbcs_base[lev] = std::make_unique<ERFPhysBCFunct_base> (lev, geom[lev], domain_bcs_type, domain_bcs_type_d, z_phys_nd[lev],
672  (solverChoice.terrain_type == TerrainType::MovingFittedMesh));
673 }

◆ MakeDiagnosticAverage()

void ERF::MakeDiagnosticAverage ( amrex::Vector< amrex::Real > &  h_havg,
amrex::MultiFab &  S,
int  n 
)
2071 {
2072  // Get the number of cells in z at level 0
2073  int dir_z = AMREX_SPACEDIM-1;
2074  auto domain = geom[0].Domain();
2075  int size_z = domain.length(dir_z);
2076  int start_z = domain.smallEnd()[dir_z];
2077  Real area_z = static_cast<Real>(domain.length(0)*domain.length(1));
2078 
2079  // resize the level 0 horizontal average vectors
2080  h_havg.resize(size_z, 0.0_rt);
2081 
2082  // Get the cell centered data and construct sums
2083 #ifdef _OPENMP
2084 #pragma omp parallel if (Gpu::notInLaunchRegion())
2085 #endif
2086  for (MFIter mfi(S); mfi.isValid(); ++mfi) {
2087  const Box& box = mfi.validbox();
2088  const IntVect& se = box.smallEnd();
2089  const IntVect& be = box.bigEnd();
2090 
2091  auto fab_arr = S[mfi].array();
2092 
2093  FArrayBox fab_reduce(box, 1, The_Async_Arena());
2094  auto arr_reduce = fab_reduce.array();
2095 
2096  ParallelFor(box, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
2097  arr_reduce(i, j, k, 0) = fab_arr(i,j,k,n);
2098  });
2099 
2100  for (int k=se[dir_z]; k <= be[dir_z]; ++k) {
2101  Box kbox(box); kbox.setSmall(dir_z,k); kbox.setBig(dir_z,k);
2102  h_havg[k-start_z] += fab_reduce.sum<RunOn::Device>(kbox,0);
2103  }
2104  }
2105 
2106  // combine sums from different MPI ranks
2107  ParallelDescriptor::ReduceRealSum(h_havg.dataPtr(), h_havg.size());
2108 
2109  // divide by the total number of cells we are averaging over
2110  for (int k = 0; k < size_z; ++k) {
2111  h_havg[k] /= area_z;
2112  }
2113 }

◆ MakeEBGeometry()

void ERF::MakeEBGeometry ( )

◆ MakeHorizontalAverages()

void ERF::MakeHorizontalAverages ( )
1965 {
1966  int lev = 0;
1967 
1968  // First, average down all levels (if doing two-way coupling)
1969  if (solverChoice.coupling_type == CouplingType::TwoWay) {
1970  AverageDown();
1971  }
1972 
1973  MultiFab mf(grids[lev], dmap[lev], 5, 0);
1974 
1975  int zdir = 2;
1976  auto domain = geom[0].Domain();
1977 
1978  bool use_moisture = (solverChoice.moisture_type != MoistureType::None);
1979  bool is_anelastic = (solverChoice.anelastic[lev] == 1);
1980 
1981  for (MFIter mfi(mf); mfi.isValid(); ++mfi) {
1982  const Box& bx = mfi.validbox();
1983  auto fab_arr = mf.array(mfi);
1984  auto const hse_arr = base_state[lev].const_array(mfi);
1985  auto const cons_arr = vars_new[lev][Vars::cons].const_array(mfi);
1986  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
1987  Real dens = cons_arr(i, j, k, Rho_comp);
1988  fab_arr(i, j, k, 0) = dens;
1989  fab_arr(i, j, k, 1) = cons_arr(i, j, k, RhoTheta_comp) / dens;
1990  if (!use_moisture) {
1991  if (is_anelastic) {
1992  fab_arr(i,j,k,2) = hse_arr(i,j,k,BaseState::p0_comp);
1993  } else {
1994  fab_arr(i,j,k,2) = getPgivenRTh(cons_arr(i,j,k,RhoTheta_comp));
1995  }
1996  }
1997  });
1998  }
1999 
2000  if (use_moisture)
2001  {
2002  for (MFIter mfi(mf); mfi.isValid(); ++mfi) {
2003  const Box& bx = mfi.validbox();
2004  auto fab_arr = mf.array(mfi);
2005  auto const hse_arr = base_state[lev].const_array(mfi);
2006  auto const cons_arr = vars_new[lev][Vars::cons].const_array(mfi);
2007  int ncomp = vars_new[lev][Vars::cons].nComp();
2008 
2009  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
2010  Real dens = cons_arr(i, j, k, Rho_comp);
2011  if (is_anelastic) {
2012  fab_arr(i,j,k,2) = hse_arr(i,j,k,BaseState::p0_comp);
2013  } else {
2014  Real qv = cons_arr(i, j, k, RhoQ1_comp) / dens;
2015  fab_arr(i, j, k, 2) = getPgivenRTh(cons_arr(i, j, k, RhoTheta_comp), qv);
2016  }
2017  fab_arr(i, j, k, 3) = (ncomp > RhoQ1_comp ? cons_arr(i, j, k, RhoQ1_comp) / dens : 0.0);
2018  fab_arr(i, j, k, 4) = (ncomp > RhoQ2_comp ? cons_arr(i, j, k, RhoQ2_comp) / dens : 0.0);
2019  });
2020  }
2021 
2022  Gpu::HostVector<Real> h_avg_qv = sumToLine(mf,3,1,domain,zdir);
2023  Gpu::HostVector<Real> h_avg_qc = sumToLine(mf,4,1,domain,zdir);
2024  }
2025 
2026  // Sum in the horizontal plane
2027  Gpu::HostVector<Real> h_avg_density = sumToLine(mf,0,1,domain,zdir);
2028  Gpu::HostVector<Real> h_avg_temperature = sumToLine(mf,1,1,domain,zdir);
2029  Gpu::HostVector<Real> h_avg_pressure = sumToLine(mf,2,1,domain,zdir);
2030 
2031  // Divide by the total number of cells we are averaging over
2032  int size_z = domain.length(zdir);
2033  Real area_z = static_cast<Real>(domain.length(0)*domain.length(1));
2034  int klen = static_cast<int>(h_avg_density.size());
2035 
2036  for (int k = 0; k < klen; ++k) {
2037  h_havg_density[k] /= area_z;
2038  h_havg_temperature[k] /= area_z;
2039  h_havg_pressure[k] /= area_z;
2040  if (solverChoice.moisture_type != MoistureType::None)
2041  {
2042  h_havg_qc[k] /= area_z;
2043  h_havg_qv[k] /= area_z;
2044  }
2045  } // k
2046 
2047  // resize device vectors
2048  d_havg_density.resize(size_z, 0.0_rt);
2049  d_havg_temperature.resize(size_z, 0.0_rt);
2050  d_havg_pressure.resize(size_z, 0.0_rt);
2051 
2052  // copy host vectors to device vectors
2053  Gpu::copy(Gpu::hostToDevice, h_havg_density.begin(), h_havg_density.end(), d_havg_density.begin());
2054  Gpu::copy(Gpu::hostToDevice, h_havg_temperature.begin(), h_havg_temperature.end(), d_havg_temperature.begin());
2055  Gpu::copy(Gpu::hostToDevice, h_havg_pressure.begin(), h_havg_pressure.end(), d_havg_pressure.begin());
2056 
2057  if (solverChoice.moisture_type != MoistureType::None)
2058  {
2059  d_havg_qv.resize(size_z, 0.0_rt);
2060  d_havg_qc.resize(size_z, 0.0_rt);
2061  Gpu::copy(Gpu::hostToDevice, h_havg_qv.begin(), h_havg_qv.end(), d_havg_qv.begin());
2062  Gpu::copy(Gpu::hostToDevice, h_havg_qc.begin(), h_havg_qc.end(), d_havg_qc.begin());
2063  }
2064 }
amrex::Gpu::DeviceVector< amrex::Real > d_havg_temperature
Definition: ERF.H:1145
amrex::Gpu::DeviceVector< amrex::Real > d_havg_qv
Definition: ERF.H:1147
amrex::Vector< amrex::Real > h_havg_pressure
Definition: ERF.H:1140
amrex::Vector< amrex::Real > h_havg_qc
Definition: ERF.H:1142
amrex::Vector< amrex::Real > h_havg_density
Definition: ERF.H:1138
amrex::Gpu::DeviceVector< amrex::Real > d_havg_qc
Definition: ERF.H:1148
amrex::Gpu::DeviceVector< amrex::Real > d_havg_density
Definition: ERF.H:1144
amrex::Vector< amrex::Real > h_havg_temperature
Definition: ERF.H:1139
amrex::Gpu::DeviceVector< amrex::Real > d_havg_pressure
Definition: ERF.H:1146
amrex::Vector< amrex::Real > h_havg_qv
Definition: ERF.H:1141
Here is the call graph for this function:

◆ MakeNewLevelFromCoarse()

void ERF::MakeNewLevelFromCoarse ( int  lev,
amrex::Real  time,
const amrex::BoxArray &  ba,
const amrex::DistributionMapping &  dm 
)
override
256 {
257  AMREX_ALWAYS_ASSERT(lev > 0);
258 
259  if (verbose) {
260  amrex::Print() <<" NEW BA FROM COARSE AT LEVEL " << lev << " " << ba << std::endl;
261  }
262 
263  //********************************************************************************************
264  // This allocates all kinds of things, including but not limited to: solution arrays,
265  // terrain arrays, metric terms and base state.
266  // *******************************************************************************************
267  init_stuff(lev, ba, dm, vars_new[lev], vars_old[lev], base_state[lev], z_phys_nd[lev]);
268 
269  t_new[lev] = time;
270  t_old[lev] = time - 1.e200;
271 
272  // ********************************************************************************************
273  // Build the data structures for metric quantities used with terrain-fitted coordinates
274  // ********************************************************************************************
275  init_zphys(lev, time);
277 
278  //
279  // Make sure that detJ and z_phys_cc are the average of the data on a finer level if there is one
280  //
281  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
282  for (int crse_lev = lev-1; crse_lev >= 0; crse_lev--) {
283  average_down( *detJ_cc[crse_lev+1], *detJ_cc[crse_lev], 0, 1, refRatio(crse_lev));
284  average_down(*z_phys_cc[crse_lev+1], *z_phys_cc[crse_lev], 0, 1, refRatio(crse_lev));
285  }
286  }
287 
288  // ********************************************************************************************
289  // Build the data structures for canopy model (depends upon z_phys)
290  // ********************************************************************************************
292  m_forest_drag[lev]->define_drag_field(ba, dm, geom[lev], z_phys_cc[lev].get(), z_phys_nd[lev].get());
293  }
294 
295  //********************************************************************************************
296  // Microphysics
297  // *******************************************************************************************
298  int q_size = micro->Get_Qmoist_Size(lev);
299  qmoist[lev].resize(q_size);
300  micro->Define(lev, solverChoice);
301  if (solverChoice.moisture_type != MoistureType::None)
302  {
303  micro->Init(lev, vars_new[lev][Vars::cons],
304  grids[lev], Geom(lev), 0.0,
305  z_phys_nd[lev], detJ_cc[lev]); // dummy dt value
306  }
307  for (int mvar(0); mvar<qmoist[lev].size(); ++mvar) {
308  qmoist[lev][mvar] = micro->Get_Qmoist_Ptr(lev,mvar);
309  }
310 
311  // *****************************************************************************************************
312  // Initialize the boundary conditions (after initializing the terrain but before calling
313  // initHSE or FillCoarsePatch)
314  // *****************************************************************************************************
315  make_physbcs(lev);
316 
317  // ********************************************************************************************
318  // Update the base state at this level by interpolation from coarser level (inside initHSE)
319  // ********************************************************************************************
320  initHSE(lev);
321 
322  // ********************************************************************************************
323  // Build the data structures for calculating diffusive/turbulent terms
324  // ********************************************************************************************
325  update_diffusive_arrays(lev, ba, dm);
326 
327  // ********************************************************************************************
328  // Fill data at the new level by interpolation from the coarser level
329  // Note that internal to FillCoarsePatch we will convert velocity to momentum,
330  // then interpolate momentum, then convert momentum back to velocity
331  // Also note that FillCoarsePatch is hard-wired to act only on lev_new at coarse and fine
332  // ********************************************************************************************
333  FillCoarsePatch(lev, time);
334 
335  // ********************************************************************************************
336  // Initialize the integrator class
337  // ********************************************************************************************
338  dt_mri_ratio[lev] = dt_mri_ratio[lev-1];
340 
341  // ********************************************************************************************
342  // If we are making a new level then the FillPatcher for this level hasn't been allocated yet
343  // ********************************************************************************************
344  if (lev > 0 && cf_width >= 0) {
347  }
348 
349  // ********************************************************************************************
350  // Create the SurfaceLayer arrays at this (new) level
351  // ********************************************************************************************
352  if (phys_bc_type[Orientation(Direction::z,Orientation::low)] == ERF_BC::surface_layer) {
353  int nlevs = finest_level+1;
354  Vector<MultiFab*> mfv_old = {&vars_old[lev][Vars::cons], &vars_old[lev][Vars::xvel],
355  &vars_old[lev][Vars::yvel], &vars_old[lev][Vars::zvel]};
356  m_SurfaceLayer->make_SurfaceLayer_at_level(lev,nlevs,
357  mfv_old, Theta_prim[lev], Qv_prim[lev],
358  Qr_prim[lev], z_phys_nd[lev],
359  Hwave[lev].get(), Lwave[lev].get(), eddyDiffs_lev[lev].get(),
360  lsm_data[lev], lsm_flux[lev], sst_lev[lev], tsk_lev[lev], lmask_lev[lev]);
361  }
362 
363 #ifdef ERF_USE_PARTICLES
364  // particleData.Redistribute();
365 #endif
366 }
void update_diffusive_arrays(int lev, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm)
Definition: ERF_MakeNewArrays.cpp:424
void initialize_integrator(int lev, amrex::MultiFab &cons_mf, amrex::MultiFab &vel_mf)
Definition: ERF_MakeNewArrays.cpp:630
void update_terrain_arrays(int lev)
Definition: ERF_MakeNewArrays.cpp:619
void init_zphys(int lev, amrex::Real time)
Definition: ERF_MakeNewArrays.cpp:514
void init_stuff(int lev, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm, amrex::Vector< amrex::MultiFab > &lev_new, amrex::Vector< amrex::MultiFab > &lev_old, amrex::MultiFab &tmp_base_state, std::unique_ptr< amrex::MultiFab > &tmp_zphys_nd)
Definition: ERF_MakeNewArrays.cpp:24
void Define_ERFFillPatchers(int lev)
Definition: ERF.cpp:2142

◆ MakeNewLevelFromScratch()

void ERF::MakeNewLevelFromScratch ( int  lev,
amrex::Real  time,
const amrex::BoxArray &  ba,
const amrex::DistributionMapping &  dm 
)
override
27 {
28  BoxArray ba;
29  DistributionMapping dm;
30  Box domain(Geom(0).Domain());
31  if (lev == 0 && restart_chkfile.empty() &&
32  (max_grid_size[0][0] >= domain.length(0)) &&
33  (max_grid_size[0][1] >= domain.length(1)) &&
34  ba_in.size() != ParallelDescriptor::NProcs())
35  {
36  // We only decompose in z if max_grid_size_z indicates we should
37  bool decompose_in_z = (max_grid_size[0][2] < domain.length(2));
38 
39  ba = ERFPostProcessBaseGrids(Geom(0).Domain(),decompose_in_z);
40  dm = DistributionMapping(ba);
41  } else {
42  ba = ba_in;
43  dm = dm_in;
44  }
45 
46  // ********************************************************************************************
47  // Define grids[lev] to be ba
48  // ********************************************************************************************
49  SetBoxArray(lev, ba);
50 
51  // ********************************************************************************************
52  // Define dmap[lev] to be dm
53  // ********************************************************************************************
54  SetDistributionMap(lev, dm);
55 
56  if (verbose) {
57  amrex::Print() <<" BA FROM SCRATCH AT LEVEL " << lev << " " << ba << std::endl;
58  }
59 
60  if (lev == 0) init_bcs();
61 
62  if ( solverChoice.terrain_type == TerrainType::EB ||
63  solverChoice.terrain_type == TerrainType::ImmersedForcing)
64  {
65  const amrex::EB2::IndexSpace& ebis = amrex::EB2::IndexSpace::top();
66  const EB2::Level& eb_level = ebis.getLevel(geom[lev]);
67  eb[lev]->make_factory(lev, geom[lev], grids[lev], dmap[lev], eb_level);
68  } else {
69  // m_factory[lev] = std::make_unique<FabFactory<FArrayBox>>();
70  }
71 
72  auto& lev_new = vars_new[lev];
73  auto& lev_old = vars_old[lev];
74 
75  //********************************************************************************************
76  // This allocates all kinds of things, including but not limited to: solution arrays,
77  // terrain arrays, metric terms and base state.
78  // *******************************************************************************************
79  init_stuff(lev, ba, dm, lev_new, lev_old, base_state[lev], z_phys_nd[lev]);
80 
81  //********************************************************************************************
82  // Land Surface Model
83  // *******************************************************************************************
84  int lsm_size = lsm.Get_Data_Size();
85  lsm_data[lev].resize(lsm_size);
86  lsm_flux[lev].resize(lsm_size);
87  lsm.Define(lev, solverChoice);
88  if (solverChoice.lsm_type != LandSurfaceType::None)
89  {
90  lsm.Init(lev, vars_new[lev][Vars::cons], Geom(lev), 0.0); // dummy dt value
91  }
92  for (int mvar(0); mvar<lsm_data[lev].size(); ++mvar) {
93  lsm_data[lev][mvar] = lsm.Get_Data_Ptr(lev,mvar);
94  lsm_flux[lev][mvar] = lsm.Get_Flux_Ptr(lev,mvar);
95  }
96 
97  // ********************************************************************************************
98  // Build the data structures for calculating diffusive/turbulent terms
99  // ********************************************************************************************
100  update_diffusive_arrays(lev, ba, dm);
101 
102  // ********************************************************************************************
103  // Build the data structures for holding sea surface temps and skin temps
104  // ********************************************************************************************
105  sst_lev[lev].resize(1); sst_lev[lev][0] = nullptr;
106  tsk_lev[lev].resize(1); tsk_lev[lev][0] = nullptr;
107 
108  // ********************************************************************************************
109  // Thin immersed body
110  // *******************************************************************************************
111  init_thin_body(lev, ba, dm);
112 
113  // ********************************************************************************************
114  // Initialize the integrator class
115  // ********************************************************************************************
116  initialize_integrator(lev, lev_new[Vars::cons],lev_new[Vars::xvel]);
117 
118  // ********************************************************************************************
119  // Initialize the data itself
120  // If (init_type == InitType::WRFInput) then we are initializing terrain and the initial data in
121  // the same call so we must call init_only before update_terrain_arrays
122  // If (init_type != InitType::WRFInput) then we want to initialize the terrain before the initial data
123  // since we may need to use the grid information before constructing
124  // initial idealized data
125  // ********************************************************************************************
126  if (restart_chkfile.empty()) {
127  if ( (solverChoice.init_type == InitType::WRFInput) || (solverChoice.init_type == InitType::Metgrid) )
128  {
129  AMREX_ALWAYS_ASSERT(solverChoice.terrain_type == TerrainType::StaticFittedMesh);
130  init_only(lev, start_time);
131  init_zphys(lev, time);
133  make_physbcs(lev);
134  } else {
135  init_zphys(lev, time);
137  // Note that for init_type != InitType::WRFInput and != InitType::Metgrid,
138  // make_physbcs is called inside init_only
139  init_only(lev, start_time);
140  }
141  } else {
142  // if restarting and nudging from input sounding, load the input sounding files
143  if (lev == 0 && solverChoice.init_type == InitType::Input_Sounding && solverChoice.nudging_from_input_sounding)
144  {
146  Error("input_sounding file name must be provided via input");
147  }
148 
150 
151  // this will interpolate the input profiles to the nominal height levels
152  // (ranging from 0 to the domain top)
153  for (int n = 0; n < input_sounding_data.n_sounding_files; n++) {
154  input_sounding_data.read_from_file(geom[lev], zlevels_stag[lev], n);
155  }
156 
157  // this will calculate the hydrostatically balanced density and pressure
158  // profiles following WRF ideal.exe
160  }
161 
162  // We re-create terrain_blanking on restart rather than storing it in the checkpoint
163  if (solverChoice.terrain_type == TerrainType::ImmersedForcing) {
164  int ngrow = ComputeGhostCells(solverChoice) + 2;
165  terrain_blanking[lev]->setVal(1.0);
166  MultiFab::Subtract(*terrain_blanking[lev], EBFactory(lev).getVolFrac(), 0, 0, 1, ngrow);
167  terrain_blanking[lev]->FillBoundary(geom[lev].periodicity());
168  }
169  }
170 
171  // Read in tables needed for windfarm simulations
172  // fill in Nturb multifab - number of turbines in each mesh cell
173  // write out the vtk files for wind turbine location and/or
174  // actuator disks
175  #ifdef ERF_USE_WINDFARM
176  init_windfarm(lev);
177  #endif
178 
179  // ********************************************************************************************
180  // Build the data structures for canopy model (depends upon z_phys)
181  // ********************************************************************************************
182  if (restart_chkfile.empty()) {
184  m_forest_drag[lev]->define_drag_field(ba, dm, geom[lev], z_phys_cc[lev].get(), z_phys_nd[lev].get());
185  }
186  }
187 
188  //********************************************************************************************
189  // Create wall distance field for RANS model (depends upon z_phys)
190  // *******************************************************************************************
191  if (solverChoice.turbChoice[lev].rans_type != RANSType::None) {
192  // Handle bottom boundary
193  poisson_wall_dist(lev);
194 
195  // Correct the wall distance for immersed bodies
201  geom[lev],
202  z_phys_cc[lev]);
203  }
204  }
205 
206  //********************************************************************************************
207  // Microphysics
208  // *******************************************************************************************
209  int q_size = micro->Get_Qmoist_Size(lev);
210  qmoist[lev].resize(q_size);
211  micro->Define(lev, solverChoice);
212  if (solverChoice.moisture_type != MoistureType::None)
213  {
214  micro->Init(lev, vars_new[lev][Vars::cons],
215  grids[lev], Geom(lev), 0.0,
216  z_phys_nd[lev], detJ_cc[lev]); // dummy dt value
217  }
218  for (int mvar(0); mvar<qmoist[lev].size(); ++mvar) {
219  qmoist[lev][mvar] = micro->Get_Qmoist_Ptr(lev,mvar);
220  }
221 
222  //********************************************************************************************
223  // Radiation
224  // *******************************************************************************************
225  if (solverChoice.rad_type != RadiationType::None)
226  {
227  rad[lev]->Init(geom[lev], ba, &vars_new[lev][Vars::cons]);
228  }
229 
230  // ********************************************************************************************
231  // If we are making a new level then the FillPatcher for this level hasn't been allocated yet
232  // ********************************************************************************************
233  if (lev > 0 && cf_width >= 0) {
236  }
237 
238 #ifdef ERF_USE_PARTICLES
239  if (restart_chkfile.empty()) {
240  if (lev == 0) {
241  initializeTracers((ParGDBBase*)GetParGDB(),z_phys_nd);
242  } else {
243  particleData.Redistribute();
244  }
245  }
246 #endif
247 }
BoxArray ERFPostProcessBaseGrids(const Box &domain, bool decompose_in_z)
Definition: ERF_ChopGrids.cpp:6
void thinbody_wall_dist(std::unique_ptr< MultiFab > &wdist, Vector< IntVect > &xfaces, Vector< IntVect > &yfaces, Vector< IntVect > &zfaces, const Geometry &geomdata, std::unique_ptr< MultiFab > &z_phys_cc)
Definition: ERF_ThinBodyWallDist.cpp:12
void init_only(int lev, amrex::Real time)
Definition: ERF.cpp:1464
void poisson_wall_dist(int lev)
Definition: ERF_PoissonWallDist.cpp:20
void init_thin_body(int lev, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm)
Definition: ERF_MakeNewLevel.cpp:606
int Get_Data_Size()
Definition: ERF_LandSurface.H:92
amrex::MultiFab * Get_Flux_Ptr(const int &lev, const int &varIdx)
Definition: ERF_LandSurface.H:86
void Init(const int &lev, const amrex::MultiFab &cons_in, const amrex::Geometry &geom, const amrex::Real &dt_advance)
Definition: ERF_LandSurface.H:43
void Define(const int &lev, SolverChoice &sc)
Definition: ERF_LandSurface.H:36
amrex::MultiFab * Get_Data_Ptr(const int &lev, const int &varIdx)
Definition: ERF_LandSurface.H:83
bool nudging_from_input_sounding
Definition: ERF_DataStruct.H:777
Here is the call graph for this function:

◆ MakeVTKFilename()

std::string ERF::MakeVTKFilename ( int  nstep)
574  {
575  // Ensure output directory exists
576  const std::string dir = "Output_HurricaneTracker";
577  if (!fs::exists(dir)) {
578  fs::create_directory(dir);
579  }
580 
581  // Construct filename with zero-padded step
582  std::ostringstream oss;
583  if(nstep==0){
584  oss << dir << "/hurricane_track_" << std::setw(7) << std::setfill('0') << nstep << ".vtk";
585  } else {
586  oss << dir << "/hurricane_track_" << std::setw(7) << std::setfill('0') << nstep+1 << ".vtk";
587  }
588 
589  return oss.str();
590 }

◆ nghost_eb_basic()

static int ERF::nghost_eb_basic ( )
inlinestaticprivate
1453  { return 5; }

◆ nghost_eb_full()

static int ERF::nghost_eb_full ( )
inlinestaticprivate
1460  { return 4; }

◆ nghost_eb_volume()

static int ERF::nghost_eb_volume ( )
inlinestaticprivate
1457  { return 5; }

◆ NumDataLogs()

AMREX_FORCE_INLINE int ERF::NumDataLogs ( )
inlineprivatenoexcept
1252  {
1253  return datalog.size();
1254  }

◆ NumDerDataLogs()

AMREX_FORCE_INLINE int ERF::NumDerDataLogs ( )
inlineprivatenoexcept
1259  {
1260  return der_datalog.size();
1261  }

◆ NumSampleLineLogs()

AMREX_FORCE_INLINE int ERF::NumSampleLineLogs ( )
inlineprivatenoexcept
1288  {
1289  return samplelinelog.size();
1290  }

◆ NumSampleLines()

AMREX_FORCE_INLINE int ERF::NumSampleLines ( )
inlineprivatenoexcept
1314  {
1315  return sampleline.size();
1316  }

◆ NumSamplePointLogs()

AMREX_FORCE_INLINE int ERF::NumSamplePointLogs ( )
inlineprivatenoexcept
1274  {
1275  return sampleptlog.size();
1276  }

◆ NumSamplePoints()

AMREX_FORCE_INLINE int ERF::NumSamplePoints ( )
inlineprivatenoexcept
1301  {
1302  return samplepoint.size();
1303  }

◆ operator=() [1/2]

ERF& ERF::operator= ( const ERF other)
delete

◆ operator=() [2/2]

ERF& ERF::operator= ( ERF &&  other)
deletenoexcept

◆ ParameterSanityChecks()

void ERF::ParameterSanityChecks ( )
private
1898 {
1899  AMREX_ALWAYS_ASSERT(cfl > 0. || fixed_dt[0] > 0.);
1900 
1901  // We don't allow use_real_bcs to be true if init_type is not either InitType::WRFInput or InitType::Metgrid
1902  AMREX_ALWAYS_ASSERT( !solverChoice.use_real_bcs ||
1903  ((solverChoice.init_type == InitType::WRFInput) || (solverChoice.init_type == InitType::Metgrid)) );
1904 
1905  AMREX_ALWAYS_ASSERT(real_width >= 0);
1906  AMREX_ALWAYS_ASSERT(real_set_width >= 0);
1907  AMREX_ALWAYS_ASSERT(real_width >= real_set_width);
1908 
1909  if (cf_width < 0 || cf_set_width < 0 || cf_width < cf_set_width) {
1910  Abort("You must set cf_width >= cf_set_width >= 0");
1911  }
1912  if (max_level > 0 && cf_set_width > 0) {
1913  for (int lev = 1; lev <= max_level; lev++) {
1914  if (cf_set_width%ref_ratio[lev-1][0] != 0 ||
1915  cf_set_width%ref_ratio[lev-1][1] != 0 ||
1916  cf_set_width%ref_ratio[lev-1][2] != 0 ) {
1917  Abort("You must set cf_width to be a multiple of ref_ratio");
1918  }
1919  }
1920  }
1921 
1922  // If fixed_mri_dt_ratio is set, it must be even
1923  if (fixed_mri_dt_ratio > 0 && (fixed_mri_dt_ratio%2 != 0) )
1924  {
1925  Abort("If you specify fixed_mri_dt_ratio, it must be even");
1926  }
1927 
1928  for (int lev = 0; lev <= max_level; lev++)
1929  {
1930  // We ignore fixed_fast_dt if not substepping
1931  if (solverChoice.substepping_type[lev] == SubsteppingType::None) {
1932  fixed_fast_dt[lev] = -1.0;
1933  }
1934 
1935  // If both fixed_dt and fast_dt are specified, their ratio must be an even integer
1936  if (fixed_dt[lev] > 0. && fixed_fast_dt[lev] > 0. && fixed_mri_dt_ratio <= 0)
1937  {
1938  Real eps = 1.e-12;
1939  int ratio = static_cast<int>( ( (1.0+eps) * fixed_dt[lev] ) / fixed_fast_dt[lev] );
1940  if (fixed_dt[lev] / fixed_fast_dt[lev] != ratio)
1941  {
1942  Abort("Ratio of fixed_dt to fixed_fast_dt must be an even integer");
1943  }
1944  }
1945 
1946  // If all three are specified, they must be consistent
1947  if (fixed_dt[lev] > 0. && fixed_fast_dt[lev] > 0. && fixed_mri_dt_ratio > 0)
1948  {
1949  if (fixed_dt[lev] / fixed_fast_dt[lev] != fixed_mri_dt_ratio)
1950  {
1951  Abort("Dt is over-specfied");
1952  }
1953  }
1954  } // lev
1955 
1956  if (solverChoice.coupling_type == CouplingType::TwoWay && cf_width > 0) {
1957  Abort("For two-way coupling you must set cf_width = 0");
1958  }
1959 }
int real_set_width
Definition: ERF.H:1051

◆ PlotFileName()

std::string ERF::PlotFileName ( int  lev) const
private

◆ PlotFileVarNames()

Vector< std::string > ERF::PlotFileVarNames ( amrex::Vector< std::string >  plot_var_names)
staticprivate
250 {
251  Vector<std::string> names;
252 
253  names.insert(names.end(), plot_var_names.begin(), plot_var_names.end());
254 
255  return names;
256 
257 }

◆ poisson_wall_dist()

void ERF::poisson_wall_dist ( int  lev)

Calculate wall distances using the Poisson equation

The zlo boundary is assumed to correspond to the land surface. If there are no boundary walls, then the other use case is to calculate wall distances for immersed boundaries (embedded or thin body).

See Tucker, P. G. (2003). Differential equation-based wall distance computation for DES and RANS. Journal of Computational Physics, 190(1), 229–248. https://doi.org/10.1016/S0021-9991(03)00272-9

21 {
22  BL_PROFILE("ERF::poisson_wall_dist()");
23 
24  bool havewall{false};
25  Orientation zlo(Direction::z, Orientation::low);
26  if ( ( phys_bc_type[zlo] == ERF_BC::surface_layer ) ||
27  ( phys_bc_type[zlo] == ERF_BC::no_slip_wall ) )/*||
28  ((phys_bc_type[zlo] == ERF_BC::slip_wall) && (dom_hi.z > dom_lo.z)) )*/
29  {
30  havewall = true;
31  }
32 
33  auto const& geomdata = geom[lev];
34 
35  if (havewall) {
36  if (solverChoice.mesh_type == MeshType::ConstantDz) {
37 // Comment this out to test the wall dist calc in the trivial case:
38 //#if 0
39  Print() << "Directly calculating direct wall distance for constant dz" << std::endl;
40  const Real* prob_lo = geomdata.ProbLo();
41  const Real* dx = geomdata.CellSize();
42  for (MFIter mfi(*walldist[lev]); mfi.isValid(); ++mfi) {
43  const Box& bx = mfi.validbox();
44  auto dist_arr = walldist[lev]->array(mfi);
45  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
46  dist_arr(i, j, k) = prob_lo[2] + (k + 0.5) * dx[2];
47  });
48  }
49  return;
50 //#endif
51  } else if (solverChoice.mesh_type == MeshType::StretchedDz) {
52  // TODO: Handle this trivial case
53  Error("Wall dist calc not implemented with grid stretching yet");
54  } else {
55  // TODO
56  Error("Wall dist calc not implemented over terrain yet");
57  }
58  }
59 
60  Print() << "Calculating Poisson wall distance" << std::endl;
61 
62  // Make sure the solver only sees the levels over which we are solving
63  BoxArray nba = walldist[lev]->boxArray();
64  nba.surroundingNodes();
65  Vector<Geometry> geom_tmp; geom_tmp.push_back(geom[lev]);
66  Vector<BoxArray> ba_tmp; ba_tmp.push_back(nba);
67  Vector<DistributionMapping> dm_tmp; dm_tmp.push_back(walldist[lev]->DistributionMap());
68 
69  Vector<MultiFab> rhs;
70  Vector<MultiFab> phi;
71 
72  if (solverChoice.terrain_type == TerrainType::EB) {
73  amrex::Error("Wall dist calc not implemented for EB");
74  } else {
75  rhs.resize(1); rhs[0].define(ba_tmp[0], dm_tmp[0], 1, 0);
76  phi.resize(1); phi[0].define(ba_tmp[0], dm_tmp[0], 1, 1);
77  }
78 
79  rhs[0].setVal(-1.0);
80 
81  // Define an overset mask to set dirichlet nodes on walls
82  iMultiFab mask(ba_tmp[0], dm_tmp[0], 1, 0);
83  Vector<const iMultiFab*> overset_mask = {&mask};
84 
85  auto const dom_lo = lbound(geom[lev].Domain());
86  auto const dom_hi = ubound(geom[lev].Domain());
87 
88  // ****************************************************************************
89  // Initialize phi
90  // (It is essential that we do this in order to fill the corners; this is
91  // used if we include blanking.)
92  // ****************************************************************************
93  phi[0].setVal(0.0);
94 
95  // ****************************************************************************
96  // Interior boundaries are marked with phi=0
97  // ****************************************************************************
98  // Overset mask is 0/1: 1 means the node is an unknown. 0 means it's known.
99  mask.setVal(1);
101  Warning("Poisson distance is inaccurate for bodies in open domains that are small compared to the domain size, skipping");
102  return;
103 #if 0
104  Gpu::DeviceVector<IntVect> xfacelist, yfacelist, zfacelist;
105 
106  xfacelist.resize(solverChoice.advChoice.zero_xflux.size());
107  yfacelist.resize(solverChoice.advChoice.zero_yflux.size());
108  zfacelist.resize(solverChoice.advChoice.zero_zflux.size());
109 
110  if (xfacelist.size() > 0) {
111  Gpu::copy(amrex::Gpu::hostToDevice,
114  xfacelist.begin());
115  Print() << " masking interior xfaces" << std::endl;
116  }
117  if (yfacelist.size() > 0) {
118  Gpu::copy(amrex::Gpu::hostToDevice,
121  yfacelist.begin());
122  Print() << " masking interior yfaces" << std::endl;
123  }
124  if (zfacelist.size() > 0) {
125  Gpu::copy(amrex::Gpu::hostToDevice,
128  zfacelist.begin());
129  Print() << " masking interior zfaces" << std::endl;
130  }
131 
132  for (MFIter mfi(phi[0]); mfi.isValid(); ++mfi) {
133  const Box& bx = mfi.validbox();
134 
135  auto phi_arr = phi[0].array(mfi);
136  auto mask_arr = mask.array(mfi);
137 
138  if (xfacelist.size() > 0) {
139  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
140  for (int iface=0; iface < xfacelist.size(); ++iface) {
141  if ((i == xfacelist[iface][0]) &&
142  (j == xfacelist[iface][1]) &&
143  (k == xfacelist[iface][2]))
144  {
145  mask_arr(i, j , k ) = 0;
146  mask_arr(i, j , k+1) = 0;
147  mask_arr(i, j+1, k ) = 0;
148  mask_arr(i, j+1, k+1) = 0;
149  }
150  }
151  });
152  }
153 
154  if (yfacelist.size() > 0) {
155  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
156  for (int iface=0; iface < yfacelist.size(); ++iface) {
157  if ((i == yfacelist[iface][0]) &&
158  (j == yfacelist[iface][1]) &&
159  (k == yfacelist[iface][2]))
160  {
161  mask_arr(i , j, k ) = 0;
162  mask_arr(i , j, k+1) = 0;
163  mask_arr(i+1, j, k ) = 0;
164  mask_arr(i+1, j, k+1) = 0;
165  }
166  }
167  });
168  }
169 
170  if (zfacelist.size() > 0) {
171  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
172  for (int iface=0; iface < zfacelist.size(); ++iface) {
173  if ((i == xfacelist[iface][0]) &&
174  (j == xfacelist[iface][1]) &&
175  (k == xfacelist[iface][2]))
176  {
177  mask_arr(i , j , k) = 0;
178  mask_arr(i , j+1, k) = 0;
179  mask_arr(i+1, j , k) = 0;
180  mask_arr(i+1, j+1, k) = 0;
181  }
182  }
183  });
184  }
185  }
186 #endif
187  }
188 
189  // ****************************************************************************
190  // Setup BCs, with solid domain boundaries being dirichlet
191  // ****************************************************************************
192  amrex::Array<amrex::LinOpBCType,AMREX_SPACEDIM> bc3d_lo, bc3d_hi;
193  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
194  if (geom[0].isPeriodic(dir)) {
195  bc3d_lo[dir] = LinOpBCType::Periodic;
196  bc3d_hi[dir] = LinOpBCType::Periodic;
197  } else {
198  bc3d_lo[dir] = LinOpBCType::Neumann;
199  bc3d_hi[dir] = LinOpBCType::Neumann;
200  }
201  }
202  if (havewall) {
203  Print() << " Poisson zlo BC is dirichlet" << std::endl;
204  bc3d_lo[2] = LinOpBCType::Dirichlet;
205  }
206  Print() << " bc lo : " << bc3d_lo << std::endl;
207  Print() << " bc hi : " << bc3d_hi << std::endl;
208 
209  if (!solverChoice.advChoice.have_zero_flux_faces && !havewall) {
210  Error("No solid boundaries in the computational domain");
211  }
212 
213  LPInfo info;
214 /* Nodal solver cannot have hidden dimensions */
215 #if 0
216  // Allow a hidden direction if the domain is one cell wide
217  if (dom_lo.x == dom_hi.x) {
218  info.setHiddenDirection(0);
219  Print() << " domain is 2D in yz" << std::endl;
220  } else if (dom_lo.y == dom_hi.y) {
221  info.setHiddenDirection(1);
222  Print() << " domain is 2D in xz" << std::endl;
223  } else if (dom_lo.z == dom_hi.z) {
224  info.setHiddenDirection(2);
225  Print() << " domain is 2D in xy" << std::endl;
226  }
227 #endif
228 
229  // ****************************************************************************
230  // Solve nodal masked Poisson problem with MLMG
231  // TODO: different solver for terrain?
232  // ****************************************************************************
233  const Real reltol = solverChoice.poisson_reltol;
234  const Real abstol = solverChoice.poisson_abstol;
235 
236  Real sigma = 1.0;
237  Vector<EBFArrayBoxFactory const*> factory_vec = { &EBFactory(lev) };
238  MLNodeLaplacian mlpoisson(geom_tmp, ba_tmp, dm_tmp, info, factory_vec, sigma);
239 
240  mlpoisson.setDomainBC(bc3d_lo, bc3d_hi);
241 
242  if (lev > 0) {
243  mlpoisson.setCoarseFineBC(nullptr, ref_ratio[lev-1], LinOpBCType::Neumann);
244  }
245 
246  mlpoisson.setLevelBC(0, nullptr);
247 
248  mlpoisson.setOversetMask(0, mask);
249 
250  // Solve
251  MLMG mlmg(mlpoisson);
252  int max_iter = 100;
253  mlmg.setMaxIter(max_iter);
254 
255  mlmg.setVerbose(mg_verbose);
256  mlmg.setBottomVerbose(0);
257 
258  mlmg.solve(GetVecOfPtrs(phi),
259  GetVecOfConstPtrs(rhs),
260  reltol, abstol);
261 
262  // Now overwrite with periodic fill outside domain and fine-fine fill inside
263  phi[0].FillBoundary(geom[lev].periodicity());
264 
265  // ****************************************************************************
266  // Compute grad(phi) to get distances
267  // - Note that phi is nodal and walldist is cell-centered
268  // - TODO: include terrain metrics for dphi/dz
269  // ****************************************************************************
270  for (MFIter mfi(*walldist[lev]); mfi.isValid(); ++mfi) {
271  const Box& bx = mfi.validbox();
272 
273  const auto invCellSize = geomdata.InvCellSizeArray();
274 
275  auto const& phi_arr = phi[0].const_array(mfi);
276  auto dist_arr = walldist[lev]->array(mfi);
277 
278  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
279  Real dpdx{0}, dpdy{0}, dpdz{0};
280 
281  // dphi/dx
282  if (dom_lo.x != dom_hi.x) {
283  dpdx = 0.25 * invCellSize[0] * (
284  (phi_arr(i+1, j , k ) - phi_arr(i, j , k ))
285  + (phi_arr(i+1, j , k+1) - phi_arr(i, j , k+1))
286  + (phi_arr(i+1, j+1, k ) - phi_arr(i, j+1, k ))
287  + (phi_arr(i+1, j+1, k+1) - phi_arr(i, j+1, k+1)) );
288  }
289 
290  // dphi/dy
291  if (dom_lo.y != dom_hi.y) {
292  dpdy = 0.25 * invCellSize[1] * (
293  (phi_arr(i , j+1, k ) - phi_arr(i , j, k ))
294  + (phi_arr(i , j+1, k+1) - phi_arr(i , j, k+1))
295  + (phi_arr(i+1, j+1, k ) - phi_arr(i+1, j, k ))
296  + (phi_arr(i+1, j+1, k+1) - phi_arr(i+1, j, k+1)) );
297  }
298 
299  // dphi/dz
300  if (dom_lo.z != dom_hi.z) {
301  dpdz = 0.25 * invCellSize[2] * (
302  (phi_arr(i , j , k+1) - phi_arr(i , j , k))
303  + (phi_arr(i , j+1, k+1) - phi_arr(i , j+1, k))
304  + (phi_arr(i+1, j , k+1) - phi_arr(i+1, j , k))
305  + (phi_arr(i+1, j+1, k+1) - phi_arr(i+1, j+1, k)) );
306  }
307 
308  Real dp_dot_dp = dpdx*dpdx + dpdy*dpdy + dpdz*dpdz;
309  Real phi_avg = 0.125 * (
310  phi_arr(i , j , k ) + phi_arr(i , j , k+1) + phi_arr(i , j+1, k ) + phi_arr(i , j+1, k+1)
311  + phi_arr(i+1, j , k ) + phi_arr(i+1, j , k+1) + phi_arr(i+1, j+1, k ) + phi_arr(i+1, j+1, k+1) );
312  dist_arr(i, j, k) = -std::sqrt(dp_dot_dp) + std::sqrt(dp_dot_dp + 2*phi_avg);
313 
314  // DEBUG: output phi instead
315  //dist_arr(i, j, k) = phi_arr(i, j, k);
316  });
317  }
318 }
if(l_use_mynn &&start_comp<=RhoKE_comp &&end_comp >=RhoKE_comp)
Definition: ERF_DiffQKEAdjustment.H:2
static int mg_verbose
Definition: ERF.H:1028
amrex::Real poisson_reltol
Definition: ERF_DataStruct.H:724
amrex::Real poisson_abstol
Definition: ERF_DataStruct.H:723
Here is the call graph for this function:

◆ post_timestep()

void ERF::post_timestep ( int  nstep,
amrex::Real  time,
amrex::Real  dt_lev 
)
505 {
506  BL_PROFILE("ERF::post_timestep()");
507 
508 #ifdef ERF_USE_PARTICLES
509  particleData.Redistribute();
510 #endif
511 
512  if (solverChoice.coupling_type == CouplingType::TwoWay)
513  {
514  int ncomp = vars_new[0][Vars::cons].nComp();
515  for (int lev = finest_level-1; lev >= 0; lev--)
516  {
517  // The quantity that is conserved is not (rho S), but rather (rho S / m^2) where
518  // m is the map scale factor at cell centers
519  // Here we pre-divide (rho S) by m^2 before refluxing
520  for (MFIter mfi(vars_new[lev][Vars::cons], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
521  const Box& bx = mfi.tilebox();
522  const Array4< Real> cons_arr = vars_new[lev][Vars::cons].array(mfi);
523  const Array4<const Real> mfx_arr = mapfac[lev][MapFacType::m_x]->const_array(mfi);
524  const Array4<const Real> mfy_arr = mapfac[lev][MapFacType::m_y]->const_array(mfi);
525  if (SolverChoice::mesh_type == MeshType::ConstantDz) {
526  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
527  {
528  cons_arr(i,j,k,n) /= (mfx_arr(i,j,0)*mfy_arr(i,j,0));
529  });
530  } else {
531  const Array4<const Real> detJ_arr = detJ_cc[lev]->const_array(mfi);
532  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
533  {
534  cons_arr(i,j,k,n) *= detJ_arr(i,j,k) / (mfx_arr(i,j,0)*mfy_arr(i,j,0));
535  });
536  }
537  } // mfi
538 
539  // This call refluxes all "slow" cell-centered variables
540  // (i.e. not density or (rho theta) or velocities) from the lev/lev+1 interface onto lev
541  getAdvFluxReg(lev+1)->Reflux(vars_new[lev][Vars::cons], 2, 2, ncomp-2);
542 
543  // Here we multiply (rho S) by m^2 after refluxing
544  for (MFIter mfi(vars_new[lev][Vars::cons], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
545  const Box& bx = mfi.tilebox();
546  const Array4< Real> cons_arr = vars_new[lev][Vars::cons].array(mfi);
547  const Array4<const Real> mfx_arr = mapfac[lev][MapFacType::m_x]->const_array(mfi);
548  const Array4<const Real> mfy_arr = mapfac[lev][MapFacType::m_y]->const_array(mfi);
549  if (SolverChoice::mesh_type == MeshType::ConstantDz) {
550  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
551  {
552  cons_arr(i,j,k,n) *= (mfx_arr(i,j,0)*mfy_arr(i,j,0));
553  });
554  } else {
555  const Array4<const Real> detJ_arr = detJ_cc[lev]->const_array(mfi);
556  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
557  {
558  cons_arr(i,j,k,n) *= (mfx_arr(i,j,0)*mfy_arr(i,j,0)) / detJ_arr(i,j,k);
559  });
560  }
561  } // mfi
562 
563  // We need to do this before anything else because refluxing changes the
564  // values of coarse cells underneath fine grids with the assumption they'll
565  // be over-written by averaging down
566  int src_comp;
567  if (solverChoice.anelastic[lev]) {
568  src_comp = 1;
569  } else {
570  src_comp = 0;
571  }
572  int num_comp = ncomp - src_comp;
573  AverageDownTo(lev,src_comp,num_comp);
574  }
575  }
576 
577  if (is_it_time_for_action(nstep, time, dt_lev0, sum_interval, sum_per)) {
580  sum_energy_quantities(time);
581  }
582 
583  if (solverChoice.pert_type == PerturbationType::Source ||
584  solverChoice.pert_type == PerturbationType::Direct ||
585  solverChoice.pert_type == PerturbationType::CPM) {
586  if (is_it_time_for_action(nstep, time, dt_lev0, pert_interval, -1.)) {
587  turbPert.debug(time);
588  }
589  }
590 
591  if (profile_int > 0 && (nstep+1) % profile_int == 0) {
592  if (destag_profiles) {
593  // all variables cell-centered
594  write_1D_profiles(time);
595  } else {
596  // some variables staggered
598  }
599  }
600 
601  if (solverChoice.rad_type != RadiationType::None)
602  {
603  if (rad_datalog_int > 0 && (nstep+1) % rad_datalog_int == 0) {
604  if (rad[0]->hasDatalog()) {
605  rad[0]->WriteDataLog(time);
606  }
607  }
608  }
609 
610  if (output_1d_column) {
611 #ifdef ERF_USE_NETCDF
612  if (is_it_time_for_action(nstep, time, dt_lev0, column_interval, column_per))
613  {
614  int lev_column = 0;
615  for (int lev = finest_level; lev >= 0; lev--)
616  {
617  Real dx_lev = geom[lev].CellSize(0);
618  Real dy_lev = geom[lev].CellSize(1);
619  int i_lev = static_cast<int>(std::floor(column_loc_x / dx_lev));
620  int j_lev = static_cast<int>(std::floor(column_loc_y / dy_lev));
621  if (grids[lev].contains(IntVect(i_lev,j_lev,0))) lev_column = lev;
622  }
623  writeToNCColumnFile(lev_column, column_file_name, column_loc_x, column_loc_y, time);
624  }
625 #else
626  Abort("To output 1D column files ERF must be compiled with NetCDF");
627 #endif
628  }
629 
631  {
634  {
635  bool is_moist = (micro->Get_Qstate_Moist_Size() > 0);
636  m_w2d->write_planes(istep[0], time, vars_new, is_moist);
637  }
638  }
639 
640  // Write plane/line sampler data
641  if (is_it_time_for_action(nstep+1, time, dt_lev0, sampler_interval, sampler_per) && (data_sampler) ) {
642  data_sampler->get_sample_data(geom, vars_new);
643  data_sampler->write_sample_data(t_new, istep, ref_ratio, geom);
644  }
645 
646  // Moving terrain
647  if ( solverChoice.terrain_type == TerrainType::MovingFittedMesh )
648  {
649  for (int lev = finest_level; lev >= 0; lev--)
650  {
651  // Copy z_phs_nd and detJ_cc at end of timestep
652  MultiFab::Copy(*z_phys_nd[lev], *z_phys_nd_new[lev], 0, 0, 1, z_phys_nd[lev]->nGrowVect());
653  MultiFab::Copy( *detJ_cc[lev], *detJ_cc_new[lev], 0, 0, 1, detJ_cc[lev]->nGrowVect());
654  MultiFab::Copy(base_state[lev],base_state_new[lev],0,0,BaseState::num_comps,base_state[lev].nGrowVect());
655 
656  make_zcc(geom[lev],*z_phys_nd[lev],*z_phys_cc[lev]);
657  }
658  }
659 
660  bool is_hurricane_tracker_io=false;
661  ParmParse pp("erf");
662  pp.query("is_hurricane_tracker_io", is_hurricane_tracker_io);
663 
664  if(is_hurricane_tracker_io) {
665  if(nstep == 0 or (nstep+1)%m_plot_int_1 == 0){
666  std::string filename = MakeVTKFilename(nstep);
667  Real velmag_threshold = 1e10;
668  pp.query("hurr_track_io_velmag_greater_than", velmag_threshold);
669  if(velmag_threshold==1e10) {
670  Abort("As hurricane tracking IO is active using erf.is_hurricane_tracker_io = true"
671  " there needs to be an input erf.hurr_track_io_velmag_greater_than which specifies the"
672  " magnitude of velocity above which cells will be tagged for refinement.");
673  }
674  int levc=finest_level;
675  MultiFab& U_new = vars_new[levc][Vars::xvel];
676  MultiFab& V_new = vars_new[levc][Vars::yvel];
677  MultiFab& W_new = vars_new[levc][Vars::zvel];
678 
679  HurricaneTracker(levc, U_new, V_new, W_new, velmag_threshold, true);
680  if (ParallelDescriptor::IOProcessor()) {
682  }
683  }
684  }
685 } // post_timestep
void make_zcc(const Geometry &geom, MultiFab &z_phys_nd, MultiFab &z_phys_cc)
Definition: ERF_TerrainMetrics.cpp:623
static amrex::Real column_loc_y
Definition: ERF.H:1086
static std::string column_file_name
Definition: ERF.H:1087
AMREX_FORCE_INLINE amrex::YAFluxRegister * getAdvFluxReg(int lev)
Definition: ERF.H:1230
static amrex::Real bndry_output_planes_per
Definition: ERF.H:1092
std::string MakeVTKFilename(int nstep)
Definition: ERF_Write1DProfiles.cpp:574
static amrex::Real column_per
Definition: ERF.H:1084
amrex::Real sampler_per
Definition: ERF.H:1411
static amrex::Real column_loc_x
Definition: ERF.H:1085
static int bndry_output_planes_interval
Definition: ERF.H:1091
int sampler_interval
Definition: ERF.H:1410
static int output_1d_column
Definition: ERF.H:1082
void WriteVTKPolyline(const std::string &filename, amrex::Vector< std::array< amrex::Real, 2 >> &points_xy)
Definition: ERF_Write1DProfiles.cpp:593
static int column_interval
Definition: ERF.H:1083
Here is the call graph for this function:

◆ post_update()

void ERF::post_update ( amrex::MultiFab &  state_mf,
amrex::Real  time,
const amrex::Geometry &  geom 
)
private

◆ print_banner()

void ERF::print_banner ( MPI_Comm  comm,
std::ostream &  out 
)
static
65  : " << msg << std::endl;
66 }
67 
68 void ERF::print_banner (MPI_Comm comm, std::ostream& out)
69 {
70 #ifdef AMREX_USE_MPI
71  int irank = 0;
72  int num_ranks = 1;
73  MPI_Comm_size(comm, &num_ranks);
74  MPI_Comm_rank(comm, &irank);
75 
76  // Only root process does the printing
77  if (irank != 0) return;
78 #else
79  amrex::ignore_unused(comm);
80 #endif
81 
82  auto etime = std::chrono::system_clock::now();
83  auto etimet = std::chrono::system_clock::to_time_t(etime);
84 #ifndef _WIN32
85  char time_buf[64];
86  ctime_r(&etimet, time_buf);
87  const std::string tstamp(time_buf);
88 #else
89  char* time_buf = new char[64];
90  ctime_s(time_buf, 64, &etimet);
91  const std::string tstamp(time_buf);
92 #endif
93 
94  const char* githash1 = amrex::buildInfoGetGitHash(1);
95  const char* githash2 = amrex::buildInfoGetGitHash(2);
96 
97  // clang-format off
98  out << dbl_line
99  << " ERF (https://github.com/erf-model/ERF)"
100  << std::endl << std::endl
101  << " ERF Git SHA :: " << githash1 << std::endl
102  << " AMReX Git SHA :: " << githash2 << std::endl
103  << " AMReX version :: " << amrex::Version() << std::endl << std::endl
104  << " Exec. time :: " << tstamp
105  << " Build time :: " << amrex::buildInfoGetBuildDate() << std::endl
106  << " C++ compiler :: " << amrex::buildInfoGetComp()
107  << " " << amrex::buildInfoGetCompVersion() << std::endl << std::endl
108  << " MPI :: "
109 #ifdef AMREX_USE_MPI
110  << "ON (Num. ranks = " << num_ranks << ")" << std::endl
111 #else
112  << "OFF " << std::endl
113 #endif
114  << " GPU :: "
115 #ifdef AMREX_USE_GPU
116  << "ON "
117 #if defined(AMREX_USE_CUDA)
118  << "(Backend: CUDA)"
119 #elif defined(AMREX_USE_HIP)
120  << "(Backend: HIP)"
121 #elif defined(AMREX_USE_SYCL)
122  << "(Backend: SYCL)"
123 #endif
124  << std::endl
125 #else
126  << "OFF" << std::endl
127 #endif
128  << " OpenMP :: "
129 #ifdef AMREX_USE_OMP
130  << "ON (Num. threads = " << omp_get_max_threads() << ")" << std::endl
131 #else
132  << "OFF" << std::endl
133 #endif
134  << std::endl;
135 
ERF()
Definition: ERF.cpp:92
const char * buildInfoGetBuildDate()
const char * buildInfoGetComp()
const char * buildInfoGetCompVersion()

Referenced by main().

Here is the caller graph for this function:

◆ print_error()

void ERF::print_error ( MPI_Comm  comm,
const std::string &  msg 
)
static
43  :
44  input_file : Input file with simulation settings
45 
46 Optional:
47  param=value : Overrides for parameters during runtime
48 )doc" << std::endl;
49 }
50 
51 void ERF::print_error (MPI_Comm comm, const std::string& msg)
52 {
53 #ifdef AMREX_USE_MPI
54  int irank = 0;
55  int num_ranks = 1;
56  MPI_Comm_size(comm, &num_ranks);
57  MPI_Comm_rank(comm, &irank);
58 

Referenced by main().

Here is the caller graph for this function:

◆ print_summary()

static void ERF::print_summary ( std::ostream &  )
static

◆ print_tpls()

void ERF::print_tpls ( std::ostream &  out)
static
140  ://github.com/erf-model/ERF/blob/development/LICENSE for details. "
141  << dash_line << std::endl;
142  // clang-format on
143 }
144 
145 void ERF::print_tpls (std::ostream& out)
146 {
147  amrex::Vector<std::string> tpls;
148 
149 #ifdef ERF_USE_NETCDF
150  tpls.push_back(std::string("NetCDF ") + NC_VERSION);
151 #endif
152 #ifdef AMREX_USE_SUNDIALS
153  tpls.push_back(std::string("SUNDIALS ") + SUNDIALS_VERSION);
154 #endif
155 
156  if (!tpls.empty()) {
157  out << " Enabled third-party libraries: ";
158  for (const auto& val : tpls) {
static void print_tpls(std::ostream &)
Definition: ERF_ConsoleIO.cpp:137

◆ print_usage()

void ERF::print_usage ( MPI_Comm  comm,
std::ostream &  out 
)
static
27 {
28 #ifdef AMREX_USE_MPI
29  int irank = 0;
30  int num_ranks = 1;
31  MPI_Comm_size(comm, &num_ranks);
32  MPI_Comm_rank(comm, &irank);
33 
34  // Only root process does the printing
35  if (irank != 0) return;
36 #else
37  amrex::ignore_unused(comm);
38 #endif
39 
40  out << R"doc(Usage:
41  ERF3d.*.ex <input_file> [param=value] [param=value] ...

Referenced by main().

Here is the caller graph for this function:

◆ project_momenta()

void ERF::project_momenta ( int  lev,
amrex::Real  dt,
amrex::Vector< amrex::MultiFab > &  vars 
)

Project the single-level momenta to enforce the anelastic constraint Note that the level may or may not be level 0.

35 {
36  BL_PROFILE("ERF::project_momenta()");
37 
38  auto const dom_lo = lbound(geom[lev].Domain());
39  auto const dom_hi = ubound(geom[lev].Domain());
40 
41  // Make sure the solver only sees the levels over which we are solving
42  Vector<BoxArray> ba_tmp; ba_tmp.push_back(mom_mf[Vars::cons].boxArray());
43  Vector<DistributionMapping> dm_tmp; dm_tmp.push_back(mom_mf[Vars::cons].DistributionMap());
44  Vector<Geometry> geom_tmp; geom_tmp.push_back(geom[lev]);
45 
46  MultiFab r_hse(base_state[lev], make_alias, BaseState::r0_comp, 1);
47 
48  Vector<MultiFab> rhs;
49  Vector<MultiFab> phi;
50 
51  if (solverChoice.terrain_type == TerrainType::EB)
52  {
53  rhs.resize(1); rhs[0].define(ba_tmp[0], dm_tmp[0], 1, 0, MFInfo(), EBFactory(lev));
54  phi.resize(1); phi[0].define(ba_tmp[0], dm_tmp[0], 1, 1, MFInfo(), EBFactory(lev));
55  } else {
56  rhs.resize(1); rhs[0].define(ba_tmp[0], dm_tmp[0], 1, 0);
57  phi.resize(1); phi[0].define(ba_tmp[0], dm_tmp[0], 1, 1);
58  }
59 
60  auto dxInv = geom[lev].InvCellSizeArray();
61 
62  // Inflow on an x-face -- note only the normal velocity is used in the projection
63  if (domain_bc_type[0] == "Inflow" || domain_bc_type[3] == "Inflow") {
65  IntVect{1,0,0},t_new[lev],BCVars::xvel_bc,false);
66  }
67 
68  // Inflow on a y-face -- note only the normal velocity is used in the projection
69  if (domain_bc_type[1] == "Inflow" || domain_bc_type[4] == "Inflow") {
71  IntVect{0,1,0},t_new[lev],BCVars::yvel_bc,false);
72  }
73 
74  if (domain_bc_type[0] == "Inflow" || domain_bc_type[3] == "Inflow" ||
75  domain_bc_type[1] == "Inflow" || domain_bc_type[4] == "Inflow") {
76  VelocityToMomentum(vars_new[lev][Vars::xvel], IntVect{0},
77  vars_new[lev][Vars::yvel], IntVect{0},
78  vars_new[lev][Vars::zvel], IntVect{0},
79  vars_new[lev][Vars::cons],
80  mom_mf[IntVars::xmom],
81  mom_mf[IntVars::ymom],
82  mom_mf[IntVars::zmom],
83  Geom(lev).Domain(),
85  }
86 
87  // If !fixed_density, we must convert (rho u) which came in
88  // to (rho0 u) which is what we will project
90  ConvertForProjection(mom_mf[Vars::cons], r_hse,
91  mom_mf[IntVars::xmom],
92  mom_mf[IntVars::ymom],
93  mom_mf[IntVars::zmom],
94  Geom(lev).Domain(),
96  }
97 
98  //
99  // ****************************************************************************
100  // Now convert the rho0w MultiFab to hold Omega rather than rhow
101  // ****************************************************************************
102  //
103  if (solverChoice.mesh_type == MeshType::VariableDz)
104  {
105  for ( MFIter mfi(rhs[0],TilingIfNotGPU()); mfi.isValid(); ++mfi)
106  {
107  const Array4<Real const>& rho0u_arr = mom_mf[IntVars::xmom].const_array(mfi);
108  const Array4<Real const>& rho0v_arr = mom_mf[IntVars::ymom].const_array(mfi);
109  const Array4<Real >& rho0w_arr = mom_mf[IntVars::zmom].array(mfi);
110 
111  const Array4<Real const>& z_nd = z_phys_nd[lev]->const_array(mfi);
112  const Array4<Real const>& mf_u = mapfac[lev][MapFacType::u_x]->const_array(mfi);
113  const Array4<Real const>& mf_v = mapfac[lev][MapFacType::v_y]->const_array(mfi);
114 
115  //
116  // Define Omega from (rho0 W) but store it in the same array
117  //
118  Box tbz = mfi.nodaltilebox(2);
119  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
120  if (k > dom_lo.z && k <= dom_hi.z) {
121  Real rho0w = rho0w_arr(i,j,k);
122  rho0w_arr(i,j,k) = OmegaFromW(i,j,k,rho0w,
123  rho0u_arr,rho0v_arr,
124  mf_u,mf_v,z_nd,dxInv);
125  } else {
126  rho0w_arr(i,j,k) = Real(0.0);
127  }
128  });
129  } // mfi
130  }
131 
132  // ****************************************************************************
133  // Compute divergence which will form RHS
134  // Note that we replace "rho0w" with the contravariant momentum, Omega
135  // ****************************************************************************
136  Array<MultiFab const*, AMREX_SPACEDIM> rho0_u_const;
137  rho0_u_const[0] = &mom_mf[IntVars::xmom];
138  rho0_u_const[1] = &mom_mf[IntVars::ymom];
139  rho0_u_const[2] = &mom_mf[IntVars::zmom];
140 
141  compute_divergence(lev, rhs[0], rho0_u_const, geom_tmp[0]);
142 
143  Real rhsnorm = rhs[0].norm0();
144 
145  if (mg_verbose > 0) {
146  Print() << "Max/L2 norm of divergence before solve at level " << lev << " : " << rhsnorm << " " << rhs[0].norm2() << std::endl;
147  }
148 
149  // ****************************************************************************
150  //
151  // No need to build the solver if RHS == 0
152  //
153  if (rhsnorm <= solverChoice.poisson_abstol) return;
154  // ****************************************************************************
155 
156  // ****************************************************************************
157  // Initialize phi to 0
158  // (It is essential that we do this in order to fill the corners; these are never
159  // used but the Saxpy requires the values to be initialized.)
160  // ****************************************************************************
161  phi[0].setVal(0.0);
162 
163  Real start_step = static_cast<Real>(ParallelDescriptor::second());
164 
165  // ****************************************************************************
166  // Allocate fluxes
167  // ****************************************************************************
168  Vector<Array<MultiFab,AMREX_SPACEDIM> > fluxes;
169  fluxes.resize(1);
170  for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
171  if (solverChoice.terrain_type == TerrainType::EB) {
172  fluxes[0][idim].define(convert(ba_tmp[0], IntVect::TheDimensionVector(idim)), dm_tmp[0], 1, 0, MFInfo(), EBFactory(lev));
173  } else {
174  fluxes[0][idim].define(convert(ba_tmp[0], IntVect::TheDimensionVector(idim)), dm_tmp[0], 1, 0);
175  }
176  }
177 
178  // ****************************************************************************
179  // Choose the solver and solve
180  // ****************************************************************************
181 
182  // ****************************************************************************
183  // EB
184  // ****************************************************************************
185  if (solverChoice.terrain_type == TerrainType::EB) {
186  solve_with_EB_mlmg(lev, rhs, phi, fluxes);
187  } else {
188 
189 #ifdef ERF_USE_FFT
190  Box my_region(ba_tmp[0].minimalBox());
191  bool boxes_make_rectangle = (my_region.numPts() == ba_tmp[0].numPts());
192 #endif
193 
194  // ****************************************************************************
195  // No terrain or grid stretching
196  // ****************************************************************************
197  if (solverChoice.mesh_type == MeshType::ConstantDz) {
198 #ifdef ERF_USE_FFT
199  if (use_fft) {
200  if (boxes_make_rectangle) {
201  solve_with_fft(lev, rhs[0], phi[0], fluxes[0]);
202  } else {
203  amrex::Warning("FFT won't work unless the union of boxes is rectangular: defaulting to MLMG");
204  solve_with_mlmg(lev, rhs, phi, fluxes);
205  }
206  } else {
207  solve_with_mlmg(lev, rhs, phi, fluxes);
208  }
209 #else
210  if (use_fft) {
211  amrex::Warning("You set use_fft=true but didn't build with USE_FFT = TRUE; defaulting to MLMG");
212  }
213  solve_with_mlmg(lev, rhs, phi, fluxes);
214 #endif
215  } // No terrain or grid stretching
216 
217  // ****************************************************************************
218  // Grid stretching (flat terrain)
219  // ****************************************************************************
220  else if (solverChoice.mesh_type == MeshType::StretchedDz) {
221 #ifndef ERF_USE_FFT
222  amrex::Abort("Rebuild with USE_FFT = TRUE so you can use the FFT solver");
223 #else
224  if (!boxes_make_rectangle) {
225  amrex::Abort("FFT won't work unless the union of boxes is rectangular");
226  } else {
227  if (!use_fft) {
228  amrex::Warning("Using FFT even though you didn't set use_fft to true; it's the best choice");
229  }
230  solve_with_fft(lev, rhs[0], phi[0], fluxes[0]);
231  }
232 #endif
233  } // grid stretching
234 
235  // ****************************************************************************
236  // General terrain
237  // ****************************************************************************
238  else if (solverChoice.mesh_type == MeshType::VariableDz) {
239 #ifdef ERF_USE_FFT
240  if (use_fft)
241  {
242  amrex::Warning("FFT solver does not work for general terrain: switching to FFT-preconditioned GMRES");
243  }
244  if (!boxes_make_rectangle) {
245  amrex::Abort("FFT preconditioner for GMRES won't work unless the union of boxes is rectangular");
246  } else {
247  solve_with_gmres(lev, rhs, phi, fluxes);
248  }
249 #else
250  amrex::Abort("Rebuild with USE_FFT = TRUE so you can use the FFT preconditioner for GMRES");
251 #endif
252  } // general terrain
253 
254  } // not EB
255 
256  // ****************************************************************************
257  // Print time in solve
258  // ****************************************************************************
259  Real end_step = static_cast<Real>(ParallelDescriptor::second());
260  if (mg_verbose > 0) {
261  amrex::Print() << "Time in solve " << end_step - start_step << std::endl;
262  }
263 
264  // ****************************************************************************
265  // Subtract dt grad(phi) from the momenta (rho0u, rho0v, Omega)
266  // ****************************************************************************
267  MultiFab::Add(mom_mf[IntVars::xmom],fluxes[0][0],0,0,1,0);
268  MultiFab::Add(mom_mf[IntVars::ymom],fluxes[0][1],0,0,1,0);
269  MultiFab::Add(mom_mf[IntVars::zmom],fluxes[0][2],0,0,1,0);
270 
271  // ****************************************************************************
272  // Define gradp from fluxes -- note that fluxes is dt * change in Gp
273  // ****************************************************************************
274  MultiFab::Saxpy(gradp[lev][GpVars::gpx],-1.0/l_dt,fluxes[0][0],0,0,1,0);
275  MultiFab::Saxpy(gradp[lev][GpVars::gpy],-1.0/l_dt,fluxes[0][1],0,0,1,0);
276  MultiFab::Saxpy(gradp[lev][GpVars::gpz],-1.0/l_dt,fluxes[0][2],0,0,1,0);
277 
278  gradp[lev][GpVars::gpx].FillBoundary(geom_tmp[0].periodicity());
279  gradp[lev][GpVars::gpy].FillBoundary(geom_tmp[0].periodicity());
280  gradp[lev][GpVars::gpz].FillBoundary(geom_tmp[0].periodicity());
281 
282  //
283  // This call is only to verify the divergence after the solve
284  // It is important we do this before computing the rho0w_arr from Omega back to rho0w
285  //
286  // ****************************************************************************
287  // THIS IS SIMPLY VERIFYING THE DIVERGENCE AFTER THE SOLVE
288  // ****************************************************************************
289  //
290  if (mg_verbose > 0)
291  {
292  compute_divergence(lev, rhs[0], rho0_u_const, geom_tmp[0]);
293 
294  Print() << "Max/L2 norm of divergence after solve at level " << lev << " : " << rhs[0].norm0() << " " << rhs[0].norm2() << std::endl;
295 
296 #if 0
297  // FOR DEBUGGING ONLY
298  for ( MFIter mfi(rhs[0],TilingIfNotGPU()); mfi.isValid(); ++mfi)
299  {
300  const Array4<Real const>& rhs_arr = rhs[0].const_array(mfi);
301  Box bx = mfi.validbox();
302  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
303  if (std::abs(rhs_arr(i,j,k)) > 1.e-10) {
304  amrex::AllPrint() << "RHS AFTER SOLVE AT " <<
305  IntVect(i,j,k) << " " << rhs_arr(i,j,k) << std::endl;
306  }
307  });
308  } // mfi
309 #endif
310 
311  } // mg_verbose
312 
313  //
314  // ****************************************************************************
315  // Now convert the rho0w MultiFab back to holding (rho0w) rather than Omega
316  // ****************************************************************************
317  //
318  if (solverChoice.mesh_type == MeshType::VariableDz)
319  {
320  for (MFIter mfi(mom_mf[Vars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi)
321  {
322  Box tbz = mfi.nodaltilebox(2);
323  const Array4<Real >& rho0u_arr = mom_mf[IntVars::xmom].array(mfi);
324  const Array4<Real >& rho0v_arr = mom_mf[IntVars::ymom].array(mfi);
325  const Array4<Real >& rho0w_arr = mom_mf[IntVars::zmom].array(mfi);
326  const Array4<Real const>& z_nd = z_phys_nd[lev]->const_array(mfi);
327  const Array4<Real const>& mf_u = mapfac[lev][MapFacType::u_x]->const_array(mfi);
328  const Array4<Real const>& mf_v = mapfac[lev][MapFacType::v_y]->const_array(mfi);
329  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
330  Real omega = rho0w_arr(i,j,k);
331  rho0w_arr(i,j,k) = WFromOmega(i,j,k,omega,
332  rho0u_arr,rho0v_arr,
333  mf_u,mf_v,z_nd,dxInv);
334  });
335  } // mfi
336  }
337 
338  // If !fixed_density, we must convert (rho0 u) back
339  // to (rho0 u) which is what we will pass back out
341  ConvertForProjection(r_hse, mom_mf[Vars::cons],
342  mom_mf[IntVars::xmom],
343  mom_mf[IntVars::ymom],
344  mom_mf[IntVars::zmom],
345  Geom(lev).Domain(),
347  }
348 
349  // ****************************************************************************
350  // Update pressure variable with phi -- note that phi is dt * change in pressure
351  // ****************************************************************************
352  MultiFab::Saxpy(pp_inc[lev], 1.0/l_dt, phi[0],0,0,1,1);
353 }
void ConvertForProjection(const MultiFab &den_div, const MultiFab &den_mlt, MultiFab &xmom, MultiFab &ymom, MultiFab &zmom, const Box &domain, const Vector< BCRec > &domain_bcs_type_h)
Definition: ERF_ConvertForProjection.cpp:25
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real WFromOmega(int &i, int &j, int &k, amrex::Real omega, const amrex::Array4< const amrex::Real > &u_arr, const amrex::Array4< const amrex::Real > &v_arr, const amrex::Array4< const amrex::Real > &mf_u, const amrex::Array4< const amrex::Real > &mf_v, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv)
Definition: ERF_TerrainMetrics.H:465
static bool use_fft
Definition: ERF.H:1029
void compute_divergence(int lev, amrex::MultiFab &rhs, amrex::Array< amrex::MultiFab const *, AMREX_SPACEDIM > rho0_u_const, amrex::Geometry const &geom_at_lev)
Definition: ERF_ComputeDivergence.cpp:10
void solve_with_mlmg(int lev, amrex::Vector< amrex::MultiFab > &rhs, amrex::Vector< amrex::MultiFab > &p, amrex::Vector< amrex::Array< amrex::MultiFab, AMREX_SPACEDIM >> &fluxes)
Definition: ERF_SolveWithMLMG.cpp:40
void solve_with_gmres(int lev, amrex::Vector< amrex::MultiFab > &rhs, amrex::Vector< amrex::MultiFab > &p, amrex::Vector< amrex::Array< amrex::MultiFab, AMREX_SPACEDIM >> &fluxes)
Definition: ERF_SolveWithGMRES.cpp:12
void solve_with_EB_mlmg(int lev, amrex::Vector< amrex::MultiFab > &rhs, amrex::Vector< amrex::MultiFab > &p, amrex::Vector< amrex::Array< amrex::MultiFab, AMREX_SPACEDIM >> &fluxes)
Definition: ERF_SolveWithEBMLMG.cpp:19
@ omega
Definition: ERF_Morrison.H:53
Here is the call graph for this function:

◆ project_velocity()

void ERF::project_velocity ( int  lev,
amrex::Real  dt 
)

Project the single-level velocity field to enforce the anelastic constraint Note that the level may or may not be level 0.

11 {
12  BL_PROFILE("ERF::project_velocity()");
13  VelocityToMomentum(vars_new[lev][Vars::xvel], IntVect{0},
14  vars_new[lev][Vars::yvel], IntVect{0},
15  vars_new[lev][Vars::zvel], IntVect{0},
16  vars_new[lev][Vars::cons],
17  rU_new[lev], rV_new[lev], rW_new[lev],
18  Geom(lev).Domain(), domain_bcs_type);
19 
20  Vector<MultiFab> tmp_mom;
21 
22  tmp_mom.push_back(MultiFab(vars_new[lev][Vars::cons],make_alias,0,1));
23  tmp_mom.push_back(MultiFab(rU_new[lev],make_alias,0,1));
24  tmp_mom.push_back(MultiFab(rV_new[lev],make_alias,0,1));
25  tmp_mom.push_back(MultiFab(rW_new[lev],make_alias,0,1));
26 
27  project_momenta(lev, l_dt, tmp_mom);
28 }
void project_momenta(int lev, amrex::Real dt, amrex::Vector< amrex::MultiFab > &vars)
Definition: ERF_PoissonSolve.cpp:34
Here is the call graph for this function:

◆ project_velocity_tb()

void ERF::project_velocity_tb ( int  lev,
amrex::Real  dt,
amrex::Vector< amrex::MultiFab > &  vars 
)

Project the single-level velocity field to enforce incompressibility with a thin body

21 {
22  BL_PROFILE("ERF::project_velocity_tb()");
23  AMREX_ALWAYS_ASSERT(solverChoice.mesh_type == MeshType::ConstantDz);
24 
25  // Make sure the solver only sees the levels over which we are solving
26  Vector<BoxArray> ba_tmp; ba_tmp.push_back(vmf[Vars::cons].boxArray());
27  Vector<DistributionMapping> dm_tmp; dm_tmp.push_back(vmf[Vars::cons].DistributionMap());
28  Vector<Geometry> geom_tmp; geom_tmp.push_back(geom[lev]);
29 
30  // Use the default settings
31  LPInfo info;
32  std::unique_ptr<MLPoisson> p_mlpoisson;
33 #if 0
34  if (overset_imask[0]) {
35  // Add overset mask around thin body
36  p_mlpoisson = std::make_unique<MLPoisson>(geom, grids, dmap, GetVecOfConstPtrs(overset_imask), info);
37  }
38  else
39 #endif
40  {
41  // Use the default settings
42  p_mlpoisson = std::make_unique<MLPoisson>(geom_tmp, ba_tmp, dm_tmp, info);
43  }
44 
45  auto bclo = get_projection_bc(Orientation::low);
46  auto bchi = get_projection_bc(Orientation::high);
47  bool need_adjust_rhs = (projection_has_dirichlet(bclo) || projection_has_dirichlet(bchi)) ? false : true;
48  p_mlpoisson->setDomainBC(bclo, bchi);
49 
50  if (lev > 0) {
51  p_mlpoisson->setCoarseFineBC(nullptr, ref_ratio[lev-1], LinOpBCType::Neumann);
52  }
53 
54  p_mlpoisson->setLevelBC(0, nullptr);
55 
56  Vector<MultiFab> rhs;
57  Vector<MultiFab> phi;
58  Vector<Array<MultiFab,AMREX_SPACEDIM> > fluxes;
59  Vector<Array<MultiFab,AMREX_SPACEDIM> > deltaf; // f^* - f^{n-1}
60  Vector<Array<MultiFab,AMREX_SPACEDIM> > u_plus_dtdf; // u + dt*deltaf
61 
62  // Used to pass array of const MFs to ComputeDivergence
63  Array<MultiFab const*, AMREX_SPACEDIM> u;
64 
65  rhs.resize(1);
66  phi.resize(1);
67  fluxes.resize(1);
68  deltaf.resize(1);
69  u_plus_dtdf.resize(1);
70 
71  rhs[0].define(ba_tmp[0], dm_tmp[0], 1, 0);
72  phi[0].define(ba_tmp[0], dm_tmp[0], 1, 0);
73  rhs[0].setVal(0.0);
74  phi[0].setVal(0.0);
75 
76  for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
77  fluxes[0][idim].define(convert(ba_tmp[0], IntVect::TheDimensionVector(idim)), dm_tmp[0], 1, 0);
78  u_plus_dtdf[0][idim].define(convert(ba_tmp[0], IntVect::TheDimensionVector(idim)), dm_tmp[0], 1, 0);
79 
80  deltaf[0][idim].define(convert(ba_tmp[0], IntVect::TheDimensionVector(idim)), dm_tmp[0], 1, 0);
81  deltaf[0][idim].setVal(0.0); // start with f^* == f^{n-1}
82  }
83 
84 #if 0
85  // DEBUG
86  u[0] = &(vmf[Vars::xvel]);
87  u[1] = &(vmf[Vars::yvel]);
88  u[2] = &(vmf[Vars::zvel]);
89  computeDivergence(rhs[0], u, geom[0]);
90  Print() << "Max norm of divergence before solve at level 0 : " << rhs[0].norm0() << std::endl;
91 #endif
92 
93  for (int itp = 0; itp < solverChoice.ncorr; ++itp)
94  {
95  // Calculate u + dt*deltaf
96  for (int idim = 0; idim < 3; ++idim) {
97  MultiFab::Copy(u_plus_dtdf[0][idim], deltaf[0][idim], 0, 0, 1, 0);
98  u_plus_dtdf[0][0].mult(-l_dt,0,1,0);
99  }
100  MultiFab::Add(u_plus_dtdf[0][0], vmf[Vars::xvel], 0, 0, 1, 0);
101  MultiFab::Add(u_plus_dtdf[0][1], vmf[Vars::yvel], 0, 0, 1, 0);
102  MultiFab::Add(u_plus_dtdf[0][2], vmf[Vars::zvel], 0, 0, 1, 0);
103 
104  u[0] = &(u_plus_dtdf[0][0]);
105  u[1] = &(u_plus_dtdf[0][1]);
106  u[2] = &(u_plus_dtdf[0][2]);
107  computeDivergence(rhs[0], u, geom_tmp[0]);
108 
109 #if 0
110  // DEBUG
111  if (itp==0) {
112  for (MFIter mfi(rhs[0], TilingIfNotGPU()); mfi.isValid(); ++mfi)
113  {
114  const Box& bx = mfi.tilebox();
115  const Array4<Real const>& divU = rhs[0].const_array(mfi);
116  const Array4<Real const>& uarr = vmf[Vars::xvel].const_array(mfi);
117  const Array4<Real const>& varr = vmf[Vars::yvel].const_array(mfi);
118  const Array4<Real const>& warr = vmf[Vars::zvel].const_array(mfi);
119  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
120  {
121  if ((i>=120) && (i<=139) && (j==0) && ((k>=127)&&(k<=128))) {
122  amrex::AllPrint() << "before project div"<<IntVect(i,j,k)<<" = "<< divU(i,j,k)
123  << " u: " << uarr(i,j,k) << " " << uarr(i+1,j,k)
124  << " v: " << varr(i,j,k) << " " << varr(i,j+1,k)
125  << " w: " << warr(i,j,k) << " " << warr(i,j,k+1)
126  << std::endl;
127  }
128  });
129  }
130  }
131 #endif
132 
133  // If all Neumann BCs, adjust RHS to make sure we can converge
134  if (need_adjust_rhs) {
135  Real offset = volWgtSumMF(lev, rhs[0], 0, false);
136  // amrex::Print() << "Poisson solvability offset = " << offset << std::endl;
137  rhs[0].plus(-offset, 0, 1);
138  }
139 
140  // Initialize phi to 0
141  phi[0].setVal(0.0);
142 
143  MLMG mlmg(*p_mlpoisson);
144  int max_iter = 100;
145  mlmg.setMaxIter(max_iter);
146 
147  mlmg.setVerbose(mg_verbose);
148  //mlmg.setBottomVerbose(mg_verbose);
149 
150  // solve for dt*p
151  mlmg.solve(GetVecOfPtrs(phi),
152  GetVecOfConstPtrs(rhs),
155 
156  mlmg.getFluxes(GetVecOfArrOfPtrs(fluxes));
157 
158  // Calculate new intermediate body force with updated gradp
159  if (thin_xforce[lev]) {
160  MultiFab::Copy( deltaf[0][0], fluxes[0][0], 0, 0, 1, 0);
161  ApplyInvertedMask(deltaf[0][0], *xflux_imask[0]);
162  }
163  if (thin_yforce[lev]) {
164  MultiFab::Copy( deltaf[0][1], fluxes[0][1], 0, 0, 1, 0);
165  ApplyInvertedMask(deltaf[0][1], *yflux_imask[0]);
166  }
167  if (thin_zforce[lev]) {
168  MultiFab::Copy( deltaf[0][2], fluxes[0][2], 0, 0, 1, 0);
169  ApplyInvertedMask(deltaf[0][2], *zflux_imask[0]);
170  }
171 
172  // DEBUG
173  // for (MFIter mfi(rhs[0], TilingIfNotGPU()); mfi.isValid(); ++mfi)
174  // {
175  // const Box& bx = mfi.tilebox();
176  // const Array4<Real const>& dfz_arr = deltaf[0][2].const_array(mfi);
177  // ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
178  // {
179  // if ((i>=120) && (i<=139) && (j==0) && (k==128)) {
180  // amrex::AllPrint()
181  // << " piter" << itp
182  // << " dfz"<<IntVect(i,j,k)<<" = "<< dfz_arr(i,j,k)
183  // << std::endl;
184  // }
185  // });
186  // }
187 
188  // Update pressure variable with phi -- note that phi is change in pressure, not the full pressure
189  MultiFab::Saxpy(pp_inc[lev], 1.0, phi[0],0,0,1,0);
190 
191  // Subtract grad(phi) from the velocity components
192  Real beta = 1.0;
193  MultiFab::Saxpy(vmf[Vars::xvel], beta, fluxes[0][0], 0, 0, 1, 0);
194  MultiFab::Saxpy(vmf[Vars::yvel], beta, fluxes[0][1], 0, 0, 1, 0);
195  MultiFab::Saxpy(vmf[Vars::zvel], beta, fluxes[0][2], 0, 0, 1, 0);
196  if (thin_xforce[lev]) {
197  ApplyMask(vmf[Vars::xvel], *xflux_imask[0]);
198  }
199  if (thin_yforce[lev]) {
200  ApplyMask(vmf[Vars::yvel], *yflux_imask[0]);
201  }
202  if (thin_zforce[lev]) {
203  ApplyMask(vmf[Vars::zvel], *zflux_imask[0]);
204  }
205  } // itp: pressure-force iterations
206 
207  // ****************************************************************************
208  // Define gradp from fluxes -- note that fluxes is dt * change in Gp
209  // ****************************************************************************
210  MultiFab::Saxpy(gradp[lev][GpVars::gpx],-1.0/l_dt,fluxes[0][0],0,0,1,0);
211  MultiFab::Saxpy(gradp[lev][GpVars::gpy],-1.0/l_dt,fluxes[0][1],0,0,1,0);
212  MultiFab::Saxpy(gradp[lev][GpVars::gpz],-1.0/l_dt,fluxes[0][2],0,0,1,0);
213 
214  gradp[lev][GpVars::gpx].FillBoundary(geom_tmp[0].periodicity());
215  gradp[lev][GpVars::gpy].FillBoundary(geom_tmp[0].periodicity());
216  gradp[lev][GpVars::gpz].FillBoundary(geom_tmp[0].periodicity());
217 
218  // Subtract grad(phi) from the velocity components
219 // Real beta = 1.0;
220 // for (int ilev = lev_min; ilev <= lev_max; ++ilev) {
221 // MultiFab::Saxpy(vmf[Vars::xvel], beta, fluxes[0][0], 0, 0, 1, 0);
222 // MultiFab::Saxpy(vmf[Vars::yvel], beta, fluxes[0][1], 0, 0, 1, 0);
223 // MultiFab::Saxpy(vmf[Vars::zvel], beta, fluxes[0][2], 0, 0, 1, 0);
224 // if (thin_xforce[lev]) {
225 // ApplyMask(vmf[Vars::xvel], *xflux_imask[0]);
226 // }
227 // if (thin_yforce[lev]) {
228 // ApplyMask(vmf[Vars::yvel], *yflux_imask[0]);
229 // }
230 // if (thin_zforce[lev]) {
231 // ApplyMask(vmf[Vars::zvel], *zflux_imask[0]);
232 // }
233 // }
234 
235 #if 0
236  // Confirm that the velocity is now divergence free
237  u[0] = &(vmf[Vars::xvel]);
238  u[1] = &(vmf[Vars::yvel]);
239  u[2] = &(vmf[Vars::zvel]);
240  computeDivergence(rhs[0], u, geom_tmp[0]);
241  Print() << "Max norm of divergence after solve at level " << lev << " : " << rhs[0].norm0() << std::endl;
242 
243 #endif
244 }
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:28
AMREX_GPU_HOST AMREX_FORCE_INLINE void ApplyInvertedMask(amrex::MultiFab &dst, const amrex::iMultiFab &imask, const int nghost=0)
Definition: ERF_Utils.H:409
amrex::Array< amrex::LinOpBCType, AMREX_SPACEDIM > get_projection_bc(amrex::Orientation::Side side) const noexcept
Definition: ERF_SolveWithMLMG.cpp:17
bool projection_has_dirichlet(amrex::Array< amrex::LinOpBCType, AMREX_SPACEDIM > bcs) const
Definition: ERF_PoissonSolve_tb.cpp:8
amrex::Real volWgtSumMF(int lev, const amrex::MultiFab &mf, int comp, bool finemask)
Definition: ERF_WriteScalarProfiles.cpp:621
int ncorr
Definition: ERF_DataStruct.H:722
Here is the call graph for this function:

◆ projection_has_dirichlet()

bool ERF::projection_has_dirichlet ( amrex::Array< amrex::LinOpBCType, AMREX_SPACEDIM >  bcs) const
9 {
10  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
11  if (bcs[dir] == LinOpBCType::Dirichlet) return true;
12  }
13  return false;
14 }

◆ ReadCheckpointFile()

void ERF::ReadCheckpointFile ( )

ERF function for reading data from a checkpoint file during restart.

420 {
421  Print() << "Restart from native checkpoint " << restart_chkfile << "\n";
422 
423  // Header
424  std::string File(restart_chkfile + "/Header");
425 
426  VisMF::IO_Buffer io_buffer(VisMF::GetIOBufferSize());
427 
428  Vector<char> fileCharPtr;
429  ParallelDescriptor::ReadAndBcastFile(File, fileCharPtr);
430  std::string fileCharPtrString(fileCharPtr.dataPtr());
431  std::istringstream is(fileCharPtrString, std::istringstream::in);
432 
433  std::string line, word;
434 
435  int chk_ncomp_cons, chk_ncomp;
436 
437  // read in title line
438  std::getline(is, line);
439 
440  // read in finest_level
441  is >> finest_level;
442  GotoNextLine(is);
443 
444  // read the number of components
445  // for each variable we store
446 
447  // conservative, cell-centered vars
448  is >> chk_ncomp_cons;
449  GotoNextLine(is);
450 
451  // x-velocity on faces
452  is >> chk_ncomp;
453  GotoNextLine(is);
454  AMREX_ASSERT(chk_ncomp == 1);
455 
456  // y-velocity on faces
457  is >> chk_ncomp;
458  GotoNextLine(is);
459  AMREX_ASSERT(chk_ncomp == 1);
460 
461  // z-velocity on faces
462  is >> chk_ncomp;
463  GotoNextLine(is);
464  AMREX_ASSERT(chk_ncomp == 1);
465 
466  // read in array of istep
467  std::getline(is, line);
468  {
469  std::istringstream lis(line);
470  int i = 0;
471  while (lis >> word) {
472  istep[i++] = std::stoi(word);
473  }
474  }
475 
476  // read in array of dt
477  std::getline(is, line);
478  {
479  std::istringstream lis(line);
480  int i = 0;
481  while (lis >> word) {
482  dt[i++] = std::stod(word);
483  }
484  }
485 
486  // read in array of t_new
487  std::getline(is, line);
488  {
489  std::istringstream lis(line);
490  int i = 0;
491  while (lis >> word) {
492  t_new[i++] = std::stod(word);
493  }
494  }
495 
496  for (int lev = 0; lev <= finest_level; ++lev) {
497  // read in level 'lev' BoxArray from Header
498  BoxArray ba;
499  ba.readFrom(is);
500  GotoNextLine(is);
501 
502  // create a distribution mapping
503  DistributionMapping dm { ba, ParallelDescriptor::NProcs() };
504 
505  MakeNewLevelFromScratch (lev, t_new[lev], ba, dm);
506  }
507 
508  // ncomp is only valid after we MakeNewLevelFromScratch (asks micro how many vars)
509  // NOTE: Data is written over ncomp, so check that we match the header file
510  int ncomp_cons = vars_new[0][Vars::cons].nComp();
511 
512  // NOTE: QKE was removed so this is for backward compatibility
513  AMREX_ASSERT((chk_ncomp_cons==ncomp_cons) || ((chk_ncomp_cons-1)==ncomp_cons));
514  //
515  // See if we have a written separate file that tells how many components and how many ghost cells
516  // we have of the base state
517  //
518  // If we can't find the file, then set the number of components to the original number = 3
519  //
520  int ncomp_base_to_read = 3;
521  IntVect ng_base = IntVect{1};
522  {
523  std::string BaseStateFile(restart_chkfile + "/num_base_state_comps");
524 
525  if (amrex::FileExists(BaseStateFile))
526  {
527  Vector<char> BaseStatefileCharPtr;
528  ParallelDescriptor::ReadAndBcastFile(BaseStateFile, BaseStatefileCharPtr);
529  std::string BaseStatefileCharPtrString(BaseStatefileCharPtr.dataPtr());
530 
531  // We set this to the default value of 3 but allow it be larger if th0 and qv0 were written
532  std::istringstream isb(BaseStatefileCharPtrString, std::istringstream::in);
533  isb >> ncomp_base_to_read;
534  isb >> ng_base;
535  }
536  }
537 
538  // read in the MultiFab data
539  for (int lev = 0; lev <= finest_level; ++lev)
540  {
541  // NOTE: For backward compatibility (chk file has QKE)
542  if ((chk_ncomp_cons-1)==ncomp_cons) {
543  MultiFab cons(grids[lev],dmap[lev],chk_ncomp_cons,0);
544  VisMF::Read(cons, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "Cell"));
545 
546  // Copy up to RhoKE_comp
547  MultiFab::Copy(vars_new[lev][Vars::cons],cons,0,0,(RhoKE_comp+1),0);
548 
549  // Only if we have a PBL model do we need to copy QKE is src to KE in dst
550  if ( (solverChoice.turbChoice[lev].pbl_type == PBLType::MYNN25) ||
551  (solverChoice.turbChoice[lev].pbl_type == PBLType::MYNNEDMF) ) {
552  MultiFab::Copy(vars_new[lev][Vars::cons],cons,(RhoKE_comp+1),RhoKE_comp,1,0);
553  vars_new[lev][Vars::cons].mult(0.5,RhoKE_comp,1,0);
554  }
555 
556  // Copy other components
557  int ncomp_remainder = ncomp_cons - (RhoKE_comp + 1);
558  MultiFab::Copy(vars_new[lev][Vars::cons],cons,(RhoKE_comp+2),(RhoKE_comp+1),ncomp_remainder,0);
559 
560  vars_new[lev][Vars::cons].setBndry(1.0e34);
561  } else {
562  MultiFab cons(grids[lev],dmap[lev],ncomp_cons,0);
563  VisMF::Read(cons, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "Cell"));
564  MultiFab::Copy(vars_new[lev][Vars::cons],cons,0,0,ncomp_cons,0);
565  vars_new[lev][Vars::cons].setBndry(1.0e34);
566  }
567 
568  MultiFab xvel(convert(grids[lev],IntVect(1,0,0)),dmap[lev],1,0);
569  VisMF::Read(xvel, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "XFace"));
570  MultiFab::Copy(vars_new[lev][Vars::xvel],xvel,0,0,1,0);
571  vars_new[lev][Vars::xvel].setBndry(1.0e34);
572 
573  MultiFab yvel(convert(grids[lev],IntVect(0,1,0)),dmap[lev],1,0);
574  VisMF::Read(yvel, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "YFace"));
575  MultiFab::Copy(vars_new[lev][Vars::yvel],yvel,0,0,1,0);
576  vars_new[lev][Vars::yvel].setBndry(1.0e34);
577 
578  MultiFab zvel(convert(grids[lev],IntVect(0,0,1)),dmap[lev],1,0);
579  VisMF::Read(zvel, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "ZFace"));
580  MultiFab::Copy(vars_new[lev][Vars::zvel],zvel,0,0,1,0);
581  vars_new[lev][Vars::zvel].setBndry(1.0e34);
582 
583  // Note that we read the ghost cells of the base state (unlike above)
584 
585  // The original base state only had 3 components and 1 ghost cell -- we read this
586  // here to be consistent with the old style
587  MultiFab base(grids[lev],dmap[lev],ncomp_base_to_read,ng_base);
588  VisMF::Read(base, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "BaseState"));
589 
590  MultiFab::Copy(base_state[lev],base,0,0,ncomp_base_to_read,ng_base);
591 
592  // Create theta0 from p0, rh0
593  if (ncomp_base_to_read < 4) {
594  for (MFIter mfi(base_state[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
595  {
596  // We only compute theta_0 on valid cells since we will impose domain BC's after restart
597  const Box& bx = mfi.tilebox();
598  Array4<Real> const& fab = base_state[lev].array(mfi);
599  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
600  {
602  / fab(i,j,k,BaseState::r0_comp);
603  });
604  }
605  }
606  // Default theta0 to 0
607  if (ncomp_base_to_read < 5) {
608  for (MFIter mfi(base_state[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
609  {
610  // We only compute theta_0 on valid cells since we will impose domain BC's after restart
611  const Box& bx = mfi.tilebox();
612  Array4<Real> const& fab = base_state[lev].array(mfi);
613  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
614  {
615  fab(i,j,k,BaseState::qv0_comp) = 0.0;
616  });
617  }
618  }
619  base_state[lev].FillBoundary(geom[lev].periodicity());
620 
621  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
622  // Note that we also read the ghost cells of z_phys_nd
623  IntVect ng = z_phys_nd[lev]->nGrowVect();
624  MultiFab z_height(convert(grids[lev],IntVect(1,1,1)),dmap[lev],1,ng);
625  VisMF::Read(z_height, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "Z_Phys_nd"));
626  MultiFab::Copy(*z_phys_nd[lev],z_height,0,0,1,ng);
628  }
629 
630  // Read in the moisture model restart variables
631  std::vector<int> qmoist_indices;
632  std::vector<std::string> qmoist_names;
633  micro->Get_Qmoist_Restart_Vars(lev, solverChoice, qmoist_indices, qmoist_names);
634  int qmoist_nvar = qmoist_indices.size();
635  for (int var = 0; var < qmoist_nvar; var++) {
636  const int ncomp = 1;
637  IntVect ng_moist = qmoist[lev][qmoist_indices[var]]->nGrowVect();
638  MultiFab moist_vars(grids[lev],dmap[lev],ncomp,ng_moist);
639  VisMF::Read(moist_vars, amrex::MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", qmoist_names[var]));
640  MultiFab::Copy(*(qmoist[lev][qmoist_indices[var]]),moist_vars,0,0,ncomp,ng_moist);
641  }
642 
643 #if defined(ERF_USE_WINDFARM)
644  if(solverChoice.windfarm_type == WindFarmType::Fitch or
645  solverChoice.windfarm_type == WindFarmType::EWP or
646  solverChoice.windfarm_type == WindFarmType::SimpleAD){
647  IntVect ng = Nturb[lev].nGrowVect();
648  MultiFab mf_Nturb(grids[lev],dmap[lev],1,ng);
649  VisMF::Read(mf_Nturb, amrex::MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "NumTurb"));
650  MultiFab::Copy(Nturb[lev],mf_Nturb,0,0,1,ng);
651  }
652 #endif
653 
654  if (solverChoice.lsm_type != LandSurfaceType::None) {
655  for (int mvar(0); mvar<lsm_data[lev].size(); ++mvar) {
656  BoxArray ba = lsm_data[lev][mvar]->boxArray();
657  DistributionMapping dm = lsm_data[lev][mvar]->DistributionMap();
658  IntVect ng = lsm_data[lev][mvar]->nGrowVect();
659  int nvar = lsm_data[lev][mvar]->nComp();
660  MultiFab lsm_vars(ba,dm,nvar,ng);
661  VisMF::Read(lsm_vars, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "LsmVars"));
662  MultiFab::Copy(*(lsm_data[lev][mvar]),lsm_vars,0,0,nvar,ng);
663  }
664  }
665 
666 
667  IntVect ng = mapfac[lev][MapFacType::m_x]->nGrowVect();
668  MultiFab mf_m(ba2d[lev],dmap[lev],1,ng);
669 
670  std::string MapFacMFileName(restart_chkfile + "/Level_0/MapFactor_mx_H");
671  if (amrex::FileExists(MapFacMFileName)) {
672  VisMF::Read(mf_m, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "MapFactor_mx"));
673  } else {
674  VisMF::Read(mf_m, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "MapFactor_m"));
675  }
676  MultiFab::Copy(*mapfac[lev][MapFacType::m_x],mf_m,0,0,1,ng);
677 
678 #if 0
680  VisMF::Read(mf_m, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "MapFactor_my"));
681  MultiFab::Copy(*mapfac[lev][MapFacType::m_y],mf_m,0,0,1,ng);
682  }
683 #endif
684 
685  ng = mapfac[lev][MapFacType::u_x]->nGrowVect();
686  MultiFab mf_u(convert(ba2d[lev],IntVect(1,0,0)),dmap[lev],1,ng);
687 
688  std::string MapFacUFileName(restart_chkfile + "/Level_0/MapFactor_ux_H");
689  if (amrex::FileExists(MapFacUFileName)) {
690  VisMF::Read(mf_u, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "MapFactor_ux"));
691  } else {
692  VisMF::Read(mf_u, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "MapFactor_u"));
693  }
694  MultiFab::Copy(*mapfac[lev][MapFacType::u_x],mf_u,0,0,1,ng);
695 
696 #if 0
698  VisMF::Read(mf_u, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "MapFactor_uy"));
699  MultiFab::Copy(*mapfac[lev][MapFacType::u_y],mf_u,0,0,1,ng);
700  }
701 #endif
702 
703  ng = mapfac[lev][MapFacType::v_x]->nGrowVect();
704  MultiFab mf_v(convert(ba2d[lev],IntVect(0,1,0)),dmap[lev],1,ng);
705 
706  std::string MapFacVFileName(restart_chkfile + "/Level_0/MapFactor_vx_H");
707  if (amrex::FileExists(MapFacVFileName)) {
708  VisMF::Read(mf_v, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "MapFactor_vx"));
709  } else {
710  VisMF::Read(mf_v, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "MapFactor_v"));
711  }
712  MultiFab::Copy(*mapfac[lev][MapFacType::v_x],mf_v,0,0,1,ng);
713 
714 #if 0
716  VisMF::Read(mf_v, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "MapFactor_vy"));
717  MultiFab::Copy(*mapfac[lev][MapFacType::v_y],mf_v,0,0,1,ng);
718  }
719 #endif
720 
721 
722  // NOTE: We read MOST data in ReadCheckpointFileMOST (see below)!
723 
724  // See if we wrote out SST data
725  std::string FirstSSTFileName(restart_chkfile + "/Level_0/SST_0_H");
726  if (amrex::FileExists(FirstSSTFileName))
727  {
728  amrex::Print() << "Reading SST data" << std::endl;
729  int ntimes = 1;
730  ng = vars_new[lev][Vars::cons].nGrowVect(); ng[2]=0;
731  MultiFab sst_at_t(ba2d[lev],dmap[lev],1,ng);
732  sst_lev[lev][0] = std::make_unique<MultiFab>(ba2d[lev],dmap[lev],1,ng);
733  for (int nt(0); nt<ntimes; ++nt) {
734  VisMF::Read(sst_at_t, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_",
735  "SST_" + std::to_string(nt)));
736  MultiFab::Copy(*sst_lev[lev][nt],sst_at_t,0,0,1,ng);
737  }
738  }
739 
740  // See if we wrote out TSK data
741  std::string FirstTSKFileName(restart_chkfile + "/Level_0/TSK_0_H");
742  if (amrex::FileExists(FirstTSKFileName))
743  {
744  amrex::Print() << "Reading TSK data" << std::endl;
745  int ntimes = 1;
746  ng = vars_new[lev][Vars::cons].nGrowVect(); ng[2]=0;
747  MultiFab tsk_at_t(ba2d[lev],dmap[lev],1,ng);
748  tsk_lev[lev][0] = std::make_unique<MultiFab>(ba2d[lev],dmap[lev],1,ng);
749  for (int nt(0); nt<ntimes; ++nt) {
750  VisMF::Read(tsk_at_t, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_",
751  "TSK_" + std::to_string(nt)));
752  MultiFab::Copy(*tsk_lev[lev][nt],tsk_at_t,0,0,1,ng);
753  }
754  }
755 
756  std::string LMaskFileName(restart_chkfile + "/Level_0/LMASK_0_H");
757  if (amrex::FileExists(LMaskFileName))
758  {
759  amrex::Print() << "Reading LMASK data" << std::endl;
760  int ntimes = 1;
761  ng = vars_new[lev][Vars::cons].nGrowVect(); ng[2]=0;
762  MultiFab lmask_at_t(ba2d[lev],dmap[lev],1,ng);
763  for (int nt(0); nt<ntimes; ++nt) {
764  VisMF::Read(lmask_at_t, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_",
765  "LMASK_" + std::to_string(nt)));
766  for (MFIter mfi(lmask_at_t); mfi.isValid(); ++mfi) {
767  const Box& bx = mfi.growntilebox();
768  Array4<int> const& dst_arr = lmask_lev[lev][nt]->array(mfi);
769  Array4<Real> const& src_arr = lmask_at_t.array(mfi);
770  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
771  {
772  dst_arr(i,j,k) = int(src_arr(i,j,k));
773  });
774  }
775  }
776  } else {
777  // Allow idealized cases over water, used to set lmask
778  ParmParse pp("erf");
779  int is_land;
780  if (pp.query("is_land", is_land, lev)) {
781  if (is_land == 1) {
782  amrex::Print() << "Level " << lev << " is land" << std::endl;
783  } else if (is_land == 0) {
784  amrex::Print() << "Level " << lev << " is water" << std::endl;
785  } else {
786  Error("is_land should be 0 or 1");
787  }
788  lmask_lev[lev][0]->setVal(is_land);
789  } else {
790  // Default to land everywhere if not specified
791  lmask_lev[lev][0]->setVal(1);
792  }
793  lmask_lev[lev][0]->FillBoundary(geom[lev].periodicity());
794  }
795 
796 #ifdef ERF_USE_NETCDF
797  IntVect ngv = ng; ngv[2] = 0;
798 
799  // Read lat/lon if it exists
801  amrex::Print() << "Reading Lat/Lon variables" << std::endl;
802  MultiFab lat(ba2d[lev],dmap[lev],1,ngv);
803  MultiFab lon(ba2d[lev],dmap[lev],1,ngv);
804  VisMF::Read(lat, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "LAT"));
805  VisMF::Read(lon, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "LON"));
806  lat_m[lev] = std::make_unique<MultiFab>(ba2d[lev],dmap[lev],1,ngv);
807  lon_m[lev] = std::make_unique<MultiFab>(ba2d[lev],dmap[lev],1,ngv);
808  MultiFab::Copy(*lat_m[lev],lat,0,0,1,ngv);
809  MultiFab::Copy(*lon_m[lev],lon,0,0,1,ngv);
810  }
811 
812  // Read sinPhi and cosPhi if it exists
814  amrex::Print() << "Reading Coriolis factors" << std::endl;
815  MultiFab sphi(ba2d[lev],dmap[lev],1,ngv);
816  MultiFab cphi(ba2d[lev],dmap[lev],1,ngv);
817  VisMF::Read(sphi, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "SinPhi"));
818  VisMF::Read(cphi, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "CosPhi"));
819  sinPhi_m[lev] = std::make_unique<MultiFab>(ba2d[lev],dmap[lev],1,ngv);
820  cosPhi_m[lev] = std::make_unique<MultiFab>(ba2d[lev],dmap[lev],1,ngv);
821  MultiFab::Copy(*sinPhi_m[lev],sphi,0,0,1,ngv);
822  MultiFab::Copy(*cosPhi_m[lev],cphi,0,0,1,ngv);
823  }
824 
825  if (solverChoice.use_real_bcs && solverChoice.init_type == InitType::WRFInput) {
826  MultiFab tmp1d(ba1d[lev],dmap[lev],1,ngv);
827  MultiFab tmp2d(ba2d[lev],dmap[lev],1,ngv);
828 
829  VisMF::Read(tmp1d, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "C1H"));
830  MultiFab::Copy(*mf_C1H[lev],tmp1d,0,0,1,ngv);
831 
832  VisMF::Read(tmp1d, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "C2H"));
833  MultiFab::Copy(*mf_C2H[lev],tmp1d,0,0,1,ngv);
834 
835  VisMF::Read(tmp2d, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "MUB"));
836  MultiFab::Copy(*mf_MUB[lev],tmp2d,0,0,1,ngv);
837  }
838 #endif
839 
840  } // for lev
841 
842 #ifdef ERF_USE_PARTICLES
843  restartTracers((ParGDBBase*)GetParGDB(),restart_chkfile);
844  if (Microphysics::modelType(solverChoice.moisture_type) == MoistureModelType::Lagrangian) {
845  dynamic_cast<LagrangianMicrophysics&>(*micro).restartParticles((ParGDBBase*)GetParGDB(),restart_chkfile);
846  }
847 #endif
848 
849 #if 0
850 #ifdef ERF_USE_NETCDF
851  // Read bdy_data files
852  if ( ((solverChoice.init_type==InitType::WRFInput) || (solverChoice.init_type==InitType::Metgrid)) &&
854  {
855  int ioproc = ParallelDescriptor::IOProcessorNumber(); // I/O rank
856  int num_time;
857  int num_var;
858  Vector<Box> bx_v;
859  if (ParallelDescriptor::IOProcessor()) {
860  // Open header file and read from it
861  std::ifstream bdy_h_file(MultiFabFileFullPrefix(0, restart_chkfile, "Level_", "bdy_H"));
862  bdy_h_file >> num_time;
863  bdy_h_file >> num_var;
864  bdy_h_file >> start_bdy_time;
865  bdy_h_file >> bdy_time_interval;
866  bdy_h_file >> real_width;
867  bx_v.resize(4*num_var);
868  for (int ivar(0); ivar<num_var; ++ivar) {
869  bdy_h_file >> bx_v[4*ivar ];
870  bdy_h_file >> bx_v[4*ivar+1];
871  bdy_h_file >> bx_v[4*ivar+2];
872  bdy_h_file >> bx_v[4*ivar+3];
873  }
874 
875  // IO size the FABs
876  bdy_data_xlo.resize(num_time);
877  bdy_data_xhi.resize(num_time);
878  bdy_data_ylo.resize(num_time);
879  bdy_data_yhi.resize(num_time);
880  for (int itime(0); itime<num_time; ++itime) {
881  bdy_data_xlo[itime].resize(num_var);
882  bdy_data_xhi[itime].resize(num_var);
883  bdy_data_ylo[itime].resize(num_var);
884  bdy_data_yhi[itime].resize(num_var);
885  for (int ivar(0); ivar<num_var; ++ivar) {
886  bdy_data_xlo[itime][ivar].resize(bx_v[4*ivar ]);
887  bdy_data_xhi[itime][ivar].resize(bx_v[4*ivar+1]);
888  bdy_data_ylo[itime][ivar].resize(bx_v[4*ivar+2]);
889  bdy_data_yhi[itime][ivar].resize(bx_v[4*ivar+3]);
890  }
891  }
892 
893  // Open data file and read from it
894  std::ifstream bdy_d_file(MultiFabFileFullPrefix(0, restart_chkfile, "Level_", "bdy_D"));
895  for (int itime(0); itime<num_time; ++itime) {
896  for (int ivar(0); ivar<num_var; ++ivar) {
897  bdy_data_xlo[itime][ivar].readFrom(bdy_d_file);
898  bdy_data_xhi[itime][ivar].readFrom(bdy_d_file);
899  bdy_data_ylo[itime][ivar].readFrom(bdy_d_file);
900  bdy_data_yhi[itime][ivar].readFrom(bdy_d_file);
901  }
902  }
903  } // IO
904 
905  // Broadcast the data
906  ParallelDescriptor::Barrier();
907  ParallelDescriptor::Bcast(&start_bdy_time,1,ioproc);
908  ParallelDescriptor::Bcast(&bdy_time_interval,1,ioproc);
909  ParallelDescriptor::Bcast(&real_width,1,ioproc);
910  ParallelDescriptor::Bcast(&num_time,1,ioproc);
911  ParallelDescriptor::Bcast(&num_var,1,ioproc);
912 
913  // Everyone size their boxes
914  bx_v.resize(4*num_var);
915 
916  ParallelDescriptor::Bcast(bx_v.dataPtr(),bx_v.size(),ioproc);
917 
918  // Everyone but IO size their FABs
919  if (!ParallelDescriptor::IOProcessor()) {
920  bdy_data_xlo.resize(num_time);
921  bdy_data_xhi.resize(num_time);
922  bdy_data_ylo.resize(num_time);
923  bdy_data_yhi.resize(num_time);
924  for (int itime(0); itime<num_time; ++itime) {
925  bdy_data_xlo[itime].resize(num_var);
926  bdy_data_xhi[itime].resize(num_var);
927  bdy_data_ylo[itime].resize(num_var);
928  bdy_data_yhi[itime].resize(num_var);
929  for (int ivar(0); ivar<num_var; ++ivar) {
930  bdy_data_xlo[itime][ivar].resize(bx_v[4*ivar ]);
931  bdy_data_xhi[itime][ivar].resize(bx_v[4*ivar+1]);
932  bdy_data_ylo[itime][ivar].resize(bx_v[4*ivar+2]);
933  bdy_data_yhi[itime][ivar].resize(bx_v[4*ivar+3]);
934  }
935  }
936  }
937 
938  for (int itime(0); itime<num_time; ++itime) {
939  for (int ivar(0); ivar<num_var; ++ivar) {
940  ParallelDescriptor::Bcast(bdy_data_xlo[itime][ivar].dataPtr(),bdy_data_xlo[itime][ivar].box().numPts(),ioproc);
941  ParallelDescriptor::Bcast(bdy_data_xhi[itime][ivar].dataPtr(),bdy_data_xhi[itime][ivar].box().numPts(),ioproc);
942  ParallelDescriptor::Bcast(bdy_data_ylo[itime][ivar].dataPtr(),bdy_data_ylo[itime][ivar].box().numPts(),ioproc);
943  ParallelDescriptor::Bcast(bdy_data_yhi[itime][ivar].dataPtr(),bdy_data_yhi[itime][ivar].box().numPts(),ioproc);
944  }
945  }
946  } // init_type == WRFInput or Metgrid
947 #endif
948 #endif
949 }
static void GotoNextLine(std::istream &is)
Definition: ERF_Checkpoint.cpp:16
void MakeNewLevelFromScratch(int lev, amrex::Real time, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm) override
Definition: ERF_MakeNewLevel.cpp:25
bool variable_coriolis
Definition: ERF_DataStruct.H:812
bool has_lat_lon
Definition: ERF_DataStruct.H:811
Here is the call graph for this function:

◆ ReadCheckpointFileSurfaceLayer()

void ERF::ReadCheckpointFileSurfaceLayer ( )

ERF function for reading additional data for MOST from a checkpoint file during restart.

This is called after the ABLMost object is instantiated.

958 {
959  for (int lev = 0; lev <= finest_level; ++lev)
960  {
961  amrex::Print() << "Reading MOST variables" << std::endl;
962 
963  IntVect ng = vars_new[lev][Vars::cons].nGrowVect(); ng[2]=0;
964  MultiFab m_var(ba2d[lev],dmap[lev],1,ng);
965  MultiFab* dst = nullptr;
966 
967  // U*
968  std::string UstarFileName(restart_chkfile + "/Level_0/Ustar_H");
969  if (amrex::FileExists(UstarFileName)) {
970  dst = m_SurfaceLayer->get_u_star(lev);
971  VisMF::Read(m_var, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "Ustar"));
972  MultiFab::Copy(*dst,m_var,0,0,1,ng);
973  }
974 
975  // W*
976  std::string WstarFileName(restart_chkfile + "/Level_0/Wstar_H");
977  if (amrex::FileExists(WstarFileName)) {
978  dst = m_SurfaceLayer->get_w_star(lev);
979  VisMF::Read(m_var, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "Wstar"));
980  MultiFab::Copy(*dst,m_var,0,0,1,ng);
981  }
982 
983  // T*
984  std::string TstarFileName(restart_chkfile + "/Level_0/Tstar_H");
985  if (amrex::FileExists(TstarFileName)) {
986  dst = m_SurfaceLayer->get_t_star(lev);
987  VisMF::Read(m_var, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "Tstar"));
988  MultiFab::Copy(*dst,m_var,0,0,1,ng);
989  }
990 
991  // Q*
992  std::string QstarFileName(restart_chkfile + "/Level_0/Qstar_H");
993  if (amrex::FileExists(QstarFileName)) {
994  dst = m_SurfaceLayer->get_q_star(lev);
995  VisMF::Read(m_var, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "Qstar"));
996  MultiFab::Copy(*dst,m_var,0,0,1,ng);
997  }
998 
999  // Olen
1000  std::string OlenFileName(restart_chkfile + "/Level_0/Olen_H");
1001  if (amrex::FileExists(OlenFileName)) {
1002  dst = m_SurfaceLayer->get_olen(lev);
1003  VisMF::Read(m_var, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "Olen"));
1004  MultiFab::Copy(*dst,m_var,0,0,1,ng);
1005  }
1006 
1007  // PBLH
1008  std::string PBLHFileName(restart_chkfile + "/Level_0/PBLH_H");
1009  if (amrex::FileExists(PBLHFileName)) {
1010  dst = m_SurfaceLayer->get_pblh(lev);
1011  VisMF::Read(m_var, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "PBLH"));
1012  MultiFab::Copy(*dst,m_var,0,0,1,ng);
1013  }
1014 
1015  // Z0
1016  std::string Z0FileName(restart_chkfile + "/Level_0/Z0_H");
1017  if (amrex::FileExists(Z0FileName)) {
1018  VisMF::Read(m_var, MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "Z0"));
1019  for (amrex::MFIter mfi(m_var); mfi.isValid(); ++mfi) {
1020  const Box& bx = mfi.growntilebox();
1021  FArrayBox* most_z0 = (m_SurfaceLayer->get_z0(lev));
1022  most_z0->copy<RunOn::Device>(m_var[mfi], bx);
1023  }
1024  }
1025  }
1026 }

◆ ReadParameters()

void ERF::ReadParameters ( )
private
1590 {
1591  {
1592  ParmParse pp; // Traditionally, max_step and stop_time do not have prefix.
1593  pp.query("max_step", max_step);
1594 
1595  std::string start_datetime, stop_datetime;
1596  if (pp.query("start_datetime", start_datetime)) {
1597  start_time = getEpochTime(start_datetime, datetime_format);
1598  if (start_time == -1.0) {
1599  amrex::Abort("Invalid start_datetime string!");
1600  }
1601  if (pp.query("stop_datetime", stop_datetime)) {
1602  stop_time = getEpochTime(stop_datetime, datetime_format);
1603  if (stop_time == -1.0) {
1604  amrex::Abort("Invalid stop_datetime string!");
1605  }
1606  }
1607  use_datetime = true;
1608  } else {
1609  pp.query("stop_time", stop_time);
1610  pp.query("start_time", start_time); // This is optional, it defaults to 0
1611  }
1612  }
1613 
1614  ParmParse pp(pp_prefix);
1615  ParmParse pp_amr("amr");
1616  {
1617  pp.query("regrid_level_0_on_restart", regrid_level_0_on_restart);
1618  pp.query("regrid_int", regrid_int);
1619  pp.query("check_file", check_file);
1620 
1621  // The regression tests use "amr.restart" and "amr.m_check_int" so we allow
1622  // for those or "erf.restart" / "erf.m_check_int" with the former taking
1623  // precedence if both are specified
1624  pp.query("check_int", m_check_int);
1625  pp.query("check_per", m_check_per);
1626  pp_amr.query("check_int", m_check_int);
1627  pp_amr.query("check_per", m_check_per);
1628 
1629  pp.query("restart", restart_chkfile);
1630  pp_amr.query("restart", restart_chkfile);
1631 
1632  // Verbosity
1633  pp.query("v", verbose);
1634  pp.query("mg_v", mg_verbose);
1635  pp.query("use_fft", use_fft);
1636 #ifndef ERF_USE_FFT
1637  if (use_fft) {
1638  amrex::Abort("You must build with USE_FFT in order to set use_fft = true in your inputs file");
1639  }
1640 #endif
1641 
1642  // Frequency of diagnostic output
1643  pp.query("sum_interval", sum_interval);
1644  pp.query("sum_period" , sum_per);
1645 
1646  pp.query("pert_interval", pert_interval);
1647 
1648  // Time step controls
1649  pp.query("cfl", cfl);
1650  pp.query("substepping_cfl", sub_cfl);
1651  pp.query("init_shrink", init_shrink);
1652  pp.query("change_max", change_max);
1653  pp.query("dt_max_initial", dt_max_initial);
1654  pp.query("dt_max", dt_max);
1655 
1656  fixed_dt.resize(max_level+1,-1.);
1657  fixed_fast_dt.resize(max_level+1,-1.);
1658 
1659  pp.query("fixed_dt", fixed_dt[0]);
1660  pp.query("fixed_fast_dt", fixed_fast_dt[0]);
1661 
1662  for (int lev = 1; lev <= max_level; lev++)
1663  {
1664  fixed_dt[lev] = fixed_dt[lev-1] / static_cast<Real>(MaxRefRatio(lev-1));
1665  fixed_fast_dt[lev] = fixed_fast_dt[lev-1] / static_cast<Real>(MaxRefRatio(lev-1));
1666  }
1667 
1668  pp.query("fixed_mri_dt_ratio", fixed_mri_dt_ratio);
1669 
1670  // We use this to keep track of how many boxes we read in from WRF initialization
1671  num_files_at_level.resize(max_level+1,0);
1672 
1673  // We use this to keep track of how many boxes are specified thru the refinement indicators
1674  num_boxes_at_level.resize(max_level+1,0);
1675  boxes_at_level.resize(max_level+1);
1676 
1677  // We always have exactly one file at level 0
1678  num_boxes_at_level[0] = 1;
1679  boxes_at_level[0].resize(1);
1680  boxes_at_level[0][0] = geom[0].Domain();
1681 
1682 #ifdef ERF_USE_NETCDF
1683  nc_init_file.resize(max_level+1);
1684 
1685  // NetCDF wrfinput initialization files -- possibly multiple files at each of multiple levels
1686  // but we always have exactly one file at level 0
1687  for (int lev = 0; lev <= max_level; lev++) {
1688  const std::string nc_file_names = Concatenate("nc_init_file_",lev,1);
1689  if (pp.contains(nc_file_names.c_str())) {
1690  int num_files = pp.countval(nc_file_names.c_str());
1691  num_files_at_level[lev] = num_files;
1692  nc_init_file[lev].resize(num_files);
1693  pp.queryarr(nc_file_names.c_str(), nc_init_file[lev],0,num_files);
1694  for (int j = 0; j < num_files; j++) {
1695  Print() << "Reading NC init file names at level " << lev << " and index " << j << " : " << nc_init_file[lev][j] << std::endl;
1696  } // j
1697  } // if pp.contains
1698  } // lev
1699 
1700  // NetCDF wrfbdy lateral boundary file
1701  if (pp.query("nc_bdy_file", nc_bdy_file)) {
1702  Print() << "Reading NC bdy file name " << nc_bdy_file << std::endl;
1703  }
1704 
1705  // NetCDF wrflow lateral boundary file
1706  if (pp.query("nc_low_file", nc_low_file)) {
1707  Print() << "Reading NC low file name " << nc_low_file << std::endl;
1708  }
1709 
1710 #endif
1711 
1712  // Flag to trigger initialization from input_sounding like WRF's ideal.exe
1713  pp.query("init_sounding_ideal", init_sounding_ideal);
1714 
1715  // Options for vertical interpolation of met_em*.nc data.
1716  pp.query("metgrid_debug_quiescent", metgrid_debug_quiescent);
1717  pp.query("metgrid_debug_isothermal", metgrid_debug_isothermal);
1718  pp.query("metgrid_debug_dry", metgrid_debug_dry);
1719  pp.query("metgrid_debug_psfc", metgrid_debug_psfc);
1720  pp.query("metgrid_debug_msf", metgrid_debug_msf);
1721  pp.query("metgrid_interp_theta", metgrid_interp_theta);
1722  pp.query("metgrid_basic_linear", metgrid_basic_linear);
1723  pp.query("metgrid_use_below_sfc", metgrid_use_below_sfc);
1724  pp.query("metgrid_use_sfc", metgrid_use_sfc);
1725  pp.query("metgrid_retain_sfc", metgrid_retain_sfc);
1726  pp.query("metgrid_proximity", metgrid_proximity);
1727  pp.query("metgrid_order", metgrid_order);
1728  pp.query("metgrid_force_sfc_k", metgrid_force_sfc_k);
1729 
1730  // Set default to FullState for now ... later we will try Perturbation
1731  interpolation_type = StateInterpType::FullState;
1732  pp.query_enum_case_insensitive("interpolation_type" ,interpolation_type);
1733 
1734  PlotFileType plotfile_type_temp = PlotFileType::None;
1735  pp.query_enum_case_insensitive("plotfile_type" ,plotfile_type_temp);
1736  pp.query_enum_case_insensitive("plotfile_type_1",plotfile_type_1);
1737  pp.query_enum_case_insensitive("plotfile_type_2",plotfile_type_2);
1738  //
1739  // This option is for backward consistency -- if only plotfile_type is set,
1740  // then it will be used for both 1 and 2 if and only if they are not set
1741  //
1742  // Default is native amrex if no type is specified
1743  //
1744  if (plotfile_type_temp == PlotFileType::None) {
1745  if (plotfile_type_1 == PlotFileType::None) {
1746  plotfile_type_1 = PlotFileType::Amrex;
1747  }
1748  if (plotfile_type_2 == PlotFileType::None) {
1749  plotfile_type_2 = PlotFileType::Amrex;
1750  }
1751  } else {
1752  if (plotfile_type_1 == PlotFileType::None) {
1753  plotfile_type_1 = plotfile_type_temp;
1754  } else {
1755  amrex::Abort("You must set either plotfile_type or plotfile_type_1, not both");
1756  }
1757  if (plotfile_type_2 == PlotFileType::None) {
1758  plotfile_type_2 = plotfile_type_temp;
1759  } else {
1760  amrex::Abort("You must set either plotfile_type or plotfile_type_2, not both");
1761  }
1762  }
1763 #ifndef ERF_USE_NETCDF
1764  if (plotfile_type_1 == PlotFileType::Netcdf ||
1765  plotfile_type_2 == PlotFileType::Netcdf) {
1766  amrex::Abort("Plotfile type = Netcdf is not allowed without USE_NETCDF = TRUE");
1767  }
1768 #endif
1769 
1770  pp.query("plot_file_1", plot_file_1);
1771  pp.query("plot_file_2", plot_file_2);
1772  pp.query("plot_int_1" , m_plot_int_1);
1773  pp.query("plot_int_2" , m_plot_int_2);
1774  pp.query("plot_per_1", m_plot_per_1);
1775  pp.query("plot_per_2", m_plot_per_2);
1776 
1777  pp.query("subvol_file", subvol_file);
1778  pp.query("subvol_int" , m_subvol_int);
1779  pp.query("subvol_per" , m_subvol_per);
1780 
1781  pp.query("expand_plotvars_to_unif_rr",m_expand_plotvars_to_unif_rr);
1782 
1783  pp.query("plot_face_vels",m_plot_face_vels);
1784 
1785  if ( (m_plot_int_1 > 0 && m_plot_per_1 > 0) ||
1786  (m_plot_int_2 > 0 && m_plot_per_2 > 0.) ) {
1787  Abort("Must choose only one of plot_int or plot_per");
1788  }
1789 
1790  pp.query("profile_int", profile_int);
1791  pp.query("destag_profiles", destag_profiles);
1792 
1793  pp.query("plot_lsm", plot_lsm);
1794 #ifdef ERF_USE_RRTMGP
1795  pp.query("plot_rad", plot_rad);
1796 #endif
1797  pp.query("profile_rad_int", rad_datalog_int);
1798 
1799  pp.query("output_1d_column", output_1d_column);
1800  pp.query("column_per", column_per);
1801  pp.query("column_interval", column_interval);
1802  pp.query("column_loc_x", column_loc_x);
1803  pp.query("column_loc_y", column_loc_y);
1804  pp.query("column_file_name", column_file_name);
1805 
1806  // Sampler output frequency
1807  pp.query("sampler_per", sampler_per);
1808  pp.query("sampler_interval", sampler_interval);
1809 
1810  // Specify information about outputting planes of data
1811  pp.query("output_bndry_planes", output_bndry_planes);
1812  pp.query("bndry_output_planes_interval", bndry_output_planes_interval);
1813  pp.query("bndry_output_planes_per", bndry_output_planes_per);
1814  pp.query("bndry_output_start_time", bndry_output_planes_start_time);
1815 
1816  // Specify whether ingest boundary planes of data
1817  pp.query("input_bndry_planes", input_bndry_planes);
1818 
1819  // Query the set and total widths for wrfbdy interior ghost cells
1820  pp.query("real_width", real_width);
1821  pp.query("real_set_width", real_set_width);
1822 
1823  // Query the set and total widths for crse-fine interior ghost cells
1824  pp.query("cf_width", cf_width);
1825  pp.query("cf_set_width", cf_set_width);
1826 
1827  // AmrMesh iterate on grids?
1828  bool iterate(true);
1829  pp_amr.query("iterate_grids",iterate);
1830  if (!iterate) SetIterateToFalse();
1831  }
1832 
1833 #ifdef ERF_USE_PARTICLES
1834  readTracersParams();
1835 #endif
1836 
1837  solverChoice.init_params(max_level,pp_prefix);
1838 
1839 #ifndef ERF_USE_NETCDF
1840  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(( (solverChoice.init_type != InitType::WRFInput) &&
1841  (solverChoice.init_type != InitType::Metgrid ) &&
1842  (solverChoice.init_type != InitType::NCFile ) ),
1843  "init_type cannot be 'WRFInput', 'MetGrid' or 'NCFile' if we don't build with netcdf!");
1844 #endif
1845 
1846  // Query the canopy model file name
1847  std::string forestfile;
1848  solverChoice.do_forest_drag = pp.query("forest_file", forestfile);
1850  for (int lev = 0; lev <= max_level; ++lev) {
1851  m_forest_drag[lev] = std::make_unique<ForestDrag>(forestfile);
1852  }
1853  }
1854 
1855  // If init from WRFInput or Metgrid make sure a valid file name is present
1856  if ((solverChoice.init_type == InitType::WRFInput) ||
1857  (solverChoice.init_type == InitType::Metgrid) ||
1858  (solverChoice.init_type == InitType::NCFile) ) {
1859  for (int lev = 0; lev <= max_level; lev++) {
1860  int num_files = nc_init_file[lev].size();
1861  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(num_files>0, "A file name must be present for init type WRFInput, Metgrid or NCFile.");
1862  for (int j = 0; j < num_files; j++) {
1863  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!nc_init_file[lev][j].empty(), "Valid file name must be present for init type WRFInput, Metgrid or NCFile.");
1864  } //j
1865  } // lev
1866  } // InitType
1867 
1868  // What type of land surface model to use
1869  // NOTE: Must be checked after init_params
1870  if (solverChoice.lsm_type == LandSurfaceType::SLM) {
1871  lsm.SetModel<SLM>();
1872  Print() << "SLM land surface model!\n";
1873  } else if (solverChoice.lsm_type == LandSurfaceType::MM5) {
1874  lsm.SetModel<MM5>();
1875  Print() << "MM5 land surface model!\n";
1876 #ifdef ERF_USE_NOAH
1877  } else if (solverChoice.lsm_type == LandSurfaceType::NOAH) {
1878  lsm.SetModel<NOAH>();
1879  Print() << "NOAH land surface model!\n";
1880 #endif
1881  } else if (solverChoice.lsm_type == LandSurfaceType::None) {
1882  lsm.SetModel<NullSurf>();
1883  Print() << "Null land surface model!\n";
1884  } else {
1885  Abort("Dont know this LandSurfaceType!") ;
1886  }
1887 
1888  if (verbose > 0) {
1889  solverChoice.display(max_level,pp_prefix);
1890  }
1891 
1893 }
AMREX_FORCE_INLINE std::time_t getEpochTime(const std::string &dateTime, const std::string &dateTimeFormat)
Definition: ERF_EpochTime.H:14
bool metgrid_basic_linear
Definition: ERF.H:1067
amrex::Vector< amrex::Vector< amrex::Box > > boxes_at_level
Definition: ERF.H:693
bool metgrid_debug_msf
Definition: ERF.H:1065
std::string plot_file_2
Definition: ERF.H:927
bool plot_rad
Definition: ERF.H:772
bool m_plot_face_vels
Definition: ERF.H:936
int regrid_int
Definition: ERF.H:919
bool metgrid_retain_sfc
Definition: ERF.H:1070
bool metgrid_use_sfc
Definition: ERF.H:1069
amrex::Vector< int > num_files_at_level
Definition: ERF.H:692
bool metgrid_debug_quiescent
Definition: ERF.H:1061
bool metgrid_interp_theta
Definition: ERF.H:1066
static amrex::Vector< amrex::Vector< std::string > > nc_init_file
Definition: ERF.H:1046
bool regrid_level_0_on_restart
Definition: ERF.H:923
int metgrid_force_sfc_k
Definition: ERF.H:1073
bool metgrid_use_below_sfc
Definition: ERF.H:1068
std::string subvol_file
Definition: ERF.H:928
amrex::Real metgrid_proximity
Definition: ERF.H:1071
std::string plot_file_1
Definition: ERF.H:926
bool metgrid_debug_dry
Definition: ERF.H:1063
bool metgrid_debug_isothermal
Definition: ERF.H:1062
bool metgrid_debug_psfc
Definition: ERF.H:1064
static std::string nc_low_file
Definition: ERF.H:1054
void ParameterSanityChecks()
Definition: ERF.cpp:1897
bool m_expand_plotvars_to_unif_rr
Definition: ERF.H:929
amrex::Vector< int > num_boxes_at_level
Definition: ERF.H:691
std::string check_file
Definition: ERF.H:945
int metgrid_order
Definition: ERF.H:1072
bool plot_lsm
Definition: ERF.H:938
void SetModel()
Definition: ERF_LandSurface.H:28
Definition: ERF_MM5.H:26
Definition: ERF_NOAH.H:30
Definition: ERF_NullSurf.H:8
Definition: ERF_SLM.H:26
void display(int max_level, std::string pp_prefix)
Definition: ERF_DataStruct.H:537
void init_params(int max_level, std::string pp_prefix)
Definition: ERF_DataStruct.H:101
Here is the call graph for this function:

◆ refinement_criteria_setup()

void ERF::refinement_criteria_setup ( )
private

Function to define the refinement criteria based on user input

166 {
167  if (max_level > 0)
168  {
169  ParmParse pp(pp_prefix);
170  Vector<std::string> refinement_indicators;
171  pp.queryarr("refinement_indicators",refinement_indicators,0,pp.countval("refinement_indicators"));
172 
173  for (int i=0; i<refinement_indicators.size(); ++i)
174  {
175  std::string ref_prefix = pp_prefix + "." + refinement_indicators[i];
176 
177  ParmParse ppr(ref_prefix);
178  RealBox realbox;
179  int lev_for_box;
180 
181  int num_real_lo = ppr.countval("in_box_lo");
182  int num_indx_lo = ppr.countval("in_box_lo_indices");
183  int num_real_hi = ppr.countval("in_box_hi");
184  int num_indx_hi = ppr.countval("in_box_hi_indices");
185 
186  AMREX_ALWAYS_ASSERT(num_real_lo == num_real_hi);
187  AMREX_ALWAYS_ASSERT(num_indx_lo == num_indx_hi);
188 
189  if ( !((num_real_lo >= AMREX_SPACEDIM-1 && num_indx_lo == 0) ||
190  (num_indx_lo >= AMREX_SPACEDIM-1 && num_real_lo == 0) ||
191  (num_indx_lo == 0 && num_real_lo == 0)) )
192  {
193  amrex::Abort("Must only specify box for refinement using real OR index space");
194  }
195 
196  if (num_real_lo > 0) {
197  std::vector<Real> rbox_lo(3), rbox_hi(3);
198  ppr.get("max_level",lev_for_box);
199  if (lev_for_box <= max_level)
200  {
201  if (n_error_buf[0] != IntVect::TheZeroVector()) {
202  amrex::Abort("Don't use n_error_buf > 0 when setting the box explicitly");
203  }
204 
205  const Real* plo = geom[lev_for_box].ProbLo();
206  const Real* phi = geom[lev_for_box].ProbHi();
207 
208  ppr.getarr("in_box_lo",rbox_lo,0,num_real_lo);
209  ppr.getarr("in_box_hi",rbox_hi,0,num_real_hi);
210 
211  if (rbox_lo[0] < plo[0]) rbox_lo[0] = plo[0];
212  if (rbox_lo[1] < plo[1]) rbox_lo[1] = plo[1];
213  if (rbox_hi[0] > phi[0]) rbox_hi[0] = phi[0];
214  if (rbox_hi[1] > phi[1]) rbox_hi[1] = phi[1];
215  if (num_real_lo < AMREX_SPACEDIM) {
216  rbox_lo[2] = plo[2];
217  rbox_hi[2] = phi[2];
218  }
219 
220  realbox = RealBox(&(rbox_lo[0]),&(rbox_hi[0]));
221 
222  Print() << "Realbox read in and intersected laterally with domain is " << realbox << std::endl;
223 
224  num_boxes_at_level[lev_for_box] += 1;
225 
226  int ilo, jlo, klo;
227  int ihi, jhi, khi;
228  const auto* dx = geom[lev_for_box].CellSize();
229  ilo = static_cast<int>((rbox_lo[0] - plo[0])/dx[0]);
230  jlo = static_cast<int>((rbox_lo[1] - plo[1])/dx[1]);
231  ihi = static_cast<int>((rbox_hi[0] - plo[0])/dx[0]-1);
232  jhi = static_cast<int>((rbox_hi[1] - plo[1])/dx[1]-1);
233  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
234  // Search for k indices corresponding to nominal grid
235  // AGL heights
236  const Box& domain = geom[lev_for_box].Domain();
237  klo = domain.smallEnd(2) - 1;
238  khi = domain.smallEnd(2) - 1;
239 
240  if (rbox_lo[2] <= zlevels_stag[lev_for_box][domain.smallEnd(2)])
241  {
242  klo = domain.smallEnd(2);
243  }
244  else
245  {
246  for (int k=domain.smallEnd(2); k<=domain.bigEnd(2)+1; ++k) {
247  if (zlevels_stag[lev_for_box][k] > rbox_lo[2]) {
248  klo = k-1;
249  break;
250  }
251  }
252  }
253  AMREX_ASSERT(klo >= domain.smallEnd(2));
254 
255  if (rbox_hi[2] >= zlevels_stag[lev_for_box][domain.bigEnd(2)+1])
256  {
257  khi = domain.bigEnd(2);
258  }
259  else
260  {
261  for (int k=klo+1; k<=domain.bigEnd(2)+1; ++k) {
262  if (zlevels_stag[lev_for_box][k] > rbox_hi[2]) {
263  khi = k-1;
264  break;
265  }
266  }
267  }
268  AMREX_ASSERT((khi <= domain.bigEnd(2)) && (khi > klo));
269 
270  // Need to update realbox because tagging is based on
271  // the initial _un_deformed grid
272  realbox = RealBox(plo[0]+ ilo *dx[0], plo[1]+ jlo *dx[1], plo[2]+ klo *dx[2],
273  plo[0]+(ihi+1)*dx[0], plo[1]+(jhi+1)*dx[1], plo[2]+(khi+1)*dx[2]);
274  } else {
275  klo = static_cast<int>((rbox_lo[2] - plo[2])/dx[2]);
276  khi = static_cast<int>((rbox_hi[2] - plo[2])/dx[2]-1);
277  }
278 
279  Box bx(IntVect(ilo,jlo,klo),IntVect(ihi,jhi,khi));
280  if ( (ilo%ref_ratio[lev_for_box-1][0] != 0) || ((ihi+1)%ref_ratio[lev_for_box-1][0] != 0) ||
281  (jlo%ref_ratio[lev_for_box-1][1] != 0) || ((jhi+1)%ref_ratio[lev_for_box-1][1] != 0) ||
282  (klo%ref_ratio[lev_for_box-1][2] != 0) || ((khi+1)%ref_ratio[lev_for_box-1][2] != 0) )
283  {
284  amrex::Print() << "Box : " << bx << std::endl;
285  amrex::Print() << "RealBox : " << realbox << std::endl;
286  amrex::Print() << "ilo, ihi+1, jlo, jhi+1, klo, khi+1 by ref_ratio : "
287  << ilo%ref_ratio[lev_for_box-1][0] << " " << (ihi+1)%ref_ratio[lev_for_box-1][0] << " "
288  << jlo%ref_ratio[lev_for_box-1][1] << " " << (jhi+1)%ref_ratio[lev_for_box-1][1] << " "
289  << klo%ref_ratio[lev_for_box-1][2] << " " << (khi+1)%ref_ratio[lev_for_box-1][2] << std::endl;
290  amrex::Error("Fine box is not legit with this ref_ratio");
291  }
292  boxes_at_level[lev_for_box].push_back(bx);
293  Print() << "Saving in 'boxes at level' as " << bx << std::endl;
294  } // lev
295  if (solverChoice.init_type == InitType::WRFInput) {
296  if (num_boxes_at_level[lev_for_box] != num_files_at_level[lev_for_box]) {
297  amrex::Error("Number of boxes doesn't match number of input files");
298 
299  }
300  }
301 
302  } else if (num_indx_lo > 0) {
303 
304  std::vector<int> box_lo(3), box_hi(3);
305  ppr.get("max_level",lev_for_box);
306  if (lev_for_box <= max_level)
307  {
308  if (n_error_buf[0] != IntVect::TheZeroVector()) {
309  amrex::Abort("Don't use n_error_buf > 0 when setting the box explicitly");
310  }
311 
312  ppr.getarr("in_box_lo_indices",box_lo,0,AMREX_SPACEDIM);
313  ppr.getarr("in_box_hi_indices",box_hi,0,AMREX_SPACEDIM);
314 
315  Box bx(IntVect(box_lo[0],box_lo[1],box_lo[2]),IntVect(box_hi[0],box_hi[1],box_hi[2]));
316  amrex::Print() << "BOX " << bx << std::endl;
317 
318  const auto* dx = geom[lev_for_box].CellSize();
319  const Real* plo = geom[lev_for_box].ProbLo();
320  realbox = RealBox(plo[0]+ box_lo[0] *dx[0], plo[1]+ box_lo[1] *dx[1], plo[2]+ box_lo[2] *dx[2],
321  plo[0]+(box_hi[0]+1)*dx[0], plo[1]+(box_hi[1]+1)*dx[1], plo[2]+(box_hi[2]+1)*dx[2]);
322 
323  Print() << "Reading " << bx << " at level " << lev_for_box << std::endl;
324  num_boxes_at_level[lev_for_box] += 1;
325 
326  if ( (box_lo[0]%ref_ratio[lev_for_box-1][0] != 0) || ((box_hi[0]+1)%ref_ratio[lev_for_box-1][0] != 0) ||
327  (box_lo[1]%ref_ratio[lev_for_box-1][1] != 0) || ((box_hi[1]+1)%ref_ratio[lev_for_box-1][1] != 0) ||
328  (box_lo[2]%ref_ratio[lev_for_box-1][2] != 0) || ((box_hi[2]+1)%ref_ratio[lev_for_box-1][2] != 0) )
329  amrex::Error("Fine box is not legit with this ref_ratio");
330  boxes_at_level[lev_for_box].push_back(bx);
331  Print() << "Saving in 'boxes at level' as " << bx << std::endl;
332  } // lev
333  if (solverChoice.init_type == InitType::WRFInput) {
334  if (num_boxes_at_level[lev_for_box] != num_files_at_level[lev_for_box]) {
335  amrex::Error("Number of boxes doesn't match number of input files");
336 
337  }
338  }
339  }
340 
341  AMRErrorTagInfo info;
342 
343  if (realbox.ok()) {
344  info.SetRealBox(realbox);
345  }
346  if (ppr.countval("start_time") > 0) {
347  Real ref_min_time; ppr.get("start_time",ref_min_time);
348  info.SetMinTime(ref_min_time);
349  }
350  if (ppr.countval("end_time") > 0) {
351  Real ref_max_time; ppr.get("end_time",ref_max_time);
352  info.SetMaxTime(ref_max_time);
353  }
354  if (ppr.countval("max_level") > 0) {
355  int ref_max_level; ppr.get("max_level",ref_max_level);
356  info.SetMaxLevel(ref_max_level);
357  }
358 
359  if (ppr.countval("value_greater")) {
360  int num_val = ppr.countval("value_greater");
361  Vector<Real> value(num_val);
362  ppr.getarr("value_greater",value,0,num_val);
363  std::string field; ppr.get("field_name",field);
364  ref_tags.push_back(AMRErrorTag(value,AMRErrorTag::GREATER,field,info));
365  }
366  else if (ppr.countval("value_less")) {
367  int num_val = ppr.countval("value_less");
368  Vector<Real> value(num_val);
369  ppr.getarr("value_less",value,0,num_val);
370  std::string field; ppr.get("field_name",field);
371  ref_tags.push_back(AMRErrorTag(value,AMRErrorTag::LESS,field,info));
372  }
373  else if (ppr.countval("adjacent_difference_greater")) {
374  int num_val = ppr.countval("adjacent_difference_greater");
375  Vector<Real> value(num_val);
376  ppr.getarr("adjacent_difference_greater",value,0,num_val);
377  std::string field; ppr.get("field_name",field);
378  ref_tags.push_back(AMRErrorTag(value,AMRErrorTag::GRAD,field,info));
379  }
380  else if (realbox.ok())
381  {
382  ref_tags.push_back(AMRErrorTag(info));
383  } else {
384  Abort(std::string("Unrecognized refinement indicator for " + refinement_indicators[i]).c_str());
385  }
386  } // loop over criteria
387  } // if max_level > 0
388 }
Here is the call graph for this function:

◆ remake_zphys()

void ERF::remake_zphys ( int  lev,
amrex::Real  time,
std::unique_ptr< amrex::MultiFab > &  temp_zphys_nd 
)
586 {
587  if (lev > 0)
588  {
589  //
590  // First interpolate from coarser level
591  // NOTE: this interpolater assumes that ALL ghost cells of the coarse MultiFab
592  // have been pre-filled - this includes ghost cells both inside and outside
593  // the domain
594  //
595  InterpFromCoarseLevel(*temp_zphys_nd, z_phys_nd[lev]->nGrowVect(),
596  IntVect(0,0,0), // do not fill ghost cells outside the domain
597  *z_phys_nd[lev-1], 0, 0, 1,
598  geom[lev-1], geom[lev],
599  refRatio(lev-1), &node_bilinear_interp,
601 
602  // This recomputes the fine values using the bottom terrain at the fine resolution,
603  // and also fills values of z_phys_nd outside the domain
604  make_terrain_fitted_coords(lev,geom[lev],*temp_zphys_nd,zlevels_stag[lev],phys_bc_type);
605 
606  std::swap(temp_zphys_nd, z_phys_nd[lev]);
607 
608  } // lev > 0
609 
610  if (solverChoice.terrain_type == TerrainType::ImmersedForcing) {
611  //
612  // This assumes we have already remade the EBGeometry
613  //
614  terrain_blanking[lev]->setVal(1.0);
615  MultiFab::Subtract(*terrain_blanking[lev], EBFactory(lev).getVolFrac(), 0, 0, 1, z_phys_nd[lev]->nGrowVect());
616  }
617 }
Here is the call graph for this function:

◆ RemakeLevel()

void ERF::RemakeLevel ( int  lev,
amrex::Real  time,
const amrex::BoxArray &  ba,
const amrex::DistributionMapping &  dm 
)
override
374 {
375  if (verbose) {
376  amrex::Print() <<" REMAKING WITH NEW BA AT LEVEL " << lev << " " << ba << std::endl;
377  }
378 
379  AMREX_ALWAYS_ASSERT(solverChoice.terrain_type != TerrainType::MovingFittedMesh);
380 
381  BoxArray ba_old(vars_new[lev][Vars::cons].boxArray());
382  DistributionMapping dm_old(vars_new[lev][Vars::cons].DistributionMap());
383 
384  if (verbose) {
385  amrex::Print() <<" OLD BA AT LEVEL " << lev << " " << ba_old << std::endl;
386  }
387 
388  int ncomp_cons = vars_new[lev][Vars::cons].nComp();
389  IntVect ngrow_state = vars_new[lev][Vars::cons].nGrowVect();
390 
391  int ngrow_vels = ComputeGhostCells(solverChoice);
392 
393  Vector<MultiFab> temp_lev_new(Vars::NumTypes);
394  Vector<MultiFab> temp_lev_old(Vars::NumTypes);
395  MultiFab temp_base_state;
396 
397  std::unique_ptr<MultiFab> temp_zphys_nd;
398 
399  //********************************************************************************************
400  // This allocates all kinds of things, including but not limited to: solution arrays,
401  // terrain arrays and metrics, and base state.
402  // *******************************************************************************************
403  init_stuff(lev, ba, dm, temp_lev_new, temp_lev_old, temp_base_state, temp_zphys_nd);
404 
405  // ********************************************************************************************
406  // Build the data structures for terrain-related quantities
407  // ********************************************************************************************
408  remake_zphys(lev, time, temp_zphys_nd);
410 
411  // ********************************************************************************************
412  // Make sure that detJ and z_phys_cc are the average of the data on a finer level if there is one
413  // ********************************************************************************************
414  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
415  for (int crse_lev = lev-1; crse_lev >= 0; crse_lev--) {
416  average_down( *detJ_cc[crse_lev+1], *detJ_cc[crse_lev], 0, 1, refRatio(crse_lev));
417  average_down(*z_phys_cc[crse_lev+1], *z_phys_cc[crse_lev], 0, 1, refRatio(crse_lev));
418  }
419  }
420 
421  // ********************************************************************************************
422  // Build the data structures for canopy model (depends upon z_phys)
423  // ********************************************************************************************
425  m_forest_drag[lev]->define_drag_field(ba, dm, geom[lev], z_phys_cc[lev].get(), z_phys_nd[lev].get());
426  }
427 
428  // *****************************************************************************************************
429  // Create the physbcs objects (after initializing the terrain but before calling FillCoarsePatch
430  // *****************************************************************************************************
431  make_physbcs(lev);
432 
433  // ********************************************************************************************
434  // Update the base state at this level by interpolation from coarser level AND copy
435  // from previous (pre-regrid) base_state array
436  // ********************************************************************************************
437  if (lev > 0) {
438  Interpolater* mapper = &cell_cons_interp;
439 
440  Vector<MultiFab*> fmf = {&base_state[lev ], &base_state[lev ]};
441  Vector<MultiFab*> cmf = {&base_state[lev-1], &base_state[lev-1]};
442  Vector<Real> ftime = {time, time};
443  Vector<Real> ctime = {time, time};
444 
445  // Call FillPatch which ASSUMES that all ghost cells at lev-1 have already been filled
446  FillPatchTwoLevels(temp_base_state, temp_base_state.nGrowVect(), IntVect(0,0,0),
447  time, cmf, ctime, fmf, ftime,
448  0, 0, temp_base_state.nComp(), geom[lev-1], geom[lev],
449  refRatio(lev-1), mapper, domain_bcs_type,
451 
452  // Impose bc's outside the domain
453  (*physbcs_base[lev])(temp_base_state,0,temp_base_state.nComp(),base_state[lev].nGrowVect());
454 
455  // *************************************************************************************************
456  // This will fill the temporary MultiFabs with data from vars_new
457  // NOTE: the momenta here are only used as scratch space, the momenta themselves are not fillpatched
458  // NOTE: we must create the new base state before calling FillPatch because we will
459  // interpolate perturbational quantities
460  // *************************************************************************************************
461  FillPatch(lev, time, {&temp_lev_new[Vars::cons],&temp_lev_new[Vars::xvel],
462  &temp_lev_new[Vars::yvel],&temp_lev_new[Vars::zvel]},
463  {&temp_lev_new[Vars::cons],&rU_new[lev],&rV_new[lev],&rW_new[lev]},
464  base_state[lev], temp_base_state, false);
465  } else {
466  temp_base_state.ParallelCopy(base_state[lev],0,0,base_state[lev].nComp(),
467  base_state[lev].nGrowVect(),base_state[lev].nGrowVect());
468  temp_lev_new[Vars::cons].ParallelCopy(vars_new[lev][Vars::cons],0,0,ncomp_cons,ngrow_state,ngrow_state);
469  temp_lev_new[Vars::xvel].ParallelCopy(vars_new[lev][Vars::xvel],0,0, 1,ngrow_vels,ngrow_vels);
470  temp_lev_new[Vars::yvel].ParallelCopy(vars_new[lev][Vars::yvel],0,0, 1,ngrow_vels,ngrow_vels);
471 
472  temp_lev_new[Vars::zvel].setVal(0.);
473  temp_lev_new[Vars::zvel].ParallelCopy(vars_new[lev][Vars::zvel],0,0, 1,
474  IntVect(ngrow_vels,ngrow_vels,0),IntVect(ngrow_vels,ngrow_vels,0));
475  }
476 
477  // Now swap the pointers since we needed both old and new in the FillPatch
478  std::swap(temp_base_state, base_state[lev]);
479 
480  // ********************************************************************************************
481  // Copy from new into old just in case
482  // ********************************************************************************************
483  MultiFab::Copy(temp_lev_old[Vars::cons],temp_lev_new[Vars::cons],0,0,ncomp_cons,ngrow_state);
484  MultiFab::Copy(temp_lev_old[Vars::xvel],temp_lev_new[Vars::xvel],0,0, 1,ngrow_vels);
485  MultiFab::Copy(temp_lev_old[Vars::yvel],temp_lev_new[Vars::yvel],0,0, 1,ngrow_vels);
486  MultiFab::Copy(temp_lev_old[Vars::zvel],temp_lev_new[Vars::zvel],0,0, 1,IntVect(ngrow_vels,ngrow_vels,0));
487 
488  // ********************************************************************************************
489  // Now swap the pointers
490  // ********************************************************************************************
491  for (int var_idx = 0; var_idx < Vars::NumTypes; ++var_idx) {
492  std::swap(temp_lev_new[var_idx], vars_new[lev][var_idx]);
493  std::swap(temp_lev_old[var_idx], vars_old[lev][var_idx]);
494  }
495 
496  t_new[lev] = time;
497  t_old[lev] = time - 1.e200;
498 
499  // ********************************************************************************************
500  // Build the data structures for calculating diffusive/turbulent terms
501  // ********************************************************************************************
502  update_diffusive_arrays(lev, ba, dm);
503 
504  //********************************************************************************************
505  // Microphysics
506  // *******************************************************************************************
507  int q_size = micro->Get_Qmoist_Size(lev);
508  qmoist[lev].resize(q_size);
509  micro->Define(lev, solverChoice);
510  if (solverChoice.moisture_type != MoistureType::None)
511  {
512  micro->Init(lev, vars_new[lev][Vars::cons],
513  grids[lev], Geom(lev), 0.0,
514  z_phys_nd[lev], detJ_cc[lev]); // dummy dt value
515  }
516  for (int mvar(0); mvar<qmoist[lev].size(); ++mvar) {
517  qmoist[lev][mvar] = micro->Get_Qmoist_Ptr(lev,mvar);
518  }
519 
520  // ********************************************************************************************
521  // Initialize the integrator class
522  // ********************************************************************************************
524 
525  // We need to re-define the FillPatcher if the grids have changed
526  if (lev > 0 && cf_width >= 0) {
527  bool ba_changed = (ba != ba_old);
528  bool dm_changed = (dm != dm_old);
529  if (ba_changed || dm_changed) {
531  }
532  }
533 
534  // ********************************************************************************************
535  // Update the SurfaceLayer arrays at this level
536  // ********************************************************************************************
537  if (phys_bc_type[Orientation(Direction::z,Orientation::low)] == ERF_BC::surface_layer) {
538  int nlevs = finest_level+1;
539  Vector<MultiFab*> mfv_old = {&vars_old[lev][Vars::cons], &vars_old[lev][Vars::xvel],
540  &vars_old[lev][Vars::yvel], &vars_old[lev][Vars::zvel]};
541  m_SurfaceLayer->make_SurfaceLayer_at_level(lev,nlevs,
542  mfv_old, Theta_prim[lev], Qv_prim[lev],
543  Qr_prim[lev], z_phys_nd[lev],
544  Hwave[lev].get(),Lwave[lev].get(),eddyDiffs_lev[lev].get(),
545  lsm_data[lev], lsm_flux[lev], sst_lev[lev], tsk_lev[lev], lmask_lev[lev]);
546  }
547 
548  // These calls are done in AmrCore::regrid if this is a regrid at lev > 0
549  // For a level 0 regrid we must explicitly do them here
550  if (lev == 0) {
551  // Define grids[lev] to be ba
552  SetBoxArray(lev, ba);
553 
554  // Define dmap[lev] to be dm
555  SetDistributionMap(lev, dm);
556  }
557 
558 #ifdef ERF_USE_PARTICLES
559  particleData.Redistribute();
560 #endif
561 }
void remake_zphys(int lev, amrex::Real time, std::unique_ptr< amrex::MultiFab > &temp_zphys_nd)
Definition: ERF_MakeNewArrays.cpp:585

◆ restart()

void ERF::restart ( )
1427 {
1429 
1430  // We set this here so that we don't over-write the checkpoint file we just started from
1432 
1434  //
1435  // Coarsening before we split the grids ensures that each resulting
1436  // grid will have an even number of cells in each direction.
1437  //
1438  BoxArray new_ba(amrex::coarsen(Geom(0).Domain(),2));
1439  //
1440  // Now split up into list of grids within max_grid_size[0] limit.
1441  //
1442  new_ba.maxSize(max_grid_size[0]/2);
1443  //
1444  // Now refine these boxes back to level 0.
1445  //
1446  new_ba.refine(2);
1447 
1448  if (refine_grid_layout) {
1449  ChopGrids(0, new_ba, ParallelDescriptor::NProcs());
1450  }
1451 
1452  if (new_ba != grids[0]) {
1453  DistributionMapping new_dm(new_ba);
1454  RemakeLevel(0,t_new[0],new_ba,new_dm);
1455  }
1456  }
1457 }
void RemakeLevel(int lev, amrex::Real time, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm) override
Definition: ERF_MakeNewLevel.cpp:373
void ReadCheckpointFile()
Definition: ERF_Checkpoint.cpp:419

◆ sample_lines()

void ERF::sample_lines ( int  lev,
amrex::Real  time,
amrex::IntVect  cell,
amrex::MultiFab &  mf 
)

Utility function for sampling data along a line along the z-dimension at the (x,y) indices specified and writes it to an output file.

Parameters
levCurrent level
timeCurrent time
cellIntVect containing the x,y-dimension indices to sample along z
mfMultiFab from which we sample the data
534 {
535  int ifile = 0;
536 
537  const int ncomp = mf.nComp(); // cell-centered state vars
538 
539  MultiFab mf_vels(grids[lev], dmap[lev], AMREX_SPACEDIM, 0);
540  average_face_to_cellcenter(mf_vels, 0,
541  Array<const MultiFab*,3>{&vars_new[lev][Vars::xvel],&vars_new[lev][Vars::yvel],&vars_new[lev][Vars::zvel]});
542 
543  //
544  // Sample the data at a line (in direction "dir") in space
545  // In this case we sample in the vertical direction so dir = 2
546  // The "k" value of "cell" is ignored
547  //
548  int dir = 2;
549  MultiFab my_line = get_line_data(mf, dir, cell);
550  MultiFab my_line_vels = get_line_data(mf_vels, dir, cell);
551  MultiFab my_line_tau11 = get_line_data(*Tau[lev][TauType::tau11], dir, cell);
552  MultiFab my_line_tau12 = get_line_data(*Tau[lev][TauType::tau12], dir, cell);
553  MultiFab my_line_tau13 = get_line_data(*Tau[lev][TauType::tau13], dir, cell);
554  MultiFab my_line_tau22 = get_line_data(*Tau[lev][TauType::tau22], dir, cell);
555  MultiFab my_line_tau23 = get_line_data(*Tau[lev][TauType::tau23], dir, cell);
556  MultiFab my_line_tau33 = get_line_data(*Tau[lev][TauType::tau33], dir, cell);
557 
558  for (MFIter mfi(my_line, false); mfi.isValid(); ++mfi)
559  {
560  // HERE DO WHATEVER YOU WANT TO THE DATA BEFORE WRITING
561 
562  std::ostream& sample_log = SampleLineLog(ifile);
563  if (sample_log.good()) {
564  sample_log << std::setw(datwidth) << std::setprecision(datprecision) << time;
565  const auto& my_line_arr = my_line[0].const_array();
566  const auto& my_line_vels_arr = my_line_vels[0].const_array();
567  const auto& my_line_tau11_arr = my_line_tau11[0].const_array();
568  const auto& my_line_tau12_arr = my_line_tau12[0].const_array();
569  const auto& my_line_tau13_arr = my_line_tau13[0].const_array();
570  const auto& my_line_tau22_arr = my_line_tau22[0].const_array();
571  const auto& my_line_tau23_arr = my_line_tau23[0].const_array();
572  const auto& my_line_tau33_arr = my_line_tau33[0].const_array();
573  const Box& my_box = my_line[0].box();
574  const int klo = my_box.smallEnd(2);
575  const int khi = my_box.bigEnd(2);
576  int i = cell[0];
577  int j = cell[1];
578  for (int n = 0; n < ncomp; n++) {
579  for (int k = klo; k <= khi; k++) {
580  sample_log << std::setw(datwidth) << std::setprecision(datprecision) << my_line_arr(i,j,k,n);
581  }
582  }
583  for (int n = 0; n < AMREX_SPACEDIM; n++) {
584  for (int k = klo; k <= khi; k++) {
585  sample_log << std::setw(datwidth) << std::setprecision(datprecision) << my_line_vels_arr(i,j,k,n);
586  }
587  }
588  for (int k = klo; k <= khi; k++) {
589  sample_log << std::setw(datwidth) << std::setprecision(datprecision) << my_line_tau11_arr(i,j,k);
590  }
591  for (int k = klo; k <= khi; k++) {
592  sample_log << std::setw(datwidth) << std::setprecision(datprecision) << my_line_tau12_arr(i,j,k);
593  }
594  for (int k = klo; k <= khi; k++) {
595  sample_log << std::setw(datwidth) << std::setprecision(datprecision) << my_line_tau13_arr(i,j,k);
596  }
597  for (int k = klo; k <= khi; k++) {
598  sample_log << std::setw(datwidth) << std::setprecision(datprecision) << my_line_tau22_arr(i,j,k);
599  }
600  for (int k = klo; k <= khi; k++) {
601  sample_log << std::setw(datwidth) << std::setprecision(datprecision) << my_line_tau23_arr(i,j,k);
602  }
603  for (int k = klo; k <= khi; k++) {
604  sample_log << std::setw(datwidth) << std::setprecision(datprecision) << my_line_tau33_arr(i,j,k);
605  }
606  sample_log << std::endl;
607  } // if good
608  } // mfi
609 }
const int datwidth
Definition: ERF.H:885
AMREX_FORCE_INLINE std::ostream & SampleLineLog(int i)
Definition: ERF.H:1280
const int datprecision
Definition: ERF.H:886

◆ sample_points()

void ERF::sample_points ( int  lev,
amrex::Real  time,
amrex::IntVect  cell,
amrex::MultiFab &  mf 
)

Utility function for sampling MultiFab data at a specified cell index.

Parameters
levLevel for the associated MultiFab data
timeCurrent time
cellIntVect containing the indexes for the cell where we want to sample
mfMultiFab from which we wish to sample data
498 {
499  int ifile = 0;
500 
501  //
502  // Sample the data at a single point in space
503  //
504  int ncomp = mf.nComp();
505  Vector<Real> my_point = get_cell_data(mf, cell);
506 
507  if (!my_point.empty()) {
508 
509  // HERE DO WHATEVER YOU WANT TO THE DATA BEFORE WRITING
510 
511  std::ostream& sample_log = SamplePointLog(ifile);
512  if (sample_log.good()) {
513  sample_log << std::setw(datwidth) << time;
514  for (int i = 0; i < ncomp; ++i)
515  {
516  sample_log << std::setw(datwidth) << my_point[i];
517  }
518  sample_log << std::endl;
519  } // if good
520  } // only write from processor that holds the cell
521 }
AMREX_FORCE_INLINE std::ostream & SamplePointLog(int i)
Definition: ERF.H:1266

◆ SampleLine()

amrex::IntVect& ERF::SampleLine ( int  i)
inlineprivate
1307  {
1308  return sampleline[i];
1309  }

◆ SampleLineLog()

AMREX_FORCE_INLINE std::ostream& ERF::SampleLineLog ( int  i)
inlineprivate
1281  {
1282  return *samplelinelog[i];
1283  }

◆ SampleLineLogName()

std::string ERF::SampleLineLogName ( int  i) const
inlineprivatenoexcept

The filename of the ith samplelinelog file.

1437 { return samplelinelogname[i]; }

◆ SamplePoint()

amrex::IntVect& ERF::SamplePoint ( int  i)
inlineprivate
1294  {
1295  return samplepoint[i];
1296  }

◆ SamplePointLog()

AMREX_FORCE_INLINE std::ostream& ERF::SamplePointLog ( int  i)
inlineprivate
1267  {
1268  return *sampleptlog[i];
1269  }

◆ SamplePointLogName()

std::string ERF::SamplePointLogName ( int  i) const
inlineprivatenoexcept

The filename of the ith sampleptlog file.

1434 { return sampleptlogname[i]; }

◆ setPlotVariables()

void ERF::setPlotVariables ( const std::string &  pp_plot_var_names,
amrex::Vector< std::string > &  plot_var_names 
)
private
23 {
24  ParmParse pp(pp_prefix);
25 
26  if (pp.contains(pp_plot_var_names.c_str()))
27  {
28  std::string nm;
29 
30  int nPltVars = pp.countval(pp_plot_var_names.c_str());
31 
32  for (int i = 0; i < nPltVars; i++)
33  {
34  pp.get(pp_plot_var_names.c_str(), nm, i);
35 
36  // Add the named variable to our list of plot variables
37  // if it is not already in the list
38  if (!containerHasElement(plot_var_names, nm)) {
39  plot_var_names.push_back(nm);
40  }
41  }
42  } else {
43  //
44  // The default is to add none of the variables to the list
45  //
46  plot_var_names.clear();
47  }
48 
49  // Get state variables in the same order as we define them,
50  // since they may be in any order in the input list
51  Vector<std::string> tmp_plot_names;
52 
53  for (int i = 0; i < cons_names.size(); ++i) {
54  if ( containerHasElement(plot_var_names, cons_names[i]) ) {
55  if (solverChoice.moisture_type == MoistureType::None) {
56  if (cons_names[i] != "rhoQ1" && cons_names[i] != "rhoQ2" && cons_names[i] != "rhoQ3" &&
57  cons_names[i] != "rhoQ4" && cons_names[i] != "rhoQ5" && cons_names[i] != "rhoQ6")
58  {
59  tmp_plot_names.push_back(cons_names[i]);
60  }
61  } else if (solverChoice.moisture_type == MoistureType::Kessler) { // allow rhoQ1, rhoQ2, rhoQ3
62  if (cons_names[i] != "rhoQ4" && cons_names[i] != "rhoQ5" && cons_names[i] != "rhoQ6")
63  {
64  tmp_plot_names.push_back(cons_names[i]);
65  }
66  } else if ( (solverChoice.moisture_type == MoistureType::SatAdj) ||
67  (solverChoice.moisture_type == MoistureType::SAM_NoPrecip_NoIce) ||
68  (solverChoice.moisture_type == MoistureType::Kessler_NoRain) ) { // allow rhoQ1, rhoQ2
69  if (cons_names[i] != "rhoQ3" && cons_names[i] != "rhoQ4" &&
70  cons_names[i] != "rhoQ5" && cons_names[i] != "rhoQ6")
71  {
72  tmp_plot_names.push_back(cons_names[i]);
73  }
74  } else if ( (solverChoice.moisture_type == MoistureType::Morrison_NoIce) ||
75  (solverChoice.moisture_type == MoistureType::SAM_NoIce ) ) { // allow rhoQ1, rhoQ2, rhoQ4
76  if (cons_names[i] != "rhoQ3" && cons_names[i] != "rhoQ5" && cons_names[i] != "rhoQ6")
77  {
78  tmp_plot_names.push_back(cons_names[i]);
79  }
80  } else
81  {
82  // For moisture_type SAM and Morrison we have all six variables
83  tmp_plot_names.push_back(cons_names[i]);
84  }
85  }
86  }
87 
88  // check for velocity since it's not in cons_names
89  // if we are asked for any velocity component, we will need them all
90  if (containerHasElement(plot_var_names, "x_velocity") ||
91  containerHasElement(plot_var_names, "y_velocity") ||
92  containerHasElement(plot_var_names, "z_velocity")) {
93  tmp_plot_names.push_back("x_velocity");
94  tmp_plot_names.push_back("y_velocity");
95  tmp_plot_names.push_back("z_velocity");
96  }
97 
98  //
99  // If the model we are running doesn't have the variable listed in the inputs file,
100  // just ignore it rather than aborting
101  //
102  for (int i = 0; i < derived_names.size(); ++i) {
103  if ( containerHasElement(plot_var_names, derived_names[i]) ) {
104  bool ok_to_add = ( (solverChoice.terrain_type == TerrainType::ImmersedForcing) ||
105  (derived_names[i] != "terrain_IB_mask") );
106  ok_to_add &= ( (SolverChoice::terrain_type == TerrainType::StaticFittedMesh) ||
107  (SolverChoice::terrain_type == TerrainType::MovingFittedMesh) ||
108  (derived_names[i] != "detJ") );
109  ok_to_add &= ( (SolverChoice::terrain_type == TerrainType::StaticFittedMesh) ||
110  (SolverChoice::terrain_type == TerrainType::MovingFittedMesh) ||
111  (derived_names[i] != "z_phys") );
112 #ifndef ERF_USE_WINDFARM
113  ok_to_add &= (derived_names[i] != "SMark0" && derived_names[i] != "SMark1");
114 #endif
115  if (ok_to_add)
116  {
117  if (solverChoice.moisture_type == MoistureType::None) { // no moist quantities allowed
118  if (derived_names[i] != "qv" && derived_names[i] != "qc" && derived_names[i] != "qrain" &&
119  derived_names[i] != "qi" && derived_names[i] != "qsnow" && derived_names[i] != "qgraup" &&
120  derived_names[i] != "rain_accum" && derived_names[i] != "snow_accum" && derived_names[i] != "graup_accum")
121  {
122  tmp_plot_names.push_back(derived_names[i]);
123  }
124  } else if ( (solverChoice.moisture_type == MoistureType::Kessler ) ||
125  (solverChoice.moisture_type == MoistureType::Morrison_NoIce) ||
126  (solverChoice.moisture_type == MoistureType::SAM_NoIce ) ) { // allow qv, qc, qrain
127  if (derived_names[i] != "qi" && derived_names[i] != "qsnow" && derived_names[i] != "qgraup" &&
128  derived_names[i] != "snow_accum" && derived_names[i] != "graup_accum")
129  {
130  tmp_plot_names.push_back(derived_names[i]);
131  }
132  } else if ( (solverChoice.moisture_type == MoistureType::SatAdj) ||
133  (solverChoice.moisture_type == MoistureType::SAM_NoPrecip_NoIce) ||
134  (solverChoice.moisture_type == MoistureType::Kessler_NoRain) ) { // allow qv, qc
135  if (derived_names[i] != "qrain" &&
136  derived_names[i] != "qi" && derived_names[i] != "qsnow" && derived_names[i] != "qgraup" &&
137  derived_names[i] != "rain_accum" && derived_names[i] != "snow_accum" && derived_names[i] != "graup_accum")
138  {
139  tmp_plot_names.push_back(derived_names[i]);
140  }
141  } else
142  {
143  // For moisture_type SAM and Morrison we have all moist quantities
144  tmp_plot_names.push_back(derived_names[i]);
145  }
146  } // use_terrain?
147  } // hasElement
148  }
149 
150 #ifdef ERF_USE_WINDFARM
151  for (int i = 0; i < derived_names.size(); ++i) {
152  if ( containerHasElement(plot_var_names, derived_names[i]) ) {
153  if(solverChoice.windfarm_type == WindFarmType::Fitch or solverChoice.windfarm_type == WindFarmType::EWP) {
154  if(derived_names[i] == "num_turb" or derived_names[i] == "SMark0") {
155  tmp_plot_names.push_back(derived_names[i]);
156  }
157  }
158  if( solverChoice.windfarm_type == WindFarmType::SimpleAD or
159  solverChoice.windfarm_type == WindFarmType::GeneralAD ) {
160  if(derived_names[i] == "num_turb" or derived_names[i] == "SMark0" or derived_names[i] == "SMark1") {
161  tmp_plot_names.push_back(derived_names[i]);
162  }
163  }
164  }
165  }
166 #endif
167 
168 #ifdef ERF_USE_PARTICLES
169  const auto& particles_namelist( particleData.getNamesUnalloc() );
170  for (auto it = particles_namelist.cbegin(); it != particles_namelist.cend(); ++it) {
171  std::string tmp( (*it)+"_count" );
172  if (containerHasElement(plot_var_names, tmp) ) {
173  tmp_plot_names.push_back(tmp);
174  }
175  }
176 #endif
177 
178  plot_var_names = tmp_plot_names;
179 }
const amrex::Vector< std::string > derived_names
Definition: ERF.H:956
const amrex::Vector< std::string > cons_names
Definition: ERF.H:951
Here is the call graph for this function:

◆ setRayleighRefFromSounding()

void ERF::setRayleighRefFromSounding ( bool  restarting)
private

Set Rayleigh mean profiles from input sounding.

Sets the Rayleigh Damping averaged quantities from an externally supplied input sounding data file.

Parameters
[in]restartingBoolean parameter that indicates whether we are currently restarting from a checkpoint file.
56 {
57  // If we are restarting then we haven't read the input_sounding file yet
58  // so we need to read it here
59  // TODO: should we store this information in the checkpoint file instead?
60  if (restarting) {
62  for (int n = 0; n < input_sounding_data.n_sounding_files; n++) {
64  }
65  }
66 
67  const Real* z_inp_sound = input_sounding_data.z_inp_sound[0].dataPtr();
68  const Real* U_inp_sound = input_sounding_data.U_inp_sound[0].dataPtr();
69  const Real* V_inp_sound = input_sounding_data.V_inp_sound[0].dataPtr();
70  const Real* theta_inp_sound = input_sounding_data.theta_inp_sound[0].dataPtr();
71  const int inp_sound_size = input_sounding_data.size(0);
72 
73  int refine_fac{1};
74  for (int lev = 0; lev <= finest_level; lev++)
75  {
76  const int klo = geom[lev].Domain().smallEnd(2);
77  const int khi = geom[lev].Domain().bigEnd(2);
78  const int Nz = khi - klo + 1;
79 
80  Vector<Real> zcc(Nz);
81  Vector<Real> zlevels_sub(zlevels_stag[0].begin()+klo/refine_fac,
82  zlevels_stag[0].begin()+khi/refine_fac+2);
83  expand_and_interpolate_1d(zcc, zlevels_sub, refine_fac, true);
84 #if 0
85  amrex::AllPrint() << "lev="<<lev<<" : (refine_fac="<<refine_fac<<",klo="<<klo<<",khi="<<khi<<") ";
86  for (int k = 0; k < zlevels_sub.size(); k++) { amrex::AllPrint() << zlevels_sub[k] << " "; }
87  amrex::AllPrint() << " --> ";
88  for (int k = 0; k < Nz; k++) { amrex::AllPrint() << zcc[k] << " "; }
89  amrex::AllPrint() << std::endl;
90 #endif
91 
92  for (int k = 0; k < Nz; k++)
93  {
94  h_rayleigh_ptrs[lev][Rayleigh::ubar][k] = interpolate_1d(z_inp_sound, U_inp_sound, zcc[k], inp_sound_size);
95  h_rayleigh_ptrs[lev][Rayleigh::vbar][k] = interpolate_1d(z_inp_sound, V_inp_sound, zcc[k], inp_sound_size);
96  h_rayleigh_ptrs[lev][Rayleigh::wbar][k] = Real(0.0);
97  h_rayleigh_ptrs[lev][Rayleigh::thetabar][k] = interpolate_1d(z_inp_sound, theta_inp_sound, zcc[k], inp_sound_size);
98  }
99 
100  // Copy from host version to device version
101  Gpu::copy(Gpu::hostToDevice, h_rayleigh_ptrs[lev][Rayleigh::ubar].begin(), h_rayleigh_ptrs[lev][Rayleigh::ubar].end(),
102  d_rayleigh_ptrs[lev][Rayleigh::ubar].begin());
103  Gpu::copy(Gpu::hostToDevice, h_rayleigh_ptrs[lev][Rayleigh::vbar].begin(), h_rayleigh_ptrs[lev][Rayleigh::vbar].end(),
104  d_rayleigh_ptrs[lev][Rayleigh::vbar].begin());
105  Gpu::copy(Gpu::hostToDevice, h_rayleigh_ptrs[lev][Rayleigh::wbar].begin(), h_rayleigh_ptrs[lev][Rayleigh::wbar].end(),
106  d_rayleigh_ptrs[lev][Rayleigh::wbar].begin());
107  Gpu::copy(Gpu::hostToDevice, h_rayleigh_ptrs[lev][Rayleigh::thetabar].begin(), h_rayleigh_ptrs[lev][Rayleigh::thetabar].end(),
108  d_rayleigh_ptrs[lev][Rayleigh::thetabar].begin());
109 
110  refine_fac *= ref_ratio[lev][2];
111  }
112 }
AMREX_FORCE_INLINE void expand_and_interpolate_1d(amrex::Vector< amrex::Real > &znew, const amrex::Vector< amrex::Real > &zorig, int refine_fac, bool destag=false)
Definition: ERF_Interpolation_1D.H:85
amrex::Vector< amrex::Vector< amrex::Real > > theta_inp_sound
Definition: ERF_InputSoundingData.H:323
amrex::Vector< amrex::Vector< amrex::Real > > z_inp_sound
Definition: ERF_InputSoundingData.H:323
amrex::Vector< amrex::Vector< amrex::Real > > U_inp_sound
Definition: ERF_InputSoundingData.H:323
amrex::Vector< amrex::Vector< amrex::Real > > V_inp_sound
Definition: ERF_InputSoundingData.H:323
int size(int itime) const
Definition: ERF_InputSoundingData.H:300
Here is the call graph for this function:

◆ setRecordDataInfo()

void ERF::setRecordDataInfo ( int  i,
const std::string &  filename 
)
inlineprivate
1337  {
1338  if (amrex::ParallelDescriptor::IOProcessor())
1339  {
1340  datalog[i] = std::make_unique<std::fstream>();
1341  datalog[i]->open(filename.c_str(),std::ios::out|std::ios::app);
1342  if (!datalog[i]->good()) {
1343  amrex::FileOpenFailed(filename);
1344  }
1345  }
1346  amrex::ParallelDescriptor::Barrier("ERF::setRecordDataInfo");
1347  }

◆ setRecordDerDataInfo()

void ERF::setRecordDerDataInfo ( int  i,
const std::string &  filename 
)
inlineprivate
1350  {
1351  if (amrex::ParallelDescriptor::IOProcessor())
1352  {
1353  der_datalog[i] = std::make_unique<std::fstream>();
1354  der_datalog[i]->open(filename.c_str(),std::ios::out|std::ios::app);
1355  if (!der_datalog[i]->good()) {
1356  amrex::FileOpenFailed(filename);
1357  }
1358  }
1359  amrex::ParallelDescriptor::Barrier("ERF::setRecordDerDataInfo");
1360  }

◆ setRecordEnergyDataInfo()

void ERF::setRecordEnergyDataInfo ( int  i,
const std::string &  filename 
)
inlineprivate
1363  {
1364  if (amrex::ParallelDescriptor::IOProcessor())
1365  {
1366  tot_e_datalog[i] = std::make_unique<std::fstream>();
1367  tot_e_datalog[i]->open(filename.c_str(),std::ios::out|std::ios::app);
1368  if (!tot_e_datalog[i]->good()) {
1369  amrex::FileOpenFailed(filename);
1370  }
1371  }
1372  amrex::ParallelDescriptor::Barrier("ERF::setRecordEnergyDataInfo");
1373  }

◆ setRecordSampleLineInfo()

void ERF::setRecordSampleLineInfo ( int  i,
int  lev,
amrex::IntVect &  cell,
const std::string &  filename 
)
inlineprivate
1393  {
1394  amrex::MultiFab dummy(grids[lev],dmap[lev],1,0);
1395  for (amrex::MFIter mfi(dummy); mfi.isValid(); ++mfi)
1396  {
1397  const amrex::Box& bx = mfi.validbox();
1398  if (bx.contains(cell)) {
1399  samplelinelog[i] = std::make_unique<std::fstream>();
1400  samplelinelog[i]->open(filename.c_str(),std::ios::out|std::ios::app);
1401  if (!samplelinelog[i]->good()) {
1402  amrex::FileOpenFailed(filename);
1403  }
1404  }
1405  }
1406  amrex::ParallelDescriptor::Barrier("ERF::setRecordSampleLineInfo");
1407  }

◆ setRecordSamplePointInfo()

void ERF::setRecordSamplePointInfo ( int  i,
int  lev,
amrex::IntVect &  cell,
const std::string &  filename 
)
inlineprivate
1376  {
1377  amrex::MultiFab dummy(grids[lev],dmap[lev],1,0);
1378  for (amrex::MFIter mfi(dummy); mfi.isValid(); ++mfi)
1379  {
1380  const amrex::Box& bx = mfi.validbox();
1381  if (bx.contains(cell)) {
1382  sampleptlog[i] = std::make_unique<std::fstream>();
1383  sampleptlog[i]->open(filename.c_str(),std::ios::out|std::ios::app);
1384  if (!sampleptlog[i]->good()) {
1385  amrex::FileOpenFailed(filename);
1386  }
1387  }
1388  }
1389  amrex::ParallelDescriptor::Barrier("ERF::setRecordSamplePointInfo");
1390  }

◆ setSpongeRefFromSounding()

void ERF::setSpongeRefFromSounding ( bool  restarting)
private

Set sponge mean profiles from input sounding.

Sets the sponge damping averaged quantities from an externally supplied input sponge data file.

Parameters
[in]restartingBoolean parameter that indicates whether we are currently restarting from a checkpoint file.
66 {
67  // If we are restarting then we haven't read the input_sponge file yet
68  // so we need to read it here
69  // TODO: should we store this information in the checkpoint file instead?
70  if (restarting) {
72  }
73 
74  const Real* z_inp_sponge = input_sponge_data.z_inp_sponge.dataPtr();
75  const Real* U_inp_sponge = input_sponge_data.U_inp_sponge.dataPtr();
76  const Real* V_inp_sponge = input_sponge_data.V_inp_sponge.dataPtr();
77  const int inp_sponge_size = input_sponge_data.size();
78 
79  for (int lev = 0; lev <= finest_level; lev++)
80  {
81  const int khi = geom[lev].Domain().bigEnd()[2];
82  Vector<Real> zcc(khi+1);
83 
84  if (z_phys_cc[lev]) {
85  // use_terrain=1
86  // calculate the damping strength based on the max height at each k
88  } else {
89  const auto *const prob_lo = geom[lev].ProbLo();
90  const auto *const dx = geom[lev].CellSize();
91  for (int k = 0; k <= khi; k++)
92  {
93  zcc[k] = prob_lo[2] + (k+0.5) * dx[2];
94  }
95  }
96 
97  for (int k = 0; k <= khi; k++)
98  {
99  h_sponge_ptrs[lev][Sponge::ubar_sponge][k] = interpolate_1d(z_inp_sponge, U_inp_sponge, zcc[k], inp_sponge_size);
100  h_sponge_ptrs[lev][Sponge::vbar_sponge][k] = interpolate_1d(z_inp_sponge, V_inp_sponge, zcc[k], inp_sponge_size);
101  }
102 
103  // Copy from host version to device version
104  Gpu::copy(Gpu::hostToDevice, h_sponge_ptrs[lev][Sponge::ubar_sponge].begin(), h_sponge_ptrs[lev][Sponge::ubar_sponge].end(),
105  d_sponge_ptrs[lev][Sponge::ubar_sponge].begin());
106  Gpu::copy(Gpu::hostToDevice, h_sponge_ptrs[lev][Sponge::vbar_sponge].begin(), h_sponge_ptrs[lev][Sponge::vbar_sponge].end(),
107  d_sponge_ptrs[lev][Sponge::vbar_sponge].begin());
108  }
109 }
AMREX_FORCE_INLINE void reduce_to_max_per_height(amrex::Vector< amrex::Real > &v, std::unique_ptr< amrex::MultiFab > &mf)
Definition: ERF_ParFunctions.H:8
amrex::Vector< amrex::Real > V_inp_sponge
Definition: ERF_InputSpongeData.H:114
amrex::Vector< amrex::Real > z_inp_sponge
Definition: ERF_InputSpongeData.H:114
amrex::Vector< amrex::Real > U_inp_sponge
Definition: ERF_InputSpongeData.H:114
int size() const
Definition: ERF_InputSpongeData.H:102
Here is the call graph for this function:

◆ solve_with_EB_mlmg()

void ERF::solve_with_EB_mlmg ( int  lev,
amrex::Vector< amrex::MultiFab > &  rhs,
amrex::Vector< amrex::MultiFab > &  p,
amrex::Vector< amrex::Array< amrex::MultiFab, AMREX_SPACEDIM >> &  fluxes 
)

Solve the Poisson equation using EB_enabled MLMG Note that the level may or may not be level 0.

20 {
21  BL_PROFILE("ERF::solve_with_EB_mlmg()");
22 
23  auto const dom_lo = lbound(geom[lev].Domain());
24  auto const dom_hi = ubound(geom[lev].Domain());
25 
26  LPInfo info;
27  // Allow a hidden direction if the domain is one cell wide in any lateral direction
28  if (dom_lo.x == dom_hi.x) {
29  info.setHiddenDirection(0);
30  } else if (dom_lo.y == dom_hi.y) {
31  info.setHiddenDirection(1);
32  }
33 
34  // Make sure the solver only sees the levels over which we are solving
35  Vector<BoxArray> ba_tmp; ba_tmp.push_back(rhs[0].boxArray());
36  Vector<DistributionMapping> dm_tmp; dm_tmp.push_back(rhs[0].DistributionMap());
37  Vector<Geometry> geom_tmp; geom_tmp.push_back(geom[lev]);
38 
39  auto bclo = get_projection_bc(Orientation::low);
40  auto bchi = get_projection_bc(Orientation::high);
41 
42  // amrex::Print() << "BCLO " << bclo[0] << " " << bclo[1] << " " << bclo[2] << std::endl;
43  // amrex::Print() << "BCHI " << bchi[0] << " " << bchi[1] << " " << bchi[2] << std::endl;
44 
45  Real reltol = solverChoice.poisson_reltol;
46  Real abstol = solverChoice.poisson_abstol;
47 
48  // ****************************************************************************
49  // Multigrid solve
50  // ****************************************************************************
51 
52  MLEBABecLap mleb (geom_tmp, ba_tmp, dm_tmp, info, {&EBFactory(lev)});
53 
54  mleb.setMaxOrder(2);
55  mleb.setDomainBC(bclo, bchi);
56  mleb.setLevelBC(0, nullptr);
57 
58  //
59  // This sets A = 0, B = 1 so that
60  // the operator A alpha - b del dot beta grad to b
61  // becomes - del dot beta grad
62  //
63  mleb.setScalars(0.0, 1.0);
64 
65  Array<MultiFab,AMREX_SPACEDIM> bcoef;
66  for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
67  bcoef[idim].define(convert(ba_tmp[0],IntVect::TheDimensionVector(idim)),
68  dm_tmp[0], 1, 0, MFInfo(), EBFactory(lev));
69  bcoef[idim].setVal(-1.0);
70  }
71  mleb.setBCoeffs(0, amrex::GetArrOfConstPtrs(bcoef));
72 
73  MLMG mlmg(mleb);
74 
75  int max_iter = 100;
76  mlmg.setMaxIter(max_iter);
77  mlmg.setVerbose(mg_verbose);
78  mlmg.setBottomVerbose(0);
79 
80  mlmg.solve(GetVecOfPtrs(phi), GetVecOfConstPtrs(rhs), reltol, abstol);
81 
82  mlmg.getFluxes(GetVecOfArrOfPtrs(fluxes));
83 
84  ImposeBCsOnPhi(lev,phi[0]);
85 
86  //
87  // This arises because we solve MINUS del dot beta grad phi = div (rho u)
88  //
89  fluxes[0][0].mult(-1.);
90  fluxes[0][1].mult(-1.);
91  fluxes[0][2].mult(-1.);
92 }
void ImposeBCsOnPhi(int lev, amrex::MultiFab &phi)
Definition: ERF_ImposeBCsOnPhi.cpp:12

◆ solve_with_gmres()

void ERF::solve_with_gmres ( int  lev,
amrex::Vector< amrex::MultiFab > &  rhs,
amrex::Vector< amrex::MultiFab > &  p,
amrex::Vector< amrex::Array< amrex::MultiFab, AMREX_SPACEDIM >> &  fluxes 
)

Solve the Poisson equation using FFT-preconditioned GMRES

14 {
15 #ifdef ERF_USE_FFT
16  BL_PROFILE("ERF::solve_with_gmres()");
17 
18  Real reltol = solverChoice.poisson_reltol;
19  Real abstol = solverChoice.poisson_abstol;
20 
21  amrex::GMRES<MultiFab, TerrainPoisson> gmsolver;
22 
23  TerrainPoisson tp(geom[lev], rhs[0].boxArray(), rhs[0].DistributionMap(), stretched_dz_d[lev],
24  z_phys_nd[lev].get(), domain_bc_type);
25 
26  gmsolver.define(tp);
27 
28  gmsolver.setVerbose(mg_verbose);
29 
30  tp.usePrecond(true);
31 
32  gmsolver.solve(phi[0], rhs[0], reltol, abstol);
33 
34  tp.getFluxes(phi[0], fluxes[0]);
35 #else
36  amrex::ignore_unused(lev, rhs, phi, fluxes);
37 #endif
38 
39  // ****************************************************************************
40  // Impose bc's on pprime
41  // ****************************************************************************
42  ImposeBCsOnPhi(lev, phi[0]);
43 }

◆ solve_with_mlmg()

void ERF::solve_with_mlmg ( int  lev,
amrex::Vector< amrex::MultiFab > &  rhs,
amrex::Vector< amrex::MultiFab > &  p,
amrex::Vector< amrex::Array< amrex::MultiFab, AMREX_SPACEDIM >> &  fluxes 
)

Solve the Poisson equation using MLMG Note that the level may or may not be level 0.

41 {
42  BL_PROFILE("ERF::solve_with_mlmg()");
43 
44  auto const dom_lo = lbound(geom[lev].Domain());
45  auto const dom_hi = ubound(geom[lev].Domain());
46 
47  LPInfo info;
48  // Allow a hidden direction if the domain is one cell wide in any lateral direction
49  if (dom_lo.x == dom_hi.x) {
50  info.setHiddenDirection(0);
51  } else if (dom_lo.y == dom_hi.y) {
52  info.setHiddenDirection(1);
53  }
54 
55  // Make sure the solver only sees the levels over which we are solving
56  Vector<BoxArray> ba_tmp; ba_tmp.push_back(rhs[0].boxArray());
57  Vector<DistributionMapping> dm_tmp; dm_tmp.push_back(rhs[0].DistributionMap());
58  Vector<Geometry> geom_tmp; geom_tmp.push_back(geom[lev]);
59 
60  auto bclo = get_projection_bc(Orientation::low);
61  auto bchi = get_projection_bc(Orientation::high);
62 
63  // amrex::Print() << "BCLO " << bclo[0] << " " << bclo[1] << " " << bclo[2] << std::endl;
64  // amrex::Print() << "BCHI " << bchi[0] << " " << bchi[1] << " " << bchi[2] << std::endl;
65 
66  Real reltol = solverChoice.poisson_reltol;
67  Real abstol = solverChoice.poisson_abstol;
68 
69  // ****************************************************************************
70  // Multigrid solve
71  // ****************************************************************************
72 
73  MLPoisson mlpoisson(geom_tmp, ba_tmp, dm_tmp, info);
74  mlpoisson.setDomainBC(bclo, bchi);
75  if (lev > 0) {
76  mlpoisson.setCoarseFineBC(nullptr, ref_ratio[lev-1], LinOpBCType::Neumann);
77  }
78  mlpoisson.setLevelBC(0, nullptr);
79 
80  // Use low order for outflow at physical boundaries
81  mlpoisson.setMaxOrder(2);
82 
83  MLMG mlmg(mlpoisson);
84  int max_iter = 100;
85  mlmg.setMaxIter(max_iter);
86 
87  mlmg.setVerbose(mg_verbose);
88  mlmg.setBottomVerbose(0);
89 
90  mlmg.solve(GetVecOfPtrs(phi),
91  GetVecOfConstPtrs(rhs),
92  reltol, abstol);
93  mlmg.getFluxes(GetVecOfArrOfPtrs(fluxes));
94 
95  // ****************************************************************************
96  // Impose bc's on pprime
97  // ****************************************************************************
98  ImposeBCsOnPhi(lev, phi[0]);
99 }

◆ sum_derived_quantities()

void ERF::sum_derived_quantities ( amrex::Real  time)
170 {
171  if (verbose <= 0 || NumDerDataLogs() <= 0) return;
172 
173  int lev = 0;
174 
175  AMREX_ALWAYS_ASSERT(lev == 0);
176 
177  // ************************************************************************
178  // WARNING: we are not filling ghost cells other than periodic outside the domain
179  // ************************************************************************
180 
181  MultiFab mf_cc_vel(grids[lev], dmap[lev], AMREX_SPACEDIM, IntVect(1,1,1));
182  mf_cc_vel.setVal(0.); // We just do this to avoid uninitialized values
183 
184  // Average all three components of velocity (on faces) to the cell center
185  average_face_to_cellcenter(mf_cc_vel,0,
186  Array<const MultiFab*,3>{&vars_new[lev][Vars::xvel],
187  &vars_new[lev][Vars::yvel],
188  &vars_new[lev][Vars::zvel]});
189  mf_cc_vel.FillBoundary(geom[lev].periodicity());
190 
191  if (!geom[lev].isPeriodic(0) || !geom[lev].isPeriodic(1) || !geom[lev].isPeriodic(2)) {
192  amrex::Warning("Ghost cells outside non-periodic physical boundaries are not filled -- vel set to 0 there");
193  }
194 
195  MultiFab r_wted_magvelsq(grids[lev], dmap[lev], AMREX_SPACEDIM, IntVect(0,0,0));
196  MultiFab unwted_magvelsq(grids[lev], dmap[lev], AMREX_SPACEDIM, IntVect(0,0,0));
197  MultiFab enstrophysq(grids[lev], dmap[lev], AMREX_SPACEDIM, IntVect(1,1,1));
198 
199 #ifdef _OPENMP
200 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
201 #endif
202  for (MFIter mfi(unwted_magvelsq, TilingIfNotGPU()); mfi.isValid(); ++mfi)
203  {
204  const Box& bx = mfi.tilebox();
205  auto& src_fab = mf_cc_vel[mfi];
206 
207  auto& dest1_fab = unwted_magvelsq[mfi];
208  derived::erf_dermagvelsq(bx, dest1_fab, 0, 1, src_fab, Geom(lev), t_new[0], nullptr, lev);
209 
210  auto& dest2_fab = enstrophysq[mfi];
211  derived::erf_derenstrophysq(bx, dest2_fab, 0, 1, src_fab, Geom(lev), t_new[0], nullptr, lev);
212  }
213 
214  // Copy the MF holding 1/2(u^2 + v^2 + w^2) into the MF that will hold 1/2 rho (u^2 + v^2 + w^2)d
215  MultiFab::Copy(r_wted_magvelsq, unwted_magvelsq, 0, 0, 1, 0);
216 
217  // Multiply the MF holding 1/2(u^2 + v^2 + w^2) by rho to get 1/2 rho (u^2 + v^2 + w^2)
218  MultiFab::Multiply(r_wted_magvelsq, vars_new[lev][Vars::cons], 0, 0, 1, 0);
219 
220  Real unwted_avg = volWgtSumMF(lev, unwted_magvelsq, 0, false);
221  Real r_wted_avg = volWgtSumMF(lev, r_wted_magvelsq, 0, false);
222  Real enstrsq_avg = volWgtSumMF(lev, enstrophysq, 0, false);
223 
224  // Get volume including terrain (consistent with volWgtSumMF routine)
225  MultiFab volume(grids[lev], dmap[lev], 1, 0);
226  auto const& dx = geom[lev].CellSizeArray();
227  Real cell_vol = dx[0]*dx[1]*dx[2];
228  volume.setVal(cell_vol);
229  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
230  MultiFab::Multiply(volume, *detJ_cc[lev], 0, 0, 1, 0);
231  }
232 #ifdef _OPENMP
233 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
234 #endif
235  for (MFIter mfi(volume, TilingIfNotGPU()); mfi.isValid(); ++mfi)
236  {
237  const Box& tbx = mfi.tilebox();
238  auto dst = volume.array(mfi);
239  const auto& mfx = mapfac[lev][MapFacType::m_x]->const_array(mfi);
240  const auto& mfy = mapfac[lev][MapFacType::m_y]->const_array(mfi);
241  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
242  {
243  dst(i,j,k) /= (mfx(i,j,0)*mfy(i,j,0));
244  });
245  }
246  Real vol = volume.sum();
247 
248  unwted_avg /= vol;
249  r_wted_avg /= vol;
250  enstrsq_avg /= vol;
251 
252  const int nfoo = 3;
253  Real foo[nfoo] = {unwted_avg,r_wted_avg,enstrsq_avg};
254 #ifdef AMREX_LAZY
255  Lazy::QueueReduction([=]() mutable {
256 #endif
257  ParallelDescriptor::ReduceRealSum(
258  foo, nfoo, ParallelDescriptor::IOProcessorNumber());
259 
260  if (ParallelDescriptor::IOProcessor()) {
261  int i = 0;
262  unwted_avg = foo[i++];
263  r_wted_avg = foo[i++];
264  enstrsq_avg = foo[i++];
265 
266  std::ostream& data_log_der = DerDataLog(0);
267 
268  if (time == 0.0) {
269  data_log_der << std::setw(datwidth) << " time";
270  data_log_der << std::setw(datwidth) << " ke_den";
271  data_log_der << std::setw(datwidth) << " velsq";
272  data_log_der << std::setw(datwidth) << " enstrophy";
273  data_log_der << std::endl;
274  }
275  data_log_der << std::setw(datwidth) << std::setprecision(timeprecision) << time;
276  data_log_der << std::setw(datwidth) << std::setprecision(datprecision) << unwted_avg;
277  data_log_der << std::setw(datwidth) << std::setprecision(datprecision) << r_wted_avg;
278  data_log_der << std::setw(datwidth) << std::setprecision(datprecision) << enstrsq_avg;
279  data_log_der << std::endl;
280 
281  } // if IOProcessor
282 #ifdef AMREX_LAZY
283  }
284 #endif
285 }
AMREX_FORCE_INLINE std::ostream & DerDataLog(int i)
Definition: ERF.H:1244
AMREX_FORCE_INLINE int NumDerDataLogs() noexcept
Definition: ERF.H:1258
void erf_dermagvelsq(const amrex::Box &bx, amrex::FArrayBox &derfab, int dcomp, int ncomp, const amrex::FArrayBox &datfab, const amrex::Geometry &, amrex::Real, const int *, const int)
Definition: ERF_Derive.cpp:346
void erf_derenstrophysq(const amrex::Box &bx, amrex::FArrayBox &derfab, int dcomp, int ncomp, const amrex::FArrayBox &datfab, const amrex::Geometry &geomdata, amrex::Real, const int *, const int)
Definition: ERF_Derive.cpp:284
Here is the call graph for this function:

◆ sum_energy_quantities()

void ERF::sum_energy_quantities ( amrex::Real  time)
289 {
290  if ( (verbose <= 0) || (tot_e_datalog.size() < 1) ) { return; }
291 
292  int lev = 0;
293 
294  AMREX_ALWAYS_ASSERT(lev == 0);
295 
296  // ************************************************************************
297  // WARNING: we are not filling ghost cells other than periodic outside the domain
298  // ************************************************************************
299 
300  MultiFab mf_cc_vel(grids[lev], dmap[lev], AMREX_SPACEDIM, IntVect(1,1,1));
301  mf_cc_vel.setVal(0.); // We just do this to avoid uninitialized values
302 
303  // Average all three components of velocity (on faces) to the cell center
304  average_face_to_cellcenter(mf_cc_vel,0,
305  Array<const MultiFab*,3>{&vars_new[lev][Vars::xvel],
306  &vars_new[lev][Vars::yvel],
307  &vars_new[lev][Vars::zvel]});
308  mf_cc_vel.FillBoundary(geom[lev].periodicity());
309 
310  if (!geom[lev].isPeriodic(0) || !geom[lev].isPeriodic(1) || !geom[lev].isPeriodic(2)) {
311  amrex::Warning("Ghost cells outside non-periodic physical boundaries are not filled -- vel set to 0 there");
312  }
313 
314  MultiFab tot_mass (grids[lev], dmap[lev], AMREX_SPACEDIM, IntVect(0,0,0));
315  MultiFab tot_energy(grids[lev], dmap[lev], AMREX_SPACEDIM, IntVect(0,0,0));
316 
317  auto const& dx = geom[lev].CellSizeArray();
318  bool is_moist = (solverChoice.moisture_type != MoistureType::None);
319 
320 #ifdef _OPENMP
321 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
322 #endif
323  for (MFIter mfi(tot_mass, TilingIfNotGPU()); mfi.isValid(); ++mfi)
324  {
325  const Box& bx = mfi.tilebox();
326 
327  const Array4<Real>& cc_vel_arr = mf_cc_vel.array(mfi);
328  const Array4<Real>& tot_mass_arr = tot_mass.array(mfi);
329  const Array4<Real>& tot_energy_arr = tot_energy.array(mfi);
330  const Array4<const Real>& cons_arr = vars_new[lev][Vars::cons].const_array(mfi);
331  const Array4<const Real>& z_arr = (z_phys_nd[lev]) ? z_phys_nd[lev]->const_array(mfi) :
332  Array4<const Real>{};
333  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
334  {
335  Real Qv = (is_moist) ? cons_arr(i,j,k,RhoQ1_comp) : 0.0;
336  Real Qc = (is_moist) ? cons_arr(i,j,k,RhoQ2_comp) : 0.0;
337  Real Qt = Qv + Qc;
338  Real Rhod = cons_arr(i,j,k,Rho_comp);
339  Real Rhot = Rhod * (1.0 + Qt);
340  Real Temp = getTgivenRandRTh(Rhod, cons_arr(i,j,k,RhoTheta_comp), Qv);
341  Real TKE = 0.5 * ( cc_vel_arr(i,j,k,0)*cc_vel_arr(i,j,k,0)
342  + cc_vel_arr(i,j,k,1)*cc_vel_arr(i,j,k,1)
343  + cc_vel_arr(i,j,k,2)*cc_vel_arr(i,j,k,2) );
344  Real zval = (z_arr) ? z_arr(i,j,k) : Real(k)*dx[2];
345 
346  Real Cv = Cp_d - R_d;
347  Real Cvv = Cp_v - R_v;
348  Real Cpv = Cp_v;
349 
350  tot_mass_arr(i,j,k) = Rhot;
351  tot_energy_arr(i,j,k) = Rhod * ( (Cv + Cvv*Qv + Cpv*Qc)*Temp - L_v*Qc
352  + (1.0 + Qt)*TKE + (1.0 + Qt)*CONST_GRAV*zval );
353 
354  });
355 
356  }
357 
358  Real tot_mass_avg = volWgtSumMF(lev, tot_mass , 0, false);
359  Real tot_energy_avg = volWgtSumMF(lev, tot_energy, 0, false);
360 
361  // Get volume including terrain (consistent with volWgtSumMF routine)
362  MultiFab volume(grids[lev], dmap[lev], 1, 0);
363  Real cell_vol = dx[0]*dx[1]*dx[2];
364  volume.setVal(cell_vol);
365  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
366  MultiFab::Multiply(volume, *detJ_cc[lev], 0, 0, 1, 0);
367  }
368 #ifdef _OPENMP
369 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
370 #endif
371  for (MFIter mfi(volume, TilingIfNotGPU()); mfi.isValid(); ++mfi)
372  {
373  const Box& tbx = mfi.tilebox();
374  auto dst = volume.array(mfi);
375  const auto& mfx = mapfac[lev][MapFacType::m_x]->const_array(mfi);
376  const auto& mfy = mapfac[lev][MapFacType::m_y]->const_array(mfi);
377  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
378  {
379  dst(i,j,k) /= (mfx(i,j,0)*mfy(i,j,0));
380  });
381  }
382  Real vol = volume.sum();
383 
384  // Divide by the volume
385  tot_mass_avg /= vol;
386  tot_energy_avg /= vol;
387 
388  const int nfoo = 2;
389  Real foo[nfoo] = {tot_mass_avg,tot_energy_avg};
390 #ifdef AMREX_LAZY
391  Lazy::QueueReduction([=]() mutable {
392 #endif
393  ParallelDescriptor::ReduceRealSum(
394  foo, nfoo, ParallelDescriptor::IOProcessorNumber());
395 
396  if (ParallelDescriptor::IOProcessor()) {
397  int i = 0;
398  tot_mass_avg = foo[i++];
399  tot_energy_avg = foo[i++];
400 
401  std::ostream& data_log_energy = *tot_e_datalog[0];
402 
403  if (time == 0.0) {
404  data_log_energy << std::setw(datwidth) << " time";
405  data_log_energy << std::setw(datwidth) << " tot_mass";
406  data_log_energy << std::setw(datwidth) << " tot_energy";
407  data_log_energy << std::endl;
408  }
409  data_log_energy << std::setw(datwidth) << std::setprecision(timeprecision) << time;
410  data_log_energy << std::setw(datwidth) << std::setprecision(datprecision) << tot_mass_avg;
411  data_log_energy << std::setw(datwidth) << std::setprecision(datprecision) << tot_energy_avg;
412  data_log_energy << std::endl;
413 
414  } // if IOProcessor
415 #ifdef AMREX_LAZY
416  }
417 #endif
418 }
constexpr amrex::Real R_v
Definition: ERF_Constants.H:11
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:12
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:21
constexpr amrex::Real Cp_v
Definition: ERF_Constants.H:13
constexpr amrex::Real R_d
Definition: ERF_Constants.H:10
constexpr amrex::Real L_v
Definition: ERF_Constants.H:16
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenRandRTh(const amrex::Real rho, const amrex::Real rhotheta, const amrex::Real qv=0.0)
Definition: ERF_EOS.H:46
Here is the call graph for this function:

◆ sum_integrated_quantities()

void ERF::sum_integrated_quantities ( amrex::Real  time)

Computes the integrated quantities on the grid such as the total scalar and total mass quantities. Prints and writes to output file.

Parameters
timeCurrent time
16 {
17  BL_PROFILE("ERF::sum_integrated_quantities()");
18 
19  if (verbose <= 0)
20  return;
21 
22  // Single level sum
23  Real mass_sl;
24 
25  // Multilevel sums
26  Real mass_ml = 0.0;
27  Real rhth_ml = 0.0;
28  Real scal_ml = 0.0;
29 
30 #if 1
31  mass_sl = volWgtSumMF(0,vars_new[0][Vars::cons],Rho_comp,false);
32  for (int lev = 0; lev <= finest_level; lev++) {
33  mass_ml += volWgtSumMF(lev,vars_new[lev][Vars::cons],Rho_comp,true);
34  }
35 #else
36  for (int lev = 0; lev <= finest_level; lev++) {
37  MultiFab pert_dens(vars_new[lev][Vars::cons].boxArray(),
38  vars_new[lev][Vars::cons].DistributionMap(),
39  1,0);
40  MultiFab r_hse (base_state[lev], make_alias, BaseState::r0_comp, 1);
41  for ( MFIter mfi(pert_dens,TilingIfNotGPU()); mfi.isValid(); ++mfi)
42  {
43  const Box& bx = mfi.tilebox();
44  const Array4<Real >& pert_dens_arr = pert_dens.array(mfi);
45  const Array4<Real const>& S_arr = vars_new[lev][Vars::cons].const_array(mfi);
46  const Array4<Real const>& r0_arr = r_hse.const_array(mfi);
47  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
48  pert_dens_arr(i, j, k, 0) = S_arr(i,j,k,Rho_comp) - r0_arr(i,j,k);
49  });
50  }
51  if (lev == 0) {
52  mass_sl = volWgtSumMF(0,pert_dens,0,false);
53  }
54  mass_ml += volWgtSumMF(lev,pert_dens,0,true);
55  } // lev
56 #endif
57 
58  Real rhth_sl = volWgtSumMF(0,vars_new[0][Vars::cons], RhoTheta_comp,false);
59  Real scal_sl = volWgtSumMF(0,vars_new[0][Vars::cons],RhoScalar_comp,false);
60 
61  for (int lev = 0; lev <= finest_level; lev++) {
62  rhth_ml += volWgtSumMF(lev,vars_new[lev][Vars::cons], RhoTheta_comp,true);
63  scal_ml += volWgtSumMF(lev,vars_new[lev][Vars::cons],RhoScalar_comp,true);
64  }
65 
66  Gpu::HostVector<Real> h_avg_ustar; h_avg_ustar.resize(1);
67  Gpu::HostVector<Real> h_avg_tstar; h_avg_tstar.resize(1);
68  Gpu::HostVector<Real> h_avg_olen; h_avg_olen.resize(1);
69  if ((m_SurfaceLayer != nullptr) && (NumDataLogs() > 0)) {
70  Box domain = geom[0].Domain();
71  int zdir = 2;
72  h_avg_ustar = sumToLine(*m_SurfaceLayer->get_u_star(0),0,1,domain,zdir);
73  h_avg_tstar = sumToLine(*m_SurfaceLayer->get_t_star(0),0,1,domain,zdir);
74  h_avg_olen = sumToLine(*m_SurfaceLayer->get_olen(0) ,0,1,domain,zdir);
75 
76  // Divide by the total number of cells we are averaging over
77  Real area_z = static_cast<Real>(domain.length(0)*domain.length(1));
78  h_avg_ustar[0] /= area_z;
79  h_avg_tstar[0] /= area_z;
80  h_avg_olen[0] /= area_z;
81 
82  } else {
83  h_avg_ustar[0] = 0.;
84  h_avg_tstar[0] = 0.;
85  h_avg_olen[0] = 0.;
86  }
87 
88  const int nfoo = 6;
89  Real foo[nfoo] = {mass_sl,rhth_sl,scal_sl,mass_ml,rhth_ml,scal_ml};
90 #ifdef AMREX_LAZY
91  Lazy::QueueReduction([=]() mutable {
92 #endif
93  ParallelDescriptor::ReduceRealSum(
94  foo, nfoo, ParallelDescriptor::IOProcessorNumber());
95 
96  if (ParallelDescriptor::IOProcessor()) {
97  int i = 0;
98  mass_sl = foo[i++];
99  rhth_sl = foo[i++];
100  scal_sl = foo[i++];
101  mass_ml = foo[i++];
102  rhth_ml = foo[i++];
103  scal_ml = foo[i++];
104 
105  Print() << '\n';
106  Print() << "TIME= " << std::setw(datwidth) << std::setprecision(timeprecision) << std::left << time << '\n';
107  if (finest_level == 0) {
108 #if 1
109  Print() << " MASS = " << mass_sl << '\n';
110 #else
111  Print() << " PERT MASS = " << mass_sl << '\n';
112 #endif
113  Print() << " RHO THETA = " << rhth_sl << '\n';
114  Print() << " RHO SCALAR = " << scal_sl << '\n';
115  } else {
116 #if 1
117  Print() << " MASS SL/ML = " << mass_sl << " " << mass_ml << '\n';
118 #else
119  Print() << " PERT MASS SL/ML = " << mass_sl << " " << mass_ml << '\n';
120 #endif
121  Print() << " RHO THETA SL/ML = " << rhth_sl << " " << rhth_ml << '\n';
122  Print() << " RHO SCALAR SL/ML = " << scal_sl << " " << scal_ml << '\n';
123  }
124 
125  // The first data log only holds scalars
126  if (NumDataLogs() > 0)
127  {
128  int n_d = 0;
129  std::ostream& data_log1 = DataLog(n_d);
130  if (data_log1.good()) {
131  if (time == 0.0) {
132  data_log1 << std::setw(datwidth) << " time";
133  data_log1 << std::setw(datwidth) << " u_star";
134  data_log1 << std::setw(datwidth) << " t_star";
135  data_log1 << std::setw(datwidth) << " olen";
136  data_log1 << std::endl;
137  } // time = 0
138 
139  // Write the quantities at this time
140  data_log1 << std::setw(datwidth) << std::setprecision(timeprecision) << time;
141  data_log1 << std::setw(datwidth) << std::setprecision(datprecision) << h_avg_ustar[0];
142  data_log1 << std::setw(datwidth) << std::setprecision(datprecision) << h_avg_tstar[0];
143  data_log1 << std::setw(datwidth) << std::setprecision(datprecision) << h_avg_olen[0];
144  data_log1 << std::endl;
145  } // if good
146  } // loop over i
147  } // if IOProcessor
148 #ifdef AMREX_LAZY
149  });
150 #endif
151 
152  // This is just an alias for convenience
153  int lev = 0;
154  if (NumSamplePointLogs() > 0 && NumSamplePoints() > 0) {
155  for (int i = 0; i < NumSamplePoints(); ++i)
156  {
157  sample_points(lev, time, SamplePoint(i), vars_new[lev][Vars::cons]);
158  }
159  }
160  if (NumSampleLineLogs() > 0 && NumSampleLines() > 0) {
161  for (int i = 0; i < NumSampleLines(); ++i)
162  {
163  sample_lines(lev, time, SampleLine(i), vars_new[lev][Vars::cons]);
164  }
165  }
166 }
AMREX_FORCE_INLINE int NumSampleLineLogs() noexcept
Definition: ERF.H:1287
AMREX_FORCE_INLINE int NumSamplePointLogs() noexcept
Definition: ERF.H:1273
amrex::IntVect & SampleLine(int i)
Definition: ERF.H:1306
AMREX_FORCE_INLINE int NumSamplePoints() noexcept
Definition: ERF.H:1300
AMREX_FORCE_INLINE int NumSampleLines() noexcept
Definition: ERF.H:1313
amrex::IntVect & SamplePoint(int i)
Definition: ERF.H:1293
void sample_points(int lev, amrex::Real time, amrex::IntVect cell, amrex::MultiFab &mf)
Definition: ERF_WriteScalarProfiles.cpp:497
AMREX_FORCE_INLINE std::ostream & DataLog(int i)
Definition: ERF.H:1237
AMREX_FORCE_INLINE int NumDataLogs() noexcept
Definition: ERF.H:1251
void sample_lines(int lev, amrex::Real time, amrex::IntVect cell, amrex::MultiFab &mf)
Definition: ERF_WriteScalarProfiles.cpp:533

◆ timeStep()

void ERF::timeStep ( int  lev,
amrex::Real  time,
int  iteration 
)
private

Function that coordinates the evolution across levels – this calls Advance to do the actual advance at this level, then recursively calls itself at finer levels

Parameters
[in]levlevel of refinement (coarsest level is 0)
[in]timestart time for time advance
[in]iterationtime step counter
18 {
19  //
20  // We need to FillPatch the coarse level before assessing whether to regrid
21  // We have not done the swap yet so we fill the "new" which will become the "old"
22  //
23  MultiFab& S_new = vars_new[lev][Vars::cons];
24  MultiFab& U_new = vars_new[lev][Vars::xvel];
25  MultiFab& V_new = vars_new[lev][Vars::yvel];
26  MultiFab& W_new = vars_new[lev][Vars::zvel];
27 
28 #ifdef ERF_USE_NETCDF
29  //
30  // Since we now only read in a subset of the time slices in wrfbdy we need to check
31  // whether it's time to read in more
32  //
33  if (solverChoice.use_real_bcs && (lev==0)) {
34  Real dT = bdy_time_interval;
35 
36  Real time_since_start_old = time - start_bdy_time;
37  int n_time_old = static_cast<int>( time_since_start_old / dT);
38 
39  Real time_since_start_new = time + dt[lev] - start_bdy_time;
40  int n_time_new = static_cast<int>( time_since_start_new / dT);
41 
42  int ntimes = bdy_data_xlo.size();
43  for (int itime = 0; itime < ntimes; itime++)
44  {
45  //if (bdy_data_xlo[itime].size() > 0) {
46  // amrex::Print() << "HAVE DATA AT TIME " << itime << std::endl;
47  //} else {
48  // amrex::Print() << " NO DATA AT TIME " << itime << std::endl;
49  //}
50 
51  bool clear_itime = (itime < n_time_old);
52 
53  if (clear_itime && bdy_data_xlo[itime].size() > 0) {
54  bdy_data_xlo[itime].clear();
55  //amrex::Print() << "CLEAR DATA AT TIME " << itime << std::endl;
56  }
57 
58  bool need_itime = (itime >= n_time_old && itime <= n_time_new+1);
59  //if (need_itime) amrex::Print() << "NEED DATA AT TIME " << itime << std::endl;
60 
61  if (bdy_data_xlo[itime].size() == 0 && need_itime) {
62  read_from_wrfbdy(itime,nc_bdy_file,geom[0].Domain(),
63  bdy_data_xlo,bdy_data_xhi,bdy_data_ylo,bdy_data_yhi,
64  real_width);
65 
66  bool use_moist = (solverChoice.moisture_type != MoistureType::None);
67  convert_all_wrfbdy_data(itime, geom[0].Domain(), bdy_data_xlo, bdy_data_xhi, bdy_data_ylo, bdy_data_yhi,
68  *mf_MUB[lev], *mf_C1H[lev], *mf_C2H[lev],
70  geom[lev], use_moist);
71  }
72  } // itime
73  } // use_real_bcs && lev == 0
74 #endif
75 
76  //
77  // NOTE: the momenta here are not fillpatched (they are only used as scratch space)
78  //
79  if (lev == 0) {
80  FillPatch(lev, time, {&S_new, &U_new, &V_new, &W_new});
81  } else if (lev < finest_level) {
82  FillPatch(lev, time, {&S_new, &U_new, &V_new, &W_new},
83  {&S_new, &rU_new[lev], &rV_new[lev], &rW_new[lev]},
84  base_state[lev], base_state[lev]);
85  }
86 
87  if (regrid_int > 0) // We may need to regrid
88  {
89  // help keep track of whether a level was already regridded
90  // from a coarser level call to regrid
91  static Vector<int> last_regrid_step(max_level+1, 0);
92 
93  // regrid changes level "lev+1" so we don't regrid on max_level
94  // also make sure we don't regrid fine levels again if
95  // it was taken care of during a coarser regrid
96  if (lev < max_level)
97  {
98  if ( (istep[lev] % regrid_int == 0) && (istep[lev] > last_regrid_step[lev]) )
99  {
100  // regrid could add newly refine levels (if finest_level < max_level)
101  // so we save the previous finest level index
102  int old_finest = finest_level;
103 
104  regrid(lev, time);
105 
106 #ifdef ERF_USE_PARTICLES
107  if (finest_level != old_finest) {
108  particleData.Redistribute();
109  }
110 #endif
111 
112  // mark that we have regridded this level already
113  for (int k = lev; k <= finest_level; ++k) {
114  last_regrid_step[k] = istep[k];
115  }
116 
117  // if there are newly created levels, set the time step
118  for (int k = old_finest+1; k <= finest_level; ++k) {
119  dt[k] = dt[k-1] / MaxRefRatio(k-1);
120  }
121  } // if
122  } // lev
123  }
124 
125  // Update what we call "old" and "new" time
126  t_old[lev] = t_new[lev];
127  t_new[lev] += dt[lev];
128 
129  if (Verbose()) {
130  amrex::Print() << "[Level " << lev << " step " << istep[lev]+1 << "] ";
131  amrex::Print() << std::setprecision(timeprecision)
132  << "ADVANCE from time = " << t_old[lev] << " to " << t_new[lev]
133  << " with dt = " << dt[lev] << std::endl;
134  }
135 
136 #ifdef ERF_USE_WW3_COUPLING
137  amrex::Print() << " About to call send_to_ww3 from ERF_Timestep" << std::endl;
138  send_to_ww3(lev);
139  amrex::Print() << " About to call read_waves from ERF_Timestep" << std::endl;
140  read_waves(lev);
141  //send_to_ww3(lev);
142  //read_waves(lev);
143  //send_to_ww3(lev);
144 #endif
145 
146  // Advance a single level for a single time step
147  Advance(lev, time, dt[lev], istep[lev], nsubsteps[lev]);
148 
149  ++istep[lev];
150 
151  if (Verbose()) {
152  amrex::Print() << "[Level " << lev << " step " << istep[lev] << "] ";
153  amrex::Print() << "Advanced " << CountCells(lev) << " cells" << std::endl;
154  }
155 
156  if (lev < finest_level)
157  {
158  // recursive call for next-finer level
159  for (int i = 1; i <= nsubsteps[lev+1]; ++i)
160  {
161  Real strt_time_for_fine = time + (i-1)*dt[lev+1];
162  timeStep(lev+1, strt_time_for_fine, i);
163  }
164  }
165 
166  if (verbose && lev == 0 && solverChoice.moisture_type != MoistureType::None) {
167  amrex::Print() << "Cloud fraction " << time << " " << cloud_fraction(time) << std::endl;
168  }
169 }
amrex::Real cloud_fraction(amrex::Real time)
Definition: ERF_WriteScalarProfiles.cpp:421
void Advance(int lev, amrex::Real time, amrex::Real dt_lev, int iteration, int ncycle)
Definition: ERF_Advance.cpp:23

◆ turbPert_amplitude()

void ERF::turbPert_amplitude ( const int  lev)
private
33 {
34  // Accessing data
35  auto& lev_new = vars_new[lev];
36 
37  // Creating local data
38  int ncons = lev_new[Vars::cons].nComp();
39  MultiFab cons_data(lev_new[Vars::cons], make_alias, 0, ncons);
40 
41  // Defining BoxArray type
42  auto m_ixtype = cons_data.boxArray().ixType();
43 
44 #ifdef _OPENMP
45 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
46 #endif
47  for (MFIter mfi(lev_new[Vars::cons], TileNoZ()); mfi.isValid(); ++mfi) {
48  const Box &bx = mfi.validbox();
49  const auto &cons_pert_arr = cons_data.array(mfi); // Address of perturbation array
50  const amrex::Array4<const amrex::Real> &pert_cell = turbPert.pb_cell[lev].array(mfi); // per-cell perturbation stored in structure
51 
52  turbPert.apply_tpi(lev, bx, RhoTheta_comp, m_ixtype, cons_pert_arr, pert_cell);
53  } // mfi
54 }
Here is the call graph for this function:

◆ turbPert_update()

void ERF::turbPert_update ( const int  lev,
const amrex::Real  dt 
)
private
13 {
14  // Accessing data
15  auto& lev_new = vars_new[lev];
16 
17  // Create aliases to state data to pass to calc_tpi_update
18  int ncons = lev_new[Vars::cons].nComp();
19  MultiFab cons_data(lev_new[Vars::cons], make_alias, 0, ncons);
20  MultiFab xvel_data(lev_new[Vars::xvel], make_alias, 0, 1);
21  MultiFab yvel_data(lev_new[Vars::yvel], make_alias, 0, 1);
22 
23  // Computing perturbation update time
24  turbPert.calc_tpi_update(lev, local_dt, xvel_data, yvel_data, cons_data);
25 
26  Print() << "Successfully initialized turbulent perturbation update time and amplitude with type: "<< turbPert.pt_type <<"\n";
27 }
int pt_type
Definition: ERF_TurbPertStruct.H:638

◆ update_diffusive_arrays()

void ERF::update_diffusive_arrays ( int  lev,
const amrex::BoxArray &  ba,
const amrex::DistributionMapping &  dm 
)
private
425 {
426  // ********************************************************************************************
427  // Diffusive terms
428  // ********************************************************************************************
429  bool l_use_terrain = (SolverChoice::terrain_type != TerrainType::None);
430  bool l_use_kturb = solverChoice.turbChoice[lev].use_kturb;
431  bool l_use_diff = ( (solverChoice.diffChoice.molec_diff_type != MolecDiffType::None) ||
432  l_use_kturb );
433  bool l_need_SmnSmn = solverChoice.turbChoice[lev].use_keqn;
434  bool l_use_moist = ( solverChoice.moisture_type != MoistureType::None );
435  bool l_rotate = ( solverChoice.use_rotate_surface_flux );
436 
437  BoxArray ba12 = convert(ba, IntVect(1,1,0));
438  BoxArray ba13 = convert(ba, IntVect(1,0,1));
439  BoxArray ba23 = convert(ba, IntVect(0,1,1));
440 
441  Tau[lev].resize(9);
442 
443  if (l_use_diff) {
444  //
445  // NOTE: We require ghost cells in the vertical when allowing grids that don't
446  // cover the entire vertical extent of the domain at this level
447  //
448  for (int i = 0; i < 3; i++) {
449  Tau[lev][i] = std::make_unique<MultiFab>( ba , dm, 1, IntVect(1,1,1) );
450  }
451  Tau[lev][TauType::tau12] = std::make_unique<MultiFab>( ba12, dm, 1, IntVect(1,1,1) );
452  Tau[lev][TauType::tau13] = std::make_unique<MultiFab>( ba13, dm, 1, IntVect(1,1,1) );
453  Tau[lev][TauType::tau23] = std::make_unique<MultiFab>( ba23, dm, 1, IntVect(1,1,1) );
454  if (l_use_terrain) {
455  Tau[lev][TauType::tau21] = std::make_unique<MultiFab>( ba12, dm, 1, IntVect(1,1,1) );
456  Tau[lev][TauType::tau31] = std::make_unique<MultiFab>( ba13, dm, 1, IntVect(1,1,1) );
457  Tau[lev][TauType::tau32] = std::make_unique<MultiFab>( ba23, dm, 1, IntVect(1,1,1) );
458  } else {
459  Tau[lev][TauType::tau21] = nullptr;
460  Tau[lev][TauType::tau31] = nullptr;
461  Tau[lev][TauType::tau32] = nullptr;
462  }
463  SFS_hfx1_lev[lev] = std::make_unique<MultiFab>( convert(ba,IntVect(1,0,0)), dm, 1, IntVect(1,1,1) );
464  SFS_hfx2_lev[lev] = std::make_unique<MultiFab>( convert(ba,IntVect(0,1,0)), dm, 1, IntVect(1,1,1) );
465  SFS_hfx3_lev[lev] = std::make_unique<MultiFab>( convert(ba,IntVect(0,0,1)), dm, 1, IntVect(1,1,1) );
466  SFS_diss_lev[lev] = std::make_unique<MultiFab>( ba , dm, 1, IntVect(1,1,1) );
467  SFS_hfx1_lev[lev]->setVal(0.);
468  SFS_hfx2_lev[lev]->setVal(0.);
469  SFS_hfx3_lev[lev]->setVal(0.);
470  SFS_diss_lev[lev]->setVal(0.);
471  if (l_use_moist) {
472  SFS_q1fx3_lev[lev] = std::make_unique<MultiFab>( convert(ba,IntVect(0,0,1)), dm, 1, IntVect(1,1,1) );
473  SFS_q2fx3_lev[lev] = std::make_unique<MultiFab>( convert(ba,IntVect(0,0,1)), dm, 1, IntVect(1,1,1) );
474  SFS_q1fx3_lev[lev]->setVal(0.0);
475  SFS_q2fx3_lev[lev]->setVal(0.0);
476  if (l_rotate) {
477  SFS_q1fx1_lev[lev] = std::make_unique<MultiFab>( convert(ba,IntVect(1,0,0)), dm, 1, IntVect(1,1,1) );
478  SFS_q1fx2_lev[lev] = std::make_unique<MultiFab>( convert(ba,IntVect(0,1,0)), dm, 1, IntVect(1,1,1) );
479  SFS_q1fx1_lev[lev]->setVal(0.0);
480  SFS_q1fx2_lev[lev]->setVal(0.0);
481  } else {
482  SFS_q1fx1_lev[lev] = nullptr;
483  SFS_q1fx2_lev[lev] = nullptr;
484  }
485  } else {
486  SFS_q1fx1_lev[lev] = nullptr;
487  SFS_q1fx2_lev[lev] = nullptr;
488  SFS_q1fx3_lev[lev] = nullptr;
489  SFS_q2fx3_lev[lev] = nullptr;
490  }
491  } else {
492  for (int i = 0; i < 9; i++) {
493  Tau[lev][i] = nullptr;
494  }
495  SFS_hfx1_lev[lev] = nullptr; SFS_hfx2_lev[lev] = nullptr; SFS_hfx3_lev[lev] = nullptr;
496  SFS_diss_lev[lev] = nullptr;
497  }
498 
499  if (l_use_kturb) {
500  eddyDiffs_lev[lev] = std::make_unique<MultiFab>(ba, dm, EddyDiff::NumDiffs, 2);
501  eddyDiffs_lev[lev]->setVal(0.0);
502  if(l_need_SmnSmn) {
503  SmnSmn_lev[lev] = std::make_unique<MultiFab>( ba, dm, 1, 0 );
504  } else {
505  SmnSmn_lev[lev] = nullptr;
506  }
507  } else {
508  eddyDiffs_lev[lev] = nullptr;
509  SmnSmn_lev[lev] = nullptr;
510  }
511 }
@ NumDiffs
Definition: ERF_IndexDefines.H:181

◆ update_terrain_arrays()

void ERF::update_terrain_arrays ( int  lev)
620 {
621  if (SolverChoice::mesh_type == MeshType::StretchedDz ||
622  SolverChoice::mesh_type == MeshType::VariableDz) {
623  make_J(geom[lev],*z_phys_nd[lev],*detJ_cc[lev]);
624  make_areas(geom[lev],*z_phys_nd[lev],*ax[lev],*ay[lev],*az[lev]);
625  make_zcc(geom[lev],*z_phys_nd[lev],*z_phys_cc[lev]);
626  }
627 }
void make_areas(const Geometry &geom, MultiFab &z_phys_nd, MultiFab &ax, MultiFab &ay, MultiFab &az)
Definition: ERF_TerrainMetrics.cpp:558
void make_J(const Geometry &geom, MultiFab &z_phys_nd, MultiFab &detJ_cc)
Definition: ERF_TerrainMetrics.cpp:520
Here is the call graph for this function:

◆ volWgtSumMF()

Real ERF::volWgtSumMF ( int  lev,
const amrex::MultiFab &  mf,
int  comp,
bool  finemask 
)

Utility function for computing a volume weighted sum of MultiFab data for a single component

Parameters
levCurrent level
mfMultiFab on which we do the volume weighted sum
compIndex of the component we want to sum
localBoolean sets whether or not to reduce the sum over the domain (false) or compute sums local to each MPI rank (true)
finemaskIf a finer level is available, determines whether we mask fine data
625 {
626  BL_PROFILE("ERF::volWgtSumMF()");
627 
628  Real sum = 0.0;
629  MultiFab tmp(grids[lev], dmap[lev], 1, 0);
630  MultiFab::Copy(tmp, mf, comp, 0, 1, 0);
631 
632  // The quantity that is conserved is not (rho S), but rather (rho S / m^2) where
633  // m is the map scale factor at cell centers
634  for (MFIter mfi(tmp, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
635  const Box& bx = mfi.tilebox();
636  const auto dst = tmp.array(mfi);
637  const auto& mfx = mapfac[lev][MapFacType::m_x]->const_array(mfi);
638  const auto& mfy = mapfac[lev][MapFacType::m_y]->const_array(mfi);
639  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
640  {
641  dst(i,j,k) /= (mfx(i,j,0)*mfy(i,j,0));
642  });
643  } // mfi
644 
645  if (lev < finest_level && finemask) {
646  const MultiFab& mask = build_fine_mask(lev+1);
647  MultiFab::Multiply(tmp, mask, 0, 0, 1, 0);
648  }
649 
650  // Get volume including terrain (consistent with volWgtSumMF routine)
651  MultiFab volume(grids[lev], dmap[lev], 1, 0);
652  auto const& dx = geom[lev].CellSizeArray();
653  Real cell_vol = dx[0]*dx[1]*dx[2];
654  volume.setVal(cell_vol);
655  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
656  MultiFab::Multiply(volume, *detJ_cc[lev], 0, 0, 1, 0);
657  }
658 #ifdef _OPENMP
659 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
660 #endif
661  for (MFIter mfi(volume, TilingIfNotGPU()); mfi.isValid(); ++mfi)
662  {
663  const Box& tbx = mfi.tilebox();
664  auto dst = volume.array(mfi);
665  const auto& mfx = mapfac[lev][MapFacType::m_x]->const_array(mfi);
666  const auto& mfy = mapfac[lev][MapFacType::m_y]->const_array(mfi);
667  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
668  {
669  dst(i,j,k) /= (mfx(i,j,0)*mfy(i,j,0));
670  });
671  }
672 
673  //
674  // Note that when we send in local = true, NO ParallelAllReduce::Sum
675  // is called inside the Dot product -- we will do that before we print
676  //
677  bool local = true;
678  sum = MultiFab::Dot(tmp, 0, volume, 0, 1, 0, local);
679 
680  return sum;
681 }
amrex::MultiFab & build_fine_mask(int lev)
Definition: ERF_WriteScalarProfiles.cpp:691

◆ write_1D_profiles()

void ERF::write_1D_profiles ( amrex::Real  time)

Writes 1-dimensional averaged quantities as profiles to output log files at the given time.

Parameters
timeCurrent time
18 {
19  BL_PROFILE("ERF::write_1D_profiles()");
20 
21  if (NumDataLogs() > 1)
22  {
23  // Define the 1d arrays we will need
24  Gpu::HostVector<Real> h_avg_u, h_avg_v, h_avg_w;
25  Gpu::HostVector<Real> h_avg_rho, h_avg_th, h_avg_ksgs, h_avg_Kmv, h_avg_Khv;
26  Gpu::HostVector<Real> h_avg_qv, h_avg_qc, h_avg_qr, h_avg_wqv, h_avg_wqc, h_avg_wqr, h_avg_qi, h_avg_qs, h_avg_qg;
27  Gpu::HostVector<Real> h_avg_wthv;
28  Gpu::HostVector<Real> h_avg_uth, h_avg_vth, h_avg_wth, h_avg_thth;
29  Gpu::HostVector<Real> h_avg_uu, h_avg_uv, h_avg_uw, h_avg_vv, h_avg_vw, h_avg_ww;
30  Gpu::HostVector<Real> h_avg_uiuiu, h_avg_uiuiv, h_avg_uiuiw;
31  Gpu::HostVector<Real> h_avg_p, h_avg_pu, h_avg_pv, h_avg_pw;
32  Gpu::HostVector<Real> h_avg_tau11, h_avg_tau12, h_avg_tau13, h_avg_tau22, h_avg_tau23, h_avg_tau33;
33  Gpu::HostVector<Real> h_avg_sgshfx, h_avg_sgsq1fx, h_avg_sgsq2fx, h_avg_sgsdiss; // only output tau_{theta,w} and epsilon for now
34 
35  if (NumDataLogs() > 1) {
37  h_avg_u, h_avg_v, h_avg_w,
38  h_avg_rho, h_avg_th, h_avg_ksgs,
39  h_avg_Kmv, h_avg_Khv,
40  h_avg_qv, h_avg_qc, h_avg_qr,
41  h_avg_wqv, h_avg_wqc, h_avg_wqr,
42  h_avg_qi, h_avg_qs, h_avg_qg,
43  h_avg_uu, h_avg_uv, h_avg_uw, h_avg_vv, h_avg_vw, h_avg_ww,
44  h_avg_uth, h_avg_vth, h_avg_wth, h_avg_thth,
45  h_avg_uiuiu, h_avg_uiuiv, h_avg_uiuiw,
46  h_avg_p, h_avg_pu, h_avg_pv, h_avg_pw,
47  h_avg_wthv);
48  }
49 
50  if (NumDataLogs() > 3 && time > 0.) {
51  derive_stress_profiles(h_avg_tau11, h_avg_tau12, h_avg_tau13,
52  h_avg_tau22, h_avg_tau23, h_avg_tau33,
53  h_avg_sgshfx, h_avg_sgsq1fx, h_avg_sgsq2fx,
54  h_avg_sgsdiss);
55  }
56 
57  int hu_size = h_avg_u.size();
58 
59  auto const& dx = geom[0].CellSizeArray();
60  if (ParallelDescriptor::IOProcessor()) {
61  if (NumDataLogs() > 1) {
62  std::ostream& data_log1 = DataLog(1);
63  if (data_log1.good()) {
64  // Write the quantities at this time
65  for (int k = 0; k < hu_size; k++) {
66  Real z;
67  if (zlevels_stag[0].size() > 1) {
68  z = 0.5 * (zlevels_stag[0][k] + zlevels_stag[0][k+1]);
69  } else {
70  z = (k + 0.5)* dx[2];
71  }
72  data_log1 << std::setw(datwidth) << std::setprecision(timeprecision) << time << " "
73  << std::setw(datwidth) << std::setprecision(datprecision) << z << " "
74  << h_avg_u[k] << " " << h_avg_v[k] << " " << h_avg_w[k] << " "
75  << h_avg_rho[k] << " " << h_avg_th[k] << " " << h_avg_ksgs[k] << " "
76  << h_avg_Kmv[k] << " " << h_avg_Khv[k] << " "
77  << h_avg_qv[k] << " " << h_avg_qc[k] << " " << h_avg_qr[k] << " "
78  << h_avg_qi[k] << " " << h_avg_qs[k] << " " << h_avg_qg[k]
79  << std::endl;
80  } // loop over z
81  } // if good
82  } // NumDataLogs
83 
84  if (NumDataLogs() > 2) {
85  std::ostream& data_log2 = DataLog(2);
86  if (data_log2.good()) {
87  // Write the perturbational quantities at this time
88  for (int k = 0; k < hu_size; k++) {
89  Real z;
90  if (zlevels_stag[0].size() > 1) {
91  z = 0.5 * (zlevels_stag[0][k] + zlevels_stag[0][k+1]);
92  } else {
93  z = (k + 0.5)* dx[2];
94  }
95  Real thv = h_avg_th[k] * (1 + 0.61*h_avg_qv[k] - h_avg_qc[k] - h_avg_qr[k]);
96  data_log2 << std::setw(datwidth) << std::setprecision(timeprecision) << time << " "
97  << std::setw(datwidth) << std::setprecision(datprecision) << z << " "
98  << h_avg_uu[k] - h_avg_u[k]*h_avg_u[k] << " "
99  << h_avg_uv[k] - h_avg_u[k]*h_avg_v[k] << " "
100  << h_avg_uw[k] - h_avg_u[k]*h_avg_w[k] << " "
101  << h_avg_vv[k] - h_avg_v[k]*h_avg_v[k] << " "
102  << h_avg_vw[k] - h_avg_v[k]*h_avg_w[k] << " "
103  << h_avg_ww[k] - h_avg_w[k]*h_avg_w[k] << " "
104  << h_avg_uth[k] - h_avg_u[k]*h_avg_th[k] << " "
105  << h_avg_vth[k] - h_avg_v[k]*h_avg_th[k] << " "
106  << h_avg_wth[k] - h_avg_w[k]*h_avg_th[k] << " "
107  << h_avg_thth[k] - h_avg_th[k]*h_avg_th[k] << " "
108  // Note: <u'_i u'_i u'_j> = <u_i u_i u_j>
109  // - <u_i u_i> * <u_j>
110  // - 2*<u_i> * <u_i u_j>
111  // + 2*<u_i>*<u_i> * <u_j>
112  << h_avg_uiuiu[k]
113  - (h_avg_uu[k] + h_avg_vv[k] + h_avg_ww[k])*h_avg_u[k]
114  - 2*(h_avg_u[k]*h_avg_uu[k] + h_avg_v[k]*h_avg_uv[k] + h_avg_w[k]*h_avg_uw[k])
115  + 2*(h_avg_u[k]*h_avg_u[k] + h_avg_v[k]*h_avg_v[k] + h_avg_w[k]*h_avg_w[k])*h_avg_u[k]
116  << " " // (u'_i u'_i)u'
117  << h_avg_uiuiv[k]
118  - (h_avg_uu[k] + h_avg_vv[k] + h_avg_ww[k])*h_avg_v[k]
119  - 2*(h_avg_u[k]*h_avg_uv[k] + h_avg_v[k]*h_avg_vv[k] + h_avg_w[k]*h_avg_vw[k])
120  + 2*(h_avg_u[k]*h_avg_u[k] + h_avg_v[k]*h_avg_v[k] + h_avg_w[k]*h_avg_w[k])*h_avg_v[k]
121  << " " // (u'_i u'_i)v'
122  << h_avg_uiuiw[k]
123  - (h_avg_uu[k] + h_avg_vv[k] + h_avg_ww[k])*h_avg_w[k]
124  - 2*(h_avg_u[k]*h_avg_uw[k] + h_avg_v[k]*h_avg_vw[k] + h_avg_w[k]*h_avg_ww[k])
125  + 2*(h_avg_u[k]*h_avg_u[k] + h_avg_v[k]*h_avg_v[k] + h_avg_w[k]*h_avg_w[k])*h_avg_w[k]
126  << " " // (u'_i u'_i)w'
127  << h_avg_pu[k] - h_avg_p[k]*h_avg_u[k] << " "
128  << h_avg_pv[k] - h_avg_p[k]*h_avg_v[k] << " "
129  << h_avg_pw[k] - h_avg_p[k]*h_avg_w[k] << " "
130  << h_avg_wqv[k] - h_avg_qv[k]*h_avg_w[k] << " "
131  << h_avg_wqc[k] - h_avg_qc[k]*h_avg_w[k] << " "
132  << h_avg_wqr[k] - h_avg_qr[k]*h_avg_w[k] << " "
133  << h_avg_wthv[k] - h_avg_w[k]*thv
134  << std::endl;
135  } // loop over z
136  } // if good
137  } // NumDataLogs
138 
139  if (NumDataLogs() > 3 && time > 0.) {
140  std::ostream& data_log3 = DataLog(3);
141  if (data_log3.good()) {
142  // Write the average stresses
143  for (int k = 0; k < hu_size; k++) {
144  Real z;
145  if (zlevels_stag[0].size() > 1) {
146  z = 0.5 * (zlevels_stag[0][k] + zlevels_stag[0][k+1]);
147  } else {
148  z = (k + 0.5)* dx[2];
149  }
150  data_log3 << std::setw(datwidth) << std::setprecision(timeprecision) << time << " "
151  << std::setw(datwidth) << std::setprecision(datprecision) << z << " "
152  << h_avg_tau11[k] << " " << h_avg_tau12[k] << " " << h_avg_tau13[k] << " "
153  << h_avg_tau22[k] << " " << h_avg_tau23[k] << " " << h_avg_tau33[k] << " "
154  << h_avg_sgshfx[k] << " "
155  << h_avg_sgsq1fx[k] << " " << h_avg_sgsq2fx[k] << " "
156  << h_avg_sgsdiss[k]
157  << std::endl;
158  } // loop over z
159  } // if good
160  } // if (NumDataLogs() > 3)
161  } // if IOProcessor
162  } // if (NumDataLogs() > 1)
163 }
void derive_diag_profiles(amrex::Real time, amrex::Gpu::HostVector< amrex::Real > &h_avg_u, amrex::Gpu::HostVector< amrex::Real > &h_avg_v, amrex::Gpu::HostVector< amrex::Real > &h_avg_w, amrex::Gpu::HostVector< amrex::Real > &h_avg_rho, amrex::Gpu::HostVector< amrex::Real > &h_avg_th, amrex::Gpu::HostVector< amrex::Real > &h_avg_ksgs, amrex::Gpu::HostVector< amrex::Real > &h_avg_Kmv, amrex::Gpu::HostVector< amrex::Real > &h_avg_Khv, amrex::Gpu::HostVector< amrex::Real > &h_avg_qv, amrex::Gpu::HostVector< amrex::Real > &h_avg_qc, amrex::Gpu::HostVector< amrex::Real > &h_avg_qr, amrex::Gpu::HostVector< amrex::Real > &h_avg_wqv, amrex::Gpu::HostVector< amrex::Real > &h_avg_wqc, amrex::Gpu::HostVector< amrex::Real > &h_avg_wqr, amrex::Gpu::HostVector< amrex::Real > &h_avg_qi, amrex::Gpu::HostVector< amrex::Real > &h_avg_qs, amrex::Gpu::HostVector< amrex::Real > &h_avg_qg, amrex::Gpu::HostVector< amrex::Real > &h_avg_uu, amrex::Gpu::HostVector< amrex::Real > &h_avg_uv, amrex::Gpu::HostVector< amrex::Real > &h_avg_uw, amrex::Gpu::HostVector< amrex::Real > &h_avg_vv, amrex::Gpu::HostVector< amrex::Real > &h_avg_vw, amrex::Gpu::HostVector< amrex::Real > &h_avg_ww, amrex::Gpu::HostVector< amrex::Real > &h_avg_uth, amrex::Gpu::HostVector< amrex::Real > &h_avg_vth, amrex::Gpu::HostVector< amrex::Real > &h_avg_wth, amrex::Gpu::HostVector< amrex::Real > &h_avg_thth, amrex::Gpu::HostVector< amrex::Real > &h_avg_ku, amrex::Gpu::HostVector< amrex::Real > &h_avg_kv, amrex::Gpu::HostVector< amrex::Real > &h_avg_kw, amrex::Gpu::HostVector< amrex::Real > &h_avg_p, amrex::Gpu::HostVector< amrex::Real > &h_avg_pu, amrex::Gpu::HostVector< amrex::Real > &h_avg_pv, amrex::Gpu::HostVector< amrex::Real > &h_avg_pw, amrex::Gpu::HostVector< amrex::Real > &h_avg_wthv)
Definition: ERF_Write1DProfiles.cpp:190
void derive_stress_profiles(amrex::Gpu::HostVector< amrex::Real > &h_avg_tau11, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau12, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau13, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau22, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau23, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau33, amrex::Gpu::HostVector< amrex::Real > &h_avg_hfx3, amrex::Gpu::HostVector< amrex::Real > &h_avg_q1fx3, amrex::Gpu::HostVector< amrex::Real > &h_avg_q2fx3, amrex::Gpu::HostVector< amrex::Real > &h_avg_diss)
Definition: ERF_Write1DProfiles.cpp:475

◆ write_1D_profiles_stag()

void ERF::write_1D_profiles_stag ( amrex::Real  time)

Writes 1-dimensional averaged quantities as profiles to output log files at the given time.

Quantities are output at their native grid locations. Therefore, w and associated flux quantities <(•)'w'>, tau13, and tau23 (where '•' includes u, v, p, theta, ...) will be output at staggered heights (i.e., coincident with z faces) rather than cell-center heights to avoid performing additional averaging. Unstaggered (i.e., cell-centered) quantities are output alongside staggered quantities at the lower cell faces in the log file; these quantities will have a zero value at the big end, corresponding to k=Nz+1.

The structure of file should follow ERF_Write1DProfiles.cpp

Parameters
timeCurrent time
26 {
27  BL_PROFILE("ERF::write_1D_profiles()");
28 
29  if (NumDataLogs() > 1)
30  {
31  // Define the 1d arrays we will need
32  Gpu::HostVector<Real> h_avg_u, h_avg_v, h_avg_w;
33  Gpu::HostVector<Real> h_avg_rho, h_avg_th, h_avg_ksgs, h_avg_Kmv, h_avg_Khv;
34  Gpu::HostVector<Real> h_avg_qv, h_avg_qc, h_avg_qr, h_avg_wqv, h_avg_wqc, h_avg_wqr, h_avg_qi, h_avg_qs, h_avg_qg;
35  Gpu::HostVector<Real> h_avg_wthv;
36  Gpu::HostVector<Real> h_avg_uth, h_avg_vth, h_avg_wth, h_avg_thth;
37  Gpu::HostVector<Real> h_avg_uu, h_avg_uv, h_avg_uw, h_avg_vv, h_avg_vw, h_avg_ww;
38  Gpu::HostVector<Real> h_avg_uiuiu, h_avg_uiuiv, h_avg_uiuiw;
39  Gpu::HostVector<Real> h_avg_p, h_avg_pu, h_avg_pv, h_avg_pw;
40  Gpu::HostVector<Real> h_avg_tau11, h_avg_tau12, h_avg_tau13, h_avg_tau22, h_avg_tau23, h_avg_tau33;
41  Gpu::HostVector<Real> h_avg_sgshfx, h_avg_sgsq1fx, h_avg_sgsq2fx, h_avg_sgsdiss; // only output tau_{theta,w} and epsilon for now
42 
43  if (NumDataLogs() > 1) {
45  h_avg_u, h_avg_v, h_avg_w,
46  h_avg_rho, h_avg_th, h_avg_ksgs,
47  h_avg_Kmv, h_avg_Khv,
48  h_avg_qv, h_avg_qc, h_avg_qr,
49  h_avg_wqv, h_avg_wqc, h_avg_wqr,
50  h_avg_qi, h_avg_qs, h_avg_qg,
51  h_avg_uu, h_avg_uv, h_avg_uw, h_avg_vv, h_avg_vw, h_avg_ww,
52  h_avg_uth, h_avg_vth, h_avg_wth, h_avg_thth,
53  h_avg_uiuiu, h_avg_uiuiv, h_avg_uiuiw,
54  h_avg_p, h_avg_pu, h_avg_pv, h_avg_pw,
55  h_avg_wthv);
56  }
57 
58  if (NumDataLogs() > 3 && time > 0.) {
59  derive_stress_profiles_stag(h_avg_tau11, h_avg_tau12, h_avg_tau13,
60  h_avg_tau22, h_avg_tau23, h_avg_tau33,
61  h_avg_sgshfx, h_avg_sgsq1fx, h_avg_sgsq2fx,
62  h_avg_sgsdiss);
63  }
64 
65  int unstag_size = h_avg_w.size() - 1; // _un_staggered heights
66 
67  auto const& dx = geom[0].CellSizeArray();
68  if (ParallelDescriptor::IOProcessor()) {
69  if (NumDataLogs() > 1) {
70  std::ostream& data_log1 = DataLog(1);
71  if (data_log1.good()) {
72  // Write the quantities at this time
73  for (int k = 0; k < unstag_size; k++) {
74  Real z = (zlevels_stag[0].size() > 1) ? zlevels_stag[0][k] : k * dx[2];
75  data_log1 << std::setw(datwidth) << std::setprecision(timeprecision) << time << " "
76  << std::setw(datwidth) << std::setprecision(datprecision) << z << " "
77  << h_avg_u[k] << " " << h_avg_v[k] << " " << h_avg_w[k] << " "
78  << h_avg_rho[k] << " " << h_avg_th[k] << " " << h_avg_ksgs[k] << " "
79  << h_avg_Kmv[k] << " " << h_avg_Khv[k] << " "
80  << h_avg_qv[k] << " " << h_avg_qc[k] << " " << h_avg_qr[k] << " "
81  << h_avg_qi[k] << " " << h_avg_qs[k] << " " << h_avg_qg[k]
82  << std::endl;
83  } // loop over z
84  // Write top face values
85  Real z = (zlevels_stag[0].size() > 1) ? zlevels_stag[0][unstag_size] : unstag_size * dx[2];
86  data_log1 << std::setw(datwidth) << std::setprecision(timeprecision) << time << " "
87  << std::setw(datwidth) << std::setprecision(datprecision) << z << " "
88  << 0 << " " << 0 << " " << h_avg_w[unstag_size] << " "
89  << 0 << " " << 0 << " " << 0 << " " // rho, theta, ksgs
90  << 0 << " " << 0 << " " // Kmv, Khv
91  << 0 << " " << 0 << " " << 0 << " " // qv, qc, qr
92  << 0 << " " << 0 << " " << 0 // qi, qs, qg
93  << std::endl;
94  } // if good
95  } // NumDataLogs
96 
97  if (NumDataLogs() > 2) {
98  std::ostream& data_log2 = DataLog(2);
99  if (data_log2.good()) {
100  // Write the perturbational quantities at this time
101  // For surface values (k=0), assume w = uw = vw = ww = 0
102  Real w_cc = h_avg_w[1] / 2; // w at first cell center
103  Real uw_cc = h_avg_uw[1] / 2; // u*w at first cell center
104  Real vw_cc = h_avg_vw[1] / 2; // v*w at first cell center
105  Real ww_cc = h_avg_ww[1] / 2; // w*w at first cell center
106  data_log2 << std::setw(datwidth) << std::setprecision(timeprecision) << time << " "
107  << std::setw(datwidth) << std::setprecision(datprecision) << 0 << " "
108  << h_avg_uu[0] - h_avg_u[0]*h_avg_u[0] << " " // u'u'
109  << h_avg_uv[0] - h_avg_u[0]*h_avg_v[0] << " " // u'v'
110  << 0 << " " // u'w'
111  << h_avg_vv[0] - h_avg_v[0]*h_avg_v[0] << " " // v'v'
112  << 0 << " " // v'w'
113  << 0 << " " // w'w'
114  << h_avg_uth[0] - h_avg_u[0]*h_avg_th[0] << " " // u'th'
115  << h_avg_vth[0] - h_avg_v[0]*h_avg_th[0] << " " // v'th'
116  << 0 << " " // w'th'
117  << h_avg_thth[0] - h_avg_th[0]*h_avg_th[0] << " " // th'th'
118  << h_avg_uiuiu[0]
119  - (h_avg_uu[0] + h_avg_vv[0] + ww_cc)*h_avg_u[0]
120  - 2*(h_avg_u[0]*h_avg_uu[0] + h_avg_v[0]*h_avg_uv[0] + w_cc*uw_cc)
121  + 2*(h_avg_u[0]*h_avg_u[0] + h_avg_v[0]*h_avg_v[0] + w_cc*w_cc)*h_avg_u[0]
122  << " " // (u'_i u'_i)u'
123  << h_avg_uiuiv[0]
124  - (h_avg_uu[0] + h_avg_vv[0] + ww_cc)*h_avg_v[0]
125  - 2*(h_avg_u[0]*h_avg_uv[0] + h_avg_v[0]*h_avg_vv[0] + w_cc*vw_cc)
126  + 2*(h_avg_u[0]*h_avg_u[0] + h_avg_v[0]*h_avg_v[0] + w_cc*w_cc)*h_avg_v[0]
127  << " " // (u'_i u'_i)v'
128  << 0 << " " // (u'_i u'_i)w'
129  << h_avg_pu[0] - h_avg_p[0]*h_avg_u[0] << " " // p'u'
130  << h_avg_pv[0] - h_avg_p[0]*h_avg_v[0] << " " // p'v'
131  << 0 << " " // p'w'
132  << 0 << " " // qv'w'
133  << 0 << " " // qc'w'
134  << 0 << " " // qr'w'
135  << 0 // thv'w'
136  << std::endl;
137 
138  // For internal values, interpolate scalar quantities to faces
139  for (int k = 1; k < unstag_size; k++) {
140  Real z = (zlevels_stag[0].size() > 1) ? zlevels_stag[0][k] : k * dx[2];
141  Real uface = 0.5*(h_avg_u[k] + h_avg_u[k-1]);
142  Real vface = 0.5*(h_avg_v[k] + h_avg_v[k-1]);
143  Real thface = 0.5*(h_avg_th[k] + h_avg_th[k-1]);
144  Real pface = 0.5*(h_avg_p[k] + h_avg_p[k-1]);
145  Real qvface = 0.5*(h_avg_qv[k] + h_avg_qv[k-1]);
146  Real qcface = 0.5*(h_avg_qc[k] + h_avg_qc[k-1]);
147  Real qrface = 0.5*(h_avg_qr[k] + h_avg_qr[k-1]);
148  Real uuface = 0.5*(h_avg_uu[k] + h_avg_uu[k-1]);
149  Real vvface = 0.5*(h_avg_vv[k] + h_avg_vv[k-1]);
150  Real thvface = thface * (1 + 0.61*qvface - qcface - qrface);
151  w_cc = 0.5*(h_avg_w[k-1] + h_avg_w[k]);
152  uw_cc = 0.5*(h_avg_uw[k-1] + h_avg_uw[k]);
153  vw_cc = 0.5*(h_avg_vw[k-1] + h_avg_vw[k]);
154  ww_cc = 0.5*(h_avg_ww[k-1] + h_avg_ww[k]);
155  data_log2 << std::setw(datwidth) << std::setprecision(timeprecision) << time << " "
156  << std::setw(datwidth) << std::setprecision(datprecision) << z << " "
157  << h_avg_uu[k] - h_avg_u[k]*h_avg_u[k] << " " // u'u'
158  << h_avg_uv[k] - h_avg_u[k]*h_avg_v[k] << " " // u'v'
159  << h_avg_uw[k] - uface*h_avg_w[k] << " " // u'w'
160  << h_avg_vv[k] - h_avg_v[k]*h_avg_v[k] << " " // v'v'
161  << h_avg_vw[k] - vface*h_avg_w[k] << " " // v'w'
162  << h_avg_ww[k] - h_avg_w[k]*h_avg_w[k] << " " // w'w'
163  << h_avg_uth[k] - h_avg_u[k]*h_avg_th[k] << " " // u'th'
164  << h_avg_vth[k] - h_avg_v[k]*h_avg_th[k] << " " // v'th'
165  << h_avg_wth[k] - h_avg_w[k]*thface << " " // w'th'
166  << h_avg_thth[k] - h_avg_th[k]*h_avg_th[k] << " " // th'th'
167  // Note: <u'_i u'_i u'_j> = <u_i u_i u_j>
168  // - <u_i u_i> * <u_j>
169  // - 2*<u_i> * <u_i u_j>
170  // + 2*<u_i>*<u_i> * <u_j>
171  << h_avg_uiuiu[k]
172  - (h_avg_uu[k] + h_avg_vv[k] + ww_cc)*h_avg_u[k]
173  - 2*(h_avg_u[k]*h_avg_uu[k] + h_avg_v[k]*h_avg_uv[k] + w_cc*uw_cc)
174  + 2*(h_avg_u[k]*h_avg_u[k] + h_avg_v[k]*h_avg_v[k] + w_cc*w_cc)*h_avg_u[k]
175  << " " // cell-centered (u'_i u'_i)u'
176  << h_avg_uiuiv[k]
177  - (h_avg_uu[k] + h_avg_vv[k] + ww_cc)*h_avg_v[k]
178  - 2*(h_avg_u[k]*h_avg_uv[k] + h_avg_v[k]*h_avg_vv[k] + w_cc*vw_cc)
179  + 2*(h_avg_u[k]*h_avg_u[k] + h_avg_v[k]*h_avg_v[k] + w_cc*w_cc)*h_avg_v[k]
180  << " " // cell-centered (u'_i u'_i)v'
181  << h_avg_uiuiw[k]
182  - (uuface + vvface + h_avg_ww[k])*h_avg_w[k]
183  - 2*(uface*h_avg_uw[k] + vface*h_avg_vw[k] + h_avg_w[k]*h_avg_ww[k])
184  + 2*(uface*uface + vface*vface + h_avg_w[k]*h_avg_w[k])*h_avg_w[k]
185  << " " // face-centered (u'_i u'_i)w'
186  << h_avg_pu[k] - h_avg_p[k]*h_avg_u[k] << " " // cell-centered p'u'
187  << h_avg_pv[k] - h_avg_p[k]*h_avg_v[k] << " " // cell-centered p'v'
188  << h_avg_pw[k] - pface*h_avg_w[k] << " " // face-centered p'w'
189  << h_avg_wqv[k] - qvface*h_avg_w[k] << " "
190  << h_avg_wqc[k] - qcface*h_avg_w[k] << " "
191  << h_avg_wqr[k] - qrface*h_avg_w[k] << " "
192  << h_avg_wthv[k] - thvface*h_avg_w[k]
193  << std::endl;
194  } // loop over z
195 
196  // Write top face values, extrapolating scalar quantities
197  const int k = unstag_size;
198  Real uface = 1.5*h_avg_u[k-1] - 0.5*h_avg_u[k-2];
199  Real vface = 1.5*h_avg_v[k-1] - 0.5*h_avg_v[k-2];
200  Real thface = 1.5*h_avg_th[k-1] - 0.5*h_avg_th[k-2];
201  Real pface = 1.5*h_avg_p[k-1] - 0.5*h_avg_p[k-2];
202  Real qvface = 1.5*h_avg_qv[k-1] - 0.5*h_avg_qv[k-2];
203  Real qcface = 1.5*h_avg_qc[k-1] - 0.5*h_avg_qc[k-2];
204  Real qrface = 1.5*h_avg_qr[k-1] - 0.5*h_avg_qr[k-2];
205  Real uuface = 1.5*h_avg_uu[k-1] - 0.5*h_avg_uu[k-2];
206  Real vvface = 1.5*h_avg_vv[k-1] - 0.5*h_avg_vv[k-2];
207  Real thvface = thface * (1 + 0.61*qvface - qcface - qrface);
208  Real z = (zlevels_stag[0].size() > 1) ? zlevels_stag[0][unstag_size] : unstag_size * dx[2];
209  data_log2 << std::setw(datwidth) << std::setprecision(timeprecision) << time << " "
210  << std::setw(datwidth) << std::setprecision(datprecision) << z << " "
211  << 0 << " " // u'u'
212  << 0 << " " // u'v'
213  << h_avg_uw[k] - uface*h_avg_w[k] << " " // u'w'
214  << 0 << " " // v'v'
215  << h_avg_vw[k] - vface*h_avg_w[k] << " " // v'w'
216  << h_avg_ww[k] - h_avg_w[k]*h_avg_w[k] << " " // w'w'
217  << 0 << " " // u'th'
218  << 0 << " " // v'th'
219  << h_avg_wth[k] - thface*h_avg_w[k] << " " // w'th'
220  << 0 << " " // th'th'
221  << 0 << " " // (u'_i u'_i)u'
222  << 0 << " " // (u'_i u'_i)v'
223  << h_avg_uiuiw[k]
224  - (uuface + vvface + h_avg_ww[k])*h_avg_w[k]
225  - 2*(uface*h_avg_uw[k] + vface*h_avg_vw[k] + h_avg_w[k]*h_avg_ww[k])
226  + 2*(uface*uface + vface*vface + h_avg_w[k]*h_avg_w[k])*h_avg_w[k]
227  << " " // (u'_i u'_i)w'
228  << 0 << " " // pu'
229  << 0 << " " // pv'
230  << h_avg_pw[k] - pface*h_avg_w[k] << " " // pw'
231  << h_avg_wqv[k] - qvface*h_avg_w[k] << " "
232  << h_avg_wqc[k] - qcface*h_avg_w[k] << " "
233  << h_avg_wqr[k] - qrface*h_avg_w[k] << " "
234  << h_avg_wthv[k] - thvface*h_avg_w[k]
235  << std::endl;
236  } // if good
237  } // NumDataLogs
238 
239  if (NumDataLogs() > 3 && time > 0.) {
240  std::ostream& data_log3 = DataLog(3);
241  if (data_log3.good()) {
242  // Write the average stresses
243  for (int k = 0; k < unstag_size; k++) {
244  Real z = (zlevels_stag[0].size() > 1) ? zlevels_stag[0][k] : k * dx[2];
245  data_log3 << std::setw(datwidth) << std::setprecision(timeprecision) << time << " "
246  << std::setw(datwidth) << std::setprecision(datprecision) << z << " "
247  << h_avg_tau11[k] << " " << h_avg_tau12[k] << " " << h_avg_tau13[k] << " "
248  << h_avg_tau22[k] << " " << h_avg_tau23[k] << " " << h_avg_tau33[k] << " "
249  << h_avg_sgshfx[k] << " "
250  << h_avg_sgsq1fx[k] << " " << h_avg_sgsq2fx[k] << " "
251  << h_avg_sgsdiss[k]
252  << std::endl;
253  } // loop over z
254  // Write top face values
255  Real NANval = 0.0;
256  Real z = (zlevels_stag[0].size() > 1) ? zlevels_stag[0][unstag_size] : unstag_size * dx[2];
257  data_log3 << std::setw(datwidth) << std::setprecision(timeprecision) << time << " "
258  << std::setw(datwidth) << std::setprecision(datprecision) << z << " "
259  << NANval << " " << NANval << " " << h_avg_tau13[unstag_size] << " "
260  << NANval << " " << h_avg_tau23[unstag_size] << " " << NANval << " "
261  << h_avg_sgshfx[unstag_size] << " "
262  << h_avg_sgsq1fx[unstag_size] << " " << h_avg_sgsq2fx[unstag_size] << " "
263  << NANval
264  << std::endl;
265  } // if good
266  } // if (NumDataLogs() > 3)
267  } // if IOProcessor
268  } // if (NumDataLogs() > 1)
269 }
void derive_diag_profiles_stag(amrex::Real time, amrex::Gpu::HostVector< amrex::Real > &h_avg_u, amrex::Gpu::HostVector< amrex::Real > &h_avg_v, amrex::Gpu::HostVector< amrex::Real > &h_avg_w, amrex::Gpu::HostVector< amrex::Real > &h_avg_rho, amrex::Gpu::HostVector< amrex::Real > &h_avg_th, amrex::Gpu::HostVector< amrex::Real > &h_avg_ksgs, amrex::Gpu::HostVector< amrex::Real > &h_avg_Kmv, amrex::Gpu::HostVector< amrex::Real > &h_avg_Khv, amrex::Gpu::HostVector< amrex::Real > &h_avg_qv, amrex::Gpu::HostVector< amrex::Real > &h_avg_qc, amrex::Gpu::HostVector< amrex::Real > &h_avg_qr, amrex::Gpu::HostVector< amrex::Real > &h_avg_wqv, amrex::Gpu::HostVector< amrex::Real > &h_avg_wqc, amrex::Gpu::HostVector< amrex::Real > &h_avg_wqr, amrex::Gpu::HostVector< amrex::Real > &h_avg_qi, amrex::Gpu::HostVector< amrex::Real > &h_avg_qs, amrex::Gpu::HostVector< amrex::Real > &h_avg_qg, amrex::Gpu::HostVector< amrex::Real > &h_avg_uu, amrex::Gpu::HostVector< amrex::Real > &h_avg_uv, amrex::Gpu::HostVector< amrex::Real > &h_avg_uw, amrex::Gpu::HostVector< amrex::Real > &h_avg_vv, amrex::Gpu::HostVector< amrex::Real > &h_avg_vw, amrex::Gpu::HostVector< amrex::Real > &h_avg_ww, amrex::Gpu::HostVector< amrex::Real > &h_avg_uth, amrex::Gpu::HostVector< amrex::Real > &h_avg_vth, amrex::Gpu::HostVector< amrex::Real > &h_avg_wth, amrex::Gpu::HostVector< amrex::Real > &h_avg_thth, amrex::Gpu::HostVector< amrex::Real > &h_avg_ku, amrex::Gpu::HostVector< amrex::Real > &h_avg_kv, amrex::Gpu::HostVector< amrex::Real > &h_avg_kw, amrex::Gpu::HostVector< amrex::Real > &h_avg_p, amrex::Gpu::HostVector< amrex::Real > &h_avg_pu, amrex::Gpu::HostVector< amrex::Real > &h_avg_pv, amrex::Gpu::HostVector< amrex::Real > &h_avg_pw, amrex::Gpu::HostVector< amrex::Real > &h_avg_wthv)
Definition: ERF_Write1DProfiles_stag.cpp:296
void derive_stress_profiles_stag(amrex::Gpu::HostVector< amrex::Real > &h_avg_tau11, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau12, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau13, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau22, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau23, amrex::Gpu::HostVector< amrex::Real > &h_avg_tau33, amrex::Gpu::HostVector< amrex::Real > &h_avg_hfx3, amrex::Gpu::HostVector< amrex::Real > &h_avg_q1fx3, amrex::Gpu::HostVector< amrex::Real > &h_avg_q2fx3, amrex::Gpu::HostVector< amrex::Real > &h_avg_diss)
Definition: ERF_Write1DProfiles_stag.cpp:605

◆ writeBuildInfo()

void ERF::writeBuildInfo ( std::ostream &  os)
static
138 {
139  std::string PrettyLine = std::string(78, '=') + "\n";
140  std::string OtherLine = std::string(78, '-') + "\n";
141  std::string SkipSpace = std::string(8, ' ');
142 
143  // build information
144  os << PrettyLine;
145  os << " ERF Build Information\n";
146  os << PrettyLine;
147 
148  os << "build date: " << buildInfoGetBuildDate() << "\n";
149  os << "build machine: " << buildInfoGetBuildMachine() << "\n";
150  os << "build dir: " << buildInfoGetBuildDir() << "\n";
151  os << "AMReX dir: " << buildInfoGetAMReXDir() << "\n";
152 
153  os << "\n";
154 
155  os << "COMP: " << buildInfoGetComp() << "\n";
156  os << "COMP version: " << buildInfoGetCompVersion() << "\n";
157 
158  os << "C++ compiler: " << buildInfoGetCXXName() << "\n";
159  os << "C++ flags: " << buildInfoGetCXXFlags() << "\n";
160 
161  os << "\n";
162 
163  os << "Link flags: " << buildInfoGetLinkFlags() << "\n";
164  os << "Libraries: " << buildInfoGetLibraries() << "\n";
165 
166  os << "\n";
167 
168  for (int n = 1; n <= buildInfoGetNumModules(); n++) {
169  os << buildInfoGetModuleName(n) << ": "
170  << buildInfoGetModuleVal(n) << "\n";
171  }
172 
173  os << "\n";
174  const char* githash1 = buildInfoGetGitHash(1);
175  const char* githash2 = buildInfoGetGitHash(2);
176  if (strlen(githash1) > 0) {
177  os << "ERF git hash: " << githash1 << "\n";
178  }
179  if (strlen(githash2) > 0) {
180  os << "AMReX git hash: " << githash2 << "\n";
181  }
182 
183  const char* buildgithash = buildInfoGetBuildGitHash();
184  const char* buildgitname = buildInfoGetBuildGitName();
185  if (strlen(buildgithash) > 0) {
186  os << buildgitname << " git hash: " << buildgithash << "\n";
187  }
188 
189  os << "\n";
190  os << " ERF Compile time variables: \n";
191 
192  os << "\n";
193  os << " ERF Defines: \n";
194 #ifdef _OPENMP
195  os << std::setw(35) << std::left << "_OPENMP " << std::setw(6) << "ON"
196  << std::endl;
197 #else
198  os << std::setw(35) << std::left << "_OPENMP " << std::setw(6) << "OFF"
199  << std::endl;
200 #endif
201 
202 #ifdef MPI_VERSION
203  os << std::setw(35) << std::left << "MPI_VERSION " << std::setw(6)
204  << MPI_VERSION << std::endl;
205 #else
206  os << std::setw(35) << std::left << "MPI_VERSION " << std::setw(6)
207  << "UNDEFINED" << std::endl;
208 #endif
209 
210 #ifdef MPI_SUBVERSION
211  os << std::setw(35) << std::left << "MPI_SUBVERSION " << std::setw(6)
212  << MPI_SUBVERSION << std::endl;
213 #else
214  os << std::setw(35) << std::left << "MPI_SUBVERSION " << std::setw(6)
215  << "UNDEFINED" << std::endl;
216 #endif
217 
218  os << "\n\n";
219 }

Referenced by main().

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

◆ WriteCheckpointFile()

void ERF::WriteCheckpointFile ( ) const

ERF function for writing a checkpoint file.

27 {
28  // chk00010 write a checkpoint file with this root directory
29  // chk00010/Header this contains information you need to save (e.g., finest_level, t_new, etc.) and also
30  // the BoxArrays at each level
31  // chk00010/Level_0/
32  // chk00010/Level_1/
33  // etc. these subdirectories will hold the MultiFab data at each level of refinement
34 
35  // checkpoint file name, e.g., chk00010
36  const std::string& checkpointname = Concatenate(check_file,istep[0],5);
37 
38  Print() << "Writing native checkpoint " << checkpointname << "\n";
39 
40  const int nlevels = finest_level+1;
41 
42  // ---- prebuild a hierarchy of directories
43  // ---- dirName is built first. if dirName exists, it is renamed. then build
44  // ---- dirName/subDirPrefix_0 .. dirName/subDirPrefix_nlevels-1
45  // ---- if callBarrier is true, call ParallelDescriptor::Barrier()
46  // ---- after all directories are built
47  // ---- ParallelDescriptor::IOProcessor() creates the directories
48  PreBuildDirectorHierarchy(checkpointname, "Level_", nlevels, true);
49 
50  int ncomp_cons = vars_new[0][Vars::cons].nComp();
51 
52  // write Header file
53  if (ParallelDescriptor::IOProcessor()) {
54 
55  std::string HeaderFileName(checkpointname + "/Header");
56  VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
57  std::ofstream HeaderFile;
58  HeaderFile.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
59  HeaderFile.open(HeaderFileName.c_str(), std::ofstream::out |
60  std::ofstream::trunc |
61  std::ofstream::binary);
62  if(! HeaderFile.good()) {
63  FileOpenFailed(HeaderFileName);
64  }
65 
66  HeaderFile.precision(17);
67 
68  // write out title line
69  HeaderFile << "Checkpoint file for ERF\n";
70 
71  // write out finest_level
72  HeaderFile << finest_level << "\n";
73 
74  // write the number of components
75  // for each variable we store
76 
77  // conservative, cell-centered vars
78  HeaderFile << ncomp_cons << "\n";
79 
80  // x-velocity on faces
81  HeaderFile << 1 << "\n";
82 
83  // y-velocity on faces
84  HeaderFile << 1 << "\n";
85 
86  // z-velocity on faces
87  HeaderFile << 1 << "\n";
88 
89  // write out array of istep
90  for (int i = 0; i < istep.size(); ++i) {
91  HeaderFile << istep[i] << " ";
92  }
93  HeaderFile << "\n";
94 
95  // write out array of dt
96  for (int i = 0; i < dt.size(); ++i) {
97  HeaderFile << dt[i] << " ";
98  }
99  HeaderFile << "\n";
100 
101  // write out array of t_new
102  for (int i = 0; i < t_new.size(); ++i) {
103  HeaderFile << t_new[i] << " ";
104  }
105  HeaderFile << "\n";
106 
107  // write the BoxArray at each level
108  for (int lev = 0; lev <= finest_level; ++lev) {
109  boxArray(lev).writeOn(HeaderFile);
110  HeaderFile << '\n';
111  }
112 
113  // Write separate file that tells how many components we have of the base state
114  std::string BaseStateFileName(checkpointname + "/num_base_state_comps");
115  std::ofstream BaseStateFile;
116  BaseStateFile.open(BaseStateFileName.c_str(), std::ofstream::out |
117  std::ofstream::trunc |
118  std::ofstream::binary);
119  if(! BaseStateFile.good()) {
120  FileOpenFailed(BaseStateFileName);
121  } else {
122  // write out number of components in base state
123  BaseStateFile << BaseState::num_comps << "\n";
124  BaseStateFile << base_state[0].nGrowVect() << "\n";
125  }
126  }
127 
128  // write the MultiFab data to, e.g., chk00010/Level_0/
129  // Here we make copies of the MultiFab with no ghost cells
130  for (int lev = 0; lev <= finest_level; ++lev)
131  {
132  MultiFab cons(grids[lev],dmap[lev],ncomp_cons,0);
133  MultiFab::Copy(cons,vars_new[lev][Vars::cons],0,0,ncomp_cons,0);
134  VisMF::Write(cons, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "Cell"));
135 
136  MultiFab xvel(convert(grids[lev],IntVect(1,0,0)),dmap[lev],1,0);
137  MultiFab::Copy(xvel,vars_new[lev][Vars::xvel],0,0,1,0);
138  VisMF::Write(xvel, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "XFace"));
139 
140  MultiFab yvel(convert(grids[lev],IntVect(0,1,0)),dmap[lev],1,0);
141  MultiFab::Copy(yvel,vars_new[lev][Vars::yvel],0,0,1,0);
142  VisMF::Write(yvel, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "YFace"));
143 
144  MultiFab zvel(convert(grids[lev],IntVect(0,0,1)),dmap[lev],1,0);
145  MultiFab::Copy(zvel,vars_new[lev][Vars::zvel],0,0,1,0);
146  VisMF::Write(zvel, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "ZFace"));
147 
148  // Note that we write the ghost cells of the base state (unlike above)
149  IntVect ng_base = base_state[lev].nGrowVect();
150  int ncomp_base = base_state[lev].nComp();
151  MultiFab base(grids[lev],dmap[lev],ncomp_base,ng_base);
152  MultiFab::Copy(base,base_state[lev],0,0,ncomp_base,ng_base);
153  VisMF::Write(base, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "BaseState"));
154 
155  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
156  // Note that we also write the ghost cells of z_phys_nd
157  IntVect ng = z_phys_nd[lev]->nGrowVect();
158  MultiFab z_height(convert(grids[lev],IntVect(1,1,1)),dmap[lev],1,ng);
159  MultiFab::Copy(z_height,*z_phys_nd[lev],0,0,1,ng);
160  VisMF::Write(z_height, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "Z_Phys_nd"));
161  }
162 
163  // We must read and write qmoist with ghost cells because we don't directly impose BCs on these vars
164  // Write the moisture model restart variables
165  std::vector<int> qmoist_indices;
166  std::vector<std::string> qmoist_names;
167  micro->Get_Qmoist_Restart_Vars(lev, solverChoice, qmoist_indices, qmoist_names);
168  int qmoist_nvar = qmoist_indices.size();
169  for (int var = 0; var < qmoist_nvar; var++) {
170  const int ncomp = 1;
171  IntVect ng_moist = qmoist[lev][qmoist_indices[var]]->nGrowVect();
172  MultiFab moist_vars(grids[lev],dmap[lev],ncomp,ng_moist);
173  MultiFab::Copy(moist_vars,*(qmoist[lev][qmoist_indices[var]]),0,0,ncomp,ng_moist);
174  VisMF::Write(moist_vars, amrex::MultiFabFileFullPrefix(lev, checkpointname, "Level_", qmoist_names[var]));
175  }
176 
177 #if defined(ERF_USE_WINDFARM)
178  if(solverChoice.windfarm_type == WindFarmType::Fitch or
179  solverChoice.windfarm_type == WindFarmType::EWP or
180  solverChoice.windfarm_type == WindFarmType::SimpleAD){
181  IntVect ng_turb = Nturb[lev].nGrowVect();
182  MultiFab mf_Nturb(grids[lev],dmap[lev],1,ng_turb);
183  MultiFab::Copy(mf_Nturb,Nturb[lev],0,0,1,ng_turb);
184  VisMF::Write(mf_Nturb, amrex::MultiFabFileFullPrefix(lev, checkpointname, "Level_", "NumTurb"));
185  }
186 #endif
187 
188  if (solverChoice.lsm_type != LandSurfaceType::None) {
189  for (int mvar(0); mvar<lsm_data[lev].size(); ++mvar) {
190  BoxArray ba = lsm_data[lev][mvar]->boxArray();
191  DistributionMapping dm = lsm_data[lev][mvar]->DistributionMap();
192  IntVect ng = lsm_data[lev][mvar]->nGrowVect();
193  int nvar = lsm_data[lev][mvar]->nComp();
194  MultiFab lsm_vars(ba,dm,nvar,ng);
195  MultiFab::Copy(lsm_vars,*(lsm_data[lev][mvar]),0,0,nvar,ng);
196  VisMF::Write(lsm_vars, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "LsmVars"));
197  }
198  }
199 
200  IntVect ng = mapfac[lev][MapFacType::m_x]->nGrowVect();
201  MultiFab mf_m(ba2d[lev],dmap[lev],1,ng);
202  MultiFab::Copy(mf_m,*mapfac[lev][MapFacType::m_x],0,0,1,ng);
203  VisMF::Write(mf_m, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "MapFactor_mx"));
204 
205 #if 0
207  MultiFab::Copy(mf_m,*mapfac[lev][MapFacType::m_y],0,0,1,ng);
208  VisMF::Write(mf_m, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "MapFactor_my"));
209  }
210 #endif
211 
212  ng = mapfac[lev][MapFacType::u_x]->nGrowVect();
213  MultiFab mf_u(convert(ba2d[lev],IntVect(1,0,0)),dmap[lev],1,ng);
214  MultiFab::Copy(mf_u,*mapfac[lev][MapFacType::u_x],0,0,1,ng);
215  VisMF::Write(mf_u, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "MapFactor_ux"));
216 
217 #if 0
219  MultiFab::Copy(mf_u,*mapfac[lev][MapFacType::u_y],0,0,1,ng);
220  VisMF::Write(mf_u, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "MapFactor_uy"));
221  }
222 #endif
223 
224  ng = mapfac[lev][MapFacType::v_x]->nGrowVect();
225  MultiFab mf_v(convert(ba2d[lev],IntVect(0,1,0)),dmap[lev],1,ng);
226  MultiFab::Copy(mf_v,*mapfac[lev][MapFacType::v_x],0,0,1,ng);
227  VisMF::Write(mf_v, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "MapFactor_vx"));
228 
229 #if 0
231  MultiFab::Copy(mf_v,*mapfac[lev][MapFacType::v_y],0,0,1,ng);
232  VisMF::Write(mf_v, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "MapFactor_vy"));
233  }
234 #endif
235 
236  if (m_SurfaceLayer) {
237  amrex::Print() << "Writing SurfaceLayer variables" << std::endl;
238  ng = vars_new[lev][Vars::cons].nGrowVect(); ng[2]=0;
239  MultiFab m_var(ba2d[lev],dmap[lev],1,ng);
240  MultiFab* src = nullptr;
241 
242  // U*
243  src = m_SurfaceLayer->get_u_star(lev);
244  MultiFab::Copy(m_var,*src,0,0,1,ng);
245  VisMF::Write(m_var, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "Ustar"));
246 
247  // W*
248  src = m_SurfaceLayer->get_w_star(lev);
249  MultiFab::Copy(m_var,*src,0,0,1,ng);
250  VisMF::Write(m_var, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "Wstar"));
251 
252  // T*
253  src = m_SurfaceLayer->get_t_star(lev);
254  MultiFab::Copy(m_var,*src,0,0,1,ng);
255  VisMF::Write(m_var, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "Tstar"));
256 
257  // Q*
258  src = m_SurfaceLayer->get_q_star(lev);
259  MultiFab::Copy(m_var,*src,0,0,1,ng);
260  VisMF::Write(m_var, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "Qstar"));
261 
262  // Olen
263  src = m_SurfaceLayer->get_olen(lev);
264  MultiFab::Copy(m_var,*src,0,0,1,ng);
265  VisMF::Write(m_var, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "Olen"));
266 
267  // PBLH
268  src = m_SurfaceLayer->get_pblh(lev);
269  MultiFab::Copy(m_var,*src,0,0,1,ng);
270  VisMF::Write(m_var, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "PBLH"));
271 
272  // Z0
273  for (MFIter mfi(m_var); mfi.isValid(); ++mfi) {
274  const Box& bx = mfi.growntilebox();
275  Array4<const Real> const& fab_arr = m_SurfaceLayer->get_z0(lev)->const_array();
276  Array4< Real> const& mv_arr = m_var.array(mfi);
277  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
278  mv_arr(i,j,k) = fab_arr(i,j,k);
279  });
280  }
281  VisMF::Write(m_var, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "Z0"));
282  }
283 
284  if (sst_lev[lev][0]) {
285  int ntimes = 1;
286  ng = vars_new[lev][Vars::cons].nGrowVect(); ng[2]=0;
287  MultiFab sst_at_t(ba2d[lev],dmap[lev],1,ng);
288  for (int nt(0); nt<ntimes; ++nt) {
289  MultiFab::Copy(sst_at_t,*sst_lev[lev][nt],0,0,1,ng);
290  VisMF::Write(sst_at_t, MultiFabFileFullPrefix(lev, checkpointname, "Level_",
291  "SST_" + std::to_string(nt)));
292  }
293  }
294 
295  if (tsk_lev[lev][0]) {
296  int ntimes = 1;
297  ng = vars_new[lev][Vars::cons].nGrowVect(); ng[2]=0;
298  MultiFab tsk_at_t(ba2d[lev],dmap[lev],1,ng);
299  for (int nt(0); nt<ntimes; ++nt) {
300  MultiFab::Copy(tsk_at_t,*tsk_lev[lev][nt],0,0,1,ng);
301  VisMF::Write(tsk_at_t, MultiFabFileFullPrefix(lev, checkpointname, "Level_",
302  "TSK_" + std::to_string(nt)));
303  }
304  }
305 
306  {
307  int ntimes = 1;
308  ng = vars_new[lev][Vars::cons].nGrowVect(); ng[2]=0;
309  MultiFab lmask_at_t(ba2d[lev],dmap[lev],1,ng);
310  for (int nt(0); nt<ntimes; ++nt) {
311  for (MFIter mfi(lmask_at_t); mfi.isValid(); ++mfi) {
312  const Box& bx = mfi.growntilebox();
313  Array4<int> const& src_arr = lmask_lev[lev][nt]->array(mfi);
314  Array4<Real> const& dst_arr = lmask_at_t.array(mfi);
315  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
316  {
317  dst_arr(i,j,k) = Real(src_arr(i,j,k));
318  });
319  }
320  VisMF::Write(lmask_at_t, MultiFabFileFullPrefix(lev, checkpointname, "Level_",
321  "LMASK_" + std::to_string(nt)));
322  }
323  }
324 
325 #ifdef ERF_USE_NETCDF
326  IntVect ngv = ng; ngv[2] = 0;
327 
328  // Write lat/lon if it exists
329  if (lat_m[lev] && lon_m[lev] && solverChoice.has_lat_lon) {
330  amrex::Print() << "Writing Lat/Lon variables" << std::endl;
331  MultiFab lat(ba2d[lev],dmap[lev],1,ngv);
332  MultiFab lon(ba2d[lev],dmap[lev],1,ngv);
333  MultiFab::Copy(lat,*lat_m[lev],0,0,1,ngv);
334  MultiFab::Copy(lon,*lon_m[lev],0,0,1,ngv);
335  VisMF::Write(lat, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "LAT"));
336  VisMF::Write(lon, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "LON"));
337  }
338 
339  // Write sinPhi and cosPhi if it exists
340  if (cosPhi_m[lev] && sinPhi_m[lev] && solverChoice.variable_coriolis) {
341  amrex::Print() << "Writing Coriolis factors" << std::endl;
342  MultiFab sphi(ba2d[lev],dmap[lev],1,ngv);
343  MultiFab cphi(ba2d[lev],dmap[lev],1,ngv);
344  MultiFab::Copy(sphi,*sinPhi_m[lev],0,0,1,ngv);
345  MultiFab::Copy(cphi,*cosPhi_m[lev],0,0,1,ngv);
346  VisMF::Write(sphi, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "SinPhi"));
347  VisMF::Write(cphi, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "CosPhi"));
348  }
349 
350  if (solverChoice.use_real_bcs && solverChoice.init_type == InitType::WRFInput) {
351  MultiFab tmp1d(ba1d[lev],dmap[lev],1,ngv);
352  MultiFab tmp2d(ba2d[lev],dmap[lev],1,ngv);
353 
354  MultiFab::Copy(tmp1d,*mf_C1H[lev],0,0,1,ngv);
355  VisMF::Write(tmp1d, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "C1H"));
356 
357  MultiFab::Copy(tmp1d,*mf_C2H[lev],0,0,1,ngv);
358  VisMF::Write(tmp1d, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "C2H"));
359 
360  MultiFab::Copy(tmp2d,*mf_MUB[lev],0,0,1,ngv);
361  VisMF::Write(tmp2d, MultiFabFileFullPrefix(lev, checkpointname, "Level_", "MUB"));
362  }
363 #endif
364 
365  } // for lev
366 
367 #ifdef ERF_USE_PARTICLES
368  particleData.Checkpoint(checkpointname);
369 #endif
370 
371 #if 0
372 #ifdef ERF_USE_NETCDF
373  // Write bdy_data files
374  if ( ParallelDescriptor::IOProcessor() &&
375  ((solverChoice.init_type==InitType::WRFInput) || (solverChoice.init_type==InitType::Metgrid)) &&
377  {
378  // Vector dimensions
379  int num_time = bdy_data_xlo.size();
380  int num_var = bdy_data_xlo[0].size();
381 
382  // Open header file and write to it
383  std::ofstream bdy_h_file(MultiFabFileFullPrefix(0, checkpointname, "Level_", "bdy_H"));
384  bdy_h_file << std::setprecision(1) << std::fixed;
385  bdy_h_file << num_time << "\n";
386  bdy_h_file << num_var << "\n";
387  bdy_h_file << start_bdy_time << "\n";
388  bdy_h_file << bdy_time_interval << "\n";
389  bdy_h_file << real_width << "\n";
390  for (int ivar(0); ivar<num_var; ++ivar) {
391  bdy_h_file << bdy_data_xlo[0][ivar].box() << "\n";
392  bdy_h_file << bdy_data_xhi[0][ivar].box() << "\n";
393  bdy_h_file << bdy_data_ylo[0][ivar].box() << "\n";
394  bdy_h_file << bdy_data_yhi[0][ivar].box() << "\n";
395  }
396 
397  // Open data file and write to it
398  std::ofstream bdy_d_file(MultiFabFileFullPrefix(0, checkpointname, "Level_", "bdy_D"));
399  for (int itime(0); itime<num_time; ++itime) {
400  if (bdy_data_xlo[itime].size() > 0) {
401  for (int ivar(0); ivar<num_var; ++ivar) {
402  bdy_data_xlo[itime][ivar].writeOn(bdy_d_file,0,1);
403  bdy_data_xhi[itime][ivar].writeOn(bdy_d_file,0,1);
404  bdy_data_ylo[itime][ivar].writeOn(bdy_d_file,0,1);
405  bdy_data_yhi[itime][ivar].writeOn(bdy_d_file,0,1);
406  }
407  }
408  }
409  }
410 #endif
411 #endif
412 
413 }

◆ WriteGenericPlotfileHeaderWithTerrain()

void ERF::WriteGenericPlotfileHeaderWithTerrain ( std::ostream &  HeaderFile,
int  nlevels,
const amrex::Vector< amrex::BoxArray > &  bArray,
const amrex::Vector< std::string > &  varnames,
const amrex::Vector< amrex::Geometry > &  my_geom,
amrex::Real  time,
const amrex::Vector< int > &  level_steps,
const amrex::Vector< amrex::IntVect > &  my_ref_ratio,
const std::string &  versionName,
const std::string &  levelPrefix,
const std::string &  mfPrefix 
) const
1676 {
1677  AMREX_ALWAYS_ASSERT(nlevels <= bArray.size());
1678  AMREX_ALWAYS_ASSERT(nlevels <= my_ref_ratio.size()+1);
1679  AMREX_ALWAYS_ASSERT(nlevels <= level_steps.size());
1680 
1681  HeaderFile.precision(17);
1682 
1683  // ---- this is the generic plot file type name
1684  HeaderFile << versionName << '\n';
1685 
1686  HeaderFile << varnames.size() << '\n';
1687 
1688  for (int ivar = 0; ivar < varnames.size(); ++ivar) {
1689  HeaderFile << varnames[ivar] << "\n";
1690  }
1691  HeaderFile << AMREX_SPACEDIM << '\n';
1692  HeaderFile << my_time << '\n';
1693  HeaderFile << finest_level << '\n';
1694  for (int i = 0; i < AMREX_SPACEDIM; ++i) {
1695  HeaderFile << my_geom[0].ProbLo(i) << ' ';
1696  }
1697  HeaderFile << '\n';
1698  for (int i = 0; i < AMREX_SPACEDIM; ++i) {
1699  HeaderFile << my_geom[0].ProbHi(i) << ' ';
1700  }
1701  HeaderFile << '\n';
1702  for (int i = 0; i < finest_level; ++i) {
1703  HeaderFile << my_ref_ratio[i][0] << ' ';
1704  }
1705  HeaderFile << '\n';
1706  for (int i = 0; i <= finest_level; ++i) {
1707  HeaderFile << my_geom[i].Domain() << ' ';
1708  }
1709  HeaderFile << '\n';
1710  for (int i = 0; i <= finest_level; ++i) {
1711  HeaderFile << level_steps[i] << ' ';
1712  }
1713  HeaderFile << '\n';
1714  for (int i = 0; i <= finest_level; ++i) {
1715  for (int k = 0; k < AMREX_SPACEDIM; ++k) {
1716  HeaderFile << my_geom[i].CellSize()[k] << ' ';
1717  }
1718  HeaderFile << '\n';
1719  }
1720  HeaderFile << (int) my_geom[0].Coord() << '\n';
1721  HeaderFile << "0\n";
1722 
1723  for (int level = 0; level <= finest_level; ++level) {
1724  HeaderFile << level << ' ' << bArray[level].size() << ' ' << my_time << '\n';
1725  HeaderFile << level_steps[level] << '\n';
1726 
1727  const IntVect& domain_lo = my_geom[level].Domain().smallEnd();
1728  for (int i = 0; i < bArray[level].size(); ++i)
1729  {
1730  // Need to shift because the RealBox ctor we call takes the
1731  // physical location of index (0,0,0). This does not affect
1732  // the usual cases where the domain index starts with 0.
1733  const Box& b = shift(bArray[level][i], -domain_lo);
1734  RealBox loc = RealBox(b, my_geom[level].CellSize(), my_geom[level].ProbLo());
1735  for (int n = 0; n < AMREX_SPACEDIM; ++n) {
1736  HeaderFile << loc.lo(n) << ' ' << loc.hi(n) << '\n';
1737  }
1738  }
1739 
1740  HeaderFile << MultiFabHeaderPath(level, levelPrefix, mfPrefix) << '\n';
1741  }
1742  HeaderFile << "1" << "\n";
1743  HeaderFile << "3" << "\n";
1744  HeaderFile << "amrexvec_nu_x" << "\n";
1745  HeaderFile << "amrexvec_nu_y" << "\n";
1746  HeaderFile << "amrexvec_nu_z" << "\n";
1747  std::string mf_nodal_prefix = "Nu_nd";
1748  for (int level = 0; level <= finest_level; ++level) {
1749  HeaderFile << MultiFabHeaderPath(level, levelPrefix, mf_nodal_prefix) << '\n';
1750  }
1751 }
Coord
Definition: ERF_DataStruct.H:81

◆ writeJobInfo()

void ERF::writeJobInfo ( const std::string &  dir) const
10 {
11  // job_info file with details about the run
12  std::ofstream jobInfoFile;
13  std::string FullPathJobInfoFile = dir;
14  FullPathJobInfoFile += "/job_info";
15  jobInfoFile.open(FullPathJobInfoFile.c_str(), std::ios::out);
16 
17  std::string PrettyLine = "==================================================="
18  "============================\n";
19  std::string OtherLine = "----------------------------------------------------"
20  "----------------------------\n";
21  std::string SkipSpace = " ";
22 
23  // job information
24  jobInfoFile << PrettyLine;
25  jobInfoFile << " ERF Job Information\n";
26  jobInfoFile << PrettyLine;
27 
28  jobInfoFile << "inputs file: " << inputs_name << "\n\n";
29 
30  jobInfoFile << "number of MPI processes: "
31  << ParallelDescriptor::NProcs() << "\n";
32 #ifdef _OPENMP
33  jobInfoFile << "number of threads: " << omp_get_max_threads() << "\n";
34 #endif
35 
36  jobInfoFile << "\n";
37  jobInfoFile << "CPU time used since start of simulation (CPU-hours): "
38  << getCPUTime() / 3600.0;
39 
40  jobInfoFile << "\n\n";
41 
42  // plotfile information
43  jobInfoFile << PrettyLine;
44  jobInfoFile << " Plotfile Information\n";
45  jobInfoFile << PrettyLine;
46 
47  time_t now = time(nullptr);
48 
49  // Convert now to tm struct for local timezone
50  tm* localtm = localtime(&now);
51  jobInfoFile << "output data / time: " << asctime(localtm);
52 
53  std::string currentDir = FileSystem::CurrentPath();
54  jobInfoFile << "output dir: " << currentDir << "\n";
55 
56  jobInfoFile << "\n\n";
57 
58  // build information
59  jobInfoFile << PrettyLine;
60  jobInfoFile << " Build Information\n";
61  jobInfoFile << PrettyLine;
62 
63  jobInfoFile << "build date: " << buildInfoGetBuildDate() << "\n";
64  jobInfoFile << "build machine: " << buildInfoGetBuildMachine() << "\n";
65  jobInfoFile << "build dir: " << buildInfoGetBuildDir() << "\n";
66  jobInfoFile << "AMReX dir: " << buildInfoGetAMReXDir() << "\n";
67 
68  jobInfoFile << "\n";
69 
70  jobInfoFile << "COMP: " << buildInfoGetComp() << "\n";
71  jobInfoFile << "COMP version: " << buildInfoGetCompVersion() << "\n";
72 
73  jobInfoFile << "\n";
74 
75  for (int n = 1; n <= buildInfoGetNumModules(); n++) {
76  jobInfoFile << buildInfoGetModuleName(n) << ": "
77  << buildInfoGetModuleVal(n) << "\n";
78  }
79 
80  jobInfoFile << "\n";
81 
82  const char* githash1 = buildInfoGetGitHash(1);
83  const char* githash2 = buildInfoGetGitHash(2);
84  if (strlen(githash1) > 0) {
85  jobInfoFile << "ERF git hash: " << githash1 << "\n";
86  }
87  if (strlen(githash2) > 0) {
88  jobInfoFile << "AMReX git hash: " << githash2 << "\n";
89  }
90 
91  const char* buildgithash = buildInfoGetBuildGitHash();
92  const char* buildgitname = buildInfoGetBuildGitName();
93  if (strlen(buildgithash) > 0) {
94  jobInfoFile << buildgitname << " git hash: " << buildgithash << "\n";
95  }
96 
97  jobInfoFile << "\n\n";
98 
99  // grid information
100  jobInfoFile << PrettyLine;
101  jobInfoFile << " Grid Information\n";
102  jobInfoFile << PrettyLine;
103 
104  int f_lev = finest_level;
105 
106  for (int i = 0; i <= f_lev; i++) {
107  jobInfoFile << " level: " << i << "\n";
108  jobInfoFile << " number of boxes = " << grids[i].size() << "\n";
109  jobInfoFile << " maximum zones = ";
110  for (int n = 0; n < AMREX_SPACEDIM; n++) {
111  jobInfoFile << geom[i].Domain().length(n) << " ";
112  }
113  jobInfoFile << "\n\n";
114  }
115 
116  jobInfoFile << " Boundary conditions\n";
117 
118  jobInfoFile << " -x: " << domain_bc_type[0] << "\n";
119  jobInfoFile << " +x: " << domain_bc_type[3] << "\n";
120  jobInfoFile << " -y: " << domain_bc_type[1] << "\n";
121  jobInfoFile << " +y: " << domain_bc_type[4] << "\n";
122  jobInfoFile << " -z: " << domain_bc_type[2] << "\n";
123  jobInfoFile << " +z: " << domain_bc_type[5] << "\n";
124 
125  jobInfoFile << "\n\n";
126 
127  // runtime parameters
128  jobInfoFile << PrettyLine;
129  jobInfoFile << " Inputs File Parameters\n";
130  jobInfoFile << PrettyLine;
131 
132  ParmParse::dumpTable(jobInfoFile, true);
133  jobInfoFile.close();
134 }
std::string inputs_name
Definition: main.cpp:14
static amrex::Real getCPUTime()
Definition: ERF.H:1322
Here is the call graph for this function:

◆ WriteMultiLevelPlotfileWithTerrain()

void ERF::WriteMultiLevelPlotfileWithTerrain ( const std::string &  plotfilename,
int  nlevels,
const amrex::Vector< const amrex::MultiFab * > &  mf,
const amrex::Vector< const amrex::MultiFab * > &  mf_nd,
const amrex::Vector< std::string > &  varnames,
const amrex::Vector< amrex::Geometry > &  my_geom,
amrex::Real  time,
const amrex::Vector< int > &  level_steps,
const amrex::Vector< amrex::IntVect > &  my_ref_ratio,
const std::string &  versionName = "HyperCLaw-V1.1",
const std::string &  levelPrefix = "Level_",
const std::string &  mfPrefix = "Cell",
const amrex::Vector< std::string > &  extra_dirs = amrex::Vector<std::string>() 
) const
1590 {
1591  BL_PROFILE("WriteMultiLevelPlotfileWithTerrain()");
1592 
1593  AMREX_ALWAYS_ASSERT(nlevels <= mf.size());
1594  AMREX_ALWAYS_ASSERT(nlevels <= rr.size()+1);
1595  AMREX_ALWAYS_ASSERT(nlevels <= level_steps.size());
1596  AMREX_ALWAYS_ASSERT(mf[0]->nComp() == varnames.size());
1597 
1598  bool callBarrier(false);
1599  PreBuildDirectorHierarchy(plotfilename, levelPrefix, nlevels, callBarrier);
1600  if (!extra_dirs.empty()) {
1601  for (const auto& d : extra_dirs) {
1602  const std::string ed = plotfilename+"/"+d;
1603  PreBuildDirectorHierarchy(ed, levelPrefix, nlevels, callBarrier);
1604  }
1605  }
1606  ParallelDescriptor::Barrier();
1607 
1608  if (ParallelDescriptor::MyProc() == ParallelDescriptor::NProcs()-1) {
1609  Vector<BoxArray> boxArrays(nlevels);
1610  for(int level(0); level < boxArrays.size(); ++level) {
1611  boxArrays[level] = mf[level]->boxArray();
1612  }
1613 
1614  auto f = [=]() {
1615  VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
1616  std::string HeaderFileName(plotfilename + "/Header");
1617  std::ofstream HeaderFile;
1618  HeaderFile.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
1619  HeaderFile.open(HeaderFileName.c_str(), std::ofstream::out |
1620  std::ofstream::trunc |
1621  std::ofstream::binary);
1622  if( ! HeaderFile.good()) FileOpenFailed(HeaderFileName);
1623  WriteGenericPlotfileHeaderWithTerrain(HeaderFile, nlevels, boxArrays, varnames,
1624  my_geom, time, level_steps, rr, versionName,
1625  levelPrefix, mfPrefix);
1626  };
1627 
1628  if (AsyncOut::UseAsyncOut()) {
1629  AsyncOut::Submit(std::move(f));
1630  } else {
1631  f();
1632  }
1633  }
1634 
1635  std::string mf_nodal_prefix = "Nu_nd";
1636  for (int level = 0; level <= finest_level; ++level)
1637  {
1638  if (AsyncOut::UseAsyncOut()) {
1639  VisMF::AsyncWrite(*mf[level],
1640  MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mfPrefix),
1641  true);
1642  VisMF::AsyncWrite(*mf_nd[level],
1643  MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_nodal_prefix),
1644  true);
1645  } else {
1646  const MultiFab* data;
1647  std::unique_ptr<MultiFab> mf_tmp;
1648  if (mf[level]->nGrowVect() != 0) {
1649  mf_tmp = std::make_unique<MultiFab>(mf[level]->boxArray(),
1650  mf[level]->DistributionMap(),
1651  mf[level]->nComp(), 0, MFInfo(),
1652  mf[level]->Factory());
1653  MultiFab::Copy(*mf_tmp, *mf[level], 0, 0, mf[level]->nComp(), 0);
1654  data = mf_tmp.get();
1655  } else {
1656  data = mf[level];
1657  }
1658  VisMF::Write(*data , MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mfPrefix));
1659  VisMF::Write(*mf_nd[level], MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_nodal_prefix));
1660  }
1661  }
1662 }
void WriteGenericPlotfileHeaderWithTerrain(std::ostream &HeaderFile, int nlevels, const amrex::Vector< amrex::BoxArray > &bArray, const amrex::Vector< std::string > &varnames, const amrex::Vector< amrex::Geometry > &my_geom, amrex::Real time, const amrex::Vector< int > &level_steps, const amrex::Vector< amrex::IntVect > &my_ref_ratio, const std::string &versionName, const std::string &levelPrefix, const std::string &mfPrefix) const
Definition: ERF_Plotfile.cpp:1665

◆ WriteMyEBSurface()

void ERF::WriteMyEBSurface ( )
6 {
7  using namespace amrex;
8 
9  amrex::Print() << "Writing the geometry to a vtp file.\n" << std::endl;
10 
11  // Only write at the finest level!
12  int lev = finest_level;
13 
14  BoxArray & ba = grids[lev];
15  DistributionMapping & dm = dmap[lev];
16 
17  const EBFArrayBoxFactory* ebfact = &EBFactory(lev);
18 
19  WriteEBSurface(ba,dm,Geom(lev),ebfact);
20 }
Definition: ERF_ConsoleIO.cpp:12
Here is the call graph for this function:

◆ writeNow()

bool ERF::writeNow ( const amrex::Real  cur_time,
const amrex::Real  dt,
const int  nstep,
const int  plot_int,
const amrex::Real  plot_per 
)
2194 {
2195  bool write_now = false;
2196 
2197  if ( plot_int > 0 && (nstep % plot_int == 0) ) {
2198  write_now = true;
2199 
2200  } else if (plot_per > 0.0) {
2201 
2202  // Check to see if we've crossed a plot_per interval by comparing
2203  // the number of intervals that have elapsed for both the current
2204  // time and the time at the beginning of this timestep.
2205 
2206  const Real eps = std::numeric_limits<Real>::epsilon() * Real(10.0) * std::abs(cur_time);
2207 
2208  int num_per_old = static_cast<int>(std::floor((cur_time-eps-dt_lev) / plot_per));
2209  int num_per_new = static_cast<int>(std::floor((cur_time-eps ) / plot_per));
2210 
2211  // Before using these, however, we must test for the case where we're
2212  // within machine epsilon of the next interval. In that case, increment
2213  // the counter, because we have indeed reached the next plot_per interval
2214  // at this point.
2215 
2216  const Real next_plot_time = (num_per_old + 1) * plot_per;
2217 
2218  if ((num_per_new == num_per_old) && std::abs(cur_time - next_plot_time) <= eps)
2219  {
2220  num_per_new += 1;
2221  }
2222 
2223  // Similarly, we have to account for the case where the old time is within
2224  // machine epsilon of the beginning of this interval, so that we don't double
2225  // count that time threshold -- we already plotted at that time on the last timestep.
2226 
2227  if ((num_per_new != num_per_old) && std::abs((cur_time - dt_lev) - next_plot_time) <= eps)
2228  num_per_old += 1;
2229 
2230  if (num_per_old != num_per_new)
2231  write_now = true;
2232  }
2233  return write_now;
2234 }
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12

◆ WritePlotFile()

void ERF::WritePlotFile ( int  which,
PlotFileType  plotfile_type,
amrex::Vector< std::string >  plot_var_names 
)
262 {
263  const Vector<std::string> varnames = PlotFileVarNames(plot_var_names);
264  const int ncomp_mf = varnames.size();
265 
266  int ncomp_cons = vars_new[0][Vars::cons].nComp();
267 
268  if (ncomp_mf == 0) return;
269 
270  // We Fillpatch here because some of the derived quantities require derivatives
271  // which require ghost cells to be filled. We do not need to call FillPatcher
272  // because we don't need to set interior fine points.
273  // NOTE: the momenta here are only used as scratch space, the momenta themselves are not fillpatched
274 
275  // Level 0 FilLPatch
277  &vars_new[0][Vars::yvel], &vars_new[0][Vars::zvel]});
278 
279  for (int lev = 1; lev <= finest_level; ++lev) {
280  bool fillset = false;
281  FillPatch(lev, t_new[lev], {&vars_new[lev][Vars::cons], &vars_new[lev][Vars::xvel],
282  &vars_new[lev][Vars::yvel], &vars_new[lev][Vars::zvel]},
283  {&vars_new[lev][Vars::cons],
284  &rU_new[lev], &rV_new[lev], &rW_new[lev]},
285  base_state[lev], base_state[lev], fillset);
286  }
287 
288  // Get qmoist pointers if using moisture
289  bool use_moisture = (solverChoice.moisture_type != MoistureType::None);
290  for (int lev = 0; lev <= finest_level; ++lev) {
291  for (int mvar(0); mvar<qmoist[lev].size(); ++mvar) {
292  qmoist[lev][mvar] = micro->Get_Qmoist_Ptr(lev,mvar);
293  }
294  }
295 
296  // Vector of MultiFabs for cell-centered data
297  Vector<MultiFab> mf(finest_level+1);
298  for (int lev = 0; lev <= finest_level; ++lev) {
299  mf[lev].define(grids[lev], dmap[lev], ncomp_mf, 0);
300  }
301 
302  // Vector of MultiFabs for nodal data
303  Vector<MultiFab> mf_nd(finest_level+1);
304  if ( SolverChoice::mesh_type != MeshType::ConstantDz) {
305  for (int lev = 0; lev <= finest_level; ++lev) {
306  BoxArray nodal_grids(grids[lev]); nodal_grids.surroundingNodes();
307  mf_nd[lev].define(nodal_grids, dmap[lev], 3, 0);
308  mf_nd[lev].setVal(0.);
309  }
310  }
311 
312  // Vector of MultiFabs for face-centered velocity
313  Vector<MultiFab> mf_u(finest_level+1);
314  Vector<MultiFab> mf_v(finest_level+1);
315  Vector<MultiFab> mf_w(finest_level+1);
316  if (m_plot_face_vels) {
317  for (int lev = 0; lev <= finest_level; ++lev) {
318  BoxArray grid_stag_u(grids[lev]); grid_stag_u.surroundingNodes(0);
319  BoxArray grid_stag_v(grids[lev]); grid_stag_v.surroundingNodes(1);
320  BoxArray grid_stag_w(grids[lev]); grid_stag_w.surroundingNodes(2);
321  mf_u[lev].define(grid_stag_u, dmap[lev], 1, 0);
322  mf_v[lev].define(grid_stag_v, dmap[lev], 1, 0);
323  mf_w[lev].define(grid_stag_w, dmap[lev], 1, 0);
324  MultiFab::Copy(mf_u[lev],vars_new[lev][Vars::xvel],0,0,1,0);
325  MultiFab::Copy(mf_v[lev],vars_new[lev][Vars::yvel],0,0,1,0);
326  MultiFab::Copy(mf_w[lev],vars_new[lev][Vars::zvel],0,0,1,0);
327  }
328  }
329 
330  // Array of MultiFabs for cell-centered velocity
331  Vector<MultiFab> mf_cc_vel(finest_level+1);
332 
333  if (containerHasElement(plot_var_names, "x_velocity" ) ||
334  containerHasElement(plot_var_names, "y_velocity" ) ||
335  containerHasElement(plot_var_names, "z_velocity" ) ||
336  containerHasElement(plot_var_names, "magvel" ) ||
337  containerHasElement(plot_var_names, "vorticity_x") ||
338  containerHasElement(plot_var_names, "vorticity_y") ||
339  containerHasElement(plot_var_names, "vorticity_z") ) {
340 
341  for (int lev = 0; lev <= finest_level; ++lev) {
342  mf_cc_vel[lev].define(grids[lev], dmap[lev], AMREX_SPACEDIM, IntVect(1,1,1));
343  mf_cc_vel[lev].setVal(-1.e20);
344  average_face_to_cellcenter(mf_cc_vel[lev],0,
345  Array<const MultiFab*,3>{&vars_new[lev][Vars::xvel],
346  &vars_new[lev][Vars::yvel],
347  &vars_new[lev][Vars::zvel]});
348  } // lev
349  } // if (vel or vort)
350 
351  // We need ghost cells if computing vorticity
352  if ( containerHasElement(plot_var_names, "vorticity_x")||
353  containerHasElement(plot_var_names, "vorticity_y") ||
354  containerHasElement(plot_var_names, "vorticity_z") )
355  {
356  amrex::Interpolater* mapper = &cell_cons_interp;
357  for (int lev = 1; lev <= finest_level; ++lev)
358  {
359  Vector<MultiFab*> fmf = {&(mf_cc_vel[lev]), &(mf_cc_vel[lev])};
360  Vector<Real> ftime = {t_new[lev], t_new[lev]};
361  Vector<MultiFab*> cmf = {&mf_cc_vel[lev-1], &mf_cc_vel[lev-1]};
362  Vector<Real> ctime = {t_new[lev], t_new[lev]};
363 
364  FillBdyCCVels(mf_cc_vel,lev-1);
365 
366  // Call FillPatch which ASSUMES that all ghost cells at lev-1 have already been filled
367  FillPatchTwoLevels(mf_cc_vel[lev], mf_cc_vel[lev].nGrowVect(), IntVect(0,0,0),
368  t_new[lev], cmf, ctime, fmf, ftime,
369  0, 0, mf_cc_vel[lev].nComp(), geom[lev-1], geom[lev],
370  refRatio(lev-1), mapper, domain_bcs_type,
372  } // lev
373  FillBdyCCVels(mf_cc_vel);
374  } // if (vort)
375 
376 
377  for (int lev = 0; lev <= finest_level; ++lev)
378  {
379  int mf_comp = 0;
380 
381  BoxArray ba(vars_new[lev][Vars::cons].boxArray());
382  DistributionMapping dm = vars_new[lev][Vars::cons].DistributionMap();
383 
384  // First, copy any of the conserved state variables into the output plotfile
385  for (int i = 0; i < cons_names.size(); ++i) {
386  if (containerHasElement(plot_var_names, cons_names[i])) {
387  MultiFab::Copy(mf[lev],vars_new[lev][Vars::cons],i,mf_comp,1,0);
388  mf_comp++;
389  }
390  }
391 
392  // Next, check for velocities
393  if (containerHasElement(plot_var_names, "x_velocity")) {
394  MultiFab::Copy(mf[lev], mf_cc_vel[lev], 0, mf_comp, 1, 0);
395  mf_comp += 1;
396  }
397  if (containerHasElement(plot_var_names, "y_velocity")) {
398  MultiFab::Copy(mf[lev], mf_cc_vel[lev], 1, mf_comp, 1, 0);
399  mf_comp += 1;
400  }
401  if (containerHasElement(plot_var_names, "z_velocity")) {
402  MultiFab::Copy(mf[lev], mf_cc_vel[lev], 2, mf_comp, 1, 0);
403  mf_comp += 1;
404  }
405 
406  // Finally, check for any derived quantities and compute them, inserting
407  // them into our output multifab
408  auto calculate_derived = [&](const std::string& der_name,
409  MultiFab& src_mf,
410  decltype(derived::erf_dernull)& der_function)
411  {
412  if (containerHasElement(plot_var_names, der_name)) {
413  MultiFab dmf(mf[lev], make_alias, mf_comp, 1);
414 #ifdef _OPENMP
415 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
416 #endif
417  for (MFIter mfi(dmf, TilingIfNotGPU()); mfi.isValid(); ++mfi)
418  {
419  const Box& bx = mfi.tilebox();
420  auto& dfab = dmf[mfi];
421  auto& sfab = src_mf[mfi];
422  der_function(bx, dfab, 0, 1, sfab, Geom(lev), t_new[0], nullptr, lev);
423  }
424 
425  mf_comp++;
426  }
427  };
428 
429  bool ismoist = (solverChoice.moisture_type != MoistureType::None);
430 
431  // Note: All derived variables must be computed in order of "derived_names" defined in ERF.H
432  calculate_derived("soundspeed", vars_new[lev][Vars::cons], derived::erf_dersoundspeed);
433  if (ismoist) {
434  calculate_derived("temp", vars_new[lev][Vars::cons], derived::erf_dermoisttemp);
435  } else {
436  calculate_derived("temp", vars_new[lev][Vars::cons], derived::erf_dertemp);
437  }
438  calculate_derived("theta", vars_new[lev][Vars::cons], derived::erf_dertheta);
439  calculate_derived("KE", vars_new[lev][Vars::cons], derived::erf_derKE);
440  calculate_derived("scalar", vars_new[lev][Vars::cons], derived::erf_derscalar);
441  calculate_derived("vorticity_x", mf_cc_vel[lev] , derived::erf_dervortx);
442  calculate_derived("vorticity_y", mf_cc_vel[lev] , derived::erf_dervorty);
443  calculate_derived("vorticity_z", mf_cc_vel[lev] , derived::erf_dervortz);
444  calculate_derived("magvel" , mf_cc_vel[lev] , derived::erf_dermagvel);
445 
446  MultiFab r_hse(base_state[lev], make_alias, BaseState::r0_comp , 1);
447  MultiFab p_hse(base_state[lev], make_alias, BaseState::p0_comp , 1);
448  MultiFab th_hse(base_state[lev], make_alias, BaseState::th0_comp, 1);
449 
450  MultiFab pressure;
451 
452  if (solverChoice.anelastic[lev] == 0) {
453  if (containerHasElement(plot_var_names, "pressure") ||
454  containerHasElement(plot_var_names, "pert_pres") ||
455  containerHasElement(plot_var_names, "dpdx") ||
456  containerHasElement(plot_var_names, "dpdy") ||
457  containerHasElement(plot_var_names, "dpdz"))
458  {
459  int ng = (containerHasElement(plot_var_names, "dpdx") || containerHasElement(plot_var_names, "dpdy") ||
460  containerHasElement(plot_var_names, "dpdz")) ? 1 : 0;
461 
462  // Allocate space for pressure
463  pressure.define(ba,dm,1,ng);
464 
465  if (ng > 0) {
466  // Default to p_hse as a way of filling ghost cells at domain boundaries
467  MultiFab::Copy(pressure,p_hse,0,0,1,1);
468  }
469 #ifdef _OPENMP
470 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
471  #endif
472  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
473  {
474  const Box& gbx = mfi.growntilebox(IntVect(ng,ng,0));
475 
476  const Array4<Real >& p_arr = pressure.array(mfi);
477  const Array4<Real const>& S_arr = vars_new[lev][Vars::cons].const_array(mfi);
478  const int ncomp = vars_new[lev][Vars::cons].nComp();
479 
480  ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
481  {
482  Real qv_for_p = (use_moisture && (ncomp > RhoQ1_comp)) ? S_arr(i,j,k,RhoQ1_comp)/S_arr(i,j,k,Rho_comp) : 0;
483  const Real rhotheta = S_arr(i,j,k,RhoTheta_comp);
484  p_arr(i, j, k) = getPgivenRTh(rhotheta,qv_for_p);
485  });
486  } // mfi
487  pressure.FillBoundary(geom[lev].periodicity());
488  } // compute compressible pressure
489  } // not anelastic
490  else {
491  // Copy p_hse into pressure if using anelastic
492  pressure.define(ba,dm,1,0);
493  MultiFab::Copy(pressure,p_hse,0,0,1,0);
494  }
495 
496  if (containerHasElement(plot_var_names, "divU"))
497  {
498  MultiFab dmf(mf[lev], make_alias, mf_comp, 1);
499  Array<MultiFab const*, AMREX_SPACEDIM> u;
500  u[0] = &(vars_new[lev][Vars::xvel]);
501  u[1] = &(vars_new[lev][Vars::yvel]);
502  u[2] = &(vars_new[lev][Vars::zvel]);
503  compute_divergence (lev, dmf, u, geom[lev]);
504  mf_comp += 1;
505  }
506 
507  if (containerHasElement(plot_var_names, "pres_hse"))
508  {
509  MultiFab::Copy(mf[lev],p_hse,0,mf_comp,1,0);
510  mf_comp += 1;
511  }
512  if (containerHasElement(plot_var_names, "dens_hse"))
513  {
514  MultiFab::Copy(mf[lev],r_hse,0,mf_comp,1,0);
515  mf_comp += 1;
516  }
517  if (containerHasElement(plot_var_names, "theta_hse"))
518  {
519  MultiFab::Copy(mf[lev],th_hse,0,mf_comp,1,0);
520  mf_comp += 1;
521  }
522 
523  if (containerHasElement(plot_var_names, "pressure"))
524  {
525  if (solverChoice.anelastic[lev] == 1) {
526  MultiFab::Copy(mf[lev], p_hse, 0, mf_comp, 1, 0);
527  } else {
528  MultiFab::Copy(mf[lev], pressure, 0, mf_comp, 1, 0);
529  }
530 
531  mf_comp += 1;
532  } // pressure
533 
534  if (containerHasElement(plot_var_names, "pert_pres"))
535  {
536  if (solverChoice.anelastic[lev] == 1) {
537  MultiFab::Copy(mf[lev], pp_inc[lev], 0, mf_comp, 1, 0);
538  } else {
539  MultiFab::Copy(mf[lev], pressure, 0, mf_comp, 1, 0);
540  MultiFab::Subtract(mf[lev],p_hse,0,mf_comp,1,IntVect{0});
541  }
542  mf_comp += 1;
543  }
544 
545  if (containerHasElement(plot_var_names, "pert_dens"))
546  {
547 #ifdef _OPENMP
548 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
549 #endif
550  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
551  {
552  const Box& bx = mfi.tilebox();
553  const Array4<Real>& derdat = mf[lev].array(mfi);
554  const Array4<Real const>& S_arr = vars_new[lev][Vars::cons].const_array(mfi);
555  const Array4<Real const>& r0_arr = r_hse.const_array(mfi);
556  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
557  derdat(i, j, k, mf_comp) = S_arr(i,j,k,Rho_comp) - r0_arr(i,j,k);
558  });
559  }
560  mf_comp ++;
561  }
562 
563  if (containerHasElement(plot_var_names, "eq_pot_temp"))
564  {
565 #ifdef _OPENMP
566 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
567 #endif
568  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
569  {
570  const Box& bx = mfi.tilebox();
571  const Array4<Real>& derdat = mf[lev].array(mfi);
572  const Array4<Real const>& S_arr = vars_new[lev][Vars::cons].const_array(mfi);
573  const Array4<Real const>& p_arr = pressure.const_array(mfi);
574  const int ncomp = vars_new[lev][Vars::cons].nComp();
575  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
576  Real qv = (use_moisture && (ncomp > RhoQ1_comp)) ? S_arr(i,j,k,RhoQ1_comp)/S_arr(i,j,k,Rho_comp) : 0.0;
577  Real qc = (use_moisture && (ncomp > RhoQ2_comp)) ? S_arr(i,j,k,RhoQ2_comp)/S_arr(i,j,k,Rho_comp) : 0.0;
578  Real T = getTgivenRandRTh(S_arr(i,j,k,Rho_comp), S_arr(i,j,k,RhoTheta_comp), qv);
579  Real fac = Cp_d + Cp_l*(qv + qc);
580  Real pv = erf_esatw(T)*100.0;
581 
582  derdat(i, j, k, mf_comp) = T*std::pow((p_arr(i,j,k) - pv)/p_0, -R_d/fac)*std::exp(L_v*qv/(fac*T)) ;
583  });
584  }
585  mf_comp ++;
586  }
587 
588  if (containerHasElement(plot_var_names, "terrain_IB_mask"))
589  {
590  MultiFab* terrain_blank = terrain_blanking[lev].get();
591  MultiFab::Copy(mf[lev],*terrain_blank,0,mf_comp,1,0);
592  mf_comp ++;
593  }
594 
595 #ifdef ERF_USE_WINDFARM
596  if ( containerHasElement(plot_var_names, "num_turb") and
597  (solverChoice.windfarm_type == WindFarmType::Fitch or solverChoice.windfarm_type == WindFarmType::EWP or
598  solverChoice.windfarm_type == WindFarmType::SimpleAD or solverChoice.windfarm_type == WindFarmType::GeneralAD) )
599  {
600  MultiFab::Copy(mf[lev],Nturb[lev],0,mf_comp,1,0);
601  mf_comp ++;
602  }
603 
604  if ( containerHasElement(plot_var_names, "SMark0") and
605  (solverChoice.windfarm_type == WindFarmType::Fitch or solverChoice.windfarm_type == WindFarmType::EWP or
606  solverChoice.windfarm_type == WindFarmType::SimpleAD or solverChoice.windfarm_type == WindFarmType::GeneralAD) )
607  {
608  MultiFab::Copy(mf[lev],SMark[lev],0,mf_comp,1,0);
609  mf_comp ++;
610  }
611 
612  if (containerHasElement(plot_var_names, "SMark1") and
613  (solverChoice.windfarm_type == WindFarmType::SimpleAD or solverChoice.windfarm_type == WindFarmType::GeneralAD))
614  {
615  MultiFab::Copy(mf[lev],SMark[lev],1,mf_comp,1,0);
616  mf_comp ++;
617  }
618 
619 #endif
620 
621  // **********************************************************************************************
622  // Allocate space if we are computing any pressure gradients
623  // **********************************************************************************************
624 
625  Vector<MultiFab> gradp_temp; gradp_temp.resize(AMREX_SPACEDIM);
626  if (containerHasElement(plot_var_names, "dpdx") ||
627  containerHasElement(plot_var_names, "dpdy") ||
628  containerHasElement(plot_var_names, "dpdz") ||
629  containerHasElement(plot_var_names, "pres_hse_x") ||
630  containerHasElement(plot_var_names, "pres_hse_y"))
631  {
632  gradp_temp[GpVars::gpx].define(convert(ba, IntVect(1,0,0)), dm, 1, 1); gradp_temp[GpVars::gpx].setVal(0.);
633  gradp_temp[GpVars::gpy].define(convert(ba, IntVect(0,1,0)), dm, 1, 1); gradp_temp[GpVars::gpy].setVal(0.);
634  gradp_temp[GpVars::gpz].define(convert(ba, IntVect(0,0,1)), dm, 1, 1); gradp_temp[GpVars::gpz].setVal(0.);
635  }
636 
637  // **********************************************************************************************
638  // These are based on computing gradient of full pressure
639  // **********************************************************************************************
640 
641  if (solverChoice.anelastic[lev] == 0) {
642  if ( (containerHasElement(plot_var_names, "dpdx")) ||
643  (containerHasElement(plot_var_names, "dpdy")) ||
644  (containerHasElement(plot_var_names, "dpdz")) ) {
645  BCRec const* bcrec_ptr = domain_bcs_type_d.data();
646  compute_gradp(pressure, geom[lev], *z_phys_nd[lev].get(), *z_phys_cc[lev].get(), bcrec_ptr, get_eb(lev), gradp_temp, solverChoice);
647  }
648  }
649 
650  if (containerHasElement(plot_var_names, "dpdx"))
651  {
652  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
653  {
654  const Box& bx = mfi.tilebox();
655  const Array4<Real >& derdat = mf[lev].array(mfi);
656  const Array4<Real const>& gpx_arr = (solverChoice.anelastic[lev] == 1) ?
657  gradp[lev][GpVars::gpx].array(mfi) : gradp_temp[GpVars::gpx].array(mfi);
658  const Array4<Real const>& mf_mx_arr = mapfac[lev][MapFacType::m_x]->const_array(mfi);
659  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
660  derdat(i ,j ,k, mf_comp) = 0.5 * (gpx_arr(i+1,j,k) + gpx_arr(i,j,k)) * mf_mx_arr(i,j,0);
661  });
662  }
663  mf_comp ++;
664  } // dpdx
665  if (containerHasElement(plot_var_names, "dpdy"))
666  {
667  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
668  {
669  const Box& bx = mfi.tilebox();
670  const Array4<Real >& derdat = mf[lev].array(mfi);
671  const Array4<Real const>& gpy_arr = (solverChoice.anelastic[lev] == 1) ?
672  gradp[lev][GpVars::gpy].array(mfi) : gradp_temp[GpVars::gpy].array(mfi);
673  const Array4<Real const>& mf_my_arr = mapfac[lev][MapFacType::m_y]->const_array(mfi);
674  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
675  derdat(i ,j ,k, mf_comp) = 0.5 * (gpy_arr(i,j+1,k) + gpy_arr(i,j,k)) * mf_my_arr(i,j,0);
676  });
677  }
678  mf_comp ++;
679  } // dpdy
680  if (containerHasElement(plot_var_names, "dpdz"))
681  {
682  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
683  {
684  const Box& bx = mfi.tilebox();
685  const Array4<Real >& derdat = mf[lev].array(mfi);
686  const Array4<Real const>& gpz_arr = (solverChoice.anelastic[lev] == 1) ?
687  gradp[lev][GpVars::gpz].array(mfi) : gradp_temp[GpVars::gpz].array(mfi);
688  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
689  derdat(i ,j ,k, mf_comp) = 0.5 * (gpz_arr(i,j,k+1) + gpz_arr(i,j,k));
690  });
691  }
692  mf_comp ++;
693  } // dpdz
694 
695  // **********************************************************************************************
696  // These are based on computing gradient of basestate pressure
697  // **********************************************************************************************
698 
699  if ( (containerHasElement(plot_var_names, "pres_hse_x")) ||
700  (containerHasElement(plot_var_names, "pres_hse_y")) ) {
701  BCRec const* bcrec_ptr = domain_bcs_type_d.data();
702  compute_gradp(p_hse, geom[lev], *z_phys_nd[lev].get(), *z_phys_cc[lev].get(), bcrec_ptr, get_eb(lev), gradp_temp, solverChoice);
703  }
704 
705  if (containerHasElement(plot_var_names, "pres_hse_x"))
706  {
707  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
708  {
709  const Box& bx = mfi.tilebox();
710  const Array4<Real >& derdat = mf[lev].array(mfi);
711  const Array4<Real const>& gpx_arr = gradp_temp[0].array(mfi);
712  const Array4<Real const>& mf_mx_arr = mapfac[lev][MapFacType::m_x]->const_array(mfi);
713  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
714  derdat(i ,j ,k, mf_comp) = 0.5 * (gpx_arr(i+1,j,k) + gpx_arr(i,j,k)) * mf_mx_arr(i,j,0);
715  });
716  }
717  mf_comp += 1;
718  } // pres_hse_x
719 
720  if (containerHasElement(plot_var_names, "pres_hse_y"))
721  {
722  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
723  {
724  const Box& bx = mfi.tilebox();
725  const Array4<Real >& derdat = mf[lev].array(mfi);
726  const Array4<Real const>& gpy_arr = gradp_temp[1].array(mfi);
727  const Array4<Real const>& mf_my_arr = mapfac[lev][MapFacType::m_y]->const_array(mfi);
728  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
729  derdat(i ,j ,k, mf_comp) = 0.5 * (gpy_arr(i,j+1,k) + gpy_arr(i,j,k)) * mf_my_arr(i,j,0);
730  });
731  }
732  mf_comp += 1;
733  } // pres_hse_y
734 
735  // **********************************************************************************************
736  // Metric terms
737  // **********************************************************************************************
738 
739  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
740  if (containerHasElement(plot_var_names, "z_phys"))
741  {
742  MultiFab::Copy(mf[lev],*z_phys_cc[lev],0,mf_comp,1,0);
743  mf_comp ++;
744  }
745 
746  if (containerHasElement(plot_var_names, "detJ"))
747  {
748  MultiFab::Copy(mf[lev],*detJ_cc[lev],0,mf_comp,1,0);
749  mf_comp ++;
750  }
751  } // use_terrain
752 
753  if (containerHasElement(plot_var_names, "mapfac")) {
754 #ifdef _OPENMP
755 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
756 #endif
757  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
758  {
759  const Box& bx = mfi.tilebox();
760  const Array4<Real>& derdat = mf[lev].array(mfi);
761  const Array4<Real>& mf_m = mapfac[lev][MapFacType::m_x]->array(mfi);
762  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
763  derdat(i ,j ,k, mf_comp) = mf_m(i,j,0);
764  });
765  }
766  mf_comp ++;
767  }
768 
769 #ifdef ERF_USE_NETCDF
771  if (containerHasElement(plot_var_names, "lat_m")) {
772 #ifdef _OPENMP
773 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
774 #endif
775  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
776  {
777  const Box& bx = mfi.tilebox();
778  const Array4<Real>& derdat = mf[lev].array(mfi);
779  const Array4<Real>& data = lat_m[lev]->array(mfi);
780  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
781  derdat(i, j, k, mf_comp) = data(i,j,0);
782  });
783  }
784  mf_comp ++;
785  } // lat_m
786 
787  if (containerHasElement(plot_var_names, "lon_m")) {
788 #ifdef _OPENMP
789 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
790 #endif
791  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
792  {
793  const Box& bx = mfi.tilebox();
794  const Array4<Real>& derdat = mf[lev].array(mfi);
795  const Array4<Real>& data = lon_m[lev]->array(mfi);
796  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
797  derdat(i, j, k, mf_comp) = data(i,j,0);
798  });
799  }
800  mf_comp ++;
801  } // lon_m
802  } // use_real_bcs
803 #endif
804 
805 
807  if (containerHasElement(plot_var_names, "u_t_avg")) {
808 #ifdef _OPENMP
809 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
810 #endif
811  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
812  {
813  const Box& bx = mfi.tilebox();
814  const Array4<Real>& derdat = mf[lev].array(mfi);
815  const Array4<Real>& data = vel_t_avg[lev]->array(mfi);
816  const Real norm = t_avg_cnt[lev];
817  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
818  {
819  derdat(i ,j ,k, mf_comp) = data(i,j,k,0) / norm;
820  });
821  }
822  mf_comp ++;
823  }
824 
825  if (containerHasElement(plot_var_names, "v_t_avg")) {
826 #ifdef _OPENMP
827 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
828 #endif
829  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
830  {
831  const Box& bx = mfi.tilebox();
832  const Array4<Real>& derdat = mf[lev].array(mfi);
833  const Array4<Real>& data = vel_t_avg[lev]->array(mfi);
834  const Real norm = t_avg_cnt[lev];
835  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
836  {
837  derdat(i ,j ,k, mf_comp) = data(i,j,k,1) / norm;
838  });
839  }
840  mf_comp ++;
841  }
842 
843  if (containerHasElement(plot_var_names, "w_t_avg")) {
844 #ifdef _OPENMP
845 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
846 #endif
847  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
848  {
849  const Box& bx = mfi.tilebox();
850  const Array4<Real>& derdat = mf[lev].array(mfi);
851  const Array4<Real>& data = vel_t_avg[lev]->array(mfi);
852  const Real norm = t_avg_cnt[lev];
853  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
854  {
855  derdat(i ,j ,k, mf_comp) = data(i,j,k,2) / norm;
856  });
857  }
858  mf_comp ++;
859  }
860 
861  if (containerHasElement(plot_var_names, "umag_t_avg")) {
862 #ifdef _OPENMP
863 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
864 #endif
865  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
866  {
867  const Box& bx = mfi.tilebox();
868  const Array4<Real>& derdat = mf[lev].array(mfi);
869  const Array4<Real>& data = vel_t_avg[lev]->array(mfi);
870  const Real norm = t_avg_cnt[lev];
871  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
872  {
873  derdat(i ,j ,k, mf_comp) = data(i,j,k,3) / norm;
874  });
875  }
876  mf_comp ++;
877  }
878  }
879 
880  if (containerHasElement(plot_var_names, "nut")) {
881  MultiFab dmf(mf[lev], make_alias, mf_comp, 1);
882  MultiFab cmf(vars_new[lev][Vars::cons], make_alias, 0, 1); // to provide rho only
883 #ifdef _OPENMP
884 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
885 #endif
886  for (MFIter mfi(dmf, TilingIfNotGPU()); mfi.isValid(); ++mfi)
887  {
888  const Box& bx = mfi.tilebox();
889  auto prim = dmf[mfi].array();
890  auto const cons = cmf[mfi].const_array();
891  auto const diff = (*eddyDiffs_lev[lev])[mfi].const_array();
892  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
893  {
894  const Real rho = cons(i, j, k, Rho_comp);
895  const Real Kmv = diff(i, j, k, EddyDiff::Mom_v);
896  prim(i,j,k) = Kmv / rho;
897  });
898  }
899 
900  mf_comp++;
901  }
902 
903  if (containerHasElement(plot_var_names, "Kmv")) {
904  MultiFab::Copy(mf[lev],*eddyDiffs_lev[lev],EddyDiff::Mom_v,mf_comp,1,0);
905  mf_comp ++;
906  }
907  if (containerHasElement(plot_var_names, "Kmh")) {
908  MultiFab::Copy(mf[lev],*eddyDiffs_lev[lev],EddyDiff::Mom_h,mf_comp,1,0);
909  mf_comp ++;
910  }
911  if (containerHasElement(plot_var_names, "Khv")) {
912  MultiFab::Copy(mf[lev],*eddyDiffs_lev[lev],EddyDiff::Theta_v,mf_comp,1,0);
913  mf_comp ++;
914  }
915  if (containerHasElement(plot_var_names, "Khh")) {
916  MultiFab::Copy(mf[lev],*eddyDiffs_lev[lev],EddyDiff::Theta_h,mf_comp,1,0);
917  mf_comp ++;
918  }
919  if (containerHasElement(plot_var_names, "Lturb")) {
920  MultiFab::Copy(mf[lev],*eddyDiffs_lev[lev],EddyDiff::Turb_lengthscale,mf_comp,1,0);
921  mf_comp ++;
922  }
923  if (containerHasElement(plot_var_names, "walldist")) {
924  MultiFab::Copy(mf[lev],*walldist[lev],0,mf_comp,1,0);
925  mf_comp ++;
926  }
927  if (containerHasElement(plot_var_names, "diss")) {
928  MultiFab::Copy(mf[lev],*SFS_diss_lev[lev],0,mf_comp,1,0);
929  mf_comp ++;
930  }
931 
932  // TODO: The size of the q variables can vary with different
933  // moisture models. Therefore, certain components may
934  // reside at different indices. For example, Kessler is
935  // warm but precipitating. This puts qp at index 3.
936  // However, SAM is cold and precipitating so qp is index 4.
937  // Need to built an external enum struct or a better pathway.
938 
939  // NOTE: Protect against accessing non-existent data
940  if (use_moisture) {
941  int n_qstate_moist = micro->Get_Qstate_Moist_Size();
942 
943  // Moist density
944  if(containerHasElement(plot_var_names, "moist_density"))
945  {
946  int n_start = RhoQ1_comp; // qv
947  int n_end = RhoQ2_comp; // qc
948  if (n_qstate_moist > 3) n_end = RhoQ3_comp; // qi
949  MultiFab::Copy( mf[lev], vars_new[lev][Vars::cons], Rho_comp, mf_comp, 1, 0);
950  for (int n_comp(n_start); n_comp <= n_end; ++n_comp) {
951  MultiFab::Add(mf[lev], vars_new[lev][Vars::cons], n_comp, mf_comp, 1, 0);
952  }
953  mf_comp += 1;
954  }
955 
956  if(containerHasElement(plot_var_names, "qv") && (n_qstate_moist >= 1))
957  {
958  MultiFab::Copy( mf[lev], vars_new[lev][Vars::cons], RhoQ1_comp, mf_comp, 1, 0);
959  MultiFab::Divide(mf[lev], vars_new[lev][Vars::cons], Rho_comp , mf_comp, 1, 0);
960  mf_comp += 1;
961  }
962 
963  if(containerHasElement(plot_var_names, "qc") && (n_qstate_moist >= 2))
964  {
965  MultiFab::Copy( mf[lev], vars_new[lev][Vars::cons], RhoQ2_comp, mf_comp, 1, 0);
966  MultiFab::Divide(mf[lev], vars_new[lev][Vars::cons], Rho_comp , mf_comp, 1, 0);
967  mf_comp += 1;
968  }
969 
970  if(containerHasElement(plot_var_names, "qi") && (n_qstate_moist >= 4))
971  {
972  MultiFab::Copy( mf[lev], vars_new[lev][Vars::cons], RhoQ3_comp, mf_comp, 1, 0);
973  MultiFab::Divide(mf[lev], vars_new[lev][Vars::cons], Rho_comp , mf_comp, 1, 0);
974  mf_comp += 1;
975  }
976 
977  if(containerHasElement(plot_var_names, "qrain") && (n_qstate_moist >= 3))
978  {
979  int n_start = (n_qstate_moist > 3) ? RhoQ4_comp : RhoQ3_comp;
980  MultiFab::Copy( mf[lev], vars_new[lev][Vars::cons], n_start , mf_comp, 1, 0);
981  MultiFab::Divide(mf[lev], vars_new[lev][Vars::cons], Rho_comp, mf_comp, 1, 0);
982  mf_comp += 1;
983  }
984 
985  if(containerHasElement(plot_var_names, "qsnow") && (n_qstate_moist >= 5))
986  {
987  MultiFab::Copy( mf[lev], vars_new[lev][Vars::cons], RhoQ5_comp, mf_comp, 1, 0);
988  MultiFab::Divide(mf[lev], vars_new[lev][Vars::cons], Rho_comp, mf_comp, 1, 0);
989  mf_comp += 1;
990  }
991 
992  if(containerHasElement(plot_var_names, "qgraup") && (n_qstate_moist >= 6))
993  {
994  MultiFab::Copy( mf[lev], vars_new[lev][Vars::cons], RhoQ6_comp, mf_comp, 1, 0);
995  MultiFab::Divide(mf[lev], vars_new[lev][Vars::cons], Rho_comp, mf_comp, 1, 0);
996  mf_comp += 1;
997  }
998 
999  // Precipitating + non-precipitating components
1000  //--------------------------------------------------------------------------
1001  if(containerHasElement(plot_var_names, "qt"))
1002  {
1003  int n_start = RhoQ1_comp; // qv
1004  int n_end = n_qstate_moist;
1005  MultiFab::Copy(mf[lev], vars_new[lev][Vars::cons], n_start, mf_comp, 1, 0);
1006  for (int n_comp(n_start+1); n_comp <= n_end; ++n_comp) {
1007  MultiFab::Add(mf[lev], vars_new[lev][Vars::cons], n_comp, mf_comp, 1, 0);
1008  }
1009  MultiFab::Divide(mf[lev], vars_new[lev][Vars::cons], Rho_comp , mf_comp, 1, 0);
1010  mf_comp += 1;
1011  }
1012 
1013  // Non-precipitating components
1014  //--------------------------------------------------------------------------
1015  if (containerHasElement(plot_var_names, "qn"))
1016  {
1017  int n_start = RhoQ1_comp; // qv
1018  int n_end = RhoQ2_comp; // qc
1019  if (n_qstate_moist > 3) n_end = RhoQ3_comp; // qi
1020  MultiFab::Copy( mf[lev], vars_new[lev][Vars::cons], n_start, mf_comp, 1, 0);
1021  for (int n_comp(n_start+1); n_comp <= n_end; ++n_comp) {
1022  MultiFab::Add(mf[lev], vars_new[lev][Vars::cons], n_comp, mf_comp, 1, 0);
1023  }
1024  MultiFab::Divide(mf[lev], vars_new[lev][Vars::cons], Rho_comp , mf_comp, 1, 0);
1025  mf_comp += 1;
1026  }
1027 
1028  // Precipitating components
1029  //--------------------------------------------------------------------------
1030  if(containerHasElement(plot_var_names, "qp") && (n_qstate_moist >= 3))
1031  {
1032  int n_start = (n_qstate_moist > 3) ? RhoQ4_comp : RhoQ3_comp;
1033  int n_end = ncomp_cons - 1;
1034  MultiFab::Copy( mf[lev], vars_new[lev][Vars::cons], n_start, mf_comp, 1, 0);
1035  for (int n_comp(n_start+1); n_comp <= n_end; ++n_comp) {
1036  MultiFab::Add( mf[lev], vars_new[lev][Vars::cons], n_comp, mf_comp, 1, 0);
1037  }
1038  MultiFab::Divide(mf[lev], vars_new[lev][Vars::cons], Rho_comp , mf_comp, 1, 0);
1039  mf_comp += 1;
1040  }
1041 
1042  if (containerHasElement(plot_var_names, "qsat"))
1043  {
1044 #ifdef _OPENMP
1045 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1046 #endif
1047  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
1048  {
1049  const Box& bx = mfi.tilebox();
1050  const Array4<Real>& derdat = mf[lev].array(mfi);
1051  const Array4<Real const>& p_arr = pressure.array(mfi);
1052  const Array4<Real const>& S_arr = vars_new[lev][Vars::cons].const_array(mfi);
1053  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1054  {
1055  Real qv = S_arr(i,j,k,RhoQ1_comp) / S_arr(i,j,k,Rho_comp);
1056  Real T = getTgivenRandRTh(S_arr(i,j,k,Rho_comp), S_arr(i,j,k,RhoTheta_comp), qv);
1057  Real p = p_arr(i,j,k) * Real(0.01);
1058  erf_qsatw(T, p, derdat(i,j,k,mf_comp));
1059  });
1060  }
1061  mf_comp ++;
1062  }
1063 
1064  if ( (solverChoice.moisture_type == MoistureType::Kessler) ||
1065  (solverChoice.moisture_type == MoistureType::Morrison_NoIce) ||
1066  (solverChoice.moisture_type == MoistureType::SAM_NoIce) )
1067  {
1068  int offset = (solverChoice.moisture_type == MoistureType::Morrison_NoIce) ? 5 : 0;
1069  if (containerHasElement(plot_var_names, "rain_accum"))
1070  {
1071  MultiFab::Copy(mf[lev],*(qmoist[lev][offset]),0,mf_comp,1,0);
1072  mf_comp += 1;
1073  }
1074  }
1075  else if ( (solverChoice.moisture_type == MoistureType::SAM) ||
1076  (solverChoice.moisture_type == MoistureType::Morrison) )
1077  {
1078  int offset = (solverChoice.moisture_type == MoistureType::Morrison) ? 5 : 0;
1079  if (containerHasElement(plot_var_names, "rain_accum"))
1080  {
1081  MultiFab::Copy(mf[lev],*(qmoist[lev][offset]),0,mf_comp,1,0);
1082  mf_comp += 1;
1083  }
1084  if (containerHasElement(plot_var_names, "snow_accum"))
1085  {
1086  MultiFab::Copy(mf[lev],*(qmoist[lev][offset+1]),0,mf_comp,1,0);
1087  mf_comp += 1;
1088  }
1089  if (containerHasElement(plot_var_names, "graup_accum"))
1090  {
1091  MultiFab::Copy(mf[lev],*(qmoist[lev][offset+2]),0,mf_comp,1,0);
1092  mf_comp += 1;
1093  }
1094  }
1095  } // use_moisture
1096 
1097 #ifdef ERF_USE_PARTICLES
1098  const auto& particles_namelist( particleData.getNames() );
1099  for (ParticlesNamesVector::size_type i = 0; i < particles_namelist.size(); i++) {
1100  if (containerHasElement(plot_var_names, std::string(particles_namelist[i]+"_count"))) {
1101  MultiFab temp_dat(mf[lev].boxArray(), mf[lev].DistributionMap(), 1, 0);
1102  temp_dat.setVal(0);
1103  particleData[particles_namelist[i]]->Increment(temp_dat, lev);
1104  MultiFab::Copy(mf[lev], temp_dat, 0, mf_comp, 1, 0);
1105  mf_comp += 1;
1106  }
1107  }
1108 
1109  Vector<std::string> particle_mesh_plot_names(0);
1110  particleData.GetMeshPlotVarNames( particle_mesh_plot_names );
1111  for (int i = 0; i < particle_mesh_plot_names.size(); i++) {
1112  std::string plot_var_name(particle_mesh_plot_names[i]);
1113  if (containerHasElement(plot_var_names, plot_var_name) ) {
1114  MultiFab temp_dat(mf[lev].boxArray(), mf[lev].DistributionMap(), 1, 1);
1115  temp_dat.setVal(0);
1116  particleData.GetMeshPlotVar(plot_var_name, temp_dat, lev);
1117  MultiFab::Copy(mf[lev], temp_dat, 0, mf_comp, 1, 0);
1118  mf_comp += 1;
1119  }
1120  }
1121 #endif
1122 
1123  {
1124  Vector<std::string> microphysics_plot_names;
1125  micro->GetPlotVarNames(microphysics_plot_names);
1126  for (auto& plot_name : microphysics_plot_names) {
1127  if (containerHasElement(plot_var_names, plot_name)) {
1128  MultiFab temp_dat(mf[lev].boxArray(), mf[lev].DistributionMap(), 1, 1);
1129  temp_dat.setVal(0);
1130  micro->GetPlotVar(plot_name, temp_dat, lev);
1131  MultiFab::Copy(mf[lev], temp_dat, 0, mf_comp, 1, 0);
1132  mf_comp += 1;
1133  }
1134  }
1135  }
1136 
1137  if (containerHasElement(plot_var_names, "volfrac")) {
1138  if ( solverChoice.terrain_type == TerrainType::EB ||
1139  solverChoice.terrain_type == TerrainType::ImmersedForcing)
1140  {
1141  MultiFab::Copy(mf[lev], EBFactory(lev).getVolFrac(), 0, mf_comp, 1, 0);
1142  } else {
1143  mf[lev].setVal(1.0, mf_comp, 1, 0);
1144  }
1145  mf_comp += 1;
1146  }
1147 
1148 #ifdef ERF_COMPUTE_ERROR
1149  // Next, check for error in velocities and if desired, output them -- note we output none or all, not just some
1150  if (containerHasElement(plot_var_names, "xvel_err") ||
1151  containerHasElement(plot_var_names, "yvel_err") ||
1152  containerHasElement(plot_var_names, "zvel_err"))
1153  {
1154  //
1155  // Moving terrain ANALYTICAL
1156  //
1157  Real H = geom[lev].ProbHi()[2];
1158  Real Ampl = 0.16;
1159  Real wavelength = 100.;
1160  Real kp = 2. * PI / wavelength;
1161  Real g = CONST_GRAV;
1162  Real omega = std::sqrt(g * kp);
1163  Real omega_t = omega * t_new[lev];
1164 
1165  const auto dx = geom[lev].CellSizeArray();
1166 
1167 #ifdef _OPENMP
1168 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1169 #endif
1170  for (MFIter mfi(mf[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi)
1171  {
1172  const Box& bx = mfi.validbox();
1173  Box xbx(bx); xbx.surroundingNodes(0);
1174  const Array4<Real> xvel_arr = vars_new[lev][Vars::xvel].array(mfi);
1175  const Array4<Real> zvel_arr = vars_new[lev][Vars::zvel].array(mfi);
1176 
1177  const Array4<Real const>& z_nd = z_phys_nd[lev]->const_array(mfi);
1178 
1179  ParallelFor(xbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
1180  {
1181  Real x = i * dx[0];
1182  Real z = 0.25 * (z_nd(i,j,k) + z_nd(i,j+1,k) + z_nd(i,j,k+1) + z_nd(i,j+1,k+1));
1183 
1184  Real z_base = Ampl * std::sin(kp * x - omega_t);
1185  z -= z_base;
1186 
1187  Real fac = std::cosh( kp * (z - H) ) / std::sinh(kp * H);
1188 
1189  xvel_arr(i,j,k) -= -Ampl * omega * fac * std::sin(kp * x - omega_t);
1190  });
1191 
1192  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
1193  {
1194  Real x = (i + 0.5) * dx[0];
1195  Real z = 0.25 * ( z_nd(i,j,k) + z_nd(i+1,j,k) + z_nd(i,j+1,k) + z_nd(i+1,j+1,k));
1196 
1197  Real z_base = Ampl * std::sin(kp * x - omega_t);
1198  z -= z_base;
1199 
1200  Real fac = std::sinh( kp * (z - H) ) / std::sinh(kp * H);
1201 
1202  zvel_arr(i,j,k) -= Ampl * omega * fac * std::cos(kp * x - omega_t);
1203  });
1204  }
1205 
1206  MultiFab temp_mf(mf[lev].boxArray(), mf[lev].DistributionMap(), AMREX_SPACEDIM, 0);
1207  average_face_to_cellcenter(temp_mf,0,
1208  Array<const MultiFab*,3>{&vars_new[lev][Vars::xvel],&vars_new[lev][Vars::yvel],&vars_new[lev][Vars::zvel]});
1209 
1210  if (containerHasElement(plot_var_names, "xvel_err")) {
1211  MultiFab::Copy(mf[lev],temp_mf,0,mf_comp,1,0);
1212  mf_comp += 1;
1213  }
1214  if (containerHasElement(plot_var_names, "yvel_err")) {
1215  MultiFab::Copy(mf[lev],temp_mf,1,mf_comp,1,0);
1216  mf_comp += 1;
1217  }
1218  if (containerHasElement(plot_var_names, "zvel_err")) {
1219  MultiFab::Copy(mf[lev],temp_mf,2,mf_comp,1,0);
1220  mf_comp += 1;
1221  }
1222 
1223  // Now restore the velocities to what they were
1224 #ifdef _OPENMP
1225 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1226 #endif
1227  for (MFIter mfi(mf[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi)
1228  {
1229  const Box& bx = mfi.validbox();
1230  Box xbx(bx); xbx.surroundingNodes(0);
1231 
1232  const Array4<Real> xvel_arr = vars_new[lev][Vars::xvel].array(mfi);
1233  const Array4<Real> zvel_arr = vars_new[lev][Vars::zvel].array(mfi);
1234 
1235  const Array4<Real const>& z_nd = z_phys_nd[lev]->const_array(mfi);
1236 
1237  ParallelFor(xbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
1238  {
1239  Real x = i * dx[0];
1240  Real z = 0.25 * (z_nd(i,j,k) + z_nd(i,j+1,k) + z_nd(i,j,k+1) + z_nd(i,j+1,k+1));
1241  Real z_base = Ampl * std::sin(kp * x - omega_t);
1242 
1243  z -= z_base;
1244 
1245  Real fac = std::cosh( kp * (z - H) ) / std::sinh(kp * H);
1246  xvel_arr(i,j,k) += -Ampl * omega * fac * std::sin(kp * x - omega_t);
1247  });
1248  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
1249  {
1250  Real x = (i + 0.5) * dx[0];
1251  Real z = 0.25 * ( z_nd(i,j,k) + z_nd(i+1,j,k) + z_nd(i,j+1,k) + z_nd(i+1,j+1,k));
1252  Real z_base = Ampl * std::sin(kp * x - omega_t);
1253 
1254  z -= z_base;
1255  Real fac = std::sinh( kp * (z - H) ) / std::sinh(kp * H);
1256 
1257  zvel_arr(i,j,k) += Ampl * omega * fac * std::cos(kp * x - omega_t);
1258  });
1259  }
1260  } // end xvel_err, yvel_err, zvel_err
1261 
1262  if (containerHasElement(plot_var_names, "pp_err"))
1263  {
1264  // Moving terrain ANALYTICAL
1265 #ifdef _OPENMP
1266 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
1267 #endif
1268  for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
1269  {
1270  const Box& bx = mfi.tilebox();
1271  const Array4<Real>& derdat = mf[lev].array(mfi);
1272  const Array4<Real const>& p0_arr = p_hse.const_array(mfi);
1273  const Array4<Real const>& S_arr = vars_new[lev][Vars::cons].const_array(mfi);
1274 
1275  const auto dx = geom[lev].CellSizeArray();
1276  const Array4<Real const>& z_nd = z_phys_nd[lev]->const_array(mfi);
1277  const Array4<Real const>& p_arr = pressure.const_array(mfi);
1278  const Array4<Real const>& r0_arr = r_hse.const_array(mfi);
1279 
1280  Real H = geom[lev].ProbHi()[2];
1281  Real Ampl = 0.16;
1282  Real wavelength = 100.;
1283  Real kp = 2. * PI / wavelength;
1284  Real g = CONST_GRAV;
1285  Real omega = std::sqrt(g * kp);
1286  Real omega_t = omega * t_new[lev];
1287 
1288  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
1289  {
1290  derdat(i, j, k, mf_comp) = p_arr(i,j,k) - p0_arr(i,j,k);
1291 
1292  Real rho_hse = r0_arr(i,j,k);
1293 
1294  Real x = (i + 0.5) * dx[0];
1295  Real z = 0.125 * ( z_nd(i,j,k ) + z_nd(i+1,j,k ) + z_nd(i,j+1,k ) + z_nd(i+1,j+1,k )
1296  +z_nd(i,j,k+1) + z_nd(i+1,j,k+1) + z_nd(i,j+1,k+1) + z_nd(i+1,j+1,k+1) );
1297  Real z_base = Ampl * std::sin(kp * x - omega_t);
1298 
1299  z -= z_base;
1300  Real fac = std::cosh( kp * (z - H) ) / std::sinh(kp * H);
1301  Real pprime_exact = -(Ampl * omega * omega / kp) * fac *
1302  std::sin(kp * x - omega_t) * r0_arr(i,j,k);
1303 
1304  derdat(i,j,k,mf_comp) -= pprime_exact;
1305  });
1306  }
1307  mf_comp += 1;
1308  }
1309 #endif
1310 
1311  if (solverChoice.rad_type != RadiationType::None) {
1312  if (containerHasElement(plot_var_names, "qsrc_sw")) {
1313  MultiFab::Copy(mf[lev], *(qheating_rates[lev]), 0, mf_comp, 1, 0);
1314  mf_comp += 1;
1315  }
1316  if (containerHasElement(plot_var_names, "qsrc_lw")) {
1317  MultiFab::Copy(mf[lev], *(qheating_rates[lev]), 1, mf_comp, 1, 0);
1318  mf_comp += 1;
1319  }
1320  }
1321 
1322  }
1323 
1324  if (solverChoice.terrain_type == TerrainType::EB)
1325  {
1326  for (int lev = 0; lev <= finest_level; ++lev) {
1327  EB_set_covered(mf[lev], 0.0);
1328  }
1329  }
1330 
1331  // Fill terrain distortion MF (nu_nd)
1332  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
1333  for (int lev(0); lev <= finest_level; ++lev) {
1334  MultiFab::Copy(mf_nd[lev],*z_phys_nd[lev],0,2,1,0);
1335  Real dz = Geom()[lev].CellSizeArray()[2];
1336  for (MFIter mfi(mf_nd[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1337  const Box& bx = mfi.tilebox();
1338  Array4<Real> mf_arr = mf_nd[lev].array(mfi);
1339  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
1340  {
1341  mf_arr(i,j,k,2) -= k * dz;
1342  });
1343  }
1344  }
1345  }
1346 
1347  std::string plotfilename;
1348  std::string plotfilenameU;
1349  std::string plotfilenameV;
1350  std::string plotfilenameW;
1351  if (which == 1) {
1352  plotfilename = Concatenate(plot_file_1, istep[0], 5);
1353  plotfilenameU = Concatenate(plot_file_1+"U", istep[0], 5);
1354  plotfilenameV = Concatenate(plot_file_1+"V", istep[0], 5);
1355  plotfilenameW = Concatenate(plot_file_1+"W", istep[0], 5);
1356  } else if (which == 2) {
1357  plotfilename = Concatenate(plot_file_2, istep[0], 5);
1358  plotfilenameU = Concatenate(plot_file_2+"U", istep[0], 5);
1359  plotfilenameV = Concatenate(plot_file_2+"V", istep[0], 5);
1360  plotfilenameW = Concatenate(plot_file_2+"W", istep[0], 5);
1361  }
1362 
1363  // LSM writes it's own data
1364  if (which==1 && plot_lsm) {
1365  lsm.Plot_Lsm_Data(t_new[0], istep, refRatio());
1366  }
1367 
1368 #ifdef ERF_USE_RRTMGP
1369  /*
1370  // write additional RRTMGP data
1371  // TODO: currently single level only
1372  if (which==1 && plot_rad) {
1373  rad[0]->writePlotfile(plot_file_1, t_new[0], istep[0]);
1374  }
1375  */
1376 #endif
1377 
1378  // Single level
1379  if (finest_level == 0)
1380  {
1381  if (plotfile_type == PlotFileType::Amrex)
1382  {
1383  Print() << "Writing native plotfile " << plotfilename << "\n";
1384  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
1385  WriteMultiLevelPlotfileWithTerrain(plotfilename, finest_level+1,
1386  GetVecOfConstPtrs(mf),
1387  GetVecOfConstPtrs(mf_nd),
1388  varnames,
1389  Geom(), t_new[0], istep, refRatio());
1390  } else {
1391  WriteMultiLevelPlotfile(plotfilename, finest_level+1,
1392  GetVecOfConstPtrs(mf),
1393  varnames,
1394  Geom(), t_new[0], istep, refRatio());
1395  }
1396  writeJobInfo(plotfilename);
1397 
1398  if (m_plot_face_vels) {
1399  Print() << "Writing face velocities" << std::endl;
1400  WriteMultiLevelPlotfile(plotfilenameU, finest_level+1,
1401  GetVecOfConstPtrs(mf_u),
1402  {"x_velocity_stag"},
1403  Geom(), t_new[0], istep, refRatio());
1404  WriteMultiLevelPlotfile(plotfilenameV, finest_level+1,
1405  GetVecOfConstPtrs(mf_v),
1406  {"y_velocity_stag"},
1407  Geom(), t_new[0], istep, refRatio());
1408  WriteMultiLevelPlotfile(plotfilenameW, finest_level+1,
1409  GetVecOfConstPtrs(mf_w),
1410  {"z_velocity_stag"},
1411  Geom(), t_new[0], istep, refRatio());
1412  }
1413 
1414 #ifdef ERF_USE_PARTICLES
1415  particleData.writePlotFile(plotfilename);
1416 #endif
1417 #ifdef ERF_USE_NETCDF
1418  } else if (plotfile_type == PlotFileType::Netcdf) {
1419  AMREX_ALWAYS_ASSERT(solverChoice.terrain_type != TerrainType::StaticFittedMesh);
1420  int lev = 0;
1421  int l_which = 0;
1422  const Real* p_lo = geom[lev].ProbLo();
1423  const Real* p_hi = geom[lev].ProbHi();
1424  const auto dx = geom[lev].CellSize();
1425  writeNCPlotFile(lev, l_which, plotfilename, GetVecOfConstPtrs(mf), varnames, istep,
1426  {p_lo[0],p_lo[1],p_lo[2]},{p_hi[0],p_hi[1],p_hi[2]}, {dx[0],dx[1],dx[2]},
1427  geom[lev].Domain(), t_new[0], start_bdy_time);
1428 #endif
1429  } else {
1430  // Here we assume the plotfile_type is PlotFileType::None
1431  Print() << "Writing no plotfile since plotfile_type is none" << std::endl;
1432  }
1433 
1434  } else { // Multilevel
1435 
1436  if (plotfile_type == PlotFileType::Amrex) {
1437 
1438  int lev0 = 0;
1439  int desired_ratio = std::max(std::max(ref_ratio[lev0][0],ref_ratio[lev0][1]),ref_ratio[lev0][2]);
1440  bool any_ratio_one = ( ( (ref_ratio[lev0][0] == 1) || (ref_ratio[lev0][1] == 1) ) ||
1441  (ref_ratio[lev0][2] == 1) );
1442  for (int lev = 1; lev < finest_level; lev++) {
1443  any_ratio_one = any_ratio_one ||
1444  ( ( (ref_ratio[lev][0] == 1) || (ref_ratio[lev][1] == 1) ) ||
1445  (ref_ratio[lev][2] == 1) );
1446  }
1447 
1448  if (any_ratio_one && m_expand_plotvars_to_unif_rr)
1449  {
1450  Vector<IntVect> r2(finest_level);
1451  Vector<Geometry> g2(finest_level+1);
1452  Vector<MultiFab> mf2(finest_level+1);
1453 
1454  mf2[0].define(grids[0], dmap[0], ncomp_mf, 0);
1455 
1456  // Copy level 0 as is
1457  MultiFab::Copy(mf2[0],mf[0],0,0,mf[0].nComp(),0);
1458 
1459  // Define a new multi-level array of Geometry's so that we pass the new "domain" at lev > 0
1460  Array<int,AMREX_SPACEDIM> periodicity =
1461  {Geom()[lev0].isPeriodic(0),Geom()[lev0].isPeriodic(1),Geom()[lev0].isPeriodic(2)};
1462  g2[lev0].define(Geom()[lev0].Domain(),&(Geom()[lev0].ProbDomain()),0,periodicity.data());
1463 
1464  r2[0] = IntVect(desired_ratio/ref_ratio[lev0][0],
1465  desired_ratio/ref_ratio[lev0][1],
1466  desired_ratio/ref_ratio[lev0][2]);
1467 
1468  for (int lev = 1; lev <= finest_level; ++lev) {
1469  if (lev > 1) {
1470  r2[lev-1][0] = r2[lev-2][0] * desired_ratio / ref_ratio[lev-1][0];
1471  r2[lev-1][1] = r2[lev-2][1] * desired_ratio / ref_ratio[lev-1][1];
1472  r2[lev-1][2] = r2[lev-2][2] * desired_ratio / ref_ratio[lev-1][2];
1473  }
1474 
1475  mf2[lev].define(refine(grids[lev],r2[lev-1]), dmap[lev], ncomp_mf, 0);
1476 
1477  // Set the new problem domain
1478  Box d2(Geom()[lev].Domain());
1479  d2.refine(r2[lev-1]);
1480 
1481  g2[lev].define(d2,&(Geom()[lev].ProbDomain()),0,periodicity.data());
1482  }
1483 
1484  //
1485  // We need to make a temporary that is the size of ncomp_mf
1486  // in order to not get an out of bounds error
1487  // even though the values will not be used
1488  //
1489  Vector<BCRec> temp_domain_bcs_type;
1490  temp_domain_bcs_type.resize(ncomp_mf);
1491 
1492  //
1493  // Do piecewise constant interpolation of mf into mf2
1494  //
1495  for (int lev = 1; lev <= finest_level; ++lev) {
1496  Interpolater* mapper_c = &pc_interp;
1497  InterpFromCoarseLevel(mf2[lev], t_new[lev], mf[lev],
1498  0, 0, ncomp_mf,
1499  geom[lev], g2[lev],
1501  r2[lev-1], mapper_c, temp_domain_bcs_type, 0);
1502  }
1503 
1504  // Define an effective ref_ratio which is isotropic to be passed into WriteMultiLevelPlotfile
1505  Vector<IntVect> rr(finest_level);
1506  for (int lev = 0; lev < finest_level; ++lev) {
1507  rr[lev] = IntVect(desired_ratio);
1508  }
1509 
1510  Print() << "Writing plotfile " << plotfilename << "\n";
1511  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
1512  WriteMultiLevelPlotfileWithTerrain(plotfilename, finest_level+1,
1513  GetVecOfConstPtrs(mf2),
1514  GetVecOfConstPtrs(mf_nd),
1515  varnames,
1516  g2, t_new[0], istep, rr);
1517  } else {
1518  WriteMultiLevelPlotfile(plotfilename, finest_level+1,
1519  GetVecOfConstPtrs(mf2), varnames,
1520  g2, t_new[0], istep, rr);
1521  }
1522 
1523  } else {
1524  if (SolverChoice::mesh_type != MeshType::ConstantDz) {
1525  WriteMultiLevelPlotfileWithTerrain(plotfilename, finest_level+1,
1526  GetVecOfConstPtrs(mf),
1527  GetVecOfConstPtrs(mf_nd),
1528  varnames,
1529  geom, t_new[0], istep, ref_ratio);
1530  } else {
1531  WriteMultiLevelPlotfile(plotfilename, finest_level+1,
1532  GetVecOfConstPtrs(mf), varnames,
1533  geom, t_new[0], istep, ref_ratio);
1534  }
1535  if (m_plot_face_vels) {
1536  Print() << "Writing face velocities" << std::endl;
1537  WriteMultiLevelPlotfile(plotfilenameU, finest_level+1,
1538  GetVecOfConstPtrs(mf_u),
1539  {"x_velocity_stag"},
1540  geom, t_new[0], istep, ref_ratio);
1541  WriteMultiLevelPlotfile(plotfilenameV, finest_level+1,
1542  GetVecOfConstPtrs(mf_v),
1543  {"y_velocity_stag"},
1544  geom, t_new[0], istep, ref_ratio);
1545  WriteMultiLevelPlotfile(plotfilenameW, finest_level+1,
1546  GetVecOfConstPtrs(mf_w),
1547  {"z_velocity_stag"},
1548  geom, t_new[0], istep, ref_ratio);
1549  }
1550  } // ref_ratio test
1551 
1552  writeJobInfo(plotfilename);
1553 
1554 #ifdef ERF_USE_PARTICLES
1555  particleData.writePlotFile(plotfilename);
1556 #endif
1557 
1558 #ifdef ERF_USE_NETCDF
1559  } else if (plotfile_type == PlotFileType::Netcdf) {
1560  AMREX_ALWAYS_ASSERT(solverChoice.terrain_type != TerrainType::StaticFittedMesh);
1561  for (int lev = 0; lev <= finest_level; ++lev) {
1562  for (int which_box = 0; which_box < num_boxes_at_level[lev]; which_box++) {
1563  Box bounding_region = (lev == 0) ? geom[lev].Domain() : boxes_at_level[lev][which_box];
1564  const Real* p_lo = geom[lev].ProbLo();
1565  const Real* p_hi = geom[lev].ProbHi();
1566  const auto dx = geom[lev].CellSizeArray();
1567  writeNCPlotFile(lev, which_box, plotfilename, GetVecOfConstPtrs(mf), varnames, istep,
1568  {p_lo[0],p_lo[1],p_lo[2]},{p_hi[0],p_hi[1],p_hi[2]}, {dx[0],dx[1],dx[2]},
1569  bounding_region, t_new[0], start_bdy_time);
1570  }
1571  }
1572 #endif
1573  }
1574  } // end multi-level
1575 }
constexpr amrex::Real PI
Definition: ERF_Constants.H:6
constexpr amrex::Real Cp_l
Definition: ERF_Constants.H:14
#define RhoQ4_comp
Definition: ERF_IndexDefines.H:45
void compute_gradp(const MultiFab &p, const Geometry &geom, MultiFab &z_phys_nd, MultiFab &z_phys_cc, BCRec const *d_bcrec_ptr, const eb_ &ebfact, Vector< MultiFab > &gradp, const SolverChoice &solverChoice)
Definition: ERF_MakeGradP.cpp:71
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:64
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsatw(amrex::Real t, amrex::Real p, amrex::Real &qsatw)
Definition: ERF_MicrophysicsUtils.H:158
void writeNCPlotFile(int lev, int which_subdomain, const std::string &dir, const Vector< const MultiFab * > &plotMF, const Vector< std::string > &plot_var_names, const Vector< int > &, Array< Real, AMREX_SPACEDIM > prob_lo, Array< Real, AMREX_SPACEDIM > prob_hi, Array< Real, AMREX_SPACEDIM > dx_in, const Box &subdomain, const Real time, const Real start_bdy_time)
Definition: ERF_NCPlotFile.cpp:14
PhysBCFunctNoOp null_bc_for_fill
Definition: ERF_Plotfile.cpp:6
static amrex::Vector< std::string > PlotFileVarNames(amrex::Vector< std::string > plot_var_names)
Definition: ERF_Plotfile.cpp:249
void WriteMultiLevelPlotfileWithTerrain(const std::string &plotfilename, int nlevels, const amrex::Vector< const amrex::MultiFab * > &mf, const amrex::Vector< const amrex::MultiFab * > &mf_nd, const amrex::Vector< std::string > &varnames, const amrex::Vector< amrex::Geometry > &my_geom, amrex::Real time, const amrex::Vector< int > &level_steps, const amrex::Vector< amrex::IntVect > &my_ref_ratio, const std::string &versionName="HyperCLaw-V1.1", const std::string &levelPrefix="Level_", const std::string &mfPrefix="Cell", const amrex::Vector< std::string > &extra_dirs=amrex::Vector< std::string >()) const
Definition: ERF_Plotfile.cpp:1578
void writeJobInfo(const std::string &dir) const
Definition: ERF_WriteJobInfo.cpp:9
void Plot_Lsm_Data(amrex::Real time, const amrex::Vector< int > &level_steps, const amrex::Vector< amrex::IntVect > &ref_ratio)
Definition: ERF_LandSurface.H:98
@ Turb_lengthscale
Definition: ERF_IndexDefines.H:180
@ Mom_h
Definition: ERF_IndexDefines.H:170
@ Theta_h
Definition: ERF_IndexDefines.H:171
void erf_dervortx(const amrex::Box &bx, amrex::FArrayBox &derfab, int dcomp, int ncomp, const amrex::FArrayBox &datfab, const amrex::Geometry &geomdata, amrex::Real, const int *, const int)
Definition: ERF_Derive.cpp:200
void erf_dervorty(const amrex::Box &bx, amrex::FArrayBox &derfab, int dcomp, int ncomp, const amrex::FArrayBox &datfab, const amrex::Geometry &geomdata, amrex::Real, const int *, const int)
Definition: ERF_Derive.cpp:228
void erf_dermagvel(const amrex::Box &bx, amrex::FArrayBox &derfab, int dcomp, int ncomp, const amrex::FArrayBox &datfab, const amrex::Geometry &, amrex::Real, const int *, const int)
Definition: ERF_Derive.cpp:319
void erf_dernull(const Box &, FArrayBox &, int, int, const FArrayBox &, const Geometry &, Real, const int *, const int)
Definition: ERF_Derive.cpp:39
void erf_dertemp(const Box &bx, FArrayBox &derfab, int, int, const FArrayBox &datfab, const Geometry &, Real, const int *, const int)
Definition: ERF_Derive.cpp:91
void erf_derKE(const Box &bx, FArrayBox &derfab, int, int, const FArrayBox &datfab, const Geometry &, Real, const int *, const int)
Definition: ERF_Derive.cpp:186
void erf_dermoisttemp(const Box &bx, FArrayBox &derfab, int, int, const FArrayBox &datfab, const Geometry &, Real, const int *, const int)
Definition: ERF_Derive.cpp:113
void erf_dersoundspeed(const Box &bx, FArrayBox &derfab, int, int, const FArrayBox &datfab, const Geometry &, Real, const int *, const int)
Definition: ERF_Derive.cpp:58
real(c_double), parameter g
Definition: ERF_module_model_constants.F90:19
Here is the call graph for this function:

◆ WriteSubvolume()

void ERF::WriteSubvolume ( )
10 {
11  ParmParse pp("erf.subvol");
12 
13  Vector<Real> origin;
14  Vector< int> ncell;
15  Vector<Real> delta;
16 
17  // **************************************************************
18  // Read in the origin, number of cells in each dir, and resolution
19  // **************************************************************
20  pp.getarr("origin",origin,0,AMREX_SPACEDIM);
21  pp.getarr("nxnynz", ncell,0,AMREX_SPACEDIM);
22  pp.getarr("dxdydz", delta,0,AMREX_SPACEDIM);
23 
24  int lev_for_sub = 0;
25 
26  bool found = false;
27  for (int i = 0; i <= finest_level; i++) {
28  if (!found) {
29  if (almostEqual(delta[0],geom[i].CellSize(0)) &&
30  almostEqual(delta[1],geom[i].CellSize(1)) &&
31  almostEqual(delta[2],geom[i].CellSize(2)) ) {
32 
33  // amrex::Print() << "XDIR " << delta[0] << " " << geom[i].CellSize(0) << std::endl;
34  // amrex::Print() << "YDIR " << delta[1] << " " << geom[i].CellSize(1) << std::endl;
35  // amrex::Print() << "ZDIR " << delta[2] << " " << geom[i].CellSize(2) << std::endl;
36  amrex::Print() << "Resolution specified matches that of level " << i << std::endl;
37  found = true;
38  lev_for_sub = i;
39  }
40  }
41  }
42 
43  if (!found) {
44  amrex::Abort("Resolution specified for subvol does not match the resolution of any of the levels.");
45  }
46 
47  // **************************************************************
48  // Now that we know which level we're at, we can figure out which (i,j,k) the origin corresponds to
49  // Note we use 1.0001 as a fudge factor since the division of two reals --> integer will do a floor
50  // **************************************************************
51  int i0 = static_cast<int>((origin[0] - geom[lev_for_sub].ProbLo(0)) * 1.0001 / delta[0]);
52  int j0 = static_cast<int>((origin[1] - geom[lev_for_sub].ProbLo(1)) * 1.0001 / delta[1]);
53  int k0 = static_cast<int>((origin[2] - geom[lev_for_sub].ProbLo(2)) * 1.0001 / delta[2]);
54 
55  found = false;
56  if (almostEqual(geom[lev_for_sub].ProbLo(0)+i0*delta[0],origin[0]) &&
57  almostEqual(geom[lev_for_sub].ProbLo(1)+j0*delta[1],origin[1]) &&
58  almostEqual(geom[lev_for_sub].ProbLo(2)+k0*delta[2],origin[2]) )
59  {
60  amrex::Print() << "Specified origin is the lower left corner of cell " << IntVect(i0,j0,k0) << std::endl;
61  found = true;
62  }
63 
64  if (!found) {
65  amrex::Abort("Origin specified does not correspond to a node at this level.");
66  }
67 
68  Box domain(geom[lev_for_sub].Domain());
69 
70  Box bx(IntVect(i0,j0,k0),IntVect(i0+ncell[0]-1,j0+ncell[1]-1,k0+ncell[2]-1));
71  amrex::Print() << "Box requested is " << bx << std::endl;
72 
73  if (!domain.contains(bx))
74  {
75  amrex::Abort("Box requested is larger than the existing domain");
76  }
77 
78  Vector<int> cs(3);
79  int count = pp.countval("chunk_size");
80  if (count > 0) {
81  pp.queryarr("chunk_size",cs,0,AMREX_SPACEDIM);
82  } else {
83  cs[0] = max_grid_size[0][0];
84  cs[1] = max_grid_size[0][1];
85  cs[2] = max_grid_size[0][2];
86  }
87  IntVect chunk_size(cs[0],cs[1],cs[2]);
88 
89  BoxArray ba(bx);
90  ba.maxSize(chunk_size);
91 
92  amrex::Print() << "BoxArray is " << ba << std::endl;
93 
94  int ncomp_mf = AMREX_SPACEDIM;
95 
96  DistributionMapping dm(ba);
97 
98  MultiFab mf(ba, dm, ncomp_mf, 0);
99 
100  MultiFab mf_cc_vel(grids[lev_for_sub], dmap[lev_for_sub], ncomp_mf, 0);
101  average_face_to_cellcenter(mf_cc_vel,0,
102  Array<const MultiFab*,3>{&vars_new[lev_for_sub][Vars::xvel],
103  &vars_new[lev_for_sub][Vars::yvel],
104  &vars_new[lev_for_sub][Vars::zvel]});
105 
106  mf.ParallelCopy(mf_cc_vel,0,0,AMREX_SPACEDIM,0,0);
107 
108  std::string subvol_filename = Concatenate(subvol_file, istep[0], 5);
109 
110  Vector<std::string> varnames;
111  varnames.push_back("x_velocity");
112  varnames.push_back("y_velocity");
113  varnames.push_back("z_velocity");
114 
115  Real time = t_new[lev_for_sub];
116 
117  amrex::Print() <<"Writing subvolume into " << subvol_filename << std::endl;
118  WriteSingleLevelPlotfile(subvol_filename,mf,varnames,geom[lev_for_sub],time,istep[0]);
119 }
real(c_double), private cs
Definition: ERF_module_mp_morr_two_moment.F90:202
Here is the call graph for this function:

◆ WriteVTKPolyline()

void ERF::WriteVTKPolyline ( const std::string &  filename,
amrex::Vector< std::array< amrex::Real, 2 >> &  points_xy 
)
595 {
596  std::ofstream vtkfile(filename);
597  if (!vtkfile.is_open()) {
598  std::cerr << "Error: Cannot open file " << filename << std::endl;
599  return;
600  }
601 
602  int num_points = points_xy.size();
603  if (num_points == 0) {
604  vtkfile << "# vtk DataFile Version 3.0\n";
605  vtkfile << "Hurricane Track\n";
606  vtkfile << "ASCII\n";
607  vtkfile << "DATASET POLYDATA\n";
608  vtkfile << "POINTS " << num_points << " float\n";
609  vtkfile.close();
610  return;
611  }
612  if (num_points < 2) {
613  points_xy.push_back(points_xy[0]);
614  }
615  num_points = points_xy.size();
616 
617  vtkfile << "# vtk DataFile Version 3.0\n";
618  vtkfile << "Hurricane Track\n";
619  vtkfile << "ASCII\n";
620  vtkfile << "DATASET POLYDATA\n";
621 
622  // Write points (Z=0 assumed)
623  vtkfile << "POINTS " << num_points << " float\n";
624  for (const auto& pt : points_xy) {
625  vtkfile << pt[0] << " " << pt[1] << " 10000.0\n";
626  }
627 
628  // Write polyline connectivity
629  vtkfile << "LINES 1 " << num_points + 1 << "\n";
630  vtkfile << num_points << " ";
631  for (int i = 0; i < num_points; ++i) {
632  vtkfile << i << " ";
633  }
634  vtkfile << "\n";
635 
636  vtkfile.close();
637 }

Member Data Documentation

◆ advflux_reg

amrex::Vector<amrex::YAFluxRegister*> ERF::advflux_reg
private

Referenced by getAdvFluxReg().

◆ ax

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::ax
private

◆ ax_src

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::ax_src
private

◆ ay

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::ay
private

◆ ay_src

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::ay_src
private

◆ az

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::az
private

◆ az_src

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::az_src
private

◆ ba1d

amrex::Vector<amrex::BoxArray> ERF::ba1d
private

◆ ba2d

amrex::Vector<amrex::BoxArray> ERF::ba2d
private

◆ base_state

amrex::Vector<amrex::MultiFab> ERF::base_state
private

◆ base_state_new

amrex::Vector<amrex::MultiFab> ERF::base_state_new
private

◆ bndry_output_planes_interval

int ERF::bndry_output_planes_interval = -1
staticprivate

◆ bndry_output_planes_per

Real ERF::bndry_output_planes_per = -1.0
staticprivate

◆ bndry_output_planes_start_time

Real ERF::bndry_output_planes_start_time = 0.0
staticprivate

◆ boxes_at_level

amrex::Vector<amrex::Vector<amrex::Box> > ERF::boxes_at_level
private

◆ cf_set_width

int ERF::cf_set_width {0}
private

◆ cf_width

int ERF::cf_width {0}
private

◆ cfl

Real ERF::cfl = 0.8
staticprivate

◆ change_max

Real ERF::change_max = 1.1
staticprivate

◆ check_file

std::string ERF::check_file {"chk"}
private

◆ column_file_name

std::string ERF::column_file_name = "column_data.nc"
staticprivate

◆ column_interval

int ERF::column_interval = -1
staticprivate

◆ column_loc_x

Real ERF::column_loc_x = 0.0
staticprivate

◆ column_loc_y

Real ERF::column_loc_y = 0.0
staticprivate

◆ column_per

Real ERF::column_per = -1.0
staticprivate

◆ cons_names

const amrex::Vector<std::string> ERF::cons_names
private
Initial value:
{"density", "rhotheta", "rhoKE", "rhoadv_0",
"rhoQ1", "rhoQ2", "rhoQ3",
"rhoQ4", "rhoQ5", "rhoQ6"}

◆ cosPhi_m

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::cosPhi_m
private

◆ d_havg_density

amrex::Gpu::DeviceVector<amrex::Real> ERF::d_havg_density
private

◆ d_havg_pressure

amrex::Gpu::DeviceVector<amrex::Real> ERF::d_havg_pressure
private

◆ d_havg_qc

amrex::Gpu::DeviceVector<amrex::Real> ERF::d_havg_qc
private

◆ d_havg_qv

amrex::Gpu::DeviceVector<amrex::Real> ERF::d_havg_qv
private

◆ d_havg_temperature

amrex::Gpu::DeviceVector<amrex::Real> ERF::d_havg_temperature
private

◆ d_rayleigh_ptrs

amrex::Vector<amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real> > > ERF::d_rayleigh_ptrs
private

◆ d_rhoqt_src

amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real> > ERF::d_rhoqt_src
private

◆ d_rhotheta_src

amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real> > ERF::d_rhotheta_src
private

◆ d_sponge_ptrs

amrex::Vector<amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real> > > ERF::d_sponge_ptrs
private

◆ d_u_geos

amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real> > ERF::d_u_geos
private

◆ d_v_geos

amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real> > ERF::d_v_geos
private

◆ d_w_subsid

amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real> > ERF::d_w_subsid
private

◆ data_sampler

std::unique_ptr<SampleData> ERF::data_sampler = nullptr
private

◆ datalog

amrex::Vector<std::unique_ptr<std::fstream> > ERF::datalog
private

◆ datalogname

amrex::Vector<std::string> ERF::datalogname
private

Referenced by DataLogName().

◆ datetime_format

const std::string ERF::datetime_format = "%Y-%m-%d %H:%M:%S"
private

◆ datprecision

const int ERF::datprecision = 6
private

◆ datwidth

const int ERF::datwidth = 14
private

◆ der_datalog

amrex::Vector<std::unique_ptr<std::fstream> > ERF::der_datalog
private

◆ der_datalogname

amrex::Vector<std::string> ERF::der_datalogname
private

Referenced by DerDataLogName().

◆ derived_names

const amrex::Vector<std::string> ERF::derived_names
private

◆ destag_profiles

bool ERF::destag_profiles = true
private

◆ detJ_cc

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::detJ_cc
private

◆ detJ_cc_new

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::detJ_cc_new
private

◆ detJ_cc_src

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::detJ_cc_src
private

◆ domain_bc_type

amrex::Array<std::string,2*AMREX_SPACEDIM> ERF::domain_bc_type
private

◆ domain_bcs_type

amrex::Vector<amrex::BCRec> ERF::domain_bcs_type
private

◆ domain_bcs_type_d

amrex::Gpu::DeviceVector<amrex::BCRec> ERF::domain_bcs_type_d
private

◆ dt

amrex::Vector<amrex::Real> ERF::dt
private

◆ dt_max

Real ERF::dt_max = 1e9
staticprivate

◆ dt_max_initial

Real ERF::dt_max_initial = 2.0e100
staticprivate

◆ dt_mri_ratio

amrex::Vector<long> ERF::dt_mri_ratio
private

◆ dz_min

amrex::Vector<amrex::Real> ERF::dz_min
private

◆ eb

amrex::Vector<std::unique_ptr<eb_> > ERF::eb
private

Referenced by EBFactory(), and get_eb().

◆ eddyDiffs_lev

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::eddyDiffs_lev
private

◆ fine_mask

amrex::MultiFab ERF::fine_mask
private

◆ finished_wave

bool ERF::finished_wave = false
private

◆ fixed_dt

amrex::Vector<amrex::Real> ERF::fixed_dt
private

◆ fixed_fast_dt

amrex::Vector<amrex::Real> ERF::fixed_fast_dt
private

◆ fixed_mri_dt_ratio

int ERF::fixed_mri_dt_ratio = 0
staticprivate

◆ FPr_c

amrex::Vector<ERFFillPatcher> ERF::FPr_c
private

◆ FPr_u

amrex::Vector<ERFFillPatcher> ERF::FPr_u
private

◆ FPr_v

amrex::Vector<ERFFillPatcher> ERF::FPr_v
private

◆ FPr_w

amrex::Vector<ERFFillPatcher> ERF::FPr_w
private

◆ gradp

amrex::Vector<amrex::Vector<amrex::MultiFab> > ERF::gradp
private

◆ h_havg_density

amrex::Vector<amrex::Real> ERF::h_havg_density
private

◆ h_havg_pressure

amrex::Vector<amrex::Real> ERF::h_havg_pressure
private

◆ h_havg_qc

amrex::Vector<amrex::Real> ERF::h_havg_qc
private

◆ h_havg_qv

amrex::Vector<amrex::Real> ERF::h_havg_qv
private

◆ h_havg_temperature

amrex::Vector<amrex::Real> ERF::h_havg_temperature
private

◆ h_rayleigh_ptrs

amrex::Vector<amrex::Vector< amrex::Vector<amrex::Real> > > ERF::h_rayleigh_ptrs
private

◆ h_rhoqt_src

amrex::Vector< amrex::Vector<amrex::Real> > ERF::h_rhoqt_src
private

◆ h_rhotheta_src

amrex::Vector< amrex::Vector<amrex::Real> > ERF::h_rhotheta_src
private

◆ h_sponge_ptrs

amrex::Vector<amrex::Vector< amrex::Vector<amrex::Real> > > ERF::h_sponge_ptrs
private

◆ h_u_geos

amrex::Vector< amrex::Vector<amrex::Real> > ERF::h_u_geos
private

◆ h_v_geos

amrex::Vector< amrex::Vector<amrex::Real> > ERF::h_v_geos
private

◆ h_w_subsid

amrex::Vector< amrex::Vector<amrex::Real> > ERF::h_w_subsid
private

◆ hurricane_track_xy

amrex::Vector<std::array<amrex::Real, 2> > ERF::hurricane_track_xy

◆ Hwave

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::Hwave
private

◆ Hwave_onegrid

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::Hwave_onegrid
private

◆ init_shrink

Real ERF::init_shrink = 1.0
staticprivate

◆ init_sounding_ideal

bool ERF::init_sounding_ideal = false
staticprivate

◆ input_bndry_planes

int ERF::input_bndry_planes = 0
staticprivate

◆ input_sounding_data

InputSoundingData ERF::input_sounding_data
private

◆ input_sponge_data

InputSpongeData ERF::input_sponge_data
private

◆ interpolation_type

StateInterpType ERF::interpolation_type
staticprivate

◆ istep

amrex::Vector<int> ERF::istep
private

◆ last_check_file_step

int ERF::last_check_file_step
private

◆ last_plot_file_step_1

int ERF::last_plot_file_step_1
private

◆ last_plot_file_step_2

int ERF::last_plot_file_step_2
private

◆ last_subvol

int ERF::last_subvol
private

◆ lmask_lev

amrex::Vector<amrex::Vector<std::unique_ptr<amrex::iMultiFab> > > ERF::lmask_lev
private

◆ lsm

LandSurface ERF::lsm
private

◆ lsm_data

amrex::Vector<amrex::Vector<amrex::MultiFab*> > ERF::lsm_data
private

◆ lsm_flux

amrex::Vector<amrex::Vector<amrex::MultiFab*> > ERF::lsm_flux
private

◆ Lwave

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::Lwave
private

◆ Lwave_onegrid

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::Lwave_onegrid
private

◆ m_bc_extdir_vals

amrex::Array<amrex::Array<amrex::Real, AMREX_SPACEDIM*2>, AMREX_SPACEDIM+NBCVAR_max> ERF::m_bc_extdir_vals
private

◆ m_bc_neumann_vals

amrex::Array<amrex::Array<amrex::Real, AMREX_SPACEDIM*2>, AMREX_SPACEDIM+NBCVAR_max> ERF::m_bc_neumann_vals
private

◆ m_check_int

int ERF::m_check_int = -1
private

◆ m_check_per

amrex::Real ERF::m_check_per = -1.0
private

◆ m_expand_plotvars_to_unif_rr

bool ERF::m_expand_plotvars_to_unif_rr = false
private

◆ m_forest_drag

amrex::Vector<std::unique_ptr<ForestDrag> > ERF::m_forest_drag
private

◆ m_plot_face_vels

bool ERF::m_plot_face_vels = false
private

◆ m_plot_int_1

int ERF::m_plot_int_1 = -1
private

◆ m_plot_int_2

int ERF::m_plot_int_2 = -1
private

◆ m_plot_per_1

amrex::Real ERF::m_plot_per_1 = -1.0
private

◆ m_plot_per_2

amrex::Real ERF::m_plot_per_2 = -1.0
private

◆ m_r2d

std::unique_ptr<ReadBndryPlanes> ERF::m_r2d = nullptr
private

◆ m_subvol_int

int ERF::m_subvol_int = -1
private

◆ m_subvol_per

amrex::Real ERF::m_subvol_per = -1.0
private

◆ m_SurfaceLayer

std::unique_ptr<SurfaceLayer> ERF::m_SurfaceLayer = nullptr
private

◆ m_w2d

std::unique_ptr<WriteBndryPlanes> ERF::m_w2d = nullptr
private

◆ mapfac

amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab> > > ERF::mapfac
private

◆ max_step

int ERF::max_step = std::numeric_limits<int>::max()
private

◆ metgrid_basic_linear

bool ERF::metgrid_basic_linear {false}
private

◆ metgrid_debug_dry

bool ERF::metgrid_debug_dry {false}
private

◆ metgrid_debug_isothermal

bool ERF::metgrid_debug_isothermal {false}
private

◆ metgrid_debug_msf

bool ERF::metgrid_debug_msf {false}
private

◆ metgrid_debug_psfc

bool ERF::metgrid_debug_psfc {false}
private

◆ metgrid_debug_quiescent

bool ERF::metgrid_debug_quiescent {false}
private

◆ metgrid_force_sfc_k

int ERF::metgrid_force_sfc_k {6}
private

◆ metgrid_interp_theta

bool ERF::metgrid_interp_theta {false}
private

◆ metgrid_order

int ERF::metgrid_order {2}
private

◆ metgrid_proximity

amrex::Real ERF::metgrid_proximity {500.0}
private

◆ metgrid_retain_sfc

bool ERF::metgrid_retain_sfc {false}
private

◆ metgrid_use_below_sfc

bool ERF::metgrid_use_below_sfc {true}
private

◆ metgrid_use_sfc

bool ERF::metgrid_use_sfc {true}
private

◆ mf_C1H

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::mf_C1H
private

◆ mf_C2H

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::mf_C2H
private

◆ mf_MUB

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::mf_MUB
private

◆ mg_verbose

int ERF::mg_verbose = 0
staticprivate

◆ micro

std::unique_ptr<Microphysics> ERF::micro
private

◆ mri_integrator_mem

amrex::Vector<std::unique_ptr<MRISplitIntegrator<amrex::Vector<amrex::MultiFab> > > > ERF::mri_integrator_mem
private

◆ nc_bdy_file

std::string ERF::nc_bdy_file
staticprivate

◆ nc_init_file

Vector< Vector< std::string > > ERF::nc_init_file = {{""}}
staticprivate

◆ nc_low_file

std::string ERF::nc_low_file
staticprivate

◆ ng_dens_hse

int ERF::ng_dens_hse
staticprivate

◆ ng_pres_hse

int ERF::ng_pres_hse
staticprivate

◆ nsubsteps

amrex::Vector<int> ERF::nsubsteps
private

◆ num_boxes_at_level

amrex::Vector<int> ERF::num_boxes_at_level
private

◆ num_files_at_level

amrex::Vector<int> ERF::num_files_at_level
private

◆ output_1d_column

int ERF::output_1d_column = 0
staticprivate

◆ output_bndry_planes

int ERF::output_bndry_planes = 0
staticprivate

◆ pert_interval

int ERF::pert_interval = -1
staticprivate

◆ phys_bc_type

amrex::GpuArray<ERF_BC, AMREX_SPACEDIM*2> ERF::phys_bc_type
private

◆ physbcs_base

amrex::Vector<std::unique_ptr<ERFPhysBCFunct_base> > ERF::physbcs_base
private

◆ physbcs_cons

amrex::Vector<std::unique_ptr<ERFPhysBCFunct_cons> > ERF::physbcs_cons
private

◆ physbcs_u

amrex::Vector<std::unique_ptr<ERFPhysBCFunct_u> > ERF::physbcs_u
private

◆ physbcs_v

amrex::Vector<std::unique_ptr<ERFPhysBCFunct_v> > ERF::physbcs_v
private

◆ physbcs_w

amrex::Vector<std::unique_ptr<ERFPhysBCFunct_w> > ERF::physbcs_w
private

◆ plot_file_1

std::string ERF::plot_file_1 {"plt_1_"}
private

◆ plot_file_2

std::string ERF::plot_file_2 {"plt_2_"}
private

◆ plot_file_on_restart

int ERF::plot_file_on_restart = 1
private

◆ plot_lsm

bool ERF::plot_lsm = false
private

◆ plot_rad

bool ERF::plot_rad = false
private

◆ plot_var_names_1

amrex::Vector<std::string> ERF::plot_var_names_1
private

◆ plot_var_names_2

amrex::Vector<std::string> ERF::plot_var_names_2
private

◆ plotfile_type_1

PlotFileType ERF::plotfile_type_1 = PlotFileType::None
staticprivate

◆ plotfile_type_2

PlotFileType ERF::plotfile_type_2 = PlotFileType::None
staticprivate

◆ pp_inc

amrex::Vector<amrex::MultiFab> ERF::pp_inc
private

◆ pp_prefix

std::string ERF::pp_prefix {"erf"}

◆ previousCPUTimeUsed

Real ERF::previousCPUTimeUsed = 0.0
staticprivate

Referenced by getCPUTime().

◆ prob

std::unique_ptr<ProblemBase> ERF::prob = nullptr
private

◆ profile_int

int ERF::profile_int = -1
private

◆ qheating_rates

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::qheating_rates
private

◆ qmoist

amrex::Vector<amrex::Vector<amrex::MultiFab*> > ERF::qmoist
private

◆ Qr_prim

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::Qr_prim
private

◆ Qv_prim

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::Qv_prim
private

◆ rad

amrex::Vector<std::unique_ptr<IRadiation> > ERF::rad
private

◆ rad_datalog_int

int ERF::rad_datalog_int = -1
private

◆ real_set_width

int ERF::real_set_width {0}
private

◆ real_width

int ERF::real_width {0}
private

◆ ref_tags

Vector< AMRErrorTag > ERF::ref_tags
staticprivate

◆ regrid_int

int ERF::regrid_int = -1
private

◆ regrid_level_0_on_restart

bool ERF::regrid_level_0_on_restart = false
private

◆ restart_chkfile

std::string ERF::restart_chkfile = ""
private

◆ rU_new

amrex::Vector<amrex::MultiFab> ERF::rU_new
private

◆ rU_old

amrex::Vector<amrex::MultiFab> ERF::rU_old
private

◆ rV_new

amrex::Vector<amrex::MultiFab> ERF::rV_new
private

◆ rV_old

amrex::Vector<amrex::MultiFab> ERF::rV_old
private

◆ rW_new

amrex::Vector<amrex::MultiFab> ERF::rW_new
private

◆ rW_old

amrex::Vector<amrex::MultiFab> ERF::rW_old
private

◆ sampleline

amrex::Vector<amrex::IntVect> ERF::sampleline
private

Referenced by NumSampleLines(), and SampleLine().

◆ samplelinelog

amrex::Vector<std::unique_ptr<std::fstream> > ERF::samplelinelog
private

◆ samplelinelogname

amrex::Vector<std::string> ERF::samplelinelogname
private

Referenced by SampleLineLogName().

◆ samplepoint

amrex::Vector<amrex::IntVect> ERF::samplepoint
private

Referenced by NumSamplePoints(), and SamplePoint().

◆ sampleptlog

amrex::Vector<std::unique_ptr<std::fstream> > ERF::sampleptlog
private

◆ sampleptlogname

amrex::Vector<std::string> ERF::sampleptlogname
private

Referenced by SamplePointLogName().

◆ sampler_interval

int ERF::sampler_interval = -1
private

◆ sampler_per

amrex::Real ERF::sampler_per = -1.0
private

◆ SFS_diss_lev

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::SFS_diss_lev
private

◆ SFS_hfx1_lev

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::SFS_hfx1_lev
private

◆ SFS_hfx2_lev

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::SFS_hfx2_lev
private

◆ SFS_hfx3_lev

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::SFS_hfx3_lev
private

◆ SFS_q1fx1_lev

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::SFS_q1fx1_lev
private

◆ SFS_q1fx2_lev

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::SFS_q1fx2_lev
private

◆ SFS_q1fx3_lev

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::SFS_q1fx3_lev
private

◆ SFS_q2fx3_lev

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::SFS_q2fx3_lev
private

◆ sinPhi_m

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::sinPhi_m
private

◆ SmnSmn_lev

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::SmnSmn_lev
private

◆ solar_zenith

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::solar_zenith
private

◆ solverChoice

SolverChoice ERF::solverChoice
staticprivate

◆ sponge_type

std::string ERF::sponge_type
staticprivate

◆ sst_lev

amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab> > > ERF::sst_lev
private

◆ start_time

amrex::Real ERF::start_time = 0.0
private

◆ startCPUTime

Real ERF::startCPUTime = 0.0
staticprivate

Referenced by getCPUTime().

◆ stop_time

amrex::Real ERF::stop_time = std::numeric_limits<amrex::Real>::max()
private

◆ stretched_dz_d

amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real> > ERF::stretched_dz_d
private

◆ stretched_dz_h

amrex::Vector<amrex::Vector<amrex::Real> > ERF::stretched_dz_h
private

◆ sub_cfl

Real ERF::sub_cfl = 1.0
staticprivate

◆ subvol_file

std::string ERF::subvol_file {"subvol"}
private

◆ sum_interval

int ERF::sum_interval = -1
staticprivate

◆ sum_per

Real ERF::sum_per = -1.0
staticprivate

◆ sw_lw_fluxes

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::sw_lw_fluxes
private

◆ t_avg_cnt

amrex::Vector<amrex::Real> ERF::t_avg_cnt
private

◆ t_new

amrex::Vector<amrex::Real> ERF::t_new
private

◆ t_old

amrex::Vector<amrex::Real> ERF::t_old
private

◆ Tau

amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab> > > ERF::Tau
private

◆ terrain_blanking

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::terrain_blanking
private

◆ th_bc_data

amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real> > ERF::th_bc_data
private

◆ Theta_prim

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::Theta_prim
private

◆ thin_xforce

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::thin_xforce
private

◆ thin_yforce

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::thin_yforce
private

◆ thin_zforce

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::thin_zforce
private

◆ timeprecision

const int ERF::timeprecision = 13
private

◆ tot_e_datalog

amrex::Vector<std::unique_ptr<std::fstream> > ERF::tot_e_datalog
private

Referenced by setRecordEnergyDataInfo().

◆ tot_e_datalogname

amrex::Vector<std::string> ERF::tot_e_datalogname
private

◆ tsk_lev

amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab> > > ERF::tsk_lev
private

◆ turbPert

TurbulentPerturbation ERF::turbPert
private

◆ use_datetime

bool ERF::use_datetime = false
private

◆ use_fft

bool ERF::use_fft = false
staticprivate

◆ vars_new

amrex::Vector<amrex::Vector<amrex::MultiFab> > ERF::vars_new
private

◆ vars_old

amrex::Vector<amrex::Vector<amrex::MultiFab> > ERF::vars_old
private

◆ vel_t_avg

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::vel_t_avg
private

◆ verbose

int ERF::verbose = 0
staticprivate

◆ walldist

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::walldist
private

◆ xflux_imask

amrex::Vector<std::unique_ptr<amrex::iMultiFab> > ERF::xflux_imask
private

◆ xvel_bc_data

amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real> > ERF::xvel_bc_data
private

◆ yflux_imask

amrex::Vector<std::unique_ptr<amrex::iMultiFab> > ERF::yflux_imask
private

◆ yvel_bc_data

amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real> > ERF::yvel_bc_data
private

◆ z_phys_cc

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::z_phys_cc
private

◆ z_phys_cc_src

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::z_phys_cc_src
private

◆ z_phys_nd

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::z_phys_nd
private

◆ z_phys_nd_new

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::z_phys_nd_new
private

◆ z_phys_nd_src

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::z_phys_nd_src
private

◆ z_t_rk

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ERF::z_t_rk
private

◆ zflux_imask

amrex::Vector<std::unique_ptr<amrex::iMultiFab> > ERF::zflux_imask
private

◆ zlevels_stag

amrex::Vector<amrex::Vector<amrex::Real> > ERF::zlevels_stag
private

◆ zmom_crse_rhs

amrex::Vector<amrex::MultiFab> ERF::zmom_crse_rhs
private

◆ zvel_bc_data

amrex::Vector<amrex::Gpu::DeviceVector<amrex::Real> > ERF::zvel_bc_data
private

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