|
5 | 5 | import CloudMicrophysics.MicrophysicsNonEq as CMNe |
6 | 6 | import CloudMicrophysics.Microphysics1M as CM1 |
7 | 7 | import CloudMicrophysics.Microphysics2M as CM2 |
| 8 | +import CloudMicrophysics.P3Scheme as CMP3 |
8 | 9 |
|
9 | 10 | import Thermodynamics as TD |
10 | 11 | import ClimaCore.Operators as Operators |
@@ -506,6 +507,68 @@ function set_precipitation_velocities!( |
506 | 507 | return nothing |
507 | 508 | end |
508 | 509 |
|
| 510 | +function set_precipitation_velocities!( |
| 511 | + Y, p, ::NonEquilMoistModel, ::Microphysics2MomentP3, |
| 512 | +) |
| 513 | + ## liquid quantities (2M warm rain) |
| 514 | + (; ᶜwₗ, ᶜwᵣ, ᶜwnₗ, ᶜwnᵣ, ᶜwₜqₜ, ᶜwₕhₜ, ᶜts, ᶜu) = p.precomputed |
| 515 | + (; ᶜΦ) = p.core |
| 516 | + |
| 517 | + (; ρ, ρq_liq, ρn_liq, ρq_rai, ρn_rai) = Y.c |
| 518 | + (; sb, rtv, ctv) = p.params.microphysics_2mp3_params.warm |
| 519 | + thp = CAP.thermodynamics_params(p.params) |
| 520 | + |
| 521 | + # Number- and mass weighted rain terminal velocity [m/s] |
| 522 | + ᶜrai_w_terms = @. lazy( |
| 523 | + CM2.rain_terminal_velocity( |
| 524 | + sb, rtv, |
| 525 | + max(zero(ρ), specific(ρq_rai, ρ)), |
| 526 | + ρ, max(zero(ρ), ρn_rai), |
| 527 | + ), |
| 528 | + ) |
| 529 | + @. ᶜwnᵣ = getindex(ᶜrai_w_terms, 1) |
| 530 | + @. ᶜwᵣ = getindex(ᶜrai_w_terms, 2) |
| 531 | + # Number- and mass weighted cloud liquid terminal velocity [m/s] |
| 532 | + ᶜliq_w_terms = @. lazy( |
| 533 | + CM2.cloud_terminal_velocity( |
| 534 | + sb.pdf_c, ctv, |
| 535 | + max(zero(ρ), specific(ρq_liq, ρ)), |
| 536 | + ρ, max(zero(ρ), ρn_liq), |
| 537 | + ), |
| 538 | + ) |
| 539 | + @. ᶜwnₗ = getindex(ᶜliq_w_terms, 1) |
| 540 | + @. ᶜwₗ = getindex(ᶜliq_w_terms, 2) |
| 541 | + |
| 542 | + ## Ice quantities |
| 543 | + (; ρq_ice, ρn_ice, ρq_rim, ρb_rim) = Y.c |
| 544 | + (; ᶜwᵢ) = p.precomputed |
| 545 | + (; cold) = CAP.microphysics_2mp3_params(p.params) |
| 546 | + |
| 547 | + # Number- and mass weighted ice terminal velocity [m/s] |
| 548 | + # Calculate terminal velocities |
| 549 | + (; ᶜlogλ, ᶜwnᵢ) = p.precomputed |
| 550 | + use_aspect_ratio = true # TODO: Make a config option |
| 551 | + ᶜF_rim = @. lazy(ρq_rim / ρq_ice) |
| 552 | + ᶜρ_rim = @. lazy(ρq_rim / ρb_rim) |
| 553 | + ᶜstate_p3 = @. lazy(CMP3.P3State(cold.params, |
| 554 | + max(0, ρq_ice), max(0, ρn_ice), ᶜF_rim, ᶜρ_rim, |
| 555 | + )) |
| 556 | + @. ᶜlogλ = CMP3.get_distribution_logλ(ᶜstate_p3) |
| 557 | + args = (cold.velocity_params, ρ, ᶜstate_p3, ᶜlogλ) |
| 558 | + @. ᶜwnᵢ = CMP3.ice_terminal_velocity_number_weighted(args...; use_aspect_ratio) |
| 559 | + @. ᶜwᵢ = CMP3.ice_terminal_velocity_mass_weighted(args...; use_aspect_ratio) |
| 560 | + |
| 561 | + # compute their contributions to energy and total water advection |
| 562 | + @. ᶜwₜqₜ = Geometry.WVector(ᶜwₗ * ρq_liq + ᶜwᵢ * ρq_ice + ᶜwᵣ * ρq_rai) / ρ |
| 563 | + @. ᶜwₕhₜ = |
| 564 | + Geometry.WVector( |
| 565 | + ᶜwₗ * ρq_liq * (Iₗ(thp, ᶜts) + ᶜΦ + $(Kin(ᶜwₗ, ᶜu))) + |
| 566 | + ᶜwᵢ * ρq_ice * (Iᵢ(thp, ᶜts) + ᶜΦ + $(Kin(ᶜwᵢ, ᶜu))) + |
| 567 | + ᶜwᵣ * ρq_rai * (Iₗ(thp, ᶜts) + ᶜΦ + $(Kin(ᶜwᵣ, ᶜu))), |
| 568 | + ) / ρ |
| 569 | + return nothing |
| 570 | +end |
| 571 | + |
509 | 572 | """ |
510 | 573 | set_precipitation_cache!(Y, p, microphysics_model, turbconv_model) |
511 | 574 |
|
@@ -744,6 +807,37 @@ function set_precipitation_cache!( |
744 | 807 | return nothing |
745 | 808 | end |
746 | 809 |
|
| 810 | +function set_precipitation_cache!(Y, p, ::Microphysics2MomentP3, ::Nothing) |
| 811 | + ### Rainy processes (2M) |
| 812 | + (; turbconv_model) = p.atmos |
| 813 | + set_precipitation_cache!(Y, p, Microphysics2Moment(), turbconv_model) |
| 814 | + # NOTE: the above function sets `ᶜSqᵢᵖ` to `0`. For P3, need to update `ᶜSqᵢᵖ` below!! |
| 815 | + |
| 816 | + ### Icy processes (P3) |
| 817 | + (; ᶜScoll, ᶜts, ᶜlogλ) = p.precomputed |
| 818 | + |
| 819 | + # get thermodynamics and microphysics params |
| 820 | + (; params) = p |
| 821 | + params_2mp3 = CAP.microphysics_2mp3_params(params) |
| 822 | + thermo_params = CAP.thermodynamics_params(params) |
| 823 | + |
| 824 | + ᶜY_reduced = (; |
| 825 | + Y.c.ρ, |
| 826 | + # condensate |
| 827 | + Y.c.ρq_liq, Y.c.ρn_liq, Y.c.ρq_rai, Y.c.ρn_rai, |
| 828 | + # ice |
| 829 | + Y.c.ρq_ice, Y.c.ρn_ice, Y.c.ρq_rim, Y.c.ρb_rim, |
| 830 | + ) |
| 831 | + |
| 832 | + # compute warm precipitation sources on the grid mean (based on SB2006 2M scheme) |
| 833 | + compute_cold_precipitation_sources_P3!( |
| 834 | + ᶜScoll, params_2mp3, thermo_params, ᶜY_reduced, ᶜts, ᶜlogλ, |
| 835 | + ) |
| 836 | + |
| 837 | + return nothing |
| 838 | + |
| 839 | +end |
| 840 | + |
747 | 841 | """ |
748 | 842 | set_precipitation_surface_fluxes!(Y, p, precipitation model) |
749 | 843 |
|
@@ -833,3 +927,8 @@ function set_precipitation_surface_fluxes!( |
833 | 927 |
|
834 | 928 | return nothing |
835 | 929 | end |
| 930 | + |
| 931 | +function set_precipitation_surface_fluxes!(Y, p, ::Microphysics2MomentP3) |
| 932 | + set_precipitation_surface_fluxes!(Y, p, Microphysics2Moment()) |
| 933 | + # TODO: Figure out what to do for ρn_ice, ρq_rim, ρb_rim |
| 934 | +end |
0 commit comments