MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
AD_Routines.F90
1 
3 
4 
5 
6 
7 
8 
9 
10 ! Generated by TAPENADE (INRIA, Tropics team)
11 ! Tapenade 3.10 (r5498) - 20 Jan 2015 09:48
12 !
13 ! Differentiation of formfunctionlocal in forward (tangent) mode:
14 ! variations of useful results: f rhop
15 ! with respect to varying inputs: rhop
16 ! RW status of diff variables: f:out rhop:in-out
17 SUBROUTINE formfunctionlocal_d(rhop, rhopd_nogp, fd, user, ierr)
18 
19 
20 !PETSc modules
21  Use petscmanagement
22 
23 
24 !DFT modules
25  USE mod_dft_fmt
26  USE mod_dft_chain
27  USE mod_dft_fmt_d
28  USE mod_dft_chain_d
29  USE mod_dft_disp_wda_d
30 
31 
32  USE basic_variables, ONLY : ncomp
33  USE eos_variables, Only:dhs, rho
34  USE vle_var, Only: rhob
35  USE mod_dft, ONLY : fa, zp
36  USE dft_fcn_module, ONLY : chempot_res
37  USE global_x, ONLY : ngrid, ngp
38  IMPLICIT NONE
39 
40 #include <finclude/petscsys.h>
41 
42 ! Input/output variables:
43  type(userctx) user
44  petscscalar rhop(ncomp,user%gxs:user%gxe)
45  petscscalar rhopd_nogp(ncomp,user%xs:user%xe)
46  !PetscScalar f(ncomp,user%xs:user%xe)
47  petscscalar fd(ncomp,user%xs:user%xe)
48  petscerrorcode ierr
49 
50 ! Local variables:
51  petscint i
52  petscint k
53  REAL,dimension(user%gxs:user%gxe) :: n0,n1,n2,n3,nv1,nv2 !ngp muss groesser als fa+fa/2 sein!!
54  REAL,dimension(user%gxs:user%gxe) :: phi_dn0,phi_dn1,phi_dn2,phi_dn3,phi_dnv1,phi_dnv2
55  REAL,dimension(user%gxs:user%gxe) :: phi_dn0d,phi_dn1d,phi_dn2d,phi_dn3d,phi_dnv1d,phi_dnv2d
56  REAL,dimension(user%xs:user%xe,ncomp) :: df_drho_fmt,df_drho_fmtd
57  REAL,dimension(user%gxs:user%gxe,ncomp) :: rhobar,lambda,rhobard,lambdad
58  REAL,dimension(user%xs:user%xe,ncomp) :: df_drho_chain,df_drho_chaind
59  REAL :: vext(ncomp)
60 
61  !DISP VAR
62  REAL,dimension(user%gxs:user%gxe,ncomp) :: rhop_wd,my_disp,df_disp_drk
63  REAL,dimension(user%gxs:user%gxe,ncomp) :: rhop_wdd,my_dispd
64  REAL,dimension(user%gxs:user%gxe) :: f_disp
65  REAL, dimension(ncomp) :: df_drho_disp
66  REAL, dimension(ncomp) :: df_drho_dispd
67 
68 
69 
70  INTRINSIC exp
71  REAL :: arg1
72  REAL :: arg1d
73  petscscalar :: rhopd(ncomp,user%gxs:user%gxe)
74 
75  rhopd = 0.0
76  rhopd(1:ncomp,user%xs:user%xe) = rhopd_nogp(1:ncomp,user%xs:user%xe)
77 
78 
79 
80 !calculate weighted densities
81  CALL fmt_weighted_densities_d(rhop, rhopd, n0, n1, n2, n3, nv1, nv2, &
82 & phi_dn0, phi_dn0d, phi_dn1, phi_dn1d, phi_dn2&
83 & , phi_dn2d, phi_dn3, phi_dn3d, phi_dnv1, &
84 & phi_dnv1d, phi_dnv2, phi_dnv2d, user)
85 !calculate averaged density rhobar and lambda (both needed for chain term)
86  CALL chain_aux_d(rhop, rhopd, rhobar, rhobard, lambda, lambdad, user)
87 !HIER DISP!!!
88  CALL disp_weighted_densities_d(rhop, rhopd, rhop_wd, rhop_wdd, user)
89  CALL disp_mu_d(rhop_wd, rhop_wdd, f_disp, my_disp, my_dispd, &
90 & df_disp_drk, user)
91 
92  fd = 0.0
93  df_drho_chaind = 0.0
94  df_drho_fmtd = 0.0
95  df_drho_dispd = 0.0
96 
97  DO i = user%xs,user%xe
98  CALL fmt_dfdrho_d(i, fa, user, phi_dn0, phi_dn0d, phi_dn1, phi_dn1d&
99 & , phi_dn2, phi_dn2d, phi_dn3, phi_dn3d, phi_dnv1, &
100 & phi_dnv1d, phi_dnv2, phi_dnv2d, df_drho_fmt, &
101 & df_drho_fmtd)
102  CALL chain_dfdrho_d(i, rhop, rhopd, lambda, lambdad, rhobar, rhobard&
103 & , df_drho_chain, df_drho_chaind, user)
104 
105 !HIER DISP!!!
106  CALL disp_dfdrho_wda_d(i, rhop, rhop_wd, my_disp, my_dispd, f_disp, &
107 & df_disp_drk, df_drho_disp, df_drho_dispd, user)
108 
109 
110  vext(1:ncomp) = 0.0
111  DO k=1,ncomp
112  IF (zp(i) .LT. dhs(k)/2.0) vext(k) = 100000.0
113 ! If( zp(ngrid) - zp(i) < dhs(k)/2.0 ) Vext(k) = 100000.0
114  arg1d = -df_drho_fmtd(i,k)-df_drho_chaind(i,k)-df_drho_dispd(k)
115  arg1 = chempot_res(k) - vext(k) - df_drho_fmt(i, k) - &
116 & df_drho_chain(i, k) - df_drho_disp(k)
117 
118  fd(k, i) = rhob(1,k)*arg1d*exp(arg1) - rhopd(k, i)
119  !f(k, i) = xx(k)*rho*EXP(arg1) - rhop(k, i)
120  END DO
121  END DO
122 END SUBROUTINE formfunctionlocal_d
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 !------------------------------------------------------------------------------------------------
133 !This Subroutine calculates the Jacobi-Vector product using derivatives obtained via AD
134 !------------------------------------------------------------------------------------------------
135 Subroutine jac_shell_ad(Jshell,v_in,v_out)
136 
137 use global_x, only: x,snes
138 Use petscmanagement
139 
140 #include "finclude/petsc.h90"
141 
142 
143 !passed
144  mat :: jshell
145  vec :: v_in !has global size discret (NOT discret +- ghost points!!)
146  vec :: v_out
147 !local
148  petscscalar, pointer :: xd(:), rhop_loc(:,:),fd(:) !for dof2, xd and fd are twice the size as for dof1
149  petscerrorcode :: ierr
150  type(userctx) :: user
151  dm :: da
152  vec :: rhop_local
153 
154 
155 
156 !get the user context and DM which are associated with nonlinear solver
157  call snesgetapplicationcontext(snes,user,ierr)
158  call snesgetdm(snes,da,ierr)
159 
160 !get local vector for x (needed because we need the ghost point values of x)
161  call dmgetlocalvector(da,rhop_local,ierr)
162 
163 !copy global to local for x (then x_local also contains ghost points)
164  call dmglobaltolocalbegin(da,x,insert_values,rhop_local,ierr)
165  call dmglobaltolocalend(da,x,insert_values,rhop_local,ierr)
166 
167 !get pointers to the vectors x_local,v_in and v_out
168  call dmdavecgetarrayf90(da,rhop_local,rhop_loc,ierr)
169  call vecgetarrayf90(v_in, xd, ierr )
170  call vecgetarrayf90(v_out, fd, ierr )
171 
172 ! Get local grid boundaries (dont know why this is neccessary again!)
173  call dmdagetcorners(da, & !the distributed array
174  & user%xs, & !corner index in x direction
175  & petsc_null_integer, & !corner index in y direction
176  & petsc_null_integer, & !corner index in z direction
177  & user%xm, & !width of locally owned part in x direction
178  & petsc_null_integer, & !width of locally owned part in y direction
179  & petsc_null_integer, & !width of locally owned part in z direction
180  & ierr) !error check
181 
182  call dmdagetghostcorners(da, & !the distributed array
183  & user%gxs, & !corner index in x direction (but now counting includes ghost points)
184  & petsc_null_integer, & !corner index in y direction (but now counting includes ghost points)
185  & petsc_null_integer, & !corner index in z direction (but now counting includes ghost points)
186  & user%gxm, & !width of locally owned part in x direction (but now including ghost points)
187  & petsc_null_integer, & !width of locally owned part in y direction (but now including ghost points)
188  & petsc_null_integer, & !width of locally owned part in z direction (but now including ghost points)
189  & ierr) !error check
190 
191 
192 ! Here we shift the starting indices up by one so that we can easily
193 ! use the Fortran convention of 1-based indices (rather 0-based indices).
194  user%xs = user%xs+1
195  user%gxs = user%gxs+1
196 
197  user%xe = user%xs+user%xm-1
198  user%gxe = user%gxs+user%gxm-1
199 
200 
201 !---------------------------------------------------------
202 !call AD generated Routine
203  !x_loc: x
204  !xd : direction which the derivative is calculated for
205  !fd : the directional derivative in direction xd
206 
207  call formfunctionlocal_d(rhop_loc,xd,fd,user,ierr)
208 !---------------------------------------------------------
209 
210 
211 
212 
213 !restore arrays
214  call dmdavecrestorearrayf90(da,rhop_local,rhop_loc,ierr )
215  call vecrestorearrayf90( v_in, xd, ierr )
216  call vecrestorearrayf90( v_out, fd, ierr )
217  call dmrestorelocalvector(da,rhop_local,ierr)
218 
219 
220 End Subroutine jac_shell_ad
221 
222 
223 
224 
225 ! empty subroutine for shell jacobian; probably should copy v_x to x, as they might not be same
226 Subroutine jac_matrix_empty(snes,v_x,jac,B,flag,dummy,ierr)
227  implicit none
228 #include "finclude/petsc.h90"
229  snes :: snes
230  vec :: v_x
231  mat :: jac,b
232  matstructure :: flag
233  petscerrorcode :: ierr
234  integer dummy(*)
235 End Subroutine jac_matrix_empty
236 
237 
238 
239 
240 
241 
242 
double lambda
Latent heat of blowing agent, J/kg.
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:120
This module contains variables associated with the PETSc solver.
Definition: mod_PETSc.F90:24
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains the vari...
Definition: modules.f90:327
In this module, the application context is defined.
Definition: mod_PETSc.F90:7
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW This module contains paramete...
Definition: modules.f90:29