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 2512 by gezelter, Thu Dec 15 21:43:16 2005 UTC vs.
Revision 3133 by chuckv, Tue May 22 19:30:27 2007 UTC

# Line 45 | Line 45
45  
46   !! @author Charles F. Vardeman II
47   !! @author Matthew Meineke
48 < !! @version $Id: doForces.F90,v 1.71 2005-12-15 21:43:16 gezelter Exp $, $Date: 2005-12-15 21:43:16 $, $Name: not supported by cvs2svn $, $Revision: 1.71 $
48 > !! @version $Id: doForces.F90,v 1.90 2007-05-22 19:30:27 chuckv Exp $, $Date: 2007-05-22 19:30:27 $, $Name: not supported by cvs2svn $, $Revision: 1.90 $
49  
50  
51   module doForces
# Line 72 | Line 72 | module doForces
72    PRIVATE
73  
74   #define __FORTRAN90
75 #include "UseTheForce/fSwitchingFunction.h"
75   #include "UseTheForce/fCutoffPolicy.h"
76   #include "UseTheForce/DarkSide/fInteractionMap.h"
77   #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h"
78  
80
79    INTEGER, PARAMETER:: PREPAIR_LOOP = 1
80    INTEGER, PARAMETER:: PAIR_LOOP    = 2
81  
# Line 91 | Line 89 | module doForces
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
# Line 107 | Line 106 | module doForces
106    logical, save :: SIM_requires_postpair_calc
107    logical, save :: SIM_requires_prepair_calc
108    logical, save :: SIM_uses_PBC
109 +  logical, save :: SIM_uses_AtomicVirial
110  
111    integer, save :: electrostaticSummationMethod
112    integer, save :: cutoffPolicy = TRADITIONAL_CUTOFF_POLICY
113  
114    real(kind=dp), save :: defaultRcut, defaultRsw, largestRcut
115    real(kind=dp), save :: skinThickness
116 <  logical, save :: defaultDoShift
116 >  logical, save :: defaultDoShiftPot
117 >  logical, save :: defaultDoShiftFrc
118  
119    public :: init_FF
120    public :: setCutoffs
121    public :: cWasLame
122    public :: setElectrostaticMethod
123 +  public :: setBoxDipole
124 +  public :: getBoxDipole
125    public :: setCutoffPolicy
126    public :: setSkinThickness
127    public :: do_force_loop
# Line 149 | Line 152 | contains
152    end type gtypeCutoffs
153    type(gtypeCutoffs), dimension(:,:), allocatable :: gtypeCutoffMap
154  
155 +  real(kind=dp), dimension(3) :: boxDipole
156 +
157   contains
158  
159    subroutine createInteractionHash()
# Line 281 | Line 286 | contains
286      logical :: i_is_GB
287      logical :: i_is_EAM
288      logical :: i_is_Shape
289 +    logical :: i_is_SC
290      logical :: GtypeFound
291  
292      integer :: myStatus, nAtypes,  i, j, istart, iend, jstart, jend
# Line 310 | Line 316 | contains
316            call getElementProperty(atypes, i, "is_GayBerne", i_is_GB)
317            call getElementProperty(atypes, i, "is_EAM", i_is_EAM)
318            call getElementProperty(atypes, i, "is_Shape", i_is_Shape)
319 <          
319 >          call getElementProperty(atypes, i, "is_SC", i_is_SC)
320  
321            if (haveDefaultCutoffs) then
322               atypeMaxCutoff(i) = defaultRcut
# Line 341 | Line 347 | contains
347               endif
348               if (i_is_Shape) then
349                  thisRcut = getShapeCut(i)
350 +                if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
351 +             endif
352 +             if (i_is_SC) then
353 +                thisRcut = getSCCut(i)
354                  if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
355               endif
356            endif
# Line 394 | Line 404 | contains
404         allocate(groupToGtypeCol(jend))
405      end if
406  
407 <    if(.not.associated(groupToGtypeCol)) then
408 <       allocate(groupToGtypeCol(jend))
407 >    if(.not.associated(groupMaxCutoffCol)) then
408 >       allocate(groupMaxCutoffCol(jend))
409      else
410 <       deallocate(groupToGtypeCol)
411 <       allocate(groupToGtypeCol(jend))
410 >       deallocate(groupMaxCutoffCol)
411 >       allocate(groupMaxCutoffCol(jend))
412      end if
413      if(.not.associated(gtypeMaxCutoffCol)) then
414         allocate(gtypeMaxCutoffCol(jend))
# Line 419 | Line 429 | contains
429      !! largest cutoff for any atypes present in this group.  We also
430      !! create gtypes at this point.
431      
432 <    tol = 1.0d-6
432 >    tol = 1.0e-6_dp
433      nGroupTypesRow = 0
434 <
434 >    nGroupTypesCol = 0
435      do i = istart, iend      
436         n_in_i = groupStartRow(i+1) - groupStartRow(i)
437         groupMaxCutoffRow(i) = 0.0_dp
# Line 553 | Line 563 | contains
563      haveGtypeCutoffMap = .true.
564     end subroutine createGtypeCutoffMap
565  
566 <   subroutine setCutoffs(defRcut, defRsw)
566 >   subroutine setCutoffs(defRcut, defRsw, defSP, defSF)
567  
568       real(kind=dp),intent(in) :: defRcut, defRsw
569 +     logical, intent(in) :: defSP, defSF
570       character(len = statusMsgSize) :: errMsg
571       integer :: localError
572  
573       defaultRcut = defRcut
574       defaultRsw = defRsw
575      
576 <     defaultDoShift = .false.
577 <     if (abs(defaultRcut-defaultRsw) .lt. 0.0001) then
567 <        
568 <        write(errMsg, *) &
569 <             'cutoffRadius and switchingRadius are set to the same', newline &
570 <             // tab, 'value.  OOPSE will use shifted ', newline &
571 <             // tab, 'potentials instead of switching functions.'
572 <        
573 <        call handleInfo("setCutoffs", errMsg)
574 <        
575 <        defaultDoShift = .true.
576 <        
577 <     endif
576 >     defaultDoShiftPot = defSP
577 >     defaultDoShiftFrc = defSF
578  
579 <     localError = 0
580 <     call setLJDefaultCutoff( defaultRcut, defaultDoShift )
581 <     call setElectrostaticCutoffRadius( defaultRcut, defaultRsw )
582 <     call setCutoffEAM( defaultRcut, localError)
583 <     if (localError /= 0) then
584 <       write(errMsg, *) 'An error has occured in setting the EAM cutoff'
585 <       call handleError("setCutoffs", errMsg)
586 <     end if
587 <     call set_switch(GROUP_SWITCH, defaultRsw, defaultRcut)
588 <
579 >     if (abs(defaultRcut-defaultRsw) .lt. 0.0001) then
580 >        if (defaultDoShiftFrc) then
581 >           write(errMsg, *) &
582 >                'cutoffRadius and switchingRadius are set to the', newline &
583 >                // tab, 'same value.  OOPSE will use shifted force', newline &
584 >                // tab, 'potentials instead of switching functions.'
585 >          
586 >           call handleInfo("setCutoffs", errMsg)
587 >        else
588 >           write(errMsg, *) &
589 >                'cutoffRadius and switchingRadius are set to the', newline &
590 >                // tab, 'same value.  OOPSE will use shifted', newline &
591 >                // tab, 'potentials instead of switching functions.'
592 >          
593 >           call handleInfo("setCutoffs", errMsg)
594 >          
595 >           defaultDoShiftPot = .true.
596 >        endif
597 >                
598 >     endif
599 >    
600 >     localError = 0
601 >     call setLJDefaultCutoff( defaultRcut, defaultDoShiftPot, &
602 >          defaultDoShiftFrc )
603 >     call setElectrostaticCutoffRadius( defaultRcut, defaultRsw )
604 >     call setCutoffEAM( defaultRcut )
605 >     call setCutoffSC( defaultRcut )
606 >     call set_switch(defaultRsw, defaultRcut)
607 >     call setHmatDangerousRcutValue(defaultRcut)
608 >        
609       haveDefaultCutoffs = .true.
610       haveGtypeCutoffMap = .false.
611 +
612     end subroutine setCutoffs
613  
614     subroutine cWasLame()
# Line 606 | Line 627 | contains
627       haveGtypeCutoffMap = .false.
628      
629     end subroutine setCutoffPolicy
630 <  
630 >    
631 >   subroutine setBoxDipole()
632 >
633 >     do_box_dipole = .true.
634 >    
635 >   end subroutine setBoxDipole
636 >
637 >   subroutine getBoxDipole( box_dipole )
638 >
639 >     real(kind=dp), intent(inout), dimension(3) :: box_dipole
640 >
641 >     box_dipole = boxDipole
642 >
643 >   end subroutine getBoxDipole
644 >
645     subroutine setElectrostaticMethod( thisESM )
646  
647       integer, intent(in) :: thisESM
# Line 632 | Line 667 | contains
667       SIM_requires_postpair_calc = SimRequiresPostpairCalc()
668       SIM_requires_prepair_calc = SimRequiresPrepairCalc()
669       SIM_uses_PBC = SimUsesPBC()
670 <    
670 >     SIM_uses_SC = SimUsesSC()
671 >     SIM_uses_AtomicVirial = SimUsesAtomicVirial()
672 >
673       haveSIMvariables = .true.
674      
675       return
# Line 640 | Line 677 | contains
677  
678    subroutine doReadyCheck(error)
679      integer, intent(out) :: error
643
680      integer :: myStatus
681  
682      error = 0
# Line 653 | Line 689 | contains
689         call createGtypeCutoffMap()      
690      endif
691  
656
692      if (VisitCutoffsAfterComputing) then
693 <       call set_switch(GROUP_SWITCH, largestRcut, largestRcut)      
693 >       call set_switch(largestRcut, largestRcut)      
694 >       call setHmatDangerousRcutValue(largestRcut)
695 >       call setCutoffEAM(largestRcut)
696 >       call setCutoffSC(largestRcut)
697 >       VisitCutoffsAfterComputing = .false.
698      endif
699  
661
700      if (.not. haveSIMvariables) then
701         call setSimVariables()
702      endif
703  
666  !  if (.not. haveRlist) then
667  !     write(default_error, *) 'rList has not been set in doForces!'
668  !     error = -1
669  !     return
670  !  endif
671
704      if (.not. haveNeighborList) then
705         write(default_error, *) 'neighbor list has not been initialized in doForces!'
706         error = -1
707         return
708      end if
709 <
709 >    
710      if (.not. haveSaneForceField) then
711         write(default_error, *) 'Force Field is not sane in doForces!'
712         error = -1
713         return
714      end if
715 <
715 >    
716   #ifdef IS_MPI
717      if (.not. isMPISimSet()) then
718         write(default_error,*) "ERROR: mpiSimulation has not been initialized!"
# Line 711 | Line 743 | contains
743      FF_uses_Dipoles = .false.
744      FF_uses_GayBerne = .false.
745      FF_uses_EAM = .false.
746 +    FF_uses_SC = .false.
747  
748      call getMatchingElementList(atypes, "is_Directional", .true., &
749           nMatches, MatchList)
# Line 727 | Line 760 | contains
760      call getMatchingElementList(atypes, "is_EAM", .true., nMatches, MatchList)
761      if (nMatches .gt. 0) FF_uses_EAM = .true.
762  
763 +    call getMatchingElementList(atypes, "is_SC", .true., nMatches, MatchList)
764 +    if (nMatches .gt. 0) FF_uses_SC = .true.
765  
766 +
767      haveSaneForceField = .true.
768  
769      if (FF_uses_EAM) then
# Line 792 | Line 828 | contains
828      integer :: istart, iend
829      integer :: ia, jb, atom1, atom2
830      integer :: nlist
831 <    real( kind = DP ) :: ratmsq, rgrpsq, rgrp, vpair, vij
831 >    real( kind = DP ) :: ratmsq, rgrpsq, rgrp, rag, vpair, vij
832      real( kind = DP ) :: sw, dswdr, swderiv, mf
833      real( kind = DP ) :: rVal
834 <    real(kind=dp),dimension(3) :: d_atm, d_grp, fpair, fij
835 <    real(kind=dp) :: rfpot, mu_i, virial
834 >    real(kind=dp),dimension(3) :: d_atm, d_grp, fpair, fij, fg, dag
835 >    real(kind=dp) :: rfpot, mu_i
836      real(kind=dp):: rCut
837      integer :: me_i, me_j, n_in_i, n_in_j
838      logical :: is_dp_i
# Line 807 | Line 843 | contains
843      integer :: loopStart, loopEnd, loop
844      integer :: iHash
845      integer :: i1
846 <  
846 >
847 >    !! the variables for the box dipole moment
848 > #ifdef IS_MPI
849 >    integer :: pChgCount_local
850 >    integer :: nChgCount_local
851 >    real(kind=dp) :: pChg_local
852 >    real(kind=dp) :: nChg_local
853 >    real(kind=dp), dimension(3) :: pChgPos_local
854 >    real(kind=dp), dimension(3) :: nChgPos_local
855 >    real(kind=dp), dimension(3) :: dipVec_local
856 > #endif
857 >    integer :: pChgCount
858 >    integer :: nChgCount
859 >    real(kind=dp) :: pChg
860 >    real(kind=dp) :: nChg
861 >    real(kind=dp) :: chg_value
862 >    real(kind=dp), dimension(3) :: pChgPos
863 >    real(kind=dp), dimension(3) :: nChgPos
864 >    real(kind=dp), dimension(3) :: dipVec
865 >    real(kind=dp), dimension(3) :: chgVec
866 >
867 >    !! initialize box dipole variables
868 >    if (do_box_dipole) then
869 > #ifdef IS_MPI
870 >       pChg_local = 0.0_dp
871 >       nChg_local = 0.0_dp
872 >       pChgCount_local = 0
873 >       nChgCount_local = 0
874 >       do i=1, 3
875 >          pChgPos_local = 0.0_dp
876 >          nChgPos_local = 0.0_dp
877 >          dipVec_local = 0.0_dp
878 >       enddo
879 > #endif
880 >       pChg = 0.0_dp
881 >       nChg = 0.0_dp
882 >       pChgCount = 0
883 >       nChgCount = 0
884 >       chg_value = 0.0_dp
885 >      
886 >       do i=1, 3
887 >          pChgPos(i) = 0.0_dp
888 >          nChgPos(i) = 0.0_dp
889 >          dipVec(i) = 0.0_dp
890 >          chgVec(i) = 0.0_dp
891 >          boxDipole(i) = 0.0_dp
892 >       enddo
893 >    endif
894  
895      !! initialize local variables  
896  
# Line 954 | Line 1037 | contains
1037  
1038                     list(nlist) = j
1039                  endif
1040 <
958 <
959 <                
1040 >                
1041                  if (rgrpsq < gtypeCutoffMap(groupToGtypeRow(i),groupToGtypeCol(j))%rCutsq) then
1042  
1043                     rCut = gtypeCutoffMap(groupToGtypeRow(i),groupToGtypeCol(j))%rCut
1044                     if (loop .eq. PAIR_LOOP) then
1045 <                      vij = 0.0d0
1046 <                      fij(1:3) = 0.0d0
1045 >                      vij = 0.0_dp
1046 >                      fij(1) = 0.0_dp
1047 >                      fij(2) = 0.0_dp
1048 >                      fij(3) = 0.0_dp
1049                     endif
1050                    
1051 <                   call get_switch(rgrpsq, sw, dswdr, rgrp, &
969 <                        group_switch, in_switching_region)
1051 >                   call get_switch(rgrpsq, sw, dswdr,rgrp, in_switching_region)
1052                    
1053                     n_in_j = groupStartCol(j+1) - groupStartCol(j)
1054                    
# Line 981 | Line 1063 | contains
1063                           if (skipThisPair(atom1, atom2))  cycle inner
1064                          
1065                           if ((n_in_i .eq. 1).and.(n_in_j .eq. 1)) then
1066 <                            d_atm(1:3) = d_grp(1:3)
1066 >                            d_atm(1) = d_grp(1)
1067 >                            d_atm(2) = d_grp(2)
1068 >                            d_atm(3) = d_grp(3)
1069                              ratmsq = rgrpsq
1070                           else
1071   #ifdef IS_MPI
# Line 1014 | Line 1098 | contains
1098                                   d_grp, rgrp, rCut)
1099   #endif
1100                              vij = vij + vpair
1101 <                            fij(1:3) = fij(1:3) + fpair(1:3)
1101 >                            fij(1) = fij(1) + fpair(1)
1102 >                            fij(2) = fij(2) + fpair(2)
1103 >                            fij(3) = fij(3) + fpair(3)
1104 >                            if (do_stress) then
1105 >                               call add_stress_tensor(d_atm, fpair, tau)
1106 >                            endif
1107                           endif
1108                        enddo inner
1109                     enddo
# Line 1022 | Line 1111 | contains
1111                     if (loop .eq. PAIR_LOOP) then
1112                        if (in_switching_region) then
1113                           swderiv = vij*dswdr/rgrp
1114 <                         fij(1) = fij(1) + swderiv*d_grp(1)
1115 <                         fij(2) = fij(2) + swderiv*d_grp(2)
1116 <                         fij(3) = fij(3) + swderiv*d_grp(3)
1114 >                         fg = swderiv*d_grp
1115 >
1116 >                         fij(1) = fij(1) + fg(1)
1117 >                         fij(2) = fij(2) + fg(2)
1118 >                         fij(3) = fij(3) + fg(3)
1119                          
1120 +                         if (do_stress .and. (n_in_i .eq. 1).and.(n_in_j .eq. 1)) then
1121 +                            call add_stress_tensor(d_atm, fg, tau)
1122 +                         endif  
1123 +                        
1124                           do ia=groupStartRow(i), groupStartRow(i+1)-1
1125                              atom1=groupListRow(ia)
1126                              mf = mfactRow(atom1)
1127 +                            ! fg is the force on atom ia due to cutoff group's
1128 +                            ! presence in switching region
1129 +                            fg = swderiv*d_grp*mf
1130   #ifdef IS_MPI
1131 <                            f_Row(1,atom1) = f_Row(1,atom1) + swderiv*d_grp(1)*mf
1132 <                            f_Row(2,atom1) = f_Row(2,atom1) + swderiv*d_grp(2)*mf
1133 <                            f_Row(3,atom1) = f_Row(3,atom1) + swderiv*d_grp(3)*mf
1131 >                            f_Row(1,atom1) = f_Row(1,atom1) + fg(1)
1132 >                            f_Row(2,atom1) = f_Row(2,atom1) + fg(2)
1133 >                            f_Row(3,atom1) = f_Row(3,atom1) + fg(3)
1134   #else
1135 <                            f(1,atom1) = f(1,atom1) + swderiv*d_grp(1)*mf
1136 <                            f(2,atom1) = f(2,atom1) + swderiv*d_grp(2)*mf
1137 <                            f(3,atom1) = f(3,atom1) + swderiv*d_grp(3)*mf
1135 >                            f(1,atom1) = f(1,atom1) + fg(1)
1136 >                            f(2,atom1) = f(2,atom1) + fg(2)
1137 >                            f(3,atom1) = f(3,atom1) + fg(3)
1138   #endif
1139 +                            if (n_in_i .gt. 1) then
1140 +                               if (do_stress.and.SIM_uses_AtomicVirial) then
1141 +                                  ! find the distance between the atom and the center of
1142 +                                  ! the cutoff group:
1143 + #ifdef IS_MPI
1144 +                                  call get_interatomic_vector(q_Row(:,atom1), &
1145 +                                       q_group_Row(:,i), dag, rag)
1146 + #else
1147 +                                  call get_interatomic_vector(q(:,atom1), &
1148 +                                       q_group(:,i), dag, rag)
1149 + #endif
1150 +                                  call add_stress_tensor(dag,fg,tau)
1151 +                               endif
1152 +                            endif
1153                           enddo
1154                          
1155                           do jb=groupStartCol(j), groupStartCol(j+1)-1
1156                              atom2=groupListCol(jb)
1157                              mf = mfactCol(atom2)
1158 +                            ! fg is the force on atom jb due to cutoff group's
1159 +                            ! presence in switching region
1160 +                            fg = -swderiv*d_grp*mf
1161   #ifdef IS_MPI
1162 <                            f_Col(1,atom2) = f_Col(1,atom2) - swderiv*d_grp(1)*mf
1163 <                            f_Col(2,atom2) = f_Col(2,atom2) - swderiv*d_grp(2)*mf
1164 <                            f_Col(3,atom2) = f_Col(3,atom2) - swderiv*d_grp(3)*mf
1162 >                            f_Col(1,atom2) = f_Col(1,atom2) + fg(1)
1163 >                            f_Col(2,atom2) = f_Col(2,atom2) + fg(2)
1164 >                            f_Col(3,atom2) = f_Col(3,atom2) + fg(3)
1165   #else
1166 <                            f(1,atom2) = f(1,atom2) - swderiv*d_grp(1)*mf
1167 <                            f(2,atom2) = f(2,atom2) - swderiv*d_grp(2)*mf
1168 <                            f(3,atom2) = f(3,atom2) - swderiv*d_grp(3)*mf
1166 >                            f(1,atom2) = f(1,atom2) + fg(1)
1167 >                            f(2,atom2) = f(2,atom2) + fg(2)
1168 >                            f(3,atom2) = f(3,atom2) + fg(3)
1169   #endif
1170 +                            if (n_in_j .gt. 1) then
1171 +                               if (do_stress.and.SIM_uses_AtomicVirial) then
1172 +                                  ! find the distance between the atom and the center of
1173 +                                  ! the cutoff group:
1174 + #ifdef IS_MPI
1175 +                                  call get_interatomic_vector(q_Col(:,atom2), &
1176 +                                       q_group_Col(:,j), dag, rag)
1177 + #else
1178 +                                  call get_interatomic_vector(q(:,atom2), &
1179 +                                       q_group(:,j), dag, rag)
1180 + #endif
1181 +                                  call add_stress_tensor(dag,fg,tau)                              
1182 +                               endif
1183 +                            endif                            
1184                           enddo
1185                        endif
1057
1058                      if (do_stress) call add_stress_tensor(d_grp, fij)
1186                     endif
1187                  endif
1188               endif
# Line 1078 | Line 1205 | contains
1205         endif
1206  
1207         if (loop .eq. PREPAIR_LOOP) then
1208 + #ifdef IS_MPI
1209 +          call do_preforce(nlocal, pot_local)
1210 + #else
1211            call do_preforce(nlocal, pot)
1212 + #endif
1213         endif
1214  
1215      enddo
# Line 1175 | Line 1306 | contains
1306                  
1307                  ! prevent overcounting of the skips
1308                  if (i.lt.j) then
1309 <                   call get_interatomic_vector(q(:,i), &
1310 <                        q(:,j), d_atm, ratmsq)
1311 <                   rVal = dsqrt(ratmsq)
1181 <                   call get_switch(ratmsq, sw, dswdr, rVal, group_switch, &
1182 <                        in_switching_region)
1309 >                   call get_interatomic_vector(q(:,i), q(:,j), d_atm, ratmsq)
1310 >                   rVal = sqrt(ratmsq)
1311 >                   call get_switch(ratmsq, sw, dswdr, rVal,in_switching_region)
1312   #ifdef IS_MPI
1313                     call rf_self_excludes(i, j, sw, eFrame, d_atm, rVal, &
1314                          vpair, pot_local(ELECTROSTATIC_POT), f, t, do_pot)
# Line 1190 | Line 1319 | contains
1319                  endif
1320               enddo
1321            endif
1322 +
1323 +          if (do_box_dipole) then
1324 + #ifdef IS_MPI
1325 +             call accumulate_box_dipole(i, eFrame, q(:,i), pChg_local, &
1326 +                  nChg_local, pChgPos_local, nChgPos_local, dipVec_local, &
1327 +                  pChgCount_local, nChgCount_local)
1328 + #else
1329 +             call accumulate_box_dipole(i, eFrame, q(:,i), pChg, nChg, &
1330 +                  pChgPos, nChgPos, dipVec, pChgCount, nChgCount)
1331 + #endif
1332 +          endif
1333         enddo
1334      endif
1335 <    
1335 >
1336   #ifdef IS_MPI
1197    
1337      if (do_pot) then
1338 <       call mpi_allreduce(pot_local, pot, LR_POT_TYPES,mpi_double_precision,mpi_sum, &
1338 > #ifdef SINGLE_PRECISION
1339 >       call mpi_allreduce(pot_local, pot, LR_POT_TYPES,mpi_real,mpi_sum, &
1340              mpi_comm_world,mpi_err)            
1341 + #else
1342 +       call mpi_allreduce(pot_local, pot, LR_POT_TYPES,mpi_double_precision, &
1343 +            mpi_sum, mpi_comm_world,mpi_err)            
1344 + #endif
1345      endif
1346 <    
1347 <    if (do_stress) then
1348 <       call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, &
1349 <            mpi_comm_world,mpi_err)
1350 <       call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, &
1351 <            mpi_comm_world,mpi_err)
1352 <    endif
1353 <    
1346 >        
1347 >    if (do_box_dipole) then
1348 >
1349 > #ifdef SINGLE_PRECISION
1350 >       call mpi_allreduce(pChg_local, pChg, 1, mpi_real, mpi_sum, &
1351 >            mpi_comm_world, mpi_err)
1352 >       call mpi_allreduce(nChg_local, nChg, 1, mpi_real, mpi_sum, &
1353 >            mpi_comm_world, mpi_err)
1354 >       call mpi_allreduce(pChgCount_local, pChgCount, 1, mpi_integer, mpi_sum,&
1355 >            mpi_comm_world, mpi_err)
1356 >       call mpi_allreduce(nChgCount_local, nChgCount, 1, mpi_integer, mpi_sum,&
1357 >            mpi_comm_world, mpi_err)
1358 >       call mpi_allreduce(pChgPos_local, pChgPos, 3, mpi_real, mpi_sum, &
1359 >            mpi_comm_world, mpi_err)
1360 >       call mpi_allreduce(nChgPos_local, nChgPos, 3, mpi_real, mpi_sum, &
1361 >            mpi_comm_world, mpi_err)
1362 >       call mpi_allreduce(dipVec_local, dipVec, 3, mpi_real, mpi_sum, &
1363 >            mpi_comm_world, mpi_err)
1364   #else
1365 <    
1366 <    if (do_stress) then
1367 <       tau = tau_Temp
1368 <       virial = virial_Temp
1365 >       call mpi_allreduce(pChg_local, pChg, 1, mpi_double_precision, mpi_sum, &
1366 >            mpi_comm_world, mpi_err)
1367 >       call mpi_allreduce(nChg_local, nChg, 1, mpi_double_precision, mpi_sum, &
1368 >            mpi_comm_world, mpi_err)
1369 >       call mpi_allreduce(pChgCount_local, pChgCount, 1, mpi_integer,&
1370 >            mpi_sum, mpi_comm_world, mpi_err)
1371 >       call mpi_allreduce(nChgCount_local, nChgCount, 1, mpi_integer,&
1372 >            mpi_sum, mpi_comm_world, mpi_err)
1373 >       call mpi_allreduce(pChgPos_local, pChgPos, 3, mpi_double_precision, &
1374 >            mpi_sum, mpi_comm_world, mpi_err)
1375 >       call mpi_allreduce(nChgPos_local, nChgPos, 3, mpi_double_precision, &
1376 >            mpi_sum, mpi_comm_world, mpi_err)
1377 >       call mpi_allreduce(dipVec_local, dipVec, 3, mpi_double_precision, &
1378 >            mpi_sum, mpi_comm_world, mpi_err)
1379 > #endif
1380 >
1381      endif
1382      
1383   #endif
1384 <    
1384 >
1385 >    if (do_box_dipole) then
1386 >       ! first load the accumulated dipole moment (if dipoles were present)
1387 >       boxDipole(1) = dipVec(1)
1388 >       boxDipole(2) = dipVec(2)
1389 >       boxDipole(3) = dipVec(3)
1390 >
1391 >       ! now include the dipole moment due to charges
1392 >       ! use the lesser of the positive and negative charge totals
1393 >       if (nChg .le. pChg) then
1394 >          chg_value = nChg
1395 >       else
1396 >          chg_value = pChg
1397 >       endif
1398 >      
1399 >       ! find the average positions
1400 >       if (pChgCount .gt. 0 .and. nChgCount .gt. 0) then
1401 >          pChgPos = pChgPos / pChgCount
1402 >          nChgPos = nChgPos / nChgCount
1403 >       endif
1404 >
1405 >       ! dipole is from the negative to the positive (physics notation)
1406 >       chgVec(1) = pChgPos(1) - nChgPos(1)
1407 >       chgVec(2) = pChgPos(2) - nChgPos(2)
1408 >       chgVec(3) = pChgPos(3) - nChgPos(3)
1409 >
1410 >       boxDipole(1) = boxDipole(1) + chgVec(1) * chg_value
1411 >       boxDipole(2) = boxDipole(2) + chgVec(2) * chg_value
1412 >       boxDipole(3) = boxDipole(3) + chgVec(3) * chg_value
1413 >
1414 >    endif
1415 >
1416    end subroutine do_force_loop
1417  
1418    subroutine do_pair(i, j, rijsq, d, sw, do_pot, &
# Line 1238 | Line 1435 | contains
1435      real ( kind = dp ), intent(inout) :: d_grp(3)
1436      real ( kind = dp ), intent(inout) :: rCut
1437      real ( kind = dp ) :: r
1438 +    real ( kind = dp ) :: a_k, b_k, c_k, d_k, dx
1439      integer :: me_i, me_j
1440 +    integer :: k
1441  
1442      integer :: iHash
1443  
1444      r = sqrt(rijsq)
1445 <    vpair = 0.0d0
1446 <    fpair(1:3) = 0.0d0
1445 >    
1446 >    vpair = 0.0_dp
1447 >    fpair(1:3) = 0.0_dp
1448  
1449   #ifdef IS_MPI
1450      me_i = atid_row(i)
# Line 1282 | Line 1482 | contains
1482      endif
1483      
1484      if ( iand(iHash, GAYBERNE_LJ).ne.0 ) then
1485 <       call do_gb_lj_pair(i, j, d, r, rijsq, rcut, sw, vpair, fpair, &
1485 >       call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1486              pot(VDW_POT), A, f, t, do_pot)
1487      endif
1488      
# Line 1305 | Line 1505 | contains
1505         call do_SC_pair(i, j, d, r, rijsq, rcut, sw, vpair, fpair, &
1506              pot(METALLIC_POT), f, do_pot)
1507      endif
1308
1309    
1508      
1509    end subroutine do_pair
1510  
# Line 1329 | Line 1527 | contains
1527      integer :: me_i, me_j, iHash
1528  
1529      r = sqrt(rijsq)
1530 <
1530 >    
1531   #ifdef IS_MPI  
1532      me_i = atid_row(i)
1533      me_j = atid_col(j)  
# Line 1361 | Line 1559 | contains
1559      if (FF_uses_SC .and. SIM_uses_SC) then
1560         call calc_SC_preforce_Frho(nlocal,pot(METALLIC_POT))
1561      endif
1364
1365
1562    end subroutine do_preforce
1563  
1564  
# Line 1374 | Line 1570 | contains
1570      real( kind = dp ) :: d(3), scaled(3)
1571      integer i
1572  
1573 <    d(1:3) = q_j(1:3) - q_i(1:3)
1573 >    d(1) = q_j(1) - q_i(1)
1574 >    d(2) = q_j(2) - q_i(2)
1575 >    d(3) = q_j(3) - q_i(3)
1576  
1577      ! Wrap back into periodic box if necessary
1578      if ( SIM_uses_PBC ) then
1579  
1580         if( .not.boxIsOrthorhombic ) then
1581            ! calc the scaled coordinates.
1582 +          ! scaled = matmul(HmatInv, d)
1583  
1584 <          scaled = matmul(HmatInv, d)
1585 <
1584 >          scaled(1) = HmatInv(1,1)*d(1) + HmatInv(1,2)*d(2) + HmatInv(1,3)*d(3)
1585 >          scaled(2) = HmatInv(2,1)*d(1) + HmatInv(2,2)*d(2) + HmatInv(2,3)*d(3)
1586 >          scaled(3) = HmatInv(3,1)*d(1) + HmatInv(3,2)*d(2) + HmatInv(3,3)*d(3)
1587 >          
1588            ! wrap the scaled coordinates
1589  
1590 <          scaled = scaled  - anint(scaled)
1590 >          scaled(1) = scaled(1) - anint(scaled(1), kind=dp)
1591 >          scaled(2) = scaled(2) - anint(scaled(2), kind=dp)
1592 >          scaled(3) = scaled(3) - anint(scaled(3), kind=dp)
1593  
1391
1594            ! calc the wrapped real coordinates from the wrapped scaled
1595            ! coordinates
1596 <
1597 <          d = matmul(Hmat,scaled)
1596 >          ! d = matmul(Hmat,scaled)
1597 >          d(1)= Hmat(1,1)*scaled(1) + Hmat(1,2)*scaled(2) + Hmat(1,3)*scaled(3)
1598 >          d(2)= Hmat(2,1)*scaled(1) + Hmat(2,2)*scaled(2) + Hmat(2,3)*scaled(3)
1599 >          d(3)= Hmat(3,1)*scaled(1) + Hmat(3,2)*scaled(2) + Hmat(3,3)*scaled(3)
1600  
1601         else
1602            ! calc the scaled coordinates.
1603  
1604 <          do i = 1, 3
1605 <             scaled(i) = d(i) * HmatInv(i,i)
1604 >          scaled(1) = d(1) * HmatInv(1,1)
1605 >          scaled(2) = d(2) * HmatInv(2,2)
1606 >          scaled(3) = d(3) * HmatInv(3,3)
1607 >          
1608 >          ! wrap the scaled coordinates
1609 >          
1610 >          scaled(1) = scaled(1) - anint(scaled(1), kind=dp)
1611 >          scaled(2) = scaled(2) - anint(scaled(2), kind=dp)
1612 >          scaled(3) = scaled(3) - anint(scaled(3), kind=dp)
1613  
1614 <             ! wrap the scaled coordinates
1614 >          ! calc the wrapped real coordinates from the wrapped scaled
1615 >          ! coordinates
1616  
1617 <             scaled(i) = scaled(i) - anint(scaled(i))
1617 >          d(1) = scaled(1)*Hmat(1,1)
1618 >          d(2) = scaled(2)*Hmat(2,2)
1619 >          d(3) = scaled(3)*Hmat(3,3)
1620  
1407             ! calc the wrapped real coordinates from the wrapped scaled
1408             ! coordinates
1409
1410             d(i) = scaled(i)*Hmat(i,i)
1411          enddo
1621         endif
1622  
1623      endif
1624  
1625 <    r_sq = dot_product(d,d)
1625 >    r_sq = d(1)*d(1) + d(2)*d(2) + d(3)*d(3)
1626  
1627    end subroutine get_interatomic_vector
1628  
# Line 1451 | Line 1660 | contains
1660         call clean_EAM()
1661      endif
1662  
1454    tau_Temp = 0.0_dp
1455    virial_Temp = 0.0_dp
1663    end subroutine zero_work_arrays
1664  
1665    function skipThisPair(atom1, atom2) result(skip_it)
# Line 1557 | Line 1764 | contains
1764  
1765    !! This cleans componets of force arrays belonging only to fortran
1766  
1767 <  subroutine add_stress_tensor(dpair, fpair)
1767 >  subroutine add_stress_tensor(dpair, fpair, tau)
1768  
1769      real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1770 +    real( kind = dp ), dimension(9), intent(inout) :: tau
1771  
1772      ! because the d vector is the rj - ri vector, and
1773      ! because fx, fy, fz are the force on atom i, we need a
1774      ! negative sign here:  
1775  
1776 <    tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1777 <    tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1778 <    tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1779 <    tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1780 <    tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1781 <    tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1782 <    tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1783 <    tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1784 <    tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1776 >    tau(1) = tau(1) - dpair(1) * fpair(1)
1777 >    tau(2) = tau(2) - dpair(1) * fpair(2)
1778 >    tau(3) = tau(3) - dpair(1) * fpair(3)
1779 >    tau(4) = tau(4) - dpair(2) * fpair(1)
1780 >    tau(5) = tau(5) - dpair(2) * fpair(2)
1781 >    tau(6) = tau(6) - dpair(2) * fpair(3)
1782 >    tau(7) = tau(7) - dpair(3) * fpair(1)
1783 >    tau(8) = tau(8) - dpair(3) * fpair(2)
1784 >    tau(9) = tau(9) - dpair(3) * fpair(3)
1785  
1578    virial_Temp = virial_Temp + &
1579         (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1580
1786    end subroutine add_stress_tensor
1787  
1788   end module doForces

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines