MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
mod_DFT_DISP_WDA_d.F90
Go to the documentation of this file.
1 
5 
6 
7 
8 
9 
10 
11 ! Generated by TAPENADE (INRIA, Tropics team)
12 ! Tapenade 3.10 (r5498) - 20 Jan 2015 09:48
13 !
14 MODULE mod_dft_disp_wda_d
15  IMPLICIT NONE
16  PRIVATE
17  PUBLIC disp_weighted_densities_d
18  PUBLIC disp_mu_d
19  PUBLIC disp_dfdrho_wda_d
20 
21  CONTAINS
22 
23  ! Differentiation of disp_weighted_densities in forward (tangent) mode:
24 ! variations of useful results: rhop_wd
25 ! with respect to varying inputs: rhop
26  SUBROUTINE disp_weighted_densities_d(rhop, rhopd, rhop_wd, rhop_wdd, &
27 & user)
28  Use petscmanagement
29  USE basic_variables, ONLY : ncomp
30  USE mod_dft, ONLY : fa_disp, ab_disp, zp, dzp
31  IMPLICIT NONE
32 
33 #include <finclude/petscsys.h>
34 
35 !passed
36 type(userctx) :: user
37 petscscalar :: rhop(ncomp,user%gxs:user%gxe)
38 petscscalar :: rhopd(ncomp,user%gxs:user%gxe)
39 REAL, INTENT(OUT) :: rhop_wd(user%gxs:user%gxe,ncomp)
40 REAL, INTENT(OUT) :: rhop_wdd(user%gxs:user%gxe,ncomp)
41 
42 
43 ! ! !local
44 ! ! INTEGER :: i, j, k
45 ! ! INTEGER :: n
46 ! ! !Fehlermeldung einbauen, falls dim > 400!!
47 ! ! REAL :: x_int(400), y_int(400), y2(400)
48 ! ! REAL :: y_intd(400), y2d(400)
49 ! ! REAL :: zmin, dz, zz
50 ! ! REAL :: xlo, xhi, int1
51 ! ! REAL :: int1d
52 ! ! INTEGER :: fa_disp_max
53 ! ! INTRINSIC MAXVAL
54 ! ! zmin = 1d-6
55 ! ! fa_disp_max = MAXVAL(fa_disp(1:ncomp))
56 ! ! rhop_wdd = 0.0
57 ! ! y2d = 0.0
58 ! ! DO k=1,ncomp
59 ! ! Do i = user%xs - fa_disp_max , user%xe + fa_disp_max
60 ! ! n = 1
61 ! ! x_int = 0.0
62 ! ! y_int = 0.0
63 ! ! y_intd = 0.0
64 ! ! DO j=i-fa_disp(k),i+fa_disp(k)
65 ! ! IF (zp(i) - zp(j+1) .LT. ab_disp(k) .AND. zp(i) - zp(j) .GE. &
66 ! ! & ab_disp(k)) THEN
67 ! ! !the position of j+1 is already within i-d/2 while j is still outside this range in this case, the integration steplength (dz) is
68 ! ! ! just the distance, which j+1 overlaps with i-d/2 and what is integrated is the interpolated value of the integrand
69 ! ! !here always n=1!
70 ! ! IF (n .NE. 1) THEN
71 ! ! GOTO 100
72 ! ! ELSE
73 ! ! !distance between grid points j and i
74 ! ! zz = zp(j) - zp(i)
75 ! ! !the part of the intervall between zp(j) and zp(j+1) which is already within i-d/2
76 ! ! dz = zp(j+1) - (zp(i)-ab_disp(k))
77 ! ! !if(dz < epsilon(dz)) dz = epsilon(dz) !bei unguenstiger Kombination von sig und ngrid kann dz unter Machinengenauigkeit epsilon
78 ! ! !liegen, dann ist x(2) = x(1) + dz = x(1) -> das fuehrt zu Abbruch in Spline Interpolation
79 ! ! !array containing x-values for spline integration
80 ! ! x_int(n) = 0.0
81 ! ! y_intd(n) = 0.0
82 ! ! y_int(n) = 0.0
83 ! ! END IF
84 ! ! ELSE IF (zp(j) .GT. zp(i) - ab_disp(k) .AND. zp(j) .LE. zp(i) &
85 ! ! & + ab_disp(k)) THEN
86 ! ! !grid point j within i+-d2
87 ! ! n = n + 1
88 ! ! !first time in this If condition, dz is stil the old value from above!
89 ! ! x_int(n) = x_int(n-1) + dz
90 ! ! zz = zp(j) - zp(i)
91 ! ! dz = dzp
92 ! ! y_intd(n) = (ab_disp(k)*ab_disp(k)-zz*zz)*rhopd(k, j)
93 ! ! y_int(n) = rhop(k, j)*(ab_disp(k)*ab_disp(k)-zz*zz)
94 ! ! IF (zp(j) .LT. zp(i) + ab_disp(k) .AND. zp(j+1) .GE. zp(i) +&
95 ! ! & ab_disp(k)) THEN
96 ! ! !zp(j) is still within zp(i)+d2 but zp(j+1) is already outside zp(i)+d2
97 ! ! dz = zp(i) + ab_disp(k) - zp(j)
98 ! ! !If(dz <= epsilon(dz)) exit !wie oben, kann auch hier bei ungluecklicher Wahl von sig und ngrid dz < eps werden und somit x(n)
99 ! ! != x(n-1) -> Abbruch in Spline interpolation. Dann einfach ngrid aendern!
100 ! ! zz = zp(j) - zp(i)
101 ! ! n = n + 1
102 ! ! x_int(n) = x_int(n-1) + dz
103 ! ! y_intd(n) = 0.0
104 ! ! y_int(n) = 0.0
105 ! ! END IF
106 ! ! END IF
107 ! ! END DO
108 ! ! xlo = x_int(1)
109 ! ! xhi = x_int(n)
110 ! ! CALL SPLINE_D(x_int(1:n), y_int(1:n), y_intd(1:n), n, 1.e30, &
111 ! ! & 1.e30, y2(1:n), y2d(1:n))
112 ! ! CALL SPLINT_INTEGRAL_D(x_int(1:n), y_int(1:n), y_intd(1:n), y2(1&
113 ! ! & :n), y2d(1:n), n, xlo, xhi, int1, int1d)
114 ! ! rhop_wdd(i, k) = 0.75*int1d/ab_disp(k)**3
115 ! ! rhop_wd(i, k) = 0.75*int1/ab_disp(k)**3
116 ! ! IF (rhop_wd(i, k) .LT. 0.0) THEN
117 ! ! rhop_wdd(i, k) = 0.0
118 ! ! rhop_wd(i, k) = 0.0
119 ! ! DO j=2,n
120 ! ! rhop_wdd(i, k) = rhop_wdd(i, k) + (x_int(j)-x_int(j-1))*(&
121 ! ! & y_intd(j)+y_intd(j-1))/2.0
122 ! ! rhop_wd(i, k) = rhop_wd(i, k) + (y_int(j)+y_int(j-1))/2.0*(&
123 ! ! & x_int(j)-x_int(j-1))
124 ! ! END DO
125 ! ! END IF
126 ! ! IF (rhop_wd(i, k) .LT. 0.0) THEN
127 ! ! rhop_wdd(i, k) = rhopd(k, i)
128 ! ! rhop_wd(i, k) = rhop(k, i)
129 ! ! END IF
130 ! ! END DO
131 ! ! END DO
132 ! ! GOTO 110
133 ! ! 100 STOP
134 ! ! 110 CONTINUE
135  END SUBROUTINE disp_weighted_densities_d
136 
137 
138 
139 ! Differentiation of disp_mu in forward (tangent) mode:
140 ! variations of useful results: my_disp
141 ! with respect to varying inputs: rhop_wd
142  SUBROUTINE disp_mu_d(rhop_wd, rhop_wdd, f_disp, my_disp, my_dispd, &
143 & df_disp_drk, user)
144 
145  Use petscmanagement
146  USE parameters, ONLY : pi
147  USE eos_constants, ONLY : ap, bp
148  USE basic_variables, ONLY : ncomp, t, parame
149  USE eos_variables, Only: dhs, sig_ij, uij
150  USE mod_dft, ONLY : fa_disp
151  IMPLICIT NONE
152 #include <finclude/petscsys.h>
153 
154 !passed
155 type(userctx) :: user
156 REAL, INTENT(IN) :: rhop_wd(user%gxs:user%gxe,ncomp)
157 REAL, INTENT(IN) :: rhop_wdd(user%gxs:user%gxe,ncomp)
158 REAL, INTENT(OUT) :: my_disp(user%gxs:user%gxe,ncomp) !chemPot_disp / kT
159 REAL, INTENT(OUT) :: my_dispd(user%gxs:user%gxe,ncomp) !chemPot_disp / kT
160 REAL, INTENT(OUT) :: f_disp(user%gxs:user%gxe) !F_disp / NkT
161 REAL, INTENT(OUT) :: df_disp_drk(user%gxs:user%gxe,ncomp) ! d(F/NkT) / drho_k = (mu/kT - F_disp / NkT)/rho
162 
163 ! ! !local
164 ! ! INTEGER :: k, ii, kk, m
165 ! ! REAL :: m_mean, m_rk(ncomp)
166 ! ! REAL :: m_meand, m_rkd(ncomp)
167 ! ! REAL :: apar(0:6), bpar(0:6)
168 ! ! REAL :: apard(0:6), bpard(0:6)
169 ! ! REAL :: ap_rk(ncomp, 0:6), bp_rk(ncomp, 0:6)
170 ! ! REAL :: ap_rkd(ncomp, 0:6), bp_rkd(ncomp, 0:6)
171 ! ! REAL :: xi(ncomp), z3
172 ! ! REAL :: xid(ncomp), z3d
173 ! ! REAL :: i1, i2, i1_rk, i2_rk
174 ! ! REAL :: i1d, i2d, i1_rkd, i2_rkd
175 ! ! REAL :: order1, order2, ord1_rk, ord2_rk
176 ! ! REAL :: order1d, order2d, ord1_rkd, ord2_rkd
177 ! ! REAL :: c1_con, c2_con, c1_rk, rho2
178 ! ! REAL :: c1_cond, c2_cond, c1_rkd, rho2d
179 ! ! REAL :: rhop_wd_sum, eta_disp, eta_rk, zms
180 ! ! REAL :: rhop_wd_sumd, eta_dispd, zmsd
181 ! ! INTEGER :: fa_disp_max
182 ! ! INTRINSIC MAXVAL
183 ! ! INTRINSIC SUM
184 ! ! INTRINSIC REAL
185 ! ! REAL :: pwy1
186 ! ! REAL :: pwr1
187 ! ! REAL :: pwr1d
188 ! ! REAL :: pwy2
189 ! ! REAL :: pwr2
190 ! ! REAL :: pwr2d
191 ! ! fa_disp_max = MAXVAL(fa_disp(1:ncomp))
192 ! ! my_dispd = 0.0
193 ! ! xid = 0.0
194 ! ! m_rkd = 0.0
195 ! ! ap_rkd = 0.0
196 ! ! bpard = 0.0
197 ! ! apard = 0.0
198 ! ! bp_rkd = 0.0
199 ! ! DO k=1,ncomp
200 ! ! Do ii = user%xs-fa_disp_max,user%xe+fa_disp_max
201 ! ! rhop_wd_sumd = SUM(rhop_wdd(ii, 1:ncomp))
202 ! ! rhop_wd_sum = SUM(rhop_wd(ii, 1:ncomp))
203 ! ! m_mean = 0.0
204 ! ! eta_disp = 0.0
205 ! ! eta_dispd = 0.0
206 ! ! m_meand = 0.0
207 ! ! DO kk=1,ncomp
208 ! ! xid(kk) = (rhop_wdd(ii, kk)*rhop_wd_sum-rhop_wd(ii, kk)*&
209 ! ! & rhop_wd_sumd)/rhop_wd_sum**2
210 ! ! xi(kk) = rhop_wd(ii, kk)/rhop_wd_sum
211 ! ! m_meand = m_meand + parame(kk,1)*xid(kk)
212 ! ! m_mean = m_mean + xi(kk)*parame(kk,1)
213 ! ! eta_dispd = eta_dispd + parame(kk,1)*dhs(kk)**3*rhop_wdd(ii, kk)
214 ! ! eta_disp = eta_disp + rhop_wd(ii, kk)*parame(kk,1)*dhs(kk)**3
215 ! ! END DO
216 ! ! eta_dispd = pi*eta_dispd/6.0
217 ! ! eta_disp = eta_disp*pi/6.0
218 ! ! eta_rk = parame(k,1)*dhs(k)**3*pi/6.0
219 ! ! m_rkd(k) = (-(m_meand*rhop_wd_sum)-(parame(k,1)-m_mean)*rhop_wd_sumd&
220 ! ! & )/rhop_wd_sum**2
221 ! ! m_rk(k) = (parame(k,1)-m_mean)/rhop_wd_sum
222 ! ! DO m=0,6
223 ! ! apard(m) = ap(m, 2)*m_meand/m_mean**2 + ap(m, 3)*(m_meand*(1.0&
224 ! ! & -2.0/m_mean)/m_mean**2+(1.0-1.0/m_mean)*2.0*m_meand/m_mean**&
225 ! ! & 2)
226 ! ! apar(m) = ap(m, 1) + (1.0-1.0/m_mean)*ap(m, 2) + (1.0-1.0/&
227 ! ! & m_mean)*(1.0-2.0/m_mean)*ap(m, 3)
228 ! ! bpard(m) = bp(m, 2)*m_meand/m_mean**2 + bp(m, 3)*(m_meand*(1.0&
229 ! ! & -2.0/m_mean)/m_mean**2+(1.0-1.0/m_mean)*2.0*m_meand/m_mean**&
230 ! ! & 2)
231 ! ! bpar(m) = bp(m, 1) + (1.0-1.0/m_mean)*bp(m, 2) + (1.0-1.0/&
232 ! ! & m_mean)*(1.0-2.0/m_mean)*bp(m, 3)
233 ! ! ! --- derivatives of apar, bpar to rho_k ---------------------------
234 ! ! ap_rkd(k, m) = (m_rkd(k)*m_mean**2-m_rk(k)*2*m_mean*m_meand)*(&
235 ! ! & ap(m, 2)+(3.0-4.0/m_mean)*ap(m, 3))/m_mean**4 + m_rk(k)*ap(m&
236 ! ! & , 3)*4.0*m_meand/m_mean**4
237 ! ! ap_rk(k, m) = m_rk(k)/m_mean**2*(ap(m, 2)+(3.0-4.0/m_mean)*ap(&
238 ! ! & m, 3))
239 ! ! bp_rkd(k, m) = (m_rkd(k)*m_mean**2-m_rk(k)*2*m_mean*m_meand)*(&
240 ! ! & bp(m, 2)+(3.0-4.0/m_mean)*bp(m, 3))/m_mean**4 + m_rk(k)*bp(m&
241 ! ! & , 3)*4.0*m_meand/m_mean**4
242 ! ! bp_rk(k, m) = m_rk(k)/m_mean**2*(bp(m, 2)+(3.0-4.0/m_mean)*bp(&
243 ! ! & m, 3))
244 ! ! END DO
245 ! ! i1 = 0.0
246 ! ! i2 = 0.0
247 ! ! i1_rk = 0.0
248 ! ! i2_rk = 0.0
249 ! ! i1_rkd = 0.0
250 ! ! i1d = 0.0
251 ! ! i2d = 0.0
252 ! ! i2_rkd = 0.0
253 ! ! DO m=0,6
254 ! ! pwy1 = REAL(m)
255 ! ! IF (eta_disp .GT. 0.0 .OR. (eta_disp .LT. 0.0 .AND. pwy1 .EQ. &
256 ! ! & INT(pwy1))) THEN
257 ! ! pwr1d = pwy1*eta_disp**(pwy1-1)*eta_dispd
258 ! ! ELSE IF (eta_disp .EQ. 0.0 .AND. pwy1 .EQ. 1.0) THEN
259 ! ! pwr1d = eta_dispd
260 ! ! ELSE
261 ! ! pwr1d = 0.0
262 ! ! END IF
263 ! ! pwr1 = eta_disp**pwy1
264 ! ! i1d = i1d + apard(m)*pwr1 + apar(m)*pwr1d
265 ! ! i1 = i1 + apar(m)*pwr1
266 ! ! pwy1 = REAL(m)
267 ! ! IF (eta_disp .GT. 0.0 .OR. (eta_disp .LT. 0.0 .AND. pwy1 .EQ. &
268 ! ! & INT(pwy1))) THEN
269 ! ! pwr1d = pwy1*eta_disp**(pwy1-1)*eta_dispd
270 ! ! ELSE IF (eta_disp .EQ. 0.0 .AND. pwy1 .EQ. 1.0) THEN
271 ! ! pwr1d = eta_dispd
272 ! ! ELSE
273 ! ! pwr1d = 0.0
274 ! ! END IF
275 ! ! pwr1 = eta_disp**pwy1
276 ! ! i2d = i2d + bpard(m)*pwr1 + bpar(m)*pwr1d
277 ! ! i2 = i2 + bpar(m)*pwr1
278 ! ! pwy1 = REAL(m - 1)
279 ! ! IF (eta_disp .GT. 0.0 .OR. (eta_disp .LT. 0.0 .AND. pwy1 .EQ. &
280 ! ! & INT(pwy1))) THEN
281 ! ! pwr1d = pwy1*eta_disp**(pwy1-1)*eta_dispd
282 ! ! ELSE IF (eta_disp .EQ. 0.0 .AND. pwy1 .EQ. 1.0) THEN
283 ! ! pwr1d = eta_dispd
284 ! ! ELSE
285 ! ! pwr1d = 0.0
286 ! ! END IF
287 ! ! pwr1 = eta_disp**pwy1
288 ! ! pwy2 = REAL(m)
289 ! ! IF (eta_disp .GT. 0.0 .OR. (eta_disp .LT. 0.0 .AND. pwy2 .EQ. &
290 ! ! & INT(pwy2))) THEN
291 ! ! pwr2d = pwy2*eta_disp**(pwy2-1)*eta_dispd
292 ! ! ELSE IF (eta_disp .EQ. 0.0 .AND. pwy2 .EQ. 1.0) THEN
293 ! ! pwr2d = eta_dispd
294 ! ! ELSE
295 ! ! pwr2d = 0.0
296 ! ! END IF
297 ! ! pwr2 = eta_disp**pwy2
298 ! ! i1_rkd = i1_rkd + REAL(m)*eta_rk*(apard(m)*pwr1+apar(m)*pwr1d)&
299 ! ! & + ap_rkd(k, m)*pwr2 + ap_rk(k, m)*pwr2d
300 ! ! i1_rk = i1_rk + apar(m)*REAL(m)*pwr1*eta_rk + ap_rk(k, m)*pwr2
301 ! ! pwy1 = REAL(m - 1)
302 ! ! IF (eta_disp .GT. 0.0 .OR. (eta_disp .LT. 0.0 .AND. pwy1 .EQ. &
303 ! ! & INT(pwy1))) THEN
304 ! ! pwr1d = pwy1*eta_disp**(pwy1-1)*eta_dispd
305 ! ! ELSE IF (eta_disp .EQ. 0.0 .AND. pwy1 .EQ. 1.0) THEN
306 ! ! pwr1d = eta_dispd
307 ! ! ELSE
308 ! ! pwr1d = 0.0
309 ! ! END IF
310 ! ! pwr1 = eta_disp**pwy1
311 ! ! pwy2 = REAL(m)
312 ! ! IF (eta_disp .GT. 0.0 .OR. (eta_disp .LT. 0.0 .AND. pwy2 .EQ. &
313 ! ! & INT(pwy2))) THEN
314 ! ! pwr2d = pwy2*eta_disp**(pwy2-1)*eta_dispd
315 ! ! ELSE IF (eta_disp .EQ. 0.0 .AND. pwy2 .EQ. 1.0) THEN
316 ! ! pwr2d = eta_dispd
317 ! ! ELSE
318 ! ! pwr2d = 0.0
319 ! ! END IF
320 ! ! pwr2 = eta_disp**pwy2
321 ! ! i2_rkd = i2_rkd + REAL(m)*eta_rk*(bpard(m)*pwr1+bpar(m)*pwr1d)&
322 ! ! & + bp_rkd(k, m)*pwr2 + bp_rk(k, m)*pwr2d
323 ! ! i2_rk = i2_rk + bpar(m)*REAL(m)*pwr1*eta_rk + bp_rk(k, m)*pwr2
324 ! ! END DO
325 ! ! ord1_rk = 0.0
326 ! ! ord2_rk = 0.0
327 ! ! order1 = 0.0
328 ! ! order2 = 0.0
329 ! ! order1d = 0.0
330 ! ! order2d = 0.0
331 ! ! ord2_rkd = 0.0
332 ! ! ord1_rkd = 0.0
333 ! ! DO kk=1,ncomp
334 ! ! !sig_ij(kk,k) = 0.5 * ( dhs(kk) + dhs(k) )
335 ! ! !uij(kk,k) = (1.0 - kij(kk,k)) * SQRT( eps(kk) * eps(k) )
336 ! ! order1d = order1d + parame(kk,1)*parame(k,1)*sig_ij(kk, k)**3*uij(kk, &
337 ! ! & k)*(xid(kk)*xi(k)+xi(kk)*xid(k))/t
338 ! ! order1 = order1 + xi(kk)*xi(k)*parame(kk,1)*parame(k,1)*sig_ij(kk, k)&
339 ! ! & **3*uij(kk, k)/t
340 ! ! order2d = order2d + parame(kk,1)*parame(k,1)*sig_ij(kk, k)**3*uij(kk, &
341 ! ! & k)**2*(xid(kk)*xi(k)+xi(kk)*xid(k))/t**2
342 ! ! order2 = order2 + xi(kk)*xi(k)*parame(kk,1)*parame(k,1)*sig_ij(kk, k)&
343 ! ! & **3*(uij(kk, k)/t)**2
344 ! ! ord1_rkd = ord1_rkd + 2.0*parame(k,1)*parame(kk,1)*sig_ij(kk, k)**3*&
345 ! ! & uij(kk, k)*(rhop_wd_sumd*xi(kk)+rhop_wd_sum*xid(kk))/t
346 ! ! ord1_rk = ord1_rk + 2.0*parame(k,1)*rhop_wd_sum*xi(kk)*parame(kk,1)*&
347 ! ! & sig_ij(kk, k)**3*uij(kk, k)/t
348 ! ! ord2_rkd = ord2_rkd + 2.0*parame(k,1)*parame(kk,1)*sig_ij(kk, k)**3*&
349 ! ! & uij(kk, k)**2*(rhop_wd_sumd*xi(kk)+rhop_wd_sum*xid(kk))/t**2
350 ! ! ord2_rk = ord2_rk + 2.0*parame(k,1)*rhop_wd_sum*xi(kk)*parame(kk,1)*&
351 ! ! & sig_ij(kk, k)**3*(uij(kk, k)/t)**2
352 ! ! END DO
353 ! ! z3d = eta_dispd
354 ! ! z3 = eta_disp
355 ! ! zmsd = -z3d
356 ! ! zms = 1.0 - z3
357 ! ! c1_cond = -((((m_meand*(8.0*z3-2.0*z3*z3)+m_mean*(8.0*z3d-2.0*(&
358 ! ! & z3d*z3+z3*z3d)))*zms**4-m_mean*(8.0*z3-2.0*z3*z3)*4*zms**3*&
359 ! ! & zmsd)/(zms**4)**2+(((1.0-m_mean)*(20.0*z3d-27.0*(z3d*z3+z3*z3d&
360 ! ! & )+12.0*3*z3**2*z3d-2.0*4*z3**3*z3d)-m_meand*(20.0*z3-27.0*z3*&
361 ! ! & z3+12.0*z3**3-2.0*z3**4))*zms**2*(2.0-z3)**2-(1.0-m_mean)*(&
362 ! ! & 20.0*z3-27.0*z3*z3+12.0*z3**3-2.0*z3**4)*2*zms*(2.0-z3)*(zmsd*&
363 ! ! & (2.0-z3)-zms*z3d))/((zms*(2.0-z3))**2)**2)/(1.0+m_mean*(8.0*z3&
364 ! ! & -2.0*z3*z3)/zms**4+(1.0-m_mean)*(20.0*z3-27.0*z3*z3+12.0*z3**3&
365 ! ! & -2.0*z3**4)/(zms*(2.0-z3))**2)**2)
366 ! ! c1_con = 1.0/(1.0+m_mean*(8.0*z3-2.0*z3*z3)/zms**4+(1.0-m_mean)*&
367 ! ! & (20.0*z3-27.0*z3*z3+12.0*z3**3-2.0*z3**4)/(zms*(2.0-z3))**2)
368 ! ! c2_cond = -((c1_cond*c1_con+c1_con*c1_cond)*(m_mean*(-(4.0*z3*z3&
369 ! ! & )+20.0*z3+8.0)/zms**5+(1.0-m_mean)*(2.0*z3**3+12.0*z3*z3-48.0*&
370 ! ! & z3+40.0)/(zms*(2.0-z3))**3)+c1_con**2*(((m_meand*(-(4.0*z3*z3)&
371 ! ! & +20.0*z3+8.0)+m_mean*(20.0*z3d-4.0*(z3d*z3+z3*z3d)))*zms**5-&
372 ! ! & m_mean*(-(4.0*z3*z3)+20.0*z3+8.0)*5*zms**4*zmsd)/(zms**5)**2+(&
373 ! ! & ((1.0-m_mean)*(2.0*3*z3**2*z3d+12.0*(z3d*z3+z3*z3d)-48.0*z3d)-&
374 ! ! & m_meand*(2.0*z3**3+12.0*z3*z3-48.0*z3+40.0))*zms**3*(2.0-z3)**&
375 ! ! & 3-(1.0-m_mean)*(2.0*z3**3+12.0*z3*z3-48.0*z3+40.0)*3*zms**2*(&
376 ! ! & 2.0-z3)**2*(zmsd*(2.0-z3)-zms*z3d))/((zms*(2.0-z3))**3)**2))
377 ! ! c2_con = -(c1_con*c1_con*(m_mean*(-(4.0*z3*z3)+20.0*z3+8.0)/zms&
378 ! ! & **5+(1.0-m_mean)*(2.0*z3**3+12.0*z3*z3-48.0*z3+40.0)/(zms*(2.0&
379 ! ! & -z3))**3))
380 ! ! c1_rkd = eta_rk*c2_cond - ((c1_cond*c1_con+c1_con*c1_cond)*m_rk(&
381 ! ! & k)+c1_con**2*m_rkd(k))*((8.0*z3-2.0*z3*z3)/zms**4-(-(2.0*z3**4&
382 ! ! & )+12.0*z3**3-27.0*z3*z3+20.0*z3)/(zms*(2.0-z3))**2) - c1_con**&
383 ! ! & 2*m_rk(k)*(((8.0*z3d-2.0*(z3d*z3+z3*z3d))*zms**4-(8.0*z3-2.0*&
384 ! ! & z3*z3)*4*zms**3*zmsd)/(zms**4)**2-((12.0*3*z3**2*z3d-2.0*4*z3&
385 ! ! & **3*z3d-27.0*(z3d*z3+z3*z3d)+20.0*z3d)*zms**2*(2.0-z3)**2-(-(&
386 ! ! & 2.0*z3**4)+12.0*z3**3-27.0*z3*z3+20.0*z3)*2*zms*(2.0-z3)*(zmsd&
387 ! ! & *(2.0-z3)-zms*z3d))/((zms*(2.0-z3))**2)**2)
388 ! ! c1_rk = c2_con*eta_rk - c1_con*c1_con*m_rk(k)*((8.0*z3-2.0*z3*z3&
389 ! ! & )/zms**4-(-(2.0*z3**4)+12.0*z3**3-27.0*z3*z3+20.0*z3)/(zms*(&
390 ! ! & 2.0-z3))**2)
391 ! ! rho2d = rhop_wd_sumd*rhop_wd_sum + rhop_wd_sum*rhop_wd_sumd
392 ! ! rho2 = rhop_wd_sum*rhop_wd_sum
393 ! ! my_dispd(ii, k) = -(2.0*pi*((order1d*rho2+order1*rho2d)*i1_rk+&
394 ! ! & order1*rho2*i1_rkd+ord1_rkd*i1+ord1_rk*i1d)) - pi*((c1_cond*&
395 ! ! & m_mean+c1_con*m_meand)*(order2*rho2*i2_rk+ord2_rk*i2)+c1_con*&
396 ! ! & m_mean*((order2d*rho2+order2*rho2d)*i2_rk+order2*rho2*i2_rkd+&
397 ! ! & ord2_rkd*i2+ord2_rk*i2d)) - pi*((c1_cond*m_rk(k)+c1_con*m_rkd(&
398 ! ! & k)+c1_rkd*m_mean+c1_rk*m_meand)*order2*rho2*i2+(c1_con*m_rk(k)&
399 ! ! & +c1_rk*m_mean)*((order2d*rho2+order2*rho2d)*i2+order2*rho2*i2d&
400 ! ! & ))
401 ! ! my_disp(ii, k) = -(2.0*pi*(order1*rho2*i1_rk+ord1_rk*i1)) - pi*&
402 ! ! & c1_con*m_mean*(order2*rho2*i2_rk+ord2_rk*i2) - pi*(c1_con*m_rk&
403 ! ! & (k)+c1_rk*m_mean)*order2*rho2*i2
404 ! ! f_disp(ii) = -(2.0*pi*rhop_wd_sum*i1*order1) - pi*rhop_wd_sum*&
405 ! ! & c1_con*m_mean*i2*order2
406 ! ! df_disp_drk(ii, k) = (my_disp(ii, k)-f_disp(ii))/rhop_wd_sum
407 ! ! END DO
408 ! ! END DO
409  END SUBROUTINE disp_mu_d
410 
411 
412 
413 ! Differentiation of disp_dfdrho_wda in forward (tangent) mode:
414 ! variations of useful results: df_drho_disp
415 ! with respect to varying inputs: my_disp df_drho_disp
416  SUBROUTINE disp_dfdrho_wda_d(ii, rhop, rhop_wd, my_disp, my_dispd, &
417 & f_disp, df_disp_drk, df_drho_disp, df_drho_dispd, user)
418 
419  Use petscmanagement
420  USE basic_variables, ONLY : ncomp
421  USE mod_dft, ONLY : zp, dzp, fa_disp, ab_disp
422  IMPLICIT NONE
423 #include <finclude/petscsys.h>
424 
425 !passed
426 INTEGER, INTENT(IN) :: ii
427 type(userctx) :: user
428 petscscalar :: rhop(ncomp,user%gxs:user%gxe)
429 REAL, INTENT(IN) :: rhop_wd(user%gxs:user%gxe,ncomp)
430 REAL, INTENT(IN) :: my_disp(user%gxs:user%gxe,ncomp) !chemPot_disp / kT
431 REAL, INTENT(IN) :: my_dispd(user%gxs:user%gxe,ncomp) !chemPot_disp / kT
432 REAL, INTENT(IN) :: f_disp(user%gxs:user%gxe) !F_disp / NkT
433 REAL, INTENT(IN) :: df_disp_drk(user%gxs:user%gxe,ncomp) ! d(F/NkT) / drho_k = (mu/kT - F_disp / NkT)/rho
434 REAL, INTENT(OUT) :: df_drho_disp(ncomp)
435 REAL, INTENT(OUT) :: df_drho_dispd(ncomp)
436 
437 ! ! !local
438 ! ! INTEGER :: n, icomp, jj
439 ! ! REAL :: zmin, zz, dz
440 ! ! REAL :: x_int(400), y_int(400), y2(400)
441 ! ! REAL :: y_intd(400), y2d(400)
442 ! ! REAL :: xhi, xlo, int2
443 ! ! REAL :: int2d
444 ! ! REAL :: rhop_sum
445 ! ! zmin = 1d-6
446 ! ! y2d = 0.0
447 ! ! DO icomp=1,ncomp
448 ! ! n = 1
449 ! ! x_int = 0.0
450 ! ! y_int = 0.0
451 ! ! y_intd = 0.0
452 ! ! DO jj=ii-fa_disp(icomp),ii+fa_disp(icomp)
453 ! ! !IF ( zp(jj+1) > (zl+zmin) ) THEN
454 ! ! IF (zp(ii) - zp(jj+1) .LT. ab_disp(icomp) .AND. zp(ii) - zp(jj) &
455 ! ! & .GE. ab_disp(icomp)) THEN
456 ! ! !the position of j+1 is already within i-d/2 while j is still outside this range in this case, the integration steplength (dz) is
457 ! ! ! just the distance, which j+1 overlaps with i-d/2 and what is integrated is the interpolated value of the integrand
458 ! ! !here always n=1!
459 ! ! IF (n .NE. 1) THEN
460 ! ! GOTO 100
461 ! ! ELSE
462 ! ! !distance between grid points j and i
463 ! ! zz = zp(jj) - zp(ii)
464 ! ! !the part of the intervall between zp(j) and zp(j+1) which is already within i-d/2
465 ! ! dz = zp(jj+1) - (zp(ii)-ab_disp(icomp))
466 ! ! !if(dz < epsilon(dz)) dz = epsilon(dz) !bei unguenstiger Kombination von sig und ngrid kann dz unter Machinengenauigkeit epsilon
467 ! ! !liegen, dann ist x(2) = x(1) + dz = x(1) -> das fuehrt zu Abbruch in Spline Interpolation
468 ! ! !array containing x-values for spline integration
469 ! ! x_int(n) = 0.0
470 ! ! y_intd(n) = 0.0
471 ! ! y_int(n) = 0.0
472 ! ! END IF
473 ! ! ELSE IF (zp(jj) .GT. zp(ii) - ab_disp(icomp) .AND. zp(jj) .LE. &
474 ! ! & zp(ii) + ab_disp(icomp)) THEN
475 ! ! !grid point j within i+-d2
476 ! ! n = n + 1
477 ! ! !first time in this If condition, dz is stil the old value from above!
478 ! ! x_int(n) = x_int(n-1) + dz
479 ! ! zz = zp(jj) - zp(ii)
480 ! ! dz = dzp
481 ! ! y_intd(n) = (ab_disp(icomp)*ab_disp(icomp)-zz*zz)*my_dispd(jj&
482 ! ! & , icomp)
483 ! ! y_int(n) = my_disp(jj, icomp)*(ab_disp(icomp)*ab_disp(icomp)-&
484 ! ! & zz*zz)
485 ! ! !rhop_sum = sum(rhop(1:ncomp,jj))
486 ! ! !y_int(n) = rhop_sum * df_disp_drk(jj,icomp) * (ab_disp(icomp)*ab_disp(icomp) - zz*zz)
487 ! ! IF (zp(jj) .LT. zp(ii) + ab_disp(icomp) .AND. zp(jj+1) .GE. zp&
488 ! ! & (ii) + ab_disp(icomp)) THEN
489 ! ! !zp(j) is still within zp(i)+d2 but zp(j+1) is already outside zp(i)+d2
490 ! ! dz = zp(ii) + ab_disp(icomp) - zp(jj)
491 ! ! !If(dz <= epsilon(dz)) exit !wie oben, kann auch hier bei ungluecklicher Wahl von sig und ngrid dz < eps werden und somit x(n)
492 ! ! != x(n-1) -> Abbruch in Spline interpolation. Dann einfach ngrid aendern!
493 ! ! zz = zp(jj) - zp(ii)
494 ! ! n = n + 1
495 ! ! x_int(n) = x_int(n-1) + dz
496 ! ! y_intd(n) = 0.0
497 ! ! y_int(n) = 0.0
498 ! ! END IF
499 ! ! END IF
500 ! ! END DO
501 ! ! xlo = x_int(1)
502 ! ! xhi = x_int(n)
503 ! ! CALL SPLINE_D(x_int(1:n), y_int(1:n), y_intd(1:n), n, 1.e30, 1.e30&
504 ! ! & , y2(1:n), y2d(1:n))
505 ! ! CALL SPLINT_INTEGRAL_D(x_int(1:n), y_int(1:n), y_intd(1:n), y2(1:n&
506 ! ! & ), y2d(1:n), n, xlo, xhi, int2, int2d)
507 ! ! df_drho_dispd(icomp) = 0.75*int2d/ab_disp(icomp)**3
508 ! ! df_drho_disp(icomp) = int2*0.75/ab_disp(icomp)**3
509 ! ! END DO
510 ! ! GOTO 110
511 ! ! 100 STOP
512 ! ! 110 CONTINUE
513  END SUBROUTINE disp_dfdrho_wda_d
514 
515 END MODULE mod_dft_disp_wda_d
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains constant...
Definition: modules.f90:6
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:200
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:120
In this module, the application context is defined.
Definition: mod_PETSc.F90:7
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:29