-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbin_microphysics_module.f90
5160 lines (4353 loc) · 212 KB
/
bin_microphysics_module.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!>@author
!>Paul Connolly, The University of Manchester
!>@brief
!>code to allocate arrays, and call activation
module bmm
use numerics_type
use numerics, only : find_pos, poly_int
!>@author
!>Paul J. Connolly, The University of Manchester
!>@brief
!>variables and types for the bin microphysics model
implicit none
! constants for the bin microphysics model
real(wp), parameter :: r_gas=8.314_wp, molw_a=29.e-3_wp,molw_water=18.e-3_wp, &
cp=1005.0_wp, cpv=1870._wp, cpw=4.27e3_wp, cpi=2104.6_wp, &
grav=9.81_wp, &
lv=2.5e6_wp, ls=2.837e6_wp, lf=ls-lv, ttr=273.15_wp, &
joules_in_an_erg=1.0e-7_wp,joules_in_a_cal=4.187e0_wp, &
rhow=1000._wp, ra=r_gas/molw_a,rv=r_gas/molw_water , &
eps1=ra/rv, rhoice=910._wp, &
mass_fragment1=pi/6._wp*rhoice*10.e-6_wp**3._wp, &
mass_fragment2=mass_fragment1, &
mass_fragment3=mass_fragment1, &
gam_fac_ent=1._wp/(1._wp+0.5_wp), & ! P+K, 12-25
gam_fac_ent2=1._wp+0.5_wp, &
onethird=1._wp/3._wp, &
twothirds=2._wp/3._wp, fourthirds=4._wp/3._wp
logical :: l_inhom
type parcel
! variables for bin model
integer(i4b) :: n_bins1,n_modes,n_comps, n_bin_mode, n_bin_modew, n_bin_mode1, &
n_sound, n_chamber, ice_flag, sce_flag
real(wp) :: dt
real(wp), dimension(:), allocatable :: time_chamber, press_chamber, &
temp_chamber, dp_chamber, dt_chamber
real(wp), dimension(:,:), allocatable :: q_sound
real(wp), dimension(:), allocatable :: t_sound, z_sound, rh_sound, &
p_sound, theta_q_sound
real(wp) :: z,p,t,w,rh, rad,qinit, t_cbase, q_cbase, p_cbase, z_cbase, &
t_ctop, q_ctop, p_ctop, z_ctop, theta_q_cbase, theta_q_ctop, &
x_ent, theta_q, zlast
! liquid water
real(wp), dimension(:), allocatable :: d, maer, npart, rho_core, &
rh_eq, rhoat, dw, da_dt, ndrop, npartall, npart_ent, &
npart_temp, npart_temp2
real(wp), dimension(:,:), allocatable :: mbin, mbinall, rhobin, &
nubin,molwbin,kappabin, &
mbin_ent, &
mbin_temp, mbin_temp2 ! all bins x all comps
! variables for ODE:
integer(i4b) :: neq, itol, ipr, ite, iz, iw, irh, ira, &
itask, istate, iopt, mf, lrw, liw
integer(i4b), dimension(:), allocatable :: iwork
integer(i4b), dimension(1) :: ipar
real(wp) :: tt, tout
real(wp), dimension(:), allocatable :: y, yold, atol, rwork
real(wp), dimension(1) :: rpar
real(wp), dimension(1) :: rtol
! ice water
real(wp), dimension(:), allocatable :: dice, maerice, npartice, rho_coreice, &
rh_eqice, rhoatice, dwice, da_dtice, nice, &
phi, rhoi, nump, rime
real(wp), dimension(:,:), allocatable :: mbinice, rhobinice, &
nubinice,molwbinice,kappabinice ! all bins x all comps
! general
integer(i4b) :: imoms
real(wp), allocatable, dimension(:,:) :: moments, mbinedges,ecoll,ecoal, &
moments_ent, mbinedges_ent, &
moments_temp, mbinedges_temp, &
mbinedges_temp2
real(wp), allocatable, dimension(:) :: momtemp, vel, cd, nre
integer(i4b), allocatable, dimension(:) :: momenttype
integer(i4b), dimension(:,:), allocatable :: indexc
! variables for ODE:
integer(i4b) :: neqice, itolice, ipri, itei, izi, iwi, irhi, &
itaskice, istateice, ioptice, mfice, lrwice, liwice
integer(i4b), dimension(:), allocatable :: iworkice
integer(i4b), dimension(1) :: iparice
real(wp) :: ttice, toutice, totaddto
real(wp), dimension(1) :: rtolice
real(wp), dimension(:), allocatable :: yice, yoldice, atolice, rworkice
real(wp), dimension(1) :: rparice
logical :: break_flag=.false.
end type parcel
type sounding
! variables for grid
integer(i4b) :: n_levels
real(wp), dimension(:,:), allocatable :: q
real(wp), dimension(:), allocatable :: theta, p, z, rh
end type sounding
type io
! variables for io
integer(i4b) :: ncid, varid, x_dimid, bin_dimid, bin2_dimid, bin3_dimid, &
mode_dimid, comp_dimid, y_dimid, z_dimid, &
dimids(2), a_dimid, xx_dimid, yy_dimid, &
zz_dimid, i_dimid, j_dimid, k_dimid, nq_dimid, nprec_dimid
integer(i4b) :: icur=1
logical :: new_file=.true.
end type io
! declare a parcel type
type(parcel) :: parcel1
! declare a sounding type
type(sounding) :: sounding1
! declare an io type
type(io) :: io1
! some namelist variables
logical :: micro_init=.true., adiabatic_prof=.false., vert_ent=.false.
real(wp) :: ent_rate, dmina,dmaxa
real(wp) :: zinit,tpert,winit,winit2, amplitude2, tau2, &
tinit,pinit,rhinit,radinit,z_ctop, alpha_therm, alpha_cond, &
alpha_therm_ice, alpha_dep, thresh_to_start_hom_mix
integer(i4b) :: microphysics_flag=0, kappa_flag,updraft_type, vent_flag, &
sce_flag=0,ice_flag=0, bin_scheme_flag=1, entrain_period=0
logical :: use_prof_for_tprh, hm_flag, mode1_flag, mode2_flag, &
chamber_override=.false., bubble_flag, &
release_aerosol, entrain_aerosol
integer(i4b) :: break_flag, ice_nucleation_flag=0
real(wp) :: dz,dt, runtime, t_thresh
! sounding spec
real(wp) :: psurf, tsurf
integer(i4b), parameter :: nlevels_r=1000
integer(i4b), parameter :: nq=3
integer(i4b) :: n_levels_s, n_levels_c, idum, n_sel
real(wp) :: mult, rh_act
real(wp), allocatable, dimension(:,:) :: q_read !nq x nlevels_r
real(wp), allocatable, dimension(:) :: theta_read,rh_read, z_read
real(wp), allocatable, dimension(:) :: time_chamber, press_chamber, temp_chamber
! aerosol setup
integer(i4b) :: n_intern, n_mode,n_sv,sv_flag,n_bins,n_comps
! aerosol_spec
real(wp), allocatable, dimension(:,:) :: n_aer1,d_aer1,sig_aer1, mass_frac_aer1
real(wp), allocatable, dimension(:) :: molw_core1,density_core1,nu_core1, &
kappa_core1
real(wp), allocatable, dimension(:) :: org_content1, molw_org1, kappa_org1, &
density_org1, delta_h_vap1,nu_org1,log_c_star1
! variables for model
real(wp) :: theta_surf,theta_init, &
theta_q_sat,t1old, p111, w_cb, n_dummy, d_dummy, x2old=1.0_wp, &
wvenv_send, tenv_send, ratio_send, mu_send=0.0_wp, radius_send, w_send, &
dilute_send, wv_send
logical :: set_theta_q_cb_flag=.true.
integer(i4b) :: entrain_count=0
! Chen and Lamb (1994) Gamma variable fit (scaled and centred logarithm)
integer(i4b), parameter :: n_cl=18
real(wp), dimension(n_cl), parameter :: gam_cl=[-0.072328469664620_wp, &
-0.324623262465577_wp, 0.363138099937540_wp, 3.323089908344732_wp, &
0.874844989423720_wp, &
-13.554426432462339_wp, -9.810322482346461_wp, 27.846739088352344_wp, &
26.480447842355410_wp,&
-29.890199206698309_wp, -32.327548996894521_wp, 15.827423311652167_wp, &
18.466605783503052_wp, -4.158566361058538_wp, -5.039533848938808_wp, &
1.477272813054374_wp, 1.038600921563425_wp, -0.457007828432810_wp]
real(wp), dimension(2), parameter :: gam_mu_cl=[260.163817050062335_wp, &
8.274747821396463_wp]
character (len=200) :: outputfile='output', scefile='input'
!private
!public :: read_in_bmm_namelist, initialise_bmm_arrays, bmm_driver, io1
public
private :: outputfile
contains
!>@author
!>Paul J. Connolly, The University of Manchester
!>@brief
!>allocate arrays for activation code
!>@param[in] n_intern: number of aerosol modes of same kind
!>@param[in] n_mode: number of aerosol modes
!>@param[in] n_sv: number of organic / volatility modes
!>@param[in] n_bins: number of size bins in a mode
!>@param[in] n_comps: number of different compositions in a mode
!>@param[in] nq: number of q-variables in sounding
!>@param[in] n_levels_s: number of levels in sounding
!>@param[in] n_levels_c: number of levels in chamber data
!>@param[inout] q_read, theta_read, rh_read, z_read: sounding
!>@param[inout] time_chamber, press_chamber, temp_chamber: chamber
!>@param[inout] n_aer1: number conc. in modes
!>@param[inout] d_aer1: diameter in modes
!>@param[inout] sig_aer1: geo std in modes
!>@param[inout] mass_frac_aer1:mass_fraction of each component
!>@param[inout] molw_core1:molw in core
!>@param[inout] density_core1: solute density
!>@param[inout] nu_core1: van hoff factor
!>@param[inout] kappa_core1: kappa parameter
!>@param[inout] org_content1: organic content in vol bins
!>@param[inout] molw_org1: molw in volatility bins
!>@param[inout] kappa_org1: kappa in volatility bins
!>@param[inout] density_org1: density in volatility bins
!>@param[inout] delta_h_vap1: enthalpy in volatility bins
!>@param[inout] nu_org1: van hoff factor in volatility bins
!>@param[inout] log_c_star1: log_c_star in volatility bins
subroutine allocate_arrays(n_intern,n_mode,n_sv,n_bins,n_comps,nq,n_levels_s, &
q_read,theta_read,rh_read,z_read, &
n_levels_c, time_chamber, press_chamber, temp_chamber, &
n_aer1,d_aer1,sig_aer1,mass_frac_aer1, molw_core1, &
density_core1, nu_core1, kappa_core1, &
org_content1,molw_org1,kappa_org1,density_org1, &
delta_h_vap1,nu_org1,log_c_star1)
use numerics_type
implicit none
integer(i4b), intent(in) :: n_intern, n_mode, n_sv, n_bins,n_comps, nq, &
n_levels_s, n_levels_c
real(wp), dimension(:), allocatable, intent(inout) :: theta_read,rh_read,z_read, &
org_content1,molw_org1,kappa_org1, &
density_org1,delta_h_vap1,nu_org1,log_c_star1, &
time_chamber, press_chamber, temp_chamber
real(wp), dimension(:,:), allocatable, intent(inout) :: q_read, &
n_aer1,d_aer1,sig_aer1,mass_frac_aer1
real(wp), dimension(:), allocatable, intent(inout) :: molw_core1,density_core1, &
nu_core1,kappa_core1
integer(i4b) :: AllocateStatus
allocate( q_read(1:nq,1:n_levels_s), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( theta_read(1:n_levels_s), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( rh_read(1:n_levels_s), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( z_read(1:n_levels_s), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( time_chamber(1:n_levels_c), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( press_chamber(1:n_levels_c), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( temp_chamber(1:n_levels_c), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( n_aer1(1:n_intern,1:n_mode), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( d_aer1(1:n_intern,1:n_mode), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( sig_aer1(1:n_intern,1:n_mode), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( mass_frac_aer1(1:n_mode,1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( molw_core1(1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( density_core1(1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( nu_core1(1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( kappa_core1(1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( org_content1(1:n_sv), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( molw_org1(1:n_sv), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( kappa_org1(1:n_sv), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( density_org1(1:n_sv), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( delta_h_vap1(1:n_sv), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( nu_org1(1:n_sv), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( log_c_star1(1:n_sv), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
end subroutine allocate_arrays
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! read in the namelist !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!>@author
!>Paul J. Connolly, The University of Manchester
!>@brief
!>read in the data from the namelists for the bin microphysics model
!>@param[in] nmlfile
subroutine read_in_bmm_namelist(nmlfile)
implicit none
character (len=200), intent(in) :: nmlfile
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! namelists !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
namelist /sounding_spec/ psurf, tsurf, &
q_read, theta_read, rh_read, z_read
namelist /chamber_spec/ time_chamber, press_chamber, temp_chamber
! define namelists for environment
namelist /run_vars/ outputfile, scefile,runtime, dt, &
zinit,tpert,use_prof_for_tprh,winit,winit2,amplitude2, &
tinit,pinit,rhinit, radinit, bubble_flag, &
microphysics_flag, ice_flag, bin_scheme_flag, sce_flag, &
ice_nucleation_flag, &
hm_flag, break_flag, mode1_flag, mode2_flag, chamber_override, &
vent_flag, &
kappa_flag, updraft_type,t_thresh, adiabatic_prof, &
entrain_period, thresh_to_start_hom_mix, release_aerosol, &
entrain_aerosol, vert_ent, &
z_ctop, ent_rate,n_levels_s, n_levels_c, &
alpha_therm,alpha_cond,alpha_therm_ice,alpha_dep
namelist /aerosol_setup/ n_intern,n_mode,n_sv,sv_flag, n_bins,n_comps
namelist /aerosol_spec/ n_aer1,d_aer1,sig_aer1, dmina,dmaxa, &
mass_frac_aer1, molw_core1, &
density_core1,nu_core1,kappa_core1, &
org_content1, molw_org1,kappa_org1, &
density_org1, delta_h_vap1,nu_org1, log_c_star1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! read in namelists and allocate arrays !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
open(8,file=nmlfile,status='old', recl=80, delim='apostrophe')
read(8,nml=run_vars)
read(8,nml=aerosol_setup)
! allocate memory / init
call allocate_arrays(n_intern,n_mode,n_sv,n_bins,n_comps,nq,n_levels_s, &
q_read,theta_read,rh_read,z_read, &
n_levels_c, time_chamber, press_chamber, temp_chamber, &
n_aer1,d_aer1,sig_aer1,mass_frac_aer1, molw_core1, &
density_core1, nu_core1, kappa_core1, &
org_content1,molw_org1,kappa_org1,density_org1, &
delta_h_vap1,nu_org1,log_c_star1)
read(8,nml=sounding_spec)
read(8,nml=aerosol_spec)
if(chamber_override) then
read(8,nml=chamber_spec)
if(chamber_override) use_prof_for_tprh=.false.
endif
close(8)
tau2 = 2._wp*pi/winit2*amplitude2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end subroutine read_in_bmm_namelist
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! initialise arrays !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!>@author
!>Paul J. Connolly, The University of Manchester
!>@brief
!>interpolates the sounding to the grid
subroutine initialise_bmm_arrays(psurf, tsurf, q_read, theta_read, rh_read, z_read, &
time_chamber, press_chamber, temp_chamber, &
runtime, dt, zinit, tpert, use_prof_for_tprh, chamber_override, &
winit, tinit, pinit, &
rhinit, radinit, bubble_flag, &
microphysics_flag, ice_flag, bin_scheme_flag, vent_flag, &
kappa_flag, updraft_type, adiabatic_prof, vert_ent, z_ctop, &
ent_rate, n_levels_s, n_levels_c, &
alpha_therm, alpha_cond, alpha_therm_ice, &
alpha_dep, n_intern, n_mode, n_sv, sv_flag, n_bins, n_comps, &
n_aer1,d_aer1,sig_aer1,dmina,dmaxa,mass_frac_aer1,molw_core1, &
density_core1, nu_core1, kappa_core1, org_content1, molw_org1, &
kappa_org1, density_org1, delta_h_vap1,nu_org1, log_c_star1, &
sce_flag)
use numerics_type
use numerics, only : find_pos, poly_int, zeroin, fmin,vode_integrate
implicit none
logical, intent(in) :: use_prof_for_tprh, adiabatic_prof, vert_ent, bubble_flag, &
chamber_override
integer(i4b), intent(in) :: microphysics_flag, ice_flag, bin_scheme_flag, vent_flag, &
kappa_flag, updraft_type, n_levels_s,n_levels_c, &
n_intern, n_mode, n_sv, &
sv_flag, n_bins, n_comps, sce_flag
real(wp), intent(in) :: psurf, radinit, &
tsurf, runtime, dt, zinit, tpert, winit, tinit, &
pinit, rhinit, alpha_therm, alpha_cond, alpha_therm_ice, &
alpha_dep, dmina,dmaxa, z_ctop, ent_rate
real(wp), dimension(1:n_levels_c), intent(in) :: time_chamber, press_chamber, &
temp_chamber
real(wp), dimension(1:n_levels_s), intent(in) :: theta_read, rh_read, z_read
real(wp), dimension(1:nq,1:n_levels_s), intent(in) :: q_read
real(wp), dimension(1:n_intern,1:n_mode), intent(in) :: n_aer1,d_aer1,sig_aer1
real(wp), dimension(1:n_mode,1:n_comps), intent(in) :: mass_frac_aer1
real(wp), dimension(1:n_comps), intent(in) :: molw_core1, density_core1, &
nu_core1, kappa_core1
real(wp), dimension(1:n_sv), intent(in) :: org_content1, molw_org1, kappa_org1, &
density_org1, delta_h_vap1, nu_org1, log_c_star1
real(wp) :: num, ntot, number_per_bin, test, var1, &
eps2, z1, z2, htry, hmin, var, dummy
real(wp), dimension(1) :: p1, z11
real(wp) :: p11, p22, rm, cpm
integer(i4b) :: i,j,k, AllocateStatus, iloc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! set variables and allocate arrays in parcel !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
parcel1%n_sound=n_levels_s
parcel1%n_chamber=n_levels_c
parcel1%n_bins1=n_bins
parcel1%n_modes=n_mode
parcel1%n_comps=n_comps
parcel1%n_bin_modew=n_bins*n_mode
parcel1%n_bin_mode1=(n_bins+1)*n_mode
parcel1%z=zinit
parcel1%p=pinit
parcel1%t=tinit
parcel1%w=winit
parcel1%rh=rhinit
parcel1%rad=radinit
parcel1%dt=dt
parcel1%ice_flag=ice_flag
parcel1%n_bin_mode=&
parcel1%n_bins1*n_mode*(1+parcel1%ice_flag) ! for all the liquid and ice
parcel1%imoms=ice_flag*5 ! phi, nmon, vol, rim, unf
allocate( parcel1%d(1:parcel1%n_bin_mode1), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
! same bin edges used for ice
allocate( parcel1%mbinedges(1:parcel1%n_bins1+1,1:parcel1%n_modes), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%maer(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%npart(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%npartall(1:parcel1%n_bin_mode), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%mbin(1:parcel1%n_bin_modew,1:n_comps+1), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%mbinall(1:parcel1%n_bin_mode,1:n_comps+1), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%rho_core(1:parcel1%n_modes), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%momtemp(1:parcel1%n_bin_mode), &
STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%moments(1:parcel1%n_bin_mode,1:n_comps+parcel1%imoms), &
STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%momenttype(1:n_comps+parcel1%imoms), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%rhobin(1:parcel1%n_bin_modew,1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%nubin(1:parcel1%n_bin_modew,1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%molwbin(1:parcel1%n_bin_modew,1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%kappabin(1:parcel1%n_bin_modew,1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%rh_eq(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%rhoat(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%dw(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%da_dt(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%ndrop(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%ecoal(1:parcel1%n_bin_mode,1:parcel1%n_bin_mode), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%ecoll(1:parcel1%n_bin_mode,1:parcel1%n_bin_mode), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%indexc(1:parcel1%n_bin_mode,1:parcel1%n_bin_mode), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%vel(1:parcel1%n_bin_mode), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%cd(1:parcel1%n_bin_mode), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%nre(1:parcel1%n_bin_mode), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%q_sound(1:parcel1%n_sound,1:nq), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%z_sound(1:parcel1%n_sound), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%t_sound(1:parcel1%n_sound), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%p_sound(1:parcel1%n_sound), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%rh_sound(1:parcel1%n_sound), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%theta_q_sound(1:parcel1%n_sound), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%time_chamber(1:parcel1%n_chamber), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%press_chamber(1:parcel1%n_chamber), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%temp_chamber(1:parcel1%n_chamber), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%dp_chamber(1:parcel1%n_chamber-1), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%dt_chamber(1:parcel1%n_chamber-1), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! calculate the density of aerosol particles within a mode !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
do i=1,n_mode
var1=sum(mass_frac_aer1(i,:)/ density_core1)
parcel1%rho_core(i) = 1._wp/var1
enddo
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! set-up size distribution !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
do k=1,n_mode
idum=k ! this is sent through to zbrent to select the correct mode
! find total number in mode between dmina and dmaxa:
! for this make sure it isnt zero
call lognormal_n_between_limits(max(n_aer1(:,k),1.e-6_wp),d_aer1(:,k),sig_aer1(:,k), &
n_intern,dmina,dmaxa, num)
!print *,num
! set up variables for parcel model
ntot=num
number_per_bin=ntot/real(n_bins,wp)
! make sure it is zero if needed
parcel1%npart(1+(k-1)*n_bins:(k)*n_bins)=min(number_per_bin, &
sum(n_aer1(:,k))/real(n_bins,wp))
parcel1%d(1+(k-1)*(n_bins+1))=dmina
do i=1,n_bins
d_dummy=parcel1%d(i+(k-1)*(n_bins+1))
n_dummy=number_per_bin*(1._wp-1.e-5_wp)
parcel1%d(i+1+(k-1)*(n_bins+1))= zeroin(&
d_dummy*0.9_wp,dmaxa*2._wp,find_upper_diameter, 1.e-30_wp)
enddo
parcel1%d((k)*(n_bins+1))=dmaxa ! nail it to end point - round off
enddo
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! aerosol mass - total !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
do k=1,parcel1%n_modes
do j=1,parcel1%n_bins1
i=j+(k-1)*(n_bins+1)
parcel1%maer(j+(k-1)*(n_bins))= &
pi/6._wp*(0.5_wp*(parcel1%d(i+1)+parcel1%d(i)))**3 * &
parcel1%rho_core(k)
enddo
enddo
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! calculate the mass of each component in a bin, including water (Koehler eq)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
do i=1,parcel1%n_bins1
do j=1,parcel1%n_modes
do k=1,parcel1%n_comps
parcel1%mbin(i+(j-1)*n_bins,k)= &
parcel1%maer(i+(j-1)*n_bins)*mass_frac_aer1(j,k)
! density in each bin:
parcel1%rhobin(i+(j-1)*n_bins,k)=density_core1(k)
! nu in each bin:
parcel1%nubin(i+(j-1)*n_bins,k)=nu_core1(k)
! molw in each bin:
parcel1%molwbin(i+(j-1)*n_bins,k)=molw_core1(k)
! kappa in each bin:
parcel1%kappabin(i+(j-1)*n_bins,k)=kappa_core1(k)
enddo
enddo
enddo
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! get initial conditions (based on sounding)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! integrate dp/dz=-p/ra/t
! dp/dz=-p/(ra*theta*(p/100000.)**0.287)
parcel1%q_sound=q_read
parcel1%z_sound=z_read
parcel1%t_sound(1)=theta_read(1)*(psurf/1.e5_wp)**(ra/cp)
parcel1%p_sound(1)=psurf
eps2=1.e-5_wp
htry=10._wp
hmin=1.e-2_wp
p1=psurf
! integrate hydrostatic equation
do i=2,n_levels_s
call vode_integrate(p1,z_read(i-1),z_read(i),eps2,htry,hmin,hydrostatic1b)
parcel1%t_sound(i)=theta_read(i)*(p1(1)/1.e5_wp)**(ra/cp)
parcel1%p_sound(i)=p1(1)
enddo
! calculate RH
do i=1,n_levels_s
parcel1%rh_sound(i)=parcel1%q_sound(1,i)/ &
(eps1*svp_liq(parcel1%t_sound(i)) / &
(parcel1%p_sound(i)- svp_liq(parcel1%t_sound(i))) )
enddo
! calculate theta_q
do i=1,n_levels_s
parcel1%theta_q_sound(i)= &
calc_theta_q3(parcel1%t_sound(i),parcel1%p_sound(i),parcel1%q_sound(1,i))
enddo
! interpolate to find parcel conditions
if (use_prof_for_tprh) then
! interpolate to find theta
iloc=find_pos(parcel1%z_sound(1:n_levels_s),parcel1%z)
iloc=min(n_levels_s-1,iloc)
iloc=max(1,iloc)
! linear interp t
call poly_int(parcel1%z_sound(iloc:iloc+1), parcel1%t_sound(iloc:iloc+1), &
min(parcel1%z,parcel1%z_sound(n_levels_s)), var,dummy)
parcel1%t=var +tpert
! linear interp rh
call poly_int(parcel1%z_sound(iloc:iloc+1), parcel1%p_sound(iloc:iloc+1), &
min(parcel1%z,parcel1%z_sound(n_levels_s)), var,dummy)
parcel1%p=var
! linear interp rh
call poly_int(parcel1%z_sound(iloc:iloc+1), parcel1%rh_sound(iloc:iloc+1), &
min(parcel1%z,parcel1%z_sound(n_levels_s)), var,dummy)
parcel1%rh=var
parcel1%rh=rhinit
!parcel1%t=parcel1%t+tpert
print *,'t,p,rh from sounding: ', parcel1%t, parcel1%p, parcel1%rh
endif
! initialise with chamber conditions
if (chamber_override) then
parcel1%time_chamber=time_chamber
parcel1%press_chamber=press_chamber
parcel1%temp_chamber=temp_chamber
! interpolate to find theta
iloc=find_pos(parcel1%time_chamber(1:n_levels_c),parcel1%TT)
iloc=min(n_levels_c-1,iloc)
iloc=max(1,iloc)
! linear interp t
call poly_int(parcel1%time_chamber(iloc:iloc+1), &
parcel1%temp_chamber(iloc:iloc+1), &
min(parcel1%TT,parcel1%time_chamber(n_levels_c)), var,dummy)
parcel1%t=var +tpert
! linear interp pressure
call poly_int(parcel1%time_chamber(iloc:iloc+1), &
parcel1%press_chamber(iloc:iloc+1), &
min(parcel1%TT,parcel1%time_chamber(n_levels_c)), var,dummy)
parcel1%p=var
parcel1%rh=rhinit
! calculate derivatives
do i=1,n_levels_c-1
parcel1%dp_chamber(i) = &
(parcel1%press_chamber(i+1)-parcel1%press_chamber(i))/ &
(parcel1%time_chamber(i+1)-parcel1%time_chamber(i))
parcel1%dt_chamber(i) = &
(parcel1%temp_chamber(i+1)-parcel1%temp_chamber(i))/ &
(parcel1%time_chamber(i+1)-parcel1%time_chamber(i))
enddo
print *,'t,p,rh from chamber: ', parcel1%t, parcel1%p, parcel1%rh
endif
parcel1%zlast=parcel1%z
parcel1%qinit=parcel1%rh*eps1*svp_liq(parcel1%t)/(parcel1%p-svp_liq(parcel1%t))
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! get cloud-base conditions (for entrainment process) !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (vert_ent) then
! find cloud-base pressure:
! cloud base qv
parcel1%q_cbase=parcel1%qinit
! calculate the dry adiabat:
theta_init=parcel1%t*(1.e5_wp/parcel1%p)**(ra/cp)
! calculate p required so that qs(t,p) = q init
parcel1%p_cbase=zeroin(parcel1%p, 100._wp,cloud_base, 1.e-30_wp)
rm=ra+parcel1%qinit*rv
cpm=cp+parcel1%qinit*cpv
parcel1%t_cbase=theta_init*(parcel1%p_cbase/1.e5_wp)**(rm/cpm)
parcel1%theta_q_cbase= &
calc_theta_q3(parcel1%t_cbase,parcel1%p_cbase,parcel1%q_cbase)
print *,'Cloud-base t, p: ',parcel1%t_cbase,parcel1%p_cbase
! now, find the height of cloud-base along dry adiabat:
theta_surf=tsurf*(1.e5_wp/psurf)**(ra/cp)
p11=parcel1%p
z11(1)=parcel1%z
p22=parcel1%p_cbase
htry=p22-p11
eps2=1.e-5_wp
call vode_integrate(z11,p11,p22,eps2,htry,hmin,hydrostatic1)
parcel1%z_cbase=z11(1)
! cloud-top properties from sounding:
parcel1%z_ctop=z_ctop
! interpolate to find t
iloc=find_pos(parcel1%z_sound(1:n_levels_s),parcel1%z_ctop)
iloc=min(n_levels_s-1,iloc)
iloc=max(1,iloc)
! linear interp t
call poly_int(parcel1%z_sound(iloc:iloc+1), parcel1%t_sound(iloc:iloc+1), &
min(parcel1%z_ctop,parcel1%z_sound(n_levels_s)), var,dummy)
parcel1%t_ctop=var
! linear interp p
call poly_int(parcel1%z_sound(iloc:iloc+1), parcel1%p_sound(iloc:iloc+1), &
min(parcel1%z_ctop,parcel1%z_sound(n_levels_s)), var,dummy)
parcel1%p_ctop=var
! linear interp q
call poly_int(parcel1%z_sound(iloc:iloc+1), parcel1%rh_sound(iloc:iloc+1), &
min(parcel1%z_ctop,parcel1%z_sound(n_levels_s)), var,dummy)
parcel1%q_ctop=var*eps1*svp_liq(parcel1%t_ctop) / &
(parcel1%p_ctop-svp_liq(parcel1%t_ctop))
parcel1%theta_q_ctop= &
calc_theta_q3(parcel1%t_ctop,parcel1%p_ctop,parcel1%q_ctop)
print *,'Cloud-top t, p: ',parcel1%t_ctop,parcel1%p_ctop
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! put water on bin, using koehler equation !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
select case(kappa_flag)
case(0)
do i=1,parcel1%n_bin_modew
n_sel=i
rh_act=0._wp !min(parcel1%rh,0.999_wp)
mult=-1._wp
! has to be less than the peak moles of water at activation
test=fmin(1.e-50_wp,1.e1_wp, koehler02,1.e-30_wp)
rh_act=min(parcel1%rh,0.999_wp)
mult=1._wp
d_dummy=zeroin(1.e-30_wp, test, koehler02,1.e-30_wp)*molw_water
parcel1%mbin(i,n_comps+1)= d_dummy
enddo
! call koehler01(parcel1%t,parcel1%mbin(:,n_comps+1),&
! parcel1%mbin,parcel1%rhobin,&
! parcel1%nubin,parcel1%molwbin,parcel1%n_bin_modew,&
! parcel1%rh_eq,parcel1%rhoat,parcel1%dw)
! print *,parcel1%rh_eq
case(1)
do i=1,parcel1%n_bin_modew
n_sel=i
rh_act=0._wp !min(parcel1%rh,0.999_wp)
mult=-1._wp
! has to be less than the peak moles of water at activation
test=fmin(1.e-50_wp,1.e1_wp, kkoehler02,1.e-30_wp)
rh_act=min(parcel1%rh,0.999_wp)
mult=1._wp
d_dummy=zeroin(1.e-30_wp, test, kkoehler02,1.e-30_wp)*molw_water
parcel1%mbin(i,n_comps+1)= d_dummy
enddo
! call kkoehler01(parcel1%t,parcel1%mbin(:,n_comps+1),&
! parcel1%mbin,parcel1%rhobin,&
! parcel1%kappabin,parcel1%molwbin,parcel1%n_bin_modew,&
! parcel1%rh_eq,parcel1%rhoat,parcel1%dw)
! print *,parcel1%rh_eq
case default
print *,'error kappa flag'
stop
end select
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! set-up ODE variables !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(adiabatic_prof) then
parcel1%neq=parcel1%n_bin_modew+5 ! p,t,rh,z,w
else
parcel1%neq=parcel1%n_bin_modew+6 ! p,t,rh,z,w,ra
if (entrain_period == 0) then
l_inhom =.false.
else
l_inhom = .true.
endif
endif
parcel1%tt=0._wp
parcel1%tout=parcel1%tt+parcel1%dt
parcel1%itol=2
parcel1%rtol=1.e-4_wp
allocate( parcel1%y(parcel1%neq), stat = allocatestatus)
if (allocatestatus /= 0) stop "*** not enough memory ***"
allocate( parcel1%yold(parcel1%neq), stat = allocatestatus)
if (allocatestatus /= 0) stop "*** not enough memory ***"
allocate( parcel1%atol(parcel1%neq), stat = allocatestatus)
if (allocatestatus /= 0) stop "*** not enough memory ***"
parcel1%atol(1:parcel1%n_bin_modew)=1.e-25_wp
parcel1%ipr=parcel1%n_bin_modew+1 ! pressure
parcel1%ite=parcel1%n_bin_modew+2 ! temperarture
parcel1%irh=parcel1%n_bin_modew+3 ! rh
parcel1%iz =parcel1%n_bin_modew+4 ! altitude
parcel1%iw =parcel1%n_bin_modew+5 ! vertical wind
! extra variables for entrainment
if(.not.adiabatic_prof) then
parcel1%ira =parcel1%n_bin_modew+6 ! radius of bubble or jet
parcel1%atol(parcel1%ira) =2.e-2_wp
if(parcel1%ira .ne. parcel1%neq) stop "*** problem with array lengths ***"
else
if(parcel1%iw .ne. parcel1%neq) stop "*** problem with array lengths ***"
endif
parcel1%atol(parcel1%ipr)=10._wp
parcel1%atol(parcel1%ite)=1.e-4_wp
parcel1%atol(parcel1%irh)=1.e-8_wp
parcel1%atol(parcel1%iz) =2.e-2_wp
parcel1%atol(parcel1%iw) =2.e-2_wp
parcel1%itask=1
parcel1%istate=1
parcel1%iopt=1
parcel1%mf=22
parcel1%lrw=22+9*parcel1%neq+2*parcel1%neq**2
allocate( parcel1%rwork(parcel1%lrw), stat = allocatestatus)
if (allocatestatus /= 0) stop "*** not enough memory ***"
parcel1%liw=30+parcel1%neq
allocate( parcel1%iwork(parcel1%liw), stat = allocatestatus)
if (allocatestatus /= 0) stop "*** not enough memory ***"
! extra input variables:
parcel1%iwork=0
parcel1%rwork=0._wp
parcel1%iwork(6) = 100 ! max steps
parcel1%iwork(7) = 10 ! max message printed per problem
parcel1%iwork(5) = 5 ! order
parcel1%rwork(5) = 0._wp !1.e-3_wp ! initial time-step
parcel1%rwork(6) = dt ! max time-step
parcel1%rwork(7) = 0._wp !1.e-9_wp ! min time-step allowed
parcel1%rwork(14) = 2._wp ! tolerance scale factor
! put water in solution vector and set p, t, rh, z, w
parcel1%y(1:parcel1%n_bin_modew)=parcel1%mbin(:,n_comps+1)
parcel1%y(parcel1%ipr)=parcel1%p
parcel1%y(parcel1%ite)=parcel1%t
parcel1%y(parcel1%irh)=parcel1%rh
parcel1%y(parcel1%iz) =parcel1%z
parcel1%y(parcel1%iw) =parcel1%w
if(.not.adiabatic_prof) then
parcel1%y(parcel1%ira) =parcel1%rad
! note, this allocates some space for the aerosol to be entrained into the parcel
allocate( parcel1%mbinedges_ent(1:parcel1%n_bins1+1,1:parcel1%n_modes), &
STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%npart_ent(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%mbin_ent(1:parcel1%n_bin_modew,1:n_comps+1), &
STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%moments_ent(1:parcel1%n_bin_mode,1:n_comps+parcel1%imoms), &
STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
! note, this allocates some space for the aerosol from evaporated drops
allocate( parcel1%mbinedges_temp(1:parcel1%n_bins1+1,1:parcel1%n_modes), &
STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%npart_temp(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%mbin_temp(1:parcel1%n_bin_modew,1:n_comps+1), &
STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%moments_temp(1:parcel1%n_bin_mode,1:n_comps+parcel1%imoms), &
STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
if(ice_flag == 1) then
! note, this allocates some space for the aerosol from evaporated ice
allocate( parcel1%mbinedges_temp2(1:parcel1%n_bins1+1,1:parcel1%n_modes), &
STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%npart_temp2(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%mbin_temp2(1:parcel1%n_bin_modew,1:n_comps+1), &
STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
! don't need moments_temp2 as that is already allocated in moments_temp
endif
endif
! do not print messages
call xsetf(0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(ice_flag .eq. 1) then
! allocation:
allocate( parcel1%dice(1:parcel1%n_bin_mode1), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%maerice(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%npartice(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%mbinice(1:parcel1%n_bin_modew,1:n_comps+1), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%rho_coreice(1:parcel1%n_modes), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%rhobinice(1:parcel1%n_bin_modew,1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%nubinice(1:parcel1%n_bin_modew,1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%molwbinice(1:parcel1%n_bin_modew,1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%kappabinice(1:parcel1%n_bin_modew,1:n_comps), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%rh_eqice(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%rhoatice(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%dwice(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%da_dtice(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%nice(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%phi(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%rhoi(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%nump(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
allocate( parcel1%rime(1:parcel1%n_bin_modew), STAT = AllocateStatus)
if (AllocateStatus /= 0) STOP "*** Not enough memory ***"
parcel1%phi=1._wp
parcel1%rhoi=rhoice
parcel1%nump=1._wp
parcel1%rime=0._wp
parcel1%rho_coreice(:) = parcel1%rho_core(:)
parcel1%npartice=0._wp
parcel1%dice=parcel1%d
parcel1%maerice=parcel1%maer
parcel1%mbinice=parcel1%mbin
parcel1%rhobinice=parcel1%rhobin
parcel1%nubinice=parcel1%nubin
parcel1%molwbinice=parcel1%molwbin
parcel1%kappabinice=parcel1%kappabin