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 2226 by kdaily, Tue May 17 02:09:25 2005 UTC vs.
Revision 2309 by chrisfen, Sun Sep 18 20:45:38 2005 UTC

# Line 45 | Line 45
45  
46   !! @author Charles F. Vardeman II
47   !! @author Matthew Meineke
48 < !! @version $Id: doForces.F90,v 1.16 2005-05-17 02:09:06 kdaily Exp $, $Date: 2005-05-17 02:09:06 $, $Name: not supported by cvs2svn $, $Revision: 1.16 $
48 > !! @version $Id: doForces.F90,v 1.46 2005-09-18 20:45:38 chrisfen Exp $, $Date: 2005-09-18 20:45:38 $, $Name: not supported by cvs2svn $, $Revision: 1.46 $
49  
50  
51   module doForces
# Line 58 | Line 58 | module doForces
58    use lj
59    use sticky
60    use electrostatic_module
61 <  use reaction_field
61 >  use reaction_field_module
62    use gb_pair
63    use shapes
64    use vector_class
# Line 73 | 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  
80  logical, save :: haveRlist = .false.
83    logical, save :: haveNeighborList = .false.
84    logical, save :: haveSIMvariables = .false.
83  logical, save :: havePropertyMap = .false.
85    logical, save :: haveSaneForceField = .false.
86 <  
86 >  logical, save :: haveInteractionHash = .false.
87 >  logical, save :: haveGtypeCutoffMap = .false.
88 >  logical, save :: haveRlist = .false.
89 >
90    logical, save :: FF_uses_DirectionalAtoms
87  logical, save :: FF_uses_LennardJones
88  logical, save :: FF_uses_Electrostatics
89  logical, save :: FF_uses_Charges
91    logical, save :: FF_uses_Dipoles
91  logical, save :: FF_uses_Quadrupoles
92  logical, save :: FF_uses_sticky
92    logical, save :: FF_uses_GayBerne
93    logical, save :: FF_uses_EAM
95  logical, save :: FF_uses_Shapes
96  logical, save :: FF_uses_FLARB
97  logical, save :: FF_uses_RF
94  
95    logical, save :: SIM_uses_DirectionalAtoms
100  logical, save :: SIM_uses_LennardJones
101  logical, save :: SIM_uses_Electrostatics
102  logical, save :: SIM_uses_Charges
103  logical, save :: SIM_uses_Dipoles
104  logical, save :: SIM_uses_Quadrupoles
105  logical, save :: SIM_uses_Sticky
106  logical, save :: SIM_uses_GayBerne
96    logical, save :: SIM_uses_EAM
108  logical, save :: SIM_uses_Shapes
109  logical, save :: SIM_uses_FLARB
110  logical, save :: SIM_uses_RF
97    logical, save :: SIM_requires_postpair_calc
98    logical, save :: SIM_requires_prepair_calc
99    logical, save :: SIM_uses_PBC
114  logical, save :: SIM_uses_molecular_cutoffs
100  
101 <  real(kind=dp), save :: rlist, rlistsq
101 >  integer, save :: electrostaticSummationMethod
102  
103    public :: init_FF
104 +  public :: setDefaultCutoffs
105    public :: do_force_loop
106 <  public :: setRlistDF
106 >  public :: createInteractionHash
107 >  public :: createGtypeCutoffMap
108 >  public :: getStickyCut
109 >  public :: getStickyPowerCut
110 >  public :: getGayBerneCut
111 >  public :: getEAMCut
112 >  public :: getShapeCut
113  
114   #ifdef PROFILE
115    public :: getforcetime
# Line 125 | Line 117 | module doForces
117    real :: forceTimeInitial, forceTimeFinal
118    integer :: nLoops
119   #endif
120 +  
121 +  !! Variables for cutoff mapping and interaction mapping
122 +  ! Bit hash to determine pair-pair interactions.
123 +  integer, dimension(:,:), allocatable :: InteractionHash
124 +  real(kind=dp), dimension(:), allocatable :: atypeMaxCutoff
125 +  real(kind=dp), dimension(:), allocatable :: groupMaxCutoff
126 +  integer, dimension(:), allocatable :: groupToGtype
127 +  real(kind=dp), dimension(:), allocatable :: gtypeMaxCutoff
128 +  type ::gtypeCutoffs
129 +     real(kind=dp) :: rcut
130 +     real(kind=dp) :: rcutsq
131 +     real(kind=dp) :: rlistsq
132 +  end type gtypeCutoffs
133 +  type(gtypeCutoffs), dimension(:,:), allocatable :: gtypeCutoffMap
134  
135 <  type :: Properties
136 <     logical :: is_Directional   = .false.
137 <     logical :: is_LennardJones  = .false.
132 <     logical :: is_Electrostatic = .false.
133 <     logical :: is_Charge        = .false.
134 <     logical :: is_Dipole        = .false.
135 <     logical :: is_Quadrupole    = .false.
136 <     logical :: is_Sticky        = .false.
137 <     logical :: is_GayBerne      = .false.
138 <     logical :: is_EAM           = .false.
139 <     logical :: is_Shape         = .false.
140 <     logical :: is_FLARB         = .false.
141 <  end type Properties
142 <
143 <  type(Properties), dimension(:),allocatable :: PropertyMap
144 <
135 >  integer, save :: cutoffPolicy = TRADITIONAL_CUTOFF_POLICY
136 >  real(kind=dp),save :: defaultRcut, defaultRsw, defaultRlist
137 >  
138   contains
139  
140 <  subroutine setRlistDF( this_rlist )
148 <    
149 <    real(kind=dp) :: this_rlist
150 <
151 <    rlist = this_rlist
152 <    rlistsq = rlist * rlist
153 <    
154 <    haveRlist = .true.
155 <
156 <  end subroutine setRlistDF    
157 <
158 <  subroutine createPropertyMap(status)
140 >  subroutine createInteractionHash(status)
141      integer :: nAtypes
142 <    integer :: status
142 >    integer, intent(out) :: status
143      integer :: i
144 <    logical :: thisProperty
145 <    real (kind=DP) :: thisDPproperty
144 >    integer :: j
145 >    integer :: iHash
146 >    !! Test Types
147 >    logical :: i_is_LJ
148 >    logical :: i_is_Elect
149 >    logical :: i_is_Sticky
150 >    logical :: i_is_StickyP
151 >    logical :: i_is_GB
152 >    logical :: i_is_EAM
153 >    logical :: i_is_Shape
154 >    logical :: j_is_LJ
155 >    logical :: j_is_Elect
156 >    logical :: j_is_Sticky
157 >    logical :: j_is_StickyP
158 >    logical :: j_is_GB
159 >    logical :: j_is_EAM
160 >    logical :: j_is_Shape
161 >    real(kind=dp) :: myRcut
162  
163 <    status = 0
163 >    status = 0  
164  
165 +    if (.not. associated(atypes)) then
166 +       call handleError("atype", "atypes was not present before call of createInteractionHash!")
167 +       status = -1
168 +       return
169 +    endif
170 +    
171      nAtypes = getSize(atypes)
172 <
172 >    
173      if (nAtypes == 0) then
174         status = -1
175         return
176      end if
177 <        
178 <    if (.not. allocated(PropertyMap)) then
179 <       allocate(PropertyMap(nAtypes))
177 >
178 >    if (.not. allocated(InteractionHash)) then
179 >       allocate(InteractionHash(nAtypes,nAtypes))
180      endif
181  
182 +    if (.not. allocated(atypeMaxCutoff)) then
183 +       allocate(atypeMaxCutoff(nAtypes))
184 +    endif
185 +        
186      do i = 1, nAtypes
187 <       call getElementProperty(atypes, i, "is_Directional", thisProperty)
188 <       PropertyMap(i)%is_Directional = thisProperty
187 >       call getElementProperty(atypes, i, "is_LennardJones", i_is_LJ)
188 >       call getElementProperty(atypes, i, "is_Electrostatic", i_is_Elect)
189 >       call getElementProperty(atypes, i, "is_Sticky", i_is_Sticky)
190 >       call getElementProperty(atypes, i, "is_StickyPower", i_is_StickyP)
191 >       call getElementProperty(atypes, i, "is_GayBerne", i_is_GB)
192 >       call getElementProperty(atypes, i, "is_EAM", i_is_EAM)
193 >       call getElementProperty(atypes, i, "is_Shape", i_is_Shape)
194  
195 <       call getElementProperty(atypes, i, "is_LennardJones", thisProperty)
183 <       PropertyMap(i)%is_LennardJones = thisProperty
184 <      
185 <       call getElementProperty(atypes, i, "is_Electrostatic", thisProperty)
186 <       PropertyMap(i)%is_Electrostatic = thisProperty
195 >       do j = i, nAtypes
196  
197 <       call getElementProperty(atypes, i, "is_Charge", thisProperty)
198 <       PropertyMap(i)%is_Charge = thisProperty
190 <      
191 <       call getElementProperty(atypes, i, "is_Dipole", thisProperty)
192 <       PropertyMap(i)%is_Dipole = thisProperty
197 >          iHash = 0
198 >          myRcut = 0.0_dp
199  
200 <       call getElementProperty(atypes, i, "is_Quadrupole", thisProperty)
201 <       PropertyMap(i)%is_Quadrupole = thisProperty
200 >          call getElementProperty(atypes, j, "is_LennardJones", j_is_LJ)
201 >          call getElementProperty(atypes, j, "is_Electrostatic", j_is_Elect)
202 >          call getElementProperty(atypes, j, "is_Sticky", j_is_Sticky)
203 >          call getElementProperty(atypes, j, "is_StickyPower", j_is_StickyP)
204 >          call getElementProperty(atypes, j, "is_GayBerne", j_is_GB)
205 >          call getElementProperty(atypes, j, "is_EAM", j_is_EAM)
206 >          call getElementProperty(atypes, j, "is_Shape", j_is_Shape)
207  
208 <       call getElementProperty(atypes, i, "is_Sticky", thisProperty)
209 <       PropertyMap(i)%is_Sticky = thisProperty
208 >          if (i_is_LJ .and. j_is_LJ) then
209 >             iHash = ior(iHash, LJ_PAIR)            
210 >          endif
211 >          
212 >          if (i_is_Elect .and. j_is_Elect) then
213 >             iHash = ior(iHash, ELECTROSTATIC_PAIR)
214 >          endif
215 >          
216 >          if (i_is_Sticky .and. j_is_Sticky) then
217 >             iHash = ior(iHash, STICKY_PAIR)
218 >          endif
219  
220 <       call getElementProperty(atypes, i, "is_GayBerne", thisProperty)
221 <       PropertyMap(i)%is_GayBerne = thisProperty
222 <
203 <       call getElementProperty(atypes, i, "is_EAM", thisProperty)
204 <       PropertyMap(i)%is_EAM = thisProperty
220 >          if (i_is_StickyP .and. j_is_StickyP) then
221 >             iHash = ior(iHash, STICKYPOWER_PAIR)
222 >          endif
223  
224 <       call getElementProperty(atypes, i, "is_Shape", thisProperty)
225 <       PropertyMap(i)%is_Shape = thisProperty
224 >          if (i_is_EAM .and. j_is_EAM) then
225 >             iHash = ior(iHash, EAM_PAIR)
226 >          endif
227  
228 <       call getElementProperty(atypes, i, "is_FLARB", thisProperty)
229 <       PropertyMap(i)%is_FLARB = thisProperty
228 >          if (i_is_GB .and. j_is_GB) iHash = ior(iHash, GAYBERNE_PAIR)
229 >          if (i_is_GB .and. j_is_LJ) iHash = ior(iHash, GAYBERNE_LJ)
230 >          if (i_is_LJ .and. j_is_GB) iHash = ior(iHash, GAYBERNE_LJ)
231 >
232 >          if (i_is_Shape .and. j_is_Shape) iHash = ior(iHash, SHAPE_PAIR)
233 >          if (i_is_Shape .and. j_is_LJ) iHash = ior(iHash, SHAPE_LJ)
234 >          if (i_is_LJ .and. j_is_Shape) iHash = ior(iHash, SHAPE_LJ)
235 >
236 >
237 >          InteractionHash(i,j) = iHash
238 >          InteractionHash(j,i) = iHash
239 >
240 >       end do
241 >
242      end do
243  
244 <    havePropertyMap = .true.
244 >    haveInteractionHash = .true.
245 >  end subroutine createInteractionHash
246  
247 <  end subroutine createPropertyMap
247 >  subroutine createGtypeCutoffMap(stat)
248 >
249 >    integer, intent(out), optional :: stat
250 >    logical :: i_is_LJ
251 >    logical :: i_is_Elect
252 >    logical :: i_is_Sticky
253 >    logical :: i_is_StickyP
254 >    logical :: i_is_GB
255 >    logical :: i_is_EAM
256 >    logical :: i_is_Shape
257 >    logical :: GtypeFound
258 >
259 >    integer :: myStatus, nAtypes,  i, j, istart, iend, jstart, jend
260 >    integer :: n_in_i, me_i, ia, g, atom1, nGroupTypes
261 >    integer :: nGroupsInRow
262 >    real(kind=dp):: thisSigma, bigSigma, thisRcut, tol, skin
263 >    real(kind=dp) :: biggestAtypeCutoff
264 >
265 >    stat = 0
266 >    if (.not. haveInteractionHash) then
267 >       call createInteractionHash(myStatus)      
268 >       if (myStatus .ne. 0) then
269 >          write(default_error, *) 'createInteractionHash failed in doForces!'
270 >          stat = -1
271 >          return
272 >       endif
273 >    endif
274 > #ifdef IS_MPI
275 >    nGroupsInRow = getNgroupsInRow(plan_group_row)
276 > #endif
277 >    nAtypes = getSize(atypes)
278 > ! Set all of the initial cutoffs to zero.
279 >    atypeMaxCutoff = 0.0_dp
280 >    do i = 1, nAtypes
281 >       if (SimHasAtype(i)) then    
282 >          call getElementProperty(atypes, i, "is_LennardJones", i_is_LJ)
283 >          call getElementProperty(atypes, i, "is_Electrostatic", i_is_Elect)
284 >          call getElementProperty(atypes, i, "is_Sticky", i_is_Sticky)
285 >          call getElementProperty(atypes, i, "is_StickyPower", i_is_StickyP)
286 >          call getElementProperty(atypes, i, "is_GayBerne", i_is_GB)
287 >          call getElementProperty(atypes, i, "is_EAM", i_is_EAM)
288 >          call getElementProperty(atypes, i, "is_Shape", i_is_Shape)
289 >          
290 >
291 >          if (i_is_LJ) then
292 >             thisRcut = getSigma(i) * 2.5_dp
293 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
294 >          endif
295 >          if (i_is_Elect) then
296 >             thisRcut = defaultRcut
297 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
298 >          endif
299 >          if (i_is_Sticky) then
300 >             thisRcut = getStickyCut(i)
301 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
302 >          endif
303 >          if (i_is_StickyP) then
304 >             thisRcut = getStickyPowerCut(i)
305 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
306 >          endif
307 >          if (i_is_GB) then
308 >             thisRcut = getGayBerneCut(i)
309 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
310 >          endif
311 >          if (i_is_EAM) then
312 >             thisRcut = getEAMCut(i)
313 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
314 >          endif
315 >          if (i_is_Shape) then
316 >             thisRcut = getShapeCut(i)
317 >             if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
318 >          endif
319 >          
320 >          if (atypeMaxCutoff(i).gt.biggestAtypeCutoff) then
321 >             biggestAtypeCutoff = atypeMaxCutoff(i)
322 >          endif
323 >       endif
324 >    enddo
325 >  
326 >    nGroupTypes = 0
327 >    
328 >    istart = 1
329 > #ifdef IS_MPI
330 >    iend = nGroupsInRow
331 > #else
332 >    iend = nGroups
333 > #endif
334 >    
335 >    !! allocate the groupToGtype and gtypeMaxCutoff here.
336 >    if(.not.allocated(groupToGtype)) then
337 >       allocate(groupToGtype(iend))
338 >       allocate(groupMaxCutoff(iend))
339 >       allocate(gtypeMaxCutoff(iend))
340 >       groupMaxCutoff = 0.0_dp
341 >       gtypeMaxCutoff = 0.0_dp
342 >    endif
343 >    !! first we do a single loop over the cutoff groups to find the
344 >    !! largest cutoff for any atypes present in this group.  We also
345 >    !! create gtypes at this point.
346 >    
347 >    tol = 1.0d-6
348 >    
349 >    do i = istart, iend      
350 >       n_in_i = groupStartRow(i+1) - groupStartRow(i)
351 >       groupMaxCutoff(i) = 0.0_dp
352 >       do ia = groupStartRow(i), groupStartRow(i+1)-1
353 >          atom1 = groupListRow(ia)
354 > #ifdef IS_MPI
355 >          me_i = atid_row(atom1)
356 > #else
357 >          me_i = atid(atom1)
358 > #endif          
359 >          if (atypeMaxCutoff(me_i).gt.groupMaxCutoff(i)) then
360 >             groupMaxCutoff(i)=atypeMaxCutoff(me_i)
361 >          endif          
362 >       enddo
363 >
364 >       if (nGroupTypes.eq.0) then
365 >          nGroupTypes = nGroupTypes + 1
366 >          gtypeMaxCutoff(nGroupTypes) = groupMaxCutoff(i)
367 >          groupToGtype(i) = nGroupTypes
368 >       else
369 >          GtypeFound = .false.
370 >          do g = 1, nGroupTypes
371 >             if ( abs(groupMaxCutoff(i) - gtypeMaxCutoff(g)).lt.tol) then
372 >                groupToGtype(i) = g
373 >                GtypeFound = .true.
374 >             endif
375 >          enddo
376 >          if (.not.GtypeFound) then            
377 >             nGroupTypes = nGroupTypes + 1
378 >             gtypeMaxCutoff(nGroupTypes) = groupMaxCutoff(i)
379 >             groupToGtype(i) = nGroupTypes
380 >          endif
381 >       endif
382 >    enddo    
383 >
384 >    !! allocate the gtypeCutoffMap here.
385 >    allocate(gtypeCutoffMap(nGroupTypes,nGroupTypes))
386 >    !! then we do a double loop over all the group TYPES to find the cutoff
387 >    !! map between groups of two types
388 >    
389 >    do i = 1, nGroupTypes
390 >       do j = 1, nGroupTypes
391 >      
392 >          select case(cutoffPolicy)
393 >          case(TRADITIONAL_CUTOFF_POLICY)
394 >             thisRcut = maxval(gtypeMaxCutoff)
395 >          case(MIX_CUTOFF_POLICY)
396 >             thisRcut = 0.5_dp * (gtypeMaxCutoff(i) + gtypeMaxCutoff(j))
397 >          case(MAX_CUTOFF_POLICY)
398 >             thisRcut = max(gtypeMaxCutoff(i), gtypeMaxCutoff(j))
399 >          case default
400 >             call handleError("createGtypeCutoffMap", "Unknown Cutoff Policy")
401 >             return
402 >          end select
403 >          gtypeCutoffMap(i,j)%rcut = thisRcut
404 >          gtypeCutoffMap(i,j)%rcutsq = thisRcut*thisRcut
405 >          skin = defaultRlist - defaultRcut
406 >          gtypeCutoffMap(i,j)%rlistsq = (thisRcut + skin)**2
407  
408 +       enddo
409 +    enddo
410 +    
411 +    haveGtypeCutoffMap = .true.
412 +   end subroutine createGtypeCutoffMap
413 +
414 +   subroutine setDefaultCutoffs(defRcut, defRsw, defRlist, cutPolicy)
415 +     real(kind=dp),intent(in) :: defRcut, defRsw, defRlist
416 +     integer, intent(in) :: cutPolicy
417 +
418 +     defaultRcut = defRcut
419 +     defaultRsw = defRsw
420 +     defaultRlist = defRlist
421 +     cutoffPolicy = cutPolicy
422 +   end subroutine setDefaultCutoffs
423 +
424 +   subroutine setCutoffPolicy(cutPolicy)
425 +
426 +     integer, intent(in) :: cutPolicy
427 +     cutoffPolicy = cutPolicy
428 +     call createGtypeCutoffMap()
429 +   end subroutine setCutoffPolicy
430 +    
431 +    
432    subroutine setSimVariables()
433      SIM_uses_DirectionalAtoms = SimUsesDirectionalAtoms()
219    SIM_uses_LennardJones = SimUsesLennardJones()
220    SIM_uses_Electrostatics = SimUsesElectrostatics()
221    SIM_uses_Charges = SimUsesCharges()
222    SIM_uses_Dipoles = SimUsesDipoles()
223    SIM_uses_Sticky = SimUsesSticky()
224    SIM_uses_GayBerne = SimUsesGayBerne()
434      SIM_uses_EAM = SimUsesEAM()
226    SIM_uses_Shapes = SimUsesShapes()
227    SIM_uses_FLARB = SimUsesFLARB()
228    SIM_uses_RF = SimUsesRF()
435      SIM_requires_postpair_calc = SimRequiresPostpairCalc()
436      SIM_requires_prepair_calc = SimRequiresPrepairCalc()
437      SIM_uses_PBC = SimUsesPBC()
# Line 241 | Line 447 | contains
447      integer :: myStatus
448  
449      error = 0
244    
245    if (.not. havePropertyMap) then
450  
451 <       myStatus = 0
451 >    if (.not. haveInteractionHash) then      
452 >       myStatus = 0      
453 >       call createInteractionHash(myStatus)      
454 >       if (myStatus .ne. 0) then
455 >          write(default_error, *) 'createInteractionHash failed in doForces!'
456 >          error = -1
457 >          return
458 >       endif
459 >    endif
460  
461 <       call createPropertyMap(myStatus)
462 <
461 >    if (.not. haveGtypeCutoffMap) then        
462 >       myStatus = 0      
463 >       call createGtypeCutoffMap(myStatus)      
464         if (myStatus .ne. 0) then
465 <          write(default_error, *) 'createPropertyMap failed in doForces!'
465 >          write(default_error, *) 'createGtypeCutoffMap failed in doForces!'
466            error = -1
467            return
468         endif
# Line 259 | Line 472 | contains
472         call setSimVariables()
473      endif
474  
475 <    if (.not. haveRlist) then
476 <       write(default_error, *) 'rList has not been set in doForces!'
477 <       error = -1
478 <       return
479 <    endif
475 >  !  if (.not. haveRlist) then
476 >  !     write(default_error, *) 'rList has not been set in doForces!'
477 >  !     error = -1
478 >  !     return
479 >  !  endif
480  
481      if (.not. haveNeighborList) then
482         write(default_error, *) 'neighbor list has not been initialized in doForces!'
# Line 286 | Line 499 | contains
499   #endif
500      return
501    end subroutine doReadyCheck
289    
502  
291  subroutine init_FF(use_RF_c, thisStat)
503  
504 <    logical, intent(in) :: use_RF_c
504 >  subroutine init_FF(thisESM, thisStat)
505  
506 +    integer, intent(in) :: thisESM
507 +    real(kind=dp), intent(in) :: dampingAlpha
508      integer, intent(out) :: thisStat  
509      integer :: my_status, nMatches
510      integer, pointer :: MatchList(:) => null()
# Line 300 | Line 513 | contains
513      !! assume things are copacetic, unless they aren't
514      thisStat = 0
515  
516 <    !! Fortran's version of a cast:
517 <    FF_uses_RF = use_RF_c
305 <    
516 >    electrostaticSummationMethod = thisESM
517 >
518      !! init_FF is called *after* all of the atom types have been
519      !! defined in atype_module using the new_atype subroutine.
520      !!
521      !! this will scan through the known atypes and figure out what
522      !! interactions are used by the force field.    
523 <  
523 >
524      FF_uses_DirectionalAtoms = .false.
313    FF_uses_LennardJones = .false.
314    FF_uses_Electrostatics = .false.
315    FF_uses_Charges = .false.    
525      FF_uses_Dipoles = .false.
317    FF_uses_Sticky = .false.
526      FF_uses_GayBerne = .false.
527      FF_uses_EAM = .false.
528 <    FF_uses_Shapes = .false.
321 <    FF_uses_FLARB = .false.
322 <    
528 >
529      call getMatchingElementList(atypes, "is_Directional", .true., &
530           nMatches, MatchList)
531      if (nMatches .gt. 0) FF_uses_DirectionalAtoms = .true.
532  
327    call getMatchingElementList(atypes, "is_LennardJones", .true., &
328         nMatches, MatchList)
329    if (nMatches .gt. 0) FF_uses_LennardJones = .true.
330    
331    call getMatchingElementList(atypes, "is_Electrostatic", .true., &
332         nMatches, MatchList)
333    if (nMatches .gt. 0) then
334       FF_uses_Electrostatics = .true.
335    endif
336
337    call getMatchingElementList(atypes, "is_Charge", .true., &
338         nMatches, MatchList)
339    if (nMatches .gt. 0) then
340       FF_uses_Charges = .true.  
341       FF_uses_Electrostatics = .true.
342    endif
343    
533      call getMatchingElementList(atypes, "is_Dipole", .true., &
534           nMatches, MatchList)
535 <    if (nMatches .gt. 0) then
347 <       FF_uses_Dipoles = .true.
348 <       FF_uses_Electrostatics = .true.
349 <       FF_uses_DirectionalAtoms = .true.
350 <    endif
351 <
352 <    call getMatchingElementList(atypes, "is_Quadrupole", .true., &
353 <         nMatches, MatchList)
354 <    if (nMatches .gt. 0) then
355 <       FF_uses_Quadrupoles = .true.
356 <       FF_uses_Electrostatics = .true.
357 <       FF_uses_DirectionalAtoms = .true.
358 <    endif
535 >    if (nMatches .gt. 0) FF_uses_Dipoles = .true.
536      
360    call getMatchingElementList(atypes, "is_Sticky", .true., nMatches, &
361         MatchList)
362    if (nMatches .gt. 0) then
363       FF_uses_Sticky = .true.
364       FF_uses_DirectionalAtoms = .true.
365    endif
366    
537      call getMatchingElementList(atypes, "is_GayBerne", .true., &
538           nMatches, MatchList)
539 <    if (nMatches .gt. 0) then
540 <       FF_uses_GayBerne = .true.
371 <       FF_uses_DirectionalAtoms = .true.
372 <    endif
373 <    
539 >    if (nMatches .gt. 0) FF_uses_GayBerne = .true.
540 >
541      call getMatchingElementList(atypes, "is_EAM", .true., nMatches, MatchList)
542      if (nMatches .gt. 0) FF_uses_EAM = .true.
376    
377    call getMatchingElementList(atypes, "is_Shape", .true., &
378         nMatches, MatchList)
379    if (nMatches .gt. 0) then
380       FF_uses_Shapes = .true.
381       FF_uses_DirectionalAtoms = .true.
382    endif
543  
384    call getMatchingElementList(atypes, "is_FLARB", .true., &
385         nMatches, MatchList)
386    if (nMatches .gt. 0) FF_uses_FLARB = .true.
544  
388    !! Assume sanity (for the sake of argument)
545      haveSaneForceField = .true.
546 <    
547 <    !! check to make sure the FF_uses_RF setting makes sense
548 <    
549 <    if (FF_uses_dipoles) then
550 <       if (FF_uses_RF) then
546 >
547 >    !! check to make sure the reaction field setting makes sense
548 >
549 >    if (FF_uses_Dipoles) then
550 >       if (electrostaticSummationMethod == 3) then
551            dielect = getDielect()
552            call initialize_rf(dielect)
553         endif
554      else
555 <       if (FF_uses_RF) then          
555 >       if (electrostaticSummationMethod == 3) then
556            write(default_error,*) 'Using Reaction Field with no dipoles?  Huh?'
557            thisStat = -1
558            haveSaneForceField = .false.
559            return
560         endif
561 <    endif
561 >    endif
562  
407    !sticky module does not contain check_sticky_FF anymore
408    !if (FF_uses_sticky) then
409    !   call check_sticky_FF(my_status)
410    !   if (my_status /= 0) then
411    !      thisStat = -1
412    !      haveSaneForceField = .false.
413    !      return
414    !   end if
415    !endif
416
563      if (FF_uses_EAM) then
564 <         call init_EAM_FF(my_status)
564 >       call init_EAM_FF(my_status)
565         if (my_status /= 0) then
566            write(default_error, *) "init_EAM_FF returned a bad status"
567            thisStat = -1
# Line 433 | Line 579 | contains
579         endif
580      endif
581  
436    if (FF_uses_GayBerne .and. FF_uses_LennardJones) then
437    endif
438    
582      if (.not. haveNeighborList) then
583         !! Create neighbor lists
584         call expandNeighborList(nLocal, my_status)
# Line 445 | Line 588 | contains
588            return
589         endif
590         haveNeighborList = .true.
591 <    endif    
592 <    
591 >    endif
592 >
593    end subroutine init_FF
451  
594  
595 +
596    !! Does force loop over i,j pairs. Calls do_pair to calculates forces.
597    !------------------------------------------------------------->
598    subroutine do_force_loop(q, q_group, A, eFrame, f, t, tau, pot, &
# Line 499 | Line 642 | contains
642      integer :: localError
643      integer :: propPack_i, propPack_j
644      integer :: loopStart, loopEnd, loop
645 <
645 >    integer :: iHash
646      real(kind=dp) :: listSkin = 1.0  
647 <    
647 >
648      !! initialize local variables  
649 <    
649 >
650   #ifdef IS_MPI
651      pot_local = 0.0_dp
652      nAtomsInRow   = getNatomsInRow(plan_atom_row)
# Line 513 | Line 656 | contains
656   #else
657      natoms = nlocal
658   #endif
659 <    
659 >
660      call doReadyCheck(localError)
661      if ( localError .ne. 0 ) then
662         call handleError("do_force_loop", "Not Initialized")
# Line 521 | Line 664 | contains
664         return
665      end if
666      call zero_work_arrays()
667 <        
667 >
668      do_pot = do_pot_c
669      do_stress = do_stress_c
670 <    
670 >
671      ! Gather all information needed by all force loops:
672 <    
672 >
673   #ifdef IS_MPI    
674 <    
674 >
675      call gather(q, q_Row, plan_atom_row_3d)
676      call gather(q, q_Col, plan_atom_col_3d)
677  
678      call gather(q_group, q_group_Row, plan_group_row_3d)
679      call gather(q_group, q_group_Col, plan_group_col_3d)
680 <        
680 >
681      if (FF_UsesDirectionalAtoms() .and. SIM_uses_DirectionalAtoms) then
682         call gather(eFrame, eFrame_Row, plan_atom_row_rotation)
683         call gather(eFrame, eFrame_Col, plan_atom_col_rotation)
684 <      
684 >
685         call gather(A, A_Row, plan_atom_row_rotation)
686         call gather(A, A_Col, plan_atom_col_rotation)
687      endif
688 <    
688 >
689   #endif
690 <    
690 >
691      !! Begin force loop timing:
692   #ifdef PROFILE
693      call cpu_time(forceTimeInitial)
694      nloops = nloops + 1
695   #endif
696 <    
696 >
697      loopEnd = PAIR_LOOP
698      if (FF_RequiresPrepairCalc() .and. SIM_requires_prepair_calc) then
699         loopStart = PREPAIR_LOOP
# Line 565 | Line 708 | contains
708         if (loop .eq. loopStart) then
709   #ifdef IS_MPI
710            call checkNeighborList(nGroupsInRow, q_group_row, listSkin, &
711 <             update_nlist)
711 >               update_nlist)
712   #else
713            call checkNeighborList(nGroups, q_group, listSkin, &
714 <             update_nlist)
714 >               update_nlist)
715   #endif
716         endif
717 <      
717 >
718         if (update_nlist) then
719            !! save current configuration and construct neighbor list
720   #ifdef IS_MPI
# Line 582 | Line 725 | contains
725            neighborListSize = size(list)
726            nlist = 0
727         endif
728 <      
728 >
729         istart = 1
730   #ifdef IS_MPI
731         iend = nGroupsInRow
# Line 592 | Line 735 | contains
735         outer: do i = istart, iend
736  
737            if (update_nlist) point(i) = nlist + 1
738 <          
738 >
739            n_in_i = groupStartRow(i+1) - groupStartRow(i)
740 <          
740 >
741            if (update_nlist) then
742   #ifdef IS_MPI
743               jstart = 1
# Line 609 | Line 752 | contains
752               ! make sure group i has neighbors
753               if (jstart .gt. jend) cycle outer
754            endif
755 <          
755 >
756            do jnab = jstart, jend
757               if (update_nlist) then
758                  j = jnab
# Line 618 | Line 761 | contains
761               endif
762  
763   #ifdef IS_MPI
764 +             me_j = atid_col(j)
765               call get_interatomic_vector(q_group_Row(:,i), &
766                    q_group_Col(:,j), d_grp, rgrpsq)
767   #else
768 +             me_j = atid(j)
769               call get_interatomic_vector(q_group(:,i), &
770                    q_group(:,j), d_grp, rgrpsq)
771   #endif
772  
773 <             if (rgrpsq < rlistsq) then
773 >             if (rgrpsq < gtypeCutoffMap(groupToGtype(i),groupToGtype(j))%rListsq) then
774                  if (update_nlist) then
775                     nlist = nlist + 1
776 <                  
776 >
777                     if (nlist > neighborListSize) then
778   #ifdef IS_MPI                
779                        call expandNeighborList(nGroupsInRow, listerror)
# Line 642 | Line 787 | contains
787                        end if
788                        neighborListSize = size(list)
789                     endif
790 <                  
790 >
791                     list(nlist) = j
792                  endif
793 <                
793 >
794                  if (loop .eq. PAIR_LOOP) then
795                     vij = 0.0d0
796                     fij(1:3) = 0.0d0
797                  endif
798 <                
798 >
799                  call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, &
800                       in_switching_region)
801 <                
801 >
802                  n_in_j = groupStartCol(j+1) - groupStartCol(j)
803 <                
803 >
804                  do ia = groupStartRow(i), groupStartRow(i+1)-1
805 <                  
805 >
806                     atom1 = groupListRow(ia)
807 <                  
807 >
808                     inner: do jb = groupStartCol(j), groupStartCol(j+1)-1
809 <                      
809 >
810                        atom2 = groupListCol(jb)
811 <                      
811 >
812                        if (skipThisPair(atom1, atom2)) cycle inner
813  
814                        if ((n_in_i .eq. 1).and.(n_in_j .eq. 1)) then
# Line 705 | Line 850 | contains
850                        endif
851                     enddo inner
852                  enddo
853 <                
853 >
854                  if (loop .eq. PAIR_LOOP) then
855                     if (in_switching_region) then
856                        swderiv = vij*dswdr/rgrp
857                        fij(1) = fij(1) + swderiv*d_grp(1)
858                        fij(2) = fij(2) + swderiv*d_grp(2)
859                        fij(3) = fij(3) + swderiv*d_grp(3)
860 <                      
860 >
861                        do ia=groupStartRow(i), groupStartRow(i+1)-1
862                           atom1=groupListRow(ia)
863                           mf = mfactRow(atom1)
# Line 726 | Line 871 | contains
871                           f(3,atom1) = f(3,atom1) + swderiv*d_grp(3)*mf
872   #endif
873                        enddo
874 <                      
874 >
875                        do jb=groupStartCol(j), groupStartCol(j+1)-1
876                           atom2=groupListCol(jb)
877                           mf = mfactCol(atom2)
# Line 741 | Line 886 | contains
886   #endif
887                        enddo
888                     endif
889 <                  
889 >
890                     if (do_stress) call add_stress_tensor(d_grp, fij)
891                  endif
892               end if
893            enddo
894         enddo outer
895 <      
895 >
896         if (update_nlist) then
897   #ifdef IS_MPI
898            point(nGroupsInRow + 1) = nlist + 1
# Line 761 | Line 906 | contains
906               update_nlist = .false.                              
907            endif
908         endif
909 <            
909 >
910         if (loop .eq. PREPAIR_LOOP) then
911            call do_preforce(nlocal, pot)
912         endif
913 <      
913 >
914      enddo
915 <    
915 >
916      !! Do timing
917   #ifdef PROFILE
918      call cpu_time(forceTimeFinal)
919      forceTime = forceTime + forceTimeFinal - forceTimeInitial
920   #endif    
921 <    
921 >
922   #ifdef IS_MPI
923      !!distribute forces
924 <    
924 >
925      f_temp = 0.0_dp
926      call scatter(f_Row,f_temp,plan_atom_row_3d)
927      do i = 1,nlocal
928         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
929      end do
930 <    
930 >
931      f_temp = 0.0_dp
932      call scatter(f_Col,f_temp,plan_atom_col_3d)
933      do i = 1,nlocal
934         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
935      end do
936 <    
936 >
937      if (FF_UsesDirectionalAtoms() .and. SIM_uses_DirectionalAtoms) then
938         t_temp = 0.0_dp
939         call scatter(t_Row,t_temp,plan_atom_row_3d)
# Line 797 | Line 942 | contains
942         end do
943         t_temp = 0.0_dp
944         call scatter(t_Col,t_temp,plan_atom_col_3d)
945 <      
945 >
946         do i = 1,nlocal
947            t(1:3,i) = t(1:3,i) + t_temp(1:3,i)
948         end do
949      endif
950 <    
950 >
951      if (do_pot) then
952         ! scatter/gather pot_row into the members of my column
953         call scatter(pot_Row, pot_Temp, plan_atom_row)
954 <      
954 >
955         ! scatter/gather pot_local into all other procs
956         ! add resultant to get total pot
957         do i = 1, nlocal
958            pot_local = pot_local + pot_Temp(i)
959         enddo
960 <      
960 >
961         pot_Temp = 0.0_DP
962 <      
962 >
963         call scatter(pot_Col, pot_Temp, plan_atom_col)
964         do i = 1, nlocal
965            pot_local = pot_local + pot_Temp(i)
966         enddo
967 <      
967 >
968      endif
969   #endif
970 <    
970 >
971      if (FF_RequiresPostpairCalc() .and. SIM_requires_postpair_calc) then
972 <      
973 <       if (FF_uses_RF .and. SIM_uses_RF) then
974 <          
972 >
973 >       if (electrostaticSummationMethod == 3) then
974 >
975   #ifdef IS_MPI
976            call scatter(rf_Row,rf,plan_atom_row_3d)
977            call scatter(rf_Col,rf_Temp,plan_atom_col_3d)
# Line 834 | Line 979 | contains
979               rf(1:3,i) = rf(1:3,i) + rf_Temp(1:3,i)
980            end do
981   #endif
982 <          
982 >
983            do i = 1, nLocal
984 <            
984 >
985               rfpot = 0.0_DP
986   #ifdef IS_MPI
987               me_i = atid_row(i)
988   #else
989               me_i = atid(i)
990   #endif
991 +             iHash = InteractionHash(me_i,me_j)
992              
993 <             if (PropertyMap(me_i)%is_Dipole) then
994 <                
993 >             if ( iand(iHash, ELECTROSTATIC_PAIR).ne.0 ) then
994 >
995                  mu_i = getDipoleMoment(me_i)
996 <    
996 >
997                  !! The reaction field needs to include a self contribution
998                  !! to the field:
999                  call accumulate_self_rf(i, mu_i, eFrame)
# Line 858 | Line 1004 | contains
1004                  pot_local = pot_local + rfpot
1005   #else
1006                  pot = pot + rfpot
1007 <      
1007 >
1008   #endif
1009 <             endif            
1009 >             endif
1010            enddo
1011         endif
1012      endif
1013 <    
1014 <    
1013 >
1014 >
1015   #ifdef IS_MPI
1016 <    
1016 >
1017      if (do_pot) then
1018         pot = pot + pot_local
1019         !! we assume the c code will do the allreduce to get the total potential
1020         !! we could do it right here if we needed to...
1021      endif
1022 <    
1022 >
1023      if (do_stress) then
1024         call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, &
1025              mpi_comm_world,mpi_err)
1026         call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, &
1027              mpi_comm_world,mpi_err)
1028      endif
1029 <    
1029 >
1030   #else
1031 <    
1031 >
1032      if (do_stress) then
1033         tau = tau_Temp
1034         virial = virial_Temp
1035      endif
1036 <    
1036 >
1037   #endif
1038 <      
1038 >
1039    end subroutine do_force_loop
1040 <  
1040 >
1041    subroutine do_pair(i, j, rijsq, d, sw, do_pot, &
1042         eFrame, A, f, t, pot, vpair, fpair)
1043  
# Line 910 | Line 1056 | contains
1056      real ( kind = dp ), intent(inout) :: d(3)
1057      integer :: me_i, me_j
1058  
1059 +    integer :: iHash
1060 +
1061      r = sqrt(rijsq)
1062      vpair = 0.0d0
1063      fpair(1:3) = 0.0d0
# Line 922 | Line 1070 | contains
1070      me_j = atid(j)
1071   #endif
1072  
1073 < !    write(*,*) i, j, me_i, me_j
1074 <    
1075 <    if (FF_uses_LennardJones .and. SIM_uses_LennardJones) then
1076 <      
929 <       if ( PropertyMap(me_i)%is_LennardJones .and. &
930 <            PropertyMap(me_j)%is_LennardJones ) then
931 <          call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
932 <       endif
933 <      
1073 >    iHash = InteractionHash(me_i, me_j)
1074 >
1075 >    if ( iand(iHash, LJ_PAIR).ne.0 ) then
1076 >       call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
1077      endif
935    
936    if (FF_uses_Electrostatics .and. SIM_uses_Electrostatics) then
937      
938       if (PropertyMap(me_i)%is_Electrostatic .and. &
939            PropertyMap(me_j)%is_Electrostatic) then
940          call doElectrostaticPair(i, j, d, r, rijsq, sw, vpair, fpair, &
941               pot, eFrame, f, t, do_pot)
942       endif
943      
944       if (FF_uses_dipoles .and. SIM_uses_dipoles) then      
945          if ( PropertyMap(me_i)%is_Dipole .and. &
946               PropertyMap(me_j)%is_Dipole) then
947             if (FF_uses_RF .and. SIM_uses_RF) then
948                call accumulate_rf(i, j, r, eFrame, sw)
949                call rf_correct_forces(i, j, d, r, eFrame, sw, f, fpair)
950             endif
951          endif
952       endif
953    endif
1078  
1079 +    if ( iand(iHash, ELECTROSTATIC_PAIR).ne.0 ) then
1080 +       call doElectrostaticPair(i, j, d, r, rijsq, sw, vpair, fpair, &
1081 +            pot, eFrame, f, t, do_pot)
1082  
1083 <    if (FF_uses_Sticky .and. SIM_uses_sticky) then
1083 >       if (electrostaticSummationMethod == 3) then
1084  
1085 <       if ( PropertyMap(me_i)%is_Sticky .and. PropertyMap(me_j)%is_Sticky) then
1086 <          call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1087 <               pot, A, f, t, do_pot)
1085 >          ! CHECK ME (RF needs to know about all electrostatic types)
1086 >          call accumulate_rf(i, j, r, eFrame, sw)
1087 >          call rf_correct_forces(i, j, d, r, eFrame, sw, f, fpair)
1088         endif
1089 <      
1089 >
1090      endif
1091  
1092 +    if ( iand(iHash, STICKY_PAIR).ne.0 ) then
1093 +       call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1094 +            pot, A, f, t, do_pot)
1095 +    endif
1096  
1097 <    if (FF_uses_GayBerne .and. SIM_uses_GayBerne) then
1098 <      
1099 <       if ( PropertyMap(me_i)%is_GayBerne .and. &
969 <            PropertyMap(me_j)%is_GayBerne) then
970 <          call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
971 <               pot, A, f, t, do_pot)
972 <       endif
973 <      
1097 >    if ( iand(iHash, STICKYPOWER_PAIR).ne.0 ) then
1098 >       call do_sticky_power_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1099 >            pot, A, f, t, do_pot)
1100      endif
1101 +
1102 +    if ( iand(iHash, GAYBERNE_PAIR).ne.0 ) then
1103 +       call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1104 +            pot, A, f, t, do_pot)
1105 +    endif
1106      
1107 <    if (FF_uses_EAM .and. SIM_uses_EAM) then
1108 <      
1109 <       if ( PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) then
979 <          call do_eam_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, &
980 <               do_pot)
981 <       endif
982 <      
1107 >    if ( iand(iHash, GAYBERNE_LJ).ne.0 ) then
1108 > !      call do_gblj_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1109 > !           pot, A, f, t, do_pot)
1110      endif
1111  
1112 +    if ( iand(iHash, EAM_PAIR).ne.0 ) then      
1113 +       call do_eam_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, &
1114 +            do_pot)
1115 +    endif
1116  
1117 < !    write(*,*) PropertyMap(me_i)%is_Shape,PropertyMap(me_j)%is_Shape
1117 >    if ( iand(iHash, SHAPE_PAIR).ne.0 ) then      
1118 >       call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1119 >            pot, A, f, t, do_pot)
1120 >    endif
1121  
1122 <    if (FF_uses_Shapes .and. SIM_uses_Shapes) then
1123 <       if ( PropertyMap(me_i)%is_Shape .and. &
1124 <            PropertyMap(me_j)%is_Shape ) then
991 <          call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
992 <               pot, A, f, t, do_pot)
993 <       endif
994 <      
1122 >    if ( iand(iHash, SHAPE_LJ).ne.0 ) then      
1123 >       call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1124 >            pot, A, f, t, do_pot)
1125      endif
1126      
1127    end subroutine do_pair
# Line 999 | Line 1129 | contains
1129    subroutine do_prepair(i, j, rijsq, d, sw, rcijsq, dc, &
1130         do_pot, do_stress, eFrame, A, f, t, pot)
1131  
1132 <   real( kind = dp ) :: pot, sw
1133 <   real( kind = dp ), dimension(9,nLocal) :: eFrame
1134 <   real (kind=dp), dimension(9,nLocal) :: A
1135 <   real (kind=dp), dimension(3,nLocal) :: f
1136 <   real (kind=dp), dimension(3,nLocal) :: t
1007 <  
1008 <   logical, intent(inout) :: do_pot, do_stress
1009 <   integer, intent(in) :: i, j
1010 <   real ( kind = dp ), intent(inout)    :: rijsq, rcijsq
1011 <   real ( kind = dp )                :: r, rc
1012 <   real ( kind = dp ), intent(inout) :: d(3), dc(3)
1013 <  
1014 <   logical :: is_EAM_i, is_EAM_j
1015 <  
1016 <   integer :: me_i, me_j
1017 <  
1132 >    real( kind = dp ) :: pot, sw
1133 >    real( kind = dp ), dimension(9,nLocal) :: eFrame
1134 >    real (kind=dp), dimension(9,nLocal) :: A
1135 >    real (kind=dp), dimension(3,nLocal) :: f
1136 >    real (kind=dp), dimension(3,nLocal) :: t
1137  
1138 +    logical, intent(inout) :: do_pot, do_stress
1139 +    integer, intent(in) :: i, j
1140 +    real ( kind = dp ), intent(inout)    :: rijsq, rcijsq
1141 +    real ( kind = dp )                :: r, rc
1142 +    real ( kind = dp ), intent(inout) :: d(3), dc(3)
1143 +
1144 +    integer :: me_i, me_j, iHash
1145 +
1146      r = sqrt(rijsq)
1020    if (SIM_uses_molecular_cutoffs) then
1021       rc = sqrt(rcijsq)
1022    else
1023       rc = r
1024    endif
1025  
1147  
1148   #ifdef IS_MPI  
1149 <   me_i = atid_row(i)
1150 <   me_j = atid_col(j)  
1149 >    me_i = atid_row(i)
1150 >    me_j = atid_col(j)  
1151   #else  
1152 <   me_i = atid(i)
1153 <   me_j = atid(j)  
1152 >    me_i = atid(i)
1153 >    me_j = atid(j)  
1154   #endif
1034  
1035   if (FF_uses_EAM .and. SIM_uses_EAM) then
1036      
1037      if (PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) &
1038           call calc_EAM_prepair_rho(i, j, d, r, rijsq )
1039      
1040   endif
1041  
1042 end subroutine do_prepair
1043
1044
1045 subroutine do_preforce(nlocal,pot)
1046   integer :: nlocal
1047   real( kind = dp ) :: pot
1048  
1049   if (FF_uses_EAM .and. SIM_uses_EAM) then
1050      call calc_EAM_preforce_Frho(nlocal,pot)
1051   endif
1052  
1053  
1054 end subroutine do_preforce
1055
1056
1057 subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
1058  
1059   real (kind = dp), dimension(3) :: q_i
1060   real (kind = dp), dimension(3) :: q_j
1061   real ( kind = dp ), intent(out) :: r_sq
1062   real( kind = dp ) :: d(3), scaled(3)
1063   integer i
1064  
1065   d(1:3) = q_j(1:3) - q_i(1:3)
1066  
1067   ! Wrap back into periodic box if necessary
1068   if ( SIM_uses_PBC ) then
1069      
1070      if( .not.boxIsOrthorhombic ) then
1071         ! calc the scaled coordinates.
1072        
1073         scaled = matmul(HmatInv, d)
1074        
1075         ! wrap the scaled coordinates
1076        
1077         scaled = scaled  - anint(scaled)
1078        
1079        
1080         ! calc the wrapped real coordinates from the wrapped scaled
1081         ! coordinates
1082        
1083         d = matmul(Hmat,scaled)
1084        
1085      else
1086         ! calc the scaled coordinates.
1087        
1088         do i = 1, 3
1089            scaled(i) = d(i) * HmatInv(i,i)
1090            
1091            ! wrap the scaled coordinates
1092            
1093            scaled(i) = scaled(i) - anint(scaled(i))
1094            
1095            ! calc the wrapped real coordinates from the wrapped scaled
1096            ! coordinates
1097            
1098            d(i) = scaled(i)*Hmat(i,i)
1099         enddo
1100      endif
1101      
1102   endif
1103  
1104   r_sq = dot_product(d,d)
1105  
1106 end subroutine get_interatomic_vector
1107
1108 subroutine zero_work_arrays()
1109  
1110 #ifdef IS_MPI
1111  
1112   q_Row = 0.0_dp
1113   q_Col = 0.0_dp
1155  
1156 <   q_group_Row = 0.0_dp
1157 <   q_group_Col = 0.0_dp  
1158 <  
1159 <   eFrame_Row = 0.0_dp
1160 <   eFrame_Col = 0.0_dp
1161 <  
1162 <   A_Row = 0.0_dp
1163 <   A_Col = 0.0_dp
1164 <  
1165 <   f_Row = 0.0_dp
1166 <   f_Col = 0.0_dp
1167 <   f_Temp = 0.0_dp
1168 <  
1169 <   t_Row = 0.0_dp
1170 <   t_Col = 0.0_dp
1171 <   t_Temp = 0.0_dp
1172 <  
1173 <   pot_Row = 0.0_dp
1174 <   pot_Col = 0.0_dp
1175 <   pot_Temp = 0.0_dp
1176 <  
1177 <   rf_Row = 0.0_dp
1178 <   rf_Col = 0.0_dp
1179 <   rf_Temp = 0.0_dp
1180 <  
1181 < #endif
1182 <
1183 <   if (FF_uses_EAM .and. SIM_uses_EAM) then
1184 <      call clean_EAM()
1185 <   endif
1186 <  
1187 <   rf = 0.0_dp
1188 <   tau_Temp = 0.0_dp
1189 <   virial_Temp = 0.0_dp
1190 < end subroutine zero_work_arrays
1191 <
1192 < function skipThisPair(atom1, atom2) result(skip_it)
1193 <   integer, intent(in) :: atom1
1194 <   integer, intent(in), optional :: atom2
1195 <   logical :: skip_it
1196 <   integer :: unique_id_1, unique_id_2
1197 <   integer :: me_i,me_j
1198 <   integer :: i
1199 <  
1200 <   skip_it = .false.
1201 <  
1202 <   !! there are a number of reasons to skip a pair or a particle
1203 <   !! mostly we do this to exclude atoms who are involved in short
1204 <   !! range interactions (bonds, bends, torsions), but we also need
1205 <   !! to exclude some overcounted interactions that result from
1206 <   !! the parallel decomposition
1207 <  
1208 < #ifdef IS_MPI
1209 <   !! in MPI, we have to look up the unique IDs for each atom
1210 <   unique_id_1 = AtomRowToGlobal(atom1)
1211 < #else
1212 <   !! in the normal loop, the atom numbers are unique
1213 <   unique_id_1 = atom1
1214 < #endif
1215 <  
1216 <   !! We were called with only one atom, so just check the global exclude
1217 <   !! list for this atom
1218 <   if (.not. present(atom2)) then
1219 <      do i = 1, nExcludes_global
1220 <         if (excludesGlobal(i) == unique_id_1) then
1221 <            skip_it = .true.
1222 <            return
1223 <         end if
1224 <      end do
1225 <      return
1226 <   end if
1227 <  
1228 < #ifdef IS_MPI
1229 <   unique_id_2 = AtomColToGlobal(atom2)
1189 < #else
1190 <   unique_id_2 = atom2
1191 < #endif
1192 <  
1156 >    iHash = InteractionHash(me_i, me_j)
1157 >
1158 >    if ( iand(iHash, EAM_PAIR).ne.0 ) then      
1159 >            call calc_EAM_prepair_rho(i, j, d, r, rijsq )
1160 >    endif
1161 >    
1162 >  end subroutine do_prepair
1163 >
1164 >
1165 >  subroutine do_preforce(nlocal,pot)
1166 >    integer :: nlocal
1167 >    real( kind = dp ) :: pot
1168 >
1169 >    if (FF_uses_EAM .and. SIM_uses_EAM) then
1170 >       call calc_EAM_preforce_Frho(nlocal,pot)
1171 >    endif
1172 >
1173 >
1174 >  end subroutine do_preforce
1175 >
1176 >
1177 >  subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
1178 >
1179 >    real (kind = dp), dimension(3) :: q_i
1180 >    real (kind = dp), dimension(3) :: q_j
1181 >    real ( kind = dp ), intent(out) :: r_sq
1182 >    real( kind = dp ) :: d(3), scaled(3)
1183 >    integer i
1184 >
1185 >    d(1:3) = q_j(1:3) - q_i(1:3)
1186 >
1187 >    ! Wrap back into periodic box if necessary
1188 >    if ( SIM_uses_PBC ) then
1189 >
1190 >       if( .not.boxIsOrthorhombic ) then
1191 >          ! calc the scaled coordinates.
1192 >
1193 >          scaled = matmul(HmatInv, d)
1194 >
1195 >          ! wrap the scaled coordinates
1196 >
1197 >          scaled = scaled  - anint(scaled)
1198 >
1199 >
1200 >          ! calc the wrapped real coordinates from the wrapped scaled
1201 >          ! coordinates
1202 >
1203 >          d = matmul(Hmat,scaled)
1204 >
1205 >       else
1206 >          ! calc the scaled coordinates.
1207 >
1208 >          do i = 1, 3
1209 >             scaled(i) = d(i) * HmatInv(i,i)
1210 >
1211 >             ! wrap the scaled coordinates
1212 >
1213 >             scaled(i) = scaled(i) - anint(scaled(i))
1214 >
1215 >             ! calc the wrapped real coordinates from the wrapped scaled
1216 >             ! coordinates
1217 >
1218 >             d(i) = scaled(i)*Hmat(i,i)
1219 >          enddo
1220 >       endif
1221 >
1222 >    endif
1223 >
1224 >    r_sq = dot_product(d,d)
1225 >
1226 >  end subroutine get_interatomic_vector
1227 >
1228 >  subroutine zero_work_arrays()
1229 >
1230   #ifdef IS_MPI
1231 <   !! this situation should only arise in MPI simulations
1232 <   if (unique_id_1 == unique_id_2) then
1233 <      skip_it = .true.
1234 <      return
1235 <   end if
1236 <  
1237 <   !! this prevents us from doing the pair on multiple processors
1238 <   if (unique_id_1 < unique_id_2) then
1239 <      if (mod(unique_id_1 + unique_id_2,2) == 0) then
1240 <         skip_it = .true.
1241 <         return
1242 <      endif
1243 <   else                
1244 <      if (mod(unique_id_1 + unique_id_2,2) == 1) then
1245 <         skip_it = .true.
1246 <         return
1247 <      endif
1248 <   endif
1231 >
1232 >    q_Row = 0.0_dp
1233 >    q_Col = 0.0_dp
1234 >
1235 >    q_group_Row = 0.0_dp
1236 >    q_group_Col = 0.0_dp  
1237 >
1238 >    eFrame_Row = 0.0_dp
1239 >    eFrame_Col = 0.0_dp
1240 >
1241 >    A_Row = 0.0_dp
1242 >    A_Col = 0.0_dp
1243 >
1244 >    f_Row = 0.0_dp
1245 >    f_Col = 0.0_dp
1246 >    f_Temp = 0.0_dp
1247 >
1248 >    t_Row = 0.0_dp
1249 >    t_Col = 0.0_dp
1250 >    t_Temp = 0.0_dp
1251 >
1252 >    pot_Row = 0.0_dp
1253 >    pot_Col = 0.0_dp
1254 >    pot_Temp = 0.0_dp
1255 >
1256 >    rf_Row = 0.0_dp
1257 >    rf_Col = 0.0_dp
1258 >    rf_Temp = 0.0_dp
1259 >
1260   #endif
1261 <  
1262 <   !! the rest of these situations can happen in all simulations:
1263 <   do i = 1, nExcludes_global      
1264 <      if ((excludesGlobal(i) == unique_id_1) .or. &
1265 <           (excludesGlobal(i) == unique_id_2)) then
1266 <         skip_it = .true.
1267 <         return
1268 <      endif
1269 <   enddo
1270 <  
1271 <   do i = 1, nSkipsForAtom(atom1)
1272 <      if (skipsForAtom(atom1, i) .eq. unique_id_2) then
1273 <         skip_it = .true.
1274 <         return
1275 <      endif
1276 <   end do
1277 <  
1278 <   return
1279 < end function skipThisPair
1280 <
1281 < function FF_UsesDirectionalAtoms() result(doesit)
1282 <   logical :: doesit
1283 <   doesit = FF_uses_DirectionalAtoms .or. FF_uses_Dipoles .or. &
1284 <        FF_uses_Quadrupoles .or. FF_uses_Sticky .or. &
1285 <        FF_uses_GayBerne .or. FF_uses_Shapes
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 <
1261 >
1262 >    if (FF_uses_EAM .and. SIM_uses_EAM) then
1263 >       call clean_EAM()
1264 >    endif
1265 >
1266 >    rf = 0.0_dp
1267 >    tau_Temp = 0.0_dp
1268 >    virial_Temp = 0.0_dp
1269 >  end subroutine zero_work_arrays
1270 >
1271 >  function skipThisPair(atom1, atom2) result(skip_it)
1272 >    integer, intent(in) :: atom1
1273 >    integer, intent(in), optional :: atom2
1274 >    logical :: skip_it
1275 >    integer :: unique_id_1, unique_id_2
1276 >    integer :: me_i,me_j
1277 >    integer :: i
1278 >
1279 >    skip_it = .false.
1280 >
1281 >    !! there are a number of reasons to skip a pair or a particle
1282 >    !! mostly we do this to exclude atoms who are involved in short
1283 >    !! range interactions (bonds, bends, torsions), but we also need
1284 >    !! to exclude some overcounted interactions that result from
1285 >    !! the parallel decomposition
1286 >
1287 > #ifdef IS_MPI
1288 >    !! in MPI, we have to look up the unique IDs for each atom
1289 >    unique_id_1 = AtomRowToGlobal(atom1)
1290 > #else
1291 >    !! in the normal loop, the atom numbers are unique
1292 >    unique_id_1 = atom1
1293 > #endif
1294 >
1295 >    !! We were called with only one atom, so just check the global exclude
1296 >    !! list for this atom
1297 >    if (.not. present(atom2)) then
1298 >       do i = 1, nExcludes_global
1299 >          if (excludesGlobal(i) == unique_id_1) then
1300 >             skip_it = .true.
1301 >             return
1302 >          end if
1303 >       end do
1304 >       return
1305 >    end if
1306 >
1307 > #ifdef IS_MPI
1308 >    unique_id_2 = AtomColToGlobal(atom2)
1309 > #else
1310 >    unique_id_2 = atom2
1311 > #endif
1312 >
1313 > #ifdef IS_MPI
1314 >    !! this situation should only arise in MPI simulations
1315 >    if (unique_id_1 == unique_id_2) then
1316 >       skip_it = .true.
1317 >       return
1318 >    end if
1319 >
1320 >    !! this prevents us from doing the pair on multiple processors
1321 >    if (unique_id_1 < unique_id_2) then
1322 >       if (mod(unique_id_1 + unique_id_2,2) == 0) then
1323 >          skip_it = .true.
1324 >          return
1325 >       endif
1326 >    else                
1327 >       if (mod(unique_id_1 + unique_id_2,2) == 1) then
1328 >          skip_it = .true.
1329 >          return
1330 >       endif
1331 >    endif
1332 > #endif
1333 >
1334 >    !! the rest of these situations can happen in all simulations:
1335 >    do i = 1, nExcludes_global      
1336 >       if ((excludesGlobal(i) == unique_id_1) .or. &
1337 >            (excludesGlobal(i) == unique_id_2)) then
1338 >          skip_it = .true.
1339 >          return
1340 >       endif
1341 >    enddo
1342 >
1343 >    do i = 1, nSkipsForAtom(atom1)
1344 >       if (skipsForAtom(atom1, i) .eq. unique_id_2) then
1345 >          skip_it = .true.
1346 >          return
1347 >       endif
1348 >    end do
1349 >
1350 >    return
1351 >  end function skipThisPair
1352 >
1353 >  function FF_UsesDirectionalAtoms() result(doesit)
1354 >    logical :: doesit
1355 >    doesit = FF_uses_DirectionalAtoms
1356 >  end function FF_UsesDirectionalAtoms
1357 >
1358 >  function FF_RequiresPrepairCalc() result(doesit)
1359 >    logical :: doesit
1360 >    doesit = FF_uses_EAM
1361 >  end function FF_RequiresPrepairCalc
1362 >
1363 >  function FF_RequiresPostpairCalc() result(doesit)
1364 >    logical :: doesit
1365 >    if (electrostaticSummationMethod == 3) doesit = .true.
1366 >  end function FF_RequiresPostpairCalc
1367 >
1368   #ifdef PROFILE
1369 < function getforcetime() result(totalforcetime)
1370 <   real(kind=dp) :: totalforcetime
1371 <   totalforcetime = forcetime
1372 < end function getforcetime
1369 >  function getforcetime() result(totalforcetime)
1370 >    real(kind=dp) :: totalforcetime
1371 >    totalforcetime = forcetime
1372 >  end function getforcetime
1373   #endif
1256
1257 !! This cleans componets of force arrays belonging only to fortran
1374  
1375 < subroutine add_stress_tensor(dpair, fpair)
1376 <  
1377 <   real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1378 <  
1379 <   ! because the d vector is the rj - ri vector, and
1380 <   ! because fx, fy, fz are the force on atom i, we need a
1381 <   ! negative sign here:  
1382 <  
1383 <   tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1384 <   tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1385 <   tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1386 <   tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1387 <   tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1388 <   tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1389 <   tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1390 <   tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1391 <   tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1392 <  
1393 <   virial_Temp = virial_Temp + &
1394 <        (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1395 <  
1396 < end subroutine add_stress_tensor
1397 <
1375 >  !! This cleans componets of force arrays belonging only to fortran
1376 >
1377 >  subroutine add_stress_tensor(dpair, fpair)
1378 >
1379 >    real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1380 >
1381 >    ! because the d vector is the rj - ri vector, and
1382 >    ! because fx, fy, fz are the force on atom i, we need a
1383 >    ! negative sign here:  
1384 >
1385 >    tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1386 >    tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1387 >    tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1388 >    tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1389 >    tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1390 >    tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1391 >    tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1392 >    tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1393 >    tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1394 >
1395 >    virial_Temp = virial_Temp + &
1396 >         (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1397 >
1398 >  end subroutine add_stress_tensor
1399 >
1400   end module doForces

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines