diff --git a/src/variables.jl b/src/variables.jl index cca72f8..e7ae566 100644 --- a/src/variables.jl +++ b/src/variables.jl @@ -15,7 +15,7 @@ const PREDEFINED_EBM_VARIABLES = @variables begin (ε(t) = 0.5), [bounds = (0.0, 1.0), description = "planetary effective emissivity, unitless"] (C(t) = 0.6744), [bounds = (0.0, 1.0), description = "cloud fraction, unitless"] (ℓ(t) = 0.8), [bounds = (0.0, 1.0), description = "sine of latitude of ice-line"] - (CO2(t) = 400), [bounds = (200.0, 1800.0), description = "CO2 concentration, in ppm"] + (CO2(t) = 400.0), [bounds = (200.0, 1800.0), description = "CO2 concentration, in ppm"] # Observables that can never be dynamic variables and hence have no default value: (OLR(t)), [description = "outgoing longwave radiation"] (ASR(t)), [description = "absorved shortwave radiation"] @@ -28,16 +28,28 @@ export T, S, f, α, α_ice, α_cloud, ΔT, ε, ℓ, C, CO2, OLR, ASR physically_plausible_limits(x) Return a tuple (min, max) of plausible limiting values for the variable `x`. +If the variable does not have defined `bounds`, then the default value ± 20% is used. +If there is no default value, a heuristic is tried, and an error is thrown if it fails. """ function physically_plausible_limits(var) if ModelingToolkit.hasbounds(var) return getbounds(var) elseif !isnothing(default_value(var)) return (0.8default_value(var), 1.2default_value(var)) + else + return physically_plausible_limits(string(ModelingToolkit.getname(var))) + end +end + +function physically_plausible_limits(var::String)::Tuple{Float64, Float64} + if var[1] == 'T' + return (200, 350) + elseif var[1] == 'α' || var[1] == 'ε' || var[1] == 'C' + return (0, 1) else error(""" Unpsecified plausible physical limits for $(var): it has no defined bounds or a default variable. You need to redefine the variable to have either of the two. """) end -end +end \ No newline at end of file