Skip to content

Commit

Permalink
restor string-based bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Datseris committed Feb 20, 2024
1 parent d1f873a commit 4c7e60d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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

0 comments on commit 4c7e60d

Please sign in to comment.