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.15 2005-09-21 17:20:14 chrisfen Exp $, $Date: 2005-09-21 17:20:14 $, $Name: not supported by cvs2svn $, $Revision: 1.15 $ |
46 |
> |
!! @version $Id: LJ.F90,v 1.27 2007-04-09 18:24:00 gezelter Exp $, $Date: 2007-04-09 18:24:00 $, $Name: not supported by cvs2svn $, $Revision: 1.27 $ |
47 |
|
|
48 |
|
|
49 |
|
module lj |
50 |
+ |
use definitions |
51 |
|
use atype_module |
52 |
|
use vector_class |
53 |
|
use simulation |
54 |
|
use status |
55 |
+ |
use fForceOptions |
56 |
|
#ifdef IS_MPI |
57 |
|
use mpiSimulation |
58 |
|
#endif |
60 |
|
|
61 |
|
implicit none |
62 |
|
PRIVATE |
63 |
+ |
#define __FORTRAN90 |
64 |
+ |
#include "UseTheForce/DarkSide/fInteractionMap.h" |
65 |
|
|
62 |
– |
integer, parameter :: DP = selected_real_kind(15) |
63 |
– |
|
66 |
|
logical, save :: useGeometricDistanceMixing = .false. |
67 |
|
logical, save :: haveMixingMap = .false. |
68 |
|
|
70 |
|
logical, save :: defaultShift = .false. |
71 |
|
logical, save :: haveDefaultCutoff = .false. |
72 |
|
|
71 |
– |
|
73 |
|
type, private :: LJtype |
74 |
|
integer :: atid |
75 |
|
real(kind=dp) :: sigma |
78 |
|
end type LJtype |
79 |
|
|
80 |
|
type, private :: LJList |
81 |
< |
integer :: nLJtypes = 0 |
81 |
> |
integer :: Nljtypes = 0 |
82 |
|
integer :: currentLJtype = 0 |
83 |
|
type(LJtype), pointer :: LJtypes(:) => null() |
84 |
|
integer, pointer :: atidToLJtype(:) => null() |
89 |
|
type :: MixParameters |
90 |
|
real(kind=DP) :: sigma |
91 |
|
real(kind=DP) :: epsilon |
92 |
< |
real(kind=dp) :: sigma6 |
92 |
> |
real(kind=dp) :: sigmai |
93 |
|
real(kind=dp) :: rCut |
93 |
– |
real(kind=dp) :: delta |
94 |
|
logical :: rCutWasSet = .false. |
95 |
|
logical :: shiftedPot |
96 |
|
logical :: isSoftCore = .false. |
100 |
|
|
101 |
|
public :: newLJtype |
102 |
|
public :: setLJDefaultCutoff |
103 |
– |
public :: setLJUniformCutoff |
104 |
– |
public :: setLJCutoffByTypes |
103 |
|
public :: getSigma |
104 |
|
public :: getEpsilon |
107 |
– |
public :: useGeometricMixing |
105 |
|
public :: do_lj_pair |
106 |
|
public :: destroyLJtypes |
107 |
|
|
154 |
|
defaultCutoff = thisRcut |
155 |
|
defaultShift = shiftedPot |
156 |
|
haveDefaultCutoff = .true. |
157 |
< |
call createMixingMap() |
158 |
< |
end subroutine setLJDefaultCutoff |
159 |
< |
|
163 |
< |
subroutine setLJUniformCutoff(thisRcut, shiftedPot) |
164 |
< |
real(kind=dp), intent(in) :: thisRcut |
165 |
< |
logical, intent(in) :: shiftedPot |
166 |
< |
integer :: nLJtypes, i, j |
167 |
< |
|
168 |
< |
if (LJMap%currentLJtype == 0) then |
169 |
< |
call handleError("LJ", "No members in LJMap") |
170 |
< |
return |
157 |
> |
!we only want to build LJ Mixing map if LJ is being used. |
158 |
> |
if(LJMap%nLJTypes /= 0) then |
159 |
> |
call createMixingMap() |
160 |
|
end if |
161 |
|
|
162 |
< |
nLJtypes = LJMap%nLJtypes |
174 |
< |
if (.not. allocated(MixingMap)) then |
175 |
< |
allocate(MixingMap(nLJtypes, nLJtypes)) |
176 |
< |
endif |
177 |
< |
|
178 |
< |
do i = 1, nLJtypes |
179 |
< |
do j = 1, nLJtypes |
180 |
< |
MixingMap(i,j)%rCut = thisRcut |
181 |
< |
MixingMap(i,j)%shiftedPot = shiftedPot |
182 |
< |
MixingMap(i,j)%rCutWasSet = .true. |
183 |
< |
enddo |
184 |
< |
enddo |
185 |
< |
call createMixingMap() |
186 |
< |
end subroutine setLJUniformCutoff |
187 |
< |
|
188 |
< |
subroutine setLJCutoffByTypes(atid1, atid2, thisRcut, shiftedPot) |
189 |
< |
integer, intent(in) :: atid1, atid2 |
190 |
< |
real(kind=dp), intent(in) :: thisRcut |
191 |
< |
logical, intent(in) :: shiftedPot |
192 |
< |
integer :: nLJtypes, ljt1, ljt2 |
193 |
< |
|
194 |
< |
if (LJMap%currentLJtype == 0) then |
195 |
< |
call handleError("LJ", "No members in LJMap") |
196 |
< |
return |
197 |
< |
end if |
198 |
< |
|
199 |
< |
nLJtypes = LJMap%nLJtypes |
200 |
< |
if (.not. allocated(MixingMap)) then |
201 |
< |
allocate(MixingMap(nLJtypes, nLJtypes)) |
202 |
< |
endif |
203 |
< |
|
204 |
< |
ljt1 = LJMap%atidToLJtype(atid1) |
205 |
< |
ljt2 = LJMap%atidToLJtype(atid2) |
162 |
> |
end subroutine setLJDefaultCutoff |
163 |
|
|
207 |
– |
MixingMap(ljt1,ljt2)%rCut = thisRcut |
208 |
– |
MixingMap(ljt1,ljt2)%shiftedPot = shiftedPot |
209 |
– |
MixingMap(ljt1,ljt2)%rCutWasSet = .true. |
210 |
– |
MixingMap(ljt2,ljt1)%rCut = thisRcut |
211 |
– |
MixingMap(ljt2,ljt1)%shiftedPot = shiftedPot |
212 |
– |
MixingMap(ljt2,ljt1)%rCutWasSet = .true. |
213 |
– |
|
214 |
– |
call createMixingMap() |
215 |
– |
end subroutine setLJCutoffByTypes |
216 |
– |
|
164 |
|
function getSigma(atid) result (s) |
165 |
|
integer, intent(in) :: atid |
166 |
|
integer :: ljt1 |
191 |
|
|
192 |
|
end function getEpsilon |
193 |
|
|
247 |
– |
subroutine useGeometricMixing() |
248 |
– |
useGeometricDistanceMixing = .true. |
249 |
– |
haveMixingMap = .false. |
250 |
– |
return |
251 |
– |
end subroutine useGeometricMixing |
252 |
– |
|
194 |
|
subroutine createMixingMap() |
195 |
|
integer :: nLJtypes, i, j |
196 |
|
real ( kind = dp ) :: s1, s2, e1, e2 |
208 |
|
allocate(MixingMap(nLJtypes, nLJtypes)) |
209 |
|
endif |
210 |
|
|
211 |
+ |
useGeometricDistanceMixing = usesGeometricDistanceMixing() |
212 |
|
do i = 1, nLJtypes |
213 |
|
|
214 |
|
s1 = LJMap%LJtypes(i)%sigma |
225 |
|
|
226 |
|
! only the distance parameter uses different mixing policies |
227 |
|
if (useGeometricDistanceMixing) then |
228 |
< |
MixingMap(i,j)%sigma = dsqrt(s1 * s2) |
228 |
> |
MixingMap(i,j)%sigma = sqrt(s1 * s2) |
229 |
|
else |
230 |
|
MixingMap(i,j)%sigma = 0.5_dp * (s1 + s2) |
231 |
|
endif |
232 |
|
|
233 |
< |
MixingMap(i,j)%epsilon = dsqrt(e1 * e2) |
233 |
> |
MixingMap(i,j)%epsilon = sqrt(e1 * e2) |
234 |
|
|
235 |
< |
MixingMap(i,j)%sigma6 = (MixingMap(i,j)%sigma)**6 |
235 |
> |
MixingMap(i,j)%sigmai = 1.0_DP / (MixingMap(i,j)%sigma) |
236 |
|
|
237 |
< |
if (MixingMap(i,j)%rCutWasSet) then |
238 |
< |
rcut6 = (MixingMap(i,j)%rcut)**6 |
237 |
> |
if (haveDefaultCutoff) then |
238 |
> |
MixingMap(i,j)%shiftedPot = defaultShift |
239 |
|
else |
240 |
< |
if (haveDefaultCutoff) then |
241 |
< |
rcut6 = defaultCutoff**6 |
300 |
< |
doShift = defaultShift |
301 |
< |
else |
302 |
< |
call handleError("LJ", "No specified or default cutoff value!") |
303 |
< |
endif |
304 |
< |
endif |
305 |
< |
|
306 |
< |
tp6 = MixingMap(i,j)%sigma6/rcut6 |
307 |
< |
tp12 = tp6**2 |
308 |
< |
MixingMap(i,j)%delta =-4.0_DP*MixingMap(i,j)%epsilon*(tp12 - tp6) |
309 |
< |
MixingMap(i,j)%shiftedPot = doShift |
240 |
> |
MixingMap(i,j)%shiftedPot = defaultShift |
241 |
> |
endif |
242 |
|
|
243 |
|
if (i.ne.j) then |
244 |
|
MixingMap(j,i)%sigma = MixingMap(i,j)%sigma |
245 |
|
MixingMap(j,i)%epsilon = MixingMap(i,j)%epsilon |
246 |
< |
MixingMap(j,i)%sigma6 = MixingMap(i,j)%sigma6 |
246 |
> |
MixingMap(j,i)%sigmai = MixingMap(i,j)%sigmai |
247 |
|
MixingMap(j,i)%rCut = MixingMap(i,j)%rCut |
316 |
– |
MixingMap(j,i)%delta = MixingMap(i,j)%delta |
248 |
|
MixingMap(j,i)%rCutWasSet = MixingMap(i,j)%rCutWasSet |
249 |
|
MixingMap(j,i)%shiftedPot = MixingMap(i,j)%shiftedPot |
250 |
|
MixingMap(j,i)%isSoftCore = MixingMap(i,j)%isSoftCore |
256 |
|
haveMixingMap = .true. |
257 |
|
|
258 |
|
end subroutine createMixingMap |
259 |
< |
|
260 |
< |
subroutine do_lj_pair(atom1, atom2, d, rij, r2, sw, vpair, fpair, & |
259 |
> |
|
260 |
> |
subroutine do_lj_pair(atom1, atom2, d, rij, r2, rcut, sw, vpair, fpair, & |
261 |
|
pot, f, do_pot) |
262 |
< |
|
262 |
> |
|
263 |
|
integer, intent(in) :: atom1, atom2 |
264 |
|
integer :: atid1, atid2, ljt1, ljt2 |
265 |
< |
real( kind = dp ), intent(in) :: rij, r2 |
265 |
> |
real( kind = dp ), intent(in) :: rij, r2, rcut |
266 |
|
real( kind = dp ) :: pot, sw, vpair |
267 |
|
real( kind = dp ), dimension(3,nLocal) :: f |
268 |
|
real( kind = dp ), intent(in), dimension(3) :: d |
272 |
|
! local Variables |
273 |
|
real( kind = dp ) :: drdx, drdy, drdz |
274 |
|
real( kind = dp ) :: fx, fy, fz |
275 |
+ |
real( kind = dp ) :: myPot, myPotC, myDeriv, myDerivC, ros, rcos |
276 |
|
real( kind = dp ) :: pot_temp, dudr |
277 |
< |
real( kind = dp ) :: sigma6 |
277 |
> |
real( kind = dp ) :: sigmai |
278 |
|
real( kind = dp ) :: epsilon |
347 |
– |
real( kind = dp ) :: r6 |
348 |
– |
real( kind = dp ) :: t6 |
349 |
– |
real( kind = dp ) :: t12 |
350 |
– |
real( kind = dp ) :: delta |
279 |
|
logical :: isSoftCore, shiftedPot |
280 |
|
integer :: id1, id2, localError |
281 |
|
|
295 |
|
ljt1 = LJMap%atidToLJtype(atid1) |
296 |
|
ljt2 = LJMap%atidToLJtype(atid2) |
297 |
|
|
298 |
< |
sigma6 = MixingMap(ljt1,ljt2)%sigma6 |
298 |
> |
sigmai = MixingMap(ljt1,ljt2)%sigmai |
299 |
|
epsilon = MixingMap(ljt1,ljt2)%epsilon |
372 |
– |
delta = MixingMap(ljt1,ljt2)%delta |
300 |
|
isSoftCore = MixingMap(ljt1,ljt2)%isSoftCore |
301 |
|
shiftedPot = MixingMap(ljt1,ljt2)%shiftedPot |
302 |
|
|
303 |
< |
r6 = r2 * r2 * r2 |
303 |
> |
ros = rij * sigmai |
304 |
> |
myPotC = 0.0_DP |
305 |
> |
myDerivC = 0.0_DP |
306 |
|
|
378 |
– |
t6 = sigma6/ r6 |
379 |
– |
t12 = t6 * t6 |
380 |
– |
|
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 |
< |
|
388 |
< |
vpair = vpair + pot_temp |
389 |
< |
|
390 |
< |
dudr = -sw * 24.0E0_DP * epsilon * t6 / rij |
391 |
< |
|
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 |
|
|
398 |
– |
vpair = vpair + pot_temp |
399 |
– |
|
400 |
– |
dudr = sw * 24.0E0_DP * epsilon * (t6 - 2.0E0_DP*t12) / rij |
325 |
|
endif |
326 |
|
|
327 |
+ |
!! these are the shifted POTENTIAL variants. |
328 |
+ |
! pot_temp = epsilon * (myPot - myPotC) |
329 |
+ |
! dudr = sw * epsilon * myDeriv * sigmai |
330 |
+ |
|
331 |
+ |
!! these are the shifted FORCE variants. |
332 |
+ |
|
333 |
+ |
pot_temp = epsilon * (myPot - myPotC - myDerivC * (rij - rcut) * sigmai) |
334 |
+ |
dudr = sw * epsilon * (myDeriv - myDerivC) * sigmai |
335 |
+ |
|
336 |
+ |
vpair = vpair + pot_temp |
337 |
+ |
|
338 |
|
drdx = d(1) / rij |
339 |
|
drdy = d(2) / rij |
340 |
|
drdz = d(3) / rij |
345 |
|
|
346 |
|
#ifdef IS_MPI |
347 |
|
if (do_pot) then |
348 |
< |
pot_Row(atom1) = pot_Row(atom1) + sw*pot_temp*0.5 |
349 |
< |
pot_Col(atom2) = pot_Col(atom2) + sw*pot_temp*0.5 |
348 |
> |
pot_Row(VDW_POT,atom1) = pot_Row(VDW_POT,atom1) + sw*pot_temp*0.5 |
349 |
> |
pot_Col(VDW_POT,atom2) = pot_Col(VDW_POT,atom2) + sw*pot_temp*0.5 |
350 |
|
endif |
351 |
|
|
352 |
|
f_Row(1,atom1) = f_Row(1,atom1) + fx |
405 |
|
end if |
406 |
|
|
407 |
|
haveMixingMap = .false. |
408 |
+ |
|
409 |
|
end subroutine destroyLJTypes |
410 |
|
|
411 |
+ |
subroutine getLJfunc(r, myPot, myDeriv) |
412 |
+ |
|
413 |
+ |
real(kind=dp), intent(in) :: r |
414 |
+ |
real(kind=dp), intent(inout) :: myPot, myDeriv |
415 |
+ |
real(kind=dp) :: ri, ri2, ri6, ri7, ri12, ri13 |
416 |
+ |
real(kind=dp) :: a, b, c, d, dx |
417 |
+ |
integer :: j |
418 |
+ |
|
419 |
+ |
ri = 1.0_DP / r |
420 |
+ |
ri2 = ri*ri |
421 |
+ |
ri6 = ri2*ri2*ri2 |
422 |
+ |
ri7 = ri6*ri |
423 |
+ |
ri12 = ri6*ri6 |
424 |
+ |
ri13 = ri12*ri |
425 |
+ |
|
426 |
+ |
myPot = 4.0_DP * (ri12 - ri6) |
427 |
+ |
myDeriv = 24.0_DP * (ri7 - 2.0_DP * ri13) |
428 |
+ |
|
429 |
+ |
return |
430 |
+ |
end subroutine getLJfunc |
431 |
+ |
|
432 |
+ |
subroutine getSoftFunc(r, myPot, myDeriv) |
433 |
+ |
|
434 |
+ |
real(kind=dp), intent(in) :: r |
435 |
+ |
real(kind=dp), intent(inout) :: myPot, myDeriv |
436 |
+ |
real(kind=dp) :: ri, ri2, ri6, ri7 |
437 |
+ |
real(kind=dp) :: a, b, c, d, dx |
438 |
+ |
integer :: j |
439 |
+ |
|
440 |
+ |
ri = 1.0_DP / r |
441 |
+ |
ri2 = ri*ri |
442 |
+ |
ri6 = ri2*ri2*ri2 |
443 |
+ |
ri7 = ri6*ri |
444 |
+ |
myPot = 4.0_DP * (ri6) |
445 |
+ |
myDeriv = - 24.0_DP * ri7 |
446 |
+ |
|
447 |
+ |
return |
448 |
+ |
end subroutine getSoftFunc |
449 |
+ |
|
450 |
|
end module lj |