ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
flowUtils_fast_b.f90
Go to the documentation of this file.
1 ! generated by tapenade (inria, ecuador team)
2 ! tapenade 3.16 (develop) - 22 aug 2023 15:51
3 !
5  implicit none
6 
7 contains
8  subroutine computettot(rho, u, v, w, p, ttot)
9 !
10 ! computettot computes the total temperature for the given
11 ! pressures, densities and velocities.
12 !
13  use constants
14  use inputphysics, only : cpmodel
15  use flowvarrefstate, only : rgas, gammainf
16  use utils_fast_b, only : terminate
17  implicit none
18 !
19 ! subroutine arguments.
20 !
21  real(kind=realtype), intent(in) :: rho, p, u, v, w
22  real(kind=realtype), intent(out) :: ttot
23 !
24 ! local variables.
25 !
26  integer(kind=inttype) :: i
27  real(kind=realtype) :: govgm1, t, kin
28 ! determine the cp model used.
29  select case (cpmodel)
30  case (cpconstant)
31 ! constant cp and thus constant gamma. the well-known
32 ! formula is valid.
33  govgm1 = gammainf/(gammainf-one)
34  t = p/(rho*rgas)
35  kin = half*(u*u+v*v+w*w)
36  ttot = t*(one+rho*kin/(govgm1*p))
37 !===============================================================
38  case (cptempcurvefits)
39 ! cp is a function of the temperature. the formula used for
40 ! constant cp is not valid anymore and a more complicated
41 ! procedure must be followed.
42  call terminate('computettot', &
43 & 'variable cp formulation not implemented yet')
44  end select
45  end subroutine computettot
46 
47  subroutine computegamma(t, gamma, mm)
48 !
49 ! computegamma computes the corresponding values of gamma for
50 ! the given dimensional temperatures.
51 !
52  use constants
53  use cpcurvefits
55  implicit none
56 !
57 ! subroutine arguments.
58 !
59  integer(kind=inttype), intent(in) :: mm
60  real(kind=realtype), dimension(mm), intent(in) :: t
61  real(kind=realtype), dimension(mm), intent(out) :: gamma
62 !
63 ! local variables.
64 !
65  integer(kind=inttype) :: i, ii, nn, start
66  real(kind=realtype) :: cp, t2
67 ! determine the cp model used in the computation.
68  select case (cpmodel)
69  case (cpconstant)
70 ! constant cp and thus constant gamma. set the values.
71  do i=1,mm
72  gamma(i) = gammaconstant
73  end do
74  end select
75 ! ================================================================
76 
77  end subroutine computegamma
78 
79  subroutine computeptot(rho, u, v, w, p, ptot)
80 !
81 ! computeptot computes the total pressure for the given
82 ! pressures, densities and velocities.
83 !
84  use constants
85  use cpcurvefits
86  use flowvarrefstate, only : tref, rgas, gammainf
87  use inputphysics, only : cpmodel
88  implicit none
89  real(kind=realtype), intent(in) :: rho, p, u, v, w
90  real(kind=realtype), intent(out) :: ptot
91 !
92 ! local parameters.
93 !
94  real(kind=realtype), parameter :: dtstop=0.01_realtype
95 !
96 ! local variables.
97 !
98  integer(kind=inttype) :: i, ii, mm, nn, nnt, start
99  real(kind=realtype) :: govgm1, kin
100  real(kind=realtype) :: t, t2, tt, dt, h, htot, cp, scale, alp
101  real(kind=realtype) :: intcport, intcportt, intcporttt
102 !
103 ! determine the cp model used.
104  select case (cpmodel)
105  case (cpconstant)
106 ! constant cp and thus constant gamma. the well-known
107 ! formula is valid.
108  govgm1 = gammainf/(gammainf-one)
109  kin = half*(u*u+v*v+w*w)
110  ptot = p*(one+rho*kin/(govgm1*p))**govgm1
111 !===============================================================
112  end select
113  end subroutine computeptot
114 
116 !
117 ! computespeedofsoundsquared does what it says.
118 !
119  use constants
120  use blockpointers, only : ie, je, ke, w, p, aa, gamma
121  use utils_fast_b, only : getcorrectfork
122  implicit none
123 !
124 ! local variables.
125 !
126  real(kind=realtype), parameter :: twothird=two*third
127  integer(kind=inttype) :: i, j, k, ii
128  real(kind=realtype) :: pp
129  logical :: correctfork
130  intrinsic mod
131 ! determine if we need to correct for k
132  correctfork = getcorrectfork()
133  if (correctfork) then
134 !$ad ii-loop
135  do ii=0,ie*je*ke-1
136  i = mod(ii, ie) + 1
137  j = mod(ii/ie, je) + 1
138  k = ii/(ie*je) + 1
139  pp = p(i, j, k) - twothird*w(i, j, k, irho)*w(i, j, k, itu1)
140  aa(i, j, k) = gamma(i, j, k)*pp/w(i, j, k, irho)
141  end do
142  else
143 !$ad ii-loop
144  do ii=0,ie*je*ke-1
145  i = mod(ii, ie) + 1
146  j = mod(ii/ie, je) + 1
147  k = ii/(ie*je) + 1
148  aa(i, j, k) = gamma(i, j, k)*p(i, j, k)/w(i, j, k, irho)
149  end do
150  end if
151  end subroutine computespeedofsoundsquared
152 
153  subroutine computeetotblock(istart, iend, jstart, jend, kstart, kend, &
154 & correctfork)
155 !
156 ! computeetot computes the total energy from the given density,
157 ! velocity and presssure. for a calorically and thermally
158 ! perfect gas the well-known expression is used; for only a
159 ! thermally perfect gas, cp is a function of temperature, curve
160 ! fits are used and a more complex expression is obtained.
161 ! it is assumed that the pointers in blockpointers already
162 ! point to the correct block.
163 !
164  use constants
165  use blockpointers, only : w, p
166  use flowvarrefstate, only : rgas, tref
167  use inputphysics, only : cpmodel, gammaconstant
168  implicit none
169 !
170 ! subroutine arguments.
171 !
172  integer(kind=inttype), intent(in) :: istart, iend, jstart, jend
173  integer(kind=inttype), intent(in) :: kstart, kend
174  logical, intent(in) :: correctfork
175 !
176 ! local variables.
177 !
178  integer(kind=inttype) :: i, j, k, ii, isize, jsize, ksize
179  real(kind=realtype) :: ovgm1, factk, scale
180  intrinsic mod
181 !
182 ! determine the cp model used in the computation.
183  select case (cpmodel)
184  case (cpconstant)
185 ! constant cp and thus constant gamma.
186 ! abbreviate 1/(gamma -1) a bit easier.
187  ovgm1 = one/(gammaconstant-one)
188 ! loop over the given range of the block and compute the first
189 ! step of the energy.
190  isize = iend - istart + 1
191  jsize = jend - jstart + 1
192  ksize = kend - kstart + 1
193  factk = ovgm1*(five*third-gammaconstant)
194  if (correctfork) then
195 !$ad ii-loop
196  do ii=0,isize*jsize*ksize-1
197  i = mod(ii, isize) + istart
198  j = mod(ii/isize, jsize) + jstart
199  k = ii/(isize*jsize) + kstart
200  w(i, j, k, irhoe) = ovgm1*p(i, j, k) + half*w(i, j, k, irho)*(&
201 & w(i, j, k, ivx)**2+w(i, j, k, ivy)**2+w(i, j, k, ivz)**2) - &
202 & factk*w(i, j, k, irho)*w(i, j, k, itu1)
203  end do
204  else
205 !$ad ii-loop
206  do ii=0,isize*jsize*ksize-1
207  i = mod(ii, isize) + istart
208  j = mod(ii/isize, jsize) + jstart
209  k = ii/(isize*jsize) + kstart
210  w(i, j, k, irhoe) = ovgm1*p(i, j, k) + half*w(i, j, k, irho)*(&
211 & w(i, j, k, ivx)**2+w(i, j, k, ivy)**2+w(i, j, k, ivz)**2)
212  end do
213  end if
214  end select
215  end subroutine computeetotblock
216 
217 ! differentiation of etot in reverse (adjoint) mode (with options noisize i4 dr8 r8):
218 ! gradient of useful results: k p u v w etotal rho
219 ! with respect to varying inputs: k p u v w rho
220  subroutine etot_fast_b(rho, rhod, u, ud, v, vd, w, wd, p, pd, k, kd, &
221 & etotal, etotald, correctfork)
222 !
223 ! etotarray computes the total energy from the given density,
224 ! velocity and presssure.
225 ! first the internal energy per unit mass is computed and after
226 ! that the kinetic energy is added as well the conversion to
227 ! energy per unit volume.
228 !
229  use constants
230  implicit none
231 !
232 ! subroutine arguments.
233 !
234  real(kind=realtype), intent(in) :: rho, p, k
235  real(kind=realtype) :: rhod, pd, kd
236  real(kind=realtype), intent(in) :: u, v, w
237  real(kind=realtype) :: ud, vd, wd
238  real(kind=realtype) :: etotal
239  real(kind=realtype) :: etotald
240  logical, intent(in) :: correctfork
241 !
242 ! local variables.
243 !
244  integer(kind=inttype) :: i
245  real(kind=realtype) :: tempd
246 ! compute the internal energy for unit mass.
247  call eint(rho, p, k, etotal, correctfork)
248  rhod = rhod + (etotal+half*(u**2+v**2+w**2))*etotald
249  tempd = half*rho*etotald
250  etotald = rho*etotald
251  ud = ud + 2*u*tempd
252  vd = vd + 2*v*tempd
253  wd = wd + 2*w*tempd
254  call eint_fast_b(rho, rhod, p, pd, k, kd, etotal, etotald, &
255 & correctfork)
256  end subroutine etot_fast_b
257 
258  subroutine etot(rho, u, v, w, p, k, etotal, correctfork)
259 !
260 ! etotarray computes the total energy from the given density,
261 ! velocity and presssure.
262 ! first the internal energy per unit mass is computed and after
263 ! that the kinetic energy is added as well the conversion to
264 ! energy per unit volume.
265 !
266  use constants
267  implicit none
268 !
269 ! subroutine arguments.
270 !
271  real(kind=realtype), intent(in) :: rho, p, k
272  real(kind=realtype), intent(in) :: u, v, w
273  real(kind=realtype), intent(out) :: etotal
274  logical, intent(in) :: correctfork
275 !
276 ! local variables.
277 !
278  integer(kind=inttype) :: i
279 ! compute the internal energy for unit mass.
280  call eint(rho, p, k, etotal, correctfork)
281  etotal = rho*(etotal+half*(u*u+v*v+w*w))
282  end subroutine etot
283 
284 ! differentiation of eint in reverse (adjoint) mode (with options noisize i4 dr8 r8):
285 ! gradient of useful results: k p einternal rho
286 ! with respect to varying inputs: k p rho
287 ! ==================================================================
288  subroutine eint_fast_b(rho, rhod, p, pd, k, kd, einternal, einternald&
289 & , correctfork)
290 !
291 ! eintarray computes the internal energy per unit mass from the
292 ! given density and pressure (and possibly turbulent energy)
293 ! for a calorically and thermally perfect gas the well-known
294 ! expression is used; for only a thermally perfect gas, cp is a
295 ! function of temperature, curve fits are used and a more
296 ! complex expression is obtained.
297 !
298  use constants
299  use cpcurvefits
300  use flowvarrefstate, only : rgas, tref
301  use inputphysics, only : cpmodel, gammaconstant
302  implicit none
303 !
304 ! subroutine arguments.
305 !
306  real(kind=realtype), intent(in) :: rho, p, k
307  real(kind=realtype) :: rhod, pd, kd
308  real(kind=realtype) :: einternal
309  real(kind=realtype) :: einternald
310  logical, intent(in) :: correctfork
311 !
312 ! local parameter.
313 !
314  real(kind=realtype), parameter :: twothird=two*third
315 !
316 ! local variables.
317 !
318  integer(kind=inttype) :: i, nn, mm, ii, start
319  real(kind=realtype) :: ovgm1, factk, pp, t, t2, scale
320  real(kind=realtype) :: tempd
321 ! determine the cp model used in the computation.
322  select case (cpmodel)
323  case (cpconstant)
324 ! abbreviate 1/(gamma -1) a bit easier.
325  ovgm1 = one/(gammaconstant-one)
326 ! loop over the number of elements of the array and compute
327 ! the total energy.
328 ! second step. correct the energy in case a turbulent kinetic
329 ! energy is present.
330  if (correctfork) then
331  factk = ovgm1*(five*third-gammaconstant)
332  kd = kd - factk*einternald
333  end if
334  tempd = ovgm1*einternald/rho
335  pd = pd + tempd
336  rhod = rhod - p*tempd/rho
337  end select
338  end subroutine eint_fast_b
339 
340 ! ==================================================================
341  subroutine eint(rho, p, k, einternal, correctfork)
342 !
343 ! eintarray computes the internal energy per unit mass from the
344 ! given density and pressure (and possibly turbulent energy)
345 ! for a calorically and thermally perfect gas the well-known
346 ! expression is used; for only a thermally perfect gas, cp is a
347 ! function of temperature, curve fits are used and a more
348 ! complex expression is obtained.
349 !
350  use constants
351  use cpcurvefits
352  use flowvarrefstate, only : rgas, tref
353  use inputphysics, only : cpmodel, gammaconstant
354  implicit none
355 !
356 ! subroutine arguments.
357 !
358  real(kind=realtype), intent(in) :: rho, p, k
359  real(kind=realtype), intent(out) :: einternal
360  logical, intent(in) :: correctfork
361 !
362 ! local parameter.
363 !
364  real(kind=realtype), parameter :: twothird=two*third
365 !
366 ! local variables.
367 !
368  integer(kind=inttype) :: i, nn, mm, ii, start
369  real(kind=realtype) :: ovgm1, factk, pp, t, t2, scale
370 ! determine the cp model used in the computation.
371  select case (cpmodel)
372  case (cpconstant)
373 ! abbreviate 1/(gamma -1) a bit easier.
374  ovgm1 = one/(gammaconstant-one)
375 ! loop over the number of elements of the array and compute
376 ! the total energy.
377  einternal = ovgm1*p/rho
378 ! second step. correct the energy in case a turbulent kinetic
379 ! energy is present.
380  if (correctfork) then
381  factk = ovgm1*(five*third-gammaconstant)
382  einternal = einternal - factk*k
383  end if
384  end select
385  end subroutine eint
386 
387  subroutine computepressuresimple(includehalos)
388 ! compute the pressure on a block with the pointers already set. this
389 ! routine is used by the forward mode ad code only.
390  use constants
391  use blockpointers
392  use flowvarrefstate
393  use inputphysics
394  implicit none
395 ! input parameter
396  logical, intent(in) :: includehalos
397 ! local variables
398  integer(kind=inttype) :: i, j, k, ii
399  real(kind=realtype) :: gm1, v2
400  integer(kind=inttype) :: ibeg, iend, isize, jbeg, jend, jsize, kbeg&
401 & , kend, ksize
402  intrinsic mod
403  intrinsic max
404 ! compute the pressures
405  gm1 = gammaconstant - one
406  if (includehalos) then
407  ibeg = 0
408  jbeg = 0
409  kbeg = 0
410  iend = ib
411  jend = jb
412  kend = kb
413  else
414  ibeg = 2
415  jbeg = 2
416  kbeg = 2
417  iend = il
418  jend = jl
419  kend = kl
420  end if
421  isize = iend - ibeg + 1
422  jsize = jend - jbeg + 1
423  ksize = kend - kbeg + 1
424 !$ad ii-loop
425  do ii=0,isize*jsize*ksize-1
426  i = mod(ii, isize) + ibeg
427  j = mod(ii/isize, jsize) + jbeg
428  k = ii/(isize*jsize) + kbeg
429  v2 = w(i, j, k, ivx)**2 + w(i, j, k, ivy)**2 + w(i, j, k, ivz)**2
430  p(i, j, k) = gm1*(w(i, j, k, irhoe)-half*w(i, j, k, irho)*v2)
431  if (p(i, j, k) .lt. 1.e-4_realtype*pinfcorr) then
432  p(i, j, k) = 1.e-4_realtype*pinfcorr
433  else
434  p(i, j, k) = p(i, j, k)
435  end if
436  end do
437  end subroutine computepressuresimple
438 
439  subroutine computepressure(ibeg, iend, jbeg, jend, kbeg, kend, &
440 & pointeroffset)
441 !
442 ! computepressure computes the pressure from the total energy,
443 ! density and velocities in the given cell range of the block to
444 ! which the pointers in blockpointers currently point.
445 ! it is possible to specify a possible pointer offset, because
446 ! this routine is also used when reading a restart file.
447 !
448  use constants
449  use inputphysics, only : cpmodel, gammaconstant
450  use blockpointers, only : w, p
451  use flowvarrefstate, only : kpresent, pinf, rgas, tref
452  use cpcurvefits
453  implicit none
454 !
455 ! subroutine arguments.
456 !
457  integer(kind=inttype), intent(in) :: ibeg, iend, jbeg, jend, kbeg, &
458 & kend
459  integer(kind=inttype), intent(in) :: pointeroffset
460 !
461 ! local parameters.
462 !
463  real(kind=realtype), parameter :: dtstop=0.01_realtype
464  real(kind=realtype), parameter :: twothird=two*third
465 !
466 ! local variables.
467 !
468  integer(kind=inttype) :: i, j, k, ip, jp, kp, nn, ii, start
469  real(kind=realtype) :: gm1, factk, v2, scale, e0, e
470  real(kind=realtype) :: trefinv, t, dt, t2, alp, cv
471  intrinsic max
472  intrinsic log
473  intrinsic abs
474  real(kind=realtype) :: abs0
475 ! determine the cp model used in the computation.
476  select case (cpmodel)
477  case (cpconstant)
478 ! constant cp and thus constant gamma. the relation
479 ! eint = cv*t can be used and consequently the standard
480 ! relation between pressure and internal energy is valid.
481 ! abbreviate some constants that occur in the pressure
482 ! computation.
483  gm1 = gammaconstant - one
484  factk = five*third - gammaconstant
485 ! loop over the cells. take the possible pointer
486 ! offset into account and store the pressure in the
487 ! position w(:,:,:, irhoe).
488  do k=kbeg,kend
489  kp = k + pointeroffset
490  do j=jbeg,jend
491  jp = j + pointeroffset
492  do i=ibeg,iend
493  ip = i + pointeroffset
494  v2 = w(ip, jp, kp, ivx)**2 + w(ip, jp, kp, ivy)**2 + w(ip, &
495 & jp, kp, ivz)**2
496  w(i, j, k, irhoe) = gm1*(w(ip, jp, kp, irhoe)-half*w(ip, jp&
497 & , kp, irho)*v2)
498  if (w(i, j, k, irhoe) .lt. 1.e-5_realtype*pinf) then
499  w(i, j, k, irhoe) = 1.e-5_realtype*pinf
500  else
501  w(i, j, k, irhoe) = w(i, j, k, irhoe)
502  end if
503  end do
504  end do
505  end do
506 ! correct p if a k-equation is present.
507  if (kpresent) then
508  do k=kbeg,kend
509  kp = k + pointeroffset
510  do j=jbeg,jend
511  jp = j + pointeroffset
512  do i=ibeg,iend
513  ip = i + pointeroffset
514  w(i, j, k, irhoe) = w(i, j, k, irhoe) + factk*w(ip, jp, kp&
515 & , irho)*w(ip, jp, kp, itu1)
516  end do
517  end do
518  end do
519  end if
520  case (cptempcurvefits)
521 ! ================================================================
522 ! cp as function of the temperature is given via curve fits.
523 ! store a scale factor when converting the nondimensional
524 ! energy to the units of cpeint
525  trefinv = one/tref
526  scale = tref/rgas
527 ! loop over the cells to compute the internal energy per
528 ! unit mass. this is stored in w(:,:,:,irhoe) for the moment.
529  do k=kbeg,kend
530  kp = k + pointeroffset
531  do j=jbeg,jend
532  jp = j + pointeroffset
533  do i=ibeg,iend
534  ip = i + pointeroffset
535  w(i, j, k, irhoe) = w(ip, jp, kp, irhoe)/w(ip, jp, kp, irho)
536  if (kpresent) w(i, j, k, irhoe) = w(i, j, k, irhoe) - w(ip, &
537 & jp, kp, itu1)
538  v2 = w(ip, jp, kp, ivx)**2 + w(ip, jp, kp, ivy)**2 + w(ip, &
539 & jp, kp, ivz)**2
540  w(i, j, k, irhoe) = w(i, j, k, irhoe) - half*v2
541  end do
542  end do
543  end do
544 ! newton algorithm to compute the temperature from the known
545 ! value of the internal energy.
546  do k=kbeg,kend
547  kp = k + pointeroffset
548  do j=jbeg,jend
549  jp = j + pointeroffset
550  do i=ibeg,iend
551  ip = i + pointeroffset
552 ! store the internal energy in the same dimensional
553 ! units as cpeint.
554  e0 = scale*w(i, j, k, irhoe)
555 ! take care of the exceptional cases.
556  if (e0 .le. cpeint(0)) then
557 ! energy smaller than the lowest value of the curve
558 ! fit. use extrapolation using constant cv.
559  t = trefinv*(cptrange(0)+(e0-cpeint(0))/cv0)
560  else if (e0 .ge. cpeint(cpnparts)) then
561 ! energy larger than the largest value of the curve
562 ! fit. use extrapolation using constant cv.
563  t = trefinv*(cptrange(cpnparts)+(e0-cpeint(cpnparts))/cvn)
564  else
565 ! the value is in the range of the curve fits.
566 ! a newton algorithm is used to find the temperature.
567 ! first find the curve fit interval to be searched.
568  ii = cpnparts
569  start = 1
570  interval:do
571 ! next guess for the interval.
572  nn = start + ii/2
573 ! determine the situation we are having here.
574  if (e0 .gt. cpeint(nn)) then
575 ! energy is larger than the upper boundary of
576 ! the current interval. update the lower
577 ! boundary.
578  start = nn + 1
579  ii = ii - 1
580  else if (e0 .ge. cpeint(nn-1)) then
581 ! nn contains the range in which the newton algorithm
582 ! must be applied.
583 ! initial guess of the dimensional temperature.
584  alp = (cpeint(nn)-e0)/(cpeint(nn)-cpeint(nn-1))
585  t = alp*cptrange(nn-1) + (one-alp)*cptrange(nn)
586 ! the actual newton algorithm to compute the
587 ! temperature.
588  newton:do
589 ! compute the internal energy as well as the
590 ! value of cv/r for the given temperature.
591 ! cv/r = cp/r - 1.0
592  cv = -one
593 ! e = integral of cv,
594  e = cptempfit(nn)%eint0 - t
595 ! not of cp.
596  do ii=1,cptempfit(nn)%nterm
597 ! update cv.
598  t2 = t**cptempfit(nn)%exponents(ii)
599  cv = cv + cptempfit(nn)%constants(ii)*t2
600 ! update e, for which this contribution must be
601 ! integrated. take the exceptional case that the
602 ! exponent == -1 into account.
603  if (cptempfit(nn)%exponents(ii) .eq. -1_inttype) &
604 & then
605  e = e + cptempfit(nn)%constants(ii)*log(t)
606  else
607  e = e + cptempfit(nn)%constants(ii)*t2*t/(&
608 & cptempfit(nn)%exponents(ii)+1)
609  end if
610  end do
611 ! compute the update and the new temperature.
612  dt = (e0-e)/cv
613  t = t + dt
614  if (dt .ge. 0.) then
615  abs0 = dt
616  else
617  abs0 = -dt
618  end if
619 ! exit the newton loop if the update is smaller
620 ! than the threshold value.
621  if (abs0 .lt. dtstop) then
622 ! create the nondimensional temperature.
623  t = t*trefinv
624  goto 100
625  end if
626  end do newton
627  end if
628 ! this is the correct range. exit the do-loop.
629 ! modify ii for the next branch to search.
630  ii = ii/2
631  end do interval
632  end if
633 ! compute the pressure from the known temperature
634 ! and density. include the correction if a k-equation
635 ! is present.
636  100 w(i, j, k, irhoe) = w(ip, jp, kp, irho)*rgas*t
637  if (w(i, j, k, irhoe) .lt. 1.e-5_realtype*pinf) then
638  w(i, j, k, irhoe) = 1.e-5_realtype*pinf
639  else
640  w(i, j, k, irhoe) = w(i, j, k, irhoe)
641  end if
642  if (kpresent) w(i, j, k, irhoe) = w(i, j, k, irhoe) + &
643 & twothird*w(ip, jp, kp, irho)*w(ip, jp, kp, itu1)
644  end do
645  end do
646  end do
647  end select
648  end subroutine computepressure
649 
650  subroutine computelamviscosity(includehalos)
651 !
652 ! computelamviscosity computes the laminar viscosity ratio in
653 ! the owned cell centers of the given block. sutherland's law is
654 ! used. it is assumed that the pointes already point to the
655 ! correct block before entering this subroutine.
656 !
657  use blockpointers
658  use constants
659  use flowvarrefstate
660  use inputphysics
661  use iteration
662  use utils_fast_b, only : getcorrectfork
663  implicit none
664 ! input variables
665  logical, intent(in) :: includehalos
666 !
667 ! local parameter.
668 !
669  real(kind=realtype), parameter :: twothird=two*third
670 !
671 ! local variables.
672 !
673  integer(kind=inttype) :: i, j, k, ii
674  real(kind=realtype) :: musuth, tsuth, ssuth, t, pp
675  logical :: correctfork
676  integer(kind=inttype) :: ibeg, iend, isize, jbeg, jend, jsize, kbeg&
677 & , kend, ksize
678  intrinsic mod
679 ! return immediately if no laminar viscosity needs to be computed.
680  if (.not.viscous) then
681  return
682  else
683 ! determine whether or not the pressure must be corrected
684 ! for the presence of the turbulent kinetic energy.
685  correctfork = getcorrectfork()
686 ! compute the nondimensional constants in sutherland's law.
687  musuth = musuthdim/muref
688  tsuth = tsuthdim/tref
689  ssuth = ssuthdim/tref
690  if (includehalos) then
691  ibeg = 1
692  jbeg = 1
693  kbeg = 1
694  iend = ie
695  jend = je
696  kend = ke
697  else
698  ibeg = 2
699  jbeg = 2
700  kbeg = 2
701  iend = il
702  jend = jl
703  kend = kl
704  end if
705 ! substract 2/3 rho k, which is a part of the normal turbulent
706 ! stresses, in case the pressure must be corrected.
707  if (correctfork) then
708  isize = iend - ibeg + 1
709  jsize = jend - jbeg + 1
710  ksize = kend - kbeg + 1
711 !$ad ii-loop
712  do ii=0,isize*jsize*ksize-1
713  i = mod(ii, isize) + ibeg
714  j = mod(ii/isize, jsize) + jbeg
715  k = ii/(isize*jsize) + kbeg
716  pp = p(i, j, k) - twothird*w(i, j, k, irho)*w(i, j, k, itu1)
717  t = pp/(rgas*w(i, j, k, irho))
718  rlv(i, j, k) = musuth*((tsuth+ssuth)/(t+ssuth))*(t/tsuth)**&
719 & 1.5_realtype
720  end do
721  else
722 ! loop over the owned cells *and* first level halos of this
723 ! block and compute the laminar viscosity ratio.
724  isize = iend - ibeg + 1
725  jsize = jend - jbeg + 1
726  ksize = kend - kbeg + 1
727 !$ad ii-loop
728  do ii=0,isize*jsize*ksize-1
729  i = mod(ii, isize) + ibeg
730  j = mod(ii/isize, jsize) + jbeg
731  k = ii/(isize*jsize) + kbeg
732 ! compute the nondimensional temperature and the
733 ! nondimensional laminar viscosity.
734  t = p(i, j, k)/(rgas*w(i, j, k, irho))
735  rlv(i, j, k) = musuth*((tsuth+ssuth)/(t+ssuth))*(t/tsuth)**&
736 & 1.5_realtype
737  end do
738  end if
739  end if
740  end subroutine computelamviscosity
741 
742  subroutine adjustinflowangle()
743  use constants
746  implicit none
747 !local vars
748  real(kind=realtype), dimension(3) :: refdir1, refdir2
749 ! velocity direction given by the rotation of a unit vector
750 ! initially aligned along the positive x-direction (1,0,0)
751 ! 1) rotate alpha radians cw about y or z-axis
752 ! 2) rotate beta radians ccw about z or y-axis
753  refdir1(:) = zero
754  refdir1(1) = one
756 ! drag direction given by the rotation of a unit vector
757 ! initially aligned along the positive x-direction (1,0,0)
758 ! 1) rotate alpha radians cw about y or z-axis
759 ! 2) rotate beta radians ccw about z or y-axis
760  call getdirvector(refdir1, alpha, beta, dragdirection, liftindex)
761 ! lift direction given by the rotation of a unit vector
762 ! initially aligned along the positive z-direction (0,0,1)
763 ! 1) rotate alpha radians cw about y or z-axis
764 ! 2) rotate beta radians ccw about z or y-axis
765  refdir2(:) = zero
766  refdir2(liftindex) = one
767  call getdirvector(refdir2, alpha, beta, liftdirection, liftindex)
768  end subroutine adjustinflowangle
769 
770  subroutine derivativerotmatrixrigid(rotationmatrix, rotationpoint, t)
771 !
772 ! derivativerotmatrixrigid determines the derivative of the
773 ! rotation matrix at the given time for the rigid body rotation,
774 ! such that the grid velocities can be determined analytically.
775 ! also the rotation point of the current time level is
776 ! determined. this value can change due to translation of the
777 ! entire grid.
778 !
779  use constants
780  use flowvarrefstate
781  use inputmotion
782  use monitor
784  implicit none
785 !
786 ! subroutine arguments.
787 !
788  real(kind=realtype), intent(in) :: t
789  real(kind=realtype), dimension(3), intent(out) :: rotationpoint
790  real(kind=realtype), dimension(3, 3), intent(out) :: rotationmatrix
791 !
792 ! local variables.
793 !
794  integer(kind=inttype) :: i, j
795  real(kind=realtype) :: phi, dphix, dphiy, dphiz
796  real(kind=realtype) :: cosx, cosy, cosz, sinx, siny, sinz
797  real(kind=realtype), dimension(3, 3) :: dm, m
798  intrinsic sin
799  intrinsic cos
800 ! determine the rotation angle around the x-axis for the new
801 ! time level and the corresponding values of the sine and cosine.
804  sinx = sin(phi)
805  cosx = cos(phi)
806 ! idem for the y-axis.
809  siny = sin(phi)
810  cosy = cos(phi)
811 ! idem for the z-axis.
814  sinz = sin(phi)
815  cosz = cos(phi)
816 ! compute the time derivative of the rotation angles around the
817 ! x-axis, y-axis and z-axis.
820 & )
823 & )
826 & )
827 ! compute the time derivative of the rotation matrix applied to
828 ! the coordinates at t == 0.
829 ! part 1. derivative of the z-rotation matrix multiplied by the
830 ! x and y rotation matrix, i.e. dmz * my * mx
831  dm(1, 1) = -(cosy*sinz*dphiz)
832  dm(1, 2) = (-(cosx*cosz)-sinx*siny*sinz)*dphiz
833  dm(1, 3) = (sinx*cosz-cosx*siny*sinz)*dphiz
834  dm(2, 1) = cosy*cosz*dphiz
835  dm(2, 2) = (sinx*siny*cosz-cosx*sinz)*dphiz
836  dm(2, 3) = (cosx*siny*cosz+sinx*sinz)*dphiz
837  dm(3, 1) = zero
838  dm(3, 2) = zero
839  dm(3, 3) = zero
840 ! part 2: mz * dmy * mx.
841  dm(1, 1) = dm(1, 1) - siny*cosz*dphiy
842  dm(1, 2) = dm(1, 2) + sinx*cosy*cosz*dphiy
843  dm(1, 3) = dm(1, 3) + cosx*cosy*cosz*dphiy
844  dm(2, 1) = dm(2, 1) - siny*sinz*dphiy
845  dm(2, 2) = dm(2, 2) + sinx*cosy*sinz*dphiy
846  dm(2, 3) = dm(2, 3) + cosx*cosy*sinz*dphiy
847  dm(3, 1) = dm(3, 1) - cosy*dphiy
848  dm(3, 2) = dm(3, 2) - sinx*siny*dphiy
849  dm(3, 3) = dm(3, 3) - cosx*siny*dphiy
850 ! part 3: mz * my * dmx
851  dm(1, 2) = dm(1, 2) + (sinx*sinz+cosx*siny*cosz)*dphix
852  dm(1, 3) = dm(1, 3) + (cosx*sinz-sinx*siny*cosz)*dphix
853  dm(2, 2) = dm(2, 2) + (cosx*siny*sinz-sinx*cosz)*dphix
854  dm(2, 3) = dm(2, 3) - (sinx*siny*sinz+cosx*cosz)*dphix
855  dm(3, 2) = dm(3, 2) + cosx*cosy*dphix
856  dm(3, 3) = dm(3, 3) - sinx*cosy*dphix
857 ! determine the rotation matrix at t == t.
858  m(1, 1) = cosy*cosz
859  m(2, 1) = cosy*sinz
860  m(3, 1) = -siny
861  m(1, 2) = sinx*siny*cosz - cosx*sinz
862  m(2, 2) = sinx*siny*sinz + cosx*cosz
863  m(3, 2) = sinx*cosy
864  m(1, 3) = cosx*siny*cosz + sinx*sinz
865  m(2, 3) = cosx*siny*sinz - sinx*cosz
866  m(3, 3) = cosx*cosy
867 ! determine the matrix product dm * inverse(m), which will give
868 ! the derivative of the rotation matrix when applied to the
869 ! current coordinates. note that inverse(m) == transpose(m).
870  do j=1,3
871  do i=1,3
872  rotationmatrix(i, j) = dm(i, 1)*m(j, 1) + dm(i, 2)*m(j, 2) + dm(&
873 & i, 3)*m(j, 3)
874  end do
875  end do
876 ! determine the rotation point at the new time level; it is
877 ! possible that this value changes due to translation of the grid.
878 ! ainf = sqrt(gammainf*pinf/rhoinf)
879 ! rotationpoint(1) = lref*rotpoint(1) &
880 ! + machgrid(1)*ainf*t/timeref
881 ! rotationpoint(2) = lref*rotpoint(2) &
882 ! + machgrid(2)*ainf*t/timeref
883 ! rotationpoint(3) = lref*rotpoint(3) &
884 ! + machgrid(3)*ainf*t/timeref
885  rotationpoint(1) = lref*rotpoint(1)
886  rotationpoint(2) = lref*rotpoint(2)
887  rotationpoint(3) = lref*rotpoint(3)
888  end subroutine derivativerotmatrixrigid
889 
890  subroutine getdirvector(refdirection, alpha, beta, winddirection, &
891 & liftindex)
892 !(xb,yb,zb,alpha,beta,xw,yw,zw)
893 !
894 ! convert the angle of attack and side slip angle to wind axes.
895 ! the components of the wind direction vector (xw,yw,zw) are
896 ! computed given the direction angles in radians and the body
897 ! direction by performing two rotations on the original
898 ! direction vector:
899 ! 1) rotation about the zb or yb-axis: alpha clockwise (cw)
900 ! (xb,yb,zb) -> (x1,y1,z1)
901 ! 2) rotation about the yl or z1-axis: beta counter-clockwise
902 ! (ccw) (x1,y1,z1) -> (xw,yw,zw)
903 ! input arguments:
904 ! alpha = angle of attack in radians
905 ! beta = side slip angle in radians
906 ! refdirection = reference direction vector
907 ! output arguments:
908 ! winddirection = unit wind vector in body axes
909 !
910  use constants
911  use utils_fast_b, only : terminate
912  implicit none
913 !
914 ! subroutine arguments.
915 !
916  real(kind=realtype), dimension(3), intent(in) :: refdirection
917  real(kind=realtype) :: alpha, beta
918  real(kind=realtype), dimension(3), intent(out) :: winddirection
919  integer(kind=inttype) :: liftindex
920 !
921 ! local variables.
922 !
923  real(kind=realtype) :: rnorm, x1, y1, z1, xbn, ybn, zbn, xw, yw, zw
924  real(kind=realtype) :: tmp
925  intrinsic sqrt
926 ! normalize the input vector.
927  rnorm = sqrt(refdirection(1)**2 + refdirection(2)**2 + refdirection(&
928 & 3)**2)
929  xbn = refdirection(1)/rnorm
930  ybn = refdirection(2)/rnorm
931  zbn = refdirection(3)/rnorm
932 !!$ ! compute the wind direction vector.
933 !!$
934 !!$ ! 1) rotate alpha radians cw about y-axis
935 !!$ ! ( <=> rotate y-axis alpha radians ccw)
936 !!$
937 !!$ call vectorrotation(x1, y1, z1, 2, alpha, xbn, ybn, zbn)
938 !!$
939 !!$ ! 2) rotate beta radians ccw about z-axis
940 !!$ ! ( <=> rotate z-axis -beta radians ccw)
941 !!$
942 !!$ call vectorrotation(xw, yw, zw, 3, -beta, x1, y1, z1)
943  if (liftindex .eq. 2) then
944 ! compute the wind direction vector.aerosurf axes different!!
945 ! 1) rotate alpha radians cw about z-axis
946 ! ( <=> rotate z-axis alpha radians ccw)
947  tmp = -alpha
948  call vectorrotation(x1, y1, z1, 3, tmp, xbn, ybn, zbn)
949 ! 2) rotate beta radians ccw about y-axis
950 ! ( <=> rotate z-axis -beta radians ccw)
951  tmp = -beta
952  call vectorrotation(xw, yw, zw, 2, tmp, x1, y1, z1)
953  else if (liftindex .eq. 3) then
954 ! compute the wind direction vector.aerosurf axes different!!
955 ! 1) rotate alpha radians cw about z-axis
956 ! ( <=> rotate z-axis alpha radians ccw)
957  call vectorrotation(x1, y1, z1, 2, alpha, xbn, ybn, zbn)
958 ! 2) rotate beta radians ccw about y-axis
959 ! ( <=> rotate z-axis -beta radians ccw)
960  call vectorrotation(xw, yw, zw, 3, beta, x1, y1, z1)
961  else
962  call terminate('getdirvector', 'invalid lift direction')
963  end if
964  winddirection(1) = xw
965  winddirection(2) = yw
966  winddirection(3) = zw
967  end subroutine getdirvector
968 
969  subroutine vectorrotation(xp, yp, zp, iaxis, angle, x, y, z)
970 !
971 ! vectorrotation rotates a given vector with respect to a
972 ! specified axis by a given angle.
973 ! input arguments:
974 ! iaxis = rotation axis (1-x, 2-y, 3-z)
975 ! angle = rotation angle (measured ccw in radians)
976 ! x, y, z = coordinates in original system
977 ! output arguments:
978 ! xp, yp, zp = coordinates in rotated system
979 !
980  use precision
981  implicit none
982 !
983 ! subroutine arguments.
984 !
985  integer(kind=inttype), intent(in) :: iaxis
986  real(kind=realtype), intent(in) :: angle, x, y, z
987  real(kind=realtype), intent(out) :: xp, yp, zp
988  intrinsic cos
989  intrinsic sin
990 ! rotation about specified axis by specified angle
991  select case (iaxis)
992  case (1)
993 ! rotation about the x-axis
994  xp = 1.*x + 0.*y + 0.*z
995  yp = 0.*x + cos(angle)*y + sin(angle)*z
996  zp = 0.*x - sin(angle)*y + cos(angle)*z
997 ! rotation about the y-axis
998  case (2)
999  xp = cos(angle)*x + 0.*y - sin(angle)*z
1000  yp = 0.*x + 1.*y + 0.*z
1001  zp = sin(angle)*x + 0.*y + cos(angle)*z
1002 ! rotation about the z-axis
1003  case (3)
1004  xp = cos(angle)*x + sin(angle)*y + 0.*z
1005  yp = -(sin(angle)*x) + cos(angle)*y + 0.*z
1006  zp = 0.*x + 0.*y + 1.*z
1007  case default
1008  write(*, *) 'vectorrotation called with invalid arguments'
1009  stop
1010  end select
1011  end subroutine vectorrotation
1012 
1013 ! differentiation of allnodalgradients in reverse (adjoint) mode (with options noisize i4 dr8 r8):
1014 ! gradient of useful results: *aa *wx *wy *wz *w *qx *qy
1015 ! *qz *ux *uy *uz *vx *vy *vz
1016 ! with respect to varying inputs: *aa *wx *wy *wz *w *qx *qy
1017 ! *qz *ux *uy *uz *vx *vy *vz
1018 ! rw status of diff variables: *aa:incr *wx:in-out *wy:in-out
1019 ! *wz:in-out *w:incr *qx:in-out *qy:in-out *qz:in-out
1020 ! *ux:in-out *uy:in-out *uz:in-out *vx:in-out *vy:in-out
1021 ! *vz:in-out
1022 ! plus diff mem management of: aa:in wx:in wy:in wz:in w:in qx:in
1023 ! qy:in qz:in ux:in uy:in uz:in vx:in vy:in vz:in
1025 !
1026 ! nodalgradients computes the nodal velocity gradients and
1027 ! minus the gradient of the speed of sound squared. the minus
1028 ! sign is present, because this is the definition of the heat
1029 ! flux. these gradients are computed for all nodes.
1030 !
1031  use constants
1032  use blockpointers
1033  implicit none
1034 ! local variables.
1035  integer(kind=inttype) :: i, j, k
1036  integer(kind=inttype) :: k1, kk
1037  integer(kind=inttype) :: istart, iend, isize, ii
1038  integer(kind=inttype) :: jstart, jend, jsize
1039  integer(kind=inttype) :: kstart, kend, ksize
1040  real(kind=realtype) :: oneoverv, ubar, vbar, wbar, a2
1041  real(kind=realtype) :: ubard, vbard, wbard, a2d
1042  real(kind=realtype) :: sx, sx1, sy, sy1, sz, sz1
1043  intrinsic mod
1044 ! zero all nodeal gradients:
1045  real(kind=realtype) :: tempd
1046  integer :: branch
1047 !$bwd-of ii-loop
1048  do ii=0,il*jl*kl-1
1049  i = mod(ii, il) + 1
1050  j = mod(ii/il, jl) + 1
1051  k = ii/(il*jl) + 1
1052 ! compute the inverse of 8 times the volume for this node.
1053  oneoverv = one/(vol(i, j, k)+vol(i, j, k+1)+vol(i+1, j, k)+vol(i+1&
1054 & , j, k+1)+vol(i, j+1, k)+vol(i, j+1, k+1)+vol(i+1, j+1, k)+vol(i&
1055 & +1, j+1, k+1))
1056 ! compute the correct velocity gradients and "unit" heat
1057 ! fluxes. the velocity gradients are stored in ux, etc.
1058  qzd(i, j, k) = oneoverv*qzd(i, j, k)
1059  qyd(i, j, k) = oneoverv*qyd(i, j, k)
1060  qxd(i, j, k) = oneoverv*qxd(i, j, k)
1061  wzd(i, j, k) = oneoverv*wzd(i, j, k)
1062  wyd(i, j, k) = oneoverv*wyd(i, j, k)
1063  wxd(i, j, k) = oneoverv*wxd(i, j, k)
1064  vzd(i, j, k) = oneoverv*vzd(i, j, k)
1065  vyd(i, j, k) = oneoverv*vyd(i, j, k)
1066  vxd(i, j, k) = oneoverv*vxd(i, j, k)
1067  uzd(i, j, k) = oneoverv*uzd(i, j, k)
1068  uyd(i, j, k) = oneoverv*uyd(i, j, k)
1069  uxd(i, j, k) = oneoverv*uxd(i, j, k)
1070  end do
1071 !$bwd-of ii-loop
1072  do ii=0,ie*jl*kl-1
1073  i = mod(ii, ie) + 1
1074  j = mod(ii/ie, jl) + 1
1075  k = ii/(ie*jl) + 1
1076 ! compute 8 times the average normal for this part of
1077 ! the control volume. the factor 8 is taken care of later
1078 ! on when the division by the volume takes place.
1079  sx = si(i-1, j, k, 1) + si(i-1, j+1, k, 1) + si(i-1, j, k+1, 1) + &
1080 & si(i-1, j+1, k+1, 1) + si(i, j, k, 1) + si(i, j+1, k, 1) + si(i&
1081 & , j, k+1, 1) + si(i, j+1, k+1, 1)
1082  sy = si(i-1, j, k, 2) + si(i-1, j+1, k, 2) + si(i-1, j, k+1, 2) + &
1083 & si(i-1, j+1, k+1, 2) + si(i, j, k, 2) + si(i, j+1, k, 2) + si(i&
1084 & , j, k+1, 2) + si(i, j+1, k+1, 2)
1085  sz = si(i-1, j, k, 3) + si(i-1, j+1, k, 3) + si(i-1, j, k+1, 3) + &
1086 & si(i-1, j+1, k+1, 3) + si(i, j, k, 3) + si(i, j+1, k, 3) + si(i&
1087 & , j, k+1, 3) + si(i, j+1, k+1, 3)
1088 ! compute the average velocities and speed of sound squared
1089 ! for this integration point. node that these variables are
1090 ! stored in w(ivx), w(ivy), w(ivz) and p.
1091 ! add the contributions to the surface integral to the node
1092 ! j-1 and substract it from the node j. for the heat flux it
1093 ! is reversed, because the negative of the gradient of the
1094 ! speed of sound must be computed.
1095  if (i .gt. 1) then
1096 myintptr = myintptr + 1
1097  myintstack(myintptr) = 0
1098  else
1099 myintptr = myintptr + 1
1100  myintstack(myintptr) = 1
1101  end if
1102  if (i .lt. ie) then
1103  a2d = sz*qzd(i, j, k) + sy*qyd(i, j, k) + sx*qxd(i, j, k)
1104  wbard = -(sz*wzd(i, j, k)) - sy*wyd(i, j, k) - sx*wxd(i, j, k)
1105  vbard = -(sz*vzd(i, j, k)) - sy*vyd(i, j, k) - sx*vxd(i, j, k)
1106  ubard = -(sz*uzd(i, j, k)) - sy*uyd(i, j, k) - sx*uxd(i, j, k)
1107  else
1108  wbard = 0.0_8
1109  vbard = 0.0_8
1110  ubard = 0.0_8
1111  a2d = 0.0_8
1112  end if
1113 branch = myintstack(myintptr)
1114  myintptr = myintptr - 1
1115  if (branch .eq. 0) then
1116  a2d = a2d - sz*qzd(i-1, j, k) - sy*qyd(i-1, j, k) - sx*qxd(i-1, &
1117 & j, k)
1118  wbard = wbard + sz*wzd(i-1, j, k) + sy*wyd(i-1, j, k) + sx*wxd(i&
1119 & -1, j, k)
1120  vbard = vbard + sz*vzd(i-1, j, k) + sy*vyd(i-1, j, k) + sx*vxd(i&
1121 & -1, j, k)
1122  ubard = ubard + sz*uzd(i-1, j, k) + sy*uyd(i-1, j, k) + sx*uxd(i&
1123 & -1, j, k)
1124  end if
1125  tempd = fourth*a2d
1126  aad(i, j, k) = aad(i, j, k) + tempd
1127  aad(i, j+1, k) = aad(i, j+1, k) + tempd
1128  aad(i, j, k+1) = aad(i, j, k+1) + tempd
1129  aad(i, j+1, k+1) = aad(i, j+1, k+1) + tempd
1130  tempd = fourth*wbard
1131  wd(i, j, k, ivz) = wd(i, j, k, ivz) + tempd
1132  wd(i, j+1, k, ivz) = wd(i, j+1, k, ivz) + tempd
1133  wd(i, j, k+1, ivz) = wd(i, j, k+1, ivz) + tempd
1134  wd(i, j+1, k+1, ivz) = wd(i, j+1, k+1, ivz) + tempd
1135  tempd = fourth*vbard
1136  wd(i, j, k, ivy) = wd(i, j, k, ivy) + tempd
1137  wd(i, j+1, k, ivy) = wd(i, j+1, k, ivy) + tempd
1138  wd(i, j, k+1, ivy) = wd(i, j, k+1, ivy) + tempd
1139  wd(i, j+1, k+1, ivy) = wd(i, j+1, k+1, ivy) + tempd
1140  tempd = fourth*ubard
1141  wd(i, j, k, ivx) = wd(i, j, k, ivx) + tempd
1142  wd(i, j+1, k, ivx) = wd(i, j+1, k, ivx) + tempd
1143  wd(i, j, k+1, ivx) = wd(i, j, k+1, ivx) + tempd
1144  wd(i, j+1, k+1, ivx) = wd(i, j+1, k+1, ivx) + tempd
1145  end do
1146 !$bwd-of ii-loop
1147  do ii=0,il*je*kl-1
1148  i = mod(ii, il) + 1
1149  j = mod(ii/il, je) + 1
1150  k = ii/(il*je) + 1
1151 ! compute 8 times the average normal for this part of
1152 ! the control volume. the factor 8 is taken care of later
1153 ! on when the division by the volume takes place.
1154  sx = sj(i, j-1, k, 1) + sj(i+1, j-1, k, 1) + sj(i, j-1, k+1, 1) + &
1155 & sj(i+1, j-1, k+1, 1) + sj(i, j, k, 1) + sj(i+1, j, k, 1) + sj(i&
1156 & , j, k+1, 1) + sj(i+1, j, k+1, 1)
1157  sy = sj(i, j-1, k, 2) + sj(i+1, j-1, k, 2) + sj(i, j-1, k+1, 2) + &
1158 & sj(i+1, j-1, k+1, 2) + sj(i, j, k, 2) + sj(i+1, j, k, 2) + sj(i&
1159 & , j, k+1, 2) + sj(i+1, j, k+1, 2)
1160  sz = sj(i, j-1, k, 3) + sj(i+1, j-1, k, 3) + sj(i, j-1, k+1, 3) + &
1161 & sj(i+1, j-1, k+1, 3) + sj(i, j, k, 3) + sj(i+1, j, k, 3) + sj(i&
1162 & , j, k+1, 3) + sj(i+1, j, k+1, 3)
1163 ! compute the average velocities and speed of sound squared
1164 ! for this integration point. node that these variables are
1165 ! stored in w(ivx), w(ivy), w(ivz) and p.
1166 ! add the contributions to the surface integral to the node
1167 ! j-1 and substract it from the node j. for the heat flux it
1168 ! is reversed, because the negative of the gradient of the
1169 ! speed of sound must be computed.
1170  if (j .gt. 1) then
1171 myintptr = myintptr + 1
1172  myintstack(myintptr) = 0
1173  else
1174 myintptr = myintptr + 1
1175  myintstack(myintptr) = 1
1176  end if
1177  if (j .lt. je) then
1178  a2d = sz*qzd(i, j, k) + sy*qyd(i, j, k) + sx*qxd(i, j, k)
1179  wbard = -(sz*wzd(i, j, k)) - sy*wyd(i, j, k) - sx*wxd(i, j, k)
1180  vbard = -(sz*vzd(i, j, k)) - sy*vyd(i, j, k) - sx*vxd(i, j, k)
1181  ubard = -(sz*uzd(i, j, k)) - sy*uyd(i, j, k) - sx*uxd(i, j, k)
1182  else
1183  wbard = 0.0_8
1184  vbard = 0.0_8
1185  ubard = 0.0_8
1186  a2d = 0.0_8
1187  end if
1188 branch = myintstack(myintptr)
1189  myintptr = myintptr - 1
1190  if (branch .eq. 0) then
1191  a2d = a2d - sz*qzd(i, j-1, k) - sy*qyd(i, j-1, k) - sx*qxd(i, j-&
1192 & 1, k)
1193  wbard = wbard + sz*wzd(i, j-1, k) + sy*wyd(i, j-1, k) + sx*wxd(i&
1194 & , j-1, k)
1195  vbard = vbard + sz*vzd(i, j-1, k) + sy*vyd(i, j-1, k) + sx*vxd(i&
1196 & , j-1, k)
1197  ubard = ubard + sz*uzd(i, j-1, k) + sy*uyd(i, j-1, k) + sx*uxd(i&
1198 & , j-1, k)
1199  end if
1200  tempd = fourth*a2d
1201  aad(i, j, k) = aad(i, j, k) + tempd
1202  aad(i+1, j, k) = aad(i+1, j, k) + tempd
1203  aad(i, j, k+1) = aad(i, j, k+1) + tempd
1204  aad(i+1, j, k+1) = aad(i+1, j, k+1) + tempd
1205  tempd = fourth*wbard
1206  wd(i, j, k, ivz) = wd(i, j, k, ivz) + tempd
1207  wd(i+1, j, k, ivz) = wd(i+1, j, k, ivz) + tempd
1208  wd(i, j, k+1, ivz) = wd(i, j, k+1, ivz) + tempd
1209  wd(i+1, j, k+1, ivz) = wd(i+1, j, k+1, ivz) + tempd
1210  tempd = fourth*vbard
1211  wd(i, j, k, ivy) = wd(i, j, k, ivy) + tempd
1212  wd(i+1, j, k, ivy) = wd(i+1, j, k, ivy) + tempd
1213  wd(i, j, k+1, ivy) = wd(i, j, k+1, ivy) + tempd
1214  wd(i+1, j, k+1, ivy) = wd(i+1, j, k+1, ivy) + tempd
1215  tempd = fourth*ubard
1216  wd(i, j, k, ivx) = wd(i, j, k, ivx) + tempd
1217  wd(i+1, j, k, ivx) = wd(i+1, j, k, ivx) + tempd
1218  wd(i, j, k+1, ivx) = wd(i, j, k+1, ivx) + tempd
1219  wd(i+1, j, k+1, ivx) = wd(i+1, j, k+1, ivx) + tempd
1220  end do
1221 !$bwd-of ii-loop
1222  do ii=0,il*jl*ke-1
1223  i = mod(ii, il) + 1
1224  j = mod(ii/il, jl) + 1
1225  k = ii/(il*jl) + 1
1226 ! compute 8 times the average normal for this part of
1227 ! the control volume. the factor 8 is taken care of later
1228 ! on when the division by the volume takes place.
1229  sx = sk(i, j, k-1, 1) + sk(i+1, j, k-1, 1) + sk(i, j+1, k-1, 1) + &
1230 & sk(i+1, j+1, k-1, 1) + sk(i, j, k, 1) + sk(i+1, j, k, 1) + sk(i&
1231 & , j+1, k, 1) + sk(i+1, j+1, k, 1)
1232  sy = sk(i, j, k-1, 2) + sk(i+1, j, k-1, 2) + sk(i, j+1, k-1, 2) + &
1233 & sk(i+1, j+1, k-1, 2) + sk(i, j, k, 2) + sk(i+1, j, k, 2) + sk(i&
1234 & , j+1, k, 2) + sk(i+1, j+1, k, 2)
1235  sz = sk(i, j, k-1, 3) + sk(i+1, j, k-1, 3) + sk(i, j+1, k-1, 3) + &
1236 & sk(i+1, j+1, k-1, 3) + sk(i, j, k, 3) + sk(i+1, j, k, 3) + sk(i&
1237 & , j+1, k, 3) + sk(i+1, j+1, k, 3)
1238 ! compute the average velocities and speed of sound squared
1239 ! for this integration point. node that these variables are
1240 ! stored in w(ivx), w(ivy), w(ivz) and p.
1241 ! add the contributions to the surface integral to the node
1242 ! j-1 and substract it from the node j. for the heat flux it
1243 ! is reversed, because the negative of the gradient of the
1244 ! speed of sound must be computed.
1245  if (k .gt. 1) then
1246 myintptr = myintptr + 1
1247  myintstack(myintptr) = 0
1248  else
1249 myintptr = myintptr + 1
1250  myintstack(myintptr) = 1
1251  end if
1252  if (k .lt. ke) then
1253  a2d = sz*qzd(i, j, k) + sy*qyd(i, j, k) + sx*qxd(i, j, k)
1254  wbard = -(sz*wzd(i, j, k)) - sy*wyd(i, j, k) - sx*wxd(i, j, k)
1255  vbard = -(sz*vzd(i, j, k)) - sy*vyd(i, j, k) - sx*vxd(i, j, k)
1256  ubard = -(sz*uzd(i, j, k)) - sy*uyd(i, j, k) - sx*uxd(i, j, k)
1257  else
1258  wbard = 0.0_8
1259  vbard = 0.0_8
1260  ubard = 0.0_8
1261  a2d = 0.0_8
1262  end if
1263 branch = myintstack(myintptr)
1264  myintptr = myintptr - 1
1265  if (branch .eq. 0) then
1266  a2d = a2d - sz*qzd(i, j, k-1) - sy*qyd(i, j, k-1) - sx*qxd(i, j&
1267 & , k-1)
1268  wbard = wbard + sz*wzd(i, j, k-1) + sy*wyd(i, j, k-1) + sx*wxd(i&
1269 & , j, k-1)
1270  vbard = vbard + sz*vzd(i, j, k-1) + sy*vyd(i, j, k-1) + sx*vxd(i&
1271 & , j, k-1)
1272  ubard = ubard + sz*uzd(i, j, k-1) + sy*uyd(i, j, k-1) + sx*uxd(i&
1273 & , j, k-1)
1274  end if
1275  tempd = fourth*a2d
1276  aad(i, j, k) = aad(i, j, k) + tempd
1277  aad(i+1, j, k) = aad(i+1, j, k) + tempd
1278  aad(i, j+1, k) = aad(i, j+1, k) + tempd
1279  aad(i+1, j+1, k) = aad(i+1, j+1, k) + tempd
1280  tempd = fourth*wbard
1281  wd(i, j, k, ivz) = wd(i, j, k, ivz) + tempd
1282  wd(i+1, j, k, ivz) = wd(i+1, j, k, ivz) + tempd
1283  wd(i, j+1, k, ivz) = wd(i, j+1, k, ivz) + tempd
1284  wd(i+1, j+1, k, ivz) = wd(i+1, j+1, k, ivz) + tempd
1285  tempd = fourth*vbard
1286  wd(i, j, k, ivy) = wd(i, j, k, ivy) + tempd
1287  wd(i+1, j, k, ivy) = wd(i+1, j, k, ivy) + tempd
1288  wd(i, j+1, k, ivy) = wd(i, j+1, k, ivy) + tempd
1289  wd(i+1, j+1, k, ivy) = wd(i+1, j+1, k, ivy) + tempd
1290  tempd = fourth*ubard
1291  wd(i, j, k, ivx) = wd(i, j, k, ivx) + tempd
1292  wd(i+1, j, k, ivx) = wd(i+1, j, k, ivx) + tempd
1293  wd(i, j+1, k, ivx) = wd(i, j+1, k, ivx) + tempd
1294  wd(i+1, j+1, k, ivx) = wd(i+1, j+1, k, ivx) + tempd
1295  end do
1296  qzd = 0.0_8
1297  qyd = 0.0_8
1298  qxd = 0.0_8
1299  wzd = 0.0_8
1300  wyd = 0.0_8
1301  wxd = 0.0_8
1302  vzd = 0.0_8
1303  vyd = 0.0_8
1304  vxd = 0.0_8
1305  uzd = 0.0_8
1306  uyd = 0.0_8
1307  uxd = 0.0_8
1308  end subroutine allnodalgradients_fast_b
1309 
1310  subroutine allnodalgradients()
1311 !
1312 ! nodalgradients computes the nodal velocity gradients and
1313 ! minus the gradient of the speed of sound squared. the minus
1314 ! sign is present, because this is the definition of the heat
1315 ! flux. these gradients are computed for all nodes.
1316 !
1317  use constants
1318  use blockpointers
1319  implicit none
1320 ! local variables.
1321  integer(kind=inttype) :: i, j, k
1322  integer(kind=inttype) :: k1, kk
1323  integer(kind=inttype) :: istart, iend, isize, ii
1324  integer(kind=inttype) :: jstart, jend, jsize
1325  integer(kind=inttype) :: kstart, kend, ksize
1326  real(kind=realtype) :: oneoverv, ubar, vbar, wbar, a2
1327  real(kind=realtype) :: sx, sx1, sy, sy1, sz, sz1
1328  intrinsic mod
1329 ! zero all nodeal gradients:
1330  ux = zero
1331  uy = zero
1332  uz = zero
1333  vx = zero
1334  vy = zero
1335  vz = zero
1336  wx = zero
1337  wy = zero
1338  wz = zero
1339  qx = zero
1340  qy = zero
1341  qz = zero
1342 !$ad ii-loop
1343 ! first part. contribution in the k-direction.
1344 ! the contribution is scattered to both the left and right node
1345 ! in k-direction.
1346  do ii=0,il*jl*ke-1
1347  i = mod(ii, il) + 1
1348  j = mod(ii/il, jl) + 1
1349  k = ii/(il*jl) + 1
1350 ! compute 8 times the average normal for this part of
1351 ! the control volume. the factor 8 is taken care of later
1352 ! on when the division by the volume takes place.
1353  sx = sk(i, j, k-1, 1) + sk(i+1, j, k-1, 1) + sk(i, j+1, k-1, 1) + &
1354 & sk(i+1, j+1, k-1, 1) + sk(i, j, k, 1) + sk(i+1, j, k, 1) + sk(i&
1355 & , j+1, k, 1) + sk(i+1, j+1, k, 1)
1356  sy = sk(i, j, k-1, 2) + sk(i+1, j, k-1, 2) + sk(i, j+1, k-1, 2) + &
1357 & sk(i+1, j+1, k-1, 2) + sk(i, j, k, 2) + sk(i+1, j, k, 2) + sk(i&
1358 & , j+1, k, 2) + sk(i+1, j+1, k, 2)
1359  sz = sk(i, j, k-1, 3) + sk(i+1, j, k-1, 3) + sk(i, j+1, k-1, 3) + &
1360 & sk(i+1, j+1, k-1, 3) + sk(i, j, k, 3) + sk(i+1, j, k, 3) + sk(i&
1361 & , j+1, k, 3) + sk(i+1, j+1, k, 3)
1362 ! compute the average velocities and speed of sound squared
1363 ! for this integration point. node that these variables are
1364 ! stored in w(ivx), w(ivy), w(ivz) and p.
1365  ubar = fourth*(w(i, j, k, ivx)+w(i+1, j, k, ivx)+w(i, j+1, k, ivx)&
1366 & +w(i+1, j+1, k, ivx))
1367  vbar = fourth*(w(i, j, k, ivy)+w(i+1, j, k, ivy)+w(i, j+1, k, ivy)&
1368 & +w(i+1, j+1, k, ivy))
1369  wbar = fourth*(w(i, j, k, ivz)+w(i+1, j, k, ivz)+w(i, j+1, k, ivz)&
1370 & +w(i+1, j+1, k, ivz))
1371  a2 = fourth*(aa(i, j, k)+aa(i+1, j, k)+aa(i, j+1, k)+aa(i+1, j+1, &
1372 & k))
1373 ! add the contributions to the surface integral to the node
1374 ! j-1 and substract it from the node j. for the heat flux it
1375 ! is reversed, because the negative of the gradient of the
1376 ! speed of sound must be computed.
1377  if (k .gt. 1) then
1378  ux(i, j, k-1) = ux(i, j, k-1) + ubar*sx
1379  uy(i, j, k-1) = uy(i, j, k-1) + ubar*sy
1380  uz(i, j, k-1) = uz(i, j, k-1) + ubar*sz
1381  vx(i, j, k-1) = vx(i, j, k-1) + vbar*sx
1382  vy(i, j, k-1) = vy(i, j, k-1) + vbar*sy
1383  vz(i, j, k-1) = vz(i, j, k-1) + vbar*sz
1384  wx(i, j, k-1) = wx(i, j, k-1) + wbar*sx
1385  wy(i, j, k-1) = wy(i, j, k-1) + wbar*sy
1386  wz(i, j, k-1) = wz(i, j, k-1) + wbar*sz
1387  qx(i, j, k-1) = qx(i, j, k-1) - a2*sx
1388  qy(i, j, k-1) = qy(i, j, k-1) - a2*sy
1389  qz(i, j, k-1) = qz(i, j, k-1) - a2*sz
1390  end if
1391  if (k .lt. ke) then
1392  ux(i, j, k) = ux(i, j, k) - ubar*sx
1393  uy(i, j, k) = uy(i, j, k) - ubar*sy
1394  uz(i, j, k) = uz(i, j, k) - ubar*sz
1395  vx(i, j, k) = vx(i, j, k) - vbar*sx
1396  vy(i, j, k) = vy(i, j, k) - vbar*sy
1397  vz(i, j, k) = vz(i, j, k) - vbar*sz
1398  wx(i, j, k) = wx(i, j, k) - wbar*sx
1399  wy(i, j, k) = wy(i, j, k) - wbar*sy
1400  wz(i, j, k) = wz(i, j, k) - wbar*sz
1401  qx(i, j, k) = qx(i, j, k) + a2*sx
1402  qy(i, j, k) = qy(i, j, k) + a2*sy
1403  qz(i, j, k) = qz(i, j, k) + a2*sz
1404  end if
1405  end do
1406 !$ad ii-loop
1407 ! second part. contribution in the j-direction.
1408 ! the contribution is scattered to both the left and right node
1409 ! in j-direction.
1410  do ii=0,il*je*kl-1
1411  i = mod(ii, il) + 1
1412  j = mod(ii/il, je) + 1
1413  k = ii/(il*je) + 1
1414 ! compute 8 times the average normal for this part of
1415 ! the control volume. the factor 8 is taken care of later
1416 ! on when the division by the volume takes place.
1417  sx = sj(i, j-1, k, 1) + sj(i+1, j-1, k, 1) + sj(i, j-1, k+1, 1) + &
1418 & sj(i+1, j-1, k+1, 1) + sj(i, j, k, 1) + sj(i+1, j, k, 1) + sj(i&
1419 & , j, k+1, 1) + sj(i+1, j, k+1, 1)
1420  sy = sj(i, j-1, k, 2) + sj(i+1, j-1, k, 2) + sj(i, j-1, k+1, 2) + &
1421 & sj(i+1, j-1, k+1, 2) + sj(i, j, k, 2) + sj(i+1, j, k, 2) + sj(i&
1422 & , j, k+1, 2) + sj(i+1, j, k+1, 2)
1423  sz = sj(i, j-1, k, 3) + sj(i+1, j-1, k, 3) + sj(i, j-1, k+1, 3) + &
1424 & sj(i+1, j-1, k+1, 3) + sj(i, j, k, 3) + sj(i+1, j, k, 3) + sj(i&
1425 & , j, k+1, 3) + sj(i+1, j, k+1, 3)
1426 ! compute the average velocities and speed of sound squared
1427 ! for this integration point. node that these variables are
1428 ! stored in w(ivx), w(ivy), w(ivz) and p.
1429  ubar = fourth*(w(i, j, k, ivx)+w(i+1, j, k, ivx)+w(i, j, k+1, ivx)&
1430 & +w(i+1, j, k+1, ivx))
1431  vbar = fourth*(w(i, j, k, ivy)+w(i+1, j, k, ivy)+w(i, j, k+1, ivy)&
1432 & +w(i+1, j, k+1, ivy))
1433  wbar = fourth*(w(i, j, k, ivz)+w(i+1, j, k, ivz)+w(i, j, k+1, ivz)&
1434 & +w(i+1, j, k+1, ivz))
1435  a2 = fourth*(aa(i, j, k)+aa(i+1, j, k)+aa(i, j, k+1)+aa(i+1, j, k+&
1436 & 1))
1437 ! add the contributions to the surface integral to the node
1438 ! j-1 and substract it from the node j. for the heat flux it
1439 ! is reversed, because the negative of the gradient of the
1440 ! speed of sound must be computed.
1441  if (j .gt. 1) then
1442  ux(i, j-1, k) = ux(i, j-1, k) + ubar*sx
1443  uy(i, j-1, k) = uy(i, j-1, k) + ubar*sy
1444  uz(i, j-1, k) = uz(i, j-1, k) + ubar*sz
1445  vx(i, j-1, k) = vx(i, j-1, k) + vbar*sx
1446  vy(i, j-1, k) = vy(i, j-1, k) + vbar*sy
1447  vz(i, j-1, k) = vz(i, j-1, k) + vbar*sz
1448  wx(i, j-1, k) = wx(i, j-1, k) + wbar*sx
1449  wy(i, j-1, k) = wy(i, j-1, k) + wbar*sy
1450  wz(i, j-1, k) = wz(i, j-1, k) + wbar*sz
1451  qx(i, j-1, k) = qx(i, j-1, k) - a2*sx
1452  qy(i, j-1, k) = qy(i, j-1, k) - a2*sy
1453  qz(i, j-1, k) = qz(i, j-1, k) - a2*sz
1454  end if
1455  if (j .lt. je) then
1456  ux(i, j, k) = ux(i, j, k) - ubar*sx
1457  uy(i, j, k) = uy(i, j, k) - ubar*sy
1458  uz(i, j, k) = uz(i, j, k) - ubar*sz
1459  vx(i, j, k) = vx(i, j, k) - vbar*sx
1460  vy(i, j, k) = vy(i, j, k) - vbar*sy
1461  vz(i, j, k) = vz(i, j, k) - vbar*sz
1462  wx(i, j, k) = wx(i, j, k) - wbar*sx
1463  wy(i, j, k) = wy(i, j, k) - wbar*sy
1464  wz(i, j, k) = wz(i, j, k) - wbar*sz
1465  qx(i, j, k) = qx(i, j, k) + a2*sx
1466  qy(i, j, k) = qy(i, j, k) + a2*sy
1467  qz(i, j, k) = qz(i, j, k) + a2*sz
1468  end if
1469  end do
1470 !$ad ii-loop
1471 ! third part. contribution in the i-direction.
1472 ! the contribution is scattered to both the left and right node
1473 ! in i-direction.
1474  do ii=0,ie*jl*kl-1
1475  i = mod(ii, ie) + 1
1476  j = mod(ii/ie, jl) + 1
1477  k = ii/(ie*jl) + 1
1478 ! compute 8 times the average normal for this part of
1479 ! the control volume. the factor 8 is taken care of later
1480 ! on when the division by the volume takes place.
1481  sx = si(i-1, j, k, 1) + si(i-1, j+1, k, 1) + si(i-1, j, k+1, 1) + &
1482 & si(i-1, j+1, k+1, 1) + si(i, j, k, 1) + si(i, j+1, k, 1) + si(i&
1483 & , j, k+1, 1) + si(i, j+1, k+1, 1)
1484  sy = si(i-1, j, k, 2) + si(i-1, j+1, k, 2) + si(i-1, j, k+1, 2) + &
1485 & si(i-1, j+1, k+1, 2) + si(i, j, k, 2) + si(i, j+1, k, 2) + si(i&
1486 & , j, k+1, 2) + si(i, j+1, k+1, 2)
1487  sz = si(i-1, j, k, 3) + si(i-1, j+1, k, 3) + si(i-1, j, k+1, 3) + &
1488 & si(i-1, j+1, k+1, 3) + si(i, j, k, 3) + si(i, j+1, k, 3) + si(i&
1489 & , j, k+1, 3) + si(i, j+1, k+1, 3)
1490 ! compute the average velocities and speed of sound squared
1491 ! for this integration point. node that these variables are
1492 ! stored in w(ivx), w(ivy), w(ivz) and p.
1493  ubar = fourth*(w(i, j, k, ivx)+w(i, j+1, k, ivx)+w(i, j, k+1, ivx)&
1494 & +w(i, j+1, k+1, ivx))
1495  vbar = fourth*(w(i, j, k, ivy)+w(i, j+1, k, ivy)+w(i, j, k+1, ivy)&
1496 & +w(i, j+1, k+1, ivy))
1497  wbar = fourth*(w(i, j, k, ivz)+w(i, j+1, k, ivz)+w(i, j, k+1, ivz)&
1498 & +w(i, j+1, k+1, ivz))
1499  a2 = fourth*(aa(i, j, k)+aa(i, j+1, k)+aa(i, j, k+1)+aa(i, j+1, k+&
1500 & 1))
1501 ! add the contributions to the surface integral to the node
1502 ! j-1 and substract it from the node j. for the heat flux it
1503 ! is reversed, because the negative of the gradient of the
1504 ! speed of sound must be computed.
1505  if (i .gt. 1) then
1506  ux(i-1, j, k) = ux(i-1, j, k) + ubar*sx
1507  uy(i-1, j, k) = uy(i-1, j, k) + ubar*sy
1508  uz(i-1, j, k) = uz(i-1, j, k) + ubar*sz
1509  vx(i-1, j, k) = vx(i-1, j, k) + vbar*sx
1510  vy(i-1, j, k) = vy(i-1, j, k) + vbar*sy
1511  vz(i-1, j, k) = vz(i-1, j, k) + vbar*sz
1512  wx(i-1, j, k) = wx(i-1, j, k) + wbar*sx
1513  wy(i-1, j, k) = wy(i-1, j, k) + wbar*sy
1514  wz(i-1, j, k) = wz(i-1, j, k) + wbar*sz
1515  qx(i-1, j, k) = qx(i-1, j, k) - a2*sx
1516  qy(i-1, j, k) = qy(i-1, j, k) - a2*sy
1517  qz(i-1, j, k) = qz(i-1, j, k) - a2*sz
1518  end if
1519  if (i .lt. ie) then
1520  ux(i, j, k) = ux(i, j, k) - ubar*sx
1521  uy(i, j, k) = uy(i, j, k) - ubar*sy
1522  uz(i, j, k) = uz(i, j, k) - ubar*sz
1523  vx(i, j, k) = vx(i, j, k) - vbar*sx
1524  vy(i, j, k) = vy(i, j, k) - vbar*sy
1525  vz(i, j, k) = vz(i, j, k) - vbar*sz
1526  wx(i, j, k) = wx(i, j, k) - wbar*sx
1527  wy(i, j, k) = wy(i, j, k) - wbar*sy
1528  wz(i, j, k) = wz(i, j, k) - wbar*sz
1529  qx(i, j, k) = qx(i, j, k) + a2*sx
1530  qy(i, j, k) = qy(i, j, k) + a2*sy
1531  qz(i, j, k) = qz(i, j, k) + a2*sz
1532  end if
1533  end do
1534 !$ad ii-loop
1535 ! divide by 8 times the volume to obtain the correct gradients.
1536  do ii=0,il*jl*kl-1
1537  i = mod(ii, il) + 1
1538  j = mod(ii/il, jl) + 1
1539  k = ii/(il*jl) + 1
1540 ! compute the inverse of 8 times the volume for this node.
1541  oneoverv = one/(vol(i, j, k)+vol(i, j, k+1)+vol(i+1, j, k)+vol(i+1&
1542 & , j, k+1)+vol(i, j+1, k)+vol(i, j+1, k+1)+vol(i+1, j+1, k)+vol(i&
1543 & +1, j+1, k+1))
1544 ! compute the correct velocity gradients and "unit" heat
1545 ! fluxes. the velocity gradients are stored in ux, etc.
1546  ux(i, j, k) = ux(i, j, k)*oneoverv
1547  uy(i, j, k) = uy(i, j, k)*oneoverv
1548  uz(i, j, k) = uz(i, j, k)*oneoverv
1549  vx(i, j, k) = vx(i, j, k)*oneoverv
1550  vy(i, j, k) = vy(i, j, k)*oneoverv
1551  vz(i, j, k) = vz(i, j, k)*oneoverv
1552  wx(i, j, k) = wx(i, j, k)*oneoverv
1553  wy(i, j, k) = wy(i, j, k)*oneoverv
1554  wz(i, j, k) = wz(i, j, k)*oneoverv
1555  qx(i, j, k) = qx(i, j, k)*oneoverv
1556  qy(i, j, k) = qy(i, j, k)*oneoverv
1557  qz(i, j, k) = qz(i, j, k)*oneoverv
1558  end do
1559  end subroutine allnodalgradients
1560 ! ----------------------------------------------------------------------
1561 ! |
1562 ! no tapenade routine below this line |
1563 ! |
1564 ! ----------------------------------------------------------------------
1565 
1566 end module flowutils_fast_b
1567 
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 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 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
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 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 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 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(kind=inttype), dimension(32) myintstack
Definition: constants.F90:299
integer, parameter irhoe
Definition: constants.F90:38
integer(kind=inttype) myintptr
Definition: constants.F90:300
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 computepressure(ibeg, iend, jbeg, jend, kbeg, kend, pointeroffset)
subroutine etot(rho, u, v, w, p, k, etotal, correctfork)
subroutine eint_fast_b(rho, rhod, p, pd, k, kd, einternal, einternald, correctfork)
subroutine computelamviscosity(includehalos)
subroutine allnodalgradients_fast_b()
subroutine computepressuresimple(includehalos)
subroutine computeetotblock(istart, iend, jstart, jend, kstart, kend, correctfork)
subroutine adjustinflowangle()
subroutine computegamma(t, gamma, mm)
subroutine computettot(rho, u, v, w, p, ttot)
subroutine derivativerotmatrixrigid(rotationmatrix, rotationpoint, t)
subroutine computeptot(rho, u, v, w, p, ptot)
subroutine vectorrotation(xp, yp, zp, iaxis, angle, x, y, z)
subroutine allnodalgradients()
subroutine eint(rho, p, k, einternal, correctfork)
subroutine computespeedofsoundsquared()
subroutine etot_fast_b(rho, rhod, u, ud, v, vd, w, wd, p, pd, k, kd, etotal, etotald, correctfork)
subroutine getdirvector(refdirection, alpha, beta, winddirection, liftindex)
real(kind=realtype) gammainf
real(kind=realtype) pinfcorr
real(kind=realtype) pinf
real(kind=realtype) rgas
real(kind=realtype) muref
real(kind=realtype) tref
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) tsuthdim
Definition: inputParam.F90:604
integer(kind=inttype) liftindex
Definition: inputParam.F90:592
real(kind=realtype), dimension(3) dragdirection
Definition: inputParam.F90:601
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
logical function getcorrectfork()
subroutine terminate(routinename, errormessage)
real(kind=realtype) function rigidrotangle(degreepolrot, coefpolrot, degreefourrot, omegafourrot, coscoeffourrot, sincoeffourrot, t)
real(kind=realtype) function derivativerigidrotangle(degreepolrot, coefpolrot, degreefourrot, omegafourrot, coscoeffourrot, sincoeffourrot, t)