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

Comparing trunk/OOPSE-3.0/src/UseTheForce/doForces.F90 (file contents):
Revision 2085 by gezelter, Tue Mar 8 21:05:46 2005 UTC vs.
Revision 2270 by gezelter, Tue Aug 9 22:33:37 2005 UTC

# Line 45 | Line 45
45  
46   !! @author Charles F. Vardeman II
47   !! @author Matthew Meineke
48 < !! @version $Id: doForces.F90,v 1.11 2005-03-08 21:05:46 gezelter Exp $, $Date: 2005-03-08 21:05:46 $, $Name: not supported by cvs2svn $, $Revision: 1.11 $
48 > !! @version $Id: doForces.F90,v 1.28 2005-08-09 22:33:37 gezelter Exp $, $Date: 2005-08-09 22:33:37 $, $Name: not supported by cvs2svn $, $Revision: 1.28 $
49  
50  
51   module doForces
# Line 73 | Line 73 | module doForces
73  
74   #define __FORTRAN90
75   #include "UseTheForce/fSwitchingFunction.h"
76 + #include "UseTheForce/DarkSide/fInteractionMap.h"
77  
78    INTEGER, PARAMETER:: PREPAIR_LOOP = 1
79    INTEGER, PARAMETER:: PAIR_LOOP    = 2
80  
80  logical, save :: haveRlist = .false.
81    logical, save :: haveNeighborList = .false.
82    logical, save :: haveSIMvariables = .false.
83  logical, save :: havePropertyMap = .false.
83    logical, save :: haveSaneForceField = .false.
84 <  
84 >  logical, save :: haveInteractionHash = .false.
85 >  logical, save :: haveGtypeCutoffMap = .false.
86 >
87    logical, save :: FF_uses_DirectionalAtoms
87  logical, save :: FF_uses_LennardJones
88  logical, save :: FF_uses_Electrostatics
89  logical, save :: FF_uses_Charges
88    logical, save :: FF_uses_Dipoles
91  logical, save :: FF_uses_Quadrupoles
92  logical, save :: FF_uses_sticky
89    logical, save :: FF_uses_GayBerne
90    logical, save :: FF_uses_EAM
95  logical, save :: FF_uses_Shapes
96  logical, save :: FF_uses_FLARB
91    logical, save :: FF_uses_RF
92  
93    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
94    logical, save :: SIM_uses_EAM
108  logical, save :: SIM_uses_Shapes
109  logical, save :: SIM_uses_FLARB
95    logical, save :: SIM_uses_RF
96    logical, save :: SIM_requires_postpair_calc
97    logical, save :: SIM_requires_prepair_calc
98    logical, save :: SIM_uses_PBC
114  logical, save :: SIM_uses_molecular_cutoffs
99  
116  real(kind=dp), save :: rlist, rlistsq
117
100    public :: init_FF
101    public :: do_force_loop
102 <  public :: setRlistDF
102 >  public :: createInteractionHash
103 >  public :: createGtypeCutoffMap
104  
105   #ifdef PROFILE
106    public :: getforcetime
# Line 125 | Line 108 | module doForces
108    real :: forceTimeInitial, forceTimeFinal
109    integer :: nLoops
110   #endif
111 <
112 <  type :: Properties
113 <     logical :: is_Directional   = .false.
114 <     logical :: is_LennardJones  = .false.
115 <     logical :: is_Electrostatic = .false.
116 <     logical :: is_Charge        = .false.
117 <     logical :: is_Dipole        = .false.
118 <     logical :: is_Quadrupole    = .false.
119 <     logical :: is_Sticky        = .false.
120 <     logical :: is_GayBerne      = .false.
121 <     logical :: is_EAM           = .false.
122 <     logical :: is_Shape         = .false.
123 <     logical :: is_FLARB         = .false.
124 <  end type Properties
125 <
143 <  type(Properties), dimension(:),allocatable :: PropertyMap
144 <
111 >  
112 >  !! Variables for cutoff mapping and interaction mapping
113 >  ! Bit hash to determine pair-pair interactions.
114 >  integer, dimension(:,:), allocatable :: InteractionHash
115 >  real(kind=dp), dimension(:), allocatable :: atypeMaxCutoff
116 >  real(kind=dp), dimension(:), allocatable :: groupMaxCutoff
117 >  integer, dimension(:), allocatable :: groupToGtype
118 >  real(kind=dp), dimension(:), allocatable :: gtypeMaxCutoff
119 >  type ::gtypeCutoffs
120 >     real(kind=dp) :: rcut
121 >     real(kind=dp) :: rcutsq
122 >     real(kind=dp) :: rlistsq
123 >  end type gtypeCutoffs
124 >  type(gtypeCutoffs), dimension(:,:), allocatable :: gtypeCutoffMap
125 >  
126   contains
127  
128 <  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)
128 >  subroutine createInteractionHash(status)
129      integer :: nAtypes
130 <    integer :: status
130 >    integer, intent(out) :: status
131      integer :: i
132 <    logical :: thisProperty
133 <    real (kind=DP) :: thisDPproperty
132 >    integer :: j
133 >    integer :: iHash
134 >    !! Test Types
135 >    logical :: i_is_LJ
136 >    logical :: i_is_Elect
137 >    logical :: i_is_Sticky
138 >    logical :: i_is_StickyP
139 >    logical :: i_is_GB
140 >    logical :: i_is_EAM
141 >    logical :: i_is_Shape
142 >    logical :: j_is_LJ
143 >    logical :: j_is_Elect
144 >    logical :: j_is_Sticky
145 >    logical :: j_is_StickyP
146 >    logical :: j_is_GB
147 >    logical :: j_is_EAM
148 >    logical :: j_is_Shape
149 >    
150 >    status = 0  
151  
152 <    status = 0
153 <
152 >    if (.not. associated(atypes)) then
153 >       call handleError("atype", "atypes was not present before call of createInteractionHash!")
154 >       status = -1
155 >       return
156 >    endif
157 >    
158      nAtypes = getSize(atypes)
159 <
159 >    
160      if (nAtypes == 0) then
161         status = -1
162         return
163      end if
164 <        
165 <    if (.not. allocated(PropertyMap)) then
166 <       allocate(PropertyMap(nAtypes))
164 >
165 >    if (.not. allocated(InteractionHash)) then
166 >       allocate(InteractionHash(nAtypes,nAtypes))
167      endif
168  
169 +    if (.not. allocated(atypeMaxCutoff)) then
170 +       allocate(atypeMaxCutoff(nAtypes))
171 +    endif
172 +        
173      do i = 1, nAtypes
174 <       call getElementProperty(atypes, i, "is_Directional", thisProperty)
175 <       PropertyMap(i)%is_Directional = thisProperty
174 >       call getElementProperty(atypes, i, "is_LennardJones", i_is_LJ)
175 >       call getElementProperty(atypes, i, "is_Electrostatic", i_is_Elect)
176 >       call getElementProperty(atypes, i, "is_Sticky", i_is_Sticky)
177 >       call getElementProperty(atypes, i, "is_StickyPower", i_is_StickyP)
178 >       call getElementProperty(atypes, i, "is_GayBerne", i_is_GB)
179 >       call getElementProperty(atypes, i, "is_EAM", i_is_EAM)
180 >       call getElementProperty(atypes, i, "is_Shape", i_is_Shape)
181  
182 <       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
182 >       if (i_is_LJ) then
183 >          thisCut = getDefaultLJCutoff(i)
184 >          if (thisCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisCut
185 >       endif
186  
188       call getElementProperty(atypes, i, "is_Charge", thisProperty)
189       PropertyMap(i)%is_Charge = thisProperty
190      
191       call getElementProperty(atypes, i, "is_Dipole", thisProperty)
192       PropertyMap(i)%is_Dipole = thisProperty
187  
194       call getElementProperty(atypes, i, "is_Quadrupole", thisProperty)
195       PropertyMap(i)%is_Quadrupole = thisProperty
188  
189 <       call getElementProperty(atypes, i, "is_Sticky", thisProperty)
198 <       PropertyMap(i)%is_Sticky = thisProperty
189 >       do j = i, nAtypes
190  
191 <       call getElementProperty(atypes, i, "is_GayBerne", thisProperty)
192 <       PropertyMap(i)%is_GayBerne = thisProperty
191 >          iHash = 0
192 >          myRcut = 0.0_dp
193  
194 <       call getElementProperty(atypes, i, "is_EAM", thisProperty)
195 <       PropertyMap(i)%is_EAM = thisProperty
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_Shape", thisProperty)
203 <       PropertyMap(i)%is_Shape = 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 <       call getElementProperty(atypes, i, "is_FLARB", thisProperty)
215 <       PropertyMap(i)%is_FLARB = thisProperty
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(defaultRcut, defaultSkinThickness, stat)
242  
243 +    real(kind=dp), intent(in), optional :: defaultRCut, defaultSkinThickness
244 +    integer, intent(out) :: stat
245 +
246 +    integer :: myStatus, nAtypes
247 +
248 +    stat = 0
249 +    if (.not. haveInteractionHash) then
250 +       call createInteractionHash(myStatus)      
251 +       if (myStatus .ne. 0) then
252 +          write(default_error, *) 'createInteractionHash failed in doForces!'
253 +          stat = -1
254 +          return
255 +       endif
256 +    endif
257 +
258 +    nAtypes = getSize(atypes)
259 +
260 +    do i = 1, nAtypes
261 +      
262 +       atypeMaxCutoff(i) =
263 +
264 +    
265 +
266 +
267 +
268 +     haveGtypeCutoffMap = .true.
269 +   end subroutine createGtypeCutoffMap
270 +
271    subroutine setSimVariables()
272      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()
273      SIM_uses_EAM = SimUsesEAM()
226    SIM_uses_Shapes = SimUsesShapes()
227    SIM_uses_FLARB = SimUsesFLARB()
274      SIM_uses_RF = SimUsesRF()
275      SIM_requires_postpair_calc = SimRequiresPostpairCalc()
276      SIM_requires_prepair_calc = SimRequiresPrepairCalc()
# Line 241 | Line 287 | contains
287      integer :: myStatus
288  
289      error = 0
244    
245    if (.not. havePropertyMap) then
290  
291 <       myStatus = 0
291 >    if (.not. haveInteractionHash) then      
292 >       myStatus = 0      
293 >       call createInteractionHash(myStatus)      
294 >       if (myStatus .ne. 0) then
295 >          write(default_error, *) 'createInteractionHash failed in doForces!'
296 >          error = -1
297 >          return
298 >       endif
299 >    endif
300  
301 <       call createPropertyMap(myStatus)
302 <
301 >    if (.not. haveGtypeCutoffMap) then        
302 >       myStatus = 0      
303 >       call createGtypeCutoffMap(myStatus)      
304         if (myStatus .ne. 0) then
305 <          write(default_error, *) 'createPropertyMap failed in doForces!'
305 >          write(default_error, *) 'createGtypeCutoffMap failed in doForces!'
306            error = -1
307            return
308         endif
# Line 286 | Line 339 | contains
339   #endif
340      return
341    end subroutine doReadyCheck
289    
342  
343 +
344    subroutine init_FF(use_RF_c, thisStat)
345  
346      logical, intent(in) :: use_RF_c
# Line 302 | Line 355 | contains
355  
356      !! Fortran's version of a cast:
357      FF_uses_RF = use_RF_c
358 <    
358 >
359      !! init_FF is called *after* all of the atom types have been
360      !! defined in atype_module using the new_atype subroutine.
361      !!
362      !! this will scan through the known atypes and figure out what
363      !! interactions are used by the force field.    
364 <  
364 >
365      FF_uses_DirectionalAtoms = .false.
313    FF_uses_LennardJones = .false.
314    FF_uses_Electrostatics = .false.
315    FF_uses_Charges = .false.    
366      FF_uses_Dipoles = .false.
317    FF_uses_Sticky = .false.
367      FF_uses_GayBerne = .false.
368      FF_uses_EAM = .false.
369 <    FF_uses_Shapes = .false.
321 <    FF_uses_FLARB = .false.
322 <    
369 >
370      call getMatchingElementList(atypes, "is_Directional", .true., &
371           nMatches, MatchList)
372      if (nMatches .gt. 0) FF_uses_DirectionalAtoms = .true.
373  
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    
374      call getMatchingElementList(atypes, "is_Dipole", .true., &
375           nMatches, MatchList)
376 <    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
376 >    if (nMatches .gt. 0) FF_uses_Dipoles = .true.
377      
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    
378      call getMatchingElementList(atypes, "is_GayBerne", .true., &
379           nMatches, MatchList)
380 <    if (nMatches .gt. 0) then
381 <       FF_uses_GayBerne = .true.
371 <       FF_uses_DirectionalAtoms = .true.
372 <    endif
373 <    
380 >    if (nMatches .gt. 0) FF_uses_GayBerne = .true.
381 >
382      call getMatchingElementList(atypes, "is_EAM", .true., nMatches, MatchList)
383      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
384  
384    call getMatchingElementList(atypes, "is_FLARB", .true., &
385         nMatches, MatchList)
386    if (nMatches .gt. 0) FF_uses_FLARB = .true.
385  
388    !! Assume sanity (for the sake of argument)
386      haveSaneForceField = .true.
387 <    
387 >
388      !! check to make sure the FF_uses_RF setting makes sense
389 <    
390 <    if (FF_uses_dipoles) then
389 >
390 >    if (FF_uses_Dipoles) then
391         if (FF_uses_RF) then
392            dielect = getDielect()
393            call initialize_rf(dielect)
# Line 402 | Line 399 | contains
399            haveSaneForceField = .false.
400            return
401         endif
402 <    endif
402 >    endif
403  
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
404      if (FF_uses_EAM) then
405 <         call init_EAM_FF(my_status)
405 >       call init_EAM_FF(my_status)
406         if (my_status /= 0) then
407            write(default_error, *) "init_EAM_FF returned a bad status"
408            thisStat = -1
# Line 433 | Line 420 | contains
420         endif
421      endif
422  
436    if (FF_uses_GayBerne .and. FF_uses_LennardJones) then
437    endif
438    
423      if (.not. haveNeighborList) then
424         !! Create neighbor lists
425         call expandNeighborList(nLocal, my_status)
# Line 445 | Line 429 | contains
429            return
430         endif
431         haveNeighborList = .true.
432 <    endif    
433 <    
432 >    endif
433 >
434    end subroutine init_FF
451  
435  
436 +
437    !! Does force loop over i,j pairs. Calls do_pair to calculates forces.
438    !------------------------------------------------------------->
439    subroutine do_force_loop(q, q_group, A, eFrame, f, t, tau, pot, &
# Line 499 | Line 483 | contains
483      integer :: localError
484      integer :: propPack_i, propPack_j
485      integer :: loopStart, loopEnd, loop
486 <
486 >    integer :: iHash
487      real(kind=dp) :: listSkin = 1.0  
488 <    
488 >
489      !! initialize local variables  
490 <    
490 >
491   #ifdef IS_MPI
492      pot_local = 0.0_dp
493      nAtomsInRow   = getNatomsInRow(plan_atom_row)
# Line 513 | Line 497 | contains
497   #else
498      natoms = nlocal
499   #endif
500 <    
500 >
501      call doReadyCheck(localError)
502      if ( localError .ne. 0 ) then
503         call handleError("do_force_loop", "Not Initialized")
# Line 521 | Line 505 | contains
505         return
506      end if
507      call zero_work_arrays()
508 <        
508 >
509      do_pot = do_pot_c
510      do_stress = do_stress_c
511 <    
511 >
512      ! Gather all information needed by all force loops:
513 <    
513 >
514   #ifdef IS_MPI    
515 <    
515 >
516      call gather(q, q_Row, plan_atom_row_3d)
517      call gather(q, q_Col, plan_atom_col_3d)
518  
519      call gather(q_group, q_group_Row, plan_group_row_3d)
520      call gather(q_group, q_group_Col, plan_group_col_3d)
521 <        
521 >
522      if (FF_UsesDirectionalAtoms() .and. SIM_uses_DirectionalAtoms) then
523         call gather(eFrame, eFrame_Row, plan_atom_row_rotation)
524         call gather(eFrame, eFrame_Col, plan_atom_col_rotation)
525 <      
525 >
526         call gather(A, A_Row, plan_atom_row_rotation)
527         call gather(A, A_Col, plan_atom_col_rotation)
528      endif
529 <    
529 >
530   #endif
531 <    
531 >
532      !! Begin force loop timing:
533   #ifdef PROFILE
534      call cpu_time(forceTimeInitial)
535      nloops = nloops + 1
536   #endif
537 <    
537 >
538      loopEnd = PAIR_LOOP
539      if (FF_RequiresPrepairCalc() .and. SIM_requires_prepair_calc) then
540         loopStart = PREPAIR_LOOP
# Line 565 | Line 549 | contains
549         if (loop .eq. loopStart) then
550   #ifdef IS_MPI
551            call checkNeighborList(nGroupsInRow, q_group_row, listSkin, &
552 <             update_nlist)
552 >               update_nlist)
553   #else
554            call checkNeighborList(nGroups, q_group, listSkin, &
555 <             update_nlist)
555 >               update_nlist)
556   #endif
557         endif
558 <      
558 >
559         if (update_nlist) then
560            !! save current configuration and construct neighbor list
561   #ifdef IS_MPI
# Line 582 | Line 566 | contains
566            neighborListSize = size(list)
567            nlist = 0
568         endif
569 <      
569 >
570         istart = 1
571   #ifdef IS_MPI
572         iend = nGroupsInRow
# Line 591 | Line 575 | contains
575   #endif
576         outer: do i = istart, iend
577  
578 <          if (update_nlist) point(i) = nlist + 1
579 <          
578 > #ifdef IS_MPI
579 >             me_i = atid_row(i)
580 > #else
581 >             me_i = atid(i)
582 > #endif
583 >
584 >          if (update_nlist) point(i) = nlist + 1
585 >
586            n_in_i = groupStartRow(i+1) - groupStartRow(i)
587 <          
587 >
588            if (update_nlist) then
589   #ifdef IS_MPI
590               jstart = 1
# Line 609 | Line 599 | contains
599               ! make sure group i has neighbors
600               if (jstart .gt. jend) cycle outer
601            endif
602 <          
602 >
603            do jnab = jstart, jend
604               if (update_nlist) then
605                  j = jnab
# Line 618 | Line 608 | contains
608               endif
609  
610   #ifdef IS_MPI
611 +             me_j = atid_col(j)
612               call get_interatomic_vector(q_group_Row(:,i), &
613                    q_group_Col(:,j), d_grp, rgrpsq)
614   #else
615 +             me_j = atid(j)
616               call get_interatomic_vector(q_group(:,i), &
617                    q_group(:,j), d_grp, rgrpsq)
618   #endif
619  
620 <             if (rgrpsq < rlistsq) then
620 >             if (rgrpsq < InteractionHash(me_i,me_j)%rListsq) then
621                  if (update_nlist) then
622                     nlist = nlist + 1
623 <                  
623 >
624                     if (nlist > neighborListSize) then
625   #ifdef IS_MPI                
626                        call expandNeighborList(nGroupsInRow, listerror)
# Line 642 | Line 634 | contains
634                        end if
635                        neighborListSize = size(list)
636                     endif
637 <                  
637 >
638                     list(nlist) = j
639                  endif
640 <                
640 >
641                  if (loop .eq. PAIR_LOOP) then
642                     vij = 0.0d0
643                     fij(1:3) = 0.0d0
644                  endif
645 <                
645 >
646                  call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, &
647                       in_switching_region)
648 <                
648 >
649                  n_in_j = groupStartCol(j+1) - groupStartCol(j)
650 <                
650 >
651                  do ia = groupStartRow(i), groupStartRow(i+1)-1
652 <                  
652 >
653                     atom1 = groupListRow(ia)
654 <                  
654 >
655                     inner: do jb = groupStartCol(j), groupStartCol(j+1)-1
656 <                      
656 >
657                        atom2 = groupListCol(jb)
658 <                      
658 >
659                        if (skipThisPair(atom1, atom2)) cycle inner
660  
661                        if ((n_in_i .eq. 1).and.(n_in_j .eq. 1)) then
# Line 705 | Line 697 | contains
697                        endif
698                     enddo inner
699                  enddo
700 <                
700 >
701                  if (loop .eq. PAIR_LOOP) then
702                     if (in_switching_region) then
703                        swderiv = vij*dswdr/rgrp
704                        fij(1) = fij(1) + swderiv*d_grp(1)
705                        fij(2) = fij(2) + swderiv*d_grp(2)
706                        fij(3) = fij(3) + swderiv*d_grp(3)
707 <                      
707 >
708                        do ia=groupStartRow(i), groupStartRow(i+1)-1
709                           atom1=groupListRow(ia)
710                           mf = mfactRow(atom1)
# Line 726 | Line 718 | contains
718                           f(3,atom1) = f(3,atom1) + swderiv*d_grp(3)*mf
719   #endif
720                        enddo
721 <                      
721 >
722                        do jb=groupStartCol(j), groupStartCol(j+1)-1
723                           atom2=groupListCol(jb)
724                           mf = mfactCol(atom2)
# Line 741 | Line 733 | contains
733   #endif
734                        enddo
735                     endif
736 <                  
736 >
737                     if (do_stress) call add_stress_tensor(d_grp, fij)
738                  endif
739               end if
740            enddo
741         enddo outer
742 <      
742 >
743         if (update_nlist) then
744   #ifdef IS_MPI
745            point(nGroupsInRow + 1) = nlist + 1
# Line 761 | Line 753 | contains
753               update_nlist = .false.                              
754            endif
755         endif
756 <            
756 >
757         if (loop .eq. PREPAIR_LOOP) then
758            call do_preforce(nlocal, pot)
759         endif
760 <      
760 >
761      enddo
762 <    
762 >
763      !! Do timing
764   #ifdef PROFILE
765      call cpu_time(forceTimeFinal)
766      forceTime = forceTime + forceTimeFinal - forceTimeInitial
767   #endif    
768 <    
768 >
769   #ifdef IS_MPI
770      !!distribute forces
771 <    
771 >
772      f_temp = 0.0_dp
773      call scatter(f_Row,f_temp,plan_atom_row_3d)
774      do i = 1,nlocal
775         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
776      end do
777 <    
777 >
778      f_temp = 0.0_dp
779      call scatter(f_Col,f_temp,plan_atom_col_3d)
780      do i = 1,nlocal
781         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
782      end do
783 <    
783 >
784      if (FF_UsesDirectionalAtoms() .and. SIM_uses_DirectionalAtoms) then
785         t_temp = 0.0_dp
786         call scatter(t_Row,t_temp,plan_atom_row_3d)
# Line 797 | Line 789 | contains
789         end do
790         t_temp = 0.0_dp
791         call scatter(t_Col,t_temp,plan_atom_col_3d)
792 <      
792 >
793         do i = 1,nlocal
794            t(1:3,i) = t(1:3,i) + t_temp(1:3,i)
795         end do
796      endif
797 <    
797 >
798      if (do_pot) then
799         ! scatter/gather pot_row into the members of my column
800         call scatter(pot_Row, pot_Temp, plan_atom_row)
801 <      
801 >
802         ! scatter/gather pot_local into all other procs
803         ! add resultant to get total pot
804         do i = 1, nlocal
805            pot_local = pot_local + pot_Temp(i)
806         enddo
807 <      
807 >
808         pot_Temp = 0.0_DP
809 <      
809 >
810         call scatter(pot_Col, pot_Temp, plan_atom_col)
811         do i = 1, nlocal
812            pot_local = pot_local + pot_Temp(i)
813         enddo
814 <      
814 >
815      endif
816   #endif
817 <    
817 >
818      if (FF_RequiresPostpairCalc() .and. SIM_requires_postpair_calc) then
819 <      
819 >
820         if (FF_uses_RF .and. SIM_uses_RF) then
821 <          
821 >
822   #ifdef IS_MPI
823            call scatter(rf_Row,rf,plan_atom_row_3d)
824            call scatter(rf_Col,rf_Temp,plan_atom_col_3d)
# Line 834 | Line 826 | contains
826               rf(1:3,i) = rf(1:3,i) + rf_Temp(1:3,i)
827            end do
828   #endif
829 <          
829 >
830            do i = 1, nLocal
831 <            
831 >
832               rfpot = 0.0_DP
833   #ifdef IS_MPI
834               me_i = atid_row(i)
835   #else
836               me_i = atid(i)
837   #endif
838 +             iHash = InteractionHash(me_i,me_j)
839              
840 <             if (PropertyMap(me_i)%is_Dipole) then
841 <                
840 >             if ( iand(iHash, ELECTROSTATIC_PAIR).ne.0 ) then
841 >
842                  mu_i = getDipoleMoment(me_i)
843 <                
843 >
844                  !! The reaction field needs to include a self contribution
845                  !! to the field:
846                  call accumulate_self_rf(i, mu_i, eFrame)
# Line 858 | Line 851 | contains
851                  pot_local = pot_local + rfpot
852   #else
853                  pot = pot + rfpot
854 <      
854 >
855   #endif
856 <             endif            
856 >             endif
857            enddo
858         endif
859      endif
860 <    
861 <    
860 >
861 >
862   #ifdef IS_MPI
863 <    
863 >
864      if (do_pot) then
865         pot = pot + pot_local
866         !! we assume the c code will do the allreduce to get the total potential
867         !! we could do it right here if we needed to...
868      endif
869 <    
869 >
870      if (do_stress) then
871         call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, &
872              mpi_comm_world,mpi_err)
873         call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, &
874              mpi_comm_world,mpi_err)
875      endif
876 <    
876 >
877   #else
878 <    
878 >
879      if (do_stress) then
880         tau = tau_Temp
881         virial = virial_Temp
882      endif
883 <    
883 >
884   #endif
885 <      
885 >
886    end subroutine do_force_loop
887 <  
887 >
888    subroutine do_pair(i, j, rijsq, d, sw, do_pot, &
889         eFrame, A, f, t, pot, vpair, fpair)
890  
# Line 908 | Line 901 | contains
901      real ( kind = dp ), intent(inout) :: rijsq
902      real ( kind = dp )                :: r
903      real ( kind = dp ), intent(inout) :: d(3)
904 +    real ( kind = dp ) :: ebalance
905      integer :: me_i, me_j
906  
907 +    integer :: iHash
908 +
909      r = sqrt(rijsq)
910      vpair = 0.0d0
911      fpair(1:3) = 0.0d0
# Line 922 | Line 918 | contains
918      me_j = atid(j)
919   #endif
920  
921 < !    write(*,*) i, j, me_i, me_j
922 <    
923 <    if (FF_uses_LennardJones .and. SIM_uses_LennardJones) then
924 <      
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 <      
921 >    iHash = InteractionHash(me_i, me_j)
922 >
923 >    if ( iand(iHash, LJ_PAIR).ne.0 ) then
924 >       call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
925      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
926  
927 +    if ( iand(iHash, ELECTROSTATIC_PAIR).ne.0 ) then
928 +       call doElectrostaticPair(i, j, d, r, rijsq, sw, vpair, fpair, &
929 +            pot, eFrame, f, t, do_pot)
930  
931 <    if (FF_uses_Sticky .and. SIM_uses_sticky) then
931 >       if (FF_uses_RF .and. SIM_uses_RF) then
932  
933 <       if ( PropertyMap(me_i)%is_Sticky .and. PropertyMap(me_j)%is_Sticky) then
934 <          call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
935 <               pot, A, f, t, do_pot)
933 >          ! CHECK ME (RF needs to know about all electrostatic types)
934 >          call accumulate_rf(i, j, r, eFrame, sw)
935 >          call rf_correct_forces(i, j, d, r, eFrame, sw, f, fpair)
936         endif
937 <      
937 >
938      endif
939  
940 +    if ( iand(iHash, STICKY_PAIR).ne.0 ) then
941 +       call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
942 +            pot, A, f, t, do_pot)
943 +    endif
944  
945 <    if (FF_uses_GayBerne .and. SIM_uses_GayBerne) then
946 <      
947 <       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 <      
945 >    if ( iand(iHash, STICKYPOWER_PAIR).ne.0 ) then
946 >       call do_sticky_power_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
947 >            pot, A, f, t, do_pot)
948      endif
949 <    
950 <    if (FF_uses_EAM .and. SIM_uses_EAM) then
951 <      
952 <       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 <      
949 >
950 >    if ( iand(iHash, GAYBERNE_PAIR).ne.0 ) then
951 >       call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
952 >            pot, A, f, t, do_pot)
953      endif
954 +    
955 +    if ( iand(iHash, GAYBERNE_LJ).ne.0 ) then
956 + !      call do_gblj_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
957 + !           pot, A, f, t, do_pot)
958 +    endif
959  
960 +    if ( iand(iHash, EAM_PAIR).ne.0 ) then      
961 +       call do_eam_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, &
962 +            do_pot)
963 +    endif
964  
965 < !    write(*,*) PropertyMap(me_i)%is_Shape,PropertyMap(me_j)%is_Shape
965 >    if ( iand(iHash, SHAPE_PAIR).ne.0 ) then      
966 >       call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
967 >            pot, A, f, t, do_pot)
968 >    endif
969  
970 <    if (FF_uses_Shapes .and. SIM_uses_Shapes) then
971 <       if ( PropertyMap(me_i)%is_Shape .and. &
972 <            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 <      
970 >    if ( iand(iHash, SHAPE_LJ).ne.0 ) then      
971 >       call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
972 >            pot, A, f, t, do_pot)
973      endif
974      
975    end subroutine do_pair
# Line 999 | Line 977 | contains
977    subroutine do_prepair(i, j, rijsq, d, sw, rcijsq, dc, &
978         do_pot, do_stress, eFrame, A, f, t, pot)
979  
980 <   real( kind = dp ) :: pot, sw
981 <   real( kind = dp ), dimension(9,nLocal) :: eFrame
982 <   real (kind=dp), dimension(9,nLocal) :: A
983 <   real (kind=dp), dimension(3,nLocal) :: f
984 <   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 <  
980 >    real( kind = dp ) :: pot, sw
981 >    real( kind = dp ), dimension(9,nLocal) :: eFrame
982 >    real (kind=dp), dimension(9,nLocal) :: A
983 >    real (kind=dp), dimension(3,nLocal) :: f
984 >    real (kind=dp), dimension(3,nLocal) :: t
985  
986 <    r = sqrt(rijsq)
987 <    if (SIM_uses_molecular_cutoffs) then
988 <       rc = sqrt(rcijsq)
989 <    else
990 <       rc = r
1024 <    endif
1025 <  
986 >    logical, intent(inout) :: do_pot, do_stress
987 >    integer, intent(in) :: i, j
988 >    real ( kind = dp ), intent(inout)    :: rijsq, rcijsq
989 >    real ( kind = dp )                :: r, rc
990 >    real ( kind = dp ), intent(inout) :: d(3), dc(3)
991  
992 +    integer :: me_i, me_j, iHash
993 +
994   #ifdef IS_MPI  
995 <   me_i = atid_row(i)
996 <   me_j = atid_col(j)  
995 >    me_i = atid_row(i)
996 >    me_j = atid_col(j)  
997   #else  
998 <   me_i = atid(i)
999 <   me_j = atid(j)  
998 >    me_i = atid(i)
999 >    me_j = atid(j)  
1000   #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
1001  
1002 <   q_group_Row = 0.0_dp
1003 <   q_group_Col = 0.0_dp  
1004 <  
1005 <   eFrame_Row = 0.0_dp
1006 <   eFrame_Col = 0.0_dp
1007 <  
1008 <   A_Row = 0.0_dp
1009 <   A_Col = 0.0_dp
1010 <  
1011 <   f_Row = 0.0_dp
1012 <   f_Col = 0.0_dp
1013 <   f_Temp = 0.0_dp
1014 <  
1015 <   t_Row = 0.0_dp
1016 <   t_Col = 0.0_dp
1017 <   t_Temp = 0.0_dp
1018 <  
1019 <   pot_Row = 0.0_dp
1020 <   pot_Col = 0.0_dp
1021 <   pot_Temp = 0.0_dp
1022 <  
1023 <   rf_Row = 0.0_dp
1024 <   rf_Col = 0.0_dp
1025 <   rf_Temp = 0.0_dp
1026 <  
1027 < #endif
1028 <
1029 <   if (FF_uses_EAM .and. SIM_uses_EAM) then
1030 <      call clean_EAM()
1031 <   endif
1032 <  
1033 <   rf = 0.0_dp
1034 <   tau_Temp = 0.0_dp
1035 <   virial_Temp = 0.0_dp
1036 < end subroutine zero_work_arrays
1037 <
1038 < function skipThisPair(atom1, atom2) result(skip_it)
1039 <   integer, intent(in) :: atom1
1040 <   integer, intent(in), optional :: atom2
1041 <   logical :: skip_it
1042 <   integer :: unique_id_1, unique_id_2
1043 <   integer :: me_i,me_j
1044 <   integer :: i
1045 <  
1046 <   skip_it = .false.
1047 <  
1048 <   !! there are a number of reasons to skip a pair or a particle
1049 <   !! mostly we do this to exclude atoms who are involved in short
1050 <   !! range interactions (bonds, bends, torsions), but we also need
1051 <   !! to exclude some overcounted interactions that result from
1052 <   !! the parallel decomposition
1053 <  
1002 >    iHash = InteractionHash(me_i, me_j)
1003 >
1004 >    if ( iand(iHash, EAM_PAIR).ne.0 ) then      
1005 >            call calc_EAM_prepair_rho(i, j, d, r, rijsq )
1006 >    endif
1007 >    
1008 >  end subroutine do_prepair
1009 >
1010 >
1011 >  subroutine do_preforce(nlocal,pot)
1012 >    integer :: nlocal
1013 >    real( kind = dp ) :: pot
1014 >
1015 >    if (FF_uses_EAM .and. SIM_uses_EAM) then
1016 >       call calc_EAM_preforce_Frho(nlocal,pot)
1017 >    endif
1018 >
1019 >
1020 >  end subroutine do_preforce
1021 >
1022 >
1023 >  subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
1024 >
1025 >    real (kind = dp), dimension(3) :: q_i
1026 >    real (kind = dp), dimension(3) :: q_j
1027 >    real ( kind = dp ), intent(out) :: r_sq
1028 >    real( kind = dp ) :: d(3), scaled(3)
1029 >    integer i
1030 >
1031 >    d(1:3) = q_j(1:3) - q_i(1:3)
1032 >
1033 >    ! Wrap back into periodic box if necessary
1034 >    if ( SIM_uses_PBC ) then
1035 >
1036 >       if( .not.boxIsOrthorhombic ) then
1037 >          ! calc the scaled coordinates.
1038 >
1039 >          scaled = matmul(HmatInv, d)
1040 >
1041 >          ! wrap the scaled coordinates
1042 >
1043 >          scaled = scaled  - anint(scaled)
1044 >
1045 >
1046 >          ! calc the wrapped real coordinates from the wrapped scaled
1047 >          ! coordinates
1048 >
1049 >          d = matmul(Hmat,scaled)
1050 >
1051 >       else
1052 >          ! calc the scaled coordinates.
1053 >
1054 >          do i = 1, 3
1055 >             scaled(i) = d(i) * HmatInv(i,i)
1056 >
1057 >             ! wrap the scaled coordinates
1058 >
1059 >             scaled(i) = scaled(i) - anint(scaled(i))
1060 >
1061 >             ! calc the wrapped real coordinates from the wrapped scaled
1062 >             ! coordinates
1063 >
1064 >             d(i) = scaled(i)*Hmat(i,i)
1065 >          enddo
1066 >       endif
1067 >
1068 >    endif
1069 >
1070 >    r_sq = dot_product(d,d)
1071 >
1072 >  end subroutine get_interatomic_vector
1073 >
1074 >  subroutine zero_work_arrays()
1075 >
1076   #ifdef IS_MPI
1077 <   !! in MPI, we have to look up the unique IDs for each atom
1078 <   unique_id_1 = AtomRowToGlobal(atom1)
1077 >
1078 >    q_Row = 0.0_dp
1079 >    q_Col = 0.0_dp
1080 >
1081 >    q_group_Row = 0.0_dp
1082 >    q_group_Col = 0.0_dp  
1083 >
1084 >    eFrame_Row = 0.0_dp
1085 >    eFrame_Col = 0.0_dp
1086 >
1087 >    A_Row = 0.0_dp
1088 >    A_Col = 0.0_dp
1089 >
1090 >    f_Row = 0.0_dp
1091 >    f_Col = 0.0_dp
1092 >    f_Temp = 0.0_dp
1093 >
1094 >    t_Row = 0.0_dp
1095 >    t_Col = 0.0_dp
1096 >    t_Temp = 0.0_dp
1097 >
1098 >    pot_Row = 0.0_dp
1099 >    pot_Col = 0.0_dp
1100 >    pot_Temp = 0.0_dp
1101 >
1102 >    rf_Row = 0.0_dp
1103 >    rf_Col = 0.0_dp
1104 >    rf_Temp = 0.0_dp
1105 >
1106 > #endif
1107 >
1108 >    if (FF_uses_EAM .and. SIM_uses_EAM) then
1109 >       call clean_EAM()
1110 >    endif
1111 >
1112 >    rf = 0.0_dp
1113 >    tau_Temp = 0.0_dp
1114 >    virial_Temp = 0.0_dp
1115 >  end subroutine zero_work_arrays
1116 >
1117 >  function skipThisPair(atom1, atom2) result(skip_it)
1118 >    integer, intent(in) :: atom1
1119 >    integer, intent(in), optional :: atom2
1120 >    logical :: skip_it
1121 >    integer :: unique_id_1, unique_id_2
1122 >    integer :: me_i,me_j
1123 >    integer :: i
1124 >
1125 >    skip_it = .false.
1126 >
1127 >    !! there are a number of reasons to skip a pair or a particle
1128 >    !! mostly we do this to exclude atoms who are involved in short
1129 >    !! range interactions (bonds, bends, torsions), but we also need
1130 >    !! to exclude some overcounted interactions that result from
1131 >    !! the parallel decomposition
1132 >
1133 > #ifdef IS_MPI
1134 >    !! in MPI, we have to look up the unique IDs for each atom
1135 >    unique_id_1 = AtomRowToGlobal(atom1)
1136   #else
1137 <   !! in the normal loop, the atom numbers are unique
1138 <   unique_id_1 = atom1
1137 >    !! in the normal loop, the atom numbers are unique
1138 >    unique_id_1 = atom1
1139   #endif
1140 <  
1141 <   !! We were called with only one atom, so just check the global exclude
1142 <   !! list for this atom
1143 <   if (.not. present(atom2)) then
1144 <      do i = 1, nExcludes_global
1145 <         if (excludesGlobal(i) == unique_id_1) then
1146 <            skip_it = .true.
1147 <            return
1148 <         end if
1149 <      end do
1150 <      return
1151 <   end if
1152 <  
1140 >
1141 >    !! We were called with only one atom, so just check the global exclude
1142 >    !! list for this atom
1143 >    if (.not. present(atom2)) then
1144 >       do i = 1, nExcludes_global
1145 >          if (excludesGlobal(i) == unique_id_1) then
1146 >             skip_it = .true.
1147 >             return
1148 >          end if
1149 >       end do
1150 >       return
1151 >    end if
1152 >
1153   #ifdef IS_MPI
1154 <   unique_id_2 = AtomColToGlobal(atom2)
1154 >    unique_id_2 = AtomColToGlobal(atom2)
1155   #else
1156 <   unique_id_2 = atom2
1156 >    unique_id_2 = atom2
1157   #endif
1158 <  
1158 >
1159   #ifdef IS_MPI
1160 <   !! this situation should only arise in MPI simulations
1161 <   if (unique_id_1 == unique_id_2) then
1162 <      skip_it = .true.
1163 <      return
1164 <   end if
1165 <  
1166 <   !! this prevents us from doing the pair on multiple processors
1167 <   if (unique_id_1 < unique_id_2) then
1168 <      if (mod(unique_id_1 + unique_id_2,2) == 0) then
1169 <         skip_it = .true.
1170 <         return
1171 <      endif
1172 <   else                
1173 <      if (mod(unique_id_1 + unique_id_2,2) == 1) then
1174 <         skip_it = .true.
1175 <         return
1176 <      endif
1177 <   endif
1160 >    !! this situation should only arise in MPI simulations
1161 >    if (unique_id_1 == unique_id_2) then
1162 >       skip_it = .true.
1163 >       return
1164 >    end if
1165 >
1166 >    !! this prevents us from doing the pair on multiple processors
1167 >    if (unique_id_1 < unique_id_2) then
1168 >       if (mod(unique_id_1 + unique_id_2,2) == 0) then
1169 >          skip_it = .true.
1170 >          return
1171 >       endif
1172 >    else                
1173 >       if (mod(unique_id_1 + unique_id_2,2) == 1) then
1174 >          skip_it = .true.
1175 >          return
1176 >       endif
1177 >    endif
1178   #endif
1179 <  
1180 <   !! the rest of these situations can happen in all simulations:
1181 <   do i = 1, nExcludes_global      
1182 <      if ((excludesGlobal(i) == unique_id_1) .or. &
1183 <           (excludesGlobal(i) == unique_id_2)) then
1184 <         skip_it = .true.
1185 <         return
1186 <      endif
1187 <   enddo
1188 <  
1189 <   do i = 1, nSkipsForAtom(atom1)
1190 <      if (skipsForAtom(atom1, i) .eq. unique_id_2) then
1191 <         skip_it = .true.
1192 <         return
1193 <      endif
1194 <   end do
1195 <  
1196 <   return
1197 < end function skipThisPair
1198 <
1199 < function FF_UsesDirectionalAtoms() result(doesit)
1200 <   logical :: doesit
1201 <   doesit = FF_uses_DirectionalAtoms .or. FF_uses_Dipoles .or. &
1202 <        FF_uses_Quadrupoles .or. FF_uses_Sticky .or. &
1203 <        FF_uses_GayBerne .or. FF_uses_Shapes
1204 < end function FF_UsesDirectionalAtoms
1205 <
1206 < function FF_RequiresPrepairCalc() result(doesit)
1207 <   logical :: doesit
1208 <   doesit = FF_uses_EAM
1209 < end function FF_RequiresPrepairCalc
1210 <
1211 < function FF_RequiresPostpairCalc() result(doesit)
1212 <   logical :: doesit
1213 <   doesit = FF_uses_RF
1248 < end function FF_RequiresPostpairCalc
1249 <
1179 >
1180 >    !! the rest of these situations can happen in all simulations:
1181 >    do i = 1, nExcludes_global      
1182 >       if ((excludesGlobal(i) == unique_id_1) .or. &
1183 >            (excludesGlobal(i) == unique_id_2)) then
1184 >          skip_it = .true.
1185 >          return
1186 >       endif
1187 >    enddo
1188 >
1189 >    do i = 1, nSkipsForAtom(atom1)
1190 >       if (skipsForAtom(atom1, i) .eq. unique_id_2) then
1191 >          skip_it = .true.
1192 >          return
1193 >       endif
1194 >    end do
1195 >
1196 >    return
1197 >  end function skipThisPair
1198 >
1199 >  function FF_UsesDirectionalAtoms() result(doesit)
1200 >    logical :: doesit
1201 >    doesit = FF_uses_DirectionalAtoms
1202 >  end function FF_UsesDirectionalAtoms
1203 >
1204 >  function FF_RequiresPrepairCalc() result(doesit)
1205 >    logical :: doesit
1206 >    doesit = FF_uses_EAM
1207 >  end function FF_RequiresPrepairCalc
1208 >
1209 >  function FF_RequiresPostpairCalc() result(doesit)
1210 >    logical :: doesit
1211 >    doesit = FF_uses_RF
1212 >  end function FF_RequiresPostpairCalc
1213 >
1214   #ifdef PROFILE
1215 < function getforcetime() result(totalforcetime)
1216 <   real(kind=dp) :: totalforcetime
1217 <   totalforcetime = forcetime
1218 < end function getforcetime
1215 >  function getforcetime() result(totalforcetime)
1216 >    real(kind=dp) :: totalforcetime
1217 >    totalforcetime = forcetime
1218 >  end function getforcetime
1219   #endif
1256
1257 !! This cleans componets of force arrays belonging only to fortran
1220  
1221 < subroutine add_stress_tensor(dpair, fpair)
1222 <  
1223 <   real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1224 <  
1225 <   ! because the d vector is the rj - ri vector, and
1226 <   ! because fx, fy, fz are the force on atom i, we need a
1227 <   ! negative sign here:  
1228 <  
1229 <   tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1230 <   tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1231 <   tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1232 <   tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1233 <   tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1234 <   tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1235 <   tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1236 <   tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1237 <   tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1238 <  
1239 <   virial_Temp = virial_Temp + &
1240 <        (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1241 <  
1242 < end subroutine add_stress_tensor
1243 <
1221 >  !! This cleans componets of force arrays belonging only to fortran
1222 >
1223 >  subroutine add_stress_tensor(dpair, fpair)
1224 >
1225 >    real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1226 >
1227 >    ! because the d vector is the rj - ri vector, and
1228 >    ! because fx, fy, fz are the force on atom i, we need a
1229 >    ! negative sign here:  
1230 >
1231 >    tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1232 >    tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1233 >    tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1234 >    tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1235 >    tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1236 >    tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1237 >    tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1238 >    tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1239 >    tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1240 >
1241 >    virial_Temp = virial_Temp + &
1242 >         (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1243 >
1244 >  end subroutine add_stress_tensor
1245 >
1246   end module doForces

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines