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