forked from rwharvey/cql3d
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ainpla.f
1994 lines (1879 loc) · 95.8 KB
/
ainpla.f
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
c
c
c
subroutine ainpla
implicit integer (i-n), real*8 (a-h,o-z)
save
c..........................................................
c This routine initialize some plasma parameter profiles
c on the whole lrzmax radial mesh
c (some where defined in diaggnde before)
c.............................................................
include 'param.h'
include 'comm.h'
c.......................................................................
cl 1. Energy, v-thermal
c.......................................................................
cl 1.1 radial mesh
do 110 k=1,ntotal
rstmss=fmass(k)*clite2/ergtkev
do 111 l=1,lrzmax
thta=rstmss/temp(k,l)
if (thta.gt.100. .or. relativ.eq."disabled") then
energy(k,l)=1.5*temp(k,l)
!write(*,*)'ainpla.1: energy(k,l)/1.5=',energy(k,l)/1.5
else
call cfpmodbe(thta,bk1,bk2)
energy(k,l)=rstmss*(bk1/bk2-1.+3./thta)
!write(*,*)'ainpla.2: energy(k,l)/1.5=',energy(k,l)/1.5
endif
c write(*,*)'ainpla: k,l,energy(k,l):',k,l,energy(k,l)
vth(k,l)=((temp(k,l)*ergtkev)/fmass(k))**.5
if (k .eq. kelec) vthe(l)=vth(kelec,l)
111 continue
110 continue
c.......................................................................
cl 1.2 parallel mesh
c.......................................................................
if (cqlpmod .eq. "enabled") then
do 120 k=1,ntotal
rstmss=fmass(k)*clite2/ergtkev
do 121 l=1,lsmax
thta=rstmss/temppar(k,l)
if (thta.gt.100. .or. relativ.eq."disabled") then
enrgypa(k,l)=1.5*temppar(k,l)
else
call cfpmodbe(thta,bk1,bk2)
enrgypa(k,l)=rstmss*(bk1/bk2-1.+3./thta)
endif
vthpar(k,l)=((temppar(k,l)*ergtkev)/fmass(k))**.5
121 continue
if (sbdry.eq."periodic" .and. transp.eq."enabled") then
enrgypa(k,0)=enrgypa(k,lsmax)
enrgypa(k,lsmax+1)=enrgypa(k,1)
vthpar(k,0)=vthpar(k,lsmax)
vthpar(k,lsmax+1)=vthpar(k,1)
endif
120 continue
endif
c.......................................................................
c 2. Compute radial Z-effective
c.......................................................................
if (izeff.eq."ion") then
k1=ngen+1
else
k1=1
endif
do 200 l=1,lrzmax
zeff(l)=0.
zeff1=0.
zeff4(l)=0.d0 !Yup[2014-05-27] Initialize to 0.
xq=0.
do 210 k=k1,ntotal
if (k.eq.kelecg .or. k.eq.kelecm) goto 210
cBobH990128 if (k.eq.izeff) goto 210
xq=xq+1.
zeff(l)=zeff(l)+bnumb(k)**2*reden(k,l)
zeff4(l)=bnumb(k)**4*reden(k,l)+zeff4(l)
zeff1=zeff1+bnumb(k)*reden(k,l)
210 continue
!if(nstates.gt.0)then
!YuP[2020-06-22] Skip this part
![contribution of partially ionized impurities to Zeff],
!because nstates and bnumb_imp() are not set yet
!(ainpla is called too early in tdinitl, before set_impurity_data is called).
!This is not important, because
!tdinitl->ainitial->diaggnde calculates zeff() and zeff4() anyway
!(at each n, including n=0).
! do kstate=1,nstates ! Now additional ions from impur.source.
! dens_kstate=dens_imp(kstate,lr_)
! xq=xq+1
! zeff(lr_)= zeff(lr_) +dens_kstate*bnumb_imp(kstate)**2
! zeff4(lr_)=zeff4(lr_)+dens_kstate*bnumb_imp(kstate)**4
! zeff1= zeff1 +dens_kstate*bnumb_imp(kstate)
! enddo ! kstate
!endif !
zeff4(l)=zeff4(l)/xq
zeff(l)=zeff(l)/zeff1
200 continue ! l=1,lrzmax
return
end
!=======================================================================
!=======================================================================
subroutine set_impurity_data !(INPUT: imp_type is in namelist)
!------------------------- contribution from partially ionized ions -----
!YuP[2020-07-02] Set general data for selected type of impurity.
! (Before 2020-07, it was part of subr.set_gscreen_hesslow).
!This subroutine should be called when
! (imp_depos_method.ne."disabled")
! At present, it is set for one ion type (imp_type in namelist),
! but it could be generalized in future.
! Below, excitation energies are from Stephan P.A. Sauer, Jens Oddershede, John R. Sabin
! Advances in Quantum Chemistry, Volume 71; http://dx.doi.org/10.1016/bs.aiq.2015.02.001
implicit integer (i-n), real*8 (a-h,o-z)
CMPIINSERT_INCLUDE
include 'param.h'
include 'comm.h'
!integer imp_type ! INPUT, from namelist
integer istat ! local
!OUTPUT:
!integer nstates ! save into comm.h, to be used by sub.cfpcoefn
!real*8 fmass_imp ! scalar; save into comm.h, to be used by sub.cfpcoefn
!Also these arrays are set in this subroutine:
!real*8, dimension(:), pointer :: a_imp !(0:nstates)
!real*8, dimension(:), pointer :: bnumb_imp !(0:nstates) !Could be set as integer?
!real*8, dimension(:), pointer :: excit_enrgy !(0:nstates)
SELECT CASE (imp_type)
! imp_type: 1->He,2->Be,3->C,4->N,5->Ne,6->Ar,7->Xe,8->W
CASE(1) ! He
nstates=2 ! He[0](neutral), He[1+], He[2+]
allocate(a_imp(0:nstates),STAT=istat) !== a^bar in paper (Table 1)
allocate(bnumb_imp(0:nstates),STAT=istat) !Z0j in Hesslow
allocate(excit_enrgy(0:nstates),STAT=istat) !Ij in Hesslow. [eV] here
fmass_imp=4.*proton
a_imp= (/173, 123, 0/ ) ! a_imp(nstates) can be any value.
bnumb_imp= (/0.d0, 1.d0, 2.d0/ ) ! Charge number of each kstate
excit_enrgy=(/42.68,59.88,1./) !eV! Last number is not important
CASE(2) ! Be
nstates=4 ! Be[0](neutral), Be[1+], Be[2+], Be[3+], Be[4+]
allocate(a_imp(0:nstates),STAT=istat) !== a^bar in paper (Table 1)
allocate(bnumb_imp(0:nstates),STAT=istat) !Z0j in Hesslow
allocate(excit_enrgy(0:nstates),STAT=istat) !Ij in Hesslow
fmass_imp=9.*proton
a_imp= (/159, 114, 67, 59, 0/ ) ! a_imp(nstates) can be any value
bnumb_imp=(/0.d0,1.d0,2.d0,3.d0,4.d0/ ) ! Charge number of each kstate
!No data on excit energy for Be. Use approximation:
excit_enrgy(0)=10.*bnumb_imp(nstates) ! 10ev*Zatomic_number for neutral
!We take excit_enrgy_eV= 10eV *Z_imp (atomic number)
![See Breizman/NF2019, after Eq.(27): mean excit. potential]
!This is ok for an atom, but not good for a partially-ionized ion.
do kstate=1,nstates-1 !All ionized states, except fully-ionized
excit_enrgy(kstate)= 15.*bnumb_imp(kstate)**2 ! 15ev*Zion^2
!This is a very rough estimate, so better find data.
enddo
excit_enrgy(nstates)=1. ! Fully-ionized: Any number .ne.0
!For fully-ionized state hbethe()=0 because z_bound=0.
CASE(3) ! C
nstates=6 !C[0](neutral),C[1+],C[2+],C[3+],C[4+],C[+5],C[+6]
allocate(a_imp(0:nstates),STAT=istat) !== a^bar (Table 1)
allocate(bnumb_imp(0:nstates),STAT=istat) !Z0j in Hesslow
allocate(excit_enrgy(0:nstates),STAT=istat) !Ij in Hesslow
fmass_imp=12.*proton
a_imp= (/144, 118, 95, 70, 42, 39, 0/ )
bnumb_imp= (/0.d0,1.d0,2.d0, 3.d0, 4.d0, 5.d0, 6.d0/ )
excit_enrgy=(/65.9,92.6,134.8,214.2,486.2,539.5,1./) !eV! Last number is not important
CASE(4) ! N
nstates=7
allocate(a_imp(0:nstates),STAT=istat) !== a^bar (Table 1)
allocate(bnumb_imp(0:nstates),STAT=istat) !Z0j in Hesslow
allocate(excit_enrgy(0:nstates),STAT=istat) !Ij in Hesslow
fmass_imp=14.*proton
a_imp= (/135, 115, 97, 79, 59, 35, 33, 0/ )
bnumb_imp=(/0.d0,1.d0,2.d0,3.d0,4.d0,5.d0,6.d0,7.d0/ )
!No data on excit energy for N. Use approximation:
excit_enrgy(0)=10.*bnumb_imp(nstates) ! 10ev*Zatomic_number for neutral
do kstate=1,nstates-1
excit_enrgy(kstate)= 15.*bnumb_imp(kstate)**2 ! 15ev*Zion^2
enddo
excit_enrgy(nstates)=1. ! Any number .ne.0
CASE(5) ! Ne
nstates=10
allocate(a_imp(0:nstates),STAT=istat) !== a^bar (Table 1)
allocate(bnumb_imp(0:nstates),STAT=istat) !Z0j in Hesslow
allocate(excit_enrgy(0:nstates),STAT=istat) !Ij in Hesslow
fmass_imp=20.*proton
a_imp= (/111, 100, 90, 80, 71, 62, 52, 40,
& 24, 23, 0/ )
bnumb_imp= (/0.d0, 1.d0, 2.d0, 3.d0, 4.d0, 5.d0, 6.d0, 7.d0,
& 8.d0, 9.d0, 10.d0/ )
excit_enrgy=(/137.2,165.2,196.9,235.2,282.8,352.6,475.0,696.8,
& 1409.2,1498.2,1.0/) !eV! Last number is not important
CASE(6) ! Ar
nstates=18
allocate(a_imp(0:nstates),STAT=istat) !== a^bar (Table 1)
allocate(bnumb_imp(0:nstates),STAT=istat) !Z0j in Hesslow
allocate(excit_enrgy(0:nstates),STAT=istat) !Ij in Hesslow
fmass_imp=40.*proton
a_imp= (/96, 90, 84, 78, 72, 65, 59, 53, 47,
& 44, 41, 38, 35, 32, 27, 21, 13, 13, 0/ )
bnumb_imp= (/0.d0,1.d0,2.d0,3.d0,4.d0,5.d0,6.d0,7.d0,8.d0,
& 9.d0,10.d0,11.d0,12.d0,13.d0,14.d0,15.d0,16.d0,17.d0,18.d0/ )
excit_enrgy=(/188.5,219.4,253.8,293.4,339.1,394.5,463.4,568.,
& 728.,795.9,879.8,989.9,1138.1,1369.5,1791.2,2497.,4677.2,
& 4838.2, 1.0/) !eV! Last number is not important
CASE(7) ! Xe (Z=54, but only states 1+,2+,3+ are given in Table 1)
nstates=54
allocate(a_imp(0:nstates),STAT=istat) !== a^bar (Table 1)
allocate(bnumb_imp(0:nstates),STAT=istat) !Z0j in Hesslow
allocate(excit_enrgy(0:nstates),STAT=istat) !Ij in Hesslow
fmass_imp=131.*proton !(131.3)
a_imp(:)=0.d0
a_imp= (/65, 65, 63, 61/ ) ! Set the rest to 0?
do kstate=0,nstates
bnumb_imp(kstate)= kstate*1.d0
enddo
!No data on excit energy for Xe. Use approximation:
excit_enrgy(0)=10.*bnumb_imp(nstates) ! 10ev*Zatomic_number for neutral
do kstate=1,nstates-1
excit_enrgy(kstate)= 15.*bnumb_imp(kstate)**2 ! 15ev*Zion^2
enddo
excit_enrgy(nstates)=1. ! Any number .ne.0
CASE(8) ! W (Z=74, but only states 0,30+,40+,50+,60+ are given in Table 1)
! Z= [0 30 40 50 60 ];
! a_bar=[59 33 25 18 13 ];
!The value of a_bar (a_imp here) in Hesslow (JPP-2018) is almost
! a linear function of Z state.
!We simply fill-in the rest of points.
!Probably the line is approaching a=10 at Z=74.
nstates=74
allocate(a_imp(0:nstates),STAT=istat) !== a^bar (Table 1)
allocate(bnumb_imp(0:nstates),STAT=istat) !Z0j in Hesslow
allocate(excit_enrgy(0:nstates),STAT=istat) !Ij in Hesslow
fmass_imp=184.*proton !(183.84)
a_imp(:)=0.d0
a_imp=(/59.0000,58.1333,57.2667,56.4000,55.5333,
& 54.6667,53.8000,52.9333,52.0667,51.2000,
& 50.3333,49.4667,48.6000,47.7333,46.8667,
& 46.0000,45.1333,44.2667,43.4000,42.5333,
& 41.6667,40.8000,39.9333,39.0667,38.2000,
& 37.3333,36.4667,35.6000,34.7333,33.8667,
& 33.0000,32.2000,31.4000,30.6000,29.8000,
& 29.0000,28.2000,27.4000,26.6000,25.8000,
& 25.0000,24.3000,23.6000,22.9000,22.2000,
& 21.5000,20.8000,20.1000,19.4000,18.7000,
& 18.0000,17.5000,17.0000,16.5000,16.0000,
& 15.5000,15.0000,14.5000,14.0000,13.5000,
& 13.0000,12.7857,12.5714,12.3571,12.1429,
& 11.9286,11.7143,11.5000,11.2857,11.0714,
& 10.8571,10.6429,10.4286,10.2143, 0.0 /)
do kstate=0,nstates
bnumb_imp(kstate)= kstate*1.d0
enddo
!No data on mean excit energy for W. Use approximation:
!10.*bnumb_imp(nstates) !10ev*Zatomic_number for neutral
excit_enrgy(0)=727.0 ! From Table 4.3 in nbsir82-2550.pdf
do kstate=1,nstates-1
excit_enrgy(kstate)=15.*(bnumb_imp(kstate)+1.)**2 !15ev*(Z+1)^2
enddo
excit_enrgy(nstates)=1. ! Any number .ne.0
CASE DEFAULT
!If none of allowed imp_type was used:
nstates=0 ! Effectively, no impurities. Below, gscreen(0,j)-->0
allocate(a_imp(0:nstates),STAT=istat)
allocate(bnumb_imp(0:nstates),STAT=istat) !Z0j in Hesslow
allocate(excit_enrgy(0:nstates),STAT=istat) !Ij in Hesslow
a_imp= 0.d0 ! a_imp(nstates) can be any value.
bnumb_imp=0.d0 ! Charge number of each kstate
excit_enrgy=1.0 ! Any number>0
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)
& 'set_impurity_data/WARNING: No data on this imp_type=',
& imp_type
CMPIINSERT_ENDIF_RANK
END SELECT
!allocate arrays for density and temperature
!of each ionization state:
allocate(fz(0:nstates),STAT=istat) !Distribution over charge states,
!to be found at each time step and each lr flux surface.
allocate(dens_imp(0:nstates,1:lrz),STAT=istat)
allocate(temp_imp(0:nstates,1:lrz),STAT=istat)
!allocate(dens_imp_allstates(1:lrz),STAT=istat)
fz(0:nstates)=0.d0 ! initialize
dens_imp(0:nstates,1:lrz)=0.d0 ! initialize
temp_imp(0:nstates,1:lrz)=0.d0 ! initialize
dens_imp_allstates(:)=0.d0 ! initialize
!The values are supposed to be defined at each time step,
!from radiative balance.
return
end subroutine set_impurity_data
!=======================================================================
!=======================================================================
subroutine set_gscreen_hesslow !(INPUT: imp_type is in namelist)
!------------------------- contribution from partially ionized ions -----
!YuP[2019-07-29] Set gscreen(p) function (of normalized momentum p)
!that describes the effect of partially screened ions
!on enhanced scattering of electrons. Fast electrons can "probe"
!the inner structure of a partially ionized ion, or a neutral atom.
!Also, set hbethe(p) function that describes the slowing down
!of free electron on bound electrons in partially ionized ion
!or neutral atom.
!See Hesslow et al, JPP-2018,vol.84, Eq.(2.25) and (2.31).
!This subroutine should only be called when gamafac.eq."hesslow" .and. kelecg.eq.1
! At present, it is set for one ion type (imp_type in namelist),
! but it could be generalized in future.
! Below, excitation energies are from Stephan P.A. Sauer, Jens Oddershede, John R. Sabin
! Advances in Quantum Chemistry, Volume 71; http://dx.doi.org/10.1016/bs.aiq.2015.02.001
implicit integer (i-n), real*8 (a-h,o-z)
CMPIINSERT_INCLUDE
include 'param.h'
include 'comm.h'
!INPUT: integer imp_type ! (from namelist)
!INPUT: bnumb_imp(),excit_enrgy(),a_imp() [set in subr.set_impurity_data]
integer istat ! local
real*8 z_imp,z_state,zz_state,z_bound,zz_bound,p_n,pa32,two3rd !local
real*8 beta_v,beta2,hj !local
!OUTPUT: gscreen(0:nstates,1:jx), hbethe(0:nstates,1:jx)
!--- Now setup gscreen for the given case from above.
write(*,*)'set_gscreen_hesslow: nstates',nstates
allocate(gscreen(0:nstates,1:jx),STAT=istat)
allocate(hbethe(0:nstates,1:jx),STAT=istat)
z_imp=bnumb_imp(nstates) !Atomic charge number (as in fully ionized state)
two3rd= 2.d0/3.d0 ! Just a constant
do kstate=0,nstates
z_state= bnumb_imp(kstate) ! Z0j in paper
z_bound= z_imp-z_state ! Nej in paper (number of bound electrons)
zz_bound= z_bound*z_bound
zz_state= z_bound*(z_imp+z_state) !=z_imp**2-z_state**2 = Zj^2-Z0j^2 in paper
excit_en_n= (excit_enrgy(kstate)*1.d-3)/restmkev ! keV/keV
!Note: excit_en_n is norm-ed by me*c^2==restmkev=510.998902d0keV
do j=1,jx
p_n= x(j)*vnorm/clight ! norm-ed momentum
!Note: p_n = gamma*v/c where v is speed,
!and gamma=sqrt(1+(x*vnorm/c)^2)=sqrt(1+p_n^2)
beta_v= p_n/gamma(j) ! = v/c
beta2= beta_v*beta_v
pa32= (p_n*a_imp(kstate))**1.5
gscreen(kstate,j)= two3rd*( zz_state*log(pa32+1.d0)
& -zz_bound*pa32/(pa32+1.d0) )
& *imp_bounde_collscat
!Note: for kstate=nstates we have z_state=z_imp (so z_bound=0),
!so that gscreen(nstates,j)=0 for all j.
!That is why the value of a_imp(nstates) is not important.
! [To disable this correction, set imp_bounde_collscat to 0]
!---> Now set hbethe(). This is Nej*[(1/k)ln(1+hj^k) - beta^2]
!in the JPP paper, in Eq.(2.31)
!Note: excit_en_n is norm-ed by me*c^2==restmkev=510.998902d0keV
hj= p_n*sqrt(gamma(j)-1.d0)/excit_en_n
hbethe(kstate,j)= z_bound*(0.2*log(1.d0+hj**5) -beta2)
& *imp_bounde_collslow
!Note: 0.2 is 1/k=1/5 in the paper
!(parameter for a smooth transition to p-->0 range)
!Note: When p is small, hj-->0 and beta-->0,
!then hbethe-->0 (no additional slowing down
!because a free electron cannot penetrate electron shells
!of the partially ionized ion.
!If we don't use this transitional form,
!but use ln(hj)-beta2, this function may become negative
!at small p.
!YuP: I plotted and verified that 0.2*log(1.d0+hj**5) -beta2
!is always positive. It becomes~0 at p_n<0.02 for Ar0(atom)
!(or at p_n<0.10 for Ar[17+])
! [To disable this correction, set imp_bounde_collslow to 0]
enddo ! j
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)'set_gscreen_hesslow: kstate, min/max gscreen=',
& kstate, MINVAL(gscreen(kstate,:)),MAXVAL(gscreen(kstate,:))
WRITE(*,*)'set_gscreen_hesslow: kstate, min/max hbethe=',
& kstate, MINVAL(hbethe(kstate,:)),MAXVAL(hbethe(kstate,:))
CMPIINSERT_ENDIF_RANK
enddo ! kstate
return
end subroutine set_gscreen_hesslow
!=======================================================================
!=======================================================================
subroutine set_get_ADPAK(kopt,imp_type,
& temp_Te,dens_nD0,dens_ne,tau_r,
& z1av,z2av)
!(INPUT: kopt,imp_type,temp_Te,dens_nD0,dens_ne,tau_r)
!YuP[2019-08-15]-[2019-08-20]
!Read impurity emissivity and charge state from POST93 data files.
!Available data files:
! [should match impurity types in subr. set_gscreen_hesslow]
! imp_type: 1->He,2->Be,3->C,4->N,5->Ne,6->Ar,7->Xe,8-W
! Oxygen.ntau, (--- imp_type not set)
! Argon.ntau (corr to imp_type=6),
! Beryllium.ntau (corr to imp_type=2),
! Carbon.ntau (corr to imp_type=3),
! Iron.ntau, (--- imp_type not set)
! Neon.ntau (corr to imp_type=5),
! Nitrogen.ntau (corr to imp_type=4)
! Comments from such data files:
! ADPAK data by Russell Hulse and Doug Post
! Rates as a function of electron temperature, neutral fraction
! and residence time. May 6, 1993 further revisions will be done.
! radiation rates, watts cm^3, and <Z> for electron density =2.0E+14/cm^3
! Columns with data:
! Te (eV), n0/ne, ntau(s cm^-3), Prad(watts cm^3), <Z>, <Z^2>
! where n0 is neutral Deuterium density (we also refer to it as nD0).
! First three columns make up a 3D grid
! over which the values of Prad,<Z>,<Z^2> are set.
! YuP: Observed that each of those grids is uniform in log10 scale.
! We will use this fact to quickly determine the nearest 3D node
! {jt,jr,jn) in the 3D grid {log10(Te); log10(n0/ne); log10(ntau)}
! for a given input point
! {log10(temp_Te), log10(dens_nD0/dens_ne), log10(dens_ne*tau_r)}
! INPUT: kopt=0 Reading data file and setting arrays (for the six columns)
! kopt=1 Determine values of <Z> and <Z^2> for given {Te,nD0,ne,tau}
! imp_type= impurity type (see above)
! temp_Te= T_e [keV] Electron temperature
! dens_nD0= n_D0 [cm^-3] Density of neutral D
! dens_ne= n_e [cm^-3] Density of electrons
! tau_r= tau [sec] Characteristic time of radial decay of T_e
! Note from A. Pigarov:
! For disruption case, I would set tau(r)=1.e-3 sec.
! For Smith-like run case tau(r)=TauT,
! where TauT is the temperature decay time.
! For quasi-stationary plasma it is likely about
! plasma confinement time ~1 s.
! OUTPUT:
! z1av= <Z> Average charge state (a value between 0 and atomic number)
! z2av= <Z^2> Average of Z^2 for given impurity
! The data tables are based on Corona equilibrium.
implicit none
CMPIINSERT_INCLUDE
integer kopt ! input: 0 for setup, 1 for getting <Z> and <Z^2>
integer imp_type ! input: Impurity type
real*8 temp_Te,dens_nD0,dens_ne,tau_r !INPUT (when kopt=1) [keV,cm^3,sec]
real*8 z1av,z2av ! OUTPUT (when kopt=1)
character*64 fname ! local: file with data
integer atn, atw ! local (just for printout)
real*8 dlog10_Te, dlog10_nD0ne, dlog10_netau !local
real*8 wtl,wtu, wrl,wru, wnl,wnu ! local
real*8 fmmm,f0mm, fm0m,f00m, fmm0,f0m0, fm00,f000 ! local
integer nt, nr, nn ! local, obtained from data file
integer jt, jr, jn, jt1, jr1, jn1, jt2, jr2, jn2 ! local
integer ios,istat,nget ! local
real*8 accur ! local, accuracy
real*8 dens_tau != dens_ne*tau_r ! local usage
real*8 r_nD0_ne != dens_nD0/dens_ne ! local usage
! To be filled up with data from file and saved into memory:
real*8, dimension(:,:,:), allocatable :: tdatm, rdatm, ndatm
real*8, dimension(:,:,:), allocatable :: emdatm, z1datm, z2datm
save tdatm, rdatm, ndatm
save emdatm, z1datm, z2datm
save nt, nr, nn
real*8 Te_min,Te_max, rn0ne_min,rn0ne_max, taun_min,taun_max
save Te_min,Te_max, rn0ne_min,rn0ne_max, taun_min,taun_max
real*8 dlog10_Te_min, dlog10_Te_max, delta_log10_Te
real*8 dlog10_n0ne_min, dlog10_n0ne_max, delta_log10_n0ne
real*8 dlog10_ntau_min, dlog10_ntau_max, delta_log10_ntau
save dlog10_Te_min, dlog10_Te_max, delta_log10_Te
save dlog10_n0ne_min, dlog10_n0ne_max, delta_log10_n0ne
save dlog10_ntau_min, dlog10_ntau_max, delta_log10_ntau
data nget /55/ ! I/O unit for accessing/reading the file
if(kopt.eq.0)then ! Setup arrays, read data into arrays
!------------- kopt=0 ----------------------------
! Selection of file name corresponding to our imp_type
if(imp_type.eq.1)then
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)'set_get_ADPAK: missing data file Helium.ntau'
CMPIINSERT_ENDIF_RANK
STOP
endif
if(imp_type.eq.7)then
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)'set_get_ADPAK: missing data file Xeon.ntau'
CMPIINSERT_ENDIF_RANK
STOP
endif
!These are available:
if(imp_type.eq.2)then
fname='./ADPAK_data/Beryllium.ntau'
endif
if(imp_type.eq.3)then
fname='./ADPAK_data/Carbon.ntau'
endif
if(imp_type.eq.4)then
fname='./ADPAK_data/Nitrogen.ntau'
endif
if(imp_type.eq.5)then
fname='./ADPAK_data/Neon.ntau'
endif
if(imp_type.eq.6)then
fname='./ADPAK_data/Argon.ntau'
endif
!Open this file:
open(unit=nget,file=fname,form='formatted',iostat=ios,
& status='old')
if (ios.ne.0) then
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*) "--- data file ADPAK_data/*.ntau not found ---"
WRITE(*,*) 'In set_get_ADPAK: fname=', fname
CMPIINSERT_ENDIF_RANK
STOP 'In set_get_ADPAK: data file not found'
endif
! read array dimensions
read(nget,9000) !First 4 lines in *.ntau file are just a comment
read(nget,9000)
read(nget,9000)
read(nget,9000)
! Next 4 lines contain (example for Argon.ntau):
! 18 atomic number (atn) [YuP: specified as integer in the file]
! 36 atomic weight (atw) [YuP: Should be 40?] [as integer, also]
! 41 =nt= number of temperature intervals [eV]
! 22 =nr= number of D_neutral_density/electron_density intervals
! 22 =nn= number of ntau intervals (n_e*tau_decay phys.quantity)
! Read actual values:
read(nget,9001) atn, atw, nt, nr, nn !
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)'In set_get_ADPAK: atn, atw, nt, nr, nn',
& atn, atw, nt, nr, nn
CMPIINSERT_ENDIF_RANK
!Note: atn and atw are not used in this subroutine.
!allocate storage for arrays
if (.NOT. ALLOCATED(tdatm)) then
allocate(tdatm(1:nt,1:nr,1:nn),STAT=istat)
allocate(rdatm(1:nt,1:nr,1:nn),STAT=istat)
allocate(ndatm(1:nt,1:nr,1:nn),STAT=istat)
allocate(emdatm(1:nt,1:nr,1:nn),STAT=istat)
allocate(z1datm(1:nt,1:nr,1:nn),STAT=istat)
allocate(z2datm(1:nt,1:nr,1:nn),STAT=istat)
else ! already allocated (should not happen)
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)'In set_get_ADPAK: Attempt to allocate arrays'
WRITE(*,*)'In set_get_ADPAK: which are already allocated'
CMPIINSERT_ENDIF_RANK
STOP 'In set_get_ADPAK: allocation problem'
endif
! read data arrays
do jn=1,nn
do jr=1,nr
do jt=1,nt
read(nget,9010) tdatm(jt,jr,jn), rdatm(jt,jr,jn),
& ndatm(jt,jr,jn), emdatm(jt,jr,jn),
& z1datm(jt,jr,jn), z2datm(jt,jr,jn)
enddo
enddo
enddo ! jn
! The data contains six columns:
! Te (eV), n0/ne, ntau(s cm^-3), Prad(watts cm^3), <Z>, <Z^2>
! where n0 is neutral Deuterium density (==nD0).
close(nget) ! Close data file
9000 format()
9001 format(5(1x,i2/))
9010 format(6(1x,e12.5))
! Convert Te to keV:
tdatm=tdatm*1.d-3 ! keV now (CQL3D uses keV; see temp() array)
! Setup uniform 1D grids in log10 scale
! Te grid
Te_min=tdatm(1, 1, 1) ! MIN value in the table
Te_max=tdatm(nt,1, 1) ! MAX value in the table
dlog10_Te_min= log10(Te_min)
dlog10_Te_max= log10(Te_max)
delta_log10_Te= (dlog10_Te_max-dlog10_Te_min)/(nt-1) ! [keV]
! n0/ne grid
rn0ne_min=rdatm(1, 1, 1) ! MIN value in the table
rn0ne_max=rdatm(1,nr, 1) ! MAX value in the table
dlog10_n0ne_min= log10(rn0ne_min)
dlog10_n0ne_max= log10(rn0ne_max)
delta_log10_n0ne= (dlog10_n0ne_max-dlog10_n0ne_min)/(nr-1) ! [-]
! ne*tau grid
taun_min=ndatm(1, 1, 1) ! MIN value in the table
taun_max=ndatm(1, 1,nn) ! MAX value in the table
dlog10_ntau_min= log10(taun_min)
dlog10_ntau_max= log10(taun_max)
delta_log10_ntau= (dlog10_ntau_max-dlog10_ntau_min)/(nn-1) ![sec/cm^3]
!Just to check:
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)'In set_get_ADPAK: MIN/MAX of tdatm [keV]:',
& MINVAL(tdatm), MAXVAL(tdatm)
WRITE(*,*)'In set_get_ADPAK: MIN/MAX of rdatm [n0/ne]:',
& MINVAL(rdatm), MAXVAL(rdatm)
WRITE(*,*)'In set_get_ADPAK: MIN/MAX of ndatm [ne*tau, sec/cm3]:',
& MINVAL(ndatm), MAXVAL(ndatm)
WRITE(*,*)'In set_get_ADPAK: MIN/MAX of z1datm:',
& MINVAL(z1datm), MAXVAL(z1datm)
CMPIINSERT_ENDIF_RANK
else ! kopt>0
!------------------------- kopt>0 ----------------------------
! For a given Te(r,t), nD0(r,t), ne(r,t), tau(r)
! [temp_Te, dens_nD0, dens_ne, tau_r in argument list]
! find the nearest point
! in the table {tdatm, rdatm, ndatm}, and then find
! corresponding values of <Z> and <Z^2>
! [z1av and z2av in argument list]
! Using uniform grids in {log10(Te); log10(n0/ne); log10(ntau)}
dens_tau= dens_ne*tau_r ! Only This combination is used below
r_nD0_ne= dens_nD0/dens_ne ! Only This combination is used below
dlog10_Te= log10(temp_Te) !Our input value
! If temp_Te is below lowest value in the table, use the lowest value:
if(dlog10_Te.lt.dlog10_Te_min)then
dlog10_Te= dlog10_Te_min
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)
& 'set_get_ADPAK/WARNING: input value temp_Te<MIN(tdatm) in table'
CMPIINSERT_ENDIF_RANK
endif
! If temp_Te is above largest value in the table, use the largest value:
if(dlog10_Te.gt.dlog10_Te_max)then
dlog10_Te= dlog10_Te_max
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)
& 'set_get_ADPAK/WARNING: input value temp_Te>MAX(tdatm) in table'
CMPIINSERT_ENDIF_RANK
endif
jt1= INT( (dlog10_Te-dlog10_Te_min)/delta_log10_Te ) +1
jt1=max(1,jt1) !Not lower than 1
jt1=min(jt1,nt) !Not exceeding nt
jt2=jt1+1
jt2=min(jt2,nt) !Not exceeding nt
! temp_Te is between tdatm(jt1,*,*) and tdatm(jt2,*,*)
wtu= (dlog10_Te-dlog10_Te_min)/delta_log10_Te -(jt1-1) !upper
wtl= 1.d0-wtu ! lower weight factor, for interpolation
!----------
if(r_nD0_ne.ge.rn0ne_min) then
dlog10_nD0ne= log10(r_nD0_ne)
else ! r_nD0_ne can be 0., or very small
dlog10_nD0ne= dlog10_n0ne_min !Set to lowest value in the table
! If nD0/ne is lower than lowest value in table, use lowest value:
! WRITE(*,*)
! &'set_get_ADPAK/WARNING: input dens_nD0/dens_ne < lowest in table'
! In ADPAK tables, the values of nD0/ne are in the range 1e-7...1.0,
! and the results (<Z> values) are almost same at small
! values of nD0/ne. In other words, when nD0~0,
! we simply use the lowest values of nD0/ne that are available.
! No need to print the message above: nD0=0 may happen frequently.
endif
! If nD0/ne is above largest value in the table, use the largest value:
if(dlog10_nD0ne.gt.dlog10_n0ne_max)then
dlog10_nD0ne= dlog10_n0ne_max
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)
&'set_get_ADPAK/WARNING: input dens_nD0/dens_ne > largest in table'
CMPIINSERT_ENDIF_RANK
endif
jr1= INT((dlog10_nD0ne-dlog10_n0ne_min)/delta_log10_n0ne) +1
jr1=max(1,jr1) !Not lower than 1
jr1=min(jr1,nr) !Not exceeding nr
jr2=jr1+1
jr2=min(jr2,nr) !Not exceeding nr
! dens_nD0/dens_ne is between rdatm(*,jr1,*) and rdatm(*,jr2,*)
wru= (dlog10_nD0ne-dlog10_n0ne_min)/delta_log10_n0ne -(jr1-1) !upper
wrl= 1.d0-wru ! lower weight factor
!----------
dlog10_netau= log10(dens_tau)
! If ne*tau_r is lower than lowest value in table, use lowest value:
if(dlog10_netau.lt.dlog10_ntau_min)then
dlog10_netau= dlog10_ntau_min
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)
&'set_get_ADPAK/WARNING: input dens_ne*tau_r < lowest in table'
CMPIINSERT_ENDIF_RANK
endif
! If ne*tau_r is above largest value in the table, use the largest value:
if(dlog10_netau.gt.dlog10_ntau_max)then
dlog10_netau= dlog10_ntau_max
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)
&'set_get_ADPAK/WARNING: input dens_ne*tau_r > largest in table'
CMPIINSERT_ENDIF_RANK
endif
jn1= INT((dlog10_netau-dlog10_ntau_min)/delta_log10_ntau) +1
jn1=max(1,jn1) !Not lower than 1
jn1=min(jn1,nn) !Not exceeding nn
jn2=jn1+1
jn2=min(jn2,nn) !Not exceeding nn
! dens_ne*tau_r is between ndatm(*,*,jn1) and ndatm(*,*,jn2)
wnu= (dlog10_netau-dlog10_ntau_min)/delta_log10_ntau -(jn1-1) !upper
wnl= 1.d0-wnu ! lower weight factor, for interpolation
!Verify that the input point is indeed between corresponding
! grid points jt1 and jt2,
! and print a warning message if not compliant.
!This verification is simply a safeguard against case when
! the Te grid in the data file is not uniform in log10 scale.
!A minor problem in such verification is that the indexes jt1 and jt2
! are found in log10 scale (see above), but the verification below
! is done in original scale. Because of numerical accuracy,
! the temp_Te point can be within [log10(); log10()] range
! corresponding to [jt1;jt2] cell, but it can slightly outside
! of such range in the original scale. So, we allow the point
! to be slightly outside of the range by setting an accur value:
accur= 1.d-3*temp_Te ! Accuracy (the point could be slightly outside
! of range just because of accuracy. Allow this - don't stop).
!Perform such verification only when temp_Te is
! within [MIN;MAX] range of the data table (grid range).
! If it is outside of the table range, use the 1st or last point
! in the table for evaluating the output values.
if(temp_Te.ge.Te_min .and. temp_Te.le.Te_max)then
! It may happen that temp_Te is smaller than the lowest value
! of Te in the table (in tdatm), or larger than the largest value.
! However, let's allow such cases. In this case, when temp_Te>MAX(tdatm),
! we use jt1=nt and jt2=nt, i.e. we take the last point in the table
! to determine <Z> and <Z^2>. Similarly - when temp_Te<MIN(tdatm).
! So, don't stop the run, just print a warning message (done above).
! In the rest of cases ( Te_min<temp_Te<Te_max ) check that
! the temp_Te point is really within the proper grid cell [jt1,jt2].
! If not, stop the run:
if( (temp_Te-tdatm(jt1,jr1,jn1).lt.-accur) .or.
& (temp_Te-tdatm(jt2,jr2,jn2).gt. accur) ) then
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)
& 'set_get_ADPAK/WARNING: temp_Te[keV],tdatm(jt1),tdatm(jt2)',
& temp_Te,tdatm(jt1,jr1,jn1),tdatm(jt2,jr2,jn2), jt1,jt2
CMPIINSERT_ENDIF_RANK
STOP 'temp_Te is outside of [jt1;jt2] cell'
endif
endif
! Similar check for nD0/ne value
accur= 1.d-3*r_nD0_ne ! Accuracy
if(r_nD0_ne.ge.rn0ne_min .and.
& r_nD0_ne.le.rn0ne_max )then
if( (r_nD0_ne-rdatm(jt1,jr1,jn1).lt.-accur) .or.
& (r_nD0_ne-rdatm(jt2,jr2,jn2).gt. accur) ) then
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)
& 'set_get_ADPAK/WARNING: dens_nD0/dens_ne,rdatm(jr1),rdatm(jr2)',
& r_nD0_ne,rdatm(jt1,jr1,jn1),rdatm(jt2,jr2,jn2), jr1,jr2
CMPIINSERT_ENDIF_RANK
STOP 'dens_nD0/dens_ne is outside of [jr1;jr2] cell'
endif
endif
! Similar check for ne*tau value
accur= 1.d-3*dens_tau ! Accuracy
if(dens_tau.ge.taun_min .and.
& dens_tau.le.taun_max )then
if( (dens_tau-ndatm(jt1,jr1,jn1).lt.-accur) .or.
& (dens_tau-ndatm(jt2,jr2,jn2).gt. accur) ) then
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,'(a,3e15.8,3i6)')
& 'set_get_ADPAK/WARNING: dens_tau,ndatm(jn1),ndatm(jn2)',
& dens_tau,ndatm(jt1,jr1,jn1),ndatm(jt2,jr2,jn2), jn1,jn2
CMPIINSERT_ENDIF_RANK
STOP 'dens_tau is outside of [jn1;jn2] cell'
endif
endif
!Make linear interpolation over each axis in 3D
! For <Z>
fmmm= z1datm(jt1,jr1,jn1)
f0mm= z1datm(jt2,jr1,jn1)
fm0m= z1datm(jt1,jr2,jn1)
f00m= z1datm(jt2,jr2,jn1)
fmm0= z1datm(jt1,jr1,jn2)
f0m0= z1datm(jt2,jr1,jn2)
fm00= z1datm(jt1,jr2,jn2)
f000= z1datm(jt2,jr2,jn2)
z1av= wnl*
& ( wtl*wrl*(fmmm)
& +wtu*wrl*(f0mm)
& +wtl*wru*(fm0m)
& +wtu*wru*(f00m) )
& +wnu*
& ( wtl*wrl*(fmm0)
& +wtu*wrl*(f0m0)
& +wtl*wru*(fm00)
& +wtu*wru*(f000) )
! And now for <Z^2>
fmmm= z2datm(jt1,jr1,jn1)
f0mm= z2datm(jt2,jr1,jn1)
fm0m= z2datm(jt1,jr2,jn1)
f00m= z2datm(jt2,jr2,jn1)
fmm0= z2datm(jt1,jr1,jn2)
f0m0= z2datm(jt2,jr1,jn2)
fm00= z2datm(jt1,jr2,jn2)
f000= z2datm(jt2,jr2,jn2)
z2av= wnl*
& ( wtl*wrl*(fmmm)
& +wtu*wrl*(f0mm)
& +wtl*wru*(fm0m)
& +wtu*wru*(f00m) )
& +wnu*
& ( wtl*wrl*(fmm0)
& +wtu*wrl*(f0m0)
& +wtl*wru*(fm00)
& +wtu*wru*(f000) )
!Could add similarly for Prad (emdatm); maybe later; not used presently.
!Could use a better interpolation scheme, but probably it is not important.
endif ! kopt
return
end subroutine set_get_ADPAK
!=======================================================================
!=======================================================================
subroutine get_distr_charge_states(Zatom,z1av,z2av, fz)
! INPUT: Zatom,z1av,z2av OUTPUT: fz(0:Zatom)
!YuP[2019-08-15]-[2019-08-20]
!To be used immediately after call to sub.set_get_ADPAK(kopt=1,...)
implicit none
CMPIINSERT_INCLUDE
integer Zatom ! INPUT: Atomic charge number
real*8 z1av,z2av !INPUT: <Z>,<Z^2> -- average charge and charge^2
real*8 fz(0:Zatom) !OUTPUT : Distribution over charge states
!with properties SUM(fz(z))=1,
! and also SUM(fz(z)*z)=<Z> [with some accuracy]
integer iz ! local: index over charge states
real*8 cn ! local: normalization constant
real*8 wl,wu ! local: weight factors for lin.interpolation
real*8 sum_fz_Z1, sum_fz_Z2 ! local, for printout
!is=0 ! array index counter, to be incremented in loop
! Form fz(z,<z>) as a function of z (parametrically dep. on z1av==<z>)
! Loop over iz=0:Zatom ! Array of charge states
do iz=0,Zatom ! Neutral and Ionized states are included here
!is=is+1
if (iz<=z1av-3) then
fz(iz)= 0.1d0* 3**(iz-(z1av-3)) !--> 0.1 at iz=z1av-3
elseif (iz<z1av-2) then ! z1av-3 < iz < z1av-2
! Interpolate between two nearest nodes:
wl= (z1av-2) - iz ! weight factor for left (lower) node
wu= iz - (z1av-3) ! weight factor for upper node
fz(iz)= 0.1d0*wl + 0.2d0*wu
elseif (iz<z1av-1) then ! z1av-2 < iz < z1av-1
wl= (z1av-1) - iz ! weight factor for left (lower) node
wu= iz - (z1av-2) ! weight factor for upper node
fz(iz)= 0.2d0*wl + 0.5d0*wu
elseif (iz<z1av) then ! z1av-1 < iz < z1av
wl= (z1av-0) - iz ! weight factor for left (lower) node
wu= iz - (z1av-1) ! weight factor for upper node
fz(iz)= 0.5d0*wl + 1.0d0*wu
! elseif (iz==z1av) then ! iz=z1av
! fz(iz)= 1.d0
elseif (iz<z1av+1) then ! z1av < iz < z1av+1
wl= (z1av+1) - iz ! weight factor for left (lower) node
wu= iz - (z1av+0) ! weight factor for upper node
fz(iz)= 1.0d0*wl + 0.5d0*wu
elseif (iz<z1av+2) then ! z1av+1 < iz < z1av+2
wl= (z1av+2) - iz ! weight factor for left (lower) node
wu= iz - (z1av+1) ! weight factor for upper node
fz(iz)= 0.5d0*wl + 0.2d0*wu
elseif (iz<z1av+3) then ! z1av+2 < iz < z1av+3
wl= (z1av+3) - iz ! weight factor for left (lower) node
wu= iz - (z1av+2) ! weight factor for upper node
fz(iz)= 0.2d0*wl + 0.1d0*wu
elseif (iz>=z1av+3)then
fz(iz)= 0.1d0* 3**(-(iz-z1av-3)) !--> 0.1 at iz=z1av+3
else
CMPIINSERT_IF_RANK_EQ_0
WRITE(*,*)'get_distr_charge_states: Invalid iz. Stopping'
CMPIINSERT_ENDIF_RANK
STOP
endif
enddo ! iz
cn= 1.d0/SUM(fz(0:Zatom)) ! normalization factor for fz().
fz(:)= cn*fz(:) !Distribution over charge states, as a func. of Z
! So now we have fz(z,<z>), such that sum(fz)=1.0 ;
! The problem is that we need to satisfy
! sum(fz*z) = z1av (= <Z>)
! and also
! sum(fz*z*z) = z2av (= <Z^2>)
! This is not guaranteed by the present crude model,
! but the tests show that it is close.
! ! For printout/verification:
! sum_fz_Z1=0.d0
! sum_fz_Z2=0.d0
! do iz=0,Zatom
! write(*,*) iz,fz(iz)
! sum_fz_Z1= sum_fz_Z1 +fz(iz)*iz
! sum_fz_Z2= sum_fz_Z2 +fz(iz)*iz*iz
! enddo
! write(*,*)'% Above: z, fz(z) over all charge states z'
! write(*,*)'% z1av,z2av=',z1av,z2av
! write(*,*)'% sum(fz*z)=', sum_fz_Z1
! write(*,*)'% sum(fz*z^2)=', sum_fz_Z2
return
end subroutine get_distr_charge_states
!=======================================================================
!=======================================================================
subroutine get_dens_nD0_ADPAK(model_dens_nD0,dens_nD0_b,dens_nD0_l
& ,rho, radmin,
& dens_nD0)
! INPUT: model_dens_nD0,dens_nD0_b,dens_nD0_l, rho,radmin
! OUTPUT: dens_nD0
! Units: 1/cm^3, cm
!YuP[2019-09-11]
!To be used before call to sub. set_get_ADPAK(kopt=1,...)
!This subr. calculates neutral density of D0,
! needed as an input for ADPAK tables,
! where it enters through the ratio nD0/ne.
! In ADPAK tables, the values of nD0/ne are in the range 1e-7...1.0,
! and the results (<Z> values) are almost same at small
! values of nD0/ne. In other words, when nD0~0,
! we simply use the lowest values of nD0/ne that are available.
implicit none
CMPIINSERT_INCLUDE
integer model_dens_nD0 ! Only one model so far for neutral D0.
real*8 dens_nD0_b ! 1/cm^3 ! Edge density of neutral D0
real*8 dens_nD0_l !cm! Scale length, in dens_nD0_b*exp[(rho-1)*radmin/dens_nD0_l]
real*8 rho ! normalized to [0;1] range
real*8 radmin ! cm
real*8 dens_nD0
SELECT CASE (model_dens_nD0)
CASE(1) !
dens_nD0= dens_nD0_b*exp((rho-1.d0)*radmin/dens_nD0_l)
! Could become very small~0 at small rho
CASE DEFAULT
dens_nD0=0.d0 ! just zero density of D0
END SELECT
! Other (future) models: make it as a func. of time?
return
end subroutine get_dens_nD0_ADPAK
!=======================================================================
!=======================================================================
subroutine set_get_pellet(kopt, timet,
& lrz, Raxis, rpcon, rmcon, dvol, Te, ne,
& pellet_V, pellet_M0, pellet_Rstart, pellet_tstart,
& pellet_rcloud1, pellet_rcloud2, pellet_rp0,
& pellet_pn, pellet_pt, pellet_pm,
& ipellet_method, pellet_fract_rem,
& ipellet_iter_max, pellet_iter_accur, pellet_Cablation,
& Gablation,dMpellet_sum,dMdv_sum)
!YuP[2019-09-15]
implicit none
CMPIINSERT_INCLUDE
integer kopt !INPUT: kopt=0 for setup; kopt=1 for pellet propagation
real*8 timet ! sec ! INPUT: physical time since start of simulation
real*8 Raxis ! cm ! INPUT
integer lrz !INPUT: size of grids below
real*8 rpcon(lrz),rmcon(lrz),dvol(lrz),Te(lrz),ne(lrz) !cm,cm^3,keV !INPUT
integer ipellet_method, ipellet_iter_max !INPUT, set in namelist
!INPUT scalars, set in namelist:
real*8 pellet_V, pellet_M0, pellet_Rstart, pellet_tstart,
& pellet_rcloud1, pellet_rcloud2, pellet_rp0,
& pellet_pn, pellet_pt, pellet_pm,
& pellet_fract_rem,
& pellet_iter_accur, pellet_Cablation
!(pellet_Cablation can also be OUTPUT, if ipellet_method=1)
integer irold,irnew ! local: range of radial indexes
real*8 Rold,Rnew !local: position of pellet at last and present step
real*8 dr ! local: distance in R travelled by pellet since last step
!OUTPUT (when kopt=1): array for storing dM/dvol mass density
! as a func. of flux surface index.
! It is recalculated each time when this subr. is called (with kopt=1)
real*8 dMdv_sum(lrz) !gram/cm^3! To be saved into dMpellet_dvol_sum()
!To calculate particle density, use convert= Avogadro/atw
! where atw is the atomic weight (40 g/mol for Argon)
!OUTPUT (when kopt=1):
real*8 dMpellet_sum ! accumulated from one call to another
! dMpellet_sum ! Total ablated material [gram], scalar.
! The remaining mass of pellet is Mpellet_rem= pellet_M0-dMpellet_sum
real*8 Gablation !ablation rate along pellet trajectory (for plots)