-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdalgo.f90
434 lines (325 loc) · 12.6 KB
/
mdalgo.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
module mdalgo
!
!
! Purpose :
! Contains propagation algorithms
!
! Date Author History of Revison
! ==== ====== ==================
! 18.02.2014 Svenja M. Janke Original
! Sascha Kandratsenka
! Dan J. Auerbach
use atom_class
use useful_things
use open_file
use force
implicit none
contains
subroutine propagator_1(s, md_algo, imass)
!
! Purpose:
! select algorithm and calculate 1st and 2nd step
!
type(atoms) :: s
integer :: md_algo
real(8) :: imass
select case (md_algo)
case (1) ! velocity Verlet Algorithm
call verlet_1(s)
case (2) ! Refson-Beeman Algorithm
call beeman_1(s)
case (3) ! Langevin
call langevin_1(s,imass)
case (4) ! Langevin up to 2nd order
call langevins_1(s,imass)
case(5)
call verlet_1(s)
end select
end subroutine propagator_1
subroutine propagator_2(s, md_algo, imass)
!
! Purpose:
! select algorithm and calculate 3rd and 4th step
!
type(atoms) :: s
integer :: md_algo
real(8) :: imass, norm
select case (md_algo)
case (1) ! velocity Verlet Algorithm
call newton(s, imass)
call verlet_2(s)
case (2) ! Refson-Beeman Algorithm
do
call newton(s, imass)
call beeman_2(s)
call norm_dist(s%vp, s%vc, 3*s%n_atoms, norm)
if (norm < 1.0e-007) then
s%v = s%vc
s%au = s%ao
s%ao = s%a
exit
else
s%vp = s%vc
end if
end do
case (3) ! Langevin
call ldfa(s,imass)
call newton(s, imass)
call langevin_2(s,imass)
case (4) ! Langevin up to 2nd order
call ldfa(s,imass)
call newton(s, imass)
call langevins_2(s,imass)
case (5)
call newton(s, imass)
call verlet_2(s)
end select
end subroutine propagator_2
subroutine verlet_1(s)
!
! Purpose:
! 1st and 2nd steps of velocity Verlet algorithm,
! Allen & Tildesley, Computer Simulation of Liquids (1987).
!
type(atoms) :: s
integer :: nf ! skip fixed atoms
nf = s%nofix
! half-step velocities
s%v(:,1:nf) = s%v(:,1:nf) + 0.5d0*step*s%a(:,1:nf)
! new positions
s%r(:,1:nf) = s%r(:,1:nf) + step*s%v(:,1:nf)
end subroutine verlet_1
subroutine verlet_2(s)
!
! Purpose:
! 3rd step of velocity Verlet algorithm,
! Allen & Tildesley, Computer Simulation of Liquids (1987).
!
type(atoms) :: s
integer :: nf ! skip fixed atoms
nf = s%nofix
! new velocities
s%v(:,1:nf) = s%v(:,1:nf) + 0.5d0*step*s%a(:,1:nf)
end subroutine verlet_2
subroutine beeman_1(s)
!
! Purpose:
! 1st and 2nd steps of Refson-Beeman algorithm,
! K. Refson, Physica 131B, (1985), 256.
! Moldy User's Manual.
!
type(atoms) :: s
real(8) :: step_sq
integer :: nf ! skip fixed atoms
nf = s%nofix
step_sq = step * step / 6.0d0
! new positions
s%r(:,1:nf) = s%r(:,1:nf) + step*s%v(:,1:nf) &
+ step_sq*(4.0*s%ao(:,1:nf) - s%au(:,1:nf))
! predicted velocities
s%vp(:,1:nf) = s%v(:,1:nf) + 0.5d0*step*(3.0d0*s%ao(:,1:nf)&
- s%au(:,1:nf))
end subroutine beeman_1
subroutine beeman_2(s)
!
! Purpose:
! 4th step of Refson-Beeman algorithm,
! K. Refson, Physica 131B, (1985), 256.
! Moldy User's Manual.
!
type(atoms) :: s
integer :: nf ! skip fixed atoms
nf = s%nofix
s%vc(:,1:nf) = s%v(:,1:nf) + step/6.0d0*(2.0d0*s%a(:,1:nf)&
+ 5.0d0*s%ao(:,1:nf) - s%au(:,1:nf))
end subroutine beeman_2
subroutine langevin_1(s, imass)
!
! Purpose:
! 1st step of Langevin Dynamics algorithm,
! Dellago et al. JCP 108 (1998) 1964
!
type(atoms) :: s
real(8) :: imass, temp
real(8), dimension( s%nofix) :: c0, c1, c2, xidt, ixidt, sigma_r, sigma_v, c_rv
real(8), dimension(3,s%nofix) :: randy, cofm
integer :: nf, i
nf = s%nofix
temp = kB*Tsurf*imass
xidt = (s%dens(1:nf)*step)
ixidt = step/xidt
do i = 1, nf
! Preventing problems due to precision issues
if (xidt(i) > 1.0d-2 .and. Tsurf > 0.0001d0) then ! use precise expressions
c0(i) = exp(-xidt(i))
c1(i) = (1.0d0 - c0(i))*ixidt(i)
c2(i) = (1.0d0 - c1(i)/step)*ixidt(i)
sigma_r(i) = ixidt(i)*sqrt(temp*(2.d0*xidt(i) - 3.d0 + 4.d0*c0(i) - c0(i)**2))
sigma_v(i) = sqrt(temp*(1.d0 - c0(i)**2))
c_rv(i) = ixidt(i)*temp*(1.d0 - c0(i))**2/(sigma_r(i)*sigma_v(i))
randy(1,i) = normal(0.0d0,1.0d0)
randy(2,i) = normal(0.0d0,1.0d0)
randy(3,i) = normal(0.0d0,1.0d0)
else ! use series up to 2nd order in xi*dt
c0(i) = 1.0d0 - xidt(i) + 0.50d0*xidt(i)**2
c1(i) = (1.0d0 - 0.50d0*xidt(i) + 2.0d0*twelfth*xidt(i)**2)*step
c2(i) = (0.5d0 - 2.0d0*twelfth*xidt(i) + 0.50d0*twelfth*xidt(i)**2)*step
sigma_r(i) = step*sqrt(temp*(8.0d0*twelfth*xidt(i) - 0.50d0*xidt(i)**2))
sigma_v(i) = sqrt(temp*2.0d0*(xidt(i) - xidt(i)**2))
c_rv(i) = 0.5d0*sqrt3*(1.0d0 - 0.125d0*xidt(i))
randy(1,i) = normal(0.0d0,1.0d0)
randy(2,i) = normal(0.0d0,1.0d0)
randy(3,i) = normal(0.0d0,1.0d0)
end if
end do
cofm(1,:) = sigma_r*randy(1,:)
cofm(2,:) = sigma_r*randy(2,:)
cofm(3,:) = sigma_r*randy(3,:)
! propagate positions
s%r(1,1:nf) = s%r(1,1:nf) + c1*s%v(1,1:nf) + c2*step*s%a(1,1:nf) + cofm(1,:)
s%r(2,1:nf) = s%r(2,1:nf) + c1*s%v(2,1:nf) + c2*step*s%a(2,1:nf) + cofm(2,:)
s%r(3,1:nf) = s%r(3,1:nf) + c1*s%v(3,1:nf) + c2*step*s%a(3,1:nf) + cofm(3,:)
cofm(1,:) = sigma_v*c_rv*randy(1,:)
cofm(2,:) = sigma_v*c_rv*randy(2,:)
cofm(3,:) = sigma_v*c_rv*randy(3,:)
! partially propagate velocities
s%v(1,1:nf) = c0*s%v(1,1:nf) + (c1 - c2)*s%a(1,1:nf) + cofm(1,:)
s%v(2,1:nf) = c0*s%v(2,1:nf) + (c1 - c2)*s%a(2,1:nf) + cofm(2,:)
s%v(3,1:nf) = c0*s%v(3,1:nf) + (c1 - c2)*s%a(3,1:nf) + cofm(3,:)
end subroutine langevin_1
subroutine langevin_2(s, imass)
!
! Purpose:
! 1st step of Langevin Dynamics algorithm,
! Dellago et al. JCP 108 (1998) 1964
!
type(atoms) :: s
real(8) :: imass, temp
real(8), dimension( s%nofix) :: c0, c1, c2, xidt, ixidt, sigma_r, sigma_v, c_rv
real(8), dimension(3,s%nofix) :: randy, cofm
integer :: nf, i
nf = s%nofix
temp = kB*Tsurf*imass
xidt = (s%dens(1:nf)*step)
ixidt = step/xidt
do i = 1, nf
! Preventing problems due to precision issues
if (xidt(i) > 1.0d-2 .and. Tsurf > 0.0001d0) then ! use precise expressions
c0(i) = exp(-xidt(i))
c1(i) = (1.0d0 - c0(i))*ixidt(i)
c2(i) = (1.0d0 - c1(i)/step)*ixidt(i)
sigma_r(i) = ixidt(i)*sqrt(temp*(2.d0*xidt(i) - 3.d0 + 4.d0*c0(i) - c0(i)**2))
sigma_v(i) = sqrt(temp*(1.d0 - c0(i)**2))
c_rv(i) = ixidt(i)*temp*(1.d0 - c0(i))**2/(sigma_r(i)*sigma_v(i))
randy(1,i) = normal(0.0d0,1.0d0)
randy(2,i) = normal(0.0d0,1.0d0)
randy(3,i) = normal(0.0d0,1.0d0)
else ! use series up to 2nd order in xi*dt
c0(i) = 1.0d0 - xidt(i) + 0.50d0*xidt(i)**2
c1(i) = (1.0d0 - 0.50d0*xidt(i) + 2.0d0*twelfth*xidt(i)**2)*step
c2(i) = (0.5d0 - 2.0d0*twelfth*xidt(i) + 0.50d0*twelfth*xidt(i)**2)*step
sigma_r(i) = step*sqrt(temp*(8.0d0*twelfth*xidt(i) - 0.50d0*xidt(i)**2))
sigma_v(i) = sqrt(temp*2.0d0*(xidt(i) - xidt(i)**2))
c_rv(i) = 0.5d0*sqrt3*(1.0d0 - 0.125d0*xidt(i))
randy(1,i) = normal(0.0d0,1.0d0)
randy(2,i) = normal(0.0d0,1.0d0)
randy(3,i) = normal(0.0d0,1.0d0)
end if
end do
cofm(1,:) = sigma_v*sqrt(1 - c_rv*c_rv)*randy(1,:)
cofm(2,:) = sigma_v*sqrt(1 - c_rv*c_rv)*randy(2,:)
cofm(3,:) = sigma_v*sqrt(1 - c_rv*c_rv)*randy(3,:)
! partially propagate velocities
s%v(1,1:nf) = s%v(1,1:nf) + c2*s%a(1,1:nf) + cofm(1,:)
s%v(2,1:nf) = s%v(2,1:nf) + c2*s%a(2,1:nf) + cofm(2,:)
s%v(3,1:nf) = s%v(3,1:nf) + c2*s%a(3,1:nf) + cofm(3,:)
end subroutine langevin_2
subroutine langevins_1(s, imass)
!
! Purpose:
! 1st step of Langevin Dynamics algorithm,
! Allen & Tildesley, Computer Simulation of Liquids (1987).
! Li & Wahnström, Phys. Rev. B (1992).
!
type(atoms) :: s
real(8) :: imass, temp
real(8), dimension( s%nofix) :: c0, c1, c2, xidt, sigma_r, sigma_v, c_rv
real(8), dimension(3,s%nofix) :: randy, cofm
integer :: i
integer :: nf ! skip fixed atoms
nf = s%nofix
xidt = (s%dens(1:nf)*step)
c0 = 1.0d0 - xidt + 0.50d0*xidt*xidt
c1 = (1.0d0 - 0.50d0*xidt + 2.0d0*twelfth*xidt*xidt)*step
c2 = (0.5d0 - 2.0d0*twelfth*xidt + 0.5d0*twelfth*xidt*xidt)*step
temp = kB*Tsurf*imass
sigma_r = step*sqrt(temp*(8.0d0*twelfth - 0.5d0*xidt)*xidt)
sigma_v = sqrt(temp*2.0d0*(1.0d0 - xidt)*xidt)
c_rv = 0.5d0*sqrt3*(1.0d0 - 0.125d0*xidt)
do i =1, nf
randy(1,i) = normal(0.0d0,1.0d0)
randy(2,i) = normal(0.0d0,1.0d0)
randy(3,i) = normal(0.0d0,1.0d0)
end do
cofm(1,:) = sigma_r*randy(1,:)
cofm(2,:) = sigma_r*randy(2,:)
cofm(3,:) = sigma_r*randy(3,:)
! propagate positions
s%r(1,1:nf) = s%r(1,1:nf) + c1*s%v(1,1:nf) + c2*step*s%a(1,1:nf) + cofm(1,:)
s%r(2,1:nf) = s%r(2,1:nf) + c1*s%v(2,1:nf) + c2*step*s%a(2,1:nf) + cofm(2,:)
s%r(3,1:nf) = s%r(3,1:nf) + c1*s%v(3,1:nf) + c2*step*s%a(3,1:nf) + cofm(3,:)
cofm(1,:) = sigma_v*c_rv*randy(1,:)
cofm(2,:) = sigma_v*c_rv*randy(2,:)
cofm(3,:) = sigma_v*c_rv*randy(3,:)
! partially propagate velocities
s%v(1,1:nf) = c0*s%v(1,1:nf) + (c1 - c2)*s%a(1,1:nf) + cofm(1,:)
s%v(2,1:nf) = c0*s%v(2,1:nf) + (c1 - c2)*s%a(2,1:nf) + cofm(2,:)
s%v(3,1:nf) = c0*s%v(3,1:nf) + (c1 - c2)*s%a(3,1:nf) + cofm(3,:)
end subroutine langevins_1
subroutine langevins_2(s, imass)
!
! Purpose:
! 1st step of Langevin Dynamics algorithm,
! Allen & Tildesley, Computer Simulation of Liquids (1987).
! Li & Wahnström, Phys. Rev. B (1992).
!Ŕ
type(atoms) :: s
real(8) :: imass, temp
real(8), dimension( s%nofix) :: c0, c1, c2, xidt, sigma_r, sigma_v, c_rv
real(8), dimension(3,s%nofix) :: randy, cofm
integer :: i
integer :: nf ! skip fixed atoms
nf = s%nofix
xidt = (s%dens(1:nf)*step)
c0 = 1.0d0 - xidt + 0.50d0*xidt*xidt
c1 = (1.0d0 - 0.50d0*xidt + 2.0d0*twelfth*xidt*xidt)*step
c2 = (0.5d0 - 2.0d0*twelfth*xidt + 0.5d0*twelfth*xidt*xidt)*step
temp = kB*Tsurf*imass
sigma_r = step*sqrt(temp*(8.0d0*twelfth - 0.5d0*xidt)*xidt)
sigma_v = sqrt(temp*2.0d0*(1.0d0 - xidt)*xidt)
c_rv = 0.5d0*sqrt3*(1.0d0 - 0.125d0*xidt)
do i =1, nf
randy(1,i) = normal(0.0d0,1.0d0)
randy(2,i) = normal(0.0d0,1.0d0)
randy(3,i) = normal(0.0d0,1.0d0)
end do
cofm(1,:) = sigma_v*sqrt(1 - c_rv*c_rv)*randy(1,:)
cofm(2,:) = sigma_v*sqrt(1 - c_rv*c_rv)*randy(2,:)
cofm(3,:) = sigma_v*sqrt(1 - c_rv*c_rv)*randy(3,:)
! partially propagate velocities
s%v(1,1:nf) = s%v(1,1:nf) + c2*s%a(1,1:nf) + cofm(1,:)
s%v(2,1:nf) = s%v(2,1:nf) + c2*s%a(2,1:nf) + cofm(2,:)
s%v(3,1:nf) = s%v(3,1:nf) + c2*s%a(3,1:nf) + cofm(3,:)
end subroutine langevins_2
subroutine newton(s, minv)
!
! Purpose:
! Newton equation
!
type(atoms) :: s
real(8) :: minv
integer :: nf ! skip fixed atoms
nf = s%nofix
s%a(:,1:nf) = s%f(:,1:nf)*minv
end subroutine newton
end module mdalgo