ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/calc_charge_charge.F90
(Generate patch)

Comparing trunk/OOPSE/libmdtools/calc_charge_charge.F90 (file contents):
Revision 1113 by tim, Thu Apr 15 16:18:26 2004 UTC vs.
Revision 1138 by gezelter, Wed Apr 28 21:39:22 2004 UTC

# Line 14 | Line 14 | module charge_charge
14    PRIVATE
15    real(kind=dp), save :: ecr = 0.0_DP
16    real(kind=dp), save :: rt  = 0.0_DP
17 +  real(kind=dp), save :: dielect  = 0.0_DP
18    real(kind=dp), save :: pre = 0.0_DP
19 +  
20    logical, save :: haveCutoffs = .false.
21    logical, save :: haveChargeMap = .false.
22 +  logical, save :: haveDielectric = .false.
23  
24    public::setCutoffsCharge
25    public::do_charge_pair
26 +  public::initialize_charge
27  
28    type :: ChargeList
29       real(kind=DP) :: charge = 0.0_DP
# Line 28 | Line 32 | contains
32    type(ChargeList), dimension(:), allocatable :: ChargeMap
33  
34   contains
35 +
36 +  subroutine initialize_charge(this_dielect)
37 +    real(kind=dp), intent(in) :: this_dielect
38      
39 +    dielect = this_dielect
40 +    haveDielectric = .true.
41 +    
42 +    ! because setCutoffsCharge is called before initialize_charge
43 +    ! we need to call it agin to make sure all of the precalculation
44 +    ! value is correct. for the time being, just a quick hack
45 +    call setCutoffsCharge(ecr, rt)
46 +    return
47 +  end subroutine initialize_charge
48 +  
49 +    
50    subroutine setCutoffsCharge(this_ecr, this_rt)
51      real(kind=dp), intent(in) :: this_ecr, this_rt
52      ecr = this_ecr
# Line 36 | Line 54 | contains
54  
55      ! pre converts from fundamental charge to kcal/mol
56      pre = 332.06508_DP
57 <
57 >    
58 >    !if (.not.haveDielectric)then
59 >    !   write(default_error,*) 'Dielect constant in charge module is not set!'
60 >    !endif
61 >    
62      haveCutoffs = .true.
63      
64      return
# Line 78 | Line 100 | contains
100    end subroutine createChargeMap
101    
102    
103 <  subroutine do_charge_pair(atom1, atom2, d, rij, r2, pot, f, &
104 <       do_pot, do_stress)
103 >  subroutine do_charge_pair(atom1, atom2, d, rij, r2, dc, rcij, rc2, mfact, &
104 >       pot, f, do_pot, do_stress, molecular_cutoffs)
105      
106 <    logical :: do_pot, do_stress
106 >    logical :: do_pot, do_stress, molecular_cutoffs
107  
108      integer atom1, atom2, me1, me2, id1, id2
109      integer :: localError
110 <    real(kind=dp) :: rij, r2, q1, q2
110 >    real(kind=dp) :: rij, r2, q1, q2, rcij, rc2
111      real(kind=dp) :: drdx, drdy, drdz, dudr, fx, fy, fz
112      real(kind=dp) :: taper, dtdr, vterm
113  
114      real( kind = dp ) :: pot
115 <    real( kind = dp ), dimension(3) :: d
115 >    real( kind = dp ), dimension(3) :: d, dc
116      real( kind = dp ), dimension(3,nLocal) :: f
117 +    real( kind = dp ), dimension(nLocal) :: mfact
118 +    real( kind = dp ) :: theR, term1, term2, fxij, fyij, fzij
119 +    real( kind = dp ) :: fxab, fyab, fzab, fxba, fyba, fzba
120      
121      if (.not. haveCutoffs) then
122         write(default_error,*) 'charge-charge does not have cutoffs set!'
# Line 118 | Line 143 | contains
143      q1 = ChargeMap(me1)%charge
144      q2 = ChargeMap(me2)%charge
145  
146 <    if (rij.le.ecr) then
146 >    if (molecular_cutoffs) then
147 >       theR = rcij
148 >    else
149 >       theR = rij
150 >    endif
151 >
152 >    if (theR.le.ecr) then
153        
154 <       if (rij.lt.rt) then
154 >       if (theR.lt.rt) then
155            taper = 1.0d0
156            dtdr = 0.0d0
157         else
158 <          taper = (ecr + 2.0d0*rij - 3.0d0*rt)*(ecr-rij)**2/ ((ecr-rt)**3)
159 <          dtdr = 6.0d0*(rij*rij - rij*rt - rij*ecr +ecr*rt)/((ecr-rt)**3)
158 >          taper = (ecr + 2.0d0*theR - 3.0d0*rt)*(ecr-theR)**2/ ((ecr-rt)**3)
159 >          dtdr = 6.0d0*(theR*theR - theR*rt - theR*ecr +ecr*rt)/((ecr-rt)**3)
160         endif
161  
162 <       vterm = pre * q1 * q2 / rij
162 >       vterm = pre * q1 * q2 / rij
163  
164 <       dudr = vterm * ( dtdr  - taper / rij )
164 >       if (molecular_cutoffs) then
165  
166 <       drdx = d(1) / rij
167 <       drdy = d(2) / rij
168 <       drdz = d(3) / rij
166 >          term1 = vterm * (taper / rij)
167 >        
168 >          fxij = term1 * d(1) / rij
169 >          fyij = term1 * d(2) / rij
170 >          fzij = term1 * d(3) / rij
171  
172 <       fx = dudr * drdx
140 <       fy = dudr * drdy
141 <       fz = dudr * drdz          
172 >          term2 = vterm * dtdr * mfact(atom1)
173  
174 +          fxab = term2 * dc(1) / rcij
175 +          fyab = term2 * dc(2) / rcij
176 +          fzab = term2 * dc(3) / rcij
177 +
178 +          term2 = vterm * dtdr * mfact(atom2)
179 +
180 +          fxba = term2 * dc(1) / rcij
181 +          fyba = term2 * dc(2) / rcij
182 +          fzba = term2 * dc(3) / rcij
183 +
184 +       else
185 +
186 +          dudr =  vterm * (dtdr  - taper / rij)
187 +          drdx = d(1) / rij
188 +          drdy = d(2) / rij
189 +          drdz = d(3) / rij
190 +          
191 +          fx = dudr * drdx
192 +          fy = dudr * drdy
193 +          fz = dudr * drdz          
194 +
195 +       endif
196 +
197 +
198   #ifdef IS_MPI
199         if (do_pot) then
200            pot_Row(atom1) = pot_Row(atom1) + vterm*taper*0.5
# Line 154 | Line 209 | contains
209         f_Col(2,atom2) = f_Col(2,atom2) - fy
210         f_Col(3,atom2) = f_Col(3,atom2) - fz
211  
212 +       if (molecular_cutoffs) then
213 +          f_Row(1,atom1) = f_Row(1,atom1) + fxab
214 +          f_Row(2,atom1) = f_Row(2,atom1) + fyab
215 +          f_Row(3,atom1) = f_Row(3,atom1) + fzab
216 +          
217 +          f_Col(1,atom2) = f_Col(1,atom2) - fxba
218 +          f_Col(2,atom2) = f_Col(2,atom2) - fyba
219 +          f_Col(3,atom2) = f_Col(3,atom2) - fzba
220 +       endif
221 +
222   #else
223  
224         if (do_pot) pot = pot + vterm*taper
# Line 166 | Line 231 | contains
231         f(2,atom2) = f(2,atom2) - fy
232         f(3,atom2) = f(3,atom2) - fz
233  
234 +       if (molecular_cutoffs) then
235 +          f(1,atom1) = f(1,atom1) + fxab
236 +          f(2,atom1) = f(2,atom1) + fyab
237 +          f(3,atom1) = f(3,atom1) + fzab
238 +          
239 +          f(1,atom2) = f(1,atom2) - fxba
240 +          f(2,atom2) = f(2,atom2) - fyba
241 +          f(3,atom2) = f(3,atom2) - fzba
242 +       endif
243 +
244   #endif
245  
246         if (do_stress) then
# Line 177 | Line 252 | contains
252            id1 = atom1
253            id2 = atom2
254   #endif
255 +
256  
257            if (molMembershipList(id1) .ne. molMembershipList(id2)) then
258 <            
258 >
259               ! because the d vector is the rj - ri vector, and
260               ! because fx, fy, fz are the force on atom i, we need a
261               ! negative sign here:
# Line 190 | Line 266 | contains
266               tau_Temp(4) = tau_Temp(4) - d(2) * fx
267               tau_Temp(5) = tau_Temp(5) - d(2) * fy
268               tau_Temp(6) = tau_Temp(6) - d(2) * fz
193             tau_Temp(7) = tau_Temp(7) - d(3) * fx
269               tau_Temp(8) = tau_Temp(8) - d(3) * fy
270               tau_Temp(9) = tau_Temp(9) - d(3) * fz
271 +
272 +             if (molecular_cutoffs) then
273 +                
274 +                tau_Temp(1) = tau_Temp(1) - d(1) * fxab
275 +                tau_Temp(2) = tau_Temp(2) - d(1) * fyab
276 +                tau_Temp(3) = tau_Temp(3) - d(1) * fzab
277 +                tau_Temp(4) = tau_Temp(4) - d(2) * fxab
278 +                tau_Temp(5) = tau_Temp(5) - d(2) * fyab
279 +                tau_Temp(6) = tau_Temp(6) - d(2) * fzab
280 +                tau_Temp(8) = tau_Temp(8) - d(3) * fyab
281 +                tau_Temp(9) = tau_Temp(9) - d(3) * fzab
282 +             endif
283              
284               virial_Temp = virial_Temp + &
285                    (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines