-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprbpush2lib.f
6711 lines (6711 loc) · 242 KB
/
prbpush2lib.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
c magnetic field and depositing current
c prbpush2lib.f contains procedures to process relativistic particles
c with and without magnetic fields:
c PGRJPOST2 deposits 3 component current density, quadratic
c interpolation, STANDARD optimization, for relativistic
c particles, and distributed data.
c PGSRJPOST2 deposits 3 component current density, quadratic
c interpolation, LOOKAHEAD optimization, for relativistic
c particles, and distributed data.
c PGSRJOST2X deposits 3 component current density, quadratic
c interpolation, VECTOR optimization, for relativistic
c particles, and distributed data.
c PGRJPOST2L deposits 3 component current density, linear interpolation,
c STANDARD optimization, for relativistic particles, and
c distributed data.
c PGSRJPOST2L deposits 3 component current density, linear
c interpolation, LOOKAHEAD optimization, for relativistic
c particles, and distributed data.
c PGSRJOST2XL deposits 3 component current density, linear
c interpolation, VECTOR optimization, for relativistic
c particles, and distributed data.
c PGRJPOST22 deposits 2 component current density, quadratic
c interpolation, STANDARD optimization, for relativistic
c particles, and distributed data.
c PGSRJPOST22 deposits 2 component current density, quadratic
c interpolation, LOOKAHEAD optimization, for relativistic
c particles, and distributed data.
c PGSRJOST22X deposits 2 component current density, quadratic
c interpolation, VECTOR optimization, for relativistic
c particles, and distributed data.
c PGRJPOST22L deposits 2 component current density, linear
c interpolation, STANDARD optimization, for relativistic
c particles, and distributed data.
c PGSRJPOST22L deposits 2 component current density, linear
c interpolation, LOOKAHEAD optimization, for relativistic
c particles, and distributed data.
c PGSRJOST22XL deposits 2 component current density, linear
c interpolation, VECTOR optimization, for relativistic
c particles, and distributed data.
c PGRPUSH2 push particles with 2 component electric field, quadratic
c interpolation, STANDARD optimization, for relativistic
c particles, and distributed data.
c PGSRPUSH2 push particles with 2 component electric field, quadratic
c interpolation, LOOKAHEAD optimization, for relativistic
c particles, and distributed data.
c PGRPUSH2L push particles with 2 component electric field, linear
c interpolation, STANDARD optimization, for relativistic
c particles, and distributed data.
c PGSRPUSH2L push particles with 2 component electric field, linear
c interpolation, LOOKAHEAD optimization, for relativistic
c particles, and distributed data.
c PGRBPUSH2 push particles with 3 component magnetic field, 2 component
c electric field, quadratic interpolation, STANDARD
c optimization, for relativistic particles, and distributed
c data.
c PGSRBPUSH2 push particles with 3 component magnetic field, 2 component
c electric field, quadratic interpolation, LOOKAHEAD
c optimization, for relativistic particles, and distributed
c data.
c PGRBPUSH2L push particles with 3 component magnetic field, 2 component
c electric field, linear interpolation, STANDARD optimization,
c for relativistic particles, and distributed data.
c PGSRBPUSH2L push particles with 3 component magnetic field, 2 component
c electric field, linear interpolation, LOOKAHEAD
c optimization, for relativistic particles, and distributed
c data.
c PGRBPUSH23 push particles with 3 component magnetic field, 3 component
c electric field, quadratic interpolation, STANDARD
c optimization, for relativistic particles, and distributed
c data.
c PGSRBPUSH23 push particles with 3 component magnetic field, 3 component
c electric field, quadratic interpolation, LOOKAHEAD
c optimization, for relativistic particles, and distributed
c data.
c PGRBPUSH23L push particles with 3 component magnetic field, 3 component
c electric field, linear interpolation, STANDARD
c optimization, for relativistic particles, and distributed
c data.
c PGSRBPUSH23L push particles with 3 component magnetic field,
c 3 component electric field, linear interpolation,
c LOOKAHEAD optimization, for relativistic particles, and
c distributed data.
c PGRBPUSH22 push particles with 1 component magnetic field, 2 component
c electric field, quadratic interpolation, STANDARD
c optimization, for relativistic particles, and distributed
c data.
c PGSRBPUSH22 push particles with 1 component magnetic field,
c 2 component electric field, quadratic interpolation,
c LOOKAHEAD optimization, for relativistic particles, and
c distributed data.
c PGRBPUSH22L push particles with 1 component magnetic field,
c 2 component electric field, linear interpolation, STANDARD
c optimization, for relativistic particles, and distributed
c data.
c PGSRBPUSH22L push particles with 1 component magnetic field,
c 2 component electric field, linear interpolation,
c LOOKAHEAD optimization, for relativistic particles, and
c distributed data.
c PRRETARD2 retard particle position a half time-step for 2-1/2d code,
c and relativistic particles, and distributed data.
c PRRETARD22 retard particle position a half time-step for 2d code,
c and relativistic particles, and distributed data.
c PCPTOV2 converts momentum to velocity for relativistic particles for
c 2-1/2d code, and distributed data.
c PCPTOV22 converts momentum to velocity for relativistic particles for
c 2d code, and distributed data.
c PRPUSH2ZF update particle co-ordinates for particles with fixed
c velocities, for 2d code, and relativistic particles, and
c distributed data.
c PRPUSH23ZF update particle co-ordinates for particles with fixed
c velocities, for 2-1/2d code, and relativistic particles,
c and distributed data.
c PGRCJPOST2 deposits time-centered particle current density, quadratic
c interpolation, for relativistic particles, and distributed
c data.
c PGRCJPOST2L deposits time-centered particle current density, linear
c interpolation, for relativistic particles, and distributed
c data.
c written by viktor k. decyk, ucla
c copyright 1999, regents of the university of california
c update: august 29, 2009
c-----------------------------------------------------------------------
subroutine PGRJPOST2(part,cu,npp,noff,qm,dt,ci,nx,ny,idimp,npmax,n
1blok,nxv,nypmx,ipbc)
c for 2-1/2d code, this subroutine calculates particle current density
c using second-order spline interpolation for relativistic particles,
c and distributed data.
c in addition, particle positions are advanced a half time-step
c scalar version using guard cells, for distributed data
c 86 flops/particle, 1 divide, 1 sqrt, 32 loads, 29 stores
c input: all, output: part, cu
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 where n,m = nearest grid points and dx = x-n, dy = y-m
c and qci = qm*pi*gami, where i = x,y,z
c where gami = 1./sqrt(1.+sum(pi**2)*ci*ci)
c part(1,n,l) = position x of particle n in partition l
c part(2,n,l) = position y of particle n in partition l
c part(3,n,l) = x momentum of particle n in partition l
c part(4,n,l) = y momentum of particle n in partition l
c part(5,n,l) = z momentum of particle n in partition l
c cu(i,j+1,k,l) = ith component of current density 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 dt = time interval between successive calculations
c ci = reciprical of velocity of light
c nx/ny = system length in x/y direction
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 current array, must be >= nx+3
c nypmx = maximum size of particle partition, including guard cells.
c ipbc = particle boundary condition = (0,1,2,3) =
c (none,2d periodic,2d reflecting,mixed reflecting/periodic)
dimension part(idimp,npmax,nblok), cu(3,nxv,nypmx,nblok)
dimension npp(nblok), noff(nblok)
qmh = .5*qm
ci2 = ci*ci
c set boundary values
if (ipbc.eq.1) then
edgelx = 0.
edgerx = float(nx)
else if (ipbc.eq.2) then
edgelx = 1.
edgely = 1.
edgerx = float(nx-1)
edgery = float(ny-1)
else if (ipbc.eq.3) then
edgelx = 1.
edgerx = float(nx-1)
endif
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
gami = 1.0/sqrt(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 current
dx = dxl*amy
dy = amx*amy
dz = dxp*amy
vx = vx*gami
vy = vy*gami
vz = vz*gami
cu(1,nl,mm,l) = cu(1,nl,mm,l) + vx*dx
cu(2,nl,mm,l) = cu(2,nl,mm,l) + vy*dx
cu(3,nl,mm,l) = cu(3,nl,mm,l) + vz*dx
dx = dxl*dyl
cu(1,nn,mm,l) = cu(1,nn,mm,l) + vx*dy
cu(2,nn,mm,l) = cu(2,nn,mm,l) + vy*dy
cu(3,nn,mm,l) = cu(3,nn,mm,l) + vz*dy
dy = amx*dyl
cu(1,np,mm,l) = cu(1,np,mm,l) + vx*dz
cu(2,np,mm,l) = cu(2,np,mm,l) + vy*dz
cu(3,np,mm,l) = cu(3,np,mm,l) + vz*dz
dz = dxp*dyl
cu(1,nl,ml,l) = cu(1,nl,ml,l) + vx*dx
cu(2,nl,ml,l) = cu(2,nl,ml,l) + vy*dx
cu(3,nl,ml,l) = cu(3,nl,ml,l) + vz*dx
dx = dxl*dyp
cu(1,nn,ml,l) = cu(1,nn,ml,l) + vx*dy
cu(2,nn,ml,l) = cu(2,nn,ml,l) + vy*dy
cu(3,nn,ml,l) = cu(3,nn,ml,l) + vz*dy
dy = amx*dyp
cu(1,np,ml,l) = cu(1,np,ml,l) + vx*dz
cu(2,np,ml,l) = cu(2,np,ml,l) + vy*dz
cu(3,np,ml,l) = cu(3,np,ml,l) + vz*dz
dz = dxp*dyp
cu(1,nl,mp,l) = cu(1,nl,mp,l) + vx*dx
cu(2,nl,mp,l) = cu(2,nl,mp,l) + vy*dx
cu(3,nl,mp,l) = cu(3,nl,mp,l) + vz*dx
cu(1,nn,mp,l) = cu(1,nn,mp,l) + vx*dy
cu(2,nn,mp,l) = cu(2,nn,mp,l) + vy*dy
cu(3,nn,mp,l) = cu(3,nn,mp,l) + vz*dy
cu(1,np,mp,l) = cu(1,np,mp,l) + vx*dz
cu(2,np,mp,l) = cu(2,np,mp,l) + vy*dz
cu(3,np,mp,l) = cu(3,np,mp,l) + vz*dz
c advance position half a time-step
dx = part(1,j,l) + vx*dt
dy = part(2,j,l) + vy*dt
c periodic boundary conditions
if (ipbc.eq.1) then
if (dx.lt.edgelx) dx = dx + edgerx
if (dx.ge.edgerx) dx = dx - edgerx
c reflecting boundary conditions
else if (ipbc.eq.2) then
if ((dx.lt.edgelx).or.(dx.ge.edgerx)) then
dx = part(1,j,l)
part(3,j,l) = -part(3,j,l)
endif
if ((dy.lt.edgely).or.(dy.ge.edgery)) then
dy = part(2,j,l)
part(4,j,l) = -part(4,j,l)
endif
c mixed reflecting/periodic boundary conditions
else if (ipbc.eq.3) then
if ((dx.lt.edgelx).or.(dx.ge.edgerx)) then
dx = part(1,j,l)
part(3,j,l) = -part(3,j,l)
endif
endif
c set new position
part(1,j,l) = dx
part(2,j,l) = dy
10 continue
20 continue
return
end
c-----------------------------------------------------------------------
subroutine PGSRJPOST2(part,cu,npp,noff,qm,dt,ci,nx,ny,idimp,npmax,
1nblok,nxv,nxyp,ipbc)
c for 2-1/2d code, this subroutine calculates particle current density
c using second-order spline interpolation for relativistic particles,
c and distributed data.
c in addition, particle positions are advanced a half time-step
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 86 flops/particle, 1 divide, 1 sqrt, 32 loads, 29 stores
c input: all, output: part, cu
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 where n,m = nearest grid points and dx = x-n, dy = y-m
c and qci = qm*pi*gami, where i = x,y,z
c where gami = 1./sqrt(1.+sum(pi**2)*ci*ci)
c part(1,n,l) = position x of particle n in partition l
c part(2,n,l) = position y of particle n in partition l
c part(3,n,l) = x momentum of particle n in partition l
c part(4,n,l) = y momentum of particle n in partition l
c part(5,n,l) = z momentum of particle n in partition l
c cu(i,j+1,k,l) = ith component of current density 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 dt = time interval between successive calculations
c ci = reciprical of velocity of light
c nx/ny = system length in x/y direction
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
c ipbc = particle boundary condition = (0,1,2,3) =
c (none,2d periodic,2d reflecting,mixed reflecting/periodic)
dimension part(idimp,npmax,nblok), cu(3,nxyp,nblok)
dimension npp(nblok), noff(nblok)
qmh = .5*qm
ci2 = ci*ci
c set boundary values
if (ipbc.eq.1) then
edgelx = 0.
edgerx = float(nx)
else if (ipbc.eq.2) then
edgelx = 1.
edgely = 1.
edgerx = float(nx-1)
edgery = float(ny-1)
else if (ipbc.eq.3) then
edgelx = 1.
edgerx = float(nx-1)
endif
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
gami = 1.0/sqrt(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
vx = vxn*gami
vy = vyn*gami
vz = vzn*gami
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 current
dx1 = cu(1,mn,l) + vx*dx
dy1 = cu(2,mn,l) + vy*dx
amy = cu(3,mn,l) + vz*dx
dx2 = cu(1,mn+1,l) + vx*dy
dy2 = cu(2,mn+1,l) + vy*dy
dx3 = cu(3,mn+1,l) + vz*dy
dx = cu(1,mn+2,l) + vx*dz
dy = cu(2,mn+2,l) + vy*dz
dz = cu(3,mn+2,l) + vz*dz
cu(1,mn,l) = dx1
cu(2,mn,l) = dy1
cu(3,mn,l) = amy
cu(1,mn+1,l) = dx2
cu(2,mn+1,l) = dy2
cu(3,mn+1,l) = dx3
cu(1,mn+2,l) = dx
cu(2,mn+2,l) = dy
cu(3,mn+2,l) = dz
dx = dxl*dyl
dy = amx*dyl
dz = dxp*dyl
dx1 = cu(1,ml,l) + vx*dx
dy1 = cu(2,ml,l) + vy*dx
amy = cu(3,ml,l) + vz*dx
dx2 = cu(1,ml+1,l) + vx*dy
dy2 = cu(2,ml+1,l) + vy*dy
dyl = cu(3,ml+1,l) + vz*dy
dx = cu(1,ml+2,l) + vx*dz
dy = cu(2,ml+2,l) + vy*dz
dz = cu(3,ml+2,l) + vz*dz
cu(1,ml,l) = dx1
cu(2,ml,l) = dy1
cu(3,ml,l) = amy
cu(1,ml+1,l) = dx2
cu(2,ml+1,l) = dy2
cu(3,ml+1,l) = dyl
cu(1,ml+2,l) = dx
cu(2,ml+2,l) = dy
cu(3,ml+2,l) = dz
dx = dxl*dyp
dy = amx*dyp
dz = dxp*dyp
dx1 = cu(1,mp,l) + vx*dx
dy1 = cu(2,mp,l) + vy*dx
amy = cu(3,mp,l) + vz*dx
dxl = cu(1,mp+1,l) + vx*dy
amx = cu(2,mp+1,l) + vy*dy
dxp = cu(3,mp+1,l) + vz*dy
dx = cu(1,mp+2,l) + vx*dz
dy = cu(2,mp+2,l) + vy*dz
dz = cu(3,mp+2,l) + vz*dz
cu(1,mp,l) = dx1
cu(2,mp,l) = dy1
cu(3,mp,l) = amy
cu(1,mp+1,l) = dxl
cu(2,mp+1,l) = amx
cu(3,mp+1,l) = dxp
cu(1,mp+2,l) = dx
cu(2,mp+2,l) = dy
cu(3,mp+2,l) = dz
c find inverse gamma for next particle
gami = 1.0/sqrt(1.0 + p2*ci2)
c advance position half a time-step
dx = part(1,j-1,l) + vx*dt
dy = part(2,j-1,l) + vy*dt
c periodic boundary conditions
if (ipbc.eq.1) then
if (dx.lt.edgelx) dx = dx + edgerx
if (dx.ge.edgerx) dx = dx - edgerx
c reflecting boundary conditions
else if (ipbc.eq.2) then
if ((dx.lt.edgelx).or.(dx.ge.edgerx)) then
dx = part(1,j-1,l)
part(3,j-1,l) = -part(3,j-1,l)
endif
if ((dy.lt.edgely).or.(dy.ge.edgery)) then
dy = part(2,j-1,l)
part(4,j-1,l) = -part(4,j-1,l)
endif
c mixed reflecting/periodic boundary conditions
else if (ipbc.eq.3) then
if ((dx.lt.edgelx).or.(dx.ge.edgerx)) then
dx = part(1,j-1,l)
part(3,j-1,l) = -part(3,j-1,l)
endif
endif
c set new position
part(1,j-1,l) = dx
part(2,j-1,l) = dy
10 continue
nop = npp(l)
c deposit current for last particle
nn = nnn + 1
mm = nxv*mmn
ml = mm + nn
amx = qm*(.75 - dxn*dxn)
amy = .75 - dyn*dyn
mn = ml + nxv
dxl = qmh*(.5 - dxn)**2
dxp = qmh*(.5 + dxn)**2
mp = mn + nxv
dyl = .5*(.5 - dyn)**2
dyp = .5*(.5 + dyn)**2
c deposit current
dx = dxl*amy
dy = amx*amy
dz = dxp*amy
vx = vxn*gami
vy = vyn*gami
vz = vzn*gami
cu(1,mn,l) = cu(1,mn,l) + vx*dx
cu(2,mn,l) = cu(2,mn,l) + vy*dx
cu(3,mn,l) = cu(3,mn,l) + vz*dx
cu(1,mn+1,l) = cu(1,mn+1,l) + vx*dy
cu(2,mn+1,l) = cu(2,mn+1,l) + vy*dy
cu(3,mn+1,l) = cu(3,mn+1,l) + vz*dy
cu(1,mn+2,l) = cu(1,mn+2,l) + vx*dz
cu(2,mn+2,l) = cu(2,mn+2,l) + vy*dz
cu(3,mn+2,l) = cu(3,mn+2,l) + vz*dz
dx = dxl*dyl
dy = amx*dyl
dz = dxp*dyl
cu(1,ml,l) = cu(1,ml,l) + vx*dx
cu(2,ml,l) = cu(2,ml,l) + vy*dx
cu(3,ml,l) = cu(3,ml,l) + vz*dx
cu(1,ml+1,l) = cu(1,ml+1,l) + vx*dy
cu(2,ml+1,l) = cu(2,ml+1,l) + vy*dy
cu(3,ml+1,l) = cu(3,ml+1,l) + vz*dy
cu(1,ml+2,l) = cu(1,ml+2,l) + vx*dz
cu(2,ml+2,l) = cu(2,ml+2,l) + vy*dz
cu(3,ml+2,l) = cu(3,ml+2,l) + vz*dz
dx = dxl*dyp
dy = amx*dyp
dz = dxp*dyp
cu(1,mp,l) = cu(1,mp,l) + vx*dx
cu(2,mp,l) = cu(2,mp,l) + vy*dx
cu(3,mp,l) = cu(3,mp,l) + vz*dx
cu(1,mp+1,l) = cu(1,mp+1,l) + vx*dy
cu(2,mp+1,l) = cu(2,mp+1,l) + vy*dy
cu(3,mp+1,l) = cu(3,mp+1,l) + vz*dy
cu(1,mp+2,l) = cu(1,mp+2,l) + vx*dz
cu(2,mp+2,l) = cu(2,mp+2,l) + vy*dz
cu(3,mp+2,l) = cu(3,mp+2,l) + vz*dz
c advance position half a time-step
dx = part(1,nop,l) + vx*dt
dy = part(2,nop,l) + vy*dt
c periodic boundary conditions
if (ipbc.eq.1) then
if (dx.lt.edgelx) dx = dx + edgerx
if (dx.ge.edgerx) dx = dx - edgerx
c reflecting boundary conditions
else if (ipbc.eq.2) then
if ((dx.lt.edgelx).or.(dx.ge.edgerx)) then
dx = part(1,nop,l)
part(3,nop,l) = -part(3,nop,l)
endif
if ((dy.lt.edgely).or.(dy.ge.edgery)) then
dy = part(2,nop,l)
part(4,nop,l) = -part(4,nop,l)
endif
c mixed reflecting/periodic boundary conditions
else if (ipbc.eq.3) then
if ((dx.lt.edgelx).or.(dx.ge.edgerx)) then
dx = part(1,nop,l)
part(3,nop,l) = -part(3,nop,l)
endif
endif
c set new position
part(1,nop,l) = dx
part(2,nop,l) = dy
20 continue
return
end
c-----------------------------------------------------------------------
subroutine PGSRJOST2X(part,cu,npp,noff,nn,amxy,qm,dt,ci,nx,ny,idim
1p,npmax,nblok,nxv,nxvyp,npd,n27,ipbc)
c for 2-1/2d code, this subroutine calculates particle current density
c using second-order spline interpolation for relativistic particles,
c with short vectors over independent weights, and distributed data,
c as in j. schwartzmeier and t. hewitt, proc. 12th conf. on numerical
c simulation of plasmas, san francisco, ca, 1987.
c in addition, particle positions are advanced a half time-step
c vectorized version with guard cells and 1d addressing
c 86 flops/particle, 1 divide, 1 sqrt, 87 loads, 83 stores
c input: all, output: part, cu
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 where n,m = nearest grid points and dx = x-n, dy = y-m
c and qci = qm*pi*gami, where i = x,y,z
c where gami = 1./sqrt(1.+sum(pi**2)*ci*ci)
c part(1,n,l) = position x of particle n in partition l
c part(2,n,l) = position y of particle n in partition l
c part(3,n,l) = x momentum of particle n in partition l
c part(4,n,l) = y momentum of particle n in partition l
c part(5,n,l) = z momentum of particle n in partition l
c cu(i,n,l) = ith component of current density at grid point (j,kk),
c where n = j + nxv*kk + 1 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 nn = scratch address array for vectorized charge deposition
c amxy = scratch weight array for vectorized charge deposition
c qm = charge on particle, in units of e
c dt = time interval between successive calculations
c ci = reciprical of velocity of light
c nx/ny = system length in x/y direction
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
c nxvyp = nxv*nypmx, first actual dimension of current array
c npd = size of scratch buffers for vectorized current deposition
c n27 = number of independent weights
c ipbc = particle boundary condition = (0,1,2,3) =
c (none,2d periodic,2d reflecting,mixed reflecting/periodic)
dimension part(idimp,npmax,nblok), cu(3*nxvyp,nblok)
dimension npp(nblok), noff(nblok)
dimension nn(n27,npd,nblok), amxy(n27,npd,nblok)
nxv3 = 3*nxv
qmh = .5*qm
ci2 = ci*ci
c set boundary values
if (ipbc.eq.1) then
edgelx = 0.
edgerx = float(nx)
else if (ipbc.eq.2) then
edgelx = 1.
edgely = 1.
edgerx = float(nx-1)
edgery = float(ny-1)
else if (ipbc.eq.3) then
edgelx = 1.
edgerx = float(nx-1)
endif
c parallel loop
do 50 l = 1, nblok
mnoff = noff(l)
npb = npd
if (npp(l).gt.npd) then
ipp = float(npp(l) - 1)/float(npd) + 1.
else
ipp = 1
endif
c outer loop over blocks of particles
do 40 j = 1, ipp
jb = (j - 1)*npd
if (j.ge.ipp) npb = npp(l) - (ipp - 1)*npd
do 10 i = 1, npb
c find interpolation weights
n = part(1,i+jb,l) + .5
m = part(2,i+jb,l) + .5
dxp = part(1,i+jb,l) - float(n)
dyp = part(2,i+jb,l) - float(m)
c find inverse gamma
vx = part(3,i+jb,l)
vy = part(4,i+jb,l)
vz = part(5,i+jb,l)
p2 = vx*vx + vy*vy + vz*vz
gami = 1.0/sqrt(1.0 + p2*ci2)
c calculate weights
n3 = 3*n + 1
m = nxv3*(m - mnoff)
amx = qm*(.75 - dxp*dxp)
amy = .75 - dyp*dyp
ml = m + n3
dxl = qmh*(.5 - dxp)**2
dxp = qmh*(.5 + dxp)**2
mn = ml + nxv3
dyl = .5*(.5 - dyp)**2
dyp = .5*(.5 + dyp)**2
mp = mn + nxv3
nn(1,i,l) = mn
nn(2,i,l) = mn + 1
nn(3,i,l) = mn + 2
nn(4,i,l) = mn + 3
nn(5,i,l) = mn + 4
nn(6,i,l) = mn + 5
nn(7,i,l) = mn + 6
nn(8,i,l) = mn + 7
nn(9,i,l) = mn + 8
nn(10,i,l) = ml
nn(11,i,l) = ml + 1
nn(12,i,l) = ml + 2
nn(13,i,l) = ml + 3
nn(14,i,l) = ml + 4
nn(15,i,l) = ml + 5
nn(16,i,l) = ml + 6
nn(17,i,l) = ml + 7
nn(18,i,l) = ml + 8
nn(19,i,l) = mp
nn(20,i,l) = mp + 1
nn(21,i,l) = mp + 2
nn(22,i,l) = mp + 3
nn(23,i,l) = mp + 4
nn(24,i,l) = mp + 5
nn(25,i,l) = mp + 6
nn(26,i,l) = mp + 7
nn(27,i,l) = mp + 8
dx = dxl*amy
dy = amx*amy
dz = dxp*amy
vx = vx*gami
vy = vy*gami
vz = vz*gami
amxy(1,i,l) = vx*dx
amxy(2,i,l) = vy*dx
amxy(3,i,l) = vz*dx
dx = dxl*dyl
amxy(4,i,l) = vx*dy
amxy(5,i,l) = vy*dy
amxy(6,i,l) = vz*dy
dy = amx*dyl
amxy(7,i,l) = vx*dz
amxy(8,i,l) = vy*dz
amxy(9,i,l) = vz*dz
dz = dxp*dyl
amxy(10,i,l) = vx*dx
amxy(11,i,l) = vy*dx
amxy(12,i,l) = vz*dx
dx = dxl*dyp
amxy(13,i,l) = vx*dy
amxy(14,i,l) = vy*dy
amxy(15,i,l) = vz*dy
dy = amx*dyp
amxy(16,i,l) = vx*dz
amxy(17,i,l) = vy*dz
amxy(18,i,l) = vz*dz
dz = dxp*dyp
amxy(19,i,l) = vx*dx
amxy(20,i,l) = vy*dx
amxy(21,i,l) = vz*dx
amxy(22,i,l) = vx*dy
amxy(23,i,l) = vy*dy
amxy(24,i,l) = vz*dy
amxy(25,i,l) = vx*dz
amxy(26,i,l) = vy*dz
amxy(27,i,l) = vz*dz
c advance position half a time-step
dx = part(1,i+jb,l) + vx*dt
dy = part(2,i+jb,l) + vy*dt
c periodic boundary conditions
if (ipbc.eq.1) then
if (dx.lt.edgelx) dx = dx + edgerx
if (dx.ge.edgerx) dx = dx - edgerx
c reflecting boundary conditions
else if (ipbc.eq.2) then
if ((dx.lt.edgelx).or.(dx.ge.edgerx)) then
dx = part(1,i+jb,l)
part(3,i+jb,l) = -part(3,i+jb,l)
endif
if ((dy.lt.edgely).or.(dy.ge.edgery)) then
dy = part(2,i+jb,l)
part(4,i+jb,l) = -part(4,i+jb,l)
endif
c mixed reflecting/periodic boundary conditions
else if (ipbc.eq.3) then
if ((dx.lt.edgelx).or.(dx.ge.edgerx)) then
dx = part(1,i+jb,l)
part(3,i+jb,l) = -part(3,i+jb,l)
endif
endif
c set new position
part(1,i+jb,l) = dx
part(2,i+jb,l) = dy
10 continue
c deposit charge
do 30 i = 1, npb
cdir$ ivdep
do 20 k = 1, 27
cu(nn(k,i,l),l) = cu(nn(k,i,l),l) + amxy(k,i,l)
20 continue
30 continue
40 continue
50 continue
return
end
c-----------------------------------------------------------------------
subroutine PGRJPOST2L(part,cu,npp,noff,qm,dt,ci,nx,ny,idimp,npmax,
1nblok,nxv,nypmx,ipbc)
c for 2-1/2d code, this subroutine calculates particle current density
c using first-order linear interpolation for relativistic particles,
c and distributed data.
c in addition, particle positions are advanced a half time-step
c scalar version using guard cells, for distributed data
c 45 flops/particle, 1 divide, 1 sqrt, 17 loads, 14 stores
c input: all, output: part, cu
c current density is approximated by values at the nearest grid points
c cu(i,n,m)=qci*(1.-dx)*(1.-dy)
c cu(i,n+1,m)=qci*dx*(1.-dy)
c cu(i,n,m+1)=qci*(1.-dx)*dy
c cu(i,n+1,m+1)=qci*dx*dy
c where n,m = leftmost grid points and dx = x-n, dy = y-m
c and qci = qm*pi*gami, where i = x,y,z
c where gami = 1./sqrt(1.+sum(pi**2)*ci*ci)
c part(1,n,l) = position x of particle n in partition l
c part(2,n,l) = position y of particle n in partition l
c part(3,n,l) = x momentum of particle n in partition l
c part(4,n,l) = y momentum of particle n in partition l
c part(5,n,l) = z momentum of particle n in partition l
c cu(i,j,k,l) = ith component of current density 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 dt = time interval between successive calculations
c ci = reciprical of velocity of light
c nx/ny = system length in x/y direction
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 current array, must be >= nx+1
c nypmx = maximum size of particle partition, including guard cells.
c ipbc = particle boundary condition = (0,1,2,3) =
c (none,2d periodic,2d reflecting,mixed reflecting/periodic)
dimension part(idimp,npmax,nblok), cu(3,nxv,nypmx,nblok)
dimension npp(nblok), noff(nblok)
ci2 = ci*ci
c set boundary values
if (ipbc.eq.1) then
edgelx = 0.
edgerx = float(nx)
else if (ipbc.eq.2) then
edgelx = 1.
edgely = 1.
edgerx = float(nx-1)
edgery = float(ny-1)
else if (ipbc.eq.3) then
edgelx = 1.
edgerx = float(nx-1)
endif
do 20 l = 1, nblok
mnoff = noff(l) - 1
do 10 j = 1, npp(l)
c find interpolation weights
nn = part(1,j,l)
mm = part(2,j,l)
dxp = qm*(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
gami = 1.0/sqrt(1.0 + p2*ci2)
c calculate weights
nn = nn + 1
mm = mm - mnoff
amx = qm - dxp
mp = mm + 1
amy = 1. - dyp
np = nn + 1
c deposit current
dx = dxp*dyp
dy = amx*dyp
vx = vx*gami
vy = vy*gami
vz = vz*gami
cu(1,np,mp,l) = cu(1,np,mp,l) + vx*dx
cu(2,np,mp,l) = cu(2,np,mp,l) + vy*dx
cu(3,np,mp,l) = cu(3,np,mp,l) + vz*dx
dx = dxp*amy
cu(1,nn,mp,l) = cu(1,nn,mp,l) + vx*dy
cu(2,nn,mp,l) = cu(2,nn,mp,l) + vy*dy
cu(3,nn,mp,l) = cu(3,nn,mp,l) + vz*dy
dy = amx*amy
cu(1,np,mm,l) = cu(1,np,mm,l) + vx*dx
cu(2,np,mm,l) = cu(2,np,mm,l) + vy*dx
cu(3,np,mm,l) = cu(3,np,mm,l) + vz*dx
cu(1,nn,mm,l) = cu(1,nn,mm,l) + vx*dy
cu(2,nn,mm,l) = cu(2,nn,mm,l) + vy*dy
cu(3,nn,mm,l) = cu(3,nn,mm,l) + vz*dy
c advance position half a time-step
dx = part(1,j,l) + vx*dt
dy = part(2,j,l) + vy*dt
c periodic boundary conditions
if (ipbc.eq.1) then
if (dx.lt.edgelx) dx = dx + edgerx
if (dx.ge.edgerx) dx = dx - edgerx
c reflecting boundary conditions
else if (ipbc.eq.2) then
if ((dx.lt.edgelx).or.(dx.ge.edgerx)) then
dx = part(1,j,l)
part(3,j,l) = -part(3,j,l)
endif
if ((dy.lt.edgely).or.(dy.ge.edgery)) then
dy = part(2,j,l)
part(4,j,l) = -part(4,j,l)
endif
c mixed reflecting/periodic boundary conditions
else if (ipbc.eq.3) then
if ((dx.lt.edgelx).or.(dx.ge.edgerx)) then
dx = part(1,j,l)
part(3,j,l) = -part(3,j,l)
endif
endif
c set new position
part(1,j,l) = dx
part(2,j,l) = dy
10 continue
20 continue
return
end
c-----------------------------------------------------------------------
subroutine PGSRJPOST2L(part,cu,npp,noff,qm,dt,ci,nx,ny,idimp,npmax
1,nblok,nxv,nxyp,ipbc)
c for 2-1/2d code, this subroutine calculates particle current density
c using first-order linear interpolation for relativistic particles,
c and distributed data.
c in addition, particle positions are advanced a half time-step
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 45 flops/particle, 1 divide, 1 sqrt, 17 loads, 14 stores
c input: all, output: part, cu
c current density is approximated by values at the nearest grid points
c cu(i,n,m)=qm*(1.-dx)*(1.-dy)
c cu(i,n+1,m)=qm*dx*(1.-dy)
c cu(i,n,m+1)=qm*(1.-dx)*dy
c cu(i,n+1,m+1)=qm*dx*dy
c where n,m = leftmost grid points and dx = x-n, dy = y-m
c and qci = qm*pi*gami, where i = x,y,z
c where gami = 1./sqrt(1.+sum(pi**2)*ci*ci)
c part(1,n,l) = position x of particle n in partition l
c part(2,n,l) = position y of particle n in partition l
c part(3,n,l) = x momentum of particle n in partition l
c part(4,n,l) = y momentum of particle n in partition l
c part(5,n,l) = z momentum of particle n in partition l
c cu(i,j,k,l) = ith component of current density 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 dt = time interval between successive calculations
c ci = reciprical of velocity of light
c nx/ny = system length in x/y direction
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 current array, must be >= nx+1
c nxyp = actual first dimension of current array, must be >= nxv*nypmx
c ipbc = particle boundary condition = (0,1,2,3) =
c (none,2d periodic,2d reflecting,mixed reflecting/periodic)
dimension part(idimp,npmax,nblok), cu(3,nxyp,nblok)
dimension npp(nblok), noff(nblok)
ci2 = ci*ci
c set boundary values
if (ipbc.eq.1) then
edgelx = 0.
edgerx = float(nx)
else if (ipbc.eq.2) then
edgelx = 1.
edgely = 1.
edgerx = float(nx-1)
edgery = float(ny-1)
else if (ipbc.eq.3) then
edgelx = 1.
edgerx = float(nx-1)
endif
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)
mmn = part(2,1,l)
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
gami = 1.0/sqrt(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)
mmn = part(2,j,l)
dxp = qm*dxn
dyp = dyn
dxn = part(1,j,l) - float(nnn)
dyn = part(2,j,l) - float(mmn)
mm = mm + nn
amx = qm - dxp
mp = mm + nxv
amy = 1. - dyp
mmn = mmn - mnoff
c calculate weights
dx = dxp*dyp
dz = amx*dyp
vx = vxn*gami
vy = vyn*gami
vz = vzn*gami
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 current
dx1 = cu(1,mp+1,l) + vx*dx
dy1 = cu(2,mp+1,l) + vy*dx