ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/UseTheForce/DarkSide/LJ.F90
(Generate patch)

Comparing trunk/OOPSE-4/src/UseTheForce/DarkSide/LJ.F90 (file contents):
Revision 2319 by chuckv, Wed Sep 21 23:45:48 2005 UTC vs.
Revision 2727 by chrisfen, Fri Apr 21 19:32:07 2006 UTC

# Line 43 | Line 43
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.16 2005-09-21 23:45:48 chuckv Exp $, $Date: 2005-09-21 23:45:48 $, $Name: not supported by cvs2svn $, $Revision: 1.16 $
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
# Line 51 | Line 51 | module lj
51    use vector_class
52    use simulation
53    use status
54 +  use fForceOptions
55   #ifdef IS_MPI
56    use mpiSimulation
57   #endif
# Line 58 | Line 59 | module lj
59  
60    implicit none
61    PRIVATE
62 + #define __FORTRAN90
63 + #include "UseTheForce/DarkSide/fInteractionMap.h"
64  
65    integer, parameter :: DP = selected_real_kind(15)
66  
# Line 68 | Line 71 | module lj
71    logical, save :: defaultShift = .false.
72    logical, save :: haveDefaultCutoff = .false.
73  
71
74    type, private :: LJtype
75       integer       :: atid
76       real(kind=dp) :: sigma
# Line 88 | Line 90 | module lj
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
93     real(kind=dp) :: delta
95       logical       :: rCutWasSet = .false.
96       logical       :: shiftedPot
97       logical       :: isSoftCore = .false.
# Line 100 | Line 101 | module lj
101  
102    public :: newLJtype
103    public :: setLJDefaultCutoff
103  public :: setLJUniformCutoff
104  public :: setLJCutoffByTypes
104    public :: getSigma
105    public :: getEpsilon
107  public :: useGeometricMixing
106    public :: do_lj_pair
107    public :: destroyLJtypes
108  
# Line 161 | Line 159 | contains
159      if(LJMap%nLJTypes /= 0) then
160         call createMixingMap()
161      end if
164  end subroutine setLJDefaultCutoff
162  
163 <  subroutine setLJUniformCutoff(thisRcut, shiftedPot)
167 <    real(kind=dp), intent(in) :: thisRcut
168 <    logical, intent(in) :: shiftedPot
169 <    integer :: nLJtypes, i, j
170 <
171 <    if (LJMap%currentLJtype == 0) then
172 <       call handleError("LJ", "No members in LJMap")
173 <       return
174 <    end if
175 <
176 <    nLJtypes = LJMap%nLJtypes
177 <    if (.not. allocated(MixingMap)) then
178 <       allocate(MixingMap(nLJtypes, nLJtypes))
179 <    endif
180 <
181 <    do i = 1, nLJtypes
182 <       do j = 1, nLJtypes
183 <          MixingMap(i,j)%rCut = thisRcut
184 <          MixingMap(i,j)%shiftedPot = shiftedPot
185 <          MixingMap(i,j)%rCutWasSet = .true.
186 <       enddo
187 <    enddo
188 <    call createMixingMap()
189 <  end subroutine setLJUniformCutoff
190 <
191 <  subroutine setLJCutoffByTypes(atid1, atid2, thisRcut, shiftedPot)
192 <    integer, intent(in) :: atid1, atid2
193 <    real(kind=dp), intent(in) :: thisRcut
194 <    logical, intent(in) :: shiftedPot
195 <    integer :: nLJtypes, ljt1, ljt2
196 <
197 <    if (LJMap%currentLJtype == 0) then
198 <       call handleError("LJ", "No members in LJMap")
199 <       return
200 <    end if
201 <
202 <    nLJtypes = LJMap%nLJtypes
203 <    if (.not. allocated(MixingMap)) then
204 <       allocate(MixingMap(nLJtypes, nLJtypes))
205 <    endif
206 <
207 <    ljt1 = LJMap%atidToLJtype(atid1)
208 <    ljt2 = LJMap%atidToLJtype(atid2)
163 >  end subroutine setLJDefaultCutoff
164  
210    MixingMap(ljt1,ljt2)%rCut = thisRcut
211    MixingMap(ljt1,ljt2)%shiftedPot = shiftedPot
212    MixingMap(ljt1,ljt2)%rCutWasSet = .true.
213    MixingMap(ljt2,ljt1)%rCut = thisRcut
214    MixingMap(ljt2,ljt1)%shiftedPot = shiftedPot
215    MixingMap(ljt2,ljt1)%rCutWasSet = .true.
216
217    call createMixingMap()
218  end subroutine setLJCutoffByTypes
219
165    function getSigma(atid) result (s)
166      integer, intent(in) :: atid
167      integer :: ljt1
# Line 247 | Line 192 | contains
192  
193    end function getEpsilon
194  
250  subroutine useGeometricMixing()
251    useGeometricDistanceMixing = .true.
252    haveMixingMap = .false.
253    return
254  end subroutine useGeometricMixing
255
195    subroutine createMixingMap()
196      integer :: nLJtypes, i, j
197      real ( kind = dp ) :: s1, s2, e1, e2
# Line 270 | Line 209 | contains
209         allocate(MixingMap(nLJtypes, nLJtypes))
210      endif
211  
212 +    useGeometricDistanceMixing = usesGeometricDistanceMixing()
213      do i = 1, nLJtypes
214  
215         s1 = LJMap%LJtypes(i)%sigma
# Line 293 | Line 233 | contains
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
303 <                doShift = defaultShift
304 <             else
305 <                call handleError("LJ", "No specified or default cutoff value!")
306 <             endif
307 <          endif
308 <          
309 <          tp6    = MixingMap(i,j)%sigma6/rcut6
310 <          tp12    = tp6**2          
311 <          MixingMap(i,j)%delta =-4.0_DP*MixingMap(i,j)%epsilon*(tp12 - tp6)
312 <          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
319             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
# Line 328 | Line 257 | contains
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
# Line 344 | Line 273 | contains
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
350    real( kind = dp ) :: r6
351    real( kind = dp ) :: t6
352    real( kind = dp ) :: t12
353    real( kind = dp ) :: delta
280      logical :: isSoftCore, shiftedPot
281      integer :: id1, id2, localError
282  
# Line 370 | Line 296 | contains
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
375    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  
381    t6  = sigma6/ r6
382    t12 = t6 * t6    
383
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 <      
391 <       vpair = vpair + pot_temp
392 <      
393 <       dudr = -sw * 24.0E0_DP * epsilon * t6 / rij
394 <      
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        
401       vpair = vpair + pot_temp
402      
403       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
# Line 413 | Line 340 | contains
340  
341   #ifdef IS_MPI
342      if (do_pot) then
343 <       pot_Row(atom1) = pot_Row(atom1) + sw*pot_temp*0.5
344 <       pot_Col(atom2) = pot_Col(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
# Line 473 | Line 400 | contains
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines