Skip to content

Commit

Permalink
finish docs: variables and integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Datseris committed Feb 20, 2024
1 parent 860583f commit 46a6963
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
40 changes: 37 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,54 @@
# EnergyBalanceModels.jl

## Global symbolic variables
## [Premade symbolic variable instances](@id global_vars)

For convenience, EnergyBalanceModels.jl defines and exports these global variables:
For convenience, EnergyBalanceModels.jl defines and exports some symbolic variables. These are used throughout the library as the default variables in [implemented processes](@id processes).
When going through documentation strings of processes, such as [`BasicRadiationBalance`](@ref),
you will notice that the function call signature is like:

```julia
BasicRadiationBalance(; T=T, kwargs...)
```

This `T=T` means that the keyword argument `T`, which represents the "temperature variable", takes the value of `EnergyBalanceModels.T`, which itself is a premade symbolic variable instance that is exported by EnergyBalanceModels.jl. You can pass in your own variables instead, by doing
```julia
@variables T1_tropics = 310.0
BasicRadiationBalance(; T=T1_tropics, kwargs...)
```

The exported symbolic variables are:

```@example MAIN
using EnergyBalanceModels
GLOBAL_EBM_VARIABLES
PREDEFINED_EBM_VARIABLES
```

## Default values, limits, etc.

All [exported symbolic variable instances](@ref) are defiled with a default value and have plausible physical limits that can be obtained with the following function:

```@docs
physically_plausible_limits(::String)
```

e.g.,

```@example MAIN
physically_plausible_limits(T)
```


## Integration with DynamicalSystems.jl

EnergyBalanceModels.jl integrates with [DynamicalSystems.jl](https://juliadynamics.github.io/DynamicalSystemsDocs.jl/dynamicalsystems/dev/) in many ways.


```@docs
physically_plausible_limits(::DynamicalSystem)
physically_plausible_ic_sampler
physically_plausible_grid
```

# ## Utilities

```@docs
Expand Down
15 changes: 15 additions & 0 deletions src/statespace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ function physically_plausible_limits(ds::DynamicalSystem)
return minmax
end

"""
physically_plausible_ic_sampler(ds::DynamicalSystem)
Return a `sampler` that can be called as a 0-argument function `sampler()`, which
yields random initial conditions within the hyperrectangle defined by the
[`physically_plausible_limits`](@ref) of `ds`.
The `sampler` is useful to give to e.g., `DynamicalSystems.basins_fractions`.
"""
function physically_plausible_ic_sampler(ds::DynamicalSystem)
minmax = physically_plausible_limits(ds)
mini = getindex.(minmax, 1)
Expand All @@ -22,6 +29,14 @@ function physically_plausible_ic_sampler(ds::DynamicalSystem)
return sampler
end

"""
physically_plausible_grid(ds::DynamicalSystem, n = 101)
Return a `grid` that is a tuple of `range` objects that each spans the
[`physically_plausible_limits`](@ref) of `ds`.
`n` can be an integer or a vector of integers (for each dimension).
The resulting `grid` is useful to give to `DynamicalSystems.AttractorsViaRecurrences`.
"""
function physically_plausible_grid(ds::DynamicalSystem, n = 101)
minmax = physically_plausible_limits(ds)
if n isa Integer
Expand Down
12 changes: 8 additions & 4 deletions src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# In the final generated energy balance model it is not necessary that all of these
# will exist in the equations.

const GLOBAL_EBM_VARIABLES = @variables begin
const PREDEFINED_EBM_VARIABLES = @variables begin
T(t) = 290.0 # [description = "temperature, in Kelvin"]
S(t) = 1.0 # [description = "insolation in units relative to solar constant"]
f(t) = 0.0 # [description = "external forcing, normalized to units of the solar constant"]
Expand Down Expand Up @@ -34,13 +34,17 @@ function physically_plausible_limits(var::String)::Tuple{Float64, Float64}
if var[1] == 'T'
return (200, 350)
elseif var == "α_ice" || var == "α_clouds"
return (0, 0.75)
elseif var[1] == 'α' || var[1] == 'ε' || var[1] == 'C'
return (0, 0.5)
elseif var[1] == 'α' || var[1] == 'ε' || var[1] == 'C' || var[1] == ''
return (0, 1)
elseif var == "ΔT"
return (5.0, 60.0)
elseif var == "CO2"
return (200.0, 1600.0)
elseif !isnothing(default_value(var))
return (0.8default_value(var), 1.2default_value(var))
else
error("Unpsecified plausible physical limits for $(var). "*
error("Unpsecified plausible physical limits for $(var) or no default value. "*
"Please edit function `physically_plausible_limits` and add one.")
end
end
Expand Down

0 comments on commit 46a6963

Please sign in to comment.