diff --git a/config/default_configs/default_edmf_config.yml b/config/default_configs/default_edmf_config.yml index 9bcaf37d0b9..5699d6bb7ba 100644 --- a/config/default_configs/default_edmf_config.yml +++ b/config/default_configs/default_edmf_config.yml @@ -32,12 +32,6 @@ edmfx_upwinding: debugging_tc: help: "Save most of the tc aux state to HDF5 file [`false` (default), `true`]" value: false -entr_coeff: - help: "Entrainment coefficient" - value: 1.0 -detr_coeff: - help: "Detrainment coefficient" - value: 0.001 edmfx_sgs_flux: help: "If set to true, it switches on EDMFX SGS flux. [`true`, `false` (default)]" value: false \ No newline at end of file diff --git a/config/model_configs/edmfx_bomex_box_v2.yml b/config/model_configs/edmfx_bomex_box_v2.yml index b812875c63a..00f58c23fc5 100644 --- a/config/model_configs/edmfx_bomex_box_v2.yml +++ b/config/model_configs/edmfx_bomex_box_v2.yml @@ -16,7 +16,6 @@ turbconv: "edmfx" z_stretch: false vert_diff: "true" x_elem: 2 -detr_coeff: 0.01 config: "box" subsidence: "Bomex" kappa_4: 1.0e12 diff --git a/examples/Manifest.toml b/examples/Manifest.toml index 4a661b4dc50..41c3da9b3a1 100644 --- a/examples/Manifest.toml +++ b/examples/Manifest.toml @@ -200,9 +200,9 @@ version = "0.1.2" [[deps.CLIMAParameters]] deps = ["DocStringExtensions", "TOML", "Test"] -git-tree-sha1 = "7b3163ccbd056dabd7ec648101830e9a6ccd019d" +git-tree-sha1 = "7f3b89db2aabb81ec5750300a37d424f1f38240d" uuid = "6eacf6c3-8458-43b9-ae03-caf5306d3d53" -version = "0.7.14" +version = "0.7.18" [[deps.CPUSummary]] deps = ["CpuId", "IfElse", "PrecompileTools", "Static"] diff --git a/src/parameterized_tendencies/radiation/held_suarez.jl b/src/parameterized_tendencies/radiation/held_suarez.jl index 1d743817ea2..cb55962a417 100644 --- a/src/parameterized_tendencies/radiation/held_suarez.jl +++ b/src/parameterized_tendencies/radiation/held_suarez.jl @@ -39,26 +39,24 @@ function forcing_tendency!(Yₜ, Y, p, t, colidx, ::HeldSuarezForcing) MSLP = FT(CAP.MSLP(params)) p_ref_theta = FT(CAP.p_ref_theta(params)) grav = FT(CAP.grav(params)) - ΔT_y_dry = FT(CAP.ΔT_y_dry(params)) - ΔT_y_wet = FT(CAP.ΔT_y_wet(params)) + Δθ_z = FT(CAP.Δθ_z(params)) + T_min = FT(CAP.T_min_hs(params)) thermo_params = CAP.thermodynamics_params(params) + σ_b = CAP.σ_b(params) + k_a = 1 / (40 * day) + k_s = 1 / (4 * day) + k_f = 1 / day z_surface = Fields.level(Fields.coordinate_field(Y.f).z[colidx], Fields.half) - σ_b = FT(7 / 10) - k_a = 1 / (40 * day) - k_s = 1 / (4 * day) - k_f = 1 / day if :ρq_tot in propertynames(Y.c) - ΔT_y = ΔT_y_wet - T_equator = FT(294) + ΔT_y = FT(CAP.ΔT_y_wet(params)) + T_equator = FT(CAP.T_equator_wet(params)) else - ΔT_y = ΔT_y_dry - T_equator = FT(315) + ΔT_y = FT(CAP.ΔT_y_dry(params)) + T_equator = FT(CAP.T_equator_wet(params)) end - Δθ_z = FT(10) - T_min = FT(200) @. ᶜσ[colidx] = ᶜp[colidx] / ( diff --git a/src/parameters/Parameters.jl b/src/parameters/Parameters.jl index 022bffe3331..903f7b005f6 100644 --- a/src/parameters/Parameters.jl +++ b/src/parameters/Parameters.jl @@ -10,38 +10,29 @@ const ACAP = AbstractClimaAtmosParameters Base.broadcastable(param_set::ACAP) = tuple(param_set) -Base.@kwdef struct ClimaAtmosParameters{FT, TP, RP, IP, MPP, SFP, TCP, SP} <: - ACAP - Omega::FT - f_plane_coriolis_frequency::FT - planet_radius::FT - astro_unit::FT - # TODO: remove defaults, or move these parameters to CLIMAParameters - f::FT = 0 # coriolis parameter. TODO: remove? - Cd::FT = 0 # drag coefficients. TODO: remove? - ug::FT = 0 - vg::FT = 0 +Base.@kwdef struct ClimaAtmosParameters{FT, TP, RP, IP, MPP, SFP, TCP} <: ACAP thermodynamics_params::TP rrtmgp_params::RP insolation_params::IP microphysics_params::MPP - surfacefluxes_params::SFP + surface_fluxes_params::SFP turbconv_params::TCP - sponge_params::SP - entr_coeff::FT = 1 - detr_coeff::FT = 0.001 - # TODO: Figure out a better place for these held-suarez parameters + Omega::FT + f_plane_coriolis_frequency::FT + planet_radius::FT + astro_unit::FT + entr_coeff::FT + detr_coeff::FT + C_E::FT + # Held Suarez ΔT_y_dry::FT ΔT_y_wet::FT - C_E::FT -end - -""" - SpongeParameters{FT} - -Parameters for both the viscous and rayleigh sponge. -""" -Base.@kwdef struct SpongeParameters{FT} + σ_b::FT + T_equator_dry::FT + T_equator_wet::FT + T_min_hs::FT + Δθ_z::FT + # Sponge alpha_rayleigh_w::FT alpha_rayleigh_uh::FT zd_viscous::FT @@ -51,13 +42,6 @@ end Base.eltype(::ClimaAtmosParameters{FT}) where {FT} = FT -rrtmgp_params(ps::ACAP) = ps.rrtmgp_params -thermodynamics_params(ps::ACAP) = ps.thermodynamics_params -surface_fluxes_params(ps::ACAP) = ps.surfacefluxes_params -microphysics_params(ps::ACAP) = ps.microphysics_params -insolation_params(ps::ACAP) = ps.insolation_params -turbconv_params(ps::ACAP) = ps.turbconv_params - # Forward Thermodynamics parameters for var in fieldnames(TD.Parameters.ThermodynamicsParameters) @eval $var(ps::ACAP) = TD.Parameters.$var(thermodynamics_params(ps)) @@ -72,18 +56,6 @@ cv_v(ps::ACAP) = TD.Parameters.cv_v(thermodynamics_params(ps)) cv_l(ps::ACAP) = TD.Parameters.cv_l(thermodynamics_params(ps)) cv_d(ps::ACAP) = TD.Parameters.cv_d(thermodynamics_params(ps)) -Omega(ps::ACAP) = ps.Omega -f_plane_coriolis_frequency(ps::ACAP) = ps.f_plane_coriolis_frequency -planet_radius(ps::ACAP) = ps.planet_radius -astro_unit(ps::ACAP) = ps.astro_unit -f(ps::ACAP) = ps.f -Cd(ps::ACAP) = ps.Cd -uh_g(ps::ACAP) = CC.Geometry.UVVector(ps.ug, ps.vg) -entr_coeff(ps::ACAP) = ps.entr_coeff -detr_coeff(ps::ACAP) = ps.detr_coeff -ΔT_y_dry(ps::ACAP) = ps.ΔT_y_dry -ΔT_y_wet(ps::ACAP) = ps.ΔT_y_wet - # Forwarding CloudMicrophysics parameters ρ_cloud_liq(ps::ACAP) = CM.Parameters.ρ_cloud_liq(microphysics_params(ps)) @@ -91,4 +63,11 @@ detr_coeff(ps::ACAP) = ps.detr_coeff day(ps::ACAP) = IP.day(insolation_params(ps)) tot_solar_irrad(ps::ACAP) = IP.tot_solar_irrad(insolation_params(ps)) +# Define parameters as functions +# Place derived parameters in exceptions vector +exceptions = [] +for var in filter(x -> !(x in exceptions), fieldnames(ClimaAtmosParameters)) + @eval $var(ps::ACAP) = ps.$var +end + end diff --git a/src/parameters/create_parameters.jl b/src/parameters/create_parameters.jl index 03e2b668715..79aa929e1db 100644 --- a/src/parameters/create_parameters.jl +++ b/src/parameters/create_parameters.jl @@ -105,49 +105,31 @@ function create_climaatmos_parameter_set( params = override_climaatmos_defaults((; pairs...), overrides) # overrides insolation_params = IP.InsolationParameters{FTD}(; params...) - pairs = CP.get_parameter_values!( - toml_dict, - [ - "alpha_rayleigh_w", - "alpha_rayleigh_uh", - "zd_viscous", - "zd_rayleigh", - "kappa_2_sponge", - ], - ) - pairs = (; pairs...) # convert to NamedTuple - pairs = override_climaatmos_defaults((; pairs...), overrides) - sponge_params = CAP.SpongeParameters(; pairs...) - - pairs = CP.get_parameter_values!( - toml_dict, - ["Omega", "planet_radius", "astro_unit", "ΔT_y_dry", "ΔT_y_wet", "C_E"], - "ClimaAtmos", - ) - pairs = (; pairs...) # convert to NamedTuple - pairs = override_climaatmos_defaults((; pairs...), overrides) - + # This will be cleaned up after rebasing from #2017 + subparam_struct_names = [ + :thermodynamics_params, + :rrtmgp_params, + :insolation_params, + :microphysics_params, + :surface_fluxes_params, + :turbconv_params, + ] + aliases = + string.( + setdiff( + fieldnames(CAP.ClimaAtmosParameters), + subparam_struct_names, + ) + ) + pairs = CP.get_parameter_values!(toml_dict, aliases) param_set = CAP.ClimaAtmosParameters(; - ug = FTD(1.0), # for Ekman problem - vg = FTD(0.0), # for Ekman problem - f = FTD(5e-5), # for Ekman problem - Cd = FTD(0.01 / (2e2 / 30)), # for Ekman problem - Omega = FTD(pairs.Omega), - planet_radius = FTD(pairs.planet_radius), - astro_unit = FTD(pairs.astro_unit), - f_plane_coriolis_frequency = FTD(0), thermodynamics_params = thermo_params, microphysics_params = microphys_params, insolation_params = insolation_params, rrtmgp_params = rrtmgp_params, - surfacefluxes_params = surf_flux_params, + surface_fluxes_params = surf_flux_params, turbconv_params = tc_params, - entr_coeff = FTD(parsed_args["entr_coeff"]), - detr_coeff = FTD(parsed_args["detr_coeff"]), - ΔT_y_dry = FTD(pairs.ΔT_y_dry), - ΔT_y_wet = FTD(pairs.ΔT_y_wet), - C_E = FTD(pairs.C_E), - sponge_params, + pairs... ) # logfilepath = joinpath(@__DIR__, "logfilepath_$FT.toml") # CP.log_parameter_information(toml_dict, logfilepath) diff --git a/src/solver/model_getters.jl b/src/solver/model_getters.jl index 8ee091980d2..c1457da235a 100644 --- a/src/solver/model_getters.jl +++ b/src/solver/model_getters.jl @@ -76,35 +76,27 @@ function get_surface_model(parsed_args) end end -function get_viscous_sponge_model( - parsed_args, - sponge_params, - ::Type{FT}, -) where {FT} +function get_viscous_sponge_model(parsed_args, params, ::Type{FT}) where {FT} vs_name = parsed_args["viscous_sponge"] return if vs_name in ("false", false, "none") nothing elseif vs_name in ("true", true, "ViscousSponge") - zd = sponge_params.zd_viscous - κ₂ = sponge_params.kappa_2_sponge + zd = params.zd_viscous + κ₂ = params.kappa_2_sponge ViscousSponge{FT}(; zd, κ₂) else error("Uncaught viscous sponge model `$vs_name`.") end end -function get_rayleigh_sponge_model( - parsed_args, - sponge_params, - ::Type{FT}, -) where {FT} +function get_rayleigh_sponge_model(parsed_args, params, ::Type{FT}) where {FT} rs_name = parsed_args["rayleigh_sponge"] return if rs_name in ("false", false) nothing elseif rs_name in ("true", true, "RayleighSponge") - zd = sponge_params.zd_rayleigh - α_uₕ = sponge_params.alpha_rayleigh_uh - α_w = sponge_params.alpha_rayleigh_w + zd = params.zd_rayleigh + α_uₕ = params.alpha_rayleigh_uh + α_w = params.alpha_rayleigh_w RayleighSponge{FT}(; zd, α_uₕ, α_w) else error("Uncaught rayleigh sponge model `$rs_name`.") diff --git a/src/solver/type_getters.jl b/src/solver/type_getters.jl index 2c93cf5f5a6..61dcbb9c8e5 100644 --- a/src/solver/type_getters.jl +++ b/src/solver/type_getters.jl @@ -13,7 +13,7 @@ import ClimaTimeSteppers as CTS import DiffEqCallbacks as DECB function get_atmos(config::AtmosConfig, params) - (; turbconv_params, sponge_params) = params + (; turbconv_params) = params (; parsed_args) = config FT = eltype(config) moisture_model = get_moisture_model(parsed_args) @@ -71,16 +71,8 @@ function get_atmos(config::AtmosConfig, params) ), hyperdiff = get_hyperdiffusion_model(parsed_args, FT), vert_diff, - viscous_sponge = get_viscous_sponge_model( - parsed_args, - sponge_params, - FT, - ), - rayleigh_sponge = get_rayleigh_sponge_model( - parsed_args, - sponge_params, - FT, - ), + viscous_sponge = get_viscous_sponge_model(parsed_args, params, FT), + rayleigh_sponge = get_rayleigh_sponge_model(parsed_args, params, FT), sfc_temperature = get_sfc_temperature_form(parsed_args), surface_model = get_surface_model(parsed_args), ) diff --git a/test/parameter_tests.jl b/test/parameter_tests.jl index 2cdb5e1aa5b..56096d01611 100644 --- a/test/parameter_tests.jl +++ b/test/parameter_tests.jl @@ -16,7 +16,7 @@ default_args = CA.cli_defaults(CA.argparse_settings()) "dt_save_to_disk" => "str", "bubble" => true, ) - parsed_args = CA.AtmosConfig(; config_dict = config_dict).parsed_args + parsed_args = CA.AtmosConfig(; config_dict).parsed_args @test parsed_args["krylov_rtol"] isa FT @test parsed_args["newton_rtol"] isa FT @test parsed_args["max_newton_iters_ode"] isa Int @@ -24,3 +24,19 @@ default_args = CA.cli_defaults(CA.argparse_settings()) @test parsed_args["dt_save_to_disk"] isa String @test parsed_args["bubble"] isa Bool end + +@testset "Test unique aliases" begin + config_dict = Dict("toml" => ["parameter_tests.toml"]) + config = CA.AtmosConfig(; config_dict) + @test_throws ErrorException CP.get_parameter_values!(config.toml_dict, ["same_alias"]) +end + +@testset "Test all parameter tomls in toml/" begin + toml_path = joinpath("..", "toml") + for toml in readdir(toml_path) + config_dict = Dict("toml" => [joinpath(toml_path, toml)]) + config = CA.AtmosConfig(;config_dict); + # Ensure that there are no errors + @test CA.create_parameter_set(config) isa CA.Parameters.ClimaAtmosParameters + end +end diff --git a/toml/edmfx_bomex_box_v2.toml b/toml/edmfx_bomex_box_v2.toml index 3da20f5a66b..f44f9e24716 100644 --- a/toml/edmfx_bomex_box_v2.toml +++ b/toml/edmfx_bomex_box_v2.toml @@ -3,3 +3,7 @@ alias = "C_E" value = 0.044 type = "float" +[detr_coeff] +alias = "detr_coeff" +value = 0.01 +type = "float"