ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
initializeFlow_d.f90
Go to the documentation of this file.
1 ! generated by tapenade (inria, ecuador team)
2 ! tapenade 3.16 (develop) - 22 aug 2023 15:51
3 !
5  use constants, only : inttype, realtype, maxstringlen
6  implicit none
7  save
8 
9 contains
10 ! differentiation of referencestate in forward (tangent) mode (with options i4 dr8 r8):
11 ! variations of useful results: pinf timeref rhoinf muref tref
12 ! winf muinf uinf pinfcorr pref rgas rhoref
13 ! with respect to varying inputs: tinfdim rhoinfdim pinfdim mach
14 ! veldirfreestream machcoef
15 ! rw status of diff variables: tinfdim:in pinf:out timeref:out
16 ! rhoinf:out muref:out rhoinfdim:in tref:out winf:out
17 ! muinf:out uinf:out pinfcorr:out pref:out pinfdim:in
18 ! rgas:out rhoref:out mach:in veldirfreestream:in
19 ! machcoef:in
20  subroutine referencestate_d()
21 !
22 ! the original version has been nuked since the computations are
23 ! no longer necessary when calling from python
24 ! this is the most compliclated routine in all of adflow. it is
25 ! stupidly complicated. this is most likely the reason your
26 ! derivatives are wrong. you don't understand this routine
27 ! and its effects.
28 ! this routine *requries* the following as input:
29 ! mach, pinfdim, tinfdim, rhoinfdim, rgasdim (machcoef non-sa
30 ! turbulence only)
31 ! optionally, pref, rhoref and tref are used if they are
32 ! are non-negative. this only happens when you want the equations
33 ! normalized by values other than the freestream
34 ! * this routine computes as output:
35 ! * muinfdim, (unused anywhere in code)
36 ! pref, rhoref, tref, muref, timeref ('dimensional' reference)
37 ! pinf, pinfcorr, rhoinf, uinf, rgas, muinf, gammainf and winf
38 ! (non-dimensionalized values used in actual computations)
39 !
40  use constants
41  use paramturb
42  use inputphysics, only : equations, mach, machd, machcoef, &
51  use flowutils_d, only : computegamma, etot, etot_d
53  implicit none
54  integer(kind=inttype) :: sps, nn, mm, ierr
55  real(kind=realtype) :: gm1, ratio
56  real(kind=realtype) :: nuinf, ktmp, uinf2
57  real(kind=realtype) :: nuinfd, ktmpd, uinf2d
58  real(kind=realtype) :: vinf, zinf, tmp1(1), tmp2(1)
59  real(kind=realtype) :: vinfd, zinfd
60  intrinsic sqrt
61  real(kind=realtype) :: arg1
62  real(kind=realtype) :: arg1d
63  real(kind=realtype) :: result1
64  real(kind=realtype) :: result1d
65  real(kind=realtype) :: temp
66  real(kind=realtype) :: temp0
67 ! compute the dimensional viscosity from sutherland's law
68  temp = (tinfdim/tsuthdim)**1.5_realtype/(ssuthdim+tinfdim)
69  muinfdimd = musuthdim*(tsuthdim+ssuthdim)*(1.5_realtype*(tinfdim/&
72 ! set the reference values. they *could* be different from the
73 ! free-stream values for an internal flow simulation. for now,
74 ! we just use the actual free stream values.
75  prefd = pinfdimd
76  pref = pinfdim
77  trefd = tinfdimd
78  tref = tinfdim
81 ! compute the value of muref, such that the nondimensional
82 ! equations are identical to the dimensional ones.
83 ! note that in the non-dimensionalization of muref there is
84 ! a reference length. however this reference length is 1.0
85 ! in this code, because the coordinates are converted to
86 ! meters.
87  temp = sqrt(pref*rhoref)
88  if (pref*rhoref .eq. 0.0_8) then
89  murefd = 0.0_8
90  else
91  murefd = (rhoref*prefd+pref*rhorefd)/(2.0*temp)
92  end if
93  muref = temp
94 ! compute timeref for a correct nondimensionalization of the
95 ! unsteady equations. some story as for the reference viscosity
96 ! concerning the reference length.
97  temp = rhoref/pref
98  temp0 = sqrt(temp)
99  if (temp .eq. 0.0_8) then
100  timerefd = 0.0_8
101  else
102  timerefd = (rhorefd-temp*prefd)/(2.0*temp0*pref)
103  end if
104  timeref = temp0
105  href = pref/rhoref
106  uref = sqrt(href)
107 ! compute the nondimensional pressure, density, velocity,
108 ! viscosity and gas constant.
110  pinf = pinfdim/pref
114  arg1 = gammainf*pinf/rhoinf
115  temp0 = sqrt(arg1)
116  if (arg1 .eq. 0.0_8) then
117  result1d = 0.0_8
118  else
119  result1d = arg1d/(2.0*temp0)
120  end if
121  result1 = temp0
122  uinfd = result1*machd + mach*result1d
123  uinf = mach*result1
124  temp0 = rhoref*tref/pref
126  rgas = rgasdim*temp0
129  tmp1(1) = tinfdim
130  call computegamma(tmp1, tmp2, 1)
131  gammainf = tmp2(1)
132 ! ----------------------------------------
133 ! compute the final winf
134 ! ----------------------------------------
135 ! allocate the memory for winf if necessary
136 ! zero out the winf first
137  winf(:) = zero
138 ! set the reference value of the flow variables, except the total
139 ! energy. this will be computed at the end of this routine.
140  winfd = 0.0_8
141  winfd(irho) = rhoinfd
142  winf(irho) = rhoinf
149 ! compute the velocity squared based on machcoef. this gives a
150 ! better indication of the 'speed' of the flow so the turubulence
151 ! intensity ration is more meaningful especially for moving
152 ! geometries. (not used in sa model)
153  temp0 = pinf/rhoinf
154  uinf2d = gammainf*(temp0*2*machcoef*machcoefd+machcoef**2*(pinfd-&
155 & temp0*rhoinfd)/rhoinf)
156  uinf2 = gammainf*(machcoef*machcoef*temp0)
157 ! set the turbulent variables if transport variables are to be
158 ! solved. we should be checking for rans equations here,
159 ! however, this code is included in block res. the issue is
160 ! that for frozen turbulence (or ank jacobian) we call the
161 ! block_res with equationtype set to laminar even though we are
162 ! actually solving the rans equations. the issue is that, the
163 ! freestream turb variables will be changed to zero, thus
164 ! changing the solution. insteady we check if nw > nwf which
165 ! will accomplish the same thing.
166  if (nw .gt. nwf) then
167  nuinfd = (muinfd-muinf*rhoinfd/rhoinf)/rhoinf
168  nuinf = muinf/rhoinf
169  select case (turbmodel)
172 & nuinfd, winf(itu1))
173 !=============================================================
175  winfd(itu1) = turbintensityinf**2*1.5_realtype*uinf2d
176  winf(itu1) = 1.5_realtype*uinf2*turbintensityinf**2
177  temp0 = winf(itu1)/(eddyvisinfratio*nuinf)
178  winfd(itu2) = (winfd(itu1)-temp0*eddyvisinfratio*nuinfd)/(&
179 & eddyvisinfratio*nuinf)
180  winf(itu2) = temp0
181 !=============================================================
182  case (ktau)
183  winfd(itu1) = turbintensityinf**2*1.5_realtype*uinf2d
184  winf(itu1) = 1.5_realtype*uinf2*turbintensityinf**2
185  temp0 = nuinf/winf(itu1)
186  winfd(itu2) = eddyvisinfratio*(nuinfd-temp0*winfd(itu1))/winf(&
187 & itu1)
188  winf(itu2) = eddyvisinfratio*temp0
189 !=============================================================
190  case (v2f)
191  winfd(itu1) = turbintensityinf**2*1.5_realtype*uinf2d
192  winf(itu1) = 1.5_realtype*uinf2*turbintensityinf**2
193  temp0 = winf(itu1)*winf(itu1)/(eddyvisinfratio*nuinf)
194  winfd(itu2) = 0.09_realtype*(2*winf(itu1)*winfd(itu1)-temp0*&
195 & eddyvisinfratio*nuinfd)/(eddyvisinfratio*nuinf)
196  winf(itu2) = 0.09_realtype*temp0
197  winfd(itu3) = 0.666666_realtype*winfd(itu1)
198  winf(itu3) = 0.666666_realtype*winf(itu1)
199  winfd(itu4) = 0.0_8
200  winf(itu4) = 0.0_realtype
201  end select
202  end if
203 ! set the value of pinfcorr. in case a k-equation is present
204 ! add 2/3 times rho*k.
205  pinfcorrd = pinfd
206  pinfcorr = pinf
207  if (kpresent) then
209 & itu1))
211  end if
212 ! compute the free stream total energy.
213  ktmp = zero
214  if (kpresent) then
215  ktmpd = winfd(itu1)
216  ktmp = winf(itu1)
217  else
218  ktmpd = 0.0_8
219  end if
220  vinf = zero
221  zinf = zero
222  zinfd = 0.0_8
223  vinfd = 0.0_8
224  call etot_d(rhoinf, rhoinfd, uinf, uinfd, vinf, vinfd, zinf, zinfd, &
225 & pinfcorr, pinfcorrd, ktmp, ktmpd, winf(irhoe), winfd(irhoe), &
226 & kpresent)
227  end subroutine referencestate_d
228 
229  subroutine referencestate()
230 !
231 ! the original version has been nuked since the computations are
232 ! no longer necessary when calling from python
233 ! this is the most compliclated routine in all of adflow. it is
234 ! stupidly complicated. this is most likely the reason your
235 ! derivatives are wrong. you don't understand this routine
236 ! and its effects.
237 ! this routine *requries* the following as input:
238 ! mach, pinfdim, tinfdim, rhoinfdim, rgasdim (machcoef non-sa
239 ! turbulence only)
240 ! optionally, pref, rhoref and tref are used if they are
241 ! are non-negative. this only happens when you want the equations
242 ! normalized by values other than the freestream
243 ! * this routine computes as output:
244 ! * muinfdim, (unused anywhere in code)
245 ! pref, rhoref, tref, muref, timeref ('dimensional' reference)
246 ! pinf, pinfcorr, rhoinf, uinf, rgas, muinf, gammainf and winf
247 ! (non-dimensionalized values used in actual computations)
248 !
249  use constants
250  use paramturb
251  use inputphysics, only : equations, mach, machcoef, musuthdim, &
257  use flowutils_d, only : computegamma, etot
258  use turbutils_d, only : sanuknowneddyratio
259  implicit none
260  integer(kind=inttype) :: sps, nn, mm, ierr
261  real(kind=realtype) :: gm1, ratio
262  real(kind=realtype) :: nuinf, ktmp, uinf2
263  real(kind=realtype) :: vinf, zinf, tmp1(1), tmp2(1)
264  intrinsic sqrt
265  real(kind=realtype) :: arg1
266  real(kind=realtype) :: result1
267 ! compute the dimensional viscosity from sutherland's law
269 & tinfdim/tsuthdim)**1.5_realtype
270 ! set the reference values. they *could* be different from the
271 ! free-stream values for an internal flow simulation. for now,
272 ! we just use the actual free stream values.
273  pref = pinfdim
274  tref = tinfdim
275  rhoref = rhoinfdim
276 ! compute the value of muref, such that the nondimensional
277 ! equations are identical to the dimensional ones.
278 ! note that in the non-dimensionalization of muref there is
279 ! a reference length. however this reference length is 1.0
280 ! in this code, because the coordinates are converted to
281 ! meters.
282  muref = sqrt(pref*rhoref)
283 ! compute timeref for a correct nondimensionalization of the
284 ! unsteady equations. some story as for the reference viscosity
285 ! concerning the reference length.
286  timeref = sqrt(rhoref/pref)
287  href = pref/rhoref
288  uref = sqrt(href)
289 ! compute the nondimensional pressure, density, velocity,
290 ! viscosity and gas constant.
291  pinf = pinfdim/pref
293  arg1 = gammainf*pinf/rhoinf
294  result1 = sqrt(arg1)
295  uinf = mach*result1
298  tmp1(1) = tinfdim
299  call computegamma(tmp1, tmp2, 1)
300  gammainf = tmp2(1)
301 ! ----------------------------------------
302 ! compute the final winf
303 ! ----------------------------------------
304 ! allocate the memory for winf if necessary
305 ! zero out the winf first
306  winf(:) = zero
307 ! set the reference value of the flow variables, except the total
308 ! energy. this will be computed at the end of this routine.
309  winf(irho) = rhoinf
313 ! compute the velocity squared based on machcoef. this gives a
314 ! better indication of the 'speed' of the flow so the turubulence
315 ! intensity ration is more meaningful especially for moving
316 ! geometries. (not used in sa model)
318 ! set the turbulent variables if transport variables are to be
319 ! solved. we should be checking for rans equations here,
320 ! however, this code is included in block res. the issue is
321 ! that for frozen turbulence (or ank jacobian) we call the
322 ! block_res with equationtype set to laminar even though we are
323 ! actually solving the rans equations. the issue is that, the
324 ! freestream turb variables will be changed to zero, thus
325 ! changing the solution. insteady we check if nw > nwf which
326 ! will accomplish the same thing.
327  if (nw .gt. nwf) then
328  nuinf = muinf/rhoinf
329  select case (turbmodel)
332 !=============================================================
334  winf(itu1) = 1.5_realtype*uinf2*turbintensityinf**2
335  winf(itu2) = winf(itu1)/(eddyvisinfratio*nuinf)
336 !=============================================================
337  case (ktau)
338  winf(itu1) = 1.5_realtype*uinf2*turbintensityinf**2
339  winf(itu2) = eddyvisinfratio*nuinf/winf(itu1)
340 !=============================================================
341  case (v2f)
342  winf(itu1) = 1.5_realtype*uinf2*turbintensityinf**2
343  winf(itu2) = 0.09_realtype*winf(itu1)**2/(eddyvisinfratio*nuinf)
344  winf(itu3) = 0.666666_realtype*winf(itu1)
345  winf(itu4) = 0.0_realtype
346  end select
347  end if
348 ! set the value of pinfcorr. in case a k-equation is present
349 ! add 2/3 times rho*k.
350  pinfcorr = pinf
352 ! compute the free stream total energy.
353  ktmp = zero
354  if (kpresent) ktmp = winf(itu1)
355  vinf = zero
356  zinf = zero
357  call etot(rhoinf, uinf, vinf, zinf, pinfcorr, ktmp, winf(irhoe), &
358 & kpresent)
359  end subroutine referencestate
360 ! ----------------------------------------------------------------------
361 ! |
362 ! no tapenade routine below this line |
363 ! |
364 ! ----------------------------------------------------------------------
365 
366 end module initializeflow_d
367 
integer(kind=inttype), parameter spalartallmarasedwards
Definition: constants.F90:128
integer(kind=inttype), parameter spalartallmaras
Definition: constants.F90:128
real(kind=realtype), parameter zero
Definition: constants.F90:71
integer, parameter itu3
Definition: constants.F90:43
real(kind=realtype), parameter third
Definition: constants.F90:81
integer, parameter itu2
Definition: constants.F90:42
integer(kind=inttype), parameter ktau
Definition: constants.F90:128
integer, parameter itu1
Definition: constants.F90:40
integer, parameter irho
Definition: constants.F90:34
integer(kind=inttype), parameter komegawilcox
Definition: constants.F90:128
integer(kind=inttype), parameter komegamodified
Definition: constants.F90:128
integer, parameter ivx
Definition: constants.F90:35
integer, parameter irhoe
Definition: constants.F90:38
integer, parameter maxstringlen
Definition: constants.F90:16
integer, parameter ivz
Definition: constants.F90:37
real(kind=realtype), parameter two
Definition: constants.F90:73
integer, parameter itu4
Definition: constants.F90:44
integer(kind=inttype), parameter mentersst
Definition: constants.F90:128
integer, parameter ivy
Definition: constants.F90:36
integer(kind=inttype), parameter v2f
Definition: constants.F90:128
subroutine etot(rho, u, v, w, p, k, etotal, correctfork)
subroutine etot_d(rho, rhod, u, ud, v, vd, w, wd, p, pd, k, kd, etotal, etotald, correctfork)
subroutine computegamma(t, gamma, mm)
real(kind=realtype) rhoinfdim
real(kind=realtype), dimension(:), allocatable winfd
real(kind=realtype) muinfdim
real(kind=realtype) gammainf
real(kind=realtype) href
real(kind=realtype) rhoinfd
real(kind=realtype) muinfdimd
real(kind=realtype) uinf
real(kind=realtype) muinfd
real(kind=realtype) pinfdim
real(kind=realtype) pinfcorr
real(kind=realtype) pinfcorrd
real(kind=realtype) pinf
real(kind=realtype) rgas
real(kind=realtype) uref
real(kind=realtype) trefd
real(kind=realtype) muref
real(kind=realtype) uinfd
real(kind=realtype) rgasd
real(kind=realtype) hrefd
real(kind=realtype) pinfdimd
real(kind=realtype) tinfdim
real(kind=realtype) prefd
real(kind=realtype) tinfdimd
real(kind=realtype) rhoref
integer(kind=inttype) nwf
real(kind=realtype), dimension(:), allocatable winf
real(kind=realtype) urefd
real(kind=realtype) muinf
real(kind=realtype) rhoinfdimd
real(kind=realtype) pinfd
real(kind=realtype) tref
integer(kind=inttype) nw
real(kind=realtype) murefd
real(kind=realtype) rhoinf
real(kind=realtype) pref
real(kind=realtype) rhorefd
real(kind=realtype) timeref
real(kind=realtype) timerefd
subroutine referencestate()
subroutine referencestate_d()
real(kind=realtype) ssuthdim
Definition: inputParam.F90:604
real(kind=realtype) turbintensityinf
Definition: inputParam.F90:597
real(kind=realtype) eddyvisinfratio
Definition: inputParam.F90:597
integer(kind=inttype) equations
Definition: inputParam.F90:583
real(kind=realtype) tsuthdim
Definition: inputParam.F90:604
real(kind=realtype), dimension(3) veldirfreestreamd
Definition: inputParam.F90:613
real(kind=realtype) machd
Definition: inputParam.F90:618
integer(kind=inttype) turbmodel
Definition: inputParam.F90:584
real(kind=realtype) machcoef
Definition: inputParam.F90:593
real(kind=realtype) machcoefd
Definition: inputParam.F90:618
real(kind=realtype) mach
Definition: inputParam.F90:593
real(kind=realtype) rgasdim
Definition: inputParam.F90:595
real(kind=realtype), dimension(3) veldirfreestream
Definition: inputParam.F90:599
real(kind=realtype) musuthdim
Definition: inputParam.F90:604
real(kind=realtype) function sanuknowneddyratio_d(eddyratio, nulam, nulamd, sanuknowneddyratio)
real(kind=realtype) function sanuknowneddyratio(eddyratio, nulam)