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 2409 by chrisfen, Wed Nov 2 20:36:25 2005 UTC vs.
Revision 2843 by chrisfen, Fri Jun 9 18:26:18 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 58 | Line 59 | module electrostatic_module
59   #define __FORTRAN90
60   #include "UseTheForce/DarkSide/fInteractionMap.h"
61   #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h"
62 < #include "UseTheForce/DarkSide/fScreeningMethod.h"
62 > #include "UseTheForce/DarkSide/fElectrostaticScreeningMethod.h"
63  
64  
65    !! these prefactors convert the multipole interactions into kcal / mol
# Line 75 | Line 76 | module electrostatic_module
76    !! This unit is also known affectionately as an esu centi-barn.
77    real(kind=dp), parameter :: pre14 = 69.13373_dp
78  
79 <  !! variables to handle different summation methods for long-range electrostatics:
79 >  real(kind=dp), parameter :: zero = 0.0_dp
80 >  
81 >  !! number of points for electrostatic splines
82 >  integer, parameter :: np = 100
83 >
84 >  !! variables to handle different summation methods for long-range
85 >  !! electrostatics:
86    integer, save :: summationMethod = NONE
87    integer, save :: screeningMethod = UNDAMPED
88    logical, save :: summationMethodChecked = .false.
# Line 83 | Line 90 | module electrostatic_module
90    real(kind=DP), save :: defaultCutoff2 = 0.0_DP
91    logical, save :: haveDefaultCutoff = .false.
92    real(kind=DP), save :: dampingAlpha = 0.0_DP
93 +  real(kind=DP), save :: alpha2 = 0.0_DP
94 +  real(kind=DP), save :: alpha4 = 0.0_DP
95 +  real(kind=DP), save :: alpha6 = 0.0_DP
96 +  real(kind=DP), save :: alpha8 = 0.0_DP
97    logical, save :: haveDampingAlpha = .false.
98    real(kind=DP), save :: dielectric = 1.0_DP
99    logical, save :: haveDielectric = .false.
89  real(kind=DP), save :: constERFC = 0.0_DP
100    real(kind=DP), save :: constEXP = 0.0_DP
101    real(kind=dp), save :: rcuti = 0.0_DP
102    real(kind=dp), save :: rcuti2 = 0.0_DP
# Line 99 | Line 109 | module electrostatic_module
109    real(kind=dp), save :: rrfsq = 1.0_DP
110    real(kind=dp), save :: preRF = 0.0_DP
111    real(kind=dp), save :: preRF2 = 0.0_DP
112 <
113 < #ifdef __IFC
112 >  real(kind=dp), save :: erfcVal = 1.0_DP
113 >  real(kind=dp), save :: derfcVal = 0.0_DP
114 >  type(cubicSpline), save :: erfcSpline
115 >  logical, save :: haveElectroSpline = .false.
116 >  real(kind=dp), save :: c1 = 1.0_DP
117 >  real(kind=dp), save :: c2 = 1.0_DP
118 >  real(kind=dp), save :: c3 = 0.0_DP
119 >  real(kind=dp), save :: c4 = 0.0_DP
120 >  real(kind=dp), save :: c5 = 0.0_DP
121 >  real(kind=dp), save :: c6 = 0.0_DP
122 >  real(kind=dp), save :: c1c = 1.0_DP
123 >  real(kind=dp), save :: c2c = 1.0_DP
124 >  real(kind=dp), save :: c3c = 0.0_DP
125 >  real(kind=dp), save :: c4c = 0.0_DP
126 >  real(kind=dp), save :: c5c = 0.0_DP
127 >  real(kind=dp), save :: c6c = 0.0_DP
128 >  real(kind=dp), save :: one_third = 1.0_DP / 3.0_DP
129 >
130 > #if defined(__IFC) || defined(__PGI)
131   ! error function for ifc version > 7.
132 <  double precision, external :: derfc
132 >  real(kind=dp), external :: erfc
133   #endif
134    
135    public :: setElectrostaticSummationMethod
# Line 110 | Line 137 | module electrostatic_module
137    public :: setElectrostaticCutoffRadius
138    public :: setDampingAlpha
139    public :: setReactionFieldDielectric
140 +  public :: buildElectroSpline
141    public :: newElectrostaticType
142    public :: setCharge
143    public :: setDipoleMoment
# Line 122 | Line 150 | module electrostatic_module
150    public :: self_self
151    public :: rf_self_excludes
152  
153 +
154    type :: Electrostatic
155       integer :: c_ident
156       logical :: is_Charge = .false.
# Line 137 | Line 166 | contains
166  
167    type(Electrostatic), dimension(:), allocatable :: ElectrostaticMap
168  
169 +  logical, save :: hasElectrostaticMap
170 +
171   contains
172  
173    subroutine setElectrostaticSummationMethod(the_ESM)
# Line 159 | Line 190 | contains
190      real(kind=dp), intent(in) :: thisRcut
191      real(kind=dp), intent(in) :: thisRsw
192      defaultCutoff = thisRcut
193 +    defaultCutoff2 = defaultCutoff*defaultCutoff
194      rrf = defaultCutoff
195      rt = thisRsw
196      haveDefaultCutoff = .true.
# Line 167 | Line 199 | contains
199    subroutine setDampingAlpha(thisAlpha)
200      real(kind=dp), intent(in) :: thisAlpha
201      dampingAlpha = thisAlpha
202 +    alpha2 = dampingAlpha*dampingAlpha
203 +    alpha4 = alpha2*alpha2
204 +    alpha6 = alpha4*alpha2
205 +    alpha8 = alpha4*alpha4
206      haveDampingAlpha = .true.
207    end subroutine setDampingAlpha
208    
# Line 175 | Line 211 | contains
211      dielectric = thisDielectric
212      haveDielectric = .true.
213    end subroutine setReactionFieldDielectric
214 +
215 +  subroutine buildElectroSpline()
216 +    real( kind = dp ), dimension(np) :: xvals, yvals
217 +    real( kind = dp ) :: dx, rmin, rval
218 +    integer :: i
219 +
220 +    rmin = 0.0_dp
221 +
222 +    dx = (defaultCutoff-rmin) / dble(np-1)
223 +    
224 +    do i = 1, np
225 +       rval = rmin + dble(i-1)*dx
226 +       xvals(i) = rval
227 +       yvals(i) = erfc(dampingAlpha*rval)
228 +    enddo
229 +
230 +    call newSpline(erfcSpline, xvals, yvals, .true.)
231 +
232 +    haveElectroSpline = .true.
233 +  end subroutine buildElectroSpline
234  
235    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
236         is_SplitDipole, is_Quadrupole, is_Tap, status)
# Line 203 | Line 259 | contains
259            return
260         end if
261  
262 <       if (.not. allocated(ElectrostaticMap)) then
207 <          allocate(ElectrostaticMap(nAtypes))
208 <       endif
262 >       allocate(ElectrostaticMap(nAtypes))
263  
264      end if
265  
# Line 223 | Line 277 | contains
277      ElectrostaticMap(myATID)%is_Quadrupole = is_Quadrupole
278      ElectrostaticMap(myATID)%is_Tap = is_Tap
279  
280 +    hasElectrostaticMap = .true.
281 +
282    end subroutine newElectrostaticType
283  
284    subroutine setCharge(c_ident, charge, status)
# Line 234 | Line 290 | contains
290      status = 0
291      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
292  
293 <    if (.not.allocated(ElectrostaticMap)) then
293 >    if (.not.hasElectrostaticMap) then
294         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setCharge!")
295         status = -1
296         return
# Line 264 | Line 320 | contains
320      status = 0
321      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
322  
323 <    if (.not.allocated(ElectrostaticMap)) then
323 >    if (.not.hasElectrostaticMap) then
324         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setDipoleMoment!")
325         status = -1
326         return
# Line 294 | Line 350 | contains
350      status = 0
351      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
352  
353 <    if (.not.allocated(ElectrostaticMap)) then
353 >    if (.not.hasElectrostaticMap) then
354         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setSplitDipoleDistance!")
355         status = -1
356         return
# Line 324 | Line 380 | contains
380      status = 0
381      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
382  
383 <    if (.not.allocated(ElectrostaticMap)) then
383 >    if (.not.hasElectrostaticMap) then
384         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setQuadrupoleMoments!")
385         status = -1
386         return
# Line 355 | Line 411 | contains
411      integer :: localError
412      real(kind=dp) :: c
413  
414 <    if (.not.allocated(ElectrostaticMap)) then
414 >    if (.not.hasElectrostaticMap) then
415         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getCharge!")
416         return
417      end if
# Line 373 | Line 429 | contains
429      integer :: localError
430      real(kind=dp) :: dm
431  
432 <    if (.not.allocated(ElectrostaticMap)) then
432 >    if (.not.hasElectrostaticMap) then
433         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getDipoleMoment!")
434         return
435      end if
# Line 392 | Line 448 | contains
448         call handleError("checkSummationMethod", "no Default Cutoff set!")
449      endif
450  
451 <    rcuti = 1.0d0 / defaultCutoff
451 >    rcuti = 1.0_dp / defaultCutoff
452      rcuti2 = rcuti*rcuti
453      rcuti3 = rcuti2*rcuti
454      rcuti4 = rcuti2*rcuti2
# Line 406 | Line 462 | contains
462            call handleError("checkSummationMethod", "no Default Cutoff set!")
463         endif
464  
465 <       constEXP = exp(-dampingAlpha*dampingAlpha*defaultCutoff*defaultCutoff)
466 <       constERFC = derfc(dampingAlpha*defaultCutoff)
467 <       invRootPi = 0.56418958354775628695d0
468 <       alphaPi = 2*dampingAlpha*invRootPi
469 <      
465 >       constEXP = exp(-alpha2*defaultCutoff2)
466 >       invRootPi = 0.56418958354775628695_dp
467 >       alphaPi = 2.0_dp*dampingAlpha*invRootPi
468 >
469 >       c1c = erfc(dampingAlpha*defaultCutoff) * rcuti
470 >       c2c = alphaPi*constEXP*rcuti + c1c*rcuti
471 >       c3c = 2.0_dp*alphaPi*alpha2 + 3.0_dp*c2c*rcuti
472 >       c4c = 4.0_dp*alphaPi*alpha4 + 5.0_dp*c3c*rcuti2
473 >       c5c = 8.0_dp*alphaPi*alpha6 + 7.0_dp*c4c*rcuti2
474 >       c6c = 16.0_dp*alphaPi*alpha8 + 9.0_dp*c5c*rcuti2
475 >    else
476 >       c1c = rcuti
477 >       c2c = c1c*rcuti
478 >       c3c = 3.0_dp*c2c*rcuti
479 >       c4c = 5.0_dp*c3c*rcuti2
480 >       c5c = 7.0_dp*c4c*rcuti2
481 >       c6c = 9.0_dp*c5c*rcuti2
482      endif
483  
484      if (summationMethod .eq. REACTION_FIELD) then
485         if (haveDielectric) then
486            defaultCutoff2 = defaultCutoff*defaultCutoff
487 <          preRF = (dielectric-1.0d0) / &
488 <               ((2.0d0*dielectric+1.0d0)*defaultCutoff2*defaultCutoff)
489 <          preRF2 = 2.0d0*preRF
487 >          preRF = (dielectric-1.0_dp) / &
488 >               ((2.0_dp*dielectric+1.0_dp)*defaultCutoff2*defaultCutoff)
489 >          preRF2 = 2.0_dp*preRF
490         else
491            call handleError("checkSummationMethod", "Dielectric not set")
492         endif
493        
494      endif
495  
496 +    if (.not.haveElectroSpline) then
497 +       call buildElectroSpline()
498 +    end if
499 +
500      summationMethodChecked = .true.
501    end subroutine checkSummationMethod
502  
431 !!$
432 !!$  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
433 !!$       vpair, fpair, pot, eFrame, f, t, do_pot)
434  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
435       vpair, fpair, pot, eFrame, f, t, do_pot, fstrs)
503  
504 +  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, rcut, sw, &
505 +       vpair, fpair, pot, eFrame, f, t, do_pot)
506 +
507      logical, intent(in) :: do_pot
508  
509      integer, intent(in) :: atom1, atom2
510      integer :: localError
511  
512 <    real(kind=dp), intent(in) :: rij, r2, sw
512 >    real(kind=dp), intent(in) :: rij, r2, sw, rcut
513      real(kind=dp), intent(in), dimension(3) :: d
514      real(kind=dp), intent(inout) :: vpair
515      real(kind=dp), intent(inout), dimension(3) :: fpair    
446    real(kind=dp), intent(inout), dimension(3) :: fstrs
516  
517      real( kind = dp ) :: pot
518      real( kind = dp ), dimension(9,nLocal) :: eFrame
# Line 466 | Line 535 | contains
535      real (kind=dp) :: cx_i, cy_i, cz_i
536      real (kind=dp) :: cx_j, cy_j, cz_j
537      real (kind=dp) :: cx2, cy2, cz2
538 <    real (kind=dp) :: ct_i, ct_j, ct_ij, a1
538 >    real (kind=dp) :: ct_i, ct_j, ct_ij, a0, a1
539      real (kind=dp) :: riji, ri, ri2, ri3, ri4
540      real (kind=dp) :: pref, vterm, epot, dudr, vterm1, vterm2
541      real (kind=dp) :: xhat, yhat, zhat
542      real (kind=dp) :: dudx, dudy, dudz
543      real (kind=dp) :: scale, sc2, bigR
544 <    real (kind=dp) :: varERFC, varEXP
545 <    real (kind=dp) :: limScale
544 >    real (kind=dp) :: varEXP
545 >    real (kind=dp) :: pot_term
546      real (kind=dp) :: preVal, rfVal
547 +    real (kind=dp) :: c2ri, c3ri, c4rij
548 +    real (kind=dp) :: cti3, ctj3, ctidotj
549 +    real (kind=dp) :: preSw, preSwSc
550 +    real (kind=dp) :: xhatdot2, yhatdot2, zhatdot2
551 +    real (kind=dp) :: xhatc4, yhatc4, zhatc4
552  
479    if (.not.allocated(ElectrostaticMap)) then
480       call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
481       return
482    end if
483
553      if (.not.summationMethodChecked) then
554         call checkSummationMethod()
555      endif
# Line 493 | Line 562 | contains
562      me2 = atid(atom2)
563   #endif
564  
496 !!$    if (rij .ge. defaultCutoff) then
497 !!$       write(*,*) 'warning: rij = ', rij, ' rcut = ', defaultCutoff, ' sw = ', sw
498 !!$    endif
499
565      !! some variables we'll need independent of electrostatic type:
566  
567 <    riji = 1.0d0 / rij
567 >    riji = 1.0_dp / rij
568    
569      xhat = d(1) * riji
570      yhat = d(2) * riji
# Line 538 | Line 603 | contains
603         if (i_is_SplitDipole) then
604            d_i = ElectrostaticMap(me1)%split_dipole_distance
605         endif
606 <
606 >       duduz_i = zero
607      endif
608  
609      if (i_is_Quadrupole) then
# Line 569 | Line 634 | contains
634         cx_i = ux_i(1)*xhat + ux_i(2)*yhat + ux_i(3)*zhat
635         cy_i = uy_i(1)*xhat + uy_i(2)*yhat + uy_i(3)*zhat
636         cz_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
637 +       dudux_i = zero
638 +       duduy_i = zero
639 +       duduz_i = zero
640      endif
641  
642      if (j_is_Charge) then
# Line 591 | Line 659 | contains
659         if (j_is_SplitDipole) then
660            d_j = ElectrostaticMap(me2)%split_dipole_distance
661         endif
662 +       duduz_j = zero
663      endif
664  
665      if (j_is_Quadrupole) then
# Line 621 | Line 690 | contains
690         cx_j = ux_j(1)*xhat + ux_j(2)*yhat + ux_j(3)*zhat
691         cy_j = uy_j(1)*xhat + uy_j(2)*yhat + uy_j(3)*zhat
692         cz_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
693 +       dudux_j = zero
694 +       duduy_j = zero
695 +       duduz_j = zero
696      endif
697    
698 <    epot = 0.0_dp
699 <    dudx = 0.0_dp
700 <    dudy = 0.0_dp
701 <    dudz = 0.0_dp
698 >    epot = zero
699 >    dudx = zero
700 >    dudy = zero
701 >    dudz = zero  
702  
631    dudux_i = 0.0_dp
632    duduy_i = 0.0_dp
633    duduz_i = 0.0_dp
634
635    dudux_j = 0.0_dp
636    duduy_j = 0.0_dp
637    duduz_j = 0.0_dp
638
703      if (i_is_Charge) then
704  
705         if (j_is_Charge) then
706 +          if (screeningMethod .eq. DAMPED) then
707 +             ! assemble the damping variables
708 +             call lookupUniformSpline1d(erfcSpline, rij, erfcVal, derfcVal)
709 +             c1 = erfcVal*riji
710 +             c2 = (-derfcVal + c1)*riji
711 +          else
712 +             c1 = riji
713 +             c2 = c1*riji
714 +          endif
715  
716 <          if (summationMethod .eq. SHIFTED_POTENTIAL) then
716 >          preVal = pre11 * q_i * q_j
717  
718 <             vterm = pre11 * q_i * q_j * (riji - rcuti)
719 <             vpair = vpair + vterm
647 <             epot = epot + sw*vterm
718 >          if (summationMethod .eq. SHIFTED_POTENTIAL) then
719 >             vterm = preVal * (c1 - c1c)
720              
721 <             dudr  = -sw*pre11*q_i*q_j * (riji*riji)
722 <            
651 <             dudx = dudx + dudr * xhat
652 <             dudy = dudy + dudr * yhat
653 <             dudz = dudz + dudr * zhat
654 <
655 < !!$          elseif (summationMethod .eq. DAMPED_WOLF) then
656 < !!$             varERFC = derfc(dampingAlpha*rij)
657 < !!$             varEXP = exp(-dampingAlpha*dampingAlpha*rij*rij)
658 < !!$             vterm = pre11 * q_i * q_j * (varERFC*riji - constERFC*rcuti)
659 < !!$             vpair = vpair + vterm
660 < !!$             epot = epot + sw*vterm
661 < !!$            
662 < !!$!             dudr  = -sw*pre11*q_i*q_j * (((varERFC*riji*riji &
663 < !!$!                  + alphaPi*varEXP*riji) - (constERFC*rcuti2 &
664 < !!$!                  + alphaPi*constEXP*rcuti)) )
665 < !!$             dudr  = -sw*pre11*q_i*q_j * (varERFC*riji*riji &
666 < !!$                  + alphaPi*varEXP*riji)
667 < !!$            
668 < !!$             dudx = dudx + dudr * xhat
669 < !!$             dudy = dudy + dudr * yhat
670 < !!$             dudz = dudz + dudr * zhat
671 <
721 >             dudr  = -sw * preVal * c2
722 >  
723            elseif (summationMethod .eq. SHIFTED_FORCE) then
724 <             vterm = pre11 * q_i * q_j * (riji + rij*rcuti2 - 2.0d0*rcuti)
674 <             vpair = vpair + vterm
675 <             epot = epot + sw*vterm
724 >             vterm = preVal * ( c1 - c1c + c2c*(rij - defaultCutoff) )
725              
726 <             dudr  = -sw*pre11*q_i*q_j * (riji*riji-rcuti2)
727 <                          
679 <             dudx = dudx + dudr * xhat
680 <             dudy = dudy + dudr * yhat
681 <             dudz = dudz + dudr * zhat
682 <
683 < !!$          elseif (summationMethod .eq. DAMPED_SHIFTED_FORCE) then
684 < !!$             varERFC = derfc(dampingAlpha*rij)
685 < !!$             varEXP = exp(-dampingAlpha*dampingAlpha*rij*rij)
686 < !!$             vterm = pre11 * q_i * q_j * (varERFC*riji - constERFC*rcuti)
687 < !!$             vpair = vpair + vterm
688 < !!$             epot = epot + sw*vterm
689 < !!$            
690 < !!$!             dudr  = -sw*pre11*q_i*q_j * (((varERFC*riji*riji &
691 < !!$!                  + alphaPi*varEXP*riji) - (constERFC*rcuti2 &
692 < !!$!                  + alphaPi*constEXP*rcuti)) )
693 < !!$             dudr  = -sw*pre11*q_i*q_j * (varERFC*riji*riji &
694 < !!$                  + alphaPi*varEXP*riji)
695 < !!$            
696 < !!$             dudx = dudx + dudr * xhat
697 < !!$             dudy = dudy + dudr * yhat
698 < !!$             dudz = dudz + dudr * zhat
699 <
726 >             dudr  = sw * preVal * (c2c - c2)
727 >  
728            elseif (summationMethod .eq. REACTION_FIELD) then
701             preVal = pre11 * q_i * q_j
729               rfVal = preRF*rij*rij
730               vterm = preVal * ( riji + rfVal )
731              
732 <             vpair = vpair + vterm
733 <             epot = epot + sw*vterm
707 <            
708 <             dudr  = sw * preVal * ( 2.0d0*rfVal - riji )*riji
709 <            
710 <             dudx = dudx + dudr * xhat
711 <             dudy = dudy + dudr * yhat
712 <             dudz = dudz + dudr * zhat
713 <
732 >             dudr  = sw * preVal * ( 2.0_dp*rfVal - riji )*riji
733 >  
734            else
735 <             vterm = pre11 * q_i * q_j * riji
716 <             vpair = vpair + vterm
717 <             epot = epot + sw*vterm
735 >             vterm = preVal * riji*erfcVal
736              
737 <             dudr  = - sw * vterm * riji
738 <            
721 <             dudx = dudx + dudr * xhat
722 <             dudy = dudy + dudr * yhat
723 <             dudz = dudz + dudr * zhat
724 <
737 >             dudr  = - sw * preVal * c2
738 >  
739            endif
740  
741 +          vpair = vpair + vterm
742 +          epot = epot + sw*vterm
743 +
744 +          dudx = dudx + dudr * xhat
745 +          dudy = dudy + dudr * yhat
746 +          dudz = dudz + dudr * zhat
747 +
748         endif
749  
750         if (j_is_Dipole) then
751 <
751 >          ! pref is used by all the possible methods
752            pref = pre12 * q_i * mu_j
753 +          preSw = sw*pref
754  
733 !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
734 !!$             ri2 = riji * riji
735 !!$             ri3 = ri2 * riji
736 !!$
737 !!$             pref = pre12 * q_i * mu_j
738 !!$             vterm = - pref * ct_j * (ri2 - rcuti2)
739 !!$             vpair = vpair + vterm
740 !!$             epot = epot + sw*vterm
741 !!$            
742 !!$             !! this has a + sign in the () because the rij vector is
743 !!$             !! r_j - r_i and the charge-dipole potential takes the origin
744 !!$             !! as the point dipole, which is atom j in this case.
745 !!$            
746 !!$             dudx = dudx - sw*pref * ( ri3*( uz_j(1) - 3.0d0*ct_j*xhat) &
747 !!$                  - rcuti3*( uz_j(1) - 3.0d0*ct_j*d(1)*rcuti ) )
748 !!$             dudy = dudy - sw*pref * ( ri3*( uz_j(2) - 3.0d0*ct_j*yhat) &
749 !!$                  - rcuti3*( uz_j(2) - 3.0d0*ct_j*d(2)*rcuti ) )
750 !!$             dudz = dudz - sw*pref * ( ri3*( uz_j(3) - 3.0d0*ct_j*zhat) &
751 !!$                  - rcuti3*( uz_j(3) - 3.0d0*ct_j*d(3)*rcuti ) )
752 !!$            
753 !!$             duduz_j(1) = duduz_j(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
754 !!$             duduz_j(2) = duduz_j(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
755 !!$             duduz_j(3) = duduz_j(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
756 !!$
757 !!$          elseif (summationMethod .eq. REACTION_FIELD) then
758
755            if (summationMethod .eq. REACTION_FIELD) then
756               ri2 = riji * riji
757               ri3 = ri2 * riji
758      
763             pref = pre12 * q_i * mu_j
759               vterm = - pref * ct_j * ( ri2 - preRF2*rij )
760               vpair = vpair + vterm
761               epot = epot + sw*vterm
762              
763 <             !! this has a + sign in the () because the rij vector is
764 <             !! r_j - r_i and the charge-dipole potential takes the origin
765 <             !! as the point dipole, which is atom j in this case.
766 <            
767 <             dudx = dudx - sw*pref*( ri3*(uz_j(1) - 3.0d0*ct_j*xhat) - &
768 <                                     preRF2*uz_j(1) )
769 <             dudy = dudy - sw*pref*( ri3*(uz_j(2) - 3.0d0*ct_j*yhat) - &
770 <                                     preRF2*uz_j(2) )
771 <             dudz = dudz - sw*pref*( ri3*(uz_j(3) - 3.0d0*ct_j*zhat) - &
777 <                                     preRF2*uz_j(3) )        
778 <             duduz_j(1) = duduz_j(1) - sw*pref * xhat * ( ri2 - preRF2*rij )
779 <             duduz_j(2) = duduz_j(2) - sw*pref * yhat * ( ri2 - preRF2*rij )
780 <             duduz_j(3) = duduz_j(3) - sw*pref * zhat * ( ri2 - preRF2*rij )
763 >             dudx = dudx - preSw*( ri3*(uz_j(1) - 3.0_dp*ct_j*xhat) - &
764 >                  preRF2*uz_j(1) )
765 >             dudy = dudy - preSw*( ri3*(uz_j(2) - 3.0_dp*ct_j*yhat) - &
766 >                  preRF2*uz_j(2) )
767 >             dudz = dudz - preSw*( ri3*(uz_j(3) - 3.0_dp*ct_j*zhat) - &
768 >                  preRF2*uz_j(3) )        
769 >             duduz_j(1) = duduz_j(1) - preSw * xhat * ( ri2 - preRF2*rij )
770 >             duduz_j(2) = duduz_j(2) - preSw * yhat * ( ri2 - preRF2*rij )
771 >             duduz_j(3) = duduz_j(3) - preSw * zhat * ( ri2 - preRF2*rij )
772  
773            else
774 +             ! determine the inverse r used if we have split dipoles
775               if (j_is_SplitDipole) then
776                  BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
777                  ri = 1.0_dp / BigR
# Line 788 | Line 780 | contains
780                  ri = riji
781                  scale = 1.0_dp
782               endif
783 <            
792 <             ri2 = ri * ri
793 <             ri3 = ri2 * ri
783 >
784               sc2 = scale * scale
785  
786 <             pref = pre12 * q_i * mu_j
787 <             vterm = - pref * ct_j * ri2 * scale
786 >             if (screeningMethod .eq. DAMPED) then
787 >                ! assemble the damping variables
788 >                call lookupUniformSpline1d(erfcSpline, rij, erfcVal, derfcVal)
789 >                c1 = erfcVal*ri
790 >                c2 = (-derfcVal + c1)*ri
791 >                c3 = -2.0_dp*derfcVal*alpha2 + 3.0_dp*c2*ri
792 >             else
793 >                c1 = ri
794 >                c2 = c1*ri
795 >                c3 = 3.0_dp*c2*ri
796 >             endif
797 >            
798 >             c2ri = c2*ri
799 >
800 >             ! calculate the potential
801 >             pot_term =  scale * c2
802 >             vterm = -pref * ct_j * pot_term
803               vpair = vpair + vterm
804               epot = epot + sw*vterm
805              
806 <             !! this has a + sign in the () because the rij vector is
807 <             !! r_j - r_i and the charge-dipole potential takes the origin
808 <             !! as the point dipole, which is atom j in this case.
809 <            
810 <             dudx = dudx - sw*pref * ri3 * ( uz_j(1) - 3.0d0*ct_j*xhat*sc2)
811 <             dudy = dudy - sw*pref * ri3 * ( uz_j(2) - 3.0d0*ct_j*yhat*sc2)
812 <             dudz = dudz - sw*pref * ri3 * ( uz_j(3) - 3.0d0*ct_j*zhat*sc2)
813 <            
809 <             duduz_j(1) = duduz_j(1) - sw*pref * ri2 * xhat * scale
810 <             duduz_j(2) = duduz_j(2) - sw*pref * ri2 * yhat * scale
811 <             duduz_j(3) = duduz_j(3) - sw*pref * ri2 * zhat * scale
806 >             ! calculate derivatives for forces and torques
807 >             dudx = dudx - preSw*( uz_j(1)*c2ri - ct_j*xhat*sc2*c3 )
808 >             dudy = dudy - preSw*( uz_j(2)*c2ri - ct_j*yhat*sc2*c3 )
809 >             dudz = dudz - preSw*( uz_j(3)*c2ri - ct_j*zhat*sc2*c3 )
810 >                          
811 >             duduz_j(1) = duduz_j(1) - preSw * pot_term * xhat
812 >             duduz_j(2) = duduz_j(2) - preSw * pot_term * yhat
813 >             duduz_j(3) = duduz_j(3) - preSw * pot_term * zhat
814  
815            endif
816         endif
817  
818         if (j_is_Quadrupole) then
819 <          ri2 = riji * riji
818 <          ri3 = ri2 * riji
819 <          ri4 = ri2 * ri2
819 >          ! first precalculate some necessary variables
820            cx2 = cx_j * cx_j
821            cy2 = cy_j * cy_j
822            cz2 = cz_j * cz_j
823 +          pref =  pre14 * q_i * one_third
824 +          
825 +          if (screeningMethod .eq. DAMPED) then
826 +             ! assemble the damping variables
827 +             call lookupUniformSpline1d(erfcSpline, rij, erfcVal, derfcVal)
828 +             c1 = erfcVal*riji
829 +             c2 = (-derfcVal + c1)*riji
830 +             c3 = -2.0_dp*derfcVal*alpha2 + 3.0_dp*c2*riji
831 +             c4 = -4.0_dp*derfcVal*alpha4 + 5.0_dp*c3*riji*riji
832 +          else
833 +             c1 = riji
834 +             c2 = c1*riji
835 +             c3 = 3.0_dp*c2*riji
836 +             c4 = 5.0_dp*c3*riji*riji
837 +          endif
838  
839 < !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
840 < !!$             pref =  pre14 * q_i / 3.0_dp
841 < !!$             vterm1 = pref * ri3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
842 < !!$                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
843 < !!$                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
844 < !!$             vterm2 = pref * rcuti3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
845 < !!$                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
846 < !!$                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
847 < !!$             vpair = vpair + ( vterm1 - vterm2 )
848 < !!$             epot = epot + sw*( vterm1 - vterm2 )
849 < !!$            
850 < !!$             dudx = dudx - (5.0_dp * &
851 < !!$                  (vterm1*riji*xhat - vterm2*rcuti2*d(1))) + sw*pref * ( &
852 < !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(1)) - &
853 < !!$                  qxx_j*2.0_dp*(xhat - rcuti*d(1))) + &
854 < !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(1)) - &
855 < !!$                  qyy_j*2.0_dp*(xhat - rcuti*d(1))) + &
856 < !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(1)) - &
857 < !!$                  qzz_j*2.0_dp*(xhat - rcuti*d(1))) )
858 < !!$             dudy = dudy - (5.0_dp * &
859 < !!$                  (vterm1*riji*yhat - vterm2*rcuti2*d(2))) + sw*pref * ( &
860 < !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(2)) - &
861 < !!$                  qxx_j*2.0_dp*(yhat - rcuti*d(2))) + &
862 < !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(2)) - &
863 < !!$                  qyy_j*2.0_dp*(yhat - rcuti*d(2))) + &
864 < !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(2)) - &
865 < !!$                  qzz_j*2.0_dp*(yhat - rcuti*d(2))) )
866 < !!$             dudz = dudz - (5.0_dp * &
867 < !!$                  (vterm1*riji*zhat - vterm2*rcuti2*d(3))) + sw*pref * ( &
868 < !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(3)) - &
869 < !!$                  qxx_j*2.0_dp*(zhat - rcuti*d(3))) + &
870 < !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(3)) - &
856 < !!$                  qyy_j*2.0_dp*(zhat - rcuti*d(3))) + &
857 < !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(3)) - &
858 < !!$                  qzz_j*2.0_dp*(zhat - rcuti*d(3))) )
859 < !!$            
860 < !!$             dudux_j(1) = dudux_j(1) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*xhat) -&
861 < !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(1)))
862 < !!$             dudux_j(2) = dudux_j(2) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*yhat) -&
863 < !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(2)))
864 < !!$             dudux_j(3) = dudux_j(3) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*zhat) -&
865 < !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(3)))
866 < !!$            
867 < !!$             duduy_j(1) = duduy_j(1) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*xhat) -&
868 < !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(1)))
869 < !!$             duduy_j(2) = duduy_j(2) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*yhat) -&
870 < !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(2)))
871 < !!$             duduy_j(3) = duduy_j(3) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*zhat) -&
872 < !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(3)))
873 < !!$            
874 < !!$             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*xhat) -&
875 < !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(1)))
876 < !!$             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*yhat) -&
877 < !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(2)))
878 < !!$             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*zhat) -&
879 < !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(3)))
880 < !!$        
881 < !!$          else
882 <             pref =  pre14 * q_i / 3.0_dp
883 <             vterm = pref * ri3 * (qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
884 <                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
885 <                  qzz_j * (3.0_dp*cz2 - 1.0_dp))
886 <             vpair = vpair + vterm
887 <             epot = epot + sw*vterm
888 <            
889 <             dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref * ri4 * ( &
890 <                  qxx_j*(6.0_dp*cx_j*ux_j(1) - 2.0_dp*xhat) + &
891 <                  qyy_j*(6.0_dp*cy_j*uy_j(1) - 2.0_dp*xhat) + &
892 <                  qzz_j*(6.0_dp*cz_j*uz_j(1) - 2.0_dp*xhat) )
893 <             dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref * ri4 * ( &
894 <                  qxx_j*(6.0_dp*cx_j*ux_j(2) - 2.0_dp*yhat) + &
895 <                  qyy_j*(6.0_dp*cy_j*uy_j(2) - 2.0_dp*yhat) + &
896 <                  qzz_j*(6.0_dp*cz_j*uz_j(2) - 2.0_dp*yhat) )
897 <             dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref * ri4 * ( &
898 <                  qxx_j*(6.0_dp*cx_j*ux_j(3) - 2.0_dp*zhat) + &
899 <                  qyy_j*(6.0_dp*cy_j*uy_j(3) - 2.0_dp*zhat) + &
900 <                  qzz_j*(6.0_dp*cz_j*uz_j(3) - 2.0_dp*zhat) )
901 <            
902 <             dudux_j(1) = dudux_j(1) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*xhat)
903 <             dudux_j(2) = dudux_j(2) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*yhat)
904 <             dudux_j(3) = dudux_j(3) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*zhat)
905 <            
906 <             duduy_j(1) = duduy_j(1) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*xhat)
907 <             duduy_j(2) = duduy_j(2) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*yhat)
908 <             duduy_j(3) = duduy_j(3) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*zhat)
909 <            
910 <             duduz_j(1) = duduz_j(1) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*xhat)
911 <             duduz_j(2) = duduz_j(2) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*yhat)
912 <             duduz_j(3) = duduz_j(3) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*zhat)
839 >          ! precompute variables for convenience
840 >          preSw = sw*pref
841 >          c2ri = c2*riji
842 >          c3ri = c3*riji
843 >          c4rij = c4*rij
844 >          xhatdot2 = 2.0_dp*xhat*c3
845 >          yhatdot2 = 2.0_dp*yhat*c3
846 >          zhatdot2 = 2.0_dp*zhat*c3
847 >          xhatc4 = xhat*c4rij
848 >          yhatc4 = yhat*c4rij
849 >          zhatc4 = zhat*c4rij
850 >
851 >          ! calculate the potential
852 >          pot_term = ( qxx_j*(cx2*c3 - c2ri) + qyy_j*(cy2*c3 - c2ri) + &
853 >               qzz_j*(cz2*c3 - c2ri) )
854 >          vterm = pref * pot_term
855 >          vpair = vpair + vterm
856 >          epot = epot + sw*vterm
857 >
858 >          ! calculate derivatives for the forces and torques
859 >          dudx = dudx - preSw * ( &
860 >               qxx_j*(cx2*xhatc4 - (2.0_dp*cx_j*ux_j(1) + xhat)*c3ri) + &
861 >               qyy_j*(cy2*xhatc4 - (2.0_dp*cy_j*uy_j(1) + xhat)*c3ri) + &
862 >               qzz_j*(cz2*xhatc4 - (2.0_dp*cz_j*uz_j(1) + xhat)*c3ri) )
863 >          dudy = dudy - preSw * ( &
864 >               qxx_j*(cx2*yhatc4 - (2.0_dp*cx_j*ux_j(2) + yhat)*c3ri) + &
865 >               qyy_j*(cy2*yhatc4 - (2.0_dp*cy_j*uy_j(2) + yhat)*c3ri) + &
866 >               qzz_j*(cz2*yhatc4 - (2.0_dp*cz_j*uz_j(2) + yhat)*c3ri) )
867 >          dudz = dudz - preSw * ( &
868 >               qxx_j*(cx2*zhatc4 - (2.0_dp*cx_j*ux_j(3) + zhat)*c3ri) + &
869 >               qyy_j*(cy2*zhatc4 - (2.0_dp*cy_j*uy_j(3) + zhat)*c3ri) + &
870 >               qzz_j*(cz2*zhatc4 - (2.0_dp*cz_j*uz_j(3) + zhat)*c3ri) )
871            
872 < !!$          endif
872 >          dudux_j(1) = dudux_j(1) + preSw*(qxx_j*cx_j*xhatdot2)
873 >          dudux_j(2) = dudux_j(2) + preSw*(qxx_j*cx_j*yhatdot2)
874 >          dudux_j(3) = dudux_j(3) + preSw*(qxx_j*cx_j*zhatdot2)
875 >          
876 >          duduy_j(1) = duduy_j(1) + preSw*(qyy_j*cy_j*xhatdot2)
877 >          duduy_j(2) = duduy_j(2) + preSw*(qyy_j*cy_j*yhatdot2)
878 >          duduy_j(3) = duduy_j(3) + preSw*(qyy_j*cy_j*zhatdot2)
879 >          
880 >          duduz_j(1) = duduz_j(1) + preSw*(qzz_j*cz_j*xhatdot2)
881 >          duduz_j(2) = duduz_j(2) + preSw*(qzz_j*cz_j*yhatdot2)
882 >          duduz_j(3) = duduz_j(3) + preSw*(qzz_j*cz_j*zhatdot2)
883 >
884 >          
885         endif
886      endif
887 <
887 >    
888      if (i_is_Dipole) then
889  
890         if (j_is_Charge) then
891 <          
892 <          pref = pre12 * q_j * mu_i
893 <          
894 < !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
925 < !!$             ri2 = riji * riji
926 < !!$             ri3 = ri2 * riji
927 < !!$
928 < !!$             pref = pre12 * q_j * mu_i
929 < !!$             vterm = pref * ct_i * (ri2 - rcuti2)
930 < !!$             vpair = vpair + vterm
931 < !!$             epot = epot + sw*vterm
932 < !!$            
933 < !!$             dudx = dudx + sw*pref * ( ri3*( uz_i(1) - 3.0d0*ct_i*xhat) &
934 < !!$                  - rcuti3*( uz_i(1) - 3.0d0*ct_i*d(1)*rcuti ) )
935 < !!$             dudy = dudy + sw*pref * ( ri3*( uz_i(2) - 3.0d0*ct_i*yhat) &
936 < !!$                  - rcuti3*( uz_i(2) - 3.0d0*ct_i*d(2)*rcuti ) )
937 < !!$             dudz = dudz + sw*pref * ( ri3*( uz_i(3) - 3.0d0*ct_i*zhat) &
938 < !!$                  - rcuti3*( uz_i(3) - 3.0d0*ct_i*d(3)*rcuti ) )
939 < !!$            
940 < !!$             duduz_i(1) = duduz_i(1) + sw*pref*( ri2*xhat - d(1)*rcuti3 )
941 < !!$             duduz_i(2) = duduz_i(2) + sw*pref*( ri2*yhat - d(2)*rcuti3 )
942 < !!$             duduz_i(3) = duduz_i(3) + sw*pref*( ri2*zhat - d(3)*rcuti3 )
943 < !!$
944 < !!$          elseif (summationMethod .eq. REACTION_FIELD) then
891 >          ! variables used by all the methods
892 >          pref = pre12 * q_j * mu_i                      
893 >          preSw = sw*pref
894 >
895            if (summationMethod .eq. REACTION_FIELD) then
896 +
897               ri2 = riji * riji
898               ri3 = ri2 * riji
899  
949             pref = pre12 * q_j * mu_i
900               vterm = pref * ct_i * ( ri2 - preRF2*rij )
901               vpair = vpair + vterm
902               epot = epot + sw*vterm
903              
904 <             dudx = dudx + sw*pref * ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat) - &
904 >             dudx = dudx + preSw * ( ri3*(uz_i(1) - 3.0_dp*ct_i*xhat) - &
905                    preRF2*uz_i(1) )
906 <             dudy = dudy + sw*pref * ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat) - &
906 >             dudy = dudy + preSw * ( ri3*(uz_i(2) - 3.0_dp*ct_i*yhat) - &
907                    preRF2*uz_i(2) )
908 <             dudz = dudz + sw*pref * ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat) - &
908 >             dudz = dudz + preSw * ( ri3*(uz_i(3) - 3.0_dp*ct_i*zhat) - &
909                    preRF2*uz_i(3) )
910              
911 <             duduz_i(1) = duduz_i(1) + sw*pref * xhat * ( ri2 - preRF2*rij )
912 <             duduz_i(2) = duduz_i(2) + sw*pref * yhat * ( ri2 - preRF2*rij )
913 <             duduz_i(3) = duduz_i(3) + sw*pref * zhat * ( ri2 - preRF2*rij )
911 >             duduz_i(1) = duduz_i(1) + preSw * xhat * ( ri2 - preRF2*rij )
912 >             duduz_i(2) = duduz_i(2) + preSw * yhat * ( ri2 - preRF2*rij )
913 >             duduz_i(3) = duduz_i(3) + preSw * zhat * ( ri2 - preRF2*rij )
914  
915            else
916 +             ! determine inverse r if we are using split dipoles
917               if (i_is_SplitDipole) then
918                  BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
919                  ri = 1.0_dp / BigR
# Line 971 | Line 922 | contains
922                  ri = riji
923                  scale = 1.0_dp
924               endif
925 <            
975 <             ri2 = ri * ri
976 <             ri3 = ri2 * ri
925 >
926               sc2 = scale * scale
927 +              
928 +             if (screeningMethod .eq. DAMPED) then
929 +                ! assemble the damping variables
930 +                call lookupUniformSpline1d(erfcSpline, rij, erfcVal, derfcVal)
931 +                c1 = erfcVal*ri
932 +                c2 = (-derfcVal + c1)*ri
933 +                c3 = -2.0_dp*derfcVal*alpha2 + 3.0_dp*c2*ri
934 +             else
935 +                c1 = ri
936 +                c2 = c1*ri
937 +                c3 = 3.0_dp*c2*ri
938 +             endif
939 +            
940 +             c2ri = c2*ri
941  
942 <             pref = pre12 * q_j * mu_i
943 <             vterm = pref * ct_i * ri2 * scale
942 >             ! calculate the potential
943 >             pot_term = c2 * scale
944 >             vterm = pref * ct_i * pot_term
945               vpair = vpair + vterm
946               epot = epot + sw*vterm
947 +
948 +             ! calculate derivatives for the forces and torques
949 +             dudx = dudx + preSw * ( uz_i(1)*c2ri - ct_i*xhat*sc2*c3 )
950 +             dudy = dudy + preSw * ( uz_i(2)*c2ri - ct_i*yhat*sc2*c3 )
951 +             dudz = dudz + preSw * ( uz_i(3)*c2ri - ct_i*zhat*sc2*c3 )
952 +
953 +             duduz_i(1) = duduz_i(1) + preSw * pot_term * xhat
954 +             duduz_i(2) = duduz_i(2) + preSw * pot_term * yhat
955 +             duduz_i(3) = duduz_i(3) + preSw * pot_term * zhat
956              
984             dudx = dudx + sw*pref * ri3 * ( uz_i(1) - 3.0d0 * ct_i * xhat*sc2)
985             dudy = dudy + sw*pref * ri3 * ( uz_i(2) - 3.0d0 * ct_i * yhat*sc2)
986             dudz = dudz + sw*pref * ri3 * ( uz_i(3) - 3.0d0 * ct_i * zhat*sc2)
987            
988             duduz_i(1) = duduz_i(1) + sw*pref * ri2 * xhat * scale
989             duduz_i(2) = duduz_i(2) + sw*pref * ri2 * yhat * scale
990             duduz_i(3) = duduz_i(3) + sw*pref * ri2 * zhat * scale
957            endif
958         endif
959        
960         if (j_is_Dipole) then
961 +          ! variables used by all methods
962 +          ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
963 +          pref = pre22 * mu_i * mu_j
964 +          preSw = sw*pref
965  
996 !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
997 !!$             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
998 !!$
999 !!$             ri2 = riji * riji
1000 !!$             ri3 = ri2 * riji
1001 !!$             ri4 = ri2 * ri2
1002 !!$
1003 !!$             pref = pre22 * mu_i * mu_j
1004 !!$             vterm = pref * (ri3 - rcuti3) * (ct_ij - 3.0d0 * ct_i * ct_j)
1005 !!$             vpair = vpair + vterm
1006 !!$             epot = epot + sw*vterm
1007 !!$            
1008 !!$             a1 = 5.0d0 * ct_i * ct_j - ct_ij
1009 !!$            
1010 !!$             dudx = dudx + sw*pref*3.0d0*( &
1011 !!$                  ri4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) &
1012 !!$                  - rcuti4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) )
1013 !!$             dudy = dudy + sw*pref*3.0d0*( &
1014 !!$                  ri4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) &
1015 !!$                  - rcuti4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) )
1016 !!$             dudz = dudz + sw*pref*3.0d0*( &
1017 !!$                  ri4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) &
1018 !!$                  - rcuti4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) )
1019 !!$            
1020 !!$             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1021 !!$                  - rcuti3*(uz_j(1) - 3.0d0*ct_j*xhat))
1022 !!$             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1023 !!$                  - rcuti3*(uz_j(2) - 3.0d0*ct_j*yhat))
1024 !!$             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1025 !!$                  - rcuti3*(uz_j(3) - 3.0d0*ct_j*zhat))
1026 !!$             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1027 !!$                  - rcuti3*(uz_i(1) - 3.0d0*ct_i*xhat))
1028 !!$             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1029 !!$                  - rcuti3*(uz_i(2) - 3.0d0*ct_i*yhat))
1030 !!$             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1031 !!$                  - rcuti3*(uz_i(3) - 3.0d0*ct_i*zhat))
1032 !!$          
1033 !!$          elseif (summationMethod .eq. DAMPED_WOLF) then
1034 !!$             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
1035 !!$            
1036 !!$             ri2 = riji * riji
1037 !!$             ri3 = ri2 * riji
1038 !!$             ri4 = ri2 * ri2
1039 !!$             sc2 = scale * scale
1040 !!$            
1041 !!$             pref = pre22 * mu_i * mu_j
1042 !!$             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j)
1043 !!$             vpair = vpair + vterm
1044 !!$             epot = epot + sw*vterm
1045 !!$            
1046 !!$             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
1047 !!$            
1048 !!$             dudx = dudx + sw*pref*3.0d0*ri4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1049 !!$             dudy = dudy + sw*pref*3.0d0*ri4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1050 !!$             dudz = dudz + sw*pref*3.0d0*ri4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1051 !!$            
1052 !!$             duduz_i(1) = duduz_i(1) + sw*pref*ri3 *(uz_j(1) - 3.0d0*ct_j*xhat)
1053 !!$             duduz_i(2) = duduz_i(2) + sw*pref*ri3 *(uz_j(2) - 3.0d0*ct_j*yhat)
1054 !!$             duduz_i(3) = duduz_i(3) + sw*pref*ri3 *(uz_j(3) - 3.0d0*ct_j*zhat)
1055 !!$            
1056 !!$             duduz_j(1) = duduz_j(1) + sw*pref*ri3 *(uz_i(1) - 3.0d0*ct_i*xhat)
1057 !!$             duduz_j(2) = duduz_j(2) + sw*pref*ri3 *(uz_i(2) - 3.0d0*ct_i*yhat)
1058 !!$             duduz_j(3) = duduz_j(3) + sw*pref*ri3 *(uz_i(3) - 3.0d0*ct_i*zhat)
1059 !!$            
1060 !!$          elseif (summationMethod .eq. REACTION_FIELD) then
966            if (summationMethod .eq. REACTION_FIELD) then
1062             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
1063
967               ri2 = riji * riji
968               ri3 = ri2 * riji
969               ri4 = ri2 * ri2
970  
971 <             pref = pre22 * mu_i * mu_j
1069 <              
1070 <             vterm = pref*( ri3*(ct_ij - 3.0d0 * ct_i * ct_j) - &
971 >             vterm = pref*( ri3*(ct_ij - 3.0_dp * ct_i * ct_j) - &
972                    preRF2*ct_ij )
973               vpair = vpair + vterm
974               epot = epot + sw*vterm
975              
976 <             a1 = 5.0d0 * ct_i * ct_j - ct_ij
976 >             a1 = 5.0_dp * ct_i * ct_j - ct_ij
977              
978 <             dudx = dudx + sw*pref*3.0d0*ri4 &
979 <                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
980 <             dudy = dudy + sw*pref*3.0d0*ri4 &
1080 <                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1081 <             dudz = dudz + sw*pref*3.0d0*ri4 &
1082 <                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
978 >             dudx = dudx + preSw*3.0_dp*ri4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
979 >             dudy = dudy + preSw*3.0_dp*ri4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
980 >             dudz = dudz + preSw*3.0_dp*ri4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
981              
982 <             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
982 >             duduz_i(1) = duduz_i(1) + preSw*(ri3*(uz_j(1)-3.0_dp*ct_j*xhat) &
983                    - preRF2*uz_j(1))
984 <             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
984 >             duduz_i(2) = duduz_i(2) + preSw*(ri3*(uz_j(2)-3.0_dp*ct_j*yhat) &
985                    - preRF2*uz_j(2))
986 <             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
986 >             duduz_i(3) = duduz_i(3) + preSw*(ri3*(uz_j(3)-3.0_dp*ct_j*zhat) &
987                    - preRF2*uz_j(3))
988 <             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
988 >             duduz_j(1) = duduz_j(1) + preSw*(ri3*(uz_i(1)-3.0_dp*ct_i*xhat) &
989                    - preRF2*uz_i(1))
990 <             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
990 >             duduz_j(2) = duduz_j(2) + preSw*(ri3*(uz_i(2)-3.0_dp*ct_i*yhat) &
991                    - preRF2*uz_i(2))
992 <             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
992 >             duduz_j(3) = duduz_j(3) + preSw*(ri3*(uz_i(3)-3.0_dp*ct_i*zhat) &
993                    - preRF2*uz_i(3))
994  
995            else
# Line 1113 | Line 1011 | contains
1011                     scale = 1.0_dp
1012                  endif
1013               endif
1014 <            
1015 <             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
1016 <            
1017 <             ri2 = ri * ri
1018 <             ri3 = ri2 * ri
1019 <             ri4 = ri2 * ri2
1014 >
1015 >             if (screeningMethod .eq. DAMPED) then
1016 >                ! assemble the damping variables
1017 >                call lookupUniformSpline1d(erfcSpline, rij, erfcVal, derfcVal)
1018 >                c1 = erfcVal*ri
1019 >                c2 = (-derfcVal + c1)*ri
1020 >                c3 = -2.0_dp*derfcVal*alpha2 + 3.0_dp*c2*ri
1021 >                c4 = -4.0_dp*derfcVal*alpha4 + 5.0_dp*c3*ri*ri
1022 >             else
1023 >                c1 = ri
1024 >                c2 = c1*ri
1025 >                c3 = 3.0_dp*c2*ri
1026 >                c4 = 5.0_dp*c3*ri*ri
1027 >             endif
1028 >
1029 >             ! precompute variables for convenience
1030               sc2 = scale * scale
1031 <            
1032 <             pref = pre22 * mu_i * mu_j
1033 <             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1031 >             cti3 = ct_i*sc2*c3
1032 >             ctj3 = ct_j*sc2*c3
1033 >             ctidotj = ct_i * ct_j * sc2        
1034 >             preSwSc = preSw*scale
1035 >             c2ri = c2*ri
1036 >             c3ri = c3*ri
1037 >             c4rij = c4*rij
1038 >
1039 >
1040 >             ! calculate the potential
1041 >             pot_term = (ct_ij*c2ri - ctidotj*c3)
1042 >             vterm = pref * pot_term
1043               vpair = vpair + vterm
1044               epot = epot + sw*vterm
1045 <            
1046 <             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
1047 <            
1048 <             dudx = dudx + sw*pref*3.0d0*ri4*scale &
1049 <                             *(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1050 <             dudy = dudy + sw*pref*3.0d0*ri4*scale &
1051 <                             *(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1052 <             dudz = dudz + sw*pref*3.0d0*ri4*scale &
1053 <                             *(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1045 >
1046 >             ! calculate derivatives for the forces and torques
1047 >             dudx = dudx + preSwSc * ( ctidotj*xhat*c4rij - &
1048 >                  (ct_i*uz_j(1) + ct_j*uz_i(1) + ct_ij*xhat)*c3ri )
1049 >             dudy = dudy + preSwSc * ( ctidotj*yhat*c4rij - &
1050 >                  (ct_i*uz_j(2) + ct_j*uz_i(2) + ct_ij*yhat)*c3ri )
1051 >             dudz = dudz + preSwSc * ( ctidotj*zhat*c4rij - &
1052 >                  (ct_i*uz_j(3) + ct_j*uz_i(3) + ct_ij*zhat)*c3ri )
1053 >
1054 >             duduz_i(1) = duduz_i(1) + preSw * ( uz_j(1)*c2ri - ctj3*xhat )
1055 >             duduz_i(2) = duduz_i(2) + preSw * ( uz_j(2)*c2ri - ctj3*yhat )
1056 >             duduz_i(3) = duduz_i(3) + preSw * ( uz_j(3)*c2ri - ctj3*zhat )
1057              
1058 <             duduz_i(1) = duduz_i(1) + sw*pref*ri3 &
1059 <                                         *(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
1060 <             duduz_i(2) = duduz_i(2) + sw*pref*ri3 &
1061 <                                         *(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
1142 <             duduz_i(3) = duduz_i(3) + sw*pref*ri3 &
1143 <                                         *(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
1144 <            
1145 <             duduz_j(1) = duduz_j(1) + sw*pref*ri3 &
1146 <                                         *(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
1147 <             duduz_j(2) = duduz_j(2) + sw*pref*ri3 &
1148 <                                         *(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
1149 <             duduz_j(3) = duduz_j(3) + sw*pref*ri3 &
1150 <                                         *(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
1058 >             duduz_j(1) = duduz_j(1) + preSw * ( uz_i(1)*c2ri - cti3*xhat )
1059 >             duduz_j(2) = duduz_j(2) + preSw * ( uz_i(2)*c2ri - cti3*yhat )
1060 >             duduz_j(3) = duduz_j(3) + preSw * ( uz_i(3)*c2ri - cti3*zhat )
1061 >
1062            endif
1063         endif
1064      endif
1065  
1066      if (i_is_Quadrupole) then
1067         if (j_is_Charge) then
1068 <
1069 <          ri2 = riji * riji
1070 <          ri3 = ri2 * riji
1071 <          ri4 = ri2 * ri2
1068 >          if (screeningMethod .eq. DAMPED) then
1069 >             ! assemble the damping variables
1070 >             call lookupUniformSpline1d(erfcSpline, rij, erfcVal, derfcVal)
1071 >             c1 = erfcVal*riji
1072 >             c2 = (-derfcVal + c1)*riji
1073 >             c3 = -2.0_dp*derfcVal*alpha2 + 3.0_dp*c2*riji
1074 >             c4 = -4.0_dp*derfcVal*alpha4 + 5.0_dp*c3*riji*riji
1075 >          else
1076 >             c1 = riji
1077 >             c2 = c1*riji
1078 >             c3 = 3.0_dp*c2*riji
1079 >             c4 = 5.0_dp*c3*riji*riji
1080 >          endif
1081 >          
1082 >          ! precompute some variables
1083            cx2 = cx_i * cx_i
1084            cy2 = cy_i * cy_i
1085            cz2 = cz_i * cz_i
1086 +          pref = pre14 * q_j * one_third
1087  
1088 < !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
1089 < !!$             pref = pre14 * q_j / 3.0_dp
1090 < !!$             vterm1 = pref * ri3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1091 < !!$                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1092 < !!$                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1093 < !!$             vterm2 = pref * rcuti3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1094 < !!$                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1095 < !!$                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1096 < !!$             vpair = vpair + ( vterm1 - vterm2 )
1097 < !!$             epot = epot + sw*( vterm1 - vterm2 )
1098 < !!$            
1099 < !!$             dudx = dudx - sw*(5.0_dp*(vterm1*riji*xhat-vterm2*rcuti2*d(1))) +&
1100 < !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(1)) - &
1101 < !!$                  qxx_i*2.0_dp*(xhat - rcuti*d(1))) + &
1102 < !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(1)) - &
1103 < !!$                  qyy_i*2.0_dp*(xhat - rcuti*d(1))) + &
1104 < !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(1)) - &
1105 < !!$                  qzz_i*2.0_dp*(xhat - rcuti*d(1))) )
1106 < !!$             dudy = dudy - sw*(5.0_dp*(vterm1*riji*yhat-vterm2*rcuti2*d(2))) +&
1107 < !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(2)) - &
1108 < !!$                  qxx_i*2.0_dp*(yhat - rcuti*d(2))) + &
1109 < !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(2)) - &
1110 < !!$                  qyy_i*2.0_dp*(yhat - rcuti*d(2))) + &
1111 < !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(2)) - &
1112 < !!$                  qzz_i*2.0_dp*(yhat - rcuti*d(2))) )
1113 < !!$             dudz = dudz - sw*(5.0_dp*(vterm1*riji*zhat-vterm2*rcuti2*d(3))) +&
1114 < !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(3)) - &
1115 < !!$                  qxx_i*2.0_dp*(zhat - rcuti*d(3))) + &
1116 < !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(3)) - &
1117 < !!$                  qyy_i*2.0_dp*(zhat - rcuti*d(3))) + &
1118 < !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(3)) - &
1119 < !!$                  qzz_i*2.0_dp*(zhat - rcuti*d(3))) )
1120 < !!$            
1121 < !!$             dudux_i(1) = dudux_i(1) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*xhat) -&
1122 < !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(1)))
1123 < !!$             dudux_i(2) = dudux_i(2) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*yhat) -&
1124 < !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(2)))
1125 < !!$             dudux_i(3) = dudux_i(3) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*zhat) -&
1126 < !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(3)))
1127 < !!$            
1128 < !!$             duduy_i(1) = duduy_i(1) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*xhat) -&
1129 < !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(1)))
1130 < !!$             duduy_i(2) = duduy_i(2) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*yhat) -&
1131 < !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(2)))
1132 < !!$             duduy_i(3) = duduy_i(3) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*zhat) -&
1210 < !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(3)))
1211 < !!$            
1212 < !!$             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*xhat) -&
1213 < !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(1)))
1214 < !!$             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*yhat) -&
1215 < !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(2)))
1216 < !!$             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*zhat) -&
1217 < !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(3)))
1218 < !!$
1219 < !!$          else
1220 <             pref = pre14 * q_j / 3.0_dp
1221 <             vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1222 <                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1223 <                  qzz_i * (3.0_dp*cz2 - 1.0_dp))
1224 <             vpair = vpair + vterm
1225 <             epot = epot + sw*vterm
1226 <            
1227 <             dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref*ri4 * ( &
1228 <                  qxx_i*(6.0_dp*cx_i*ux_i(1) - 2.0_dp*xhat) + &
1229 <                  qyy_i*(6.0_dp*cy_i*uy_i(1) - 2.0_dp*xhat) + &
1230 <                  qzz_i*(6.0_dp*cz_i*uz_i(1) - 2.0_dp*xhat) )
1231 <             dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref*ri4 * ( &
1232 <                  qxx_i*(6.0_dp*cx_i*ux_i(2) - 2.0_dp*yhat) + &
1233 <                  qyy_i*(6.0_dp*cy_i*uy_i(2) - 2.0_dp*yhat) + &
1234 <                  qzz_i*(6.0_dp*cz_i*uz_i(2) - 2.0_dp*yhat) )
1235 <             dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref*ri4 * ( &
1236 <                  qxx_i*(6.0_dp*cx_i*ux_i(3) - 2.0_dp*zhat) + &
1237 <                  qyy_i*(6.0_dp*cy_i*uy_i(3) - 2.0_dp*zhat) + &
1238 <                  qzz_i*(6.0_dp*cz_i*uz_i(3) - 2.0_dp*zhat) )
1239 <            
1240 <             dudux_i(1) = dudux_i(1) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*xhat)
1241 <             dudux_i(2) = dudux_i(2) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*yhat)
1242 <             dudux_i(3) = dudux_i(3) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*zhat)
1243 <            
1244 <             duduy_i(1) = duduy_i(1) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*xhat)
1245 <             duduy_i(2) = duduy_i(2) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*yhat)
1246 <             duduy_i(3) = duduy_i(3) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*zhat)
1247 <            
1248 <             duduz_i(1) = duduz_i(1) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*xhat)
1249 <             duduz_i(2) = duduz_i(2) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*yhat)
1250 <             duduz_i(3) = duduz_i(3) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*zhat)
1251 < !!$          endif
1088 >          ! calculate the potential
1089 >          pot_term = ( qxx_i * (cx2*c3 - c2ri) + qyy_i * (cy2*c3 - c2ri) + &
1090 >               qzz_i * (cz2*c3 - c2ri) )
1091 >
1092 >          vterm = pref * pot_term
1093 >          vpair = vpair + vterm
1094 >          epot = epot + sw*vterm
1095 >
1096 >          ! precompute variables for convenience
1097 >          preSw = sw*pref
1098 >          c2ri = c2*riji
1099 >          c3ri = c3*riji
1100 >          c4rij = c4*rij
1101 >          xhatdot2 = 2.0_dp*xhat*c3
1102 >          yhatdot2 = 2.0_dp*yhat*c3
1103 >          zhatdot2 = 2.0_dp*zhat*c3
1104 >          xhatc4 = xhat*c4rij
1105 >          yhatc4 = yhat*c4rij
1106 >          zhatc4 = zhat*c4rij
1107 >
1108 >          ! calculate the derivatives for the forces and torques
1109 >          dudx = dudx - preSw * ( &
1110 >               qxx_i*(cx2*xhatc4 - (2.0_dp*cx_i*ux_i(1) + xhat)*c3ri) + &
1111 >               qyy_i*(cy2*xhatc4 - (2.0_dp*cy_i*uy_i(1) + xhat)*c3ri) + &
1112 >               qzz_i*(cz2*xhatc4 - (2.0_dp*cz_i*uz_i(1) + xhat)*c3ri) )
1113 >          dudy = dudy - preSw * ( &
1114 >               qxx_i*(cx2*yhatc4 - (2.0_dp*cx_i*ux_i(2) + yhat)*c3ri) + &
1115 >               qyy_i*(cy2*yhatc4 - (2.0_dp*cy_i*uy_i(2) + yhat)*c3ri) + &
1116 >               qzz_i*(cz2*yhatc4 - (2.0_dp*cz_i*uz_i(2) + yhat)*c3ri) )
1117 >          dudz = dudz - preSw * ( &
1118 >               qxx_i*(cx2*zhatc4 - (2.0_dp*cx_i*ux_i(3) + zhat)*c3ri) + &
1119 >               qyy_i*(cy2*zhatc4 - (2.0_dp*cy_i*uy_i(3) + zhat)*c3ri) + &
1120 >               qzz_i*(cz2*zhatc4 - (2.0_dp*cz_i*uz_i(3) + zhat)*c3ri) )
1121 >          
1122 >          dudux_i(1) = dudux_i(1) + preSw*(qxx_i*cx_i*xhatdot2)
1123 >          dudux_i(2) = dudux_i(2) + preSw*(qxx_i*cx_i*yhatdot2)
1124 >          dudux_i(3) = dudux_i(3) + preSw*(qxx_i*cx_i*zhatdot2)
1125 >          
1126 >          duduy_i(1) = duduy_i(1) + preSw*(qyy_i*cy_i*xhatdot2)
1127 >          duduy_i(2) = duduy_i(2) + preSw*(qyy_i*cy_i*yhatdot2)
1128 >          duduy_i(3) = duduy_i(3) + preSw*(qyy_i*cy_i*zhatdot2)
1129 >          
1130 >          duduz_i(1) = duduz_i(1) + preSw*(qzz_i*cz_i*xhatdot2)
1131 >          duduz_i(2) = duduz_i(2) + preSw*(qzz_i*cz_i*yhatdot2)
1132 >          duduz_i(3) = duduz_i(3) + preSw*(qzz_i*cz_i*zhatdot2)
1133         endif
1134      endif
1135  
1136  
1137      if (do_pot) then
1138   #ifdef IS_MPI
1139 <       pot_row(ELECTROSTATIC_POT,atom1) = pot_row(ELECTROSTATIC_POT,atom1) + 0.5d0*epot
1140 <       pot_col(ELECTROSTATIC_POT,atom2) = pot_col(ELECTROSTATIC_POT,atom2) + 0.5d0*epot
1139 >       pot_row(ELECTROSTATIC_POT,atom1) = pot_row(ELECTROSTATIC_POT,atom1) + 0.5_dp*epot
1140 >       pot_col(ELECTROSTATIC_POT,atom2) = pot_col(ELECTROSTATIC_POT,atom2) + 0.5_dp*epot
1141   #else
1142         pot = pot + epot
1143   #endif
# Line 1373 | Line 1254 | contains
1254      integer :: atid1
1255      real(kind=dp), dimension(9,nLocal) :: eFrame
1256      real(kind=dp), dimension(3,nLocal) :: t
1257 <    real(kind=dp) :: mu1, c1
1257 >    real(kind=dp) :: mu1, chg1
1258      real(kind=dp) :: preVal, epot, mypot
1259      real(kind=dp) :: eix, eiy, eiz
1260  
# Line 1389 | Line 1270 | contains
1270            mu1 = getDipoleMoment(atid1)
1271            
1272            preVal = pre22 * preRF2 * mu1*mu1
1273 <          mypot = mypot - 0.5d0*preVal
1273 >          mypot = mypot - 0.5_dp*preVal
1274            
1275            ! The self-correction term adds into the reaction field vector
1276            
# Line 1409 | Line 1290 | contains
1290            
1291         endif
1292  
1293 < !!$    elseif (summationMethod .eq. UNDAMPED_WOLF) then
1294 < !!$       if (ElectrostaticMap(atid1)%is_Charge) then
1295 < !!$          c1 = getCharge(atid1)
1296 < !!$          
1297 < !!$          mypot = mypot - (rcuti * 0.5_dp * c1 * c1)
1298 < !!$       endif
1299 < !!$      
1300 < !!$    elseif (summationMethod .eq. DAMPED_WOLF) then
1301 < !!$       if (ElectrostaticMap(atid1)%is_Charge) then
1302 < !!$          c1 = getCharge(atid1)
1303 < !!$          
1304 < !!$          mypot = mypot - (constERFC * rcuti * 0.5_dp + &
1305 < !!$               dampingAlpha*invRootPi) * c1 * c1      
1306 < !!$       endif
1293 >    elseif ( (summationMethod .eq. SHIFTED_FORCE) .or. &
1294 >         (summationMethod .eq. SHIFTED_POTENTIAL) ) then
1295 >       if (ElectrostaticMap(atid1)%is_Charge) then
1296 >          chg1 = getCharge(atid1)
1297 >          
1298 >          if (screeningMethod .eq. DAMPED) then
1299 >             mypot = mypot - (c1c * 0.5_dp + &
1300 >                  dampingAlpha*invRootPi) * chg1 * chg1    
1301 >            
1302 >          else            
1303 >             mypot = mypot - (rcuti * 0.5_dp * chg1 * chg1)
1304 >            
1305 >          endif
1306 >       endif
1307      endif
1308      
1309      return
# Line 1459 | Line 1340 | contains
1340         call checkSummationMethod()
1341      endif
1342  
1343 <    dudx = 0.0d0
1344 <    dudy = 0.0d0
1345 <    dudz = 0.0d0
1343 >    dudx = zero
1344 >    dudy = zero
1345 >    dudz = zero
1346  
1347 <    riji = 1.0d0/rij
1347 >    riji = 1.0_dp/rij
1348  
1349      xhat = d(1) * riji
1350      yhat = d(2) * riji
# Line 1487 | Line 1368 | contains
1368        
1369         myPot = myPot + sw*vterm
1370        
1371 <       dudr  = sw*preVal * 2.0d0*rfVal*riji
1371 >       dudr  = sw*preVal * 2.0_dp*rfVal*riji
1372        
1373         dudx = dudx + dudr * xhat
1374         dudy = dudy + dudr * yhat
# Line 1508 | Line 1389 | contains
1389         vterm = - pref * ct_j * ( ri2 - preRF2*rij )
1390         myPot = myPot + sw*vterm
1391        
1392 <       dudx = dudx - sw*pref*( ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1392 >       dudx = dudx - sw*pref*( ri3*(uz_j(1)-3.0_dp*ct_j*xhat) &
1393              - preRF2*uz_j(1) )
1394 <       dudy = dudy - sw*pref*( ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1394 >       dudy = dudy - sw*pref*( ri3*(uz_j(2)-3.0_dp*ct_j*yhat) &
1395              - preRF2*uz_j(2) )
1396 <       dudz = dudz - sw*pref*( ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1396 >       dudz = dudz - sw*pref*( ri3*(uz_j(3)-3.0_dp*ct_j*zhat) &
1397              - preRF2*uz_j(3) )
1398        
1399         duduz_j(1) = duduz_j(1) - sw * pref * xhat * ( ri2 - preRF2*rij )
# Line 1534 | Line 1415 | contains
1415         vterm = pref * ct_i * ( ri2 - preRF2*rij )
1416         myPot = myPot + sw*vterm
1417        
1418 <       dudx = dudx + sw*pref*( ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1418 >       dudx = dudx + sw*pref*( ri3*(uz_i(1)-3.0_dp*ct_i*xhat) &
1419              - preRF2*uz_i(1) )
1420 <       dudy = dudy + sw*pref*( ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1420 >       dudy = dudy + sw*pref*( ri3*(uz_i(2)-3.0_dp*ct_i*yhat) &
1421              - preRF2*uz_i(2) )
1422 <       dudz = dudz + sw*pref*( ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1422 >       dudz = dudz + sw*pref*( ri3*(uz_i(3)-3.0_dp*ct_i*zhat) &
1423              - preRF2*uz_i(3) )
1424        
1425         duduz_i(1) = duduz_i(1) + sw * pref * xhat * ( ri2 - preRF2*rij )

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines