Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add energy variable type to dispatch on #1031

Merged
merged 1 commit into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion driver/dycore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function compute_ref_state!(
return nothing
end

function set_prog_from_aux!(state)
function set_prog_from_aux!(state, ::TC.ρθVar)
prog_gm = TC.center_prog_grid_mean(state)
aux_gm = TC.center_aux_grid_mean(state)
@. prog_gm.ρθ_liq_ice = prog_gm.ρ * aux_gm.θ_liq_ice
Expand Down
1 change: 1 addition & 0 deletions driver/generate_namelist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function default_namelist(
namelist_defaults["logging"] = Dict()
namelist_defaults["logging"]["truncate_stack_trace"] = truncate_stack_trace

namelist_defaults["energy_var"] = "rhotheta"
namelist_defaults["turbulence"] = Dict()

namelist_defaults["turbulence"]["EDMF_PrognosticTKE"] = Dict()
Expand Down
2 changes: 1 addition & 1 deletion driver/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function initialize(sim::Simulation1d)
FT = eltype(sim.grid)
t = FT(0)
Cases.initialize_profiles(sim.case, sim.grid, sim.param_set, state)
set_prog_from_aux!(state)
set_prog_from_aux!(state, sim.edmf.evar)
set_thermo_state!(state, sim.grid, sim.edmf.moisture_model, sim.param_set)
assign_thermo_aux!(state, sim.grid, sim.edmf.moisture_model, sim.param_set)

Expand Down
3 changes: 3 additions & 0 deletions integration_tests/cli_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ function parse_commandline()
arg_type = Int
"--moisture_model" # Moisture model (equilibrium or non-equilibrium)
arg_type = String
"--energy_var" # Energy variable [rho-theta]
arg_type = String
default = "rhotheta"
"--precipitation_model" # Precipitation model (None, cutoff or clima_1m)
arg_type = String
"--thermo_covariance_model" # covariance model (prognostic or diagnostic)
Expand Down
1 change: 1 addition & 0 deletions integration_tests/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ overwrite_namelist_map = Dict(
"moisture_model" => (nl, pa, key) -> (nl["thermodynamics"]["moisture_model"] = pa[key]),
"precipitation_model" => (nl, pa, key) -> (nl["microphysics"]["precipitation_model"] = pa[key]),
"thermo_covariance_model" => (nl, pa, key) -> (nl["thermodynamics"]["thermo_covariance_model"] = pa[key]),
"energy_var" => (nl, pa, key) -> (nl["energy_var"] = pa[key]),
)
no_overwrites = (
"case", # default_namelist already overwrites namelist["meta"]["casename"]
Expand Down
23 changes: 21 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ function CasesBase(case::T; inversion_type, surf_params, Fo, Rad, LESDat = nothi
)
end

struct EDMFModel{N_up, FT, MM, TCM, PM, ENT, EBGC, EC, EDS, EPG}
abstract type AbstractEnergyVariable end
struct ρeVar <: AbstractEnergyVariable end
struct ρθVar <: AbstractEnergyVariable end

struct EDMFModel{N_up, FT, MM, TCM, PM, ENT, EBGC, EC, EDS, EPG, EV}
surface_area::FT
max_area::FT
minimum_area::FT
Expand All @@ -460,6 +464,7 @@ struct EDMFModel{N_up, FT, MM, TCM, PM, ENT, EBGC, EC, EDS, EPG}
entr_closure::EC
entr_dim_scale::EDS
entr_pi_subset::EPG
evar::EV
function EDMFModel(namelist, precip_model) where {PS}
# TODO: move this into arg list
FT = Float64
Expand Down Expand Up @@ -492,6 +497,16 @@ struct EDMFModel{N_up, FT, MM, TCM, PM, ENT, EBGC, EC, EDS, EPG}
error("Something went wrong. Invalid moisture model: '$moisture_model_name'")
end

evar_name = parse_namelist(namelist, "energy_var"; default = "rhotheta")

evar = if evar_name == "rhotheta"
ρθVar()
elseif evar_name == "rhoe"
ρeVar()
else
error("Bad energy variable given")
end

thermo_covariance_model_name =
parse_namelist(namelist, "thermodynamics", "thermo_covariance_model"; default = "prognostic")

Expand Down Expand Up @@ -617,7 +632,8 @@ struct EDMFModel{N_up, FT, MM, TCM, PM, ENT, EBGC, EC, EDS, EPG}
EBGC = typeof(bg_closure)
ENT = typeof(en_thermo)
EPG = typeof(entr_pi_subset)
return new{n_updrafts, FT, MM, TCM, PM, ENT, EBGC, EC, EDS, EPG}(
EV = typeof(evar)
return new{n_updrafts, FT, MM, TCM, PM, ENT, EBGC, EC, EDS, EPG, EV}(
surface_area,
max_area,
minimum_area,
Expand All @@ -630,6 +646,7 @@ struct EDMFModel{N_up, FT, MM, TCM, PM, ENT, EBGC, EC, EDS, EPG}
entr_closure,
entr_dim_scale,
entr_pi_subset,
evar,
)
end
end
Expand All @@ -638,6 +655,8 @@ n_updrafts(::EDMFModel{N_up}) where {N_up} = N_up
Base.eltype(::EDMFModel{N_up, FT}) where {N_up, FT} = FT
n_Π_groups(m::EDMFModel) = length(m.entr_pi_subset)
entrainment_Π_subset(m::EDMFModel) = m.entr_pi_subset
energy_var(m::EDMFModel) = m.evar

Base.broadcastable(edmf::EDMFModel) = Ref(edmf)

struct State{P, A, T}
Expand Down