s = 0.6 # outflow + permanent burial [1/yr]
r = 20.0 # maximum sediment release rate [μg/(L⋅yr)]
m = 30.0 # P concentration at half-maximum release [μg/L]
q = 8 # steepness of the sediment release [-]
# Fraction of the maximum release rate that is active at concentration P.
# Written as x/(1+x) with x = (P/m)^q: computing P^q and m^q separately
# overflows once q gets large.
recycling_fraction(P, q) = (P / m)^q / (1 + (P / m)^q);
lake_P_release(P, q) = r * recycling_fraction(P, q);
lake_P_loss(P) = s * P;
# One year of lake dynamics.
lake_P_change(P, L, q) = L - lake_P_loss(P) + lake_P_release(P, q);
P_grid = 0:0.1:60
# HW 2's piecewise-linear release: nothing below 25, ramping to the maximum at 35.
R_hw2(P) = P <= 25 ? 0.0 : (P >= 35 ? 20.0 : 20 * (P - 25) / 10)
p_rec = plot(xlims=(0, 60), ylims=(0, 23), legend=:topleft,
xticks=[0, 10, 20, 25, 35, 40, 50, 60],
xlabel="P [μg/L]", ylabel="Sediment release [μg/(L⋅yr)]")
# Shade the three regimes FIRST so they sit behind the curves.
plot!(p_rec, [0, 25], [0, 0], fillrange=[23, 23], color=cb_blue,
alpha=0.12, linewidth=0, label=nothing)
plot!(p_rec, [25, 35], [0, 0], fillrange=[23, 23], color=cb_yellow,
alpha=0.18, linewidth=0, label=nothing)
plot!(p_rec, [35, 60], [0, 0], fillrange=[23, 23], color=cb_vermillion,
alpha=0.12, linewidth=0, label=nothing)
# Mark the regime boundaries with lines as well as fill -- washed-out colours
# on a projector should not be the only thing separating the three regimes.
for boundary in (25, 35)
plot!(p_rec, [boundary, boundary], [0, 23], color=:black, linewidth=2,
linestyle=:dash, label=nothing)
end
plot!(p_rec, P_grid, lake_P_release.(P_grid, q), color=:black, linewidth=5, label="smooth, q = 8")
plot!(p_rec, P_grid, lake_P_release.(P_grid, 12), color=cb_purple, linewidth=3,
linestyle=:dot, label="smooth, q = 12")
plot!(p_rec, P_grid, R_hw2.(P_grid), color=cb_orange, linewidth=3,
linestyle=:dash, label="HW 2, piecewise")
annotate!(p_rec, 12, 9, text("oxic:\nsediment holds P", 18, :center))
annotate!(p_rec, 30, 21, text("transition", 18, :center))
annotate!(p_rec, 47.5, 7, text("anoxic:\nreleasing at capacity", 18, :center))
plot!(p_rec, size=(1200, 500), left_margin=10mm)