1 |
!! Calculates Long Range forces Lennard-Jones interactions. |
2 |
!! Corresponds to the force field defined in lj_FF.cpp |
3 |
!! @author Charles F. Vardeman II |
4 |
!! @author Matthew Meineke |
5 |
!! @version $Id: calc_LJ_FF.F90,v 1.13 2003-03-18 19:09:12 gezelter Exp $, $Date: 2003-03-18 19:09:12 $, $Name: not supported by cvs2svn $, $Revision: 1.13 $ |
6 |
|
7 |
module lj |
8 |
use definitions |
9 |
use atype_module |
10 |
use vector_class |
11 |
#ifdef IS_MPI |
12 |
use mpiSimulation |
13 |
#endif |
14 |
use force_globals |
15 |
|
16 |
implicit none |
17 |
PRIVATE |
18 |
|
19 |
#define __FORTRAN90 |
20 |
#include "fForceField.h" |
21 |
|
22 |
integer, save :: LJ_Mixing_Policy |
23 |
integer, save :: LJ_rcut |
24 |
|
25 |
!! Logical has lj force field module been initialized? |
26 |
|
27 |
logical, save :: LJ_FF_initialized = .false. |
28 |
|
29 |
!! Public methods and data |
30 |
public :: init_LJ_FF |
31 |
public :: LJ_new_rcut |
32 |
public :: do_lj_pair |
33 |
|
34 |
type :: lj_mixed_params |
35 |
!! Lennard-Jones epsilon |
36 |
real ( kind = dp ) :: epsilon = 0.0_dp |
37 |
!! Lennard-Jones Sigma |
38 |
real ( kind = dp ) :: sigma = 0.0_dp |
39 |
!! Lennard-Jones Sigma to sixth |
40 |
real ( kind = dp ) :: sigma6 = 0.0_dp |
41 |
!! |
42 |
real ( kind = dp ) :: tp6 |
43 |
real ( kind = dp ) :: tp12 |
44 |
|
45 |
real ( kind = dp ) :: delta = 0.0_dp |
46 |
|
47 |
end type lj_mixed_params |
48 |
|
49 |
type (lj_mixed_params), dimension(:,:), pointer :: ljMixed |
50 |
|
51 |
contains |
52 |
|
53 |
subroutine init_LJ_FF(mix_Policy, rcut, status) |
54 |
integer, intent(in) :: mix_Policy |
55 |
integer, intent(out) :: status |
56 |
integer :: myStatus |
57 |
real(kind=dp) :: rcut |
58 |
|
59 |
if (mix_Policy == LB_MIXING_RULE) then |
60 |
LJ_Mixing_Policy = LB_MIXING_RULE |
61 |
else |
62 |
if (mix_Policy == EXPLICIT_MIXING_RULE) then |
63 |
LJ_Mixing_Policy = EXPLICIT_MIXING_RULE |
64 |
else |
65 |
write(*,*) 'Unknown Mixing Policy!' |
66 |
status = -1 |
67 |
return |
68 |
endif |
69 |
endif |
70 |
|
71 |
LJ_rcut = rcut |
72 |
|
73 |
status = 0 |
74 |
call createMixingList(myStatus) |
75 |
if (myStatus /= 0) then |
76 |
status = -1 |
77 |
return |
78 |
end if |
79 |
|
80 |
LJ_FF_initialized = .true. |
81 |
|
82 |
end subroutine init_LJ_FF |
83 |
|
84 |
subroutine LJ_new_rcut(rcut, status) |
85 |
integer :: status, myStatus |
86 |
real(kind=dp) :: rcut |
87 |
|
88 |
LJ_rcut = rcut |
89 |
status = 0 |
90 |
call createMixingList(myStatus) |
91 |
if (myStatus /= 0) then |
92 |
status = -1 |
93 |
return |
94 |
end if |
95 |
|
96 |
return |
97 |
end subroutine LJ_new_rcut |
98 |
|
99 |
subroutine createMixingList(status) |
100 |
integer :: nAtypes |
101 |
integer :: status |
102 |
integer :: i |
103 |
integer :: j |
104 |
real ( kind = dp ) :: mySigma_i,mySigma_j |
105 |
real ( kind = dp ) :: myEpsilon_i,myEpsilon_j |
106 |
real ( kind = dp ) :: rcut6 |
107 |
status = 0 |
108 |
|
109 |
nAtypes = getSize(atypes) |
110 |
if (nAtypes == 0) then |
111 |
status = -1 |
112 |
return |
113 |
end if |
114 |
|
115 |
if (.not. associated(ljMixed)) then |
116 |
allocate(ljMixed(nAtypes, nAtypes)) |
117 |
else |
118 |
status = -1 |
119 |
return |
120 |
end if |
121 |
|
122 |
rcut6 = LJ_rcut**6 |
123 |
|
124 |
do i = 1, nAtypes |
125 |
|
126 |
call getElementProperty(atypes, i, "lj_epsilon", myEpsilon_i) |
127 |
call getElementProperty(atypes, i, "lj_sigma", mySigma_i) |
128 |
! do self mixing rule |
129 |
ljMixed(i,i)%sigma = mySigma_i |
130 |
|
131 |
ljMixed(i,i)%sigma6 = (ljMixed(i,i)%sigma) ** 6 |
132 |
ljMixed(i,i)%tp6 = ljMixed(i,i)%sigma6/rcut6 |
133 |
|
134 |
ljMixed(i,i)%tp12 = (ljMixed(i,i)%tp6) ** 2 |
135 |
|
136 |
ljMixed(i,i)%epsilon = myEpsilon_i |
137 |
|
138 |
ljMixed(i,i)%delta = -4.0_DP * ljMixed(i,i)%epsilon * & |
139 |
(ljMixed(i,i)%tp12 - ljMixed(i,i)%tp6) |
140 |
|
141 |
do j = i + 1, nAtypes |
142 |
call getElementProperty(atypes,j,"lj_epsilon",myEpsilon_j) |
143 |
call getElementProperty(atypes,j,"lj_sigma", mySigma_j) |
144 |
|
145 |
ljMixed(i,j)%sigma = & |
146 |
calcLJMix("sigma",mySigma_i, & |
147 |
mySigma_j) |
148 |
|
149 |
ljMixed(i,j)%sigma6 = & |
150 |
(ljMixed(i,j)%sigma)**6 |
151 |
|
152 |
|
153 |
ljMixed(i,j)%tp6 = ljMixed(i,j)%sigma6/rcut6 |
154 |
|
155 |
ljMixed(i,j)%tp12 = (ljMixed(i,j)%tp6) ** 2 |
156 |
|
157 |
|
158 |
ljMixed(i,j)%epsilon = & |
159 |
calcLJMix("epsilon",myEpsilon_i, & |
160 |
myEpsilon_j) |
161 |
|
162 |
ljMixed(i,j)%delta = -4.0_DP * ljMixed(i,j)%epsilon * & |
163 |
(ljMixed(i,j)%tp12 - ljMixed(i,j)%tp6) |
164 |
|
165 |
|
166 |
ljMixed(j,i)%sigma = ljMixed(i,j)%sigma |
167 |
ljMixed(j,i)%sigma6 = ljMixed(i,j)%sigma6 |
168 |
ljMixed(j,i)%tp6 = ljMixed(i,j)%tp6 |
169 |
ljMixed(j,i)%tp12 = ljMixed(i,j)%tp12 |
170 |
ljMixed(j,i)%epsilon = ljMixed(i,j)%epsilon |
171 |
ljMixed(j,i)%delta = ljMixed(i,j)%delta |
172 |
|
173 |
end do |
174 |
end do |
175 |
|
176 |
end subroutine createMixingList |
177 |
|
178 |
subroutine do_lj_pair(atom1, atom2, d, rij, r2, pot, f, do_pot, do_stress) |
179 |
|
180 |
integer, intent(in) :: atom1, atom2 |
181 |
real( kind = dp ), intent(in) :: rij, r2 |
182 |
real( kind = dp ) :: pot |
183 |
real( kind = dp ), dimension(:,:) :: f |
184 |
real( kind = dp ), intent(in), dimension(3) :: d |
185 |
logical, intent(in) :: do_pot, do_stress |
186 |
|
187 |
! local Variables |
188 |
real( kind = dp ) :: drdx, drdy, drdz |
189 |
real( kind = dp ) :: fx, fy, fz |
190 |
real( kind = dp ) :: pot_temp, dudr |
191 |
real( kind = dp ) :: sigma6 |
192 |
real( kind = dp ) :: epsilon |
193 |
real( kind = dp ) :: r6 |
194 |
real( kind = dp ) :: t6 |
195 |
real( kind = dp ) :: t12 |
196 |
real( kind = dp ) :: delta |
197 |
|
198 |
|
199 |
if (rij.lt.LJ_rcut) then |
200 |
|
201 |
! Look up the correct parameters in the mixing matrix |
202 |
#ifdef IS_MPI |
203 |
sigma6 = ljMixed(atid_Row(atom1),atid_Col(atom2))%sigma6 |
204 |
epsilon = ljMixed(atid_Row(atom1),atid_Col(atom2))%epsilon |
205 |
delta = ljMixed(atid_Row(atom1),atid_Col(atom2))%delta |
206 |
#else |
207 |
sigma6 = ljMixed(atid(atom1),atid(atom2))%sigma6 |
208 |
epsilon = ljMixed(atid(atom1),atid(atom2))%epsilon |
209 |
delta = ljMixed(atid(atom1),atid(atom2))%delta |
210 |
#endif |
211 |
|
212 |
r6 = r2 * r2 * r2 |
213 |
|
214 |
t6 = sigma6/ r6 |
215 |
t12 = t6 * t6 |
216 |
|
217 |
pot_temp = 4.0E0_DP * epsilon * (t12 - t6) + delta |
218 |
|
219 |
dudr = 24.0E0_DP * epsilon * (t6 - 2.0E0_DP*t12) / rij |
220 |
|
221 |
drdx = -d(1) / rij |
222 |
drdy = -d(2) / rij |
223 |
drdz = -d(3) / rij |
224 |
|
225 |
fx = dudr * drdx |
226 |
fy = dudr * drdy |
227 |
fz = dudr * drdz |
228 |
|
229 |
#ifdef IS_MPI |
230 |
if (do_pot) then |
231 |
pot_Row(atom1) = pot_Row(atom1) + pot_temp*0.5 |
232 |
pot_Col(atom2) = pot_Col(atom2) + pot_temp*0.5 |
233 |
endif |
234 |
|
235 |
f_Row(1,atom1) = f_Row(1,atom1) + fx |
236 |
f_Row(2,atom1) = f_Row(2,atom1) + fy |
237 |
f_Row(3,atom1) = f_Row(3,atom1) + fz |
238 |
|
239 |
f_Col(1,atom2) = f_Col(1,atom2) - fx |
240 |
f_Col(2,atom2) = f_Col(2,atom2) - fy |
241 |
f_Col(3,atom2) = f_Col(3,atom2) - fz |
242 |
|
243 |
#else |
244 |
if (do_pot) pot = pot + pot_temp |
245 |
|
246 |
f(1,atom1) = f(1,atom1) + fx |
247 |
f(2,atom1) = f(2,atom1) + fy |
248 |
f(3,atom1) = f(3,atom1) + fz |
249 |
|
250 |
f(1,atom2) = f(1,atom2) - fx |
251 |
f(2,atom2) = f(2,atom2) - fy |
252 |
f(3,atom2) = f(3,atom2) - fz |
253 |
#endif |
254 |
|
255 |
if (do_stress) then |
256 |
tau_Temp(1) = tau_Temp(1) + fx * d(1) |
257 |
tau_Temp(2) = tau_Temp(2) + fx * d(2) |
258 |
tau_Temp(3) = tau_Temp(3) + fx * d(3) |
259 |
tau_Temp(4) = tau_Temp(4) + fy * d(1) |
260 |
tau_Temp(5) = tau_Temp(5) + fy * d(2) |
261 |
tau_Temp(6) = tau_Temp(6) + fy * d(3) |
262 |
tau_Temp(7) = tau_Temp(7) + fz * d(1) |
263 |
tau_Temp(8) = tau_Temp(8) + fz * d(2) |
264 |
tau_Temp(9) = tau_Temp(9) + fz * d(3) |
265 |
virial_Temp = virial_Temp + (tau_Temp(1) + tau_Temp(5) + tau_Temp(9)) |
266 |
endif |
267 |
|
268 |
endif |
269 |
return |
270 |
end subroutine do_lj_pair |
271 |
|
272 |
|
273 |
!! Calculates the mixing for sigma or epslon |
274 |
|
275 |
function calcLJMix(thisParam,param1,param2,status) result(myMixParam) |
276 |
character(len=*) :: thisParam |
277 |
real(kind = dp) :: param1 |
278 |
real(kind = dp) :: param2 |
279 |
real(kind = dp ) :: myMixParam |
280 |
|
281 |
integer, optional :: status |
282 |
|
283 |
myMixParam = 0.0_dp |
284 |
|
285 |
if (present(status)) status = 0 |
286 |
select case (LJ_Mixing_Policy) |
287 |
case (LB_MIXING_RULE) |
288 |
select case (thisParam) |
289 |
case ("sigma") |
290 |
myMixParam = 0.5_dp * (param1 + param2) |
291 |
case ("epsilon") |
292 |
myMixParam = sqrt(param1 * param2) |
293 |
case default |
294 |
status = -1 |
295 |
end select |
296 |
case default |
297 |
status = -1 |
298 |
end select |
299 |
end function calcLJMix |
300 |
|
301 |
end module lj |