|
160 | 160 | @. term_vel_rai = CM1.terminal_velocity(ps.rain, ps.sedimentation.rain, ρ, q_rai) |
161 | 161 | @. term_vel_sno = CM1.terminal_velocity(ps.snow, ps.sedimentation.snow, ρ, q_sno) |
162 | 162 | end |
163 | | -@inline function precompute_aux_precip!(ps::Precipitation2M, Y, aux) |
| 163 | +@inline function precompute_aux_precip!(ps::Precipitation2M, Y, aux) # called by `make_rhs_function` |
164 | 164 |
|
165 | 165 | FT = eltype(Y.ρq_rai) |
166 | 166 | sb2006 = ps.rain_formation |
|
177 | 177 | @. term_vel_N_rai = getindex(CM2.rain_terminal_velocity(sb2006, vel_scheme, q_rai, ρ, N_rai), 1) |
178 | 178 | @. term_vel_rai = getindex(CM2.rain_terminal_velocity(sb2006, vel_scheme, q_rai, ρ, N_rai), 2) |
179 | 179 | end |
| 180 | +@inline function precompute_aux_precip!(ps::IcePrecipitationP3, Y, aux) |
| 181 | + # State, `Y`, includes: ρq_ice, ρq_rim, N_ice, B_rim |
| 182 | + |
| 183 | + # update state variables |
| 184 | + (; sedimentation, params) = ps |
| 185 | + (; ρq_ice, ρq_rim, N_ice, B_rim) = Y |
| 186 | + (; ρ) = aux.thermo_variables |
| 187 | + (; F_rim, ρ_rim, logλ) = aux.microph_variables |
| 188 | + (; term_vel_N_ice, term_vel_q_ice) = aux.velocities |
| 189 | + |
| 190 | + # Calculate derived rime quantities |
| 191 | + # @. F_rim = ifelse(Y.ρq_ice < eps(FT), FT(0), Y.ρq_rim / Y.ρq_ice) |
| 192 | + # @. ρ_rim = ifelse(Y.B_rim < eps(FT), FT(0), Y.ρq_rim / Y.B_rim) |
| 193 | + |
| 194 | + @. F_rim = ifelse(isnan(ρq_rim / ρq_ice), zero(ρq_rim), ρq_rim / ρq_ice) |
| 195 | + @. ρ_rim = ifelse(isnan(ρq_rim / B_rim), zero(ρq_rim), ρq_rim / B_rim) |
| 196 | + # Calculate distribution parameters |
| 197 | + @. logλ = CMP3.get_distribution_logλ(CMP3.P3State(params, ρq_ice, N_ice, F_rim, ρ_rim)) |
| 198 | + |
| 199 | + # Calculate terminal velocities |
| 200 | + use_aspect_ratio = true |
| 201 | + @. term_vel_N_ice = CMP3.ice_terminal_velocity_number_weighted( |
| 202 | + sedimentation, ρ, CMP3.P3State(params, ρq_ice, N_ice, F_rim, ρ_rim), logλ; use_aspect_ratio |
| 203 | + ) |
| 204 | + @. term_vel_q_ice = CMP3.ice_terminal_velocity_mass_weighted( |
| 205 | + sedimentation, ρ, CMP3.P3State(params, ρq_ice, N_ice, F_rim, ρ_rim), logλ; use_aspect_ratio |
| 206 | + ) |
| 207 | + # args = (ps.sedimentation, ρ, ps.params, ρq_ice, N_ice, F_rim, ρ_rim, logλ) |
| 208 | + # @. term_vel_N_ice = CMP3.ice_terminal_velocity_number_weighted(args...; use_aspect_ratio) |
| 209 | + # @. term_vel_q_ice = CMP3.ice_terminal_velocity_mass_weighted(args...; use_aspect_ratio) |
| 210 | + |
| 211 | +end |
| 212 | +function precompute_aux_precip!(ps::Precipitation2M_P3, Y, aux) |
| 213 | + precompute_aux_precip!(ps.liq_precip, Y, aux) |
| 214 | + precompute_aux_precip!(ps.ice_precip, Y, aux) |
| 215 | +end |
180 | 216 | @inline function precompute_aux_precip!(ps::PrecipitationP3, Y, aux) |
181 | 217 |
|
182 | 218 | # update state variables |
|
580 | 616 | end |
581 | 617 | end |
582 | 618 |
|
| 619 | +@inline function precompute_aux_precip_sources!(ps::IcePrecipitationP3, Y, aux) |
| 620 | + |
| 621 | + # TODO: So far, implemented directly in precip_sources_tendency! |
| 622 | + |
| 623 | + return nothing |
| 624 | +end |
| 625 | + |
583 | 626 | @inline function precompute_aux_precip_sources!(ps::PrecipitationP3, aux) |
584 | 627 | # TODO [P3] |
585 | 628 | return nothing |
|
670 | 713 | @inline function cloud_sources_tendency!(::EquilibriumMoisture, dY, Y, aux, t) end |
671 | 714 | @inline function cloud_sources_tendency!(ms::NonEquilibriumMoisture, dY, Y, aux, t) |
672 | 715 |
|
673 | | - precompute_aux_moisture_sources!(ms, aux) |
| 716 | + precompute_aux_moisture_sources!(ms, aux) # defined in `Common/tendency.jl` |
674 | 717 |
|
675 | 718 | @. dY.ρq_liq += aux.thermo_variables.ρ * aux.cloud_sources.q_liq |
676 | 719 | @. dY.ρq_ice += aux.thermo_variables.ρ * aux.cloud_sources.q_ice |
|
740 | 783 | @inline function precip_sources_tendency!(ms::MoistureP3, ps::PrecipitationP3, dY, Y, aux, t) |
741 | 784 | return dY |
742 | 785 | end |
| 786 | +@inline function precip_sources_tendency!(ms::AbstractMoistureStyle, ps::Precipitation2M_P3, dY, Y, aux, t) |
| 787 | + precip_sources_tendency!(ms, ps.liq_precip, dY, Y, aux, t) |
| 788 | + # TODO [P3] |
| 789 | + # precompute_aux_precip_sources!(ps, Y, aux) |
| 790 | + |
| 791 | + #= |
| 792 | + function bulk_liquid_ice_collision_sources( |
| 793 | + params, logλ, L_ice, F_rim, ρ_rim, |
| 794 | + psd_c, psd_r, L_c, N_c, L_r, N_r, |
| 795 | + aps, tps, vel, ρₐ, T, |
| 796 | + ) |
| 797 | + =# |
| 798 | + (; ρ, ts) = aux.thermo_variables |
| 799 | + (; ρq_liq, ρq_rai, ρq_ice, N_liq, N_rai, N_ice) = Y |
| 800 | + (; air_params, thermo_params) = aux |
| 801 | + (; logλ, F_rim, ρ_rim) = aux.microph_variables |
| 802 | + (; pdf_c, pdf_r) = ps.liq_precip.rain_formation |
| 803 | + (; ice_precip) = ps |
| 804 | + |
| 805 | + coll_src = @. CMP3.bulk_liquid_ice_collision_sources( |
| 806 | + ice_precip.params, logλ, ρq_ice, N_ice, F_rim, ρ_rim, |
| 807 | + pdf_c, pdf_r, ρq_liq, N_liq, ρq_rai, N_rai, |
| 808 | + air_params, thermo_params, (ice_precip.sedimentation,), |
| 809 | + ρ, TD.air_temperature(thermo_params, ts), |
| 810 | + ) |
| 811 | + |
| 812 | + @. dY.ρq_liq += ρ * coll_src.∂ₜq_c |
| 813 | + @. dY.ρq_rai += ρ * coll_src.∂ₜq_r |
| 814 | + @. dY.N_liq += coll_src.∂ₜN_c |
| 815 | + @. dY.N_rai += coll_src.∂ₜN_r |
| 816 | + @. dY.ρq_rim += coll_src.∂ₜL_rim |
| 817 | + @. dY.ρq_ice += coll_src.∂ₜL_ice |
| 818 | + @. dY.B_rim += coll_src.∂ₜB_rim |
| 819 | + |
| 820 | + return dY |
| 821 | +end |
743 | 822 | @inline function precip_sources_tendency!(ms::CloudyMoisture, ps::CloudyPrecip, dY, Y, aux, t) |
744 | 823 |
|
745 | 824 | precompute_aux_precip_sources!(ps, aux) |
|
0 commit comments