ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
flowUtils_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 !
4 module flowutils_b
5  implicit none
6 
7 contains
8 ! differentiation of computettot in reverse (adjoint) mode (with options noisize i4 dr8 r8):
9 ! gradient of useful results: rgas p u v w ttot rho
10 ! with respect to varying inputs: rgas p u v w ttot rho
11  subroutine computettot_b(rho, rhod, u, ud, v, vd, w, wd, p, pd, ttot, &
12 & ttotd)
13 !
14 ! computettot computes the total temperature for the given
15 ! pressures, densities and velocities.
16 !
17  use constants
18  use inputphysics, only : cpmodel
19  use flowvarrefstate, only : rgas, rgasd, gammainf
20  use utils_b, only : terminate
21  implicit none
22 !
23 ! subroutine arguments.
24 !
25  real(kind=realtype), intent(in) :: rho, p, u, v, w
26  real(kind=realtype) :: rhod, pd, ud, vd, wd
27  real(kind=realtype) :: ttot
28  real(kind=realtype) :: ttotd
29 !
30 ! local variables.
31 !
32  integer(kind=inttype) :: i
33  real(kind=realtype) :: govgm1, t, kin
34  real(kind=realtype) :: td, kind0
35  real(kind=realtype) :: tempd
36  real(kind=realtype) :: temp
37  real(kind=realtype) :: tempd0
38 ! determine the cp model used.
39  select case (cpmodel)
40  case (cpconstant)
41 ! constant cp and thus constant gamma. the well-known
42 ! formula is valid.
43  govgm1 = gammainf/(gammainf-one)
44  t = p/(rho*rgas)
45  kin = half*(u*u+v*v+w*w)
46 !===============================================================
47  temp = rho*kin/(govgm1*p)
48  td = (one+temp)*ttotd
49  tempd0 = t*ttotd/(govgm1*p)
50  rhod = rhod + kin*tempd0
51  kind0 = rho*tempd0
52  tempd = td/(rho*rgas)
53  pd = pd + tempd - govgm1*temp*tempd0
54  tempd0 = half*kind0
55  ud = ud + 2*u*tempd0
56  vd = vd + 2*v*tempd0
57  wd = wd + 2*w*tempd0
58  tempd0 = -(p*tempd/(rho*rgas))
59  rhod = rhod + rgas*tempd0
60  rgasd = rgasd + rho*tempd0
61  ttotd = 0.0_8
62  end select
63  end subroutine computettot_b
64 
65  subroutine computettot(rho, u, v, w, p, ttot)
66 !
67 ! computettot computes the total temperature for the given
68 ! pressures, densities and velocities.
69 !
70  use constants
71  use inputphysics, only : cpmodel
72  use flowvarrefstate, only : rgas, gammainf
73  use utils_b, only : terminate
74  implicit none
75 !
76 ! subroutine arguments.
77 !
78  real(kind=realtype), intent(in) :: rho, p, u, v, w
79  real(kind=realtype), intent(out) :: ttot
80 !
81 ! local variables.
82 !
83  integer(kind=inttype) :: i
84  real(kind=realtype) :: govgm1, t, kin
85 ! determine the cp model used.
86  select case (cpmodel)
87  case (cpconstant)
88 ! constant cp and thus constant gamma. the well-known
89 ! formula is valid.
90  govgm1 = gammainf/(gammainf-one)
91  t = p/(rho*rgas)
92  kin = half*(u*u+v*v+w*w)
93  ttot = t*(one+rho*kin/(govgm1*p))
94 !===============================================================
95  case (cptempcurvefits)
96 ! cp is a function of the temperature. the formula used for
97 ! constant cp is not valid anymore and a more complicated
98 ! procedure must be followed.
99  call terminate('computettot', &
100 & 'variable cp formulation not implemented yet')
101  end select
102  end subroutine computettot
103 
104  subroutine computegamma(t, gamma, mm)
105 !
106 ! computegamma computes the corresponding values of gamma for
107 ! the given dimensional temperatures.
108 !
109  use constants
110  use cpcurvefits
111  use inputphysics, only : cpmodel, gammaconstant
112  implicit none
113 !
114 ! subroutine arguments.
115 !
116  integer(kind=inttype), intent(in) :: mm
117  real(kind=realtype), dimension(mm), intent(in) :: t
118  real(kind=realtype), dimension(mm), intent(out) :: gamma
119 !
120 ! local variables.
121 !
122  integer(kind=inttype) :: i, ii, nn, start
123  real(kind=realtype) :: cp, t2
124 ! determine the cp model used in the computation.
125  select case (cpmodel)
126  case (cpconstant)
127 ! constant cp and thus constant gamma. set the values.
128  do i=1,mm
129  gamma(i) = gammaconstant
130  end do
131  end select
132 ! ================================================================
133 
134  end subroutine computegamma
135 
136 ! differentiation of computeptot in reverse (adjoint) mode (with options noisize i4 dr8 r8):
137 ! gradient of useful results: p u v w ptot rho
138 ! with respect to varying inputs: p u v w ptot rho
139  subroutine computeptot_b(rho, rhod, u, ud, v, vd, w, wd, p, pd, ptot, &
140 & ptotd)
141 !
142 ! computeptot computes the total pressure for the given
143 ! pressures, densities and velocities.
144 !
145  use constants
146  use cpcurvefits
147  use flowvarrefstate, only : tref, trefd, rgas, rgasd, gammainf
148  use inputphysics, only : cpmodel
149  implicit none
150  real(kind=realtype), intent(in) :: rho, p, u, v, w
151  real(kind=realtype) :: rhod, pd, ud, vd, wd
152  real(kind=realtype) :: ptot
153  real(kind=realtype) :: ptotd
154 !
155 ! local parameters.
156 !
157  real(kind=realtype), parameter :: dtstop=0.01_realtype
158 !
159 ! local variables.
160 !
161  integer(kind=inttype) :: i, ii, mm, nn, nnt, start
162  real(kind=realtype) :: govgm1, kin
163  real(kind=realtype) :: kind0
164  real(kind=realtype) :: t, t2, tt, dt, h, htot, cp, scale, alp
165  real(kind=realtype) :: intcport, intcportt, intcporttt
166  real(kind=realtype) :: temp
167  real(kind=realtype) :: tempd
168 !
169 ! determine the cp model used.
170  select case (cpmodel)
171  case (cpconstant)
172 ! constant cp and thus constant gamma. the well-known
173 ! formula is valid.
174  govgm1 = gammainf/(gammainf-one)
175  kin = half*(u*u+v*v+w*w)
176 !===============================================================
177  temp = rho*kin/(govgm1*p)
178  if (one + temp .le. 0.0_8 .and. (govgm1 .eq. 0.0_8 .or. govgm1 &
179 & .ne. int(govgm1))) then
180  tempd = 0.0_8
181  else
182  tempd = (one+temp)**(govgm1-1)*ptotd
183  end if
184  pd = pd + (one+temp)**govgm1*ptotd - govgm1*temp*tempd
185  rhod = rhod + kin*tempd
186  kind0 = rho*tempd
187  tempd = half*kind0
188  ud = ud + 2*u*tempd
189  vd = vd + 2*v*tempd
190  wd = wd + 2*w*tempd
191  ptotd = 0.0_8
192  end select
193  end subroutine computeptot_b
194 
195  subroutine computeptot(rho, u, v, w, p, ptot)
196 !
197 ! computeptot computes the total pressure for the given
198 ! pressures, densities and velocities.
199 !
200  use constants
201  use cpcurvefits
202  use flowvarrefstate, only : tref, rgas, gammainf
203  use inputphysics, only : cpmodel
204  implicit none
205  real(kind=realtype), intent(in) :: rho, p, u, v, w
206  real(kind=realtype), intent(out) :: ptot
207 !
208 ! local parameters.
209 !
210  real(kind=realtype), parameter :: dtstop=0.01_realtype
211 !
212 ! local variables.
213 !
214  integer(kind=inttype) :: i, ii, mm, nn, nnt, start
215  real(kind=realtype) :: govgm1, kin
216  real(kind=realtype) :: t, t2, tt, dt, h, htot, cp, scale, alp
217  real(kind=realtype) :: intcport, intcportt, intcporttt
218 !
219 ! determine the cp model used.
220  select case (cpmodel)
221  case (cpconstant)
222 ! constant cp and thus constant gamma. the well-known
223 ! formula is valid.
224  govgm1 = gammainf/(gammainf-one)
225  kin = half*(u*u+v*v+w*w)
226  ptot = p*(one+rho*kin/(govgm1*p))**govgm1
227 !===============================================================
228  end select
229  end subroutine computeptot
230 
231 ! differentiation of computespeedofsoundsquared in reverse (adjoint) mode (with options noisize i4 dr8 r8):
232 ! gradient of useful results: *aa *p *w
233 ! with respect to varying inputs: *aa *p *w
234 ! rw status of diff variables: *aa:in-out *p:incr *w:incr
235 ! plus diff mem management of: aa:in p:in w:in
237 !
238 ! computespeedofsoundsquared does what it says.
239 !
240  use constants
241  use blockpointers, only : ie, je, ke, w, wd, p, pd, aa, aad, gamma
242  use utils_b, only : getcorrectfork
243  implicit none
244 !
245 ! local variables.
246 !
247  real(kind=realtype), parameter :: twothird=two*third
248  integer(kind=inttype) :: i, j, k, ii
249  real(kind=realtype) :: pp
250  real(kind=realtype) :: ppd
251  logical :: correctfork
252  intrinsic mod
253  real(kind=realtype) :: temp
254  real(kind=realtype) :: temp0
255  real(kind=realtype) :: tempd
256  real(kind=realtype) :: tempd0
257 ! determine if we need to correct for k
258  correctfork = getcorrectfork()
259  if (correctfork) then
260 !$bwd-of ii-loop
261  do ii=0,ie*je*ke-1
262  i = mod(ii, ie) + 1
263  j = mod(ii/ie, je) + 1
264  k = ii/(ie*je) + 1
265  pp = p(i, j, k) - twothird*w(i, j, k, irho)*w(i, j, k, itu1)
266  temp = w(i, j, k, irho)
267  tempd = gamma(i, j, k)*aad(i, j, k)/temp
268  aad(i, j, k) = 0.0_8
269  ppd = tempd
270  wd(i, j, k, irho) = wd(i, j, k, irho) - pp*tempd/temp - w(i, j, &
271 & k, itu1)*twothird*ppd
272  pd(i, j, k) = pd(i, j, k) + ppd
273  wd(i, j, k, itu1) = wd(i, j, k, itu1) - w(i, j, k, irho)*&
274 & twothird*ppd
275  end do
276  else
277 !$bwd-of ii-loop
278  do ii=0,ie*je*ke-1
279  i = mod(ii, ie) + 1
280  j = mod(ii/ie, je) + 1
281  k = ii/(ie*je) + 1
282  temp0 = w(i, j, k, irho)
283  tempd0 = gamma(i, j, k)*aad(i, j, k)/temp0
284  aad(i, j, k) = 0.0_8
285  pd(i, j, k) = pd(i, j, k) + tempd0
286  wd(i, j, k, irho) = wd(i, j, k, irho) - p(i, j, k)*tempd0/temp0
287  end do
288  end if
289  end subroutine computespeedofsoundsquared_b
290 
292 !
293 ! computespeedofsoundsquared does what it says.
294 !
295  use constants
296  use blockpointers, only : ie, je, ke, w, p, aa, gamma
297  use utils_b, only : getcorrectfork
298  implicit none
299 !
300 ! local variables.
301 !
302  real(kind=realtype), parameter :: twothird=two*third
303  integer(kind=inttype) :: i, j, k, ii
304  real(kind=realtype) :: pp
305  logical :: correctfork
306  intrinsic mod
307 ! determine if we need to correct for k
308  correctfork = getcorrectfork()
309  if (correctfork) then
310 !$ad ii-loop
311  do ii=0,ie*je*ke-1
312  i = mod(ii, ie) + 1
313  j = mod(ii/ie, je) + 1
314  k = ii/(ie*je) + 1
315  pp = p(i, j, k) - twothird*w(i, j, k, irho)*w(i, j, k, itu1)
316  aa(i, j, k) = gamma(i, j, k)*pp/w(i, j, k, irho)
317  end do
318  else
319 !$ad ii-loop
320  do ii=0,ie*je*ke-1
321  i = mod(ii, ie) + 1
322  j = mod(ii/ie, je) + 1
323  k = ii/(ie*je) + 1
324  aa(i, j, k) = gamma(i, j, k)*p(i, j, k)/w(i, j, k, irho)
325  end do
326  end if
327  end subroutine computespeedofsoundsquared
328 
329 ! differentiation of computeetotblock in reverse (adjoint) mode (with options noisize i4 dr8 r8):
330 ! gradient of useful results: *p *w
331 ! with respect to varying inputs: *p *w
332 ! rw status of diff variables: *p:incr *w:in-out
333 ! plus diff mem management of: p:in w:in
334  subroutine computeetotblock_b(istart, iend, jstart, jend, kstart, kend&
335 & , correctfork)
336 !
337 ! computeetot computes the total energy from the given density,
338 ! velocity and presssure. for a calorically and thermally
339 ! perfect gas the well-known expression is used; for only a
340 ! thermally perfect gas, cp is a function of temperature, curve
341 ! fits are used and a more complex expression is obtained.
342 ! it is assumed that the pointers in blockpointers already
343 ! point to the correct block.
344 !
345  use constants
346  use blockpointers, only : w, wd, p, pd
347  use flowvarrefstate, only : rgas, rgasd, tref, trefd
348  use inputphysics, only : cpmodel, gammaconstant
349  implicit none
350 !
351 ! subroutine arguments.
352 !
353  integer(kind=inttype), intent(in) :: istart, iend, jstart, jend
354  integer(kind=inttype), intent(in) :: kstart, kend
355  logical, intent(in) :: correctfork
356 !
357 ! local variables.
358 !
359  integer(kind=inttype) :: i, j, k, ii, isize, jsize, ksize
360  real(kind=realtype) :: ovgm1, factk, scale
361  intrinsic mod
362  real(kind=realtype) :: tmp
363  real(kind=realtype) :: tmpd
364  real(kind=realtype) :: temp
365  real(kind=realtype) :: temp0
366  real(kind=realtype) :: temp1
367  real(kind=realtype) :: temp2
368  real(kind=realtype) :: tempd
369  real(kind=realtype) :: tmp0
370  real(kind=realtype) :: tmpd0
371  real(kind=realtype) :: tempd0
372 !
373 ! determine the cp model used in the computation.
374  select case (cpmodel)
375  case (cpconstant)
376 ! constant cp and thus constant gamma.
377 ! abbreviate 1/(gamma -1) a bit easier.
378  ovgm1 = one/(gammaconstant-one)
379 ! loop over the given range of the block and compute the first
380 ! step of the energy.
381  isize = iend - istart + 1
382  jsize = jend - jstart + 1
383  ksize = kend - kstart + 1
384  factk = ovgm1*(five*third-gammaconstant)
385  if (correctfork) then
386 !$bwd-of ii-loop
387  do ii=0,isize*jsize*ksize-1
388  i = mod(ii, isize) + istart
389  j = mod(ii/isize, jsize) + jstart
390  k = ii/(isize*jsize) + kstart
391  tmpd = wd(i, j, k, irhoe)
392  wd(i, j, k, irhoe) = 0.0_8
393  temp = w(i, j, k, ivz)
394  temp0 = w(i, j, k, ivy)
395  temp1 = w(i, j, k, ivx)
396  pd(i, j, k) = pd(i, j, k) + ovgm1*tmpd
397  wd(i, j, k, irho) = wd(i, j, k, irho) + ((temp1**2+temp0**2+&
398 & temp**2)*half-w(i, j, k, itu1)*factk)*tmpd
399  tempd = w(i, j, k, irho)*half*tmpd
400  wd(i, j, k, itu1) = wd(i, j, k, itu1) - w(i, j, k, irho)*factk&
401 & *tmpd
402  wd(i, j, k, ivx) = wd(i, j, k, ivx) + 2*temp1*tempd
403  wd(i, j, k, ivy) = wd(i, j, k, ivy) + 2*temp0*tempd
404  wd(i, j, k, ivz) = wd(i, j, k, ivz) + 2*temp*tempd
405  end do
406  else
407 !$bwd-of ii-loop
408  do ii=0,isize*jsize*ksize-1
409  i = mod(ii, isize) + istart
410  j = mod(ii/isize, jsize) + jstart
411  k = ii/(isize*jsize) + kstart
412  tmpd0 = wd(i, j, k, irhoe)
413  wd(i, j, k, irhoe) = 0.0_8
414  temp2 = w(i, j, k, ivz)
415  temp1 = w(i, j, k, ivy)
416  temp0 = w(i, j, k, ivx)
417  pd(i, j, k) = pd(i, j, k) + ovgm1*tmpd0
418  wd(i, j, k, irho) = wd(i, j, k, irho) + (temp0**2+temp1**2+&
419 & temp2**2)*half*tmpd0
420  tempd0 = w(i, j, k, irho)*half*tmpd0
421  wd(i, j, k, ivx) = wd(i, j, k, ivx) + 2*temp0*tempd0
422  wd(i, j, k, ivy) = wd(i, j, k, ivy) + 2*temp1*tempd0
423  wd(i, j, k, ivz) = wd(i, j, k, ivz) + 2*temp2*tempd0
424  end do
425  end if
426  end select
427  end subroutine computeetotblock_b
428 
429  subroutine computeetotblock(istart, iend, jstart, jend, kstart, kend, &
430 & correctfork)
431 !
432 ! computeetot computes the total energy from the given density,
433 ! velocity and presssure. for a calorically and thermally
434 ! perfect gas the well-known expression is used; for only a
435 ! thermally perfect gas, cp is a function of temperature, curve
436 ! fits are used and a more complex expression is obtained.
437 ! it is assumed that the pointers in blockpointers already
438 ! point to the correct block.
439 !
440  use constants
441  use blockpointers, only : w, p
442  use flowvarrefstate, only : rgas, tref
443  use inputphysics, only : cpmodel, gammaconstant
444  implicit none
445 !
446 ! subroutine arguments.
447 !
448  integer(kind=inttype), intent(in) :: istart, iend, jstart, jend
449  integer(kind=inttype), intent(in) :: kstart, kend
450  logical, intent(in) :: correctfork
451 !
452 ! local variables.
453 !
454  integer(kind=inttype) :: i, j, k, ii, isize, jsize, ksize
455  real(kind=realtype) :: ovgm1, factk, scale
456  intrinsic mod
457 !
458 ! determine the cp model used in the computation.
459  select case (cpmodel)
460  case (cpconstant)
461 ! constant cp and thus constant gamma.
462 ! abbreviate 1/(gamma -1) a bit easier.
463  ovgm1 = one/(gammaconstant-one)
464 ! loop over the given range of the block and compute the first
465 ! step of the energy.
466  isize = iend - istart + 1
467  jsize = jend - jstart + 1
468  ksize = kend - kstart + 1
469  factk = ovgm1*(five*third-gammaconstant)
470  if (correctfork) then
471 !$ad ii-loop
472  do ii=0,isize*jsize*ksize-1
473  i = mod(ii, isize) + istart
474  j = mod(ii/isize, jsize) + jstart
475  k = ii/(isize*jsize) + kstart
476  w(i, j, k, irhoe) = ovgm1*p(i, j, k) + half*w(i, j, k, irho)*(&
477 & w(i, j, k, ivx)**2+w(i, j, k, ivy)**2+w(i, j, k, ivz)**2) - &
478 & factk*w(i, j, k, irho)*w(i, j, k, itu1)
479  end do
480  else
481 !$ad ii-loop
482  do ii=0,isize*jsize*ksize-1
483  i = mod(ii, isize) + istart
484  j = mod(ii/isize, jsize) + jstart
485  k = ii/(isize*jsize) + kstart
486  w(i, j, k, irhoe) = ovgm1*p(i, j, k) + half*w(i, j, k, irho)*(&
487 & w(i, j, k, ivx)**2+w(i, j, k, ivy)**2+w(i, j, k, ivz)**2)
488  end do
489  end if
490  end select
491  end subroutine computeetotblock
492 
493 ! differentiation of etot in reverse (adjoint) mode (with options noisize i4 dr8 r8):
494 ! gradient of useful results: k p u v w etotal rho
495 ! with respect to varying inputs: k p u v w etotal rho
496  subroutine etot_b(rho, rhod, u, ud, v, vd, w, wd, p, pd, k, kd, etotal&
497 & , etotald, correctfork)
498 !
499 ! etotarray computes the total energy from the given density,
500 ! velocity and presssure.
501 ! first the internal energy per unit mass is computed and after
502 ! that the kinetic energy is added as well the conversion to
503 ! energy per unit volume.
504 !
505  use constants
506  implicit none
507 !
508 ! subroutine arguments.
509 !
510  real(kind=realtype), intent(in) :: rho, p, k
511  real(kind=realtype) :: rhod, pd, kd
512  real(kind=realtype), intent(in) :: u, v, w
513  real(kind=realtype) :: ud, vd, wd
514  real(kind=realtype) :: etotal
515  real(kind=realtype) :: etotald
516  logical, intent(in) :: correctfork
517 !
518 ! local variables.
519 !
520  integer(kind=inttype) :: i
521  real(kind=realtype) :: tempd
522 ! compute the internal energy for unit mass.
523  call pushreal8(etotal)
524  call eint(rho, p, k, etotal, correctfork)
525  rhod = rhod + (etotal+half*(u**2+v**2+w**2))*etotald
526  tempd = half*rho*etotald
527  etotald = rho*etotald
528  ud = ud + 2*u*tempd
529  vd = vd + 2*v*tempd
530  wd = wd + 2*w*tempd
531  call popreal8(etotal)
532  call eint_b(rho, rhod, p, pd, k, kd, etotal, etotald, correctfork)
533  end subroutine etot_b
534 
535  subroutine etot(rho, u, v, w, p, k, etotal, correctfork)
536 !
537 ! etotarray computes the total energy from the given density,
538 ! velocity and presssure.
539 ! first the internal energy per unit mass is computed and after
540 ! that the kinetic energy is added as well the conversion to
541 ! energy per unit volume.
542 !
543  use constants
544  implicit none
545 !
546 ! subroutine arguments.
547 !
548  real(kind=realtype), intent(in) :: rho, p, k
549  real(kind=realtype), intent(in) :: u, v, w
550  real(kind=realtype), intent(out) :: etotal
551  logical, intent(in) :: correctfork
552 !
553 ! local variables.
554 !
555  integer(kind=inttype) :: i
556 ! compute the internal energy for unit mass.
557  call eint(rho, p, k, etotal, correctfork)
558  etotal = rho*(etotal+half*(u*u+v*v+w*w))
559  end subroutine etot
560 
561 ! differentiation of eint in reverse (adjoint) mode (with options noisize i4 dr8 r8):
562 ! gradient of useful results: k p einternal rho
563 ! with respect to varying inputs: k p einternal rho
564 ! ==================================================================
565  subroutine eint_b(rho, rhod, p, pd, k, kd, einternal, einternald, &
566 & correctfork)
567 !
568 ! eintarray computes the internal energy per unit mass from the
569 ! given density and pressure (and possibly turbulent energy)
570 ! for a calorically and thermally perfect gas the well-known
571 ! expression is used; for only a thermally perfect gas, cp is a
572 ! function of temperature, curve fits are used and a more
573 ! complex expression is obtained.
574 !
575  use constants
576  use cpcurvefits
577  use flowvarrefstate, only : rgas, rgasd, tref, trefd
578  use inputphysics, only : cpmodel, gammaconstant
579  implicit none
580 !
581 ! subroutine arguments.
582 !
583  real(kind=realtype), intent(in) :: rho, p, k
584  real(kind=realtype) :: rhod, pd, kd
585  real(kind=realtype) :: einternal
586  real(kind=realtype) :: einternald
587  logical, intent(in) :: correctfork
588 !
589 ! local parameter.
590 !
591  real(kind=realtype), parameter :: twothird=two*third
592 !
593 ! local variables.
594 !
595  integer(kind=inttype) :: i, nn, mm, ii, start
596  real(kind=realtype) :: ovgm1, factk, pp, t, t2, scale
597  real(kind=realtype) :: tempd
598 ! determine the cp model used in the computation.
599  select case (cpmodel)
600  case (cpconstant)
601 ! abbreviate 1/(gamma -1) a bit easier.
602  ovgm1 = one/(gammaconstant-one)
603 ! loop over the number of elements of the array and compute
604 ! the total energy.
605 ! second step. correct the energy in case a turbulent kinetic
606 ! energy is present.
607  if (correctfork) then
608  factk = ovgm1*(five*third-gammaconstant)
609  kd = kd - factk*einternald
610  end if
611  tempd = ovgm1*einternald/rho
612  pd = pd + tempd
613  rhod = rhod - p*tempd/rho
614  einternald = 0.0_8
615  end select
616  end subroutine eint_b
617 
618 ! ==================================================================
619  subroutine eint(rho, p, k, einternal, correctfork)
620 !
621 ! eintarray computes the internal energy per unit mass from the
622 ! given density and pressure (and possibly turbulent energy)
623 ! for a calorically and thermally perfect gas the well-known
624 ! expression is used; for only a thermally perfect gas, cp is a
625 ! function of temperature, curve fits are used and a more
626 ! complex expression is obtained.
627 !
628  use constants
629  use cpcurvefits
630  use flowvarrefstate, only : rgas, tref
631  use inputphysics, only : cpmodel, gammaconstant
632  implicit none
633 !
634 ! subroutine arguments.
635 !
636  real(kind=realtype), intent(in) :: rho, p, k
637  real(kind=realtype), intent(out) :: einternal
638  logical, intent(in) :: correctfork
639 !
640 ! local parameter.
641 !
642  real(kind=realtype), parameter :: twothird=two*third
643 !
644 ! local variables.
645 !
646  integer(kind=inttype) :: i, nn, mm, ii, start
647  real(kind=realtype) :: ovgm1, factk, pp, t, t2, scale
648 ! determine the cp model used in the computation.
649  select case (cpmodel)
650  case (cpconstant)
651 ! abbreviate 1/(gamma -1) a bit easier.
652  ovgm1 = one/(gammaconstant-one)
653 ! loop over the number of elements of the array and compute
654 ! the total energy.
655  einternal = ovgm1*p/rho
656 ! second step. correct the energy in case a turbulent kinetic
657 ! energy is present.
658  if (correctfork) then
659  factk = ovgm1*(five*third-gammaconstant)
660  einternal = einternal - factk*k
661  end if
662  end select
663  end subroutine eint
664 
665 ! differentiation of computepressuresimple in reverse (adjoint) mode (with options noisize i4 dr8 r8):
666 ! gradient of useful results: pinfcorr *p *w
667 ! with respect to varying inputs: pinfcorr *p *w
668 ! rw status of diff variables: pinfcorr:incr *p:in-out *w:incr
669 ! plus diff mem management of: p:in w:in
670  subroutine computepressuresimple_b(includehalos)
671 ! compute the pressure on a block with the pointers already set. this
672 ! routine is used by the forward mode ad code only.
673  use constants
674  use blockpointers
675  use flowvarrefstate
676  use inputphysics
677  implicit none
678 ! input parameter
679  logical, intent(in) :: includehalos
680 ! local variables
681  integer(kind=inttype) :: i, j, k, ii
682  real(kind=realtype) :: gm1, v2
683  real(kind=realtype) :: v2d
684  integer(kind=inttype) :: ibeg, iend, isize, jbeg, jend, jsize, kbeg&
685 & , kend, ksize
686  intrinsic mod
687  intrinsic max
688  real(kind=realtype) :: tempd
689 ! compute the pressures
690  gm1 = gammaconstant - one
691  if (includehalos) then
692  ibeg = 0
693  jbeg = 0
694  kbeg = 0
695  iend = ib
696  jend = jb
697  kend = kb
698  else
699  ibeg = 2
700  jbeg = 2
701  kbeg = 2
702  iend = il
703  jend = jl
704  kend = kl
705  end if
706  isize = iend - ibeg + 1
707  jsize = jend - jbeg + 1
708  ksize = kend - kbeg + 1
709 !$bwd-of ii-loop
710  do ii=0,isize*jsize*ksize-1
711  i = mod(ii, isize) + ibeg
712  j = mod(ii/isize, jsize) + jbeg
713  k = ii/(isize*jsize) + kbeg
714  v2 = w(i, j, k, ivx)**2 + w(i, j, k, ivy)**2 + w(i, j, k, ivz)**2
715  p(i, j, k) = gm1*(w(i, j, k, irhoe)-half*w(i, j, k, irho)*v2)
716  if (p(i, j, k) .lt. 1.e-4_realtype*pinfcorr) then
717  pinfcorrd = pinfcorrd + 1.e-4_realtype*pd(i, j, k)
718  pd(i, j, k) = 0.0_8
719  end if
720  tempd = gm1*pd(i, j, k)
721  pd(i, j, k) = 0.0_8
722  wd(i, j, k, irhoe) = wd(i, j, k, irhoe) + tempd
723  wd(i, j, k, irho) = wd(i, j, k, irho) - v2*half*tempd
724  v2d = -(w(i, j, k, irho)*half*tempd)
725  wd(i, j, k, ivx) = wd(i, j, k, ivx) + 2*w(i, j, k, ivx)*v2d
726  wd(i, j, k, ivy) = wd(i, j, k, ivy) + 2*w(i, j, k, ivy)*v2d
727  wd(i, j, k, ivz) = wd(i, j, k, ivz) + 2*w(i, j, k, ivz)*v2d
728  end do
729  end subroutine computepressuresimple_b
730 
731  subroutine computepressuresimple(includehalos)
732 ! compute the pressure on a block with the pointers already set. this
733 ! routine is used by the forward mode ad code only.
734  use constants
735  use blockpointers
736  use flowvarrefstate
737  use inputphysics
738  implicit none
739 ! input parameter
740  logical, intent(in) :: includehalos
741 ! local variables
742  integer(kind=inttype) :: i, j, k, ii
743  real(kind=realtype) :: gm1, v2
744  integer(kind=inttype) :: ibeg, iend, isize, jbeg, jend, jsize, kbeg&
745 & , kend, ksize
746  intrinsic mod
747  intrinsic max
748 ! compute the pressures
749  gm1 = gammaconstant - one
750  if (includehalos) then
751  ibeg = 0
752  jbeg = 0
753  kbeg = 0
754  iend = ib
755  jend = jb
756  kend = kb
757  else
758  ibeg = 2
759  jbeg = 2
760  kbeg = 2
761  iend = il
762  jend = jl
763  kend = kl
764  end if
765  isize = iend - ibeg + 1
766  jsize = jend - jbeg + 1
767  ksize = kend - kbeg + 1
768 !$ad ii-loop
769  do ii=0,isize*jsize*ksize-1
770  i = mod(ii, isize) + ibeg
771  j = mod(ii/isize, jsize) + jbeg
772  k = ii/(isize*jsize) + kbeg
773  v2 = w(i, j, k, ivx)**2 + w(i, j, k, ivy)**2 + w(i, j, k, ivz)**2
774  p(i, j, k) = gm1*(w(i, j, k, irhoe)-half*w(i, j, k, irho)*v2)
775  if (p(i, j, k) .lt. 1.e-4_realtype*pinfcorr) then
776  p(i, j, k) = 1.e-4_realtype*pinfcorr
777  else
778  p(i, j, k) = p(i, j, k)
779  end if
780  end do
781  end subroutine computepressuresimple
782 
783  subroutine computepressure(ibeg, iend, jbeg, jend, kbeg, kend, &
784 & pointeroffset)
785 !
786 ! computepressure computes the pressure from the total energy,
787 ! density and velocities in the given cell range of the block to
788 ! which the pointers in blockpointers currently point.
789 ! it is possible to specify a possible pointer offset, because
790 ! this routine is also used when reading a restart file.
791 !
792  use constants
793  use inputphysics, only : cpmodel, gammaconstant
794  use blockpointers, only : w, p
795  use flowvarrefstate, only : kpresent, pinf, rgas, tref
796  use cpcurvefits
797  implicit none
798 !
799 ! subroutine arguments.
800 !
801  integer(kind=inttype), intent(in) :: ibeg, iend, jbeg, jend, kbeg, &
802 & kend
803  integer(kind=inttype), intent(in) :: pointeroffset
804 !
805 ! local parameters.
806 !
807  real(kind=realtype), parameter :: dtstop=0.01_realtype
808  real(kind=realtype), parameter :: twothird=two*third
809 !
810 ! local variables.
811 !
812  integer(kind=inttype) :: i, j, k, ip, jp, kp, nn, ii, start
813  real(kind=realtype) :: gm1, factk, v2, scale, e0, e
814  real(kind=realtype) :: trefinv, t, dt, t2, alp, cv
815  intrinsic max
816  intrinsic log
817  intrinsic abs
818  real(kind=realtype) :: abs0
819 ! determine the cp model used in the computation.
820  select case (cpmodel)
821  case (cpconstant)
822 ! constant cp and thus constant gamma. the relation
823 ! eint = cv*t can be used and consequently the standard
824 ! relation between pressure and internal energy is valid.
825 ! abbreviate some constants that occur in the pressure
826 ! computation.
827  gm1 = gammaconstant - one
828  factk = five*third - gammaconstant
829 ! loop over the cells. take the possible pointer
830 ! offset into account and store the pressure in the
831 ! position w(:,:,:, irhoe).
832  do k=kbeg,kend
833  kp = k + pointeroffset
834  do j=jbeg,jend
835  jp = j + pointeroffset
836  do i=ibeg,iend
837  ip = i + pointeroffset
838  v2 = w(ip, jp, kp, ivx)**2 + w(ip, jp, kp, ivy)**2 + w(ip, &
839 & jp, kp, ivz)**2
840  w(i, j, k, irhoe) = gm1*(w(ip, jp, kp, irhoe)-half*w(ip, jp&
841 & , kp, irho)*v2)
842  if (w(i, j, k, irhoe) .lt. 1.e-5_realtype*pinf) then
843  w(i, j, k, irhoe) = 1.e-5_realtype*pinf
844  else
845  w(i, j, k, irhoe) = w(i, j, k, irhoe)
846  end if
847  end do
848  end do
849  end do
850 ! correct p if a k-equation is present.
851  if (kpresent) then
852  do k=kbeg,kend
853  kp = k + pointeroffset
854  do j=jbeg,jend
855  jp = j + pointeroffset
856  do i=ibeg,iend
857  ip = i + pointeroffset
858  w(i, j, k, irhoe) = w(i, j, k, irhoe) + factk*w(ip, jp, kp&
859 & , irho)*w(ip, jp, kp, itu1)
860  end do
861  end do
862  end do
863  end if
864  case (cptempcurvefits)
865 ! ================================================================
866 ! cp as function of the temperature is given via curve fits.
867 ! store a scale factor when converting the nondimensional
868 ! energy to the units of cpeint
869  trefinv = one/tref
870  scale = tref/rgas
871 ! loop over the cells to compute the internal energy per
872 ! unit mass. this is stored in w(:,:,:,irhoe) for the moment.
873  do k=kbeg,kend
874  kp = k + pointeroffset
875  do j=jbeg,jend
876  jp = j + pointeroffset
877  do i=ibeg,iend
878  ip = i + pointeroffset
879  w(i, j, k, irhoe) = w(ip, jp, kp, irhoe)/w(ip, jp, kp, irho)
880  if (kpresent) w(i, j, k, irhoe) = w(i, j, k, irhoe) - w(ip, &
881 & jp, kp, itu1)
882  v2 = w(ip, jp, kp, ivx)**2 + w(ip, jp, kp, ivy)**2 + w(ip, &
883 & jp, kp, ivz)**2
884  w(i, j, k, irhoe) = w(i, j, k, irhoe) - half*v2
885  end do
886  end do
887  end do
888 ! newton algorithm to compute the temperature from the known
889 ! value of the internal energy.
890  do k=kbeg,kend
891  kp = k + pointeroffset
892  do j=jbeg,jend
893  jp = j + pointeroffset
894  do i=ibeg,iend
895  ip = i + pointeroffset
896 ! store the internal energy in the same dimensional
897 ! units as cpeint.
898  e0 = scale*w(i, j, k, irhoe)
899 ! take care of the exceptional cases.
900  if (e0 .le. cpeint(0)) then
901 ! energy smaller than the lowest value of the curve
902 ! fit. use extrapolation using constant cv.
903  t = trefinv*(cptrange(0)+(e0-cpeint(0))/cv0)
904  else if (e0 .ge. cpeint(cpnparts)) then
905 ! energy larger than the largest value of the curve
906 ! fit. use extrapolation using constant cv.
907  t = trefinv*(cptrange(cpnparts)+(e0-cpeint(cpnparts))/cvn)
908  else
909 ! the value is in the range of the curve fits.
910 ! a newton algorithm is used to find the temperature.
911 ! first find the curve fit interval to be searched.
912  ii = cpnparts
913  start = 1
914  interval:do
915 ! next guess for the interval.
916  nn = start + ii/2
917 ! determine the situation we are having here.
918  if (e0 .gt. cpeint(nn)) then
919 ! energy is larger than the upper boundary of
920 ! the current interval. update the lower
921 ! boundary.
922  start = nn + 1
923  ii = ii - 1
924  else if (e0 .ge. cpeint(nn-1)) then
925 ! nn contains the range in which the newton algorithm
926 ! must be applied.
927 ! initial guess of the dimensional temperature.
928  alp = (cpeint(nn)-e0)/(cpeint(nn)-cpeint(nn-1))
929  t = alp*cptrange(nn-1) + (one-alp)*cptrange(nn)
930 ! the actual newton algorithm to compute the
931 ! temperature.
932  newton:do
933 ! compute the internal energy as well as the
934 ! value of cv/r for the given temperature.
935 ! cv/r = cp/r - 1.0
936  cv = -one
937 ! e = integral of cv,
938  e = cptempfit(nn)%eint0 - t
939 ! not of cp.
940  do ii=1,cptempfit(nn)%nterm
941 ! update cv.
942  t2 = t**cptempfit(nn)%exponents(ii)
943  cv = cv + cptempfit(nn)%constants(ii)*t2
944 ! update e, for which this contribution must be
945 ! integrated. take the exceptional case that the
946 ! exponent == -1 into account.
947  if (cptempfit(nn)%exponents(ii) .eq. -1_inttype) &
948 & then
949  e = e + cptempfit(nn)%constants(ii)*log(t)
950  else
951  e = e + cptempfit(nn)%constants(ii)*t2*t/(&
952 & cptempfit(nn)%exponents(ii)+1)
953  end if
954  end do
955 ! compute the update and the new temperature.
956  dt = (e0-e)/cv
957  t = t + dt
958  if (dt .ge. 0.) then
959  abs0 = dt
960  else
961  abs0 = -dt
962  end if
963 ! exit the newton loop if the update is smaller
964 ! than the threshold value.
965  if (abs0 .lt. dtstop) then
966 ! create the nondimensional temperature.
967  t = t*trefinv
968  goto 100
969  end if
970  end do newton
971  end if
972 ! this is the correct range. exit the do-loop.
973 ! modify ii for the next branch to search.
974  ii = ii/2
975  end do interval
976  end if
977 ! compute the pressure from the known temperature
978 ! and density. include the correction if a k-equation
979 ! is present.
980  100 w(i, j, k, irhoe) = w(ip, jp, kp, irho)*rgas*t
981  if (w(i, j, k, irhoe) .lt. 1.e-5_realtype*pinf) then
982  w(i, j, k, irhoe) = 1.e-5_realtype*pinf
983  else
984  w(i, j, k, irhoe) = w(i, j, k, irhoe)
985  end if
986  if (kpresent) w(i, j, k, irhoe) = w(i, j, k, irhoe) + &
987 & twothird*w(ip, jp, kp, irho)*w(ip, jp, kp, itu1)
988  end do
989  end do
990  end do
991  end select
992  end subroutine computepressure
993 
994 ! differentiation of computelamviscosity in reverse (adjoint) mode (with options noisize i4 dr8 r8):
995 ! gradient of useful results: muref tref rgas *p *w *rlv
996 ! with respect to varying inputs: muref tref rgas *p *w *rlv
997 ! rw status of diff variables: muref:incr tref:incr rgas:incr
998 ! *p:incr *w:incr *rlv:in-out
999 ! plus diff mem management of: p:in w:in rlv:in
1000  subroutine computelamviscosity_b(includehalos)
1001 !
1002 ! computelamviscosity computes the laminar viscosity ratio in
1003 ! the owned cell centers of the given block. sutherland's law is
1004 ! used. it is assumed that the pointes already point to the
1005 ! correct block before entering this subroutine.
1006 !
1007  use blockpointers
1008  use constants
1009  use flowvarrefstate
1010  use inputphysics
1011  use iteration
1012  use utils_b, only : getcorrectfork
1013  implicit none
1014 ! input variables
1015  logical, intent(in) :: includehalos
1016 !
1017 ! local parameter.
1018 !
1019  real(kind=realtype), parameter :: twothird=two*third
1020 !
1021 ! local variables.
1022 !
1023  integer(kind=inttype) :: i, j, k, ii
1024  real(kind=realtype) :: musuth, tsuth, ssuth, t, pp
1025  real(kind=realtype) :: musuthd, tsuthd, ssuthd, td, ppd
1026  logical :: correctfork
1027  integer(kind=inttype) :: ibeg, iend, isize, jbeg, jend, jsize, kbeg&
1028 & , kend, ksize
1029  intrinsic mod
1030  real(kind=realtype) :: temp
1031  real(kind=realtype) :: temp0
1032  real(kind=realtype) :: tempd
1033  real(kind=realtype) :: tempd0
1034  real(kind=realtype) :: temp1
1035  real(kind=realtype) :: tempd1
1036 ! return immediately if no laminar viscosity needs to be computed.
1037  if (viscous) then
1038 ! determine whether or not the pressure must be corrected
1039 ! for the presence of the turbulent kinetic energy.
1040  correctfork = getcorrectfork()
1041 ! compute the nondimensional constants in sutherland's law.
1042  musuth = musuthdim/muref
1043  tsuth = tsuthdim/tref
1044  ssuth = ssuthdim/tref
1045  if (includehalos) then
1046  ibeg = 1
1047  jbeg = 1
1048  kbeg = 1
1049  iend = ie
1050  jend = je
1051  kend = ke
1052  else
1053  ibeg = 2
1054  jbeg = 2
1055  kbeg = 2
1056  iend = il
1057  jend = jl
1058  kend = kl
1059  end if
1060 ! substract 2/3 rho k, which is a part of the normal turbulent
1061 ! stresses, in case the pressure must be corrected.
1062  if (correctfork) then
1063  isize = iend - ibeg + 1
1064  jsize = jend - jbeg + 1
1065  ksize = kend - kbeg + 1
1066  ssuthd = 0.0_8
1067  musuthd = 0.0_8
1068  tsuthd = 0.0_8
1069 !$bwd-of ii-loop
1070  do ii=0,isize*jsize*ksize-1
1071  i = mod(ii, isize) + ibeg
1072  j = mod(ii/isize, jsize) + jbeg
1073  k = ii/(isize*jsize) + kbeg
1074  pp = p(i, j, k) - twothird*w(i, j, k, irho)*w(i, j, k, itu1)
1075  t = pp/(rgas*w(i, j, k, irho))
1076  temp0 = t/tsuth
1077  temp = musuth*(tsuth+ssuth)/(t+ssuth)
1078  tempd0 = temp0**1.5_realtype*rlvd(i, j, k)/(t+ssuth)
1079  tempd = 1.5_realtype*temp0**0.5*temp*rlvd(i, j, k)/tsuth
1080  rlvd(i, j, k) = 0.0_8
1081  tsuthd = tsuthd + musuth*tempd0 - temp0*tempd
1082  musuthd = musuthd + (tsuth+ssuth)*tempd0
1083  tempd1 = -(temp*tempd0)
1084  td = tempd + tempd1
1085  ssuthd = ssuthd + musuth*tempd0 + tempd1
1086  temp = w(i, j, k, irho)
1087  temp0 = rgas*temp
1088  ppd = td/temp0
1089  tempd = -(pp*td/temp0**2)
1090  rgasd = rgasd + temp*tempd
1091  wd(i, j, k, irho) = wd(i, j, k, irho) + rgas*tempd - w(i, j, k&
1092 & , itu1)*twothird*ppd
1093  pd(i, j, k) = pd(i, j, k) + ppd
1094  wd(i, j, k, itu1) = wd(i, j, k, itu1) - w(i, j, k, irho)*&
1095 & twothird*ppd
1096  end do
1097  else
1098 ! loop over the owned cells *and* first level halos of this
1099 ! block and compute the laminar viscosity ratio.
1100  isize = iend - ibeg + 1
1101  jsize = jend - jbeg + 1
1102  ksize = kend - kbeg + 1
1103  ssuthd = 0.0_8
1104  musuthd = 0.0_8
1105  tsuthd = 0.0_8
1106 !$bwd-of ii-loop
1107  do ii=0,isize*jsize*ksize-1
1108  i = mod(ii, isize) + ibeg
1109  j = mod(ii/isize, jsize) + jbeg
1110  k = ii/(isize*jsize) + kbeg
1111 ! compute the nondimensional temperature and the
1112 ! nondimensional laminar viscosity.
1113  t = p(i, j, k)/(rgas*w(i, j, k, irho))
1114  temp1 = t/tsuth
1115  temp0 = musuth*(tsuth+ssuth)/(t+ssuth)
1116  tempd = temp1**1.5_realtype*rlvd(i, j, k)/(t+ssuth)
1117  tempd1 = 1.5_realtype*temp1**0.5*temp0*rlvd(i, j, k)/tsuth
1118  rlvd(i, j, k) = 0.0_8
1119  tsuthd = tsuthd + musuth*tempd - temp1*tempd1
1120  musuthd = musuthd + (tsuth+ssuth)*tempd
1121  tempd0 = -(temp0*tempd)
1122  td = tempd1 + tempd0
1123  ssuthd = ssuthd + musuth*tempd + tempd0
1124  temp1 = w(i, j, k, irho)
1125  temp0 = rgas*temp1
1126  pd(i, j, k) = pd(i, j, k) + td/temp0
1127  tempd = -(p(i, j, k)*td/temp0**2)
1128  rgasd = rgasd + temp1*tempd
1129  wd(i, j, k, irho) = wd(i, j, k, irho) + rgas*tempd
1130  end do
1131  end if
1132  trefd = trefd - ssuthdim*ssuthd/tref**2 - tsuthdim*tsuthd/tref**2
1133  murefd = murefd - musuthdim*musuthd/muref**2
1134  end if
1135  end subroutine computelamviscosity_b
1136 
1137  subroutine computelamviscosity(includehalos)
1138 !
1139 ! computelamviscosity computes the laminar viscosity ratio in
1140 ! the owned cell centers of the given block. sutherland's law is
1141 ! used. it is assumed that the pointes already point to the
1142 ! correct block before entering this subroutine.
1143 !
1144  use blockpointers
1145  use constants
1146  use flowvarrefstate
1147  use inputphysics
1148  use iteration
1149  use utils_b, only : getcorrectfork
1150  implicit none
1151 ! input variables
1152  logical, intent(in) :: includehalos
1153 !
1154 ! local parameter.
1155 !
1156  real(kind=realtype), parameter :: twothird=two*third
1157 !
1158 ! local variables.
1159 !
1160  integer(kind=inttype) :: i, j, k, ii
1161  real(kind=realtype) :: musuth, tsuth, ssuth, t, pp
1162  logical :: correctfork
1163  integer(kind=inttype) :: ibeg, iend, isize, jbeg, jend, jsize, kbeg&
1164 & , kend, ksize
1165  intrinsic mod
1166 ! return immediately if no laminar viscosity needs to be computed.
1167  if (.not.viscous) then
1168  return
1169  else
1170 ! determine whether or not the pressure must be corrected
1171 ! for the presence of the turbulent kinetic energy.
1172  correctfork = getcorrectfork()
1173 ! compute the nondimensional constants in sutherland's law.
1174  musuth = musuthdim/muref
1175  tsuth = tsuthdim/tref
1176  ssuth = ssuthdim/tref
1177  if (includehalos) then
1178  ibeg = 1
1179  jbeg = 1
1180  kbeg = 1
1181  iend = ie
1182  jend = je
1183  kend = ke
1184  else
1185  ibeg = 2
1186  jbeg = 2
1187  kbeg = 2
1188  iend = il
1189  jend = jl
1190  kend = kl
1191  end if
1192 ! substract 2/3 rho k, which is a part of the normal turbulent
1193 ! stresses, in case the pressure must be corrected.
1194  if (correctfork) then
1195  isize = iend - ibeg + 1
1196  jsize = jend - jbeg + 1
1197  ksize = kend - kbeg + 1
1198 !$ad ii-loop
1199  do ii=0,isize*jsize*ksize-1
1200  i = mod(ii, isize) + ibeg
1201  j = mod(ii/isize, jsize) + jbeg
1202  k = ii/(isize*jsize) + kbeg
1203  pp = p(i, j, k) - twothird*w(i, j, k, irho)*w(i, j, k, itu1)
1204  t = pp/(rgas*w(i, j, k, irho))
1205  rlv(i, j, k) = musuth*((tsuth+ssuth)/(t+ssuth))*(t/tsuth)**&
1206 & 1.5_realtype
1207  end do
1208  else
1209 ! loop over the owned cells *and* first level halos of this
1210 ! block and compute the laminar viscosity ratio.
1211  isize = iend - ibeg + 1
1212  jsize = jend - jbeg + 1
1213  ksize = kend - kbeg + 1
1214 !$ad ii-loop
1215  do ii=0,isize*jsize*ksize-1
1216  i = mod(ii, isize) + ibeg
1217  j = mod(ii/isize, jsize) + jbeg
1218  k = ii/(isize*jsize) + kbeg
1219 ! compute the nondimensional temperature and the
1220 ! nondimensional laminar viscosity.
1221  t = p(i, j, k)/(rgas*w(i, j, k, irho))
1222  rlv(i, j, k) = musuth*((tsuth+ssuth)/(t+ssuth))*(t/tsuth)**&
1223 & 1.5_realtype
1224  end do
1225  end if
1226  end if
1227  end subroutine computelamviscosity
1228 
1229 ! differentiation of adjustinflowangle in reverse (adjoint) mode (with options noisize i4 dr8 r8):
1230 ! gradient of useful results: veldirfreestream dragdirection
1231 ! liftdirection
1232 ! with respect to varying inputs: alpha veldirfreestream beta
1233 ! dragdirection liftdirection
1234 ! rw status of diff variables: alpha:out veldirfreestream:in-out
1235 ! beta:out dragdirection:in-out liftdirection:in-out
1236  subroutine adjustinflowangle_b()
1237  use constants
1238  use inputphysics, only : alpha, alphad, beta, betad, liftindex, &
1241  implicit none
1242 !local vars
1243  real(kind=realtype), dimension(3) :: refdir1, refdir2
1244 ! velocity direction given by the rotation of a unit vector
1245 ! initially aligned along the positive x-direction (1,0,0)
1246 ! 1) rotate alpha radians cw about y or z-axis
1247 ! 2) rotate beta radians ccw about z or y-axis
1248  refdir1(:) = zero
1249  refdir1(1) = one
1250 ! drag direction given by the rotation of a unit vector
1251 ! initially aligned along the positive x-direction (1,0,0)
1252 ! 1) rotate alpha radians cw about y or z-axis
1253 ! 2) rotate beta radians ccw about z or y-axis
1254 ! lift direction given by the rotation of a unit vector
1255 ! initially aligned along the positive z-direction (0,0,1)
1256 ! 1) rotate alpha radians cw about y or z-axis
1257 ! 2) rotate beta radians ccw about z or y-axis
1258  refdir2(:) = zero
1259  refdir2(liftindex) = one
1260  alphad = 0.0_8
1261  betad = 0.0_8
1262  call getdirvector_b(refdir2, alpha, alphad, beta, betad, &
1264  call getdirvector_b(refdir1, alpha, alphad, beta, betad, &
1266  call getdirvector_b(refdir1, alpha, alphad, beta, betad, &
1268  end subroutine adjustinflowangle_b
1269 
1270  subroutine adjustinflowangle()
1271  use constants
1274  implicit none
1275 !local vars
1276  real(kind=realtype), dimension(3) :: refdir1, refdir2
1277 ! velocity direction given by the rotation of a unit vector
1278 ! initially aligned along the positive x-direction (1,0,0)
1279 ! 1) rotate alpha radians cw about y or z-axis
1280 ! 2) rotate beta radians ccw about z or y-axis
1281  refdir1(:) = zero
1282  refdir1(1) = one
1284 ! drag direction given by the rotation of a unit vector
1285 ! initially aligned along the positive x-direction (1,0,0)
1286 ! 1) rotate alpha radians cw about y or z-axis
1287 ! 2) rotate beta radians ccw about z or y-axis
1288  call getdirvector(refdir1, alpha, beta, dragdirection, liftindex)
1289 ! lift direction given by the rotation of a unit vector
1290 ! initially aligned along the positive z-direction (0,0,1)
1291 ! 1) rotate alpha radians cw about y or z-axis
1292 ! 2) rotate beta radians ccw about z or y-axis
1293  refdir2(:) = zero
1294  refdir2(liftindex) = one
1295  call getdirvector(refdir2, alpha, beta, liftdirection, liftindex)
1296  end subroutine adjustinflowangle
1297 
1298 ! differentiation of derivativerotmatrixrigid in reverse (adjoint) mode (with options noisize i4 dr8 r8):
1299 ! gradient of useful results: timeref rotationmatrix
1300 ! with respect to varying inputs: timeref
1301  subroutine derivativerotmatrixrigid_b(rotationmatrix, rotationmatrixd&
1302 & , rotationpoint, t)
1303 !
1304 ! derivativerotmatrixrigid determines the derivative of the
1305 ! rotation matrix at the given time for the rigid body rotation,
1306 ! such that the grid velocities can be determined analytically.
1307 ! also the rotation point of the current time level is
1308 ! determined. this value can change due to translation of the
1309 ! entire grid.
1310 !
1311  use constants
1312  use flowvarrefstate
1313  use inputmotion
1314  use monitor
1317  implicit none
1318 !
1319 ! subroutine arguments.
1320 !
1321  real(kind=realtype), intent(in) :: t
1322  real(kind=realtype), dimension(3) :: rotationpoint
1323  real(kind=realtype), dimension(3, 3) :: rotationmatrix
1324  real(kind=realtype), dimension(3, 3) :: rotationmatrixd
1325 !
1326 ! local variables.
1327 !
1328  integer(kind=inttype) :: i, j
1329  real(kind=realtype) :: phi, dphix, dphiy, dphiz
1330  real(kind=realtype) :: dphixd, dphiyd, dphizd
1331  real(kind=realtype) :: cosx, cosy, cosz, sinx, siny, sinz
1332  real(kind=realtype), dimension(3, 3) :: dm, m
1333  real(kind=realtype), dimension(3, 3) :: dmd
1334  intrinsic sin
1335  intrinsic cos
1336 ! determine the rotation angle around the x-axis for the new
1337 ! time level and the corresponding values of the sine and cosine.
1340  sinx = sin(phi)
1341  cosx = cos(phi)
1342 ! idem for the y-axis.
1345  siny = sin(phi)
1346  cosy = cos(phi)
1347 ! idem for the z-axis.
1350  sinz = sin(phi)
1351  cosz = cos(phi)
1352 ! compute the time derivative of the rotation angles around the
1353 ! x-axis, y-axis and z-axis.
1354 ! compute the time derivative of the rotation matrix applied to
1355 ! the coordinates at t == 0.
1356 ! part 1. derivative of the z-rotation matrix multiplied by the
1357 ! x and y rotation matrix, i.e. dmz * my * mx
1358 ! part 2: mz * dmy * mx.
1359 ! part 3: mz * my * dmx
1360 ! determine the rotation matrix at t == t.
1361  m(1, 1) = cosy*cosz
1362  m(2, 1) = cosy*sinz
1363  m(3, 1) = -siny
1364  m(1, 2) = sinx*siny*cosz - cosx*sinz
1365  m(2, 2) = sinx*siny*sinz + cosx*cosz
1366  m(3, 2) = sinx*cosy
1367  m(1, 3) = cosx*siny*cosz + sinx*sinz
1368  m(2, 3) = cosx*siny*sinz - sinx*cosz
1369  m(3, 3) = cosx*cosy
1370  dmd = 0.0_8
1371  do j=3,1,-1
1372  do i=3,1,-1
1373  dmd(i, 1) = dmd(i, 1) + m(j, 1)*rotationmatrixd(i, j)
1374  dmd(i, 2) = dmd(i, 2) + m(j, 2)*rotationmatrixd(i, j)
1375  dmd(i, 3) = dmd(i, 3) + m(j, 3)*rotationmatrixd(i, j)
1376  rotationmatrixd(i, j) = 0.0_8
1377  end do
1378  end do
1379  dphixd = cosx*cosy*dmd(3, 2) - sinx*cosy*dmd(3, 3) + (cosx*siny*sinz&
1380 & -sinx*cosz)*dmd(2, 2) - (sinx*siny*sinz+cosx*cosz)*dmd(2, 3) + (&
1381 & cosx*sinz-sinx*siny*cosz)*dmd(1, 3) + (sinx*sinz+cosx*siny*cosz)*&
1382 & dmd(1, 2)
1383  dphiyd = sinz*cosx*cosy*dmd(2, 3) - cosx*siny*dmd(3, 3) - sinx*siny*&
1384 & dmd(3, 2) - cosy*dmd(3, 1) + sinz*sinx*cosy*dmd(2, 2) + cosz*cosx*&
1385 & cosy*dmd(1, 3) - siny*sinz*dmd(2, 1) + cosz*sinx*cosy*dmd(1, 2) - &
1386 & siny*cosz*dmd(1, 1)
1387  dmd(3, 3) = 0.0_8
1388  dmd(3, 2) = 0.0_8
1389  dmd(3, 1) = 0.0_8
1390  dphizd = (cosx*siny*cosz+sinx*sinz)*dmd(2, 3) + (sinx*siny*cosz-cosx&
1391 & *sinz)*dmd(2, 2) + cosy*cosz*dmd(2, 1) + (sinx*cosz-cosx*siny*sinz&
1392 & )*dmd(1, 3) + (-(cosx*cosz)-sinx*siny*sinz)*dmd(1, 2) - cosy*sinz*&
1393 & dmd(1, 1)
1394  dmd(2, 3) = 0.0_8
1395  dmd(2, 2) = 0.0_8
1396  dmd(2, 1) = 0.0_8
1397  dmd(1, 3) = 0.0_8
1398  dmd(1, 2) = 0.0_8
1401 & coscoeffourzrot, sincoeffourzrot, t, dphizd&
1402 & )
1405 & coscoeffouryrot, sincoeffouryrot, t, dphiyd&
1406 & )
1409 & coscoeffourxrot, sincoeffourxrot, t, dphixd&
1410 & )
1411  end subroutine derivativerotmatrixrigid_b
1412 
1413  subroutine derivativerotmatrixrigid(rotationmatrix, rotationpoint, t)
1414 !
1415 ! derivativerotmatrixrigid determines the derivative of the
1416 ! rotation matrix at the given time for the rigid body rotation,
1417 ! such that the grid velocities can be determined analytically.
1418 ! also the rotation point of the current time level is
1419 ! determined. this value can change due to translation of the
1420 ! entire grid.
1421 !
1422  use constants
1423  use flowvarrefstate
1424  use inputmotion
1425  use monitor
1427  implicit none
1428 !
1429 ! subroutine arguments.
1430 !
1431  real(kind=realtype), intent(in) :: t
1432  real(kind=realtype), dimension(3), intent(out) :: rotationpoint
1433  real(kind=realtype), dimension(3, 3), intent(out) :: rotationmatrix
1434 !
1435 ! local variables.
1436 !
1437  integer(kind=inttype) :: i, j
1438  real(kind=realtype) :: phi, dphix, dphiy, dphiz
1439  real(kind=realtype) :: cosx, cosy, cosz, sinx, siny, sinz
1440  real(kind=realtype), dimension(3, 3) :: dm, m
1441  intrinsic sin
1442  intrinsic cos
1443 ! determine the rotation angle around the x-axis for the new
1444 ! time level and the corresponding values of the sine and cosine.
1447  sinx = sin(phi)
1448  cosx = cos(phi)
1449 ! idem for the y-axis.
1452  siny = sin(phi)
1453  cosy = cos(phi)
1454 ! idem for the z-axis.
1457  sinz = sin(phi)
1458  cosz = cos(phi)
1459 ! compute the time derivative of the rotation angles around the
1460 ! x-axis, y-axis and z-axis.
1463 & )
1466 & )
1469 & )
1470 ! compute the time derivative of the rotation matrix applied to
1471 ! the coordinates at t == 0.
1472 ! part 1. derivative of the z-rotation matrix multiplied by the
1473 ! x and y rotation matrix, i.e. dmz * my * mx
1474  dm(1, 1) = -(cosy*sinz*dphiz)
1475  dm(1, 2) = (-(cosx*cosz)-sinx*siny*sinz)*dphiz
1476  dm(1, 3) = (sinx*cosz-cosx*siny*sinz)*dphiz
1477  dm(2, 1) = cosy*cosz*dphiz
1478  dm(2, 2) = (sinx*siny*cosz-cosx*sinz)*dphiz
1479  dm(2, 3) = (cosx*siny*cosz+sinx*sinz)*dphiz
1480  dm(3, 1) = zero
1481  dm(3, 2) = zero
1482  dm(3, 3) = zero
1483 ! part 2: mz * dmy * mx.
1484  dm(1, 1) = dm(1, 1) - siny*cosz*dphiy
1485  dm(1, 2) = dm(1, 2) + sinx*cosy*cosz*dphiy
1486  dm(1, 3) = dm(1, 3) + cosx*cosy*cosz*dphiy
1487  dm(2, 1) = dm(2, 1) - siny*sinz*dphiy
1488  dm(2, 2) = dm(2, 2) + sinx*cosy*sinz*dphiy
1489  dm(2, 3) = dm(2, 3) + cosx*cosy*sinz*dphiy
1490  dm(3, 1) = dm(3, 1) - cosy*dphiy
1491  dm(3, 2) = dm(3, 2) - sinx*siny*dphiy
1492  dm(3, 3) = dm(3, 3) - cosx*siny*dphiy
1493 ! part 3: mz * my * dmx
1494  dm(1, 2) = dm(1, 2) + (sinx*sinz+cosx*siny*cosz)*dphix
1495  dm(1, 3) = dm(1, 3) + (cosx*sinz-sinx*siny*cosz)*dphix
1496  dm(2, 2) = dm(2, 2) + (cosx*siny*sinz-sinx*cosz)*dphix
1497  dm(2, 3) = dm(2, 3) - (sinx*siny*sinz+cosx*cosz)*dphix
1498  dm(3, 2) = dm(3, 2) + cosx*cosy*dphix
1499  dm(3, 3) = dm(3, 3) - sinx*cosy*dphix
1500 ! determine the rotation matrix at t == t.
1501  m(1, 1) = cosy*cosz
1502  m(2, 1) = cosy*sinz
1503  m(3, 1) = -siny
1504  m(1, 2) = sinx*siny*cosz - cosx*sinz
1505  m(2, 2) = sinx*siny*sinz + cosx*cosz
1506  m(3, 2) = sinx*cosy
1507  m(1, 3) = cosx*siny*cosz + sinx*sinz
1508  m(2, 3) = cosx*siny*sinz - sinx*cosz
1509  m(3, 3) = cosx*cosy
1510 ! determine the matrix product dm * inverse(m), which will give
1511 ! the derivative of the rotation matrix when applied to the
1512 ! current coordinates. note that inverse(m) == transpose(m).
1513  do j=1,3
1514  do i=1,3
1515  rotationmatrix(i, j) = dm(i, 1)*m(j, 1) + dm(i, 2)*m(j, 2) + dm(&
1516 & i, 3)*m(j, 3)
1517  end do
1518  end do
1519 ! determine the rotation point at the new time level; it is
1520 ! possible that this value changes due to translation of the grid.
1521 ! ainf = sqrt(gammainf*pinf/rhoinf)
1522 ! rotationpoint(1) = lref*rotpoint(1) &
1523 ! + machgrid(1)*ainf*t/timeref
1524 ! rotationpoint(2) = lref*rotpoint(2) &
1525 ! + machgrid(2)*ainf*t/timeref
1526 ! rotationpoint(3) = lref*rotpoint(3) &
1527 ! + machgrid(3)*ainf*t/timeref
1528  rotationpoint(1) = lref*rotpoint(1)
1529  rotationpoint(2) = lref*rotpoint(2)
1530  rotationpoint(3) = lref*rotpoint(3)
1531  end subroutine derivativerotmatrixrigid
1532 
1533 ! differentiation of getdirvector in reverse (adjoint) mode (with options noisize i4 dr8 r8):
1534 ! gradient of useful results: alpha beta winddirection
1535 ! with respect to varying inputs: alpha beta winddirection
1536  subroutine getdirvector_b(refdirection, alpha, alphad, beta, betad, &
1537 & winddirection, winddirectiond, liftindex)
1538 !(xb,yb,zb,alpha,beta,xw,yw,zw)
1539 !
1540 ! convert the angle of attack and side slip angle to wind axes.
1541 ! the components of the wind direction vector (xw,yw,zw) are
1542 ! computed given the direction angles in radians and the body
1543 ! direction by performing two rotations on the original
1544 ! direction vector:
1545 ! 1) rotation about the zb or yb-axis: alpha clockwise (cw)
1546 ! (xb,yb,zb) -> (x1,y1,z1)
1547 ! 2) rotation about the yl or z1-axis: beta counter-clockwise
1548 ! (ccw) (x1,y1,z1) -> (xw,yw,zw)
1549 ! input arguments:
1550 ! alpha = angle of attack in radians
1551 ! beta = side slip angle in radians
1552 ! refdirection = reference direction vector
1553 ! output arguments:
1554 ! winddirection = unit wind vector in body axes
1555 !
1556  use constants
1557  use utils_b, only : terminate
1558  implicit none
1559 !
1560 ! subroutine arguments.
1561 !
1562  real(kind=realtype), dimension(3), intent(in) :: refdirection
1563  real(kind=realtype) :: alpha, beta
1564  real(kind=realtype) :: alphad, betad
1565  real(kind=realtype), dimension(3) :: winddirection
1566  real(kind=realtype), dimension(3) :: winddirectiond
1567  integer(kind=inttype) :: liftindex
1568 !
1569 ! local variables.
1570 !
1571  real(kind=realtype) :: rnorm, x1, y1, z1, xbn, ybn, zbn, xw, yw, zw
1572  real(kind=realtype) :: x1d, y1d, z1d, xbnd, ybnd, zbnd, xwd, ywd, &
1573 & zwd
1574  real(kind=realtype) :: tmp
1575  real(kind=realtype) :: tmpd
1576  intrinsic sqrt
1577  integer :: branch
1578 ! normalize the input vector.
1579  rnorm = sqrt(refdirection(1)**2 + refdirection(2)**2 + refdirection(&
1580 & 3)**2)
1581  xbn = refdirection(1)/rnorm
1582  ybn = refdirection(2)/rnorm
1583  zbn = refdirection(3)/rnorm
1584 !!$ ! compute the wind direction vector.
1585 !!$
1586 !!$ ! 1) rotate alpha radians cw about y-axis
1587 !!$ ! ( <=> rotate y-axis alpha radians ccw)
1588 !!$
1589 !!$ call vectorrotation(x1, y1, z1, 2, alpha, xbn, ybn, zbn)
1590 !!$
1591 !!$ ! 2) rotate beta radians ccw about z-axis
1592 !!$ ! ( <=> rotate z-axis -beta radians ccw)
1593 !!$
1594 !!$ call vectorrotation(xw, yw, zw, 3, -beta, x1, y1, z1)
1595  if (liftindex .eq. 2) then
1596 ! compute the wind direction vector.aerosurf axes different!!
1597 ! 1) rotate alpha radians cw about z-axis
1598 ! ( <=> rotate z-axis alpha radians ccw)
1599  tmp = -alpha
1600  call vectorrotation(x1, y1, z1, 3, tmp, xbn, ybn, zbn)
1601 ! 2) rotate beta radians ccw about y-axis
1602 ! ( <=> rotate z-axis -beta radians ccw)
1603  tmp = -beta
1604  call pushcontrol2b(0)
1605  else if (liftindex .eq. 3) then
1606 ! compute the wind direction vector.aerosurf axes different!!
1607 ! 1) rotate alpha radians cw about z-axis
1608 ! ( <=> rotate z-axis alpha radians ccw)
1609  call vectorrotation(x1, y1, z1, 2, alpha, xbn, ybn, zbn)
1610 ! 2) rotate beta radians ccw about y-axis
1611 ! ( <=> rotate z-axis -beta radians ccw)
1612  call pushcontrol2b(1)
1613  else
1614  call pushcontrol2b(2)
1615  end if
1616  zwd = winddirectiond(3)
1617  winddirectiond(3) = 0.0_8
1618  ywd = winddirectiond(2)
1619  winddirectiond(2) = 0.0_8
1620  xwd = winddirectiond(1)
1621  winddirectiond(1) = 0.0_8
1622  call popcontrol2b(branch)
1623  if (branch .eq. 0) then
1624  tmpd = 0.0_8
1625  call vectorrotation_b(xw, xwd, yw, ywd, zw, zwd, 2, tmp, tmpd, x1&
1626 & , x1d, y1, y1d, z1, z1d)
1627  betad = betad - tmpd
1628  tmp = -alpha
1629  tmpd = 0.0_8
1630  call vectorrotation_b(x1, x1d, y1, y1d, z1, z1d, 3, tmp, tmpd, xbn&
1631 & , xbnd, ybn, ybnd, zbn, zbnd)
1632  alphad = alphad - tmpd
1633  else if (branch .eq. 1) then
1634  call vectorrotation_b(xw, xwd, yw, ywd, zw, zwd, 3, beta, betad, &
1635 & x1, x1d, y1, y1d, z1, z1d)
1636  call vectorrotation_b(x1, x1d, y1, y1d, z1, z1d, 2, alpha, alphad&
1637 & , xbn, xbnd, ybn, ybnd, zbn, zbnd)
1638  end if
1639  end subroutine getdirvector_b
1640 
1641  subroutine getdirvector(refdirection, alpha, beta, winddirection, &
1642 & liftindex)
1643 !(xb,yb,zb,alpha,beta,xw,yw,zw)
1644 !
1645 ! convert the angle of attack and side slip angle to wind axes.
1646 ! the components of the wind direction vector (xw,yw,zw) are
1647 ! computed given the direction angles in radians and the body
1648 ! direction by performing two rotations on the original
1649 ! direction vector:
1650 ! 1) rotation about the zb or yb-axis: alpha clockwise (cw)
1651 ! (xb,yb,zb) -> (x1,y1,z1)
1652 ! 2) rotation about the yl or z1-axis: beta counter-clockwise
1653 ! (ccw) (x1,y1,z1) -> (xw,yw,zw)
1654 ! input arguments:
1655 ! alpha = angle of attack in radians
1656 ! beta = side slip angle in radians
1657 ! refdirection = reference direction vector
1658 ! output arguments:
1659 ! winddirection = unit wind vector in body axes
1660 !
1661  use constants
1662  use utils_b, only : terminate
1663  implicit none
1664 !
1665 ! subroutine arguments.
1666 !
1667  real(kind=realtype), dimension(3), intent(in) :: refdirection
1668  real(kind=realtype) :: alpha, beta
1669  real(kind=realtype), dimension(3), intent(out) :: winddirection
1670  integer(kind=inttype) :: liftindex
1671 !
1672 ! local variables.
1673 !
1674  real(kind=realtype) :: rnorm, x1, y1, z1, xbn, ybn, zbn, xw, yw, zw
1675  real(kind=realtype) :: tmp
1676  intrinsic sqrt
1677 ! normalize the input vector.
1678  rnorm = sqrt(refdirection(1)**2 + refdirection(2)**2 + refdirection(&
1679 & 3)**2)
1680  xbn = refdirection(1)/rnorm
1681  ybn = refdirection(2)/rnorm
1682  zbn = refdirection(3)/rnorm
1683 !!$ ! compute the wind direction vector.
1684 !!$
1685 !!$ ! 1) rotate alpha radians cw about y-axis
1686 !!$ ! ( <=> rotate y-axis alpha radians ccw)
1687 !!$
1688 !!$ call vectorrotation(x1, y1, z1, 2, alpha, xbn, ybn, zbn)
1689 !!$
1690 !!$ ! 2) rotate beta radians ccw about z-axis
1691 !!$ ! ( <=> rotate z-axis -beta radians ccw)
1692 !!$
1693 !!$ call vectorrotation(xw, yw, zw, 3, -beta, x1, y1, z1)
1694  if (liftindex .eq. 2) then
1695 ! compute the wind direction vector.aerosurf axes different!!
1696 ! 1) rotate alpha radians cw about z-axis
1697 ! ( <=> rotate z-axis alpha radians ccw)
1698  tmp = -alpha
1699  call vectorrotation(x1, y1, z1, 3, tmp, xbn, ybn, zbn)
1700 ! 2) rotate beta radians ccw about y-axis
1701 ! ( <=> rotate z-axis -beta radians ccw)
1702  tmp = -beta
1703  call vectorrotation(xw, yw, zw, 2, tmp, x1, y1, z1)
1704  else if (liftindex .eq. 3) then
1705 ! compute the wind direction vector.aerosurf axes different!!
1706 ! 1) rotate alpha radians cw about z-axis
1707 ! ( <=> rotate z-axis alpha radians ccw)
1708  call vectorrotation(x1, y1, z1, 2, alpha, xbn, ybn, zbn)
1709 ! 2) rotate beta radians ccw about y-axis
1710 ! ( <=> rotate z-axis -beta radians ccw)
1711  call vectorrotation(xw, yw, zw, 3, beta, x1, y1, z1)
1712  else
1713  call terminate('getdirvector', 'invalid lift direction')
1714  end if
1715  winddirection(1) = xw
1716  winddirection(2) = yw
1717  winddirection(3) = zw
1718  end subroutine getdirvector
1719 
1720 ! differentiation of vectorrotation in reverse (adjoint) mode (with options noisize i4 dr8 r8):
1721 ! gradient of useful results: xp yp angle zp
1722 ! with respect to varying inputs: x y z angle
1723  subroutine vectorrotation_b(xp, xpd, yp, ypd, zp, zpd, iaxis, angle, &
1724 & angled, x, xd, y, yd, z, zd)
1725 !
1726 ! vectorrotation rotates a given vector with respect to a
1727 ! specified axis by a given angle.
1728 ! input arguments:
1729 ! iaxis = rotation axis (1-x, 2-y, 3-z)
1730 ! angle = rotation angle (measured ccw in radians)
1731 ! x, y, z = coordinates in original system
1732 ! output arguments:
1733 ! xp, yp, zp = coordinates in rotated system
1734 !
1735  use precision
1736  implicit none
1737 !
1738 ! subroutine arguments.
1739 !
1740  integer(kind=inttype), intent(in) :: iaxis
1741  real(kind=realtype), intent(in) :: angle, x, y, z
1742  real(kind=realtype) :: angled, xd, yd, zd
1743  real(kind=realtype) :: xp, yp, zp
1744  real(kind=realtype) :: xpd, ypd, zpd
1745  intrinsic cos
1746  intrinsic sin
1747 ! rotation about specified axis by specified angle
1748  select case (iaxis)
1749  case (1)
1750  xd = xpd
1751  angled = angled + (cos(angle)*z-sin(angle)*y)*ypd - (cos(angle)*y+&
1752 & sin(angle)*z)*zpd
1753  yd = cos(angle)*ypd - sin(angle)*zpd
1754  zd = cos(angle)*zpd + sin(angle)*ypd
1755  case (2)
1756  angled = angled + (cos(angle)*x-sin(angle)*z)*zpd - (sin(angle)*x+&
1757 & cos(angle)*z)*xpd
1758  xd = sin(angle)*zpd + cos(angle)*xpd
1759  yd = ypd
1760  zd = cos(angle)*zpd - sin(angle)*xpd
1761  case (3)
1762  xd = cos(angle)*xpd - sin(angle)*ypd
1763  yd = cos(angle)*ypd + sin(angle)*xpd
1764  zd = zpd
1765  angled = angled + (cos(angle)*y-sin(angle)*x)*xpd - (sin(angle)*y+&
1766 & cos(angle)*x)*ypd
1767  case default
1768  stop
1769  end select
1770  end subroutine vectorrotation_b
1771 
1772  subroutine vectorrotation(xp, yp, zp, iaxis, angle, x, y, z)
1773 !
1774 ! vectorrotation rotates a given vector with respect to a
1775 ! specified axis by a given angle.
1776 ! input arguments:
1777 ! iaxis = rotation axis (1-x, 2-y, 3-z)
1778 ! angle = rotation angle (measured ccw in radians)
1779 ! x, y, z = coordinates in original system
1780 ! output arguments:
1781 ! xp, yp, zp = coordinates in rotated system
1782 !
1783  use precision
1784  implicit none
1785 !
1786 ! subroutine arguments.
1787 !
1788  integer(kind=inttype), intent(in) :: iaxis
1789  real(kind=realtype), intent(in) :: angle, x, y, z
1790  real(kind=realtype), intent(out) :: xp, yp, zp
1791  intrinsic cos
1792  intrinsic sin
1793 ! rotation about specified axis by specified angle
1794  select case (iaxis)
1795  case (1)
1796 ! rotation about the x-axis
1797  xp = 1.*x + 0.*y + 0.*z
1798  yp = 0.*x + cos(angle)*y + sin(angle)*z
1799  zp = 0.*x - sin(angle)*y + cos(angle)*z
1800 ! rotation about the y-axis
1801  case (2)
1802  xp = cos(angle)*x + 0.*y - sin(angle)*z
1803  yp = 0.*x + 1.*y + 0.*z
1804  zp = sin(angle)*x + 0.*y + cos(angle)*z
1805 ! rotation about the z-axis
1806  case (3)
1807  xp = cos(angle)*x + sin(angle)*y + 0.*z
1808  yp = -(sin(angle)*x) + cos(angle)*y + 0.*z
1809  zp = 0.*x + 0.*y + 1.*z
1810  case default
1811  write(*, *) 'vectorrotation called with invalid arguments'
1812  stop
1813  end select
1814  end subroutine vectorrotation
1815 
1816 ! differentiation of allnodalgradients in reverse (adjoint) mode (with options noisize i4 dr8 r8):
1817 ! gradient of useful results: *aa *wx *wy *wz *w *qx *qy
1818 ! *qz *vol *ux *uy *uz *si *sj *sk *vx *vy *vz
1819 ! with respect to varying inputs: *aa *wx *wy *wz *w *qx *qy
1820 ! *qz *vol *ux *uy *uz *si *sj *sk *vx *vy *vz
1821 ! rw status of diff variables: *aa:incr *wx:in-out *wy:in-out
1822 ! *wz:in-out *w:incr *qx:in-out *qy:in-out *qz:in-out
1823 ! *vol:incr *ux:in-out *uy:in-out *uz:in-out *si:incr
1824 ! *sj:incr *sk:incr *vx:in-out *vy:in-out *vz:in-out
1825 ! plus diff mem management of: aa:in wx:in wy:in wz:in w:in qx:in
1826 ! qy:in qz:in vol:in ux:in uy:in uz:in si:in sj:in
1827 ! sk:in vx:in vy:in vz:in
1828  subroutine allnodalgradients_b()
1829 !
1830 ! nodalgradients computes the nodal velocity gradients and
1831 ! minus the gradient of the speed of sound squared. the minus
1832 ! sign is present, because this is the definition of the heat
1833 ! flux. these gradients are computed for all nodes.
1834 !
1835  use constants
1836  use blockpointers
1837  implicit none
1838 ! local variables.
1839  integer(kind=inttype) :: i, j, k
1840  integer(kind=inttype) :: k1, kk
1841  integer(kind=inttype) :: istart, iend, isize, ii
1842  integer(kind=inttype) :: jstart, jend, jsize
1843  integer(kind=inttype) :: kstart, kend, ksize
1844  real(kind=realtype) :: oneoverv, ubar, vbar, wbar, a2
1845  real(kind=realtype) :: oneovervd, ubard, vbard, wbard, a2d
1846  real(kind=realtype) :: sx, sx1, sy, sy1, sz, sz1
1847  real(kind=realtype) :: sxd, syd, szd
1848  intrinsic mod
1849  real(kind=realtype) :: temp
1850  real(kind=realtype) :: tempd
1851  integer :: branch
1852 ! zero all nodeal gradients:
1853  ux = zero
1854  uy = zero
1855  uz = zero
1856  vx = zero
1857  vy = zero
1858  vz = zero
1859  wx = zero
1860  wy = zero
1861  wz = zero
1862  qx = zero
1863  qy = zero
1864  qz = zero
1865 !$fwd-of ii-loop
1866 ! first part. contribution in the k-direction.
1867 ! the contribution is scattered to both the left and right node
1868 ! in k-direction.
1869  do ii=0,il*jl*ke-1
1870  i = mod(ii, il) + 1
1871  j = mod(ii/il, jl) + 1
1872  k = ii/(il*jl) + 1
1873 ! compute 8 times the average normal for this part of
1874 ! the control volume. the factor 8 is taken care of later
1875 ! on when the division by the volume takes place.
1876  sx = sk(i, j, k-1, 1) + sk(i+1, j, k-1, 1) + sk(i, j+1, k-1, 1) + &
1877 & sk(i+1, j+1, k-1, 1) + sk(i, j, k, 1) + sk(i+1, j, k, 1) + sk(i&
1878 & , j+1, k, 1) + sk(i+1, j+1, k, 1)
1879  sy = sk(i, j, k-1, 2) + sk(i+1, j, k-1, 2) + sk(i, j+1, k-1, 2) + &
1880 & sk(i+1, j+1, k-1, 2) + sk(i, j, k, 2) + sk(i+1, j, k, 2) + sk(i&
1881 & , j+1, k, 2) + sk(i+1, j+1, k, 2)
1882  sz = sk(i, j, k-1, 3) + sk(i+1, j, k-1, 3) + sk(i, j+1, k-1, 3) + &
1883 & sk(i+1, j+1, k-1, 3) + sk(i, j, k, 3) + sk(i+1, j, k, 3) + sk(i&
1884 & , j+1, k, 3) + sk(i+1, j+1, k, 3)
1885 ! compute the average velocities and speed of sound squared
1886 ! for this integration point. node that these variables are
1887 ! stored in w(ivx), w(ivy), w(ivz) and p.
1888  ubar = fourth*(w(i, j, k, ivx)+w(i+1, j, k, ivx)+w(i, j+1, k, ivx)&
1889 & +w(i+1, j+1, k, ivx))
1890  vbar = fourth*(w(i, j, k, ivy)+w(i+1, j, k, ivy)+w(i, j+1, k, ivy)&
1891 & +w(i+1, j+1, k, ivy))
1892  wbar = fourth*(w(i, j, k, ivz)+w(i+1, j, k, ivz)+w(i, j+1, k, ivz)&
1893 & +w(i+1, j+1, k, ivz))
1894  a2 = fourth*(aa(i, j, k)+aa(i+1, j, k)+aa(i, j+1, k)+aa(i+1, j+1, &
1895 & k))
1896 ! add the contributions to the surface integral to the node
1897 ! j-1 and substract it from the node j. for the heat flux it
1898 ! is reversed, because the negative of the gradient of the
1899 ! speed of sound must be computed.
1900  if (k .gt. 1) then
1901  ux(i, j, k-1) = ux(i, j, k-1) + ubar*sx
1902  uy(i, j, k-1) = uy(i, j, k-1) + ubar*sy
1903  uz(i, j, k-1) = uz(i, j, k-1) + ubar*sz
1904  vx(i, j, k-1) = vx(i, j, k-1) + vbar*sx
1905  vy(i, j, k-1) = vy(i, j, k-1) + vbar*sy
1906  vz(i, j, k-1) = vz(i, j, k-1) + vbar*sz
1907  wx(i, j, k-1) = wx(i, j, k-1) + wbar*sx
1908  wy(i, j, k-1) = wy(i, j, k-1) + wbar*sy
1909  wz(i, j, k-1) = wz(i, j, k-1) + wbar*sz
1910  qx(i, j, k-1) = qx(i, j, k-1) - a2*sx
1911  qy(i, j, k-1) = qy(i, j, k-1) - a2*sy
1912  qz(i, j, k-1) = qz(i, j, k-1) - a2*sz
1913  end if
1914  if (k .lt. ke) then
1915  ux(i, j, k) = ux(i, j, k) - ubar*sx
1916  uy(i, j, k) = uy(i, j, k) - ubar*sy
1917  uz(i, j, k) = uz(i, j, k) - ubar*sz
1918  vx(i, j, k) = vx(i, j, k) - vbar*sx
1919  vy(i, j, k) = vy(i, j, k) - vbar*sy
1920  vz(i, j, k) = vz(i, j, k) - vbar*sz
1921  wx(i, j, k) = wx(i, j, k) - wbar*sx
1922  wy(i, j, k) = wy(i, j, k) - wbar*sy
1923  wz(i, j, k) = wz(i, j, k) - wbar*sz
1924  qx(i, j, k) = qx(i, j, k) + a2*sx
1925  qy(i, j, k) = qy(i, j, k) + a2*sy
1926  qz(i, j, k) = qz(i, j, k) + a2*sz
1927  end if
1928  end do
1929 !$fwd-of ii-loop
1930 ! second part. contribution in the j-direction.
1931 ! the contribution is scattered to both the left and right node
1932 ! in j-direction.
1933  do ii=0,il*je*kl-1
1934  i = mod(ii, il) + 1
1935  j = mod(ii/il, je) + 1
1936  k = ii/(il*je) + 1
1937 ! compute 8 times the average normal for this part of
1938 ! the control volume. the factor 8 is taken care of later
1939 ! on when the division by the volume takes place.
1940  sx = sj(i, j-1, k, 1) + sj(i+1, j-1, k, 1) + sj(i, j-1, k+1, 1) + &
1941 & sj(i+1, j-1, k+1, 1) + sj(i, j, k, 1) + sj(i+1, j, k, 1) + sj(i&
1942 & , j, k+1, 1) + sj(i+1, j, k+1, 1)
1943  sy = sj(i, j-1, k, 2) + sj(i+1, j-1, k, 2) + sj(i, j-1, k+1, 2) + &
1944 & sj(i+1, j-1, k+1, 2) + sj(i, j, k, 2) + sj(i+1, j, k, 2) + sj(i&
1945 & , j, k+1, 2) + sj(i+1, j, k+1, 2)
1946  sz = sj(i, j-1, k, 3) + sj(i+1, j-1, k, 3) + sj(i, j-1, k+1, 3) + &
1947 & sj(i+1, j-1, k+1, 3) + sj(i, j, k, 3) + sj(i+1, j, k, 3) + sj(i&
1948 & , j, k+1, 3) + sj(i+1, j, k+1, 3)
1949 ! compute the average velocities and speed of sound squared
1950 ! for this integration point. node that these variables are
1951 ! stored in w(ivx), w(ivy), w(ivz) and p.
1952  ubar = fourth*(w(i, j, k, ivx)+w(i+1, j, k, ivx)+w(i, j, k+1, ivx)&
1953 & +w(i+1, j, k+1, ivx))
1954  vbar = fourth*(w(i, j, k, ivy)+w(i+1, j, k, ivy)+w(i, j, k+1, ivy)&
1955 & +w(i+1, j, k+1, ivy))
1956  wbar = fourth*(w(i, j, k, ivz)+w(i+1, j, k, ivz)+w(i, j, k+1, ivz)&
1957 & +w(i+1, j, k+1, ivz))
1958  a2 = fourth*(aa(i, j, k)+aa(i+1, j, k)+aa(i, j, k+1)+aa(i+1, j, k+&
1959 & 1))
1960 ! add the contributions to the surface integral to the node
1961 ! j-1 and substract it from the node j. for the heat flux it
1962 ! is reversed, because the negative of the gradient of the
1963 ! speed of sound must be computed.
1964  if (j .gt. 1) then
1965  ux(i, j-1, k) = ux(i, j-1, k) + ubar*sx
1966  uy(i, j-1, k) = uy(i, j-1, k) + ubar*sy
1967  uz(i, j-1, k) = uz(i, j-1, k) + ubar*sz
1968  vx(i, j-1, k) = vx(i, j-1, k) + vbar*sx
1969  vy(i, j-1, k) = vy(i, j-1, k) + vbar*sy
1970  vz(i, j-1, k) = vz(i, j-1, k) + vbar*sz
1971  wx(i, j-1, k) = wx(i, j-1, k) + wbar*sx
1972  wy(i, j-1, k) = wy(i, j-1, k) + wbar*sy
1973  wz(i, j-1, k) = wz(i, j-1, k) + wbar*sz
1974  qx(i, j-1, k) = qx(i, j-1, k) - a2*sx
1975  qy(i, j-1, k) = qy(i, j-1, k) - a2*sy
1976  qz(i, j-1, k) = qz(i, j-1, k) - a2*sz
1977  end if
1978  if (j .lt. je) then
1979  ux(i, j, k) = ux(i, j, k) - ubar*sx
1980  uy(i, j, k) = uy(i, j, k) - ubar*sy
1981  uz(i, j, k) = uz(i, j, k) - ubar*sz
1982  vx(i, j, k) = vx(i, j, k) - vbar*sx
1983  vy(i, j, k) = vy(i, j, k) - vbar*sy
1984  vz(i, j, k) = vz(i, j, k) - vbar*sz
1985  wx(i, j, k) = wx(i, j, k) - wbar*sx
1986  wy(i, j, k) = wy(i, j, k) - wbar*sy
1987  wz(i, j, k) = wz(i, j, k) - wbar*sz
1988  qx(i, j, k) = qx(i, j, k) + a2*sx
1989  qy(i, j, k) = qy(i, j, k) + a2*sy
1990  qz(i, j, k) = qz(i, j, k) + a2*sz
1991  end if
1992  end do
1993 !$fwd-of ii-loop
1994 ! third part. contribution in the i-direction.
1995 ! the contribution is scattered to both the left and right node
1996 ! in i-direction.
1997  do ii=0,ie*jl*kl-1
1998  i = mod(ii, ie) + 1
1999  j = mod(ii/ie, jl) + 1
2000  k = ii/(ie*jl) + 1
2001 ! compute 8 times the average normal for this part of
2002 ! the control volume. the factor 8 is taken care of later
2003 ! on when the division by the volume takes place.
2004  sx = si(i-1, j, k, 1) + si(i-1, j+1, k, 1) + si(i-1, j, k+1, 1) + &
2005 & si(i-1, j+1, k+1, 1) + si(i, j, k, 1) + si(i, j+1, k, 1) + si(i&
2006 & , j, k+1, 1) + si(i, j+1, k+1, 1)
2007  sy = si(i-1, j, k, 2) + si(i-1, j+1, k, 2) + si(i-1, j, k+1, 2) + &
2008 & si(i-1, j+1, k+1, 2) + si(i, j, k, 2) + si(i, j+1, k, 2) + si(i&
2009 & , j, k+1, 2) + si(i, j+1, k+1, 2)
2010  sz = si(i-1, j, k, 3) + si(i-1, j+1, k, 3) + si(i-1, j, k+1, 3) + &
2011 & si(i-1, j+1, k+1, 3) + si(i, j, k, 3) + si(i, j+1, k, 3) + si(i&
2012 & , j, k+1, 3) + si(i, j+1, k+1, 3)
2013 ! compute the average velocities and speed of sound squared
2014 ! for this integration point. node that these variables are
2015 ! stored in w(ivx), w(ivy), w(ivz) and p.
2016  ubar = fourth*(w(i, j, k, ivx)+w(i, j+1, k, ivx)+w(i, j, k+1, ivx)&
2017 & +w(i, j+1, k+1, ivx))
2018  vbar = fourth*(w(i, j, k, ivy)+w(i, j+1, k, ivy)+w(i, j, k+1, ivy)&
2019 & +w(i, j+1, k+1, ivy))
2020  wbar = fourth*(w(i, j, k, ivz)+w(i, j+1, k, ivz)+w(i, j, k+1, ivz)&
2021 & +w(i, j+1, k+1, ivz))
2022  a2 = fourth*(aa(i, j, k)+aa(i, j+1, k)+aa(i, j, k+1)+aa(i, j+1, k+&
2023 & 1))
2024 ! add the contributions to the surface integral to the node
2025 ! j-1 and substract it from the node j. for the heat flux it
2026 ! is reversed, because the negative of the gradient of the
2027 ! speed of sound must be computed.
2028  if (i .gt. 1) then
2029  ux(i-1, j, k) = ux(i-1, j, k) + ubar*sx
2030  uy(i-1, j, k) = uy(i-1, j, k) + ubar*sy
2031  uz(i-1, j, k) = uz(i-1, j, k) + ubar*sz
2032  vx(i-1, j, k) = vx(i-1, j, k) + vbar*sx
2033  vy(i-1, j, k) = vy(i-1, j, k) + vbar*sy
2034  vz(i-1, j, k) = vz(i-1, j, k) + vbar*sz
2035  wx(i-1, j, k) = wx(i-1, j, k) + wbar*sx
2036  wy(i-1, j, k) = wy(i-1, j, k) + wbar*sy
2037  wz(i-1, j, k) = wz(i-1, j, k) + wbar*sz
2038  qx(i-1, j, k) = qx(i-1, j, k) - a2*sx
2039  qy(i-1, j, k) = qy(i-1, j, k) - a2*sy
2040  qz(i-1, j, k) = qz(i-1, j, k) - a2*sz
2041  end if
2042  if (i .lt. ie) then
2043  ux(i, j, k) = ux(i, j, k) - ubar*sx
2044  uy(i, j, k) = uy(i, j, k) - ubar*sy
2045  uz(i, j, k) = uz(i, j, k) - ubar*sz
2046  vx(i, j, k) = vx(i, j, k) - vbar*sx
2047  vy(i, j, k) = vy(i, j, k) - vbar*sy
2048  vz(i, j, k) = vz(i, j, k) - vbar*sz
2049  wx(i, j, k) = wx(i, j, k) - wbar*sx
2050  wy(i, j, k) = wy(i, j, k) - wbar*sy
2051  wz(i, j, k) = wz(i, j, k) - wbar*sz
2052  qx(i, j, k) = qx(i, j, k) + a2*sx
2053  qy(i, j, k) = qy(i, j, k) + a2*sy
2054  qz(i, j, k) = qz(i, j, k) + a2*sz
2055  end if
2056  end do
2057 !$bwd-of ii-loop
2058  do ii=0,il*jl*kl-1
2059  i = mod(ii, il) + 1
2060  j = mod(ii/il, jl) + 1
2061  k = ii/(il*jl) + 1
2062 ! compute the inverse of 8 times the volume for this node.
2063  oneoverv = one/(vol(i, j, k)+vol(i, j, k+1)+vol(i+1, j, k)+vol(i+1&
2064 & , j, k+1)+vol(i, j+1, k)+vol(i, j+1, k+1)+vol(i+1, j+1, k)+vol(i&
2065 & +1, j+1, k+1))
2066 ! compute the correct velocity gradients and "unit" heat
2067 ! fluxes. the velocity gradients are stored in ux, etc.
2068  oneovervd = qz(i, j, k)*qzd(i, j, k) + qy(i, j, k)*qyd(i, j, k) + &
2069 & qx(i, j, k)*qxd(i, j, k) + wz(i, j, k)*wzd(i, j, k) + wy(i, j, k&
2070 & )*wyd(i, j, k) + wx(i, j, k)*wxd(i, j, k) + vz(i, j, k)*vzd(i, j&
2071 & , k) + vy(i, j, k)*vyd(i, j, k) + vx(i, j, k)*vxd(i, j, k) + uz(&
2072 & i, j, k)*uzd(i, j, k) + uy(i, j, k)*uyd(i, j, k) + ux(i, j, k)*&
2073 & uxd(i, j, k)
2074  qzd(i, j, k) = oneoverv*qzd(i, j, k)
2075  qyd(i, j, k) = oneoverv*qyd(i, j, k)
2076  qxd(i, j, k) = oneoverv*qxd(i, j, k)
2077  wzd(i, j, k) = oneoverv*wzd(i, j, k)
2078  wyd(i, j, k) = oneoverv*wyd(i, j, k)
2079  wxd(i, j, k) = oneoverv*wxd(i, j, k)
2080  vzd(i, j, k) = oneoverv*vzd(i, j, k)
2081  vyd(i, j, k) = oneoverv*vyd(i, j, k)
2082  vxd(i, j, k) = oneoverv*vxd(i, j, k)
2083  uzd(i, j, k) = oneoverv*uzd(i, j, k)
2084  uyd(i, j, k) = oneoverv*uyd(i, j, k)
2085  uxd(i, j, k) = oneoverv*uxd(i, j, k)
2086  temp = vol(i, j, k) + vol(i, j, k+1) + vol(i+1, j, k) + vol(i+1, j&
2087 & , k+1) + vol(i, j+1, k) + vol(i, j+1, k+1) + vol(i+1, j+1, k) + &
2088 & vol(i+1, j+1, k+1)
2089  tempd = -(one*oneovervd/temp**2)
2090  vold(i, j, k) = vold(i, j, k) + tempd
2091  vold(i, j, k+1) = vold(i, j, k+1) + tempd
2092  vold(i+1, j, k) = vold(i+1, j, k) + tempd
2093  vold(i+1, j, k+1) = vold(i+1, j, k+1) + tempd
2094  vold(i, j+1, k) = vold(i, j+1, k) + tempd
2095  vold(i, j+1, k+1) = vold(i, j+1, k+1) + tempd
2096  vold(i+1, j+1, k) = vold(i+1, j+1, k) + tempd
2097  vold(i+1, j+1, k+1) = vold(i+1, j+1, k+1) + tempd
2098  end do
2099 !$bwd-of ii-loop
2100  do ii=0,ie*jl*kl-1
2101  i = mod(ii, ie) + 1
2102  j = mod(ii/ie, jl) + 1
2103  k = ii/(ie*jl) + 1
2104 ! compute 8 times the average normal for this part of
2105 ! the control volume. the factor 8 is taken care of later
2106 ! on when the division by the volume takes place.
2107  sx = si(i-1, j, k, 1) + si(i-1, j+1, k, 1) + si(i-1, j, k+1, 1) + &
2108 & si(i-1, j+1, k+1, 1) + si(i, j, k, 1) + si(i, j+1, k, 1) + si(i&
2109 & , j, k+1, 1) + si(i, j+1, k+1, 1)
2110  sy = si(i-1, j, k, 2) + si(i-1, j+1, k, 2) + si(i-1, j, k+1, 2) + &
2111 & si(i-1, j+1, k+1, 2) + si(i, j, k, 2) + si(i, j+1, k, 2) + si(i&
2112 & , j, k+1, 2) + si(i, j+1, k+1, 2)
2113  sz = si(i-1, j, k, 3) + si(i-1, j+1, k, 3) + si(i-1, j, k+1, 3) + &
2114 & si(i-1, j+1, k+1, 3) + si(i, j, k, 3) + si(i, j+1, k, 3) + si(i&
2115 & , j, k+1, 3) + si(i, j+1, k+1, 3)
2116 ! compute the average velocities and speed of sound squared
2117 ! for this integration point. node that these variables are
2118 ! stored in w(ivx), w(ivy), w(ivz) and p.
2119  ubar = fourth*(w(i, j, k, ivx)+w(i, j+1, k, ivx)+w(i, j, k+1, ivx)&
2120 & +w(i, j+1, k+1, ivx))
2121  vbar = fourth*(w(i, j, k, ivy)+w(i, j+1, k, ivy)+w(i, j, k+1, ivy)&
2122 & +w(i, j+1, k+1, ivy))
2123  wbar = fourth*(w(i, j, k, ivz)+w(i, j+1, k, ivz)+w(i, j, k+1, ivz)&
2124 & +w(i, j+1, k+1, ivz))
2125  a2 = fourth*(aa(i, j, k)+aa(i, j+1, k)+aa(i, j, k+1)+aa(i, j+1, k+&
2126 & 1))
2127 ! add the contributions to the surface integral to the node
2128 ! j-1 and substract it from the node j. for the heat flux it
2129 ! is reversed, because the negative of the gradient of the
2130 ! speed of sound must be computed.
2131  if (i .gt. 1) then
2132  call pushcontrol1b(0)
2133  else
2134  call pushcontrol1b(1)
2135  end if
2136  if (i .lt. ie) then
2137  a2d = sz*qzd(i, j, k) + sy*qyd(i, j, k) + sx*qxd(i, j, k)
2138  szd = a2*qzd(i, j, k) - wbar*wzd(i, j, k) - vbar*vzd(i, j, k) - &
2139 & ubar*uzd(i, j, k)
2140  syd = a2*qyd(i, j, k) - wbar*wyd(i, j, k) - vbar*vyd(i, j, k) - &
2141 & ubar*uyd(i, j, k)
2142  sxd = a2*qxd(i, j, k) - wbar*wxd(i, j, k) - vbar*vxd(i, j, k) - &
2143 & ubar*uxd(i, j, k)
2144  wbard = -(sz*wzd(i, j, k)) - sy*wyd(i, j, k) - sx*wxd(i, j, k)
2145  vbard = -(sz*vzd(i, j, k)) - sy*vyd(i, j, k) - sx*vxd(i, j, k)
2146  ubard = -(sz*uzd(i, j, k)) - sy*uyd(i, j, k) - sx*uxd(i, j, k)
2147  else
2148  wbard = 0.0_8
2149  vbard = 0.0_8
2150  ubard = 0.0_8
2151  a2d = 0.0_8
2152  sxd = 0.0_8
2153  syd = 0.0_8
2154  szd = 0.0_8
2155  end if
2156  call popcontrol1b(branch)
2157  if (branch .eq. 0) then
2158  a2d = a2d - sz*qzd(i-1, j, k) - sy*qyd(i-1, j, k) - sx*qxd(i-1, &
2159 & j, k)
2160  szd = szd + wbar*wzd(i-1, j, k) - a2*qzd(i-1, j, k) + vbar*vzd(i&
2161 & -1, j, k) + ubar*uzd(i-1, j, k)
2162  syd = syd + wbar*wyd(i-1, j, k) - a2*qyd(i-1, j, k) + vbar*vyd(i&
2163 & -1, j, k) + ubar*uyd(i-1, j, k)
2164  sxd = sxd + wbar*wxd(i-1, j, k) - a2*qxd(i-1, j, k) + vbar*vxd(i&
2165 & -1, j, k) + ubar*uxd(i-1, j, k)
2166  wbard = wbard + sz*wzd(i-1, j, k) + sy*wyd(i-1, j, k) + sx*wxd(i&
2167 & -1, j, k)
2168  vbard = vbard + sz*vzd(i-1, j, k) + sy*vyd(i-1, j, k) + sx*vxd(i&
2169 & -1, j, k)
2170  ubard = ubard + sz*uzd(i-1, j, k) + sy*uyd(i-1, j, k) + sx*uxd(i&
2171 & -1, j, k)
2172  end if
2173  tempd = fourth*a2d
2174  aad(i, j, k) = aad(i, j, k) + tempd
2175  aad(i, j+1, k) = aad(i, j+1, k) + tempd
2176  aad(i, j, k+1) = aad(i, j, k+1) + tempd
2177  aad(i, j+1, k+1) = aad(i, j+1, k+1) + tempd
2178  tempd = fourth*wbard
2179  wd(i, j, k, ivz) = wd(i, j, k, ivz) + tempd
2180  wd(i, j+1, k, ivz) = wd(i, j+1, k, ivz) + tempd
2181  wd(i, j, k+1, ivz) = wd(i, j, k+1, ivz) + tempd
2182  wd(i, j+1, k+1, ivz) = wd(i, j+1, k+1, ivz) + tempd
2183  tempd = fourth*vbard
2184  wd(i, j, k, ivy) = wd(i, j, k, ivy) + tempd
2185  wd(i, j+1, k, ivy) = wd(i, j+1, k, ivy) + tempd
2186  wd(i, j, k+1, ivy) = wd(i, j, k+1, ivy) + tempd
2187  wd(i, j+1, k+1, ivy) = wd(i, j+1, k+1, ivy) + tempd
2188  tempd = fourth*ubard
2189  wd(i, j, k, ivx) = wd(i, j, k, ivx) + tempd
2190  wd(i, j+1, k, ivx) = wd(i, j+1, k, ivx) + tempd
2191  wd(i, j, k+1, ivx) = wd(i, j, k+1, ivx) + tempd
2192  wd(i, j+1, k+1, ivx) = wd(i, j+1, k+1, ivx) + tempd
2193  sid(i-1, j, k, 3) = sid(i-1, j, k, 3) + szd
2194  sid(i-1, j+1, k, 3) = sid(i-1, j+1, k, 3) + szd
2195  sid(i-1, j, k+1, 3) = sid(i-1, j, k+1, 3) + szd
2196  sid(i-1, j+1, k+1, 3) = sid(i-1, j+1, k+1, 3) + szd
2197  sid(i, j, k, 3) = sid(i, j, k, 3) + szd
2198  sid(i, j+1, k, 3) = sid(i, j+1, k, 3) + szd
2199  sid(i, j, k+1, 3) = sid(i, j, k+1, 3) + szd
2200  sid(i, j+1, k+1, 3) = sid(i, j+1, k+1, 3) + szd
2201  sid(i-1, j, k, 2) = sid(i-1, j, k, 2) + syd
2202  sid(i-1, j+1, k, 2) = sid(i-1, j+1, k, 2) + syd
2203  sid(i-1, j, k+1, 2) = sid(i-1, j, k+1, 2) + syd
2204  sid(i-1, j+1, k+1, 2) = sid(i-1, j+1, k+1, 2) + syd
2205  sid(i, j, k, 2) = sid(i, j, k, 2) + syd
2206  sid(i, j+1, k, 2) = sid(i, j+1, k, 2) + syd
2207  sid(i, j, k+1, 2) = sid(i, j, k+1, 2) + syd
2208  sid(i, j+1, k+1, 2) = sid(i, j+1, k+1, 2) + syd
2209  sid(i-1, j, k, 1) = sid(i-1, j, k, 1) + sxd
2210  sid(i-1, j+1, k, 1) = sid(i-1, j+1, k, 1) + sxd
2211  sid(i-1, j, k+1, 1) = sid(i-1, j, k+1, 1) + sxd
2212  sid(i-1, j+1, k+1, 1) = sid(i-1, j+1, k+1, 1) + sxd
2213  sid(i, j, k, 1) = sid(i, j, k, 1) + sxd
2214  sid(i, j+1, k, 1) = sid(i, j+1, k, 1) + sxd
2215  sid(i, j, k+1, 1) = sid(i, j, k+1, 1) + sxd
2216  sid(i, j+1, k+1, 1) = sid(i, j+1, k+1, 1) + sxd
2217  end do
2218 !$bwd-of ii-loop
2219  do ii=0,il*je*kl-1
2220  i = mod(ii, il) + 1
2221  j = mod(ii/il, je) + 1
2222  k = ii/(il*je) + 1
2223 ! compute 8 times the average normal for this part of
2224 ! the control volume. the factor 8 is taken care of later
2225 ! on when the division by the volume takes place.
2226  sx = sj(i, j-1, k, 1) + sj(i+1, j-1, k, 1) + sj(i, j-1, k+1, 1) + &
2227 & sj(i+1, j-1, k+1, 1) + sj(i, j, k, 1) + sj(i+1, j, k, 1) + sj(i&
2228 & , j, k+1, 1) + sj(i+1, j, k+1, 1)
2229  sy = sj(i, j-1, k, 2) + sj(i+1, j-1, k, 2) + sj(i, j-1, k+1, 2) + &
2230 & sj(i+1, j-1, k+1, 2) + sj(i, j, k, 2) + sj(i+1, j, k, 2) + sj(i&
2231 & , j, k+1, 2) + sj(i+1, j, k+1, 2)
2232  sz = sj(i, j-1, k, 3) + sj(i+1, j-1, k, 3) + sj(i, j-1, k+1, 3) + &
2233 & sj(i+1, j-1, k+1, 3) + sj(i, j, k, 3) + sj(i+1, j, k, 3) + sj(i&
2234 & , j, k+1, 3) + sj(i+1, j, k+1, 3)
2235 ! compute the average velocities and speed of sound squared
2236 ! for this integration point. node that these variables are
2237 ! stored in w(ivx), w(ivy), w(ivz) and p.
2238  ubar = fourth*(w(i, j, k, ivx)+w(i+1, j, k, ivx)+w(i, j, k+1, ivx)&
2239 & +w(i+1, j, k+1, ivx))
2240  vbar = fourth*(w(i, j, k, ivy)+w(i+1, j, k, ivy)+w(i, j, k+1, ivy)&
2241 & +w(i+1, j, k+1, ivy))
2242  wbar = fourth*(w(i, j, k, ivz)+w(i+1, j, k, ivz)+w(i, j, k+1, ivz)&
2243 & +w(i+1, j, k+1, ivz))
2244  a2 = fourth*(aa(i, j, k)+aa(i+1, j, k)+aa(i, j, k+1)+aa(i+1, j, k+&
2245 & 1))
2246 ! add the contributions to the surface integral to the node
2247 ! j-1 and substract it from the node j. for the heat flux it
2248 ! is reversed, because the negative of the gradient of the
2249 ! speed of sound must be computed.
2250  if (j .gt. 1) then
2251  call pushcontrol1b(0)
2252  else
2253  call pushcontrol1b(1)
2254  end if
2255  if (j .lt. je) then
2256  a2d = sz*qzd(i, j, k) + sy*qyd(i, j, k) + sx*qxd(i, j, k)
2257  szd = a2*qzd(i, j, k) - wbar*wzd(i, j, k) - vbar*vzd(i, j, k) - &
2258 & ubar*uzd(i, j, k)
2259  syd = a2*qyd(i, j, k) - wbar*wyd(i, j, k) - vbar*vyd(i, j, k) - &
2260 & ubar*uyd(i, j, k)
2261  sxd = a2*qxd(i, j, k) - wbar*wxd(i, j, k) - vbar*vxd(i, j, k) - &
2262 & ubar*uxd(i, j, k)
2263  wbard = -(sz*wzd(i, j, k)) - sy*wyd(i, j, k) - sx*wxd(i, j, k)
2264  vbard = -(sz*vzd(i, j, k)) - sy*vyd(i, j, k) - sx*vxd(i, j, k)
2265  ubard = -(sz*uzd(i, j, k)) - sy*uyd(i, j, k) - sx*uxd(i, j, k)
2266  else
2267  wbard = 0.0_8
2268  vbard = 0.0_8
2269  ubard = 0.0_8
2270  a2d = 0.0_8
2271  sxd = 0.0_8
2272  syd = 0.0_8
2273  szd = 0.0_8
2274  end if
2275  call popcontrol1b(branch)
2276  if (branch .eq. 0) then
2277  a2d = a2d - sz*qzd(i, j-1, k) - sy*qyd(i, j-1, k) - sx*qxd(i, j-&
2278 & 1, k)
2279  szd = szd + wbar*wzd(i, j-1, k) - a2*qzd(i, j-1, k) + vbar*vzd(i&
2280 & , j-1, k) + ubar*uzd(i, j-1, k)
2281  syd = syd + wbar*wyd(i, j-1, k) - a2*qyd(i, j-1, k) + vbar*vyd(i&
2282 & , j-1, k) + ubar*uyd(i, j-1, k)
2283  sxd = sxd + wbar*wxd(i, j-1, k) - a2*qxd(i, j-1, k) + vbar*vxd(i&
2284 & , j-1, k) + ubar*uxd(i, j-1, k)
2285  wbard = wbard + sz*wzd(i, j-1, k) + sy*wyd(i, j-1, k) + sx*wxd(i&
2286 & , j-1, k)
2287  vbard = vbard + sz*vzd(i, j-1, k) + sy*vyd(i, j-1, k) + sx*vxd(i&
2288 & , j-1, k)
2289  ubard = ubard + sz*uzd(i, j-1, k) + sy*uyd(i, j-1, k) + sx*uxd(i&
2290 & , j-1, k)
2291  end if
2292  tempd = fourth*a2d
2293  aad(i, j, k) = aad(i, j, k) + tempd
2294  aad(i+1, j, k) = aad(i+1, j, k) + tempd
2295  aad(i, j, k+1) = aad(i, j, k+1) + tempd
2296  aad(i+1, j, k+1) = aad(i+1, j, k+1) + tempd
2297  tempd = fourth*wbard
2298  wd(i, j, k, ivz) = wd(i, j, k, ivz) + tempd
2299  wd(i+1, j, k, ivz) = wd(i+1, j, k, ivz) + tempd
2300  wd(i, j, k+1, ivz) = wd(i, j, k+1, ivz) + tempd
2301  wd(i+1, j, k+1, ivz) = wd(i+1, j, k+1, ivz) + tempd
2302  tempd = fourth*vbard
2303  wd(i, j, k, ivy) = wd(i, j, k, ivy) + tempd
2304  wd(i+1, j, k, ivy) = wd(i+1, j, k, ivy) + tempd
2305  wd(i, j, k+1, ivy) = wd(i, j, k+1, ivy) + tempd
2306  wd(i+1, j, k+1, ivy) = wd(i+1, j, k+1, ivy) + tempd
2307  tempd = fourth*ubard
2308  wd(i, j, k, ivx) = wd(i, j, k, ivx) + tempd
2309  wd(i+1, j, k, ivx) = wd(i+1, j, k, ivx) + tempd
2310  wd(i, j, k+1, ivx) = wd(i, j, k+1, ivx) + tempd
2311  wd(i+1, j, k+1, ivx) = wd(i+1, j, k+1, ivx) + tempd
2312  sjd(i, j-1, k, 3) = sjd(i, j-1, k, 3) + szd
2313  sjd(i+1, j-1, k, 3) = sjd(i+1, j-1, k, 3) + szd
2314  sjd(i, j-1, k+1, 3) = sjd(i, j-1, k+1, 3) + szd
2315  sjd(i+1, j-1, k+1, 3) = sjd(i+1, j-1, k+1, 3) + szd
2316  sjd(i, j, k, 3) = sjd(i, j, k, 3) + szd
2317  sjd(i+1, j, k, 3) = sjd(i+1, j, k, 3) + szd
2318  sjd(i, j, k+1, 3) = sjd(i, j, k+1, 3) + szd
2319  sjd(i+1, j, k+1, 3) = sjd(i+1, j, k+1, 3) + szd
2320  sjd(i, j-1, k, 2) = sjd(i, j-1, k, 2) + syd
2321  sjd(i+1, j-1, k, 2) = sjd(i+1, j-1, k, 2) + syd
2322  sjd(i, j-1, k+1, 2) = sjd(i, j-1, k+1, 2) + syd
2323  sjd(i+1, j-1, k+1, 2) = sjd(i+1, j-1, k+1, 2) + syd
2324  sjd(i, j, k, 2) = sjd(i, j, k, 2) + syd
2325  sjd(i+1, j, k, 2) = sjd(i+1, j, k, 2) + syd
2326  sjd(i, j, k+1, 2) = sjd(i, j, k+1, 2) + syd
2327  sjd(i+1, j, k+1, 2) = sjd(i+1, j, k+1, 2) + syd
2328  sjd(i, j-1, k, 1) = sjd(i, j-1, k, 1) + sxd
2329  sjd(i+1, j-1, k, 1) = sjd(i+1, j-1, k, 1) + sxd
2330  sjd(i, j-1, k+1, 1) = sjd(i, j-1, k+1, 1) + sxd
2331  sjd(i+1, j-1, k+1, 1) = sjd(i+1, j-1, k+1, 1) + sxd
2332  sjd(i, j, k, 1) = sjd(i, j, k, 1) + sxd
2333  sjd(i+1, j, k, 1) = sjd(i+1, j, k, 1) + sxd
2334  sjd(i, j, k+1, 1) = sjd(i, j, k+1, 1) + sxd
2335  sjd(i+1, j, k+1, 1) = sjd(i+1, j, k+1, 1) + sxd
2336  end do
2337 !$bwd-of ii-loop
2338  do ii=0,il*jl*ke-1
2339  i = mod(ii, il) + 1
2340  j = mod(ii/il, jl) + 1
2341  k = ii/(il*jl) + 1
2342 ! compute 8 times the average normal for this part of
2343 ! the control volume. the factor 8 is taken care of later
2344 ! on when the division by the volume takes place.
2345  sx = sk(i, j, k-1, 1) + sk(i+1, j, k-1, 1) + sk(i, j+1, k-1, 1) + &
2346 & sk(i+1, j+1, k-1, 1) + sk(i, j, k, 1) + sk(i+1, j, k, 1) + sk(i&
2347 & , j+1, k, 1) + sk(i+1, j+1, k, 1)
2348  sy = sk(i, j, k-1, 2) + sk(i+1, j, k-1, 2) + sk(i, j+1, k-1, 2) + &
2349 & sk(i+1, j+1, k-1, 2) + sk(i, j, k, 2) + sk(i+1, j, k, 2) + sk(i&
2350 & , j+1, k, 2) + sk(i+1, j+1, k, 2)
2351  sz = sk(i, j, k-1, 3) + sk(i+1, j, k-1, 3) + sk(i, j+1, k-1, 3) + &
2352 & sk(i+1, j+1, k-1, 3) + sk(i, j, k, 3) + sk(i+1, j, k, 3) + sk(i&
2353 & , j+1, k, 3) + sk(i+1, j+1, k, 3)
2354 ! compute the average velocities and speed of sound squared
2355 ! for this integration point. node that these variables are
2356 ! stored in w(ivx), w(ivy), w(ivz) and p.
2357  ubar = fourth*(w(i, j, k, ivx)+w(i+1, j, k, ivx)+w(i, j+1, k, ivx)&
2358 & +w(i+1, j+1, k, ivx))
2359  vbar = fourth*(w(i, j, k, ivy)+w(i+1, j, k, ivy)+w(i, j+1, k, ivy)&
2360 & +w(i+1, j+1, k, ivy))
2361  wbar = fourth*(w(i, j, k, ivz)+w(i+1, j, k, ivz)+w(i, j+1, k, ivz)&
2362 & +w(i+1, j+1, k, ivz))
2363  a2 = fourth*(aa(i, j, k)+aa(i+1, j, k)+aa(i, j+1, k)+aa(i+1, j+1, &
2364 & k))
2365 ! add the contributions to the surface integral to the node
2366 ! j-1 and substract it from the node j. for the heat flux it
2367 ! is reversed, because the negative of the gradient of the
2368 ! speed of sound must be computed.
2369  if (k .gt. 1) then
2370  call pushcontrol1b(0)
2371  else
2372  call pushcontrol1b(1)
2373  end if
2374  if (k .lt. ke) then
2375  a2d = sz*qzd(i, j, k) + sy*qyd(i, j, k) + sx*qxd(i, j, k)
2376  szd = a2*qzd(i, j, k) - wbar*wzd(i, j, k) - vbar*vzd(i, j, k) - &
2377 & ubar*uzd(i, j, k)
2378  syd = a2*qyd(i, j, k) - wbar*wyd(i, j, k) - vbar*vyd(i, j, k) - &
2379 & ubar*uyd(i, j, k)
2380  sxd = a2*qxd(i, j, k) - wbar*wxd(i, j, k) - vbar*vxd(i, j, k) - &
2381 & ubar*uxd(i, j, k)
2382  wbard = -(sz*wzd(i, j, k)) - sy*wyd(i, j, k) - sx*wxd(i, j, k)
2383  vbard = -(sz*vzd(i, j, k)) - sy*vyd(i, j, k) - sx*vxd(i, j, k)
2384  ubard = -(sz*uzd(i, j, k)) - sy*uyd(i, j, k) - sx*uxd(i, j, k)
2385  else
2386  wbard = 0.0_8
2387  vbard = 0.0_8
2388  ubard = 0.0_8
2389  a2d = 0.0_8
2390  sxd = 0.0_8
2391  syd = 0.0_8
2392  szd = 0.0_8
2393  end if
2394  call popcontrol1b(branch)
2395  if (branch .eq. 0) then
2396  a2d = a2d - sz*qzd(i, j, k-1) - sy*qyd(i, j, k-1) - sx*qxd(i, j&
2397 & , k-1)
2398  szd = szd + wbar*wzd(i, j, k-1) - a2*qzd(i, j, k-1) + vbar*vzd(i&
2399 & , j, k-1) + ubar*uzd(i, j, k-1)
2400  syd = syd + wbar*wyd(i, j, k-1) - a2*qyd(i, j, k-1) + vbar*vyd(i&
2401 & , j, k-1) + ubar*uyd(i, j, k-1)
2402  sxd = sxd + wbar*wxd(i, j, k-1) - a2*qxd(i, j, k-1) + vbar*vxd(i&
2403 & , j, k-1) + ubar*uxd(i, j, k-1)
2404  wbard = wbard + sz*wzd(i, j, k-1) + sy*wyd(i, j, k-1) + sx*wxd(i&
2405 & , j, k-1)
2406  vbard = vbard + sz*vzd(i, j, k-1) + sy*vyd(i, j, k-1) + sx*vxd(i&
2407 & , j, k-1)
2408  ubard = ubard + sz*uzd(i, j, k-1) + sy*uyd(i, j, k-1) + sx*uxd(i&
2409 & , j, k-1)
2410  end if
2411  tempd = fourth*a2d
2412  aad(i, j, k) = aad(i, j, k) + tempd
2413  aad(i+1, j, k) = aad(i+1, j, k) + tempd
2414  aad(i, j+1, k) = aad(i, j+1, k) + tempd
2415  aad(i+1, j+1, k) = aad(i+1, j+1, k) + tempd
2416  tempd = fourth*wbard
2417  wd(i, j, k, ivz) = wd(i, j, k, ivz) + tempd
2418  wd(i+1, j, k, ivz) = wd(i+1, j, k, ivz) + tempd
2419  wd(i, j+1, k, ivz) = wd(i, j+1, k, ivz) + tempd
2420  wd(i+1, j+1, k, ivz) = wd(i+1, j+1, k, ivz) + tempd
2421  tempd = fourth*vbard
2422  wd(i, j, k, ivy) = wd(i, j, k, ivy) + tempd
2423  wd(i+1, j, k, ivy) = wd(i+1, j, k, ivy) + tempd
2424  wd(i, j+1, k, ivy) = wd(i, j+1, k, ivy) + tempd
2425  wd(i+1, j+1, k, ivy) = wd(i+1, j+1, k, ivy) + tempd
2426  tempd = fourth*ubard
2427  wd(i, j, k, ivx) = wd(i, j, k, ivx) + tempd
2428  wd(i+1, j, k, ivx) = wd(i+1, j, k, ivx) + tempd
2429  wd(i, j+1, k, ivx) = wd(i, j+1, k, ivx) + tempd
2430  wd(i+1, j+1, k, ivx) = wd(i+1, j+1, k, ivx) + tempd
2431  skd(i, j, k-1, 3) = skd(i, j, k-1, 3) + szd
2432  skd(i+1, j, k-1, 3) = skd(i+1, j, k-1, 3) + szd
2433  skd(i, j+1, k-1, 3) = skd(i, j+1, k-1, 3) + szd
2434  skd(i+1, j+1, k-1, 3) = skd(i+1, j+1, k-1, 3) + szd
2435  skd(i, j, k, 3) = skd(i, j, k, 3) + szd
2436  skd(i+1, j, k, 3) = skd(i+1, j, k, 3) + szd
2437  skd(i, j+1, k, 3) = skd(i, j+1, k, 3) + szd
2438  skd(i+1, j+1, k, 3) = skd(i+1, j+1, k, 3) + szd
2439  skd(i, j, k-1, 2) = skd(i, j, k-1, 2) + syd
2440  skd(i+1, j, k-1, 2) = skd(i+1, j, k-1, 2) + syd
2441  skd(i, j+1, k-1, 2) = skd(i, j+1, k-1, 2) + syd
2442  skd(i+1, j+1, k-1, 2) = skd(i+1, j+1, k-1, 2) + syd
2443  skd(i, j, k, 2) = skd(i, j, k, 2) + syd
2444  skd(i+1, j, k, 2) = skd(i+1, j, k, 2) + syd
2445  skd(i, j+1, k, 2) = skd(i, j+1, k, 2) + syd
2446  skd(i+1, j+1, k, 2) = skd(i+1, j+1, k, 2) + syd
2447  skd(i, j, k-1, 1) = skd(i, j, k-1, 1) + sxd
2448  skd(i+1, j, k-1, 1) = skd(i+1, j, k-1, 1) + sxd
2449  skd(i, j+1, k-1, 1) = skd(i, j+1, k-1, 1) + sxd
2450  skd(i+1, j+1, k-1, 1) = skd(i+1, j+1, k-1, 1) + sxd
2451  skd(i, j, k, 1) = skd(i, j, k, 1) + sxd
2452  skd(i+1, j, k, 1) = skd(i+1, j, k, 1) + sxd
2453  skd(i, j+1, k, 1) = skd(i, j+1, k, 1) + sxd
2454  skd(i+1, j+1, k, 1) = skd(i+1, j+1, k, 1) + sxd
2455  end do
2456  qzd = 0.0_8
2457  qyd = 0.0_8
2458  qxd = 0.0_8
2459  wzd = 0.0_8
2460  wyd = 0.0_8
2461  wxd = 0.0_8
2462  vzd = 0.0_8
2463  vyd = 0.0_8
2464  vxd = 0.0_8
2465  uzd = 0.0_8
2466  uyd = 0.0_8
2467  uxd = 0.0_8
2468  end subroutine allnodalgradients_b
2469 
2470  subroutine allnodalgradients()
2471 !
2472 ! nodalgradients computes the nodal velocity gradients and
2473 ! minus the gradient of the speed of sound squared. the minus
2474 ! sign is present, because this is the definition of the heat
2475 ! flux. these gradients are computed for all nodes.
2476 !
2477  use constants
2478  use blockpointers
2479  implicit none
2480 ! local variables.
2481  integer(kind=inttype) :: i, j, k
2482  integer(kind=inttype) :: k1, kk
2483  integer(kind=inttype) :: istart, iend, isize, ii
2484  integer(kind=inttype) :: jstart, jend, jsize
2485  integer(kind=inttype) :: kstart, kend, ksize
2486  real(kind=realtype) :: oneoverv, ubar, vbar, wbar, a2
2487  real(kind=realtype) :: sx, sx1, sy, sy1, sz, sz1
2488  intrinsic mod
2489 ! zero all nodeal gradients:
2490  ux = zero
2491  uy = zero
2492  uz = zero
2493  vx = zero
2494  vy = zero
2495  vz = zero
2496  wx = zero
2497  wy = zero
2498  wz = zero
2499  qx = zero
2500  qy = zero
2501  qz = zero
2502 !$ad ii-loop
2503 ! first part. contribution in the k-direction.
2504 ! the contribution is scattered to both the left and right node
2505 ! in k-direction.
2506  do ii=0,il*jl*ke-1
2507  i = mod(ii, il) + 1
2508  j = mod(ii/il, jl) + 1
2509  k = ii/(il*jl) + 1
2510 ! compute 8 times the average normal for this part of
2511 ! the control volume. the factor 8 is taken care of later
2512 ! on when the division by the volume takes place.
2513  sx = sk(i, j, k-1, 1) + sk(i+1, j, k-1, 1) + sk(i, j+1, k-1, 1) + &
2514 & sk(i+1, j+1, k-1, 1) + sk(i, j, k, 1) + sk(i+1, j, k, 1) + sk(i&
2515 & , j+1, k, 1) + sk(i+1, j+1, k, 1)
2516  sy = sk(i, j, k-1, 2) + sk(i+1, j, k-1, 2) + sk(i, j+1, k-1, 2) + &
2517 & sk(i+1, j+1, k-1, 2) + sk(i, j, k, 2) + sk(i+1, j, k, 2) + sk(i&
2518 & , j+1, k, 2) + sk(i+1, j+1, k, 2)
2519  sz = sk(i, j, k-1, 3) + sk(i+1, j, k-1, 3) + sk(i, j+1, k-1, 3) + &
2520 & sk(i+1, j+1, k-1, 3) + sk(i, j, k, 3) + sk(i+1, j, k, 3) + sk(i&
2521 & , j+1, k, 3) + sk(i+1, j+1, k, 3)
2522 ! compute the average velocities and speed of sound squared
2523 ! for this integration point. node that these variables are
2524 ! stored in w(ivx), w(ivy), w(ivz) and p.
2525  ubar = fourth*(w(i, j, k, ivx)+w(i+1, j, k, ivx)+w(i, j+1, k, ivx)&
2526 & +w(i+1, j+1, k, ivx))
2527  vbar = fourth*(w(i, j, k, ivy)+w(i+1, j, k, ivy)+w(i, j+1, k, ivy)&
2528 & +w(i+1, j+1, k, ivy))
2529  wbar = fourth*(w(i, j, k, ivz)+w(i+1, j, k, ivz)+w(i, j+1, k, ivz)&
2530 & +w(i+1, j+1, k, ivz))
2531  a2 = fourth*(aa(i, j, k)+aa(i+1, j, k)+aa(i, j+1, k)+aa(i+1, j+1, &
2532 & k))
2533 ! add the contributions to the surface integral to the node
2534 ! j-1 and substract it from the node j. for the heat flux it
2535 ! is reversed, because the negative of the gradient of the
2536 ! speed of sound must be computed.
2537  if (k .gt. 1) then
2538  ux(i, j, k-1) = ux(i, j, k-1) + ubar*sx
2539  uy(i, j, k-1) = uy(i, j, k-1) + ubar*sy
2540  uz(i, j, k-1) = uz(i, j, k-1) + ubar*sz
2541  vx(i, j, k-1) = vx(i, j, k-1) + vbar*sx
2542  vy(i, j, k-1) = vy(i, j, k-1) + vbar*sy
2543  vz(i, j, k-1) = vz(i, j, k-1) + vbar*sz
2544  wx(i, j, k-1) = wx(i, j, k-1) + wbar*sx
2545  wy(i, j, k-1) = wy(i, j, k-1) + wbar*sy
2546  wz(i, j, k-1) = wz(i, j, k-1) + wbar*sz
2547  qx(i, j, k-1) = qx(i, j, k-1) - a2*sx
2548  qy(i, j, k-1) = qy(i, j, k-1) - a2*sy
2549  qz(i, j, k-1) = qz(i, j, k-1) - a2*sz
2550  end if
2551  if (k .lt. ke) then
2552  ux(i, j, k) = ux(i, j, k) - ubar*sx
2553  uy(i, j, k) = uy(i, j, k) - ubar*sy
2554  uz(i, j, k) = uz(i, j, k) - ubar*sz
2555  vx(i, j, k) = vx(i, j, k) - vbar*sx
2556  vy(i, j, k) = vy(i, j, k) - vbar*sy
2557  vz(i, j, k) = vz(i, j, k) - vbar*sz
2558  wx(i, j, k) = wx(i, j, k) - wbar*sx
2559  wy(i, j, k) = wy(i, j, k) - wbar*sy
2560  wz(i, j, k) = wz(i, j, k) - wbar*sz
2561  qx(i, j, k) = qx(i, j, k) + a2*sx
2562  qy(i, j, k) = qy(i, j, k) + a2*sy
2563  qz(i, j, k) = qz(i, j, k) + a2*sz
2564  end if
2565  end do
2566 !$ad ii-loop
2567 ! second part. contribution in the j-direction.
2568 ! the contribution is scattered to both the left and right node
2569 ! in j-direction.
2570  do ii=0,il*je*kl-1
2571  i = mod(ii, il) + 1
2572  j = mod(ii/il, je) + 1
2573  k = ii/(il*je) + 1
2574 ! compute 8 times the average normal for this part of
2575 ! the control volume. the factor 8 is taken care of later
2576 ! on when the division by the volume takes place.
2577  sx = sj(i, j-1, k, 1) + sj(i+1, j-1, k, 1) + sj(i, j-1, k+1, 1) + &
2578 & sj(i+1, j-1, k+1, 1) + sj(i, j, k, 1) + sj(i+1, j, k, 1) + sj(i&
2579 & , j, k+1, 1) + sj(i+1, j, k+1, 1)
2580  sy = sj(i, j-1, k, 2) + sj(i+1, j-1, k, 2) + sj(i, j-1, k+1, 2) + &
2581 & sj(i+1, j-1, k+1, 2) + sj(i, j, k, 2) + sj(i+1, j, k, 2) + sj(i&
2582 & , j, k+1, 2) + sj(i+1, j, k+1, 2)
2583  sz = sj(i, j-1, k, 3) + sj(i+1, j-1, k, 3) + sj(i, j-1, k+1, 3) + &
2584 & sj(i+1, j-1, k+1, 3) + sj(i, j, k, 3) + sj(i+1, j, k, 3) + sj(i&
2585 & , j, k+1, 3) + sj(i+1, j, k+1, 3)
2586 ! compute the average velocities and speed of sound squared
2587 ! for this integration point. node that these variables are
2588 ! stored in w(ivx), w(ivy), w(ivz) and p.
2589  ubar = fourth*(w(i, j, k, ivx)+w(i+1, j, k, ivx)+w(i, j, k+1, ivx)&
2590 & +w(i+1, j, k+1, ivx))
2591  vbar = fourth*(w(i, j, k, ivy)+w(i+1, j, k, ivy)+w(i, j, k+1, ivy)&
2592 & +w(i+1, j, k+1, ivy))
2593  wbar = fourth*(w(i, j, k, ivz)+w(i+1, j, k, ivz)+w(i, j, k+1, ivz)&
2594 & +w(i+1, j, k+1, ivz))
2595  a2 = fourth*(aa(i, j, k)+aa(i+1, j, k)+aa(i, j, k+1)+aa(i+1, j, k+&
2596 & 1))
2597 ! add the contributions to the surface integral to the node
2598 ! j-1 and substract it from the node j. for the heat flux it
2599 ! is reversed, because the negative of the gradient of the
2600 ! speed of sound must be computed.
2601  if (j .gt. 1) then
2602  ux(i, j-1, k) = ux(i, j-1, k) + ubar*sx
2603  uy(i, j-1, k) = uy(i, j-1, k) + ubar*sy
2604  uz(i, j-1, k) = uz(i, j-1, k) + ubar*sz
2605  vx(i, j-1, k) = vx(i, j-1, k) + vbar*sx
2606  vy(i, j-1, k) = vy(i, j-1, k) + vbar*sy
2607  vz(i, j-1, k) = vz(i, j-1, k) + vbar*sz
2608  wx(i, j-1, k) = wx(i, j-1, k) + wbar*sx
2609  wy(i, j-1, k) = wy(i, j-1, k) + wbar*sy
2610  wz(i, j-1, k) = wz(i, j-1, k) + wbar*sz
2611  qx(i, j-1, k) = qx(i, j-1, k) - a2*sx
2612  qy(i, j-1, k) = qy(i, j-1, k) - a2*sy
2613  qz(i, j-1, k) = qz(i, j-1, k) - a2*sz
2614  end if
2615  if (j .lt. je) then
2616  ux(i, j, k) = ux(i, j, k) - ubar*sx
2617  uy(i, j, k) = uy(i, j, k) - ubar*sy
2618  uz(i, j, k) = uz(i, j, k) - ubar*sz
2619  vx(i, j, k) = vx(i, j, k) - vbar*sx
2620  vy(i, j, k) = vy(i, j, k) - vbar*sy
2621  vz(i, j, k) = vz(i, j, k) - vbar*sz
2622  wx(i, j, k) = wx(i, j, k) - wbar*sx
2623  wy(i, j, k) = wy(i, j, k) - wbar*sy
2624  wz(i, j, k) = wz(i, j, k) - wbar*sz
2625  qx(i, j, k) = qx(i, j, k) + a2*sx
2626  qy(i, j, k) = qy(i, j, k) + a2*sy
2627  qz(i, j, k) = qz(i, j, k) + a2*sz
2628  end if
2629  end do
2630 !$ad ii-loop
2631 ! third part. contribution in the i-direction.
2632 ! the contribution is scattered to both the left and right node
2633 ! in i-direction.
2634  do ii=0,ie*jl*kl-1
2635  i = mod(ii, ie) + 1
2636  j = mod(ii/ie, jl) + 1
2637  k = ii/(ie*jl) + 1
2638 ! compute 8 times the average normal for this part of
2639 ! the control volume. the factor 8 is taken care of later
2640 ! on when the division by the volume takes place.
2641  sx = si(i-1, j, k, 1) + si(i-1, j+1, k, 1) + si(i-1, j, k+1, 1) + &
2642 & si(i-1, j+1, k+1, 1) + si(i, j, k, 1) + si(i, j+1, k, 1) + si(i&
2643 & , j, k+1, 1) + si(i, j+1, k+1, 1)
2644  sy = si(i-1, j, k, 2) + si(i-1, j+1, k, 2) + si(i-1, j, k+1, 2) + &
2645 & si(i-1, j+1, k+1, 2) + si(i, j, k, 2) + si(i, j+1, k, 2) + si(i&
2646 & , j, k+1, 2) + si(i, j+1, k+1, 2)
2647  sz = si(i-1, j, k, 3) + si(i-1, j+1, k, 3) + si(i-1, j, k+1, 3) + &
2648 & si(i-1, j+1, k+1, 3) + si(i, j, k, 3) + si(i, j+1, k, 3) + si(i&
2649 & , j, k+1, 3) + si(i, j+1, k+1, 3)
2650 ! compute the average velocities and speed of sound squared
2651 ! for this integration point. node that these variables are
2652 ! stored in w(ivx), w(ivy), w(ivz) and p.
2653  ubar = fourth*(w(i, j, k, ivx)+w(i, j+1, k, ivx)+w(i, j, k+1, ivx)&
2654 & +w(i, j+1, k+1, ivx))
2655  vbar = fourth*(w(i, j, k, ivy)+w(i, j+1, k, ivy)+w(i, j, k+1, ivy)&
2656 & +w(i, j+1, k+1, ivy))
2657  wbar = fourth*(w(i, j, k, ivz)+w(i, j+1, k, ivz)+w(i, j, k+1, ivz)&
2658 & +w(i, j+1, k+1, ivz))
2659  a2 = fourth*(aa(i, j, k)+aa(i, j+1, k)+aa(i, j, k+1)+aa(i, j+1, k+&
2660 & 1))
2661 ! add the contributions to the surface integral to the node
2662 ! j-1 and substract it from the node j. for the heat flux it
2663 ! is reversed, because the negative of the gradient of the
2664 ! speed of sound must be computed.
2665  if (i .gt. 1) then
2666  ux(i-1, j, k) = ux(i-1, j, k) + ubar*sx
2667  uy(i-1, j, k) = uy(i-1, j, k) + ubar*sy
2668  uz(i-1, j, k) = uz(i-1, j, k) + ubar*sz
2669  vx(i-1, j, k) = vx(i-1, j, k) + vbar*sx
2670  vy(i-1, j, k) = vy(i-1, j, k) + vbar*sy
2671  vz(i-1, j, k) = vz(i-1, j, k) + vbar*sz
2672  wx(i-1, j, k) = wx(i-1, j, k) + wbar*sx
2673  wy(i-1, j, k) = wy(i-1, j, k) + wbar*sy
2674  wz(i-1, j, k) = wz(i-1, j, k) + wbar*sz
2675  qx(i-1, j, k) = qx(i-1, j, k) - a2*sx
2676  qy(i-1, j, k) = qy(i-1, j, k) - a2*sy
2677  qz(i-1, j, k) = qz(i-1, j, k) - a2*sz
2678  end if
2679  if (i .lt. ie) then
2680  ux(i, j, k) = ux(i, j, k) - ubar*sx
2681  uy(i, j, k) = uy(i, j, k) - ubar*sy
2682  uz(i, j, k) = uz(i, j, k) - ubar*sz
2683  vx(i, j, k) = vx(i, j, k) - vbar*sx
2684  vy(i, j, k) = vy(i, j, k) - vbar*sy
2685  vz(i, j, k) = vz(i, j, k) - vbar*sz
2686  wx(i, j, k) = wx(i, j, k) - wbar*sx
2687  wy(i, j, k) = wy(i, j, k) - wbar*sy
2688  wz(i, j, k) = wz(i, j, k) - wbar*sz
2689  qx(i, j, k) = qx(i, j, k) + a2*sx
2690  qy(i, j, k) = qy(i, j, k) + a2*sy
2691  qz(i, j, k) = qz(i, j, k) + a2*sz
2692  end if
2693  end do
2694 !$ad ii-loop
2695 ! divide by 8 times the volume to obtain the correct gradients.
2696  do ii=0,il*jl*kl-1
2697  i = mod(ii, il) + 1
2698  j = mod(ii/il, jl) + 1
2699  k = ii/(il*jl) + 1
2700 ! compute the inverse of 8 times the volume for this node.
2701  oneoverv = one/(vol(i, j, k)+vol(i, j, k+1)+vol(i+1, j, k)+vol(i+1&
2702 & , j, k+1)+vol(i, j+1, k)+vol(i, j+1, k+1)+vol(i+1, j+1, k)+vol(i&
2703 & +1, j+1, k+1))
2704 ! compute the correct velocity gradients and "unit" heat
2705 ! fluxes. the velocity gradients are stored in ux, etc.
2706  ux(i, j, k) = ux(i, j, k)*oneoverv
2707  uy(i, j, k) = uy(i, j, k)*oneoverv
2708  uz(i, j, k) = uz(i, j, k)*oneoverv
2709  vx(i, j, k) = vx(i, j, k)*oneoverv
2710  vy(i, j, k) = vy(i, j, k)*oneoverv
2711  vz(i, j, k) = vz(i, j, k)*oneoverv
2712  wx(i, j, k) = wx(i, j, k)*oneoverv
2713  wy(i, j, k) = wy(i, j, k)*oneoverv
2714  wz(i, j, k) = wz(i, j, k)*oneoverv
2715  qx(i, j, k) = qx(i, j, k)*oneoverv
2716  qy(i, j, k) = qy(i, j, k)*oneoverv
2717  qz(i, j, k) = qz(i, j, k)*oneoverv
2718  end do
2719  end subroutine allnodalgradients
2720 ! ----------------------------------------------------------------------
2721 ! |
2722 ! no tapenade routine below this line |
2723 ! |
2724 ! ----------------------------------------------------------------------
2725 
2726 end module flowutils_b
2727 
real(kind=realtype), dimension(:, :, :), pointer gamma
real(kind=realtype), dimension(:, :, :), pointer qz
integer(kind=inttype) jl
real(kind=realtype), dimension(:, :, :), pointer wzd
real(kind=realtype), dimension(:, :, :), pointer aad
real(kind=realtype), dimension(:, :, :, :), pointer sjd
real(kind=realtype), dimension(:, :, :), pointer vxd
real(kind=realtype), dimension(:, :, :), pointer qy
real(kind=realtype), dimension(:, :, :), pointer aa
real(kind=realtype), dimension(:, :, :), pointer uz
real(kind=realtype), dimension(:, :, :, :), pointer wd
real(kind=realtype), dimension(:, :, :), pointer uzd
real(kind=realtype), dimension(:, :, :), pointer vold
real(kind=realtype), dimension(:, :, :), pointer qxd
real(kind=realtype), dimension(:, :, :), pointer p
integer(kind=inttype) ie
real(kind=realtype), dimension(:, :, :, :), pointer w
real(kind=realtype), dimension(:, :, :), pointer uy
real(kind=realtype), dimension(:, :, :), pointer wyd
real(kind=realtype), dimension(:, :, :), pointer wx
real(kind=realtype), dimension(:, :, :, :), pointer skd
integer(kind=inttype) jb
integer(kind=inttype) kb
real(kind=realtype), dimension(:, :, :), pointer rlv
real(kind=realtype), dimension(:, :, :, :), pointer si
real(kind=realtype), dimension(:, :, :, :), pointer sid
real(kind=realtype), dimension(:, :, :, :), pointer sj
real(kind=realtype), dimension(:, :, :), pointer uyd
real(kind=realtype), dimension(:, :, :), pointer qx
real(kind=realtype), dimension(:, :, :), pointer uxd
real(kind=realtype), dimension(:, :, :), pointer vz
real(kind=realtype), dimension(:, :, :), pointer qyd
real(kind=realtype), dimension(:, :, :, :), pointer sk
real(kind=realtype), dimension(:, :, :), pointer ux
real(kind=realtype), dimension(:, :, :), pointer wy
real(kind=realtype), dimension(:, :, :), pointer rlvd
real(kind=realtype), dimension(:, :, :), pointer wz
real(kind=realtype), dimension(:, :, :), pointer vol
real(kind=realtype), dimension(:, :, :), pointer wxd
integer(kind=inttype) ib
real(kind=realtype), dimension(:, :, :), pointer vy
real(kind=realtype), dimension(:, :, :), pointer vx
integer(kind=inttype) je
integer(kind=inttype) ke
real(kind=realtype), dimension(:, :, :), pointer qzd
real(kind=realtype), dimension(:, :, :), pointer vzd
real(kind=realtype), dimension(:, :, :), pointer pd
real(kind=realtype), dimension(:, :, :), pointer vyd
integer(kind=inttype) kl
integer(kind=inttype) il
integer(kind=inttype), parameter cptempcurvefits
Definition: constants.F90:124
real(kind=realtype), parameter zero
Definition: constants.F90:71
real(kind=realtype), parameter third
Definition: constants.F90:81
integer, parameter itu1
Definition: constants.F90:40
integer, parameter irho
Definition: constants.F90:34
integer, parameter ivx
Definition: constants.F90:35
integer, parameter irhoe
Definition: constants.F90:38
real(kind=realtype), parameter five
Definition: constants.F90:76
real(kind=realtype), parameter one
Definition: constants.F90:72
real(kind=realtype), parameter half
Definition: constants.F90:80
integer, parameter ivz
Definition: constants.F90:37
real(kind=realtype), parameter two
Definition: constants.F90:73
integer(kind=inttype), parameter cpconstant
Definition: constants.F90:124
real(kind=realtype), parameter fourth
Definition: constants.F90:82
integer, parameter ivy
Definition: constants.F90:36
real(kind=realtype) cvn
Definition: CpCurveFits.f90:58
real(kind=realtype), dimension(:), allocatable cptrange
Definition: CpCurveFits.f90:46
integer(kind=inttype) cpnparts
Definition: CpCurveFits.f90:44
real(kind=realtype) cv0
Definition: CpCurveFits.f90:58
type(cptempfittype), dimension(:), allocatable cptempfit
Definition: CpCurveFits.f90:49
real(kind=realtype), dimension(:), allocatable cpeint
Definition: CpCurveFits.f90:47
subroutine computeptot(rho, u, v, w, p, ptot)
subroutine eint_b(rho, rhod, p, pd, k, kd, einternal, einternald, correctfork)
subroutine computeptot_b(rho, rhod, u, ud, v, vd, w, wd, p, pd, ptot, ptotd)
subroutine computelamviscosity(includehalos)
subroutine computelamviscosity_b(includehalos)
subroutine computepressuresimple_b(includehalos)
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 computepressuresimple(includehalos)
subroutine computespeedofsoundsquared()
subroutine vectorrotation(xp, yp, zp, iaxis, angle, x, y, z)
subroutine computepressure(ibeg, iend, jbeg, jend, kbeg, kend, pointeroffset)
subroutine derivativerotmatrixrigid(rotationmatrix, rotationpoint, t)
subroutine getdirvector(refdirection, alpha, beta, winddirection, liftindex)
subroutine adjustinflowangle_b()
subroutine eint(rho, p, k, einternal, correctfork)
subroutine computespeedofsoundsquared_b()
subroutine adjustinflowangle()
subroutine computettot(rho, u, v, w, p, ttot)
Definition: flowUtils_b.f90:66
subroutine allnodalgradients()
subroutine vectorrotation_b(xp, xpd, yp, ypd, zp, zpd, iaxis, angle, angled, x, xd, y, yd, z, zd)
subroutine allnodalgradients_b()
subroutine derivativerotmatrixrigid_b(rotationmatrix, rotationmatrixd, rotationpoint, t)
subroutine computeetotblock_b(istart, iend, jstart, jend, kstart, kend, correctfork)
subroutine computegamma(t, gamma, mm)
subroutine computeetotblock(istart, iend, jstart, jend, kstart, kend, correctfork)
subroutine getdirvector_b(refdirection, alpha, alphad, beta, betad, winddirection, winddirectiond, liftindex)
subroutine computettot_b(rho, rhod, u, ud, v, vd, w, wd, p, pd, ttot, ttotd)
Definition: flowUtils_b.f90:13
real(kind=realtype) gammainf
real(kind=realtype) pinfcorr
real(kind=realtype) pinfcorrd
real(kind=realtype) pinf
real(kind=realtype) rgas
real(kind=realtype) trefd
real(kind=realtype) muref
real(kind=realtype) rgasd
real(kind=realtype) tref
real(kind=realtype) murefd
real(kind=realtype) lref
integer(kind=inttype) degreefouryrot
Definition: inputParam.F90:354
integer(kind=inttype) degreefourxrot
Definition: inputParam.F90:353
integer(kind=inttype) degreepolxrot
Definition: inputParam.F90:337
real(kind=realtype) omegafouryrot
Definition: inputParam.F90:363
integer(kind=inttype) degreepolyrot
Definition: inputParam.F90:338
real(kind=realtype), dimension(:), allocatable coefpolxrot
Definition: inputParam.F90:345
real(kind=realtype) omegafourzrot
Definition: inputParam.F90:364
real(kind=realtype) omegafourxrot
Definition: inputParam.F90:362
real(kind=realtype), dimension(:), allocatable sincoeffouryrot
Definition: inputParam.F90:385
real(kind=realtype), dimension(:), allocatable coscoeffourxrot
Definition: inputParam.F90:373
real(kind=realtype), dimension(:), allocatable sincoeffourzrot
Definition: inputParam.F90:386
integer(kind=inttype) degreepolzrot
Definition: inputParam.F90:339
real(kind=realtype), dimension(:), allocatable coscoeffouryrot
Definition: inputParam.F90:374
integer(kind=inttype) degreefourzrot
Definition: inputParam.F90:355
real(kind=realtype), dimension(:), allocatable coefpolzrot
Definition: inputParam.F90:347
real(kind=realtype), dimension(:), allocatable coefpolyrot
Definition: inputParam.F90:346
real(kind=realtype), dimension(3) rotpoint
Definition: inputParam.F90:330
real(kind=realtype), dimension(:), allocatable coscoeffourzrot
Definition: inputParam.F90:375
real(kind=realtype), dimension(:), allocatable sincoeffourxrot
Definition: inputParam.F90:384
real(kind=realtype) ssuthdim
Definition: inputParam.F90:604
real(kind=realtype) gammaconstant
Definition: inputParam.F90:595
real(kind=realtype) betad
Definition: inputParam.F90:612
real(kind=realtype) tsuthdim
Definition: inputParam.F90:604
real(kind=realtype), dimension(3) liftdirectiond
Definition: inputParam.F90:614
real(kind=realtype), dimension(3) dragdirectiond
Definition: inputParam.F90:615
integer(kind=inttype) liftindex
Definition: inputParam.F90:592
real(kind=realtype), dimension(3) dragdirection
Definition: inputParam.F90:601
real(kind=realtype), dimension(3) veldirfreestreamd
Definition: inputParam.F90:613
real(kind=realtype) alphad
Definition: inputParam.F90:612
real(kind=realtype) beta
Definition: inputParam.F90:591
real(kind=realtype), dimension(3) liftdirection
Definition: inputParam.F90:600
integer(kind=inttype) cpmodel
Definition: inputParam.F90:584
real(kind=realtype), dimension(3) veldirfreestream
Definition: inputParam.F90:599
real(kind=realtype) musuthdim
Definition: inputParam.F90:604
real(kind=realtype) alpha
Definition: inputParam.F90:591
integer, parameter realtype
Definition: precision.F90:112
real(kind=realtype) function derivativerigidrotangle(degreepolrot, coefpolrot, degreefourrot, omegafourrot, coscoeffourrot, sincoeffourrot, t)
Definition: utils_b.f90:402
logical function getcorrectfork()
Definition: utils_b.f90:480
subroutine terminate(routinename, errormessage)
Definition: utils_b.f90:493
subroutine derivativerigidrotangle_b(degreepolrot, coefpolrot, degreefourrot, omegafourrot, coscoeffourrot, sincoeffourrot, t, derivativerigidrotangled)
Definition: utils_b.f90:352
real(kind=realtype) function rigidrotangle(degreepolrot, coefpolrot, degreefourrot, omegafourrot, coscoeffourrot, sincoeffourrot, t)
Definition: utils_b.f90:666