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 2204 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
Revision 2717 by gezelter, Mon Apr 17 21:49:12 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.11 2005-04-15 22:03:47 gezelter Exp $, $Date: 2005-04-15 22:03:47 $, $Name: not supported by cvs2svn $, $Revision: 1.11 $
46 > !! @version $Id: LJ.F90,v 1.21 2006-04-17 21:49:12 gezelter Exp $, $Date: 2006-04-17 21:49:12 $, $Name: not supported by cvs2svn $, $Revision: 1.21 $
47  
48  
49   module lj
50    use atype_module
51  use switcheroo
51    use vector_class
52    use simulation
53    use status
54 +  use fForceOptions
55 +  use interpolation
56   #ifdef IS_MPI
57    use mpiSimulation
58   #endif
# Line 59 | Line 60 | module lj
60  
61    implicit none
62    PRIVATE
63 + #define __FORTRAN90
64 + #include "UseTheForce/DarkSide/fInteractionMap.h"
65  
66    integer, parameter :: DP = selected_real_kind(15)
67  
68 <  type, private :: LjType
69 <     integer :: c_ident
70 <     integer :: atid
68 >  logical, save :: useGeometricDistanceMixing = .false.
69 >  logical, save :: haveMixingMap = .false.
70 >  logical, save :: useSplines = .false.
71 >
72 >  real(kind=DP), save :: defaultCutoff = 0.0_DP
73 >  logical, save :: defaultShift = .false.
74 >  logical, save :: haveDefaultCutoff = .false.
75 >
76 >  type, private :: LJtype
77 >     integer       :: atid
78       real(kind=dp) :: sigma
79       real(kind=dp) :: epsilon
80 <     logical :: soft_pot
81 <  end type LjType
80 >     logical       :: isSoftCore = .false.
81 >  end type LJtype
82  
83 <  type(LjType), dimension(:), allocatable :: ParameterMap
83 >  type, private :: LJList
84 >     integer               :: Nljtypes = 0
85 >     integer               :: currentLJtype = 0
86 >     type(LJtype), pointer :: LJtypes(:)      => null()
87 >     integer, pointer      :: atidToLJtype(:) => null()
88 >  end type LJList
89  
90 <  logical, save :: haveMixingMap = .false.
90 >  type(LJList), save :: LJMap
91  
92    type :: MixParameters
93       real(kind=DP) :: sigma
94       real(kind=DP) :: epsilon
95 <     real(kind=dp)  :: sigma6
96 <     real(kind=dp)  :: tp6
97 <     real(kind=dp)  :: tp12
98 <     real(kind=dp)  :: delta
99 <     logical :: soft_pot    
95 >     real(kind=dp) :: sigmai
96 >     real(kind=dp) :: rCut
97 >     logical       :: rCutWasSet = .false.
98 >     logical       :: shiftedPot
99 >     logical       :: isSoftCore = .false.
100    end type MixParameters
101  
102    type(MixParameters), dimension(:,:), allocatable :: MixingMap
103  
104 <  real(kind=DP), save :: LJ_rcut
105 <  logical, save :: have_rcut = .false.
106 <  logical, save :: LJ_do_shift = .false.
107 <  logical, save :: useGeometricDistanceMixing = .false.
104 >  type(cubicSpline), save :: vLJspline
105 >  type(cubicSpline), save :: vLJpspline
106 >  type(cubicSpline), save :: vSoftSpline
107 >  type(cubicSpline), save :: vSoftpSpline
108  
109 <  !! Public methods and data
110 <
96 <  public :: setCutoffLJ
97 <  public :: useGeometricMixing
98 <  public :: do_lj_pair
99 <  public :: newLJtype  
109 >  public :: newLJtype
110 >  public :: setLJDefaultCutoff
111    public :: getSigma
112    public :: getEpsilon
113 <  public :: destroyLJTypes
113 >  public :: do_lj_pair
114 >  public :: destroyLJtypes
115 >  public :: setLJsplineRmax
116  
117   contains
118  
119 <  subroutine newLJtype(c_ident, sigma, epsilon, soft_pot, status)
119 >  subroutine newLJtype(c_ident, sigma, epsilon, isSoftCore, status)
120      integer,intent(in) :: c_ident
121      real(kind=dp),intent(in) :: sigma
122      real(kind=dp),intent(in) :: epsilon
123 <    integer, intent(in) :: soft_pot
123 >    integer, intent(in) :: isSoftCore
124      integer,intent(out) :: status
125 <    integer :: nATypes, myATID
125 >    integer :: nLJTypes, ntypes, myATID
126      integer, pointer :: MatchList(:) => null()
127 +    integer :: current
128  
129      status = 0
130 +    ! check to see if this is the first time into this routine...
131 +    if (.not.associated(LJMap%LJtypes)) then
132  
133 <    myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
133 >       call getMatchingElementList(atypes, "is_LennardJones", .true., &
134 >            nLJTypes, MatchList)
135 >      
136 >       LJMap%nLJtypes =  nLJTypes
137  
138 <    if (.not.allocated(ParameterMap)) then
138 >       allocate(LJMap%LJtypes(nLJTypes))
139  
140 <       !call getMatchingElementList(atypes, "is_LennardJones", .true., &
122 <       !     nLJTypes, MatchList)
123 <       nAtypes = getSize(atypes)
124 <       if (nAtypes == 0) then
125 <          status = -1
126 <          return
127 <       end if
140 >       ntypes = getSize(atypes)
141  
142 <       if (.not. allocated(ParameterMap)) then
130 <          allocate(ParameterMap(nAtypes))
131 <       endif
132 <
142 >       allocate(LJMap%atidToLJtype(ntypes))
143      end if
144  
145 <    if (myATID .gt. size(ParameterMap)) then
146 <       status = -1
137 <       return
138 <    endif
145 >    LJMap%currentLJtype = LJMap%currentLJtype + 1
146 >    current = LJMap%currentLJtype
147  
148 <    ! set the values for ParameterMap for this atom type:
149 <
150 <    ParameterMap(myATID)%c_ident = c_ident
151 <    ParameterMap(myATID)%atid = myATID
152 <    ParameterMap(myATID)%epsilon = epsilon
153 <    ParameterMap(myATID)%sigma = sigma
154 <    if (soft_pot == 1) then
147 <       ParameterMap(myATID)%soft_pot = .true.
148 >    myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
149 >    LJMap%atidToLJtype(myATID)        = current
150 >    LJMap%LJtypes(current)%atid       = myATID
151 >    LJMap%LJtypes(current)%sigma      = sigma
152 >    LJMap%LJtypes(current)%epsilon    = epsilon
153 >    if (isSoftCore .eq. 1) then
154 >       LJMap%LJtypes(current)%isSoftCore = .true.
155      else
156 <       ParameterMap(myATID)%soft_pot = .false.
156 >       LJMap%LJtypes(current)%isSoftCore = .false.
157      endif
158    end subroutine newLJtype
159  
160 +  subroutine setLJDefaultCutoff(thisRcut, shiftedPot)
161 +    real(kind=dp), intent(in) :: thisRcut
162 +    logical, intent(in) :: shiftedPot
163 +    defaultCutoff = thisRcut
164 +    defaultShift = shiftedPot
165 +    haveDefaultCutoff = .true.
166 +    !we only want to build LJ Mixing map and spline if LJ is being used.
167 +    if(LJMap%nLJTypes /= 0) then
168 +       call createMixingMap()
169 +       call setLJsplineRmax(defaultCutoff)
170 +    end if
171 +
172 +  end subroutine setLJDefaultCutoff
173 +
174    function getSigma(atid) result (s)
175      integer, intent(in) :: atid
176 <    integer :: localError
176 >    integer :: ljt1
177      real(kind=dp) :: s
178  
179 <    if (.not.allocated(ParameterMap)) then
180 <       call handleError("LJ", "no ParameterMap was present before first call of getSigma!")
179 >    if (LJMap%currentLJtype == 0) then
180 >       call handleError("LJ", "No members in LJMap")
181         return
182      end if
183  
184 <    s = ParameterMap(atid)%sigma
184 >    ljt1 = LJMap%atidToLJtype(atid)
185 >    s = LJMap%LJtypes(ljt1)%sigma
186 >
187    end function getSigma
188  
189    function getEpsilon(atid) result (e)
190      integer, intent(in) :: atid
191 <    integer :: localError
191 >    integer :: ljt1
192      real(kind=dp) :: e
193  
194 <    if (.not.allocated(ParameterMap)) then
195 <       call handleError("LJ", "no ParameterMap was present before first call of getEpsilon!")
194 >    if (LJMap%currentLJtype == 0) then
195 >       call handleError("LJ", "No members in LJMap")
196         return
197      end if
198  
199 <    e = ParameterMap(atid)%epsilon
199 >    ljt1 = LJMap%atidToLJtype(atid)
200 >    e = LJMap%LJtypes(ljt1)%epsilon
201 >
202    end function getEpsilon
203  
204 +  subroutine createMixingMap()
205 +    integer :: nLJtypes, i, j
206 +    real ( kind = dp ) :: s1, s2, e1, e2
207 +    real ( kind = dp ) :: rcut6, tp6, tp12
208 +    logical :: isSoftCore1, isSoftCore2, doShift
209  
210 <  subroutine setCutoffLJ(rcut, do_shift, status)
211 <    logical, intent(in):: do_shift
182 <    integer :: status, myStatus
183 <    real(kind=dp) :: rcut
184 <
185 < #define __FORTRAN90
186 < #include "UseTheForce/fSwitchingFunction.h"
187 <
188 <    status = 0
189 <
190 <    LJ_rcut = rcut
191 <    LJ_do_shift = do_shift
192 <    call set_switch(LJ_SWITCH, rcut, rcut)
193 <    have_rcut = .true.
194 <
195 <    return
196 <  end subroutine setCutoffLJ
197 <
198 <  subroutine useGeometricMixing()
199 <    useGeometricDistanceMixing = .true.
200 <    haveMixingMap = .false.
201 <    return
202 <  end subroutine useGeometricMixing
203 <
204 <  subroutine createMixingMap(status)
205 <    integer :: nATIDs
206 <    integer :: status
207 <    integer :: i
208 <    integer :: j
209 <    real ( kind = dp ) :: Sigma_i, Sigma_j
210 <    real ( kind = dp ) :: Epsilon_i, Epsilon_j
211 <    real ( kind = dp ) :: rcut6
212 <    logical :: i_is_LJ, j_is_LJ
213 <
214 <    status = 0
215 <
216 <    if (.not. allocated(ParameterMap)) then
217 <       call handleError("LJ", "no ParameterMap was present before call of createMixingMap!")
218 <       status = -1
210 >    if (LJMap%currentLJtype == 0) then
211 >       call handleError("LJ", "No members in LJMap")
212         return
220    endif
221
222    nATIDs = size(ParameterMap)
223
224    if (nATIDs == 0) then
225       status = -1
226       return
213      end if
214  
215 +    nLJtypes = LJMap%nLJtypes
216 +
217      if (.not. allocated(MixingMap)) then
218 <       allocate(MixingMap(nATIDs, nATIDs))
218 >       allocate(MixingMap(nLJtypes, nLJtypes))
219      endif
220  
221 <    if (.not.have_rcut) then
222 <       status = -1
235 <       return
236 <    endif
221 >    useGeometricDistanceMixing = usesGeometricDistanceMixing()
222 >    do i = 1, nLJtypes
223  
224 <    rcut6 = LJ_rcut**6
224 >       s1 = LJMap%LJtypes(i)%sigma
225 >       e1 = LJMap%LJtypes(i)%epsilon
226 >       isSoftCore1 = LJMap%LJtypes(i)%isSoftCore
227  
228 <    ! This loops through all atypes, even those that don't support LJ forces.
229 <    do i = 1, nATIDs
230 <       call getElementProperty(atypes, i, "is_LennardJones", i_is_LJ)
231 <       if (i_is_LJ) then
232 <          Epsilon_i = ParameterMap(i)%epsilon
233 <          Sigma_i = ParameterMap(i)%sigma
228 >       do j = i, nLJtypes
229 >          
230 >          s2 = LJMap%LJtypes(j)%sigma
231 >          e2 = LJMap%LJtypes(j)%epsilon
232 >          isSoftCore2 = LJMap%LJtypes(j)%isSoftCore
233 >          
234 >          MixingMap(i,j)%isSoftCore = isSoftCore1 .or. isSoftCore2
235  
236 <          ! do self mixing rule
237 <          MixingMap(i,i)%sigma   = Sigma_i          
238 <          MixingMap(i,i)%sigma6  = Sigma_i ** 6          
239 <          MixingMap(i,i)%tp6     = (MixingMap(i,i)%sigma6)/rcut6          
240 <          MixingMap(i,i)%tp12    = (MixingMap(i,i)%tp6) ** 2
241 <          MixingMap(i,i)%epsilon = Epsilon_i          
242 <          MixingMap(i,i)%delta   = -4.0_DP * MixingMap(i,i)%epsilon * &
243 <               (MixingMap(i,i)%tp12 - MixingMap(i,i)%tp6)
255 <          MixingMap(i,i)%soft_pot = ParameterMap(i)%soft_pot
236 >          ! only the distance parameter uses different mixing policies
237 >          if (useGeometricDistanceMixing) then
238 >             MixingMap(i,j)%sigma = dsqrt(s1 * s2)
239 >          else
240 >             MixingMap(i,j)%sigma = 0.5_dp * (s1 + s2)
241 >          endif
242 >          
243 >          MixingMap(i,j)%epsilon = dsqrt(e1 * e2)
244  
245 <          do j = i + 1, nATIDs
258 <             call getElementProperty(atypes, j, "is_LennardJones", j_is_LJ)
245 >          MixingMap(i,j)%sigmai = 1.0_DP  / (MixingMap(i,j)%sigma)
246  
247 <             if (j_is_LJ) then
248 <                Epsilon_j = ParameterMap(j)%epsilon
249 <                Sigma_j = ParameterMap(j)%sigma
247 >          if (haveDefaultCutoff) then
248 >             MixingMap(i,j)%shiftedPot = defaultShift
249 >          else
250 >             MixingMap(i,j)%shiftedPot = defaultShift
251 >          endif          
252  
253 <                ! only the distance parameter uses different mixing policies
254 <                if (useGeometricDistanceMixing) then
255 <                   ! only for OPLS as far as we can tell
256 <                   MixingMap(i,j)%sigma = dsqrt(Sigma_i * Sigma_j)
257 <                else
258 <                   ! everyone else
259 <                   MixingMap(i,j)%sigma = 0.5_dp * (Sigma_i + Sigma_j)
260 <                endif
253 >          if (i.ne.j) then
254 >             MixingMap(j,i)%sigma      = MixingMap(i,j)%sigma
255 >             MixingMap(j,i)%epsilon    = MixingMap(i,j)%epsilon
256 >             MixingMap(j,i)%sigmai     = MixingMap(i,j)%sigmai
257 >             MixingMap(j,i)%rCut       = MixingMap(i,j)%rCut
258 >             MixingMap(j,i)%rCutWasSet = MixingMap(i,j)%rCutWasSet
259 >             MixingMap(j,i)%shiftedPot = MixingMap(i,j)%shiftedPot
260 >             MixingMap(j,i)%isSoftCore = MixingMap(i,j)%isSoftCore
261 >          endif
262  
263 <                ! energy parameter is always geometric mean:
264 <                MixingMap(i,j)%epsilon = dsqrt(Epsilon_i * Epsilon_j)
265 <
276 <                MixingMap(i,j)%sigma6 = (MixingMap(i,j)%sigma)**6
277 <                MixingMap(i,j)%tp6    = MixingMap(i,j)%sigma6/rcut6
278 <                MixingMap(i,j)%tp12    = (MixingMap(i,j)%tp6) ** 2
279 <
280 <                MixingMap(i,j)%delta = -4.0_DP * MixingMap(i,j)%epsilon * &
281 <                     (MixingMap(i,j)%tp12 - MixingMap(i,j)%tp6)
282 <
283 <                MixingMap(i,j)%soft_pot = ParameterMap(i)%soft_pot .or. ParameterMap(j)%soft_pot
284 <
285 <
286 <                MixingMap(j,i)%sigma   = MixingMap(i,j)%sigma
287 <                MixingMap(j,i)%sigma6  = MixingMap(i,j)%sigma6
288 <                MixingMap(j,i)%tp6     = MixingMap(i,j)%tp6
289 <                MixingMap(j,i)%tp12    = MixingMap(i,j)%tp12
290 <                MixingMap(j,i)%epsilon = MixingMap(i,j)%epsilon
291 <                MixingMap(j,i)%delta   = MixingMap(i,j)%delta
292 <                MixingMap(j,i)%soft_pot   = MixingMap(i,j)%soft_pot
293 <             endif
294 <          end do
295 <       endif
296 <    end do
297 <
263 >       enddo
264 >    enddo
265 >    
266      haveMixingMap = .true.
267 <
267 >    
268    end subroutine createMixingMap
269 +  
270 +  subroutine setLJsplineRmax(largestRcut)
271 +    real( kind = dp ), intent(in) :: largestRcut
272 +    real( kind = dp ) :: s, bigS, smallS, rmax, rmin
273 +    integer :: np, i
274  
275 <  subroutine do_lj_pair(atom1, atom2, d, rij, r2, sw, vpair, fpair, &
303 <       pot, f, do_pot)
275 >    if (LJMap%nLJtypes .ne. 0) then
276  
277 +       !
278 +       ! find the largest and smallest values of sigma that we'll need
279 +       !
280 +       bigS = 0.0_DP
281 +       smallS = 1.0e9
282 +       do i = 1, LJMap%nLJtypes
283 +          s = LJMap%LJtypes(i)%sigma
284 +          if (s .gt. bigS) bigS = s
285 +          if (s .lt. smallS) smallS = s
286 +       enddo
287 +      
288 +       !
289 +       ! give ourselves a 20% margin just in case
290 +       !
291 +       rmax = 1.2 * largestRcut / smallS    
292 +       !
293 +       ! assume atoms will never get closer than 1 angstrom
294 +       !
295 +       rmin = 1 / bigS
296 +       !
297 +       ! assume 500 points is enough
298 +       !
299 +       np = 500
300 +      
301 +       write(*,*) 'calling setupSplines with rmin = ', rmin, ' rmax = ', rmax, &
302 +            ' np = ', np
303 +      
304 +       call setupSplines(rmin, rmax, np)
305 +
306 +    endif
307 +    return
308 +  end subroutine setLJsplineRmax
309 +        
310 +  subroutine do_lj_pair(atom1, atom2, d, rij, r2, rcut, sw, vpair, fpair, &
311 +       pot, f, do_pot)
312 +    
313      integer, intent(in) ::  atom1, atom2
314 <    real( kind = dp ), intent(in) :: rij, r2
314 >    integer :: atid1, atid2, ljt1, ljt2
315 >    real( kind = dp ), intent(in) :: rij, r2, rcut
316      real( kind = dp ) :: pot, sw, vpair
317      real( kind = dp ), dimension(3,nLocal) :: f    
318      real( kind = dp ), intent(in), dimension(3) :: d
# Line 313 | Line 322 | contains
322      ! local Variables
323      real( kind = dp ) :: drdx, drdy, drdz
324      real( kind = dp ) :: fx, fy, fz
325 +    real( kind = dp ) :: myPot, myPotC, myDeriv, myDerivC, ros, rcos
326      real( kind = dp ) :: pot_temp, dudr
327 <    real( kind = dp ) :: sigma6
327 >    real( kind = dp ) :: sigmai
328      real( kind = dp ) :: epsilon
329 <    real( kind = dp ) :: r6
320 <    real( kind = dp ) :: t6
321 <    real( kind = dp ) :: t12
322 <    real( kind = dp ) :: delta
323 <    logical :: soft_pot
329 >    logical :: isSoftCore, shiftedPot
330      integer :: id1, id2, localError
331  
332      if (.not.haveMixingMap) then
333 <       localError = 0
328 <       call createMixingMap(localError)
329 <       if ( localError .ne. 0 ) then
330 <          call handleError("LJ", "MixingMap creation failed!")
331 <          return
332 <       end if
333 >       call createMixingMap()
334      endif
335  
336      ! Look up the correct parameters in the mixing matrix
337   #ifdef IS_MPI
338 <    sigma6   = MixingMap(atid_Row(atom1),atid_Col(atom2))%sigma6
339 <    epsilon  = MixingMap(atid_Row(atom1),atid_Col(atom2))%epsilon
339 <    delta    = MixingMap(atid_Row(atom1),atid_Col(atom2))%delta
340 <    soft_pot =  MixingMap(atid_Row(atom1),atid_Col(atom2))%soft_pot
338 >    atid1 = atid_Row(atom1)
339 >    atid2 = atid_Col(atom2)
340   #else
341 <    sigma6   = MixingMap(atid(atom1),atid(atom2))%sigma6
342 <    epsilon  = MixingMap(atid(atom1),atid(atom2))%epsilon
344 <    delta    = MixingMap(atid(atom1),atid(atom2))%delta
345 <    soft_pot    = MixingMap(atid(atom1),atid(atom2))%soft_pot
341 >    atid1 = atid(atom1)
342 >    atid2 = atid(atom2)
343   #endif
344  
345 <    r6 = r2 * r2 * r2
345 >    ljt1 = LJMap%atidToLJtype(atid1)
346 >    ljt2 = LJMap%atidToLJtype(atid2)
347  
348 <    t6  = sigma6/ r6
349 <    t12 = t6 * t6    
348 >    sigmai     = MixingMap(ljt1,ljt2)%sigmai
349 >    epsilon    = MixingMap(ljt1,ljt2)%epsilon
350 >    isSoftCore = MixingMap(ljt1,ljt2)%isSoftCore
351 >    shiftedPot = MixingMap(ljt1,ljt2)%shiftedPot
352  
353 <    if (soft_pot) then
354 <       pot_temp = 4.0E0_DP * epsilon * t12
355 <       if (LJ_do_shift) then
356 <          pot_temp = pot_temp + delta
357 <       endif
353 >    ros = rij * sigmai
354 >    myPotC = 0.0_DP
355  
356 <       vpair = vpair + pot_temp
356 >    if (isSoftCore) then
357  
358 <       dudr = sw * 24.0E0_DP * epsilon * (-2.0E0_DP)*t12 / rij
358 >       call getSoftFunc(ros, myPot, myDeriv)
359  
360 <    else
361 <       pot_temp = 4.0E0_DP * epsilon * (t12 - t6)
362 <       if (LJ_do_shift) then
366 <          pot_temp = pot_temp + delta
360 >       if (shiftedPot) then
361 >          rcos = rcut * sigmai
362 >          call getSoftFunc(rcos, myPotC, myDerivC)
363         endif
364 +              
365 +    else
366  
367 <       vpair = vpair + pot_temp
367 >       call getLJfunc(ros, myPot, myDeriv)
368  
369 <       dudr = sw * 24.0E0_DP * epsilon * (t6 - 2.0E0_DP*t12) / rij
369 >       if (shiftedPot) then
370 >          rcos = rcut * sigmai
371 >          call getLJfunc(rcos, myPotC, myDerivC)
372 >       endif
373 >      
374      endif
375  
376 +    !write(*,*) rij, ros, rcos, myPot, myDeriv, myPotC
377 +
378 +    pot_temp = epsilon * (myPot - myPotC)
379 +    vpair = vpair + pot_temp
380 +    dudr = sw * epsilon * myDeriv * sigmai
381 +
382      drdx = d(1) / rij
383      drdy = d(2) / rij
384      drdz = d(3) / rij
# Line 379 | Line 387 | contains
387      fy = dudr * drdy
388      fz = dudr * drdz
389  
382
390   #ifdef IS_MPI
391      if (do_pot) then
392 <       pot_Row(atom1) = pot_Row(atom1) + sw*pot_temp*0.5
393 <       pot_Col(atom2) = pot_Col(atom2) + sw*pot_temp*0.5
392 >       pot_Row(VDW_POT,atom1) = pot_Row(VDW_POT,atom1) + sw*pot_temp*0.5
393 >       pot_Col(VDW_POT,atom2) = pot_Col(VDW_POT,atom2) + sw*pot_temp*0.5
394      endif
395  
396      f_Row(1,atom1) = f_Row(1,atom1) + fx
# Line 427 | Line 434 | contains
434    end subroutine do_lj_pair
435  
436    subroutine destroyLJTypes()
437 <    if(allocated(ParameterMap)) deallocate(ParameterMap)
438 <    if(allocated(MixingMap)) deallocate(MixingMap)
437 >
438 >    LJMap%nLJtypes = 0
439 >    LJMap%currentLJtype = 0
440 >    
441 >    if (associated(LJMap%LJtypes)) then
442 >       deallocate(LJMap%LJtypes)
443 >       LJMap%LJtypes => null()
444 >    end if
445 >    
446 >    if (associated(LJMap%atidToLJtype)) then
447 >       deallocate(LJMap%atidToLJtype)
448 >       LJMap%atidToLJtype => null()
449 >    end if
450 >    
451      haveMixingMap = .false.
452 +
453 +    call deleteSpline(vLJspline)
454 +    call deleteSpline(vLJpspline)
455 +    call deleteSpline(vSoftSpline)
456 +    call deleteSpline(vSoftpSpline)
457 +
458    end subroutine destroyLJTypes
459  
460 +  subroutine getLJfunc(r, myPot, myDeriv)
461  
462 +    real(kind=dp), intent(in) :: r
463 +    real(kind=dp), intent(inout) :: myPot, myDeriv
464 +    real(kind=dp) :: ri, ri2, ri6, ri7, ri12, ri13
465 +    real(kind=dp) :: a, b, c, d, dx
466 +    integer :: j
467 +
468 +    if (useSplines) then
469 +       j = MAX(1, MIN(vLJspline%np, idint((r-vLJspline%x(1)) * vLJspline%dx_i) + 1))
470 +      
471 +       dx = r - vLJspline%x(j)
472 +      
473 +       a = vLJspline%c(1,j)
474 +       b = vLJspline%c(2,j)
475 +       c = vLJspline%c(3,j)
476 +       d = vLJspline%c(4,j)
477 +      
478 +       myPot = c + dx * d
479 +       myPot = b + dx * myPot
480 +       myPot = a + dx * myPot
481 +
482 +       a = vLJpspline%c(1,j)
483 +       b = vLJpspline%c(2,j)
484 +       c = vLJpspline%c(3,j)
485 +       d = vLJpspline%c(4,j)
486 +      
487 +       myDeriv = c + dx * d
488 +       myDeriv = b + dx * myDeriv  
489 +       myDeriv = a + dx * myDeriv
490 +      
491 +    else
492 +       ri = 1.0_DP / r
493 +       ri2 = ri*ri
494 +       ri6 = ri2*ri2*ri2
495 +       ri7 = ri6*ri
496 +       ri12 = ri6*ri6
497 +       ri13 = ri12*ri
498 +      
499 +       myPot = 4.0_DP * (ri12 - ri6)
500 +       myDeriv = 24.0_DP * (ri7 - 2.0_DP * ri13)
501 +    endif
502 +
503 +    return
504 +  end subroutine getLJfunc
505 +
506 +  subroutine getSoftFunc(r, myPot, myDeriv)
507 +    
508 +    real(kind=dp), intent(in) :: r
509 +    real(kind=dp), intent(inout) :: myPot, myDeriv
510 +    real(kind=dp) :: ri, ri2, ri6, ri7
511 +    real(kind=dp) :: a, b, c, d, dx
512 +    integer :: j
513 +    
514 +    if (useSplines) then
515 +       j = MAX(1, MIN(vSoftSpline%np, idint((r-vSoftSpline%x(1)) * vSoftSpline%dx_i) + 1))
516 +      
517 +       dx = r - vSoftSpline%x(j)
518 +      
519 +       a = vSoftSpline%c(1,j)
520 +       b = vSoftSpline%c(2,j)
521 +       c = vSoftSpline%c(3,j)
522 +       d = vSoftSpline%c(4,j)
523 +      
524 +       myPot = c + dx * d
525 +       myPot = b + dx * myPot
526 +       myPot = a + dx * myPot
527 +
528 +       a = vSoftPspline%c(1,j)
529 +       b = vSoftPspline%c(2,j)
530 +       c = vSoftPspline%c(3,j)
531 +       d = vSoftPspline%c(4,j)
532 +      
533 +       myDeriv = c + dx * d
534 +       myDeriv = b + dx * myDeriv  
535 +       myDeriv = a + dx * myDeriv
536 +      
537 +    else
538 +       ri = 1.0_DP / r    
539 +       ri2 = ri*ri
540 +       ri6 = ri2*ri2*ri2
541 +       ri7 = ri6*ri
542 +       myPot = 4.0_DP * (ri6)
543 +       myDeriv = - 24.0_DP * ri7
544 +    endif
545 +
546 +    return
547 +  end subroutine getSoftFunc
548 +
549 +  subroutine setupSplines(rmin, rmax, np)
550 +    real( kind = dp ), intent(in) :: rmin, rmax
551 +    integer, intent(in) :: np
552 +    real( kind = dp ) :: rvals(np), vLJ(np), vLJp(np), vSoft(np), vSoftp(np)
553 +    real( kind = dp ) :: dr, r, ri, ri2, ri6, ri7, ri12, ri13
554 +    real( kind = dp ) :: vljpp1, vljppn, vsoftpp1, vsoftppn
555 +    integer :: i
556 +
557 +    dr = (rmax-rmin) / float(np-1)
558 +    
559 +    do i = 1, np
560 +       r = rmin + dble(i-1)*dr
561 +       ri = 1.0_DP / r
562 +       ri2 = ri*ri
563 +       ri6 = ri2*ri2*ri2
564 +       ri7 = ri6*ri
565 +       ri12 = ri6*ri6
566 +       ri13 = ri12*ri
567 +
568 +       rvals(i) = r
569 +       vLJ(i) = 4.0_DP * (ri12 - ri6)
570 +       vLJp(i) = 24.0_DP * (ri7 - 2.0_DP * ri13)
571 +
572 +       vSoft(i) = 4.0_DP * (ri6)
573 +       vSoftp(i) = - 24.0_DP * ri7      
574 +    enddo
575 +
576 +    vljpp1 = 624.0_DP / (rmin)**(14)  - 168.0_DP / (rmin)**(8)
577 +    vljppn = 624.0_DP / (rmax)**(14)  - 168.0_DP / (rmax)**(8)
578 +
579 +    vsoftpp1 = 168.0_DP / (rmin)**(8)
580 +    vsoftppn = 168.0_DP / (rmax)**(8)
581 +
582 +    call newSpline(vLJspline, rvals, vLJ, vLJp(1), vLJp(np), .true.)
583 +    call newSpline(vLJpspline, rvals, vLJp, vljpp1, vljppn, .true.)
584 +    call newSpline(vSoftSpline, rvals, vSoft, vSoftp(1), vSoftp(np), .true.)
585 +    call newSpline(vSoftpSpline, rvals, vSoftp, vsoftpp1, vsoftppn, .true.)
586 +
587 +    return
588 +  end subroutine setupSplines
589   end module lj

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines