|
4 | 4 |
|
5 | 5 | import CloudMicrophysics.MicrophysicsNonEq as CMNe |
6 | 6 | import CloudMicrophysics.Microphysics1M as CM1 |
| 7 | +import CloudMicrophysics.Microphysics2M as CM2 |
7 | 8 |
|
8 | 9 | import Thermodynamics as TD |
9 | 10 | import ClimaCore.Operators as Operators |
@@ -97,6 +98,59 @@ function set_precipitation_velocities!( |
97 | 98 | ) / Y.c.ρ |
98 | 99 | return nothing |
99 | 100 | end |
| 101 | +function set_precipitation_velocities!( |
| 102 | + Y, |
| 103 | + p, |
| 104 | + moisture_model::NonEquilMoistModel, |
| 105 | + precip_model::Microphysics2Moment, |
| 106 | +) |
| 107 | + (; ᶜwₗ, ᶜwᵢ, ᶜwᵣ, ᶜwₛ, ᶜwnₗ, ᶜwnᵣ, ᶜwₜqₜ, ᶜwₕhₜ, ᶜts, ᶜu) = p.precomputed |
| 108 | + (; q_liq, q_ice, q_rai, q_sno) = p.precomputed.ᶜspecific |
| 109 | + (; ᶜΦ) = p.core |
| 110 | + |
| 111 | + cm1c = CAP.microphysics_cloud_params(p.params) |
| 112 | + cm1p = CAP.microphysics_1m_params(p.params) |
| 113 | + cm2p = CAP.microphysics_2m_params(p.params) |
| 114 | + thp = CAP.thermodynamics_params(p.params) |
| 115 | + |
| 116 | + # compute the precipitation terminal velocity [m/s] |
| 117 | + # TODO sedimentation of snow is based on the 1M scheme |
| 118 | + @. ᶜwnᵣ = getindex( |
| 119 | + CM2.rain_terminal_velocity(cm2p.sb, cm2p.tv, q_rai, Y.c.ρ, Y.c.ρn_rai), |
| 120 | + 1, |
| 121 | + ) |
| 122 | + @. ᶜwᵣ = getindex( |
| 123 | + CM2.rain_terminal_velocity(cm2p.sb, cm2p.tv, q_rai, Y.c.ρ, Y.c.ρn_rai), |
| 124 | + 2, |
| 125 | + ) |
| 126 | + @. ᶜwₛ = CM1.terminal_velocity(cm1p.ps, cm1p.tv.snow, Y.c.ρ, q_sno) |
| 127 | + # compute sedimentation velocity for cloud condensate [m/s] |
| 128 | + # TODO sedimentation velocities of cloud condensates are based |
| 129 | + # on the 1M scheme. Sedimentation velocity of cloud number concentration |
| 130 | + # is equal to that of the mass. |
| 131 | + @. ᶜwnₗ = |
| 132 | + CMNe.terminal_velocity(cm1c.liquid, cm1c.Ch2022.rain, Y.c.ρ, q_liq) |
| 133 | + @. ᶜwₗ = CMNe.terminal_velocity(cm1c.liquid, cm1c.Ch2022.rain, Y.c.ρ, q_liq) |
| 134 | + @. ᶜwᵢ = |
| 135 | + CMNe.terminal_velocity(cm1c.ice, cm1c.Ch2022.small_ice, Y.c.ρ, q_ice) |
| 136 | + |
| 137 | + # compute their contributions to energy and total water advection |
| 138 | + @. ᶜwₜqₜ = |
| 139 | + Geometry.WVector( |
| 140 | + ᶜwₗ * Y.c.ρq_liq + |
| 141 | + ᶜwᵢ * Y.c.ρq_ice + |
| 142 | + ᶜwᵣ * Y.c.ρq_rai + |
| 143 | + ᶜwₛ * Y.c.ρq_sno, |
| 144 | + ) / Y.c.ρ |
| 145 | + @. ᶜwₕhₜ = |
| 146 | + Geometry.WVector( |
| 147 | + ᶜwₗ * Y.c.ρq_liq * (Iₗ(thp, ᶜts) + ᶜΦ + $(Kin(ᶜwₗ, ᶜu))) + |
| 148 | + ᶜwᵢ * Y.c.ρq_ice * (Iᵢ(thp, ᶜts) + ᶜΦ + $(Kin(ᶜwᵢ, ᶜu))) + |
| 149 | + ᶜwᵣ * Y.c.ρq_rai * (Iₗ(thp, ᶜts) + ᶜΦ + $(Kin(ᶜwᵣ, ᶜu))) + |
| 150 | + ᶜwₛ * Y.c.ρq_sno * (Iᵢ(thp, ᶜts) + ᶜΦ + $(Kin(ᶜwₛ, ᶜu))), |
| 151 | + ) / Y.c.ρ |
| 152 | + return nothing |
| 153 | +end |
100 | 154 |
|
101 | 155 | """ |
102 | 156 | set_precipitation_cache!(Y, p, precip_model, turbconv_model) |
@@ -262,6 +316,65 @@ function set_precipitation_cache!( |
262 | 316 | # in edmf sub-domains. |
263 | 317 | return nothing |
264 | 318 | end |
| 319 | +function set_precipitation_cache!(Y, p, ::Microphysics2Moment, _) |
| 320 | + (; dt) = p |
| 321 | + (; ᶜts) = p.precomputed |
| 322 | + (; ᶜSqₗᵖ, ᶜSqᵢᵖ, ᶜSqᵣᵖ, ᶜSqₛᵖ) = p.precomputed |
| 323 | + (; ᶜSnₗᵖ, ᶜSnᵣᵖ) = p.precomputed |
| 324 | + |
| 325 | + (; q_liq, q_rai, n_liq, n_rai) = p.precomputed.ᶜspecific |
| 326 | + |
| 327 | + ᶜSᵖ = p.scratch.ᶜtemp_scalar |
| 328 | + ᶜS₂ᵖ = p.scratch.ᶜtemp_scalar_2 |
| 329 | + |
| 330 | + # get thermodynamics and microphysics params |
| 331 | + (; params) = p |
| 332 | + cmp = CAP.microphysics_2m_params(params) |
| 333 | + thp = CAP.thermodynamics_params(params) |
| 334 | + |
| 335 | + # compute warm precipitation sources on the grid mean (based on SB2006 2M scheme) |
| 336 | + compute_warm_precipitation_sources_2M!( |
| 337 | + ᶜSᵖ, |
| 338 | + ᶜS₂ᵖ, |
| 339 | + ᶜSnₗᵖ, |
| 340 | + ᶜSnᵣᵖ, |
| 341 | + ᶜSqₗᵖ, |
| 342 | + ᶜSqᵣᵖ, |
| 343 | + Y.c.ρ, |
| 344 | + n_liq, |
| 345 | + n_rai, |
| 346 | + q_liq, |
| 347 | + q_rai, |
| 348 | + ᶜts, |
| 349 | + dt, |
| 350 | + cmp, |
| 351 | + thp, |
| 352 | + ) |
| 353 | + |
| 354 | + #TODO - implement 2M cold processes! |
| 355 | + @. ᶜSqᵢᵖ = 0 |
| 356 | + @. ᶜSqₛᵖ = 0 |
| 357 | + |
| 358 | + return nothing |
| 359 | +end |
| 360 | +function set_precipitation_cache!( |
| 361 | + Y, |
| 362 | + p, |
| 363 | + ::Microphysics2Moment, |
| 364 | + ::DiagnosticEDMFX, |
| 365 | +) |
| 366 | + error("Not implemented yet") |
| 367 | + return nothing |
| 368 | +end |
| 369 | +function set_precipitation_cache!( |
| 370 | + Y, |
| 371 | + p, |
| 372 | + ::Microphysics2Moment, |
| 373 | + ::PrognosticEDMFX, |
| 374 | +) |
| 375 | + error("Not implemented yet") |
| 376 | + return nothing |
| 377 | +end |
265 | 378 |
|
266 | 379 | """ |
267 | 380 | set_precipitation_surface_fluxes!(Y, p, precipitation model) |
|
301 | 414 | function set_precipitation_surface_fluxes!( |
302 | 415 | Y, |
303 | 416 | p, |
304 | | - precip_model::Microphysics1Moment, |
| 417 | + precip_model::Union{Microphysics1Moment, Microphysics2Moment}, |
305 | 418 | ) |
306 | 419 | (; surface_rain_flux, surface_snow_flux) = p.precomputed |
307 | 420 | (; col_integrated_precip_energy_tendency,) = p.conservation_check |
|
0 commit comments