forked from pastfalk/LEOPARD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBessel_int.f90
executable file
·358 lines (250 loc) · 8.63 KB
/
Bessel_int.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
!> Computes perpendicular velocity integrals over the interval [vperp(iperp),vperp(iperp+1)] using generalized hypergeomtric function / Bessel function identities
!! \param n Bessel index
!! \param m index of particle species
!! \param iarb index of species among the particle species with arbitrary velocity distribution
!! \param k wavenumber
!! \param iperp index of perpendicular velocity gridpoint of the interval (lower limit) which is to be integrated over
!! \param esc boolean array indicating which dielectric tensor components are still not converged with respect to summation over the Bessel index
!! \param Ivpe array containing the values of the perpendicular velocity integrals for the given velocity interval
subroutine Bessel_int(n,m,iarb,k,iperp,esc,Ivpe)
use param_mod
implicit none
real :: k
integer :: m,n,ndp,nfrac,iarb
integer :: iperp
real, dimension(3,5) :: Ivpe
real :: lambda
real(kind=16) :: arg
real(kind=16) :: h1, x
integer :: j
real(kind=16), dimension(4) :: HGF
integer :: il
real(kind=16), allocatable, dimension(:) :: a
real(kind=16), allocatable, dimension(:) :: b
integer :: na,nb
logical, dimension(6) :: esc
real :: Bes_term1, Bes_term2
if(vperp(iperp,iarb).eq.0.0) then
Ivpe=0.0
return
endif
lambda=(k*sin(theta))/(mu(m)*q(m))
arg=lambda*lambda*vperp(iperp,iarb)*vperp(iperp,iarb)
!determine how many terms have to be included in the continued fraction formula that is used for
!the computation of the generalized hypergeometric function needed for the evaluation of the perpendicular velocity integral
!and determine whether arbitrary precision arithmetic has to be employed or not
call acc_F(arg,ndp,nfrac)
!compute the Bessel function terms required for the estimation of some of the perpendicular velocity integrals
call fort_Bes(n,lambda*vperp(iperp,iarb),Bes_term1,Bes_term2)
if ( n.ne.0) then
!compute a prefactor required for the evaluation of the perpendicular velocity integrals
x=lambda*vperp(iperp,iarb)
h1=1.0_16
do j=1,n
h1=h1*(x/(2.0_16 *j))
enddo
h1=h1*h1
!compute generalized hypergeometric functions 2F3 and 1F2, and use them for evaluating the perpendicular velocity integrals
na=2
nb=3
allocate(a(na),b(nb))
if(esc(1).or.esc(3).or.esc(5).or.esc(4).or.esc(6)) then
do il=1,5
if(il.ne.2) then
a(1)=1.0_16 *n+0.5_16
a(2)=1.0_16 *n+il*0.5_16
b(1)=1.0_16 *n+1.0_16
b(2)=1.0_16 *n+(il+2)*0.5_16
b(3)=2.0_16 *n+1.0_16
if(ndp.eq.0) then
call F23(a,b,-arg,nfrac,HGF(1))
else
call F23_mpfun(a,b,-arg,ndp,nfrac,HGF(1))
endif
Ivpe(1,il)=vperp(iperp,iarb)**il *h1/(2.0*n+1.0*il) *HGF(1)
else
if ((vperp(iperp,iarb).ne.0.0).and.((Bes_term1-Bes_term2).ne.0.0).and.&
& ((log10(abs(0.5*vperp(iperp,iarb)**2))+log10(abs(Bes_term1-Bes_term2))).gt.-299.0)) then
Ivpe(1,2)=0.5*vperp(iperp,iarb)*vperp(iperp,iarb) *&
& (Bes_term1-Bes_term2)
else
Ivpe(1,2)=0.0
endif
endif
enddo
else
Ivpe(1,1)=0.0
Ivpe(1,2)=0.0
Ivpe(1,3)=0.0
Ivpe(1,4)=0.0
Ivpe(1,5)=0.0
endif
if(esc(2)) then
a(1)=1.0_16 *n+0.5_16
a(2)=1.0_16 *n+1.0_16
b(1)=1.0_16 *n
b(2)=1.0_16 *n+2.0_16
b(3)=2.0_16 *n+1.0_16
if(ndp.eq.0) then
call F23(a,b,-arg,nfrac,HGF(1))
else
call F23_mpfun(a,b,-arg,ndp,nfrac,HGF(1))
endif
do il=1,5
a(1)=1.0_16 *n+0.5_16
a(2)=1.0_16 *n+(il+2)*0.5_16
b(1)=1.0_16 *n
b(2)=1.0_16 *n+(il+4)*0.5_16
b(3)=2.0_16 *n+1.0_16
if(ndp.eq.0) then
call F23(a,b,-arg,nfrac,HGF(2))
else
call F23_mpfun(a,b,-arg,ndp,nfrac,HGF(2))
endif
a(1)=1.0_16 *n-0.5_16
a(2)=1.0_16 *n+il*0.5_16
b(1)=1.0_16 *n
b(2)=1.0_16 *n+(il+2)*0.5_16
b(3)=2.0_16 *n-1.0_16
if(ndp.eq.0) then
call F23(a,b,-arg,nfrac,HGF(3))
else
call F23_mpfun(a,b,-arg,ndp,nfrac,HGF(3))
endif
a(1)=1.0_16 *n+1.5_16
a(2)=1.0_16 *n+(il+4)*0.5_16
b(1)=1.0_16 *n+2.0_16
b(2)=1.0_16 *n+(il+6)*0.5_16
b(3)=2.0_16 *n+3.0_16
if(ndp.eq.0) then
call F23(a,b,-arg,nfrac,HGF(4))
else
call F23_mpfun(a,b,-arg,ndp,nfrac,HGF(4))
endif
Ivpe(2,il)=-vperp(iperp,iarb)**(il+2) /(2.0*il)*n*h1 /(1.0*(n+1)) * HGF(1)+&
& vperp(iperp,iarb)**(il+2)/(1.0*il)*n*h1 /(1.0*(2*n+il+2)) * HGF(2)+&
& vperp(iperp,iarb)**(il+2)*n*n*h1/arg /(1.0*(2*n+il)) * HGF(3)+&
& vperp(iperp,iarb)**(il+2)*h1*arg/(16.0*(2*n+il+4)*(n+1)*(n+1)) *HGF(4)
enddo
else
Ivpe(2,1)=0.0
Ivpe(2,2)=0.0
Ivpe(2,3)=0.0
Ivpe(2,4)=0.0
Ivpe(2,5)=0.0
endif
if(esc(4).or.esc(6)) then
do il=1,5
if ((vperp(iperp,iarb).ne.0.0).and.(Bes_term1.ne.0.0).and.&
& ((log10(abs(vperp(iperp,iarb)**il/(2*lambda)))+log10(abs(Bes_term1))).gt.-299.0)) then
Ivpe(3,il)=vperp(iperp,iarb)**il/(2 *lambda)* Bes_term1- il*Ivpe(1,il)/(2*lambda)
else
Ivpe(3,il)=0.0
endif
enddo
else
Ivpe(3,1)=0.0
Ivpe(3,2)=0.0
Ivpe(3,3)=0.0
Ivpe(3,4)=0.0
Ivpe(3,5)=0.0
endif
deallocate(a,b)
else
if(esc(1).or.esc(3).or.esc(4).or.esc(5).or.esc(6)) then
Ivpe(1,1)=0.0 !not needed
if ((vperp(iperp,iarb).ne.0.0).and.((Bes_term1-Bes_term2).ne.0.0).and.&
& ((log10(abs(0.5*vperp(iperp,iarb)*vperp(iperp,iarb)))+log10(abs(Bes_term1-Bes_term2))).gt.-299.0)) then
Ivpe(1,2)= 0.5*vperp(iperp,iarb)*vperp(iperp,iarb) *&
&(Bes_term1-Bes_term2)
else
Ivpe(1,2)=0.0
endif
na=2
nb=3
allocate(a(na),b(nb))
do il=3,5
a(1)=0.5_16
a(2)=il*0.5_16
b(1)=1.0_16
b(2)=1.0_16
b(3)=(il+2)*0.5_16
if(ndp.eq.0) then
call F23(a,b,-arg,nfrac,HGF(1))
else
call F23_mpfun(a,b,-arg,ndp,nfrac,HGF(1))
endif
Ivpe(1,il)=vperp(iperp,iarb)**il /(1.0*il) *HGF(1)
enddo
deallocate(a,b)
else
Ivpe(1,1)=0.0
Ivpe(1,2)=0.0
Ivpe(1,3)=0.0
Ivpe(1,4)=0.0
Ivpe(1,5)=0.0
endif
if(esc(2)) then
na=2
nb=3
allocate(a(na),b(nb))
do il=1,5
if(il.ne.2) then
a(1)=1.5_16
a(2)=(il+4)*0.5_16
b(1)=2.0_16
b(2)=3.0_16
b(3)=(il+6)*0.5_16
if(ndp.eq.0) then
call F23(a,b,-arg,nfrac,HGF(1))
else
call F23_mpfun(a,b,-arg,ndp,nfrac,HGF(1))
endif
Ivpe(2,il)= arg*vperp(iperp,iarb)**(il+2) /(4.0*(il+4)) *HGF(1)
else
deallocate(a,b)
na=1
nb=2
allocate(a(na),b(nb))
a(1)=1.5_16
b(1)=2.0_16
b(2)=4.0_16
if(ndp.eq.0) then
call F12(a,b,-arg,nfrac,HGF(1))
else
call F12_mpfun(a,b,-arg,ndp,nfrac,HGF(1))
endif
Ivpe(2,il)= arg*vperp(iperp,iarb)**(il+2) /(4.0*(il+4)) *HGF(1)
deallocate(a,b)
na=2
nb=3
allocate(a(na),b(nb))
endif
enddo
deallocate(a,b)
else
Ivpe(2,1)=0.0
Ivpe(2,2)=0.0
Ivpe(2,3)=0.0
Ivpe(2,4)=0.0
Ivpe(2,5)=0.0
endif
if(esc(4).or.esc(6)) then
Ivpe(3,1)=0.0 !not needed
do il=2,5
if ((vperp(iperp,iarb).ne.0.0).and.(Bes_term1.ne.0.0).and.&
& ((log10(abs(vperp(iperp,iarb)**il/(2*lambda)))+log10(abs(Bes_term1))).gt.-299.0)) then
Ivpe(3,il)=vperp(iperp,iarb)**il /(2*lambda)*Bes_term1- il*1.0/(2*lambda) * Ivpe(1,il)
else
Ivpe(3,il)=0.0
endif
enddo
else
Ivpe(3,1)=0.0
Ivpe(3,2)=0.0
Ivpe(3,3)=0.0
Ivpe(3,4)=0.0
Ivpe(3,5)=0.0
endif
endif
end subroutine Bessel_int