-
Notifications
You must be signed in to change notification settings - Fork 14
/
link-cell.f
391 lines (284 loc) · 14.3 KB
/
link-cell.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
********************************************************************************
** FICHE F.20. ROUTINES TO CONSTRUCT AND USE CELL LINKED-LIST METHOD **
** This FORTRAN code is intended to illustrate points made in the text. **
** To our knowledge it works correctly. However it is the responsibility of **
** the user to test it, if it is to be used in a research application. **
********************************************************************************
C *******************************************************************
C ** CONSTRUCTION OF CELL LINKED-LISTS AND USE IN FORCE ROUTINE. **
C ** **
C ** REFERENCES: **
C ** **
C ** QUENTREC AND BROT, J. COMPUT. PHYS. 13, 430, 1975. **
C ** HOCKNEY AND EASTWOOD, COMPUTER SIMULATION USING PARTICLES, **
C ** MCGRAW HILL, 1981. **
C ** **
C ** ROUTINES SUPPLIED: **
C ** **
C ** SUBROUTINE MAPS **
C ** SETS UP MAP OF CELL STRUCTURE FOR USE IN FORCE **
C ** SUBROUTINE LINKS ( RCUT ) **
C ** SETS UP HEAD OF CHAIN ARRAY AND LINKED LIST **
C ** SUBROUTINE FORCE ( SIGMA, RCUT, V, W ) **
C ** CALCULATES FORCES USING A LINKED LIST **
C ** **
C ** USAGE: **
C ** **
C ** SUBROUTINE MAPS IS CALLED ONCE AT THE START OF A SIMULATION **
C ** TO ESTABLISH CELL NEIGHBOUR IDENTITIES. AT EACH TIMESTEP, **
C ** SUBROUTINE LINKS IS CALLED TO SET UP THE LINKED LIST AND THIS **
C ** IS IMMEDIATELY USED BY SUBROUTINE FORCE. **
C *******************************************************************
SUBROUTINE MAPS
COMMON / BLOCK2 / LIST, HEAD, MAP
C *******************************************************************
C ** ROUTINE TO SET UP A LIST OF NEIGHBOURING CELLS **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** INTEGER M NUMBER OF CELLS IN EACH DIRECTION **
C ** INTEGER MAPSIZ SIZE OF CELL-CELL MAP **
C ** INTEGER MAP(MAPSIZ) LIST OF NEIGHBOURING CELLS **
C ** **
C ** USAGE: **
C ** **
C ** THIS SUBROUTINE SETS UP A LIST OF THE THIRTEEN NEIGHBOURING **
C ** CELLS OF EACH OF THE SMALL CELLS IN THE CENTRAL BOX. THE **
C ** EFFECTS OF THE PERIODIC BOUNDARY CONDITIONS ARE INCLUDED. **
C ** THE SUBROUTINE IS CALLED ONCE AT THE BEGINNING OF THE **
C ** SIMULATION AND THE MAP IS USED IN THE FORCE SUBROUTINE **
C *******************************************************************
INTEGER N, M, NCELL, MAPSIZ
PARAMETER ( N = 1372, M = 5, NCELL = M * M * M )
PARAMETER ( MAPSIZ = 13 * NCELL )
INTEGER LIST(N), HEAD(NCELL), MAP(MAPSIZ)
INTEGER IX, IY, IZ, IMAP, ICELL
C *******************************************************************
C ** STATEMENT FUNCTION TO GIVE CELL INDEX **
ICELL ( IX, IY, IZ) = 1 + MOD ( IX - 1 + M, M )
: + MOD ( IY - 1 + M, M ) * M
: + MOD ( IZ - 1 + M, M ) * M * M
C ** FIND HALF THE NEAREST NEIGHBOURS OF EACH CELL **
DO 50 IZ = 1, M
DO 40 IY = 1, M
DO 30 IX = 1, M
IMAP = ( ICELL ( IX, IY, IZ ) - 1 ) * 13
MAP( IMAP + 1 ) = ICELL( IX + 1, IY , IZ )
MAP( IMAP + 2 ) = ICELL( IX + 1, IY + 1, IZ )
MAP( IMAP + 3 ) = ICELL( IX , IY + 1, IZ )
MAP( IMAP + 4 ) = ICELL( IX - 1, IY + 1, IZ )
MAP( IMAP + 5 ) = ICELL( IX + 1, IY , IZ - 1 )
MAP( IMAP + 6 ) = ICELL( IX + 1, IY + 1, IZ - 1 )
MAP( IMAP + 7 ) = ICELL( IX , IY + 1, IZ - 1 )
MAP( IMAP + 8 ) = ICELL( IX - 1, IY + 1, IZ - 1 )
MAP( IMAP + 9 ) = ICELL( IX + 1, IY , IZ + 1 )
MAP( IMAP + 10 ) = ICELL( IX + 1, IY + 1, IZ + 1 )
MAP( IMAP + 11 ) = ICELL( IX , IY + 1, IZ + 1 )
MAP( IMAP + 12 ) = ICELL( IX - 1, IY + 1, IZ + 1 )
MAP( IMAP + 13 ) = ICELL( IX , IY , IZ + 1 )
30 CONTINUE
40 CONTINUE
50 CONTINUE
RETURN
END
SUBROUTINE LINKS ( RCUT )
COMMON / BLOCK1 / RX, RY, RZ, VX, VY, VZ, FX, FY, FZ
COMMON / BLOCK2 / LIST, HEAD, MAP
C *******************************************************************
C ** ROUTINE TO SET UP LINKED LIST AND THE HEAD OF CHAIN ARRAYS **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** INTEGER N NUMBER OF ATOMS **
C ** INTEGER M NUMBER OF CELLS IN EACH DIRECTION **
C ** INTEGER NCELL TOTAL NUMBER OF CELLS (M**3) **
C ** INTEGER LIST(N) LINKED LIST OF ATOMS **
C ** INTEGER HEAD(NCELL) HEAD OF CHAIN FOR EACH CELL **
C ** REAL RX(N),RY(N),RZ(N) POSITIONS **
C ** REAL RCUT THE CUTOFF DISTANCE FOR THE FORCE **
C ** **
C ** USAGE: **
C ** **
C ** EACH ATOM IS SORTED INTO ONE OF THE M**3 SMALL CELLS. **
C ** THE FIRST ATOM IN EACH CELL IS PLACED IN THE HEAD ARRAY. **
C ** SUBSEQUENT ATOMS ARE PLACED IN THE LINKED LIST ARRAY. **
C ** ATOM COORDINATES ARE ASSUMED TO BE BETWEEN -0.5 AND +0.5. **
C ** THE ROUTINE IS CALLED EVERY TIMESTEP BEFORE THE FORCE ROUTINE.**
C *******************************************************************
INTEGER N, M, NCELL, MAPSIZ
PARAMETER ( N = 1372, M = 5, NCELL = M * M * M )
PARAMETER ( MAPSIZ = 13 * NCELL )
REAL RX(N), RY(N), RZ(N)
REAL VX(N), VY(N), VZ(N)
REAL FX(N), FY(N), FZ(N)
INTEGER HEAD(NCELL), LIST(N), MAP(MAPSIZ)
REAL CELLI, RCUT, CELL
INTEGER ICELL, I
C *******************************************************************
C ** ZERO HEAD OF CHAIN ARRAY **
DO 10 ICELL = 1, NCELL
HEAD(ICELL) = 0
10 CONTINUE
CELLI = REAL ( M )
CELL = 1.0 / CELLI
IF ( CELL .LT. RCUT ) THEN
STOP ' CELL SIZE TOO SMALL FOR CUTOFF '
ENDIF
C ** SORT ALL ATOMS **
DO 20 I = 1, N
ICELL = 1 + INT ( ( RX(I) + 0.5 ) * CELLI )
: + INT ( ( RY(I) + 0.5 ) * CELLI ) * M
: + INT ( ( RZ(I) + 0.5 ) * CELLI ) * M * M
LIST(I) = HEAD(ICELL)
HEAD(ICELL) = I
20 CONTINUE
RETURN
END
SUBROUTINE FORCE ( SIGMA, RCUT, V, W )
COMMON / BLOCK1 / RX, RY, RZ, VX, VY, VZ, FX, FY, FZ
COMMON / BLOCK2 / LIST, HEAD, MAP
C *******************************************************************
C ** ROUTINE TO COMPUTE FORCES AND POTENTIAL USING A LINK LIST **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** INTEGER N NUMBER OF ATOMS **
C ** INTEGER M NUMBER OF CELLS IN EACH DIRECTION **
C ** INTEGER NCELL NUMBER OF SMALL CELLS (M**3) **
C ** INTEGER MAPSIZ SIZE OF CELL-CELL MAP **
C ** INTEGER LIST(N) THE LINKED LIST **
C ** INTEGER HEAD(NCELL) THE HEAD OF CHAIN ARRAY **
C ** INTEGER MAP(MAPSIZ) LIST OF NEIGHBOURING CELLS **
C ** REAL RX(N),RY(N),RZ(N) POSITIONS **
C ** REAL FX(N),FY(N),FZ(N) FORCES **
C ** REAL SIGMA THE LJ LENGTH PARAMETER **
C ** REAL RCUT THE CUT-OFF DISTANCE **
C ** REAL V THE POTENTIAL ENERGY **
C ** REAL W THE VIRIAL **
C ** **
C ** USAGE: **
C ** **
C ** FORCE IS CALLED IN AN MD PROGRAM TO CALCULATE THE FORCE ON **
C ** EACH ATOM. THE ROUTINE IS WRITTEN FOR A LIQUID OF LENNARD **
C ** JONES ATOMS. SUBROUTINE FORCE REQUIRES A LINKED LIST, SET UP **
C ** USING SUBROUTINE LINKS, AND THE MAP OF THE SMALL CELLS SET UP **
C ** USING SUBROUTINE MAPS. **
C *******************************************************************
INTEGER N, M, NCELL, MAPSIZ
PARAMETER ( N = 1372, M = 5, NCELL = M * M * M )
PARAMETER ( MAPSIZ = 13 * NCELL)
REAL RX(N), RY(N), RZ(N)
REAL VX(N), VY(N), VZ(N)
REAL FX(N), FY(N), FZ(N)
INTEGER HEAD(NCELL), LIST(N), MAP(MAPSIZ)
REAL RCUT, SIGMA, V, W
REAL RXI, RYI, RZI, FXIJ, FYIJ, FZIJ, FIJ, RCUTSQ
REAL SIGSQ, FXI, FYI, FZI, SR2, SR6, VIJ, WIJ
REAL RIJSQ, RXIJ, RYIJ, RZIJ
INTEGER ICELL, JCELL0, JCELL, I, J, NABOR
C *******************************************************************
SIGSQ = SIGMA ** 2
RCUTSQ = RCUT ** 2
C ** ZERO FORCES AND POTENTIAL **
DO 10 I = 1, N
FX(I) = 0.0
FY(I) = 0.0
FZ(I) = 0.0
10 CONTINUE
V = 0.0
W = 0.0
C ** LOOP OVER ALL CELLS **
DO 5000 ICELL = 1, NCELL
I = HEAD(ICELL)
C ** LOOP OVER ALL MOLECULES IN THE CELL **
1000 IF ( I .GT. 0 ) THEN
RXI = RX(I)
RYI = RY(I)
RZI = RZ(I)
FXI = FX(I)
FYI = FY(I)
FZI = FZ(I)
C ** LOOP OVER ALL MOLECULES BELOW I IN THE CURRENT CELL **
J = LIST(I)
2000 IF ( J .GT. 0 ) THEN
RXIJ = RXI - RX(J)
RYIJ = RYI - RY(J)
RZIJ = RZI - RZ(J)
RXIJ = RXIJ - ANINT ( RXIJ )
RYIJ = RYIJ - ANINT ( RYIJ )
RZIJ = RZIJ - ANINT ( RZIJ )
RIJSQ = RXIJ * RXIJ + RYIJ * RYIJ + RZIJ * RZIJ
IF ( RIJSQ .LT. RCUTSQ ) THEN
SR2 = SIGSQ / RIJSQ
SR6 = SR2 * SR2 * SR2
VIJ = SR6 * ( SR6 - 1.0 )
WIJ = SR6 * ( SR6 - 0.5 )
V = V + VIJ
W = W + WIJ
FIJ = WIJ / RIJSQ
FXIJ = FIJ * RXIJ
FYIJ = FIJ * RYIJ
FZIJ = FIJ * RZIJ
FXI = FXI + FXIJ
FYI = FYI + FYIJ
FZI = FZI + FZIJ
FX(J) = FX(J) - FXIJ
FY(J) = FY(J) - FYIJ
FZ(J) = FZ(J) - FZIJ
ENDIF
J = LIST(J)
GO TO 2000
ENDIF
C ** LOOP OVER NEIGHBOURING CELLS **
JCELL0 = 13 * (ICELL - 1)
DO 4000 NABOR = 1, 13
JCELL = MAP ( JCELL0 + NABOR )
C ** LOOP OVER ALL MOLECULES IN NEIGHBOURING CELLS **
J = HEAD(JCELL)
3000 IF ( J .NE. 0 ) THEN
RXIJ = RXI - RX(J)
RYIJ = RYI - RY(J)
RZIJ = RZI - RZ(J)
RXIJ = RXIJ - ANINT ( RXIJ )
RYIJ = RYIJ - ANINT ( RYIJ )
RZIJ = RZIJ - ANINT ( RZIJ )
RIJSQ = RXIJ * RXIJ + RYIJ * RYIJ + RZIJ * RZIJ
IF ( RIJSQ. LT. RCUTSQ ) THEN
SR2 = SIGSQ / RIJSQ
SR6 = SR2 * SR2 * SR2
VIJ = SR6 * ( SR6 - 1.0 )
WIJ = SR6 * ( SR6 - 0.5 )
V = V + VIJ
W = W + WIJ
FIJ = WIJ / RIJSQ
FXIJ = FIJ * RXIJ
FYIJ = FIJ * RYIJ
FZIJ = FIJ * RZIJ
FXI = FXI + FXIJ
FYI = FYI + FYIJ
FZI = FZI + FZIJ
FX(J) = FX(J) - FXIJ
FY(J) = FY(J) - FYIJ
FZ(J) = FZ(J) - FZIJ
ENDIF
J = LIST(J)
GO TO 3000
ENDIF
4000 CONTINUE
FX(I) = FXI
FY(I) = FYI
FZ(I) = FZI
I = LIST(I)
GO TO 1000
ENDIF
5000 CONTINUE
C ** INCORPORATE ENERGY FACTORS **
V = 4.0 * V
W = 48.0 * W / 3.0
DO 50 I = 1, N
FX(I) = 48.0 * FX(I)
FY(I) = 48.0 * FY(I)
FZ(I) = 48.0 * FZ(I)
50 CONTINUE
RETURN
END