|  | 
| 1 | 1 | import OrdinaryDiffEq as ODE | 
| 2 |  | -using Plots | 
|  | 2 | +using CairoMakie | 
| 3 | 3 | 
 | 
| 4 | 4 | import ClimaCore as CC | 
| 5 | 5 | import ClimaParams as CP | 
| @@ -86,39 +86,52 @@ function run_box_simulation(::Type{FT}, opts) where {FT} | 
| 86 | 86 | 
 | 
| 87 | 87 |     # plot results | 
| 88 | 88 |     time = solver.t | 
| 89 |  | -    q_liq = [] | 
| 90 |  | -    q_rai = [] | 
| 91 |  | -    for u in solver.u | 
| 92 |  | -        q_liq = [q_liq; parent(u.ρq_liq) / (opts["rhod"] .+ parent(u.ρq_tot))] | 
| 93 |  | -        q_rai = [q_rai; parent(u.ρq_rai) / (opts["rhod"] .+ parent(u.ρq_tot))] | 
|  | 89 | +    q_liq = map(solver.u) do u | 
|  | 90 | +        only(parent(u.ρq_liq)) / (opts["rhod"] .+ only(parent(u.ρq_tot))) | 
|  | 91 | +    end | 
|  | 92 | +    q_rai = map(solver.u) do u | 
|  | 93 | +        only(parent(u.ρq_rai)) / (opts["rhod"] .+ only(parent(u.ρq_tot))) | 
| 94 | 94 |     end | 
| 95 | 95 | 
 | 
| 96 |  | -    plot(time ./ 60, q_liq .* 1000, label = "qc", lw = 2) | 
| 97 |  | -    plot!(time ./ 60, q_rai .* 1000, label = "qr", lw = 2) | 
| 98 |  | -    p1 = plot!( | 
| 99 |  | -        xlabel = "time [m]", | 
| 100 |  | -        ylabel = "specific water content [g/kg]", | 
| 101 |  | -        legend = :right, | 
| 102 |  | -        left_margin = 3Plots.mm, | 
| 103 |  | -        bottom_margin = 3Plots.mm, | 
| 104 |  | -    ) | 
|  | 96 | +    s_to_min = 1 / 60 | 
|  | 97 | +    m⁻³_to_cm⁻³ = 1e-6 | 
|  | 98 | + | 
|  | 99 | +    function plot_qc_qr!(gp) | 
|  | 100 | +        ax = Axis(gp; xlabel = "time [m]", ylabel = "specific water content [g/kg]") | 
|  | 101 | +        lines!(ax, time * s_to_min, q_liq .* 1000, label = "qc", linewidth = 2) | 
|  | 102 | +        lines!(ax, time * s_to_min, q_rai .* 1000, label = "qr", linewidth = 2) | 
|  | 103 | +        axislegend(ax; position = :rc) | 
|  | 104 | +        nothing | 
|  | 105 | +    end | 
| 105 | 106 | 
 | 
| 106 |  | -    if opts["precipitation_choice"] == "Precipitation1M" | 
| 107 |  | -        plot(p1, size = (400, 300)) | 
| 108 |  | -    elseif opts["precipitation_choice"] == "Precipitation2M" | 
| 109 |  | -        N_liq = [] | 
| 110 |  | -        N_rai = [] | 
| 111 |  | -        for u in solver.u | 
| 112 |  | -            N_liq = [N_liq; parent(u.N_liq)] | 
| 113 |  | -            N_rai = [N_rai; parent(u.N_rai)] | 
|  | 107 | +    with_theme(theme_minimal()) do | 
|  | 108 | +        if opts["precipitation_choice"] == "Precipitation1M" | 
|  | 109 | +            fig = Figure(size = (400, 300)) | 
|  | 110 | +            plot_qc_qr!(fig[1, 1]) | 
|  | 111 | +        elseif opts["precipitation_choice"] == "Precipitation2M" | 
|  | 112 | +            N_liq = map(solver.u) do u | 
|  | 113 | +                only(parent(u.N_liq)) | 
|  | 114 | +            end | 
|  | 115 | +            N_rai = map(solver.u) do u | 
|  | 116 | +                only(parent(u.N_rai)) | 
|  | 117 | +            end | 
|  | 118 | +            fig = Figure(size = (400, 300)) | 
|  | 119 | +            plot_qc_qr!(fig[1, 1]) | 
|  | 120 | +            ax = Axis(fig[1, 2]; xlabel = "time [m]", ylabel = "Nc [1/cm³]") | 
|  | 121 | +            lines!(ax, time * s_to_min, N_liq * m⁻³_to_cm⁻³, linewidth = 2) | 
|  | 122 | +            axr = Axis( | 
|  | 123 | +                fig[1, 2]; | 
|  | 124 | +                xlabel = "time [m]", ylabel = "Nr [1/cm³]", | 
|  | 125 | +                yaxisposition = :right, rightspinevisible = true, | 
|  | 126 | +            ) | 
|  | 127 | +            hidespines!(axr, :l, :b, :t)  # don't hide right spine | 
|  | 128 | +            hidexdecorations!(axr) | 
|  | 129 | +            lines!(axr, time * s_to_min, N_rai * m⁻³_to_cm⁻³, linewidth = 2, color = Cycled(2)) | 
| 114 | 130 |         end | 
| 115 |  | -        plot(time ./ 60, N_liq ./ 10^6, xlabel = "time [m]", ylabel = "Nc [1/cm^3]", label = "N_c", lw = 2) | 
| 116 |  | -        plot!(twinx(), time ./ 60, N_rai ./ 10^6, ylabel = "Nr [1/cm^3]", label = "N_r", c = 2, lw = 2) | 
| 117 |  | -        p2 = plot!(legend = false, right_margin = 3Plots.mm) | 
| 118 |  | -        plot(p1, p2, size = (800, 300)) | 
|  | 131 | +        fig | 
| 119 | 132 |     end | 
| 120 | 133 | 
 | 
| 121 |  | -    savefig(path * "/result.pdf") | 
|  | 134 | +    save(joinpath(path, "result.pdf"), fig) | 
| 122 | 135 | 
 | 
| 123 | 136 |     return solver | 
| 124 | 137 | end | 
|  | 
0 commit comments