-
Notifications
You must be signed in to change notification settings - Fork 0
/
DPDchrom-r.f90
4129 lines (3606 loc) · 116 KB
/
DPDchrom-r.f90
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
implicit none
include "mpif.h"
common /cell/ dlx,dly,dlz,rcut,kpbc !box size on each node (dlx,dly,dlz), cut radius (rcut), type of PBC(kpbc)
common /cella/ dlxa,dlya,dlza !complete cox size
common /sizes/ sz !size of main arrays (like r and v)
common /bxsize/ ilx,ily,ilz !number of box bins
common /na/ natms,natmsfan !current number of "real" particles(natms), current number of right "ghost" particles
common /nab/ natmsfanbond !current number of left "ghost" particles. necessary for bond forces calculation
common /data/ alpha,sigma,gamma !dpd parameters
common /time/ dt ! timestep
common /comm/ ssz,fsz !size of communication arrays, ssz is for moving atoms between nodes, fsz - for "ghost" atoms
common /npall/ npall !total number of atoms in the system
common /shwi/ shwi !transfer radius for "ghost" atoms
common /correl/ corr,bcorr,bcorrt !arrays that store global atom numbers. corr converts atom number on the node to the global number, bcorr does the opposite, bcorrt shows atom state ("real,"ghost" or on the other node)
common /den/ rho !density
common /bondf/ k_eq,k_bond !bond parameters - eq.length, stiffness
common /anglef/ k_eqa,k_angle !angle parameters - eq.value, energy coefficient
common /fname/ msi !name of input file
common /mpidpd/ rank, nproc ! node number and total number of nodes
common /rxyz/ rx,ry,rz !coordinates
common /fxyz/ fx,fy,fz !forces
common /vxyz/ vx,vy,vz !velocities
common /vwxyz/ vwx,vwy,vwz !waved velocities(for integration)
common /ptype/ kindp !current particle types
common /sndrcv/ sndr,sndl,fanl,fanr,rcv,rcvf !communication arrays. sndr,sndl - for moving particles, fanl,fanr - for "ghost", rcv,rcvf - for receive
common /funnumb/ npl,fann !npl - number of "ghost" atoms than have been sent to left node, fann - numbers of these particles. necessary for receiving forces actiong on atoms close to the node boundary from left node
common /commf/ fsend,rcou !array that stores forces to be sent to the right node (see above); rcou - detailed number of ghost particles
common /bnd/ cn !main bond array
common /rst/ nbond,nangles !number of bonds,number of angles
common /typel/ typelist,ntype !type of the atoms that present in the system and number of such types
common /ptypeall/ kindpall !particle types
common /top/ cln,nrow,ncol ! number of nodes in 1 row,row and column number of node
common /angl/ ca,angles ! main angle arrays
common /prs/ press ! pressure
common /vale/ val !valencies
common /probcb/ probc,probb !probabilities of chemical reactions
common /ch/ rchem !radius of chemical reactions
common /bmult/ mult !angles/bond snd rcv arrays size multiplier
common /lambd/ lambda
real*4,pointer :: sndr(:,:),sndl(:,:),fanl(:,:),fanr(:,:),rcv(:),rcvf(:) !size ssz,4;ssz,4;fsz,4;fsz,4;ssz*8,fsz*8
real*4,pointer :: rx(:,:),ry(:,:),rz(:,:) ! size sz,3
real*4,pointer :: vwx(:,:),vwy(:,:),vwz(:,:) ! size sz,2
real*4,pointer :: fx(:),fy(:),fz(:) ! size sz
real*4,pointer :: vx(:),vy(:),vz(:) ! size sz
integer*1,pointer :: kindp(:,:) ! size sz,3
integer*4,pointer :: corr(:,:),bcorr(:)! size sz,3 and npall
integer*1,pointer :: bcorrt(:) !size npall
integer*4,pointer :: fann(:,:) !size fsz/8,4
real*4,pointer :: fsend(:) ! size 3*fsz/2
integer*4,pointer :: cn(:,:) !size npall,0:maximum number of bonds
integer*1,pointer :: kindpall(:) ! size npall
integer*4,pointer :: ca(:,:) !size npall, 0: maximum number of angles
integer*4,pointer :: angles(:) !size 3*nangles
integer*1,pointer :: val(:) !size npall
real*4,pointer :: alpha(:,:),probc(:,:),probb(:,:) !size 10,10
real*4,pointer :: k_eq(:,:),k_bond(:,:) !size 10,10
real*4,pointer :: k_eqa(:,:,:),k_angle(:,:,:) !size 10,10,10
integer*4 nbond,nangles
integer*4 rank,nproc,cln,nrow,ncol
real*4 uni
integer*4 sz,ssz,fsz,npall
integer*4 ilx,ily,ilz
integer ierr
integer*4 steps1,steps2,steps3,qstp,rststp,nstp,chemstp
integer*4 kpbc,rst
real*4 dlx,dly,dlz,rcut,dlxtar
real*4 dlxa,dlya,dlza
integer*4 rcou(4)
integer*4 natms,natmsfan,npl(4),natmsfanbond,mult
real*4 sigma,dt,gamma
real*4 shwi
real*4 rho
character*8 msi
real*4 vall(3),vl(1)
real*8 start
integer*1 typelist(10),ntype
integer*4 i,j,curdef
real*4 press(3)
real*4 rchem
real*4 lambda
integer*1 def_res
! MPI initialization
call mpi_init(ierr)
call mpi_comm_rank(mpi_comm_world,rank,ierr)
call mpi_comm_size(mpi_comm_world,nproc,ierr)
! randon number generator initialization
vl=uni()
! read input script
call rconf(steps1,steps2,steps3,qstp,rst,rststp,chemstp,def_res)
! read restart.dat file
call readrst()
! allocate arrays
allocate (vwx(sz,2),vwy(sz,2),vwz(sz,2),fx(sz),fy(sz),fz(sz))
allocate (fann(fsz/8,4))
allocate (fsend(3*fsz/2))
allocate (fanl(max(fsz,ssz),4),fanr(max(fsz,ssz),4),rcvf(max(fsz,ssz)*8))
sndr => fanr
sndl => fanl
rcv => rcvf
! generate initial ghost beads arrays
call initial()
! output information
if(rank==0) then
write(*,*) 'dpdnanov1.25k'
write(*,*)
write(*,*) 'Some technical information'
write(*,*) 'Number of nodes :',nproc
write(*,*) 'Number of nodes in 1 row :',cln
write(*,*)
write(*,*) 'System information'
write(*,*) 'Box size X Y Z :',dlxa,dlya,dlza
write(*,*) 'Box size at each node :',dlx,dly,dlz
write(*,*) 'DPD density :',rho
write(*,*) 'Total number of particles :',npall
write(*,*) 'Types of particles :',typelist(1:ntype)
write(*,*)
write(*,*) 'Integration information'
write(*,*) 'Timestep :',dt
write(*,*) 'Number of steps in 1st stage :',steps1
write(*,*) 'Number of steps in 2nd stage :',steps2
write(*,*) 'Number of steps in 3rd stage :',steps3
write(*,*)
write(*,*) 'DPD Parameters'
write(*,*) 'Sigma :',sigma
write(*,*) 'Gamma :',gamma
do i=1,ntype
do j=i,ntype
write(*,*) 'DPD coeff btw',typelist(i),'and',typelist(j),'is',alpha(typelist(i),typelist(j))
end do
end do
do i=1,ntype
do j=i,ntype
write(*,*) 'Chem probabilities btw',typelist(i),'and',typelist(j),'are',probc(typelist(i),typelist(j)),probb(typelist(i),typelist(j))
end do
end do
write(*,*)
end if
! calculate forces
fsend=0
call forces()
call forcesbond(1)
if (rank==0) start=mpi_wtime()
! start 2nd stage - equilibrium stage
if (rank==0) start=mpi_wtime()
do nstp=1,steps2
! integrate beads positions and velocities
call intr()
! calculate forces
call forces()
call forcesbond(1)
! integrate beads velocoties
call intv()
! perform reactions
if (mod(nstp,chemstp)==0) then
call chem()
end if
! control output
if (mod(nstp,qstp)==0) then
vl=(sum(vz*vz)+sum(vy*vy)+sum(vx*vx))
vl=vl/natms/3
call gsum(vl,1)
vl=vl/nproc
vall(1)=sum(vx)
vall(2)=sum(vy)
vall(3)=sum(vz)
call gsum(vall,3)
call pressure()
if (rank==0) write(*,*)'stage 2', nstp,vl,maxval(abs(vall)),sum(press)/3.0
end if
! control CM velocily
if (mod(nstp,100)==0) call vcontrol()
! output restart file
!if (mod(nstp,rststp)==0.and.rst==1) call writerst()
end do
! finish 2nd stage
! output time
if (rank==0) write(*,*) 'equilibration stage took',mpi_wtime()-start,'s'
! output restart file
if (rst==1) call writerst()
! start 3rd stage - remove overstreched bonds
if (rank==0) start=mpi_wtime()
do nstp=1,steps3
! integrate beads positions and velocities
call intr()
! calculate forces
call forces()
call forcesbond(nstp-2)
! integrate beads velocoties
call intv()
! control output
if (mod(nstp,qstp)==0) then
vl=(sum(vz*vz)+sum(vy*vy)+sum(vx*vx))
vl=vl/natms/3
call gsum(vl,1)
vl=vl/nproc
vall(1)=sum(vx)
vall(2)=sum(vy)
vall(3)=sum(vz)
call gsum(vall,3)
call pressure()
if (rank==0) write(*,*)'removing bonds stage', nstp,vl,maxval(abs(vall)),sum(press)/3.0
end if
! control CM velocily
if (mod(nstp,100)==0) call vcontrol()
! output restart file
if (mod(nstp,rststp)==0.and.rst==1) call writerst()
end do
! finish 3rd stage
! output time
if (rank==0) write(*,*) 'removing bonds stage took',mpi_wtime()-start,'s'
! output restart file
if (rst==1) call writerst()
! delete arrays
call barrier
nullify(rx,ry,rz,vwx,vwy,vwz,fx,fy,fz,vx,vy,vz,kindp,corr,bcorr,bcorrt,sndr,sndl,fanl,rcv,rcvf,fann,fsend)
! end mpi
call mpi_finalize(ierr)
end
subroutine forces()
! #####################################################################
! # #
! # subroutine 1: #
! # calculate all forces: conservative, dissipative, and random #
! # #
! #####################################################################
implicit none
save
common /cell/ dlx,dly,dlz,rcut,kpbc
common /sizes/ sz
common /bxsize/ ilx,ily,ilz
common /na/ natms,natmsfan
common /rxyz/ rx,ry,rz
common /fxyz/ fx,fy,fz
common /vwxyz/ vwx,vwy,vwz
common /ptype/ kindp
common /shwi/ shwi
common /prs/ press
integer*4 sz
integer*4 ilx,ily,ilz
real*4,pointer :: rx(:,:),ry(:,:),rz(:,:)
real*4,pointer :: vwx(:,:),vwy(:,:),vwz(:,:)
real*4,pointer :: fx(:),fy(:),fz(:)
integer*1,pointer :: kindp(:,:)
integer*4,pointer :: fmap(:,:,:)
real*4,pointer :: fmapc(:,:)
logical init
integer*4 link(sz,2),lct(ilx+1,0:ily+1,ilz)
integer*4 natms,natmsfan
integer*4 ncells,ix,iy,iz,jx,jy,jz
real*4 dlx,dly,dlz,rcut,rcsq,shwi
integer*4 i,j,ic,kc,ii
integer*4 kpbc
real*4 xd,yd,zd,rsq,cz
integer*4 arrtype
real*4 press(3)
data init/.true./
! set initial values
if (init) then
init=.false.
rcsq=rcut**2
allocate (fmap(3,18,(ilx+1)*(ily+1)*(ilz+1)),fmapc(18,(ilx+1)*(ily+1)*(ilz+1)))
end if
! create subcells map
ncells=ilx*ily*ilz
call fmaps(fmap,fmapc)
! zero arrays
fx=0
fy=0
fz=0
press=0
link=0
lct=0
! create linked list for real particles
do i=1,natms
ix=min(int(rx(i,1)/rcut),ilx-1)+1
iy=min(int(ry(i,1)/rcut),ily-1)+1
iz=min(int(rz(i,1)/rcut),ilz-1)+1
j=lct(ix,iy,iz)
lct(ix,iy,iz)=i
link(i,1)=j
end do
! create linked list for ghost particles
do i=1,natmsfan
if (rx(i,2)>=(dlx+rcut)) then
cycle
elseif (rx(i,2)<dlx) then
ix=min(int(rx(i,2)/rcut),ilx-1)+1
elseif (rx(i,2)<(dlx+rcut)) then
ix=ilx+1
end if
if (ry(i,2)>=(dly+rcut).or.ry(i,2)<=(-rcut)) then
cycle
elseif (ry(i,2)<0) then
iy=0
elseif (ry(i,2)<dly) then
iy=min(int(ry(i,2)/rcut),ily-1)+1
elseif (ry(i,2)<(dly+rcut)) then
iy=ily+1
end if
iz=min(int(rz(i,2)/rcut),ilz-1)+1
j=lct(ix,iy,iz)
lct(ix,iy,iz)=i
link(i,2)=j
end do
! primary loop over subcells
iz=1
iy=1
ix=1
do ic=1,ncells
ii=lct(ix,iy,iz)
if (ii>0) then
! secondary loop over subcells
do kc=1,17
i=ii
cz=fmapc(kc,ic)
jx=fmap(1,kc,ic)
jy=fmap(2,kc,ic)
jz=fmap(3,kc,ic)
if (jx<0) exit
j=lct(jx,jy,jz)
! ignore if empty
if (j>0) then
arrtype=1
if (jx>ilx.or.jy>ily) arrtype=2
do while(i/=0)
! check if the subcells are identical
if ((jx==ix).and.(jy==iy).and.(jz==iz)) j=link(i,1)
if (j>0) then
do while(j/=0)
! distance in space
xd=-(rx(j,arrtype)-rx(i,1))
yd=-(ry(j,arrtype)-ry(i,1))
zd=-(rz(j,arrtype)-rz(i,1)+cz)
rsq = xd*xd + yd*yd + zd*zd
! test the distance
if (rcsq>rsq) call fcdrij(i,j,rsq,xd,yd,zd,arrtype)
! go to the next particle (second subcell)
j=link(j,arrtype)
end do
end if
! return to the first particle (second subcell)
j=lct(jx,jy,jz)
! go to the next particle (first subcell)
i=link(i,1)
end do
end if
end do
end if
! move to the next subcell
ix=ix+1
if (ix>ilx) then
ix=1
iy=iy+1
if(iy>ily)then
iy=1
iz=iz+1
end if
end if
end do
! send forces acting on right "ghost" particles
call fsendunpck()
end
subroutine fmaps(fmap,fmapc)
! #####################################################################
! # #
! # subroutine 2: #
! # create map of cubcells neighbours #
! # for forces #
! # #
! #####################################################################
implicit none
common /bxsize/ ilx,ily,ilz
common /cell/ dlx,dly,dlz,rcut,kpbc
real*4 dlx,dly,dlz,rcut
integer*4 kpbc
integer*4 ilx,ily,ilz
integer*4 ic,kc
integer*4 nsbcll,ncells,ix,iy,iz,jx,jy,jz
real*4 cy,cz
integer*4 fmap(3,18,*)
real*4 fmapc(18,*)
integer*4 nix,niy,niz,nix1,niy1,niz1,nix2,niy2,niz2,nix3,niy3,niz3,nix4,niy4,niz4
dimension nix(18),niy(18),niz(18),nix1(14),niy1(14),niz1(14),nix2(17),niy2(17),niz2(17),nix3(11),niy3(11),niz3(11),nix4(14),niy4(14),niz4(14)
data nix1/0,0,0,1, 0,0, 1, 1,1,1, 1, 1, 1,1/
data niy1/0,0,1,0, 1,1,-1, 0,0,1,-1,-1, 1,1/
data niz1/0,1,0,0,-1,1, 0,-1,1,0,-1, 1,-1,1/
data nix2/0,0,0,1, 0,0, 1, 1,1,1, 1, 1, 1,1,-1,-1,-1/
data niy2/0,0,1,0, 1,1,-1, 0,0,1,-1,-1, 1,1, 1, 1, 1/
data niz2/0,1,0,0,-1,1, 0,-1,1,0,-1, 1,-1,1, 1, 0,-1/
data nix3/0,0,0,1, 0,0, 1,1,1, 1,1/
data niy3/0,0,1,0, 1,1, 0,0,1, 1,1/
data niz3/0,1,0,0,-1,1,-1,1,0,-1,1/
data nix4/0,0,0,1, 0,0, 1,1,1, 1,1,-1,-1,-1/
data niy4/0,0,1,0, 1,1, 0,0,1, 1,1, 1, 1, 1/
data niz4/0,1,0,0,-1,1,-1,1,0,-1,1, 1, 0,-1/
iz=1
iy=1
ix=1
fmap(:,:,1:ilx*ily*ilz)=-1
fmapc(:,1:ilx*ily*ilz)=0
ncells=ilx*ily*ilz
! loop over subcells
do ic=1,ncells
! case 1 - thin domain along X
if (ilx==1) then
nix(1:14)=nix1
niy(1:14)=niy1
niz(1:14)=niz1
nsbcll=14
goto 335
end if
! case 2 - thin domain along Y
if (ily==1) then
nix(1:14)=nix4
niy(1:14)=niy4
niz(1:14)=niz4
nsbcll=14
if (ix==1) then
nix(1:11)=nix3
niy(1:11)=niy3
niz(1:11)=niz3
nsbcll=11
elseif (ix==ilx) then
nix(1:17)=nix2
niy(1:17)=niy2
niz(1:17)=niz2
nsbcll=17
end if
goto 335
end if
! case 3 - normal domain
if (iy==1.and.ix<ilx) then
nix(1:11)=nix3
niy(1:11)=niy3
niz(1:11)=niz3
nsbcll=11
elseif (iy==ily.and.ix>1) then
nix(1:17)=nix2
niy(1:17)=niy2
niz(1:17)=niz2
nsbcll=17
else
nix(1:14)=nix1
niy(1:14)=niy1
niz(1:14)=niz1
nsbcll=14
end if
335 continue
! put all data to arrays
do kc=1,nsbcll
jx=ix+nix(kc)
jy=iy+niy(kc)
jz=iz+niz(kc)
cz=0
if(jz>ilz)then
jz=jz-ilz
cz=dlz
elseif(jz<1)then
jz=jz+ilz
cz=-dlz
end if
fmap(1,kc,ic)=jx
fmap(2,kc,ic)=jy
fmap(3,kc,ic)=jz
fmapc(kc,ic)=cz
end do
! move to the next subcell
ix=ix+1
if (ix>ilx) then
ix=1
iy=iy+1
if(iy>ily)then
iy=1
iz=iz+1
end if
end if
end do
end
subroutine fcdrij (i,j,rsq,xd,yd,zd,arrtype)
! #####################################################################
! # #
! # subroutine 3: #
! # calculate all forces: conservative, dissipative, and random #
! # for 1 pair of particles #
! # #
! #####################################################################
implicit none
save
common /data/ alpha,sigma,gamma
common /time/ dt
common /sizes/ sz
common /fxyz/ fx,fy,fz
common /vwxyz/ vwx,vwy,vwz
common /ptype/ kindp
common /commf/ fsend,rcou
common /prs/ press
real*4,pointer :: vwx(:,:),vwy(:,:),vwz(:,:)
real*4,pointer :: fx(:),fy(:),fz(:)
integer*1,pointer :: kindp(:,:)
real*4,pointer :: fsend(:)
real*4,pointer :: alpha(:,:)
integer*4 sz
real*4 dt2inv,sigma,rfac,dt,gamma
real*4 rij,rsq,rijinv,exij,eyij,ezij,xd,yd,zd
real*4 omega
integer*4 rcou(4)
real*4 vxij,vyij,vzij
real*4 fcfac,fdfac,frfac,fctot,fcxij,fcyij,fczij
real*4 uni
integer*4 arrtype,nfi,nfj
integer*4 i,j
real*4 press(3)
logical init/.true./
! set initial values
if (init) then
init = .false.
rfac=sqrt(3.d0)
dt2inv=sigma*rfac/sqrt(dt)
end if
! calculate distance between particles
rij=sqrt(rsq)
rijinv=1.0/rij
omega=1.0 - rij
! calculate distance vector projections
exij=xd*rijinv
eyij=yd*rijinv
ezij=zd*rijinv
! calculate relative velocity
vxij=vwx(i,1) - vwx(j,arrtype)
vyij=vwy(i,1) - vwy(j,arrtype)
vzij=vwz(i,1) - vwz(j,arrtype)
! get type of particles
nfi=kindp(i,1)
nfj=kindp(j,arrtype)
! calculate the pairwise concervative force
fcfac=omega*alpha(nfi,nfj)
! calculate the pairwise dissipative force
fdfac=-gamma*omega*omega*(exij*vxij + eyij*vyij + ezij*vzij)
! calculate the pairwise random force
frfac=omega*dt2inv*(2.0*uni()-1.0)
! calculate the total force
fctot =fcfac + fdfac + frfac
! calculate force projections
fcxij=fctot * exij
fcyij=fctot * eyij
fczij=fctot * ezij
fx(i)=fx(i) + fcxij
fy(i)=fy(i) + fcyij
fz(i)=fz(i) + fczij
! calculate pressure
press(3)=press(3)+fcfac*ezij*ezij/rijinv
press(2)=press(2)+fcfac*eyij*eyij/rijinv
press(1)=press(1)+fcfac*exij*exij/rijinv
! apply Newton 3rd law
if (arrtype==1) then
fx(j)=fx(j) - fcxij
fy(j)=fy(j) - fcyij
fz(j)=fz(j) - fczij
else
! apply forces to "ghost" beads
fsend(3*j-2)=-fcxij+fsend(3*j-2)
fsend(3*j-1)=-fcyij+fsend(3*j-1)
fsend(3*j)=-fczij+fsend(3*j)
end if
end
subroutine fsendunpck()
! #####################################################################
! # #
! # subroutine 4: #
! # send and receive forces #
! # send to the "right", receive from the "left" #
! # update forces matrix acting on "real" particles #
! # #
! #####################################################################
implicit none
include 'mpif.h'
save
common /funnumb/ npl,fann
common /fxyz/ fx,fy,fz
common /commf/ fsend,rcou
common /na/ natms,natmsfan
common /sndrcv/ sndr,sndl,fanl,fanr,rcv,rcvf
common /mpidpd/ rank, nproc
common /top/ cln,nrow,ncol
real*4,pointer :: sndr(:,:),sndl(:,:),fanl(:,:),fanr(:,:),rcv(:),rcvf(:) !size ssz,4;ssz,4;fsz,4;fsz,4;ssz*8,fsz*8
real*4,pointer :: fx(:),fy(:),fz(:) ! size sz
real*4,pointer :: fsend(:) ! size 3*fsz/2
integer*4,pointer :: fann(:,:) !size fsz/8,4
integer*4 npl(4),natms,natmsfan,i,j,k,m,indcur
integer*4 rcou(4)
integer*4 rank, nproc,cln,nrow,ncol
integer lproc(4),rproc(4)
integer ierr
integer status(MPI_STATUS_SIZE)
logical init /.true./
! set nodes exchange matrix
if (init) then
lproc(3)=rank-1
if (ncol==1) lproc(3)=rank+cln-1
lproc(2)=lproc(3)-cln
if (nrow==1) lproc(2)=nproc-cln+lproc(3)
lproc(4)=lproc(3)+cln
if (nrow==nproc/cln) lproc(4)=lproc(3)-nproc+cln
lproc(1)=rank-cln
if (nrow==1) lproc(1)=nproc-cln+rank
rproc(3)=rank+1
if (ncol==cln) rproc(3)=rank-cln+1
rproc(2)=rproc(3)+cln
if (nrow==nproc/cln) rproc(2)=rproc(3)-nproc+cln
rproc(4)=rproc(3)-cln
if (nrow==1) rproc(4)=nproc-cln+rproc(3)
rproc(1)=rank+cln
if (nrow==nproc/cln) rproc(1)=rank-nproc+cln
init=.false.
end if
! send and receive forces; update forces matrix
indcur=1
do m=1,4
if (rproc(m)==rank) then
rcvf(1:rcou(m))=fsend(indcur:indcur-1+rcou(m))
else
call MPI_Sendrecv(fsend(indcur), rcou(m), MPI_real,rproc(m), 1,rcvf, 3*npl(m), MPI_real, lproc(m), 1, MPI_Comm_world, status,ierr )
end if
indcur=indcur+rcou(m)
j=1
do i=1,3*npl(m),3
k=fann(j,m)
fx(k)=fx(k)+rcvf(i)
fy(k)=fy(k)+rcvf(i+1)
fz(k)=fz(k)+rcvf(i+2)
j=j+1
end do
end do
fsend=0
end
real*4 function uni()
! #####################################################################
! # #
! # function 5: #
! # random number generator based on the universal random number #
! # generator of marsaglia, zaman and tsang #
! # (stats and prob. lett. 8 (1990) 35-39.) #
! # #
! # it must be called once to initialise parameters u,c,cd,cm #
! # #
! #####################################################################
implicit none
common /mpidpd/ rank, nproc
logical,save :: init
data init /.true./
integer,save :: ir,jr
integer i,ii,j,jj,k,l,m,idnode
real*8,save :: c,cd,cm,u(1:97)
real*8 s,t
integer*4 nproc,rank
! initialise parameters u,c,cd,cm
if (init) then
init = .false.
! initial values of i,j,k must be in range 1 to 178 (not all 1)
! initial value of l must be in range 0 to 168
i = mod(rank,166) + 12
j = mod(rank,144) + 34
k = mod(rank,122) + 56
l = mod(rank,90) + 78
ir = 97
jr = 33
do ii=1,97
s = 0.0d0
t = 0.5d0
do jj=1,24
m = mod(mod(i*j,179)*k,179)
i = j
j = k
k = m
l = mod(53*l+1,169)
if (mod(l*m,64)>=32) s = s+t
t = 0.5d0*t
end do
u(ii)=s
end do
c = 362436.0d0/16777216.0d0
cd = 7654321.0d0/16777216.0d0
cm = 16777213.0d0/16777216.0d0
end if
! calculate random number
uni=u(ir)-u(jr)
if (uni < 0.0d0) uni = uni + 1.0d0
u(ir)=uni
ir=ir-1
if (ir == 0) ir = 97
jr=jr-1
if (jr == 0) jr = 97
c = c-cd
if (c < 0.0d0) c = c+cm
uni = uni-c
if (uni < 0.0d0) uni = uni + 1.0d0
end
subroutine intr()
! #################################################################
! # #
! # subroutine 6: #
! # integrate the positions of the particles, #
! # send leaving and ghost particles #
! # #
! #################################################################
implicit none
save
common /sizes/ sz
common /time/ dt
common /na/ natms,natmsfan
common /nab/ natmsfanbond
common /comm/ ssz,fsz
common /npall/ npall
common /rxyz/ rx,ry,rz
common /fxyz/ fx,fy,fz
common /vxyz/ vx,vy,vz
common /vwxyz/ vwx,vwy,vwz
common /correl/ corr,bcorr,bcorrt
common /ptype/ kindp
common /cell/ dlx,dly,dlz,rcut,kpbc
common /sndrcv/ sndr,sndl,fanl,fanr,rcv,rcvf
common /funnumb/ npl,fann
common /shwi/ shwi
common /lambd/ lambda
integer*4 sz,ssz,fsz,npall
real*4,pointer :: sndr(:,:),sndl(:,:),fanl(:,:),fanr(:,:),rcv(:),rcvf(:)
real*4,pointer :: rx(:,:),ry(:,:),rz(:,:)
real*4,pointer :: vwx(:,:),vwy(:,:),vwz(:,:)
real*4,pointer :: fx(:),fy(:),fz(:)
real*4,pointer :: vx(:),vy(:),vz(:)
integer*4,pointer :: corr(:,:),bcorr(:)
integer*1,pointer :: bcorrt(:)
integer*1,pointer :: kindp(:,:)
integer*4,pointer :: fann(:,:)
real*4 dt
real*4 vwxb,vwyb,vwzb,vxb,vyb,vzb,rxb,ryb,rzb
real*4 lambda,dtlam,dt2
real*4 dlx,dly,dlz,rcut,shwi
integer*4 natms,natmsfan,natmsfanbond
integer*4 i,j,shft,r1(4),l1(4),lr(4),rl(4)
integer*4 res,fan,kpbc,resfan,neinum
integer*4 npl(4)
integer*4 neinumb(2),neilist(4,2)
real*4 rxres(4,2),ryres(4,2)
logical init/.true./
! set initial values
if (init) then
dtlam = lambda*dt
dt2 = 0.50*dt
init=.false.
end if
! zero arrays
shft=0
r1=0
l1=0
lr=0
rl=0
fann=0
natmsfan=0
natmsfanbond=0
npl=0
bcorrt=0
! loop over particles, integrate positions and velocities
do i = 1, natms
vwxb = vx(i-shft) + dtlam*fx(i-shft)
vwyb = vy(i-shft) + dtlam*fy(i-shft)
vwzb = vz(i-shft) + dtlam*fz(i-shft)
vxb = vx(i-shft) + dt2*fx(i-shft)
vyb = vy(i-shft) + dt2*fy(i-shft)
vzb = vz(i-shft) + dt2*fz(i-shft)
if (dt*vxb>dlx) call error(60)
if (dt*vyb>dly) call error(61)
rxb = rx(i-shft,1) + dt*vxb
ryb = ry(i-shft,1) + dt*vyb
rzb = rz(i-shft,1) + dt*vzb
! check if ith bead will leave this node's subvolume after integration
call pbc(rxb,ryb,rzb,res,neinum)
! put information about leaving bead to the communication array
if (res==1) then
sndr(r1(neinum)+1,neinum)=rxb
sndr(r1(neinum)+2,neinum)=ryb
sndr(r1(neinum)+3,neinum)=rzb
sndr(r1(neinum)+4,neinum)=vxb
sndr(r1(neinum)+5,neinum)=vyb
sndr(r1(neinum)+6,neinum)=vzb
sndr(r1(neinum)+7,neinum)=vwxb
sndr(r1(neinum)+8,neinum)=vwyb
sndr(r1(neinum)+9,neinum)=vwzb
sndr(r1(neinum)+10,neinum)=real(corr(i-shft,1))
r1(neinum)=r1(neinum)+10
vx(i-shft)=vx(natms-shft)
vy(i-shft)=vy(natms-shft)
vz(i-shft)=vz(natms-shft)
fx(i-shft)=fx(natms-shft)
fy(i-shft)=fy(natms-shft)
fz(i-shft)=fz(natms-shft)
rx(i-shft,1)=rx(natms-shft,1)
ry(i-shft,1)=ry(natms-shft,1)
rz(i-shft,1)=rz(natms-shft,1)
kindp(i-shft,1)=kindp(natms-shft,1)
corr(i-shft,1)=corr(natms-shft,1)
shft=shft+1
elseif (res==-1) then
sndl(l1(neinum)+1,neinum)=rxb
sndl(l1(neinum)+2,neinum)=ryb
sndl(l1(neinum)+3,neinum)=rzb
sndl(l1(neinum)+4,neinum)=vxb
sndl(l1(neinum)+5,neinum)=vyb
sndl(l1(neinum)+6,neinum)=vzb
sndl(l1(neinum)+7,neinum)=vwxb
sndl(l1(neinum)+8,neinum)=vwyb
sndl(l1(neinum)+9,neinum)=vwzb
sndl(l1(neinum)+10,neinum)=real(corr(i-shft,1))
l1(neinum)=l1(neinum)+10
vx(i-shft)=vx(natms-shft)
vy(i-shft)=vy(natms-shft)
vz(i-shft)=vz(natms-shft)
fx(i-shft)=fx(natms-shft)
fy(i-shft)=fy(natms-shft)
fz(i-shft)=fz(natms-shft)
rx(i-shft,1)=rx(natms-shft,1)
ry(i-shft,1)=ry(natms-shft,1)
rz(i-shft,1)=rz(natms-shft,1)
kindp(i-shft,1)=kindp(natms-shft,1)
corr(i-shft,1)=corr(natms-shft,1)
shft=shft+1
! update positions and velocities arrays if the bead remains inside node's subvolume
else
vx(i-shft)=vxb
vy(i-shft)=vyb
vz(i-shft)=vzb
rx(i-shft,1)=rxb
ry(i-shft,1)=ryb
rz(i-shft,1)=rzb
vwx(i-shft,1)=vwxb
vwy(i-shft,1)=vwyb
vwz(i-shft,1)=vwzb
end if
end do
! calculate remaining number of beads; zero arrays
natms=natms-shft
vx(natms+1:)=0
vy(natms+1:)=0
vz(natms+1:)=0
rx(natms+1:,1)=0
ry(natms+1:,1)=0
rz(natms+1:,1)=0
fx(natms+1:)=0
fy(natms+1:)=0
fz(natms+1:)=0
vwx(natms+1:,1)=0
vwy(natms+1:,1)=0
vwz(natms+1:,1)=0
! send and receive leaving atoms
call send(l1,r1,1)
! update beads arrays
call unpck(l1,r1,1)
! define ghost beads
do i=1,natms
rxb=rx(i,1)
ryb=ry(i,1)
call pbcf(rxb,ryb,neinumb,neilist,rxres,ryres)
do j=1,neinumb(1)
neinum=neilist(j,1)
npl(neinum)=npl(neinum)+1
fann(npl(neinum),neinum)=i
fanl(lr(neinum)+1,neinum)=rxres(j,1)
fanl(lr(neinum)+2,neinum)=ryres(j,1)
fanl(lr(neinum)+3,neinum)=rz(i,1)
fanl(lr(neinum)+4,neinum)=vwx(i,1)
fanl(lr(neinum)+5,neinum)=vwy(i,1)
fanl(lr(neinum)+6,neinum)=vwz(i,1)
fanl(lr(neinum)+7,neinum)=real(corr(i,1))
lr(neinum)=lr(neinum)+7
end do