AlgebraicJulia / DiagrammaticEquations.jl

MIT License
9 stars 1 forks source link

Multi-species Klausmeier #63

Open jpfairbanks opened 1 month ago

jpfairbanks commented 1 month ago

I worked this out for the Roe PR #62 as an example, but I think it is a nice example for the Klausmeier docs page:

# See Klausmeier Equation 2.a
Hydrodynamics = @decapode begin
  (w, consumption)::DualForm0
  dX::Form1
  (a,ν)::Constant
  ∂ₜ(w) == a - w - consumption + ν * L(dX, w)
end

# See Klausmeier Equation 2.b
Phytodynamics = @decapode begin
  (n,w)::DualForm0
  m::Constant
  consumption = w * n^2
  ∂ₜ(n) == consumption - m*n + Δ(n)
end

Superposition = @decapde begin
  total = part1 + part2
end

compose_klausmeier = @relation () begin
  phyto(N1, W, consumption1)
  phyto(N2, W, consumption2)
  superposition(consumption, consumption1, consumption2)
  hydro(consumption, W)
end

klausmeier_cospan = oapply(compose_klausmeier,
                           [Open(Phytodynamics, [:consumption, :w]), Open(Phytodynamics, [:consumption, :w])
                            Open(Hydrodynamics, [:total, :part1, :part2]),
                            Open(Hydrodynamics, [:consumption, :w])])
Klausmeier = apex(klausmeier_cospan)
lukem12345 commented 1 month ago

The thing to check is that this conserves mass. A particular test is this: if one were to split the density field for a plant species in half, and then duplicate it, will the expression result in the same dynamics.

Water depletion in the original model is quadratic in plant density in an area, times the water density in an area. You could implement some "normalized plant density" term. But in any regard, I would be cautious about using the term "superposition" without verifying that this indeed exhibits superpositioning.