Skip to content

Commit e82e4e7

Browse files
authored
Merge pull request #533 from CliMA/he/p3-multiple-solutions-doc-image
docs: add P3 multiple solutions example
2 parents 0a4bac4 + 4206d2d commit e82e4e7

File tree

2 files changed

+70
-11
lines changed

2 files changed

+70
-11
lines changed

docs/src/P3Scheme.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,14 @@ which looks like this:
284284

285285
```@example
286286
include("plots/P3SlopeParameterizations.jl")
287+
288+
nothing # hide
287289
```
288290
![](P3SlopeParameterizations_power_law.svg)
289291

290-
With this choice, it appears that some values of $\log(L/N)$ gives rise to multiple solutions for $λ$, as seen in the plot below.
291-
292-
!!! todo "TODO: Add plot of multiple solutions"
292+
With this choice, it appears that some values of $\log(L/N)$ gives rise to multiple solutions for $λ$, as seen in the plot below. Each vertical line shows a different solution for $λ$ for a given value of $\log(L/N)$. The right panel shows the number concentration distribution $N'(D)$ for the different solutions.
293293

294+
![](P3SlopeParameterizations_multiple_solutions.svg)
294295

295296
#### $μ$ as a constant
296297

docs/src/plots/P3SlopeParameterizations.jl

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import CloudMicrophysics as CM
33
import ClimaParams as CP
44
import CloudMicrophysics.Parameters as CMP
55
import CloudMicrophysics.P3Scheme as P3
6+
import Printf
67

78
FT = Float64
89

@@ -12,6 +13,7 @@ function make_slope_plot(slope_law, title)
1213
fig = Makie.Figure(size = (400, 300), figure_padding = 20)
1314

1415
ax = Makie.Axis(fig[1, 1]; title, xscale = log10, xlabel = "λ", ylabel = "μ")
16+
Makie.vlines!(λ_bnds, color = (:gray, 0.5))
1517

1618
Makie.lines!(ax, exp.(logλs), P3.get_μ.(slope_law, logλs))
1719

@@ -20,18 +22,74 @@ end
2022

2123

2224
# Power law parameterization
23-
slope_power_law = CMP.ParametersP3(FT).slope
25+
params = CMP.ParametersP3(FT)
26+
slope_power_law = params.slope
27+
28+
log_λ_from_μ(spl::CMP.SlopePowerLaw, μ) = log((μ + spl.c) / spl.a) / spl.b
29+
λ_bnds = log_λ_from_μ.(slope_power_law, [0.0, 6.0]) .|> exp
2430

2531
fig = Makie.with_theme(Makie.theme_minimal()) do
2632
make_slope_plot(slope_power_law, "μ as a function of λ (power law)")
2733
end
2834
Makie.save("P3SlopeParameterizations_power_law.svg", fig)
2935

30-
# Constant parameterization
31-
# params = CMP.ParametersP3(FT; slope_law = :constant)
32-
# slope_constant = params.slope
36+
# Multiple solutions issue
37+
38+
function make_multiple_solutions_plot()
39+
state = P3.get_state(params; F_rim = 0.0, ρ_r = 400.0)
40+
L_known = 2.39e-4
41+
N_known = 1e5
42+
target_log_L_div_N = log(L_known) - log(N_known)
43+
shape_problem(log_λ) = P3.log_L_div_N(state, log_λ) - target_log_L_div_N
44+
shape_sol = shape_problem.(logλs)
45+
# Brute-force roots
46+
dists = P3.get_distribution_parameters_all_solutions(state; L = L_known, N = N_known)
47+
48+
# Make figure
49+
fig = Makie.Figure(size = (800, 300), figure_padding = 20)
50+
ax = Makie.Axis(fig[1, 1];
51+
title = "Valid solutions of shape solver",
52+
xscale = log10, xlabel = "λ", ylabel = "shape solution", limits = ((10^3.55, 10^4.7), (-0.5, 0.5)),
53+
)
54+
Makie.vlines!(λ_bnds, color = (:gray, 0.5))
55+
Makie.hlines!(ax, 0; color = (:gray, 0.2))
56+
57+
Makie.lines!(ax, exp.(logλs), shape_sol; color = :black)
58+
map(dists) do dist
59+
λ = exp(dist.log_λ)
60+
Makie.vlines!(ax, λ; label = Printf.@sprintf("λ = %.0f m⁻¹", λ))
61+
end
62+
Makie.axislegend(ax; framevisible = true)
63+
64+
# N_ice axis
65+
mm_to_m = 1e-3 # m
66+
m_to_mm = 1e3 # mm
67+
m_to_cm = 1e2 # cm
68+
Ds = 10.0 .^ (-4:0.001:1.0) * mm_to_m # in m
69+
Ds_mm = Ds * m_to_mm # for plotting
70+
ax_opts = (;
71+
limits = (extrema(Ds_mm), nothing),
72+
xscale = log10,
73+
xlabel = "D (mm)",
74+
)
75+
Makie.Axis(
76+
fig[1, 2];
77+
ax_opts...,
78+
# ylabel = L"$N_{ice}$ (1/cm³)",
79+
ylabel = "[1/cm⁴]",
80+
title = "Number concentration distribution, N'(D)",
81+
)
82+
Makie.vlines!(state.D_th * m_to_mm, color = (:gray, 0.5))
83+
for dist in dists
84+
N′ = @. exp(P3.log_N′ice(dist, Ds))
85+
Makie.lines!(Ds_mm, N′ / m_to_cm^4)
86+
# Makie.lines!(Ds_mm, cumsum(N′.(Ds) .* Ds / m_to_cm^3)) # CUMULATIVE DISTRIBUTION
87+
end
3388

34-
# fig = Makie.with_theme(Makie.theme_minimal()) do
35-
# make_slope_plot(slope_constant, "μ as a constant")
36-
# end
37-
# save("P3SlopeParameterizations_constant.svg", fig)
89+
return fig
90+
end
91+
92+
fig = Makie.with_theme(Makie.theme_minimal()) do
93+
make_multiple_solutions_plot()
94+
end
95+
Makie.save("P3SlopeParameterizations_multiple_solutions.svg", fig)

0 commit comments

Comments
 (0)