Skip to content

Commit

Permalink
Display composition diagrams in EBM-Melt (#285)
Browse files Browse the repository at this point in the history
Co-authored-by: James P. Fairbanks <[email protected]>
  • Loading branch information
lukem12345 and jpfairbanks authored Dec 4, 2024
1 parent af8a502 commit 7bfa6d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ DecapodesCUDAExt = "CUDA"
ACSets = "0.2"
Aqua = "0.8"
CUDA = "5.2"
CombinatorialSpaces = "0.6.3"
ComponentArrays = "0.15"
CombinatorialSpaces = "0.6.8"
DiagrammaticEquations = "0.1.7"
Distributions = "0.25"
GeometryBasics = "0.4.2"
Expand Down
24 changes: 16 additions & 8 deletions docs/src/ebm_melt/ebm_melt.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ ice_dynamics = apex(oapply(ice_dynamics_composition_diagram,
[Open(halfar_eq2, [:Γ,:n]),
Open(glens_law, [:Γ,:n])]))
draw_composition(ice_dynamics_composition_diagram)
```

The composition pattern tells you how to couple the variables and introduces namespaces that we will use later when supplying initial conditions.

The following code creates the Budyko-Sellers model as a composite of individual terms.

```@example DEC
energy_balance = @decapode begin
(Tₛ, ASR, OLR, HT)::Form0
C::Constant
Expand Down Expand Up @@ -156,9 +165,12 @@ budyko_sellers = apex(oapply(budyko_sellers_composition_diagram,
Open(outgoing_longwave_radiation, [:Tₛ, :OLR]),
Open(heat_transfer, [:Tₛ, :HT, :cosϕᵖ]),
Open(insolation, [:Q, :cosϕᵖ])]))
nothing # hide
draw_composition(budyko_sellers_composition_diagram)
```

Our full model can then be composed by adding terms for melting of water. We will assume that the meltwater is transported by diffusion because the transport of meltwater is so much faster than the melting process itself. If you wanted to increase the physical realism of this model, using a different model of melting and water transport would be a good place to start.

``` @example DEC
warming = @decapode begin
Tₛ::Form0
Expand All @@ -177,14 +189,12 @@ end
budyko_sellers_halfar_water_composition_diagram = @relation () begin
budyko_sellers(Tₛ)
warming(A, Tₛ)
melting(Tₛ, h, melt)
halfar(A, h, melt)
end
nothing # hide
draw_composition(budyko_sellers_halfar_water_composition_diagram)
```

``` @example DEC
Expand Down Expand Up @@ -246,6 +256,7 @@ u₀ = ComponentArray(
h = h₀,
melting_water = water)
# The underscore-separated words are the namespaces that were introduced by oapply.
constants_and_parameters = (
budyko_sellers_absorbed_radiation_α = α,
budyko_sellers_outgoing_radiation_A = A,
Expand All @@ -260,7 +271,6 @@ constants_and_parameters = (
melting_Dₕ₂ₒ = Dₕ₂ₒ)
# Define how symbols map to Julia functions
function generate(sd, my_symbol; hodge=GeometricHodge())
op = @match my_symbol begin
:♯ => begin
Expand All @@ -270,8 +280,6 @@ function generate(sd, my_symbol; hodge=GeometricHodge())
:mag => x -> begin
norm.(x)
end
:^ => (x,y) -> x .^ y
:* => (x,y) -> x .* y
x => error("Unmatched operator $my_symbol")
end
return (args...) -> op(args...)
Expand Down

0 comments on commit 7bfa6d9

Please sign in to comment.