-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdpush2.f
4740 lines (4740 loc) · 158 KB
/
dpush2.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 Fortran Library for Skeleton 2-1/2D Darwin PIC Code
c written by Viktor K. Decyk, UCLA
c-----------------------------------------------------------------------
subroutine DISTR2H(part,vtx,vty,vtz,vdx,vdy,vdz,npx,npy,idimp,nop,
1nx,ny,ipbc)
c for 2-1/2d code, this subroutine calculates initial particle
c co-ordinates and velocities with uniform density and maxwellian
c velocity with drift
c part(1,n) = position x of particle n
c part(2,n) = position y of particle n
c part(3,n) = velocity vx of particle n
c part(4,n) = velocity vy of particle n
c part(5,n) = velocity vz of particle n
c vtx/vty/vtz = thermal velocity of electrons in x/y/z direction
c vdx/vdy/vdz = drift velocity of beam electrons in x/y/z direction
c npx/npy = initial number of particles distributed in x/y direction
c idimp = size of phase space = 5
c nop = number of particles
c nx/ny = system length in x/y direction
c ipbc = particle boundary condition = (0,1,2,3) =
c (none,2d periodic,2d reflecting,mixed reflecting/periodic)
c ranorm = gaussian random number with zero mean and unit variance
implicit none
integer npx, npy, idimp, nop, nx, ny, ipbc
real vtx, vty, vtz, vdx, vdy, vdz
real part
dimension part(idimp,nop)
c local data
integer j, k, k1, npxy
real edgelx, edgely, at1, at2, at3, sum1, sum2, sum3
double precision dsum1, dsum2, dsum3
double precision ranorm
npxy = npx*npy
c set boundary values
edgelx = 0.0
edgely = 0.0
at1 = real(nx)/real(npx)
at2 = real(ny)/real(npy)
if (ipbc.eq.2) then
edgelx = 1.0
edgely = 1.0
at1 = real(nx-2)/real(npx)
at2 = real(ny-2)/real(npy)
else if (ipbc.eq.3) then
edgelx = 1.0
at1 = real(nx-2)/real(npx)
endif
c uniform density profile
do 20 k = 1, npy
k1 = npx*(k - 1)
at3 = edgely + at2*(real(k) - 0.5)
do 10 j = 1, npx
part(1,j+k1) = edgelx + at1*(real(j) - 0.5)
part(2,j+k1) = at3
10 continue
20 continue
c maxwellian velocity distribution
do 30 j = 1, npxy
part(3,j) = vtx*ranorm()
part(4,j) = vty*ranorm()
part(5,j) = vtz*ranorm()
30 continue
c add correct drift
dsum1 = 0.0d0
dsum2 = 0.0d0
dsum3 = 0.0d0
do 40 j = 1, npxy
dsum1 = dsum1 + part(3,j)
dsum2 = dsum2 + part(4,j)
dsum3 = dsum3 + part(5,j)
40 continue
sum1 = dsum1
sum2 = dsum2
sum3 = dsum3
at1 = 1./real(npxy)
sum1 = at1*sum1 - vdx
sum2 = at1*sum2 - vdy
sum3 = at1*sum3 - vdz
do 50 j = 1, npxy
part(3,j) = part(3,j) - sum1
part(4,j) = part(4,j) - sum2
part(5,j) = part(5,j) - sum3
50 continue
return
end
c-----------------------------------------------------------------------
subroutine GBPUSH23L(part,fxy,bxy,qbm,dt,dtc,ek,idimp,nop,nx,ny,
1nxv,nyv,ipbc)
c for 2-1/2d code, this subroutine updates particle co-ordinates and
c velocities using leap-frog scheme in time and first-order linear
c interpolation in space, with magnetic field. Using the Boris Mover.
c scalar version using guard cells
c 119 flops/particle, 1 divide, 29 loads, 5 stores
c input: all, output: part, ek
c velocity equations used are:
c vx(t+dt/2) = rot(1)*(vx(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(2)*(vy(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(3)*(vz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt) +
c .5*(q/m)*fx(x(t),y(t))*dt)
c vy(t+dt/2) = rot(4)*(vx(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(5)*(vy(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(6)*(vz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt) +
c .5*(q/m)*fy(x(t),y(t))*dt)
c vz(t+dt/2) = rot(7)*(vx(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(8)*(vy(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(9)*(vz(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)), omy = (q/m)*by(x(t),y(t)), and
c omz = (q/m)*bz(x(t),y(t)).
c position equations used are:
c x(t+dt)=x(t) + vx(t+dt/2)*dt
c y(t+dt)=y(t) + vy(t+dt/2)*dt
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) = (1-dy)*((1-dx)*fx(n,m)+dx*fx(n+1,m)) + dy*((1-dx)*fx(n,m+1)
c + dx*fx(n+1,m+1))
c where n,m = leftmost 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) = position x of particle n
c part(2,n) = position y of particle n
c part(3,n) = velocity vx of particle n
c part(4,n) = velocity vy of particle n
c part(5,n) = velocity vz of particle n
c fxy(1,j,k) = x component of force/charge at grid (j,k)
c fxy(2,j,k) = y component of force/charge at grid (j,k)
c fxy(3,j,k) = z component of force/charge at grid (j,k)
c that is, convolution of electric field over particle shape
c bxy(1,j,k) = x component of magnetic field at grid (j,k)
c bxy(2,j,k) = y component of magnetic field at grid (j,k)
c bxy(3,j,k) = z component of magnetic field at grid (j,k)
c that is, the convolution of magnetic field over particle shape
c qbm = particle charge/mass ratio
c dt = time interval between successive calculations
c dtc = time interval between successive co-ordinate calculations
c kinetic energy/mass at time t is also calculated, using
c ek = .5*sum((vx(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt)**2 +
c (vy(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt)**2 +
c (vz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt)**2)
c idimp = size of phase space = 5
c nop = number of particles
c nx/ny = system length in x/y direction
c nxv = second dimension of field arrays, must be >= nx+1
c nyv = third dimension of field arrays, must be >= ny+1
c ipbc = particle boundary condition = (0,1,2,3) =
c (none,2d periodic,2d reflecting,mixed reflecting/periodic)
implicit none
integer idimp, nop, nx, ny, nxv, nyv, ipbc
real qbm, dt, dtc, ek
real part, fxy, bxy
dimension part(idimp,nop)
dimension fxy(3,nxv,nyv), bxy(3,nxv,nyv)
c local data
integer j, nn, mm, np, mp
real qtmh, edgelx, edgely, edgerx, edgery, dxp, dyp, amx, amy
real dx, dy, dz, ox, oy, oz, acx, acy, acz, omxt, omyt, omzt, omt
real anorm, rot1, rot2, rot3, rot4, rot5, rot6, rot7, rot8, rot9
double precision sum1
qtmh = 0.5*qbm*dt
sum1 = 0.0d0
c set boundary values
edgelx = 0.0
edgely = 0.0
edgerx = real(nx)
edgery = real(ny)
if (ipbc.eq.2) then
edgelx = 1.0
edgely = 1.0
edgerx = real(nx-1)
edgery = real(ny-1)
else if (ipbc.eq.3) then
edgelx = 1.0
edgerx = real(nx-1)
endif
do 10 j = 1, nop
c find interpolation weights
nn = part(1,j)
mm = part(2,j)
dxp = part(1,j) - real(nn)
dyp = part(2,j) - real(mm)
nn = nn + 1
mm = mm + 1
amx = 1.0 - dxp
mp = mm + 1
amy = 1.0 - dyp
np = nn + 1
c find electric field
dx = dyp*(dxp*fxy(1,np,mp) + amx*fxy(1,nn,mp))
1 + amy*(dxp*fxy(1,np,mm) + amx*fxy(1,nn,mm))
dy = dyp*(dxp*fxy(2,np,mp) + amx*fxy(2,nn,mp))
1 + amy*(dxp*fxy(2,np,mm) + amx*fxy(2,nn,mm))
dz = dyp*(dxp*fxy(3,np,mp) + amx*fxy(3,nn,mp))
1 + amy*(dxp*fxy(3,np,mm) + amx*fxy(3,nn,mm))
c find magnetic field
ox = dyp*(dxp*bxy(1,np,mp) + amx*bxy(1,nn,mp))
1 + amy*(dxp*bxy(1,np,mm) + amx*bxy(1,nn,mm))
oy = dyp*(dxp*bxy(2,np,mp) + amx*bxy(2,nn,mp))
1 + amy*(dxp*bxy(2,np,mm) + amx*bxy(2,nn,mm))
oz = dyp*(dxp*bxy(3,np,mp) + amx*bxy(3,nn,mp))
1 + amy*(dxp*bxy(3,np,mm) + amx*bxy(3,nn,mm))
c calculate half impulse
dx = qtmh*dx
dy = qtmh*dy
dz = qtmh*dz
c half acceleration
acx = part(3,j) + dx
acy = part(4,j) + dy
acz = part(5,j) + dz
c time-centered kinetic energy
sum1 = sum1 + (acx*acx + acy*acy + acz*acz)
c calculate cyclotron frequency
omxt = qtmh*ox
omyt = qtmh*oy
omzt = qtmh*oz
c calculate rotation matrix
omt = omxt*omxt + omyt*omyt + omzt*omzt
anorm = 2.0/(1.0 + omt)
omt = 0.5*(1.0 - 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
dx = (rot1*acx + rot2*acy + rot3*acz)*anorm + dx
dy = (rot4*acx + rot5*acy + rot6*acz)*anorm + dy
dz = (rot7*acx + rot8*acy + rot9*acz)*anorm + dz
part(3,j) = dx
part(4,j) = dy
part(5,j) = dz
c new position
dx = part(1,j) + dx*dtc
dy = part(2,j) + dy*dtc
c periodic boundary conditions
if (ipbc.eq.1) then
if (dx.lt.edgelx) dx = dx + edgerx
if (dx.ge.edgerx) dx = dx - edgerx
if (dy.lt.edgely) dy = dy + edgery
if (dy.ge.edgery) dy = dy - edgery
c reflecting boundary conditions
else if (ipbc.eq.2) then
if ((dx.lt.edgelx).or.(dx.ge.edgerx)) then
dx = part(1,j)
part(3,j) = -part(3,j)
endif
if ((dy.lt.edgely).or.(dy.ge.edgery)) then
dy = part(2,j)
part(4,j) = -part(4,j)
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)
part(3,j) = -part(3,j)
endif
if (dy.lt.edgely) dy = dy + edgery
if (dy.ge.edgery) dy = dy - edgery
endif
c set new position
part(1,j) = dx
part(2,j) = dy
10 continue
c normalize kinetic energy
ek = ek + 0.5*sum1
return
end
c-----------------------------------------------------------------------
subroutine GPOST2L(part,q,qm,nop,idimp,nxv,nyv)
c for 2d code, this subroutine calculates particle charge density
c using first-order linear interpolation, periodic boundaries
c scalar version using guard cells
c 17 flops/particle, 6 loads, 4 stores
c input: all, output: q
c charge density is approximated by values at the nearest grid points
c q(n,m)=qm*(1.-dx)*(1.-dy)
c q(n+1,m)=qm*dx*(1.-dy)
c q(n,m+1)=qm*(1.-dx)*dy
c q(n+1,m+1)=qm*dx*dy
c where n,m = leftmost grid points and dx = x-n, dy = y-m
c part(1,n) = position x of particle n
c part(2,n) = position y of particle n
c q(j,k) = charge density at grid point j,k
c qm = charge on particle, in units of e
c nop = number of particles
c idimp = size of phase space = 4
c nxv = first dimension of charge array, must be >= nx+1
c nyv = second dimension of charge array, must be >= ny+1
implicit none
integer nop, idimp, nxv, nyv
real qm
real part, q
dimension part(idimp,nop), q(nxv,nyv)
c local data
integer j, nn, mm, np, mp
real dxp, dyp, amx, amy
c find interpolation weights
do 10 j = 1, nop
nn = part(1,j)
mm = part(2,j)
dxp = qm*(part(1,j) - real(nn))
dyp = part(2,j) - real(mm)
nn = nn + 1
mm = mm + 1
amx = qm - dxp
mp = mm + 1
amy = 1. - dyp
np = nn + 1
c deposit charge
q(np,mp) = q(np,mp) + dxp*dyp
q(nn,mp) = q(nn,mp) + amx*dyp
q(np,mm) = q(np,mm) + dxp*amy
q(nn,mm) = q(nn,mm) + amx*amy
10 continue
return
end
c-----------------------------------------------------------------------
subroutine GJPOST2L(part,cu,qm,dt,nop,idimp,nx,ny,nxv,nyv,ipbc)
c for 2-1/2d code, this subroutine calculates particle current density
c using first-order linear interpolation
c in addition, particle positions are advanced a half time-step
c scalar version using guard cells
c 41 flops/particle, 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*vi, where i = x,y,z
c part(1,n) = position x of particle n
c part(2,n) = position y of particle n
c part(3,n) = x velocity of particle n
c part(4,n) = y velocity of particle n
c part(5,n) = z velocity of particle n
c cu(i,j,k) = ith component of current density at grid point j,k
c qm = charge on particle, in units of e
c dt = time interval between successive calculations
c nop = number of particles
c idimp = size of phase space = 5
c nx/ny = system length in x/y direction
c nxv = second dimension of current array, must be >= nx+1
c nyv = third dimension of current array, must be >= ny+1
c ipbc = particle boundary condition = (0,1,2,3) =
c (none,2d periodic,2d reflecting,mixed reflecting/periodic)
implicit none
integer nop, idimp, nx, ny, nxv, nyv, ipbc
real qm, dt
real part, cu
dimension part(idimp,nop), cu(3,nxv,nyv)
c local data
integer j, nn, mm, np, mp
real edgelx, edgely, edgerx, edgery, dxp, dyp, amx, amy
real dx, dy, vx, vy, vz
c set boundary values
edgelx = 0.0
edgely = 0.0
edgerx = real(nx)
edgery = real(ny)
if (ipbc.eq.2) then
edgelx = 1.0
edgely = 1.0
edgerx = real(nx-1)
edgery = real(ny-1)
else if (ipbc.eq.3) then
edgelx = 1.0
edgerx = real(nx-1)
endif
do 10 j = 1, nop
c find interpolation weights
nn = part(1,j)
mm = part(2,j)
dxp = qm*(part(1,j) - real(nn))
dyp = part(2,j) - real(mm)
nn = nn + 1
mm = mm + 1
amx = qm - dxp
mp = mm + 1
amy = 1.0 - dyp
np = nn + 1
c deposit current
dx = dxp*dyp
dy = amx*dyp
vx = part(3,j)
vy = part(4,j)
vz = part(5,j)
cu(1,np,mp) = cu(1,np,mp) + vx*dx
cu(2,np,mp) = cu(2,np,mp) + vy*dx
cu(3,np,mp) = cu(3,np,mp) + vz*dx
dx = dxp*amy
cu(1,nn,mp) = cu(1,nn,mp) + vx*dy
cu(2,nn,mp) = cu(2,nn,mp) + vy*dy
cu(3,nn,mp) = cu(3,nn,mp) + vz*dy
dy = amx*amy
cu(1,np,mm) = cu(1,np,mm) + vx*dx
cu(2,np,mm) = cu(2,np,mm) + vy*dx
cu(3,np,mm) = cu(3,np,mm) + vz*dx
cu(1,nn,mm) = cu(1,nn,mm) + vx*dy
cu(2,nn,mm) = cu(2,nn,mm) + vy*dy
cu(3,nn,mm) = cu(3,nn,mm) + vz*dy
c advance position half a time-step
dx = part(1,j) + vx*dt
dy = part(2,j) + 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
if (dy.lt.edgely) dy = dy + edgery
if (dy.ge.edgery) dy = dy - edgery
c reflecting boundary conditions
else if (ipbc.eq.2) then
if ((dx.lt.edgelx).or.(dx.ge.edgerx)) then
dx = part(1,j)
part(3,j) = -part(3,j)
endif
if ((dy.lt.edgely).or.(dy.ge.edgery)) then
dy = part(2,j)
part(4,j) = -part(4,j)
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)
part(3,j) = -part(3,j)
endif
if (dy.lt.edgely) dy = dy + edgery
if (dy.ge.edgery) dy = dy - edgery
endif
c set new position
part(1,j) = dx
part(2,j) = dy
10 continue
return
end
c-----------------------------------------------------------------------
subroutine GMJPOST2L(part,amu,qm,nop,idimp,nxv,nyv)
c for 2-1/2d code, this subroutine calculates particle momentum flux
c using first-order spline interpolation
c scalar version using guard cells
c 51 flops/particle, 21 loads, 16 stores
c input: all, output: amu
c momentum flux is approximated by values at the nearest grid points
c amu(i,n,m)=qci*(1.-dx)*(1.-dy)
c amu(i,n+1,m)=qci*dx*(1.-dy)
c amu(i,n,m+1)=qci*(1.-dx)*dy
c amu(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*vj*vk, where jk = xx-yy,xy,zx,zy, for i = 1, 4
c where vj = vj(t-dt/2) and vk = vk(t-dt/2)
c part(1,n) = position x of particle n at t
c part(2,n) = position y of particle n at t
c part(3,n) = x velocity of particle n at t - dt/2
c part(4,n) = y velocity of particle n at t - dt/2
c part(5,n) = z velocity of particle n at t - dt/2
c amu(i,j,k) = ith component of momentum flux at grid point j,k
c qm = charge on particle, in units of e
c nop = number of particles
c idimp = size of phase space = 5
c nxv = second dimension of flux array, must be >= nx+1
c nyv = third dimension of flux array, must be >= ny+1
implicit none
integer nop, idimp, nxv, nyv
real part, amu, qm
dimension part(idimp,nop), amu(4,nxv,nyv)
c local data
integer j, nn, mm, np, mp
real dxp, dyp, amx, amy
real dx, dy, vx, vy, vz, v1, v2, v3, v4
c find interpolation weights
do 10 j = 1, nop
nn = part(1,j)
mm = part(2,j)
dxp = qm*(part(1,j) - real(nn))
dyp = part(2,j) - real(mm)
nn = nn + 1
mm = mm + 1
amx = qm - dxp
mp = mm + 1
amy = 1.0 - dyp
np = nn + 1
c deposit momentum flux
dx = dxp*dyp
dy = amx*dyp
vx = part(3,j)
vy = part(4,j)
vz = part(5,j)
v1 = vx*vx - vy*vy
v2 = vx*vy
v3 = vz*vx
v4 = vz*vy
amu(1,np,mp) = amu(1,np,mp) + v1*dx
amu(2,np,mp) = amu(2,np,mp) + v2*dx
amu(3,np,mp) = amu(3,np,mp) + v3*dx
amu(4,np,mp) = amu(4,np,mp) + v4*dx
dx = dxp*amy
amu(1,nn,mp) = amu(1,nn,mp) + v1*dy
amu(2,nn,mp) = amu(2,nn,mp) + v2*dy
amu(3,nn,mp) = amu(3,nn,mp) + v3*dy
amu(4,nn,mp) = amu(4,nn,mp) + v4*dy
dy = amx*amy
amu(1,np,mm) = amu(1,np,mm) + v1*dx
amu(2,np,mm) = amu(2,np,mm) + v2*dx
amu(3,np,mm) = amu(3,np,mm) + v3*dx
amu(4,np,mm) = amu(4,np,mm) + v4*dx
amu(1,nn,mm) = amu(1,nn,mm) + v1*dy
amu(2,nn,mm) = amu(2,nn,mm) + v2*dy
amu(3,nn,mm) = amu(3,nn,mm) + v3*dy
amu(4,nn,mm) = amu(4,nn,mm) + v4*dy
10 continue
return
end
c-----------------------------------------------------------------------
subroutine GDJPOST2L(part,fxy,bxy,dcu,amu,qm,qbm,dt,idimp,nop,nxv,
1nyv)
c for 2-1/2d code, this subroutine calculates particle momentum flux
c and acceleration density using first-order spline interpolation.
c scalar version using guard cells
c 194 flops/particle, 1 divide, 57 loads, 28 stores
c input: all, output: dcu, amu
c acceleration density is approximated by values at the nearest grid
c points
c dcu(i,n,m)=qci*(1.-dx)*(1.-dy)
c dcu(i,n+1,m)=qci*dx*(1.-dy)
c dcu(i,n,m+1)=qci*(1.-dx)*dy
c dcu(i,n+1,m+1)=qci*dx*dy
c and qci = qm*dvj/dt, where j = x,y,z, for i = 1, 3
c where dvj = (vj(t+dt/2)-vj(t-dt/2))/dt
c momentum flux is approximated by values at the nearest grid points
c amu(i,n,m)=qci*(1.-dx)*(1.-dy)
c amu(i,n+1,m)=qci*dx*(1.-dy)
c amu(i,n,m+1)=qci*(1.-dx)*dy
c amu(i,n+1,m+1)=qci*dx*dy
c and qci = qm*vj*vk, where jk = xx-yy,xy,zx,zy, for i = 1, 4
c where vj = 0.5*(vj(t+dt/2)+vj(t-dt/2),
c and vk = 0.5*(vk(t+dt/2)+vk(t-dt/2))
c where n,m = nearest grid points and dx = x-n, dy = y-m
c velocity equations at t=t+dt/2 are calculated from:
c vx(t+dt/2) = rot(1)*(vx(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(2)*(vy(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(3)*(vz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt) +
c .5*(q/m)*fx(x(t),y(t))*dt)
c vy(t+dt/2) = rot(4)*(vx(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(5)*(vy(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(6)*(vz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt) +
c .5*(q/m)*fy(x(t),y(t))*dt)
c vz(t+dt/2) = rot(7)*(vx(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(8)*(vy(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(9)*(vz(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)), omy = (q/m)*by(x(t),y(t)), and
c omz = (q/m)*bz(x(t),y(t)).
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) = (1-dy)*((1-dx)*fx(n,m)+dx*fx(n+1,m)) + dy*((1-dx)*fx(n,m+1)
c + dx*fx(n+1,m+1))
c where n,m = leftmost 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) = position x of particle n at t
c part(2,n) = position y of particle n at t
c part(3,n) = velocity vx of particle n at t - dt/2
c part(4,n) = velocity vy of particle n at t - dt/2
c part(5,n) = velocity vz of particle n at t - dt/2
c fxy(1,j,k) = x component of force/charge at grid (j,k)
c fxy(2,j,k) = y component of force/charge at grid (j,k)
c fxy(3,j,k) = z component of force/charge at grid (j,k)
c that is, convolution of electric field over particle shape
c bxy(1,j,k) = x component of magnetic field at grid (j,k)
c bxy(2,j,k) = y component of magnetic field at grid (j,k)
c bxy(3,j,k) = z component of magnetic field at grid (j,k)
c that is, the convolution of magnetic field over particle shape
c dcu(i,j,k) = ith component of acceleration density
c at grid point j,k for i = 1, 3
c amu(i,j,k) = ith component of momentum flux
c at grid point j,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 idimp = size of phase space = 5
c nop = number of particles
c nxv = second dimension of field arrays, must be >= nx+1
c nyv = third dimension of field arrays, must be >= ny+1
implicit none
integer idimp, nop, nxv, nyv
real part, fxy, bxy, dcu, amu, qm, qbm, dt
dimension part(idimp,nop)
dimension fxy(3,nxv,nyv), bxy(3,nxv,nyv)
dimension dcu(3,nxv,nyv), amu(4,nxv,nyv)
c local data
integer j, nn, mm, np, mp
real qtmh, dti, dxp, dyp, amx, amy, 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, v1, v2, v3, v4
qtmh = .5*qbm*dt
dti = 1.0/dt
do 10 j = 1, nop
c find interpolation weights
nn = part(1,j)
mm = part(2,j)
dxp = part(1,j) - real(nn)
dyp = part(2,j) - real(mm)
nn = nn + 1
mm = mm + 1
amx = 1. - dxp
mp = mm + 1
amy = 1. - dyp
np = nn + 1
c find electric field
dx = dyp*(dxp*fxy(1,np,mp) + amx*fxy(1,nn,mp))
1 + amy*(dxp*fxy(1,np,mm) + amx*fxy(1,nn,mm))
dy = dyp*(dxp*fxy(2,np,mp) + amx*fxy(2,nn,mp))
1 + amy*(dxp*fxy(2,np,mm) + amx*fxy(2,nn,mm))
dz = dyp*(dxp*fxy(3,np,mp) + amx*fxy(3,nn,mp))
1 + amy*(dxp*fxy(3,np,mm) + amx*fxy(3,nn,mm))
c find magnetic field
ox = dyp*(dxp*bxy(1,np,mp) + amx*bxy(1,nn,mp))
1 + amy*(dxp*bxy(1,np,mm) + amx*bxy(1,nn,mm))
oy = dyp*(dxp*bxy(2,np,mp) + amx*bxy(2,nn,mp))
1 + amy*(dxp*bxy(2,np,mm) + amx*bxy(2,nn,mm))
oz = dyp*(dxp*bxy(3,np,mp) + amx*bxy(3,nn,mp))
1 + amy*(dxp*bxy(3,np,mm) + amx*bxy(3,nn,mm))
c calculate half impulse
dx = qtmh*dx
dy = qtmh*dy
dz = qtmh*dz
c half acceleration
vx = part(3,j)
vy = part(4,j)
vz = part(5,j)
acx = vx + dx
acy = vy + dy
acz = vz + dz
c calculate cyclotron frequency
omxt = qtmh*ox
omyt = qtmh*oy
omzt = qtmh*oz
c calculate rotation matrix
omt = omxt*omxt + omyt*omyt + omzt*omzt
anorm = 2.0/(1.0 + omt)
omt = 0.5*(1.0 - 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
dx = (rot1*acx + rot2*acy + rot3*acz)*anorm + dx
dy = (rot4*acx + rot5*acy + rot6*acz)*anorm + dy
dz = (rot7*acx + rot8*acy + rot9*acz)*anorm + dz
c deposit momentum flux and acceleration density
amx = qm*amx
dxp = qm*dxp
ox = 0.5*(dx + vx)
oy = 0.5*(dy + vy)
oz = 0.5*(dz + vz)
vx = dti*(dx - vx)
vy = dti*(dy - vy)
vz = dti*(dz - vz)
dx = dxp*dyp
dy = amx*dyp
v1 = ox*ox - oy*oy
v2 = ox*oy
v3 = oz*ox
v4 = oz*oy
amu(1,np,mp) = amu(1,np,mp) + v1*dx
amu(2,np,mp) = amu(2,np,mp) + v2*dx
amu(3,np,mp) = amu(3,np,mp) + v3*dx
amu(4,np,mp) = amu(4,np,mp) + v4*dx
dcu(1,np,mp) = dcu(1,np,mp) + vx*dx
dcu(2,np,mp) = dcu(2,np,mp) + vy*dx
dcu(3,np,mp) = dcu(3,np,mp) + vz*dx
dx = dxp*amy
amu(1,nn,mp) = amu(1,nn,mp) + v1*dy
amu(2,nn,mp) = amu(2,nn,mp) + v2*dy
amu(3,nn,mp) = amu(3,nn,mp) + v3*dy
amu(4,nn,mp) = amu(4,nn,mp) + v4*dy
dcu(1,nn,mp) = dcu(1,nn,mp) + vx*dy
dcu(2,nn,mp) = dcu(2,nn,mp) + vy*dy
dcu(3,nn,mp) = dcu(3,nn,mp) + vz*dy
dy = amx*amy
amu(1,np,mm) = amu(1,np,mm) + v1*dx
amu(2,np,mm) = amu(2,np,mm) + v2*dx
amu(3,np,mm) = amu(3,np,mm) + v3*dx
amu(4,np,mm) = amu(4,np,mm) + v4*dx
dcu(1,np,mm) = dcu(1,np,mm) + vx*dx
dcu(2,np,mm) = dcu(2,np,mm) + vy*dx
dcu(3,np,mm) = dcu(3,np,mm) + vz*dx
amu(1,nn,mm) = amu(1,nn,mm) + v1*dy
amu(2,nn,mm) = amu(2,nn,mm) + v2*dy
amu(3,nn,mm) = amu(3,nn,mm) + v3*dy
amu(4,nn,mm) = amu(4,nn,mm) + v4*dy
dcu(1,nn,mm) = dcu(1,nn,mm) + vx*dy
dcu(2,nn,mm) = dcu(2,nn,mm) + vy*dy
dcu(3,nn,mm) = dcu(3,nn,mm) + vz*dy
10 continue
return
end
c-----------------------------------------------------------------------
subroutine GDCJPOST2L(part,fxy,bxy,cu,dcu,amu,qm,qbm,dt,idimp,nop,
1nxv,nyv)
c for 2-1/2d code, this subroutine calculates particle momentum flux,
c acceleration density and current density using first-order spline
c interpolation.
c scalar version using guard cells
c 218 flops/particle, 1 divide, 69 loads, 40 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*(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 and qci = qm*vj, where j = x,y,z, for i = 1, 3
c where vj = .5*(vj(t+dt/2)+vj(t-dt/2))
c acceleration density is approximated by values at the nearest grid
c points
c dcu(i,n,m)=qci*(1.-dx)*(1.-dy)
c dcu(i,n+1,m)=qci*dx*(1.-dy)
c dcu(i,n,m+1)=qci*(1.-dx)*dy
c dcu(i,n+1,m+1)=qci*dx*dy
c and qci = qm*dvj/dt, where j = x,y,z, for i = 1, 3
c where dvj = (vj(t+dt/2)-vj(t-dt/2))/dt
c momentum flux is approximated by values at the nearest grid points
c amu(i,n,m)=qci*(1.-dx)*(1.-dy)
c amu(i,n+1,m)=qci*dx*(1.-dy)
c amu(i,n,m+1)=qci*(1.-dx)*dy
c amu(i,n+1,m+1)=qci*dx*dy
c and qci = qm*vj*vk, where jk = xx-yy,xy,zx,zy, for i = 1, 4
c where vj = 0.5*(vj(t+dt/2)+vj(t-dt/2),
c and vk = 0.5*(vk(t+dt/2)+vk(t-dt/2))
c where n,m = nearest grid points and dx = x-n, dy = y-m
c velocity equations at t=t+dt/2 are calculated from:
c vx(t+dt/2) = rot(1)*(vx(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(2)*(vy(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(3)*(vz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt) +
c .5*(q/m)*fx(x(t),y(t))*dt)
c vy(t+dt/2) = rot(4)*(vx(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(5)*(vy(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(6)*(vz(t-dt/2) + .5*(q/m)*fz(x(t),y(t))*dt) +
c .5*(q/m)*fy(x(t),y(t))*dt)
c vz(t+dt/2) = rot(7)*(vx(t-dt/2) + .5*(q/m)*fx(x(t),y(t))*dt) +
c rot(8)*(vy(t-dt/2) + .5*(q/m)*fy(x(t),y(t))*dt) +
c rot(9)*(vz(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)), omy = (q/m)*by(x(t),y(t)), and
c omz = (q/m)*bz(x(t),y(t)).
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) = (1-dy)*((1-dx)*fx(n,m)+dx*fx(n+1,m)) + dy*((1-dx)*fx(n,m+1)
c + dx*fx(n+1,m+1))
c where n,m = leftmost 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) = position x of particle n at t
c part(2,n) = position y of particle n at t
c part(3,n) = velocity vx of particle n at t - dt/2
c part(4,n) = velocity vy of particle n at t - dt/2
c part(5,n) = velocity vz of particle n at t - dt/2
c fxy(1,j,k) = x component of force/charge at grid (j,k)
c fxy(2,j,k) = y component of force/charge at grid (j,k)
c fxy(3,j,k) = z component of force/charge at grid (j,k)
c that is, convolution of electric field over particle shape
c bxy(1,j,k) = x component of magnetic field at grid (j,k)
c bxy(2,j,k) = y component of magnetic field at grid (j,k)
c bxy(3,j,k) = z component of magnetic field at grid (j,k)
c that is, the convolution of magnetic field over particle shape
c cu(i,j,k) = ith component of current density
c at grid point j,k for i = 1, 3
c dcu(i,j,k) = ith component of acceleration density
c at grid point j,k for i = 1, 3
c amu(i,j,k) = ith component of momentum flux
c at grid point j,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 idimp = size of phase space = 5
c nop = number of particles
c nxv = second dimension of field arrays, must be >= nx+1
c nyv = third dimension of field arrays, must be >= ny+1
implicit none
integer idimp, nop, nxv, nyv
real part, fxy, bxy, cu, dcu, amu, qm, qbm, dt
dimension part(idimp,nop)
dimension fxy(3,nxv,nyv), bxy(3,nxv,nyv)
dimension cu(3,nxv,nyv), dcu(3,nxv,nyv), amu(4,nxv,nyv)
c local data
integer j, nn, mm, np, mp
real qtmh, dti, dxp, dyp, amx, amy, 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, v1, v2, v3, v4
qtmh = 0.5*qbm*dt
dti = 1.0/dt
do 10 j = 1, nop
c find interpolation weights
nn = part(1,j)
mm = part(2,j)
dxp = part(1,j) - real(nn)
dyp = part(2,j) - real(mm)
nn = nn + 1
mm = mm + 1
amx = 1.0 - dxp
mp = mm + 1
amy = 1.0 - dyp
np = nn + 1
c find electric field
dx = dyp*(dxp*fxy(1,np,mp) + amx*fxy(1,nn,mp))
1 + amy*(dxp*fxy(1,np,mm) + amx*fxy(1,nn,mm))
dy = dyp*(dxp*fxy(2,np,mp) + amx*fxy(2,nn,mp))
1 + amy*(dxp*fxy(2,np,mm) + amx*fxy(2,nn,mm))
dz = dyp*(dxp*fxy(3,np,mp) + amx*fxy(3,nn,mp))
1 + amy*(dxp*fxy(3,np,mm) + amx*fxy(3,nn,mm))
c find magnetic field
ox = dyp*(dxp*bxy(1,np,mp) + amx*bxy(1,nn,mp))
1 + amy*(dxp*bxy(1,np,mm) + amx*bxy(1,nn,mm))
oy = dyp*(dxp*bxy(2,np,mp) + amx*bxy(2,nn,mp))
1 + amy*(dxp*bxy(2,np,mm) + amx*bxy(2,nn,mm))
oz = dyp*(dxp*bxy(3,np,mp) + amx*bxy(3,nn,mp))
1 + amy*(dxp*bxy(3,np,mm) + amx*bxy(3,nn,mm))
c calculate half impulse
dx = qtmh*dx
dy = qtmh*dy
dz = qtmh*dz
c half acceleration
vx = part(3,j)
vy = part(4,j)
vz = part(5,j)
acx = vx + dx
acy = vy + dy
acz = vz + dz
c calculate cyclotron frequency
omxt = qtmh*ox
omyt = qtmh*oy
omzt = qtmh*oz
c calculate rotation matrix
omt = omxt*omxt + omyt*omyt + omzt*omzt
anorm = 2.0/(1.0 + omt)
omt = 0.5*(1.0 - 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
dx = (rot1*acx + rot2*acy + rot3*acz)*anorm + dx
dy = (rot4*acx + rot5*acy + rot6*acz)*anorm + dy
dz = (rot7*acx + rot8*acy + rot9*acz)*anorm + dz
c deposit momentum flux, acceleration density, and current density
amx = qm*amx
dxp = qm*dxp
ox = 0.5*(dx + vx)
oy = 0.5*(dy + vy)
oz = 0.5*(dz + vz)
vx = dti*(dx - vx)
vy = dti*(dy - vy)
vz = dti*(dz - vz)
dx = dxp*dyp
dy = amx*dyp
v1 = ox*ox - oy*oy
v2 = ox*oy
v3 = oz*ox
v4 = oz*oy
amu(1,np,mp) = amu(1,np,mp) + v1*dx
amu(2,np,mp) = amu(2,np,mp) + v2*dx
amu(3,np,mp) = amu(3,np,mp) + v3*dx
amu(4,np,mp) = amu(4,np,mp) + v4*dx
dcu(1,np,mp) = dcu(1,np,mp) + vx*dx
dcu(2,np,mp) = dcu(2,np,mp) + vy*dx
dcu(3,np,mp) = dcu(3,np,mp) + vz*dx
cu(1,np,mp) = cu(1,np,mp) + ox*dx
cu(2,np,mp) = cu(2,np,mp) + oy*dx
cu(3,np,mp) = cu(3,np,mp) + oz*dx
dx = dxp*amy
amu(1,nn,mp) = amu(1,nn,mp) + v1*dy
amu(2,nn,mp) = amu(2,nn,mp) + v2*dy
amu(3,nn,mp) = amu(3,nn,mp) + v3*dy
amu(4,nn,mp) = amu(4,nn,mp) + v4*dy
dcu(1,nn,mp) = dcu(1,nn,mp) + vx*dy
dcu(2,nn,mp) = dcu(2,nn,mp) + vy*dy
dcu(3,nn,mp) = dcu(3,nn,mp) + vz*dy
cu(1,nn,mp) = cu(1,nn,mp) + ox*dy
cu(2,nn,mp) = cu(2,nn,mp) + oy*dy
cu(3,nn,mp) = cu(3,nn,mp) + oz*dy
dy = amx*amy
amu(1,np,mm) = amu(1,np,mm) + v1*dx
amu(2,np,mm) = amu(2,np,mm) + v2*dx
amu(3,np,mm) = amu(3,np,mm) + v3*dx
amu(4,np,mm) = amu(4,np,mm) + v4*dx
dcu(1,np,mm) = dcu(1,np,mm) + vx*dx
dcu(2,np,mm) = dcu(2,np,mm) + vy*dx
dcu(3,np,mm) = dcu(3,np,mm) + vz*dx
cu(1,np,mm) = cu(1,np,mm) + ox*dx
cu(2,np,mm) = cu(2,np,mm) + oy*dx
cu(3,np,mm) = cu(3,np,mm) + oz*dx
amu(1,nn,mm) = amu(1,nn,mm) + v1*dy
amu(2,nn,mm) = amu(2,nn,mm) + v2*dy
amu(3,nn,mm) = amu(3,nn,mm) + v3*dy
amu(4,nn,mm) = amu(4,nn,mm) + v4*dy
dcu(1,nn,mm) = dcu(1,nn,mm) + vx*dy
dcu(2,nn,mm) = dcu(2,nn,mm) + vy*dy
dcu(3,nn,mm) = dcu(3,nn,mm) + vz*dy
cu(1,nn,mm) = cu(1,nn,mm) + ox*dy
cu(2,nn,mm) = cu(2,nn,mm) + oy*dy
cu(3,nn,mm) = cu(3,nn,mm) + oz*dy
10 continue
return
end
c-----------------------------------------------------------------------
subroutine DSORTP2YL(parta,partb,npic,idimp,nop,ny1)
c this subroutine sorts particles by y grid
c linear interpolation
c parta/partb = input/output particle arrays
c parta(2,n) = position y of particle n
c npic = address offset for reordering particles
c idimp = size of phase space = 4
c nop = number of particles
c ny1 = system length in y direction + 1
implicit none
integer npic, idimp, nop, ny1
real parta, partb
dimension parta(idimp,nop), partb(idimp,nop), npic(ny1)
c local data
integer i, j, k, m, isum, ist, ip
c clear counter array
do 10 k = 1, ny1
npic(k) = 0
10 continue
c find how many particles in each grid
do 20 j = 1, nop
m = parta(2,j)
m = m + 1
npic(m) = npic(m) + 1
20 continue
c find address offset
isum = 0
do 30 k = 1, ny1
ist = npic(k)
npic(k) = isum
isum = isum + ist
30 continue
c find addresses of particles at each grid and reorder particles
do 50 j = 1, nop
m = parta(2,j)