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 2339 by chrisfen, Wed Sep 28 18:47:17 2005 UTC vs.
Revision 2405 by chrisfen, Tue Nov 1 19:24:57 2005 UTC

# Line 54 | Line 54 | module electrostatic_module
54  
55    PRIVATE
56  
57 +
58   #define __FORTRAN90
59 + #include "UseTheForce/DarkSide/fInteractionMap.h"
60   #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h"
61  
62 +
63    !! these prefactors convert the multipole interactions into kcal / mol
64    !! all were computed assuming distances are measured in angstroms
65    !! Charge-Charge, assuming charges are measured in electrons
# Line 75 | Line 78 | module electrostatic_module
78    integer, save :: summationMethod = NONE
79    logical, save :: summationMethodChecked = .false.
80    real(kind=DP), save :: defaultCutoff = 0.0_DP
81 +  real(kind=DP), save :: defaultCutoff2 = 0.0_DP
82    logical, save :: haveDefaultCutoff = .false.
83    real(kind=DP), save :: dampingAlpha = 0.0_DP
84    logical, save :: haveDampingAlpha = .false.
85 <  real(kind=DP), save :: dielectric = 0.0_DP
85 >  real(kind=DP), save :: dielectric = 1.0_DP
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.
90 <  real(kind=dp), save :: rcuti = 0.0_dp
91 <  real(kind=dp), save :: rcuti2 = 0.0_dp
92 <  real(kind=dp), save :: rcuti3 = 0.0_dp
93 <  real(kind=dp), save :: rcuti4 = 0.0_dp
94 <  real(kind=dp), save :: alphaPi = 0.0_dp
95 <  real(kind=dp), save :: invRootPi = 0.0_dp
96 <  
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
92 >  real(kind=dp), save :: rcuti4 = 0.0_DP
93 >  real(kind=dp), save :: alphaPi = 0.0_DP
94 >  real(kind=dp), save :: invRootPi = 0.0_DP
95 >  real(kind=dp), save :: rrf = 1.0_DP
96 >  real(kind=dp), save :: rt = 1.0_DP
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
100 >
101   #ifdef __IFC
102   ! error function for ifc version > 7.
103    double precision, external :: derfc
# Line 107 | Line 115 | module electrostatic_module
115    public :: doElectrostaticPair
116    public :: getCharge
117    public :: getDipoleMoment
110  public :: pre22
118    public :: destroyElectrostaticTypes
119 +  public :: self_self
120 +  public :: rf_self_excludes
121  
122    type :: Electrostatic
123       integer :: c_ident
# Line 138 | Line 147 | contains
147  
148    end subroutine setElectrostaticSummationMethod
149  
150 <  subroutine setElectrostaticCutoffRadius(thisRcut)
150 >  subroutine setElectrostaticCutoffRadius(thisRcut, thisRsw)
151      real(kind=dp), intent(in) :: thisRcut
152 +    real(kind=dp), intent(in) :: thisRsw
153      defaultCutoff = thisRcut
154 +    rrf = defaultCutoff
155 +    rt = thisRsw
156      haveDefaultCutoff = .true.
157    end subroutine setElectrostaticCutoffRadius
158  
# Line 378 | Line 390 | contains
390      rcuti4 = rcuti2*rcuti2
391  
392      if (summationMethod .eq. DAMPED_WOLF) then
393 <       if (.not.haveDWAconstants) then
394 <          
383 <          if (.not.haveDampingAlpha) then
384 <             call handleError("checkSummationMethod", "no Damping Alpha set!")
385 <          endif
386 <          
387 <          if (.not.haveDefaultCutoff) then
388 <             call handleError("checkSummationMethod", "no Default Cutoff set!")
389 <          endif
390 <
391 <          constEXP = exp(-dampingAlpha*dampingAlpha*defaultCutoff*defaultCutoff)
392 <          constERFC = derfc(dampingAlpha*defaultCutoff)
393 <          invRootPi = 0.56418958354775628695d0
394 <          alphaPi = 2*dampingAlpha*invRootPi
395 <          
396 <          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  
410
424    subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
425         vpair, fpair, pot, eFrame, f, t, do_pot)
426  
# Line 419 | Line 432 | contains
432      real(kind=dp), intent(in) :: rij, r2, sw
433      real(kind=dp), intent(in), dimension(3) :: d
434      real(kind=dp), intent(inout) :: vpair
435 <    real(kind=dp), intent(inout), dimension(3) :: fpair
435 >    real(kind=dp), intent(inout), dimension(3) :: fpair    
436  
437      real( kind = dp ) :: pot
438      real( kind = dp ), dimension(9,nLocal) :: eFrame
# Line 448 | Line 461 | contains
461      real (kind=dp) :: dudx, dudy, dudz
462      real (kind=dp) :: scale, sc2, bigR
463      real (kind=dp) :: varERFC, varEXP
464 +    real (kind=dp) :: limScale
465 +    real (kind=dp) :: preVal, rfVal
466  
467      if (.not.allocated(ElectrostaticMap)) then
468         call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
# Line 456 | Line 471 | contains
471  
472      if (.not.summationMethodChecked) then
473         call checkSummationMethod()
459      
474      endif
475  
462
476   #ifdef IS_MPI
477      me1 = atid_Row(atom1)
478      me2 = atid_Col(atom2)
# Line 471 | Line 484 | contains
484      !! some variables we'll need independent of electrostatic type:
485  
486      riji = 1.0d0 / rij
487 <
487 >  
488      xhat = d(1) * riji
489      yhat = d(2) * riji
490      zhat = d(3) * riji
# Line 612 | Line 625 | contains
625         if (j_is_Charge) then
626  
627            if (summationMethod .eq. UNDAMPED_WOLF) then
615
628               vterm = pre11 * q_i * q_j * (riji - rcuti)
629               vpair = vpair + vterm
630               epot = epot + sw*vterm
631              
632 <             dudr  = -sw*pre11*q_i*q_j * (riji*riji*riji - rcuti2*rcuti)
632 >             dudr  = -sw*pre11*q_i*q_j * (riji*riji-rcuti2)
633              
634 <             dudx = dudx + dudr * d(1)
635 <             dudy = dudy + dudr * d(2)
636 <             dudz = dudz + dudr * d(3)
634 >             dudx = dudx + dudr * xhat
635 >             dudy = dudy + dudr * yhat
636 >             dudz = dudz + dudr * zhat
637  
638            elseif (summationMethod .eq. DAMPED_WOLF) then
627
639               varERFC = derfc(dampingAlpha*rij)
640               varEXP = exp(-dampingAlpha*dampingAlpha*rij*rij)
641               vterm = pre11 * q_i * q_j * (varERFC*riji - constERFC*rcuti)
642               vpair = vpair + vterm
643               epot = epot + sw*vterm
644              
645 <             dudr  = -sw*pre11*q_i*q_j * ( riji*(varERFC*riji*riji &
646 <                                                 + alphaPi*varEXP) &
647 <                                         - rcuti*(constERFC*rcuti2 &
648 <                                                 + alphaPi*constEXP) )
645 >             dudr  = -sw*pre11*q_i*q_j * (((varERFC*riji*riji &
646 >                  + alphaPi*varEXP*riji) - (constERFC*rcuti2 &
647 >                  + alphaPi*constEXP*rcuti)) )
648 >            
649 >             dudx = dudx + dudr * xhat
650 >             dudy = dudy + dudr * yhat
651 >             dudz = dudz + dudr * zhat
652 >
653 >          elseif (summationMethod .eq. REACTION_FIELD) then
654 >             preVal = pre11 * q_i * q_j
655 >             rfVal = preRF*rij*rij
656 >             vterm = preVal * ( riji + rfVal )
657              
658 <             dudx = dudx + dudr * d(1)
659 <             dudy = dudy + dudr * d(2)
660 <             dudz = dudz + dudr * d(3)
658 >             vpair = vpair + vterm
659 >             epot = epot + sw*vterm
660 >            
661 >             dudr  = sw * preVal * ( 2.0d0*rfVal - riji )*riji
662 >            
663 >             dudx = dudx + dudr * xhat
664 >             dudy = dudy + dudr * yhat
665 >             dudz = dudz + dudr * zhat
666  
667            else
644
668               vterm = pre11 * q_i * q_j * riji
669               vpair = vpair + vterm
670               epot = epot + sw*vterm
# Line 684 | Line 707 | contains
707               duduz_j(2) = duduz_j(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
708               duduz_j(3) = duduz_j(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
709  
710 +          elseif (summationMethod .eq. REACTION_FIELD) then
711 +             ri2 = riji * riji
712 +             ri3 = ri2 * riji
713 +    
714 +             pref = pre12 * q_i * mu_j
715 +             vterm = - pref * ct_j * ( ri2 - preRF2*rij )
716 +             vpair = vpair + vterm
717 +             epot = epot + sw*vterm
718 +            
719 +             !! this has a + sign in the () because the rij vector is
720 +             !! r_j - r_i and the charge-dipole potential takes the origin
721 +             !! as the point dipole, which is atom j in this case.
722 +            
723 +             dudx = dudx - sw*pref*( ri3*(uz_j(1) - 3.0d0*ct_j*xhat) - &
724 +                                     preRF2*uz_j(1) )
725 +             dudy = dudy - sw*pref*( ri3*(uz_j(2) - 3.0d0*ct_j*yhat) - &
726 +                                     preRF2*uz_j(2) )
727 +             dudz = dudz - sw*pref*( ri3*(uz_j(3) - 3.0d0*ct_j*zhat) - &
728 +                                     preRF2*uz_j(3) )        
729 +             duduz_j(1) = duduz_j(1) - sw*pref * xhat * ( ri2 - preRF2*rij )
730 +             duduz_j(2) = duduz_j(2) - sw*pref * yhat * ( ri2 - preRF2*rij )
731 +             duduz_j(3) = duduz_j(3) - sw*pref * zhat * ( ri2 - preRF2*rij )
732 +
733            else
734               if (j_is_SplitDipole) then
735                  BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
# Line 835 | Line 881 | contains
881               vpair = vpair + vterm
882               epot = epot + sw*vterm
883              
838             !! this has a + sign in the () because the rij vector is
839             !! r_j - r_i and the charge-dipole potential takes the origin
840             !! as the point dipole, which is atom j in this case.
841            
884               dudx = dudx + sw*pref * ( ri3*( uz_i(1) - 3.0d0*ct_i*xhat) &
885                    - rcuti3*( uz_i(1) - 3.0d0*ct_i*d(1)*rcuti ) )
886               dudy = dudy + sw*pref * ( ri3*( uz_i(2) - 3.0d0*ct_i*yhat) &
# Line 846 | Line 888 | contains
888               dudz = dudz + sw*pref * ( ri3*( uz_i(3) - 3.0d0*ct_i*zhat) &
889                    - rcuti3*( uz_i(3) - 3.0d0*ct_i*d(3)*rcuti ) )
890              
891 <             duduz_i(1) = duduz_i(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
892 <             duduz_i(2) = duduz_i(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
893 <             duduz_i(3) = duduz_i(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
891 >             duduz_i(1) = duduz_i(1) + sw*pref*( ri2*xhat - d(1)*rcuti3 )
892 >             duduz_i(2) = duduz_i(2) + sw*pref*( ri2*yhat - d(2)*rcuti3 )
893 >             duduz_i(3) = duduz_i(3) + sw*pref*( ri2*zhat - d(3)*rcuti3 )
894  
895 +          elseif (summationMethod .eq. REACTION_FIELD) then
896 +             ri2 = riji * riji
897 +             ri3 = ri2 * riji
898 +
899 +             pref = pre12 * q_j * mu_i
900 +             vterm = pref * ct_i * ( ri2 - preRF2*rij )
901 +             vpair = vpair + vterm
902 +             epot = epot + sw*vterm
903 +            
904 +             dudx = dudx + sw*pref * ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat) - &
905 +                  preRF2*uz_i(1) )
906 +             dudy = dudy + sw*pref * ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat) - &
907 +                  preRF2*uz_i(2) )
908 +             dudz = dudz + sw*pref * ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat) - &
909 +                  preRF2*uz_i(3) )
910 +            
911 +             duduz_i(1) = duduz_i(1) + sw*pref * xhat * ( ri2 - preRF2*rij )
912 +             duduz_i(2) = duduz_i(2) + sw*pref * yhat * ( ri2 - preRF2*rij )
913 +             duduz_i(3) = duduz_i(3) + sw*pref * zhat * ( ri2 - preRF2*rij )
914 +
915            else
916               if (i_is_SplitDipole) then
917                  BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
# Line 882 | Line 944 | contains
944         if (j_is_Dipole) then
945  
946            if (summationMethod .eq. UNDAMPED_WOLF) then
947 + !!$             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
948 + !!$
949 + !!$             ri2 = riji * riji
950 + !!$             ri3 = ri2 * riji
951 + !!$             ri4 = ri2 * ri2
952 + !!$
953 + !!$             pref = pre22 * mu_i * mu_j
954 + !!$             vterm = pref * (ri3 - rcuti3) * (ct_ij - 3.0d0 * ct_i * ct_j)
955 + !!$             vpair = vpair + vterm
956 + !!$             epot = epot + sw*vterm
957 + !!$            
958 + !!$             a1 = 5.0d0 * ct_i * ct_j - ct_ij
959 + !!$            
960 + !!$             dudx = dudx + sw*pref*3.0d0*( &
961 + !!$                  ri4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) &
962 + !!$                  - rcuti4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) )
963 + !!$             dudy = dudy + sw*pref*3.0d0*( &
964 + !!$                  ri4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) &
965 + !!$                  - rcuti4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) )
966 + !!$             dudz = dudz + sw*pref*3.0d0*( &
967 + !!$                  ri4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) &
968 + !!$                  - rcuti4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) )
969 + !!$            
970 + !!$             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
971 + !!$                  - rcuti3*(uz_j(1) - 3.0d0*ct_j*xhat))
972 + !!$             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
973 + !!$                  - rcuti3*(uz_j(2) - 3.0d0*ct_j*yhat))
974 + !!$             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
975 + !!$                  - rcuti3*(uz_j(3) - 3.0d0*ct_j*zhat))
976 + !!$             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
977 + !!$                  - rcuti3*(uz_i(1) - 3.0d0*ct_i*xhat))
978 + !!$             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
979 + !!$                  - rcuti3*(uz_i(2) - 3.0d0*ct_i*yhat))
980 + !!$             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
981 + !!$                  - rcuti3*(uz_i(3) - 3.0d0*ct_i*zhat))
982 +          
983 +          elseif (summationMethod .eq. DAMPED_WOLF) then
984 +             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
985 +            
986               ri2 = riji * riji
987               ri3 = ri2 * riji
988               ri4 = ri2 * ri2
989 +             sc2 = scale * scale
990 +            
991 +             pref = pre22 * mu_i * mu_j
992 +             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j)
993 +             vpair = vpair + vterm
994 +             epot = epot + sw*vterm
995 +            
996 +             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
997 +            
998 +             dudx = dudx + sw*pref*3.0d0*ri4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
999 +             dudy = dudy + sw*pref*3.0d0*ri4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1000 +             dudz = dudz + sw*pref*3.0d0*ri4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1001 +            
1002 +             duduz_i(1) = duduz_i(1) + sw*pref*ri3 *(uz_j(1) - 3.0d0*ct_j*xhat)
1003 +             duduz_i(2) = duduz_i(2) + sw*pref*ri3 *(uz_j(2) - 3.0d0*ct_j*yhat)
1004 +             duduz_i(3) = duduz_i(3) + sw*pref*ri3 *(uz_j(3) - 3.0d0*ct_j*zhat)
1005 +            
1006 +             duduz_j(1) = duduz_j(1) + sw*pref*ri3 *(uz_i(1) - 3.0d0*ct_i*xhat)
1007 +             duduz_j(2) = duduz_j(2) + sw*pref*ri3 *(uz_i(2) - 3.0d0*ct_i*yhat)
1008 +             duduz_j(3) = duduz_j(3) + sw*pref*ri3 *(uz_i(3) - 3.0d0*ct_i*zhat)
1009 +            
1010 +          elseif (summationMethod .eq. REACTION_FIELD) then
1011 +             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
1012  
1013 +             ri2 = riji * riji
1014 +             ri3 = ri2 * riji
1015 +             ri4 = ri2 * ri2
1016 +
1017               pref = pre22 * mu_i * mu_j
1018 <             vterm = pref * (ri3 - rcuti3) * (ct_ij - 3.0d0 * ct_i * ct_j)
1018 >              
1019 >             vterm = pref*( ri3*(ct_ij - 3.0d0 * ct_i * ct_j) - &
1020 >                  preRF2*ct_ij )
1021               vpair = vpair + vterm
1022               epot = epot + sw*vterm
1023              
1024               a1 = 5.0d0 * ct_i * ct_j - ct_ij
1025              
1026               dudx = dudx + sw*pref*3.0d0*ri4 &
1027 <                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) &
898 <                         - sw*pref*3.0d0*rcuti4 &
899 <                             * (a1*rcuti*d(1)-ct_i*uz_j(1)-ct_j*uz_i(1))
1027 >                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1028               dudy = dudy + sw*pref*3.0d0*ri4 &
1029 <                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) &
902 <                         - sw*pref*3.0d0*rcuti4 &
903 <                             * (a1*rcuti*d(2)-ct_i*uz_j(2)-ct_j*uz_i(2))
1029 >                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1030               dudz = dudz + sw*pref*3.0d0*ri4 &
1031 <                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) &
906 <                         - sw*pref*3.0d0*rcuti4 &
907 <                             * (a1*rcuti*d(3)-ct_i*uz_j(3)-ct_j*uz_i(3))
1031 >                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1032              
1033               duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1034 <                  - rcuti3*(uz_j(1) - 3.0d0*ct_j*d(1)*rcuti))
1034 >                  - preRF2*uz_j(1))
1035               duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1036 <                  - rcuti3*(uz_j(2) - 3.0d0*ct_j*d(2)*rcuti))
1036 >                  - preRF2*uz_j(2))
1037               duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1038 <                  - rcuti3*(uz_j(3) - 3.0d0*ct_j*d(3)*rcuti))
1038 >                  - preRF2*uz_j(3))
1039               duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1040 <                  - rcuti3*(uz_i(1) - 3.0d0*ct_i*d(1)*rcuti))
1040 >                  - preRF2*uz_i(1))
1041               duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1042 <                  - rcuti3*(uz_i(2) - 3.0d0*ct_i*d(2)*rcuti))
1042 >                  - preRF2*uz_i(2))
1043               duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1044 <                  - rcuti3*(uz_i(3) - 3.0d0*ct_i*d(3)*rcuti))
1044 >                  - preRF2*uz_i(3))
1045  
1046            else
1047               if (i_is_SplitDipole) then
# Line 1080 | Line 1204 | contains
1204  
1205      if (do_pot) then
1206   #ifdef IS_MPI
1207 <       pot_row(atom1) = pot_row(atom1) + 0.5d0*epot
1208 <       pot_col(atom2) = pot_col(atom2) + 0.5d0*epot
1207 >       pot_row(ELECTROSTATIC_POT,atom1) = pot_row(ELECTROSTATIC_POT,atom1) + 0.5d0*epot
1208 >       pot_col(ELECTROSTATIC_POT,atom2) = pot_col(ELECTROSTATIC_POT,atom2) + 0.5d0*epot
1209   #else
1210         pot = pot + epot
1211   #endif
# Line 1185 | Line 1309 | contains
1309  
1310      return
1311    end subroutine doElectrostaticPair
1188
1189  !! calculates the switching functions and their derivatives for a given
1190  subroutine calc_switch(r, mu, scale, dscale)
1191
1192    real (kind=dp), intent(in) :: r, mu
1193    real (kind=dp), intent(inout) :: scale, dscale
1194    real (kind=dp) :: rl, ru, mulow, minRatio, temp, scaleVal
1195
1196    ! distances must be in angstroms
1197    rl = 2.75d0
1198    ru = 3.75d0
1199    mulow = 0.0d0 !3.3856d0 ! 1.84 * 1.84
1200    minRatio = mulow / (mu*mu)
1201    scaleVal = 1.0d0 - minRatio
1202    
1203    if (r.lt.rl) then
1204       scale = minRatio
1205       dscale = 0.0d0
1206    elseif (r.gt.ru) then
1207       scale = 1.0d0
1208       dscale = 0.0d0
1209    else
1210       scale = 1.0d0 - scaleVal*((ru + 2.0d0*r - 3.0d0*rl) * (ru-r)**2) &
1211                        / ((ru - rl)**3)
1212       dscale = -scaleVal * 6.0d0 * (r-ru)*(r-rl)/((ru - rl)**3)    
1213    endif
1214        
1215    return
1216  end subroutine calc_switch
1312  
1313    subroutine destroyElectrostaticTypes()
1314  
1315      if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap)
1316 +
1317 +  end subroutine destroyElectrostaticTypes
1318 +
1319 +  subroutine self_self(atom1, eFrame, mypot, t, do_pot)
1320 +    logical, intent(in) :: do_pot
1321 +    integer, intent(in) :: atom1
1322 +    integer :: atid1
1323 +    real(kind=dp), dimension(9,nLocal) :: eFrame
1324 +    real(kind=dp), dimension(3,nLocal) :: t
1325 +    real(kind=dp) :: mu1, c1
1326 +    real(kind=dp) :: preVal, epot, mypot
1327 +    real(kind=dp) :: eix, eiy, eiz
1328 +
1329 +    ! this is a local only array, so we use the local atom type id's:
1330 +    atid1 = atid(atom1)
1331 +
1332 +    if (.not.summationMethodChecked) then
1333 +       call checkSummationMethod()
1334 +    endif
1335 +    
1336 +    if (summationMethod .eq. REACTION_FIELD) then
1337 +       if (ElectrostaticMap(atid1)%is_Dipole) then
1338 +          mu1 = getDipoleMoment(atid1)
1339 +          
1340 +          preVal = pre22 * preRF2 * mu1*mu1
1341 +          mypot = mypot - 0.5d0*preVal
1342 +          
1343 +          ! The self-correction term adds into the reaction field vector
1344 +          
1345 +          eix = preVal * eFrame(3,atom1)
1346 +          eiy = preVal * eFrame(6,atom1)
1347 +          eiz = preVal * eFrame(9,atom1)
1348 +          
1349 +          ! once again, this is self-self, so only the local arrays are needed
1350 +          ! even for MPI jobs:
1351 +          
1352 +          t(1,atom1)=t(1,atom1) - eFrame(6,atom1)*eiz + &
1353 +               eFrame(9,atom1)*eiy
1354 +          t(2,atom1)=t(2,atom1) - eFrame(9,atom1)*eix + &
1355 +               eFrame(3,atom1)*eiz
1356 +          t(3,atom1)=t(3,atom1) - eFrame(3,atom1)*eiy + &
1357 +               eFrame(6,atom1)*eix
1358 +          
1359 +       endif
1360 +
1361 +    elseif (summationMethod .eq. UNDAMPED_WOLF) then
1362 +       if (ElectrostaticMap(atid1)%is_Charge) then
1363 +          c1 = getCharge(atid1)
1364 +          
1365 +          mypot = mypot - (rcuti * 0.5_dp * c1 * c1)
1366 +       endif
1367 +      
1368 +    elseif (summationMethod .eq. DAMPED_WOLF) then
1369 +       if (ElectrostaticMap(atid1)%is_Charge) then
1370 +          c1 = getCharge(atid1)
1371 +          
1372 +          mypot = mypot - (constERFC * rcuti * 0.5_dp + &
1373 +               dampingAlpha*invRootPi) * c1 * c1      
1374 +       endif
1375 +    endif
1376 +    
1377 +    return
1378 +  end subroutine self_self
1379 +
1380 +  subroutine rf_self_excludes(atom1, atom2, sw, eFrame, d, rij, vpair, myPot, &
1381 +       f, t, do_pot)
1382 +    logical, intent(in) :: do_pot
1383 +    integer, intent(in) :: atom1
1384 +    integer, intent(in) :: atom2
1385 +    logical :: i_is_Charge, j_is_Charge
1386 +    logical :: i_is_Dipole, j_is_Dipole
1387 +    integer :: atid1
1388 +    integer :: atid2
1389 +    real(kind=dp), intent(in) :: rij
1390 +    real(kind=dp), intent(in) :: sw
1391 +    real(kind=dp), intent(in), dimension(3) :: d
1392 +    real(kind=dp), intent(inout) :: vpair
1393 +    real(kind=dp), dimension(9,nLocal) :: eFrame
1394 +    real(kind=dp), dimension(3,nLocal) :: f
1395 +    real(kind=dp), dimension(3,nLocal) :: t
1396 +    real (kind = dp), dimension(3) :: duduz_i
1397 +    real (kind = dp), dimension(3) :: duduz_j
1398 +    real (kind = dp), dimension(3) :: uz_i
1399 +    real (kind = dp), dimension(3) :: uz_j
1400 +    real(kind=dp) :: q_i, q_j, mu_i, mu_j
1401 +    real(kind=dp) :: xhat, yhat, zhat
1402 +    real(kind=dp) :: ct_i, ct_j
1403 +    real(kind=dp) :: ri2, ri3, riji, vterm
1404 +    real(kind=dp) :: pref, preVal, rfVal, myPot
1405 +    real(kind=dp) :: dudx, dudy, dudz, dudr
1406  
1407 <  end subroutine destroyElectrostaticTypes
1407 >    if (.not.summationMethodChecked) then
1408 >       call checkSummationMethod()
1409 >    endif
1410  
1411 +    dudx = 0.0d0
1412 +    dudy = 0.0d0
1413 +    dudz = 0.0d0
1414 +
1415 +    riji = 1.0d0/rij
1416 +
1417 +    xhat = d(1) * riji
1418 +    yhat = d(2) * riji
1419 +    zhat = d(3) * riji
1420 +
1421 +    ! this is a local only array, so we use the local atom type id's:
1422 +    atid1 = atid(atom1)
1423 +    atid2 = atid(atom2)
1424 +    i_is_Charge = ElectrostaticMap(atid1)%is_Charge
1425 +    j_is_Charge = ElectrostaticMap(atid2)%is_Charge
1426 +    i_is_Dipole = ElectrostaticMap(atid1)%is_Dipole
1427 +    j_is_Dipole = ElectrostaticMap(atid2)%is_Dipole
1428 +
1429 +    if (i_is_Charge.and.j_is_Charge) then
1430 +       q_i = ElectrostaticMap(atid1)%charge
1431 +       q_j = ElectrostaticMap(atid2)%charge
1432 +      
1433 +       preVal = pre11 * q_i * q_j
1434 +       rfVal = preRF*rij*rij
1435 +       vterm = preVal * rfVal
1436 +      
1437 +       myPot = myPot + sw*vterm
1438 +      
1439 +       dudr  = sw*preVal * 2.0d0*rfVal*riji
1440 +      
1441 +       dudx = dudx + dudr * xhat
1442 +       dudy = dudy + dudr * yhat
1443 +       dudz = dudz + dudr * zhat
1444 +      
1445 +    elseif (i_is_Charge.and.j_is_Dipole) then
1446 +       q_i = ElectrostaticMap(atid1)%charge
1447 +       mu_j = ElectrostaticMap(atid2)%dipole_moment
1448 +       uz_j(1) = eFrame(3,atom2)
1449 +       uz_j(2) = eFrame(6,atom2)
1450 +       uz_j(3) = eFrame(9,atom2)
1451 +       ct_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
1452 +      
1453 +       ri2 = riji * riji
1454 +       ri3 = ri2 * riji
1455 +      
1456 +       pref = pre12 * q_i * mu_j
1457 +       vterm = - pref * ct_j * ( ri2 - preRF2*rij )
1458 +       myPot = myPot + sw*vterm
1459 +      
1460 +       dudx = dudx - sw*pref*( ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1461 +            - preRF2*uz_j(1) )
1462 +       dudy = dudy - sw*pref*( ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1463 +            - preRF2*uz_j(2) )
1464 +       dudz = dudz - sw*pref*( ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1465 +            - preRF2*uz_j(3) )
1466 +      
1467 +       duduz_j(1) = duduz_j(1) - sw * pref * xhat * ( ri2 - preRF2*rij )
1468 +       duduz_j(2) = duduz_j(2) - sw * pref * yhat * ( ri2 - preRF2*rij )
1469 +       duduz_j(3) = duduz_j(3) - sw * pref * zhat * ( ri2 - preRF2*rij )
1470 +      
1471 +    elseif (i_is_Dipole.and.j_is_Charge) then
1472 +       mu_i = ElectrostaticMap(atid1)%dipole_moment
1473 +       q_j = ElectrostaticMap(atid2)%charge
1474 +       uz_i(1) = eFrame(3,atom1)
1475 +       uz_i(2) = eFrame(6,atom1)
1476 +       uz_i(3) = eFrame(9,atom1)
1477 +       ct_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
1478 +      
1479 +       ri2 = riji * riji
1480 +       ri3 = ri2 * riji
1481 +      
1482 +       pref = pre12 * q_j * mu_i
1483 +       vterm = pref * ct_i * ( ri2 - preRF2*rij )
1484 +       myPot = myPot + sw*vterm
1485 +      
1486 +       dudx = dudx + sw*pref*( ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1487 +            - preRF2*uz_i(1) )
1488 +       dudy = dudy + sw*pref*( ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1489 +            - preRF2*uz_i(2) )
1490 +       dudz = dudz + sw*pref*( ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1491 +            - preRF2*uz_i(3) )
1492 +      
1493 +       duduz_i(1) = duduz_i(1) + sw * pref * xhat * ( ri2 - preRF2*rij )
1494 +       duduz_i(2) = duduz_i(2) + sw * pref * yhat * ( ri2 - preRF2*rij )
1495 +       duduz_i(3) = duduz_i(3) + sw * pref * zhat * ( ri2 - preRF2*rij )
1496 +      
1497 +    endif
1498 +      
1499 +
1500 +    ! accumulate the forces and torques resulting from the self term
1501 +    f(1,atom1) = f(1,atom1) + dudx
1502 +    f(2,atom1) = f(2,atom1) + dudy
1503 +    f(3,atom1) = f(3,atom1) + dudz
1504 +    
1505 +    f(1,atom2) = f(1,atom2) - dudx
1506 +    f(2,atom2) = f(2,atom2) - dudy
1507 +    f(3,atom2) = f(3,atom2) - dudz
1508 +    
1509 +    if (i_is_Dipole) then
1510 +       t(1,atom1)=t(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1511 +       t(2,atom1)=t(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
1512 +       t(3,atom1)=t(3,atom1) - uz_i(1)*duduz_i(2) + uz_i(2)*duduz_i(1)
1513 +    elseif (j_is_Dipole) then
1514 +       t(1,atom2)=t(1,atom2) - uz_j(2)*duduz_j(3) + uz_j(3)*duduz_j(2)
1515 +       t(2,atom2)=t(2,atom2) - uz_j(3)*duduz_j(1) + uz_j(1)*duduz_j(3)
1516 +       t(3,atom2)=t(3,atom2) - uz_j(1)*duduz_j(2) + uz_j(2)*duduz_j(1)
1517 +    endif
1518 +
1519 +    return
1520 +  end subroutine rf_self_excludes
1521 +
1522   end module electrostatic_module

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines