-
Notifications
You must be signed in to change notification settings - Fork 0
/
prdpush2lib.f
4041 lines (4041 loc) · 150 KB
/
prdpush2lib.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 2d parallel PIC library for pushing relativistic particles with darwin
c electric and magnetic fields and depositing current and derivative of
c current
c prdpush2lib.f contains procedures to process relativistic particles
c with darwin electric and magnetic fields:
c PGRMJPOST2 deposits momentum flux for 2-1/2d code, quadratic
c interpolation, STANDARD optimization, for relativistic
c particles, and distributed data.
c PGSRMJPOST2 deposits momentum flux for 2-1/2d code, quadratic
c interpolation, LOOKAHEAD optimization, for relativistic
c particles, and distributed data.
c PGRDCJPOST2 deposits momentum flux, acceleration density and current
c density for 2-1/2d code, quadratic interpolation, STANDARD
c optimization, for relativistic particles, and distributed
c data.
c PGSRDCJPOST2 deposits momentum flux, acceleration density and current
c density for 2-1/2d code, quadratic interpolation,
c LOOKAHEAD optimization, for relativistic particles, and
c distributed data.
c PGRMJPOST22 deposits momentum flux for 2d code, quadratic
c interpolation, STANDARD optimization, for relativistic
c particles, and distributed data.
c PGSRMJPOST22 deposits momentum flux for 2d code, quadratic
c interpolation, LOOKAHEAD optimization, for relativistic
c particles, and distributed data.
c PGRDCJPOST22 deposits momentum flux, acceleration density and current
c density for 2d code, quadratic interpolation, STANDARD
c optimization, for relativistic particles, and distributed
c data.
c PGSRDCJPOST22 deposits momentum flux, acceleration density and current
c density for 2d code, quadratic interpolation, LOOKAHEAD
c optimization, for relativistic particles, and
c distributed data.
c PGRMJPOST2L deposits momentum flux for 2-1/2d code, linear
c interpolation, STANDARD optimization, for relativistic
c particles, and distributed data.
c PGSRMJPOST2L deposits momentum flux for 2-1/2d code, linear
c interpolation, LOOKAHEAD optimization, for relativistic
c particles, and distributed data.
c PGRDCJPOST2L deposits momentum flux, acceleration density and current
c density for 2-1/2d code, linear interpolation, STANDARD
c optimization, for relativistic particles, and distributed
c data.
c PGSRDCJPOST2L deposits momentum flux, acceleration density and current
c density for 2-1/2d code, linear interpolation, LOOKAHEAD
c optimization, for relativistic particles, and
c distributed data.
c PGRMJPOST22L deposits momentum flux for 2d code, linear interpolation,
c STANDARD optimization, for relativistic particles, and
c distributed data.
c PGSRMJPOST22L deposits momentum flux for 2d code, linear interpolation,
c LOOKAHEAD optimization, for relativistic particles, and
c distributed data.
c PGRDCJPOST22L deposits momentum flux, acceleration density and current
c density for 2d code, linear interpolation, STANDARD
c optimization, for relativistic particles, and
c distributed data.
c PGSRDCJPOST22L deposits momentum flux, acceleration density and current
c density for 2d code, linear interpolation, LOOKAHEAD
c optimization, for relativistic particles, and
c distributed data.
c written by viktor k. decyk, ucla
c copyright 2006, regents of the university of california
c update: november 3, 2009
c-----------------------------------------------------------------------
subroutine PGRMJPOST2(part,amu,npp,noff,qm,ci,idimp,npmax,nblok,nx
1v,nypmx)
c for 2-1/2d code, this subroutine calculates particle momentum flux
c using second-order spline interpolation for relativistic particles
c scalar version using guard cells, for distributed data
c 123 flops/particle, 1 divide, 41 loads, 36 stores
c input: all, output: amu
c momentum flux is approximated by values at the nearest grid points
c amu(i,n,m)=qci*(.75-dx**2)*(.75-dy**2)
c amu(i,n+1,m)=.5*qci*((.5+dx)**2)*(.75-dy**2)
c amu(i,n-1,m)=.5*qci*((.5-dx)**2)*(.75-dy**2)
c amu(i,n,m+1)=.5*qci*(.75-dx**2)*(.5+dy)**2
c amu(i,n+1,m+1)=.25*qci*((.5+dx)**2)*(.5+dy)**2
c amu(i,n-1,m+1)=.25*qci*((.5-dx)**2)*(.5+dy)**2
c amu(i,n,m-1)=.5*qci*(.75-dx**2)*(.5-dy)**2
c amu(i,n+1,m-1)=.25*qci*((.5+dx)**2)*(.5-dy)**2
c amu(i,n-1,m-1)=.25*qci*((.5-dx)**2)*(.5-dy)**2
c where n,m = nearest grid points and dx = x-n, dy = y-m
c and qci = qm*pj*pk*gami2, where jk = xx-yy,xy,zx,zy, for i = 1, 4
c where pj = pj(t-dt/2) and pk = pk(t-dt/2)
c where gami2 = 1./(1.+sum(pi**2)*ci*ci)
c part(1,n,l)) = position x of particle n at t in partition l
c part(2,n,l)) = position y of particle n at t in partition l
c part(3,n,l)) = x momentum of particle n at t - dt/2 in partition l
c part(4,n,l)) = y momentum of particle n at t - dt/2 in partition l
c part(5,n,l)) = z momentum of particle n at t - dt/2 in partition l
c amu(i,j+1,k,l) = ith component of momentum flux at grid point (j,kk)
c where kk = k + noff(l) - 1
c npp(l) = number of particles in partition l
c noff(l) = lowermost global gridpoint in particle partition l.
c qm = charge on particle, in units of e
c ci = reciprical of velocity of light
c idimp = size of phase space = 5
c npmax = maximum number of particles in each partition
c nblok = number of particle partitions.
c nxv = first dimension of flux array, must be >= nx+3
c nypmx = maximum size of particle partition, including guard cells.
implicit none
integer npp, noff, idimp, npmax, nblok, nxv, nypmx
real part, amu, qm, ci
dimension part(idimp,npmax,nblok), amu(4,nxv,nypmx,nblok)
dimension npp(nblok), noff(nblok)
integer j, l, mnoff, nn, mm, nl, np, ml, mp
real qmh, ci2, gami2, dxp, dyp, amx, amy, dxl, dyl
real dx, dy, dz, vx, vy, vz, p2, v1, v2, v3, v4
qmh = .5*qm
ci2 = ci*ci
do 20 l = 1, nblok
mnoff = noff(l) - 1
do 10 j = 1, npp(l)
c find interpolation weights
nn = part(1,j,l) + .5
mm = part(2,j,l) + .5
dxp = part(1,j,l) - float(nn)
dyp = part(2,j,l) - float(mm)
c find inverse gamma
vx = part(3,j,l)
vy = part(4,j,l)
vz = part(5,j,l)
p2 = vx*vx + vy*vy + vz*vz
gami2 = 1.0/(1.0 + p2*ci2)
c calculate weights
nl = nn + 1
amx = qm*(.75 - dxp*dxp)
ml = mm - mnoff
amy = .75 - dyp*dyp
nn = nl + 1
dxl = qmh*(.5 - dxp)**2
np = nl + 2
dxp = qmh*(.5 + dxp)**2
mm = ml + 1
dyl = .5*(.5 - dyp)**2
mp = ml + 2
dyp = .5*(.5 + dyp)**2
c deposit momentum flux
dx = dxl*amy
dy = amx*amy
dz = dxp*amy
v1 = (vx*vx - vy*vy)*gami2
v2 = (vx*vy)*gami2
v3 = (vz*vx)*gami2
v4 = (vz*vy)*gami2
amu(1,nl,mm,l) = amu(1,nl,mm,l) + v1*dx
amu(2,nl,mm,l) = amu(2,nl,mm,l) + v2*dx
amu(3,nl,mm,l) = amu(3,nl,mm,l) + v3*dx
amu(4,nl,mm,l) = amu(4,nl,mm,l) + v4*dx
dx = dxl*dyl
amu(1,nn,mm,l) = amu(1,nn,mm,l) + v1*dy
amu(2,nn,mm,l) = amu(2,nn,mm,l) + v2*dy
amu(3,nn,mm,l) = amu(3,nn,mm,l) + v3*dy
amu(4,nn,mm,l) = amu(4,nn,mm,l) + v4*dy
dy = amx*dyl
amu(1,np,mm,l) = amu(1,np,mm,l) + v1*dz
amu(2,np,mm,l) = amu(2,np,mm,l) + v2*dz
amu(3,np,mm,l) = amu(3,np,mm,l) + v3*dz
amu(4,np,mm,l) = amu(4,np,mm,l) + v4*dz
dz = dxp*dyl
amu(1,nl,ml,l) = amu(1,nl,ml,l) + v1*dx
amu(2,nl,ml,l) = amu(2,nl,ml,l) + v2*dx
amu(3,nl,ml,l) = amu(3,nl,ml,l) + v3*dx
amu(4,nl,ml,l) = amu(4,nl,ml,l) + v4*dx
dx = dxl*dyp
amu(1,nn,ml,l) = amu(1,nn,ml,l) + v1*dy
amu(2,nn,ml,l) = amu(2,nn,ml,l) + v2*dy
amu(3,nn,ml,l) = amu(3,nn,ml,l) + v3*dy
amu(4,nn,ml,l) = amu(4,nn,ml,l) + v4*dy
dy = amx*dyp
amu(1,np,ml,l) = amu(1,np,ml,l) + v1*dz
amu(2,np,ml,l) = amu(2,np,ml,l) + v2*dz
amu(3,np,ml,l) = amu(3,np,ml,l) + v3*dz
amu(4,np,ml,l) = amu(4,np,ml,l) + v4*dz
dz = dxp*dyp
amu(1,nl,mp,l) = amu(1,nl,mp,l) + v1*dx
amu(2,nl,mp,l) = amu(2,nl,mp,l) + v2*dx
amu(3,nl,mp,l) = amu(3,nl,mp,l) + v3*dx
amu(4,nl,mp,l) = amu(4,nl,mp,l) + v4*dx
amu(1,nn,mp,l) = amu(1,nn,mp,l) + v1*dy
amu(2,nn,mp,l) = amu(2,nn,mp,l) + v2*dy
amu(3,nn,mp,l) = amu(3,nn,mp,l) + v3*dy
amu(4,nn,mp,l) = amu(4,nn,mp,l) + v4*dy
amu(1,np,mp,l) = amu(1,np,mp,l) + v1*dz
amu(2,np,mp,l) = amu(2,np,mp,l) + v2*dz
amu(3,np,mp,l) = amu(3,np,mp,l) + v3*dz
amu(4,np,mp,l) = amu(4,np,mp,l) + v4*dz
10 continue
20 continue
return
end
c-----------------------------------------------------------------------
subroutine PGSRMJPOST2(part,amu,npp,noff,qm,ci,idimp,npmax,nblok,n
1xv,nxyp)
c for 2-1/2d code, this subroutine calculates particle momentum flux
c using second-order spline interpolation for relativistic particles
c scalar version using guard cells, integer conversion precalculation,
c and 1d addressing, for distributed data
c cases 9-10 in v.k.decyk et al, computers in physics 10, 290 (1996).
c 123 flops/particle, 1 divide, 41 loads, 36 stores
c input: all, output: amu
c momentum flux is approximated by values at the nearest grid points
c amu(i,n,m)=qci*(.75-dx**2)*(.75-dy**2)
c amu(i,n+1,m)=.5*qci*((.5+dx)**2)*(.75-dy**2)
c amu(i,n-1,m)=.5*qci*((.5-dx)**2)*(.75-dy**2)
c amu(i,n,m+1)=.5*qci*(.75-dx**2)*(.5+dy)**2
c amu(i,n+1,m+1)=.25*qci*((.5+dx)**2)*(.5+dy)**2
c amu(i,n-1,m+1)=.25*qci*((.5-dx)**2)*(.5+dy)**2
c amu(i,n,m-1)=.5*qci*(.75-dx**2)*(.5-dy)**2
c amu(i,n+1,m-1)=.25*qci*((.5+dx)**2)*(.5-dy)**2
c amu(i,n-1,m-1)=.25*qci*((.5-dx)**2)*(.5-dy)**2
c where n,m = nearest grid points and dx = x-n, dy = y-m
c and qci = qm*pj*pk*gami2, where jk = xx-yy,xy,zx,zy, for i = 1, 4
c where pj = pj(t-dt/2) and pk = pk(t-dt/2)
c where gami2 = 1./(1.+sum(pi**2)*ci*ci)
c part(1,n,l) = position x of particle n at t in partition l
c part(2,n,l) = position y of particle n at t in partition l
c part(3,n,l) = x momentum of particle n at t - dt/2 in partition l
c part(4,n,l) = y momentum of particle n at t - dt/2 in partition l
c part(5,n,l) = z momentum of particle n at t - dt/2 in partition l
c amu(i,n,l) = ith component of momentum flux at grid point (j,kk),
c where n = j + nxv*k, and kk = k + noff(l) - 1
c npp(l) = number of particles in partition l
c noff(l) = lowermost global gridpoint in particle partition l.
c qm = charge on particle, in units of e
c ci = reciprical of velocity of light
c idimp = size of phase space = 5
c npmax = maximum number of particles in each partition
c nblok = number of particle partitions.
c nxv = first virtual dimension of current array, must be >= nx+3
c nxyp = first actual dimension of current array, must be >= nxv*nypmx
implicit none
integer npp, noff, idimp, npmax, nblok, nxv, nxyp
real part, amu, qm, ci
dimension part(idimp,npmax,nblok), amu(4,nxyp,nblok)
dimension npp(nblok), noff(nblok)
integer nnn, mmn, j, l, mnoff, nn, mm, ml, mn, mp
real dxn, dyn, qmh, ci2, gami2, dxp, dyp, amx, amy, dxl, dyl
real dx, dy, dz, vxn, vyn, vzn, vx, vy, vz, p2, v1, v2, v3, v4
real dx1, dy1, dx2, dy2, dx3
qmh = .5*qm
ci2 = ci*ci
do 20 l = 1, nblok
if (npp(l).lt.1) go to 20
mnoff = noff(l)
c begin first particle
nnn = part(1,1,l) + .5
mmn = part(2,1,l) + .5
dxn = part(1,1,l) - float(nnn)
dyn = part(2,1,l) - float(mmn)
c find inverse gamma
vxn = part(3,1,l)
vyn = part(4,1,l)
vzn = part(5,1,l)
p2 = vxn*vxn + vyn*vyn + vzn*vzn
gami2 = 1.0/(1.0 + p2*ci2)
mmn = mmn - mnoff
do 10 j = 2, npp(l)
c find interpolation weights
nn = nnn + 1
mm = nxv*mmn
nnn = part(1,j,l) + .5
mmn = part(2,j,l) + .5
dxp = dxn
dyp = dyn
dxn = part(1,j,l) - float(nnn)
dyn = part(2,j,l) - float(mmn)
ml = mm + nn
amx = qm*(.75 - dxp*dxp)
amy = .75 - dyp*dyp
mn = ml + nxv
dxl = qmh*(.5 - dxp)**2
dxp = qmh*(.5 + dxp)**2
mp = mn + nxv
dyl = .5*(.5 - dyp)**2
dyp = .5*(.5 + dyp)**2
mmn = mmn - mnoff
c calculate weights
dx = dxl*amy
dy = amx*amy
dz = dxp*amy
v1 = (vxn*vxn - vyn*vyn)*gami2
v2 = (vxn*vyn)*gami2
v3 = (vzn*vxn)*gami2
v4 = (vzn*vyn)*gami2
c get momentum for next particle
vxn = part(3,j,l)
vyn = part(4,j,l)
vzn = part(5,j,l)
p2 = vxn*vxn + vyn*vyn + vzn*vzn
c deposit momentum flux
dx1 = amu(1,mn,l) + v1*dx
dy1 = amu(2,mn,l) + v2*dx
amy = amu(3,mn,l) + v3*dx
vx = amu(4,mn,l) + v4*dx
dx2 = amu(1,mn+1,l) + v1*dy
dy2 = amu(2,mn+1,l) + v2*dy
dx3 = amu(3,mn+1,l) + v3*dy
vy = amu(4,mn+1,l) + v4*dy
dx = amu(1,mn+2,l) + v1*dz
dy = amu(2,mn+2,l) + v2*dz
vz = amu(3,mn+2,l) + v3*dz
dz = amu(4,mn+2,l) + v4*dz
amu(1,mn,l) = dx1
amu(2,mn,l) = dy1
amu(3,mn,l) = amy
amu(4,mn,l) = vx
amu(1,mn+1,l) = dx2
amu(2,mn+1,l) = dy2
amu(3,mn+1,l) = dx3
amu(4,mn+1,l) = vy
amu(1,mn+2,l) = dx
amu(2,mn+2,l) = dy
amu(3,mn+2,l) = vz
amu(4,mn+2,l) = dz
dx = dxl*dyl
dy = amx*dyl
dz = dxp*dyl
dx1 = amu(1,ml,l) + v1*dx
dy1 = amu(2,ml,l) + v2*dx
amy = amu(3,ml,l) + v3*dx
vx = amu(4,ml,l) + v4*dx
dx2 = amu(1,ml+1,l) + v1*dy
dy2 = amu(2,ml+1,l) + v2*dy
dyl = amu(3,ml+1,l) + v3*dy
vy = amu(4,ml+1,l) + v4*dy
dx = amu(1,ml+2,l) + v1*dz
dy = amu(2,ml+2,l) + v2*dz
vz = amu(3,ml+2,l) + v3*dz
dz = amu(4,ml+2,l) + v4*dz
amu(1,ml,l) = dx1
amu(2,ml,l) = dy1
amu(3,ml,l) = amy
amu(4,ml,l) = vx
amu(1,ml+1,l) = dx2
amu(2,ml+1,l) = dy2
amu(3,ml+1,l) = dyl
amu(4,ml+1,l) = vy
amu(1,ml+2,l) = dx
amu(2,ml+2,l) = dy
amu(3,ml+2,l) = vz
amu(4,ml+2,l) = dz
dx = dxl*dyp
dy = amx*dyp
dz = dxp*dyp
dx1 = amu(1,mp,l) + v1*dx
dy1 = amu(2,mp,l) + v2*dx
amy = amu(3,mp,l) + v3*dx
vx = amu(4,mp,l) + v4*dx
dxl = amu(1,mp+1,l) + v1*dy
amx = amu(2,mp+1,l) + v2*dy
dxp = amu(3,mp+1,l) + v3*dy
vy = amu(4,mp+1,l) + v4*dy
dx = amu(1,mp+2,l) + v1*dz
dy = amu(2,mp+2,l) + v2*dz
vz = amu(3,mp+2,l) + v3*dz
dz = amu(4,mp+2,l) + v4*dz
amu(1,mp,l) = dx1
amu(2,mp,l) = dy1
amu(3,mp,l) = amy
amu(4,mp,l) = vx
amu(1,mp+1,l) = dxl
amu(2,mp+1,l) = amx
amu(3,mp+1,l) = dxp
amu(4,mp+1,l) = vy
amu(1,mp+2,l) = dx
amu(2,mp+2,l) = dy
amu(3,mp+2,l) = vz
amu(4,mp+2,l) = dz
c find inverse gamma for next particle
gami2 = 1.0/(1.0 + p2*ci2)
10 continue
c deposit momentum flux for last particle
nn = nnn + 1
mm = nxv*mmn
amx = qm*(.75 - dxn*dxn)
amy = .75 - dyn*dyn
ml = mm + nn
dxl = qmh*(.5 - dxn)**2
dxp = qmh*(.5 + dxn)**2
mn = ml + nxv
dyl = .5*(.5 - dyn)**2
dyp = .5*(.5 + dyn)**2
mp = mn + nxv
c deposit momentum flux
dx = dxl*amy
dy = amx*amy
dz = dxp*amy
v1 = (vxn*vxn - vyn*vyn)*gami2
v2 = (vxn*vyn)*gami2
v3 = (vzn*vxn)*gami2
v4 = (vzn*vyn)*gami2
amu(1,mn,l) = amu(1,mn,l) + v1*dx
amu(2,mn,l) = amu(2,mn,l) + v2*dx
amu(3,mn,l) = amu(3,mn,l) + v3*dx
amu(4,mn,l) = amu(4,mn,l) + v4*dx
amu(1,mn+1,l) = amu(1,mn+1,l) + v1*dy
amu(2,mn+1,l) = amu(2,mn+1,l) + v2*dy
amu(3,mn+1,l) = amu(3,mn+1,l) + v3*dy
amu(4,mn+1,l) = amu(4,mn+1,l) + v4*dy
amu(1,mn+2,l) = amu(1,mn+2,l) + v1*dz
amu(2,mn+2,l) = amu(2,mn+2,l) + v2*dz
amu(3,mn+2,l) = amu(3,mn+2,l) + v3*dz
amu(4,mn+2,l) = amu(4,mn+2,l) + v4*dz
dx = dxl*dyl
dy = amx*dyl
dz = dxp*dyl
amu(1,ml,l) = amu(1,ml,l) + v1*dx
amu(2,ml,l) = amu(2,ml,l) + v2*dx
amu(3,ml,l) = amu(3,ml,l) + v3*dx
amu(4,ml,l) = amu(4,ml,l) + v4*dx
amu(1,ml+1,l) = amu(1,ml+1,l) + v1*dy
amu(2,ml+1,l) = amu(2,ml+1,l) + v2*dy
amu(3,ml+1,l) = amu(3,ml+1,l) + v3*dy
amu(4,ml+1,l) = amu(4,ml+1,l) + v4*dy
amu(1,ml+2,l) = amu(1,ml+2,l) + v1*dz
amu(2,ml+2,l) = amu(2,ml+2,l) + v2*dz
amu(3,ml+2,l) = amu(3,ml+2,l) + v3*dz
amu(4,ml+2,l) = amu(4,ml+2,l) + v4*dz
dx = dxl*dyp
dy = amx*dyp
dz = dxp*dyp
amu(1,mp,l) = amu(1,mp,l) + v1*dx
amu(2,mp,l) = amu(2,mp,l) + v2*dx
amu(3,mp,l) = amu(3,mp,l) + v3*dx
amu(4,mp,l) = amu(4,mp,l) + v4*dx
amu(1,mp+1,l) = amu(1,mp+1,l) + v1*dy
amu(2,mp+1,l) = amu(2,mp+1,l) + v2*dy
amu(3,mp+1,l) = amu(3,mp+1,l) + v3*dy
amu(4,mp+1,l) = amu(4,mp+1,l) + v4*dy
amu(1,mp+2,l) = amu(1,mp+2,l) + v1*dz
amu(2,mp+2,l) = amu(2,mp+2,l) + v2*dz
amu(3,mp+2,l) = amu(3,mp+2,l) + v3*dz
amu(4,mp+2,l) = amu(4,mp+2,l) + v4*dz
20 continue
return
end
c-----------------------------------------------------------------------
subroutine PGRDCJPOST2(part,fxy,bxy,npp,noff,cu,dcu,amu,qm,qbm,dt,
1ci,idimp,npmax,nblok,nxv,nypmx)
c for 2-1/2d code, this subroutine calculates particle momentum flux,
c acceleration density, and current density using second-order spline
c interpolation for relativistic particles.
c scalar version using guard cells, for distributed data
c 430 flops/particle, 2 divide, 1 sqrt, 150 loads, 80 stores
c input: all, output: cu, dcu, amu
c current density is approximated by values at the nearest grid points
c cu(i,n,m)=qci*(.75-dx**2)*(.75-dy**2)
c cu(i,n+1,m)=.5*qci*((.5+dx)**2)*(.75-dy**2)
c cu(i,n-1,m)=.5*qci*((.5-dx)**2)*(.75-dy**2)
c cu(i,n,m+1)=.5*qci*(.75-dx**2)*(.5+dy)**2
c cu(i,n+1,m+1)=.25*qci*((.5+dx)**2)*(.5+dy)**2
c cu(i,n-1,m+1)=.25*qci*((.5-dx)**2)*(.5+dy)**2
c cu(i,n,m-1)=.5*qci*(.75-dx**2)*(.5-dy)**2
c cu(i,n+1,m-1)=.25*qci*((.5+dx)**2)*(.5-dy)**2
c cu(i,n-1,m-1)=.25*qci*((.5-dx)**2)*(.5-dy)**2
c and qci = qm*pj*gami, where j = x,y,z, for i = 1, 3
c where pj = .5*(pj(t+dt/2)+pj(t-dt/2))
c where gami = 1./sqrt(1.+sum(pi**2)*ci*ci)
c acceleration density is approximated by values at the nearest grid
c points
c dcu(i,n,m)=qci*(.75-dx**2)*(.75-dy**2)
c dcu(i,n+1,m)=.5*qci*((.5+dx)**2)*(.75-dy**2)
c dcu(i,n-1,m)=.5*qci*((.5-dx)**2)*(.75-dy**2)
c dcu(i,n,m+1)=.5*qci*(.75-dx**2)*(.5+dy)**2
c dcu(i,n+1,m+1)=.25*qci*((.5+dx)**2)*(.5+dy)**2
c dcu(i,n-1,m+1)=.25*qci*((.5-dx)**2)*(.5+dy)**2
c dcu(i,n,m-1)=.5*qci*(.75-dx**2)*(.5-dy)**2
c dcu(i,n+1,m-1)=.25*qci*((.5+dx)**2)*(.5-dy)**2
c dcu(i,n-1,m-1)=.25*qci*((.5-dx)**2)*(.5-dy)**2
c and qci = qm*dvj*gami/dt, where j = x,y,z, for i = 1, 3
c where dvj = dpj - pj*gami*dgamma, dpj = (pj(t+dt/2)-pj(t-dt/2)),
c pj = .5*(pj(t+dt/2)+pj(t-dt/2)),
c dgamma = (q/m)*ci*ci*gami*(sum(pj*Ej))*dt,
c and Ej = jth component of electric field
c momentum flux is approximated by values at the nearest grid points
c amu(i,n,m)=qci*(.75-dx**2)*(.75-dy**2)
c amu(i,n+1,m)=.5*qci*((.5+dx)**2)*(.75-dy**2)
c amu(i,n-1,m)=.5*qci*((.5-dx)**2)*(.75-dy**2)
c amu(i,n,m+1)=.5*qci*(.75-dx**2)*(.5+dy)**2
c amu(i,n+1,m+1)=.25*qci*((.5+dx)**2)*(.5+dy)**2
c amu(i,n-1,m+1)=.25*qci*((.5-dx)**2)*(.5+dy)**2
c amu(i,n,m-1)=.5*qci*(.75-dx**2)*(.5-dy)**2
c amu(i,n+1,m-1)=.25*qci*((.5+dx)**2)*(.5-dy)**2
c amu(i,n-1,m-1)=.25*qci*((.5-dx)**2)*(.5-dy)**2
c and qci = qm*pj*pk*gami**2, where jk = xx-yy,xy,zx,zy, for i = 1, 4
c where pj = 0.5*(pj(t+dt/2)+pj(t-dt/2),
c and pk = 0.5*(pk(t+dt/2)+pk(t-dt/2))
c where n,m = nearest grid points and dx = x-n, dy = y-m
c momentum equations used are:
c px(t+dt/2) = rot(1)*(px(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(2)*(py(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(3)*(pz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt) +
c .5*(q/m)*fx(x(t),y(t))*dt)
c py(t+dt/2) = rot(4)*(px(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(5)*(py(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(6)*(pz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt) +
c .5*(q/m)*fy(x(t),y(t))*dt)
c pz(t+dt/2) = rot(7)*(px(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(8)*(py(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(9)*(pz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt) +
c .5*(q/m)*fz(x(t),y(t))*dt)
c where q/m is charge/mass, and the rotation matrix is given by:
c rot(1) = (1 - (om*dt/2)**2 + 2*(omx*dt/2)**2)/(1 + (om*dt/2)**2)
c rot(2) = 2*(omz*dt/2 + (omx*dt/2)*(omy*dt/2))/(1 + (om*dt/2)**2)
c rot(3) = 2*(-omy*dt/2 + (omx*dt/2)*(omz*dt/2))/(1 + (om*dt/2)**2)
c rot(4) = 2*(-omz*dt/2 + (omx*dt/2)*(omy*dt/2))/(1 + (om*dt/2)**2)
c rot(5) = (1 - (om*dt/2)**2 + 2*(omy*dt/2)**2)/(1 + (om*dt/2)**2)
c rot(6) = 2*(omx*dt/2 + (omy*dt/2)*(omz*dt/2))/(1 + (om*dt/2)**2)
c rot(7) = 2*(omy*dt/2 + (omx*dt/2)*(omz*dt/2))/(1 + (om*dt/2)**2)
c rot(8) = 2*(-omx*dt/2 + (omy*dt/2)*(omz*dt/2))/(1 + (om*dt/2)**2)
c rot(9) = (1 - (om*dt/2)**2 + 2*(omz*dt/2)**2)/(1 + (om*dt/2)**2)
c and om**2 = omx**2 + omy**2 + omz**2
c the rotation matrix is determined by:
c omx = (q/m)*bx(x(t),y(t))*gami, omy = (q/m)*by(x(t),y(t))*gami, and
c omz = (q/m)*bz(x(t),y(t))*gami.
c fx(x(t),y(t)), fy(x(t),y(t)), and fz(x(t),y(t))
c bx(x(t),y(t)), by(x(t),y(t)), and bz(x(t),y(t))
c are approximated by interpolation from the nearest grid points:
c fx(x,y) = (.75-dy**2)*((.75-dx**2)*fx(n,m)+(.5*(.5+dx)**2)*fx(n+1,m)+
c (.5*(.5-dx)**2)*fx(n-1,m)) + (.5*(.5+dy)**2)*((.75-dx**2)*fx(n,m+1)+
c (.5*(.5+dx)**2)*fx(n+1,m+1)+(.5*(.5-dx)**2)*fx(n-1,m+1)) +
c (.5*(.5-dy)**2)*((.75-dx**2)*fx(n,m-1)+(.5*(.5+dx)**2)*fx(n+1,m-1)+
c (.5*(.5-dx)**2)*fx(n-1,m-1))
c where n,m = nearest grid points and dx = x-n, dy = y-m
c similarly for fy(x,y), fz(x,y), bx(x,y), by(x,y), bz(x,y)
c part(1,n,l) = position x of particle n at t in partition l
c part(2,n,l) = position y of particle n at t in partition l
c part(3,n,l) = momentum px of particle n at t - dt/2 in partition l
c part(4,n,l) = momentum py of particle n at t - dt/2 in partition l
c part(5,n,l) = momentum pz of particle n at t - dt/2 in partition l
c fxy(1,j+1,k,l) = x component of force/charge at grid (j,kk)
c fxy(2,j+1,k,l) = y component of force/charge at grid (j,kk)
c fxy(3,j+1,k,l) = z component of force/charge at grid (j,kk)
c where kk = k + noff(l) - 1
c that is, convolution of electric field over particle shape
c bxy(1,j+1,k,l) = x component of magnetic field at grid (j,kk)
c bxy(2,j+1,k,l) = y component of magnetic field at grid (j,kk)
c bxy(3,j+1,k,l) = z component of magnetic field at grid (j,kk)
c npp(l) = number of particles in partition l
c noff(l) = lowermost global gridpoint in particle partition l.
c that is, the convolution of magnetic field over particle shape
c cu(i,j+1,k,l) = ith component of current density
c at grid point j,kk for i = 1, 3
c dcu(i,j+1,k,l) = ith component of acceleration density
c at grid point j,kk for i = 1, 3
c amu(i,j+1,k,l) = ith component of momentum flux
c at grid point j,kk for i = 1, 4
c qm = charge on particle, in units of e
c qbm = particle charge/mass ratio
c dt = time interval between successive calculations
c ci = reciprical of velocity of light
c idimp = size of phase space = 5
c npmax = maximum number of particles in each partition
c nblok = number of particle partitions.
c nxv = first dimension of flux array, must be >= nx+3
c nypmx = maximum size of particle partition, including guard cells.
implicit none
integer npp, noff, idimp, npmax, nblok, nxv, nypmx
real part, fxy, bxy, cu, dcu, amu, qm, qbm, dt, ci
dimension part(idimp,npmax,nblok)
dimension fxy(3,nxv,nypmx,nblok), bxy(3,nxv,nypmx,nblok)
dimension cu(3,nxv,nypmx,nblok), dcu(3,nxv,nypmx,nblok)
dimension amu(4,nxv,nypmx,nblok)
dimension npp(nblok), noff(nblok)
integer j, l, mnoff, nn, mm, nl, np, ml, mp
real qtmh, dti, ci2, gami, qtmg, gh, dxp, dyp, amx, amy, dxl, dyl
real dx, dy, dz, ox, oy, oz
real acx, acy, acz, omxt, omyt, omzt, omt, anorm
real rot1, rot2, rot3, rot4, rot5, rot6, rot7, rot8, rot9
real vx, vy, vz, p2, v1, v2, v3, v4
qtmh = .5*qbm*dt
dti = 1.0/dt
ci2 = ci*ci
do 20 l = 1, nblok
mnoff = noff(l) - 1
do 10 j = 1, npp(l)
c find interpolation weights
nn = part(1,j,l) + .5
mm = part(2,j,l) + .5
dxp = part(1,j,l) - float(nn)
dyp = part(2,j,l) - float(mm)
nl = nn + 1
ml = mm - mnoff
amx = .75 - dxp*dxp
mm = mm + 2
amy = .75 - dyp*dyp
nn = nl + 1
dxl = .5*(.5 - dxp)**2
np = nl + 2
dxp = .5*(.5 + dxp)**2
mm = ml + 1
dyl = .5*(.5 - dyp)**2
mp = mm + 1
dyp = .5*(.5 + dyp)**2
c find electric field
dx = amy*(dxl*fxy(1,nl,mm,l) + amx*fxy(1,nn,mm,l) + dxp*fxy(1,np,m
1m,l)) + dyl*(dxl*fxy(1,nl,ml,l) + amx*fxy(1,nn,ml,l) + dxp*fxy(1,n
2p,ml,l)) + dyp*(dxl*fxy(1,nl,mp,l) + amx*fxy(1,nn,mp,l) + dxp*fxy(
31,np,mp,l))
dy = amy*(dxl*fxy(2,nl,mm,l) + amx*fxy(2,nn,mm,l) + dxp*fxy(2,np,m
1m,l)) + dyl*(dxl*fxy(2,nl,ml,l) + amx*fxy(2,nn,ml,l) + dxp*fxy(2,n
2p,ml,l)) + dyp*(dxl*fxy(2,nl,mp,l) + amx*fxy(2,nn,mp,l) + dxp*fxy(
32,np,mp,l))
dz = amy*(dxl*fxy(3,nl,mm,l) + amx*fxy(3,nn,mm,l) + dxp*fxy(3,np,m
1m,l)) + dyl*(dxl*fxy(3,nl,ml,l) + amx*fxy(3,nn,ml,l) + dxp*fxy(3,n
2p,ml,l)) + dyp*(dxl*fxy(3,nl,mp,l) + amx*fxy(3,nn,mp,l) + dxp*fxy(
33,np,mp,l))
c calculate half impulse
dx = qtmh*dx
dy = qtmh*dy
dz = qtmh*dz
c half acceleration
vx = part(3,j,l)
vy = part(4,j,l)
vz = part(5,j,l)
acx = vx + dx
acy = vy + dy
acz = vz + dz
c find inverse gamma
p2 = acx*acx + acy*acy + acz*acz
gami = 1.0/sqrt(1.0 + p2*ci2)
c find magnetic field
ox = amy*(dxl*bxy(1,nl,mm,l) + amx*bxy(1,nn,mm,l) + dxp*bxy(1,np,m
1m,l)) + dyl*(dxl*bxy(1,nl,ml,l) + amx*bxy(1,nn,ml,l) + dxp*bxy(1,n
2p,ml,l)) + dyp*(dxl*bxy(1,nl,mp,l) + amx*bxy(1,nn,mp,l) + dxp*bxy(
31,np,mp,l))
oy = amy*(dxl*bxy(2,nl,mm,l) + amx*bxy(2,nn,mm,l) + dxp*bxy(2,np,m
1m,l)) + dyl*(dxl*bxy(2,nl,ml,l) + amx*bxy(2,nn,ml,l) + dxp*bxy(2,n
2p,ml,l)) + dyp*(dxl*bxy(2,nl,mp,l) + amx*bxy(2,nn,mp,l) + dxp*bxy(
32,np,mp,l))
oz = amy*(dxl*bxy(3,nl,mm,l) + amx*bxy(3,nn,mm,l) + dxp*bxy(3,np,m
1m,l)) + dyl*(dxl*bxy(3,nl,ml,l) + amx*bxy(3,nn,ml,l) + dxp*bxy(3,n
2p,ml,l)) + dyp*(dxl*bxy(3,nl,mp,l) + amx*bxy(3,nn,mp,l) + dxp*bxy(
33,np,mp,l))
c renormalize magnetic field
qtmg = qtmh*gami
gh = 0.5*gami
c calculate cyclotron frequency
omxt = qtmg*ox
omyt = qtmg*oy
omzt = qtmg*oz
qtmg = dti*gami
c calculate rotation matrix
omt = omxt*omxt + omyt*omyt + omzt*omzt
anorm = 2./(1. + omt)
omt = .5*(1. - omt)
rot4 = omxt*omyt
rot7 = omxt*omzt
rot8 = omyt*omzt
rot1 = omt + omxt*omxt
rot5 = omt + omyt*omyt
rot9 = omt + omzt*omzt
rot2 = rot4 + omzt
rot4 = rot4 - omzt
rot3 = rot7 - omyt
rot7 = rot7 + omyt
rot6 = rot8 + omxt
rot8 = rot8 - omxt
c new velocity
v1 = (rot1*acx + rot2*acy + rot3*acz)*anorm + dx
v2 = (rot4*acx + rot5*acy + rot6*acz)*anorm + dy
v3 = (rot7*acx + rot8*acy + rot9*acz)*anorm + dz
c deposit momentum flux, acceleration density, and current density
amx = qm*amx
dxl = qm*dxl
dxp = qm*dxp
ox = gh*(v1 + vx)
oy = gh*(v2 + vy)
oz = gh*(v3 + vz)
vx = v1 - vx
vy = v2 - vy
vz = v3 - vz
gh = 2.0*ci2*(ox*dx + oy*dy + oz*dz)
dx = dxl*amy
dy = amx*amy
dz = dxp*amy
v1 = ox*ox - oy*oy
v2 = ox*oy
v3 = oz*ox
v4 = oz*oy
vx = qtmg*(vx - ox*gh)
vy = qtmg*(vy - oy*gh)
vz = qtmg*(vz - oz*gh)
amu(1,nl,mm,l) = amu(1,nl,mm,l) + v1*dx
amu(2,nl,mm,l) = amu(2,nl,mm,l) + v2*dx
amu(3,nl,mm,l) = amu(3,nl,mm,l) + v3*dx
amu(4,nl,mm,l) = amu(4,nl,mm,l) + v4*dx
dcu(1,nl,mm,l) = dcu(1,nl,mm,l) + vx*dx
dcu(2,nl,mm,l) = dcu(2,nl,mm,l) + vy*dx
dcu(3,nl,mm,l) = dcu(3,nl,mm,l) + vz*dx
cu(1,nl,mm,l) = cu(1,nl,mm,l) + ox*dx
cu(2,nl,mm,l) = cu(2,nl,mm,l) + oy*dx
cu(3,nl,mm,l) = cu(3,nl,mm,l) + oz*dx
dx = dxl*dyl
amu(1,nn,mm,l) = amu(1,nn,mm,l) + v1*dy
amu(2,nn,mm,l) = amu(2,nn,mm,l) + v2*dy
amu(3,nn,mm,l) = amu(3,nn,mm,l) + v3*dy
amu(4,nn,mm,l) = amu(4,nn,mm,l) + v4*dy
dcu(1,nn,mm,l) = dcu(1,nn,mm,l) + vx*dy
dcu(2,nn,mm,l) = dcu(2,nn,mm,l) + vy*dy
dcu(3,nn,mm,l) = dcu(3,nn,mm,l) + vz*dy
cu(1,nn,mm,l) = cu(1,nn,mm,l) + ox*dy
cu(2,nn,mm,l) = cu(2,nn,mm,l) + oy*dy
cu(3,nn,mm,l) = cu(3,nn,mm,l) + oz*dy
dy = amx*dyl
amu(1,np,mm,l) = amu(1,np,mm,l) + v1*dz
amu(2,np,mm,l) = amu(2,np,mm,l) + v2*dz
amu(3,np,mm,l) = amu(3,np,mm,l) + v3*dz
amu(4,np,mm,l) = amu(4,np,mm,l) + v4*dz
dcu(1,np,mm,l) = dcu(1,np,mm,l) + vx*dz
dcu(2,np,mm,l) = dcu(2,np,mm,l) + vy*dz
dcu(3,np,mm,l) = dcu(3,np,mm,l) + vz*dz
cu(1,np,mm,l) = cu(1,np,mm,l) + ox*dz
cu(2,np,mm,l) = cu(2,np,mm,l) + oy*dz
cu(3,np,mm,l) = cu(3,np,mm,l) + oz*dz
dz = dxp*dyl
amu(1,nl,ml,l) = amu(1,nl,ml,l) + v1*dx
amu(2,nl,ml,l) = amu(2,nl,ml,l) + v2*dx
amu(3,nl,ml,l) = amu(3,nl,ml,l) + v3*dx
amu(4,nl,ml,l) = amu(4,nl,ml,l) + v4*dx
dcu(1,nl,ml,l) = dcu(1,nl,ml,l) + vx*dx
dcu(2,nl,ml,l) = dcu(2,nl,ml,l) + vy*dx
dcu(3,nl,ml,l) = dcu(3,nl,ml,l) + vz*dx
cu(1,nl,ml,l) = cu(1,nl,ml,l) + ox*dx
cu(2,nl,ml,l) = cu(2,nl,ml,l) + oy*dx
cu(3,nl,ml,l) = cu(3,nl,ml,l) + oz*dx
dx = dxl*dyp
amu(1,nn,ml,l) = amu(1,nn,ml,l) + v1*dy
amu(2,nn,ml,l) = amu(2,nn,ml,l) + v2*dy
amu(3,nn,ml,l) = amu(3,nn,ml,l) + v3*dy
amu(4,nn,ml,l) = amu(4,nn,ml,l) + v4*dy
dcu(1,nn,ml,l) = dcu(1,nn,ml,l) + vx*dy
dcu(2,nn,ml,l) = dcu(2,nn,ml,l) + vy*dy
dcu(3,nn,ml,l) = dcu(3,nn,ml,l) + vz*dy
cu(1,nn,ml,l) = cu(1,nn,ml,l) + ox*dy
cu(2,nn,ml,l) = cu(2,nn,ml,l) + oy*dy
cu(3,nn,ml,l) = cu(3,nn,ml,l) + oz*dy
dy = amx*dyp
amu(1,np,ml,l) = amu(1,np,ml,l) + v1*dz
amu(2,np,ml,l) = amu(2,np,ml,l) + v2*dz
amu(3,np,ml,l) = amu(3,np,ml,l) + v3*dz
amu(4,np,ml,l) = amu(4,np,ml,l) + v4*dz
dcu(1,np,ml,l) = dcu(1,np,ml,l) + vx*dz
dcu(2,np,ml,l) = dcu(2,np,ml,l) + vy*dz
dcu(3,np,ml,l) = dcu(3,np,ml,l) + vz*dz
cu(1,np,ml,l) = cu(1,np,ml,l) + ox*dz
cu(2,np,ml,l) = cu(2,np,ml,l) + oy*dz
cu(3,np,ml,l) = cu(3,np,ml,l) + oz*dz
dz = dxp*dyp
amu(1,nl,mp,l) = amu(1,nl,mp,l) + v1*dx
amu(2,nl,mp,l) = amu(2,nl,mp,l) + v2*dx
amu(3,nl,mp,l) = amu(3,nl,mp,l) + v3*dx
amu(4,nl,mp,l) = amu(4,nl,mp,l) + v4*dx
dcu(1,nl,mp,l) = dcu(1,nl,mp,l) + vx*dx
dcu(2,nl,mp,l) = dcu(2,nl,mp,l) + vy*dx
dcu(3,nl,mp,l) = dcu(3,nl,mp,l) + vz*dx
cu(1,nl,mp,l) = cu(1,nl,mp,l) + ox*dx
cu(2,nl,mp,l) = cu(2,nl,mp,l) + oy*dx
cu(3,nl,mp,l) = cu(3,nl,mp,l) + oz*dx
amu(1,nn,mp,l) = amu(1,nn,mp,l) + v1*dy
amu(2,nn,mp,l) = amu(2,nn,mp,l) + v2*dy
amu(3,nn,mp,l) = amu(3,nn,mp,l) + v3*dy
amu(4,nn,mp,l) = amu(4,nn,mp,l) + v4*dy
dcu(1,nn,mp,l) = dcu(1,nn,mp,l) + vx*dy
dcu(2,nn,mp,l) = dcu(2,nn,mp,l) + vy*dy
dcu(3,nn,mp,l) = dcu(3,nn,mp,l) + vz*dy
cu(1,nn,mp,l) = cu(1,nn,mp,l) + ox*dy
cu(2,nn,mp,l) = cu(2,nn,mp,l) + oy*dy
cu(3,nn,mp,l) = cu(3,nn,mp,l) + oz*dy
amu(1,np,mp,l) = amu(1,np,mp,l) + v1*dz
amu(2,np,mp,l) = amu(2,np,mp,l) + v2*dz
amu(3,np,mp,l) = amu(3,np,mp,l) + v3*dz
amu(4,np,mp,l) = amu(4,np,mp,l) + v4*dz
dcu(1,np,mp,l) = dcu(1,np,mp,l) + vx*dz
dcu(2,np,mp,l) = dcu(2,np,mp,l) + vy*dz
dcu(3,np,mp,l) = dcu(3,np,mp,l) + vz*dz
cu(1,np,mp,l) = cu(1,np,mp,l) + ox*dz
cu(2,np,mp,l) = cu(2,np,mp,l) + oy*dz
cu(3,np,mp,l) = cu(3,np,mp,l) + oz*dz
10 continue
20 continue
return
end
c-----------------------------------------------------------------------
subroutine PGSRDCJPOST2(part,fxy,bxy,npp,noff,cu,dcu,amu,qm,qbm,dt
1,ci,idimp,npmax,nblok,nxv,nxyp)
c for 2-1/2d code, this subroutine calculates particle momentum flux,
c acceleration density, and current density using second-order spline
c interpolation for relativistic particles.
c scalar version using guard cells, integer conversion precalculation,
c and 1d addressing, for distributed data
c 430 flops/particle, 2 divide, 1 sqrt, 150 loads, 80 stores
c input: all, output: cu, dcu, amu
c current density is approximated by values at the nearest grid points
c cu(i,n,m)=qci*(.75-dx**2)*(.75-dy**2)
c cu(i,n+1,m)=.5*qci*((.5+dx)**2)*(.75-dy**2)
c cu(i,n-1,m)=.5*qci*((.5-dx)**2)*(.75-dy**2)
c cu(i,n,m+1)=.5*qci*(.75-dx**2)*(.5+dy)**2
c cu(i,n+1,m+1)=.25*qci*((.5+dx)**2)*(.5+dy)**2
c cu(i,n-1,m+1)=.25*qci*((.5-dx)**2)*(.5+dy)**2
c cu(i,n,m-1)=.5*qci*(.75-dx**2)*(.5-dy)**2
c cu(i,n+1,m-1)=.25*qci*((.5+dx)**2)*(.5-dy)**2
c cu(i,n-1,m-1)=.25*qci*((.5-dx)**2)*(.5-dy)**2
c and qci = qm*pj*gami, where j = x,y,z, for i = 1, 3
c where pj = .5*(pj(t+dt/2)+pj(t-dt/2))
c where gami = 1./sqrt(1.+sum(pi**2)*ci*ci)
c acceleration density is approximated by values at the nearest grid
c points
c dcu(i,n,m)=qci*(.75-dx**2)*(.75-dy**2)
c dcu(i,n+1,m)=.5*qci*((.5+dx)**2)*(.75-dy**2)
c dcu(i,n-1,m)=.5*qci*((.5-dx)**2)*(.75-dy**2)
c dcu(i,n,m+1)=.5*qci*(.75-dx**2)*(.5+dy)**2
c dcu(i,n+1,m+1)=.25*qci*((.5+dx)**2)*(.5+dy)**2
c dcu(i,n-1,m+1)=.25*qci*((.5-dx)**2)*(.5+dy)**2
c dcu(i,n,m-1)=.5*qci*(.75-dx**2)*(.5-dy)**2
c dcu(i,n+1,m-1)=.25*qci*((.5+dx)**2)*(.5-dy)**2
c dcu(i,n-1,m-1)=.25*qci*((.5-dx)**2)*(.5-dy)**2
c and qci = qm*dvj*gami/dt, where j = x,y,z, for i = 1, 3
c where dvj = dpj - pj*gami*dgamma, dpj = (pj(t+dt/2)-pj(t-dt/2)),
c pj = .5*(pj(t+dt/2)+pj(t-dt/2)),
c dgamma = (q/m)*ci*ci*gami*(sum(pj*Ej))*dt,
c and Ej = jth component of electric field
c momentum flux is approximated by values at the nearest grid points
c amu(i,n,m)=qci*(.75-dx**2)*(.75-dy**2)
c amu(i,n+1,m)=.5*qci*((.5+dx)**2)*(.75-dy**2)
c amu(i,n-1,m)=.5*qci*((.5-dx)**2)*(.75-dy**2)
c amu(i,n,m+1)=.5*qci*(.75-dx**2)*(.5+dy)**2
c amu(i,n+1,m+1)=.25*qci*((.5+dx)**2)*(.5+dy)**2
c amu(i,n-1,m+1)=.25*qci*((.5-dx)**2)*(.5+dy)**2
c amu(i,n,m-1)=.5*qci*(.75-dx**2)*(.5-dy)**2
c amu(i,n+1,m-1)=.25*qci*((.5+dx)**2)*(.5-dy)**2
c amu(i,n-1,m-1)=.25*qci*((.5-dx)**2)*(.5-dy)**2
c and qci = qm*pj*pk*gami**2, where jk = xx-yy,xy,zx,zy, for i = 1, 4
c where pj = 0.5*(pj(t+dt/2)+pj(t-dt/2),
c and pk = 0.5*(pk(t+dt/2)+pk(t-dt/2))
c where n,m = nearest grid points and dx = x-n, dy = y-m
c momentum equations used are:
c px(t+dt/2) = rot(1)*(px(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(2)*(py(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(3)*(pz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt) +
c .5*(q/m)*fx(x(t),y(t))*dt)
c py(t+dt/2) = rot(4)*(px(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(5)*(py(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(6)*(pz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt) +
c .5*(q/m)*fy(x(t),y(t))*dt)
c pz(t+dt/2) = rot(7)*(px(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(8)*(py(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(9)*(pz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt) +
c .5*(q/m)*fz(x(t),y(t))*dt)
c where q/m is charge/mass, and the rotation matrix is given by:
c rot(1) = (1 - (om*dt/2)**2 + 2*(omx*dt/2)**2)/(1 + (om*dt/2)**2)
c rot(2) = 2*(omz*dt/2 + (omx*dt/2)*(omy*dt/2))/(1 + (om*dt/2)**2)
c rot(3) = 2*(-omy*dt/2 + (omx*dt/2)*(omz*dt/2))/(1 + (om*dt/2)**2)
c rot(4) = 2*(-omz*dt/2 + (omx*dt/2)*(omy*dt/2))/(1 + (om*dt/2)**2)
c rot(5) = (1 - (om*dt/2)**2 + 2*(omy*dt/2)**2)/(1 + (om*dt/2)**2)
c rot(6) = 2*(omx*dt/2 + (omy*dt/2)*(omz*dt/2))/(1 + (om*dt/2)**2)
c rot(7) = 2*(omy*dt/2 + (omx*dt/2)*(omz*dt/2))/(1 + (om*dt/2)**2)
c rot(8) = 2*(-omx*dt/2 + (omy*dt/2)*(omz*dt/2))/(1 + (om*dt/2)**2)
c rot(9) = (1 - (om*dt/2)**2 + 2*(omz*dt/2)**2)/(1 + (om*dt/2)**2)
c and om**2 = omx**2 + omy**2 + omz**2
c the rotation matrix is determined by:
c omx = (q/m)*bx(x(t),y(t))*gami, omy = (q/m)*by(x(t),y(t))*gami, and
c omz = (q/m)*bz(x(t),y(t))*gami.
c fx(x(t),y(t)), fy(x(t),y(t)), and fz(x(t),y(t))
c bx(x(t),y(t)), by(x(t),y(t)), and bz(x(t),y(t))
c are approximated by interpolation from the nearest grid points:
c fx(x,y) = (.75-dy**2)*((.75-dx**2)*fx(n,m)+(.5*(.5+dx)**2)*fx(n+1,m)+
c (.5*(.5-dx)**2)*fx(n-1,m)) + (.5*(.5+dy)**2)*((.75-dx**2)*fx(n,m+1)+
c (.5*(.5+dx)**2)*fx(n+1,m+1)+(.5*(.5-dx)**2)*fx(n-1,m+1)) +
c (.5*(.5-dy)**2)*((.75-dx**2)*fx(n,m-1)+(.5*(.5+dx)**2)*fx(n+1,m-1)+
c (.5*(.5-dx)**2)*fx(n-1,m-1))
c where n,m = nearest grid points and dx = x-n, dy = y-m
c similarly for fy(x,y), fz(x,y), bx(x,y), by(x,y), bz(x,y)
c part(1,n,l) = position x of particle n at t in partition l
c part(2,n,l) = position y of particle n at t in partition l
c part(3,n,l) = momentum px of particle n at t - dt/2 in partition l
c part(4,n,l) = momentum py of particle n at t - dt/2 in partition l
c part(5,nv) = momentum pz of particle n at t - dt/2 in partition l
c fxy(1,j+1,k+1,l) = x component of force/charge at grid (j,kk)
c fxy(2,j+1,k+1,l) = y component of force/charge at grid (j,kk)
c fxy(3,j+1,k+1,l) = z component of force/charge at grid (j,kk)
c that is, convolution of electric field over particle shape
c where kk = k + noff(l) - 1
c bxy(1,j+1,k+1,l) = x component of magnetic field at grid (j,kk)
c bxy(2,j+1,k+1,l) = y component of magnetic field at grid (j,kk)
c bxy(3,j+1,k+1,l) = z component of magnetic field at grid (j,kk)
c that is, the convolution of magnetic field over particle shape
c npp(l) = number of particles in partition l
c noff(l) = lowermost global gridpoint in particle partition l.
c cu(i,n,l) = ith component of current density at grid point j,kk
c where n = j + nxv*k, for i = 1, 3
c dcu(i,n,l) = ith component of acceleration density at grid point j,kk
c where n = j + nxv*k, for i = 1, 3
c amu(i,n,l) = ith component of momentum flux at grid point j,kk
c where n = j + nxv*k, for i = 1, 4
c qm = charge on particle, in units of e
c qbm = particle charge/mass ratio
c dt = time interval between successive calculations
c ci = reciprical of velocity of light
c idimp = size of phase space = 5
c npmax = maximum number of particles in each partition
c nblok = number of particle partitions.
c nxv = first dimension of field arrays, must be >= nx+3
c nxyp = second actual dimension of field array, must be >= nxv*nypmx
implicit none
integer npp, noff, idimp, npmax, nblok, nxv, nxyp
real part, fxy, bxy, cu, dcu, amu, qm, qbm, dt, ci
dimension part(idimp,npmax,nblok)
dimension fxy(3,nxyp,nblok), bxy(3,nxyp,nblok)
dimension cu(3,nxyp,nblok), dcu(3,nxyp,nblok), amu(4,nxyp,nblok)
dimension npp(nblok), noff(nblok)
integer nop1, j, l, mnoff, nop, nnn, mmn, nn, mm, ml, mn, mp
real qtmh, dti, ci2, gami, qtmg, gh, dxn, dyn
real dxp, dyp, amx, amy, dxl, dyl, dx, dy, dz, ox, oy, oz
real acx, acy, acz, omxt, omyt, omzt, omt, anorm
real rot1, rot2, rot3, rot4, rot5, rot6, rot7, rot8, rot9
real vx, vy, vz, p2, v1, v2, v3, v4
real dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4, dx5, dy5, dx6
qtmh = .5*qbm*dt
dti = 1.0/dt
ci2 = ci*ci
do 20 l = 1, nblok
if (npp(l).lt.1) go to 20
mnoff = noff(l)
c begin first particle
nnn = part(1,1,l) + .5
mmn = part(2,1,l) + .5
dxn = part(1,1,l) - float(nnn)
dyn = part(2,1,l) - float(mmn)
mmn = mmn - mnoff
nop1 = npp(l) - 1
do 10 j = 1, nop1
c find interpolation weights
nn = nnn + 1
mm = nxv*mmn
nnn = part(1,j+1,l) + .5
mmn = part(2,j+1,l) + .5
dx = dxn
dy = dyn
dxn = part(1,j+1,l) - float(nnn)
dyn = part(2,j+1,l) - float(mmn)
ml = mm + nn
amx = .75 - dx*dx
amy = .75 - dy*dy
mn = ml + nxv
dxl = .5*(.5 - dx)**2
dxp = .5*(.5 + dx)**2
mp = mn + nxv
dyl = .5*(.5 - dy)**2
dyp = .5*(.5 + dy)**2
mmn = mmn - mnoff
c find electric field
dx = amy*(dxl*fxy(1,mn,l) + amx*fxy(1,mn+1,l) + dxp*fxy(1,mn+2,l))
1 + dyl*(dxl*fxy(1,ml,l) + amx*fxy(1,ml+1,l) + dxp*fxy(1,ml+2,l)) +
2 dyp*(dxl*fxy(1,mp,l) + amx*fxy(1,mp+1,l) + dxp*fxy(1,mp+2,l))
dy = amy*(dxl*fxy(2,mn,l) + amx*fxy(2,mn+1,l) + dxp*fxy(2,mn+2,l))
1 + dyl*(dxl*fxy(2,ml,l) + amx*fxy(2,ml+1,l) + dxp*fxy(2,ml+2,l)) +
2 dyp*(dxl*fxy(2,mp,l) + amx*fxy(2,mp+1,l) + dxp*fxy(2,mp+2,l))
dz = amy*(dxl*fxy(3,mn,l) + amx*fxy(3,mn+1,l) + dxp*fxy(3,mn+2,l))
1 + dyl*(dxl*fxy(3,ml,l) + amx*fxy(3,ml+1,l) + dxp*fxy(3,ml+2,l)) +
2 dyp*(dxl*fxy(3,mp,l) + amx*fxy(3,mp+1,l) + dxp*fxy(3,mp+2,l))
c calculate half impulse
dx = qtmh*dx
dy = qtmh*dy
dz = qtmh*dz
c half acceleration
vx = part(3,j,l)
vy = part(4,j,l)
vz = part(5,j,l)
acx = vx + dx
acy = vy + dy
acz = vz + dz
c find inverse gamma
p2 = acx*acx + acy*acy + acz*acz
gami = 1.0/sqrt(1.0 + p2*ci2)
c find magnetic field
ox = amy*(dxl*bxy(1,mn,l) + amx*bxy(1,mn+1,l) + dxp*bxy(1,mn+2,l))
1 + dyl*(dxl*bxy(1,ml,l) + amx*bxy(1,ml+1,l) + dxp*bxy(1,ml+2,l)) +
2 dyp*(dxl*bxy(1,mp,l) + amx*bxy(1,mp+1,l) + dxp*bxy(1,mp+2,l))
oy = amy*(dxl*bxy(2,mn,l) + amx*bxy(2,mn+1,l) + dxp*bxy(2,mn+2,l))
1 + dyl*(dxl*bxy(2,ml,l) + amx*bxy(2,ml+1,l) + dxp*bxy(2,ml+2,l)) +
2 dyp*(dxl*bxy(2,mp,l) + amx*bxy(2,mp+1,l) + dxp*bxy(2,mp+2,l))
oz = amy*(dxl*bxy(3,mn,l) + amx*bxy(3,mn+1,l) + dxp*bxy(3,mn+2,l))
1 + dyl*(dxl*bxy(3,ml,l) + amx*bxy(3,ml+1,l) + dxp*bxy(3,ml+2,l)) +
2 dyp*(dxl*bxy(3,mp,l) + amx*bxy(3,mp+1,l) + dxp*bxy(3,mp+2,l))
c renormalize magnetic field
qtmg = qtmh*gami
gh = 0.5*gami
c calculate cyclotron frequency
omxt = qtmg*ox
omyt = qtmg*oy
omzt = qtmg*oz
qtmg = dti*gami
c calculate rotation matrix
omt = omxt*omxt + omyt*omyt + omzt*omzt
anorm = 2./(1. + omt)