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 2439 by chrisfen, Tue Nov 15 19:42:22 2005 UTC vs.
Revision 2722 by gezelter, Thu Apr 20 18:24:24 2006 UTC

# Line 47 | Line 47 | module electrostatic_module
47    use vector_class
48    use simulation
49    use status
50 +  use interpolation
51   #ifdef IS_MPI
52    use mpiSimulation
53   #endif
# Line 64 | Line 65 | module electrostatic_module
65    !! these prefactors convert the multipole interactions into kcal / mol
66    !! all were computed assuming distances are measured in angstroms
67    !! Charge-Charge, assuming charges are measured in electrons
68 <  real(kind=dp), parameter :: pre11 = 332.0637778_dp
68 >  real(kind=dp), parameter :: pre11 = 332.0637778d0
69    !! Charge-Dipole, assuming charges are measured in electrons, and
70    !! dipoles are measured in debyes
71 <  real(kind=dp), parameter :: pre12 = 69.13373_dp
71 >  real(kind=dp), parameter :: pre12 = 69.13373d0
72    !! Dipole-Dipole, assuming dipoles are measured in debyes
73 <  real(kind=dp), parameter :: pre22 = 14.39325_dp
73 >  real(kind=dp), parameter :: pre22 = 14.39325d0
74    !! Charge-Quadrupole, assuming charges are measured in electrons, and
75    !! quadrupoles are measured in 10^-26 esu cm^2
76    !! This unit is also known affectionately as an esu centi-barn.
77 <  real(kind=dp), parameter :: pre14 = 69.13373_dp
77 >  real(kind=dp), parameter :: pre14 = 69.13373d0
78  
79 +  real(kind=dp), parameter :: zero = 0.0d0
80 +
81    !! variables to handle different summation methods for long-range
82    !! electrostatics:
83    integer, save :: summationMethod = NONE
# Line 103 | Line 106 | module electrostatic_module
106    real(kind=dp), save :: f0 = 1.0_DP
107    real(kind=dp), save :: f1 = 1.0_DP
108    real(kind=dp), save :: f2 = 0.0_DP
109 +  real(kind=dp), save :: f3 = 0.0_DP
110 +  real(kind=dp), save :: f4 = 0.0_DP
111    real(kind=dp), save :: f0c = 1.0_DP
112    real(kind=dp), save :: f1c = 1.0_DP
113    real(kind=dp), save :: f2c = 0.0_DP
114 +  real(kind=dp), save :: f3c = 0.0_DP
115 +  real(kind=dp), save :: f4c = 0.0_DP
116  
117 < #ifdef __IFC
117 > #if defined(__IFC) || defined(__PGI)
118   ! error function for ifc version > 7.
119    double precision, external :: derfc
120   #endif
# Line 117 | Line 124 | module electrostatic_module
124    public :: setElectrostaticCutoffRadius
125    public :: setDampingAlpha
126    public :: setReactionFieldDielectric
127 +  public :: buildElectroSplines
128    public :: newElectrostaticType
129    public :: setCharge
130    public :: setDipoleMoment
# Line 129 | Line 137 | module electrostatic_module
137    public :: self_self
138    public :: rf_self_excludes
139  
140 +
141    type :: Electrostatic
142       integer :: c_ident
143       logical :: is_Charge = .false.
# Line 144 | Line 153 | contains
153  
154    type(Electrostatic), dimension(:), allocatable :: ElectrostaticMap
155  
156 +  logical, save :: hasElectrostaticMap
157 +
158   contains
159  
160    subroutine setElectrostaticSummationMethod(the_ESM)
# Line 166 | Line 177 | contains
177      real(kind=dp), intent(in) :: thisRcut
178      real(kind=dp), intent(in) :: thisRsw
179      defaultCutoff = thisRcut
180 +    defaultCutoff2 = defaultCutoff*defaultCutoff
181      rrf = defaultCutoff
182      rt = thisRsw
183      haveDefaultCutoff = .true.
# Line 184 | Line 196 | contains
196      haveDielectric = .true.
197    end subroutine setReactionFieldDielectric
198  
199 +  subroutine buildElectroSplines()
200 +  end subroutine buildElectroSplines
201 +
202    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
203         is_SplitDipole, is_Quadrupole, is_Tap, status)
204  
# Line 211 | Line 226 | contains
226            return
227         end if
228  
229 <       if (.not. allocated(ElectrostaticMap)) then
215 <          allocate(ElectrostaticMap(nAtypes))
216 <       endif
229 >       allocate(ElectrostaticMap(nAtypes))
230  
231      end if
232  
# Line 231 | Line 244 | contains
244      ElectrostaticMap(myATID)%is_Quadrupole = is_Quadrupole
245      ElectrostaticMap(myATID)%is_Tap = is_Tap
246  
247 +    hasElectrostaticMap = .true.
248 +
249    end subroutine newElectrostaticType
250  
251    subroutine setCharge(c_ident, charge, status)
# Line 242 | Line 257 | contains
257      status = 0
258      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
259  
260 <    if (.not.allocated(ElectrostaticMap)) then
260 >    if (.not.hasElectrostaticMap) then
261         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setCharge!")
262         status = -1
263         return
# Line 272 | Line 287 | contains
287      status = 0
288      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
289  
290 <    if (.not.allocated(ElectrostaticMap)) then
290 >    if (.not.hasElectrostaticMap) then
291         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setDipoleMoment!")
292         status = -1
293         return
# Line 302 | Line 317 | contains
317      status = 0
318      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
319  
320 <    if (.not.allocated(ElectrostaticMap)) then
320 >    if (.not.hasElectrostaticMap) then
321         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setSplitDipoleDistance!")
322         status = -1
323         return
# Line 332 | Line 347 | contains
347      status = 0
348      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
349  
350 <    if (.not.allocated(ElectrostaticMap)) then
350 >    if (.not.hasElectrostaticMap) then
351         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setQuadrupoleMoments!")
352         status = -1
353         return
# Line 363 | Line 378 | contains
378      integer :: localError
379      real(kind=dp) :: c
380  
381 <    if (.not.allocated(ElectrostaticMap)) then
381 >    if (.not.hasElectrostaticMap) then
382         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getCharge!")
383         return
384      end if
# Line 381 | Line 396 | contains
396      integer :: localError
397      real(kind=dp) :: dm
398  
399 <    if (.not.allocated(ElectrostaticMap)) then
399 >    if (.not.hasElectrostaticMap) then
400         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getDipoleMoment!")
401         return
402      end if
# Line 414 | Line 429 | contains
429            call handleError("checkSummationMethod", "no Default Cutoff set!")
430         endif
431  
432 <       constEXP = exp(-alpha2*defaultCutoff*defaultCutoff)
432 >       constEXP = exp(-alpha2*defaultCutoff2)
433         invRootPi = 0.56418958354775628695d0
434         alphaPi = 2.0d0*dampingAlpha*invRootPi
435         f0c = derfc(dampingAlpha*defaultCutoff)
436         f1c = alphaPi*defaultCutoff*constEXP + f0c
437 <       f2c = alphaPi*2.0d0*alpha2*constEXP*rcuti2
438 <
437 >       f2c = alphaPi*2.0d0*alpha2*constEXP
438 >       f3c = alphaPi*2.0d0*alpha2*constEXP*defaultCutoff2*defaultCutoff
439      endif
440  
441      if (summationMethod .eq. REACTION_FIELD) then
# Line 439 | Line 454 | contains
454    end subroutine checkSummationMethod
455  
456  
457 <  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
457 >  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, rcut, sw, &
458         vpair, fpair, pot, eFrame, f, t, do_pot)
459  
460      logical, intent(in) :: do_pot
# Line 447 | Line 462 | contains
462      integer, intent(in) :: atom1, atom2
463      integer :: localError
464  
465 <    real(kind=dp), intent(in) :: rij, r2, sw
465 >    real(kind=dp), intent(in) :: rij, r2, sw, rcut
466      real(kind=dp), intent(in), dimension(3) :: d
467      real(kind=dp), intent(inout) :: vpair
468      real(kind=dp), intent(inout), dimension(3) :: fpair    
# Line 482 | Line 497 | contains
497      real (kind=dp) :: varEXP
498      real (kind=dp) :: pot_term
499      real (kind=dp) :: preVal, rfVal
500 <
486 <    if (.not.allocated(ElectrostaticMap)) then
487 <       call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
488 <       return
489 <    end if
500 >    real (kind=dp) :: f13, f134
501  
502      if (.not.summationMethodChecked) then
503         call checkSummationMethod()
# Line 500 | Line 511 | contains
511      me2 = atid(atom2)
512   #endif
513  
503 !!$    if (rij .ge. defaultCutoff) then
504 !!$       write(*,*) 'warning: rij = ', rij, ' rcut = ', defaultCutoff, ' sw = ', sw
505 !!$    endif
506
514      !! some variables we'll need independent of electrostatic type:
515  
516      riji = 1.0d0 / rij
# Line 545 | Line 552 | contains
552         if (i_is_SplitDipole) then
553            d_i = ElectrostaticMap(me1)%split_dipole_distance
554         endif
555 <
555 >       duduz_i = zero
556      endif
557  
558      if (i_is_Quadrupole) then
# Line 576 | Line 583 | contains
583         cx_i = ux_i(1)*xhat + ux_i(2)*yhat + ux_i(3)*zhat
584         cy_i = uy_i(1)*xhat + uy_i(2)*yhat + uy_i(3)*zhat
585         cz_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
586 +       dudux_i = zero
587 +       duduy_i = zero
588 +       duduz_i = zero
589      endif
590  
591      if (j_is_Charge) then
# Line 598 | Line 608 | contains
608         if (j_is_SplitDipole) then
609            d_j = ElectrostaticMap(me2)%split_dipole_distance
610         endif
611 +       duduz_j = zero
612      endif
613  
614      if (j_is_Quadrupole) then
# Line 628 | Line 639 | contains
639         cx_j = ux_j(1)*xhat + ux_j(2)*yhat + ux_j(3)*zhat
640         cy_j = uy_j(1)*xhat + uy_j(2)*yhat + uy_j(3)*zhat
641         cz_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
642 +       dudux_j = zero
643 +       duduy_j = zero
644 +       duduz_j = zero
645      endif
646    
647 <    epot = 0.0_dp
648 <    dudx = 0.0_dp
649 <    dudy = 0.0_dp
650 <    dudz = 0.0_dp
647 >    epot = zero
648 >    dudx = zero
649 >    dudy = zero
650 >    dudz = zero  
651  
638    dudux_i = 0.0_dp
639    duduy_i = 0.0_dp
640    duduz_i = 0.0_dp
641
642    dudux_j = 0.0_dp
643    duduy_j = 0.0_dp
644    duduz_j = 0.0_dp
645
652      if (i_is_Charge) then
653  
654         if (j_is_Charge) then
# Line 688 | Line 694 | contains
694         endif
695  
696         if (j_is_Dipole) then
697 +          if (screeningMethod .eq. DAMPED) then
698 +             f0 = derfc(dampingAlpha*rij)
699 +             varEXP = exp(-alpha2*rij*rij)
700 +             f1 = alphaPi*rij*varEXP + f0
701 +             f3 = alphaPi*2.0d0*alpha2*varEXP*rij*rij*rij
702 +          endif
703  
704            pref = pre12 * q_i * mu_j
705  
# Line 715 | Line 727 | contains
727  
728            else
729               if (j_is_SplitDipole) then
730 <                BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
731 <                ri = 1.0_dp / BigR
730 >                BigR = sqrt(r2 + 0.25d0 * d_j * d_j)
731 >                ri = 1.0d0 / BigR
732                  scale = rij * ri
733               else
734                  ri = riji
735 <                scale = 1.0_dp
735 >                scale = 1.0d0
736               endif
737              
738               ri2 = ri * ri
739               ri3 = ri2 * ri
740               sc2 = scale * scale
741  
742 <             vterm = - pref * ct_j * ri2 * scale
742 >             pot_term =  ri2 * scale * f1
743 >             vterm = - pref * ct_j * pot_term
744               vpair = vpair + vterm
745               epot = epot + sw*vterm
746              
# Line 735 | Line 748 | contains
748               !! r_j - r_i and the charge-dipole potential takes the origin
749               !! as the point dipole, which is atom j in this case.
750              
751 <             dudx = dudx - sw*pref * ri3 * ( uz_j(1) - 3.0d0*ct_j*xhat*sc2)
752 <             dudy = dudy - sw*pref * ri3 * ( uz_j(2) - 3.0d0*ct_j*yhat*sc2)
753 <             dudz = dudz - sw*pref * ri3 * ( uz_j(3) - 3.0d0*ct_j*zhat*sc2)
754 <            
755 <             duduz_j(1) = duduz_j(1) - sw*pref * ri2 * xhat * scale
756 <             duduz_j(2) = duduz_j(2) - sw*pref * ri2 * yhat * scale
757 <             duduz_j(3) = duduz_j(3) - sw*pref * ri2 * zhat * scale
751 >             dudx = dudx - sw*pref * ri3 * ( uz_j(1)*f1 - &
752 >                  ct_j*xhat*sc2*( 3.0d0*f1 + f3 ) )
753 >             dudy = dudy - sw*pref * ri3 * ( uz_j(2)*f1 - &
754 >                  ct_j*yhat*sc2*( 3.0d0*f1 + f3 ) )
755 >             dudz = dudz - sw*pref * ri3 * ( uz_j(3)*f1 - &
756 >                  ct_j*zhat*sc2*( 3.0d0*f1 + f3 ) )
757 >                          
758 >             duduz_j(1) = duduz_j(1) - sw*pref * pot_term * xhat
759 >             duduz_j(2) = duduz_j(2) - sw*pref * pot_term * yhat
760 >             duduz_j(3) = duduz_j(3) - sw*pref * pot_term * zhat
761  
762            endif
763         endif
764  
765         if (j_is_Quadrupole) then
766 +          if (screeningMethod .eq. DAMPED) then
767 +             f0 = derfc(dampingAlpha*rij)
768 +             varEXP = exp(-alpha2*rij*rij)
769 +             f1 = alphaPi*rij*varEXP + f0
770 +             f2 = alphaPi*2.0d0*alpha2*varEXP
771 +             f3 = f2*rij*rij*rij
772 +             f4 = 2.0d0*alpha2*f2*rij
773 +          endif
774 +
775            ri2 = riji * riji
776            ri3 = ri2 * riji
777            ri4 = ri2 * ri2
# Line 754 | Line 779 | contains
779            cy2 = cy_j * cy_j
780            cz2 = cz_j * cz_j
781  
782 <          pref =  pre14 * q_i / 3.0_dp
783 <          vterm = pref * ri3 * (qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
784 <               qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
785 <               qzz_j * (3.0_dp*cz2 - 1.0_dp))
782 >          pref =  pre14 * q_i / 3.0d0
783 >          pot_term = ri3*(qxx_j * (3.0d0*cx2 - 1.0d0) + &
784 >               qyy_j * (3.0d0*cy2 - 1.0d0) + &
785 >               qzz_j * (3.0d0*cz2 - 1.0d0))
786 >          vterm = pref * (pot_term*f1 + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f2)
787            vpair = vpair + vterm
788            epot = epot + sw*vterm
789            
790 <          dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref * ri4 * ( &
791 <               qxx_j*(6.0_dp*cx_j*ux_j(1) - 2.0_dp*xhat) + &
792 <               qyy_j*(6.0_dp*cy_j*uy_j(1) - 2.0_dp*xhat) + &
793 <               qzz_j*(6.0_dp*cz_j*uz_j(1) - 2.0_dp*xhat) )
794 <          dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref * ri4 * ( &
795 <               qxx_j*(6.0_dp*cx_j*ux_j(2) - 2.0_dp*yhat) + &
796 <               qyy_j*(6.0_dp*cy_j*uy_j(2) - 2.0_dp*yhat) + &
797 <               qzz_j*(6.0_dp*cz_j*uz_j(2) - 2.0_dp*yhat) )
798 <          dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref * ri4 * ( &
799 <               qxx_j*(6.0_dp*cx_j*ux_j(3) - 2.0_dp*zhat) + &
800 <               qyy_j*(6.0_dp*cy_j*uy_j(3) - 2.0_dp*zhat) + &
801 <               qzz_j*(6.0_dp*cz_j*uz_j(3) - 2.0_dp*zhat) )
790 >          dudx = dudx - sw*pref*pot_term*riji*xhat*(5.0d0*f1 + f3) + &
791 >               sw*pref*ri4 * ( &
792 >               qxx_j*(2.0d0*cx_j*ux_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
793 >               qyy_j*(2.0d0*cy_j*uy_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
794 >               qzz_j*(2.0d0*cz_j*uz_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) ) &
795 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
796 >          dudy = dudy - sw*pref*pot_term*riji*yhat*(5.0d0*f1 + f3) + &
797 >               sw*pref*ri4 * ( &
798 >               qxx_j*(2.0d0*cx_j*ux_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
799 >               qyy_j*(2.0d0*cy_j*uy_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
800 >               qzz_j*(2.0d0*cz_j*uz_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) ) &
801 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
802 >          dudz = dudz - sw*pref*pot_term*riji*zhat*(5.0d0*f1 + f3) + &
803 >               sw*pref*ri4 * ( &
804 >               qxx_j*(2.0d0*cx_j*ux_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
805 >               qyy_j*(2.0d0*cy_j*uy_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
806 >               qzz_j*(2.0d0*cz_j*uz_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) ) &
807 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
808            
809 <          dudux_j(1) = dudux_j(1) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*xhat)
810 <          dudux_j(2) = dudux_j(2) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*yhat)
811 <          dudux_j(3) = dudux_j(3) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*zhat)
809 >          dudux_j(1) = dudux_j(1) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*xhat) &
810 >               * (3.0d0*f1 + f3) )
811 >          dudux_j(2) = dudux_j(2) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*yhat) &
812 >               * (3.0d0*f1 + f3) )
813 >          dudux_j(3) = dudux_j(3) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*zhat) &
814 >               * (3.0d0*f1 + f3) )
815            
816 <          duduy_j(1) = duduy_j(1) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*xhat)
817 <          duduy_j(2) = duduy_j(2) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*yhat)
818 <          duduy_j(3) = duduy_j(3) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*zhat)
816 >          duduy_j(1) = duduy_j(1) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*xhat) &
817 >               * (3.0d0*f1 + f3) )
818 >          duduy_j(2) = duduy_j(2) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*yhat) &
819 >               * (3.0d0*f1 + f3) )
820 >          duduy_j(3) = duduy_j(3) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*zhat) &
821 >               * (3.0d0*f1 + f3) )
822            
823 <          duduz_j(1) = duduz_j(1) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*xhat)
824 <          duduz_j(2) = duduz_j(2) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*yhat)
825 <          duduz_j(3) = duduz_j(3) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*zhat)
826 <          
823 >          duduz_j(1) = duduz_j(1) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*xhat) &
824 >               * (3.0d0*f1 + f3) )
825 >          duduz_j(2) = duduz_j(2) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*yhat) &
826 >               * (3.0d0*f1 + f3) )
827 >          duduz_j(3) = duduz_j(3) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*zhat) &
828 >               * (3.0d0*f1 + f3) )
829 >          
830         endif
831      endif
832      
833      if (i_is_Dipole) then
834  
835         if (j_is_Charge) then
836 +          if (screeningMethod .eq. DAMPED) then
837 +             f0 = derfc(dampingAlpha*rij)
838 +             varEXP = exp(-alpha2*rij*rij)
839 +             f1 = alphaPi*rij*varEXP + f0
840 +             f3 = alphaPi*2.0d0*alpha2*varEXP*rij*rij*rij
841 +          endif
842            
843            pref = pre12 * q_j * mu_i
844            
# Line 799 | Line 846 | contains
846               ri2 = riji * riji
847               ri3 = ri2 * riji
848              
849 <             pot_term = ri2 - rcuti2
849 >             pot_term = ri2*f1 - rcuti2*f1c
850               vterm = pref * ct_i * pot_term
851               vpair = vpair + vterm
852               epot = epot + sw*vterm
853              
854 <             dudx = dudx + sw*pref * ( ri3*(uz_i(1)-3.0d0*ct_i*xhat) )
855 <             dudy = dudy + sw*pref * ( ri3*(uz_i(2)-3.0d0*ct_i*yhat) )
856 <             dudz = dudz + sw*pref * ( ri3*(uz_i(3)-3.0d0*ct_i*zhat) )
854 >             dudx = dudx + sw*pref*( ri3*(uz_i(1)*f1-ct_i*xhat*(3.0d0*f1+f3)) )
855 >             dudy = dudy + sw*pref*( ri3*(uz_i(2)*f1-ct_i*yhat*(3.0d0*f1+f3)) )
856 >             dudz = dudz + sw*pref*( ri3*(uz_i(3)*f1-ct_i*zhat*(3.0d0*f1+f3)) )
857              
858               duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
859               duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
# Line 816 | Line 863 | contains
863               ri2 = riji * riji
864               ri3 = ri2 * riji
865  
866 <             pot_term = ri2 - rcuti2 + 2.0d0*rcuti3*( rij - defaultCutoff )
866 >             !! might need a -(f1c-f0c) or dct_i/dr in the derivative term...
867 >             pot_term = ri2*f1 - rcuti2*f1c + &
868 >                  (2.0d0*rcuti3*f1c + f2c)*( rij - defaultCutoff )
869               vterm = pref * ct_i * pot_term
870               vpair = vpair + vterm
871               epot = epot + sw*vterm
872              
873 <             dudx = dudx + sw*pref * ( (ri3-rcuti3)*(uz_i(1)-3.0d0*ct_i*xhat) )
874 <             dudy = dudy + sw*pref * ( (ri3-rcuti3)*(uz_i(2)-3.0d0*ct_i*yhat) )
875 <             dudz = dudz + sw*pref * ( (ri3-rcuti3)*(uz_i(3)-3.0d0*ct_i*zhat) )
873 >             dudx = dudx + sw*pref*( ri3*(uz_i(1)*f1-ct_i*xhat*(3.0d0*f1+f3)) &
874 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
875 >             dudy = dudy + sw*pref*( ri3*(uz_i(2)*f1-ct_i*yhat*(3.0d0*f1+f3)) &
876 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
877 >             dudz = dudz + sw*pref*( ri3*(uz_i(3)*f1-ct_i*zhat*(3.0d0*f1+f3)) &
878 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
879              
880               duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
881               duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
882               duduz_i(3) = duduz_i(3) + sw*pref * zhat * pot_term
883 <
883 >
884            elseif (summationMethod .eq. REACTION_FIELD) then
885               ri2 = riji * riji
886               ri3 = ri2 * riji
# Line 850 | Line 902 | contains
902  
903            else
904               if (i_is_SplitDipole) then
905 <                BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
906 <                ri = 1.0_dp / BigR
905 >                BigR = sqrt(r2 + 0.25d0 * d_i * d_i)
906 >                ri = 1.0d0 / BigR
907                  scale = rij * ri
908               else
909                  ri = riji
910 <                scale = 1.0_dp
910 >                scale = 1.0d0
911               endif
912              
913               ri2 = ri * ri
914               ri3 = ri2 * ri
915               sc2 = scale * scale
916  
917 <             vterm = pref * ct_i * ri2 * scale
917 >             pot_term = ri2 * f1 * scale
918 >             vterm = pref * ct_i * pot_term
919               vpair = vpair + vterm
920               epot = epot + sw*vterm
921              
922 <             dudx = dudx + sw*pref * ri3 * ( uz_i(1) - 3.0d0 * ct_i * xhat*sc2)
923 <             dudy = dudy + sw*pref * ri3 * ( uz_i(2) - 3.0d0 * ct_i * yhat*sc2)
924 <             dudz = dudz + sw*pref * ri3 * ( uz_i(3) - 3.0d0 * ct_i * zhat*sc2)
922 >             dudx = dudx + sw*pref * ri3 * ( uz_i(1)*f1 - &
923 >                  ct_i*xhat*sc2*( 3.0d0*f1 + f3 ) )
924 >             dudy = dudy + sw*pref * ri3 * ( uz_i(2)*f1 - &
925 >                  ct_i*yhat*sc2*( 3.0d0*f1 + f3 ) )
926 >             dudz = dudz + sw*pref * ri3 * ( uz_i(3)*f1 - &
927 >                  ct_i*zhat*sc2*( 3.0d0*f1 + f3 ) )
928              
929 <             duduz_i(1) = duduz_i(1) + sw*pref * ri2 * xhat * scale
930 <             duduz_i(2) = duduz_i(2) + sw*pref * ri2 * yhat * scale
931 <             duduz_i(3) = duduz_i(3) + sw*pref * ri2 * zhat * scale
929 >             duduz_i(1) = duduz_i(1) + sw*pref * pot_term * xhat
930 >             duduz_i(2) = duduz_i(2) + sw*pref * pot_term * yhat
931 >             duduz_i(3) = duduz_i(3) + sw*pref * pot_term * zhat
932            endif
933         endif
934        
935         if (j_is_Dipole) then
936 +          if (screeningMethod .eq. DAMPED) then
937 +             f0 = derfc(dampingAlpha*rij)
938 +             varEXP = exp(-alpha2*rij*rij)
939 +             f1 = alphaPi*rij*varEXP + f0
940 +             f2 = alphaPi*2.0d0*alpha2*varEXP
941 +             f3 = f2*rij*rij*rij
942 +             f4 = 2.0d0*alpha2*f3*rij*rij
943 +          endif
944 +
945            ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
946            
947            ri2 = riji * riji
# Line 916 | Line 981 | contains
981            else
982               if (i_is_SplitDipole) then
983                  if (j_is_SplitDipole) then
984 <                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i + 0.25_dp * d_j * d_j)
984 >                   BigR = sqrt(r2 + 0.25d0 * d_i * d_i + 0.25d0 * d_j * d_j)
985                  else
986 <                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
986 >                   BigR = sqrt(r2 + 0.25d0 * d_i * d_i)
987                  endif
988 <                ri = 1.0_dp / BigR
988 >                ri = 1.0d0 / BigR
989                  scale = rij * ri                
990               else
991                  if (j_is_SplitDipole) then
992 <                   BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
993 <                   ri = 1.0_dp / BigR
992 >                   BigR = sqrt(r2 + 0.25d0 * d_j * d_j)
993 >                   ri = 1.0d0 / BigR
994                     scale = rij * ri                            
995                  else                
996                     ri = riji
997 <                   scale = 1.0_dp
997 >                   scale = 1.0d0
998                  endif
999               endif
1000              
1001               sc2 = scale * scale
1002  
1003 <             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1003 >             pot_term = (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1004 >             vterm = pref * ( ri3*pot_term*f1 + (ct_i * ct_j)*f2 )
1005               vpair = vpair + vterm
1006               epot = epot + sw*vterm
1007              
1008 <             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
1008 >             f13 = f1+f3
1009 >             f134 = f13 + f4
1010              
1011 <             dudx = dudx + sw*pref*3.0d0*ri4*scale &
1012 <                             *(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1013 <             dudy = dudy + sw*pref*3.0d0*ri4*scale &
1014 <                             *(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1015 <             dudz = dudz + sw*pref*3.0d0*ri4*scale &
1016 <                             *(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1011 > !!$             dudx = dudx + sw*pref * ( ri4*scale*( &
1012 > !!$                  3.0d0*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))*f1 &
1013 > !!$                  - pot_term*f3) &
1014 > !!$                  + 2.0d0*ct_i*ct_j*xhat*(ct_i*uz_j(1)+ct_j*uz_i(1))*f3 &
1015 > !!$                  + (ct_i * ct_j)*f4 )
1016 > !!$             dudy = dudy + sw*pref * ( ri4*scale*( &
1017 > !!$                  3.0d0*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))*f1 &
1018 > !!$                  - pot_term*f3) &
1019 > !!$                  + 2.0d0*ct_i*ct_j*yhat*(ct_i*uz_j(2)+ct_j*uz_i(2))*f3 &
1020 > !!$                  + (ct_i * ct_j)*f4 )
1021 > !!$             dudz = dudz + sw*pref * ( ri4*scale*( &
1022 > !!$                  3.0d0*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))*f1 &
1023 > !!$                  - pot_term*f3) &
1024 > !!$                  + 2.0d0*ct_i*ct_j*zhat*(ct_i*uz_j(3)+ct_j*uz_i(3))*f3 &
1025 > !!$                  + (ct_i * ct_j)*f4 )
1026 >
1027 >             dudx = dudx + sw*pref * ( ri4*scale*( &
1028 >                  15.0d0*(ct_i * ct_j * sc2)*xhat*f134 - &
1029 >                  3.0d0*(ct_i*uz_j(1) + ct_j*uz_i(1) + ct_ij*xhat)*f134) )
1030 >             dudy = dudy + sw*pref * ( ri4*scale*( &
1031 >                  15.0d0*(ct_i * ct_j * sc2)*yhat*f134 - &
1032 >                  3.0d0*(ct_i*uz_j(2) + ct_j*uz_i(2) + ct_ij*yhat)*f134) )
1033 >             dudz = dudz + sw*pref * ( ri4*scale*( &
1034 >                  15.0d0*(ct_i * ct_j * sc2)*zhat*f134 - &
1035 >                  3.0d0*(ct_i*uz_j(3) + ct_j*uz_i(3) + ct_ij*zhat)*f134) )
1036              
1037 <             duduz_i(1) = duduz_i(1) + sw*pref*ri3 &
1038 <                                         *(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
1039 <             duduz_i(2) = duduz_i(2) + sw*pref*ri3 &
1040 <                                         *(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
1041 <             duduz_i(3) = duduz_i(3) + sw*pref*ri3 &
1042 <                                         *(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
1037 >             duduz_i(1) = duduz_i(1) + sw*pref * &
1038 >                  ( ri3*(uz_j(1) - 3.0d0*ct_j*xhat*sc2)*f1 + (ct_j*xhat)*f2 )
1039 >             duduz_i(2) = duduz_i(2) + sw*pref * &
1040 >                  ( ri3*(uz_j(2) - 3.0d0*ct_j*yhat*sc2)*f1 + (ct_j*yhat)*f2 )
1041 >             duduz_i(3) = duduz_i(3) + sw*pref * &
1042 >                  ( ri3*(uz_j(3) - 3.0d0*ct_j*zhat*sc2)*f1 + (ct_j*zhat)*f2 )
1043              
1044 <             duduz_j(1) = duduz_j(1) + sw*pref*ri3 &
1045 <                                         *(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
1046 <             duduz_j(2) = duduz_j(2) + sw*pref*ri3 &
1047 <                                         *(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
1048 <             duduz_j(3) = duduz_j(3) + sw*pref*ri3 &
1049 <                                         *(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
1044 >             duduz_j(1) = duduz_j(1) + sw*pref * &
1045 >                  ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat*sc2)*f1 + (ct_i*xhat)*f2 )
1046 >             duduz_j(2) = duduz_j(2) + sw*pref * &
1047 >                  ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat*sc2)*f1 + (ct_i*yhat)*f2 )
1048 >             duduz_j(3) = duduz_j(3) + sw*pref * &
1049 >                  ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat*sc2)*f1 + (ct_i*zhat)*f2 )
1050            endif
1051         endif
1052      endif
1053  
1054      if (i_is_Quadrupole) then
1055         if (j_is_Charge) then
1056 +          if (screeningMethod .eq. DAMPED) then
1057 +             f0 = derfc(dampingAlpha*rij)
1058 +             varEXP = exp(-alpha2*rij*rij)
1059 +             f1 = alphaPi*rij*varEXP + f0
1060 +             f2 = alphaPi*2.0d0*alpha2*varEXP
1061 +             f3 = f2*rij*rij*rij
1062 +             f4 = 2.0d0*alpha2*f2*rij
1063 +          endif
1064 +
1065            ri2 = riji * riji
1066            ri3 = ri2 * riji
1067            ri4 = ri2 * ri2
# Line 974 | Line 1069 | contains
1069            cy2 = cy_i * cy_i
1070            cz2 = cz_i * cz_i
1071  
1072 <          pref = pre14 * q_j / 3.0_dp
1073 <          vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1074 <               qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1075 <               qzz_i * (3.0_dp*cz2 - 1.0_dp))
1072 >          pref = pre14 * q_j / 3.0d0
1073 >          pot_term = ri3 * (qxx_i * (3.0d0*cx2 - 1.0d0) + &
1074 >                            qyy_i * (3.0d0*cy2 - 1.0d0) + &
1075 >                            qzz_i * (3.0d0*cz2 - 1.0d0))
1076 >          vterm = pref * (pot_term*f1 + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f2)
1077            vpair = vpair + vterm
1078            epot = epot + sw*vterm
1079            
1080 <          dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref*ri4 * ( &
1081 <               qxx_i*(6.0_dp*cx_i*ux_i(1) - 2.0_dp*xhat) + &
1082 <               qyy_i*(6.0_dp*cy_i*uy_i(1) - 2.0_dp*xhat) + &
1083 <               qzz_i*(6.0_dp*cz_i*uz_i(1) - 2.0_dp*xhat) )
1084 <          dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref*ri4 * ( &
1085 <               qxx_i*(6.0_dp*cx_i*ux_i(2) - 2.0_dp*yhat) + &
1086 <               qyy_i*(6.0_dp*cy_i*uy_i(2) - 2.0_dp*yhat) + &
1087 <               qzz_i*(6.0_dp*cz_i*uz_i(2) - 2.0_dp*yhat) )
1088 <          dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref*ri4 * ( &
1089 <               qxx_i*(6.0_dp*cx_i*ux_i(3) - 2.0_dp*zhat) + &
1090 <               qyy_i*(6.0_dp*cy_i*uy_i(3) - 2.0_dp*zhat) + &
1091 <               qzz_i*(6.0_dp*cz_i*uz_i(3) - 2.0_dp*zhat) )
1092 <          
1093 <          dudux_i(1) = dudux_i(1) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*xhat)
1094 <          dudux_i(2) = dudux_i(2) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*yhat)
1095 <          dudux_i(3) = dudux_i(3) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*zhat)
1096 <          
1097 <          duduy_i(1) = duduy_i(1) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*xhat)
1002 <          duduy_i(2) = duduy_i(2) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*yhat)
1003 <          duduy_i(3) = duduy_i(3) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*zhat)
1080 >          dudx = dudx - sw*pref*pot_term*riji*xhat*(5.0d0*f1 + f3) + &
1081 >               sw*pref*ri4 * ( &
1082 >               qxx_i*(2.0d0*cx_i*ux_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
1083 >               qyy_i*(2.0d0*cy_i*uy_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
1084 >               qzz_i*(2.0d0*cz_i*uz_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) ) &
1085 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1086 >          dudy = dudy - sw*pref*pot_term*riji*yhat*(5.0d0*f1 + f3) + &
1087 >               sw*pref*ri4 * ( &
1088 >               qxx_i*(2.0d0*cx_i*ux_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
1089 >               qyy_i*(2.0d0*cy_i*uy_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
1090 >               qzz_i*(2.0d0*cz_i*uz_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) ) &
1091 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1092 >          dudz = dudz - sw*pref*pot_term*riji*zhat*(5.0d0*f1 + f3) + &
1093 >               sw*pref*ri4 * ( &
1094 >               qxx_i*(2.0d0*cx_i*ux_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
1095 >               qyy_i*(2.0d0*cy_i*uy_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
1096 >               qzz_i*(2.0d0*cz_i*uz_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) ) &
1097 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1098            
1099 <          duduz_i(1) = duduz_i(1) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*xhat)
1100 <          duduz_i(2) = duduz_i(2) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*yhat)
1101 <          duduz_i(3) = duduz_i(3) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*zhat)
1099 >          dudux_i(1) = dudux_i(1) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*xhat) &
1100 >               * (3.0d0*f1 + f3) )
1101 >          dudux_i(2) = dudux_i(2) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*yhat) &
1102 >               * (3.0d0*f1 + f3) )
1103 >          dudux_i(3) = dudux_i(3) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*zhat) &
1104 >               * (3.0d0*f1 + f3) )
1105 >          
1106 >          duduy_i(1) = duduy_i(1) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*xhat) &
1107 >               * (3.0d0*f1 + f3) )
1108 >          duduy_i(2) = duduy_i(2) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*yhat) &
1109 >               * (3.0d0*f1 + f3) )
1110 >          duduy_i(3) = duduy_i(3) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*zhat) &
1111 >               * (3.0d0*f1 + f3) )
1112 >          
1113 >          duduz_i(1) = duduz_i(1) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*xhat) &
1114 >               * (3.0d0*f1 + f3) )
1115 >          duduz_i(2) = duduz_i(2) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*yhat) &
1116 >               * (3.0d0*f1 + f3) )
1117 >          duduz_i(3) = duduz_i(3) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*zhat) &
1118 >               * (3.0d0*f1 + f3) )
1119  
1120         endif
1121      endif
# Line 1166 | Line 1277 | contains
1277            
1278         endif
1279  
1280 <    elseif (summationMethod .eq. SHIFTED_FORCE) then
1280 >    elseif ( (summationMethod .eq. SHIFTED_FORCE) .or. &
1281 >         (summationMethod .eq. SHIFTED_POTENTIAL) ) then
1282         if (ElectrostaticMap(atid1)%is_Charge) then
1283            c1 = getCharge(atid1)
1284            
1285            if (screeningMethod .eq. DAMPED) then
1286 <             mypot = mypot - (f0c * rcuti * 0.5_dp + &
1286 >             mypot = mypot - (f0c * rcuti * 0.5d0 + &
1287                    dampingAlpha*invRootPi) * c1 * c1    
1288              
1289            else            
1290 <             mypot = mypot - (rcuti * 0.5_dp * c1 * c1)
1290 >             mypot = mypot - (rcuti * 0.5d0 * c1 * c1)
1291              
1292            endif
1293         endif
# Line 1215 | Line 1327 | contains
1327         call checkSummationMethod()
1328      endif
1329  
1330 <    dudx = 0.0d0
1331 <    dudy = 0.0d0
1332 <    dudz = 0.0d0
1330 >    dudx = zero
1331 >    dudy = zero
1332 >    dudz = zero
1333  
1334      riji = 1.0d0/rij
1335  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines