1 |
< |
subroutine accumulate_rf(atom1, atom2, rij) |
1 |
> |
module reaction_field |
2 |
> |
use simulation |
3 |
> |
use definitions |
4 |
> |
use atype_module |
5 |
> |
use vector_class |
6 |
> |
#ifdef IS_MPI |
7 |
> |
use mpiSimulation |
8 |
> |
#endif |
9 |
> |
implicit none |
10 |
|
|
11 |
< |
include 'sizes.inc' |
4 |
< |
include 'simulation.inc' |
11 |
> |
contains |
12 |
|
|
13 |
< |
integer atom1, atom2 |
7 |
< |
double precision taper, rij |
13 |
> |
subroutine accumulate_rf(atom1, atom2, rij, u_l) |
14 |
|
|
15 |
< |
if (rij.le.rrf) then |
16 |
< |
|
17 |
< |
if (rij.lt.rt) then |
12 |
< |
taper = 1.0d0 |
13 |
< |
else |
14 |
< |
taper = (rrf + 2.0d0*rij - 3.0d0*rt)*(rrf-rij)**2/ ((rrf-rt)**3) |
15 |
< |
endif |
16 |
< |
|
17 |
< |
rflx(atom1) = rflx(atom1) + ulx(atom2)*mu(atom2)*taper |
18 |
< |
rfly(atom1) = rfly(atom1) + uly(atom2)*mu(atom2)*taper |
19 |
< |
rflz(atom1) = rflz(atom1) + ulz(atom2)*mu(atom2)*taper |
20 |
< |
|
21 |
< |
rflx(atom2) = rflx(atom2) + ulx(atom1)*mu(atom1)*taper |
22 |
< |
rfly(atom2) = rfly(atom2) + uly(atom1)*mu(atom1)*taper |
23 |
< |
rflz(atom2) = rflz(atom2) + ulz(atom1)*mu(atom1)*taper |
15 |
> |
integer, intent(in) :: atom1, atom2 |
16 |
> |
real (kind = dp), intent(in) :: rij |
17 |
> |
real (kind = dp), dimension(3, getNlocal()) :: u_l |
18 |
|
|
19 |
< |
endif |
20 |
< |
return |
21 |
< |
|
22 |
< |
end subroutine accumulate_rf |
19 |
> |
integer :: me1, me2 |
20 |
> |
real (kind = dp) :: rrf, rt, taper, mu1, mu2 |
21 |
> |
real (kind = dp), dimension(3) :: ul1 |
22 |
> |
real (kind = dp), dimension(3) :: ul2 |
23 |
> |
|
24 |
> |
rrf = getRrf() |
25 |
> |
|
26 |
> |
if (rij.le.rrf) then |
27 |
> |
|
28 |
> |
rt = getRt() |
29 |
> |
|
30 |
> |
if (rij.lt.rt) then |
31 |
> |
taper = 1.0d0 |
32 |
> |
else |
33 |
> |
taper = (rrf + 2.0d0*rij - 3.0d0*rt)*(rrf-rij)**2/ ((rrf-rt)**3) |
34 |
> |
endif |
35 |
> |
|
36 |
> |
#ifdef IS_MPI |
37 |
> |
me1 = atid_Row(atom1) |
38 |
> |
ul1(1) = u_l_Row(1,atom1) |
39 |
> |
ul1(2) = u_l_Row(2,atom1) |
40 |
> |
ul1(3) = u_l_Row(3,atom1) |
41 |
> |
|
42 |
> |
me2 = atid_Col(atom2) |
43 |
> |
ul2(1) = u_l_Col(1,atom2) |
44 |
> |
ul2(2) = u_l_Col(2,atom2) |
45 |
> |
ul2(3) = u_l_Col(3,atom2) |
46 |
> |
#else |
47 |
> |
me1 = atid(atom1) |
48 |
> |
ul1(1) = u_l(1,atom1) |
49 |
> |
ul1(2) = u_l(2,atom1) |
50 |
> |
ul1(3) = u_l(3,atom1) |
51 |
> |
|
52 |
> |
me2 = atid(atom2) |
53 |
> |
ul2(1) = u_l(1,atom2) |
54 |
> |
ul2(2) = u_l(2,atom2) |
55 |
> |
ul2(3) = u_l(3,atom2) |
56 |
> |
#endif |
57 |
> |
|
58 |
> |
call getElementProperty(atypes, me1, "dipole_moment", mu1) |
59 |
> |
call getElementProperty(atypes, me2, "dipole_moment", mu2) |
60 |
> |
|
61 |
> |
|
62 |
> |
#ifdef IS_MPI |
63 |
> |
rf_Row(1,atom1) = rf_Row(1,atom1) + ul2(1)*mu2*taper |
64 |
> |
rf_Row(2,atom1) = rf_Row(2,atom1) + ul2(2)*mu2*taper |
65 |
> |
rf_Row(3,atom1) = rf_Row(3,atom1) + ul2(3)*mu2*taper |
66 |
> |
|
67 |
> |
rf_Col(1,atom2) = rf_Col(1,atom2) + ul1(1)*mu2*taper |
68 |
> |
rf_Col(2,atom2) = rf_Col(2,atom2) + ul1(2)*mu2*taper |
69 |
> |
rf_Col(3,atom2) = rf_Col(3,atom2) + ul1(3)*mu2*taper |
70 |
> |
#else |
71 |
> |
rf(1,atom1) = rf(1,atom1) + ul2(1)*mu2*taper |
72 |
> |
rf(2,atom1) = rf(2,atom1) + ul2(2)*mu2*taper |
73 |
> |
rf(3,atom1) = rf(3,atom1) + ul2(3)*mu2*taper |
74 |
> |
|
75 |
> |
rf(1,atom2) = rf(1,atom2) + ul1(1)*mu2*taper |
76 |
> |
rf(2,atom2) = rf(2,atom2) + ul1(2)*mu2*taper |
77 |
> |
rf(3,atom2) = rf(3,atom2) + ul1(3)*mu2*taper |
78 |
> |
#endif |
79 |
> |
|
80 |
> |
endif |
81 |
> |
return |
82 |
> |
end subroutine accumulate_rf |
83 |
|
|
84 |
< |
subroutine accumulate_self_rf() |
85 |
< |
|
86 |
< |
include 'sizes.inc' |
87 |
< |
include 'simulation.inc' |
88 |
< |
|
89 |
< |
integer i, ia, a1, atype1 |
90 |
< |
logical is_dipole_atype |
91 |
< |
external is_dipole_atype |
92 |
< |
|
93 |
< |
do i = 1, nmol |
40 |
< |
do ia = 1, na(i) |
41 |
< |
a1 = atom_index(i,ia) |
42 |
< |
|
43 |
< |
atype1 = atype(a1) |
84 |
> |
subroutine accumulate_self_rf(atom1, mu1, u_l) |
85 |
> |
|
86 |
> |
integer, intent(in) :: atom1 |
87 |
> |
real(kind=dp), intent(in) :: mu1 |
88 |
> |
real(kind=dp), dimension(3,getNlocal()) :: u_l |
89 |
> |
|
90 |
> |
!! should work for both MPI and non-MPI version since this is not pairwise. |
91 |
> |
rf(1,atom1) = rf(1,atom1) + u_l(1,atom1)*mu1 |
92 |
> |
rf(2,atom1) = rf(2,atom1) + u_l(2,atom1)*mu1 |
93 |
> |
rf(3,atom1) = rf(3,atom1) + u_l(3,atom1)*mu1 |
94 |
|
|
95 |
< |
if (is_dipole_atype(atype1)) then |
96 |
< |
|
47 |
< |
rflx(a1) = rflx(a1) + ulx(a1)*mu(a1) |
48 |
< |
rfly(a1) = rfly(a1) + uly(a1)*mu(a1) |
49 |
< |
rflz(a1) = rflz(a1) + ulz(a1)*mu(a1) |
50 |
< |
|
51 |
< |
endif |
52 |
< |
enddo |
53 |
< |
enddo |
54 |
< |
|
55 |
< |
return |
56 |
< |
end subroutine accumulate_self_rf |
57 |
< |
|
58 |
< |
subroutine reaction_field(pot) |
95 |
> |
return |
96 |
> |
end subroutine accumulate_self_rf |
97 |
|
|
98 |
< |
include 'sizes.inc' |
99 |
< |
include 'simulation.inc' |
98 |
> |
subroutine reaction_field(a1, mu1, u_l, rfpot, t, do_pot) |
99 |
> |
|
100 |
> |
! compute torques on dipoles: |
101 |
> |
! pre converts from mu in units of debye to kcal/mol |
102 |
> |
|
103 |
> |
rrf = getRrf() |
104 |
> |
dielect = getDielect() |
105 |
> |
rrfsq = rrf * rrf |
106 |
> |
pre = 14.38362d0*2.0d0*(dielect-1.0d0)/((2.0d0*dielect+1.0d0)*rrfsq*rrf) |
107 |
> |
|
108 |
> |
! The torque contribution is dipole cross reaction_field |
109 |
> |
|
110 |
> |
t(1,a1) = t(1,a1) + pre*mu1*(u_l(2,a1)*rf(3,a1) - u_l(3,a1)*rf(2,a1)) |
111 |
> |
t(2,a1) = t(2,a1) + pre*mu1*(u_l(3,a1)*rf(1,a1) - u_l(1,a1)*rf(3,a1)) |
112 |
> |
t(3,a1) = t(3,a1) + pre*mu1*(u_l(1,a1)*rf(2,a1) - u_l(2,a1)*rf(1,a1)) |
113 |
> |
|
114 |
> |
! the potential contribution is -1/2 dipole dot reaction_field |
115 |
> |
|
116 |
> |
if (do_pot) then |
117 |
> |
rfpot = rfpot - 0.5d0 * pre * mu1 * & |
118 |
> |
(rf(1,a1)*u_l(1,a1) + rf(2,a1)*u_l(2,a1) + rf(3,a1)*u_l(3,a1)) |
119 |
> |
endif |
120 |
> |
|
121 |
> |
return |
122 |
> |
end subroutine reaction_field |
123 |
|
|
124 |
< |
double precision rrfsq, pre |
64 |
< |
integer i, ia, a1, atype1 |
65 |
< |
logical is_dipole_atype |
66 |
< |
external is_dipole_atype |
67 |
< |
|
68 |
< |
! do single loop to compute torques on dipoles: |
69 |
< |
! pre converts from mu in units of debye to kcal/mol |
70 |
< |
|
71 |
< |
rrfsq = rrf * rrf |
72 |
< |
pre = 14.38362d0*2.0d0*(dielect-1.0d0)/((2.0d0*dielect+1.0d0)*rrfsq*rrf) |
73 |
< |
|
74 |
< |
do i = 1, nmol |
75 |
< |
do ia = 1, na(i) |
76 |
< |
a1 = atom_index(i,ia) |
77 |
< |
|
78 |
< |
atype1 = atype(a1) |
79 |
< |
|
80 |
< |
if (is_dipole_atype(atype1)) then |
81 |
< |
|
82 |
< |
! The torque contribution is dipole cross reaction_field |
83 |
< |
|
84 |
< |
tlx(a1) = tlx(a1) + pre*mu(a1)*(uly(a1)*rflz(a1) - ulz(a1)*rfly(a1)) |
85 |
< |
tly(a1) = tly(a1) + pre*mu(a1)*(ulz(a1)*rflx(a1) - ulx(a1)*rflz(a1)) |
86 |
< |
tlz(a1) = tlz(a1) + pre*mu(a1)*(ulx(a1)*rfly(a1) - uly(a1)*rflx(a1)) |
87 |
< |
|
88 |
< |
! the potential contribution is -1/2 dipole dot reaction_field |
89 |
< |
|
90 |
< |
pot = pot - 0.5d0 * pre * mu(a1) * & |
91 |
< |
(rflx(a1)*ulx(a1) + rfly(a1)*uly(a1) + rflz(a1)*ulz(a1)) |
92 |
< |
|
93 |
< |
endif |
94 |
< |
|
95 |
< |
enddo |
96 |
< |
enddo |
97 |
< |
|
98 |
< |
end subroutine reaction_field |
99 |
< |
|
100 |
< |
subroutine rf_correct_forces(atom1, atom2, dx, dy, dz, rij) |
101 |
< |
include 'sizes.inc' |
102 |
< |
include 'simulation.inc' |
103 |
< |
|
104 |
< |
integer atom1, atom2 |
105 |
< |
double precision dtdr, rrfsq, prerf, rij |
106 |
< |
double precision dudx, dudy, dudz, u1dotu2, dx, dy, dz |
107 |
< |
|
108 |
< |
rrfsq = rrf * rrf |
109 |
< |
prerf = 14.38362d0*2.0d0*(dielect-1.0d0)/((2.0d0*dielect+1.0d0)*rrfsq*rrf) |
110 |
< |
|
111 |
< |
if (rij.le.rrf) then |
112 |
< |
|
113 |
< |
! cubic taper |
114 |
< |
if (rij.lt.rt) then |
115 |
< |
dtdr = 0.0d0 |
116 |
< |
else |
117 |
< |
dtdr = 6.0d0*(rij*rij - rij*rt - rij*rrf +rrf*rt)/((rrf-rt)**3) |
118 |
< |
endif |
119 |
< |
|
120 |
< |
u1dotu2 = ulx(atom1)*ulx(atom2) + uly(atom1)*uly(atom2) + & |
121 |
< |
ulz(atom1)*ulz(atom2) |
122 |
< |
|
123 |
< |
dudx = - prerf*mu(atom1)*mu(atom2)*u1dotu2*dtdr*dx/rij |
124 |
< |
dudy = - prerf*mu(atom1)*mu(atom2)*u1dotu2*dtdr*dy/rij |
125 |
< |
dudz = - prerf*mu(atom1)*mu(atom2)*u1dotu2*dtdr*dz/rij |
126 |
< |
|
127 |
< |
flx(atom1) = flx(atom1) + dudx |
128 |
< |
fly(atom1) = fly(atom1) + dudy |
129 |
< |
flz(atom1) = flz(atom1) + dudz |
124 |
> |
subroutine rf_correct_forces(atom1, atom2, d, rij, u_l, f, do_stress) |
125 |
|
|
126 |
< |
flx(atom2) = flx(atom2) - dudx |
127 |
< |
fly(atom2) = fly(atom2) - dudy |
128 |
< |
flz(atom2) = flz(atom2) - dudz |
129 |
< |
|
130 |
< |
! add contribution to the virial as well |
131 |
< |
virial = virial + ( dx*dudx + dy*dudy + dz*dudz ) |
132 |
< |
|
133 |
< |
endif |
134 |
< |
|
135 |
< |
return |
136 |
< |
end subroutine rf_correct_forces |
126 |
> |
integer, intent(in) :: atom1, atom2 |
127 |
> |
real(kind=dp), dimension(3), intent(in) :: d |
128 |
> |
real(kind=dp), intent(in) :: rij |
129 |
> |
real( kind = dp ), dimension(3,getNlocal()) :: u_l |
130 |
> |
real( kind = dp ), dimension(3,getNlocal()) :: f |
131 |
> |
logical, intent(in) :: do_stress |
132 |
> |
|
133 |
> |
real (kind = dp), dimension(3) :: ul1 |
134 |
> |
real (kind = dp), dimension(3) :: ul2 |
135 |
> |
real (kind = dp) :: dtdr, rrfsq, prerf |
136 |
> |
real (kind = dp) :: dudx, dudy, dudz, u1dotu2 |
137 |
> |
|
138 |
> |
rrf = getRrf() |
139 |
> |
|
140 |
> |
if (rij.le.rrf) then |
141 |
> |
|
142 |
> |
rrfsq = rrf * rrf |
143 |
> |
dielect = getDielect() |
144 |
> |
prerf = 14.38362d0*2.0d0*(dielect-1.0d0)/((2.0d0*dielect+1.0d0)*rrfsq*rrf) |
145 |
> |
rt = getRt() |
146 |
> |
|
147 |
> |
if (rij.lt.rt) then |
148 |
> |
dtdr = 0.0d0 |
149 |
> |
else |
150 |
> |
dtdr = 6.0d0*(rij*rij - rij*rt - rij*rrf +rrf*rt)/((rrf-rt)**3) |
151 |
> |
endif |
152 |
> |
|
153 |
> |
#ifdef IS_MPI |
154 |
> |
me1 = atid_Row(atom1) |
155 |
> |
ul1(1) = u_l_Row(1,atom1) |
156 |
> |
ul1(2) = u_l_Row(2,atom1) |
157 |
> |
ul1(3) = u_l_Row(3,atom1) |
158 |
> |
|
159 |
> |
me2 = atid_Col(atom2) |
160 |
> |
ul2(1) = u_l_Col(1,atom2) |
161 |
> |
ul2(2) = u_l_Col(2,atom2) |
162 |
> |
ul2(3) = u_l_Col(3,atom2) |
163 |
> |
#else |
164 |
> |
me1 = atid(atom1) |
165 |
> |
ul1(1) = u_l(1,atom1) |
166 |
> |
ul1(2) = u_l(2,atom1) |
167 |
> |
ul1(3) = u_l(3,atom1) |
168 |
> |
|
169 |
> |
me2 = atid(atom2) |
170 |
> |
ul2(1) = u_l(1,atom2) |
171 |
> |
ul2(2) = u_l(2,atom2) |
172 |
> |
ul2(3) = u_l(3,atom2) |
173 |
> |
#endif |
174 |
> |
|
175 |
> |
call getElementProperty(atypes, me1, "dipole_moment", mu1) |
176 |
> |
call getElementProperty(atypes, me2, "dipole_moment", mu2) |
177 |
> |
|
178 |
> |
u1dotu2 = ul1(1)*ul2(1) + ul1(2)*ul2(2) + ul1(3)*ul2(3) |
179 |
> |
|
180 |
> |
dudx = - prerf*mu1*mu2*u1dotu2*dtdr*d(1)/rij |
181 |
> |
dudy = - prerf*mu1*mu2*u1dotu2*dtdr*d(2)/rij |
182 |
> |
dudz = - prerf*mu1*mu2*u1dotu2*dtdr*d(3)/rij |
183 |
> |
|
184 |
> |
#ifdef IS_MPI |
185 |
> |
f_Row(1,atom1) = f_Row(1,atom1) + dudx |
186 |
> |
f_Row(2,atom1) = f_Row(2,atom1) + dudy |
187 |
> |
f_Row(3,atom1) = f_Row(3,atom1) + dudz |
188 |
> |
|
189 |
> |
f_Col(1,atom2) = f_Col(1,atom2) - dudx |
190 |
> |
f_Col(2,atom2) = f_Col(2,atom2) - dudy |
191 |
> |
f_Col(3,atom2) = f_Col(3,atom2) - dudz |
192 |
> |
#else |
193 |
> |
f(1,atom1) = f(1,atom1) + dudx |
194 |
> |
f(2,atom1) = f(2,atom1) + dudy |
195 |
> |
f(3,atom1) = f(3,atom1) + dudz |
196 |
> |
|
197 |
> |
f(1,atom2) = f(1,atom2) - dudx |
198 |
> |
f(2,atom2) = f(2,atom2) - dudy |
199 |
> |
f(3,atom2) = f(3,atom2) - dudz |
200 |
> |
#endif |
201 |
> |
|
202 |
> |
if (do_stress) then |
203 |
> |
tau_Temp(1) = tau_Temp(1) + dudx * d(1) |
204 |
> |
tau_Temp(2) = tau_Temp(2) + dudx * d(2) |
205 |
> |
tau_Temp(3) = tau_Temp(3) + dudx * d(3) |
206 |
> |
tau_Temp(4) = tau_Temp(4) + dudy * d(1) |
207 |
> |
tau_Temp(5) = tau_Temp(5) + dudy * d(2) |
208 |
> |
tau_Temp(6) = tau_Temp(6) + dudy * d(3) |
209 |
> |
tau_Temp(7) = tau_Temp(7) + dudz * d(1) |
210 |
> |
tau_Temp(8) = tau_Temp(8) + dudz * d(2) |
211 |
> |
tau_Temp(9) = tau_Temp(9) + dudz * d(3) |
212 |
> |
virial_Temp = virial_Temp + (tau_Temp(1) + tau_Temp(5) + tau_Temp(9)) |
213 |
> |
endif |
214 |
> |
|
215 |
> |
endif |
216 |
> |
|
217 |
> |
return |
218 |
> |
end subroutine rf_correct_forces |
219 |
> |
end module reaction_field |