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 1624 by chuckv, Thu Oct 21 15:25:30 2004 UTC vs.
Revision 1948 by gezelter, Fri Jan 14 20:31:16 2005 UTC

# Line 1 | Line 1
1 + !!
2 + !! Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 + !!
4 + !! The University of Notre Dame grants you ("Licensee") a
5 + !! non-exclusive, royalty free, license to use, modify and
6 + !! redistribute this software in source and binary code form, provided
7 + !! that the following conditions are met:
8 + !!
9 + !! 1. Acknowledgement of the program authors must be made in any
10 + !!    publication of scientific results based in part on use of the
11 + !!    program.  An acceptable form of acknowledgement is citation of
12 + !!    the article in which the program was described (Matthew
13 + !!    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 + !!    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 + !!    Parallel Simulation Engine for Molecular Dynamics,"
16 + !!    J. Comput. Chem. 26, pp. 252-271 (2005))
17 + !!
18 + !! 2. Redistributions of source code must retain the above copyright
19 + !!    notice, this list of conditions and the following disclaimer.
20 + !!
21 + !! 3. Redistributions in binary form must reproduce the above copyright
22 + !!    notice, this list of conditions and the following disclaimer in the
23 + !!    documentation and/or other materials provided with the
24 + !!    distribution.
25 + !!
26 + !! This software is provided "AS IS," without a warranty of any
27 + !! kind. All express or implied conditions, representations and
28 + !! warranties, including any implied warranty of merchantability,
29 + !! fitness for a particular purpose or non-infringement, are hereby
30 + !! excluded.  The University of Notre Dame and its licensors shall not
31 + !! be liable for any damages suffered by licensee as a result of
32 + !! using, modifying or distributing the software or its
33 + !! derivatives. In no event will the University of Notre Dame or its
34 + !! licensors be liable for any lost revenue, profit or data, or for
35 + !! direct, indirect, special, consequential, incidental or punitive
36 + !! damages, however caused and regardless of the theory of liability,
37 + !! arising out of the use of or inability to use software, even if the
38 + !! University of Notre Dame has been advised of the possibility of
39 + !! such damages.
40 + !!
41 +
42 +
43   !! Calculates Long Range forces Lennard-Jones interactions.
2 !! Corresponds to the force field defined in lj_FF.cpp
44   !! @author Charles F. Vardeman II
45   !! @author Matthew Meineke
46 < !! @version $Id: LJ.F90,v 1.2 2004-10-21 15:25:30 chuckv Exp $, $Date: 2004-10-21 15:25:30 $, $Name: not supported by cvs2svn $, $Revision: 1.2 $
46 > !! @version $Id: LJ.F90,v 1.7 2005-01-14 20:31:16 gezelter Exp $, $Date: 2005-01-14 20:31:16 $, $Name: not supported by cvs2svn $, $Revision: 1.7 $
47  
48 +
49   module lj
50    use atype_module
51    use switcheroo
52    use vector_class
53    use simulation
54 +  use status
55   #ifdef IS_MPI
56    use mpiSimulation
57   #endif
# Line 18 | Line 61 | module lj
61    PRIVATE
62    
63    integer, parameter :: DP = selected_real_kind(15)
21
22 #define __FORTRAN90
23 #include "UseTheForce/fForceField.h"
24
25  integer, save :: LJ_Mixing_Policy
26  real(kind=DP), save :: LJ_rcut
27  logical, save :: havePolicy = .false.
28  logical, save :: haveCut = .false.
29  logical, save :: LJ_do_shift = .false.
64    
65 <  !! Logical has lj force field module been initialized?
65 >  type, private :: LjType
66 >     integer :: c_ident
67 >     integer :: atid
68 >     real(kind=dp) :: sigma
69 >     real(kind=dp) :: epsilon
70 >  end type LjType
71    
72 <  logical, save :: LJ_FF_initialized = .false.
72 >  type(LjType), dimension(:), allocatable :: ParameterMap
73    
74 <  !! Public methods and data
36 <  public :: init_LJ_FF
37 <  public :: setCutoffLJ
38 <  public :: do_lj_pair
39 <  public :: newLJtype
74 >  logical, save :: haveMixingMap = .false.
75    
76 <  !! structure for lj type parameters
77 <  type, private :: ljType
78 <    integer :: lj_ident
79 <    real(kind=dp) :: lj_sigma
80 <    real(kind=dp) :: lj_epsilon
81 <  end type ljType
76 >  type :: MixParameters
77 >     real(kind=DP) :: sigma
78 >     real(kind=DP) :: epsilon
79 >     real(kind=dp)  :: sigma6
80 >     real(kind=dp)  :: tp6
81 >     real(kind=dp)  :: tp12
82 >     real(kind=dp)  :: delta
83 >  end type MixParameters
84    
85 <  !! List of lj type parameters
49 <  type, private :: ljTypeList
50 <    integer  :: n_lj_types = 0
51 <    integer  :: currentAddition = 0
52 <    type(ljType), pointer :: ljParams(:) => null()
53 <  end type ljTypeList
85 >  type(MixParameters), dimension(:,:), allocatable :: MixingMap
86    
87 <  !! The list of lj Parameters
88 <  type (ljTypeList), save :: ljParameterList
87 >  real(kind=DP), save :: LJ_rcut
88 >  logical, save :: have_rcut = .false.
89 >  logical, save :: LJ_do_shift = .false.
90 >  logical, save :: useGeometricDistanceMixing = .false.
91 >  
92 >  !! Public methods and data
93    
94 +  public :: setCutoffLJ
95 +  public :: useGeometricMixing
96 +  public :: do_lj_pair
97 +  public :: newLJtype  
98 +  public :: getSigma
99 +  public :: getEpsilon
100    
59  type :: lj_mixed_params
60     !! Lennard-Jones epsilon
61     real ( kind = dp )  :: epsilon = 0.0_dp
62     !! Lennard-Jones Sigma
63     real ( kind = dp )  :: sigma = 0.0_dp
64     !! Lennard-Jones Sigma to sixth
65     real ( kind = dp )  :: sigma6 = 0.0_dp
66     !!
67     real ( kind = dp )  :: tp6
68     real ( kind = dp )  :: tp12
69     real ( kind = dp )  :: delta  = 0.0_dp
70  end type lj_mixed_params
71  
72  type (lj_mixed_params), dimension(:,:), pointer :: ljMixed
73  
74  
75  
101   contains
102  
103 <  subroutine newLJtype(ident,lj_sigma,lj_epsilon,status)
104 <    integer,intent(in) :: ident
105 <    real(kind=dp),intent(in) :: lj_sigma
106 <    real(kind=dp),intent(in) :: lj_epsilon
103 >  subroutine newLJtype(c_ident, sigma, epsilon, status)
104 >    integer,intent(in) :: c_ident
105 >    real(kind=dp),intent(in) :: sigma
106 >    real(kind=dp),intent(in) :: epsilon
107      integer,intent(out) :: status
108 <    
109 <    integer,pointer                        :: Matchlist(:) => null()
110 <    integer :: current
86 <    integer :: nAtypes
108 >    integer :: nATypes, myATID
109 >    integer, pointer :: MatchList(:) => null()
110 >
111      status = 0
112      
113 <        !! Assume that atypes has already been set and get the total number of types in atypes
90 <  
91 <  
113 >    myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
114  
115 <    ! check to see if this is the first time into
116 <    if (.not.associated(ljParameterList%ljParams)) then
117 <       call getMatchingElementList(atypes, "is_lj", .true., nAtypes, MatchList)
118 <       ljParameterList%n_lj_types = nAtypes
115 >    if (.not.allocated(ParameterMap)) then
116 >      
117 >       !call getMatchingElementList(atypes, "is_LennardJones", .true., &
118 >       !     nLJTypes, MatchList)
119 >       nAtypes = getSize(atypes)
120         if (nAtypes == 0) then
121 <         status = -1
122 <         return
121 >          status = -1
122 >          return
123         end if
124 <       allocate(ljParameterList%ljParams(nAtypes))
124 >      
125 >       if (.not. allocated(ParameterMap)) then
126 >          allocate(ParameterMap(nAtypes))
127 >       endif
128 >      
129      end if
130  
131 <    ljParameterList%currentAddition = ljParameterList%currentAddition + 1
132 <    current = ljParameterList%currentAddition
131 >    if (myATID .gt. size(ParameterMap)) then
132 >       status = -1
133 >       return
134 >    endif
135      
136 <    ! set the values for ljParameterList
137 <    ljParameterList%ljParams(current)%lj_ident = ident
138 <    ljParameterList%ljParams(current)%lj_epsilon = lj_epsilon
139 <    ljParameterList%ljParams(current)%lj_sigma = lj_sigma
136 >    ! set the values for ParameterMap for this atom type:
137 >
138 >    ParameterMap(myATID)%c_ident = c_ident
139 >    ParameterMap(myATID)%atid = myATID
140 >    ParameterMap(myATID)%epsilon = epsilon
141 >    ParameterMap(myATID)%sigma = sigma
142      
143    end subroutine newLJtype
144 <  
145 <  subroutine init_LJ_FF(mix_Policy, status)
146 <    integer, intent(in) :: mix_Policy
147 <    integer, intent(out) :: status
148 <    integer :: myStatus
144 >
145 >  function getSigma(atid) result (s)
146 >    integer, intent(in) :: atid
147 >    integer :: localError
148 >    real(kind=dp) :: s
149      
150 <    if (mix_Policy == LB_MIXING_RULE) then
151 <       LJ_Mixing_Policy = LB_MIXING_RULE
152 <    else
153 <       if (mix_Policy == EXPLICIT_MIXING_RULE) then
154 <          LJ_Mixing_Policy = EXPLICIT_MIXING_RULE
155 <       else
156 <          write(*,*) 'Unknown Mixing Policy!'
126 <          status = -1
127 <          return
128 <       endif
129 <    endif
150 >    if (.not.allocated(ParameterMap)) then
151 >       call handleError("LJ", "no ParameterMap was present before first call of getSigma!")
152 >       return
153 >    end if
154 >    
155 >    s = ParameterMap(atid)%sigma
156 >  end function getSigma
157  
158 <    havePolicy = .true.
159 <
160 <    if (haveCut) then
161 <       status = 0
162 <       call createMixingList(myStatus)
163 <       if (myStatus /= 0) then
164 <          status = -1
165 <          return
139 <       end if
140 <      
141 <       LJ_FF_initialized = .true.
158 >  function getEpsilon(atid) result (e)
159 >    integer, intent(in) :: atid
160 >    integer :: localError
161 >    real(kind=dp) :: e
162 >    
163 >    if (.not.allocated(ParameterMap)) then
164 >       call handleError("LJ", "no ParameterMap was present before first call of getEpsilon!")
165 >       return
166      end if
167 <  
168 <  end subroutine init_LJ_FF
169 <  
167 >    
168 >    e = ParameterMap(atid)%epsilon
169 >  end function getEpsilon
170 >
171 >
172    subroutine setCutoffLJ(rcut, do_shift, status)
173      logical, intent(in):: do_shift
174      integer :: status, myStatus
# Line 156 | Line 182 | contains
182      LJ_rcut = rcut
183      LJ_do_shift = do_shift
184      call set_switch(LJ_SWITCH, rcut, rcut)
185 <    haveCut = .true.
160 <
161 <    if (havePolicy) then
162 <       status = 0
163 <       call createMixingList(myStatus)
164 <       if (myStatus /= 0) then
165 <          status = -1
166 <          return
167 <       end if
168 <      
169 <       LJ_FF_initialized = .true.
170 <    end if    
185 >    have_rcut = .true.
186      
187      return
188    end subroutine setCutoffLJ
189 +
190 +  subroutine useGeometricMixing()
191 +    useGeometricDistanceMixing = .true.
192 +    haveMixingMap = .false.
193 +    return
194 +  end subroutine useGeometricMixing
195    
196 <  subroutine createMixingList(status)
197 <    integer :: nAtypes
196 >  subroutine createMixingMap(status)
197 >    integer :: nATIDs
198      integer :: status
199      integer :: i
200      integer :: j
201 <    real ( kind = dp ) :: mySigma_i,mySigma_j
202 <    real ( kind = dp ) :: myEpsilon_i,myEpsilon_j
201 >    real ( kind = dp ) :: Sigma_i, Sigma_j
202 >    real ( kind = dp ) :: Epsilon_i, Epsilon_j
203      real ( kind = dp ) :: rcut6
204 <    logical :: I_isLJ, J_isLJ
204 >
205      status = 0
206      
207 <    ! we only allocate this array to the number of lj_atypes
208 <    nAtypes = size(ljParameterList%ljParams)
209 <    if (nAtypes == 0) then
207 >    nATIDs = size(ParameterMap)
208 >    
209 >    if (nATIDs == 0) then
210         status = -1
211         return
212      end if
192        
193    if (.not. associated(ljMixed)) then
194       allocate(ljMixed(nAtypes, nAtypes))
195    endif
213  
214 +    if (.not.have_rcut) then
215 +       status = -1
216 +       return
217 +    endif
218 +    
219 +    if (.not. allocated(MixingMap)) then
220 +       allocate(MixingMap(nATIDs, nATIDs))
221 +    endif
222 +    
223      rcut6 = LJ_rcut**6
224 <
225 < ! This loops through all atypes, even those that don't support LJ forces.
226 <    do i = 1, nAtypes
227 <
228 <          myEpsilon_i = ljParameterList%ljParams(i)%lj_epsilon
229 <          mySigma_i = ljParameterList%ljParams(i)%lj_sigma
224 >    
225 >    ! This loops through all atypes, even those that don't support LJ forces.
226 >    do i = 1, nATIDs
227 >      
228 >       Epsilon_i = ParameterMap(i)%epsilon
229 >       Sigma_i = ParameterMap(i)%sigma
230 >      
231 >       ! do self mixing rule
232 >       MixingMap(i,i)%sigma   = Sigma_i          
233 >       MixingMap(i,i)%sigma6  = Sigma_i ** 6          
234 >       MixingMap(i,i)%tp6     = (MixingMap(i,i)%sigma6)/rcut6          
235 >       MixingMap(i,i)%tp12    = (MixingMap(i,i)%tp6) ** 2
236 >       MixingMap(i,i)%epsilon = Epsilon_i          
237 >       MixingMap(i,i)%delta   = -4.0_DP * MixingMap(i,i)%epsilon * &
238 >            (MixingMap(i,i)%tp12 - MixingMap(i,i)%tp6)
239 >      
240 >       do j = i + 1, nATIDs
241            
242 <          ! do self mixing rule
243 <          ljMixed(i,i)%sigma   = mySigma_i
242 >          Epsilon_j = ParameterMap(j)%epsilon
243 >          Sigma_j = ParameterMap(j)%sigma
244            
245 <          ljMixed(i,i)%sigma6  = (ljMixed(i,i)%sigma) ** 6
245 >          ! only the distance parameter uses different mixing policies
246 >          if (useGeometricDistanceMixing) then
247 >             ! only for OPLS as far as we can tell
248 >             MixingMap(i,j)%sigma = dsqrt(Sigma_i * Sigma_j)
249 >          else
250 >             ! everyone else
251 >             MixingMap(i,j)%sigma = 0.5_dp * (Sigma_i + Sigma_j)
252 >          endif
253            
254 <          ljMixed(i,i)%tp6     = (ljMixed(i,i)%sigma6)/rcut6
254 >          ! energy parameter is always geometric mean:
255 >          MixingMap(i,j)%epsilon = dsqrt(Epsilon_i * Epsilon_j)
256 >                    
257 >          MixingMap(i,j)%sigma6 = (MixingMap(i,j)%sigma)**6
258 >          MixingMap(i,j)%tp6    = MixingMap(i,j)%sigma6/rcut6
259 >          MixingMap(i,j)%tp12    = (MixingMap(i,j)%tp6) ** 2
260            
261 <          ljMixed(i,i)%tp12    = (ljMixed(i,i)%tp6) ** 2
261 >          MixingMap(i,j)%delta = -4.0_DP * MixingMap(i,j)%epsilon * &
262 >               (MixingMap(i,j)%tp12 - MixingMap(i,j)%tp6)
263            
264 +          MixingMap(j,i)%sigma   = MixingMap(i,j)%sigma
265 +          MixingMap(j,i)%sigma6  = MixingMap(i,j)%sigma6
266 +          MixingMap(j,i)%tp6     = MixingMap(i,j)%tp6
267 +          MixingMap(j,i)%tp12    = MixingMap(i,j)%tp12
268 +          MixingMap(j,i)%epsilon = MixingMap(i,j)%epsilon
269 +          MixingMap(j,i)%delta   = MixingMap(i,j)%delta
270            
271 <          ljMixed(i,i)%epsilon = myEpsilon_i
216 <          
217 <          ljMixed(i,i)%delta = -4.0_DP * ljMixed(i,i)%epsilon * &
218 <            (ljMixed(i,i)%tp12 - ljMixed(i,i)%tp6)
219 <          
220 <          do j = i + 1, nAtypes
221 <
222 <                myEpsilon_j = ljParameterList%ljParams(j)%lj_epsilon
223 <                mySigma_j = ljParameterList%ljParams(j)%lj_sigma
224 <
225 <                          
226 <                ljMixed(i,j)%sigma  =  &
227 <                     calcLJMix("sigma",mySigma_i, &
228 <                     mySigma_j)
229 <                
230 <                ljMixed(i,j)%sigma6 = &
231 <                     (ljMixed(i,j)%sigma)**6
232 <                
233 <                
234 <                ljMixed(i,j)%tp6     = ljMixed(i,j)%sigma6/rcut6
235 <                
236 <                ljMixed(i,j)%tp12    = (ljMixed(i,j)%tp6) ** 2
237 <                
238 <                
239 <                ljMixed(i,j)%epsilon = &
240 <                     calcLJMix("epsilon",myEpsilon_i, &
241 <                     myEpsilon_j)
242 <                
243 <                ljMixed(i,j)%delta = -4.0_DP * ljMixed(i,j)%epsilon * &
244 <                     (ljMixed(i,j)%tp12 - ljMixed(i,j)%tp6)
245 <                
246 <                
247 <                ljMixed(j,i)%sigma   = ljMixed(i,j)%sigma
248 <                ljMixed(j,i)%sigma6  = ljMixed(i,j)%sigma6
249 <                ljMixed(j,i)%tp6     = ljMixed(i,j)%tp6
250 <                ljMixed(j,i)%tp12    = ljMixed(i,j)%tp12
251 <                ljMixed(j,i)%epsilon = ljMixed(i,j)%epsilon
252 <                ljMixed(j,i)%delta   = ljMixed(i,j)%delta
253 <          
254 <          end do
271 >       end do
272      end do
273      
274 <  end subroutine createMixingList
275 <  
274 >    haveMixingMap = .true.
275 >
276 >  end subroutine createMixingMap
277 >        
278    subroutine do_lj_pair(atom1, atom2, d, rij, r2, sw, vpair, fpair, &
279         pot, f, do_pot)
280  
# Line 277 | Line 296 | contains
296      real( kind = dp ) :: t6
297      real( kind = dp ) :: t12
298      real( kind = dp ) :: delta
299 <    integer :: id1, id2
299 >    integer :: id1, id2, localError
300  
301 +    if (.not.haveMixingMap) then
302 +       localError = 0
303 +       call createMixingMap(localError)
304 +       if ( localError .ne. 0 ) then
305 +          call handleError("LJ", "MixingMap creation failed!")
306 +          return
307 +       end if
308 +    endif
309 +
310      ! Look up the correct parameters in the mixing matrix
311   #ifdef IS_MPI
312 <    sigma6   = ljMixed(atid_Row(atom1),atid_Col(atom2))%sigma6
313 <    epsilon  = ljMixed(atid_Row(atom1),atid_Col(atom2))%epsilon
314 <    delta    = ljMixed(atid_Row(atom1),atid_Col(atom2))%delta
312 >    sigma6   = MixingMap(atid_Row(atom1),atid_Col(atom2))%sigma6
313 >    epsilon  = MixingMap(atid_Row(atom1),atid_Col(atom2))%epsilon
314 >    delta    = MixingMap(atid_Row(atom1),atid_Col(atom2))%delta
315   #else
316 <    sigma6   = ljMixed(atid(atom1),atid(atom2))%sigma6
317 <    epsilon  = ljMixed(atid(atom1),atid(atom2))%epsilon
318 <    delta    = ljMixed(atid(atom1),atid(atom2))%delta
316 >    sigma6   = MixingMap(atid(atom1),atid(atom2))%sigma6
317 >    epsilon  = MixingMap(atid(atom1),atid(atom2))%epsilon
318 >    delta    = MixingMap(atid(atom1),atid(atom2))%delta
319   #endif
320  
321      r6 = r2 * r2 * r2
# Line 361 | Line 389 | contains
389    
390    
391    !! Calculates the mixing for sigma or epslon
364  
365  function calcLJMix(thisParam,param1,param2,status) result(myMixParam)
366    character(len=*) :: thisParam
367    real(kind = dp)  :: param1
368    real(kind = dp)  :: param2
369    real(kind = dp ) :: myMixParam
370
371    integer, optional :: status  
372
373    myMixParam = 0.0_dp
392      
375    if (present(status)) status = 0
376    select case (LJ_Mixing_Policy)
377    case (1)
378       select case (thisParam)
379       case ("sigma")
380          myMixParam = 0.5_dp * (param1 + param2)
381       case ("epsilon")
382          myMixParam = sqrt(param1 * param2)
383       case default
384          status = -1
385       end select
386    case default
387       status = -1
388    end select
389  end function calcLJMix
390  
393   end module lj
392
393 subroutine newLJtype(ident,lj_sigma,lj_epsilon,status)
394    use lj, ONLY : module_newLJtype => newLJtype
395    integer, parameter :: DP = selected_real_kind(15)
396    integer,intent(inout) :: ident
397    real(kind=dp),intent(inout) :: lj_sigma
398    real(kind=dp),intent(inout) :: lj_epsilon
399    integer,intent(inout) :: status
400
401    call module_newLJtype(ident,lj_sigma,lj_epsilon,status)
402
403 end subroutine newLJtype
404

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines