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

Comparing trunk/OOPSE-4/src/UseTheForce/DarkSide/electrostatic.F90 (file contents):
Revision 2395 by chrisfen, Mon Oct 24 14:06:36 2005 UTC vs.
Revision 2402 by chrisfen, Tue Nov 1 19:09:30 2005 UTC

# Line 86 | Line 86 | module electrostatic_module
86    logical, save :: haveDielectric = .false.
87    real(kind=DP), save :: constERFC = 0.0_DP
88    real(kind=DP), save :: constEXP = 0.0_DP
89  logical, save :: haveDWAconstants = .false.
89    real(kind=dp), save :: rcuti = 0.0_DP
90    real(kind=dp), save :: rcuti2 = 0.0_DP
91    real(kind=dp), save :: rcuti3 = 0.0_DP
# Line 98 | Line 97 | module electrostatic_module
97    real(kind=dp), save :: rrfsq = 1.0_DP
98    real(kind=dp), save :: preRF = 0.0_DP
99    real(kind=dp), save :: preRF2 = 0.0_DP
101  logical, save :: preRFCalculated = .false.
100  
101   #ifdef __IFC
102   ! error function for ifc version > 7.
# Line 109 | Line 107 | module electrostatic_module
107    public :: setElectrostaticCutoffRadius
108    public :: setDampedWolfAlpha
109    public :: setReactionFieldDielectric
112  public :: setReactionFieldPrefactor
110    public :: newElectrostaticType
111    public :: setCharge
112    public :: setDipoleMoment
# Line 119 | Line 116 | module electrostatic_module
116    public :: getCharge
117    public :: getDipoleMoment
118    public :: destroyElectrostaticTypes
119 <  public :: rf_self_self
119 >  public :: self_self
120 >  public :: rf_self_excludes
121  
122    type :: Electrostatic
123       integer :: c_ident
# Line 169 | Line 167 | contains
167      dielectric = thisDielectric
168      haveDielectric = .true.
169    end subroutine setReactionFieldDielectric
172
173  subroutine setReactionFieldPrefactor
174    if (haveDefaultCutoff .and. haveDielectric) then
175       defaultCutoff2 = defaultCutoff*defaultCutoff
176       preRF = (dielectric-1.0d0) / &
177            ((2.0d0*dielectric+1.0d0)*defaultCutoff2*defaultCutoff)
178       preRF2 = 2.0d0*preRF
179       preRFCalculated = .true.
180    else if (.not.haveDefaultCutoff) then
181       call handleError("setReactionFieldPrefactor", "Default cutoff not set")
182    else
183       call handleError("setReactionFieldPrefactor", "Dielectric not set")
184    endif
185  end subroutine setReactionFieldPrefactor
170  
171    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
172         is_SplitDipole, is_Quadrupole, is_Tap, status)
# Line 406 | Line 390 | contains
390      rcuti4 = rcuti2*rcuti2
391  
392      if (summationMethod .eq. DAMPED_WOLF) then
393 <       if (.not.haveDWAconstants) then
394 <          
411 <          if (.not.haveDampingAlpha) then
412 <             call handleError("checkSummationMethod", "no Damping Alpha set!")
413 <          endif
414 <          
415 <          if (.not.haveDefaultCutoff) then
416 <             call handleError("checkSummationMethod", "no Default Cutoff set!")
417 <          endif
418 <
419 <          constEXP = exp(-dampingAlpha*dampingAlpha*defaultCutoff*defaultCutoff)
420 <          constERFC = derfc(dampingAlpha*defaultCutoff)
421 <          invRootPi = 0.56418958354775628695d0
422 <          alphaPi = 2*dampingAlpha*invRootPi
423 <  
424 <          haveDWAconstants = .true.
393 >       if (.not.haveDampingAlpha) then
394 >          call handleError("checkSummationMethod", "no Damping Alpha set!")
395         endif
396 +      
397 +       if (.not.haveDefaultCutoff) then
398 +          call handleError("checkSummationMethod", "no Default Cutoff set!")
399 +       endif
400 +
401 +       constEXP = exp(-dampingAlpha*dampingAlpha*defaultCutoff*defaultCutoff)
402 +       constERFC = derfc(dampingAlpha*defaultCutoff)
403 +       invRootPi = 0.56418958354775628695d0
404 +       alphaPi = 2*dampingAlpha*invRootPi
405 +      
406      endif
407  
408      if (summationMethod .eq. REACTION_FIELD) then
409 <       if (.not.haveDielectric) then
410 <          call handleError("checkSummationMethod", "no reaction field Dielectric set!")
409 >       if (haveDielectric) then
410 >          defaultCutoff2 = defaultCutoff*defaultCutoff
411 >          preRF = (dielectric-1.0d0) / &
412 >               ((2.0d0*dielectric+1.0d0)*defaultCutoff2*defaultCutoff)
413 >          preRF2 = 2.0d0*preRF
414 >       else
415 >          call handleError("checkSummationMethod", "Dielectric not set")
416         endif
417 +      
418      endif
419  
420      summationMethodChecked = .true.
421    end subroutine checkSummationMethod
422  
423 <
424 <
423 > !!$
424 > !!$  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
425 > !!$       vpair, fpair, pot, eFrame, f, t, do_pot)
426    subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
427 <       vpair, fpair, pot, eFrame, f, t, do_pot)
427 >       vpair, fpair, pot, eFrame, f, t, do_pot, felec)
428  
429      logical, intent(in) :: do_pot
430  
# Line 447 | Line 434 | contains
434      real(kind=dp), intent(in) :: rij, r2, sw
435      real(kind=dp), intent(in), dimension(3) :: d
436      real(kind=dp), intent(inout) :: vpair
437 <    real(kind=dp), intent(inout), dimension(3) :: fpair
437 >    real(kind=dp), intent(inout), dimension(3) :: fpair    
438 >    real(kind=dp), intent(inout), dimension(3) :: felec
439  
440      real( kind = dp ) :: pot
441      real( kind = dp ), dimension(9,nLocal) :: eFrame
# Line 488 | Line 476 | contains
476         call checkSummationMethod()
477      endif
478  
491    if (.not.preRFCalculated) then
492       call setReactionFieldPrefactor()
493    endif
494
479   #ifdef IS_MPI
480      me1 = atid_Row(atom1)
481      me2 = atid_Col(atom2)
# Line 648 | Line 632 | contains
632               vpair = vpair + vterm
633               epot = epot + sw*vterm
634              
635 <             dudr  = -sw*pre11*q_i*q_j * (riji*riji-rcuti2)*riji
635 >             dudr  = -sw*pre11*q_i*q_j * (riji*riji-rcuti2)
636              
637 <             dudx = dudx + dudr * d(1)
638 <             dudy = dudy + dudr * d(2)
639 <             dudz = dudz + dudr * d(3)
637 >             dudx = dudx + dudr * xhat
638 >             dudy = dudy + dudr * yhat
639 >             dudz = dudz + dudr * zhat
640  
641            elseif (summationMethod .eq. DAMPED_WOLF) then
642               varERFC = derfc(dampingAlpha*rij)
# Line 661 | Line 645 | contains
645               vpair = vpair + vterm
646               epot = epot + sw*vterm
647              
648 <             dudr  = -sw*pre11*q_i*q_j * ( riji*((varERFC*riji*riji &
649 <                                                  + alphaPi*varEXP) &
650 <                                                 - (constERFC*rcuti2 &
667 <                                                    + alphaPi*constEXP)) )
648 >             dudr  = -sw*pre11*q_i*q_j * (((varERFC*riji*riji &
649 >                  + alphaPi*varEXP*riji) - (constERFC*rcuti2 &
650 >                  + alphaPi*constEXP*rcuti)) )
651              
652 <             dudx = dudx + dudr * d(1)
653 <             dudy = dudy + dudr * d(2)
654 <             dudz = dudz + dudr * d(3)
652 >             dudx = dudx + dudr * xhat
653 >             dudy = dudy + dudr * yhat
654 >             dudz = dudz + dudr * zhat
655  
656            elseif (summationMethod .eq. REACTION_FIELD) then
657               preVal = pre11 * q_i * q_j
658               rfVal = preRF*rij*rij
659               vterm = preVal * ( riji + rfVal )
660 +            
661               vpair = vpair + vterm
662               epot = epot + sw*vterm
663              
# Line 727 | Line 711 | contains
711               duduz_j(3) = duduz_j(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
712  
713            elseif (summationMethod .eq. REACTION_FIELD) then
714 <             ri2 = ri * ri
715 <             ri3 = ri2 * ri
714 >             ri2 = riji * riji
715 >             ri3 = ri2 * riji
716      
717               pref = pre12 * q_i * mu_j
718               vterm = - pref * ct_j * ( ri2 - preRF2*rij )
# Line 900 | Line 884 | contains
884               vpair = vpair + vterm
885               epot = epot + sw*vterm
886              
903             !! this has a + sign in the () because the rij vector is
904             !! r_j - r_i and the charge-dipole potential takes the origin
905             !! as the point dipole, which is atom j in this case.
906            
887               dudx = dudx + sw*pref * ( ri3*( uz_i(1) - 3.0d0*ct_i*xhat) &
888                    - rcuti3*( uz_i(1) - 3.0d0*ct_i*d(1)*rcuti ) )
889               dudy = dudy + sw*pref * ( ri3*( uz_i(2) - 3.0d0*ct_i*yhat) &
# Line 911 | Line 891 | contains
891               dudz = dudz + sw*pref * ( ri3*( uz_i(3) - 3.0d0*ct_i*zhat) &
892                    - rcuti3*( uz_i(3) - 3.0d0*ct_i*d(3)*rcuti ) )
893              
894 <             duduz_i(1) = duduz_i(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
895 <             duduz_i(2) = duduz_i(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
896 <             duduz_i(3) = duduz_i(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
894 >             duduz_i(1) = duduz_i(1) + sw*pref*( ri2*xhat - d(1)*rcuti3 )
895 >             duduz_i(2) = duduz_i(2) + sw*pref*( ri2*yhat - d(2)*rcuti3 )
896 >             duduz_i(3) = duduz_i(3) + sw*pref*( ri2*zhat - d(3)*rcuti3 )
897  
898            elseif (summationMethod .eq. REACTION_FIELD) then
899 <             ri2 = ri * ri
900 <             ri3 = ri2 * ri
899 >             ri2 = riji * riji
900 >             ri3 = ri2 * riji
901  
902               pref = pre12 * q_j * mu_i
903 <             vterm = pref * ct_i * ( ri2 - preRF*rij )
903 >             vterm = pref * ct_i * ( ri2 - preRF2*rij )
904               vpair = vpair + vterm
905               epot = epot + sw*vterm
906              
907 <             dudx = dudx + sw*pref * ri3 * ( uz_i(1) - 3.0d0*ct_i*xhat - &
908 <                                             preRF*uz_i(1) )
909 <             dudy = dudy + sw*pref * ri3 * ( uz_i(2) - 3.0d0*ct_i*yhat - &
910 <                                             preRF*uz_i(2) )
911 <             dudz = dudz + sw*pref * ri3 * ( uz_i(3) - 3.0d0*ct_i*zhat - &
912 <                                             preRF*uz_i(3) )
907 >             dudx = dudx + sw*pref * ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat) - &
908 >                  preRF2*uz_i(1) )
909 >             dudy = dudy + sw*pref * ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat) - &
910 >                  preRF2*uz_i(2) )
911 >             dudz = dudz + sw*pref * ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat) - &
912 >                  preRF2*uz_i(3) )
913              
914 <             duduz_i(1) = duduz_i(1) + sw*pref * xhat * ( ri2 - preRF*rij )
915 <             duduz_i(2) = duduz_i(2) + sw*pref * yhat * ( ri2 - preRF*rij )
916 <             duduz_i(3) = duduz_i(3) + sw*pref * zhat * ( ri2 - preRF*rij )
914 >             duduz_i(1) = duduz_i(1) + sw*pref * xhat * ( ri2 - preRF2*rij )
915 >             duduz_i(2) = duduz_i(2) + sw*pref * yhat * ( ri2 - preRF2*rij )
916 >             duduz_i(3) = duduz_i(3) + sw*pref * zhat * ( ri2 - preRF2*rij )
917  
918            else
919               if (i_is_SplitDipole) then
# Line 967 | Line 947 | contains
947         if (j_is_Dipole) then
948  
949            if (summationMethod .eq. UNDAMPED_WOLF) then
950 + !!$             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
951 + !!$
952 + !!$             ri2 = riji * riji
953 + !!$             ri3 = ri2 * riji
954 + !!$             ri4 = ri2 * ri2
955 + !!$
956 + !!$             pref = pre22 * mu_i * mu_j
957 + !!$             vterm = pref * (ri3 - rcuti3) * (ct_ij - 3.0d0 * ct_i * ct_j)
958 + !!$             vpair = vpair + vterm
959 + !!$             epot = epot + sw*vterm
960 + !!$            
961 + !!$             a1 = 5.0d0 * ct_i * ct_j - ct_ij
962 + !!$            
963 + !!$             dudx = dudx + sw*pref*3.0d0*( &
964 + !!$                  ri4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) &
965 + !!$                  - rcuti4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) )
966 + !!$             dudy = dudy + sw*pref*3.0d0*( &
967 + !!$                  ri4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) &
968 + !!$                  - rcuti4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) )
969 + !!$             dudz = dudz + sw*pref*3.0d0*( &
970 + !!$                  ri4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) &
971 + !!$                  - rcuti4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) )
972 + !!$            
973 + !!$             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
974 + !!$                  - rcuti3*(uz_j(1) - 3.0d0*ct_j*xhat))
975 + !!$             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
976 + !!$                  - rcuti3*(uz_j(2) - 3.0d0*ct_j*yhat))
977 + !!$             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
978 + !!$                  - rcuti3*(uz_j(3) - 3.0d0*ct_j*zhat))
979 + !!$             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
980 + !!$                  - rcuti3*(uz_i(1) - 3.0d0*ct_i*xhat))
981 + !!$             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
982 + !!$                  - rcuti3*(uz_i(2) - 3.0d0*ct_i*yhat))
983 + !!$             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
984 + !!$                  - rcuti3*(uz_i(3) - 3.0d0*ct_i*zhat))
985 +          
986 +          elseif (summationMethod .eq. DAMPED_WOLF) then
987 +             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
988 +            
989               ri2 = riji * riji
990               ri3 = ri2 * riji
991               ri4 = ri2 * ri2
992 <
992 >             sc2 = scale * scale
993 >            
994               pref = pre22 * mu_i * mu_j
995 <             vterm = pref * (ri3 - rcuti3) * (ct_ij - 3.0d0 * ct_i * ct_j)
995 >             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j)
996               vpair = vpair + vterm
997               epot = epot + sw*vterm
998              
999 <             a1 = 5.0d0 * ct_i * ct_j - ct_ij
999 >             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
1000              
1001 <             dudx = dudx + sw*pref*3.0d0*ri4 &
1002 <                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) &
1003 <                         - sw*pref*3.0d0*rcuti4 &
984 <                             * (a1*rcuti*d(1)-ct_i*uz_j(1)-ct_j*uz_i(1))
985 <             dudy = dudy + sw*pref*3.0d0*ri4 &
986 <                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) &
987 <                         - sw*pref*3.0d0*rcuti4 &
988 <                             * (a1*rcuti*d(2)-ct_i*uz_j(2)-ct_j*uz_i(2))
989 <             dudz = dudz + sw*pref*3.0d0*ri4 &
990 <                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) &
991 <                         - sw*pref*3.0d0*rcuti4 &
992 <                             * (a1*rcuti*d(3)-ct_i*uz_j(3)-ct_j*uz_i(3))
1001 >             dudx = dudx + sw*pref*3.0d0*ri4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1002 >             dudy = dudy + sw*pref*3.0d0*ri4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1003 >             dudz = dudz + sw*pref*3.0d0*ri4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1004              
1005 <             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1006 <                  - rcuti3*(uz_j(1) - 3.0d0*ct_j*d(1)*rcuti))
1007 <             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1008 <                  - rcuti3*(uz_j(2) - 3.0d0*ct_j*d(2)*rcuti))
1009 <             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1010 <                  - rcuti3*(uz_j(3) - 3.0d0*ct_j*d(3)*rcuti))
1011 <             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1012 <                  - rcuti3*(uz_i(1) - 3.0d0*ct_i*d(1)*rcuti))
1013 <             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1003 <                  - rcuti3*(uz_i(2) - 3.0d0*ct_i*d(2)*rcuti))
1004 <             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1005 <                  - rcuti3*(uz_i(3) - 3.0d0*ct_i*d(3)*rcuti))
1006 <
1007 <         elseif (summationMethod .eq. REACTION_FIELD) then
1005 >             duduz_i(1) = duduz_i(1) + sw*pref*ri3 *(uz_j(1) - 3.0d0*ct_j*xhat)
1006 >             duduz_i(2) = duduz_i(2) + sw*pref*ri3 *(uz_j(2) - 3.0d0*ct_j*yhat)
1007 >             duduz_i(3) = duduz_i(3) + sw*pref*ri3 *(uz_j(3) - 3.0d0*ct_j*zhat)
1008 >            
1009 >             duduz_j(1) = duduz_j(1) + sw*pref*ri3 *(uz_i(1) - 3.0d0*ct_i*xhat)
1010 >             duduz_j(2) = duduz_j(2) + sw*pref*ri3 *(uz_i(2) - 3.0d0*ct_i*yhat)
1011 >             duduz_j(3) = duduz_j(3) + sw*pref*ri3 *(uz_i(3) - 3.0d0*ct_i*zhat)
1012 >            
1013 >          elseif (summationMethod .eq. REACTION_FIELD) then
1014               ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
1015  
1016               ri2 = riji * riji
# Line 1313 | Line 1319 | contains
1319  
1320    end subroutine destroyElectrostaticTypes
1321  
1322 <  subroutine rf_self_self(atom1, eFrame, rfpot, t, do_pot)
1322 >  subroutine self_self(atom1, eFrame, mypot, t, do_pot)
1323      logical, intent(in) :: do_pot
1324      integer, intent(in) :: atom1
1325      integer :: atid1
1326      real(kind=dp), dimension(9,nLocal) :: eFrame
1327      real(kind=dp), dimension(3,nLocal) :: t
1328 <    real(kind=dp) :: mu1
1329 <    real(kind=dp) :: preVal, epot, rfpot
1328 >    real(kind=dp) :: mu1, c1
1329 >    real(kind=dp) :: preVal, epot, mypot
1330      real(kind=dp) :: eix, eiy, eiz
1331  
1332      ! this is a local only array, so we use the local atom type id's:
1333      atid1 = atid(atom1)
1328    
1329    if (ElectrostaticMap(atid1)%is_Dipole) then
1330       mu1 = getDipoleMoment(atid1)
1331      
1332       preVal = pre22 * preRF2 * mu1*mu1
1333       rfpot = rfpot - 0.5d0*preVal
1334  
1335 <       ! The self-correction term adds into the reaction field vector
1335 >    if (.not.summationMethodChecked) then
1336 >       call checkSummationMethod()
1337 >    endif
1338 >    
1339 >    if (summationMethod .eq. REACTION_FIELD) then
1340 >       if (ElectrostaticMap(atid1)%is_Dipole) then
1341 >          mu1 = getDipoleMoment(atid1)
1342 >          
1343 >          preVal = pre22 * preRF2 * mu1*mu1
1344 >          mypot = mypot - 0.5d0*preVal
1345 >          
1346 >          ! The self-correction term adds into the reaction field vector
1347 >          
1348 >          eix = preVal * eFrame(3,atom1)
1349 >          eiy = preVal * eFrame(6,atom1)
1350 >          eiz = preVal * eFrame(9,atom1)
1351 >          
1352 >          ! once again, this is self-self, so only the local arrays are needed
1353 >          ! even for MPI jobs:
1354 >          
1355 >          t(1,atom1)=t(1,atom1) - eFrame(6,atom1)*eiz + &
1356 >               eFrame(9,atom1)*eiy
1357 >          t(2,atom1)=t(2,atom1) - eFrame(9,atom1)*eix + &
1358 >               eFrame(3,atom1)*eiz
1359 >          t(3,atom1)=t(3,atom1) - eFrame(3,atom1)*eiy + &
1360 >               eFrame(6,atom1)*eix
1361 >          
1362 >       endif
1363 >
1364 >    elseif (summationMethod .eq. UNDAMPED_WOLF) then
1365 >       if (ElectrostaticMap(atid1)%is_Charge) then
1366 >          c1 = getCharge(atid1)
1367 >          
1368 >          mypot = mypot - (rcuti * 0.5_dp * c1 * c1)
1369 >       endif
1370        
1371 <       eix = preVal * eFrame(3,atom1)
1372 <       eiy = preVal * eFrame(6,atom1)
1373 <       eiz = preVal * eFrame(9,atom1)
1371 >    elseif (summationMethod .eq. DAMPED_WOLF) then
1372 >       if (ElectrostaticMap(atid1)%is_Charge) then
1373 >          c1 = getCharge(atid1)
1374 >          
1375 >          mypot = mypot - (constERFC * rcuti * 0.5_dp + &
1376 >               dampingAlpha*invRootPi) * c1 * c1      
1377 >       endif
1378 >    endif
1379 >    
1380 >    return
1381 >  end subroutine self_self
1382  
1383 <       ! once again, this is self-self, so only the local arrays are needed
1384 <       ! even for MPI jobs:
1385 <      
1386 <       t(1,atom1)=t(1,atom1) - eFrame(6,atom1)*eiz + &
1387 <            eFrame(9,atom1)*eiy
1388 <       t(2,atom1)=t(2,atom1) - eFrame(9,atom1)*eix + &
1389 <            eFrame(3,atom1)*eiz
1390 <       t(3,atom1)=t(3,atom1) - eFrame(3,atom1)*eiy + &
1391 <            eFrame(6,atom1)*eix
1383 >  subroutine rf_self_excludes(atom1, atom2, sw, eFrame, d, rij, vpair, myPot, &
1384 >       f, t, do_pot)
1385 >    logical, intent(in) :: do_pot
1386 >    integer, intent(in) :: atom1
1387 >    integer, intent(in) :: atom2
1388 >    logical :: i_is_Charge, j_is_Charge
1389 >    logical :: i_is_Dipole, j_is_Dipole
1390 >    integer :: atid1
1391 >    integer :: atid2
1392 >    real(kind=dp), intent(in) :: rij
1393 >    real(kind=dp), intent(in) :: sw
1394 >    real(kind=dp), intent(in), dimension(3) :: d
1395 >    real(kind=dp), intent(inout) :: vpair
1396 >    real(kind=dp), dimension(9,nLocal) :: eFrame
1397 >    real(kind=dp), dimension(3,nLocal) :: f
1398 >    real(kind=dp), dimension(3,nLocal) :: t
1399 >    real (kind = dp), dimension(3) :: duduz_i
1400 >    real (kind = dp), dimension(3) :: duduz_j
1401 >    real (kind = dp), dimension(3) :: uz_i
1402 >    real (kind = dp), dimension(3) :: uz_j
1403 >    real(kind=dp) :: q_i, q_j, mu_i, mu_j
1404 >    real(kind=dp) :: xhat, yhat, zhat
1405 >    real(kind=dp) :: ct_i, ct_j
1406 >    real(kind=dp) :: ri2, ri3, riji, vterm
1407 >    real(kind=dp) :: pref, preVal, rfVal, myPot
1408 >    real(kind=dp) :: dudx, dudy, dudz, dudr
1409 >
1410 >    if (.not.summationMethodChecked) then
1411 >       call checkSummationMethod()
1412 >    endif
1413 >
1414 >    dudx = 0.0d0
1415 >    dudy = 0.0d0
1416 >    dudz = 0.0d0
1417 >
1418 >    riji = 1.0d0/rij
1419  
1420 +    xhat = d(1) * riji
1421 +    yhat = d(2) * riji
1422 +    zhat = d(3) * riji
1423 +
1424 +    ! this is a local only array, so we use the local atom type id's:
1425 +    atid1 = atid(atom1)
1426 +    atid2 = atid(atom2)
1427 +    i_is_Charge = ElectrostaticMap(atid1)%is_Charge
1428 +    j_is_Charge = ElectrostaticMap(atid2)%is_Charge
1429 +    i_is_Dipole = ElectrostaticMap(atid1)%is_Dipole
1430 +    j_is_Dipole = ElectrostaticMap(atid2)%is_Dipole
1431 +
1432 +    if (i_is_Charge.and.j_is_Charge) then
1433 +       q_i = ElectrostaticMap(atid1)%charge
1434 +       q_j = ElectrostaticMap(atid2)%charge
1435 +      
1436 +       preVal = pre11 * q_i * q_j
1437 +       rfVal = preRF*rij*rij
1438 +       vterm = preVal * rfVal
1439 +      
1440 +       myPot = myPot + sw*vterm
1441 +      
1442 +       dudr  = sw*preVal * 2.0d0*rfVal*riji
1443 +      
1444 +       dudx = dudx + dudr * xhat
1445 +       dudy = dudy + dudr * yhat
1446 +       dudz = dudz + dudr * zhat
1447 +      
1448 +    elseif (i_is_Charge.and.j_is_Dipole) then
1449 +       q_i = ElectrostaticMap(atid1)%charge
1450 +       mu_j = ElectrostaticMap(atid2)%dipole_moment
1451 +       uz_j(1) = eFrame(3,atom2)
1452 +       uz_j(2) = eFrame(6,atom2)
1453 +       uz_j(3) = eFrame(9,atom2)
1454 +       ct_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
1455 +      
1456 +       ri2 = riji * riji
1457 +       ri3 = ri2 * riji
1458 +      
1459 +       pref = pre12 * q_i * mu_j
1460 +       vterm = - pref * ct_j * ( ri2 - preRF2*rij )
1461 +       myPot = myPot + sw*vterm
1462 +      
1463 +       dudx = dudx - sw*pref*( ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1464 +            - preRF2*uz_j(1) )
1465 +       dudy = dudy - sw*pref*( ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1466 +            - preRF2*uz_j(2) )
1467 +       dudz = dudz - sw*pref*( ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1468 +            - preRF2*uz_j(3) )
1469 +      
1470 +       duduz_j(1) = duduz_j(1) - sw * pref * xhat * ( ri2 - preRF2*rij )
1471 +       duduz_j(2) = duduz_j(2) - sw * pref * yhat * ( ri2 - preRF2*rij )
1472 +       duduz_j(3) = duduz_j(3) - sw * pref * zhat * ( ri2 - preRF2*rij )
1473 +      
1474 +    elseif (i_is_Dipole.and.j_is_Charge) then
1475 +       mu_i = ElectrostaticMap(atid1)%dipole_moment
1476 +       q_j = ElectrostaticMap(atid2)%charge
1477 +       uz_i(1) = eFrame(3,atom1)
1478 +       uz_i(2) = eFrame(6,atom1)
1479 +       uz_i(3) = eFrame(9,atom1)
1480 +       ct_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
1481 +      
1482 +       ri2 = riji * riji
1483 +       ri3 = ri2 * riji
1484 +      
1485 +       pref = pre12 * q_j * mu_i
1486 +       vterm = pref * ct_i * ( ri2 - preRF2*rij )
1487 +       myPot = myPot + sw*vterm
1488 +      
1489 +       dudx = dudx + sw*pref*( ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1490 +            - preRF2*uz_i(1) )
1491 +       dudy = dudy + sw*pref*( ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1492 +            - preRF2*uz_i(2) )
1493 +       dudz = dudz + sw*pref*( ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1494 +            - preRF2*uz_i(3) )
1495 +      
1496 +       duduz_i(1) = duduz_i(1) + sw * pref * xhat * ( ri2 - preRF2*rij )
1497 +       duduz_i(2) = duduz_i(2) + sw * pref * yhat * ( ri2 - preRF2*rij )
1498 +       duduz_i(3) = duduz_i(3) + sw * pref * zhat * ( ri2 - preRF2*rij )
1499 +      
1500      endif
1501 +      
1502 +
1503 +    ! accumulate the forces and torques resulting from the self term
1504 +    f(1,atom1) = f(1,atom1) + dudx
1505 +    f(2,atom1) = f(2,atom1) + dudy
1506 +    f(3,atom1) = f(3,atom1) + dudz
1507      
1508 +    f(1,atom2) = f(1,atom2) - dudx
1509 +    f(2,atom2) = f(2,atom2) - dudy
1510 +    f(3,atom2) = f(3,atom2) - dudz
1511 +    
1512 +    if (i_is_Dipole) then
1513 +       t(1,atom1)=t(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1514 +       t(2,atom1)=t(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
1515 +       t(3,atom1)=t(3,atom1) - uz_i(1)*duduz_i(2) + uz_i(2)*duduz_i(1)
1516 +    elseif (j_is_Dipole) then
1517 +       t(1,atom2)=t(1,atom2) - uz_j(2)*duduz_j(3) + uz_j(3)*duduz_j(2)
1518 +       t(2,atom2)=t(2,atom2) - uz_j(3)*duduz_j(1) + uz_j(1)*duduz_j(3)
1519 +       t(3,atom2)=t(3,atom2) - uz_j(1)*duduz_j(2) + uz_j(2)*duduz_j(1)
1520 +    endif
1521 +
1522      return
1523 <  end subroutine rf_self_self
1523 >  end subroutine rf_self_excludes
1524  
1525   end module electrostatic_module

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines