Skip to content

Commit

Permalink
Refactor initialization routines, problem definition (erf-model#1232)
Browse files Browse the repository at this point in the history
* Minor cleanup + update comments

* Update .gitignore

* Additional clarifying comments and minor cleanup

* Make sure base state is set prior to calling init_custom

* Move common includes into prob_common.H

* Add common includes for erf_init_dens_hse and erf_init_rayleigh

* Restore final call to initHSE in order to pass reg tests for now

* Implement ProblemBase class, refactor all problems

- ProblemBase provides stubs for erf_init_dens_hse, init_custom_prob,
  init_custom_terrain, and erf_init_rayleigh
- Each problem in Exec implements a derived class, overriding these functions
- The ERF constructor instantiates the derived class

* Add init_isentropic_hse[_terrain] functions to ProblemBase

- add new prob_common.cpp source file
- cleanup prob_common.H
- cleanup all prob.cpp that had copies of these functions

* Rearrange function declarations for consistency

* Add ProbParmDefaults struct

* Implement additional recipes for erf_init_dens_hse

for variable density, with and without terrain

* Add T_0 to the ProbParmDefaults; make consistent the usage of T_0 (ref potential temperature)

* Implement init_custom(lev) which calls new prob->init_state()

init_state() will set the background field to a uniform field based on
parms.rho_0 and parms.T_0 and should only be called in the absence of any other
initialization type -- NOTE: this **will break the r-tests** because the
prob.cpp source files have not been updated to guarantee that the background
field is not double-counted!

* Rename init_custom_prob() --> init_custom_pert() for clarity

* Implement init_type="uniform" for backwards compatibility

* Add missing source/header files

* Implement default initialization based on HSE

* Whitespace

* Remove redundant initHSE call

verified that there is no change in rtests

* Add virtual destructor and comment unused vars.

* Update DensityCurrent* gold data

* Update MovingTerrain* gold data

* Update TaylorGreen* gold data

* Fixes for GPU

* Cleanup prob source files

* Move ProblemBase member functions to HSE_utils namespace

because member functions (e.g., init_isentropic_hse) cannot be called from
inside a device lambda

---------

Co-authored-by: Aaron M. Lattanzi <[email protected]>
Co-authored-by: AMLattanzi <[email protected]>
Co-authored-by: Ann Almgren <[email protected]>
  • Loading branch information
4 people authored Sep 8, 2023
1 parent 6f05140 commit 049f84f
Show file tree
Hide file tree
Showing 197 changed files with 7,246 additions and 8,238 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# Log files
datlog
log.*

# Ignore everything in Build except the cmake script
/Build/*
Expand All @@ -21,6 +22,9 @@ datlog
!/Build/cmake_with_poisson.sh
!/Build/cmake_with_warm_no_precip.sh

# Temporary files
*/Testing/Temporary
.*.swp

/Exec/WORK/*
ic.txt
Expand All @@ -35,3 +39,4 @@ cmake_build*
cmake*ser*
cmake*par*
.idea
*.ipynb
2 changes: 2 additions & 0 deletions CMake/BuildERFExe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ function(build_erf_lib erf_lib_name)
${SRC_DIR}/Diffusion/NumericalDiffusion.cpp
${SRC_DIR}/Diffusion/PBLModels.cpp
${SRC_DIR}/Initialization/ERF_init_custom.cpp
${SRC_DIR}/Initialization/ERF_init_from_hse.cpp
${SRC_DIR}/Initialization/ERF_init_from_input_sounding.cpp
${SRC_DIR}/Initialization/ERF_init_from_wrfinput.cpp
${SRC_DIR}/Initialization/ERF_init_from_metgrid.cpp
${SRC_DIR}/Initialization/ERF_init_uniform.cpp
${SRC_DIR}/Initialization/ERF_init1d.cpp
${SRC_DIR}/IO/Checkpoint.cpp
${SRC_DIR}/IO/ERF_ReadBndryPlanes.cpp
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs.read
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ erf.molec_diff_type = "None"
erf.les_type = "Smagorinsky"
erf.Cs = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs.write
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ erf.molec_diff_type = "None"
erf.les_type = "Smagorinsky"
erf.Cs = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_deardorff
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ erf.Ck = 0.1
erf.sigma_k = 1.0
erf.Ce = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_deardorff_msf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ erf.Ck = 0.1
erf.sigma_k = 1.0
erf.Ce = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_deardorff_no_msf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ erf.Ck = 0.1
erf.sigma_k = 1.0
erf.Ce = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_ml_most
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ erf.use_gravity = false
erf.les_type = "Smagorinsky"
erf.Cs = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_most
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ erf.molec_diff_type = "None"
erf.les_type = "Smagorinsky"
erf.Cs = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_most_msf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ erf.dycore_vert_adv_type = "Upwind_3rd"
erf.dryscal_horiz_adv_type = "Upwind_3rd"
erf.dryscal_vert_adv_type = "Upwind_3rd"

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_most_no_msf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ erf.dycore_vert_adv_type = "Upwind_3rd"
erf.dryscal_horiz_adv_type = "Upwind_3rd"
erf.dryscal_vert_adv_type = "Upwind_3rd"

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_most_test
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ erf.les_type = "Smagorinsky"
#erf.pbl_type = "MYNN2.5"
erf.Cs = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_numdiff
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ erf.Ce = 0.1
erf.use_NumDiff = true
erf.NumDiffCoeff = 0.5

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_omp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ erf.Ck = 0.1
erf.sigma_k = 1.0
erf.Ce = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_sample
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ erf.molec_diff_type = "None"
erf.les_type = "Smagorinsky"
erf.Cs = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_smagorinsky
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ erf.molec_diff_type = "None"
erf.les_type = "Smagorinsky"
erf.Cs = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_smagorinsky_msf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ erf.dynamicViscosity = 1.0
erf.les_type = "Smagorinsky"
erf.Cs = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
2 changes: 2 additions & 0 deletions Exec/ABL/inputs_smagorinsky_no_msf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ erf.dynamicViscosity = 1.0
erf.les_type = "Smagorinsky"
erf.Cs = 0.1

erf.init_type = "uniform"

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.A_0 = 1.0
Expand Down
63 changes: 56 additions & 7 deletions Exec/ABL/prob.H
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#ifndef _PROB_H_
#define _PROB_H_

#include <AMReX_REAL.H>
#include <string>

struct ProbParm {
amrex::Real rho_0 = 0.0;
amrex::Real Theta_0 = 0.0;
amrex::Real A_0 = 1.0;
amrex::Real QKE_0 = 0.1;
#include "AMReX_REAL.H"

#include "prob_common.H"

struct ProbParm : ProbParmDefaults {
amrex::Real rho_0 = 0.0;
amrex::Real T_0 = 0.0;
amrex::Real A_0 = 1.0;
amrex::Real QKE_0 = 0.1;

amrex::Real U_0 = 0.0;
amrex::Real V_0 = 0.0;
Expand Down Expand Up @@ -37,6 +41,51 @@ struct ProbParm {
amrex::Real vfac;
}; // namespace ProbParm

extern ProbParm parms;
class Problem : public ProblemBase
{
public:
Problem(const amrex::Real* problo, const amrex::Real* probhi);

#include "Prob/init_constant_density_hse.H"
#include "Prob/init_rayleigh_damping.H"

void init_custom_pert (
const amrex::Box& bx,
const amrex::Box& xbx,
const amrex::Box& ybx,
const amrex::Box& zbx,
amrex::Array4<amrex::Real > const& state,
amrex::Array4<amrex::Real > const& x_vel,
amrex::Array4<amrex::Real > const& y_vel,
amrex::Array4<amrex::Real > const& z_vel,
amrex::Array4<amrex::Real > const& r_hse,
amrex::Array4<amrex::Real > const& p_hse,
amrex::Array4<amrex::Real const> const& z_nd,
amrex::Array4<amrex::Real const> const& z_cc,
#if defined(ERF_USE_MOISTURE)
amrex::Array4<amrex::Real > const& qv,
amrex::Array4<amrex::Real > const& qc,
amrex::Array4<amrex::Real > const& qi,
#elif defined(ERF_USE_WARM_NO_PRECIP)
amrex::Array4<amrex::Real > const& qv,
amrex::Array4<amrex::Real > const& qc,
#endif
amrex::GeometryData const& geomdata,
amrex::Array4<amrex::Real const> const& mf_m,
amrex::Array4<amrex::Real const> const& mf_u,
amrex::Array4<amrex::Real const> const& mf_v,
const SolverChoice& sc) override;

void init_custom_terrain (
const amrex::Geometry& geom,
amrex::MultiFab& z_phys_nd,
const amrex::Real& time) override;

protected:
std::string name() override { return "ABL"; }

private:
ProbParm parms;
};

#endif
Loading

0 comments on commit 049f84f

Please sign in to comment.