forked from plasmasim/sceptic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfvinjecttest.F
445 lines (418 loc) · 14.1 KB
/
fvinjecttest.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
program fvinjecttest
c To test fvinject
c Grabbed initially from sceptic.F
logical success,finaldiags
real rmax
character*100 string
logical readpart,writepart
logical lsmooth,lcolcont
c Common storage:
include 'piccom.f'
include 'fvcom.f'
include 'colncom.f'
common /distfunc/ud,uneutral
real ftest(nxfvi:nxfva,nzfvi:nzfva)
external fv
c diagnostics
real vydist(nxfvi:nxfva),fmaxwell(nxfvi:nxfva),vzdist(nxfvi:nxfva)
common /vinjdiag/vydist,vzdist
c Local diagnostics
integer ndist
parameter (ndist=40)
real vphidist(-ndist:ndist),vphi(-ndist:ndist)
$ ,fmdist(-ndist:ndist)
real phiangle(npartmax), pindex(npartmax),tanvel(npartmax)
$ ,cosarr(npartmax)
parameter (ncdist=20)
real cosdist(ncdist),cdangle(ncdist)
real cosangle(ncdist),acdist(ncdist),ratc(ncdist)
real acint(ncdist)
real qthtest(nthfvsize),fvthtest(nthfvsize)
c real worka(0:nxfva-nxfvi+2,0:nzfva-nzfvi+2)
c Data
data rmax/5./
data readpart/.false./writepart/.false./
c Diagnostic array
vmax=4.
do j=-ndist,ndist
vphi(j)=j*vmax/ndist
vphidist(j)=0.
enddo
c Full size arrays by default. Can be changed later by switches.
nr=nrsize
nth=nthfvsize
c Common defaults. Avoid block data.
success=.false.
vd=.000
debyelen=.1
vprobe=-4.
Ezext=0.
bdyfc=4.
Ti=1.
diags=.false.
finaldiags=.false.
ldist=.false.
avelim=0.6
nstepsave=0
nsamax=40
lsmooth=.false.
lcolcont=.true.
ircell=1
itcell=1
norbits=0
npart=1
ninjcomp0=npartmax
ninjcomp=ninjcomp0
linsulate=.false.
lfloat=.false.
rmtoz=1.
ierad=1
rhomin=0.
rhomax=0.
lat0=.false.
lfext=.false.
colnwt=0.
icolntype=0
vneutral=0.
localinj=.false.
damplen=0.
ipfsw=3
call pfset(0)
lfixedn=.true.
ipstep=1
c Deal with arguments. Lots of these are spurious carry-overs.
if(iargc().eq.0) goto 51
do 1 i=1,iargc()
call getarg(i,string)
if(string(1:1) .eq. ' ') then
goto 3
endif
if(string(1:8) .eq. '--rhoinf')then
read(string(9:),*)rhoinf
lfixedn=.false.
endif
if(string(1:2) .eq. '-r') readpart=.true.
if(string(1:2) .eq. '-w') writepart=.true.
if(string(1:2) .eq. '-f') finaldiags=.true.
if(string(1:2) .eq. '-s') diags=.true.
if(string(1:3) .eq. '-er') then
read(string(4:),*)ierad
elseif(string(1:2) .eq. '-e') then
ldist=.true.
c try to read the cell from the rest of the string.
read(string(3:),*,err=261,end=261)ircell,itcell
goto 262
c restore defaults on read error.
261 ircell=1
itcell=1
262 continue
endif
if(string(1:2) .eq. '-b') read(string(3:),*)bdyfc
if(string(1:2) .eq. '-t') read(string(3:),*)Ti
if(string(1:2) .eq. '-x') read(string(3:),*)rmax
if(string(1:3) .eq. '-vd') read(string(4:),*)vd
if(string(1:3) .eq. '-vn') read(string(4:),*)vneutral
if(string(1:3) .eq. '-pf') then
lfloat=.true.
elseif(string(1:3) .eq. '-pi') then
linsulate=.true.
elseif(string(1:2) .eq. '-p') then
read(string(3:),*)vprobe
endif
if(string(1:2) .eq. '-z') read(string(3:),*)Ezext
if(string(1:2) .eq. '-l') read(string(3:),*)debyelen
if(string(1:3) .eq. '-nr') read(string(4:),*)nr
c if(string(1:3) .eq. '-nt') read(string(4:),*)nth
c Can't change here.
if(string(1:3) .eq. '-ni') read(string(4:),*)npart
if(string(1:3) .eq. '-kt') then
read(string(4:),*)icolntype
elseif(string(1:2) .eq. '-k') then
read(string(3:),*)colnwt
endif
if(string(1:2) .eq. '-m') read(string(3:),*)myid
if(string(1:2) .eq. '-a') then
read(string(3:),*,err=251,end=251)ipfsw
call pfset(ipfsw)
goto 252
251 ipfsw=0
252 continue
endif
if(string(1:2) .eq. '-?') goto 51
1 continue
3 continue
c write(*,*)linsulate,diags
c Set Array sizes, allowed variable.
if(nr.gt.nrsize)then
write(*,*)'Too many radial points:',nr,' Set to',nrsize
nr=nrsize
endif
if(npart.gt.npartmax)then
write(*,*)'Too many ions:',npart,' Set to',npartmax
npart=npartmax
endif
write(*,505)nr,nthfvsize,npart
505 format(' Mesh: ',i3,' x',i3,' Particles:',i7)
r(nr)=rmax
Eneutral=colnwt*(vd-vneutral)
uneutral=vneutral/sqrt(2.*Ti)
write(*,*)'vd,vneutral,icolntype,colnwt,Eneutral',
$ vd,vneutral,icolntype,colnwt,Eneutral,uneutral
c********************
c Real init testing section.
c
ud=vd/sqrt(2.*Ti)
actot=0.
acdist(1)=0.
acint(1)=0.
cosangle(1)=-1.
do j=2,ncdist
cosdist(j)=0.
cdangle(j) =-1.+2.*(j-1.5)/(ncdist-1)
acdist(j)=canglecx(-cdangle(j),ud)
actot=actot+acdist(j)
cosangle(j)=-1.+2.*(j-1)/(ncdist-1)
c acint(j)=acint(j-1)+0.5*(acdist(j)+acdist(j-1))
acint(j)=acint(j-1)+acdist(j)
$ *(cosangle(j)-cosangle(j-1))
enddo
c Renormalize to sum equals 1.
do j=2,ncdist
acdist(j)=0.5*(ncdist-1)*acdist(j)/actot
enddo
c Now actot is \int canglecx dcostheta.
ldiaginj=diags
write(*,*) 'Testing fvinject. Drift velocity=',vd
call fvinjinit()
write(*,*) 'Finished initialization on grid',
$ nthfvsize,nxfva,nzfva
write(*,*)'acint,qthfv(nthfvsize)',acint(ncdist),qthfv(nthfvsize)
510 format(10f8.3)
if(nthfvsize.le.10)then
write(string,'(''('',i3,''f8.3)'')')nthfvsize
write(*,*)'qxfv(ix,ith)='
write(*,string)((qxfv(i,j),j=1,nthfvsize),i=nxfvi,nxfva)
write(*,*)'nthfvsize=',nthfvsize,' vx=',nxfvi,nxfva
write(*,*)' th qxfv(nxfva,ith) qthfv qfv(1,1,ith)'
write(*,'(4f12.4)')(fvth(i),qxfv(nxfva,i),qthfv(i),
$ qfv(1,1,i),
$ i=1,nthfvsize)
endif
c write(*,*)'ztrfv(ix,ith)='
c write(*,string)((qxfv(i,j),j=1,nthfvsize),i=nxfvi,nxfva)
c Test the function evaluation
write(*,*)'ud,uneutral',ud,uneutral
do i=nxfvi,nxfva
do j=nzfvi,nzfva
ftest(i,j)=fv(vxfv(i),vzfv(j))
c write(*,'(a,3f10.5)')'f-value at vx,vy',
c $ ftest(i,j),vxfv(i),vzfv(j)
enddo
enddo
c Plot the function.
if(lfloat) then
100 call pltinit(0.,1.,0.,1.)
j=1 + 256*10 + 256*256*7
call hidweb(vxfv(nxfvi),vzfv(nzfvi),ftest,
$ nxfva-nxfvi+1,nxfva-nxfvi+1,nzfva-nzfvi+1,j)
call boxtitle('f(vx,vz)')
call ax3labels('vx','vz','f(vx,vz)')
call axident3()
if(ieye3d().ne.0) goto 100
c plot ztrfv
call pltinit(vxfv(nxfvi),vxfv(nxfva),float(nzfvi),float(nzfva))
call axis()
call axlabels('vxfv','ztrfv')
do i=1,nthfvsize
call polyline(vxfv,ztrfv(nxfvi,i),nxfva-nxfvi+1)
call polymark(vxfv,ztrfv(nxfvi,i),nxfva-nxfvi+1,mod(i,16))
enddo
call pltend()
endif
c Plot the integrals.
if(linsulate) then
600 call pltinit(0.,1.,0.,1.)
jsw=1 + 256*10 + 256*256*7
call hidweb(vxfv,fvth(1),qxfv,
$ nxfva-nxfvi+1,nxfva-nxfvi+1,nthfvsize,jsw)
call boxtitle('qxfv(vx,th)')
call axident3()
call ax3labels('vx','th','qxfv(vx,th)')
if(ieye3d().ne.0) goto 600
do j=1,nthfvsize
c qfv for all the thetas
call minmax2(qfv(nzfvi,nxfvi,j),nzfva-nzfvi+1,nzfva-nzfvi+1,
$ nzfva-nzfvi+1,qmin,qmax)
if(qmin.ne.qmax)then
write(*,*)'j,th',j,fvth(j)
601 call pltinit(0.,1.,0.,1.)
jsw=1 + 256*10 + 256*256*7
call hidweb(vzfv,vxfv,qfv(nzfvi,nxfvi,j),
$ nzfva-nzfvi+1,nzfva-nzfvi+1,nxfva-nxfvi+1,jsw)
call boxtitle('qfv(vz,vx)')
call axident3()
call ax3labels('vz','vx','qfv(vz,vx)')
if(ieye3d().ne.0) goto 601
else
write(*,*)'Flat qfv',j,qmin,qmax
endif
enddo
c endif
620 call pltinit(0.,1.,0.,1.)
jsw=1 + 256*10 + 256*256*7
call hidweb(vxfv,vzfv,fqvxvz,
$ nxfva-nxfvi+1,nxfva-nxfvi+1,nzfva-nzfvi+1,jsw)
call boxtitle('fqvxvz(vx,vz)'//
$ ' tangential cumulative distribution')
call axident3()
call ax3labels('vx','vz','fqvxvz(vx,vz)')
if(ieye3d().ne.0) goto 620
endif
if(npart.le.100)
$ write(*,*)'Reinjection particle No, position, velocity'
dt=.0001
do i=1,npart
call fvreinject(i,dt,icolntype)
if(npart.le.100) write(*,701)i,(xp(k,i),k=1,6)
701 format(i6,6f10.4)
phiangle(i)=atan2(xp(5,i),xp(4,i))
pindex(i)=i
vp=(xp(1,i)*xp(5,i)-xp(2,i)*xp(4,i))/
$ sqrt(xp(1,i)**2+xp(2,i)**2)
tanvel(i)=vp
ip=nint(ndist*vp/vmax)
if(ip.lt.-ndist)ip=-ndist
if(ip.gt.ndist)ip=ndist
vphidist(ip)=vphidist(ip)+1.
ca=xp(3,i)/sqrt(xp(1,i)**2+xp(2,i)**2+xp(3,i)**2)
cosarr(i)=ca
icdist=nint(1.5+(ncdist-1)*(ca+1)/2.000001)
cosdist(icdist)=cosdist(icdist)+1
enddo
itotal=0
aver=0
am1=0
do j=2,ncdist
itotal=itotal+cosdist(j)
cosdist(j)=0.5*(ncdist-1)*cosdist(j)/npart
ratc(j)=cosdist(j)/acdist(j)
aver=aver+ratc(j)
am1=am1+ratc(j)*cosangle(j)
enddo
aver=aver/ncdist
am1=am1/ncdist
write(*,*)'npart,itotal,average,1st moment',npart,itotal,aver,am1
c Plot some diagnostics
c The fvinject theta distribution function. Includes the poles.
do j=1,nthfvsize
qthtest(j)=qxfv(nxfva,j)
fvthtest(j)=-fvth(j)
enddo
c Integrate:
total=0.
do j=1,nthfvsize-1
total=total+
$ (fvthtest(j+1)-fvthtest(j))*(qthtest(j+1)+qthtest(j))*0.5
enddo
do j=1,nthfvsize
qthtest(j)=qthtest(j)/abs(total)
enddo
c This then seems to give excellent agreement with analytic form.
c And provided dt is small enough, so does the reinjection.
call autoplot(fvthtest,qthfv,nthfvsize)
call axlabels('cos(!Aq!@)','Cumulative angle distribution')
call color(4)
call dashset(1)
if(uneutral.eq.0.)call polyline(cosangle,acint,ncdist)
call pltend()
write(*,'(2f10.5)')(cdangle(j),acdist(j),j=1,ncdist)
call automark(cdangle(2),cosdist(2),ncdist-1,1)
call axlabels('cos(!Aq!@)','Injection angle distribution')
if(uneutral.eq.0.)call polyline(cdangle(2),acdist(2),ncdist-1)
call color(4)
call dashset(1)
call polyline(fvthtest,qthtest,nthfvsize)
call pltend()
if(uneutral.eq.0.)then
call automark(cosangle,ratc,ncdist,3)
call axlabels('cos(!Aq!@)','Distribution ratio')
call pltend()
endif
c call automark(pindex,phiangle,npart,10)
c call axlabels('index','phiangle')
c call pltend()
c call automark(pindex,tanvel,npart,10)
c call axlabels('index','azimuthal velocity')
c call pltend()
call autoplot(vphi,vphidist,ndist+ndist+1)
call axlabels('v','Azimuthal velocity distribution')
call minmax(vphidist,ndist+ndist+1,vphimin,vphimax)
do j=-ndist,ndist
v=vphi(j)
c velocity is in Te units; convert to those.
fmdist(j)=exp(-v**2/(2.*Ti))*vphimax
enddo
call dashset(1)
call polyline(vphi,fmdist,ndist+ndist+1)
call dashset(0)
call pltend()
c
call autoplot(vxfv,vydist,nxfva-nxfvi+1)
call axlabels('v','y-velocity distribution')
call minmax(vydist,nxfva-nxfvi+1,vymin,vymax)
do j=nxfvi,nxfva
v=vxfv(j)
fmaxwell(j)=exp(-v**2)*vymax
enddo
call dashset(1)
call polyline(vxfv,fmaxwell,nxfva-nxfvi+1)
call dashset(0)
call pltend()
c
call autoplot(vzfv,vzdist,nxfva-nxfvi+1)
call axlabels('v','z-velocity distribution')
call minmax(vzdist,nxfva-nxfvi+1,vzmin,vzmax)
do j=nxfvi,nxfva
v=vzfv(j)
fmaxwell(j)=fvcx(v-vneutral/sqrt(2.*Ti)
$ ,(vd-vneutral)/sqrt(2.*Ti))*npart*(vzfv(2)-vzfv(1))
enddo
call dashset(1)
call polyline(vzfv,fmaxwell,nxfva-nxfvi+1)
call dashset(0)
call jdrwstr(.02,.02,
$ 'Comparing injection flux _ to f(vz)- - distrib.'
$ //' Should not agree', 1.)
write(*,*)'Injection flux as fn of vz'
do k=nxfvi,nxfva
write(*,'(i3,f6.2,f10.1)')k,vzfv(k),vzdist(k)
enddo
call pltend()
call exit(0)
51 write(*,*) 'Usage: fvinjecttest -vdfff.ff [other options]'
write(*,*) ' Test the fvinjection routine specifying total'
$ ,' drift -vd, of which'
write(*,*) ' -vnfff.ff is neutral drift.'
write(*,*) ' -pf plot f(vx,vz). -pi plot integrated f (qxfv).'
write(*,*) ' -nrii -ntii set r- and theta- array size ii.'
write(*,*) ' -aii set plotfile ii. -mii set myid (seed)'
write(*,*) ' -s give solving diagnostics. -ni injections.'
end
c******************************************************************
c Notes
c 8 Oct 05. Got it apparently working. Doing time tests.
c With nrxnt=90x90, and vx x vz =50 x 50
c Initialization approximately 0.6s
c 1000000 reinjections approximately 4s. Actually may be just 200000.
c Probably small enough to be negligible.
c***************************************************************
function canglecx(ct,ud)
c Return the angle distribution function for a cx constant collision
c frequency distribution when the normalized velocity is ud, at angle
c cos(theta)=ct
real ct,ud
x=abs(2.*ct*ud)
if(x.lt.1.e-10)x=1.e-10
canglecx=0.5*(ct*ud*(1.+ sign(experfcc(1/x),ct*ud))
$ + 1./sqrt(3.1415926))
end