forked from cdominik/optool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
optool_fractal.f90
2469 lines (2314 loc) · 79.7 KB
/
optool_fractal.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
!--------------------------------------------------------------------------------
!
! OPACFRACTAL version 3.0
!
!--------------------------------------------------------------------------------
!
! OPACFRACTAL v3.0 computes light scattering properties of randomly oriented
! fractal dust aggregates by means of the modified mean field theory developed
! in Tazaki & Tanaka (2018). This code is also capable of computing the light
! scattering solution based on the Rayleigh-Gans-Debye theory and the Mean field
! theory.
!
! If you wish to publish a paper that contains results obtained by this code,
! please acknowledge this code and cite relevant papers.
!
! Disclaimer:
! I reject all responsibility for the use of this code. Although it has been
! tested, the code may still contain a bug. I am not responsible for any damages
! caused by the use of the code. If you find a bug, please let me know.
!
! Ryo Tazaki (2020/Nov/11)
! email: r.tazaki -at- uva.nl
!
!--------------------------------------------------------------------------------
!
! LIMITATION OF THE CODE
!
!--------------------------------------------------------------------------------
!
! Here, I summarize some limitations of the code for each approximation (iqsca).
! The limitation can be simply judged by the phase shift induced by an aggregate
! (Equation 9 in Tazaki & Tanaka 2018; see also Section 3.2 in this paper).
!
! iqsca=1: All outputs would be physically reasonable for the phase shift <~ 1.
!
! iqsca=2: The extinction cross section would be calculated without limitation.
! However, the other outputs would be reliable for the phase shift < ~1.
!
! iqsca=3: The extinction cross section would be calculated without limitation.
! Scattering and absorption cross sections could be calculated
! for the phase shift > 1, however too large phase shift may
! cause some problem.
! The asymmetry parameter and the sattering matrix elements would be
! reliable for the phase shift < ~1.
!
! For the two-point correlation function, I suggest to use iqcor=1 because
! it is numerically stable and is likely to reproduce optical properties
! of fractal aggregates.
!
!--------------------------------------------------------------------------------
!
! IMPORTANT REFERENCES
!
!--------------------------------------------------------------------------------
!
! If you wish to publish a paper by using this code, following references should
! be cited depending on the code options (iqsca and iqcor) you used.
!
! Light scattering solver:
! iqsca = 1 : Tazaki et al. 2016, ApJ, 823, 70
! iqsca = 2 : Botet et al. 1997, ApOpt, 36, 8791
! iqsca = 3 : Tazaki & Tanaka 2018, ApJ, 860, 79
!
! The two-point correlation function of monomers:
! iqcor = 1 : Tazaki et al. 2016, ApJ, 823, 70
! iqcor = 2 : Berry & Percival 1986, AcOpt, 33, 577
! iqcor = 3 : Botet et al. 1995, JPhA, 28, 297
!
! The geometric cross section of aggregates (to be used when iqsca=3):
! iqgeo = 2 : Okuzumi et al. 2009, ApJ, 707, 1247
! iqgeo = 3 : Tazaki (submitted)
!
!--------------------------------------------------------------------------------
!
! LIST OF SUBROUTINES BY OTHER AUTHORS
!
!--------------------------------------------------------------------------------
!
! OPACFRACTAL v3.0 contains following subroutines provided by other authors.
! I thank the authors for the availability of the subroutines.
!
! lorenz_mie : BHMIE written by Bruce T. Draine with modifications
! renorm_mie : BHMIE written by Bruce T. Draine with modifications
! gamma : Zhang, S. and Jin, J. (1996) "Computation of Special Functions."
! chgm : Zhang, S. and Jin, J. (1996) "Computation of Special Functions."
! lpmns : Zhang, S. and Jin, J. (1996) "Computation of Special Functions."
! lpn : Zhang, S. and Jin, J. (1996) "Computation of Special Functions."
! ludcmp : Press, W. H. et al. (1997), "Numerical Recipes in Fortran 77"
! lubksb : Press, W. H. et al. (1997), "Numerical Recipes in Fortran 77"
! gauleg : Press, W. H. et al. (1997), "Numerical Recipes in Fortran 77"
! geofrac : Tazaki (submitted to MNRAS)
!
!--------------------------------------------------------------------------------
!
! INPUT PARAMETERS
!
!--------------------------------------------------------------------------------
!
! lmd : wavelength (micron)
! R0 : monomer radius (micron)
! Df : fractal dimension
! PN : number of monomers
! k0 : fractal prefactor; PN = k0 (Rg/R0)^Df
! refrel : complex refractive index of a monomer particle
! nang : Number of angular grid between 0 ang 90 degrees.
! If nang=91, then angular width is 1 degree.
! <TIPS>
! For iqsca=3, I suggest the users to check the convergence
! of the results by changing nang.
! iqsca : Switch for the light scattering solver
! iqsca = 1 : Rayleigh-Gans-Debye theory
! iqsca = 2 : Mean-field theory
! iqsca = 3 : Modified mean-field theory
! iqcor : Switch for the two-point correlation function
! iqcor = 1 : Gaussian cutoff
! iqcor = 2 : Exponential cutoff
! iqcor = 3 : Fractal dimension cutoff
! iqgeo : Switch for the two-point correlation function
! iqgeo = 1 : pi * rc^2, rc is the characteristic radius
! iqgeo = 2 : Okuzumi et al. (2009)
! iqgeo = 3 : Tazaki (submitted)
! iquiet : Switch for standard output during a calculation
! iquiet = 0 : show stdout
! iquiet = 1 : suppress stdout (including warnings)
!
!--------------------------------------------------------------------------------
!
! OUTPUT PARAMETERS
!
!--------------------------------------------------------------------------------
!
! Cext : extinction cross section (micron^2)
! Csca : scattering cross section (micron^2)
! Cabsp : absorption cross section (micron^2)
! Gsca : asymmetry parameter
! Smat(4,2*nang-1) : Scattering matrix elements S_ij
! where S_ij obeys Bohren & Huffman's definition.
! The first column contains each element of scat. matrix
! Smat(1,:) : S_11,
! Smat(2,:) : S_12,
! Smat(3,:) : S_33,
! Smat(4,:) : S_34,
! and the second column contains values at each scattering
! angle from 0 deg to 180 deg with 2*nang-1 grid points.
! dphi : Phase shift induced by the aggregates
!
!--------------------------------------------------------------------------------
!
! HISTORY
!
!--------------------------------------------------------------------------------
!
! version 1.0 (July 24 2017)
! - Initial release
!
! version 2.2 (Oct. 24 2017)
! - Implemented geometrical optics approximation (Modified Mean Field; MMF)
! - Implemented a stable algorithm for computations of the spherical Bessel
! function of the first kind at large order and/or large argument.
! - Fixed bug of Legendre polynomial calculations with large order.
! - Implemented dynamic allocation for some special function calculations.
! - Fixed bug about compiler dependence (ifort or gfortran)
!
! version 2.3 (Dec. 05 2017)
! - Implemented efficient computation of $a(\nu,n,p)$ and $b(\nu,n,p)$
! using the parity arguments.
!
! version 2.5 (May. 31 2020)
! - Fixed a bug about initialization of Qsca and gsca in (renormalized)
! Lorentz-Mie routine. This does not change the results, since both of
! them are not used to obtain final results.
!
! version 3.0 (Jan. 19, 2020)
! - BUG fixed: Add a simple prescription for negative S(q) for iqcor=3.
! - Fixed a code crush for OpenMP mode.
! - Fixed a few type mismatchs and over/underflow signals.
! - Unified notation for Cabs in iqsca=1 for safety.
! - Updated f77 subroutines to f90.
! - Implemented parameterized real precision
! - Implemented more efficient loop structure at calculations of
! gaunt coefficients : a(nu,n,p) and b(nu,n,p).
! - Removed the iqcor=4 option because it is practically unimportant.
! - Added a return variable "phase shift"
! - Added models of for geometric cross sections (iqgeo option)
! - Implemented geofractal code (called by iqgeo=3)
!
!--------------------------------------------------------------------------------
! Some constants
!--------------------------------------------------------------------------------
module types
implicit none
integer, parameter :: dp = selected_real_kind(P=15)
end module types
module const
use types
implicit none
real(kind=dp),parameter :: pi = 3.1415926535897932384_dp
real(kind=dp),parameter :: twopi = 2.0_dp * pi
real(kind=dp),parameter :: halfpi = 0.5_dp * pi
real(kind=dp),parameter :: d2r = pi/180.0_dp ! degree to radian
real(kind=dp),parameter :: r2d = 1.0_dp/d2r ! radian to degree
integer ,parameter :: jm = 400 ! Number of grid points of Gauss-Ledengre
! for integration of Gaunt coefficients.
integer,parameter :: nn = 100000 ! Number of grid points in the numerical
! integration for Sp(kRg)
end module const
!--------------------------------------------------------------------------------
!
!
! MAIN ROUTINE
!
!
!--------------------------------------------------------------------------------
subroutine meanscatt(lmd,R0,PN,Df,k0,refrel,iqsca,iqcor,iqgeo,iquiet,nang,&
Cext,Csca,Cabsp,g_asym,Smat,dphi)
use types; use const; use IOunits
implicit none
!--------------------------------------------------------------------------------
! Input variables
!--------------------------------------------------------------------------------
integer :: iqsca ! switch of method
integer :: iqcor ! switch of correlation function
integer :: iqgeo ! switch of geometric cross section
integer :: iquiet ! switch of suppress warning messages
integer :: nang ! Number of angle mesh between 0 to 90 deg.
real(kind=dp) :: PN ! Number of monomers
real(kind=dp) :: R0 ! Monomer radius
real(kind=dp) :: df, k0 ! fractal dimension and prefactor
real(kind=dp) :: lmd ! wavelength
complex(kind=dp) :: refrel ! complex refractive index
!--------------------------------------------------------------------------------
! Output variables
!--------------------------------------------------------------------------------
real(kind=dp) :: Cext ! Extinction cross section
real(kind=dp) :: Csca ! Scattering
real(kind=dp) :: Cabsp ! Absorption
real(kind=dp) :: g_asym ! asymmetry parameter
real(kind=dp) :: dphi ! Phase shift induced by aggregate
real(kind=dp) :: ang(1:2*nang-1) ! angle grids (from 0.0 to 180.0 deg)
real(kind=dp) :: Smat(1:4,2*nang-1) ! Scatteing matrix elements
real(kind=dp) :: PF(1:2*nang-1) ! Phase function (BH def.)
!--------------------------------------------------------------------------------
! Local variables
!--------------------------------------------------------------------------------
real(kind=dp),parameter :: eta=25.0_dp
real(kind=dp),parameter :: qRg_crit=26.0_dp
real(kind=dp) :: Rg ! radius of gyration
real(kind=dp) :: Rc ! characteristic radius
real(kind=dp) :: k ! wavenumber
real(kind=dp) :: x0,xg ! size parameter of monomer and agg.
real(kind=dp) :: xstop ! used in Mie truncation
real(kind=dp) :: xi ! used in xi (Berry corr)
integer::nstop,numax,nmax
integer::nu,n,p,j,pmin,pmax
integer::degmax,order
integer::iqapp,iqcon ! call geofractal
real(kind=dp),allocatable,dimension(:)::x,w
real(kind=dp)::x1,x2,anunp,bnunp
real(kind=dp)::dang,S11,S12,S33,S34
real(kind=dp)::q,Sq,al,bb,xx,cc
real(kind=dp)::nrm
real(kind=dp)::GC,tau
real(kind=dp),allocatable,dimension(:)::PMN,PMND,LP,DLP
real(kind=dp),allocatable,dimension(:,:)::AL1N,LN,DLN
real(kind=dp)::ff,dphic,dphi0
complex(kind=dp)::sumA,sumB,Sp_tmp
complex(kind=dp),allocatable,dimension(:)::an,bn,y,r,Sp
complex(kind=dp),allocatable,dimension(:,:)::ad,dd,S
complex(kind=dp),allocatable,dimension(:,:,:)::T
complex(kind=dp),dimension(1:2*nang-1)::S1,S2
complex(kind=dp)::cn1,cn2
complex(kind=dp):: mgmref
logical,parameter::debug=.false.
complex(kind=dp)::wa1,wa2
!--------------------------------------------------------------------------------
k = twopi/lmd ! wavenumber
Rg = R0 * (PN/k0) ** (1.0_dp/df) ! Radius of gyration of the aggregate
Rc = sqrt(5.0_dp/3.0_dp)*Rg ! Characteristic radius of the aggregate
xg = k * Rg ! size parameter of aggregates
x0 = k * R0 ! size parameter of a monomer
!--------------------------------------------------------------------------------
!
! Truncation order of the monomer's scattering field
!
!--------------------------------------------------------------------------------
xstop = x0 + 4.0_dp * x0 ** (1.0_dp/3.0_dp) + 2.0_dp
nstop = nint(xstop)
numax = nstop
nmax = nstop
!--------------------------------------------------------------------------------
!
! Check input parameters
!
!--------------------------------------------------------------------------------
if(iquiet .eq. 0) then
write(*,fmt='(1PE15.5,A)') lmd, " = wavelength (um)"
write(*,fmt='(1PE15.5,A)') R0 , " = monomer radius (um)"
write(*,fmt='(1PE15.5,A)') Rg , " = gyration radius (um)"
write(*,fmt='(1PE15.5,A)') Rc , " = characteristic radius (um)"
write(*,fmt='(1PE15.5,A)') x0, " = size parameter of a monomer x0 (um)"
write(*,fmt='(1PE15.5,A)') xg, " = size parameter of an aggregate xg (um)"
write(*,fmt='(I15,A)' ) nstop, " = expansion order of scat. field."
endif
if (iqsca .ne. 1 .and. iqsca .ne. 2 .and. iqsca .ne. 3) then
write(stde,*) 'ERROR: Inappropriate iqsca value.'
write(stde,*) ' STOP.'
stop
endif
if (iqcor .ne. 1 .and. iqcor .ne. 2 .and. iqcor .ne. 3) then
write(stde,*) 'ERROR: Inappropriate iqcor value.'
write(stde,*) ' STOP.'
stop
endif
if (iqgeo .ne. 1 .and. iqgeo .ne. 2 .and. iqgeo .ne. 3) then
write(stde,*) 'ERROR: Inappropriate iqgeo value.'
write(stde,*) ' STOP.'
stop
endif
if (nang .le. 1) then
write(stde,*) 'ERROR: Inappropriate nang value. '
write(stde,*) ' nang should be larger than 1.'
write(stde,*) ' STOP.'
stop
endif
if (iquiet .ne. 0 .and. iquiet .ne. 1) then
write(stde,*) 'ERROR: Inappropriate iquiet value.'
write(stde,*) ' STOP.'
stop
endif
if (PN .lt. 1.0) then
write(stde,*) 'ERROR: Number of monomer is less than unity'
write(stde,*) ' STOP.'
stop
endif
if (df .gt. 3.0) then
write(stde,*) 'ERROR: Fractal dimension should be less than 3.0.'
write(stde,*) ' STOP.'
stop
endif
if(numax + nmax .ge. 500 .and. iquiet .eq. 0) then
write(stde,*) "WARNING: the truncation order of monomer's scattered light"
write(stde,*) " field exceeds the maximum value (=500). "
write(stde,*) " This may cause a code crush at computations of "
write(stde,*) " the spherical Bessel function of the 1st kind. "
endif
!
! compute the phase shift (Equation 9 in Tazaki & Tanaka 2018)
!
ff = PN*(R0/RC)**3.0_dp
call MGmixing(refrel,mgmref,ff)
dphic = 2.0_dp*k*Rc*abs(mgmref-1.0_dp)
dphi0 = 2.0_dp*x0*abs(refrel-1.0_dp)
dphi = max(dphic,dphi0)
if (dphi .ge. 1.0_dp .and. iquiet .eq. 0) then
write(stde,*) 'WARNING: The phase shift by an aggregate exceeds unity.'
write(stde,*) ' Output of scattering matrix elements are not '
write(stde,*) ' physically guaranteed.'
endif
!
if(debug) write(stde,*) 'DEBUG MODE ON'
!--------------------------------------------------------------------------------
!
! Computation part
!
!--------------------------------------------------------------------------------
!
! First, compute Lorenz-Mie scattering coefficients of a monomer
!
allocate(an(nstop),bn(nstop),ad(2,nstop),dd(2,nstop))
! initilizing arrays
ad = cmplx(0.0_dp,0.0_dp,kind=dp)
dd = cmplx(0.0_dp,0.0_dp,kind=dp)
!
call lorenz_mie(x0,refrel,nstop,an,bn)
!
!
ad(1,:) = an(:)
ad(2,:) = bn(:)
!
! Solve multiple scattering?
! iqsca = 1 : No
! iqsca = 2 : Yes
!
if(iqsca .eq. 1) then
!
! Scattering coefficients of the monomer is
! equal to Lorenz-Mie solution.
!
dd(1,:)= ad(1,:)
dd(2,:)= ad(2,:)
elseif(iqsca .ge. 2) then
!--------------------------------------------------------------------------------
!
! Calculate a(nu,n,p) and b(nu,n,p):
!
! 2p + 1 /+1
! a(nu,n,p) = -------- | dx P_nu^1(x) * P_n^1(x) * P_p(x),
! 2 /-1
!
! 2p + 1 /+1 dP_p(x)
! b(nu,n,p) = -------- | dx P_nu^1(x) * P_n^1(x) * -------,
! 2 /-1 dx
!
! where P_n^m is the associated Legendre function (n: degree, m: order),
! P_n is the Legendre polynominal function
! (see Equations (29, 30) in Tazaki & Tanaka 2018).
! The integration is performed with the Gauss-Legendre quadrature.
!
!--------------------------------------------------------------------------------
!
! Preparing for gauss-legendre quadrature
!
allocate(x(jm),w(jm))
! initializing arrays
x = 0.0_dp
w = 0.0_dp
! range of integration
x1 = -1.0_dp
x2 = 1.0_dp
call gauleg(x1,x2,x,w,jm)
!--------------------------------------------------------------------------------
!
! Storing values of the associated Legendgre function and
! the Legendre polynominals and its derivative at each Gauss-Ledengre point.
!
! The values are stored in
! AL1N(n,j) = P_n^1(x_j) : Associated Legendre function with order 1.
! LN (n,j) = P_n(x_j) : Ledengre polynominals
! DLN (n,j) = P_n(x_j)' : Derivative of Legendre polynominals
!
!--------------------------------------------------------------------------------
order = 1
degmax = nstop
pmax = 2*nstop
allocate(PMN(0:degmax),PMND(0:degmax),LP(0:pmax),DLP(0:pmax))
allocate(AL1N(0:degmax,1:jm),LN(0:pmax,1:jm),DLN(0:pmax,1:jm))
do j=1,jm
call lpmns(order,degmax,x(j),PMN,PMND)
call lpn(pmax,x(j),LP,DLP)
AL1N(:,j) = PMN(:)
LN (:,j) = LP(:)
DLN(:,j) = DLP(:)
enddo
deallocate(PMN,PMND,LP,DLP)
!
! Preparing arrays for the structure integration Sp(kRg),
! and the translation matrix.
!
allocate(Sp(0:numax+nmax),T(2,numax,nmax))
! initializing arrays
Sp = cmplx(0.0_dp,0.0_dp,kind=dp)
T = cmplx(0.0_dp,0.0_dp,kind=dp)
!
! The structure integration Sp
!
!call spout(iqcor,df) !for output
do p=0,numax+nmax
Sp_tmp = cmplx(0.0_dp,0.0_dp,kind=dp)
if(debug) then
Sp(p) = (df/(16.0*xg*xg))&
*Gamma(0.5_dp*(df-2.0_dp))/Gamma(0.5_dp*df)
else
call integration_of_Sp(iqcor,iqgeo,df,p,xg,Sp_tmp)
Sp(p) = Sp_tmp
endif
enddo
!--------------------------------------------------------------------------------
!
! Caltulate translation matrix coefficients
!
! Translation coefficients: A and B (Equation # from Tazaki & Tanaka 2018)
! T(1,nu,n) : \bar{A}_{1,n}^{1,nu} defined in Equation (14)
! T(2,nu,n) : \bar{A}_{1,n}^{1,nu} defined in Equation (15)
! anunp : a(nu,n,p) defined in Equation (29)
! bnunp : b(nu,n,p) defined in Equation (30)
!
! Note about the rule of rum with respect to the index p
! (RT and Botet, in private communication, 2017).
!
! Just before Equation (4) in Botet et al. (1997), it is written that
! p should have the same parity as n+nu. However, this is only true
! true for a(nu,n,p), and not for b(nu,n,p)
! Thus, in this code, index p runs ALL integers between |nu-n| and nu+n.
!
! Tips for efficient computation.
! The parity of the integrand of a and b leads following properties:
! - a(nu,n,p) .ne. 0 and b(nu,n,p) = 0 when p has the same parity as n+nu
! - b(nu,n,p) .ne. 0 and a(nu,n,p) = 0 when p has the opposite parity to n+nu
!
!--------------------------------------------------------------------------------
do nu=1,numax
do n=1,nmax
pmin=abs(n-nu)
pmax=nu+n
sumA = 0.0_dp
sumB = 0.0_dp
do p=pmin,pmax
anunp=0.0_dp
bnunp=0.0_dp
if(mod(pmax,2) .eq. mod(p,2)) then
do j=1,jm
anunp = anunp + w(j) * AL1N(nu,j) * AL1N(n,j) * LN(p,j)
enddo
else
do j=1,jm
bnunp = bnunp + w(j) * AL1N(nu,j) * AL1N(n,j) * DLN(p,j)
enddo
endif
anunp = 0.5_dp * real(2*p+1,kind=dp) * anunp
bnunp = 0.5_dp * real(2*p+1,kind=dp) * bnunp
sumA = sumA + real(n*(n+1)+nu*(nu+1)-p*(p+1),kind=dp) * anunp * Sp(p)
sumB = sumB + bnunp * Sp(p)
enddo
T(1,nu,n) = sumA * real(2*nu+1,kind=dp) / real(n*(n+1)*nu*(nu+1),kind=dp)
T(2,nu,n) = sumB * 2.0_dp * real(2*nu+1,kind=dp) / real(n*(n+1)*nu*(nu+1),kind=dp)
enddo
enddo
deallocate(x,w,Sp,AL1N,LN,DLN)
allocate(S(2*numax,2*nmax),y(2*nmax),r(2*nmax))
! initializing arrays
S = cmplx(0.0_dp,0.0_dp,kind=dp)
y = cmplx(0.0_dp,0.0_dp,kind=dp)
r = cmplx(0.0_dp,0.0_dp,kind=dp)
do n=1,nmax
do nu=1,numax
S(2*n-1,2*nu-1) = (PN-1.0_dp) * ad(1,n) * T(1,nu,n) !a*A
S(2*n-1,2*nu) = (PN-1.0_dp) * ad(1,n) * T(2,nu,n) !a*B
S(2*n,2*nu-1) = (PN-1.0_dp) * ad(2,n) * T(2,nu,n) !b*B
S(2*n,2*nu) = (PN-1.0_dp) * ad(2,n) * T(1,nu,n) !b*A
enddo
y(2*n-1) = ad(1,n)
y(2*n) = ad(2,n)
enddo
do n=1,2*nmax
S(n,n) = 1.0_dp + S(n,n)
enddo
!
! Inverting the translation matrix elements (S),
! and find the mean-field vector (r).
! S * r = y
! ==> r = S^{-1} * y
call complex_leqs_solver(2*nstop,4*nstop,S,y,r)
!
! Finally, I obtain mean-field scattering coefficients
! dd(1,n) : d^(1)_n
! dd(2,n) : d^(2)_n
!
do n=1,nmax
dd(1,n) = r(2*n-1)
dd(2,n) = r(2*n)
enddo
deallocate(T,S,y,r)
endif
if(iquiet .eq. 0) then
write(*,*) '----- Lorenz-Mie coefficients -----'
write(*,fmt='(A3,4A15)') "n","Re(an)","Im(an)","Re(bn)","Im(bn)"
wa1=0.0
wa2=0.0
do n=1,nstop
wa1 = wa1 + ad(1,n)
wa2 = wa2 + ad(2,n)
write(*,fmt='(I3,1P4E15.5)') n,real(ad(1,n)),aimag(ad(1,n)),real(ad(2,n)),aimag(ad(2,n))
enddo
if(debug) then
write(*,fmt='(1P2E15.5)') real(wa1)/real(nstop,kind=dp),aimag(wa1)/real(nstop,kind=dp),&
& real(wa2)/real(nstop,kind=dp),aimag(wa2)/real(nstop,kind=dp)
endif
write(*,*) '----- Mean field coefficients -----'
write(*,fmt='(A3,4A15)') "n","Re(d1n(1))","Im(d1n(1))","Re(d1n(2))","Im(d1n(2))"
wa1=0.0
wa2=0.0
do n=1,nstop
wa1 = wa1 + dd(1,n)
wa2 = wa2 + dd(2,n)
write(*,fmt='(I3,1P4E15.5)') n,real(dd(1,n)),aimag(dd(1,n)),real(dd(2,n)),aimag(dd(2,n))
enddo
if(debug) then
write(*,fmt='(1P2E15.5)') real(wa1)/real(nstop,kind=dp),aimag(wa1)/real(nstop,kind=dp),&
& real(wa2)/real(nstop,kind=dp),aimag(wa2)/real(nstop,kind=dp)
endif
endif
!
! Replacing the lorenz-mie scattering coefficients by the mean-field
! scattering coefficients, and find scatternig amplitude of each
! monomer.
!
dang=halfpi/real(nang-1,kind=dp)
call renorm_mie(dd,nstop,nang,dang,S1,S2)
!
! Compute scattering matrix elements based on scattering amplitude
! of each monomer and the static structure factor of an aggregate
!
Smat = 0.0_dp
do j=1,2*nang-1
! scattering angle in radian
ang(j) = dang * real(j-1,kind=dp)
! magnitude of scattering vector
q = 2.0_dp*k*sin(0.5_dp*ang(j))
! scattering matrix elements of each monomer
S11 = 0.5_dp*ABS(S2(j))*ABS(S2(j))
S11 = S11 + 0.5_dp*ABS(S1(j))*ABS(S1(j))
S12 = 0.5_dp*ABS(S2(j))*ABS(S2(j))
S12 = S12 - 0.5_dp*ABS(S1(j))*ABS(S1(j))
S33 = DBLE( S1(j)*CONJG(S2(j)) )
S34 = AIMAG( S2(j)*CONJG(S1(j)) )
!
! Compute interference of scattered waves based on a statistical
! distribution of monomers specified by the two-point correlation
! function. The inteference pattern is characterized by the quantity
! called the static structure factor (Sq) as defined in Eq (17) in
! Tazaki & Tanaka (2018).
!
! The analytical expression of the static structure factor is available
! for the case of iqcor = 1 and 2, but not for iqcor =3.
! Hence, iqcor=3 requires additional numerical integration.
!
if(iqcor .eq. 1) then
! compute confluent hypergeometric function
if(df .eq. 3.0_dp) then
if(q*q*Rg*Rg/3.0 .ge. eta) then
Sq = 0.0_dp
else
Sq = exp(-q*q*Rg*Rg/3.0_dp)
endif
else
AL = 0.5_dp * df
BB = 1.5_dp
XX = -q*q*Rg*Rg/df
if(q*Rg .lt. qRg_crit) then
call chgm(AL,BB,XX,Sq)
else
CC=sqrt(pi)*Df**(0.5_dp*Df)/(2.0*gamma(0.5_dp*(3.0-Df)))
Sq=CC*(q*RG)**(-Df)
endif
endif
elseif(iqcor .eq. 2) then
xi = sqrt(2.0_dp/(df*(df+1.0_dp))) * Rg
IF(J .eq. 1) then
Sq = 1.0_dp
else
Sq = sin((df-1.0_dp)*atan(q*xi))/(q*xi*(df-1.0_dp)&
*(1.0_dp+(q*xi)**2.0_dp)**((df-1.0_dp)/2.0_dp))
endif
elseif(iqcor .eq. 3) then
call structure_factor_integration(df,q,Rg,Sq)
endif
Smat(1,j) = PN * S11 * (1.0_dp + (PN-1.0_dp) * Sq)
Smat(2,j) = PN * S12 * (1.0_dp + (PN-1.0_dp) * Sq)
Smat(3,j) = PN * S33 * (1.0_dp + (PN-1.0_dp) * Sq)
Smat(4,j) = PN * S34 * (1.0_dp + (PN-1.0_dp) * Sq)
! safety check.
if(Smat(1,j) .lt. 0.d0) then
write(stde,*) 'ERROR: S11 for aggregte becomes negative. Strange!'
write(stde,*) ' STOP.'
stop
endif
enddo
!
! Compute scattering cross section of aggregates
! by integrating S11 via Simpson's rule.
!
Csca = 0.0_dp
do j=1,nang-1
Csca = Csca + dang * &
( Smat(1,2*j-1) * sin(ang(2*j-1)) + &
4.0_dp*Smat(1,2*j ) * sin(ang(2*j )) + &
Smat(1,2*j+1) * sin(ang(2*j+1)) ) / 3.0_dp
enddo
Csca = twopi * Csca / k / k
PF(:) = Smat(1,:) / Csca / k / k
!
! asymmetry parameter by integrating
! phase function with Simpson's rule.
!
g_asym = 0.0_dp
nrm = 0.0_dp
DO j=1,nang-1
g_asym = g_asym + dang * &
( PF(2*j-1) * sin(ang(2*j-1)) * cos(ang(2*j-1)) + &
4.0_dp*PF(2*j ) * sin(ang(2*j )) * cos(ang(2*j )) + &
PF(2*j+1) * sin(ang(2*j+1)) * cos(ang(2*j+1)) ) / 3.0d0
nrm = nrm + dang * &
( PF(2*j-1) * sin(ang(2*j-1)) + &
4.0_dp*PF(2*j ) * sin(ang(2*j )) + &
PF(2*j+1) * sin(ang(2*j+1)) ) / 3.0_dp
END DO
nrm = twopi * nrm
g_asym = twopi * g_asym
!
! Check normalization of phase function
!
if (abs(nrm-1.0_dp) .gt. 1.0e-3_dp) then
write(stde,*) ABS(nrm-1.0_dp)*1.0e2_dp
write(stde,*) 'ERROR: Phase function is not normalized to unity. Strange!'
stop
end if
!
! Calculate optical cross sections.
!
! For the case of an isolcated individual monomer,
! each cross section can be written by
! (Equation (4.61; 4.62) in Bohren & Huffman textbook.)
!
! nstop
! 2*pi ---
! C_ext = ------ \ (2n+1) Re ( an + bn )
! k^2 /--
! n=1
!
! nstop
! 2*pi ---
! C_sca = ------ \ (2n+1) ( |an|^2 + |bn|^2 )
! k^2 /--
! n=1
!
! nstop
! 2*pi --- 1 1
! C_abs = ------ \ (2n+1) Re{|an|^2 ( --- - 1 ) + |bn|^2 ( --- - 1 )}
! k^2 /-- an* bn*
! n=1
!
! where (an,bn) is scattering coefficients of each monomer and * denotes
! the complex conjugate.
!
if(iqsca .eq. 1) then
Cabsp = 0.0_dp
do n=1,nstop
cn1 = 1.0_dp/conjg(ad(1,n))-1.0_dp
cn2 = 1.0_dp/conjg(ad(2,n))-1.0_dp
Cabsp = Cabsp + real(2*n+1,kind=dp)*&
&real(cn1*abs(ad(1,n))*abs(ad(1,n))+cn2*abs(ad(2,n))*abs(ad(2,n)))
enddo
Cabsp = Cabsp * twopi * PN / k / k
Cext = Cabsp + Csca
elseif(iqsca .eq. 2) then
Cext = 0.0_dp
do n=1,nstop
Cext = Cext + real(2*n+1,kind=dp)*real(dd(1,n)+dd(2,n))
enddo
Cext = Cext * twopi * PN / k / k
Cabsp = Cext - Csca
elseif(iqsca .eq. 3) then
Cext = 0.0_dp
Cabsp = 0.0_dp
! Cext : Mean-field extinction
! Cabsp : RGD theory
do n=1,nstop
Cext = Cext + real(2*n+1,kind=dp)*real(dd(1,n)+dd(2,n))
cn1 = 1.0_dp/conjg(ad(1,n))-1.0_dp
cn2 = 1.0_dp/conjg(ad(2,n))-1.0_dp
Cabsp = Cabsp + real(2*n+1,kind=dp)*&
&real(cn1*abs(ad(1,n))*abs(ad(1,n))+cn2*abs(ad(2,n))*abs(ad(2,n)))
enddo
Cext = Cext * twopi * PN / k / k
Cabsp = Cabsp * twopi * PN / k / k
!
! Geometrical cross section of an aggregate
!
if(iqgeo .eq. 1) then
GC = pi * RC * RC
elseif(iqgeo .eq. 2) then
call geocross(PN,R0,RC,GC)
elseif(iqgeo .eq. 3) then
iqapp=3 ! use approximate solution
iqcon=1 ! without small-cluster limit.
call geofrac(iqapp,iqcon,iqcor,PN,k0,df,GC)
GC = GC * PN * pi * R0 * R0
endif
!
! Compute "tau" of an aggregate, where Cabsp is RGD theory's one
!
tau = (Cabsp/GC)
!
! RGD theory with geometrical optics approximation.
! TIP: To avoid underflow, tau>eta=10, Cabsp = GC.
!
if(tau .ge. 10.0_dp) then
Cabsp = GC
else
Cabsp = GC * (1.0_dp - exp(-tau))
endif
! Compare MFT vs. RGD+GeoOpt, take the larger one.
Cabsp = max(Cabsp,Cext-Csca)
! Scattrering is computed from Cext(MFT)-Cabs.
Csca = Cext - Cabsp
endif
deallocate(an,bn,ad,dd)
return
end subroutine meanscatt
!--------------------------------------------------------------------------------
!
! This subroutine finds effective refractive index of an aggregates
! by using Maxwell--Garnett mixing rule.
!
! eps1: dielectric function of material 1
! eps2: dielectric function of material 2 (vacuum)
! f1 : volume filling factor of material 1
! f2 : volume filling factor of material 2 ( = Porosity )
!
!--------------------------------------------------------------------------------
subroutine MGmixing(refrel,mgav,f1)
use types
implicit none
real(kind=dp)::f1
complex(kind=dp)::eps1,eps2,refrel
complex(kind=dp)::mg,mgav
eps1 = refrel*refrel
eps2 = cmplx(1.0_dp,0.0_dp,kind=dp)
mg=eps2*(2.0_dp*f1*(eps1-eps2)+eps1+2.0_dp*eps2)/&
(eps1+2.0_dp*eps2-f1*(eps1-eps2))
mgav=sqrt(mg)
return
end subroutine MGmixing
!--------------------------------------------------------------------------------
!
! This subroutine performs integration of the static structure factor by
! Botet et al. (1995) based on df-dependent cut-off function for two-point
! correlation function.
! The statis structure factor S(q) is given by
!
!
! c*df /x_max
! S(q) = ---- * | dx x^{df-2}*sin(q*Rg*x)*exp[-c*x^df],
! q*Rg /0
!
!
! where x = u/Rg; where Rg is the radius of gyration and u is the
! distance between two monomers; q is the magnitude of scattering
! vector, df is the fractal dimension, c=0.5 is normalization factor.
!
! Since we have a steep cut-off function for x>1, it would be enough
! to take x_max slightly larger than unity.
! Here we determine xmax so that eta=c*x^df becomes 25.
!
! We use Simpson's rule for the numerical integration, and then,
! the integration range [0,xmax] will be divided by 2*m points.
!
! Caution:
! For large df(>2) and large qRg, the numerical integration sometimes
! returns a negative value of S(q). Since S(q) is a power spectrum,
! it must be positive. I also noticed that the same problem arises with
! the code written by Pascal Rannou. Because of this ill behavior, I
! prefer to use Gausian-cut-off model, which is more stable.
!
! A not-too-bad tentative prescription is simply set S(q)=0 when S(q)<0,
! which means scattered waves from each monomer is incoherent. This is
! what I did in if-sentence at the end of this subroutine.
!
!--------------------------------------------------------------------------------
subroutine structure_factor_integration(D,q,Rg,Sq)
use types
implicit none
integer::i
integer , parameter :: m = 100000 ! # of integration grids
real(kind=dp), parameter :: c = 0.5_dp ! normalization factor by Botet+97
real(kind=dp)::xmax,D,q,Rg,Sq,h
real(kind=dp)::func,x0,x1,x2,eta
! estimate upper limit of integration: xmax
eta = 25
xmax = (eta/c)**(1.0_dp/D)
if(q .eq. 0.0_dp) then
Sq = 1.0_dp
else
Sq = 0.0_dp
h = xmax/real(2*m,kind=dp)
do i=0,m-1
x0 = real(2*i,kind=dp)*h
x1 = real(2*i+1,kind=dp)*h
x2 = real(2*i+2,kind=dp)*h
Sq = Sq + h * ( func(x0,c,D,q,Rg) +&
4.0_dp*func(x1,c,D,q,Rg) +&
func(x2,c,D,q,Rg) )/3.0d0
end do
Sq = Sq * c * D / q / Rg
endif
! switch-off the monomer-monomer correlation when S(q)<0.
if(Sq .lt. 0.0_dp) then
Sq = 0.0_dp
endif
return
end subroutine structure_factor_integration
function func(x,c,D,q,Rg)
use types
implicit none
real(kind=dp), parameter :: floorval = 1.e-30_dp
real(kind=dp)::q,Rg,D,c,x
real(kind=dp)::func
if(x .eq. 0.0_dp) then
func = 0.0_dp
else
func = sin(q*Rg*x)*exp(-c*x**D)*x**(D-2.0_dp)
if(abs(func) .le. floorval) then
func = 0.0_dp
endif
endif
return
end function func
!--------------------------------------------------------------------------------
!
! Calculate Lorenz-Mie scattering coefficients (an,bn) for a monomer particle.
!
! Since monomer's size parameter is supposed not to be very large,
! I use simple Bohren & Huffman Mie algorithm is used.
!
! The original BHMIE code is taken from Bruce Draine's HP:
! https://www.astro.princeton.edu/~draine/scattering.html
! although we have slightly modified it.
!
!--------------------------------------------------------------------------------
subroutine lorenz_mie(x,refrel,nstop,a,b)
use types; use IOunits
implicit none
integer,parameter :: nmxx=150000
integer :: nstop
real(kind=dp) :: x
complex(kind=dp) :: refrel
!--------------------------------------------------------------------------------
integer :: n,nmx,en
real(kind=dp) :: xstop,ymod,enr,nr
real(kind=dp) :: psi0,psi1,psi,chi0,chi1,chi
complex(kind=dp) :: xi1,xi,y
complex(kind=dp),allocatable,dimension(:) :: d
complex(kind=dp),dimension(nstop) :: a,b
y = refrel * x
ymod = abs(y)
xstop = x + 4.0_dp * x ** (1.0_dp/3.0_dp) + 2.0_dp
nmx = nint(max(xstop,ymod)) + 15
if(nmx .gt. nmxx) then
write(stde,*) "Error: nmx > nmxx=",nmxx,"for |m|x=",ymod
stop
endif
! calculate logarithmic derivative D_n(mx)
! by downward recurrence.
! Initial value is set as D(mx)=0+0i at n=NMX.
allocate(d(1:nmx))
d(nmx)=cmplx(0.0_dp,0.0_dp,kind=dp)
do n=1,nmx-1
en = nmx-n+1
enr = real(nmx-n+1,kind=dp)
d(nmx-n) = (enr/y) - (1.0_dp/(d(en) + enr/y))
enddo