-
Notifications
You must be signed in to change notification settings - Fork 0
/
08-dynamic.f90
341 lines (271 loc) · 10.1 KB
/
08-dynamic.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
module mo_dynamic
use mo_syst
use mo_config
implicit none
type msd_t
integer :: natom ! Number of particles
integer :: ndt ! sample frequency
integer :: nhist ! length of histdata
logical :: calc_flag = .false., msd_flag, fkt_flag
real(8) :: dt, kx
integer :: cumstep = -1
integer :: histidx = 0
integer :: cumcount
real(8), allocatable, dimension(:) :: msd ! msd
real(8), allocatable, dimension(:) :: alpha2 ! non-gaussian parameter
real(8), allocatable, dimension(:) :: fkt ! intemediate scatter function
real(8), allocatable, dimension(:,:) :: histdata ! array used to stor history config
contains
procedure :: pmsd => print_msd
procedure :: pfkt => print_fkt
end type
type vcorr_t
integer :: natom
integer :: ndt
integer :: nhist
integer :: cumstep = -1
integer :: histidx = 0
logical :: calc_flag = .false.
integer :: cumcount
real(8), allocatable, dimension(:) :: vcorr
real(8), allocatable, dimension(:,:) :: histdata
end type
type(msd_t) :: msd1, msd2, msd3
type(vcorr_t) :: vcorr1
contains
subroutine init_msd( con, msd, ndt, nhist, dt, kx )
implicit none
! para list
type(con_t), intent(in) :: con
type(msd_t), intent(inout) :: msd
integer, intent(in) :: ndt, nhist
real(8), intent(in) :: dt, kx
! readin variables
msd%natom = con%natom
msd%ndt = ndt
msd%nhist = nhist
! allocate memory
if ( dt > 0.d0 ) then
allocate( msd%msd(nhist) )
allocate( msd%alpha2(nhist) )
msd%msd_flag = .true.
msd%dt = dt
msd%msd = 0.d0
msd%alpha2 = 0.d0
else
msd%msd_flag = .false.
end if
if ( kx > 0.d0 ) then
allocate( msd%fkt(nhist) )
msd%fkt_flag = .true.
msd%kx = kx
msd%fkt = 0.d0
else
msd%fkt_flag = .false.
end if
if ( msd%msd_flag .or. msd%fkt_flag ) then
allocate( msd%histdata(msd%natom,nhist) )
msd%histdata = 0.d0
end if
! initiate variables
msd%cumstep = -1
msd%cumcount = 0
msd%calc_flag = .false.
end subroutine
subroutine calc_msd( con, tmsd )
implicit none
! para list
type(con_t), intent(in) :: con
type(msd_t), intent(inout) :: tmsd
! local
integer :: t0, idx
integer :: i
real(8), dimension(con%natom) :: rt0, td
associate( &
ra => con%ra, &
msd => tmsd%msd, &
alpha2 => tmsd%alpha2, &
fkt => tmsd%fkt, &
calc_flag => tmsd%calc_flag, &
msd_flag => tmsd%msd_flag, &
fkt_flag => tmsd%fkt_flag, &
histidx => tmsd%histidx, &
cumstep => tmsd%cumstep, &
ndt => tmsd%ndt, &
nhist => tmsd%nhist, &
kx => tmsd%kx, &
cumcount => tmsd%cumcount, &
histdata => tmsd%histdata &
)
! take one snapshot every ndt step
cumstep = cumstep + 1
if ( cumstep == ndt+1 ) cumstep = 0
if ( cumstep /= 0 ) return
! main v
histidx = histidx + 1
! if histidx less then nhist, then just store configure, not calc msd
if ( .not. calc_flag .and. histidx == nhist ) calc_flag = .true.
! if histidx largeer than dimension of histdata, then reset it to one
if ( histidx == nhist + 1 ) histidx = 1
! store config in "history data"
histdata(:, histidx) = ra(1, :)
if ( calc_flag ) then
cumcount = cumcount + 1
t0 = mod(histidx, nhist) + 1
rt0 = histdata(:,t0)
do i=1, nhist
! deprecated
! ! Index
! ! if histidx >= i; idx = histidx - i + 1
! ! if histidx < i; idx = histidx - i + 1 + nhist
! ! 1 2 3 4 5 ! histdata
! ! hi ! histidx
! ! i ! idx = 1
! ! i ! idx = 4
! ! i ! idx = 5
! ! idx = histidx-i+1
! ! if ( idx <= 0 ) idx = idx + nhist
! Index
! t0 is the next number of histidx, and it is the oldest data in histdata
! 1 2 3 4 5 ! histdata
! hi ! histidx
! t0 ! t0
! i ! idx = 5
! i ! idx = 1
! i ! idx = 2
idx = i - t0 + 1
if ( idx <= 0 ) idx = idx + nhist
td = histdata(:, i) - rt0
if ( msd_flag ) then
msd(idx) = msd(idx) + sum( td**2 )
alpha2(idx) = alpha2(idx) + sum( td**4 )
end if
if ( fkt_flag ) then
fkt(idx) = fkt(idx) + sum( cos(td*kx) )
end if
end do
end if
end associate
end subroutine
pure function print_msd( this, i ) result( re )
implicit none
! para list
class(msd_t), intent(in) :: this
integer, intent(in) :: i
! result
real(8) :: re
if ( this%msd_flag .and. this%calc_flag ) then
re = this%msd(i) / this%cumcount / this%natom
else
re = - 1.d0
end if
end function
pure function print_fkt( this, i ) result( re )
implicit none
! para list
class(msd_t), intent(in) :: this
integer, intent(in) :: i
! result
real(8) :: re
if ( this%fkt_flag .and. this%calc_flag ) then
re = this%fkt(i) / this%cumcount / this%natom
else
re = - 1.d0
end if
end function
subroutine endof_msd( tmsd )
implicit none
! para list
type(msd_t), intent(inout) :: tmsd
associate( &
natom => tmsd%natom, &
cumcount => tmsd%cumcount &
)
if ( tmsd%msd_flag .and. tmsd%calc_flag ) then
tmsd%msd = tmsd%msd / ( cumcount * natom )
tmsd%alpha2 = tmsd%alpha2 / ( cumcount * natom )
tmsd%alpha2 = tmsd%alpha2 / tmsd%msd**2 / 3.d0 - 1.d0
end if
if ( tmsd%msd_flag .and. tmsd%calc_flag ) then
tmsd%fkt = tmsd%fkt / ( cumcount * natom )
end if
end associate
end subroutine
subroutine init_vcorr( con, vcorr, ndt, nhist )
implicit none
! para list
type(con_t), intent(in) :: con
type(vcorr_t), intent(inout) :: vcorr
integer, intent(in) :: ndt
integer, intent(in) :: nhist
! readin variables
vcorr%natom = con%natom
vcorr%ndt = ndt
vcorr%nhist = nhist
! allocate memory
allocate( vcorr%vcorr(nhist) )
allocate( vcorr%histdata(con%natom, nhist) )
vcorr%vcorr = 0.d0
vcorr%histdata = 0.d0
! initiate variables
vcorr%cumcount = 0
vcorr%cumstep = -1
vcorr%calc_flag = .false.
end subroutine
subroutine calc_vcorr( con, tvcorr )
implicit none
! para list
type(con_t), intent(in) :: con
type(vcorr_t), intent(inout) :: tvcorr
! local
integer :: idx
integer :: i
real(8), dimension(con%natom) :: thi
associate( &
va => con%va, &
vcorr => tvcorr%vcorr, &
calc_flag => tvcorr%calc_flag, &
histidx => tvcorr%histidx, &
cumstep => tvcorr%cumstep, &
ndt => tvcorr%ndt, &
nhist => tvcorr%nhist, &
cumcount => tvcorr%cumcount, &
histdata => tvcorr%histdata &
)
cumstep = cumstep + 1
if ( cumstep >= ndt ) cumstep = 0
if ( cumstep /= 0 ) return
! main v
histidx = histidx + 1
! if histidx less then nhist, then just store configure, not calc vcorr
if ( .not. calc_flag .and. histidx == nhist ) calc_flag = .true.
! if histidx greater then max dim of histdata, reset to one
if ( histidx == nhist + 1 ) histidx = 1
! store config to "history data"
histdata(:, histidx) = va(1, :)
thi = va(1, :)
if ( calc_flag ) then
cumcount = cumcount + 1
do i=1, nhist
! if histidx >= i; idx = histidx - i + 1
! if histidx < i; idx = histidx - i + 1 + nhist
! 1 2 3 4 5 !
! hi !
! i ! idx = 1
! i ! idx = 4
! i ! idx = 5
idx = histidx-i+1
if ( idx <= 0 ) idx = idx + nhist
vcorr(idx) = vcorr(idx) + dot_product( histdata(:, i), thi )
end do
end if
end associate
end subroutine
subroutine endof_vcorr( tvcorr )
implicit none
! para list
type(vcorr_t), intent(inout) :: tvcorr
tvcorr%vcorr = tvcorr%vcorr / tvcorr%cumcount
tvcorr%vcorr = tvcorr%vcorr / tvcorr%vcorr(1)
end subroutine
end module