ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
initializeFlow_b.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 reverse (adjoint) mode (with options noisize i4 dr8 r8):
11 ! gradient of useful results: tinfdim pinf timeref rhoinf
12 ! muref rhoinfdim tref winf muinf uinf pinfcorr
13 ! pref pinfdim rgas rhoref mach veldirfreestream
14 ! machcoef
15 ! with respect to varying inputs: tinfdim pinf timeref rhoinf
16 ! muref rhoinfdim tref winf muinf uinf pinfcorr
17 ! pref pinfdim rgas rhoref mach veldirfreestream
18 ! machcoef
19 ! rw status of diff variables: tinfdim:incr pinf:in-zero timeref:in-zero
20 ! rhoinf:in-zero muref:in-zero rhoinfdim:incr tref:in-zero
21 ! winf:in-zero muinf:in-zero uinf:in-zero pinfcorr:in-zero
22 ! pref:in-zero pinfdim:incr rgas:in-zero rhoref:in-zero
23 ! mach:incr veldirfreestream:incr machcoef:incr
24  subroutine referencestate_b()
25 !
26 ! the original version has been nuked since the computations are
27 ! no longer necessary when calling from python
28 ! this is the most compliclated routine in all of adflow. it is
29 ! stupidly complicated. this is most likely the reason your
30 ! derivatives are wrong. you don't understand this routine
31 ! and its effects.
32 ! this routine *requries* the following as input:
33 ! mach, pinfdim, tinfdim, rhoinfdim, rgasdim (machcoef non-sa
34 ! turbulence only)
35 ! optionally, pref, rhoref and tref are used if they are
36 ! are non-negative. this only happens when you want the equations
37 ! normalized by values other than the freestream
38 ! * this routine computes as output:
39 ! * muinfdim, (unused anywhere in code)
40 ! pref, rhoref, tref, muref, timeref ('dimensional' reference)
41 ! pinf, pinfcorr, rhoinf, uinf, rgas, muinf, gammainf and winf
42 ! (non-dimensionalized values used in actual computations)
43 !
44  use constants
45  use paramturb
46  use inputphysics, only : equations, mach, machd, machcoef, &
55  use flowutils_b, only : computegamma, etot, etot_b
57  implicit none
58  integer(kind=inttype) :: sps, nn, mm, ierr
59  real(kind=realtype) :: gm1, ratio
60  real(kind=realtype) :: nuinf, ktmp, uinf2
61  real(kind=realtype) :: nuinfd, ktmpd, uinf2d
62  real(kind=realtype) :: vinf, zinf, tmp1(1), tmp2(1)
63  real(kind=realtype) :: vinfd, zinfd
64  intrinsic sqrt
65  real(kind=realtype) :: temp
66  real(kind=realtype) :: tempd
67  real(kind=realtype) :: temp0
68  real(kind=realtype) :: tempd0
69  real(kind=realtype) :: tmp
70  real(kind=realtype) :: tmpd
71  real(kind=realtype) :: tmp0
72  real(kind=realtype) :: tmpd0
73  real(kind=realtype) :: tmp3
74  real(kind=realtype) :: tmpd1
75  real(kind=realtype) :: tmp4
76  real(kind=realtype) :: tmpd2
77  integer :: branch
78 ! compute the dimensional viscosity from sutherland's law
80 & tinfdim/tsuthdim)**1.5_realtype
81 ! set the reference values. they *could* be different from the
82 ! free-stream values for an internal flow simulation. for now,
83 ! we just use the actual free stream values.
84  pref = pinfdim
85  tref = tinfdim
87 ! compute the value of muref, such that the nondimensional
88 ! equations are identical to the dimensional ones.
89 ! note that in the non-dimensionalization of muref there is
90 ! a reference length. however this reference length is 1.0
91 ! in this code, because the coordinates are converted to
92 ! meters.
93  muref = sqrt(pref*rhoref)
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 ! compute the nondimensional pressure, density, velocity,
98 ! viscosity and gas constant.
99  pinf = pinfdim/pref
101  uinf = mach*sqrt(gammainf*pinf/rhoinf)
103  call computegamma(tmp1, tmp2, 1)
104  call pushreal8(gammainf)
105  gammainf = tmp2(1)
106 ! ----------------------------------------
107 ! compute the final winf
108 ! ----------------------------------------
109 ! allocate the memory for winf if necessary
110 ! zero out the winf first
111  winf(:) = zero
112 ! set the reference value of the flow variables, except the total
113 ! energy. this will be computed at the end of this routine.
114  winf(irho) = rhoinf
118 ! compute the velocity squared based on machcoef. this gives a
119 ! better indication of the 'speed' of the flow so the turubulence
120 ! intensity ration is more meaningful especially for moving
121 ! geometries. (not used in sa model)
123 ! set the turbulent variables if transport variables are to be
124 ! solved. we should be checking for rans equations here,
125 ! however, this code is included in block res. the issue is
126 ! that for frozen turbulence (or ank jacobian) we call the
127 ! block_res with equationtype set to laminar even though we are
128 ! actually solving the rans equations. the issue is that, the
129 ! freestream turb variables will be changed to zero, thus
130 ! changing the solution. insteady we check if nw > nwf which
131 ! will accomplish the same thing.
132  if (nw .gt. nwf) then
133  nuinf = muinf/rhoinf
134  select case (turbmodel)
137 !=============================================================
138  call pushcontrol3b(1)
140  winf(itu1) = 1.5_realtype*uinf2*turbintensityinf**2
141  tmp = winf(itu1)/(eddyvisinfratio*nuinf)
142  call pushreal8(winf(itu2))
143  winf(itu2) = tmp
144 !=============================================================
145  call pushcontrol3b(2)
146  case (ktau)
147  winf(itu1) = 1.5_realtype*uinf2*turbintensityinf**2
148  tmp0 = eddyvisinfratio*nuinf/winf(itu1)
149  call pushreal8(winf(itu2))
150  winf(itu2) = tmp0
151 !=============================================================
152  call pushcontrol3b(3)
153  case (v2f)
154  winf(itu1) = 1.5_realtype*uinf2*turbintensityinf**2
155  tmp3 = 0.09_realtype*winf(itu1)**2/(eddyvisinfratio*nuinf)
156  call pushreal8(winf(itu2))
157  winf(itu2) = tmp3
158  tmp4 = 0.666666_realtype*winf(itu1)
159  call pushreal8(winf(itu3))
160  winf(itu3) = tmp4
161  call pushreal8(winf(itu4))
162  winf(itu4) = 0.0_realtype
163  call pushcontrol3b(4)
164  case default
165  call pushcontrol3b(0)
166  end select
167  else
168  call pushcontrol3b(5)
169  end if
170 ! set the value of pinfcorr. in case a k-equation is present
171 ! add 2/3 times rho*k.
172  pinfcorr = pinf
173  if (kpresent) then
175  call pushcontrol1b(0)
176  else
177  call pushcontrol1b(1)
178  end if
179 ! compute the free stream total energy.
180  ktmp = zero
181  if (kpresent) then
182  ktmp = winf(itu1)
183  call pushcontrol1b(0)
184  else
185  call pushcontrol1b(1)
186  end if
187  vinf = zero
188  zinf = zero
189  vinfd = 0.0_8
190  zinfd = 0.0_8
191  ktmpd = 0.0_8
192  call etot_b(rhoinf, rhoinfd, uinf, uinfd, vinf, vinfd, zinf, zinfd, &
193 & pinfcorr, pinfcorrd, ktmp, ktmpd, winf(irhoe), winfd(irhoe), &
194 & kpresent)
195  call popcontrol1b(branch)
196  if (branch .eq. 0) winfd(itu1) = winfd(itu1) + ktmpd
197  call popcontrol1b(branch)
198  if (branch .eq. 0) then
199  pinfd = pinfd + pinfcorrd
200  tempd0 = two*third*pinfcorrd
201  rhoinfd = rhoinfd + winf(itu1)*tempd0
202  winfd(itu1) = winfd(itu1) + rhoinf*tempd0
203  pinfcorrd = 0.0_8
204  end if
205  pinfd = pinfd + pinfcorrd
206  call popcontrol3b(branch)
207  if (branch .lt. 3) then
208  if (branch .eq. 0) then
209  uinf2d = 0.0_8
210  nuinfd = 0.0_8
211  else if (branch .eq. 1) then
212  call sanuknowneddyratio_b(eddyvisinfratio, nuinf, nuinfd, winfd(&
213 & itu1))
214  winfd(itu1) = 0.0_8
215  uinf2d = 0.0_8
216  else
217  call popreal8(winf(itu2))
218  tmpd = winfd(itu2)
219  winfd(itu2) = 0.0_8
220  tempd0 = tmpd/(eddyvisinfratio*nuinf)
221  winfd(itu1) = winfd(itu1) + tempd0
222  nuinfd = -(winf(itu1)*tempd0/nuinf)
223  uinf2d = 1.5_realtype*turbintensityinf**2*winfd(itu1)
224  winfd(itu1) = 0.0_8
225  end if
226  else if (branch .eq. 3) then
227  call popreal8(winf(itu2))
228  tmpd0 = winfd(itu2)
229  winfd(itu2) = 0.0_8
230  tempd0 = eddyvisinfratio*tmpd0/winf(itu1)
231  nuinfd = tempd0
232  winfd(itu1) = winfd(itu1) - nuinf*tempd0/winf(itu1)
233  uinf2d = 1.5_realtype*turbintensityinf**2*winfd(itu1)
234  winfd(itu1) = 0.0_8
235  else if (branch .eq. 4) then
236  call popreal8(winf(itu4))
237  winfd(itu4) = 0.0_8
238  call popreal8(winf(itu3))
239  tmpd2 = winfd(itu3)
240  winfd(itu3) = 0.0_8
241  winfd(itu1) = winfd(itu1) + 0.666666_realtype*tmpd2
242  call popreal8(winf(itu2))
243  tmpd1 = winfd(itu2)
244  winfd(itu2) = 0.0_8
245  tempd0 = 0.09_realtype*tmpd1/(eddyvisinfratio*nuinf)
246  winfd(itu1) = winfd(itu1) + 2*winf(itu1)*tempd0
247  nuinfd = -(winf(itu1)**2*tempd0/nuinf)
248  uinf2d = 1.5_realtype*turbintensityinf**2*winfd(itu1)
249  winfd(itu1) = 0.0_8
250  else
251  uinf2d = 0.0_8
252  goto 100
253  end if
254  muinfd = muinfd + nuinfd/rhoinf
255  rhoinfd = rhoinfd - muinf*nuinfd/rhoinf**2
256  100 if (rhoref/pref .eq. 0.0_8) then
257  tempd = 0.0_8
258  else
259  tempd = timerefd/(pref*2.0*sqrt(rhoref/pref))
260  end if
262  tempd0 = machcoef**2*gammainf*uinf2d/rhoinf
263  pinfd = pinfd + tempd0
264  rhoinfd = rhoinfd - pinf*tempd0/rhoinf
267  winfd(ivz) = 0.0_8
270  winfd(ivy) = 0.0_8
273  winfd(ivx) = 0.0_8
274  call popreal8(gammainf)
277  tempd0 = rgasdim*rgasd/pref
278  rhorefd = rhorefd + tref*tempd0
279  trefd = trefd + rhoref*tempd0
280  prefd = prefd - rhoref*tref*tempd0/pref
281  temp = gammainf*pinf/rhoinf
282  temp0 = sqrt(temp)
283  machd = machd + temp0*uinfd
284  if (temp .eq. 0.0_8) then
285  tempd0 = 0.0_8
286  else
287  tempd0 = gammainf*mach*uinfd/(rhoinf*2.0*temp0)
288  end if
289  rhoinfd = rhoinfd + winfd(irho) - pinf*tempd0/rhoinf
290  pinfd = pinfd + tempd0
291  rhorefd = rhorefd + tempd - rhoinfdim*rhoinfd/rhoref**2
292  prefd = prefd - pinfdim*pinfd/pref**2 - rhoref*tempd/pref
293  if (pref*rhoref .eq. 0.0_8) then
294  tempd = 0.0_8
295  else
296  tempd = murefd/(2.0*sqrt(pref*rhoref))
297  end if
298  prefd = prefd + rhoref*tempd
300  rhorefd = rhorefd + pref*tempd
303  tinfdimd = tinfdimd + trefd + (1.5_realtype*(tinfdim/tsuthdim)**0.5/&
304 & tsuthdim-(tinfdim/tsuthdim)**1.5_realtype/(ssuthdim+tinfdim))*&
305 & tempd
306  pinfd = 0.0_8
307  timerefd = 0.0_8
308  rhoinfd = 0.0_8
309  murefd = 0.0_8
310  trefd = 0.0_8
311  winfd = 0.0_8
312  muinfd = 0.0_8
313  uinfd = 0.0_8
314  pinfcorrd = 0.0_8
315  prefd = 0.0_8
316  rgasd = 0.0_8
317  rhorefd = 0.0_8
318  end subroutine referencestate_b
319 
320  subroutine referencestate()
321 !
322 ! the original version has been nuked since the computations are
323 ! no longer necessary when calling from python
324 ! this is the most compliclated routine in all of adflow. it is
325 ! stupidly complicated. this is most likely the reason your
326 ! derivatives are wrong. you don't understand this routine
327 ! and its effects.
328 ! this routine *requries* the following as input:
329 ! mach, pinfdim, tinfdim, rhoinfdim, rgasdim (machcoef non-sa
330 ! turbulence only)
331 ! optionally, pref, rhoref and tref are used if they are
332 ! are non-negative. this only happens when you want the equations
333 ! normalized by values other than the freestream
334 ! * this routine computes as output:
335 ! * muinfdim, (unused anywhere in code)
336 ! pref, rhoref, tref, muref, timeref ('dimensional' reference)
337 ! pinf, pinfcorr, rhoinf, uinf, rgas, muinf, gammainf and winf
338 ! (non-dimensionalized values used in actual computations)
339 !
340  use constants
341  use paramturb
342  use inputphysics, only : equations, mach, machcoef, musuthdim, &
348  use flowutils_b, only : computegamma, etot
349  use turbutils_b, only : sanuknowneddyratio
350  implicit none
351  integer(kind=inttype) :: sps, nn, mm, ierr
352  real(kind=realtype) :: gm1, ratio
353  real(kind=realtype) :: nuinf, ktmp, uinf2
354  real(kind=realtype) :: vinf, zinf, tmp1(1), tmp2(1)
355  intrinsic sqrt
356 ! compute the dimensional viscosity from sutherland's law
358 & tinfdim/tsuthdim)**1.5_realtype
359 ! set the reference values. they *could* be different from the
360 ! free-stream values for an internal flow simulation. for now,
361 ! we just use the actual free stream values.
362  pref = pinfdim
363  tref = tinfdim
364  rhoref = rhoinfdim
365 ! compute the value of muref, such that the nondimensional
366 ! equations are identical to the dimensional ones.
367 ! note that in the non-dimensionalization of muref there is
368 ! a reference length. however this reference length is 1.0
369 ! in this code, because the coordinates are converted to
370 ! meters.
371  muref = sqrt(pref*rhoref)
372 ! compute timeref for a correct nondimensionalization of the
373 ! unsteady equations. some story as for the reference viscosity
374 ! concerning the reference length.
375  timeref = sqrt(rhoref/pref)
376  href = pref/rhoref
377  uref = sqrt(href)
378 ! compute the nondimensional pressure, density, velocity,
379 ! viscosity and gas constant.
380  pinf = pinfdim/pref
382  uinf = mach*sqrt(gammainf*pinf/rhoinf)
385  tmp1(1) = tinfdim
386  call computegamma(tmp1, tmp2, 1)
387  gammainf = tmp2(1)
388 ! ----------------------------------------
389 ! compute the final winf
390 ! ----------------------------------------
391 ! allocate the memory for winf if necessary
392 ! zero out the winf first
393  winf(:) = zero
394 ! set the reference value of the flow variables, except the total
395 ! energy. this will be computed at the end of this routine.
396  winf(irho) = rhoinf
400 ! compute the velocity squared based on machcoef. this gives a
401 ! better indication of the 'speed' of the flow so the turubulence
402 ! intensity ration is more meaningful especially for moving
403 ! geometries. (not used in sa model)
405 ! set the turbulent variables if transport variables are to be
406 ! solved. we should be checking for rans equations here,
407 ! however, this code is included in block res. the issue is
408 ! that for frozen turbulence (or ank jacobian) we call the
409 ! block_res with equationtype set to laminar even though we are
410 ! actually solving the rans equations. the issue is that, the
411 ! freestream turb variables will be changed to zero, thus
412 ! changing the solution. insteady we check if nw > nwf which
413 ! will accomplish the same thing.
414  if (nw .gt. nwf) then
415  nuinf = muinf/rhoinf
416  select case (turbmodel)
419 !=============================================================
421  winf(itu1) = 1.5_realtype*uinf2*turbintensityinf**2
422  winf(itu2) = winf(itu1)/(eddyvisinfratio*nuinf)
423 !=============================================================
424  case (ktau)
425  winf(itu1) = 1.5_realtype*uinf2*turbintensityinf**2
426  winf(itu2) = eddyvisinfratio*nuinf/winf(itu1)
427 !=============================================================
428  case (v2f)
429  winf(itu1) = 1.5_realtype*uinf2*turbintensityinf**2
430  winf(itu2) = 0.09_realtype*winf(itu1)**2/(eddyvisinfratio*nuinf)
431  winf(itu3) = 0.666666_realtype*winf(itu1)
432  winf(itu4) = 0.0_realtype
433  end select
434  end if
435 ! set the value of pinfcorr. in case a k-equation is present
436 ! add 2/3 times rho*k.
437  pinfcorr = pinf
439 ! compute the free stream total energy.
440  ktmp = zero
441  if (kpresent) ktmp = winf(itu1)
442  vinf = zero
443  zinf = zero
444  call etot(rhoinf, uinf, vinf, zinf, pinfcorr, ktmp, winf(irhoe), &
445 & kpresent)
446  end subroutine referencestate
447 ! ----------------------------------------------------------------------
448 ! |
449 ! no tapenade routine below this line |
450 ! |
451 ! ----------------------------------------------------------------------
452 
453 end module initializeflow_b
454 
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_b(rho, rhod, u, ud, v, vd, w, wd, p, pd, k, kd, etotal, etotald, correctfork)
subroutine etot(rho, u, v, w, p, k, etotal, 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_b()
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
subroutine sanuknowneddyratio_b(eddyratio, nulam, nulamd, sanuknowneddyratiod)
real(kind=realtype) function sanuknowneddyratio(eddyratio, nulam)