Skip to content

Commit

Permalink
add businger and gryanik
Browse files Browse the repository at this point in the history
  • Loading branch information
LenkaNovak committed Oct 10, 2023
1 parent 5bb0901 commit df9933d
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 2 deletions.
5 changes: 3 additions & 2 deletions config/model_configs/interactive_debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ turb_flux_partition: "CombinedStateFluxes"
h_elem: 4
dt_save_restart: "5days"
precip_model: "0M"
run_name: "interactive_debug_run"
job_id: "interactive_debug_run"
run_name: "interactive_debug_run_bus"
job_id: "interactive_debug_run_bus"
monthly_checkpoint: true
universal_function: "Businger" # "Businger" or "Gryanik"
4 changes: 4 additions & 0 deletions experiments/AMIP/modular/cli_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ function argparse_settings()
default = "PrescribedSurface"
"--atmos_config_file"
help = "A yaml file used to set the atmospheric model configuration. If nothing is specified, the default configuration is used."
"--universal_function"
help = "Universal function type [`Businger` (default), `Gryanik`]"
arg_type = String
default = "Businger"
# ClimaLSM specific
"--land_albedo_type"
help = "Access land surface albedo information from data file. [`function`, `map_static`, `map_temporal`]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import ClimaCoupler.FieldExchanger: get_thermo_params
import ClimaCoupler.Interfacer: get_field, update_field!, name, get_model_state_vector
using StaticArrays

include("climaatmos_param_init.jl")

# the clima atmos `integrator` is now defined
struct ClimaAtmosSimulation{P, Y, D, I} <: AtmosModelSimulation
params::P
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import ClimaAtmos.TurbulenceConvection as TC
import ClimaAtmos.TurbulenceConvection.Parameters as TCP
import CLIMAParameters as CP
import RRTMGP.Parameters as RP
import SurfaceFluxes as SF
import SurfaceFluxes.UniversalFunctions as UF
import Insolation.Parameters as IP
import Thermodynamics as TD
import CloudMicrophysics as CM

function get_uf_pairs(::UF.Businger, toml_dict::CP.AbstractTOMLDict)
aliases = [
"Pr_0_Businger",
"a_m_Businger",
"a_h_Businger",
"ζ_a_Businger",
"γ_Businger",
]
pairs = CP.get_parameter_values!(toml_dict, aliases, "UniversalFunctions")
pairs = (; pairs...) # convert to NamedTuple
pairs = (;
Pr_0 = pairs.Pr_0_Businger,
a_m = pairs.a_m_Businger,
a_h = pairs.a_h_Businger,
ζ_a = pairs.ζ_a_Businger,
γ = pairs.γ_Businger,
)
end

function get_uf_pairs(::UF.Gryanik, toml_dict::CP.AbstractTOMLDict)
aliases = [
"Pr_0_Gryanik",
"a_m_Gryanik",
"a_h_Gryanik",
"b_m_Gryanik",
"b_h_Gryanik",
"ζ_a_Gryanik",
"γ_Gryanik",
]
pairs = CP.get_parameter_values!(toml_dict, aliases, "UniversalFunctions")
pairs = (; pairs...) # convert to NamedTuple
pairs = (;
Pr_0 = pairs.Pr_0_Gryanik,
a_m = pairs.a_m_Gryanik,
a_h = pairs.a_h_Gryanik,
b_m = pairs.a_m_Gryanik,
b_h = pairs.a_h_Gryanik,
ζ_a = pairs.ζ_a_Gryanik,
γ = pairs.γ_Gryanik,
)
end

function create_parameter_set(config::CA.AtmosConfig)
# Helper function that creates a parameter struct. If a struct has nested
# parameter structs, they must be passed to subparam_structs as a NamedTuple.
function create_parameter_struct(param_struct; subparam_structs = (;))
aliases = string.(fieldnames(param_struct))
aliases = setdiff(aliases, string.(propertynames(subparam_structs)))
pairs = CP.get_parameter_values!(toml_dict, aliases)
# Workaround for setting τ_precip = dt
if parsed_args["override_τ_precip"] &&
param_struct == CM.Parameters.CloudMicrophysicsParameters
pairs = (;
pairs...,
τ_precip = FT(CA.time_to_seconds(parsed_args["dt"])),
)
end
return param_struct{FT, typeof.(values(subparam_structs))...}(;
pairs...,
subparam_structs...,
)
end

(; toml_dict, parsed_args) = config
FT = CP.float_type(toml_dict)

thermo_params =
create_parameter_struct(TD.Parameters.ThermodynamicsParameters)
rrtmgp_params = create_parameter_struct(RP.RRTMGPParameters)
insolation_params = create_parameter_struct(IP.InsolationParameters)
microphys_params = create_parameter_struct(
CM.Parameters.CloudMicrophysicsParameters;
subparam_structs = (; thermo_params),
)

if config.universal_function == "Businger"
universal_function = UF.Businger
elseif config.universal_function == "Gryanik"
universal_function = UF.Gryanik
else
error("Unknown universal function: $(config.universal_function)")
end

pairs = get_uf_pairs(universal_function, toml_dict)
ufp = UF.BusingerParams{FT}(; pairs...)

surf_flux_params = create_parameter_struct(
SF.Parameters.SurfaceFluxesParameters;
subparam_structs = (; ufp, thermo_params),
)
turbconv_params = create_parameter_struct(
TCP.TurbulenceConvectionParameters;
subparam_structs = (; microphys_params, surf_flux_params),
)
return create_parameter_struct(
CAP.ClimaAtmosParameters;
subparam_structs = (;
thermodynamics_params = thermo_params,
rrtmgp_params,
insolation_params,
microphysics_params = microphys_params,
surface_fluxes_params = surf_flux_params,
turbconv_params,
),
)
end

0 comments on commit df9933d

Please sign in to comment.