-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdiag2lib.f
365 lines (365 loc) · 12.3 KB
/
pdiag2lib.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
c-----------------------------------------------------------------------
c 2d parallel PIC library for diagnostics
c pdiag2lib.f contains diagnostic procedures:
c PVDIST2 calculates 2 component velocity distribution and velocity
c moments, for distributed data.
c PVDIST23 calculates 3 component velocity distribution and velocity
c moments, for distributed data.
c PSDIST2 calculates entropy from 2 component velocity distribution,
c for distributed data.
c PSDIST23 calculates entropy from 3 component velocity distribution,
c for distributed data.
c written by viktor k. decyk, ucla
c copyright 1994, regents of the university of california
c update: november 6, 2009
c-----------------------------------------------------------------------
subroutine PVDIST2(part,fv,fvm,npp,idimp,npmax,nblok,nmv,nmvf)
c for 2d code, this subroutine calculates 2d velocity distribution
c and velocity moments
c input: all except fvm, output: fv, fvm
c part(3,n,l) = velocity vx of particle n in partition l
c part(4,n,l) = velocity vy of particle n in partition l
c fv = distribution function, number of particles in each velocity range
c maximum velocity (used for scaling) is contained in first element fv.
c vdrift for i-th dimension is contained in fvm(1,i)
c vth for i-th dimension is contained in fvm(2,i)
c entropy for i-th dimension is contained in fvm(3,i), defined to be:
c s/k = -sum(f(v)/np)*log(f(v)/(np*delta_v)). Assumes that distribution
c is uniform in space and distributions in each dimension are
c independent.
c npp(l) = number of particles in partition l
c idimp = size of phase space = 4
c npmax = maximum number of particles in each partition
c nblok = number of particle partitions
c the number of velocity bins used is 2*nmv + 1, nmvf >= 2*nmv+2
implicit none
integer idimp, npmax, nblok, nmv, nmvf
integer npp
real part, fv, fvm
dimension part(idimp,npmax,nblok)
dimension fv(nmvf,2,nblok), fvm(3,2,nblok)
dimension npp(nblok)
c local data
integer j, l, nvx, nvy
real anmv, svx, svy
double precision sumvx, sumvy, sumvx2, sumvy2, anp
double precision sum5, work5
dimension sum5(5), work5(5)
anmv = real(nmv)
do 40 l = 1, nblok
svx = anmv/fv(1,1,l)
svy = anmv/fv(1,2,l)
c zero out distribution
do 10 j = 2, nmvf
fv(j,1,l) = 0.
fv(j,2,l) = 0.
10 continue
c count particles in each velocity region
anp = 0.0d0
anmv = anmv + 2.5
sumvx = 0.0d0
sumvy = 0.0d0
sumvx2 = 0.0d0
sumvy2 = 0.0d0
do 20 j = 1, npp(l)
anp = anp + 1.
nvx = part(3,j,l)*svx + anmv
sumvx = sumvx + part(3,j,l)
sumvx2 = sumvx2 + part(3,j,l)**2
nvy = part(4,j,l)*svy + anmv
sumvy = sumvy + part(4,j,l)
sumvy2 = sumvy2 + part(4,j,l)**2
if ((nvx.ge.2).and.(nvx.le.nmvf)) fv(nvx,1,l) = fv(nvx,1,l) + 1.
if ((nvy.ge.2).and.(nvy.le.nmvf)) fv(nvy,2,l) = fv(nvy,2,l) + 1.
20 continue
sum5(1) = sumvx
sum5(2) = sumvy
sum5(3) = sumvx2
sum5(4) = sumvy2
sum5(5) = anp
call PDSUM(sum5,work5,5,1)
sumvx = sum5(1)
sumvy = sum5(2)
sumvx2 = sum5(3)
sumvy2 = sum5(4)
anp = sum5(5)
c calculate velocity moments
if (anp.ne.0.0d0) anp = 1.0d0/anp
sumvx = sumvx*anp
fvm(1,1,l) = sumvx
fvm(2,1,l) = dsqrt(sumvx2*anp - sumvx**2)
sumvy = sumvy*anp
fvm(1,2,l) = sumvy
fvm(2,2,l) = dsqrt(sumvy2*anp - sumvy**2)
c calculate entropy
sumvx = 0.0d0
sumvy = 0.0d0
sumvx2 = 0.0d0
sumvy2 = 0.0d0
do 30 j = 2, nmvf
if (fv(j,1,l).gt.0.) then
sumvx = sumvx + fv(j,1,l)
sumvx2 = sumvx2 + fv(j,1,l)*dlog(dble(fv(j,1,l)*svx))
endif
if (fv(j,2,l).gt.0.) then
sumvy = sumvy + fv(j,2,l)
sumvy2 = sumvy2 + fv(j,2,l)*dlog(dble(fv(j,2,l)*svy))
endif
30 continue
sum5(1) = sumvx
sum5(2) = sumvy
sum5(3) = sumvx2
sum5(4) = sumvy2
call PDSUM(sum5,work5,4,1)
sumvx = sum5(1)
sumvy = sum5(2)
sumvx2 = sum5(3)
sumvy2 = sum5(4)
if (sumvx.gt.0.0d0) sumvx = -sumvx2/sumvx + dlog(sumvx)
if (sumvy.gt.0.0d0) sumvy = -sumvy2/sumvy + dlog(sumvy)
fvm(3,1,l) = sumvx
fvm(3,2,l) = sumvy
40 continue
return
end
c-----------------------------------------------------------------------
subroutine PVDIST23(part,fv,fvm,npp,idimp,npmax,nblok,nmv,nmvf)
c for 2-1/2d code, this subroutine calculates 3d velocity distribution
c and velocity moments
c input: all except fvm, output: fv, fvm
c part(3,n,l) = velocity vx of particle n in partition l
c part(4,n,l) = velocity vy of particle n in partition l
c part(5,n,l) = velocity vz of particle n in partition l
c fv = distribution function, number of particles in each velocity range
c maximum velocity (used for scaling) is contained in first element fv.
c vdrift for i-th dimension is contained in fvm(1,i)
c vth for i-th dimension is contained in fvm(2,i)
c entropy for i-th dimension is contained in fvm(3,i), defined to be:
c s/k = -sum(f(v)/np)*log(f(v)/(np*delta_v)). Assumes that distribution
c is uniform in space and distributions in each dimension are
c independent.
c npp(l) = number of particles in partition l
c idimp = size of phase space = 5
c npmax = maximum number of particles in each partition
c nblok = number of particle partitions
c the number of velocity bins used is 2*nmv + 1, nmvf >= 2*nmv+2
implicit none
integer idimp, npmax, nblok, nmv, nmvf
integer npp
real part, fv, fvm
dimension part(idimp,npmax,nblok)
dimension fv(nmvf,3,nblok), fvm(3,3,nblok)
dimension npp(nblok)
c local data
integer j, l, nvx, nvy, nvz
real anmv, svx, svy, svz
double precision sumvx, sumvy, sumvz, sumvx2, sumvy2, sumvz2, anp
double precision sum7, work7
dimension sum7(7), work7(7)
anmv = real(nmv)
do 40 l = 1, nblok
svx = anmv/fv(1,1,l)
svy = anmv/fv(1,2,l)
svz = anmv/fv(1,3,l)
c zero out distribution
do 10 j = 2, nmvf
fv(j,1,l) = 0.
fv(j,2,l) = 0.
fv(j,3,l) = 0.
10 continue
c count particles in each velocity region
anp = 0.0d0
anmv = anmv + 2.5
sumvx = 0.0d0
sumvy = 0.0d0
sumvz = 0.0d0
sumvx2 = 0.0d0
sumvy2 = 0.0d0
sumvz2 = 0.0d0
do 20 j = 1, npp(l)
anp = anp + 1.
nvx = part(3,j,l)*svx + anmv
sumvx = sumvx + part(3,j,l)
sumvx2 = sumvx2 + part(3,j,l)**2
nvy = part(4,j,l)*svy + anmv
sumvy = sumvy + part(4,j,l)
sumvy2 = sumvy2 + part(4,j,l)**2
nvz = part(5,j,l)*svz + anmv
sumvz = sumvz + part(5,j,l)
sumvz2 = sumvz2 + part(5,j,l)**2
if ((nvx.ge.2).and.(nvx.le.nmvf)) fv(nvx,1,l) = fv(nvx,1,l) + 1.
if ((nvy.ge.2).and.(nvy.le.nmvf)) fv(nvy,2,l) = fv(nvy,2,l) + 1.
if ((nvz.ge.2).and.(nvz.le.nmvf)) fv(nvz,3,l) = fv(nvz,3,l) + 1.
20 continue
sum7(1) = sumvx
sum7(2) = sumvy
sum7(3) = sumvz
sum7(4) = sumvx2
sum7(5) = sumvy2
sum7(6) = sumvz2
sum7(7) = anp
call PDSUM(sum7,work7,7,1)
sumvx = sum7(1)
sumvy = sum7(2)
sumvz = sum7(3)
sumvx2 = sum7(4)
sumvy2 = sum7(5)
sumvz2 = sum7(6)
anp = sum7(7)
c calculate velocity moments
if (anp.ne.0.0d0) anp = 1.0d0/anp
sumvx = sumvx*anp
fvm(1,1,l) = sumvx
fvm(2,1,l) = dsqrt(sumvx2*anp - sumvx**2)
sumvy = sumvy*anp
fvm(1,2,l) = sumvy
fvm(2,2,l) = dsqrt(sumvy2*anp - sumvy**2)
sumvz = sumvz*anp
fvm(1,3,l) = sumvz
fvm(2,3,l) = dsqrt(sumvz2*anp - sumvz**2)
c calculate entropy
sumvx = 0.0d0
sumvy = 0.0d0
sumvz = 0.0d0
sumvx2 = 0.0d0
sumvy2 = 0.0d0
sumvz2 = 0.0d0
do 30 j = 2, nmvf
if (fv(j,1,l).gt.0.) then
sumvx = sumvx + fv(j,1,l)
sumvx2 = sumvx2 + fv(j,1,l)*dlog(dble(fv(j,1,l)*svx))
endif
if (fv(j,2,l).gt.0.) then
sumvy = sumvy + fv(j,2,l)
sumvy2 = sumvy2 + fv(j,2,l)*dlog(dble(fv(j,2,l)*svy))
endif
if (fv(j,3,l).gt.0.) then
sumvz = sumvz + fv(j,3,l)
sumvz2 = sumvz2 + fv(j,3,l)*dlog(dble(fv(j,3,l)*svz))
endif
30 continue
sum7(1) = sumvx
sum7(2) = sumvy
sum7(3) = sumvz
sum7(4) = sumvx2
sum7(5) = sumvy2
sum7(6) = sumvz2
call PDSUM(sum7,work7,6,1)
sumvx = sum7(1)
sumvy = sum7(2)
sumvz = sum7(3)
sumvx2 = sum7(4)
sumvy2 = sum7(5)
sumvz2 = sum7(6)
if (sumvx.gt.0.0d0) sumvx = -sumvx2/sumvx + dlog(sumvx)
if (sumvy.gt.0.0d0) sumvy = -sumvy2/sumvy + dlog(sumvy)
if (sumvz.gt.0.0d0) sumvz = -sumvz2/sumvz + dlog(sumvz)
fvm(3,1,l) = sumvx
fvm(3,2,l) = sumvy
fvm(3,3,l) = sumvz
40 continue
return
end
c-----------------------------------------------------------------------
subroutine PSDIST2(fv,fvm,nblok,nmv,nmvf)
c for 2d code, this subroutine calculates entropy from 2d velocity
c distribution
c input: all except fvm, output: fvm
c fv = distribution function, number of particles in each velocity range
c maximum velocity (used for scaling) is contained in first element fv.
c entropy for i-th dimension is contained in fvm(3,i), defined to be:
c s/k = -sum(f(v)/np)*log(f(v)/(np*delta_v)). Assumes that distribution
c is uniform in space and distributions in each dimension are
c independent.
c nblok = number of particle partitions
c the number of velocity bins used is 2*nmv + 1, nmvf >= 2*nmv+2
implicit none
integer nblok, nmv, nmvf
real fv, fvm
dimension fv(nmvf,2,nblok), fvm(3,2,nblok)
c local data
integer j, l
real anmv, svx, svy
double precision sumvx, sumvy, sumvx2, sumvy2
anmv = real(nmv)
do 20 l = 1, nblok
svx = anmv/fv(1,1,l)
svy = anmv/fv(1,2,l)
c calculate entropy
sumvx = 0.0d0
sumvy = 0.0d0
sumvx2 = 0.0d0
sumvy2 = 0.0d0
do 10 j = 2, nmvf
if (fv(j,1,l).gt.0.) then
sumvx = sumvx + fv(j,1,l)
sumvx2 = sumvx2 + fv(j,1,l)*dlog(dble(fv(j,1,l)*svx))
endif
if (fv(j,2,l).gt.0.) then
sumvy = sumvy + fv(j,2,l)
sumvy2 = sumvy2 + fv(j,2,l)*dlog(dble(fv(j,2,l)*svy))
endif
10 continue
if (sumvx.gt.0.0d0) sumvx = -sumvx2/sumvx + dlog(sumvx)
if (sumvy.gt.0.0d0) sumvy = -sumvy2/sumvy + dlog(sumvy)
fvm(3,1,l) = sumvx
fvm(3,2,l) = sumvy
20 continue
return
end
c-----------------------------------------------------------------------
subroutine PSDIST23(fv,fvm,nblok,nmv,nmvf)
c for 2-1/2d code, this subroutine calculates entropy from 3d velocity
c distribution
c input: all except fvm, output: fvm
c fv = distribution function, number of particles in each velocity range
c maximum velocity (used for scaling) is contained in first element fv.
c entropy for i-th dimension is contained in fvm(3,i), defined to be:
c s/k = -sum(f(v)/np)*log(f(v)/(np*delta_v)). Assumes that distribution
c is uniform in space and distributions in each dimension are
c independent.
c nblok = number of particle partitions
c the number of velocity bins used is 2*nmv + 1, nmvf >= 2*nmv+2
implicit none
integer nblok, nmv, nmvf
real fv, fvm
dimension fv(nmvf,3,nblok), fvm(3,3,nblok)
c local data
integer j, l
real anmv, svx, svy, svz
double precision sumvx, sumvy, sumvz, sumvx2, sumvy2, sumvz2
anmv = real(nmv)
do 20 l = 1, nblok
svx = anmv/fv(1,1,l)
svy = anmv/fv(1,2,l)
svz = anmv/fv(1,3,l)
c calculate entropy
sumvx = 0.0d0
sumvy = 0.0d0
sumvz = 0.0d0
sumvx2 = 0.0d0
sumvy2 = 0.0d0
sumvz2 = 0.0d0
do 10 j = 2, nmvf
if (fv(j,1,l).gt.0.) then
sumvx = sumvx + fv(j,1,l)
sumvx2 = sumvx2 + fv(j,1,l)*dlog(dble(fv(j,1,l)*svx))
endif
if (fv(j,2,l).gt.0.) then
sumvy = sumvy + fv(j,2,l)
sumvy2 = sumvy2 + fv(j,2,l)*dlog(dble(fv(j,2,l)*svy))
endif
if (fv(j,3,l).gt.0.) then
sumvz = sumvz + fv(j,3,l)
sumvz2 = sumvz2 + fv(j,3,l)*dlog(dble(fv(j,3,l)*svz))
endif
10 continue
if (sumvx.gt.0.0d0) sumvx = -sumvx2/sumvx + dlog(sumvx)
if (sumvy.gt.0.0d0) sumvy = -sumvy2/sumvy + dlog(sumvy)
if (sumvz.gt.0.0d0) sumvz = -sumvz2/sumvz + dlog(sumvz)
fvm(3,1,l) = sumvx
fvm(3,2,l) = sumvy
fvm(3,3,l) = sumvz
20 continue
return
end