1 |
mmeineke |
377 |
module reaction_field |
2 |
|
|
use force_globals |
3 |
|
|
use definitions |
4 |
|
|
use atype_module |
5 |
|
|
use vector_class |
6 |
chuckv |
460 |
use simulation |
7 |
mmeineke |
377 |
#ifdef IS_MPI |
8 |
|
|
use mpiSimulation |
9 |
|
|
#endif |
10 |
|
|
implicit none |
11 |
|
|
|
12 |
|
|
real(kind=dp), save :: rrf |
13 |
|
|
real(kind=dp), save :: rt |
14 |
|
|
real(kind=dp), save :: dielect |
15 |
|
|
real(kind=dp), save :: rrfsq |
16 |
|
|
real(kind=dp), save :: pre |
17 |
|
|
logical, save :: rf_initialized = .false. |
18 |
|
|
|
19 |
|
|
contains |
20 |
|
|
|
21 |
|
|
subroutine initialize_rf(this_rrf, this_rt, this_dielect) |
22 |
|
|
real(kind=dp), intent(in) :: this_rrf, this_rt, this_dielect |
23 |
|
|
|
24 |
|
|
rrf = this_rrf |
25 |
|
|
rt = this_rt |
26 |
|
|
dielect = this_dielect |
27 |
|
|
|
28 |
|
|
rrfsq = rrf * rrf |
29 |
|
|
pre = 14.38362d0*2.0d0*(dielect-1.0d0)/((2.0d0*dielect+1.0d0)*rrfsq*rrf) |
30 |
|
|
|
31 |
gezelter |
394 |
|
32 |
|
|
write(*,*) 'rrf = ', rrf |
33 |
|
|
write(*,*) 'rt = ', rt |
34 |
|
|
write(*,*) 'dielect = ', dielect |
35 |
|
|
write(*,*) 'pre = ', pre |
36 |
mmeineke |
377 |
rf_initialized = .true. |
37 |
|
|
|
38 |
|
|
return |
39 |
|
|
end subroutine initialize_rf |
40 |
|
|
|
41 |
|
|
subroutine accumulate_rf(atom1, atom2, rij, u_l) |
42 |
|
|
|
43 |
|
|
integer, intent(in) :: atom1, atom2 |
44 |
|
|
real (kind = dp), intent(in) :: rij |
45 |
chuckv |
460 |
real (kind = dp), dimension(3,getNlocal()) :: u_l |
46 |
mmeineke |
377 |
|
47 |
|
|
integer :: me1, me2 |
48 |
|
|
real (kind = dp) :: taper, mu1, mu2 |
49 |
|
|
real (kind = dp), dimension(3) :: ul1 |
50 |
|
|
real (kind = dp), dimension(3) :: ul2 |
51 |
|
|
|
52 |
|
|
if (.not.rf_initialized) then |
53 |
|
|
write(default_error,*) 'Reaction field not initialized!' |
54 |
|
|
return |
55 |
|
|
endif |
56 |
|
|
|
57 |
|
|
if (rij.le.rrf) then |
58 |
|
|
|
59 |
|
|
if (rij.lt.rt) then |
60 |
|
|
taper = 1.0d0 |
61 |
|
|
else |
62 |
|
|
taper = (rrf + 2.0d0*rij - 3.0d0*rt)*(rrf-rij)**2/ ((rrf-rt)**3) |
63 |
|
|
endif |
64 |
|
|
|
65 |
|
|
#ifdef IS_MPI |
66 |
|
|
me1 = atid_Row(atom1) |
67 |
|
|
ul1(1) = u_l_Row(1,atom1) |
68 |
|
|
ul1(2) = u_l_Row(2,atom1) |
69 |
|
|
ul1(3) = u_l_Row(3,atom1) |
70 |
|
|
|
71 |
|
|
me2 = atid_Col(atom2) |
72 |
|
|
ul2(1) = u_l_Col(1,atom2) |
73 |
|
|
ul2(2) = u_l_Col(2,atom2) |
74 |
|
|
ul2(3) = u_l_Col(3,atom2) |
75 |
|
|
#else |
76 |
|
|
me1 = atid(atom1) |
77 |
|
|
ul1(1) = u_l(1,atom1) |
78 |
|
|
ul1(2) = u_l(2,atom1) |
79 |
|
|
ul1(3) = u_l(3,atom1) |
80 |
|
|
|
81 |
|
|
me2 = atid(atom2) |
82 |
|
|
ul2(1) = u_l(1,atom2) |
83 |
|
|
ul2(2) = u_l(2,atom2) |
84 |
|
|
ul2(3) = u_l(3,atom2) |
85 |
|
|
#endif |
86 |
|
|
|
87 |
|
|
call getElementProperty(atypes, me1, "dipole_moment", mu1) |
88 |
|
|
call getElementProperty(atypes, me2, "dipole_moment", mu2) |
89 |
|
|
|
90 |
|
|
|
91 |
|
|
#ifdef IS_MPI |
92 |
|
|
rf_Row(1,atom1) = rf_Row(1,atom1) + ul2(1)*mu2*taper |
93 |
|
|
rf_Row(2,atom1) = rf_Row(2,atom1) + ul2(2)*mu2*taper |
94 |
|
|
rf_Row(3,atom1) = rf_Row(3,atom1) + ul2(3)*mu2*taper |
95 |
|
|
|
96 |
gezelter |
394 |
rf_Col(1,atom2) = rf_Col(1,atom2) + ul1(1)*mu1*taper |
97 |
|
|
rf_Col(2,atom2) = rf_Col(2,atom2) + ul1(2)*mu1*taper |
98 |
|
|
rf_Col(3,atom2) = rf_Col(3,atom2) + ul1(3)*mu1*taper |
99 |
mmeineke |
377 |
#else |
100 |
|
|
rf(1,atom1) = rf(1,atom1) + ul2(1)*mu2*taper |
101 |
|
|
rf(2,atom1) = rf(2,atom1) + ul2(2)*mu2*taper |
102 |
|
|
rf(3,atom1) = rf(3,atom1) + ul2(3)*mu2*taper |
103 |
|
|
|
104 |
gezelter |
394 |
rf(1,atom2) = rf(1,atom2) + ul1(1)*mu1*taper |
105 |
|
|
rf(2,atom2) = rf(2,atom2) + ul1(2)*mu1*taper |
106 |
|
|
rf(3,atom2) = rf(3,atom2) + ul1(3)*mu1*taper |
107 |
mmeineke |
377 |
#endif |
108 |
|
|
|
109 |
|
|
endif |
110 |
|
|
return |
111 |
|
|
end subroutine accumulate_rf |
112 |
|
|
|
113 |
|
|
subroutine accumulate_self_rf(atom1, mu1, u_l) |
114 |
|
|
|
115 |
|
|
integer, intent(in) :: atom1 |
116 |
|
|
real(kind=dp), intent(in) :: mu1 |
117 |
chuckv |
460 |
real(kind=dp), dimension(3,getNlocal()) :: u_l |
118 |
mmeineke |
377 |
|
119 |
|
|
!! should work for both MPI and non-MPI version since this is not pairwise. |
120 |
|
|
rf(1,atom1) = rf(1,atom1) + u_l(1,atom1)*mu1 |
121 |
|
|
rf(2,atom1) = rf(2,atom1) + u_l(2,atom1)*mu1 |
122 |
|
|
rf(3,atom1) = rf(3,atom1) + u_l(3,atom1)*mu1 |
123 |
|
|
|
124 |
|
|
return |
125 |
|
|
end subroutine accumulate_self_rf |
126 |
|
|
|
127 |
|
|
subroutine reaction_field_final(a1, mu1, u_l, rfpot, t, do_pot) |
128 |
|
|
|
129 |
|
|
integer, intent(in) :: a1 |
130 |
|
|
real (kind=dp), intent(in) :: mu1 |
131 |
|
|
real (kind=dp), intent(inout) :: rfpot |
132 |
|
|
logical, intent(in) :: do_pot |
133 |
chuckv |
460 |
real (kind = dp), dimension(3,getNlocal()) :: u_l |
134 |
|
|
real (kind = dp), dimension(3,getNlocal()) :: t |
135 |
mmeineke |
377 |
|
136 |
|
|
if (.not.rf_initialized) then |
137 |
|
|
write(default_error,*) 'Reaction field not initialized!' |
138 |
|
|
return |
139 |
|
|
endif |
140 |
|
|
|
141 |
|
|
! compute torques on dipoles: |
142 |
|
|
! pre converts from mu in units of debye to kcal/mol |
143 |
|
|
|
144 |
gezelter |
394 |
! The torque contribution is dipole cross reaction_field |
145 |
|
|
|
146 |
mmeineke |
377 |
t(1,a1) = t(1,a1) + pre*mu1*(u_l(2,a1)*rf(3,a1) - u_l(3,a1)*rf(2,a1)) |
147 |
|
|
t(2,a1) = t(2,a1) + pre*mu1*(u_l(3,a1)*rf(1,a1) - u_l(1,a1)*rf(3,a1)) |
148 |
|
|
t(3,a1) = t(3,a1) + pre*mu1*(u_l(1,a1)*rf(2,a1) - u_l(2,a1)*rf(1,a1)) |
149 |
|
|
|
150 |
|
|
! the potential contribution is -1/2 dipole dot reaction_field |
151 |
|
|
|
152 |
|
|
if (do_pot) then |
153 |
|
|
rfpot = rfpot - 0.5d0 * pre * mu1 * & |
154 |
|
|
(rf(1,a1)*u_l(1,a1) + rf(2,a1)*u_l(2,a1) + rf(3,a1)*u_l(3,a1)) |
155 |
|
|
endif |
156 |
|
|
|
157 |
|
|
return |
158 |
|
|
end subroutine reaction_field_final |
159 |
|
|
|
160 |
|
|
subroutine rf_correct_forces(atom1, atom2, d, rij, u_l, f, do_stress) |
161 |
|
|
|
162 |
|
|
integer, intent(in) :: atom1, atom2 |
163 |
|
|
real(kind=dp), dimension(3), intent(in) :: d |
164 |
|
|
real(kind=dp), intent(in) :: rij |
165 |
chuckv |
460 |
real( kind = dp ), dimension(3,getNlocal()) :: u_l |
166 |
|
|
real( kind = dp ), dimension(3,getNlocal()) :: f |
167 |
mmeineke |
377 |
logical, intent(in) :: do_stress |
168 |
|
|
|
169 |
|
|
real (kind = dp), dimension(3) :: ul1 |
170 |
|
|
real (kind = dp), dimension(3) :: ul2 |
171 |
|
|
real (kind = dp) :: dtdr |
172 |
|
|
real (kind = dp) :: dudx, dudy, dudz, u1dotu2 |
173 |
|
|
integer :: me1, me2 |
174 |
|
|
real (kind = dp) :: mu1, mu2 |
175 |
|
|
|
176 |
|
|
if (.not.rf_initialized) then |
177 |
|
|
write(default_error,*) 'Reaction field not initialized!' |
178 |
|
|
return |
179 |
|
|
endif |
180 |
|
|
|
181 |
|
|
if (rij.le.rrf) then |
182 |
|
|
|
183 |
|
|
if (rij.lt.rt) then |
184 |
|
|
dtdr = 0.0d0 |
185 |
|
|
else |
186 |
|
|
dtdr = 6.0d0*(rij*rij - rij*rt - rij*rrf +rrf*rt)/((rrf-rt)**3) |
187 |
|
|
endif |
188 |
|
|
|
189 |
|
|
#ifdef IS_MPI |
190 |
|
|
me1 = atid_Row(atom1) |
191 |
|
|
ul1(1) = u_l_Row(1,atom1) |
192 |
|
|
ul1(2) = u_l_Row(2,atom1) |
193 |
|
|
ul1(3) = u_l_Row(3,atom1) |
194 |
|
|
|
195 |
|
|
me2 = atid_Col(atom2) |
196 |
|
|
ul2(1) = u_l_Col(1,atom2) |
197 |
|
|
ul2(2) = u_l_Col(2,atom2) |
198 |
|
|
ul2(3) = u_l_Col(3,atom2) |
199 |
|
|
#else |
200 |
|
|
me1 = atid(atom1) |
201 |
|
|
ul1(1) = u_l(1,atom1) |
202 |
|
|
ul1(2) = u_l(2,atom1) |
203 |
|
|
ul1(3) = u_l(3,atom1) |
204 |
|
|
|
205 |
|
|
me2 = atid(atom2) |
206 |
|
|
ul2(1) = u_l(1,atom2) |
207 |
|
|
ul2(2) = u_l(2,atom2) |
208 |
|
|
ul2(3) = u_l(3,atom2) |
209 |
|
|
#endif |
210 |
|
|
|
211 |
|
|
call getElementProperty(atypes, me1, "dipole_moment", mu1) |
212 |
|
|
call getElementProperty(atypes, me2, "dipole_moment", mu2) |
213 |
|
|
|
214 |
|
|
u1dotu2 = ul1(1)*ul2(1) + ul1(2)*ul2(2) + ul1(3)*ul2(3) |
215 |
|
|
|
216 |
|
|
dudx = - pre*mu1*mu2*u1dotu2*dtdr*d(1)/rij |
217 |
|
|
dudy = - pre*mu1*mu2*u1dotu2*dtdr*d(2)/rij |
218 |
|
|
dudz = - pre*mu1*mu2*u1dotu2*dtdr*d(3)/rij |
219 |
|
|
|
220 |
|
|
#ifdef IS_MPI |
221 |
|
|
f_Row(1,atom1) = f_Row(1,atom1) + dudx |
222 |
|
|
f_Row(2,atom1) = f_Row(2,atom1) + dudy |
223 |
|
|
f_Row(3,atom1) = f_Row(3,atom1) + dudz |
224 |
|
|
|
225 |
|
|
f_Col(1,atom2) = f_Col(1,atom2) - dudx |
226 |
|
|
f_Col(2,atom2) = f_Col(2,atom2) - dudy |
227 |
|
|
f_Col(3,atom2) = f_Col(3,atom2) - dudz |
228 |
|
|
#else |
229 |
|
|
f(1,atom1) = f(1,atom1) + dudx |
230 |
|
|
f(2,atom1) = f(2,atom1) + dudy |
231 |
|
|
f(3,atom1) = f(3,atom1) + dudz |
232 |
|
|
|
233 |
|
|
f(1,atom2) = f(1,atom2) - dudx |
234 |
|
|
f(2,atom2) = f(2,atom2) - dudy |
235 |
|
|
f(3,atom2) = f(3,atom2) - dudz |
236 |
|
|
#endif |
237 |
|
|
|
238 |
|
|
if (do_stress) then |
239 |
gezelter |
483 |
if (molMembershipList(atom1) .ne. molMembershipList(atom2)) then |
240 |
gezelter |
611 |
|
241 |
|
|
! because the d vector is the rj - ri vector, and |
242 |
|
|
! because dudx, dudy, and dudz are the |
243 |
|
|
! (positive) force on atom i (negative on atom j) we need |
244 |
|
|
! a negative sign here: |
245 |
|
|
|
246 |
|
|
tau_Temp(1) = tau_Temp(1) - d(1) * dudx |
247 |
|
|
tau_Temp(2) = tau_Temp(2) - d(1) * dudy |
248 |
|
|
tau_Temp(3) = tau_Temp(3) - d(1) * dudz |
249 |
|
|
tau_Temp(4) = tau_Temp(4) - d(2) * dudx |
250 |
|
|
tau_Temp(5) = tau_Temp(5) - d(2) * dudy |
251 |
|
|
tau_Temp(6) = tau_Temp(6) - d(2) * dudz |
252 |
|
|
tau_Temp(7) = tau_Temp(7) - d(3) * dudx |
253 |
|
|
tau_Temp(8) = tau_Temp(8) - d(3) * dudy |
254 |
|
|
tau_Temp(9) = tau_Temp(9) - d(3) * dudz |
255 |
gezelter |
483 |
virial_Temp = virial_Temp + & |
256 |
|
|
(tau_Temp(1) + tau_Temp(5) + tau_Temp(9)) |
257 |
|
|
endif |
258 |
mmeineke |
377 |
endif |
259 |
|
|
endif |
260 |
|
|
|
261 |
|
|
return |
262 |
|
|
end subroutine rf_correct_forces |
263 |
|
|
end module reaction_field |