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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines