@@ -188,7 +188,7 @@ def make_adapt_substeps(
188
188
n_substeps_min = math .ceil (timestep / dt_range [1 ])
189
189
190
190
@numba .njit (** jit_flags )
191
- def adapt_substeps (args , n_substeps , thd , rtol_thd ):
191
+ def adapt_substeps (step_impl_args , n_substeps , thd , rtol_thd ):
192
192
n_substeps = np .maximum (n_substeps_min , n_substeps // multiplier )
193
193
success = False
194
194
for burnout in range (fuse + 1 ):
@@ -202,15 +202,15 @@ def adapt_substeps(args, n_substeps, thd, rtol_thd):
202
202
),
203
203
return_value = (0 , False ),
204
204
)
205
- thd_new_long , success = step_fake (args , timestep , n_substeps )
205
+ thd_new_long , success = step_fake (step_impl_args , timestep , n_substeps )
206
206
if success :
207
207
break
208
208
n_substeps *= multiplier
209
209
for burnout in range (fuse + 1 ):
210
210
if burnout == fuse :
211
211
return warn ("burnout (short)" , __file__ , return_value = (0 , False ))
212
212
thd_new_short , success = step_fake (
213
- args , timestep , n_substeps * multiplier
213
+ step_impl_args , timestep , n_substeps * multiplier
214
214
)
215
215
if not success :
216
216
return warn ("short failed" , __file__ , return_value = (0 , False ))
@@ -230,18 +230,18 @@ def adapt_substeps(args, n_substeps, thd, rtol_thd):
230
230
@staticmethod
231
231
def make_step_fake (jit_flags , step_impl ):
232
232
@numba .njit (** jit_flags )
233
- def step_fake (args , dt , n_substeps ):
233
+ def step_fake (step_impl_args , dt , n_substeps ):
234
234
dt /= n_substeps
235
- _ , thd_new , _ , _ , _ , _ , success = step_impl (* args , dt , 1 , True )
235
+ _ , thd_new , _ , _ , _ , _ , success = step_impl (* step_impl_args , dt , 1 , True )
236
236
return thd_new , success
237
237
238
238
return step_fake
239
239
240
240
@staticmethod
241
241
def make_step (jit_flags , step_impl ):
242
242
@numba .njit (** jit_flags )
243
- def step (args , dt , n_substeps ):
244
- return step_impl (* args , dt , n_substeps , False )
243
+ def step (step_impl_args , dt , n_substeps ):
244
+ return step_impl (* step_impl_args , dt , n_substeps , False )
245
245
246
246
return step
247
247
@@ -293,6 +293,7 @@ def step_impl( # pylint: disable=too-many-arguments,too-many-locals
293
293
lv = formulae .latent_heat_vapourisation__lv (T )
294
294
pvs = formulae .saturation_vapour_pressure__pvs_water (T )
295
295
DTp = formulae .diffusion_thermics__D (T , p )
296
+ KTp = formulae .diffusion_thermics__K (T , p )
296
297
RH = pv / pvs
297
298
Sc = formulae .trivia__air_schmidt_number (
298
299
dynamic_viscosity = air_dynamic_viscosity ,
@@ -317,7 +318,7 @@ def step_impl( # pylint: disable=too-many-arguments,too-many-locals
317
318
lv ,
318
319
pvs ,
319
320
DTp ,
320
- formulae . diffusion_thermics__K ( T , p ) ,
321
+ KTp ,
321
322
rtol_x ,
322
323
)
323
324
dml_dt = (ml_new - ml_old ) / timestep
@@ -376,21 +377,12 @@ def make_calculate_ml_new( # pylint: disable=too-many-statements
376
377
):
377
378
@numba .njit (** jit_flags )
378
379
def minfun ( # pylint: disable=too-many-arguments,too-many-locals
379
- x_new ,
380
- x_old ,
381
- timestep ,
382
- kappa ,
383
- f_org ,
384
- rd3 ,
385
- temperature ,
386
- RH ,
387
- lv ,
388
- pvs ,
389
- D ,
390
- K ,
391
- mass_ventilation_factor ,
392
- heat_ventilation_factor ,
380
+ x_new , x_old , timestep , kappa , f_org , rd3 , temperature , RH , Fk , Fd
393
381
):
382
+ """
383
+ root finding problem for the implicit-in-x Euler step
384
+ neglecting dependence of `Fk` and `Fd` on particle size
385
+ """
394
386
if x_new > formulae .diffusion_coordinate__x_max ():
395
387
return x_old - x_new
396
388
mass_new = formulae .diffusion_coordinate__mass (x_new )
@@ -405,15 +397,7 @@ def minfun( # pylint: disable=too-many-arguments,too-many-locals
405
397
temperature , volume_new , formulae .constants .PI_4_3 * rd3 , f_org
406
398
),
407
399
)
408
- r_dr_dt = formulae .drop_growth__r_dr_dt (
409
- RH_eq ,
410
- temperature ,
411
- RH ,
412
- lv ,
413
- pvs ,
414
- D * mass_ventilation_factor ,
415
- K * heat_ventilation_factor ,
416
- )
400
+ r_dr_dt = formulae .drop_growth__r_dr_dt (RH_eq = RH_eq , RH = RH , Fk = Fk , Fd = Fd )
417
401
dm_dt = formulae .particle_shape_and_density__dm_dt (r = r_new , r_dr_dt = r_dr_dt )
418
402
return (
419
403
x_old
@@ -476,29 +460,25 @@ def calculate_ml_new( # pylint: disable=too-many-branches,too-many-arguments,to
476
460
)
477
461
)
478
462
heat_ventilation_factor = mass_ventilation_factor # TODO #1588
479
- args = (
463
+ Fk = formulae .drop_growth__Fk (
464
+ T = T , K = Kr * heat_ventilation_factor , lv = lv
465
+ )
466
+ Fd = formulae .drop_growth__Fd (
467
+ T = T , D = Dr * mass_ventilation_factor , pvs = pvs
468
+ )
469
+ minfun_args = (
480
470
x_old ,
481
471
timestep ,
482
472
attributes .kappa [drop ],
483
473
attributes .f_org [drop ],
484
474
rd3 ,
485
475
T ,
486
476
RH ,
487
- lv ,
488
- pvs ,
489
- Dr ,
490
- Kr ,
491
- mass_ventilation_factor ,
492
- heat_ventilation_factor ,
477
+ Fk ,
478
+ Fd ,
493
479
)
494
480
r_dr_dt_old = formulae .drop_growth__r_dr_dt (
495
- RH_eq ,
496
- T ,
497
- RH ,
498
- lv ,
499
- pvs ,
500
- mass_ventilation_factor * Dr ,
501
- heat_ventilation_factor * Kr ,
481
+ RH_eq = RH_eq , RH = RH , Fk = Fk , Fd = Fd
502
482
)
503
483
mass_old = formulae .diffusion_coordinate__mass (x_old )
504
484
dm_dt_old = formulae .particle_shape_and_density__dm_dt (
@@ -514,8 +494,8 @@ def calculate_ml_new( # pylint: disable=too-many-branches,too-many-arguments,to
514
494
else :
515
495
a = x_old
516
496
b = max (x_insane , a + dx_old )
517
- fa = minfun (a , * args )
518
- fb = minfun (b , * args )
497
+ fa = minfun (a , * minfun_args )
498
+ fb = minfun (b , * minfun_args )
519
499
520
500
counter = 0
521
501
while not fa * fb < 0 :
@@ -545,7 +525,7 @@ def calculate_ml_new( # pylint: disable=too-many-branches,too-many-arguments,to
545
525
success = False
546
526
break
547
527
b = max (x_insane , a + math .ldexp (dx_old , counter ))
548
- fb = minfun (b , * args )
528
+ fb = minfun (b , * minfun_args )
549
529
550
530
if not success :
551
531
break
@@ -556,7 +536,7 @@ def calculate_ml_new( # pylint: disable=too-many-branches,too-many-arguments,to
556
536
557
537
x_new , iters_taken = toms748_solve (
558
538
minfun ,
559
- args ,
539
+ minfun_args ,
560
540
a ,
561
541
b ,
562
542
fa ,
@@ -673,7 +653,7 @@ def solve( # pylint: disable=too-many-arguments,too-many-locals
673
653
timestep ,
674
654
n_substeps ,
675
655
):
676
- args = (
656
+ step_impl_args = (
677
657
attributes ,
678
658
cell_idx ,
679
659
thd ,
@@ -689,7 +669,9 @@ def solve( # pylint: disable=too-many-arguments,too-many-locals
689
669
)
690
670
success = True
691
671
if adaptive :
692
- n_substeps , success = adapt_substeps (args , n_substeps , thd , rtols .thd )
672
+ n_substeps , success = adapt_substeps (
673
+ step_impl_args , n_substeps , thd , rtols .thd
674
+ )
693
675
if success :
694
676
(
695
677
water_vapour_mixing_ratio ,
@@ -699,7 +681,7 @@ def solve( # pylint: disable=too-many-arguments,too-many-locals
699
681
n_ripening ,
700
682
RH_max ,
701
683
success ,
702
- ) = step (args , timestep , n_substeps )
684
+ ) = step (step_impl_args , timestep , n_substeps )
703
685
else :
704
686
n_activating , n_deactivating , n_ripening , RH_max = - 1 , - 1 , - 1 , - 1
705
687
return (
0 commit comments