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

Comparing trunk/OOPSE-4/src/UseTheForce/doForces.F90 (file contents):
Revision 2407 by chrisfen, Wed Nov 2 20:35:34 2005 UTC vs.
Revision 2917 by chrisfen, Mon Jul 3 13:18:43 2006 UTC

# Line 45 | Line 45
45  
46   !! @author Charles F. Vardeman II
47   !! @author Matthew Meineke
48 < !! @version $Id: doForces.F90,v 1.66 2005-11-02 20:35:34 chrisfen Exp $, $Date: 2005-11-02 20:35:34 $, $Name: not supported by cvs2svn $, $Revision: 1.66 $
48 > !! @version $Id: doForces.F90,v 1.84 2006-07-03 13:18:43 chrisfen Exp $, $Date: 2006-07-03 13:18:43 $, $Name: not supported by cvs2svn $, $Revision: 1.84 $
49  
50  
51   module doForces
# Line 62 | Line 62 | module doForces
62    use shapes
63    use vector_class
64    use eam
65 +  use suttonchen
66    use status
67   #ifdef IS_MPI
68    use mpiSimulation
# Line 71 | Line 72 | module doForces
72    PRIVATE
73  
74   #define __FORTRAN90
74 #include "UseTheForce/fSwitchingFunction.h"
75   #include "UseTheForce/fCutoffPolicy.h"
76   #include "UseTheForce/DarkSide/fInteractionMap.h"
77   #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h"
78  
79
79    INTEGER, PARAMETER:: PREPAIR_LOOP = 1
80    INTEGER, PARAMETER:: PAIR_LOOP    = 2
81  
# Line 86 | Line 85 | module doForces
85    logical, save :: haveInteractionHash = .false.
86    logical, save :: haveGtypeCutoffMap = .false.
87    logical, save :: haveDefaultCutoffs = .false.
88 <  logical, save :: haveRlist = .false.
88 >  logical, save :: haveSkinThickness = .false.
89 >  logical, save :: haveElectrostaticSummationMethod = .false.
90 >  logical, save :: haveCutoffPolicy = .false.
91 >  logical, save :: VisitCutoffsAfterComputing = .false.
92 >  logical, save :: do_box_dipole = .false.
93  
94    logical, save :: FF_uses_DirectionalAtoms
95    logical, save :: FF_uses_Dipoles
96    logical, save :: FF_uses_GayBerne
97    logical, save :: FF_uses_EAM
98 +  logical, save :: FF_uses_SC
99 +  logical, save :: FF_uses_MEAM
100 +
101  
102    logical, save :: SIM_uses_DirectionalAtoms
103    logical, save :: SIM_uses_EAM
104 +  logical, save :: SIM_uses_SC
105 +  logical, save :: SIM_uses_MEAM
106    logical, save :: SIM_requires_postpair_calc
107    logical, save :: SIM_requires_prepair_calc
108    logical, save :: SIM_uses_PBC
109  
110    integer, save :: electrostaticSummationMethod
111 +  integer, save :: cutoffPolicy = TRADITIONAL_CUTOFF_POLICY
112  
113 +  real(kind=dp), save :: defaultRcut, defaultRsw, largestRcut
114 +  real(kind=dp), save :: skinThickness
115 +  logical, save :: defaultDoShift
116 +
117    public :: init_FF
118 <  public :: setDefaultCutoffs
118 >  public :: setCutoffs
119 >  public :: cWasLame
120 >  public :: setElectrostaticMethod
121 >  public :: setBoxDipole
122 >  public :: getBoxDipole
123 >  public :: setCutoffPolicy
124 >  public :: setSkinThickness
125    public :: do_force_loop
107  public :: createInteractionHash
108  public :: createGtypeCutoffMap
109  public :: getStickyCut
110  public :: getStickyPowerCut
111  public :: getGayBerneCut
112  public :: getEAMCut
113  public :: getShapeCut
126  
127   #ifdef PROFILE
128    public :: getforcetime
# Line 138 | Line 150 | module doForces
150    end type gtypeCutoffs
151    type(gtypeCutoffs), dimension(:,:), allocatable :: gtypeCutoffMap
152  
153 <  integer, save :: cutoffPolicy = TRADITIONAL_CUTOFF_POLICY
154 <  real(kind=dp),save :: defaultRcut, defaultRsw, defaultRlist
143 <  real(kind=dp),save :: listSkin
144 <  
153 >  real(kind=dp), dimension(3) :: boxDipole
154 >
155   contains
156  
157 <  subroutine createInteractionHash(status)
157 >  subroutine createInteractionHash()
158      integer :: nAtypes
149    integer, intent(out) :: status
159      integer :: i
160      integer :: j
161      integer :: iHash
# Line 158 | Line 167 | contains
167      logical :: i_is_GB
168      logical :: i_is_EAM
169      logical :: i_is_Shape
170 +    logical :: i_is_SC
171 +    logical :: i_is_MEAM
172      logical :: j_is_LJ
173      logical :: j_is_Elect
174      logical :: j_is_Sticky
# Line 165 | Line 176 | contains
176      logical :: j_is_GB
177      logical :: j_is_EAM
178      logical :: j_is_Shape
179 +    logical :: j_is_SC
180 +    logical :: j_is_MEAM
181      real(kind=dp) :: myRcut
182  
170    status = 0  
171
183      if (.not. associated(atypes)) then
184 <       call handleError("atype", "atypes was not present before call of createInteractionHash!")
174 <       status = -1
184 >       call handleError("doForces", "atypes was not present before call of createInteractionHash!")
185         return
186      endif
187      
188      nAtypes = getSize(atypes)
189      
190      if (nAtypes == 0) then
191 <       status = -1
191 >       call handleError("doForces", "nAtypes was zero during call of createInteractionHash!")
192         return
193      end if
194  
# Line 204 | Line 214 | contains
214         call getElementProperty(atypes, i, "is_GayBerne", i_is_GB)
215         call getElementProperty(atypes, i, "is_EAM", i_is_EAM)
216         call getElementProperty(atypes, i, "is_Shape", i_is_Shape)
217 +       call getElementProperty(atypes, i, "is_SC", i_is_SC)
218 +       call getElementProperty(atypes, i, "is_MEAM", i_is_MEAM)
219  
220         do j = i, nAtypes
221  
# Line 217 | Line 229 | contains
229            call getElementProperty(atypes, j, "is_GayBerne", j_is_GB)
230            call getElementProperty(atypes, j, "is_EAM", j_is_EAM)
231            call getElementProperty(atypes, j, "is_Shape", j_is_Shape)
232 +          call getElementProperty(atypes, j, "is_SC", j_is_SC)
233 +          call getElementProperty(atypes, j, "is_MEAM", j_is_MEAM)
234  
235            if (i_is_LJ .and. j_is_LJ) then
236               iHash = ior(iHash, LJ_PAIR)            
# Line 238 | Line 252 | contains
252               iHash = ior(iHash, EAM_PAIR)
253            endif
254  
255 +          if (i_is_SC .and. j_is_SC) then
256 +             iHash = ior(iHash, SC_PAIR)
257 +          endif
258 +
259            if (i_is_GB .and. j_is_GB) iHash = ior(iHash, GAYBERNE_PAIR)
260            if (i_is_GB .and. j_is_LJ) iHash = ior(iHash, GAYBERNE_LJ)
261            if (i_is_LJ .and. j_is_GB) iHash = ior(iHash, GAYBERNE_LJ)
# Line 257 | Line 275 | contains
275      haveInteractionHash = .true.
276    end subroutine createInteractionHash
277  
278 <  subroutine createGtypeCutoffMap(stat)
278 >  subroutine createGtypeCutoffMap()
279  
262    integer, intent(out), optional :: stat
280      logical :: i_is_LJ
281      logical :: i_is_Elect
282      logical :: i_is_Sticky
# Line 267 | Line 284 | contains
284      logical :: i_is_GB
285      logical :: i_is_EAM
286      logical :: i_is_Shape
287 +    logical :: i_is_SC
288      logical :: GtypeFound
289  
290      integer :: myStatus, nAtypes,  i, j, istart, iend, jstart, jend
# Line 274 | Line 292 | contains
292      integer :: nGroupsInRow
293      integer :: nGroupsInCol
294      integer :: nGroupTypesRow,nGroupTypesCol
295 <    real(kind=dp):: thisSigma, bigSigma, thisRcut, tradRcut, tol, skin
295 >    real(kind=dp):: thisSigma, bigSigma, thisRcut, tradRcut, tol
296      real(kind=dp) :: biggestAtypeCutoff
297  
280    stat = 0
298      if (.not. haveInteractionHash) then
299 <       call createInteractionHash(myStatus)      
283 <       if (myStatus .ne. 0) then
284 <          write(default_error, *) 'createInteractionHash failed in doForces!'
285 <          stat = -1
286 <          return
287 <       endif
299 >       call createInteractionHash()      
300      endif
301   #ifdef IS_MPI
302      nGroupsInRow = getNgroupsInRow(plan_group_row)
# Line 302 | Line 314 | contains
314            call getElementProperty(atypes, i, "is_GayBerne", i_is_GB)
315            call getElementProperty(atypes, i, "is_EAM", i_is_EAM)
316            call getElementProperty(atypes, i, "is_Shape", i_is_Shape)
317 <          
317 >          call getElementProperty(atypes, i, "is_SC", i_is_SC)
318  
319            if (haveDefaultCutoffs) then
320               atypeMaxCutoff(i) = defaultRcut
# Line 335 | Line 347 | contains
347                  thisRcut = getShapeCut(i)
348                  if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
349               endif
350 +             if (i_is_SC) then
351 +                thisRcut = getSCCut(i)
352 +                if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
353 +             endif
354            endif
355 <          
340 <          
355 >                    
356            if (atypeMaxCutoff(i).gt.biggestAtypeCutoff) then
357               biggestAtypeCutoff = atypeMaxCutoff(i)
358            endif
359  
360         endif
361      enddo
347  
348
362      
363      istart = 1
364      jstart = 1
# Line 389 | Line 402 | contains
402         allocate(groupToGtypeCol(jend))
403      end if
404  
405 <    if(.not.associated(groupToGtypeCol)) then
406 <       allocate(groupToGtypeCol(jend))
405 >    if(.not.associated(groupMaxCutoffCol)) then
406 >       allocate(groupMaxCutoffCol(jend))
407      else
408 <       deallocate(groupToGtypeCol)
409 <       allocate(groupToGtypeCol(jend))
408 >       deallocate(groupMaxCutoffCol)
409 >       allocate(groupMaxCutoffCol(jend))
410      end if
411      if(.not.associated(gtypeMaxCutoffCol)) then
412         allocate(gtypeMaxCutoffCol(jend))
# Line 414 | Line 427 | contains
427      !! largest cutoff for any atypes present in this group.  We also
428      !! create gtypes at this point.
429      
430 <    tol = 1.0d-6
430 >    tol = 1.0e-6_dp
431      nGroupTypesRow = 0
432 <
432 >    nGroupTypesCol = 0
433      do i = istart, iend      
434         n_in_i = groupStartRow(i+1) - groupStartRow(i)
435         groupMaxCutoffRow(i) = 0.0_dp
# Line 431 | Line 444 | contains
444               groupMaxCutoffRow(i)=atypeMaxCutoff(me_i)
445            endif          
446         enddo
434
447         if (nGroupTypesRow.eq.0) then
448            nGroupTypesRow = nGroupTypesRow + 1
449            gtypeMaxCutoffRow(nGroupTypesRow) = groupMaxCutoffRow(i)
# Line 494 | Line 506 | contains
506      groupMaxCutoffCol => groupMaxCutoffRow
507   #endif
508  
497
498
499
500
509      !! allocate the gtypeCutoffMap here.
510      allocate(gtypeCutoffMap(nGroupTypesRow,nGroupTypesCol))
511      !! then we do a double loop over all the group TYPES to find the cutoff
512      !! map between groups of two types
513      tradRcut = max(maxval(gtypeMaxCutoffRow),maxval(gtypeMaxCutoffCol))
514  
515 <    do i = 1, nGroupTypesRow
515 >    do i = 1, nGroupTypesRow      
516         do j = 1, nGroupTypesCol
517        
518            select case(cutoffPolicy)
# Line 519 | Line 527 | contains
527               return
528            end select
529            gtypeCutoffMap(i,j)%rcut = thisRcut
530 +          
531 +          if (thisRcut.gt.largestRcut) largestRcut = thisRcut
532 +
533            gtypeCutoffMap(i,j)%rcutsq = thisRcut*thisRcut
523          skin = defaultRlist - defaultRcut
524          listSkin = skin ! set neighbor list skin thickness
525          gtypeCutoffMap(i,j)%rlistsq = (thisRcut + skin)**2
534  
535 +          if (.not.haveSkinThickness) then
536 +             skinThickness = 1.0_dp
537 +          endif
538 +
539 +          gtypeCutoffMap(i,j)%rlistsq = (thisRcut + skinThickness)**2
540 +
541            ! sanity check
542  
543            if (haveDefaultCutoffs) then
# Line 533 | Line 547 | contains
547            endif
548         enddo
549      enddo
550 +
551      if(allocated(gtypeMaxCutoffRow)) deallocate(gtypeMaxCutoffRow)
552      if(allocated(groupMaxCutoffRow)) deallocate(groupMaxCutoffRow)
553      if(allocated(atypeMaxCutoff)) deallocate(atypeMaxCutoff)
# Line 546 | Line 561 | contains
561      haveGtypeCutoffMap = .true.
562     end subroutine createGtypeCutoffMap
563  
564 <   subroutine setDefaultCutoffs(defRcut, defRsw, defRlist, cutPolicy)
550 <     real(kind=dp),intent(in) :: defRcut, defRsw, defRlist
551 <     integer, intent(in) :: cutPolicy
564 >   subroutine setCutoffs(defRcut, defRsw)
565  
566 +     real(kind=dp),intent(in) :: defRcut, defRsw
567 +     character(len = statusMsgSize) :: errMsg
568 +     integer :: localError
569 +
570       defaultRcut = defRcut
571       defaultRsw = defRsw
572 <     defaultRlist = defRlist
573 <     cutoffPolicy = cutPolicy
574 <
575 <     haveDefaultCutoffs = .true.
576 <   end subroutine setDefaultCutoffs
572 >    
573 >     defaultDoShift = .false.
574 >     if (abs(defaultRcut-defaultRsw) .lt. 0.0001) then
575 >        
576 >        write(errMsg, *) &
577 >             'cutoffRadius and switchingRadius are set to the same', newline &
578 >             // tab, 'value.  OOPSE will use shifted ', newline &
579 >             // tab, 'potentials instead of switching functions.'
580 >        
581 >        call handleInfo("setCutoffs", errMsg)
582 >        
583 >        defaultDoShift = .true.
584 >        
585 >     endif
586 >    
587 >     localError = 0
588 >     call setLJDefaultCutoff( defaultRcut, defaultDoShift )
589 >     call setElectrostaticCutoffRadius( defaultRcut, defaultRsw )
590 >     call setCutoffEAM( defaultRcut )
591 >     call setCutoffSC( defaultRcut )
592 >     call set_switch(defaultRsw, defaultRcut)
593 >     call setHmatDangerousRcutValue(defaultRcut)
594 >        
595 >     haveDefaultCutoffs = .true.
596 >     haveGtypeCutoffMap = .false.
597  
598 <   subroutine setCutoffPolicy(cutPolicy)
598 >   end subroutine setCutoffs
599  
600 +   subroutine cWasLame()
601 +    
602 +     VisitCutoffsAfterComputing = .true.
603 +     return
604 +    
605 +   end subroutine cWasLame
606 +  
607 +   subroutine setCutoffPolicy(cutPolicy)
608 +    
609       integer, intent(in) :: cutPolicy
610 +    
611       cutoffPolicy = cutPolicy
612 <     call createGtypeCutoffMap()
612 >     haveCutoffPolicy = .true.
613 >     haveGtypeCutoffMap = .false.
614 >    
615     end subroutine setCutoffPolicy
616 +  
617 +   subroutine setBoxDipole()
618 +
619 +     do_box_dipole = .true.
620      
621 <    
569 <  subroutine setSimVariables()
570 <    SIM_uses_DirectionalAtoms = SimUsesDirectionalAtoms()
571 <    SIM_uses_EAM = SimUsesEAM()
572 <    SIM_requires_postpair_calc = SimRequiresPostpairCalc()
573 <    SIM_requires_prepair_calc = SimRequiresPrepairCalc()
574 <    SIM_uses_PBC = SimUsesPBC()
621 >   end subroutine setBoxDipole
622  
623 <    haveSIMvariables = .true.
623 >   subroutine getBoxDipole( box_dipole )
624  
625 <    return
579 <  end subroutine setSimVariables
625 >     real(kind=dp), intent(inout), dimension(3) :: box_dipole
626  
627 +     box_dipole = boxDipole
628 +
629 +   end subroutine getBoxDipole
630 +
631 +   subroutine setElectrostaticMethod( thisESM )
632 +
633 +     integer, intent(in) :: thisESM
634 +
635 +     electrostaticSummationMethod = thisESM
636 +     haveElectrostaticSummationMethod = .true.
637 +    
638 +   end subroutine setElectrostaticMethod
639 +
640 +   subroutine setSkinThickness( thisSkin )
641 +    
642 +     real(kind=dp), intent(in) :: thisSkin
643 +    
644 +     skinThickness = thisSkin
645 +     haveSkinThickness = .true.    
646 +     haveGtypeCutoffMap = .false.
647 +    
648 +   end subroutine setSkinThickness
649 +      
650 +   subroutine setSimVariables()
651 +     SIM_uses_DirectionalAtoms = SimUsesDirectionalAtoms()
652 +     SIM_uses_EAM = SimUsesEAM()
653 +     SIM_requires_postpair_calc = SimRequiresPostpairCalc()
654 +     SIM_requires_prepair_calc = SimRequiresPrepairCalc()
655 +     SIM_uses_PBC = SimUsesPBC()
656 +     SIM_uses_SC = SimUsesSC()
657 +
658 +     haveSIMvariables = .true.
659 +    
660 +     return
661 +   end subroutine setSimVariables
662 +
663    subroutine doReadyCheck(error)
664      integer, intent(out) :: error
583
665      integer :: myStatus
666  
667      error = 0
668  
669      if (.not. haveInteractionHash) then      
670 <       myStatus = 0      
590 <       call createInteractionHash(myStatus)      
591 <       if (myStatus .ne. 0) then
592 <          write(default_error, *) 'createInteractionHash failed in doForces!'
593 <          error = -1
594 <          return
595 <       endif
670 >       call createInteractionHash()      
671      endif
672  
673      if (.not. haveGtypeCutoffMap) then        
674 <       myStatus = 0      
600 <       call createGtypeCutoffMap(myStatus)      
601 <       if (myStatus .ne. 0) then
602 <          write(default_error, *) 'createGtypeCutoffMap failed in doForces!'
603 <          error = -1
604 <          return
605 <       endif
674 >       call createGtypeCutoffMap()      
675      endif
676  
677 +    if (VisitCutoffsAfterComputing) then
678 +       call set_switch(largestRcut, largestRcut)      
679 +       call setHmatDangerousRcutValue(largestRcut)
680 +       call setCutoffEAM(largestRcut)
681 +       call setCutoffSC(largestRcut)
682 +       VisitCutoffsAfterComputing = .false.
683 +    endif
684 +
685      if (.not. haveSIMvariables) then
686         call setSimVariables()
687      endif
688  
612  !  if (.not. haveRlist) then
613  !     write(default_error, *) 'rList has not been set in doForces!'
614  !     error = -1
615  !     return
616  !  endif
617
689      if (.not. haveNeighborList) then
690         write(default_error, *) 'neighbor list has not been initialized in doForces!'
691         error = -1
692         return
693      end if
694 <
694 >    
695      if (.not. haveSaneForceField) then
696         write(default_error, *) 'Force Field is not sane in doForces!'
697         error = -1
698         return
699      end if
700 <
700 >    
701   #ifdef IS_MPI
702      if (.not. isMPISimSet()) then
703         write(default_error,*) "ERROR: mpiSimulation has not been initialized!"
# Line 638 | Line 709 | contains
709    end subroutine doReadyCheck
710  
711  
712 <  subroutine init_FF(thisESM, thisStat)
712 >  subroutine init_FF(thisStat)
713  
643    integer, intent(in) :: thisESM
714      integer, intent(out) :: thisStat  
715      integer :: my_status, nMatches
716      integer, pointer :: MatchList(:) => null()
# Line 648 | Line 718 | contains
718      !! assume things are copacetic, unless they aren't
719      thisStat = 0
720  
651    electrostaticSummationMethod = thisESM
652
721      !! init_FF is called *after* all of the atom types have been
722      !! defined in atype_module using the new_atype subroutine.
723      !!
# Line 660 | Line 728 | contains
728      FF_uses_Dipoles = .false.
729      FF_uses_GayBerne = .false.
730      FF_uses_EAM = .false.
731 +    FF_uses_SC = .false.
732  
733      call getMatchingElementList(atypes, "is_Directional", .true., &
734           nMatches, MatchList)
# Line 676 | Line 745 | contains
745      call getMatchingElementList(atypes, "is_EAM", .true., nMatches, MatchList)
746      if (nMatches .gt. 0) FF_uses_EAM = .true.
747  
748 +    call getMatchingElementList(atypes, "is_SC", .true., nMatches, MatchList)
749 +    if (nMatches .gt. 0) FF_uses_SC = .true.
750  
751 +
752      haveSaneForceField = .true.
753  
754      if (FF_uses_EAM) then
# Line 745 | Line 817 | contains
817      real( kind = DP ) :: sw, dswdr, swderiv, mf
818      real( kind = DP ) :: rVal
819      real(kind=dp),dimension(3) :: d_atm, d_grp, fpair, fij
748    real(kind=dp), dimension(3) :: fstrs, f2strs
820      real(kind=dp) :: rfpot, mu_i, virial
821 +    real(kind=dp):: rCut
822      integer :: me_i, me_j, n_in_i, n_in_j
823      logical :: is_dp_i
824      integer :: neighborListSize
# Line 756 | Line 828 | contains
828      integer :: loopStart, loopEnd, loop
829      integer :: iHash
830      integer :: i1
831 <  
831 >
832 >    !! the variables for the box dipole moment
833 > #ifdef IS_MPI
834 >    integer :: pChgCount_local
835 >    integer :: nChgCount_local
836 >    real(kind=dp) :: pChg_local
837 >    real(kind=dp) :: nChg_local
838 >    real(kind=dp), dimension(3) :: pChgPos_local
839 >    real(kind=dp), dimension(3) :: nChgPos_local
840 >    real(kind=dp), dimension(3) :: dipVec_local
841 > #endif
842 >    integer :: pChgCount
843 >    integer :: nChgCount
844 >    real(kind=dp) :: pChg
845 >    real(kind=dp) :: nChg
846 >    real(kind=dp) :: chg_value
847 >    real(kind=dp), dimension(3) :: pChgPos
848 >    real(kind=dp), dimension(3) :: nChgPos
849 >    real(kind=dp), dimension(3) :: dipVec
850 >    real(kind=dp), dimension(3) :: chgVec
851  
852 +    !! initialize box dipole variables
853 +    if (do_box_dipole) then
854 + #ifdef IS_MPI
855 +       pChg_local = 0.0_dp
856 +       nChg_local = 0.0_dp
857 +       pChgCount_local = 0
858 +       nChgCount_local = 0
859 +       do i=1, 3
860 +          pChgPos_local = 0.0_dp
861 +          nChgPos_local = 0.0_dp
862 +          dipVec_local = 0.0_dp
863 +       enddo
864 + #endif
865 +       pChg = 0.0_dp
866 +       nChg = 0.0_dp
867 +       pChgCount = 0
868 +       nChgCount = 0
869 +       chg_value = 0.0_dp
870 +      
871 +       do i=1, 3
872 +          pChgPos(i) = 0.0_dp
873 +          nChgPos(i) = 0.0_dp
874 +          dipVec(i) = 0.0_dp
875 +          chgVec(i) = 0.0_dp
876 +          boxDipole(i) = 0.0_dp
877 +       enddo
878 +    endif
879 +
880      !! initialize local variables  
881  
882   #ifdef IS_MPI
# Line 820 | Line 939 | contains
939         ! (but only on the first time through):
940         if (loop .eq. loopStart) then
941   #ifdef IS_MPI
942 <          call checkNeighborList(nGroupsInRow, q_group_row, listSkin, &
942 >          call checkNeighborList(nGroupsInRow, q_group_row, skinThickness, &
943                 update_nlist)
944   #else
945 <          call checkNeighborList(nGroups, q_group, listSkin, &
945 >          call checkNeighborList(nGroups, q_group, skinThickness, &
946                 update_nlist)
947   #endif
948         endif
# Line 903 | Line 1022 | contains
1022  
1023                     list(nlist) = j
1024                  endif
1025 <                
1025 >                
1026                  if (rgrpsq < gtypeCutoffMap(groupToGtypeRow(i),groupToGtypeCol(j))%rCutsq) then
1027  
1028 +                   rCut = gtypeCutoffMap(groupToGtypeRow(i),groupToGtypeCol(j))%rCut
1029                     if (loop .eq. PAIR_LOOP) then
1030 <                      vij = 0.0d0
1031 <                      fij(1:3) = 0.0d0
1030 >                      vij = 0.0_dp
1031 >                      fij(1) = 0.0_dp
1032 >                      fij(2) = 0.0_dp
1033 >                      fij(3) = 0.0_dp
1034                     endif
1035                    
1036 <                   call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, &
915 <                        in_switching_region)
1036 >                   call get_switch(rgrpsq, sw, dswdr,rgrp, in_switching_region)
1037                    
1038                     n_in_j = groupStartCol(j+1) - groupStartCol(j)
1039                    
# Line 927 | Line 1048 | contains
1048                           if (skipThisPair(atom1, atom2))  cycle inner
1049                          
1050                           if ((n_in_i .eq. 1).and.(n_in_j .eq. 1)) then
1051 <                            d_atm(1:3) = d_grp(1:3)
1051 >                            d_atm(1) = d_grp(1)
1052 >                            d_atm(2) = d_grp(2)
1053 >                            d_atm(3) = d_grp(3)
1054                              ratmsq = rgrpsq
1055                           else
1056   #ifdef IS_MPI
# Line 942 | Line 1065 | contains
1065                           if (loop .eq. PREPAIR_LOOP) then
1066   #ifdef IS_MPI                      
1067                              call do_prepair(atom1, atom2, ratmsq, d_atm, sw, &
1068 <                                 rgrpsq, d_grp, do_pot, do_stress, &
1068 >                                 rgrpsq, d_grp, rCut, do_pot, do_stress, &
1069                                   eFrame, A, f, t, pot_local)
1070   #else
1071                              call do_prepair(atom1, atom2, ratmsq, d_atm, sw, &
1072 <                                 rgrpsq, d_grp, do_pot, do_stress, &
1072 >                                 rgrpsq, d_grp, rCut, do_pot, do_stress, &
1073                                   eFrame, A, f, t, pot)
1074   #endif                                              
1075                           else
1076   #ifdef IS_MPI                      
1077                              call do_pair(atom1, atom2, ratmsq, d_atm, sw, &
1078                                   do_pot, eFrame, A, f, t, pot_local, vpair, &
1079 <                                 fpair, d_grp, rgrp, fstrs)
1079 >                                 fpair, d_grp, rgrp, rCut)
1080   #else
1081                              call do_pair(atom1, atom2, ratmsq, d_atm, sw, &
1082                                   do_pot, eFrame, A, f, t, pot, vpair, fpair, &
1083 <                                 d_grp, rgrp, fstrs)
1083 >                                 d_grp, rgrp, rCut)
1084   #endif
962                            f2strs(1:3) = f2strs(1:3) + fstrs(1:3)
1085                              vij = vij + vpair
1086 <                            fij(1:3) = fij(1:3) + fpair(1:3)
1086 >                            fij(1) = fij(1) + fpair(1)
1087 >                            fij(2) = fij(2) + fpair(2)
1088 >                            fij(3) = fij(3) + fpair(3)
1089                           endif
1090                        enddo inner
1091                     enddo
# Line 1122 | Line 1246 | contains
1246                  
1247                  ! prevent overcounting of the skips
1248                  if (i.lt.j) then
1249 <                   call get_interatomic_vector(q(:,i), &
1250 <                        q(:,j), d_atm, ratmsq)
1251 <                   rVal = dsqrt(ratmsq)
1128 <                   call get_switch(ratmsq, sw, dswdr, rVal, group_switch, &
1129 <                        in_switching_region)
1249 >                   call get_interatomic_vector(q(:,i), q(:,j), d_atm, ratmsq)
1250 >                   rVal = sqrt(ratmsq)
1251 >                   call get_switch(ratmsq, sw, dswdr, rVal,in_switching_region)
1252   #ifdef IS_MPI
1253                     call rf_self_excludes(i, j, sw, eFrame, d_atm, rVal, &
1254                          vpair, pot_local(ELECTROSTATIC_POT), f, t, do_pot)
# Line 1137 | Line 1259 | contains
1259                  endif
1260               enddo
1261            endif
1262 +
1263 +          if (do_box_dipole) then
1264 + #ifdef IS_MPI
1265 +             call accumulate_box_dipole(i, eFrame, q(:,i), pChg_local, &
1266 +                  nChg_local, pChgPos_local, nChgPos_local, dipVec_local, &
1267 +                  pChgCount_local, nChgCount_local)
1268 + #else
1269 +             call accumulate_box_dipole(i, eFrame, q(:,i), pChg, nChg, &
1270 +                  pChgPos, nChgPos, dipVec, pChgCount, nChgCount)
1271 + #endif
1272 +          endif
1273         enddo
1274      endif
1275 <    
1275 >
1276   #ifdef IS_MPI
1144    
1277      if (do_pot) then
1278 <       call mpi_allreduce(pot_local, pot, LR_POT_TYPES,mpi_double_precision,mpi_sum, &
1278 > #ifdef SINGLE_PRECISION
1279 >       call mpi_allreduce(pot_local, pot, LR_POT_TYPES,mpi_real,mpi_sum, &
1280              mpi_comm_world,mpi_err)            
1281 + #else
1282 +       call mpi_allreduce(pot_local, pot, LR_POT_TYPES,mpi_double_precision, &
1283 +            mpi_sum, mpi_comm_world,mpi_err)            
1284 + #endif
1285      endif
1286      
1287      if (do_stress) then
1288 + #ifdef SINGLE_PRECISION
1289 +       call mpi_allreduce(tau_Temp, tau, 9,mpi_real,mpi_sum, &
1290 +            mpi_comm_world,mpi_err)
1291 +       call mpi_allreduce(virial_Temp, virial,1,mpi_real,mpi_sum, &
1292 +            mpi_comm_world,mpi_err)
1293 + #else
1294         call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, &
1295              mpi_comm_world,mpi_err)
1296         call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, &
1297              mpi_comm_world,mpi_err)
1298 + #endif
1299      endif
1300      
1301 +    if (do_box_dipole) then
1302 +
1303 + #ifdef SINGLE_PRECISION
1304 +       call mpi_allreduce(pChg_local, pChg, 1, mpi_real, mpi_sum, &
1305 +            mpi_comm_world, mpi_err)
1306 +       call mpi_allreduce(nChg_local, nChg, 1, mpi_real, mpi_sum, &
1307 +            mpi_comm_world, mpi_err)
1308 +       call mpi_allreduce(pChgCount_local, pChgCount, 1, mpi_integer, mpi_sum,&
1309 +            mpi_comm_world, mpi_err)
1310 +       call mpi_allreduce(nChgCount_local, nChgCount, 1, mpi_integer, mpi_sum,&
1311 +            mpi_comm_world, mpi_err)
1312 +       call mpi_allreduce(pChgPos_local, pChgPos, 3, mpi_real, mpi_sum, &
1313 +            mpi_comm_world, mpi_err)
1314 +       call mpi_allreduce(nChgPos_local, nChgPos, 3, mpi_real, mpi_sum, &
1315 +            mpi_comm_world, mpi_err)
1316 +       call mpi_allreduce(dipVec_local, dipVec, 3, mpi_real, mpi_sum, &
1317 +            mpi_comm_world, mpi_err)
1318 + #else
1319 +       call mpi_allreduce(pChg_local, pChg, 1, mpi_double_precision, mpi_sum, &
1320 +            mpi_comm_world, mpi_err)
1321 +       call mpi_allreduce(nChg_local, nChg, 1, mpi_double_precision, mpi_sum, &
1322 +            mpi_comm_world, mpi_err)
1323 +       call mpi_allreduce(pChgCount_local, pChgCount, 1, mpi_integer,&
1324 +            mpi_sum, mpi_comm_world, mpi_err)
1325 +       call mpi_allreduce(nChgCount_local, nChgCount, 1, mpi_integer,&
1326 +            mpi_sum, mpi_comm_world, mpi_err)
1327 +       call mpi_allreduce(pChgPos_local, pChgPos, 3, mpi_double_precision, &
1328 +            mpi_sum, mpi_comm_world, mpi_err)
1329 +       call mpi_allreduce(nChgPos_local, nChgPos, 3, mpi_double_precision, &
1330 +            mpi_sum, mpi_comm_world, mpi_err)
1331 +       call mpi_allreduce(dipVec_local, dipVec, 3, mpi_double_precision, &
1332 +            mpi_sum, mpi_comm_world, mpi_err)
1333 + #endif
1334 +
1335 +    endif
1336 +
1337   #else
1338      
1339      if (do_stress) then
# Line 1162 | Line 1342 | contains
1342      endif
1343      
1344   #endif
1345 <    
1345 >
1346 >    if (do_box_dipole) then
1347 >       ! first load the accumulated dipole moment (if dipoles were present)
1348 >       boxDipole(1) = dipVec(1)
1349 >       boxDipole(2) = dipVec(2)
1350 >       boxDipole(3) = dipVec(3)
1351 >
1352 >       ! now include the dipole moment due to charges
1353 >       ! use the lesser of the positive and negative charge totals
1354 >       if (nChg .le. pChg) then
1355 >          chg_value = nChg
1356 >       else
1357 >          chg_value = pChg
1358 >       endif
1359 >      
1360 >       ! find the average positions
1361 >       if (pChgCount .gt. 0 .and. nChgCount .gt. 0) then
1362 >          pChgPos = pChgPos / pChgCount
1363 >          nChgPos = nChgPos / nChgCount
1364 >       endif
1365 >
1366 >       ! dipole is from the negative to the positive (physics notation)
1367 >       chgVec(1) = pChgPos(1) - nChgPos(1)
1368 >       chgVec(2) = pChgPos(2) - nChgPos(2)
1369 >       chgVec(3) = pChgPos(3) - nChgPos(3)
1370 >
1371 >       boxDipole(1) = boxDipole(1) + chgVec(1) * chg_value
1372 >       boxDipole(2) = boxDipole(2) + chgVec(2) * chg_value
1373 >       boxDipole(3) = boxDipole(3) + chgVec(3) * chg_value
1374 >
1375 >    endif
1376 >
1377    end subroutine do_force_loop
1378  
1168 !!$  subroutine do_pair(i, j, rijsq, d, sw, do_pot, &
1169 !!$       eFrame, A, f, t, pot, vpair, fpair, d_grp, r_grp)
1379    subroutine do_pair(i, j, rijsq, d, sw, do_pot, &
1380 <       eFrame, A, f, t, pot, vpair, fpair, d_grp, r_grp, fstrs)
1380 >       eFrame, A, f, t, pot, vpair, fpair, d_grp, r_grp, rCut)
1381  
1382      real( kind = dp ) :: vpair, sw
1383      real( kind = dp ), dimension(LR_POT_TYPES) :: pot
1384      real( kind = dp ), dimension(3) :: fpair
1176    real( kind = dp ), dimension(3) :: fstrs
1385      real( kind = dp ), dimension(nLocal)   :: mfact
1386      real( kind = dp ), dimension(9,nLocal) :: eFrame
1387      real( kind = dp ), dimension(9,nLocal) :: A
# Line 1186 | Line 1394 | contains
1394      real ( kind = dp ), intent(inout) :: r_grp
1395      real ( kind = dp ), intent(inout) :: d(3)
1396      real ( kind = dp ), intent(inout) :: d_grp(3)
1397 +    real ( kind = dp ), intent(inout) :: rCut
1398      real ( kind = dp ) :: r
1399 +    real ( kind = dp ) :: a_k, b_k, c_k, d_k, dx
1400      integer :: me_i, me_j
1401 +    integer :: k
1402  
1403      integer :: iHash
1404  
1405      r = sqrt(rijsq)
1406 <    vpair = 0.0d0
1407 <    fpair(1:3) = 0.0d0
1406 >    
1407 >    vpair = 0.0_dp
1408 >    fpair(1:3) = 0.0_dp
1409  
1410   #ifdef IS_MPI
1411      me_i = atid_row(i)
# Line 1206 | Line 1418 | contains
1418      iHash = InteractionHash(me_i, me_j)
1419      
1420      if ( iand(iHash, LJ_PAIR).ne.0 ) then
1421 <       call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1421 >       call do_lj_pair(i, j, d, r, rijsq, rcut, sw, vpair, fpair, &
1422              pot(VDW_POT), f, do_pot)
1423      endif
1424      
1425      if ( iand(iHash, ELECTROSTATIC_PAIR).ne.0 ) then
1426 < !!$       call doElectrostaticPair(i, j, d, r, rijsq, sw, vpair, fpair, &
1427 < !!$            pot(ELECTROSTATIC_POT), eFrame, f, t, do_pot)
1216 <       call doElectrostaticPair(i, j, d, r, rijsq, sw, vpair, fpair, &
1217 <            pot(ELECTROSTATIC_POT), eFrame, f, t, do_pot, fstrs)
1426 >       call doElectrostaticPair(i, j, d, r, rijsq, rcut, sw, vpair, fpair, &
1427 >            pot(ELECTROSTATIC_POT), eFrame, f, t, do_pot)
1428      endif
1429      
1430      if ( iand(iHash, STICKY_PAIR).ne.0 ) then
# Line 1233 | Line 1443 | contains
1443      endif
1444      
1445      if ( iand(iHash, GAYBERNE_LJ).ne.0 ) then
1446 <       call do_gb_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1446 >       call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1447              pot(VDW_POT), A, f, t, do_pot)
1448      endif
1449      
# Line 1251 | Line 1461 | contains
1461         call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1462              pot(VDW_POT), A, f, t, do_pot)
1463      endif
1464 +
1465 +    if ( iand(iHash, SC_PAIR).ne.0 ) then      
1466 +       call do_SC_pair(i, j, d, r, rijsq, rcut, sw, vpair, fpair, &
1467 +            pot(METALLIC_POT), f, do_pot)
1468 +    endif
1469      
1470    end subroutine do_pair
1471  
1472 <  subroutine do_prepair(i, j, rijsq, d, sw, rcijsq, dc, &
1472 >  subroutine do_prepair(i, j, rijsq, d, sw, rcijsq, dc, rCut, &
1473         do_pot, do_stress, eFrame, A, f, t, pot)
1474  
1475      real( kind = dp ) :: sw
# Line 1266 | Line 1481 | contains
1481  
1482      logical, intent(inout) :: do_pot, do_stress
1483      integer, intent(in) :: i, j
1484 <    real ( kind = dp ), intent(inout)    :: rijsq, rcijsq
1484 >    real ( kind = dp ), intent(inout)    :: rijsq, rcijsq, rCut
1485      real ( kind = dp )                :: r, rc
1486      real ( kind = dp ), intent(inout) :: d(3), dc(3)
1487  
1488      integer :: me_i, me_j, iHash
1489  
1490      r = sqrt(rijsq)
1491 <
1491 >    
1492   #ifdef IS_MPI  
1493      me_i = atid_row(i)
1494      me_j = atid_col(j)  
# Line 1285 | Line 1500 | contains
1500      iHash = InteractionHash(me_i, me_j)
1501  
1502      if ( iand(iHash, EAM_PAIR).ne.0 ) then      
1503 <            call calc_EAM_prepair_rho(i, j, d, r, rijsq )
1503 >            call calc_EAM_prepair_rho(i, j, d, r, rijsq)
1504      endif
1505 +
1506 +    if ( iand(iHash, SC_PAIR).ne.0 ) then      
1507 +            call calc_SC_prepair_rho(i, j, d, r, rijsq, rcut )
1508 +    endif
1509      
1510    end subroutine do_prepair
1511  
# Line 1298 | Line 1517 | contains
1517      if (FF_uses_EAM .and. SIM_uses_EAM) then
1518         call calc_EAM_preforce_Frho(nlocal,pot(METALLIC_POT))
1519      endif
1520 <
1521 <
1520 >    if (FF_uses_SC .and. SIM_uses_SC) then
1521 >       call calc_SC_preforce_Frho(nlocal,pot(METALLIC_POT))
1522 >    endif
1523    end subroutine do_preforce
1524  
1525  
# Line 1311 | Line 1531 | contains
1531      real( kind = dp ) :: d(3), scaled(3)
1532      integer i
1533  
1534 <    d(1:3) = q_j(1:3) - q_i(1:3)
1534 >    d(1) = q_j(1) - q_i(1)
1535 >    d(2) = q_j(2) - q_i(2)
1536 >    d(3) = q_j(3) - q_i(3)
1537  
1538      ! Wrap back into periodic box if necessary
1539      if ( SIM_uses_PBC ) then
1540  
1541         if( .not.boxIsOrthorhombic ) then
1542            ! calc the scaled coordinates.
1543 +          ! scaled = matmul(HmatInv, d)
1544  
1545 <          scaled = matmul(HmatInv, d)
1546 <
1545 >          scaled(1) = HmatInv(1,1)*d(1) + HmatInv(1,2)*d(2) + HmatInv(1,3)*d(3)
1546 >          scaled(2) = HmatInv(2,1)*d(1) + HmatInv(2,2)*d(2) + HmatInv(2,3)*d(3)
1547 >          scaled(3) = HmatInv(3,1)*d(1) + HmatInv(3,2)*d(2) + HmatInv(3,3)*d(3)
1548 >          
1549            ! wrap the scaled coordinates
1550  
1551 <          scaled = scaled  - anint(scaled)
1551 >          scaled(1) = scaled(1) - anint(scaled(1), kind=dp)
1552 >          scaled(2) = scaled(2) - anint(scaled(2), kind=dp)
1553 >          scaled(3) = scaled(3) - anint(scaled(3), kind=dp)
1554  
1328
1555            ! calc the wrapped real coordinates from the wrapped scaled
1556            ! coordinates
1557 +          ! d = matmul(Hmat,scaled)
1558 +          d(1)= Hmat(1,1)*scaled(1) + Hmat(1,2)*scaled(2) + Hmat(1,3)*scaled(3)
1559 +          d(2)= Hmat(2,1)*scaled(1) + Hmat(2,2)*scaled(2) + Hmat(2,3)*scaled(3)
1560 +          d(3)= Hmat(3,1)*scaled(1) + Hmat(3,2)*scaled(2) + Hmat(3,3)*scaled(3)
1561  
1332          d = matmul(Hmat,scaled)
1333
1562         else
1563            ! calc the scaled coordinates.
1564  
1565 <          do i = 1, 3
1566 <             scaled(i) = d(i) * HmatInv(i,i)
1565 >          scaled(1) = d(1) * HmatInv(1,1)
1566 >          scaled(2) = d(2) * HmatInv(2,2)
1567 >          scaled(3) = d(3) * HmatInv(3,3)
1568 >          
1569 >          ! wrap the scaled coordinates
1570 >          
1571 >          scaled(1) = scaled(1) - anint(scaled(1), kind=dp)
1572 >          scaled(2) = scaled(2) - anint(scaled(2), kind=dp)
1573 >          scaled(3) = scaled(3) - anint(scaled(3), kind=dp)
1574  
1575 <             ! wrap the scaled coordinates
1575 >          ! calc the wrapped real coordinates from the wrapped scaled
1576 >          ! coordinates
1577  
1578 <             scaled(i) = scaled(i) - anint(scaled(i))
1578 >          d(1) = scaled(1)*Hmat(1,1)
1579 >          d(2) = scaled(2)*Hmat(2,2)
1580 >          d(3) = scaled(3)*Hmat(3,3)
1581  
1344             ! calc the wrapped real coordinates from the wrapped scaled
1345             ! coordinates
1346
1347             d(i) = scaled(i)*Hmat(i,i)
1348          enddo
1582         endif
1583  
1584      endif
1585  
1586 <    r_sq = dot_product(d,d)
1586 >    r_sq = d(1)*d(1) + d(2)*d(2) + d(3)*d(3)
1587  
1588    end subroutine get_interatomic_vector
1589  
# Line 1481 | Line 1714 | contains
1714  
1715    function FF_RequiresPrepairCalc() result(doesit)
1716      logical :: doesit
1717 <    doesit = FF_uses_EAM
1717 >    doesit = FF_uses_EAM .or. FF_uses_SC &
1718 >         .or. FF_uses_MEAM
1719    end function FF_RequiresPrepairCalc
1720  
1721   #ifdef PROFILE

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines