forked from GAmfe/genray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemission.f
5444 lines (4582 loc) · 180 KB
/
emission.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
subroutine emiss_coef(aK,fluctcur,ce,flux,v_group,omega,nr,
+iabsorp_collisional,coll_mult,tempe,dense,zeff,
+al_emis,j_emis)
c al_emis (1/cm)
c j_emis (erg*sec/cm**3)
c
c-----calculates the emission coefficient j_emis(erg*sec/cm**3)
c and absorption al_emis (1/cm)
c
c see the article
c R.W.Harvey at al., Phys.Fluids B 5(2),Febrary 1993, page 446
c j_emis is the power radiated by the plasma
c per unit volume-radian frequency-steradian,
c
c formula (3)
c j_emis=pi*Nr**2(omega/clight)**2*vectorE^*tensorG*vectorE/S
c
c vector S(omega,k) is the flux energy density per frequency and
c per unit volume of k space,
c
c formula(4)
c S=vectorVgroup*U
c
c vectorVgroup is the wave group velocity
c
c U is the spectral energy density
c
c formula (5)
c U=1/(8*pi)(vectorB^*vectorB+
c +vectorE^*d(omega*eps_hermitian)/domega*vectorE)
c
c al_emis is absorption coefficient, the inverse damping length
c along the ray of rf wave energy
c
c formula (2)
c al_emis=(omega/(4*pi))vectorE^*eps_anti-herm*vectorE/abs(S)
c
c G is the correlation tensor formula(7)
c
c if iabsorp_collisional=1 it will add the collisional absorption
c al_emis_collisional=nu_ei/(Vgroup) (1/cm)
c in the absorption coeficient
c nu_ei is the electron-ion collision frequency
c coll_mult = multiplier for coll absorption expression (default=1.0)
c------------------------------------------------------------------
implicit none
c-----input
double complex aK(3,3) ! anti-hermitian relativistic tensor
double complex fluctcur(3,3)! correltion tensor G for the fluctuating current(erg)
double complex ce(3) ! wave (normalized) electric field in Stix frame
c wave energy flux for the normalized field |E|=1
c flux=(vectorB*vector_B^*+vector_E*d(omega*tensor_eps_herm)/dw*vector_E)
double complex flux ! wave energy flux for the normalized field |E|=1
double precision omega ! wave angle frequency (1/sec) =2*pi*f
double precision v_group ! wave group velocity [cm/sec]
double precision nr ! ray refructive index
integer iabsorp_collisional ! =0 do not calculate collisional absorption
! =1 to calculte collisonal absorption
double precision coll_mult ! multiplier for coll absorption
double precision tempe, !electron temperature (keV)
& dense, !electron density (10*13/cm**3
& zeff !plasma charge
c-----output
double precision al_emis !(1/sm)
double precision j_emis !(erg*sec/sm**3)
c-----local
double complex cec(3),cal_emis,cj_emis
integer i,j
double precision s,pi,clight,absflux,p
double precision arg,cln,r_nu_ei,al_emis_collisional
pi=4*datan(1.d0)
clight=2.99792458d10 !cm/sec
c--------------------------------------------------------------
c ce - wave electric field
c cec- comlex conjugate wave electric field
c----------------------------------------------------------
do i=1,3
cec(i)=dconjg(ce(i))
enddo
p=flux*dconjg(flux)
absflux=dsqrt(p)
c write(*,*)'emiss_coeff flux,absflux',flux,absflux
c s is the energy flux density per frequency and per unit volume in k space
s=dabs(v_group*absflux/(8.d0*pi))
s=s*4.d0*pi
c write(*,*)'emiss_coeff v_group,absflux,s',v_group,absflux,s
cal_emis=dcmplx(0.0d00,0.0d00)
cj_emis=dcmplx(0.0d00,0.0d00)
c write(*,*)'emiss_coef aK(i,j)',aK(1,1),aK(1,2),aK(1,3)
c write(*,*)aK(2,1),aK(2,2),aK(2,3)
c write(*,*)aK(3,1),aK(3,2),aK(3,3)
c write(*,*)'emiss_coef fluctcur',fluctcur(1,1)*omega,
c +fluctcur(1,2)*omega,fluctcur(1,3)*omega
c write(*,*)fluctcur(2,1)*omega,
c +fluctcur(2,2)*omega,fluctcur(2,3)*omega
c write(*,*)fluctcur(3,1)*omega,
c +fluctcur(3,2)*omega,fluctcur(3,3)*omega
c write(*,*)'emiss_coef ce',ce
do i=1,3
do j=1,3
cal_emis=cal_emis+cec(i)*aK(i,j)*ce(j)
cj_emis =cj_emis +cec(i)*fluctcur(i,j)*ce(j)
c write(*,*)'emiss_coef i,j',i,j
c write(*,*)'cec(i),ce(j),aK(i,j)',cec(i),ce(j),aK(i,j)
c write(*,*)'cec(i)*aK(i,j)*ce(j)',cec(i)*aK(i,j)*ce(j)
c write(*,*)'fluctcur(i,j)',fluctcur(i,j)
c write(*,*)'cj_emis',cj_emis
enddo
enddo
c write(*,*)'emiss_coef 0 cal_emis',cal_emis
c write(*,*)'emiss_coef 0 cj_emis',cj_emis
cal_emis=cal_emis*omega/(4.d0*pi)/s
cj_emis=cj_emis*pi*(nr*omega/clight)**2/s
c write(*,*)'omega,s,omega/(4.d0*pi)/s',omega,s,omega/(4.d0*pi)/s
c write(*,*)'nr,clight,pi*(nr*omega/clight)**2/s',
c +nr,clight,pi*(nr*omega/clight)**2/s
c write(*,*)'emiss_coef cal_emis',cal_emis
c write(*,*)'emiss_coef cj_emis',cj_emis
p=cal_emis*dconjg(cal_emis)
al_emis=dsqrt(p)
al_emis=al_emis*4.d0*pi
c write(*,*)'emiss_coeff cal_emis,al_emis',cal_emis,al_emis
p=cj_emis*dconjg(cj_emis)
j_emis=dsqrt(p)*omega
j_emis=j_emis*4.d0*pi
c write(*,*)'emiss_coeff nr,cj_emis,j_emis',nr,cj_emis,j_emis
if (iabsorp_collisional.eq.0) then
al_emis_collisional=0.d0
endif
if (iabsorp_collisional.eq.1) then
c-------------------------------------------------------------------------------------
c collisional absorption calculations
c-------------------------------------------------------------------------------------
c--------Coulomb Logarithm = cln
arg=(1.d3/tempe)*dsqrt(10.d0*dense) !tempe KeV,
!dense 10**13/sm**3
cln=24.d0-dlog(arg)
c--------electron-ion collision rate =r_nu_ei [1/sec]
r_nu_ei=dense/(tempe*dsqrt(tempe))*zeff*cln*0.919d3 ![1/sec]
al_emis_collisional=2.d0*r_nu_ei/(v_group)*coll_mult
endif
c write(*,*)'al_emis,al_emis_collisional',
c &al_emis,al_emis_collisional
c-----total absorption
al_emis= al_emis+al_emis_collisional
return
end
subroutine emis_tens(X,Y,T_kev,nll_in,np_in,
+n_relt_harm1,n_relt_harm2,n_relt_intgr,
+i_resonance_curve_integration_method,epsi,
+i_fkin,r,z,phi,
+aK,fluctcur)
c-----calulates the anti-hermitian relativistic dielectric tensor aK
c for electron plasma
c and the correlation tensor fluctcur=G for the fluctuating current density
c
c see the article
c R.W.Harvey at all Phys.Fluids B 5(2),Febrary 1993, page 446
c G is the correlation tensor formula(7)
c aK formula (6)
c
c INPUTS:
c
c X = (fpe/f)**2
c Y = fce/f
c T_kev - electron temperature
c nll_in - parallel index of refraction N.
c np_in - perpendicular refractive index N
c n_relt_harm1 - min number of used cyclotron jn harmonics,
c n_relt_harm2 - max number of used cyclotron jn harmonics,
c n_relt_harm1 <= jn <= n_relt_harm2
c n_relt_intgr - the number of points for the integration over p_perp
c i_fkin =0 the usage of the analytic relativistic distribution
c =1 the usage of the numerical 3D distribution from diskf or netcdfnm.nc
c written be CQL3D code or created analytically at mesh points
c r - the major radius (it is used for i_fkin=1)
c z - the vertical coordinate (it is used for i_fkin=1)
c phi - toroidal angle
c----------------------------------------------------------------------
c i_resonance_curve_interation_method
c
c i_resonance_curve_integration_method=1 angle integration
c now it works for ellipse case only c
c
c i_resonance_curve_integration_method=2 rectangle formula
c for p_perp integration
c
c i_resonance_curve_integration_method=3 trapezoidal formula
c for p_perp integration
c
c i_resonance_curve_integration_method=4 !adaptive Simpson
c for p_perp integration
c
c epsi is the accuracy used in integration by adaptive Simpson
c------------------------------------------------------------
c OUTPUT:
c aK(3,3): the nine components of the anti-hermition
c part dielectric relativistic tensor
c evaluated at (X,Y,Te,nll,np,n)
c
c fluctcur(3,3) the correlation tensor fluctcur=G (egr)
c for the fluctuating current density
c
implicit none
c input
double precision X,Y,T_kev,nll_in,np_in,epsi
integer n_relt_harm1,n_relt_harm2,n_relt_intgr,i_fkin,
&i_resonance_curve_integration_method
double precision r,z,phi
c output
double complex aK(3,3),fluctcur(3,3)
c local
double precision c,mass_e,k_1_kev,nll,np,nlls,p_perp0,theta,pi,
.dens,xpidens,xpidensmcs,p,psi,rho
double complex integral(3,3)
double complex fluctcur_n(3,3)
integer jn,ires,jn_negative
c external zeroK, npnllmin, ec_cond, intgr_rl,fdens_fdist
double precision fdens_fdist,fpsi,rhopsi,densrho
c =2.99792458d10 !speed of light (cm/sec)
mass_e=9.1094d-28 !electron rest mass (g)
k_1_kev=1.6022d-9 !egrs in 1 KeV (erg)
theta=mass_e*c**2/(k_1_kev*T_kev)
pi=4.d0*datan(1.d0)
call npnllmin(nll_in,np_in,nll,np)
nlls = nll**2
c-----initialization aK=0
call zeroK(aK)
call zeroK(fluctcur)
c-----the loop over the cyclotron harmonics
write(*,*)'emission.f in emis_tens'
do jn=n_relt_harm1,n_relt_harm2
jn_negative=-jn
c-------control the EC resonance condition
cSm060315
c call ec_cond(jn,Y,nll,ires,p_perp0)
call ec_cond(jn_negative,Y,nll,ires,p_perp0)
c write(*,*)'emission.f emis_tens jn,ires,p_perp0',jn,ires,p_perp0
if(ires.eq.0) then
c---------no resonace
goto 10
endif
cSm060315
c call intgr_emis(jn,nll,np,Y,theta,ires,p_perp0,n_relt_intgr,
call intgr_emis(jn_negative,nll,np,Y,theta,ires,p_perp0,
+ n_relt_intgr,i_resonance_curve_integration_method,epsi,
+ i_fkin,r,z,phi,
+ integral,fluctcur_n)
c write(*,*)'emis_tens after integr_emis integral',integral
c write(*,*)'emis_tens after integr_emis fluctcur_n',fluctcur_n
aK(1,1)=aK(1,1)+integral(1,1)
aK(1,2)=aK(1,2)+integral(1,2)
aK(1,3)=aK(1,3)+integral(1,3)
aK(2,2)=aK(2,2)+integral(2,2)
aK(2,3)=aK(2,3)+integral(2,3)
aK(3,3)=aK(3,3)+integral(3,3)
fluctcur(1,1)=fluctcur(1,1)+fluctcur_n(1,1)
fluctcur(1,2)=fluctcur(1,2)+fluctcur_n(1,2)
fluctcur(1,3)=fluctcur(1,3)+fluctcur_n(1,3)
fluctcur(2,2)=fluctcur(2,2)+fluctcur_n(2,2)
fluctcur(2,3)=fluctcur(2,3)+fluctcur_n(2,3)
fluctcur(3,3)=fluctcur(3,3)+fluctcur_n(3,3)
10 continue
enddo !jn
if (i_fkin.eq.0) then
dens=1.d0
else
c dens=fdens_fdist(r,z,phi)
cSm011228 call the density of the bulk plasma to reduce the CPU time
psi=fpsi(r,z)
rho=rhopsi(psi)
dens=densrho(rho,1)
c write(*,*)'emision_tens dens',dens
c dens=1.d0
endif
c-----normalization for the unit electron density
xpidens=X*pi/dens
aK(1,1)=-xpidens*aK(1,1)
aK(1,2)=-xpidens*aK(1,2)
aK(1,3)=-xpidens*aK(1,3)
aK(2,2)=-xpidens*aK(2,2)
aK(2,3)=-xpidens*aK(2,3)
aK(3,3)=-xpidens*aK(3,3)
c aK(2,1)=-aK(1,2)
c aK(3,1)= aK(1,3)
c aK(3,2)=-aK(2,3)
cSm060705
aK(2,1)=conjg(aK(1,2))
aK(3,1)=conjg(aK(1,3))
aK(3,2)=conjg(aK(2,3))
xpidensmcs=X*pi/(2.d0*pi)**5*(mass_e*c**2)/dens
fluctcur(1,1)=fluctcur(1,1)*xpidensmcs
fluctcur(1,2)=fluctcur(1,2)*xpidensmcs
fluctcur(1,3)=fluctcur(1,3)*xpidensmcs
fluctcur(2,2)=fluctcur(2,2)*xpidensmcs
fluctcur(2,3)=fluctcur(2,3)*xpidensmcs
fluctcur(3,3)=fluctcur(3,3)*xpidensmcs
fluctcur(2,1)=-fluctcur(1,2)
fluctcur(3,1)= fluctcur(1,3)
fluctcur(3,2)=-fluctcur(2,3)
return
end
subroutine intgr_emis(n,nll,np,Y,theta,ires,p_perp0,
+n_relt_intgr,i_resonance_curve_integration_method,epsi,
+i_fkin,r,z,phi,
+integral,fluctcur_n)
c-----------------------------------------------------------------
c calculates the matrix: double complex integrals
c for the relativistic electron plasma
c I(n)^=integral(0<=p_perp<=p_perp0)g_n, g_n={sum_k=1,2,G_nk(p_perp)
c fluctcar(n)^=integral(0<=p_perp<=p_perp0)g_fluctcur_n.
c g_fluctcur_n={sum_k=1,2,g_fluctcur_nk(p_perp)
c for the EC harmonic with number 'n'
c-----------------------------------------------------------------
c input
c n - EC harmonic number
c nll - N_parallel
c np - N_perpendicular
c Y = omega_ce/omega for the electron rest mass
c theta = mc**2/T
c ires =0 no resonance,=1 ellipse,=2 parabola,=3 hyperbole
c n_relt_intgr - the number of points for the integration over p_perp
c p_perp0 - max value of the perpendicular momentum divided by mc
c on the resonanse ellipse
c i_fkin =0 the usage of the analytic relativistic distribution
c =1 the usage of the numerical 3D distribution from diskf
c written be CQL3D code
c r - the major radius (it is used for i_fkin=1)
c z - the vertical coordinate (it is used for i_fkin=1)
c phi - toroidal angle (it is used for i_fkin=1)
c i_resonance_curve_interation_method
c
c i_resonance_curve_integration_method=1 angle integration
c now it works for ellipse case only c
c
c i_resonance_curve_integration_method=2 rectangle formula
c for p_perp integration
c
c i_resonance_curve_integration_method=3 trapezoidal formula
c for p_perp integration
c
c i_resonance_curve_integration_method=4 !adaptive Simpson
c for p_perp integration
c
c epsi is the accuracy used in integration by adaptive Simpson
c
c------------------------------------------------------------
c output
c integral(3,3) double complex integral from G_nk over 0<=p_perp=<p_perpmax
c fluctcur(3,3) double complec integral from fluct_cur_nk over 0<=p_perp=<p_perpmax
c----------------------------------------------------------------
c The integration method is specified by the variable
c i_resonance_curve_integration_method.
c Now this variable is set inside this subroutine.
c----------------------------------------------------------------
implicit none
c input
double precision nll,np,Y,theta,p_perp0,epsi
integer n,ires,n_relt_intgr,i_fkin,
&i_resonance_curve_integration_method
double precision r,z,phi
double precision vnormloc,massloc ! cm/sec, g
COMMON /dskin1/vnormloc,massloc
c output
double complex integral(3,3)
double complex fluctcur_n(3,3)
c local
cSm060725
double precision eps,p_permax,h,p_perp,p,p_t,clight,p_int,
c double precision eps,p_permax,h,p_perp,p,p_t,jmax,clight,p_int,
&vmax_d_vt
double complex i,g_n(3,3),g_fluctcur_n(3,3)
cSm060725
integer j,jmax
c-----for integration along ellipse by angle
double precision rme,rtem0,vper,xint,cs,sn,thet1,thet2,p_par,
& p_par_min,p_par_pl,p_perp_min,p_perp_pl,v0dc,vmax1dc,vpar0dc,
+vpar1dc,vpar2dc,dth,vt0,cdvt,tem0,dvper,vmaxdt
c external
c ec_cond, zeroK, g_n
double precision temperho
i = ( 0.0d0,1.0d0) !imaginary number
jmax=n_relt_intgr
cSm060310
if(ires.eq.0)goto10 ! no resonance
vmax_d_vt=10.d0
call p_perp_max_calc(i_fkin,theta,n,Y,nll,vmax_d_vt,
&vnormloc,p_permax,ires)
if(ires.eq.4) then
c--------the resonance curve is outside the grid
call zeroK(integral)
call zeroK(fluctcur_n)
goto 10
else
h=p_permax/(n_relt_intgr) ! step of integration over p_perp
endif
c calculations of the integrals over p_perp
call zeroK(integral)
call zeroK(fluctcur_n)
c----------------------------------------------------------
c i_resonance_curve_interation_method
c
c i_resonance_curve_interation_method=1 angle integration
c now it works for ellipse case only c
c i_resonance_curve_interation_method=2 rectangle formula
c for p_perp integraion
c
c i_resonance_curve_interation_method=3 trapezoidal formula
c for p_perp integraion
c
c i_resonance_curve_integration_method=4 !adaptive Simpson
c for p_perp integration
c------------------------------------------------------------
goto (1,2,3,4) i_resonance_curve_integration_method
1 continue
cSm060327
if(dabs(nll).ge.1.d0) goto 3 !to trapezoidal formula
c--------------------------------------------------------------------
c integration along the resonance curve using angle (thet)
c thet1<thet<thet2
c begin
c--------------------------------------------------------------------
clight=2.99792458d10
rme=9.1094d-28
call get_rtem0_from_one(rtem0)
tem0=temperho(0.d0,1)*rtem0
vt0=dsqrt(2.d0*tem0*1.6022d-9/rme) !(cm/sec)the central
!thermal velocity
cdvt=clight/vt0
vmaxdt=dsqrt(rtem0)
call ec_condh(n,Y,nll,vmaxdt/cdvt,ires,v0dc,vmax1dc,vpar0dc,
+vpar1dc,vpar2dc,thet1,thet2)
c write(8,*)'theta integration boundaries: thet1,thet2',
c thet1,thet2
c-----Subdivide theta range of integration
dth=(thet2-thet1)/(jmax-1)
do j=1,jmax
xint=thet1+(j-1)*dth
cs=dcos(xint)
sn=dsin(xint)
p_par=(vpar0dc-dabs(v0dc)*cs) !vper/Vt
p_perp=vmax1dc*sn !vpar/Vt
if(p_perp.lt.1.d-3) p_perp=1.d-3 !to avoid singularity
call g_n_emis_theta(p_perp,p_par,y,nll,np,theta,n,i_fkin,
& r,z,phi,g_n,g_fluctcur_n)
if((j.ne.jmax).and.(j.ne.1)) then
sn=dsin(xint+dth)
p_perp_pl=vmax1dc*sn !vper/c
sn=dsin(xint-dth)
p_perp_min=vmax1dc*sn
h=0.5d0*(dabs(p_perp_pl-p_perp)+dabs(p_perp-p_perp_min))
else
if(j.eq.1) then
sn=dsin(xint+dth)
p_perp_pl=vmax1dc*sn !vper/c
h=0.5d0*dabs(p_perp_pl-p_perp)
else
!j=jmax
sn=dsin(xint-dth)
p_perp_min=vmax1dc*sn !vper/c
h=0.5d0*dabs(p_perp-p_perp_min)
endif
endif
integral(1,1)=integral(1,1)+h*g_n(1,1)
integral(1,2)=integral(1,2)+h*g_n(1,2)
integral(1,3)=integral(1,3)+h*g_n(1,3)
integral(2,2)=integral(2,2)+h*g_n(2,2)
integral(2,3)=integral(2,3)+h*g_n(2,3)
integral(3,3)=integral(3,3)+h*g_n(3,3)
fluctcur_n(1,1)=fluctcur_n(1,1)+h*g_fluctcur_n(1,1)
fluctcur_n(1,2)=fluctcur_n(1,2)+h*g_fluctcur_n(1,2)
fluctcur_n(1,3)=fluctcur_n(1,3)+h*g_fluctcur_n(1,3)
fluctcur_n(2,2)=fluctcur_n(2,2)+h*g_fluctcur_n(2,2)
fluctcur_n(2,3)=fluctcur_n(2,3)+h*g_fluctcur_n(2,3)
fluctcur_n(3,3)=fluctcur_n(3,3)+h*g_fluctcur_n(3,3)
enddo
goto 20
c--------------------------------------------------------------------
c integration along the resonance curve using angle (thet)
c thet1<thet<thet2
c end
c--------------------------------------------------------------------
2 continue
c --------------------------------------------------------------------
c integration along the resonance curve using rectangle
c formula
c begin
c--------------------------------------------------------------------
cSm060306
do j=1,jmax
p_perp=h*(j-0.5)
call g_n_emis(p_perp,y,nll,np,theta,n,i_fkin,r,z,phi,
. g_n,g_fluctcur_n)
integral(1,1)=integral(1,1)+g_n(1,1)
integral(1,2)=integral(1,2)+g_n(1,2)
integral(1,3)=integral(1,3)+g_n(1,3)
integral(2,2)=integral(2,2)+g_n(2,2)
integral(2,3)=integral(2,3)+g_n(2,3)
integral(3,3)=integral(3,3)+g_n(3,3)
fluctcur_n(1,1)=fluctcur_n(1,1)+g_fluctcur_n(1,1)
fluctcur_n(1,2)=fluctcur_n(1,2)+g_fluctcur_n(1,2)
fluctcur_n(1,3)=fluctcur_n(1,3)+g_fluctcur_n(1,3)
fluctcur_n(2,2)=fluctcur_n(2,2)+g_fluctcur_n(2,2)
fluctcur_n(2,3)=fluctcur_n(2,3)+g_fluctcur_n(2,3)
fluctcur_n(3,3)=fluctcur_n(3,3)+g_fluctcur_n(3,3)
enddo
integral(1,1)=integral(1,1)*h
integral(1,2)=integral(1,2)*h
integral(1,3)=integral(1,3)*h
integral(2,2)=integral(2,2)*h
integral(2,3)=integral(2,3)*h
integral(3,3)=integral(3,3)*h
fluctcur_n(1,1)=fluctcur_n(1,1)*h
fluctcur_n(1,2)=fluctcur_n(1,2)*h
fluctcur_n(1,3)=fluctcur_n(1,3)*h
fluctcur_n(2,2)=fluctcur_n(2,2)*h
fluctcur_n(2,3)=fluctcur_n(2,3)*h
fluctcur_n(3,3)=fluctcur_n(3,3)*h
goto 20
c --------------------------------------------------------------------
c integration along the resonance curve using rectangle
c formula
c end
c--------------------------------------------------------------------
3 continue
cSm060306
c --------------------------------------------------------------------
c integration along the resonance curve using trapezoidal
c formula
c begin
c--------------------------------------------------------------------
do j=0,jmax
p_int=1.d0
if((j.eq.1).or.(j.eq.jmax)) p_int=0.5d0
p_perp=h*j
if(p_perp.lt.1.d-3) p_perp=1.d-3
if(j.eq.jmax) p_perp=p_perp-1.d-3
call g_n_emis(p_perp,y,nll,np,theta,n,i_fkin,r,z,phi,
. g_n,g_fluctcur_n)
integral(1,1)=integral(1,1)+p_int*g_n(1,1)
integral(1,2)=integral(1,2)+p_int*g_n(1,2)
integral(1,3)=integral(1,3)+p_int*g_n(1,3)
integral(2,2)=integral(2,2)+p_int*g_n(2,2)
integral(2,3)=integral(2,3)+p_int*g_n(2,3)
integral(3,3)=integral(3,3)+p_int*g_n(3,3)
fluctcur_n(1,1)=fluctcur_n(1,1)+p_int*g_fluctcur_n(1,1)
fluctcur_n(1,2)=fluctcur_n(1,2)+p_int*g_fluctcur_n(1,2)
fluctcur_n(1,3)=fluctcur_n(1,3)+p_int*g_fluctcur_n(1,3)
fluctcur_n(2,2)=fluctcur_n(2,2)+p_int*g_fluctcur_n(2,2)
fluctcur_n(2,3)=fluctcur_n(2,3)+p_int*g_fluctcur_n(2,3)
fluctcur_n(3,3)=fluctcur_n(3,3)+p_int*g_fluctcur_n(3,3)
enddo
integral(1,1)=integral(1,1)*h
integral(1,2)=integral(1,2)*h
integral(1,3)=integral(1,3)*h
integral(2,2)=integral(2,2)*h
integral(2,3)=integral(2,3)*h
integral(3,3)=integral(3,3)*h
fluctcur_n(1,1)=fluctcur_n(1,1)*h
fluctcur_n(1,2)=fluctcur_n(1,2)*h
fluctcur_n(1,3)=fluctcur_n(1,3)*h
fluctcur_n(2,2)=fluctcur_n(2,2)*h
fluctcur_n(2,3)=fluctcur_n(2,3)*h
fluctcur_n(3,3)=fluctcur_n(3,3)*h
goto20
c --------------------------------------------------------------------
c end integration along the resonance curve using trapezoidal
c formula
c end
c--------------------------------------------------------------------
4 continue
cSm070417
c -------------------------------------------------------------------
c integration along the resonance curve using
c the adaptive Simpson function
c--------------------------------------------------------------------
c write(*,*)'emission.f intgr_emis before adaptive_simpson'
call calc_emission_integral_array_by_adaptive_simpson
&(y,nll,np,theta,n,i_fkin,r,z,phi,p_permax,epsi,
&integral,fluctcur_n)
c write(*,*)'intgr_emis after adaptive_simpson'
c write(*,*)'integral',integral
c write(*,*)'fluctcur_n',fluctcur_n
c--------------------------------------------------------------------
20 continue
integral(2,1)=-integral(2,1)
integral(3,1)= integral(3,1)
integral(3,2)=-integral(3,2)
fluctcur_n(2,1)=-fluctcur_n(2,1)
fluctcur_n(3,1)= fluctcur_n(3,1)
fluctcur_n(3,2)=-fluctcur_n(3,2)
10 continue
return
end
subroutine g_n_emis(p_perp,y,nll,np,theta,n,i_fkin,r,z,phi,
.g_n,g_fluctcur_n)
c calculates under integral complex marix functions
c g_n(3,3)=sum{k}g_nk and g_fluctcur_n(3,3)=sum{k}g_fluctcur_nk
c input
c p_perp - momentum divided by (mc)
c y = omega_ce/omega for the electron rest mass
c nll - N_parallel
c np - N_perpendicular
c theta - mc**2/T
c n - n number of the given resonance harmonic
c i_fkin =0 the usage of the analytical relativistic distributin
c =1 the usage of the numerical 3D distribution from diskf
c written be CQL3D code
c r - the major radius (it is used for i_fkin=1)
c z - the vertical coordinate (it is used for i_fkin=1)
c phi - toroidal angle(it is used for i_fkin=1)
c output
c g_n(3,3) under integral matrix double complex function
c g_fluctcur_n(3,3)
c-------------------------------------------------------
implicit none
c-----input
double precision p_perp,y,nll,np,theta,r,z,phi
integer n,i_fkin
c-----external root_res, s_calcn, zeroK, unde_intgr
double precision u_n,u_flcur_n
c-----output
double complex g_n(3,3), g_fluctcur_n(3,3)
c-----local
double complex sn_k(3,3),g_nk(3,3),g_fluctcur_nk(3,3)
double precision gamma, p_par_rl(2),coeff,eps,ps,ps_max,pi,
+dgdp_par,u_nk,u_flcur_nk,coeff_fc
integer k,kmax,i,j
c kmax - total number of the resonace condition root p_perp_k(p_perp)
pi=4.d0*datan(1.d0)
c-----calculations ot the roots p_par_rl of the resonace condition
c-----gamma=N_par*p_par_rl+nY
call root_res(p_perp,nll,n,Y,kmax,p_par_rl)
c write(*,*)'g_n_emis number of roots p_par_rl(p_perp) kmax',kmax
c-----initialize g_n
call zeroK(g_n)
call zeroK(g_fluctcur_n)
if (kmax.eq.0) goto 20
c eps=1.d-9 ! the min value of Maxwell exponent
c ps_max=(1.d0-dlog(eps)/theta)**2-1.d0
do k=1,kmax
ps=p_perp*p_perp+p_par_rl(k)*p_par_rl(k)
gamma=dsqrt(1.d0+ps)
c if(ps.gt.ps_max) then
c write(*,*)'emission.f g_n_emis k,ps,ps_max',k,ps,ps_max
c goto 10
c endif
c write(*,*)'g_n_emis k,p_perp,p_par_rl(k),ps',
c . k,p_perp,p_par_rl(k),ps
call s_calcn(n,p_perp,p_par_rl(k),np,y,sn_k)
c write(*,*)'g_n_emis k,sn_k',k,sn_k
c--------resonance condition uses the delta function with argument
c g_delta=gamma-nll*p_par-n*y
c the derivative from this argument d(g_delta)/dp_par=dgdp_par
dgdp_par=dabs((p_par_rl(k)-nll*gamma)/gamma)
cSm030415
c if(dgdp_par.lt.1.d-3)then
c write(*,*)'dgdp_par k,p_par_rl(k),nll,p_perp,gamma',
c + k,p_par_rl(k),nll,p_perp,gamma
c endif
call unde_intgr(p_perp,p_par_rl(k),y,nll,theta,n,i_fkin,
+ r,z,phi,u_nk,u_flcur_nk)
c write(*,*)'in g_n_emis after unde_integr u_nk,u_flcur_nk',
c + u_nk,u_flcur_nk
coeff=2.d0*pi*u_nk/dgdp_par
coeff_fc=2.d0*pi*u_flcur_nk/dgdp_par
c write(*,*)'in g_n_emis u_nk,u_flcur_nk',u_nk,u_flcur_nk
c write(*,*)'in g_n_emis coeff,coeff_fc',coeff,coeff_fc
g_nk(1,1)=coeff*sn_k(1,1)
g_nk(1,2)=coeff*sn_k(1,2)
g_nk(1,3)=coeff*sn_k(1,3)
g_nk(2,2)=coeff*sn_k(2,2)
g_nk(2,3)=coeff*sn_k(2,3)
g_nk(3,3)=coeff*sn_k(3,3)
g_nk(2,1)=-g_nk(1,2)
g_nk(3,1)= g_nk(1,3)
g_nk(3,2)=-g_nk(2,3)
g_fluctcur_nk(1,1)=coeff_fc*sn_k(1,1)
g_fluctcur_nk(1,2)=coeff_fc*sn_k(1,2)
g_fluctcur_nk(1,3)=coeff_fc*sn_k(1,3)
g_fluctcur_nk(2,2)=coeff_fc*sn_k(2,2)
g_fluctcur_nk(2,3)=coeff_fc*sn_k(2,3)
g_fluctcur_nk(3,3)=coeff_fc*sn_k(3,3)
do i=1,3
do j=1,3
g_n(i,j)=g_n(i,j)+g_nk(i,j)
g_fluctcur_n(i,j)=g_fluctcur_n(i,j)+g_fluctcur_nk(i,j)
enddo
enddo
10 continue
enddo !kmax
20 continue
return
end
subroutine unde_intgr(p_perp,p_par,y,nll,
+theta,n,i_fkin,r,z,phi,u_n,u_flcur_n)
c calculates under integral functions
c u_n=U_n(np=p_per,p_perp=p_parallel)=(1/gamma)*
c (n*Y*df/dp^_perpendicular+N_parallel*p^_perpendicular*df/dp^_parallel)
c u_n is used in under integral complex marix function G_nk(3,3)
c
c u_flcur_n=f*p^perp/gamma
c u_flcur_n is used in under integral complex matrix fluct_car_nk(3,3)
c Here p^=p/mc
c input
c p_perp - perpendicular momentum divided by (mc)
c p_par parallel momentum/mc
c y = omega_ce/omega for the electron rest mass
c nll - N_parallel
c theta - mc**2/T
c n - n number of the given resonance harmonic
c i_fkin =0 the usage of the analytical relativistic Maxwellian distributin
c =1 the usage of the numerical 3D distribution from diskf or
c netcdfnm.nc files or the mesh distribution given analytically
c written be CQL3D code
c r - the major radius (it is used for i_fkin=1)
c z - the vertical coordinate (it is used for i_fkin=1)
c phi - toroidal angle
c-------------------------------------------------------
implicit none
c input
double precision p_perp,p_par,y,nll,theta
double precision r,z,phi
integer n,i_fkin
c external besk2as, root_res,psif,rhopsi,bmin_psi,b
double precision psif,rhopsi,bmin_psi,b,fdens_fdist
c output
double precision u_n,u_flcur_n
c_for test
double precision vnormloc,massloc
COMMON /dskin1/vnormloc,massloc !v (cm/sec),m( g)
cendtest
c local
double precision gamma, bk2,f_maxw,ps,p,ps_max,eps,pi,d_maxw_dp,
+ m_e,clight,energy,psi,rho,pitch,pitch0,bmin,btotal,
+ c_pitch,s_pitch,s_pitch0,c_pitch0,
+ dptc0dpt, !d(pitch0)/d(pitch)
+ dens,u_np,u_flcur_np
c distributin function and its derivatives
double precision fdist0,dfdx,dfdpitch,dfdpitc0,dfdp
integer initial
c-----!
pi=4*datan(1.d0)
ps=p_perp*p_perp+p_par*p_par
p=dsqrt(ps)
gamma=dsqrt(1.d0+ps)
if (i_fkin.eq.0) then
c--------usage of the analytical relativistic Maxwellian distribution
c calculation the Mackdonalds function bk2=K_2(theta)*EXP(theta)
call besk2as(theta,bk2)
eps=1.d-9 ! the min value of Maxwell exponent
ps_max=(1.d0-dlog(eps)/theta)**2-1.d0
c if(ps.gt.ps_max) then
c u_n=0.d0
c goto 10
c endif
f_maxw=theta*dexp(theta*(1.d0-gamma))/(4.d0*pi*bk2)
u_n=-p_perp*theta*f_maxw*(n*y+nll*p_par)/(gamma*gamma)
u_flcur_n=p_perp*f_maxw/gamma
cSm070126
c write(*,*)' emission unde_int'
c write(*,*)' old u_n, old f_maxw,u_n,u_flcur_n',
c & f_maxw,u_n,u_flcur_n
call analytical_distrib(theta,p,r,z,phi,
& f_maxw,d_maxw_dp)
u_n=p_perp*d_maxw_dp*(n*y+nll*p_par)/gamma/p
u_flcur_n=p_perp*f_maxw/gamma
c write(*,*)'unde_intgr new f_maxw,u_n u_flcur_n',
c & f_maxw,u_n,u_flcur_n
goto10
endif
if (i_fkin.eq.1)then
c--------usage of the numerical 3D relativistic distribution from diskf file
c written by CQL3D code
initial=0
c energy=p**2/(2m) ps=(p/mc)**2. energy should be in KeV
c pitch
c rho
m_e=9.1094d-28 !g
clight=2.99792458d10 !cm/sec
energy=0.5d0*ps*m_e*clight**2 !erg
energy=energy/1.6022d-9 !KeV
psi=psif(z,r) !poloidal flux
rho=rhopsi(psi)!small radius
if (p.ne.0.d0) then
pitch=dacos(p_par/p)
else
pitch=0.d0
endif
if (pitch.gt.pi) pitch=pi
if (pitch.lt.-pi) pitch=-pi
c------- pitch0 is pitch angle for the point with the minimal
c------- value of the magnetic field at the give flux surface with the poloidal flux=psi
pitch0=pitch
dptc0dpt=1.d0
cSm060227
c goto 100
bmin=bmin_psi(psi)
btotal=b(z,r,phi)
if (p.ne.0.d0) then
c_pitch=p_par/p !cos(pitch)
s_pitch=p_perp/p !sin(pitch)
else
c_pitch=1.d0 !cos(pitch)
s_pitch=0.d0 !sin(pitch)
endif
c--------s_pitch0=sin and c_pitch0=cos of the pitch angle for the minimal b
s_pitch0=s_pitch*dsqrt(bmin/btotal) !sin(pitch0)
c write(*,*)'bmin,btotal,s_pitch,s_pitch0',
c + bmin,btotal,s_pitch,s_pitch0
if (s_pitch0.gt.1.d0) then
s_pitch0=1.d0
c_pitch0=0.d0
else
c_pitch0=dsqrt(1.d0-s_pitch0**2) !dabs(cos(pitch0))
endif
if (c_pitch.lt.0.d0) then
c_pitch0=-c_pitch0
endif
pitch0=dacos(c_pitch0)
if (pitch0.gt.pi) pitch0=pi
if (pitch0.lt.-pi) pitch0=-pi
c write(*,*)'emission in u_n pitch,pitch0',pitch,pitch0
c--------d(pitch0)/d(pitch)
c dptc0dpt=(c_pitch/c_pitch0)*(s_pitch0/s_pitch)
cSm051206
if((dabs(c_pitch0).lt.1.d-12).or.(dabs(s_pitch).lt.1.d-12))
& then
dptc0dpt=1.d0
else
dptc0dpt=(c_pitch/c_pitch0)*(s_pitch0/s_pitch)
endif
c write(*,*)'c_pitch,c_pitch0',c_pitch,c_pitch0
c write(*,*)'s_pitch,s_pitch0',s_pitch,s_pitch0
100 continue
c--------calculations of the distribution function fdist0
c and its derivatives df/dx,df/dpitch0
c x = momentum-per-mass(nomalized to maximum 1.)
c vel=dsqrt(2.d0*energy*1.d3*1.6022d-12/fmass(1))
c at the point (rho,energy,pitch0). Here pitch0=pitch0(r,z,pitch)
c write(*,*)'unde_intgr initial,energy,pitch0,rho',
c + initial,energy,pitch0,rho
call dskin(initial,energy,pitch0,rho,fdist0,dfdx,dfdpitc0,