|
131 | 131 | @. θ_dry = TD.dry_pottemp(thermo_params, T, ρ_dry) |
132 | 132 | @. θ_liq_ice = TD.liquid_ice_pottemp(thermo_params, ts) |
133 | 133 | end |
| 134 | +@inline function precompute_aux_thermo!(ms::NonEquilibriumMoisture, ps::Precipitation2M_P3, Y, aux) |
| 135 | + precompute_aux_thermo!(ms, ps.liq_precip, Y, aux) |
| 136 | + # precompute_aux_thermo!(ms, ps.ice_precip, Y, aux) # no additional `IcePrecipitationP3` thermo state |
| 137 | +end |
134 | 138 | function separate_liq_rai(FT, moments, pdists, cloudy_params, ρd) |
135 | 139 | tmp = CL.ParticleDistributions.get_standard_N_q(pdists, cloudy_params.size_threshold / cloudy_params.norms[2]) |
136 | 140 | moments_like = ntuple(length(moments)) do k |
|
190 | 194 | @. term_vel_rai = CM1.terminal_velocity(ps.rain, ps.sedimentation.rain, ρ, q_rai) |
191 | 195 | @. term_vel_sno = CM1.terminal_velocity(ps.snow, ps.sedimentation.snow, ρ, q_sno) |
192 | 196 | end |
193 | | -@inline function precompute_aux_precip!(ps::Precipitation2M, Y, aux) |
| 197 | +@inline function precompute_aux_precip!(ps::Precipitation2M, Y, aux) # called by `make_rhs_function` |
194 | 198 |
|
195 | 199 | FT = eltype(Y.ρq_rai) |
196 | 200 | sb2006 = ps.rain_formation |
|
207 | 211 | @. term_vel_N_rai = getindex(CM2.rain_terminal_velocity(sb2006, vel_scheme, q_rai, ρ, N_rai), 1) |
208 | 212 | @. term_vel_rai = getindex(CM2.rain_terminal_velocity(sb2006, vel_scheme, q_rai, ρ, N_rai), 2) |
209 | 213 | end |
| 214 | +@inline function precompute_aux_precip!(ps::IcePrecipitationP3, Y, aux) |
| 215 | + # State, `Y`, includes: ρq_ice, ρq_rim, N_ice, B_rim |
| 216 | + |
| 217 | + # update state variables |
| 218 | + (; sedimentation, params) = ps |
| 219 | + (; ρq_ice, ρq_rim, N_ice, B_rim) = Y |
| 220 | + (; ρ) = aux.thermo_variables |
| 221 | + (; F_rim, ρ_rim, logλ) = aux.microph_variables |
| 222 | + (; term_vel_N_ice, term_vel_q_ice) = aux.velocities |
| 223 | + |
| 224 | + # Calculate derived rime quantities |
| 225 | + # @. F_rim = ifelse(Y.ρq_ice < eps(FT), FT(0), Y.ρq_rim / Y.ρq_ice) |
| 226 | + # @. ρ_rim = ifelse(Y.B_rim < eps(FT), FT(0), Y.ρq_rim / Y.B_rim) |
| 227 | + |
| 228 | + @. F_rim = ifelse(isnan(ρq_rim / ρq_ice), zero(ρq_rim), ρq_rim / ρq_ice) |
| 229 | + @. ρ_rim = ifelse(isnan(ρq_rim / B_rim), zero(ρq_rim), ρq_rim / B_rim) |
| 230 | + # Calculate distribution parameters |
| 231 | + @. logλ = CMP3.get_distribution_logλ(CMP3.P3State(params, ρq_ice, N_ice, F_rim, ρ_rim)) |
| 232 | + |
| 233 | + # Calculate terminal velocities |
| 234 | + use_aspect_ratio = true |
| 235 | + @. term_vel_N_ice = CMP3.ice_terminal_velocity_number_weighted( |
| 236 | + sedimentation, ρ, CMP3.P3State(params, ρq_ice, N_ice, F_rim, ρ_rim), logλ; use_aspect_ratio |
| 237 | + ) |
| 238 | + @. term_vel_q_ice = CMP3.ice_terminal_velocity_mass_weighted( |
| 239 | + sedimentation, ρ, CMP3.P3State(params, ρq_ice, N_ice, F_rim, ρ_rim), logλ; use_aspect_ratio |
| 240 | + ) |
| 241 | + # args = (ps.sedimentation, ρ, ps.params, ρq_ice, N_ice, F_rim, ρ_rim, logλ) |
| 242 | + # @. term_vel_N_ice = CMP3.ice_terminal_velocity_number_weighted(args...; use_aspect_ratio) |
| 243 | + # @. term_vel_q_ice = CMP3.ice_terminal_velocity_mass_weighted(args...; use_aspect_ratio) |
| 244 | + |
| 245 | +end |
| 246 | +function precompute_aux_precip!(ps::Precipitation2M_P3, Y, aux) |
| 247 | + precompute_aux_precip!(ps.liq_precip, Y, aux) |
| 248 | + precompute_aux_precip!(ps.ice_precip, Y, aux) |
| 249 | +end |
210 | 250 | @inline function precompute_aux_precip!(ps::PrecipitationP3, Y, aux) |
211 | 251 |
|
212 | 252 | # update state variables |
|
373 | 413 |
|
374 | 414 | @. aux.cloud_sources = to_sources(S_q_liq, S_q_ice) |
375 | 415 | end |
| 416 | +@inline function precompute_aux_moisture_sources!(ms::NonEquilibriumMoisture, ps::Precipitation2M_P3, aux) |
| 417 | + precompute_aux_moisture_sources!(ms, ps.liq_precip, aux) |
| 418 | + # precompute_aux_moisture_sources!(ms, ps.ice_precip, aux) # no additional `IcePrecipitationP3` thermo state |
| 419 | +end |
376 | 420 |
|
377 | 421 | @inline function precompute_aux_precip_sources!(ps::AbstractPrecipitationStyle, aux) |
378 | 422 | error("precompute_aux not implemented for a given $ps") |
|
646 | 690 | end |
647 | 691 | end |
648 | 692 |
|
| 693 | +@inline function precompute_aux_precip_sources!(ps::IcePrecipitationP3, Y, aux) |
| 694 | + |
| 695 | + # TODO: So far, implemented directly in precip_sources_tendency! |
| 696 | + |
| 697 | + return nothing |
| 698 | +end |
| 699 | + |
649 | 700 | @inline function precompute_aux_precip_sources!(ps::PrecipitationP3, aux) |
650 | 701 | # TODO [P3] |
651 | 702 | return nothing |
|
736 | 787 | @inline function cloud_sources_tendency!(::EquilibriumMoisture, ::AbstractPrecipitationStyle, dY, Y, aux, t) end |
737 | 788 | @inline function cloud_sources_tendency!(ms::NonEquilibriumMoisture, ps::AbstractPrecipitationStyle, dY, Y, aux, t) |
738 | 789 |
|
739 | | - precompute_aux_moisture_sources!(ms, ps, aux) |
| 790 | + precompute_aux_moisture_sources!(ms, ps, aux) # defined in `Common/tendency.jl` |
740 | 791 |
|
741 | 792 | @. dY.ρq_liq += aux.thermo_variables.ρ * aux.cloud_sources.q_liq |
742 | 793 | @. dY.ρq_ice += aux.thermo_variables.ρ * aux.cloud_sources.q_ice |
|
806 | 857 | @inline function precip_sources_tendency!(ms::MoistureP3, ps::PrecipitationP3, dY, Y, aux, t) |
807 | 858 | return dY |
808 | 859 | end |
| 860 | +@inline function precip_sources_tendency!(ms::AbstractMoistureStyle, ps::Precipitation2M_P3, dY, Y, aux, t) |
| 861 | + precip_sources_tendency!(ms, ps.liq_precip, dY, Y, aux, t) |
| 862 | + # TODO [P3] |
| 863 | + # precompute_aux_precip_sources!(ps, Y, aux) |
| 864 | + |
| 865 | + #= |
| 866 | + function bulk_liquid_ice_collision_sources( |
| 867 | + params, logλ, L_ice, F_rim, ρ_rim, |
| 868 | + psd_c, psd_r, L_c, N_c, L_r, N_r, |
| 869 | + aps, tps, vel, ρₐ, T, |
| 870 | + ) |
| 871 | + =# |
| 872 | + (; ρ, ts) = aux.thermo_variables |
| 873 | + (; ρq_liq, ρq_rai, ρq_ice, N_liq, N_rai, N_ice) = Y |
| 874 | + (; air_params, thermo_params) = aux |
| 875 | + (; logλ, F_rim, ρ_rim) = aux.microph_variables |
| 876 | + (; pdf_c, pdf_r) = ps.liq_precip.rain_formation |
| 877 | + (; ice_precip) = ps |
| 878 | + |
| 879 | + coll_src = @. CMP3.bulk_liquid_ice_collision_sources( |
| 880 | + ice_precip.params, logλ, ρq_ice, N_ice, F_rim, ρ_rim, |
| 881 | + pdf_c, pdf_r, ρq_liq, N_liq, ρq_rai, N_rai, |
| 882 | + air_params, thermo_params, (ice_precip.sedimentation,), |
| 883 | + ρ, TD.air_temperature(thermo_params, ts), |
| 884 | + ) |
| 885 | + |
| 886 | + @. dY.ρq_liq += ρ * coll_src.∂ₜq_c |
| 887 | + @. dY.ρq_rai += ρ * coll_src.∂ₜq_r |
| 888 | + @. dY.N_liq += coll_src.∂ₜN_c |
| 889 | + @. dY.N_rai += coll_src.∂ₜN_r |
| 890 | + @. dY.ρq_rim += coll_src.∂ₜL_rim |
| 891 | + @. dY.ρq_ice += coll_src.∂ₜL_ice |
| 892 | + @. dY.B_rim += coll_src.∂ₜB_rim |
| 893 | + |
| 894 | + return dY |
| 895 | +end |
809 | 896 | @inline function precip_sources_tendency!(ms::CloudyMoisture, ps::CloudyPrecip, dY, Y, aux, t) |
810 | 897 |
|
811 | 898 | precompute_aux_precip_sources!(ps, aux) |
|
0 commit comments