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 2381 by chrisfen, Tue Oct 18 15:01:42 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 97 | Line 96 | module electrostatic_module
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 <  logical, save :: preRFCalculated = .false.
99 >  real(kind=dp), save :: preRF2 = 0.0_DP
100  
101   #ifdef __IFC
102   ! error function for ifc version > 7.
# Line 108 | Line 107 | module electrostatic_module
107    public :: setElectrostaticCutoffRadius
108    public :: setDampedWolfAlpha
109    public :: setReactionFieldDielectric
111  public :: setReactionFieldPrefactor
110    public :: newElectrostaticType
111    public :: setCharge
112    public :: setDipoleMoment
# Line 117 | Line 115 | module electrostatic_module
115    public :: doElectrostaticPair
116    public :: getCharge
117    public :: getDipoleMoment
120  public :: pre22
118    public :: destroyElectrostaticTypes
119 <  public :: accumulate_rf
120 <  public :: accumulate_self_rf
124 <  public :: reaction_field_final
125 <  public :: rf_correct_forces
119 >  public :: self_self
120 >  public :: rf_self_excludes
121  
122    type :: Electrostatic
123       integer :: c_ident
# Line 172 | Line 167 | contains
167      dielectric = thisDielectric
168      haveDielectric = .true.
169    end subroutine setReactionFieldDielectric
175
176  subroutine setReactionFieldPrefactor
177    if (haveDefaultCutoff .and. haveDielectric) then
178       defaultCutoff2 = defaultCutoff*defaultCutoff
179       preRF = pre22 * 2.0d0*(dielectric-1.0d0) / &
180            ((2.0d0*dielectric+1.0d0)*defaultCutoff2*defaultCutoff)
181       preRFCalculated = .true.
182    else if (.not.haveDefaultCutoff) then
183       call handleError("setReactionFieldPrefactor", "Default cutoff not set")
184    else
185       call handleError("setReactionFieldPrefactor", "Dielectric not set")
186    endif
187  end subroutine setReactionFieldPrefactor
170  
171    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
172         is_SplitDipole, is_Quadrupole, is_Tap, status)
# Line 408 | Line 390 | contains
390      rcuti4 = rcuti2*rcuti2
391  
392      if (summationMethod .eq. DAMPED_WOLF) then
393 <       if (.not.haveDWAconstants) then
394 <          
413 <          if (.not.haveDampingAlpha) then
414 <             call handleError("checkSummationMethod", "no Damping Alpha set!")
415 <          endif
416 <          
417 <          if (.not.haveDefaultCutoff) then
418 <             call handleError("checkSummationMethod", "no Default Cutoff set!")
419 <          endif
420 <
421 <          constEXP = exp(-dampingAlpha*dampingAlpha*defaultCutoff*defaultCutoff)
422 <          constERFC = derfc(dampingAlpha*defaultCutoff)
423 <          invRootPi = 0.56418958354775628695d0
424 <          alphaPi = 2*dampingAlpha*invRootPi
425 <  
426 <          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 449 | 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 479 | Line 465 | contains
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 487 | Line 474 | contains
474  
475      if (.not.summationMethodChecked) then
476         call checkSummationMethod()
490      
477      endif
478  
493
479   #ifdef IS_MPI
480      me1 = atid_Row(atom1)
481      me2 = atid_Col(atom2)
# Line 643 | Line 628 | contains
628         if (j_is_Charge) then
629  
630            if (summationMethod .eq. UNDAMPED_WOLF) then
646
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-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
658
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 <                                                 - (constERFC*rcuti2 &
668 <                                                    + 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 714 | Line 709 | contains
709               duduz_j(1) = duduz_j(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
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
# Line 866 | Line 884 | contains
884               vpair = vpair + vterm
885               epot = epot + sw*vterm
886              
869             !! this has a + sign in the () because the rij vector is
870             !! r_j - r_i and the charge-dipole potential takes the origin
871             !! as the point dipole, which is atom j in this case.
872            
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 877 | 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 913 | 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)) &
929 <                         - sw*pref*3.0d0*rcuti4 &
930 <                             * (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)) &
933 <                         - sw*pref*3.0d0*rcuti4 &
934 <                             * (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)) &
937 <                         - sw*pref*3.0d0*rcuti4 &
938 <                             * (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 1217 | Line 1313 | contains
1313      return
1314    end subroutine doElectrostaticPair
1315  
1220  !! calculates the switching functions and their derivatives for a given
1221  subroutine calc_switch(r, mu, scale, dscale)
1222
1223    real (kind=dp), intent(in) :: r, mu
1224    real (kind=dp), intent(inout) :: scale, dscale
1225    real (kind=dp) :: rl, ru, mulow, minRatio, temp, scaleVal
1226
1227    ! distances must be in angstroms
1228    rl = 2.75d0
1229    ru = 3.75d0
1230    mulow = 0.0d0 !3.3856d0 ! 1.84 * 1.84
1231    minRatio = mulow / (mu*mu)
1232    scaleVal = 1.0d0 - minRatio
1233    
1234    if (r.lt.rl) then
1235       scale = minRatio
1236       dscale = 0.0d0
1237    elseif (r.gt.ru) then
1238       scale = 1.0d0
1239       dscale = 0.0d0
1240    else
1241       scale = 1.0d0 - scaleVal*((ru + 2.0d0*r - 3.0d0*rl) * (ru-r)**2) &
1242                        / ((ru - rl)**3)
1243       dscale = -scaleVal * 6.0d0 * (r-ru)*(r-rl)/((ru - rl)**3)    
1244    endif
1245        
1246    return
1247  end subroutine calc_switch
1248
1316    subroutine destroyElectrostaticTypes()
1317  
1318      if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap)
1319  
1320    end subroutine destroyElectrostaticTypes
1321  
1322 <  subroutine accumulate_rf(atom1, atom2, rij, eFrame, taper)
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 <    integer, intent(in) :: atom1, atom2
1333 <    real (kind = dp), intent(in) :: rij
1259 <    real (kind = dp), dimension(9,nLocal) :: eFrame
1332 >    ! this is a local only array, so we use the local atom type id's:
1333 >    atid1 = atid(atom1)
1334  
1335 <    integer :: me1, me2
1336 <    real (kind = dp), intent(in) :: taper
1337 <    real (kind = dp):: mu1, mu2
1338 <    real (kind = dp), dimension(3) :: ul1
1339 <    real (kind = dp), dimension(3) :: ul2  
1340 <
1341 <    integer :: localError
1342 <
1343 < #ifdef IS_MPI
1344 <    me1 = atid_Row(atom1)
1345 <    ul1(1) = eFrame_Row(3,atom1)
1346 <    ul1(2) = eFrame_Row(6,atom1)
1347 <    ul1(3) = eFrame_Row(9,atom1)
1348 <
1349 <    me2 = atid_Col(atom2)
1350 <    ul2(1) = eFrame_Col(3,atom2)
1351 <    ul2(2) = eFrame_Col(6,atom2)
1352 <    ul2(3) = eFrame_Col(9,atom2)
1353 < #else
1354 <    me1 = atid(atom1)
1355 <    ul1(1) = eFrame(3,atom1)
1356 <    ul1(2) = eFrame(6,atom1)
1357 <    ul1(3) = eFrame(9,atom1)
1358 <
1359 <    me2 = atid(atom2)
1360 <    ul2(1) = eFrame(3,atom2)
1361 <    ul2(2) = eFrame(6,atom2)
1362 <    ul2(3) = eFrame(9,atom2)
1289 < #endif
1290 <
1291 <    mu1 = getDipoleMoment(me1)
1292 <    mu2 = getDipoleMoment(me2)
1293 <
1294 < #ifdef IS_MPI
1295 <    rf_Row(1,atom1) = rf_Row(1,atom1) + ul2(1)*mu2*taper
1296 <    rf_Row(2,atom1) = rf_Row(2,atom1) + ul2(2)*mu2*taper
1297 <    rf_Row(3,atom1) = rf_Row(3,atom1) + ul2(3)*mu2*taper
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 <    rf_Col(1,atom2) = rf_Col(1,atom2) + ul1(1)*mu1*taper
1365 <    rf_Col(2,atom2) = rf_Col(2,atom2) + ul1(2)*mu1*taper
1366 <    rf_Col(3,atom2) = rf_Col(3,atom2) + ul1(3)*mu1*taper
1367 < #else
1368 <    rf(1,atom1) = rf(1,atom1) + ul2(1)*mu2*taper
1369 <    rf(2,atom1) = rf(2,atom1) + ul2(2)*mu2*taper
1370 <    rf(3,atom1) = rf(3,atom1) + ul2(3)*mu2*taper
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 <    rf(1,atom2) = rf(1,atom2) + ul1(1)*mu1*taper
1384 <    rf(2,atom2) = rf(2,atom2) + ul1(2)*mu1*taper
1385 <    rf(3,atom2) = rf(3,atom2) + ul1(3)*mu1*taper    
1310 < #endif
1311 <    return  
1312 <  end subroutine accumulate_rf
1313 <
1314 <  subroutine accumulate_self_rf(atom1, mu1, eFrame)
1315 <
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 <    real(kind=dp), intent(in) :: mu1
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 <    !! should work for both MPI and non-MPI version since this is not pairwise.
1411 <    rf(1,atom1) = rf(1,atom1) + eFrame(3,atom1)*mu1
1322 <    rf(2,atom1) = rf(2,atom1) + eFrame(6,atom1)*mu1
1323 <    rf(3,atom1) = rf(3,atom1) + eFrame(9,atom1)*mu1
1324 <
1325 <    return
1326 <  end subroutine accumulate_self_rf
1327 <
1328 <  subroutine reaction_field_final(a1, mu1, eFrame, rfpot, t, do_pot)
1329 <
1330 <    integer, intent(in) :: a1
1331 <    real (kind=dp), intent(in) :: mu1
1332 <    real (kind=dp), intent(inout) :: rfpot
1333 <    logical, intent(in) :: do_pot
1334 <    real (kind = dp), dimension(9,nLocal) :: eFrame
1335 <    real (kind = dp), dimension(3,nLocal) :: t
1336 <
1337 <    integer :: localError
1338 <
1339 <    if (.not.preRFCalculated) then
1340 <       call setReactionFieldPrefactor()
1410 >    if (.not.summationMethodChecked) then
1411 >       call checkSummationMethod()
1412      endif
1413  
1414 <    ! compute torques on dipoles:
1415 <    ! pre converts from mu in units of debye to kcal/mol
1414 >    dudx = 0.0d0
1415 >    dudy = 0.0d0
1416 >    dudz = 0.0d0
1417  
1418 <    ! The torque contribution is dipole cross reaction_field  
1418 >    riji = 1.0d0/rij
1419  
1420 <    t(1,a1) = t(1,a1) + preRF*mu1*(eFrame(6,a1)*rf(3,a1) - &
1421 <                                   eFrame(9,a1)*rf(2,a1))
1422 <    t(2,a1) = t(2,a1) + preRF*mu1*(eFrame(9,a1)*rf(1,a1) - &
1351 <                                   eFrame(3,a1)*rf(3,a1))
1352 <    t(3,a1) = t(3,a1) + preRF*mu1*(eFrame(3,a1)*rf(2,a1) - &
1353 <                                   eFrame(6,a1)*rf(1,a1))
1420 >    xhat = d(1) * riji
1421 >    yhat = d(2) * riji
1422 >    zhat = d(3) * riji
1423  
1424 <    ! the potential contribution is -1/2 dipole dot reaction_field
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 (do_pot) then
1433 <       rfpot = rfpot - 0.5d0 * preRF * mu1 * &
1434 <            (rf(1,a1)*eFrame(3,a1) + rf(2,a1)*eFrame(6,a1) + &
1435 <             rf(3,a1)*eFrame(9,a1))
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 <    return
1504 <  end subroutine reaction_field_final
1505 <
1506 <  subroutine rf_correct_forces(atom1, atom2, d, rij, eFrame, taper, f, fpair)
1507 <
1508 <    integer, intent(in) :: atom1, atom2
1509 <    real(kind=dp), dimension(3), intent(in) :: d
1510 <    real(kind=dp), intent(in) :: rij, taper
1511 <    real( kind = dp ), dimension(9,nLocal) :: eFrame
1512 <    real( kind = dp ), dimension(3,nLocal) :: f
1513 <    real( kind = dp ), dimension(3), intent(inout) :: fpair
1514 <
1515 <    real (kind = dp), dimension(3) :: ul1
1516 <    real (kind = dp), dimension(3) :: ul2
1517 <    real (kind = dp) :: dtdr
1518 <    real (kind = dp) :: dudx, dudy, dudz, u1dotu2
1519 <    integer :: me1, me2, id1, id2
1380 <    real (kind = dp) :: mu1, mu2
1381 <
1382 <    integer :: localError
1383 <
1384 <    if (.not.preRFCalculated) then
1385 <       call setReactionFieldPrefactor()
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  
1388    if (rij.le.rrf) then
1389
1390       if (rij.lt.rt) then
1391          dtdr = 0.0d0
1392       else
1393          !         write(*,*) 'rf correct in taper region'
1394          dtdr = 6.0d0*(rij*rij - rij*rt - rij*rrf +rrf*rt)/((rrf-rt)**3)
1395       endif
1396
1397 #ifdef IS_MPI
1398       me1 = atid_Row(atom1)
1399       ul1(1) = eFrame_Row(3,atom1)
1400       ul1(2) = eFrame_Row(6,atom1)
1401       ul1(3) = eFrame_Row(9,atom1)
1402
1403       me2 = atid_Col(atom2)
1404       ul2(1) = eFrame_Col(3,atom2)
1405       ul2(2) = eFrame_Col(6,atom2)
1406       ul2(3) = eFrame_Col(9,atom2)
1407 #else
1408       me1 = atid(atom1)
1409       ul1(1) = eFrame(3,atom1)
1410       ul1(2) = eFrame(6,atom1)
1411       ul1(3) = eFrame(9,atom1)
1412
1413       me2 = atid(atom2)
1414       ul2(1) = eFrame(3,atom2)
1415       ul2(2) = eFrame(6,atom2)
1416       ul2(3) = eFrame(9,atom2)
1417 #endif
1418
1419       mu1 = getDipoleMoment(me1)
1420       mu2 = getDipoleMoment(me2)
1421
1422       u1dotu2 = ul1(1)*ul2(1) + ul1(2)*ul2(2) + ul1(3)*ul2(3)
1423
1424       dudx = - preRF*mu1*mu2*u1dotu2*dtdr*d(1)/rij
1425       dudy = - preRF*mu1*mu2*u1dotu2*dtdr*d(2)/rij
1426       dudz = - preRF*mu1*mu2*u1dotu2*dtdr*d(3)/rij
1427
1428 #ifdef IS_MPI
1429       f_Row(1,atom1) = f_Row(1,atom1) + dudx
1430       f_Row(2,atom1) = f_Row(2,atom1) + dudy
1431       f_Row(3,atom1) = f_Row(3,atom1) + dudz
1432
1433       f_Col(1,atom2) = f_Col(1,atom2) - dudx
1434       f_Col(2,atom2) = f_Col(2,atom2) - dudy
1435       f_Col(3,atom2) = f_Col(3,atom2) - dudz
1436 #else
1437       f(1,atom1) = f(1,atom1) + dudx
1438       f(2,atom1) = f(2,atom1) + dudy
1439       f(3,atom1) = f(3,atom1) + dudz
1440
1441       f(1,atom2) = f(1,atom2) - dudx
1442       f(2,atom2) = f(2,atom2) - dudy
1443       f(3,atom2) = f(3,atom2) - dudz
1444 #endif
1445
1446 #ifdef IS_MPI
1447       id1 = AtomRowToGlobal(atom1)
1448       id2 = AtomColToGlobal(atom2)
1449 #else
1450       id1 = atom1
1451       id2 = atom2
1452 #endif
1453
1454       if (molMembershipList(id1) .ne. molMembershipList(id2)) then
1455
1456          fpair(1) = fpair(1) + dudx
1457          fpair(2) = fpair(2) + dudy
1458          fpair(3) = fpair(3) + dudz
1459
1460       endif
1461
1462    end if
1522      return
1523 <  end subroutine rf_correct_forces
1523 >  end subroutine rf_self_excludes
1524  
1525   end module electrostatic_module

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines