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

Comparing trunk/OOPSE-4/src/UseTheForce/doForces.F90 (file contents):
Revision 1628 by gezelter, Thu Oct 21 20:15:31 2004 UTC vs.
Revision 2275 by gezelter, Fri Aug 26 16:36: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   !! doForces.F90
43   !! module doForces
44   !! Calculates Long Range forces.
45  
46   !! @author Charles F. Vardeman II
47   !! @author Matthew Meineke
48 < !! @version $Id: doForces.F90,v 1.2 2004-10-21 20:15:22 gezelter Exp $, $Date: 2004-10-21 20:15:22 $, $Name: not supported by cvs2svn $, $Revision: 1.2 $
48 > !! @version $Id: doForces.F90,v 1.31 2005-08-26 16:36:16 gezelter Exp $, $Date: 2005-08-26 16:36:16 $, $Name: not supported by cvs2svn $, $Revision: 1.31 $
49  
50 +
51   module doForces
52    use force_globals
53    use simulation
# Line 14 | Line 56 | module doForces
56    use switcheroo
57    use neighborLists  
58    use lj
59 <  use sticky_pair
60 <  use dipole_dipole
19 <  use charge_charge
59 >  use sticky
60 >  use electrostatic_module
61    use reaction_field
62    use gb_pair
63 +  use shapes
64    use vector_class
65    use eam
66    use status
# Line 31 | Line 73 | module doForces
73  
74   #define __FORTRAN90
75   #include "UseTheForce/fSwitchingFunction.h"
76 + #include "UseTheForce/fCutoffPolicy.h"
77 + #include "UseTheForce/DarkSide/fInteractionMap.h"
78  
79 +
80    INTEGER, PARAMETER:: PREPAIR_LOOP = 1
81    INTEGER, PARAMETER:: PAIR_LOOP    = 2
82  
38  logical, save :: haveRlist = .false.
83    logical, save :: haveNeighborList = .false.
84    logical, save :: haveSIMvariables = .false.
41  logical, save :: havePropertyMap = .false.
85    logical, save :: haveSaneForceField = .false.
86 <  logical, save :: FF_uses_LJ
87 <  logical, save :: FF_uses_sticky
88 <  logical, save :: FF_uses_charges
89 <  logical, save :: FF_uses_dipoles
90 <  logical, save :: FF_uses_RF
91 <  logical, save :: FF_uses_GB
86 >  logical, save :: haveInteractionHash = .false.
87 >  logical, save :: haveGtypeCutoffMap = .false.
88 >
89 >  logical, save :: FF_uses_DirectionalAtoms
90 >  logical, save :: FF_uses_Dipoles
91 >  logical, save :: FF_uses_GayBerne
92    logical, save :: FF_uses_EAM
93 <  logical, save :: SIM_uses_LJ
94 <  logical, save :: SIM_uses_sticky
95 <  logical, save :: SIM_uses_charges
53 <  logical, save :: SIM_uses_dipoles
54 <  logical, save :: SIM_uses_RF
55 <  logical, save :: SIM_uses_GB
93 >  logical, save :: FF_uses_RF
94 >
95 >  logical, save :: SIM_uses_DirectionalAtoms
96    logical, save :: SIM_uses_EAM
97 +  logical, save :: SIM_uses_RF
98    logical, save :: SIM_requires_postpair_calc
99    logical, save :: SIM_requires_prepair_calc
59  logical, save :: SIM_uses_directional_atoms
100    logical, save :: SIM_uses_PBC
61  logical, save :: SIM_uses_molecular_cutoffs
101  
63  real(kind=dp), save :: rlist, rlistsq
64
102    public :: init_FF
103 +  public :: setDefaultCutoffs
104    public :: do_force_loop
105 <  public :: setRlistDF
105 >  public :: createInteractionHash
106 >  public :: createGtypeCutoffMap
107  
108   #ifdef PROFILE
109    public :: getforcetime
# Line 72 | Line 111 | module doForces
111    real :: forceTimeInitial, forceTimeFinal
112    integer :: nLoops
113   #endif
114 +  
115 +  !! Variables for cutoff mapping and interaction mapping
116 +  ! Bit hash to determine pair-pair interactions.
117 +  integer, dimension(:,:), allocatable :: InteractionHash
118 +  real(kind=dp), dimension(:), allocatable :: atypeMaxCutoff
119 +  real(kind=dp), dimension(:), allocatable :: groupMaxCutoff
120 +  integer, dimension(:), allocatable :: groupToGtype
121 +  real(kind=dp), dimension(:), allocatable :: gtypeMaxCutoff
122 +  type ::gtypeCutoffs
123 +     real(kind=dp) :: rcut
124 +     real(kind=dp) :: rcutsq
125 +     real(kind=dp) :: rlistsq
126 +  end type gtypeCutoffs
127 +  type(gtypeCutoffs), dimension(:,:), allocatable :: gtypeCutoffMap
128  
129 <  type :: Properties
130 <     logical :: is_lj     = .false.
131 <     logical :: is_sticky = .false.
79 <     logical :: is_dp     = .false.
80 <     logical :: is_gb     = .false.
81 <     logical :: is_eam    = .false.
82 <     logical :: is_charge = .false.
83 <     real(kind=DP) :: charge = 0.0_DP
84 <     real(kind=DP) :: dipole_moment = 0.0_DP
85 <  end type Properties
86 <
87 <  type(Properties), dimension(:),allocatable :: PropertyMap
88 <
129 >  integer, save :: cutoffPolicy = TRADITIONAL_CUTOFF_POLICY
130 >  real(kind=dp),save :: defaultRcut, defaultRsw, defaultRlist
131 >  
132   contains
133  
134 <  subroutine setRlistDF( this_rlist )
92 <    
93 <    real(kind=dp) :: this_rlist
94 <
95 <    rlist = this_rlist
96 <    rlistsq = rlist * rlist
97 <    
98 <    haveRlist = .true.
99 <
100 <  end subroutine setRlistDF    
101 <
102 <  subroutine createPropertyMap(status)
134 >  subroutine createInteractionHash(status)
135      integer :: nAtypes
136 <    integer :: status
136 >    integer, intent(out) :: status
137      integer :: i
138 <    logical :: thisProperty
139 <    real (kind=DP) :: thisDPproperty
138 >    integer :: j
139 >    integer :: iHash
140 >    !! Test Types
141 >    logical :: i_is_LJ
142 >    logical :: i_is_Elect
143 >    logical :: i_is_Sticky
144 >    logical :: i_is_StickyP
145 >    logical :: i_is_GB
146 >    logical :: i_is_EAM
147 >    logical :: i_is_Shape
148 >    logical :: j_is_LJ
149 >    logical :: j_is_Elect
150 >    logical :: j_is_Sticky
151 >    logical :: j_is_StickyP
152 >    logical :: j_is_GB
153 >    logical :: j_is_EAM
154 >    logical :: j_is_Shape
155 >    real(kind=dp) :: myRcut
156  
157 <    status = 0
157 >    status = 0  
158  
159 +    if (.not. associated(atypes)) then
160 +       call handleError("atype", "atypes was not present before call of createInteractionHash!")
161 +       status = -1
162 +       return
163 +    endif
164 +    
165      nAtypes = getSize(atypes)
166 <
166 >    
167      if (nAtypes == 0) then
168         status = -1
169         return
170      end if
171 <        
172 <    if (.not. allocated(PropertyMap)) then
173 <       allocate(PropertyMap(nAtypes))
171 >
172 >    if (.not. allocated(InteractionHash)) then
173 >       allocate(InteractionHash(nAtypes,nAtypes))
174      endif
175  
176 +    if (.not. allocated(atypeMaxCutoff)) then
177 +       allocate(atypeMaxCutoff(nAtypes))
178 +    endif
179 +        
180      do i = 1, nAtypes
181 <       call getElementProperty(atypes, i, "is_LJ", thisProperty)
182 <       PropertyMap(i)%is_LJ = thisProperty
181 >       call getElementProperty(atypes, i, "is_LennardJones", i_is_LJ)
182 >       call getElementProperty(atypes, i, "is_Electrostatic", i_is_Elect)
183 >       call getElementProperty(atypes, i, "is_Sticky", i_is_Sticky)
184 >       call getElementProperty(atypes, i, "is_StickyPower", i_is_StickyP)
185 >       call getElementProperty(atypes, i, "is_GayBerne", i_is_GB)
186 >       call getElementProperty(atypes, i, "is_EAM", i_is_EAM)
187 >       call getElementProperty(atypes, i, "is_Shape", i_is_Shape)
188  
189 <       call getElementProperty(atypes, i, "is_Charge", thisProperty)
127 <       PropertyMap(i)%is_Charge = thisProperty
128 <      
129 <       if (thisProperty) then
130 <          call getElementProperty(atypes, i, "charge", thisDPproperty)
131 <          PropertyMap(i)%charge = thisDPproperty
132 <       endif
189 >       do j = i, nAtypes
190  
191 <       call getElementProperty(atypes, i, "is_DP", thisProperty)
192 <       PropertyMap(i)%is_DP = thisProperty
191 >          iHash = 0
192 >          myRcut = 0.0_dp
193  
194 <       if (thisProperty) then
195 <          call getElementProperty(atypes, i, "dipole_moment", thisDPproperty)
196 <          PropertyMap(i)%dipole_moment = thisDPproperty
197 <       endif
194 >          call getElementProperty(atypes, j, "is_LennardJones", j_is_LJ)
195 >          call getElementProperty(atypes, j, "is_Electrostatic", j_is_Elect)
196 >          call getElementProperty(atypes, j, "is_Sticky", j_is_Sticky)
197 >          call getElementProperty(atypes, j, "is_StickyPower", j_is_StickyP)
198 >          call getElementProperty(atypes, j, "is_GayBerne", j_is_GB)
199 >          call getElementProperty(atypes, j, "is_EAM", j_is_EAM)
200 >          call getElementProperty(atypes, j, "is_Shape", j_is_Shape)
201  
202 <       call getElementProperty(atypes, i, "is_Sticky", thisProperty)
203 <       PropertyMap(i)%is_Sticky = thisProperty
204 <       call getElementProperty(atypes, i, "is_GB", thisProperty)
205 <       PropertyMap(i)%is_GB = thisProperty
206 <       call getElementProperty(atypes, i, "is_EAM", thisProperty)
207 <       PropertyMap(i)%is_EAM = thisProperty
202 >          if (i_is_LJ .and. j_is_LJ) then
203 >             iHash = ior(iHash, LJ_PAIR)            
204 >          endif
205 >          
206 >          if (i_is_Elect .and. j_is_Elect) then
207 >             iHash = ior(iHash, ELECTROSTATIC_PAIR)
208 >          endif
209 >          
210 >          if (i_is_Sticky .and. j_is_Sticky) then
211 >             iHash = ior(iHash, STICKY_PAIR)
212 >          endif
213 >
214 >          if (i_is_StickyP .and. j_is_StickyP) then
215 >             iHash = ior(iHash, STICKYPOWER_PAIR)
216 >          endif
217 >
218 >          if (i_is_EAM .and. j_is_EAM) then
219 >             iHash = ior(iHash, EAM_PAIR)
220 >          endif
221 >
222 >          if (i_is_GB .and. j_is_GB) iHash = ior(iHash, GAYBERNE_PAIR)
223 >          if (i_is_GB .and. j_is_LJ) iHash = ior(iHash, GAYBERNE_LJ)
224 >          if (i_is_LJ .and. j_is_GB) iHash = ior(iHash, GAYBERNE_LJ)
225 >
226 >          if (i_is_Shape .and. j_is_Shape) iHash = ior(iHash, SHAPE_PAIR)
227 >          if (i_is_Shape .and. j_is_LJ) iHash = ior(iHash, SHAPE_LJ)
228 >          if (i_is_LJ .and. j_is_Shape) iHash = ior(iHash, SHAPE_LJ)
229 >
230 >
231 >          InteractionHash(i,j) = iHash
232 >          InteractionHash(j,i) = iHash
233 >
234 >       end do
235 >
236      end do
237  
238 <    havePropertyMap = .true.
238 >    haveInteractionHash = .true.
239 >  end subroutine createInteractionHash
240  
241 <  end subroutine createPropertyMap
241 >  subroutine createGtypeCutoffMap(stat)
242 >
243 >    integer, intent(out), optional :: stat
244 >    logical :: i_is_LJ
245 >    logical :: i_is_Elect
246 >    logical :: i_is_Sticky
247 >    logical :: i_is_StickyP
248 >    logical :: i_is_GB
249 >    logical :: i_is_EAM
250 >    logical :: i_is_Shape
251 >
252 >    integer :: myStatus, nAtypes,  i, j, istart, iend, jstart, jend
253 >    integer :: n_in_i
254 >    real(kind=dp):: thisSigma, bigSigma, thisRcut
255 >    real(kind=dp) :: biggestAtypeCutoff
256 >
257 >    stat = 0
258 >    if (.not. haveInteractionHash) then
259 >       call createInteractionHash(myStatus)      
260 >       if (myStatus .ne. 0) then
261 >          write(default_error, *) 'createInteractionHash failed in doForces!'
262 >          stat = -1
263 >          return
264 >       endif
265 >    endif
266 >
267 >    nAtypes = getSize(atypes)
268 >    
269 >    do i = 1, nAtypes
270 >       if (SimHasAtype(i)) then          
271 >          call getElementProperty(atypes, i, "is_LennardJones", i_is_LJ)
272 >          call getElementProperty(atypes, i, "is_Electrostatic", i_is_Elect)
273 >          call getElementProperty(atypes, i, "is_Sticky", i_is_Sticky)
274 >          call getElementProperty(atypes, i, "is_StickyPower", i_is_StickyP)
275 >          call getElementProperty(atypes, i, "is_GayBerne", i_is_GB)
276 >          call getElementProperty(atypes, i, "is_EAM", i_is_EAM)
277 >          call getElementProperty(atypes, i, "is_Shape", i_is_Shape)
278 >          
279 >          if (i_is_LJ) then
280 >             thisRcut = getSigma(i) * 2.5_dp
281 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
282 >          endif
283 >          if (i_is_Elect) then
284 >             thisRcut = defaultRcut
285 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
286 >          endif
287 >          if (i_is_Sticky) then
288 >             thisRcut = getStickyCut(i)
289 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
290 >          endif
291 >          if (i_is_StickyP) then
292 >             thisRcut = getStickyPowerCut(i)
293 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
294 >          endif
295 >          if (i_is_GB) then
296 >             thisRcut = getGayBerneCut(i)
297 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
298 >          endif
299 >          if (i_is_EAM) then
300 >             thisRcut = getEAMCut(i)
301 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
302 >          endif
303 >          if (i_is_Shape) then
304 >             thisRcut = getShapeCut(i)
305 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
306 >          endif
307 >          
308 >          if (atypeMaxCutoff(i).gt.biggestAtypeCutoff) then
309 >             biggestAtypeCutoff = atypeMaxCutoff(i)
310 >          endif
311 >       endif
312 >    enddo
313 >
314 >    istart = 1
315 > #ifdef IS_MPI
316 >    iend = nGroupsInRow
317 > #else
318 >    iend = nGroups
319 > #endif
320 >    outer: do i = istart, iend
321 >      
322 >       n_in_i = groupStartRow(i+1) - groupStartRow(i)
323 >      
324 > #ifdef IS_MPI
325 >       jstart = 1
326 >       jend = nGroupsInCol
327 > #else
328 >       jstart = i+1
329 >       jend = nGroups
330 > #endif
331 >      
332 >      
333 >      
334 >      
335 >      
336 >      
337 >    enddo outer        
338 >    
339 >     haveGtypeCutoffMap = .true.
340 >   end subroutine createGtypeCutoffMap
341 >
342 >   subroutine setDefaultCutoffs(defRcut, defRsw, defRlist, cutPolicy)
343 >     real(kind=dp),intent(in) :: defRcut, defRsw, defRlist
344 >     integer, intent(in) :: cutPolicy
345 >
346 >     defaultRcut = defRcut
347 >     defaultRsw = defRsw
348 >     defaultRlist = defRlist
349 >     cutoffPolicy = cutPolicy
350 >   end subroutine setDefaultCutoffs
351 >
352 >   subroutine setCutoffPolicy(cutPolicy)
353  
354 +     integer, intent(in) :: cutPolicy
355 +     cutoffPolicy = cutPolicy
356 +     call createGtypeCutoffMap()
357 +
358 +   end subroutine setCutoffPolicy
359 +    
360 +    
361    subroutine setSimVariables()
362 <    SIM_uses_LJ = SimUsesLJ()
156 <    SIM_uses_sticky = SimUsesSticky()
157 <    SIM_uses_charges = SimUsesCharges()
158 <    SIM_uses_dipoles = SimUsesDipoles()
159 <    SIM_uses_RF = SimUsesRF()
160 <    SIM_uses_GB = SimUsesGB()
362 >    SIM_uses_DirectionalAtoms = SimUsesDirectionalAtoms()
363      SIM_uses_EAM = SimUsesEAM()
364 +    SIM_uses_RF = SimUsesRF()
365      SIM_requires_postpair_calc = SimRequiresPostpairCalc()
366      SIM_requires_prepair_calc = SimRequiresPrepairCalc()
164    SIM_uses_directional_atoms = SimUsesDirectionalAtoms()
367      SIM_uses_PBC = SimUsesPBC()
166    !SIM_uses_molecular_cutoffs = SimUsesMolecularCutoffs()
368  
369      haveSIMvariables = .true.
370  
# Line 176 | Line 377 | contains
377      integer :: myStatus
378  
379      error = 0
179    
180    if (.not. havePropertyMap) then
380  
381 <       myStatus = 0
381 >    if (.not. haveInteractionHash) then      
382 >       myStatus = 0      
383 >       call createInteractionHash(myStatus)      
384 >       if (myStatus .ne. 0) then
385 >          write(default_error, *) 'createInteractionHash failed in doForces!'
386 >          error = -1
387 >          return
388 >       endif
389 >    endif
390  
391 <       call createPropertyMap(myStatus)
392 <
391 >    if (.not. haveGtypeCutoffMap) then        
392 >       myStatus = 0      
393 >       call createGtypeCutoffMap(myStatus)      
394         if (myStatus .ne. 0) then
395 <          write(default_error, *) 'createPropertyMap failed in doForces!'
395 >          write(default_error, *) 'createGtypeCutoffMap failed in doForces!'
396            error = -1
397            return
398         endif
# Line 221 | Line 429 | contains
429   #endif
430      return
431    end subroutine doReadyCheck
224    
432  
433 +
434    subroutine init_FF(use_RF_c, thisStat)
435  
436      logical, intent(in) :: use_RF_c
# Line 237 | Line 445 | contains
445  
446      !! Fortran's version of a cast:
447      FF_uses_RF = use_RF_c
448 <    
448 >
449      !! init_FF is called *after* all of the atom types have been
450      !! defined in atype_module using the new_atype subroutine.
451      !!
452      !! this will scan through the known atypes and figure out what
453      !! interactions are used by the force field.    
454 <  
455 <    FF_uses_LJ = .false.
456 <    FF_uses_sticky = .false.
457 <    FF_uses_charges = .false.
250 <    FF_uses_dipoles = .false.
251 <    FF_uses_GB = .false.
454 >
455 >    FF_uses_DirectionalAtoms = .false.
456 >    FF_uses_Dipoles = .false.
457 >    FF_uses_GayBerne = .false.
458      FF_uses_EAM = .false.
459 +
460 +    call getMatchingElementList(atypes, "is_Directional", .true., &
461 +         nMatches, MatchList)
462 +    if (nMatches .gt. 0) FF_uses_DirectionalAtoms = .true.
463 +
464 +    call getMatchingElementList(atypes, "is_Dipole", .true., &
465 +         nMatches, MatchList)
466 +    if (nMatches .gt. 0) FF_uses_Dipoles = .true.
467      
468 <    call getMatchingElementList(atypes, "is_LJ", .true., nMatches, MatchList)
469 <    if (nMatches .gt. 0) FF_uses_LJ = .true.
470 <    
471 <    call getMatchingElementList(atypes, "is_Charge", .true., nMatches, MatchList)
258 <    if (nMatches .gt. 0) FF_uses_charges = .true.  
259 <    
260 <    call getMatchingElementList(atypes, "is_DP", .true., nMatches, MatchList)
261 <    if (nMatches .gt. 0) FF_uses_dipoles = .true.
262 <    
263 <    call getMatchingElementList(atypes, "is_Sticky", .true., nMatches, &
264 <         MatchList)
265 <    if (nMatches .gt. 0) FF_uses_Sticky = .true.
266 <    
267 <    call getMatchingElementList(atypes, "is_GB", .true., nMatches, MatchList)
268 <    if (nMatches .gt. 0) FF_uses_GB = .true.
269 <    
468 >    call getMatchingElementList(atypes, "is_GayBerne", .true., &
469 >         nMatches, MatchList)
470 >    if (nMatches .gt. 0) FF_uses_GayBerne = .true.
471 >
472      call getMatchingElementList(atypes, "is_EAM", .true., nMatches, MatchList)
473      if (nMatches .gt. 0) FF_uses_EAM = .true.
474 <    
475 <    !! Assume sanity (for the sake of argument)
474 >
475 >
476      haveSaneForceField = .true.
477 <    
477 >
478      !! check to make sure the FF_uses_RF setting makes sense
479 <    
480 <    if (FF_uses_dipoles) then
479 >
480 >    if (FF_uses_Dipoles) then
481         if (FF_uses_RF) then
482            dielect = getDielect()
483            call initialize_rf(dielect)
# Line 287 | Line 489 | contains
489            haveSaneForceField = .false.
490            return
491         endif
290    endif
291
292    if (FF_uses_sticky) then
293       call check_sticky_FF(my_status)
294       if (my_status /= 0) then
295          thisStat = -1
296          haveSaneForceField = .false.
297          return
298       end if
492      endif
493  
494      if (FF_uses_EAM) then
495 <         call init_EAM_FF(my_status)
495 >       call init_EAM_FF(my_status)
496         if (my_status /= 0) then
497            write(default_error, *) "init_EAM_FF returned a bad status"
498            thisStat = -1
# Line 308 | Line 501 | contains
501         end if
502      endif
503  
504 <    if (FF_uses_GB) then
504 >    if (FF_uses_GayBerne) then
505         call check_gb_pair_FF(my_status)
506         if (my_status .ne. 0) then
507            thisStat = -1
# Line 317 | Line 510 | contains
510         endif
511      endif
512  
320    if (FF_uses_GB .and. FF_uses_LJ) then
321    endif
322
513      if (.not. haveNeighborList) then
514         !! Create neighbor lists
515         call expandNeighborList(nLocal, my_status)
# Line 329 | Line 519 | contains
519            return
520         endif
521         haveNeighborList = .true.
522 <    endif    
523 <    
522 >    endif
523 >
524    end subroutine init_FF
335  
525  
526 +
527    !! Does force loop over i,j pairs. Calls do_pair to calculates forces.
528    !------------------------------------------------------------->
529 <  subroutine do_force_loop(q, q_group, A, u_l, f, t, tau, pot, &
529 >  subroutine do_force_loop(q, q_group, A, eFrame, f, t, tau, pot, &
530         do_pot_c, do_stress_c, error)
531      !! Position array provided by C, dimensioned by getNlocal
532      real ( kind = dp ), dimension(3, nLocal) :: q
# Line 345 | Line 535 | contains
535      !! Rotation Matrix for each long range particle in simulation.
536      real( kind = dp), dimension(9, nLocal) :: A    
537      !! Unit vectors for dipoles (lab frame)
538 <    real( kind = dp ), dimension(3,nLocal) :: u_l
538 >    real( kind = dp ), dimension(9,nLocal) :: eFrame
539      !! Force array provided by C, dimensioned by getNlocal
540      real ( kind = dp ), dimension(3,nLocal) :: f
541      !! Torsion array provided by C, dimensioned by getNlocal
# Line 383 | Line 573 | contains
573      integer :: localError
574      integer :: propPack_i, propPack_j
575      integer :: loopStart, loopEnd, loop
576 <
576 >    integer :: iHash
577      real(kind=dp) :: listSkin = 1.0  
578 <    
578 >
579      !! initialize local variables  
580 <    
580 >
581   #ifdef IS_MPI
582      pot_local = 0.0_dp
583      nAtomsInRow   = getNatomsInRow(plan_atom_row)
# Line 397 | Line 587 | contains
587   #else
588      natoms = nlocal
589   #endif
590 <    
590 >
591      call doReadyCheck(localError)
592      if ( localError .ne. 0 ) then
593         call handleError("do_force_loop", "Not Initialized")
# Line 405 | Line 595 | contains
595         return
596      end if
597      call zero_work_arrays()
598 <        
598 >
599      do_pot = do_pot_c
600      do_stress = do_stress_c
601 <    
601 >
602      ! Gather all information needed by all force loops:
603 <    
603 >
604   #ifdef IS_MPI    
605 <    
605 >
606      call gather(q, q_Row, plan_atom_row_3d)
607      call gather(q, q_Col, plan_atom_col_3d)
608  
609      call gather(q_group, q_group_Row, plan_group_row_3d)
610      call gather(q_group, q_group_Col, plan_group_col_3d)
611 <        
612 <    if (FF_UsesDirectionalAtoms() .and. SIM_uses_directional_atoms) then
613 <       call gather(u_l, u_l_Row, plan_atom_row_3d)
614 <       call gather(u_l, u_l_Col, plan_atom_col_3d)
615 <      
611 >
612 >    if (FF_UsesDirectionalAtoms() .and. SIM_uses_DirectionalAtoms) then
613 >       call gather(eFrame, eFrame_Row, plan_atom_row_rotation)
614 >       call gather(eFrame, eFrame_Col, plan_atom_col_rotation)
615 >
616         call gather(A, A_Row, plan_atom_row_rotation)
617         call gather(A, A_Col, plan_atom_col_rotation)
618      endif
619 <    
619 >
620   #endif
621 <    
621 >
622      !! Begin force loop timing:
623   #ifdef PROFILE
624      call cpu_time(forceTimeInitial)
625      nloops = nloops + 1
626   #endif
627 <    
627 >
628      loopEnd = PAIR_LOOP
629      if (FF_RequiresPrepairCalc() .and. SIM_requires_prepair_calc) then
630         loopStart = PREPAIR_LOOP
# Line 449 | Line 639 | contains
639         if (loop .eq. loopStart) then
640   #ifdef IS_MPI
641            call checkNeighborList(nGroupsInRow, q_group_row, listSkin, &
642 <             update_nlist)
642 >               update_nlist)
643   #else
644            call checkNeighborList(nGroups, q_group, listSkin, &
645 <             update_nlist)
645 >               update_nlist)
646   #endif
647         endif
648 <      
648 >
649         if (update_nlist) then
650            !! save current configuration and construct neighbor list
651   #ifdef IS_MPI
# Line 466 | Line 656 | contains
656            neighborListSize = size(list)
657            nlist = 0
658         endif
659 <      
659 >
660         istart = 1
661   #ifdef IS_MPI
662         iend = nGroupsInRow
# Line 476 | Line 666 | contains
666         outer: do i = istart, iend
667  
668            if (update_nlist) point(i) = nlist + 1
669 <          
669 >
670            n_in_i = groupStartRow(i+1) - groupStartRow(i)
671 <          
671 >
672            if (update_nlist) then
673   #ifdef IS_MPI
674               jstart = 1
# Line 493 | Line 683 | contains
683               ! make sure group i has neighbors
684               if (jstart .gt. jend) cycle outer
685            endif
686 <          
686 >
687            do jnab = jstart, jend
688               if (update_nlist) then
689                  j = jnab
# Line 502 | Line 692 | contains
692               endif
693  
694   #ifdef IS_MPI
695 +             me_j = atid_col(j)
696               call get_interatomic_vector(q_group_Row(:,i), &
697                    q_group_Col(:,j), d_grp, rgrpsq)
698   #else
699 +             me_j = atid(j)
700               call get_interatomic_vector(q_group(:,i), &
701                    q_group(:,j), d_grp, rgrpsq)
702   #endif
703  
704 <             if (rgrpsq < rlistsq) then
704 >             if (rgrpsq < InteractionHash(me_i,me_j)%rListsq) then
705                  if (update_nlist) then
706                     nlist = nlist + 1
707 <                  
707 >
708                     if (nlist > neighborListSize) then
709   #ifdef IS_MPI                
710                        call expandNeighborList(nGroupsInRow, listerror)
# Line 526 | Line 718 | contains
718                        end if
719                        neighborListSize = size(list)
720                     endif
721 <                  
721 >
722                     list(nlist) = j
723                  endif
724 <                
724 >
725                  if (loop .eq. PAIR_LOOP) then
726                     vij = 0.0d0
727                     fij(1:3) = 0.0d0
728                  endif
729 <                
729 >
730                  call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, &
731                       in_switching_region)
732 <                
732 >
733                  n_in_j = groupStartCol(j+1) - groupStartCol(j)
734 <                
734 >
735                  do ia = groupStartRow(i), groupStartRow(i+1)-1
736 <                  
736 >
737                     atom1 = groupListRow(ia)
738 <                  
738 >
739                     inner: do jb = groupStartCol(j), groupStartCol(j+1)-1
740 <                      
740 >
741                        atom2 = groupListCol(jb)
742 <                      
742 >
743                        if (skipThisPair(atom1, atom2)) cycle inner
744  
745                        if ((n_in_i .eq. 1).and.(n_in_j .eq. 1)) then
# Line 567 | Line 759 | contains
759   #ifdef IS_MPI                      
760                           call do_prepair(atom1, atom2, ratmsq, d_atm, sw, &
761                                rgrpsq, d_grp, do_pot, do_stress, &
762 <                              u_l, A, f, t, pot_local)
762 >                              eFrame, A, f, t, pot_local)
763   #else
764                           call do_prepair(atom1, atom2, ratmsq, d_atm, sw, &
765                                rgrpsq, d_grp, do_pot, do_stress, &
766 <                              u_l, A, f, t, pot)
766 >                              eFrame, A, f, t, pot)
767   #endif                                              
768                        else
769   #ifdef IS_MPI                      
770                           call do_pair(atom1, atom2, ratmsq, d_atm, sw, &
771                                do_pot, &
772 <                              u_l, A, f, t, pot_local, vpair, fpair)
772 >                              eFrame, A, f, t, pot_local, vpair, fpair)
773   #else
774                           call do_pair(atom1, atom2, ratmsq, d_atm, sw, &
775                                do_pot,  &
776 <                              u_l, A, f, t, pot, vpair, fpair)
776 >                              eFrame, A, f, t, pot, vpair, fpair)
777   #endif
778  
779                           vij = vij + vpair
# Line 589 | Line 781 | contains
781                        endif
782                     enddo inner
783                  enddo
784 <                
784 >
785                  if (loop .eq. PAIR_LOOP) then
786                     if (in_switching_region) then
787                        swderiv = vij*dswdr/rgrp
788                        fij(1) = fij(1) + swderiv*d_grp(1)
789                        fij(2) = fij(2) + swderiv*d_grp(2)
790                        fij(3) = fij(3) + swderiv*d_grp(3)
791 <                      
791 >
792                        do ia=groupStartRow(i), groupStartRow(i+1)-1
793                           atom1=groupListRow(ia)
794                           mf = mfactRow(atom1)
# Line 610 | Line 802 | contains
802                           f(3,atom1) = f(3,atom1) + swderiv*d_grp(3)*mf
803   #endif
804                        enddo
805 <                      
805 >
806                        do jb=groupStartCol(j), groupStartCol(j+1)-1
807                           atom2=groupListCol(jb)
808                           mf = mfactCol(atom2)
# Line 625 | Line 817 | contains
817   #endif
818                        enddo
819                     endif
820 <                  
820 >
821                     if (do_stress) call add_stress_tensor(d_grp, fij)
822                  endif
823               end if
824            enddo
825         enddo outer
826 <      
826 >
827         if (update_nlist) then
828   #ifdef IS_MPI
829            point(nGroupsInRow + 1) = nlist + 1
# Line 645 | Line 837 | contains
837               update_nlist = .false.                              
838            endif
839         endif
840 <            
840 >
841         if (loop .eq. PREPAIR_LOOP) then
842            call do_preforce(nlocal, pot)
843         endif
844 <      
844 >
845      enddo
846 <    
846 >
847      !! Do timing
848   #ifdef PROFILE
849      call cpu_time(forceTimeFinal)
850      forceTime = forceTime + forceTimeFinal - forceTimeInitial
851   #endif    
852 <    
852 >
853   #ifdef IS_MPI
854      !!distribute forces
855 <    
855 >
856      f_temp = 0.0_dp
857      call scatter(f_Row,f_temp,plan_atom_row_3d)
858      do i = 1,nlocal
859         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
860      end do
861 <    
861 >
862      f_temp = 0.0_dp
863      call scatter(f_Col,f_temp,plan_atom_col_3d)
864      do i = 1,nlocal
865         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
866      end do
867 <    
868 <    if (FF_UsesDirectionalAtoms() .and. SIM_uses_directional_atoms) then
867 >
868 >    if (FF_UsesDirectionalAtoms() .and. SIM_uses_DirectionalAtoms) then
869         t_temp = 0.0_dp
870         call scatter(t_Row,t_temp,plan_atom_row_3d)
871         do i = 1,nlocal
# Line 681 | Line 873 | contains
873         end do
874         t_temp = 0.0_dp
875         call scatter(t_Col,t_temp,plan_atom_col_3d)
876 <      
876 >
877         do i = 1,nlocal
878            t(1:3,i) = t(1:3,i) + t_temp(1:3,i)
879         end do
880      endif
881 <    
881 >
882      if (do_pot) then
883         ! scatter/gather pot_row into the members of my column
884         call scatter(pot_Row, pot_Temp, plan_atom_row)
885 <      
885 >
886         ! scatter/gather pot_local into all other procs
887         ! add resultant to get total pot
888         do i = 1, nlocal
889            pot_local = pot_local + pot_Temp(i)
890         enddo
891 <      
891 >
892         pot_Temp = 0.0_DP
893 <      
893 >
894         call scatter(pot_Col, pot_Temp, plan_atom_col)
895         do i = 1, nlocal
896            pot_local = pot_local + pot_Temp(i)
897         enddo
898 <      
898 >
899      endif
900   #endif
901 <    
901 >
902      if (FF_RequiresPostpairCalc() .and. SIM_requires_postpair_calc) then
903 <      
903 >
904         if (FF_uses_RF .and. SIM_uses_RF) then
905 <          
905 >
906   #ifdef IS_MPI
907            call scatter(rf_Row,rf,plan_atom_row_3d)
908            call scatter(rf_Col,rf_Temp,plan_atom_col_3d)
# Line 718 | Line 910 | contains
910               rf(1:3,i) = rf(1:3,i) + rf_Temp(1:3,i)
911            end do
912   #endif
913 <          
913 >
914            do i = 1, nLocal
915 <            
915 >
916               rfpot = 0.0_DP
917   #ifdef IS_MPI
918               me_i = atid_row(i)
919   #else
920               me_i = atid(i)
921   #endif
922 +             iHash = InteractionHash(me_i,me_j)
923              
924 <             if (PropertyMap(me_i)%is_DP) then
925 <                
926 <                mu_i = PropertyMap(me_i)%dipole_moment
927 <                
924 >             if ( iand(iHash, ELECTROSTATIC_PAIR).ne.0 ) then
925 >
926 >                mu_i = getDipoleMoment(me_i)
927 >
928                  !! The reaction field needs to include a self contribution
929                  !! to the field:
930 <                call accumulate_self_rf(i, mu_i, u_l)
930 >                call accumulate_self_rf(i, mu_i, eFrame)
931                  !! Get the reaction field contribution to the
932                  !! potential and torques:
933 <                call reaction_field_final(i, mu_i, u_l, rfpot, t, do_pot)
933 >                call reaction_field_final(i, mu_i, eFrame, rfpot, t, do_pot)
934   #ifdef IS_MPI
935                  pot_local = pot_local + rfpot
936   #else
937                  pot = pot + rfpot
938 <      
938 >
939   #endif
940 <             endif            
940 >             endif
941            enddo
942         endif
943      endif
944 <    
945 <    
944 >
945 >
946   #ifdef IS_MPI
947 <    
947 >
948      if (do_pot) then
949         pot = pot + pot_local
950         !! we assume the c code will do the allreduce to get the total potential
951         !! we could do it right here if we needed to...
952      endif
953 <    
953 >
954      if (do_stress) then
955         call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, &
956              mpi_comm_world,mpi_err)
957         call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, &
958              mpi_comm_world,mpi_err)
959      endif
960 <    
960 >
961   #else
962 <    
962 >
963      if (do_stress) then
964         tau = tau_Temp
965         virial = virial_Temp
966      endif
967 <    
967 >
968   #endif
969 <      
969 >
970    end subroutine do_force_loop
971 <  
971 >
972    subroutine do_pair(i, j, rijsq, d, sw, do_pot, &
973 <       u_l, A, f, t, pot, vpair, fpair)
973 >       eFrame, A, f, t, pot, vpair, fpair)
974  
975      real( kind = dp ) :: pot, vpair, sw
976      real( kind = dp ), dimension(3) :: fpair
977      real( kind = dp ), dimension(nLocal)   :: mfact
978 <    real( kind = dp ), dimension(3,nLocal) :: u_l
978 >    real( kind = dp ), dimension(9,nLocal) :: eFrame
979      real( kind = dp ), dimension(9,nLocal) :: A
980      real( kind = dp ), dimension(3,nLocal) :: f
981      real( kind = dp ), dimension(3,nLocal) :: t
# Line 792 | Line 985 | contains
985      real ( kind = dp ), intent(inout) :: rijsq
986      real ( kind = dp )                :: r
987      real ( kind = dp ), intent(inout) :: d(3)
988 +    real ( kind = dp ) :: ebalance
989      integer :: me_i, me_j
990  
991 +    integer :: iHash
992 +
993      r = sqrt(rijsq)
994      vpair = 0.0d0
995      fpair(1:3) = 0.0d0
# Line 805 | Line 1001 | contains
1001      me_i = atid(i)
1002      me_j = atid(j)
1003   #endif
1004 <    
1005 <    if (FF_uses_LJ .and. SIM_uses_LJ) then
1006 <      
1007 <       if ( PropertyMap(me_i)%is_LJ .and. PropertyMap(me_j)%is_LJ ) then
1008 <          call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
813 <       endif
814 <      
1004 >
1005 >    iHash = InteractionHash(me_i, me_j)
1006 >
1007 >    if ( iand(iHash, LJ_PAIR).ne.0 ) then
1008 >       call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
1009      endif
1010 <    
1011 <    if (FF_uses_charges .and. SIM_uses_charges) then
1012 <      
1013 <       if (PropertyMap(me_i)%is_Charge .and. PropertyMap(me_j)%is_Charge) then
1014 <          call do_charge_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
1015 <       endif
1016 <      
1017 <    endif
1018 <    
1019 <    if (FF_uses_dipoles .and. SIM_uses_dipoles) then
826 <      
827 <       if ( PropertyMap(me_i)%is_DP .and. PropertyMap(me_j)%is_DP) then
828 <          call do_dipole_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, u_l, f, t, &
829 <               do_pot)
830 <          if (FF_uses_RF .and. SIM_uses_RF) then
831 <             call accumulate_rf(i, j, r, u_l, sw)
832 <             call rf_correct_forces(i, j, d, r, u_l, sw, f, fpair)
833 <          endif          
1010 >
1011 >    if ( iand(iHash, ELECTROSTATIC_PAIR).ne.0 ) then
1012 >       call doElectrostaticPair(i, j, d, r, rijsq, sw, vpair, fpair, &
1013 >            pot, eFrame, f, t, do_pot)
1014 >
1015 >       if (FF_uses_RF .and. SIM_uses_RF) then
1016 >
1017 >          ! CHECK ME (RF needs to know about all electrostatic types)
1018 >          call accumulate_rf(i, j, r, eFrame, sw)
1019 >          call rf_correct_forces(i, j, d, r, eFrame, sw, f, fpair)
1020         endif
1021  
1022      endif
1023  
1024 <    if (FF_uses_Sticky .and. SIM_uses_sticky) then
1024 >    if ( iand(iHash, STICKY_PAIR).ne.0 ) then
1025 >       call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1026 >            pot, A, f, t, do_pot)
1027 >    endif
1028  
1029 <       if ( PropertyMap(me_i)%is_Sticky .and. PropertyMap(me_j)%is_Sticky) then
1030 <          call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, A, f, t, &
1031 <               do_pot)
1032 <       endif
1029 >    if ( iand(iHash, STICKYPOWER_PAIR).ne.0 ) then
1030 >       call do_sticky_power_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1031 >            pot, A, f, t, do_pot)
1032 >    endif
1033  
1034 +    if ( iand(iHash, GAYBERNE_PAIR).ne.0 ) then
1035 +       call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1036 +            pot, A, f, t, do_pot)
1037      endif
1038 +    
1039 +    if ( iand(iHash, GAYBERNE_LJ).ne.0 ) then
1040 + !      call do_gblj_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1041 + !           pot, A, f, t, do_pot)
1042 +    endif
1043  
1044 +    if ( iand(iHash, EAM_PAIR).ne.0 ) then      
1045 +       call do_eam_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, &
1046 +            do_pot)
1047 +    endif
1048  
1049 <    if (FF_uses_GB .and. SIM_uses_GB) then
1050 <      
1051 <       if ( PropertyMap(me_i)%is_GB .and. PropertyMap(me_j)%is_GB) then
1052 <          call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, u_l, f, t, &
852 <               do_pot)
853 <       endif
1049 >    if ( iand(iHash, SHAPE_PAIR).ne.0 ) then      
1050 >       call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1051 >            pot, A, f, t, do_pot)
1052 >    endif
1053  
1054 +    if ( iand(iHash, SHAPE_LJ).ne.0 ) then      
1055 +       call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1056 +            pot, A, f, t, do_pot)
1057      endif
856      
857    if (FF_uses_EAM .and. SIM_uses_EAM) then
858      
859       if ( PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) then
860          call do_eam_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, &
861               do_pot)
862       endif
863      
864    endif
1058      
1059    end subroutine do_pair
1060  
1061    subroutine do_prepair(i, j, rijsq, d, sw, rcijsq, dc, &
1062 <       do_pot, do_stress, u_l, A, f, t, pot)
1062 >       do_pot, do_stress, eFrame, A, f, t, pot)
1063  
1064 <   real( kind = dp ) :: pot, sw
1065 <   real( kind = dp ), dimension(3,nLocal) :: u_l
1066 <   real (kind=dp), dimension(9,nLocal) :: A
1067 <   real (kind=dp), dimension(3,nLocal) :: f
1068 <   real (kind=dp), dimension(3,nLocal) :: t
876 <  
877 <   logical, intent(inout) :: do_pot, do_stress
878 <   integer, intent(in) :: i, j
879 <   real ( kind = dp ), intent(inout)    :: rijsq, rcijsq
880 <   real ( kind = dp )                :: r, rc
881 <   real ( kind = dp ), intent(inout) :: d(3), dc(3)
882 <  
883 <   logical :: is_EAM_i, is_EAM_j
884 <  
885 <   integer :: me_i, me_j
886 <  
1064 >    real( kind = dp ) :: pot, sw
1065 >    real( kind = dp ), dimension(9,nLocal) :: eFrame
1066 >    real (kind=dp), dimension(9,nLocal) :: A
1067 >    real (kind=dp), dimension(3,nLocal) :: f
1068 >    real (kind=dp), dimension(3,nLocal) :: t
1069  
1070 <    r = sqrt(rijsq)
1071 <    if (SIM_uses_molecular_cutoffs) then
1072 <       rc = sqrt(rcijsq)
1073 <    else
1074 <       rc = r
893 <    endif
894 <  
1070 >    logical, intent(inout) :: do_pot, do_stress
1071 >    integer, intent(in) :: i, j
1072 >    real ( kind = dp ), intent(inout)    :: rijsq, rcijsq
1073 >    real ( kind = dp )                :: r, rc
1074 >    real ( kind = dp ), intent(inout) :: d(3), dc(3)
1075  
1076 +    integer :: me_i, me_j, iHash
1077 +
1078   #ifdef IS_MPI  
1079 <   me_i = atid_row(i)
1080 <   me_j = atid_col(j)  
1079 >    me_i = atid_row(i)
1080 >    me_j = atid_col(j)  
1081   #else  
1082 <   me_i = atid(i)
1083 <   me_j = atid(j)  
1082 >    me_i = atid(i)
1083 >    me_j = atid(j)  
1084   #endif
1085 <  
1086 <   if (FF_uses_EAM .and. SIM_uses_EAM) then
1087 <      
1088 <      if (PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) &
1089 <           call calc_EAM_prepair_rho(i, j, d, r, rijsq )
1090 <      
1091 <   endif
1092 <  
1093 < end subroutine do_prepair
1094 <
1095 <
1096 < subroutine do_preforce(nlocal,pot)
1097 <   integer :: nlocal
1098 <   real( kind = dp ) :: pot
1099 <  
1100 <   if (FF_uses_EAM .and. SIM_uses_EAM) then
1101 <      call calc_EAM_preforce_Frho(nlocal,pot)
1102 <   endif
1103 <  
1104 <  
1105 < end subroutine do_preforce
1106 <
1107 <
1108 < subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
1109 <  
1110 <   real (kind = dp), dimension(3) :: q_i
1111 <   real (kind = dp), dimension(3) :: q_j
1112 <   real ( kind = dp ), intent(out) :: r_sq
1113 <   real( kind = dp ) :: d(3), scaled(3)
1114 <   integer i
1115 <  
1116 <   d(1:3) = q_j(1:3) - q_i(1:3)
1117 <  
1118 <   ! Wrap back into periodic box if necessary
1119 <   if ( SIM_uses_PBC ) then
1120 <      
1121 <      if( .not.boxIsOrthorhombic ) then
1122 <         ! calc the scaled coordinates.
1123 <        
1124 <         scaled = matmul(HmatInv, d)
1125 <        
1126 <         ! wrap the scaled coordinates
1127 <        
1128 <         scaled = scaled  - anint(scaled)
1129 <        
1130 <        
1131 <         ! calc the wrapped real coordinates from the wrapped scaled
1132 <         ! coordinates
1133 <        
1134 <         d = matmul(Hmat,scaled)
1135 <        
1136 <      else
1137 <         ! calc the scaled coordinates.
1138 <        
1139 <         do i = 1, 3
1140 <            scaled(i) = d(i) * HmatInv(i,i)
1141 <            
1142 <            ! wrap the scaled coordinates
1143 <            
1144 <            scaled(i) = scaled(i) - anint(scaled(i))
1145 <            
1146 <            ! calc the wrapped real coordinates from the wrapped scaled
1147 <            ! coordinates
1148 <            
1149 <            d(i) = scaled(i)*Hmat(i,i)
1150 <         enddo
1151 <      endif
1152 <      
1153 <   endif
1154 <  
1155 <   r_sq = dot_product(d,d)
1156 <  
1157 < end subroutine get_interatomic_vector
1158 <
1159 < subroutine zero_work_arrays()
978 <  
1085 >
1086 >    iHash = InteractionHash(me_i, me_j)
1087 >
1088 >    if ( iand(iHash, EAM_PAIR).ne.0 ) then      
1089 >            call calc_EAM_prepair_rho(i, j, d, r, rijsq )
1090 >    endif
1091 >    
1092 >  end subroutine do_prepair
1093 >
1094 >
1095 >  subroutine do_preforce(nlocal,pot)
1096 >    integer :: nlocal
1097 >    real( kind = dp ) :: pot
1098 >
1099 >    if (FF_uses_EAM .and. SIM_uses_EAM) then
1100 >       call calc_EAM_preforce_Frho(nlocal,pot)
1101 >    endif
1102 >
1103 >
1104 >  end subroutine do_preforce
1105 >
1106 >
1107 >  subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
1108 >
1109 >    real (kind = dp), dimension(3) :: q_i
1110 >    real (kind = dp), dimension(3) :: q_j
1111 >    real ( kind = dp ), intent(out) :: r_sq
1112 >    real( kind = dp ) :: d(3), scaled(3)
1113 >    integer i
1114 >
1115 >    d(1:3) = q_j(1:3) - q_i(1:3)
1116 >
1117 >    ! Wrap back into periodic box if necessary
1118 >    if ( SIM_uses_PBC ) then
1119 >
1120 >       if( .not.boxIsOrthorhombic ) then
1121 >          ! calc the scaled coordinates.
1122 >
1123 >          scaled = matmul(HmatInv, d)
1124 >
1125 >          ! wrap the scaled coordinates
1126 >
1127 >          scaled = scaled  - anint(scaled)
1128 >
1129 >
1130 >          ! calc the wrapped real coordinates from the wrapped scaled
1131 >          ! coordinates
1132 >
1133 >          d = matmul(Hmat,scaled)
1134 >
1135 >       else
1136 >          ! calc the scaled coordinates.
1137 >
1138 >          do i = 1, 3
1139 >             scaled(i) = d(i) * HmatInv(i,i)
1140 >
1141 >             ! wrap the scaled coordinates
1142 >
1143 >             scaled(i) = scaled(i) - anint(scaled(i))
1144 >
1145 >             ! calc the wrapped real coordinates from the wrapped scaled
1146 >             ! coordinates
1147 >
1148 >             d(i) = scaled(i)*Hmat(i,i)
1149 >          enddo
1150 >       endif
1151 >
1152 >    endif
1153 >
1154 >    r_sq = dot_product(d,d)
1155 >
1156 >  end subroutine get_interatomic_vector
1157 >
1158 >  subroutine zero_work_arrays()
1159 >
1160   #ifdef IS_MPI
980  
981   q_Row = 0.0_dp
982   q_Col = 0.0_dp
1161  
1162 <   q_group_Row = 0.0_dp
1163 <   q_group_Col = 0.0_dp  
1164 <  
1165 <   u_l_Row = 0.0_dp
1166 <   u_l_Col = 0.0_dp
1167 <  
1168 <   A_Row = 0.0_dp
1169 <   A_Col = 0.0_dp
1170 <  
1171 <   f_Row = 0.0_dp
1172 <   f_Col = 0.0_dp
1173 <   f_Temp = 0.0_dp
1174 <  
1175 <   t_Row = 0.0_dp
1176 <   t_Col = 0.0_dp
1177 <   t_Temp = 0.0_dp
1178 <  
1179 <   pot_Row = 0.0_dp
1180 <   pot_Col = 0.0_dp
1181 <   pot_Temp = 0.0_dp
1182 <  
1183 <   rf_Row = 0.0_dp
1184 <   rf_Col = 0.0_dp
1185 <   rf_Temp = 0.0_dp
1186 <  
1187 < #endif
1188 <
1189 <   if (FF_uses_EAM .and. SIM_uses_EAM) then
1190 <      call clean_EAM()
1191 <   endif
1192 <  
1193 <   rf = 0.0_dp
1194 <   tau_Temp = 0.0_dp
1195 <   virial_Temp = 0.0_dp
1196 < end subroutine zero_work_arrays
1197 <
1198 < function skipThisPair(atom1, atom2) result(skip_it)
1199 <   integer, intent(in) :: atom1
1200 <   integer, intent(in), optional :: atom2
1201 <   logical :: skip_it
1202 <   integer :: unique_id_1, unique_id_2
1203 <   integer :: me_i,me_j
1204 <   integer :: i
1205 <  
1206 <   skip_it = .false.
1207 <  
1208 <   !! there are a number of reasons to skip a pair or a particle
1209 <   !! mostly we do this to exclude atoms who are involved in short
1210 <   !! range interactions (bonds, bends, torsions), but we also need
1211 <   !! to exclude some overcounted interactions that result from
1212 <   !! the parallel decomposition
1213 <  
1162 >    q_Row = 0.0_dp
1163 >    q_Col = 0.0_dp
1164 >
1165 >    q_group_Row = 0.0_dp
1166 >    q_group_Col = 0.0_dp  
1167 >
1168 >    eFrame_Row = 0.0_dp
1169 >    eFrame_Col = 0.0_dp
1170 >
1171 >    A_Row = 0.0_dp
1172 >    A_Col = 0.0_dp
1173 >
1174 >    f_Row = 0.0_dp
1175 >    f_Col = 0.0_dp
1176 >    f_Temp = 0.0_dp
1177 >
1178 >    t_Row = 0.0_dp
1179 >    t_Col = 0.0_dp
1180 >    t_Temp = 0.0_dp
1181 >
1182 >    pot_Row = 0.0_dp
1183 >    pot_Col = 0.0_dp
1184 >    pot_Temp = 0.0_dp
1185 >
1186 >    rf_Row = 0.0_dp
1187 >    rf_Col = 0.0_dp
1188 >    rf_Temp = 0.0_dp
1189 >
1190 > #endif
1191 >
1192 >    if (FF_uses_EAM .and. SIM_uses_EAM) then
1193 >       call clean_EAM()
1194 >    endif
1195 >
1196 >    rf = 0.0_dp
1197 >    tau_Temp = 0.0_dp
1198 >    virial_Temp = 0.0_dp
1199 >  end subroutine zero_work_arrays
1200 >
1201 >  function skipThisPair(atom1, atom2) result(skip_it)
1202 >    integer, intent(in) :: atom1
1203 >    integer, intent(in), optional :: atom2
1204 >    logical :: skip_it
1205 >    integer :: unique_id_1, unique_id_2
1206 >    integer :: me_i,me_j
1207 >    integer :: i
1208 >
1209 >    skip_it = .false.
1210 >
1211 >    !! there are a number of reasons to skip a pair or a particle
1212 >    !! mostly we do this to exclude atoms who are involved in short
1213 >    !! range interactions (bonds, bends, torsions), but we also need
1214 >    !! to exclude some overcounted interactions that result from
1215 >    !! the parallel decomposition
1216 >
1217   #ifdef IS_MPI
1218 <   !! in MPI, we have to look up the unique IDs for each atom
1219 <   unique_id_1 = AtomRowToGlobal(atom1)
1218 >    !! in MPI, we have to look up the unique IDs for each atom
1219 >    unique_id_1 = AtomRowToGlobal(atom1)
1220   #else
1221 <   !! in the normal loop, the atom numbers are unique
1222 <   unique_id_1 = atom1
1221 >    !! in the normal loop, the atom numbers are unique
1222 >    unique_id_1 = atom1
1223   #endif
1224 <  
1225 <   !! We were called with only one atom, so just check the global exclude
1226 <   !! list for this atom
1227 <   if (.not. present(atom2)) then
1228 <      do i = 1, nExcludes_global
1229 <         if (excludesGlobal(i) == unique_id_1) then
1230 <            skip_it = .true.
1231 <            return
1232 <         end if
1233 <      end do
1234 <      return
1235 <   end if
1236 <  
1224 >
1225 >    !! We were called with only one atom, so just check the global exclude
1226 >    !! list for this atom
1227 >    if (.not. present(atom2)) then
1228 >       do i = 1, nExcludes_global
1229 >          if (excludesGlobal(i) == unique_id_1) then
1230 >             skip_it = .true.
1231 >             return
1232 >          end if
1233 >       end do
1234 >       return
1235 >    end if
1236 >
1237   #ifdef IS_MPI
1238 <   unique_id_2 = AtomColToGlobal(atom2)
1238 >    unique_id_2 = AtomColToGlobal(atom2)
1239   #else
1240 <   unique_id_2 = atom2
1240 >    unique_id_2 = atom2
1241   #endif
1242 <  
1242 >
1243   #ifdef IS_MPI
1244 <   !! this situation should only arise in MPI simulations
1245 <   if (unique_id_1 == unique_id_2) then
1246 <      skip_it = .true.
1247 <      return
1248 <   end if
1249 <  
1250 <   !! this prevents us from doing the pair on multiple processors
1251 <   if (unique_id_1 < unique_id_2) then
1252 <      if (mod(unique_id_1 + unique_id_2,2) == 0) then
1253 <         skip_it = .true.
1254 <         return
1255 <      endif
1256 <   else                
1257 <      if (mod(unique_id_1 + unique_id_2,2) == 1) then
1258 <         skip_it = .true.
1259 <         return
1260 <      endif
1261 <   endif
1244 >    !! this situation should only arise in MPI simulations
1245 >    if (unique_id_1 == unique_id_2) then
1246 >       skip_it = .true.
1247 >       return
1248 >    end if
1249 >
1250 >    !! this prevents us from doing the pair on multiple processors
1251 >    if (unique_id_1 < unique_id_2) then
1252 >       if (mod(unique_id_1 + unique_id_2,2) == 0) then
1253 >          skip_it = .true.
1254 >          return
1255 >       endif
1256 >    else                
1257 >       if (mod(unique_id_1 + unique_id_2,2) == 1) then
1258 >          skip_it = .true.
1259 >          return
1260 >       endif
1261 >    endif
1262   #endif
1263 <  
1264 <   !! the rest of these situations can happen in all simulations:
1265 <   do i = 1, nExcludes_global      
1266 <      if ((excludesGlobal(i) == unique_id_1) .or. &
1267 <           (excludesGlobal(i) == unique_id_2)) then
1268 <         skip_it = .true.
1269 <         return
1270 <      endif
1271 <   enddo
1272 <  
1273 <   do i = 1, nSkipsForAtom(atom1)
1274 <      if (skipsForAtom(atom1, i) .eq. unique_id_2) then
1275 <         skip_it = .true.
1276 <         return
1277 <      endif
1278 <   end do
1279 <  
1280 <   return
1281 < end function skipThisPair
1282 <
1283 < function FF_UsesDirectionalAtoms() result(doesit)
1284 <   logical :: doesit
1285 <   doesit = FF_uses_dipoles .or. FF_uses_sticky .or. &
1286 <        FF_uses_GB .or. FF_uses_RF
1287 < end function FF_UsesDirectionalAtoms
1288 <
1289 < function FF_RequiresPrepairCalc() result(doesit)
1290 <   logical :: doesit
1291 <   doesit = FF_uses_EAM
1292 < end function FF_RequiresPrepairCalc
1293 <
1294 < function FF_RequiresPostpairCalc() result(doesit)
1295 <   logical :: doesit
1296 <   doesit = FF_uses_RF
1297 < end function FF_RequiresPostpairCalc
1117 <
1263 >
1264 >    !! the rest of these situations can happen in all simulations:
1265 >    do i = 1, nExcludes_global      
1266 >       if ((excludesGlobal(i) == unique_id_1) .or. &
1267 >            (excludesGlobal(i) == unique_id_2)) then
1268 >          skip_it = .true.
1269 >          return
1270 >       endif
1271 >    enddo
1272 >
1273 >    do i = 1, nSkipsForAtom(atom1)
1274 >       if (skipsForAtom(atom1, i) .eq. unique_id_2) then
1275 >          skip_it = .true.
1276 >          return
1277 >       endif
1278 >    end do
1279 >
1280 >    return
1281 >  end function skipThisPair
1282 >
1283 >  function FF_UsesDirectionalAtoms() result(doesit)
1284 >    logical :: doesit
1285 >    doesit = FF_uses_DirectionalAtoms
1286 >  end function FF_UsesDirectionalAtoms
1287 >
1288 >  function FF_RequiresPrepairCalc() result(doesit)
1289 >    logical :: doesit
1290 >    doesit = FF_uses_EAM
1291 >  end function FF_RequiresPrepairCalc
1292 >
1293 >  function FF_RequiresPostpairCalc() result(doesit)
1294 >    logical :: doesit
1295 >    doesit = FF_uses_RF
1296 >  end function FF_RequiresPostpairCalc
1297 >
1298   #ifdef PROFILE
1299 < function getforcetime() result(totalforcetime)
1300 <   real(kind=dp) :: totalforcetime
1301 <   totalforcetime = forcetime
1302 < end function getforcetime
1299 >  function getforcetime() result(totalforcetime)
1300 >    real(kind=dp) :: totalforcetime
1301 >    totalforcetime = forcetime
1302 >  end function getforcetime
1303   #endif
1124
1125 !! This cleans componets of force arrays belonging only to fortran
1304  
1305 < subroutine add_stress_tensor(dpair, fpair)
1128 <  
1129 <   real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1130 <  
1131 <   ! because the d vector is the rj - ri vector, and
1132 <   ! because fx, fy, fz are the force on atom i, we need a
1133 <   ! negative sign here:  
1134 <  
1135 <   tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1136 <   tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1137 <   tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1138 <   tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1139 <   tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1140 <   tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1141 <   tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1142 <   tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1143 <   tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1144 <  
1145 <   virial_Temp = virial_Temp + &
1146 <        (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1147 <  
1148 < end subroutine add_stress_tensor
1149 <
1150 < end module doForces
1305 >  !! This cleans componets of force arrays belonging only to fortran
1306  
1307 < !! Interfaces for C programs to module....
1307 >  subroutine add_stress_tensor(dpair, fpair)
1308  
1309 < subroutine initFortranFF(use_RF_c, thisStat)
1155 <    use doForces, ONLY: init_FF
1156 <    logical, intent(in) :: use_RF_c
1309 >    real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1310  
1311 <    integer, intent(out) :: thisStat  
1312 <    call init_FF(use_RF_c, thisStat)
1311 >    ! because the d vector is the rj - ri vector, and
1312 >    ! because fx, fy, fz are the force on atom i, we need a
1313 >    ! negative sign here:  
1314  
1315 < end subroutine initFortranFF
1315 >    tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1316 >    tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1317 >    tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1318 >    tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1319 >    tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1320 >    tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1321 >    tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1322 >    tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1323 >    tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1324  
1325 <  subroutine doForceloop(q, q_group, A, u_l, f, t, tau, pot, &
1326 <       do_pot_c, do_stress_c, error)
1165 <      
1166 <       use definitions, ONLY: dp
1167 <       use simulation
1168 <       use doForces, ONLY: do_force_loop
1169 <    !! Position array provided by C, dimensioned by getNlocal
1170 <    real ( kind = dp ), dimension(3, nLocal) :: q
1171 <    !! molecular center-of-mass position array
1172 <    real ( kind = dp ), dimension(3, nGroups) :: q_group
1173 <    !! Rotation Matrix for each long range particle in simulation.
1174 <    real( kind = dp), dimension(9, nLocal) :: A    
1175 <    !! Unit vectors for dipoles (lab frame)
1176 <    real( kind = dp ), dimension(3,nLocal) :: u_l
1177 <    !! Force array provided by C, dimensioned by getNlocal
1178 <    real ( kind = dp ), dimension(3,nLocal) :: f
1179 <    !! Torsion array provided by C, dimensioned by getNlocal
1180 <    real( kind = dp ), dimension(3,nLocal) :: t    
1325 >    virial_Temp = virial_Temp + &
1326 >         (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1327  
1328 <    !! Stress Tensor
1329 <    real( kind = dp), dimension(9) :: tau  
1330 <    real ( kind = dp ) :: pot
1185 <    logical ( kind = 2) :: do_pot_c, do_stress_c
1186 <    integer :: error
1187 <    
1188 <    call do_force_loop(q, q_group, A, u_l, f, t, tau, pot, &
1189 <       do_pot_c, do_stress_c, error)
1190 <      
1191 < end subroutine doForceloop
1328 >  end subroutine add_stress_tensor
1329 >
1330 > end module doForces

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines