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 2402 by chrisfen, Tue Nov 1 19:09:30 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 <
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 419 | 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 448 | Line 464 | contains
464      real (kind=dp) :: dudx, dudy, dudz
465      real (kind=dp) :: scale, sc2, bigR
466      real (kind=dp) :: varERFC, varEXP
467 +    real (kind=dp) :: limScale
468 +    real (kind=dp) :: preVal, rfVal
469  
470      if (.not.allocated(ElectrostaticMap)) then
471         call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
# Line 456 | Line 474 | contains
474  
475      if (.not.summationMethodChecked) then
476         call checkSummationMethod()
459      
477      endif
478  
462
479   #ifdef IS_MPI
480      me1 = atid_Row(atom1)
481      me2 = atid_Col(atom2)
# Line 471 | Line 487 | contains
487      !! some variables we'll need independent of electrostatic type:
488  
489      riji = 1.0d0 / rij
490 <
490 >  
491      xhat = d(1) * riji
492      yhat = d(2) * riji
493      zhat = d(3) * riji
# Line 612 | Line 628 | contains
628         if (j_is_Charge) then
629  
630            if (summationMethod .eq. UNDAMPED_WOLF) then
615
631               vterm = pre11 * q_i * q_j * (riji - rcuti)
632               vpair = vpair + vterm
633               epot = epot + sw*vterm
634              
635 <             dudr  = -sw*pre11*q_i*q_j * (riji*riji*riji - rcuti2*rcuti)
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
627
642               varERFC = derfc(dampingAlpha*rij)
643               varEXP = exp(-dampingAlpha*dampingAlpha*rij*rij)
644               vterm = pre11 * q_i * q_j * (varERFC*riji - constERFC*rcuti)
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 <                                         - rcuti*(constERFC*rcuti2 &
637 <                                                 + 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 <          else
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 >            
664 >             dudr  = sw * preVal * ( 2.0d0*rfVal - riji )*riji
665 >            
666 >             dudx = dudx + dudr * xhat
667 >             dudy = dudy + dudr * yhat
668 >             dudz = dudz + dudr * zhat
669  
670 +          else
671               vterm = pre11 * q_i * q_j * riji
672               vpair = vpair + vterm
673               epot = epot + sw*vterm
# Line 684 | Line 710 | contains
710               duduz_j(2) = duduz_j(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
711               duduz_j(3) = duduz_j(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
712  
713 +          elseif (summationMethod .eq. REACTION_FIELD) then
714 +             ri2 = riji * riji
715 +             ri3 = ri2 * riji
716 +    
717 +             pref = pre12 * q_i * mu_j
718 +             vterm = - pref * ct_j * ( ri2 - preRF2*rij )
719 +             vpair = vpair + vterm
720 +             epot = epot + sw*vterm
721 +            
722 +             !! this has a + sign in the () because the rij vector is
723 +             !! r_j - r_i and the charge-dipole potential takes the origin
724 +             !! as the point dipole, which is atom j in this case.
725 +            
726 +             dudx = dudx - sw*pref*( ri3*(uz_j(1) - 3.0d0*ct_j*xhat) - &
727 +                                     preRF2*uz_j(1) )
728 +             dudy = dudy - sw*pref*( ri3*(uz_j(2) - 3.0d0*ct_j*yhat) - &
729 +                                     preRF2*uz_j(2) )
730 +             dudz = dudz - sw*pref*( ri3*(uz_j(3) - 3.0d0*ct_j*zhat) - &
731 +                                     preRF2*uz_j(3) )        
732 +             duduz_j(1) = duduz_j(1) - sw*pref * xhat * ( ri2 - preRF2*rij )
733 +             duduz_j(2) = duduz_j(2) - sw*pref * yhat * ( ri2 - preRF2*rij )
734 +             duduz_j(3) = duduz_j(3) - sw*pref * zhat * ( ri2 - preRF2*rij )
735 +
736            else
737               if (j_is_SplitDipole) then
738                  BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
# Line 835 | Line 884 | contains
884               vpair = vpair + vterm
885               epot = epot + sw*vterm
886              
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            
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 846 | 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 = riji * riji
900 +             ri3 = ri2 * riji
901 +
902 +             pref = pre12 * q_j * mu_i
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 +                  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 - 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
920                  BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
# Line 882 | 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 +             sc2 = scale * scale
993 +            
994 +             pref = pre22 * mu_i * mu_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 * sc2 - ct_ij
1000 +            
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 +             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
1017 +             ri3 = ri2 * riji
1018 +             ri4 = ri2 * ri2
1019 +
1020               pref = pre22 * mu_i * mu_j
1021 <             vterm = pref * (ri3 - rcuti3) * (ct_ij - 3.0d0 * ct_i * ct_j)
1021 >              
1022 >             vterm = pref*( ri3*(ct_ij - 3.0d0 * ct_i * ct_j) - &
1023 >                  preRF2*ct_ij )
1024               vpair = vpair + vterm
1025               epot = epot + sw*vterm
1026              
1027               a1 = 5.0d0 * ct_i * ct_j - ct_ij
1028              
1029               dudx = dudx + sw*pref*3.0d0*ri4 &
1030 <                             * (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))
1030 >                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1031               dudy = dudy + sw*pref*3.0d0*ri4 &
1032 <                             * (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))
1032 >                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1033               dudz = dudz + sw*pref*3.0d0*ri4 &
1034 <                             * (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))
1034 >                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1035              
1036               duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1037 <                  - rcuti3*(uz_j(1) - 3.0d0*ct_j*d(1)*rcuti))
1037 >                  - preRF2*uz_j(1))
1038               duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1039 <                  - rcuti3*(uz_j(2) - 3.0d0*ct_j*d(2)*rcuti))
1039 >                  - preRF2*uz_j(2))
1040               duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1041 <                  - rcuti3*(uz_j(3) - 3.0d0*ct_j*d(3)*rcuti))
1041 >                  - preRF2*uz_j(3))
1042               duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1043 <                  - rcuti3*(uz_i(1) - 3.0d0*ct_i*d(1)*rcuti))
1043 >                  - preRF2*uz_i(1))
1044               duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1045 <                  - rcuti3*(uz_i(2) - 3.0d0*ct_i*d(2)*rcuti))
1045 >                  - preRF2*uz_i(2))
1046               duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1047 <                  - rcuti3*(uz_i(3) - 3.0d0*ct_i*d(3)*rcuti))
1047 >                  - preRF2*uz_i(3))
1048  
1049            else
1050               if (i_is_SplitDipole) then
# Line 1080 | Line 1207 | contains
1207  
1208      if (do_pot) then
1209   #ifdef IS_MPI
1210 <       pot_row(atom1) = pot_row(atom1) + 0.5d0*epot
1211 <       pot_col(atom2) = pot_col(atom2) + 0.5d0*epot
1210 >       pot_row(ELECTROSTATIC_POT,atom1) = pot_row(ELECTROSTATIC_POT,atom1) + 0.5d0*epot
1211 >       pot_col(ELECTROSTATIC_POT,atom2) = pot_col(ELECTROSTATIC_POT,atom2) + 0.5d0*epot
1212   #else
1213         pot = pot + epot
1214   #endif
# Line 1186 | Line 1313 | contains
1313      return
1314    end subroutine doElectrostaticPair
1315  
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
1217
1316    subroutine destroyElectrostaticTypes()
1317  
1318      if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap)
1319 +
1320 +  end subroutine destroyElectrostaticTypes
1321 +
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, 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)
1334 +
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 +    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 +  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 <  end subroutine destroyElectrostaticTypes
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_excludes
1524 +
1525   end module electrostatic_module

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines