-
Notifications
You must be signed in to change notification settings - Fork 1
/
cell_lists.jl
98 lines (74 loc) · 2.34 KB
/
cell_lists.jl
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
#!/usr/local/bin/julia
include("input.jl")
include("hamiltonian.jl")
include("PBC.jl")
# ==============================================================================
function build_list!(X::particle{Float64}, Z::clist)
for i in 1:nPart
vec_index!(X, Z, i)
c = 1 + Z.mc[1] + Z.mc[2]*M + Z.mc[3]*M^2
@inbounds Z.list[i] = Z.head[c]
@inbounds Z.head[c] = i
end
end
# ==============================================================================
function clear_list!(Z::clist)
fill!(Z.list, 0)
fill!(Z.head, 0)
end
# ==============================================================================
# Compute interactions
# ==============================================================================
function compute_force!(X::particle{Float64}, Z::clist)
fill!(X.f, 0.0)
X.pe = 0.0
if nopot == 1
return X
end
clear_list!(Z)
build_list!(X, Z)
for i in 1:nPart
vec_index!(X, Z, i)
for ci1 in (Z.mc[1]-1):(Z.mc[1]+1),
ci2 in (Z.mc[2]-1):(Z.mc[2]+1),
ci3 in (Z.mc[3]-1):(Z.mc[3]+1)
adjc = 1 + cind(ci1) + cind(ci2)*M + cind(ci3)*M*M
j = Z.head[adjc]
while j != 0
if i<j
update_force!(X, Z, i, j)
end
@inbounds j = Z.list[j]
end
end
end
end
# ==============================================================================
function update_force!(X::particle{Float64},
Z::clist,
i::Int64,
j::Int64)
for l in 1:3
Z.r[l] = X.q[l,i] - X.q[l,j]
end
dist = PBC(Z)
ff = fLJ(dist)
X.pe += peLJ(dist)
for l in 1:3
X.f[l,i] += ff*Z.r[l]
X.f[l,j] -= ff*Z.r[l]
end
end
# ==============================================================================
function vec_index!(X::particle{Float64}, Z::clist, i::Int)
for j in 1:dim
@inbounds Z.dx[j] = remap(X.q[j,i] + L2)
@inbounds Z.mc[j] = floor(Int, Z.dx[j]/L*M)
end
end
# ==============================================================================
function cind(x::Int64)::Int64
while x >= M; x -= M; end
while x < 0; x += M; end
return x
end