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 2162 by chrisfen, Mon Apr 11 20:19:22 2005 UTC vs.
Revision 2279 by chrisfen, Tue Aug 30 18:23:50 2005 UTC

# Line 40 | Line 40 | module electrostatic_module
40   !!
41  
42   module electrostatic_module
43 <  
43 >
44    use force_globals
45    use definitions
46    use atype_module
# Line 77 | Line 77 | module electrostatic_module
77    public :: getCharge
78    public :: getDipoleMoment
79    public :: pre22
80 +  public :: destroyElectrostaticTypes
81  
82    type :: Electrostatic
83       integer :: c_ident
# Line 84 | Line 85 | module electrostatic_module
85       logical :: is_Dipole = .false.
86       logical :: is_SplitDipole = .false.
87       logical :: is_Quadrupole = .false.
88 +     logical :: is_Tap = .false.
89       real(kind=DP) :: charge = 0.0_DP
90       real(kind=DP) :: dipole_moment = 0.0_DP
91       real(kind=DP) :: split_dipole_distance = 0.0_DP
# Line 95 | Line 97 | contains
97   contains
98  
99    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
100 <       is_SplitDipole, is_Quadrupole, status)
101 <    
100 >       is_SplitDipole, is_Quadrupole, is_Tap, status)
101 >
102      integer, intent(in) :: c_ident
103      logical, intent(in) :: is_Charge
104      logical, intent(in) :: is_Dipole
105      logical, intent(in) :: is_SplitDipole
106      logical, intent(in) :: is_Quadrupole
107 +    logical, intent(in) :: is_Tap
108      integer, intent(out) :: status
109      integer :: nAtypes, myATID, i, j
110  
111      status = 0
112      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
113 <    
113 >
114      !! Be simple-minded and assume that we need an ElectrostaticMap that
115      !! is the same size as the total number of atom types
116  
117      if (.not.allocated(ElectrostaticMap)) then
118 <      
118 >
119         nAtypes = getSize(atypes)
120 <    
120 >
121         if (nAtypes == 0) then
122            status = -1
123            return
124         end if
125 <      
125 >
126         if (.not. allocated(ElectrostaticMap)) then
127            allocate(ElectrostaticMap(nAtypes))
128         endif
129 <      
129 >
130      end if
131  
132      if (myATID .gt. size(ElectrostaticMap)) then
133         status = -1
134         return
135      endif
136 <    
136 >
137      ! set the values for ElectrostaticMap for this atom type:
138  
139      ElectrostaticMap(myATID)%c_ident = c_ident
# Line 138 | Line 141 | contains
141      ElectrostaticMap(myATID)%is_Dipole = is_Dipole
142      ElectrostaticMap(myATID)%is_SplitDipole = is_SplitDipole
143      ElectrostaticMap(myATID)%is_Quadrupole = is_Quadrupole
144 <    
144 >    ElectrostaticMap(myATID)%is_Tap = is_Tap
145 >
146    end subroutine newElectrostaticType
147  
148    subroutine setCharge(c_ident, charge, status)
# Line 166 | Line 170 | contains
170         call handleError("electrostatic", "Attempt to setCharge of an atom type that is not a charge!")
171         status = -1
172         return
173 <    endif      
173 >    endif
174  
175      ElectrostaticMap(myATID)%charge = charge
176    end subroutine setCharge
# Line 257 | Line 261 | contains
261         status = -1
262         return
263      endif
264 <    
264 >
265      do i = 1, 3
266 <          ElectrostaticMap(myATID)%quadrupole_moments(i) = &
267 <               quadrupole_moments(i)
268 <       enddo
266 >       ElectrostaticMap(myATID)%quadrupole_moments(i) = &
267 >            quadrupole_moments(i)
268 >    enddo
269  
270    end subroutine setQuadrupoleMoments
271  
272 <  
272 >
273    function getCharge(atid) result (c)
274      integer, intent(in) :: atid
275      integer :: localError
276      real(kind=dp) :: c
277 <    
277 >
278      if (.not.allocated(ElectrostaticMap)) then
279         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getCharge!")
280         return
281      end if
282 <    
282 >
283      if (.not.ElectrostaticMap(atid)%is_Charge) then
284         call handleError("electrostatic", "getCharge was called for an atom type that isn't a charge!")
285         return
286      endif
287 <    
287 >
288      c = ElectrostaticMap(atid)%charge
289    end function getCharge
290  
# Line 288 | Line 292 | contains
292      integer, intent(in) :: atid
293      integer :: localError
294      real(kind=dp) :: dm
295 <    
295 >
296      if (.not.allocated(ElectrostaticMap)) then
297         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getDipoleMoment!")
298         return
299      end if
300 <    
300 >
301      if (.not.ElectrostaticMap(atid)%is_Dipole) then
302         call handleError("electrostatic", "getDipoleMoment was called for an atom type that isn't a dipole!")
303         return
304      endif
305 <    
305 >
306      dm = ElectrostaticMap(atid)%dipole_moment
307    end function getDipoleMoment
308  
309    subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
310 <       vpair, fpair, pot, eFrame, f, t, do_pot)
311 <    
310 >       vpair, fpair, pot, eFrame, f, t, do_pot, corrMethod)
311 >
312      logical, intent(in) :: do_pot
313 <    
313 >
314      integer, intent(in) :: atom1, atom2
315      integer :: localError
316 +    integer, intent(in) :: corrMethod
317  
318      real(kind=dp), intent(in) :: rij, r2, sw
319      real(kind=dp), intent(in), dimension(3) :: d
# Line 319 | Line 324 | contains
324      real( kind = dp ), dimension(9,nLocal) :: eFrame
325      real( kind = dp ), dimension(3,nLocal) :: f
326      real( kind = dp ), dimension(3,nLocal) :: t
327 <    
327 >
328      real (kind = dp), dimension(3) :: ux_i, uy_i, uz_i
329      real (kind = dp), dimension(3) :: ux_j, uy_j, uz_j
330      real (kind = dp), dimension(3) :: dudux_i, duduy_i, duduz_i
# Line 327 | Line 332 | contains
332  
333      logical :: i_is_Charge, i_is_Dipole, i_is_SplitDipole, i_is_Quadrupole
334      logical :: j_is_Charge, j_is_Dipole, j_is_SplitDipole, j_is_Quadrupole
335 +    logical :: i_is_Tap, j_is_Tap
336 +    logical :: use_damped_wolf, use_undamped_wolf
337      integer :: me1, me2, id1, id2
338      real (kind=dp) :: q_i, q_j, mu_i, mu_j, d_i, d_j
339      real (kind=dp) :: qxx_i, qyy_i, qzz_i
# Line 339 | Line 346 | contains
346      real (kind=dp) :: pref, vterm, epot, dudr    
347      real (kind=dp) :: xhat, yhat, zhat
348      real (kind=dp) :: dudx, dudy, dudz
349 <    real (kind=dp) :: scale, sc2, bigR
349 >    real (kind=dp) :: scale, sc2, bigR, switcher, dswitcher
350  
351 +    use_damped_wolf = .false.
352 +    use_undamped_wolf = .false.
353 +    if (corrMethod .eq. 1) then
354 +       use_undamped_wolf = .true.
355 +    elseif (corrMethod .eq. 2) then
356 +       use_damped_wolf = .true.
357 +    endif
358 +
359      if (.not.allocated(ElectrostaticMap)) then
360         call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
361         return
# Line 363 | Line 378 | contains
378      zhat = d(3) * riji
379  
380      !! logicals
366
381      i_is_Charge = ElectrostaticMap(me1)%is_Charge
382      i_is_Dipole = ElectrostaticMap(me1)%is_Dipole
383      i_is_SplitDipole = ElectrostaticMap(me1)%is_SplitDipole
384      i_is_Quadrupole = ElectrostaticMap(me1)%is_Quadrupole
385 +    i_is_Tap = ElectrostaticMap(me1)%is_Tap
386  
387      j_is_Charge = ElectrostaticMap(me2)%is_Charge
388      j_is_Dipole = ElectrostaticMap(me2)%is_Dipole
389      j_is_SplitDipole = ElectrostaticMap(me2)%is_SplitDipole
390      j_is_Quadrupole = ElectrostaticMap(me2)%is_Quadrupole
391 +    j_is_Tap = ElectrostaticMap(me2)%is_Tap
392  
393      if (i_is_Charge) then
394         q_i = ElectrostaticMap(me1)%charge      
395      endif
396 <    
396 >
397      if (i_is_Dipole) then
398         mu_i = ElectrostaticMap(me1)%dipole_moment
399   #ifdef IS_MPI
# Line 394 | Line 410 | contains
410         if (i_is_SplitDipole) then
411            d_i = ElectrostaticMap(me1)%split_dipole_distance
412         endif
413 <      
413 >
414      endif
415  
416      if (i_is_Quadrupole) then
# Line 427 | Line 443 | contains
443         cz_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
444      endif
445  
430
446      if (j_is_Charge) then
447         q_j = ElectrostaticMap(me2)%charge      
448      endif
449 <    
449 >
450      if (j_is_Dipole) then
451         mu_j = ElectrostaticMap(me2)%dipole_moment
452   #ifdef IS_MPI
# Line 479 | Line 494 | contains
494         cy_j = uy_j(1)*xhat + uy_j(2)*yhat + uy_j(3)*zhat
495         cz_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
496      endif
497 +  
498 + !!$    switcher = 1.0d0
499 + !!$    dswitcher = 0.0d0
500 + !!$    ebalance = 0.0d0
501 + !!$    ! weaken the dipole interaction at close range for TAP water
502 + !!$    if (j_is_Tap .and. i_is_Tap) then
503 + !!$      call calc_switch(rij, mu_i, switcher, dswitcher)
504 + !!$    endif
505  
506      epot = 0.0_dp
507      dudx = 0.0_dp
# Line 496 | Line 519 | contains
519      if (i_is_Charge) then
520  
521         if (j_is_Charge) then
522 <          
522 >
523            vterm = pre11 * q_i * q_j * riji
524            vpair = vpair + vterm
525            epot = epot + sw*vterm
# Line 506 | Line 529 | contains
529            dudx = dudx + dudr * xhat
530            dudy = dudy + dudr * yhat
531            dudz = dudz + dudr * zhat
532 <      
532 >
533         endif
534  
535         if (j_is_Dipole) then
# Line 523 | Line 546 | contains
546            ri2 = ri * ri
547            ri3 = ri2 * ri
548            sc2 = scale * scale
549 <            
549 >
550            pref = pre12 * q_i * mu_j
551            vterm = - pref * ct_j * ri2 * scale
552            vpair = vpair + vterm
# Line 540 | Line 563 | contains
563            duduz_j(1) = duduz_j(1) - pref * sw * ri2 * xhat * scale
564            duduz_j(2) = duduz_j(2) - pref * sw * ri2 * yhat * scale
565            duduz_j(3) = duduz_j(3) - pref * sw * ri2 * zhat * scale
566 <          
566 >
567         endif
568  
569         if (j_is_Quadrupole) then
# Line 571 | Line 594 | contains
594                 qxx_j*(6.0_dp*cx_j*ux_j(3) - 2.0_dp*zhat) + &
595                 qyy_j*(6.0_dp*cy_j*uy_j(3) - 2.0_dp*zhat) + &
596                 qzz_j*(6.0_dp*cz_j*uz_j(3) - 2.0_dp*zhat) )
597 <          
597 >
598            dudux_j(1) = dudux_j(1) + pref * sw * ri3 * (qxx_j*6.0_dp*cx_j*xhat)
599            dudux_j(2) = dudux_j(2) + pref * sw * ri3 * (qxx_j*6.0_dp*cx_j*yhat)
600            dudux_j(3) = dudux_j(3) + pref * sw * ri3 * (qxx_j*6.0_dp*cx_j*zhat)
# Line 586 | Line 609 | contains
609         endif
610  
611      endif
612 <  
612 >
613      if (i_is_Dipole) then
614 <      
614 >
615         if (j_is_Charge) then
616  
617            if (i_is_SplitDipole) then
# Line 603 | Line 626 | contains
626            ri2 = ri * ri
627            ri3 = ri2 * ri
628            sc2 = scale * scale
629 <            
629 >
630            pref = pre12 * q_j * mu_i
631            vterm = pref * ct_i * ri2 * scale
632            vpair = vpair + vterm
# Line 650 | Line 673 | contains
673            vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
674            vpair = vpair + vterm
675            epot = epot + sw * vterm
676 <          
676 >
677            a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
678  
679 <          dudx=dudx+pref*sw*3.0d0*ri4*scale*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
680 <          dudy=dudy+pref*sw*3.0d0*ri4*scale*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
681 <          dudz=dudz+pref*sw*3.0d0*ri4*scale*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
679 >          dudx = dudx + pref*sw*3.0d0*ri4*scale &
680 >                         *(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
681 >          dudy = dudy + pref*sw*3.0d0*ri4*scale &
682 >                         *(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
683 >          dudz = dudz + pref*sw*3.0d0*ri4*scale &
684 >                         *(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
685  
686 <          duduz_i(1) = duduz_i(1) + pref*sw*ri3*(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
687 <          duduz_i(2) = duduz_i(2) + pref*sw*ri3*(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
688 <          duduz_i(3) = duduz_i(3) + pref*sw*ri3*(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
686 >          duduz_i(1) = duduz_i(1) + pref*sw*ri3 &
687 >                                     *(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
688 >          duduz_i(2) = duduz_i(2) + pref*sw*ri3 &
689 >                                     *(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
690 >          duduz_i(3) = duduz_i(3) + pref*sw*ri3 &
691 >                                     *(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
692  
693 <          duduz_j(1) = duduz_j(1) + pref*sw*ri3*(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
694 <          duduz_j(2) = duduz_j(2) + pref*sw*ri3*(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
695 <          duduz_j(3) = duduz_j(3) + pref*sw*ri3*(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
693 >          duduz_j(1) = duduz_j(1) + pref*sw*ri3 &
694 >                                     *(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
695 >          duduz_j(2) = duduz_j(2) + pref*sw*ri3 &
696 >                                     *(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
697 >          duduz_j(3) = duduz_j(3) + pref*sw*ri3 &
698 >                                     *(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
699         endif
700  
701      endif
702  
703      if (i_is_Quadrupole) then
704         if (j_is_Charge) then
705 <          
705 >
706            ri2 = riji * riji
707            ri3 = ri2 * riji
708            ri4 = ri2 * ri2
709            cx2 = cx_i * cx_i
710            cy2 = cy_i * cy_i
711            cz2 = cz_i * cz_i
712 <          
712 >
713            pref = pre14 * q_j / 3.0_dp
714            vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
715                 qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
716                 qzz_i * (3.0_dp*cz2 - 1.0_dp))
717            vpair = vpair + vterm
718            epot = epot + sw * vterm
719 <          
719 >
720            dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + pref * sw * ri4 * ( &
721                 qxx_i*(6.0_dp*cx_i*ux_i(1) - 2.0_dp*xhat) + &
722                 qyy_i*(6.0_dp*cy_i*uy_i(1) - 2.0_dp*xhat) + &
# Line 697 | Line 729 | contains
729                 qxx_i*(6.0_dp*cx_i*ux_i(3) - 2.0_dp*zhat) + &
730                 qyy_i*(6.0_dp*cy_i*uy_i(3) - 2.0_dp*zhat) + &
731                 qzz_i*(6.0_dp*cz_i*uz_i(3) - 2.0_dp*zhat) )
732 <          
732 >
733            dudux_i(1) = dudux_i(1) + pref * sw * ri3 * (qxx_i*6.0_dp*cx_i*xhat)
734            dudux_i(2) = dudux_i(2) + pref * sw * ri3 * (qxx_i*6.0_dp*cx_i*yhat)
735            dudux_i(3) = dudux_i(3) + pref * sw * ri3 * (qxx_i*6.0_dp*cx_i*zhat)
736 <          
736 >
737            duduy_i(1) = duduy_i(1) + pref * sw * ri3 * (qyy_i*6.0_dp*cy_i*xhat)
738            duduy_i(2) = duduy_i(2) + pref * sw * ri3 * (qyy_i*6.0_dp*cy_i*yhat)
739            duduy_i(3) = duduy_i(3) + pref * sw * ri3 * (qyy_i*6.0_dp*cy_i*zhat)
740 <          
740 >
741            duduz_i(1) = duduz_i(1) + pref * sw * ri3 * (qzz_i*6.0_dp*cz_i*xhat)
742            duduz_i(2) = duduz_i(2) + pref * sw * ri3 * (qzz_i*6.0_dp*cz_i*yhat)
743            duduz_i(3) = duduz_i(3) + pref * sw * ri3 * (qzz_i*6.0_dp*cz_i*zhat)
744         endif
745      endif
746 <      
747 <    
746 >
747 >
748      if (do_pot) then
749   #ifdef IS_MPI
750         pot_row(atom1) = pot_row(atom1) + 0.5d0*epot
# Line 721 | Line 753 | contains
753         pot = pot + epot
754   #endif
755      endif
756 <        
756 >
757   #ifdef IS_MPI
758      f_Row(1,atom1) = f_Row(1,atom1) + dudx
759      f_Row(2,atom1) = f_Row(2,atom1) + dudy
760      f_Row(3,atom1) = f_Row(3,atom1) + dudz
761 <    
761 >
762      f_Col(1,atom2) = f_Col(1,atom2) - dudx
763      f_Col(2,atom2) = f_Col(2,atom2) - dudy
764      f_Col(3,atom2) = f_Col(3,atom2) - dudz
765 <    
765 >
766      if (i_is_Dipole .or. i_is_Quadrupole) then
767         t_Row(1,atom1)=t_Row(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
768         t_Row(2,atom1)=t_Row(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
# Line 765 | Line 797 | contains
797      f(1,atom1) = f(1,atom1) + dudx
798      f(2,atom1) = f(2,atom1) + dudy
799      f(3,atom1) = f(3,atom1) + dudz
800 <    
800 >
801      f(1,atom2) = f(1,atom2) - dudx
802      f(2,atom2) = f(2,atom2) - dudy
803      f(3,atom2) = f(3,atom2) - dudz
804 <    
804 >
805      if (i_is_Dipole .or. i_is_Quadrupole) then
806         t(1,atom1)=t(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
807         t(2,atom1)=t(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
# Line 801 | Line 833 | contains
833      endif
834  
835   #endif
836 <    
836 >
837   #ifdef IS_MPI
838      id1 = AtomRowToGlobal(atom1)
839      id2 = AtomColToGlobal(atom2)
# Line 811 | Line 843 | contains
843   #endif
844  
845      if (molMembershipList(id1) .ne. molMembershipList(id2)) then
846 <      
846 >
847         fpair(1) = fpair(1) + dudx
848         fpair(2) = fpair(2) + dudy
849         fpair(3) = fpair(3) + dudz
# Line 820 | Line 852 | contains
852  
853      return
854    end subroutine doElectrostaticPair
855 <  
855 >
856 >  !! calculates the switching functions and their derivatives for a given
857 >  subroutine calc_switch(r, mu, scale, dscale)
858 >
859 >    real (kind=dp), intent(in) :: r, mu
860 >    real (kind=dp), intent(inout) :: scale, dscale
861 >    real (kind=dp) :: rl, ru, mulow, minRatio, temp, scaleVal
862 >
863 >    ! distances must be in angstroms
864 >    rl = 2.75d0
865 >    ru = 3.75d0
866 >    mulow = 0.0d0 !3.3856d0 ! 1.84 * 1.84
867 >    minRatio = mulow / (mu*mu)
868 >    scaleVal = 1.0d0 - minRatio
869 >    
870 >    if (r.lt.rl) then
871 >       scale = minRatio
872 >       dscale = 0.0d0
873 >    elseif (r.gt.ru) then
874 >       scale = 1.0d0
875 >       dscale = 0.0d0
876 >    else
877 >       scale = 1.0d0 - scaleVal*((ru + 2.0d0*r - 3.0d0*rl) * (ru-r)**2) &
878 >                        / ((ru - rl)**3)
879 >       dscale = -scaleVal * 6.0d0 * (r-ru)*(r-rl)/((ru - rl)**3)    
880 >    endif
881 >        
882 >    return
883 >  end subroutine calc_switch
884 >
885 >  subroutine destroyElectrostaticTypes()
886 >
887 >    if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap)
888 >
889 >  end subroutine destroyElectrostaticTypes
890 >
891   end module electrostatic_module

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines