@@ -29,7 +29,7 @@ function qₚ(q_rain_snow)
29
29
return max (FT (0 ), q_rain_snow)
30
30
end
31
31
32
- # Helper function to limit the tendency
32
+ # Helper function to compute the limit of the tendency
33
33
function limit (q, dt, n:: Int )
34
34
return q / float (dt) / n
35
35
end
@@ -85,11 +85,10 @@ function cloud_sources(
85
85
86
86
S = CMNe. conv_q_vap_to_q_liq_ice_MM2015 (cm_params, thp, q, ρ, Tₐ (thp, ts))
87
87
88
- # keeping the same limiter for now
89
88
return ifelse (
90
89
S > FT (0 ),
91
- min (S, limit (qᵥ (thp, ts), dt, 2 )),
92
- - min (abs (S), limit (qₗ (thp, ts, qₚ (qᵣ)), dt, 2 )),
90
+ triangle_inequality_limiter (S, limit (qᵥ (thp, ts), dt, 2 )),
91
+ - triangle_inequality_limiter (abs (S), limit (qₗ (thp, ts, qₚ (qᵣ)), dt, 2 )),
93
92
)
94
93
end
95
94
function cloud_sources (cm_params:: CMP.CloudIce{FT} , thp, ts, qₛ, dt) where {FT}
@@ -99,11 +98,10 @@ function cloud_sources(cm_params::CMP.CloudIce{FT}, thp, ts, qₛ, dt) where {FT
99
98
100
99
S = CMNe. conv_q_vap_to_q_liq_ice_MM2015 (cm_params, thp, q, ρ, Tₐ (thp, ts))
101
100
102
- # keeping the same limiter for now
103
101
return ifelse (
104
102
S > FT (0 ),
105
- min (S, limit (qᵥ (thp, ts), dt, 2 )),
106
- - min (abs (S), limit (qᵢ (thp, ts, qₚ (qₛ)), dt, 2 )),
103
+ triangle_inequality_limiter (S, limit (qᵥ (thp, ts), dt, 2 )),
104
+ - triangle_inequality_limiter (abs (S), limit (qᵢ (thp, ts, qₚ (qₛ)), dt, 2 )),
107
105
)
108
106
end
109
107
@@ -119,9 +117,9 @@ Returns the qₜ source term due to precipitation formation
119
117
defined as Δm_tot / (m_dry + m_tot) for the 0-moment scheme
120
118
"""
121
119
function q_tot_0M_precipitation_sources (thp, cmp:: CMP.Parameters0M , dt, qₜ, ts)
122
- return - min (
123
- max (qₜ, 0 ) / float (dt),
120
+ return - triangle_inequality_limiter (
124
121
- CM0. remove_precipitation (cmp, PP (thp, ts)),
122
+ max (qₜ, 0 ) / float (dt),
125
123
)
126
124
end
127
125
@@ -190,77 +188,77 @@ function compute_precipitation_sources!(
190
188
CM1. conv_q_liq_to_q_rai (mp. pr. acnv1M, qₗ (thp, ts, qₚ (qᵣ)), true ),
191
189
CM2. conv_q_liq_to_q_rai (mp. var, qₗ (thp, ts, qₚ (qᵣ)), ρ, mp. Ndp),
192
190
)
193
- @. Sᵖ = min ( limit (qₗ (thp, ts, qₚ (qᵣ)), dt, 5 ), Sᵖ )
191
+ @. Sᵖ = triangle_inequality_limiter (Sᵖ, limit (qₗ (thp, ts, qₚ (qᵣ)), dt, 5 ))
194
192
@. Sqₗᵖ -= Sᵖ
195
193
@. Sqᵣᵖ += Sᵖ
196
194
197
195
# snow autoconversion assuming no supersaturation: q_ice -> q_snow
198
- @. Sᵖ = min (
199
- limit (qᵢ (thp, ts, qₚ (qₛ)), dt, 5 ),
196
+ @. Sᵖ = triangle_inequality_limiter (
200
197
CM1. conv_q_ice_to_q_sno_no_supersat (mp. ps. acnv1M, qᵢ (thp, ts, qₚ (qₛ)), true ),
198
+ limit (qᵢ (thp, ts, qₚ (qₛ)), dt, 5 ),
201
199
)
202
200
@. Sqᵢᵖ -= Sᵖ
203
201
@. Sqₛᵖ += Sᵖ
204
202
205
203
# accretion: q_liq + q_rain -> q_rain
206
- @. Sᵖ = min (
207
- limit (qₗ (thp, ts, qₚ (qᵣ)), dt, 5 ),
204
+ @. Sᵖ = triangle_inequality_limiter (
208
205
CM1. accretion (mp. cl, mp. pr, mp. tv. rain, mp. ce, qₗ (thp, ts, qₚ (qᵣ)), qₚ (qᵣ), ρ),
206
+ limit (qₗ (thp, ts, qₚ (qᵣ)), dt, 5 ),
209
207
)
210
208
@. Sqₗᵖ -= Sᵖ
211
209
@. Sqᵣᵖ += Sᵖ
212
210
213
211
# accretion: q_ice + q_snow -> q_snow
214
- @. Sᵖ = min (
215
- limit (qᵢ (thp, ts, qₚ (qₛ)), dt, 5 ),
212
+ @. Sᵖ = triangle_inequality_limiter (
216
213
CM1. accretion (mp. ci, mp. ps, mp. tv. snow, mp. ce, qᵢ (thp, ts, qₚ (qₛ)), qₚ (qₛ), ρ),
214
+ limit (qᵢ (thp, ts, qₚ (qₛ)), dt, 5 ),
217
215
)
218
216
@. Sqᵢᵖ -= Sᵖ
219
217
@. Sqₛᵖ += Sᵖ
220
218
221
219
# accretion: q_liq + q_sno -> q_sno or q_rai
222
220
# sink of cloud water via accretion cloud water + snow
223
- @. Sᵖ = min (
224
- limit (qₗ (thp, ts, qₚ (qᵣ)), dt, 5 ),
221
+ @. Sᵖ = triangle_inequality_limiter (
225
222
CM1. accretion (mp. cl, mp. ps, mp. tv. snow, mp. ce, qₗ (thp, ts, qₚ (qᵣ)), qₚ (qₛ), ρ),
223
+ limit (qₗ (thp, ts, qₚ (qᵣ)), dt, 5 ),
226
224
)
227
225
# if T < T_freeze cloud droplets freeze to become snow
228
226
# else the snow melts and both cloud water and snow become rain
229
227
α (thp, ts) = TD. Parameters. cv_l (thp) / TD. latent_heat_fusion (thp, ts) * (Tₐ (thp, ts) - mp. ps. T_freeze)
230
228
@. Sᵖ_snow = ifelse (
231
229
Tₐ (thp, ts) < mp. ps. T_freeze,
232
230
Sᵖ,
233
- FT (- 1 ) * min (Sᵖ * α (thp, ts), limit (qₚ (qₛ), dt, 5 )),
231
+ FT (- 1 ) * triangle_inequality_limiter (Sᵖ * α (thp, ts), limit (qₚ (qₛ), dt, 5 )),
234
232
)
235
233
@. Sqₛᵖ += Sᵖ_snow
236
234
@. Sqₗᵖ -= Sᵖ
237
235
@. Sqᵣᵖ += ifelse (Tₐ (thp, ts) < mp. ps. T_freeze, FT (0 ), Sᵖ - Sᵖ_snow)
238
236
239
237
# accretion: q_ice + q_rai -> q_sno
240
- @. Sᵖ = min (
241
- limit (qᵢ (thp, ts, qₚ (qₛ)), dt, 5 ),
238
+ @. Sᵖ = triangle_inequality_limiter (
242
239
CM1. accretion (mp. ci, mp. pr, mp. tv. rain, mp. ce, qᵢ (thp, ts, qₚ (qₛ)), qₚ (qᵣ), ρ),
240
+ limit (qᵢ (thp, ts, qₚ (qₛ)), dt, 5 ),
243
241
)
244
242
@. Sqᵢᵖ -= Sᵖ
245
243
@. Sqₛᵖ += Sᵖ
246
244
# sink of rain via accretion cloud ice - rain
247
- @. Sᵖ = min (
248
- limit (qₚ (qᵣ), dt, 5 ),
245
+ @. Sᵖ = triangle_inequality_limiter (
249
246
CM1. accretion_rain_sink (mp. pr, mp. ci, mp. tv. rain, mp. ce, qᵢ (thp, ts, qₚ (qₛ)), qₚ (qᵣ), ρ),
247
+ limit (qₚ (qᵣ), dt, 5 ),
250
248
)
251
249
@. Sqᵣᵖ -= Sᵖ
252
250
@. Sqₛᵖ += Sᵖ
253
251
254
252
# accretion: q_rai + q_sno -> q_rai or q_sno
255
253
@. Sᵖ = ifelse (
256
254
Tₐ (thp, ts) < mp. ps. T_freeze,
257
- min (
258
- limit (qₚ (qᵣ), dt, 5 ),
255
+ triangle_inequality_limiter (
259
256
CM1. accretion_snow_rain (mp. ps, mp. pr, mp. tv. rain, mp. tv. snow, mp. ce, qₚ (qₛ), qₚ (qᵣ), ρ),
257
+ limit (qₚ (qᵣ), dt, 5 ),
260
258
),
261
- - min (
262
- limit (qₚ (qₛ), dt, 5 ),
259
+ - triangle_inequality_limiter (
263
260
CM1. accretion_snow_rain (mp. pr, mp. ps, mp. tv. snow, mp. tv. rain, mp. ce, qₚ (qᵣ), qₚ (qₛ), ρ),
261
+ limit (qₚ (qₛ), dt, 5 ),
264
262
),
265
263
)
266
264
@. Sqₛᵖ += Sᵖ
@@ -302,16 +300,16 @@ function compute_precipitation_sinks!(
302
300
303
301
# ! format: off
304
302
# evaporation: q_rai -> q_vap
305
- @. Sᵖ = - min (
306
- limit (qₚ (qᵣ), dt, 5 ),
303
+ @. Sᵖ = - triangle_inequality_limiter (
307
304
- CM1. evaporation_sublimation (rps... , PP (thp, ts), qₚ (qᵣ), ρ, Tₐ (thp, ts)),
305
+ limit (qₚ (qᵣ), dt, 5 ),
308
306
)
309
307
@. Sqᵣᵖ += Sᵖ
310
308
311
309
# melting: q_sno -> q_rai
312
- @. Sᵖ = min (
313
- limit (qₚ (qₛ), dt, 5 ),
310
+ @. Sᵖ = triangle_inequality_limiter (
314
311
CM1. snow_melt (sps... , qₚ (qₛ), ρ, Tₐ (thp, ts)),
312
+ limit (qₚ (qₛ), dt, 5 ),
315
313
)
316
314
@. Sqᵣᵖ += Sᵖ
317
315
@. Sqₛᵖ -= Sᵖ
@@ -320,8 +318,8 @@ function compute_precipitation_sinks!(
320
318
@. Sᵖ = CM1. evaporation_sublimation (sps... , PP (thp, ts), qₚ (qₛ), ρ, Tₐ (thp, ts))
321
319
@. Sᵖ = ifelse (
322
320
Sᵖ > FT (0 ),
323
- min ( limit (qᵥ (thp, ts), dt, 5 ), Sᵖ ),
324
- - min ( limit (qₚ (qₛ), dt, 5 ), FT ( - 1 ) * Sᵖ ),
321
+ triangle_inequality_limiter (Sᵖ, limit (qᵥ (thp, ts), dt, 5 )),
322
+ - triangle_inequality_limiter ( FT ( - 1 ) * Sᵖ, limit (qₚ (qₛ), dt, 5 )),
325
323
)
326
324
@. Sqₛᵖ += Sᵖ
327
325
# ! format: on
0 commit comments