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

Comparing trunk/OOPSE-2.0/src/UseTheForce/doForces.F90 (file contents):
Revision 1930 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
Revision 2268 by gezelter, Fri Jul 29 19:38:27 2005 UTC

# Line 45 | Line 45
45  
46   !! @author Charles F. Vardeman II
47   !! @author Matthew Meineke
48 < !! @version $Id: doForces.F90,v 1.9 2005-01-12 22:40:37 gezelter Exp $, $Date: 2005-01-12 22:40:37 $, $Name: not supported by cvs2svn $, $Revision: 1.9 $
48 > !! @version $Id: doForces.F90,v 1.26 2005-07-29 19:38:27 gezelter Exp $, $Date: 2005-07-29 19:38:27 $, $Name: not supported by cvs2svn $, $Revision: 1.26 $
49  
50  
51   module doForces
# Line 57 | Line 57 | module doForces
57    use neighborLists  
58    use lj
59    use sticky
60 <  use dipole_dipole
61 <  use charge_charge
60 >  use electrostatic_module
61    use reaction_field
62    use gb_pair
63    use shapes
# Line 74 | 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
# Line 81 | Line 81 | module doForces
81    logical, save :: haveRlist = .false.
82    logical, save :: haveNeighborList = .false.
83    logical, save :: haveSIMvariables = .false.
84  logical, save :: havePropertyMap = .false.
84    logical, save :: haveSaneForceField = .false.
85 <  
85 >  logical, save :: haveInteractionMap = .false.
86 >
87    logical, save :: FF_uses_DirectionalAtoms
88    logical, save :: FF_uses_LennardJones
89 <  logical, save :: FF_uses_Electrostatic
90 <  logical, save :: FF_uses_charges
91 <  logical, save :: FF_uses_dipoles
92 <  logical, save :: FF_uses_sticky
89 >  logical, save :: FF_uses_Electrostatics
90 >  logical, save :: FF_uses_Charges
91 >  logical, save :: FF_uses_Dipoles
92 >  logical, save :: FF_uses_Quadrupoles
93 >  logical, save :: FF_uses_Sticky
94 >  logical, save :: FF_uses_StickyPower
95    logical, save :: FF_uses_GayBerne
96    logical, save :: FF_uses_EAM
97    logical, save :: FF_uses_Shapes
# Line 101 | Line 103 | module doForces
103    logical, save :: SIM_uses_Electrostatics
104    logical, save :: SIM_uses_Charges
105    logical, save :: SIM_uses_Dipoles
106 +  logical, save :: SIM_uses_Quadrupoles
107    logical, save :: SIM_uses_Sticky
108 +  logical, save :: SIM_uses_StickyPower
109    logical, save :: SIM_uses_GayBerne
110    logical, save :: SIM_uses_EAM
111    logical, save :: SIM_uses_Shapes
# Line 112 | Line 116 | module doForces
116    logical, save :: SIM_uses_PBC
117    logical, save :: SIM_uses_molecular_cutoffs
118  
119 <  real(kind=dp), save :: rlist, rlistsq
119 >  !!!GO AWAY---------
120 >  !!!!!real(kind=dp), save :: rlist, rlistsq
121  
122    public :: init_FF
123    public :: do_force_loop
124 <  public :: setRlistDF
124 > !  public :: setRlistDF
125 >  !public :: addInteraction
126 >  !public :: setInteractionHash
127 >  !public :: getInteractionHash
128 >  public :: createInteractionMap
129 >  public :: createRcuts
130  
131   #ifdef PROFILE
132    public :: getforcetime
# Line 125 | Line 135 | module doForces
135    integer :: nLoops
136   #endif
137  
138 <  type :: Properties
139 <     logical :: is_Directional   = .false.
140 <     logical :: is_LennardJones  = .false.
141 <     logical :: is_Electrostatic = .false.
142 <     logical :: is_Charge        = .false.
143 <     logical :: is_Dipole        = .false.
144 <     logical :: is_Sticky        = .false.
145 <     logical :: is_GayBerne      = .false.
146 <     logical :: is_EAM           = .false.
137 <     logical :: is_Shape         = .false.
138 <     logical :: is_FLARB         = .false.
139 <  end type Properties
138 >  type, public :: Interaction
139 >     integer :: InteractionHash
140 >     real(kind=dp) :: rCut = 0.0_dp
141 >     real(kind=dp) :: rCutSq = 0.0_dp    
142 >     real(kind=dp) :: rListSq = 0.0_dp
143 >  end type Interaction
144 >  
145 >  type(Interaction), dimension(:,:),allocatable :: InteractionMap
146 >  
147  
148 <  type(Properties), dimension(:),allocatable :: PropertyMap
142 <
148 >  
149   contains
150  
151 <  subroutine setRlistDF( this_rlist )
152 <    
147 <    real(kind=dp) :: this_rlist
148 <
149 <    rlist = this_rlist
150 <    rlistsq = rlist * rlist
151 <    
152 <    haveRlist = .true.
153 <
154 <  end subroutine setRlistDF    
155 <
156 <  subroutine createPropertyMap(status)
151 >
152 >  subroutine createInteractionMap(status)
153      integer :: nAtypes
154 <    integer :: status
154 >    integer, intent(out) :: status
155      integer :: i
156 <    logical :: thisProperty
157 <    real (kind=DP) :: thisDPproperty
156 >    integer :: j
157 >    integer :: ihash
158 >    real(kind=dp) :: myRcut
159 >    !! Test Types
160 >    logical :: i_is_LJ
161 >    logical :: i_is_Elect
162 >    logical :: i_is_Sticky
163 >    logical :: i_is_StickyP
164 >    logical :: i_is_GB
165 >    logical :: i_is_EAM
166 >    logical :: i_is_Shape
167 >    logical :: j_is_LJ
168 >    logical :: j_is_Elect
169 >    logical :: j_is_Sticky
170 >    logical :: j_is_StickyP
171 >    logical :: j_is_GB
172 >    logical :: j_is_EAM
173 >    logical :: j_is_Shape
174 >    
175 >    status = 0  
176  
177 <    status = 0
178 <
177 >    if (.not. associated(atypes)) then
178 >       call handleError("atype", "atypes was not present before call of createDefaultInteractionMap!")
179 >       status = -1
180 >       return
181 >    endif
182 >    
183      nAtypes = getSize(atypes)
184 <
184 >    
185      if (nAtypes == 0) then
186         status = -1
187         return
188      end if
171        
172    if (.not. allocated(PropertyMap)) then
173       allocate(PropertyMap(nAtypes))
174    endif
189  
190 +    if (.not. allocated(InteractionMap)) then
191 +       allocate(InteractionMap(nAtypes,nAtypes))
192 +    endif
193 +        
194      do i = 1, nAtypes
195 <       call getElementProperty(atypes, i, "is_Directional", thisProperty)
196 <       PropertyMap(i)%is_Directional = thisProperty
195 >       call getElementProperty(atypes, i, "is_LennardJones", i_is_LJ)
196 >       call getElementProperty(atypes, i, "is_Electrostatic", i_is_Elect)
197 >       call getElementProperty(atypes, i, "is_Sticky", i_is_Sticky)
198 >       call getElementProperty(atypes, i, "is_StickyPower", i_is_StickyP)
199 >       call getElementProperty(atypes, i, "is_GayBerne", i_is_GB)
200 >       call getElementProperty(atypes, i, "is_EAM", i_is_EAM)
201 >       call getElementProperty(atypes, i, "is_Shape", i_is_Shape)
202  
203 <       call getElementProperty(atypes, i, "is_LennardJones", thisProperty)
181 <       PropertyMap(i)%is_LennardJones = thisProperty
182 <      
183 <       call getElementProperty(atypes, i, "is_Electrostatic", thisProperty)
184 <       PropertyMap(i)%is_Electrostatic = thisProperty
203 >       do j = i, nAtypes
204  
205 <       call getElementProperty(atypes, i, "is_Charge", thisProperty)
206 <       PropertyMap(i)%is_Charge = thisProperty
188 <      
189 <       call getElementProperty(atypes, i, "is_Dipole", thisProperty)
190 <       PropertyMap(i)%is_Dipole = thisProperty
205 >          iHash = 0
206 >          myRcut = 0.0_dp
207  
208 <       call getElementProperty(atypes, i, "is_Sticky", thisProperty)
209 <       PropertyMap(i)%is_Sticky = thisProperty
208 >          call getElementProperty(atypes, j, "is_LennardJones", j_is_LJ)
209 >          call getElementProperty(atypes, j, "is_Electrostatic", j_is_Elect)
210 >          call getElementProperty(atypes, j, "is_Sticky", j_is_Sticky)
211 >          call getElementProperty(atypes, j, "is_StickyPower", j_is_StickyP)
212 >          call getElementProperty(atypes, j, "is_GayBerne", j_is_GB)
213 >          call getElementProperty(atypes, j, "is_EAM", j_is_EAM)
214 >          call getElementProperty(atypes, j, "is_Shape", j_is_Shape)
215  
216 <       call getElementProperty(atypes, i, "is_GayBerne", thisProperty)
217 <       PropertyMap(i)%is_GayBerne = thisProperty
216 >          if (i_is_LJ .and. j_is_LJ) then
217 >             iHash = ior(iHash, LJ_PAIR)            
218 >          endif
219 >          
220 >          if (i_is_Elect .and. j_is_Elect) then
221 >             iHash = ior(iHash, ELECTROSTATIC_PAIR)
222 >          endif
223 >          
224 >          if (i_is_Sticky .and. j_is_Sticky) then
225 >             iHash = ior(iHash, STICKY_PAIR)
226 >          endif
227  
228 <       call getElementProperty(atypes, i, "is_EAM", thisProperty)
229 <       PropertyMap(i)%is_EAM = thisProperty
228 >          if (i_is_StickyP .and. j_is_StickyP) then
229 >             iHash = ior(iHash, STICKYPOWER_PAIR)
230 >          endif
231  
232 <       call getElementProperty(atypes, i, "is_Shape", thisProperty)
233 <       PropertyMap(i)%is_Shape = thisProperty
232 >          if (i_is_EAM .and. j_is_EAM) then
233 >             iHash = ior(iHash, EAM_PAIR)
234 >          endif
235  
236 <       call getElementProperty(atypes, i, "is_FLARB", thisProperty)
237 <       PropertyMap(i)%is_FLARB = thisProperty
236 >          if (i_is_GB .and. j_is_GB) iHash = ior(iHash, GAYBERNE_PAIR)
237 >          if (i_is_GB .and. j_is_LJ) iHash = ior(iHash, GAYBERNE_LJ)
238 >          if (i_is_LJ .and. j_is_GB) iHash = ior(iHash, GAYBERNE_LJ)
239 >
240 >          if (i_is_Shape .and. j_is_Shape) iHash = ior(iHash, SHAPE_PAIR)
241 >          if (i_is_Shape .and. j_is_LJ) iHash = ior(iHash, SHAPE_LJ)
242 >          if (i_is_LJ .and. j_is_Shape) iHash = ior(iHash, SHAPE_LJ)
243 >
244 >
245 >          InteractionMap(i,j)%InteractionHash = iHash
246 >          InteractionMap(j,i)%InteractionHash = iHash
247 >
248 >       end do
249 >
250      end do
251  
252 <    havePropertyMap = .true.
252 >    haveInteractionMap = .true.
253 >  end subroutine createInteractionMap
254  
255 <  end subroutine createPropertyMap
255 >  ! Query each potential and return the cutoff for that potential. We
256 >  ! build the neighbor list based on the largest cutoff value for that
257 >  ! atype. Each potential can decide whether to calculate the force for
258 >  ! that atype based upon it's own cutoff.
259 >  
260 >  subroutine createRcuts(defaultRcut, defaultSkinThickness, stat)
261  
262 +    real(kind=dp), intent(in), optional :: defaultRCut, defaultSkinThickness
263 +    integer :: iMap
264 +    integer :: map_i,map_j
265 +    real(kind=dp) :: thisRCut = 0.0_dp
266 +    real(kind=dp) :: actualCutoff = 0.0_dp
267 +    integer, intent(out) :: stat
268 +    integer :: nAtypes
269 +    integer :: myStatus
270 +
271 +    stat = 0
272 +    if (.not. haveInteractionMap) then
273 +
274 +       call createInteractionMap(myStatus)
275 +
276 +       if (myStatus .ne. 0) then
277 +          write(default_error, *) 'createInteractionMap failed in doForces!'
278 +          stat = -1
279 +          return
280 +       endif
281 +    endif
282 +
283 +    nAtypes = getSize(atypes)
284 +    !! If we pass a default rcut, set all atypes to that cutoff distance
285 +    if(present(defaultRList)) then
286 +       InteractionMap(:,:)%rCut = defaultRCut
287 +       InteractionMap(:,:)%rCutSq = defaultRCut*defaultRCut
288 +       InteractionMap(:,:)%rListSq = (defaultRCut+defaultSkinThickness)**2
289 +       haveRlist = .true.
290 +       return
291 +    end if
292 +
293 +    do map_i = 1,nAtypes
294 +       do map_j = map_i,nAtypes
295 +          iMap = InteractionMap(map_i, map_j)%InteractionHash
296 +          
297 +          if ( iand(iMap, LJ_PAIR).ne.0 ) then
298 +             ! thisRCut = getLJCutOff(map_i,map_j)
299 +             if (thisRcut > actualCutoff) actualCutoff = thisRcut
300 +          endif
301 +          
302 +          if ( iand(iMap, ELECTROSTATIC_PAIR).ne.0 ) then
303 +             ! thisRCut = getElectrostaticCutOff(map_i,map_j)
304 +             if (thisRcut > actualCutoff) actualCutoff = thisRcut
305 +          endif
306 +          
307 +          if ( iand(iMap, STICKY_PAIR).ne.0 ) then
308 +             ! thisRCut = getStickyCutOff(map_i,map_j)
309 +              if (thisRcut > actualCutoff) actualCutoff = thisRcut
310 +           endif
311 +          
312 +           if ( iand(iMap, STICKYPOWER_PAIR).ne.0 ) then
313 +              ! thisRCut = getStickyPowerCutOff(map_i,map_j)
314 +              if (thisRcut > actualCutoff) actualCutoff = thisRcut
315 +           endif
316 +          
317 +           if ( iand(iMap, GAYBERNE_PAIR).ne.0 ) then
318 +              ! thisRCut = getGayberneCutOff(map_i,map_j)
319 +              if (thisRcut > actualCutoff) actualCutoff = thisRcut
320 +           endif
321 +          
322 +           if ( iand(iMap, GAYBERNE_LJ).ne.0 ) then
323 + !              thisRCut = getGaybrneLJCutOff(map_i,map_j)
324 +              if (thisRcut > actualCutoff) actualCutoff = thisRcut
325 +           endif
326 +          
327 +           if ( iand(iMap, EAM_PAIR).ne.0 ) then      
328 + !              thisRCut = getEAMCutOff(map_i,map_j)
329 +              if (thisRcut > actualCutoff) actualCutoff = thisRcut
330 +           endif
331 +          
332 +           if ( iand(iMap, SHAPE_PAIR).ne.0 ) then      
333 + !              thisRCut = getShapeCutOff(map_i,map_j)
334 +              if (thisRcut > actualCutoff) actualCutoff = thisRcut
335 +           endif
336 +          
337 +           if ( iand(iMap, SHAPE_LJ).ne.0 ) then      
338 + !              thisRCut = getShapeLJCutOff(map_i,map_j)
339 +              if (thisRcut > actualCutoff) actualCutoff = thisRcut
340 +           endif
341 +           InteractionMap(map_i, map_j)%rCut = actualCutoff
342 +           InteractionMap(map_i, map_j)%rCutSq = actualCutoff * actualCutoff
343 +           InteractionMap(map_i, map_j)%rListSq = (actualCutoff + skinThickness)**2
344 +
345 +           InteractionMap(map_j, map_i)%rCut = InteractionMap(map_i, map_j)%rCut
346 +           InteractionMap(map_j, map_i)%rCutSq = InteractionMap(map_i, map_j)%rCutSq
347 +           InteractionMap(map_j, map_i)%rListSq = InteractionMap(map_i, map_j)%rListSq
348 +        end do
349 +     end do
350 +     ! now the groups
351 +
352 +
353 +
354 +     haveRlist = .true.
355 +  end subroutine createRcuts
356 +
357 +
358 + !!! THIS GOES AWAY FOR SIZE DEPENDENT CUTOFF
359 + !!$  subroutine setRlistDF( this_rlist )
360 + !!$
361 + !!$   real(kind=dp) :: this_rlist
362 + !!$
363 + !!$    rlist = this_rlist
364 + !!$    rlistsq = rlist * rlist
365 + !!$
366 + !!$    haveRlist = .true.
367 + !!$
368 + !!$  end subroutine setRlistDF
369 +
370 +
371    subroutine setSimVariables()
372      SIM_uses_DirectionalAtoms = SimUsesDirectionalAtoms()
373      SIM_uses_LennardJones = SimUsesLennardJones()
# Line 216 | Line 375 | contains
375      SIM_uses_Charges = SimUsesCharges()
376      SIM_uses_Dipoles = SimUsesDipoles()
377      SIM_uses_Sticky = SimUsesSticky()
378 +    SIM_uses_StickyPower = SimUsesStickyPower()
379      SIM_uses_GayBerne = SimUsesGayBerne()
380      SIM_uses_EAM = SimUsesEAM()
381      SIM_uses_Shapes = SimUsesShapes()
# Line 236 | Line 396 | contains
396      integer :: myStatus
397  
398      error = 0
239    
240    if (.not. havePropertyMap) then
399  
400 <       myStatus = 0
401 <
402 <       call createPropertyMap(myStatus)
403 <
400 >    if (.not. haveInteractionMap) then
401 >      
402 >       myStatus = 0      
403 >       call createInteractionMap(myStatus)
404 >      
405         if (myStatus .ne. 0) then
406 <          write(default_error, *) 'createPropertyMap failed in doForces!'
406 >          write(default_error, *) 'createInteractionMap failed in doForces!'
407            error = -1
408            return
409         endif
# Line 281 | Line 440 | contains
440   #endif
441      return
442    end subroutine doReadyCheck
284    
443  
444 +
445    subroutine init_FF(use_RF_c, thisStat)
446  
447      logical, intent(in) :: use_RF_c
# Line 297 | Line 456 | contains
456  
457      !! Fortran's version of a cast:
458      FF_uses_RF = use_RF_c
459 <    
459 >
460      !! init_FF is called *after* all of the atom types have been
461      !! defined in atype_module using the new_atype subroutine.
462      !!
463      !! this will scan through the known atypes and figure out what
464      !! interactions are used by the force field.    
465 <  
465 >
466      FF_uses_DirectionalAtoms = .false.
467      FF_uses_LennardJones = .false.
468 <    FF_uses_Electrostatic = .false.
468 >    FF_uses_Electrostatics = .false.
469      FF_uses_Charges = .false.    
470      FF_uses_Dipoles = .false.
471      FF_uses_Sticky = .false.
472 +    FF_uses_StickyPower = .false.
473      FF_uses_GayBerne = .false.
474      FF_uses_EAM = .false.
475      FF_uses_Shapes = .false.
476      FF_uses_FLARB = .false.
477 <    
477 >
478      call getMatchingElementList(atypes, "is_Directional", .true., &
479           nMatches, MatchList)
480      if (nMatches .gt. 0) FF_uses_DirectionalAtoms = .true.
# Line 322 | Line 482 | contains
482      call getMatchingElementList(atypes, "is_LennardJones", .true., &
483           nMatches, MatchList)
484      if (nMatches .gt. 0) FF_uses_LennardJones = .true.
485 <    
485 >
486      call getMatchingElementList(atypes, "is_Electrostatic", .true., &
487           nMatches, MatchList)
488      if (nMatches .gt. 0) then
489 <       FF_uses_Electrostatic = .true.
489 >       FF_uses_Electrostatics = .true.
490      endif
491  
492      call getMatchingElementList(atypes, "is_Charge", .true., &
493           nMatches, MatchList)
494      if (nMatches .gt. 0) then
495 <       FF_uses_charges = .true.  
496 <       FF_uses_electrostatic = .true.
495 >       FF_uses_Charges = .true.  
496 >       FF_uses_Electrostatics = .true.
497      endif
498 <    
498 >
499      call getMatchingElementList(atypes, "is_Dipole", .true., &
500           nMatches, MatchList)
501      if (nMatches .gt. 0) then
502 <       FF_uses_dipoles = .true.
503 <       FF_uses_electrostatic = .true.
502 >       FF_uses_Dipoles = .true.
503 >       FF_uses_Electrostatics = .true.
504         FF_uses_DirectionalAtoms = .true.
505      endif
506 <    
506 >
507 >    call getMatchingElementList(atypes, "is_Quadrupole", .true., &
508 >         nMatches, MatchList)
509 >    if (nMatches .gt. 0) then
510 >       FF_uses_Quadrupoles = .true.
511 >       FF_uses_Electrostatics = .true.
512 >       FF_uses_DirectionalAtoms = .true.
513 >    endif
514 >
515      call getMatchingElementList(atypes, "is_Sticky", .true., nMatches, &
516           MatchList)
517      if (nMatches .gt. 0) then
518         FF_uses_Sticky = .true.
519         FF_uses_DirectionalAtoms = .true.
520      endif
521 +
522 +    call getMatchingElementList(atypes, "is_StickyPower", .true., nMatches, &
523 +         MatchList)
524 +    if (nMatches .gt. 0) then
525 +       FF_uses_StickyPower = .true.
526 +       FF_uses_DirectionalAtoms = .true.
527 +    endif
528      
529      call getMatchingElementList(atypes, "is_GayBerne", .true., &
530           nMatches, MatchList)
# Line 357 | Line 532 | contains
532         FF_uses_GayBerne = .true.
533         FF_uses_DirectionalAtoms = .true.
534      endif
535 <    
535 >
536      call getMatchingElementList(atypes, "is_EAM", .true., nMatches, MatchList)
537      if (nMatches .gt. 0) FF_uses_EAM = .true.
538 <    
538 >
539      call getMatchingElementList(atypes, "is_Shape", .true., &
540           nMatches, MatchList)
541      if (nMatches .gt. 0) then
# Line 374 | Line 549 | contains
549  
550      !! Assume sanity (for the sake of argument)
551      haveSaneForceField = .true.
552 <    
552 >
553      !! check to make sure the FF_uses_RF setting makes sense
554 <    
554 >
555      if (FF_uses_dipoles) then
556         if (FF_uses_RF) then
557            dielect = getDielect()
# Line 389 | Line 564 | contains
564            haveSaneForceField = .false.
565            return
566         endif
567 <    endif
567 >    endif
568  
569      !sticky module does not contain check_sticky_FF anymore
570      !if (FF_uses_sticky) then
# Line 402 | Line 577 | contains
577      !endif
578  
579      if (FF_uses_EAM) then
580 <         call init_EAM_FF(my_status)
580 >       call init_EAM_FF(my_status)
581         if (my_status /= 0) then
582            write(default_error, *) "init_EAM_FF returned a bad status"
583            thisStat = -1
# Line 422 | Line 597 | contains
597  
598      if (FF_uses_GayBerne .and. FF_uses_LennardJones) then
599      endif
600 <    
600 >
601      if (.not. haveNeighborList) then
602         !! Create neighbor lists
603         call expandNeighborList(nLocal, my_status)
# Line 432 | Line 607 | contains
607            return
608         endif
609         haveNeighborList = .true.
610 <    endif    
611 <    
610 >    endif
611 >
612    end subroutine init_FF
438  
613  
614 +
615    !! Does force loop over i,j pairs. Calls do_pair to calculates forces.
616    !------------------------------------------------------------->
617    subroutine do_force_loop(q, q_group, A, eFrame, f, t, tau, pot, &
# Line 486 | Line 661 | contains
661      integer :: localError
662      integer :: propPack_i, propPack_j
663      integer :: loopStart, loopEnd, loop
664 <
664 >    integer :: iMap
665      real(kind=dp) :: listSkin = 1.0  
666 <    
666 >
667      !! initialize local variables  
668 <    
668 >
669   #ifdef IS_MPI
670      pot_local = 0.0_dp
671      nAtomsInRow   = getNatomsInRow(plan_atom_row)
# Line 500 | Line 675 | contains
675   #else
676      natoms = nlocal
677   #endif
678 <    
678 >
679      call doReadyCheck(localError)
680      if ( localError .ne. 0 ) then
681         call handleError("do_force_loop", "Not Initialized")
# Line 508 | Line 683 | contains
683         return
684      end if
685      call zero_work_arrays()
686 <        
686 >
687      do_pot = do_pot_c
688      do_stress = do_stress_c
689 <    
689 >
690      ! Gather all information needed by all force loops:
691 <    
691 >
692   #ifdef IS_MPI    
693 <    
693 >
694      call gather(q, q_Row, plan_atom_row_3d)
695      call gather(q, q_Col, plan_atom_col_3d)
696  
697      call gather(q_group, q_group_Row, plan_group_row_3d)
698      call gather(q_group, q_group_Col, plan_group_col_3d)
699 <        
699 >
700      if (FF_UsesDirectionalAtoms() .and. SIM_uses_DirectionalAtoms) then
701         call gather(eFrame, eFrame_Row, plan_atom_row_rotation)
702         call gather(eFrame, eFrame_Col, plan_atom_col_rotation)
703 <      
703 >
704         call gather(A, A_Row, plan_atom_row_rotation)
705         call gather(A, A_Col, plan_atom_col_rotation)
706      endif
707 <    
707 >
708   #endif
709 <    
709 >
710      !! Begin force loop timing:
711   #ifdef PROFILE
712      call cpu_time(forceTimeInitial)
713      nloops = nloops + 1
714   #endif
715 <    
715 >
716      loopEnd = PAIR_LOOP
717      if (FF_RequiresPrepairCalc() .and. SIM_requires_prepair_calc) then
718         loopStart = PREPAIR_LOOP
# Line 552 | Line 727 | contains
727         if (loop .eq. loopStart) then
728   #ifdef IS_MPI
729            call checkNeighborList(nGroupsInRow, q_group_row, listSkin, &
730 <             update_nlist)
730 >               update_nlist)
731   #else
732            call checkNeighborList(nGroups, q_group, listSkin, &
733 <             update_nlist)
733 >               update_nlist)
734   #endif
735         endif
736 <      
736 >
737         if (update_nlist) then
738            !! save current configuration and construct neighbor list
739   #ifdef IS_MPI
# Line 569 | Line 744 | contains
744            neighborListSize = size(list)
745            nlist = 0
746         endif
747 <      
747 >
748         istart = 1
749   #ifdef IS_MPI
750         iend = nGroupsInRow
# Line 578 | Line 753 | contains
753   #endif
754         outer: do i = istart, iend
755  
756 <          if (update_nlist) point(i) = nlist + 1
757 <          
756 > #ifdef IS_MPI
757 >             me_i = atid_row(i)
758 > #else
759 >             me_i = atid(i)
760 > #endif
761 >
762 >          if (update_nlist) point(i) = nlist + 1
763 >
764            n_in_i = groupStartRow(i+1) - groupStartRow(i)
765 <          
765 >
766            if (update_nlist) then
767   #ifdef IS_MPI
768               jstart = 1
# Line 596 | Line 777 | contains
777               ! make sure group i has neighbors
778               if (jstart .gt. jend) cycle outer
779            endif
780 <          
780 >
781            do jnab = jstart, jend
782               if (update_nlist) then
783                  j = jnab
# Line 605 | Line 786 | contains
786               endif
787  
788   #ifdef IS_MPI
789 +             me_j = atid_col(j)
790               call get_interatomic_vector(q_group_Row(:,i), &
791                    q_group_Col(:,j), d_grp, rgrpsq)
792   #else
793 +             me_j = atid(j)
794               call get_interatomic_vector(q_group(:,i), &
795                    q_group(:,j), d_grp, rgrpsq)
796   #endif
797  
798 <             if (rgrpsq < rlistsq) then
798 >             if (rgrpsq < InteractionMap(me_i,me_j)%rListsq) then
799                  if (update_nlist) then
800                     nlist = nlist + 1
801 <                  
801 >
802                     if (nlist > neighborListSize) then
803   #ifdef IS_MPI                
804                        call expandNeighborList(nGroupsInRow, listerror)
# Line 629 | Line 812 | contains
812                        end if
813                        neighborListSize = size(list)
814                     endif
815 <                  
815 >
816                     list(nlist) = j
817                  endif
818 <                
818 >
819                  if (loop .eq. PAIR_LOOP) then
820                     vij = 0.0d0
821                     fij(1:3) = 0.0d0
822                  endif
823 <                
823 >
824                  call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, &
825                       in_switching_region)
826 <                
826 >
827                  n_in_j = groupStartCol(j+1) - groupStartCol(j)
828 <                
828 >
829                  do ia = groupStartRow(i), groupStartRow(i+1)-1
830 <                  
830 >
831                     atom1 = groupListRow(ia)
832 <                  
832 >
833                     inner: do jb = groupStartCol(j), groupStartCol(j+1)-1
834 <                      
834 >
835                        atom2 = groupListCol(jb)
836 <                      
836 >
837                        if (skipThisPair(atom1, atom2)) cycle inner
838  
839                        if ((n_in_i .eq. 1).and.(n_in_j .eq. 1)) then
# Line 692 | Line 875 | contains
875                        endif
876                     enddo inner
877                  enddo
878 <                
878 >
879                  if (loop .eq. PAIR_LOOP) then
880                     if (in_switching_region) then
881                        swderiv = vij*dswdr/rgrp
882                        fij(1) = fij(1) + swderiv*d_grp(1)
883                        fij(2) = fij(2) + swderiv*d_grp(2)
884                        fij(3) = fij(3) + swderiv*d_grp(3)
885 <                      
885 >
886                        do ia=groupStartRow(i), groupStartRow(i+1)-1
887                           atom1=groupListRow(ia)
888                           mf = mfactRow(atom1)
# Line 713 | Line 896 | contains
896                           f(3,atom1) = f(3,atom1) + swderiv*d_grp(3)*mf
897   #endif
898                        enddo
899 <                      
899 >
900                        do jb=groupStartCol(j), groupStartCol(j+1)-1
901                           atom2=groupListCol(jb)
902                           mf = mfactCol(atom2)
# Line 728 | Line 911 | contains
911   #endif
912                        enddo
913                     endif
914 <                  
914 >
915                     if (do_stress) call add_stress_tensor(d_grp, fij)
916                  endif
917               end if
918            enddo
919         enddo outer
920 <      
920 >
921         if (update_nlist) then
922   #ifdef IS_MPI
923            point(nGroupsInRow + 1) = nlist + 1
# Line 748 | Line 931 | contains
931               update_nlist = .false.                              
932            endif
933         endif
934 <            
934 >
935         if (loop .eq. PREPAIR_LOOP) then
936            call do_preforce(nlocal, pot)
937         endif
938 <      
938 >
939      enddo
940 <    
940 >
941      !! Do timing
942   #ifdef PROFILE
943      call cpu_time(forceTimeFinal)
944      forceTime = forceTime + forceTimeFinal - forceTimeInitial
945   #endif    
946 <    
946 >
947   #ifdef IS_MPI
948      !!distribute forces
949 <    
949 >
950      f_temp = 0.0_dp
951      call scatter(f_Row,f_temp,plan_atom_row_3d)
952      do i = 1,nlocal
953         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
954      end do
955 <    
955 >
956      f_temp = 0.0_dp
957      call scatter(f_Col,f_temp,plan_atom_col_3d)
958      do i = 1,nlocal
959         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
960      end do
961 <    
961 >
962      if (FF_UsesDirectionalAtoms() .and. SIM_uses_DirectionalAtoms) then
963         t_temp = 0.0_dp
964         call scatter(t_Row,t_temp,plan_atom_row_3d)
# Line 784 | Line 967 | contains
967         end do
968         t_temp = 0.0_dp
969         call scatter(t_Col,t_temp,plan_atom_col_3d)
970 <      
970 >
971         do i = 1,nlocal
972            t(1:3,i) = t(1:3,i) + t_temp(1:3,i)
973         end do
974      endif
975 <    
975 >
976      if (do_pot) then
977         ! scatter/gather pot_row into the members of my column
978         call scatter(pot_Row, pot_Temp, plan_atom_row)
979 <      
979 >
980         ! scatter/gather pot_local into all other procs
981         ! add resultant to get total pot
982         do i = 1, nlocal
983            pot_local = pot_local + pot_Temp(i)
984         enddo
985 <      
985 >
986         pot_Temp = 0.0_DP
987 <      
987 >
988         call scatter(pot_Col, pot_Temp, plan_atom_col)
989         do i = 1, nlocal
990            pot_local = pot_local + pot_Temp(i)
991         enddo
992 <      
992 >
993      endif
994   #endif
995 <    
995 >
996      if (FF_RequiresPostpairCalc() .and. SIM_requires_postpair_calc) then
997 <      
997 >
998         if (FF_uses_RF .and. SIM_uses_RF) then
999 <          
999 >
1000   #ifdef IS_MPI
1001            call scatter(rf_Row,rf,plan_atom_row_3d)
1002            call scatter(rf_Col,rf_Temp,plan_atom_col_3d)
# Line 821 | Line 1004 | contains
1004               rf(1:3,i) = rf(1:3,i) + rf_Temp(1:3,i)
1005            end do
1006   #endif
1007 <          
1007 >
1008            do i = 1, nLocal
1009 <            
1009 >
1010               rfpot = 0.0_DP
1011   #ifdef IS_MPI
1012               me_i = atid_row(i)
1013   #else
1014               me_i = atid(i)
1015   #endif
1016 +             iMap = InteractionMap(me_i, me_j)%InteractionHash
1017              
1018 <             if (PropertyMap(me_i)%is_Dipole) then
1019 <                
1018 >             if ( iand(iMap, ELECTROSTATIC_PAIR).ne.0 ) then
1019 >
1020                  mu_i = getDipoleMoment(me_i)
1021 <                
1021 >
1022                  !! The reaction field needs to include a self contribution
1023                  !! to the field:
1024                  call accumulate_self_rf(i, mu_i, eFrame)
# Line 845 | Line 1029 | contains
1029                  pot_local = pot_local + rfpot
1030   #else
1031                  pot = pot + rfpot
1032 <      
1032 >
1033   #endif
1034 <             endif            
1034 >             endif
1035            enddo
1036         endif
1037      endif
1038 <    
1039 <    
1038 >
1039 >
1040   #ifdef IS_MPI
1041 <    
1041 >
1042      if (do_pot) then
1043         pot = pot + pot_local
1044         !! we assume the c code will do the allreduce to get the total potential
1045         !! we could do it right here if we needed to...
1046      endif
1047 <    
1047 >
1048      if (do_stress) then
1049         call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, &
1050              mpi_comm_world,mpi_err)
1051         call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, &
1052              mpi_comm_world,mpi_err)
1053      endif
1054 <    
1054 >
1055   #else
1056 <    
1056 >
1057      if (do_stress) then
1058         tau = tau_Temp
1059         virial = virial_Temp
1060      endif
1061 <    
1061 >
1062   #endif
1063 <      
1063 >
1064    end subroutine do_force_loop
1065 <  
1065 >
1066    subroutine do_pair(i, j, rijsq, d, sw, do_pot, &
1067         eFrame, A, f, t, pot, vpair, fpair)
1068  
# Line 895 | Line 1079 | contains
1079      real ( kind = dp ), intent(inout) :: rijsq
1080      real ( kind = dp )                :: r
1081      real ( kind = dp ), intent(inout) :: d(3)
1082 +    real ( kind = dp ) :: ebalance
1083      integer :: me_i, me_j
1084  
1085 +    integer :: iMap
1086 +
1087      r = sqrt(rijsq)
1088      vpair = 0.0d0
1089      fpair(1:3) = 0.0d0
# Line 909 | Line 1096 | contains
1096      me_j = atid(j)
1097   #endif
1098  
1099 < !    write(*,*) i, j, me_i, me_j
913 <    
914 <    if (FF_uses_LennardJones .and. SIM_uses_LennardJones) then
915 <      
916 <       if ( PropertyMap(me_i)%is_LennardJones .and. &
917 <            PropertyMap(me_j)%is_LennardJones ) then
918 <          call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
919 <       endif
920 <      
921 <    endif
922 <    
923 <    if (FF_uses_charges .and. SIM_uses_charges) then
924 <      
925 <       if (PropertyMap(me_i)%is_Charge .and. PropertyMap(me_j)%is_Charge) then
926 <          call do_charge_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
927 <               pot, f, do_pot)
928 <       endif
929 <      
930 <    endif
931 <    
932 <    if (FF_uses_dipoles .and. SIM_uses_dipoles) then
933 <      
934 <       if ( PropertyMap(me_i)%is_Dipole .and. PropertyMap(me_j)%is_Dipole) then
935 <          call do_dipole_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
936 <               pot, eFrame, f, t, do_pot)
937 <          if (FF_uses_RF .and. SIM_uses_RF) then
938 <             call accumulate_rf(i, j, r, eFrame, sw)
939 <             call rf_correct_forces(i, j, d, r, eFrame, sw, f, fpair)
940 <          endif
941 <       endif
1099 >    iMap = InteractionMap(me_i, me_j)%InteractionHash
1100  
1101 +    if ( iand(iMap, LJ_PAIR).ne.0 ) then
1102 +       call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
1103      endif
1104  
1105 <    if (FF_uses_Sticky .and. SIM_uses_sticky) then
1105 >    if ( iand(iMap, ELECTROSTATIC_PAIR).ne.0 ) then
1106 >       call doElectrostaticPair(i, j, d, r, rijsq, sw, vpair, fpair, &
1107 >            pot, eFrame, f, t, do_pot)
1108  
1109 <       if ( PropertyMap(me_i)%is_Sticky .and. PropertyMap(me_j)%is_Sticky) then
1110 <          call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1111 <               pot, A, f, t, do_pot)
1109 >       if (FF_uses_RF .and. SIM_uses_RF) then
1110 >
1111 >          ! CHECK ME (RF needs to know about all electrostatic types)
1112 >          call accumulate_rf(i, j, r, eFrame, sw)
1113 >          call rf_correct_forces(i, j, d, r, eFrame, sw, f, fpair)
1114         endif
1115 <      
1115 >
1116      endif
1117  
1118 +    if ( iand(iMap, STICKY_PAIR).ne.0 ) then
1119 +       call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1120 +            pot, A, f, t, do_pot)
1121 +    endif
1122  
1123 <    if (FF_uses_GayBerne .and. SIM_uses_GayBerne) then
1124 <      
1125 <       if ( PropertyMap(me_i)%is_GayBerne .and. &
958 <            PropertyMap(me_j)%is_GayBerne) then
959 <          call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
960 <               pot, A, f, t, do_pot)
961 <       endif
962 <      
1123 >    if ( iand(iMap, STICKYPOWER_PAIR).ne.0 ) then
1124 >       call do_sticky_power_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1125 >            pot, A, f, t, do_pot)
1126      endif
1127 +
1128 +    if ( iand(iMap, GAYBERNE_PAIR).ne.0 ) then
1129 +       call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1130 +            pot, A, f, t, do_pot)
1131 +    endif
1132      
1133 <    if (FF_uses_EAM .and. SIM_uses_EAM) then
1134 <      
1135 <       if ( PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) then
968 <          call do_eam_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, &
969 <               do_pot)
970 <       endif
971 <      
1133 >    if ( iand(iMap, GAYBERNE_LJ).ne.0 ) then
1134 > !      call do_gblj_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1135 > !           pot, A, f, t, do_pot)
1136      endif
1137  
1138 <
1139 < !    write(*,*) PropertyMap(me_i)%is_Shape,PropertyMap(me_j)%is_Shape
1138 >    if ( iand(iMap, EAM_PAIR).ne.0 ) then      
1139 >       call do_eam_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, &
1140 >            do_pot)
1141 >    endif
1142  
1143 <    if (FF_uses_Shapes .and. SIM_uses_Shapes) then
1144 <       if ( PropertyMap(me_i)%is_Shape .and. &
1145 <            PropertyMap(me_j)%is_Shape ) then
980 <          call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
981 <               pot, A, f, t, do_pot)
982 <       endif
983 <      
1143 >    if ( iand(iMap, SHAPE_PAIR).ne.0 ) then      
1144 >       call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1145 >            pot, A, f, t, do_pot)
1146      endif
1147 +
1148 +    if ( iand(iMap, SHAPE_LJ).ne.0 ) then      
1149 +       call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1150 +            pot, A, f, t, do_pot)
1151 +    endif
1152      
1153    end subroutine do_pair
1154  
1155    subroutine do_prepair(i, j, rijsq, d, sw, rcijsq, dc, &
1156         do_pot, do_stress, eFrame, A, f, t, pot)
1157  
1158 <   real( kind = dp ) :: pot, sw
1159 <   real( kind = dp ), dimension(9,nLocal) :: eFrame
1160 <   real (kind=dp), dimension(9,nLocal) :: A
1161 <   real (kind=dp), dimension(3,nLocal) :: f
1162 <   real (kind=dp), dimension(3,nLocal) :: t
996 <  
997 <   logical, intent(inout) :: do_pot, do_stress
998 <   integer, intent(in) :: i, j
999 <   real ( kind = dp ), intent(inout)    :: rijsq, rcijsq
1000 <   real ( kind = dp )                :: r, rc
1001 <   real ( kind = dp ), intent(inout) :: d(3), dc(3)
1002 <  
1003 <   logical :: is_EAM_i, is_EAM_j
1004 <  
1005 <   integer :: me_i, me_j
1006 <  
1158 >    real( kind = dp ) :: pot, sw
1159 >    real( kind = dp ), dimension(9,nLocal) :: eFrame
1160 >    real (kind=dp), dimension(9,nLocal) :: A
1161 >    real (kind=dp), dimension(3,nLocal) :: f
1162 >    real (kind=dp), dimension(3,nLocal) :: t
1163  
1164 <    r = sqrt(rijsq)
1165 <    if (SIM_uses_molecular_cutoffs) then
1166 <       rc = sqrt(rcijsq)
1167 <    else
1168 <       rc = r
1013 <    endif
1014 <  
1164 >    logical, intent(inout) :: do_pot, do_stress
1165 >    integer, intent(in) :: i, j
1166 >    real ( kind = dp ), intent(inout)    :: rijsq, rcijsq
1167 >    real ( kind = dp )                :: r, rc
1168 >    real ( kind = dp ), intent(inout) :: d(3), dc(3)
1169  
1170 +    integer :: me_i, me_j, iMap
1171 +
1172   #ifdef IS_MPI  
1173 <   me_i = atid_row(i)
1174 <   me_j = atid_col(j)  
1173 >    me_i = atid_row(i)
1174 >    me_j = atid_col(j)  
1175   #else  
1176 <   me_i = atid(i)
1177 <   me_j = atid(j)  
1176 >    me_i = atid(i)
1177 >    me_j = atid(j)  
1178   #endif
1023  
1024   if (FF_uses_EAM .and. SIM_uses_EAM) then
1025      
1026      if (PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) &
1027           call calc_EAM_prepair_rho(i, j, d, r, rijsq )
1028      
1029   endif
1030  
1031 end subroutine do_prepair
1032
1033
1034 subroutine do_preforce(nlocal,pot)
1035   integer :: nlocal
1036   real( kind = dp ) :: pot
1037  
1038   if (FF_uses_EAM .and. SIM_uses_EAM) then
1039      call calc_EAM_preforce_Frho(nlocal,pot)
1040   endif
1041  
1042  
1043 end subroutine do_preforce
1044
1045
1046 subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
1047  
1048   real (kind = dp), dimension(3) :: q_i
1049   real (kind = dp), dimension(3) :: q_j
1050   real ( kind = dp ), intent(out) :: r_sq
1051   real( kind = dp ) :: d(3), scaled(3)
1052   integer i
1053  
1054   d(1:3) = q_j(1:3) - q_i(1:3)
1055  
1056   ! Wrap back into periodic box if necessary
1057   if ( SIM_uses_PBC ) then
1058      
1059      if( .not.boxIsOrthorhombic ) then
1060         ! calc the scaled coordinates.
1061        
1062         scaled = matmul(HmatInv, d)
1063        
1064         ! wrap the scaled coordinates
1065        
1066         scaled = scaled  - anint(scaled)
1067        
1068        
1069         ! calc the wrapped real coordinates from the wrapped scaled
1070         ! coordinates
1071        
1072         d = matmul(Hmat,scaled)
1073        
1074      else
1075         ! calc the scaled coordinates.
1076        
1077         do i = 1, 3
1078            scaled(i) = d(i) * HmatInv(i,i)
1079            
1080            ! wrap the scaled coordinates
1081            
1082            scaled(i) = scaled(i) - anint(scaled(i))
1083            
1084            ! calc the wrapped real coordinates from the wrapped scaled
1085            ! coordinates
1086            
1087            d(i) = scaled(i)*Hmat(i,i)
1088         enddo
1089      endif
1090      
1091   endif
1092  
1093   r_sq = dot_product(d,d)
1094  
1095 end subroutine get_interatomic_vector
1096
1097 subroutine zero_work_arrays()
1098  
1099 #ifdef IS_MPI
1100  
1101   q_Row = 0.0_dp
1102   q_Col = 0.0_dp
1179  
1180 <   q_group_Row = 0.0_dp
1181 <   q_group_Col = 0.0_dp  
1182 <  
1183 <   eFrame_Row = 0.0_dp
1184 <   eFrame_Col = 0.0_dp
1185 <  
1186 <   A_Row = 0.0_dp
1187 <   A_Col = 0.0_dp
1188 <  
1189 <   f_Row = 0.0_dp
1190 <   f_Col = 0.0_dp
1191 <   f_Temp = 0.0_dp
1192 <  
1193 <   t_Row = 0.0_dp
1194 <   t_Col = 0.0_dp
1195 <   t_Temp = 0.0_dp
1196 <  
1197 <   pot_Row = 0.0_dp
1198 <   pot_Col = 0.0_dp
1199 <   pot_Temp = 0.0_dp
1200 <  
1201 <   rf_Row = 0.0_dp
1202 <   rf_Col = 0.0_dp
1203 <   rf_Temp = 0.0_dp
1204 <  
1205 < #endif
1206 <
1207 <   if (FF_uses_EAM .and. SIM_uses_EAM) then
1208 <      call clean_EAM()
1209 <   endif
1210 <  
1211 <   rf = 0.0_dp
1212 <   tau_Temp = 0.0_dp
1213 <   virial_Temp = 0.0_dp
1214 < end subroutine zero_work_arrays
1215 <
1216 < function skipThisPair(atom1, atom2) result(skip_it)
1217 <   integer, intent(in) :: atom1
1218 <   integer, intent(in), optional :: atom2
1219 <   logical :: skip_it
1220 <   integer :: unique_id_1, unique_id_2
1221 <   integer :: me_i,me_j
1222 <   integer :: i
1223 <  
1224 <   skip_it = .false.
1225 <  
1226 <   !! there are a number of reasons to skip a pair or a particle
1227 <   !! mostly we do this to exclude atoms who are involved in short
1228 <   !! range interactions (bonds, bends, torsions), but we also need
1229 <   !! to exclude some overcounted interactions that result from
1230 <   !! the parallel decomposition
1231 <  
1180 >    iMap = InteractionMap(me_i, me_j)%InteractionHash
1181 >
1182 >    if ( iand(iMap, EAM_PAIR).ne.0 ) then      
1183 >            call calc_EAM_prepair_rho(i, j, d, r, rijsq )
1184 >    endif
1185 >    
1186 >  end subroutine do_prepair
1187 >
1188 >
1189 >  subroutine do_preforce(nlocal,pot)
1190 >    integer :: nlocal
1191 >    real( kind = dp ) :: pot
1192 >
1193 >    if (FF_uses_EAM .and. SIM_uses_EAM) then
1194 >       call calc_EAM_preforce_Frho(nlocal,pot)
1195 >    endif
1196 >
1197 >
1198 >  end subroutine do_preforce
1199 >
1200 >
1201 >  subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
1202 >
1203 >    real (kind = dp), dimension(3) :: q_i
1204 >    real (kind = dp), dimension(3) :: q_j
1205 >    real ( kind = dp ), intent(out) :: r_sq
1206 >    real( kind = dp ) :: d(3), scaled(3)
1207 >    integer i
1208 >
1209 >    d(1:3) = q_j(1:3) - q_i(1:3)
1210 >
1211 >    ! Wrap back into periodic box if necessary
1212 >    if ( SIM_uses_PBC ) then
1213 >
1214 >       if( .not.boxIsOrthorhombic ) then
1215 >          ! calc the scaled coordinates.
1216 >
1217 >          scaled = matmul(HmatInv, d)
1218 >
1219 >          ! wrap the scaled coordinates
1220 >
1221 >          scaled = scaled  - anint(scaled)
1222 >
1223 >
1224 >          ! calc the wrapped real coordinates from the wrapped scaled
1225 >          ! coordinates
1226 >
1227 >          d = matmul(Hmat,scaled)
1228 >
1229 >       else
1230 >          ! calc the scaled coordinates.
1231 >
1232 >          do i = 1, 3
1233 >             scaled(i) = d(i) * HmatInv(i,i)
1234 >
1235 >             ! wrap the scaled coordinates
1236 >
1237 >             scaled(i) = scaled(i) - anint(scaled(i))
1238 >
1239 >             ! calc the wrapped real coordinates from the wrapped scaled
1240 >             ! coordinates
1241 >
1242 >             d(i) = scaled(i)*Hmat(i,i)
1243 >          enddo
1244 >       endif
1245 >
1246 >    endif
1247 >
1248 >    r_sq = dot_product(d,d)
1249 >
1250 >  end subroutine get_interatomic_vector
1251 >
1252 >  subroutine zero_work_arrays()
1253 >
1254   #ifdef IS_MPI
1255 <   !! in MPI, we have to look up the unique IDs for each atom
1256 <   unique_id_1 = AtomRowToGlobal(atom1)
1257 < #else
1258 <   !! in the normal loop, the atom numbers are unique
1259 <   unique_id_1 = atom1
1260 < #endif
1261 <  
1262 <   !! We were called with only one atom, so just check the global exclude
1263 <   !! list for this atom
1264 <   if (.not. present(atom2)) then
1265 <      do i = 1, nExcludes_global
1266 <         if (excludesGlobal(i) == unique_id_1) then
1267 <            skip_it = .true.
1268 <            return
1269 <         end if
1270 <      end do
1271 <      return
1272 <   end if
1273 <  
1274 < #ifdef IS_MPI
1275 <   unique_id_2 = AtomColToGlobal(atom2)
1276 < #else
1277 <   unique_id_2 = atom2
1278 < #endif
1279 <  
1255 >
1256 >    q_Row = 0.0_dp
1257 >    q_Col = 0.0_dp
1258 >
1259 >    q_group_Row = 0.0_dp
1260 >    q_group_Col = 0.0_dp  
1261 >
1262 >    eFrame_Row = 0.0_dp
1263 >    eFrame_Col = 0.0_dp
1264 >
1265 >    A_Row = 0.0_dp
1266 >    A_Col = 0.0_dp
1267 >
1268 >    f_Row = 0.0_dp
1269 >    f_Col = 0.0_dp
1270 >    f_Temp = 0.0_dp
1271 >
1272 >    t_Row = 0.0_dp
1273 >    t_Col = 0.0_dp
1274 >    t_Temp = 0.0_dp
1275 >
1276 >    pot_Row = 0.0_dp
1277 >    pot_Col = 0.0_dp
1278 >    pot_Temp = 0.0_dp
1279 >
1280 >    rf_Row = 0.0_dp
1281 >    rf_Col = 0.0_dp
1282 >    rf_Temp = 0.0_dp
1283 >
1284 > #endif
1285 >
1286 >    if (FF_uses_EAM .and. SIM_uses_EAM) then
1287 >       call clean_EAM()
1288 >    endif
1289 >
1290 >    rf = 0.0_dp
1291 >    tau_Temp = 0.0_dp
1292 >    virial_Temp = 0.0_dp
1293 >  end subroutine zero_work_arrays
1294 >
1295 >  function skipThisPair(atom1, atom2) result(skip_it)
1296 >    integer, intent(in) :: atom1
1297 >    integer, intent(in), optional :: atom2
1298 >    logical :: skip_it
1299 >    integer :: unique_id_1, unique_id_2
1300 >    integer :: me_i,me_j
1301 >    integer :: i
1302 >
1303 >    skip_it = .false.
1304 >
1305 >    !! there are a number of reasons to skip a pair or a particle
1306 >    !! mostly we do this to exclude atoms who are involved in short
1307 >    !! range interactions (bonds, bends, torsions), but we also need
1308 >    !! to exclude some overcounted interactions that result from
1309 >    !! the parallel decomposition
1310 >
1311   #ifdef IS_MPI
1312 <   !! this situation should only arise in MPI simulations
1313 <   if (unique_id_1 == unique_id_2) then
1314 <      skip_it = .true.
1315 <      return
1316 <   end if
1188 <  
1189 <   !! this prevents us from doing the pair on multiple processors
1190 <   if (unique_id_1 < unique_id_2) then
1191 <      if (mod(unique_id_1 + unique_id_2,2) == 0) then
1192 <         skip_it = .true.
1193 <         return
1194 <      endif
1195 <   else                
1196 <      if (mod(unique_id_1 + unique_id_2,2) == 1) then
1197 <         skip_it = .true.
1198 <         return
1199 <      endif
1200 <   endif
1312 >    !! in MPI, we have to look up the unique IDs for each atom
1313 >    unique_id_1 = AtomRowToGlobal(atom1)
1314 > #else
1315 >    !! in the normal loop, the atom numbers are unique
1316 >    unique_id_1 = atom1
1317   #endif
1318 <  
1319 <   !! the rest of these situations can happen in all simulations:
1320 <   do i = 1, nExcludes_global      
1321 <      if ((excludesGlobal(i) == unique_id_1) .or. &
1322 <           (excludesGlobal(i) == unique_id_2)) then
1323 <         skip_it = .true.
1324 <         return
1325 <      endif
1326 <   enddo
1327 <  
1328 <   do i = 1, nSkipsForAtom(atom1)
1329 <      if (skipsForAtom(atom1, i) .eq. unique_id_2) then
1330 <         skip_it = .true.
1331 <         return
1332 <      endif
1333 <   end do
1334 <  
1335 <   return
1336 < end function skipThisPair
1337 <
1338 < function FF_UsesDirectionalAtoms() result(doesit)
1339 <   logical :: doesit
1340 <   doesit = FF_uses_DirectionalAtoms .or. FF_uses_Dipoles .or. &
1341 <        FF_uses_Sticky .or. FF_uses_GayBerne .or. FF_uses_Shapes
1342 < end function FF_UsesDirectionalAtoms
1343 <
1344 < function FF_RequiresPrepairCalc() result(doesit)
1345 <   logical :: doesit
1346 <   doesit = FF_uses_EAM
1347 < end function FF_RequiresPrepairCalc
1348 <
1349 < function FF_RequiresPostpairCalc() result(doesit)
1350 <   logical :: doesit
1351 <   doesit = FF_uses_RF
1352 < end function FF_RequiresPostpairCalc
1353 <
1318 >
1319 >    !! We were called with only one atom, so just check the global exclude
1320 >    !! list for this atom
1321 >    if (.not. present(atom2)) then
1322 >       do i = 1, nExcludes_global
1323 >          if (excludesGlobal(i) == unique_id_1) then
1324 >             skip_it = .true.
1325 >             return
1326 >          end if
1327 >       end do
1328 >       return
1329 >    end if
1330 >
1331 > #ifdef IS_MPI
1332 >    unique_id_2 = AtomColToGlobal(atom2)
1333 > #else
1334 >    unique_id_2 = atom2
1335 > #endif
1336 >
1337 > #ifdef IS_MPI
1338 >    !! this situation should only arise in MPI simulations
1339 >    if (unique_id_1 == unique_id_2) then
1340 >       skip_it = .true.
1341 >       return
1342 >    end if
1343 >
1344 >    !! this prevents us from doing the pair on multiple processors
1345 >    if (unique_id_1 < unique_id_2) then
1346 >       if (mod(unique_id_1 + unique_id_2,2) == 0) then
1347 >          skip_it = .true.
1348 >          return
1349 >       endif
1350 >    else                
1351 >       if (mod(unique_id_1 + unique_id_2,2) == 1) then
1352 >          skip_it = .true.
1353 >          return
1354 >       endif
1355 >    endif
1356 > #endif
1357 >
1358 >    !! the rest of these situations can happen in all simulations:
1359 >    do i = 1, nExcludes_global      
1360 >       if ((excludesGlobal(i) == unique_id_1) .or. &
1361 >            (excludesGlobal(i) == unique_id_2)) then
1362 >          skip_it = .true.
1363 >          return
1364 >       endif
1365 >    enddo
1366 >
1367 >    do i = 1, nSkipsForAtom(atom1)
1368 >       if (skipsForAtom(atom1, i) .eq. unique_id_2) then
1369 >          skip_it = .true.
1370 >          return
1371 >       endif
1372 >    end do
1373 >
1374 >    return
1375 >  end function skipThisPair
1376 >
1377 >  function FF_UsesDirectionalAtoms() result(doesit)
1378 >    logical :: doesit
1379 >    doesit = FF_uses_DirectionalAtoms .or. FF_uses_Dipoles .or. &
1380 >         FF_uses_Quadrupoles .or. FF_uses_Sticky .or. &
1381 >         FF_uses_StickyPower .or. FF_uses_GayBerne .or. FF_uses_Shapes
1382 >  end function FF_UsesDirectionalAtoms
1383 >
1384 >  function FF_RequiresPrepairCalc() result(doesit)
1385 >    logical :: doesit
1386 >    doesit = FF_uses_EAM
1387 >  end function FF_RequiresPrepairCalc
1388 >
1389 >  function FF_RequiresPostpairCalc() result(doesit)
1390 >    logical :: doesit
1391 >    doesit = FF_uses_RF
1392 >  end function FF_RequiresPostpairCalc
1393 >
1394   #ifdef PROFILE
1395 < function getforcetime() result(totalforcetime)
1396 <   real(kind=dp) :: totalforcetime
1397 <   totalforcetime = forcetime
1398 < end function getforcetime
1395 >  function getforcetime() result(totalforcetime)
1396 >    real(kind=dp) :: totalforcetime
1397 >    totalforcetime = forcetime
1398 >  end function getforcetime
1399   #endif
1244
1245 !! This cleans componets of force arrays belonging only to fortran
1400  
1401 < subroutine add_stress_tensor(dpair, fpair)
1248 <  
1249 <   real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1250 <  
1251 <   ! because the d vector is the rj - ri vector, and
1252 <   ! because fx, fy, fz are the force on atom i, we need a
1253 <   ! negative sign here:  
1254 <  
1255 <   tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1256 <   tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1257 <   tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1258 <   tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1259 <   tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1260 <   tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1261 <   tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1262 <   tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1263 <   tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1264 <  
1265 <   virial_Temp = virial_Temp + &
1266 <        (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1267 <  
1268 < end subroutine add_stress_tensor
1269 <
1270 < end module doForces
1401 >  !! This cleans componets of force arrays belonging only to fortran
1402  
1403 < !! Interfaces for C programs to module....
1403 >  subroutine add_stress_tensor(dpair, fpair)
1404  
1405 < subroutine initFortranFF(use_RF_c, thisStat)
1275 <    use doForces, ONLY: init_FF
1276 <    logical, intent(in) :: use_RF_c
1405 >    real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1406  
1407 <    integer, intent(out) :: thisStat  
1408 <    call init_FF(use_RF_c, thisStat)
1407 >    ! because the d vector is the rj - ri vector, and
1408 >    ! because fx, fy, fz are the force on atom i, we need a
1409 >    ! negative sign here:  
1410  
1411 < end subroutine initFortranFF
1411 >    tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1412 >    tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1413 >    tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1414 >    tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1415 >    tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1416 >    tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1417 >    tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1418 >    tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1419 >    tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1420  
1421 <  subroutine doForceloop(q, q_group, A, eFrame, f, t, tau, pot, &
1422 <       do_pot_c, do_stress_c, error)
1285 <      
1286 <       use definitions, ONLY: dp
1287 <       use simulation
1288 <       use doForces, ONLY: do_force_loop
1289 <    !! Position array provided by C, dimensioned by getNlocal
1290 <    real ( kind = dp ), dimension(3, nLocal) :: q
1291 <    !! molecular center-of-mass position array
1292 <    real ( kind = dp ), dimension(3, nGroups) :: q_group
1293 <    !! Rotation Matrix for each long range particle in simulation.
1294 <    real( kind = dp), dimension(9, nLocal) :: A    
1295 <    !! Unit vectors for dipoles (lab frame)
1296 <    real( kind = dp ), dimension(9,nLocal) :: eFrame
1297 <    !! Force array provided by C, dimensioned by getNlocal
1298 <    real ( kind = dp ), dimension(3,nLocal) :: f
1299 <    !! Torsion array provided by C, dimensioned by getNlocal
1300 <    real( kind = dp ), dimension(3,nLocal) :: t    
1421 >    virial_Temp = virial_Temp + &
1422 >         (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1423  
1424 <    !! Stress Tensor
1425 <    real( kind = dp), dimension(9) :: tau  
1426 <    real ( kind = dp ) :: pot
1305 <    logical ( kind = 2) :: do_pot_c, do_stress_c
1306 <    integer :: error
1307 <    
1308 <    call do_force_loop(q, q_group, A, eFrame, f, t, tau, pot, &
1309 <       do_pot_c, do_stress_c, error)
1310 <      
1311 < end subroutine doForceloop
1424 >  end subroutine add_stress_tensor
1425 >
1426 > end module doForces

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines