43 |
|
!! Calculates Long Range forces Lennard-Jones interactions. |
44 |
|
!! @author Charles F. Vardeman II |
45 |
|
!! @author Matthew Meineke |
46 |
< |
!! @version $Id: LJ.F90,v 1.17 2005-10-12 18:59:16 chuckv Exp $, $Date: 2005-10-12 18:59:16 $, $Name: not supported by cvs2svn $, $Revision: 1.17 $ |
46 |
> |
!! @version $Id: LJ.F90,v 1.23 2006-04-21 19:32:07 chrisfen Exp $, $Date: 2006-04-21 19:32:07 $, $Name: not supported by cvs2svn $, $Revision: 1.23 $ |
47 |
|
|
48 |
|
|
49 |
|
module lj |
51 |
|
use vector_class |
52 |
|
use simulation |
53 |
|
use status |
54 |
+ |
use fForceOptions |
55 |
|
#ifdef IS_MPI |
56 |
|
use mpiSimulation |
57 |
|
#endif |
71 |
|
logical, save :: defaultShift = .false. |
72 |
|
logical, save :: haveDefaultCutoff = .false. |
73 |
|
|
73 |
– |
|
74 |
|
type, private :: LJtype |
75 |
|
integer :: atid |
76 |
|
real(kind=dp) :: sigma |
90 |
|
type :: MixParameters |
91 |
|
real(kind=DP) :: sigma |
92 |
|
real(kind=DP) :: epsilon |
93 |
< |
real(kind=dp) :: sigma6 |
93 |
> |
real(kind=dp) :: sigmai |
94 |
|
real(kind=dp) :: rCut |
95 |
– |
real(kind=dp) :: delta |
95 |
|
logical :: rCutWasSet = .false. |
96 |
|
logical :: shiftedPot |
97 |
|
logical :: isSoftCore = .false. |
101 |
|
|
102 |
|
public :: newLJtype |
103 |
|
public :: setLJDefaultCutoff |
105 |
– |
public :: setLJUniformCutoff |
106 |
– |
public :: setLJCutoffByTypes |
104 |
|
public :: getSigma |
105 |
|
public :: getEpsilon |
109 |
– |
public :: useGeometricMixing |
106 |
|
public :: do_lj_pair |
107 |
|
public :: destroyLJtypes |
108 |
|
|
159 |
|
if(LJMap%nLJTypes /= 0) then |
160 |
|
call createMixingMap() |
161 |
|
end if |
166 |
– |
end subroutine setLJDefaultCutoff |
162 |
|
|
163 |
< |
subroutine setLJUniformCutoff(thisRcut, shiftedPot) |
169 |
< |
real(kind=dp), intent(in) :: thisRcut |
170 |
< |
logical, intent(in) :: shiftedPot |
171 |
< |
integer :: nLJtypes, i, j |
172 |
< |
|
173 |
< |
if (LJMap%currentLJtype == 0) then |
174 |
< |
call handleError("LJ", "No members in LJMap") |
175 |
< |
return |
176 |
< |
end if |
177 |
< |
|
178 |
< |
nLJtypes = LJMap%nLJtypes |
179 |
< |
if (.not. allocated(MixingMap)) then |
180 |
< |
allocate(MixingMap(nLJtypes, nLJtypes)) |
181 |
< |
endif |
182 |
< |
|
183 |
< |
do i = 1, nLJtypes |
184 |
< |
do j = 1, nLJtypes |
185 |
< |
MixingMap(i,j)%rCut = thisRcut |
186 |
< |
MixingMap(i,j)%shiftedPot = shiftedPot |
187 |
< |
MixingMap(i,j)%rCutWasSet = .true. |
188 |
< |
enddo |
189 |
< |
enddo |
190 |
< |
call createMixingMap() |
191 |
< |
end subroutine setLJUniformCutoff |
192 |
< |
|
193 |
< |
subroutine setLJCutoffByTypes(atid1, atid2, thisRcut, shiftedPot) |
194 |
< |
integer, intent(in) :: atid1, atid2 |
195 |
< |
real(kind=dp), intent(in) :: thisRcut |
196 |
< |
logical, intent(in) :: shiftedPot |
197 |
< |
integer :: nLJtypes, ljt1, ljt2 |
198 |
< |
|
199 |
< |
if (LJMap%currentLJtype == 0) then |
200 |
< |
call handleError("LJ", "No members in LJMap") |
201 |
< |
return |
202 |
< |
end if |
203 |
< |
|
204 |
< |
nLJtypes = LJMap%nLJtypes |
205 |
< |
if (.not. allocated(MixingMap)) then |
206 |
< |
allocate(MixingMap(nLJtypes, nLJtypes)) |
207 |
< |
endif |
208 |
< |
|
209 |
< |
ljt1 = LJMap%atidToLJtype(atid1) |
210 |
< |
ljt2 = LJMap%atidToLJtype(atid2) |
211 |
< |
|
212 |
< |
MixingMap(ljt1,ljt2)%rCut = thisRcut |
213 |
< |
MixingMap(ljt1,ljt2)%shiftedPot = shiftedPot |
214 |
< |
MixingMap(ljt1,ljt2)%rCutWasSet = .true. |
215 |
< |
MixingMap(ljt2,ljt1)%rCut = thisRcut |
216 |
< |
MixingMap(ljt2,ljt1)%shiftedPot = shiftedPot |
217 |
< |
MixingMap(ljt2,ljt1)%rCutWasSet = .true. |
163 |
> |
end subroutine setLJDefaultCutoff |
164 |
|
|
219 |
– |
call createMixingMap() |
220 |
– |
end subroutine setLJCutoffByTypes |
221 |
– |
|
165 |
|
function getSigma(atid) result (s) |
166 |
|
integer, intent(in) :: atid |
167 |
|
integer :: ljt1 |
192 |
|
|
193 |
|
end function getEpsilon |
194 |
|
|
252 |
– |
subroutine useGeometricMixing() |
253 |
– |
useGeometricDistanceMixing = .true. |
254 |
– |
haveMixingMap = .false. |
255 |
– |
return |
256 |
– |
end subroutine useGeometricMixing |
257 |
– |
|
195 |
|
subroutine createMixingMap() |
196 |
|
integer :: nLJtypes, i, j |
197 |
|
real ( kind = dp ) :: s1, s2, e1, e2 |
209 |
|
allocate(MixingMap(nLJtypes, nLJtypes)) |
210 |
|
endif |
211 |
|
|
212 |
+ |
useGeometricDistanceMixing = usesGeometricDistanceMixing() |
213 |
|
do i = 1, nLJtypes |
214 |
|
|
215 |
|
s1 = LJMap%LJtypes(i)%sigma |
233 |
|
|
234 |
|
MixingMap(i,j)%epsilon = dsqrt(e1 * e2) |
235 |
|
|
236 |
< |
MixingMap(i,j)%sigma6 = (MixingMap(i,j)%sigma)**6 |
236 |
> |
MixingMap(i,j)%sigmai = 1.0_DP / (MixingMap(i,j)%sigma) |
237 |
|
|
238 |
< |
if (MixingMap(i,j)%rCutWasSet) then |
239 |
< |
rcut6 = (MixingMap(i,j)%rcut)**6 |
238 |
> |
if (haveDefaultCutoff) then |
239 |
> |
MixingMap(i,j)%shiftedPot = defaultShift |
240 |
|
else |
241 |
< |
if (haveDefaultCutoff) then |
242 |
< |
rcut6 = defaultCutoff**6 |
305 |
< |
doShift = defaultShift |
306 |
< |
else |
307 |
< |
call handleError("LJ", "No specified or default cutoff value!") |
308 |
< |
endif |
309 |
< |
endif |
310 |
< |
|
311 |
< |
tp6 = MixingMap(i,j)%sigma6/rcut6 |
312 |
< |
tp12 = tp6**2 |
313 |
< |
MixingMap(i,j)%delta =-4.0_DP*MixingMap(i,j)%epsilon*(tp12 - tp6) |
314 |
< |
MixingMap(i,j)%shiftedPot = doShift |
241 |
> |
MixingMap(i,j)%shiftedPot = defaultShift |
242 |
> |
endif |
243 |
|
|
244 |
|
if (i.ne.j) then |
245 |
|
MixingMap(j,i)%sigma = MixingMap(i,j)%sigma |
246 |
|
MixingMap(j,i)%epsilon = MixingMap(i,j)%epsilon |
247 |
< |
MixingMap(j,i)%sigma6 = MixingMap(i,j)%sigma6 |
247 |
> |
MixingMap(j,i)%sigmai = MixingMap(i,j)%sigmai |
248 |
|
MixingMap(j,i)%rCut = MixingMap(i,j)%rCut |
321 |
– |
MixingMap(j,i)%delta = MixingMap(i,j)%delta |
249 |
|
MixingMap(j,i)%rCutWasSet = MixingMap(i,j)%rCutWasSet |
250 |
|
MixingMap(j,i)%shiftedPot = MixingMap(i,j)%shiftedPot |
251 |
|
MixingMap(j,i)%isSoftCore = MixingMap(i,j)%isSoftCore |
257 |
|
haveMixingMap = .true. |
258 |
|
|
259 |
|
end subroutine createMixingMap |
260 |
< |
|
261 |
< |
subroutine do_lj_pair(atom1, atom2, d, rij, r2, sw, vpair, fpair, & |
260 |
> |
|
261 |
> |
subroutine do_lj_pair(atom1, atom2, d, rij, r2, rcut, sw, vpair, fpair, & |
262 |
|
pot, f, do_pot) |
263 |
< |
|
263 |
> |
|
264 |
|
integer, intent(in) :: atom1, atom2 |
265 |
|
integer :: atid1, atid2, ljt1, ljt2 |
266 |
< |
real( kind = dp ), intent(in) :: rij, r2 |
266 |
> |
real( kind = dp ), intent(in) :: rij, r2, rcut |
267 |
|
real( kind = dp ) :: pot, sw, vpair |
268 |
|
real( kind = dp ), dimension(3,nLocal) :: f |
269 |
|
real( kind = dp ), intent(in), dimension(3) :: d |
273 |
|
! local Variables |
274 |
|
real( kind = dp ) :: drdx, drdy, drdz |
275 |
|
real( kind = dp ) :: fx, fy, fz |
276 |
+ |
real( kind = dp ) :: myPot, myPotC, myDeriv, myDerivC, ros, rcos |
277 |
|
real( kind = dp ) :: pot_temp, dudr |
278 |
< |
real( kind = dp ) :: sigma6 |
278 |
> |
real( kind = dp ) :: sigmai |
279 |
|
real( kind = dp ) :: epsilon |
352 |
– |
real( kind = dp ) :: r6 |
353 |
– |
real( kind = dp ) :: t6 |
354 |
– |
real( kind = dp ) :: t12 |
355 |
– |
real( kind = dp ) :: delta |
280 |
|
logical :: isSoftCore, shiftedPot |
281 |
|
integer :: id1, id2, localError |
282 |
|
|
296 |
|
ljt1 = LJMap%atidToLJtype(atid1) |
297 |
|
ljt2 = LJMap%atidToLJtype(atid2) |
298 |
|
|
299 |
< |
sigma6 = MixingMap(ljt1,ljt2)%sigma6 |
299 |
> |
sigmai = MixingMap(ljt1,ljt2)%sigmai |
300 |
|
epsilon = MixingMap(ljt1,ljt2)%epsilon |
377 |
– |
delta = MixingMap(ljt1,ljt2)%delta |
301 |
|
isSoftCore = MixingMap(ljt1,ljt2)%isSoftCore |
302 |
|
shiftedPot = MixingMap(ljt1,ljt2)%shiftedPot |
303 |
|
|
304 |
< |
r6 = r2 * r2 * r2 |
304 |
> |
ros = rij * sigmai |
305 |
> |
myPotC = 0.0_DP |
306 |
|
|
383 |
– |
t6 = sigma6/ r6 |
384 |
– |
t12 = t6 * t6 |
385 |
– |
|
307 |
|
if (isSoftCore) then |
308 |
< |
|
309 |
< |
pot_temp = 4.0E0_DP * epsilon * t6 |
308 |
> |
|
309 |
> |
call getSoftFunc(ros, myPot, myDeriv) |
310 |
> |
|
311 |
|
if (shiftedPot) then |
312 |
< |
pot_temp = pot_temp + delta |
312 |
> |
rcos = rcut * sigmai |
313 |
> |
call getSoftFunc(rcos, myPotC, myDerivC) |
314 |
|
endif |
315 |
< |
|
393 |
< |
vpair = vpair + pot_temp |
394 |
< |
|
395 |
< |
dudr = -sw * 24.0E0_DP * epsilon * t6 / rij |
396 |
< |
|
315 |
> |
|
316 |
|
else |
317 |
< |
pot_temp = 4.0E0_DP * epsilon * (t12 - t6) |
317 |
> |
|
318 |
> |
call getLJfunc(ros, myPot, myDeriv) |
319 |
> |
|
320 |
|
if (shiftedPot) then |
321 |
< |
pot_temp = pot_temp + delta |
321 |
> |
rcos = rcut * sigmai |
322 |
> |
call getLJfunc(rcos, myPotC, myDerivC) |
323 |
|
endif |
324 |
|
|
403 |
– |
vpair = vpair + pot_temp |
404 |
– |
|
405 |
– |
dudr = sw * 24.0E0_DP * epsilon * (t6 - 2.0E0_DP*t12) / rij |
325 |
|
endif |
326 |
|
|
327 |
+ |
!write(*,*) rij, ros, rcos, myPot, myDeriv, myPotC |
328 |
+ |
|
329 |
+ |
pot_temp = epsilon * (myPot - myPotC) |
330 |
+ |
vpair = vpair + pot_temp |
331 |
+ |
dudr = sw * epsilon * myDeriv * sigmai |
332 |
+ |
|
333 |
|
drdx = d(1) / rij |
334 |
|
drdy = d(2) / rij |
335 |
|
drdz = d(3) / rij |
340 |
|
|
341 |
|
#ifdef IS_MPI |
342 |
|
if (do_pot) then |
343 |
< |
pot_Row(LJ_POT,atom1) = pot_Row(LJ_POT,atom1) + sw*pot_temp*0.5 |
344 |
< |
pot_Col(LJ_POT,atom2) = pot_Col(LJ_POT,atom2) + sw*pot_temp*0.5 |
343 |
> |
pot_Row(VDW_POT,atom1) = pot_Row(VDW_POT,atom1) + sw*pot_temp*0.5 |
344 |
> |
pot_Col(VDW_POT,atom2) = pot_Col(VDW_POT,atom2) + sw*pot_temp*0.5 |
345 |
|
endif |
346 |
|
|
347 |
|
f_Row(1,atom1) = f_Row(1,atom1) + fx |
400 |
|
end if |
401 |
|
|
402 |
|
haveMixingMap = .false. |
403 |
+ |
|
404 |
|
end subroutine destroyLJTypes |
405 |
|
|
406 |
+ |
subroutine getLJfunc(r, myPot, myDeriv) |
407 |
+ |
|
408 |
+ |
real(kind=dp), intent(in) :: r |
409 |
+ |
real(kind=dp), intent(inout) :: myPot, myDeriv |
410 |
+ |
real(kind=dp) :: ri, ri2, ri6, ri7, ri12, ri13 |
411 |
+ |
real(kind=dp) :: a, b, c, d, dx |
412 |
+ |
integer :: j |
413 |
+ |
|
414 |
+ |
ri = 1.0_DP / r |
415 |
+ |
ri2 = ri*ri |
416 |
+ |
ri6 = ri2*ri2*ri2 |
417 |
+ |
ri7 = ri6*ri |
418 |
+ |
ri12 = ri6*ri6 |
419 |
+ |
ri13 = ri12*ri |
420 |
+ |
|
421 |
+ |
myPot = 4.0_DP * (ri12 - ri6) |
422 |
+ |
myDeriv = 24.0_DP * (ri7 - 2.0_DP * ri13) |
423 |
+ |
|
424 |
+ |
return |
425 |
+ |
end subroutine getLJfunc |
426 |
+ |
|
427 |
+ |
subroutine getSoftFunc(r, myPot, myDeriv) |
428 |
+ |
|
429 |
+ |
real(kind=dp), intent(in) :: r |
430 |
+ |
real(kind=dp), intent(inout) :: myPot, myDeriv |
431 |
+ |
real(kind=dp) :: ri, ri2, ri6, ri7 |
432 |
+ |
real(kind=dp) :: a, b, c, d, dx |
433 |
+ |
integer :: j |
434 |
+ |
|
435 |
+ |
ri = 1.0_DP / r |
436 |
+ |
ri2 = ri*ri |
437 |
+ |
ri6 = ri2*ri2*ri2 |
438 |
+ |
ri7 = ri6*ri |
439 |
+ |
myPot = 4.0_DP * (ri6) |
440 |
+ |
myDeriv = - 24.0_DP * ri7 |
441 |
+ |
|
442 |
+ |
return |
443 |
+ |
end subroutine getSoftFunc |
444 |
+ |
|
445 |
|
end module lj |