ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
blockette.F90
Go to the documentation of this file.
1 module blockette
2 
3  use constants
4  ! This temporary module contains all cache-blocked code. It also
5  ! contains the statically allocated variables on which the blocked
6  ! code operates.
7 
8  ! Dummy Block dimensions
9  integer(kind=intType), parameter :: bs = 8
10  integer(kind=intType), parameter :: bbil = bs + 1, bbjl = bs + 1, bbkl = bs + 1
11  integer(kind=intType), parameter :: bbie = bs + 2, bbje = bs + 2, bbke = bs + 2
12  integer(kind=intType), parameter :: bbib = bs + 3, bbjb = bs + 3, bbkb = bs + 3
13 
14  ! Actual dimensions to execute
15  integer(kind=intType) :: nx, ny, nz, il, jl, kl, ie, je, ke, ib, jb, kb
16 
17  ! Variables to track transferring variables between blockettes
18  integer(kind=intType) :: singlehalostart, doublehalostart, nodestart
19 
20  ! Current indices into the original block
21  integer(kind=intType) :: ii, jj, kk
22 
23  ! Double halos
24  real(kind=realtype), dimension(0:bbib, 0:bbjb, 0:bbkb, 1:6) :: w
25  real(kind=realtype), dimension(0:bbib, 0:bbjb, 0:bbkb) :: p, gamma
26  real(kind=realtype), dimension(0:bbib, 0:bbjb, 0:bbkb) :: ss ! Entropy
27 
28  ! Single halos
29  real(kind=realtype), dimension(0:bbie, 0:bbje, 0:bbke, 3) :: x
30  real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke) :: rlv, rev, vol, aa
31  real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke) :: radi, radj, radk, dtl
32  real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke, 3) :: dss ! Shock sensor
33 
34  ! No halos
35  real(kind=realtype), dimension(2:bbil, 2:bbjl, 2:bbkl) :: volref, d2wall
36  integer(kind=intType), dimension(2:bbil, 2:bbjl, 2:bbkl) :: iblank
37 
38  ! Face Porosities
39  integer(kind=porType), dimension(1:bbil, 2:bbjl, 2:bbkl) :: pori
40  integer(kind=porType), dimension(2:bbil, 1:bbjl, 2:bbkl) :: porj
41  integer(kind=porType), dimension(2:bbil, 2:bbjl, 1:bbkl) :: pork
42 
43  ! Single halos (only owned cells significant)
44  real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke, 1:5) :: fw
45  real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke, 1:6) :: dw
46 
47  ! Face projected areas
48  real(kind=realtype), dimension(0:bbie, 1:bbje, 1:bbke, 3) :: si
49  real(kind=realtype), dimension(1:bbie, 0:bbje, 1:bbke, 3) :: sj
50  real(kind=realtype), dimension(1:bbie, 1:bbje, 0:bbke, 3) :: sk
51 
52  ! Face velocities
53  real(kind=realtype), dimension(0:bbie, 1:bbje, 1:bbke) :: sfacei
54  real(kind=realtype), dimension(1:bbie, 0:bbje, 1:bbke) :: sfacej
55  real(kind=realtype), dimension(1:bbie, 1:bbje, 0:bbke) :: sfacek
56 
57  ! Nodal gradients
58  real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) :: ux, uy, uz
59  real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) :: vx, vy, vz
60  real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) :: wx, wy, wz
61  real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) :: qx, qy, qz
62 
63  ! Make *all* of these variables tread-private
64  !$OMP THREADPRIVATE(nx, ny, nz, il, jl, kl, ie, je, ke, ib, jb, kb)
65  !$OMP THREADPRIVATE(w, p, gamma, ss, x, rlv, rev, vol, aa, radI, radJ, radK)
66  !$OMP THREADPRIVATE(dss, volRef, d2wall, iblank, porI, porJ, porK, fw, dw)
67  !$OMP THREADPRIVATE(sI, sJ, sK, ux, uy, uz, vx, vy, vz, wx, wy, wz, qx, qy, qz)
68 contains
69 
70  subroutine blocketteres(useDissApprox, useViscApprox, useUpdateIntermed, useFlowRes, useTurbRes, useSpatial, &
71  useStoreWall, famLists, funcValues, forces, bcDataNames, bcDataValues, bcDataFamLists)
72 
73  ! Copy the values from blockPointers (assumed set) into the
74  ! blockette
75 
76  use constants
77  use block, only: ndom
78  use bcroutines, only: applyallbc_block
85  use flowvarrefstate, only: nwf, nw, nt1, nt2
87  use section, only: sections, nsections
88  use iteration, only: rfil, currentlevel
89  use haloexchange, only: exchangecoor, whalo2
91  use utils, only: setpointers, echk
93  use residuals, only: sourceterms_block
96  use oversetdata, only: oversetpresent
100  implicit none
101 
102  ! Input/Output
103  logical, intent(in), optional :: useDissApprox, useViscApprox, useUpdateIntermed, useFlowRes
104  logical, intent(in), optional :: useTurbRes, useSpatial, useStoreWall
105  integer(kind=intType), optional, dimension(:, :), intent(in) :: famLists
106  real(kind=realtype), optional, dimension(:, :), intent(out) :: funcvalues
107  character, optional, dimension(:, :), intent(in) :: bcDataNames
108  real(kind=realtype), optional, dimension(:), intent(in) :: bcdatavalues
109  integer(kind=intType), optional, dimension(:, :) :: bcDataFamLists
110  real(kind=realtype), intent(out), optional, dimension(:, :, :) :: forces
111 
112  ! Misc
113  logical :: dissApprox, viscApprox, updateIntermed, flowRes, turbRes, spatial, storeWall
114  integer(kind=intType) :: nn, sps, fSize, lstart, lend, iRegion
115  real(kind=realtype) :: plocal
116 
117  ! Set the defaults. The default is to compute the full, exact,
118  ! RANS residual without updating the spatial values or the local
119  ! timeStep.
120  dissapprox = .false.
121  viscapprox = .false.
122  ! Update intermediate flag is to copy out intermediate variables
123  ! that are computed during the blockette residual computation from
124  ! blockette memory back to the main memory. These are the time
125  ! step, spectral radii for all cases, and nodal gradients and
126  ! speed of sound squared for viscous simulations. The regular
127  ! "block" residuals do not need to copy out these since they
128  ! are already computed in place. For the block residual, this
129  ! flag only determines if we update the time step along with
130  ! the spectral radii.
131  updateintermed = .false.
132  flowres = .true.
133  turbres = .true.
134  spatial = .false.
135  storewall = .true.
136 
137  ! Parse the input variables
138  if (present(usedissapprox)) then
139  dissapprox = usedissapprox
140  end if
141 
142  if (present(useviscapprox)) then
143  viscapprox = useviscapprox
144  end if
145 
146  if (present(useupdateintermed)) then
147  updateintermed = useupdateintermed
148  end if
149 
150  if (present(useflowres)) then
151  flowres = useflowres
152  end if
153 
154  if (present(useturbres)) then
155  turbres = useturbres
156  end if
157 
158  if (present(usespatial)) then
159  spatial = usespatial
160  end if
161 
162  if (present(usestorewall)) then
163  storewall = usestorewall
164  end if
165 
166  ! Spatial-only updates first
167  if (spatial) then
168  call adjustinflowangle()
169 
170  ! Update all the BCData
171  call referencestate
172  if (present(bcdatanames)) then
173  do sps = 1, ntimeintervalsspectral
174  call setbcdata(bcdatanames, bcdatavalues, bcdatafamlists, sps, &
175  size(bcdatavalues), size(bcdatafamlists, 2))
176  end do
177  call setbcdatafinegrid(.true.)
178  end if
179 
180  do sps = 1, ntimeintervalsspectral
181  do nn = 1, ndom
182  call setpointers(nn, currentlevel, sps)
183  call xhalo_block()
184  end do
185  end do
186 
187  ! Now exchange the coordinates (fine level only)
188  call exchangecoor(1)
189 
190  do sps = 1, ntimeintervalsspectral
191  ! Update overset connectivity if necessary
192  if (oversetpresent .and. oversetupdatemode == updatefast) then
193  call updateoversetconnectivity(1_inttype, sps)
194  end if
195  end do
196  end if
197 
198  ! Compute the required derived values and apply the BCs
199  do sps = 1, ntimeintervalsspectral
200  do nn = 1, ndom
201  call setpointers(nn, currentlevel, sps)
202 
203  if (spatial) then
204  call volume_block
205  call metric_block
206  call boundarynormals
207 
209  call updatewalldistancesquickly(nn, 1, sps)
210  end if
211  end if
212 
213  ! Compute the pressures/viscositites
214  call computepressuresimple(.false.)
215 
216  ! Compute Laminar/eddy viscosity if required
217  call computelamviscosity(.false.)
218  call computeeddyviscosity(.false.)
219 
220  ! Make sure to call the turb BC's first incase we need to
221  ! correct for K
222  if (equations == ransequations .and. turbres) then
223  call bcturbtreatment
224  call applyallturbbcthisblock(.true.)
225  end if
226  call applyallbc_block(.true.)
227 
228  end do
229  end do
230 
231  ! Compute the ranges of the residuals we are dealing with:
232  if (flowres .and. turbres) then
233  lstart = 1
234  lend = nw
235 
236  else if (flowres .and. (.not. turbres)) then
237  lstart = 1
238  lend = nwf
239 
240  else if ((.not. flowres) .and. turbres) then
241  lstart = nt1
242  lend = nt2
243  end if
244 
245  ! Exchange values
246  call whalo2(1_inttype, lstart, lend, .true., .true., .true.)
247 
248  ! Need to re-apply the BCs. The reason is that BC halos behind
249  ! interpolated cells need to be recomputed with their new
250  ! interpolated values from actual compute cells. Only needed for
251  ! overset.
252  if (oversetpresent) then
253  do sps = 1, ntimeintervalsspectral
254  do nn = 1, ndom
255  call setpointers(nn, currentlevel, sps)
256  if (equations == ransequations .and. turbres) then
257  call bcturbtreatment
258  call applyallturbbcthisblock(.true.)
259  end if
260  call applyallbc_block(.true.)
261  end do
262  end do
263  end if
264 
265  ! Main loop for the residual...This is where the blockette magic happens.
266  spsloop: do sps = 1, ntimeintervalsspectral
267  blockloop: do nn = 1, ndom
268  call setpointers(nn, currentlevel, sps)
269 
270  rfil = one
271  blockettes: if (useblockettes) then
272  call blocketterescore(dissapprox, viscapprox, updateintermed, flowres, turbres, storewall)
273  else
274  call blockrescore(dissapprox, viscapprox, updateintermed, flowres, turbres, storewall, nn, sps)
275  end if blockettes
276 
277  if (currentlevel == 1) then
278  do iregion = 1, nactuatorregions
279  call sourceterms_block(nn, .true., iregion, plocal)
280  end do
281  end if
282  end do blockloop
283  end do spsloop
284 
285  ! Compute the final solution values
286  if (present(famlists)) then
287  call getsolution(famlists, funcvalues)
288  end if
289 
290  if (present(forces)) then
291  do sps = 1, ntimeintervalsspectral
292  ! Now we can retrieve the forces/tractions for this spectral instance
293  fsize = size(forces, 2)
294  call getforces(forces(:, :, sps), fsize, sps)
295  end do
296  end if
297  end subroutine blocketteres
298 
299  subroutine blocketterescore(dissApprox, viscApprox, updateIntermed, flowRes, turbRes, storeWall)
300 
301  ! Main subroutine for computing the reisdual for the given block using blockettes
302  use constants
303 
304  use constants
305  use blockpointers, only: &
306  bnx => nx, bny => ny, bnz => nz, &
307  bil => il, bjl => jl, bkl => kl, &
308  bie => ie, bje => je, bke => ke, &
309  bib => ib, bjb => jb, bkb => kb, &
310  bw => w, bp => p, bgamma => gamma, &
311  bradi => radi, bradj => radj, bradk => radk, &
312  bux => ux, buy => uy, buz => uz, &
313  bvx => vx, bvy => vy, bvz => vz, &
314  bwx => wx, bwy => wy, bwz => wz, &
315  bqx => qx, bqy => qy, bqz => qz, &
316  bx => x, brlv => rlv, brev => rev, bvol => vol, bvolref => volref, bd2wall => d2wall, &
317  biblank => iblank, bpori => pori, bporj => porj, bpork => pork, bdw => dw, bfw => fw, &
318  bshocksensor => shocksensor, &
319  bsi => si, bsj => sj, bsk => sk, &
320  bsfacei => sfacei, bsfacej => sfacej, bsfacek => sfacek, &
321  bdtl => dtl, baa => aa, &
323  use flowvarrefstate, only: nwf, nw, viscous, nt1, nt2
324  use iteration, only: currentlevel
327  use utils, only: setpointers, echk
329  use oversetdata, only: oversetpresent
330 
331  implicit none
332 
333  ! Input
334  logical, intent(in) :: dissApprox, viscApprox, updateIntermed, flowRes, turbRes, storeWall
335 
336  ! Working:
337  integer(kind=intType) :: i, j, k, l, lStart, lEnd
338 
339  ! Compute the ranges of the residuals we are dealing with:
340  if (flowres .and. turbres) then
341  lstart = 1
342  lend = nw
343 
344  else if (flowres .and. (.not. turbres)) then
345  lstart = 1
346  lend = nwf
347 
348  else if ((.not. flowres) .and. turbres) then
349  lstart = nt1
350  lend = nt2
351  end if
352 
353  ! Block loop over the owned cells
354  !$OMP parallel do private(i,j,k,l) collapse(2)
355  do kk = 2, bkl, bs
356  do jj = 2, bjl, bs
357  do ii = 2, bil, bs
358 
359  ! Determine the actual size this block will be and set
360  ! the sizes in the blockette module for each of the
361  ! subroutines.
362 
363  nx = min(ii + bs - 1, bil) - ii + 1
364  ny = min(jj + bs - 1, bjl) - jj + 1
365  nz = min(kk + bs - 1, bkl) - kk + 1
366 
367  il = nx + 1; jl = ny + 1; kl = nz + 1
368  ie = nx + 2; je = ny + 2; ke = nz + 2
369  ib = nx + 3; jb = ny + 3; kb = nz + 3
370 
371  firstblockette: if (ii == 2) then
372 
373  ! First loop. Need to compute the extra stuff. Set
374  ! the generic starts and copy the extra
375  ! variables in to the starting slots
376  singlehalostart = 1
377  doublehalostart = 0
378  nodestart = 1
379 
380  ! Double halos
381  do k = 0, kb
382  do j = 0, jb
383  do i = 0, 3
384  w(i, j, k, 1:nw) = bw(i + ii - 2, j + jj - 2, k + kk - 2, 1:nw)
385  p(i, j, k) = bp(i + ii - 2, j + jj - 2, k + kk - 2)
386  gamma(i, j, k) = bgamma(i + ii - 2, j + jj - 2, k + kk - 2)
387  if (currentlevel == 1) then
388  ss(i, j, k) = bshocksensor(i + ii - 2, j + jj - 2, k + kk - 2)
389  end if
390  end do
391  end do
392  end do
393 
394  ! Single halos
395  do k = 1, ke
396  do j = 1, je
397  do i = 1, 2
398  rlv(i, j, k) = brlv(i + ii - 2, j + jj - 2, k + kk - 2)
399  rev(i, j, k) = brev(i + ii - 2, j + jj - 2, k + kk - 2)
400  vol(i, j, k) = bvol(i + ii - 2, j + jj - 2, k + kk - 2)
401  end do
402  end do
403  end do
404 
405  ! X
406  do k = 0, ke
407  do j = 0, je
408  do i = 0, 1
409  x(i, j, k, :) = bx(i + ii - 2, j + jj - 2, k + kk - 2, :)
410  end do
411  end do
412  end do
413  else
414 
415  ! Subsequent loop. We can save a bunch of work by
416  ! copying some of the pre-computed values from the
417  ! previous blockette to this blockette. Basically the
418  ! values that are at the "I end" get shuffled back to
419  ! the I-start. We *also* do this for some of the
420  ! intermediate variables that are costly to compute
421  ! like the nodal gradients, and spectral radius which
422  ! helps cut back on the amount of data duplication.
423 
424  ! Important Note: This cell is not the first cell. If
425  ! this code is being executed, the previous blockette
426  ! was copied fully in the i direction.
427  ! Therefore, we can just copy the values from
428  ! the end of the blockette as it is allocated.
429  ! To do this, we ignore the dimensions of the "current"
430  ! blockette, and just take the baseline BS dimensions
431  ! as the current blockette might be partially filled
432  ! in the i direction.
433 
434  singlehalostart = 3
435  doublehalostart = 4
436  nodestart = 2
437 
438  ! Double halos
439  do k = 0, kb
440  do j = 0, jb
441  do i = 0, 3
442  w(i, j, k, 1:nw) = w(bs + i, j, k, 1:nw)
443  p(i, j, k) = p(bs + i, j, k)
444  gamma(i, j, k) = gamma(bs + i, j, k)
445  ss(i, j, k) = ss(bs + i, j, k)
446  end do
447  end do
448  end do
449 
450  ! Single halos
451  do k = 1, ke
452  do j = 1, je
453  do i = 1, 2
454  rlv(i, j, k) = rlv(bs + i, j, k)
455  rev(i, j, k) = rev(bs + i, j, k)
456  vol(i, j, k) = vol(bs + i, j, k)
457 
458  ! Computed variables
459 
460  ! DONT Copy the spectral-radii. The loop that calculates
461  ! spectral radii also calculates portion of the time step,
462  ! so we don't want to mess with its boundaries to keep
463  ! it simple.
464  aa(i, j, k) = aa(bs + i, j, k)
465  dss(i, j, k, :) = dss(bs + i, j, k, :)
466  end do
467  end do
468  end do
469 
470  ! X
471  do k = 0, ke
472  do j = 0, je
473  do i = 0, 1
474  x(i, j, k, :) = x(bs + i, j, k, :)
475  end do
476  end do
477  end do
478 
479  ! Nodal gradients
480  do k = 1, kl
481  do j = 1, jl
482  ux(1, j, k) = ux(bs + 1, j, k)
483  uy(1, j, k) = uy(bs + 1, j, k)
484  uz(1, j, k) = uz(bs + 1, j, k)
485 
486  vx(1, j, k) = vx(bs + 1, j, k)
487  vy(1, j, k) = vy(bs + 1, j, k)
488  vz(1, j, k) = vz(bs + 1, j, k)
489 
490  wx(1, j, k) = wx(bs + 1, j, k)
491  wy(1, j, k) = wy(bs + 1, j, k)
492  wz(1, j, k) = wz(bs + 1, j, k)
493 
494  qx(1, j, k) = qx(bs + 1, j, k)
495  qy(1, j, k) = qy(bs + 1, j, k)
496  qz(1, j, k) = qz(bs + 1, j, k)
497  end do
498  end do
499  end if firstblockette
500 
501  ! -------------------------------------
502  ! Fill in the remaining values
503  ! -------------------------------------
504 
505  ! Double halos
506  do k = 0, kb
507  do j = 0, jb
508  do i = 4, ib
509  w(i, j, k, 1:nw) = bw(i + ii - 2, j + jj - 2, k + kk - 2, 1:nw)
510  p(i, j, k) = bp(i + ii - 2, j + jj - 2, k + kk - 2)
511  gamma(i, j, k) = bgamma(i + ii - 2, j + jj - 2, k + kk - 2)
512  if (currentlevel == 1) then
513  ss(i, j, k) = bshocksensor(i + ii - 2, j + jj - 2, k + kk - 2)
514  end if
515  end do
516  end do
517  end do
518 
519  ! Single halos
520  do k = 1, ke
521  do j = 1, je
522  do i = 3, ie
523  rlv(i, j, k) = brlv(i + ii - 2, j + jj - 2, k + kk - 2)
524  rev(i, j, k) = brev(i + ii - 2, j + jj - 2, k + kk - 2)
525  vol(i, j, k) = bvol(i + ii - 2, j + jj - 2, k + kk - 2)
526  end do
527  end do
528  end do
529 
530  ! X
531  do k = 0, ke
532  do j = 0, je
533  do i = 2, ie
534  x(i, j, k, :) = bx(i + ii - 2, j + jj - 2, k + kk - 2, :)
535  end do
536  end do
537  end do
538 
539  ! No Halos (no change)
540  do k = 2, kl
541  do j = 2, jl
542  do i = 2, il
543  iblank(i, j, k) = biblank(i + ii - 2, j + jj - 2, k + kk - 2)
544  if (equations .eq. ransequations) &
545  d2wall(i, j, k) = bd2wall(i + ii - 2, j + jj - 2, k + kk - 2)
546  volref(i, j, k) = bvolref(i + ii - 2, j + jj - 2, k + kk - 2)
547  end do
548  end do
549  end do
550 
551  ! Porosities (no change)
552  do k = 2, kl
553  do j = 2, jl
554  do i = 1, il
555  pori(i, j, k) = bpori(i + ii - 2, j + jj - 2, k + kk - 2)
556  end do
557  end do
558  end do
559 
560  do k = 2, kl
561  do j = 1, jl
562  do i = 2, il
563  porj(i, j, k) = bporj(i + ii - 2, j + jj - 2, k + kk - 2)
564  end do
565  end do
566  end do
567 
568  do k = 1, kl
569  do j = 2, jl
570  do i = 2, il
571  pork(i, j, k) = bpork(i + ii - 2, j + jj - 2, k + kk - 2)
572  end do
573  end do
574  end do
575 
576  ! Face velocities if necessary
577  if (addgridvelocities) then
578  do k = 1, ke
579  do j = 1, je
580  do i = 0, ie
581  sfacei(i, j, k) = bsfacei(i + ii - 2, j + jj - 2, k + kk - 2)
582  end do
583  end do
584  end do
585 
586  do k = 1, ke
587  do j = 0, je
588  do i = 1, ie
589  sfacej(i, j, k) = bsfacej(i + ii - 2, j + jj - 2, k + kk - 2)
590  end do
591  end do
592  end do
593 
594  do k = 0, ke
595  do j = 1, je
596  do i = 1, ie
597  sfacek(i, j, k) = bsfacek(i + ii - 2, j + jj - 2, k + kk - 2)
598  end do
599  end do
600  end do
601  else
602  sfacei = zero
603  sfacej = zero
604  sfacek = zero
605  end if
606 
607  ! Clear the viscous flux before we start.
608  fw = zero
609 
610  ! Call the routines in order:
611  call metrics
612  call initres(lstart, lend)
613 
614  ! Compute turbulence residual for RANS equations
615  if (equations == ransequations .and. turbres) then
616 
617  ! Initialize only the Turblent Variables
618  !call unsteadyTurbSpectral_block(itu1, itu1, nn, sps)
619 
620  select case (turbmodel)
621 
622  case (spalartallmaras)
623  call sasource
624  call saadvection
625  !call unsteadyTurbTerm(1_intType, 1_intType, itu1-1, qq)
626  call saviscous
627  call saresscale
628  end select
629  end if
630 
631  call timestep(updateintermed)
632 
633  if (flowres) then
635 
636  if (dissapprox) then
637  select case (spacediscr)
638  case (dissscalar)
640  case (dissmatrix)
642  case (upwind)
643  call inviscidupwindflux(.false.)
644  end select
645  else
646  select case (spacediscr)
647  case (dissscalar)
649  case (dissmatrix)
651  case (upwind)
652  call inviscidupwindflux(.true.)
653  end select
654  end if
655 
656  if (viscous) then
658  if (viscapprox) then
659  call viscousfluxapprox
660  else
661  call allnodalgradients
662  call viscousflux(storewall)
663  end if
664  end if
665 
666  call sumdwandfw
667  end if
668 
669  ! Now we can just set the part of dw we computed
670  ! (owned cells only) and we're done!
671  do l = lstart, lend
672  do k = 2, kl
673  do j = 2, jl
674  do i = 2, il
675  bdw(i + ii - 2, j + jj - 2, k + kk - 2, l) = dw(i, j, k, l)
676  end do
677  end do
678  end do
679  end do
680 
681  ! Also copy out the intermediate variables if asked for them
682  ! we need these to be updated in main memory because
683  ! the reverse mode AD routines do use these variables.
684  ! after every ANK and NK step, blocketteRes is called
685  ! with updateIntermed = True, and it will update these
686  ! arrays in main memory. The time step is required
687  ! for the ANK and MG solver steps.
688  intermed: if (updateintermed) then
689  ! time step
690  do k = 2, kl
691  do j = 2, jl
692  do i = 2, il
693  bdtl(i + ii - 2, j + jj - 2, k + kk - 2) = dtl(i, j, k)
694  end do
695  end do
696  end do
697 
698  ! Spectral radii
699  do k = 1, ke
700  do j = 1, je
701  do i = 1, ie
702  bradi(i + ii - 2, j + jj - 2, k + kk - 2) = radi(i, j, k)
703  bradj(i + ii - 2, j + jj - 2, k + kk - 2) = radj(i, j, k)
704  bradk(i + ii - 2, j + jj - 2, k + kk - 2) = radk(i, j, k)
705  end do
706  end do
707  end do
708 
709  ! need aa and nodal gradients if we have viscous fluxes
710  visc: if (viscous .and. flowres) then
711 
712  ! speed of sound squared
713  do k = 1, ke
714  do j = 1, je
715  do i = 1, ie
716  baa(i + ii - 2, j + jj - 2, k + kk - 2) = aa(i, j, k)
717  end do
718  end do
719  end do
720 
721  ! nodal gradients
722  do k = 1, kl
723  do j = 1, jl
724  do i = 1, il
725 
726  bux(i + ii - 2, j + jj - 2, k + kk - 2) = ux(i, j, k)
727  buy(i + ii - 2, j + jj - 2, k + kk - 2) = uy(i, j, k)
728  buz(i + ii - 2, j + jj - 2, k + kk - 2) = uz(i, j, k)
729 
730  bvx(i + ii - 2, j + jj - 2, k + kk - 2) = vx(i, j, k)
731  bvy(i + ii - 2, j + jj - 2, k + kk - 2) = vy(i, j, k)
732  bvz(i + ii - 2, j + jj - 2, k + kk - 2) = vz(i, j, k)
733 
734  bwx(i + ii - 2, j + jj - 2, k + kk - 2) = wx(i, j, k)
735  bwy(i + ii - 2, j + jj - 2, k + kk - 2) = wy(i, j, k)
736  bwz(i + ii - 2, j + jj - 2, k + kk - 2) = wz(i, j, k)
737 
738  bqx(i + ii - 2, j + jj - 2, k + kk - 2) = qx(i, j, k)
739  bqy(i + ii - 2, j + jj - 2, k + kk - 2) = qy(i, j, k)
740  bqz(i + ii - 2, j + jj - 2, k + kk - 2) = qz(i, j, k)
741 
742  end do
743  end do
744  end do
745  end if visc
746 
747  end if intermed
748 
749  end do
750  end do
751  end do
752  !$OMP END PARALLEL DO
753  end subroutine blocketterescore
754 
755  subroutine blockrescore(dissApprox, viscApprox, updateIntermed, flowRes, turbRes, storeWall, nn, sps)
756 
757  use constants
758  use fluxes, only: inviscidcentralflux_block => inviscidcentralflux, &
759  invisciddissfluxscalar_block => invisciddissfluxscalar, &
760  invisciddissfluxmatrix_block => invisciddissfluxmatrix, &
761  inviscidupwindflux_block => inviscidupwindflux, &
762  invisciddissfluxscalarapprox_block => invisciddissfluxscalarapprox, &
763  invisciddissfluxmatrixapprox_block => invisciddissfluxmatrixapprox, &
764  viscousflux_block => viscousflux, &
765  viscousfluxapprox_block => viscousfluxapprox
766  use solverutils, only: timestep_block
767  use flowvarrefstate, only: nwf, nw, viscous, nt1, nt2
769  use residuals, only: initres_block
770  use sa, only: sa_block
771  use adjointextra, only: sumdwandfw_block => sumdwandfw
773  use flowutils, only: allnodalgradients_block => allnodalgradients, &
774  computespeedofsoundsquared_block => computespeedofsoundsquared
775 
776  implicit none
777  ! Input
778  logical, intent(in) :: dissApprox, viscApprox, updateIntermed, flowRes, turbRes, storeWall
779  integer(kind=intType), intent(in) :: nn, sps
780 
781  ! Working:
782  integer(kind=intType) :: i, j, k, lStart, lEnd
783 
784  ! Compute the ranges of the residuals we are dealing with:
785  if (flowres .and. turbres) then
786  lstart = 1
787  lend = nw
788 
789  else if (flowres .and. (.not. turbres)) then
790  lstart = 1
791  lend = nwf
792 
793  else if ((.not. flowres) .and. turbres) then
794  lstart = nt1
795  lend = nt2
796  end if
797 
798  ! Compute time step
799  call timestep_block(.not. updateintermed)
800 
801  call initres_block(lstart, lend, nn, sps) ! Initialize only the Turblent Variables
802 
803  fw = zero
804 
805  ! Possible Turblent Equations
806  if (equations == ransequations .and. turbres) then
807  ! Compute the skin-friction velocity (wall functions only)
808  !call computeUtau_block
809 
810  ! Now call the selected turbulence model
811  select case (turbmodel)
812  case (spalartallmaras)
813  call sa_block(.true.)
814  end select
815  end if
816 
817  if (flowres) then
818 
819  call inviscidcentralflux_block
820  if (dissapprox) then
821  select case (spacediscr)
822  case (dissscalar)
823  call invisciddissfluxscalarapprox_block
824  case (dissmatrix)
825  call invisciddissfluxmatrixapprox_block
826  case (upwind)
827  call inviscidupwindflux_block(.true.)
828  end select
829  else
830  select case (spacediscr)
831  case (dissscalar)
832  call invisciddissfluxscalar_block
833  case (dissmatrix)
834  call invisciddissfluxmatrix_block
835  case (upwind)
836  call inviscidupwindflux_block(.true.)
837  end select
838  end if
839 
840  if (viscous) then
841  call computespeedofsoundsquared_block
842  if (viscapprox) then
843  call viscousfluxapprox_block
844  else
845  call allnodalgradients_block
846  call viscousflux_block
847  end if
848  end if
849 
850  call sumdwandfw_block
851  end if
852  end subroutine blockrescore
853 
854  subroutine metrics
855  ! ---------------------------------------------
856  ! Metric computation
857  ! ---------------------------------------------
858 
859  use constants
860  use blockpointers, only: righthanded
861  implicit none
862 
863  integer(kind=intType) :: i, j, k, l, m, n
864  real(kind=realtype), dimension(3) :: v1, v2
865  real(kind=realtype) :: fact
866 
867  ! Projected areas of cell faces in the i direction.
868  if (righthanded) then
869  fact = half
870  else
871  fact = -half
872  end if
873  do k = 1, ke
874  n = k - 1
875  do j = 1, je
876  m = j - 1
877  do i = 0, ie
878 
879  ! Determine the two diagonal vectors of the face.
880 
881  v1(1) = x(i, j, n, 1) - x(i, m, k, 1)
882  v1(2) = x(i, j, n, 2) - x(i, m, k, 2)
883  v1(3) = x(i, j, n, 3) - x(i, m, k, 3)
884 
885  v2(1) = x(i, j, k, 1) - x(i, m, n, 1)
886  v2(2) = x(i, j, k, 2) - x(i, m, n, 2)
887  v2(3) = x(i, j, k, 3) - x(i, m, n, 3)
888 
889  ! The face normal, which is the cross product of the two
890  ! diagonal vectors times fact; remember that fact is
891  ! either -0.5 or 0.5.
892 
893  si(i, j, k, 1) = fact * (v1(2) * v2(3) - v1(3) * v2(2))
894  si(i, j, k, 2) = fact * (v1(3) * v2(1) - v1(1) * v2(3))
895  si(i, j, k, 3) = fact * (v1(1) * v2(2) - v1(2) * v2(1))
896 
897  end do
898  end do
899  end do
900 
901  ! Projected areas of cell faces in the j direction.
902 
903  do k = 1, ke
904  n = k - 1
905  do j = 0, je
906  do i = 1, ie
907  l = i - 1
908 
909  ! Determine the two diagonal vectors of the face.
910 
911  v1(1) = x(i, j, n, 1) - x(l, j, k, 1)
912  v1(2) = x(i, j, n, 2) - x(l, j, k, 2)
913  v1(3) = x(i, j, n, 3) - x(l, j, k, 3)
914 
915  v2(1) = x(l, j, n, 1) - x(i, j, k, 1)
916  v2(2) = x(l, j, n, 2) - x(i, j, k, 2)
917  v2(3) = x(l, j, n, 3) - x(i, j, k, 3)
918 
919  ! The face normal, which is the cross product of the two
920  ! diagonal vectors times fact; remember that fact is
921  ! either -0.5 or 0.5.
922 
923  sj(i, j, k, 1) = fact * (v1(2) * v2(3) - v1(3) * v2(2))
924  sj(i, j, k, 2) = fact * (v1(3) * v2(1) - v1(1) * v2(3))
925  sj(i, j, k, 3) = fact * (v1(1) * v2(2) - v1(2) * v2(1))
926 
927  end do
928  end do
929  end do
930 
931  ! Projected areas of cell faces in the k direction.
932 
933  do k = 0, ke
934  do j = 1, je
935  m = j - 1
936  do i = 1, ie
937  l = i - 1
938 
939  ! Determine the two diagonal vectors of the face.
940 
941  v1(1) = x(i, j, k, 1) - x(l, m, k, 1)
942  v1(2) = x(i, j, k, 2) - x(l, m, k, 2)
943  v1(3) = x(i, j, k, 3) - x(l, m, k, 3)
944 
945  v2(1) = x(l, j, k, 1) - x(i, m, k, 1)
946  v2(2) = x(l, j, k, 2) - x(i, m, k, 2)
947  v2(3) = x(l, j, k, 3) - x(i, m, k, 3)
948 
949  ! The face normal, which is the cross product of the two
950  ! diagonal vectors times fact; remember that fact is
951  ! either -0.5 or 0.5.
952 
953  sk(i, j, k, 1) = fact * (v1(2) * v2(3) - v1(3) * v2(2))
954  sk(i, j, k, 2) = fact * (v1(3) * v2(1) - v1(1) * v2(3))
955  sk(i, j, k, 3) = fact * (v1(1) * v2(2) - v1(2) * v2(1))
956 
957  end do
958  end do
959  end do
960  end subroutine metrics
961 
962  subroutine initres(varStart, varEnd)
963  ! ---------------------------------------------
964  ! Init Res
965  ! ---------------------------------------------
966 
967  use constants
968  implicit none
969 
970  integer(kind=intType) :: varStart, varEnd
971  ! Obviously this needs to be more complex for the actual code.
972  dw(:, :, :, varstart:varend) = zero
973 
974  end subroutine initres
975 
976  subroutine sasource
977  ! ---------------------------------------------
978  ! SA Source Term
979  ! ---------------------------------------------
980 
981  use constants
982  use paramturb
983  use blockpointers, only: sectionid
985  use inputdiscretization, only: approxsa
986  use section, only: sections
987  use sa, only: cv13, kar2inv, cw36, cb3inv
988  use flowvarrefstate, only: timeref
989 
990  implicit none
991 
992  ! Variables for sa Souce
993  real(kind=realtype) :: fv1, fv2, ft2
994  real(kind=realtype) :: sst, nu, dist2inv, chi, chi2, chi3
995  real(kind=realtype) :: rr, gg, gg6, termfw, fwsa, term1, term2
996  real(kind=realtype) :: dfv1, dfv2, dft2, drr, dgg, dfw, sqrtprod
997  real(kind=realtype) :: uux, uuy, uuz, vvx, vvy, vvz, wwx, wwy, wwz
998  real(kind=realtype) :: div2, fact, sxx, syy, szz, sxy, sxz, syz
999  real(kind=realtype) :: vortx, vorty, vortz
1000  real(kind=realtype) :: omegax, omegay, omegaz
1001  real(kind=realtype) :: strainmag2, prod
1002  real(kind=realtype), parameter :: xminn = 1.e-10_realtype
1003  real(kind=realtype), parameter :: f23 = two * third
1004  integer(kind=intType) :: i, j, k
1005  real(kind=realtype) :: term1fact
1006 
1007  ! Set model constants
1008  cv13 = rsacv1**3
1009  kar2inv = one / (rsak**2)
1010  cw36 = rsacw3**6
1011  cb3inv = one / rsacb3
1012 
1013  ! set the approximate multiplier here
1014  term1fact = one
1015  if (approxsa) term1fact = zero
1016 
1017  ! Determine the non-dimensional wheel speed of this block.
1018 
1019  omegax = timeref * sections(sectionid)%rotRate(1)
1020  omegay = timeref * sections(sectionid)%rotRate(2)
1021  omegaz = timeref * sections(sectionid)%rotRate(3)
1022  do k = 2, kl
1023  do j = 2, jl
1024  do i = 2, il
1025 
1026  ! Compute the gradient of u in the cell center. Use is made
1027  ! of the fact that the surrounding normals sum up to zero,
1028  ! such that the cell i,j,k does not give a contribution.
1029  ! The gradient is scaled by the factor 2*vol.
1030 
1031  uux = w(i + 1, j, k, ivx) * si(i, j, k, 1) - w(i - 1, j, k, ivx) * si(i - 1, j, k, 1) &
1032  + w(i, j + 1, k, ivx) * sj(i, j, k, 1) - w(i, j - 1, k, ivx) * sj(i, j - 1, k, 1) &
1033  + w(i, j, k + 1, ivx) * sk(i, j, k, 1) - w(i, j, k - 1, ivx) * sk(i, j, k - 1, 1)
1034  uuy = w(i + 1, j, k, ivx) * si(i, j, k, 2) - w(i - 1, j, k, ivx) * si(i - 1, j, k, 2) &
1035  + w(i, j + 1, k, ivx) * sj(i, j, k, 2) - w(i, j - 1, k, ivx) * sj(i, j - 1, k, 2) &
1036  + w(i, j, k + 1, ivx) * sk(i, j, k, 2) - w(i, j, k - 1, ivx) * sk(i, j, k - 1, 2)
1037  uuz = w(i + 1, j, k, ivx) * si(i, j, k, 3) - w(i - 1, j, k, ivx) * si(i - 1, j, k, 3) &
1038  + w(i, j + 1, k, ivx) * sj(i, j, k, 3) - w(i, j - 1, k, ivx) * sj(i, j - 1, k, 3) &
1039  + w(i, j, k + 1, ivx) * sk(i, j, k, 3) - w(i, j, k - 1, ivx) * sk(i, j, k - 1, 3)
1040 
1041  ! Idem for the gradient of v.
1042 
1043  vvx = w(i + 1, j, k, ivy) * si(i, j, k, 1) - w(i - 1, j, k, ivy) * si(i - 1, j, k, 1) &
1044  + w(i, j + 1, k, ivy) * sj(i, j, k, 1) - w(i, j - 1, k, ivy) * sj(i, j - 1, k, 1) &
1045  + w(i, j, k + 1, ivy) * sk(i, j, k, 1) - w(i, j, k - 1, ivy) * sk(i, j, k - 1, 1)
1046  vvy = w(i + 1, j, k, ivy) * si(i, j, k, 2) - w(i - 1, j, k, ivy) * si(i - 1, j, k, 2) &
1047  + w(i, j + 1, k, ivy) * sj(i, j, k, 2) - w(i, j - 1, k, ivy) * sj(i, j - 1, k, 2) &
1048  + w(i, j, k + 1, ivy) * sk(i, j, k, 2) - w(i, j, k - 1, ivy) * sk(i, j, k - 1, 2)
1049  vvz = w(i + 1, j, k, ivy) * si(i, j, k, 3) - w(i - 1, j, k, ivy) * si(i - 1, j, k, 3) &
1050  + w(i, j + 1, k, ivy) * sj(i, j, k, 3) - w(i, j - 1, k, ivy) * sj(i, j - 1, k, 3) &
1051  + w(i, j, k + 1, ivy) * sk(i, j, k, 3) - w(i, j, k - 1, ivy) * sk(i, j, k - 1, 3)
1052 
1053  ! And for the gradient of w.
1054 
1055  wwx = w(i + 1, j, k, ivz) * si(i, j, k, 1) - w(i - 1, j, k, ivz) * si(i - 1, j, k, 1) &
1056  + w(i, j + 1, k, ivz) * sj(i, j, k, 1) - w(i, j - 1, k, ivz) * sj(i, j - 1, k, 1) &
1057  + w(i, j, k + 1, ivz) * sk(i, j, k, 1) - w(i, j, k - 1, ivz) * sk(i, j, k - 1, 1)
1058  wwy = w(i + 1, j, k, ivz) * si(i, j, k, 2) - w(i - 1, j, k, ivz) * si(i - 1, j, k, 2) &
1059  + w(i, j + 1, k, ivz) * sj(i, j, k, 2) - w(i, j - 1, k, ivz) * sj(i, j - 1, k, 2) &
1060  + w(i, j, k + 1, ivz) * sk(i, j, k, 2) - w(i, j, k - 1, ivz) * sk(i, j, k - 1, 2)
1061  wwz = w(i + 1, j, k, ivz) * si(i, j, k, 3) - w(i - 1, j, k, ivz) * si(i - 1, j, k, 3) &
1062  + w(i, j + 1, k, ivz) * sj(i, j, k, 3) - w(i, j - 1, k, ivz) * sj(i, j - 1, k, 3) &
1063  + w(i, j, k + 1, ivz) * sk(i, j, k, 3) - w(i, j, k - 1, ivz) * sk(i, j, k - 1, 3)
1064 
1065  ! Compute the components of the stress tensor.
1066  ! The combination of the current scaling of the velocity
1067  ! gradients (2*vol) and the definition of the stress tensor,
1068  ! leads to the factor 1/(4*vol).
1069 
1070  fact = fourth / vol(i, j, k)
1071 
1072  ! -- Calcs for strain --
1073  sxx = two * fact * uux
1074  syy = two * fact * vvy
1075  szz = two * fact * wwz
1076 
1077  sxy = fact * (uuy + vvx)
1078  sxz = fact * (uuz + wwx)
1079  syz = fact * (vvz + wwy)
1080 
1081  ! Compute 2/3 * divergence of velocity squared
1082 
1083  div2 = f23 * (sxx + syy + szz)**2
1084 
1085  ! Compute strain production term
1086 
1087  strainmag2 = two * (sxy**2 + sxz**2 + syz**2) &
1088  + sxx**2 + syy**2 + szz**2
1089 
1090  ! -- Calcs for vorticity --
1091 
1092  ! Compute the three components of the vorticity vector.
1093  ! Substract the part coming from the rotating frame.
1094 
1095  vortx = two * fact * (wwy - vvz) - two * omegax
1096  vorty = two * fact * (uuz - wwx) - two * omegay
1097  vortz = two * fact * (vvx - uuy) - two * omegaz
1098 
1099  if (turbprod == strain) then
1100  sqrtprod = sqrt(max(two * strainmag2 - div2, eps))
1101  else
1102  sqrtprod = sqrt(vortx**2 + vorty**2 + vortz**2)
1103  end if
1104 
1105  ! Compute the laminar kinematic viscosity, the inverse of
1106  ! wall distance squared, the ratio chi (ratio of nuTilde
1107  ! and nu) and the functions fv1 and fv2. The latter corrects
1108  ! the production term near a viscous wall.
1109 
1110  nu = rlv(i, j, k) / w(i, j, k, irho)
1111  dist2inv = one / (d2wall(i, j, k)**2)
1112  chi = w(i, j, k, itu1) / nu
1113  chi2 = chi * chi
1114  chi3 = chi * chi2
1115  fv1 = chi3 / (chi3 + cv13)
1116  fv2 = one - chi / (one + chi * fv1)
1117 
1118  ! The function ft2, which is designed to keep a laminar
1119  ! solution laminar. When running in fully turbulent mode
1120  ! this function should be set to 0.0.
1121 
1122  ft2 = zero
1123  if (useft2sa) then
1124  ft2 = rsact3 * exp(-rsact4 * chi2)
1125  end if
1126 
1127  ! Correct the production term to account for the influence
1128  ! of the wall.
1129 
1130  sst = sqrtprod + w(i, j, k, itu1) * fv2 * kar2inv * dist2inv
1131 
1132  ! Add rotation term (useRotationSA defined in inputParams.F90)
1133 
1134  if (userotationsa) then
1135  sst = sst + rsacrot * min(zero, sqrt(two * strainmag2))
1136  end if
1137 
1138  ! Make sure that this term remains positive
1139  ! (the function fv2 is negative between chi = 1 and 18.4,
1140  ! which can cause sst to go negative, which is undesirable).
1141 
1142  sst = max(sst, xminn)
1143 
1144  ! Compute the function fw. The argument rr is cut off at 10
1145  ! to avoid numerical problems. This is ok, because the
1146  ! asymptotical value of fw is then already reached.
1147 
1148  rr = w(i, j, k, itu1) * kar2inv * dist2inv / sst
1149  rr = min(rr, 10.0_realtype)
1150  gg = rr + rsacw2 * (rr**6 - rr)
1151  gg6 = gg**6
1152  termfw = ((one + cw36) / (gg6 + cw36))**sixth
1153  fwsa = gg * termfw
1154 
1155  ! Compute the source term; some terms are saved for the
1156  ! linearization. The source term is stored in dvt.
1157 
1158  term1 = rsacb1 * (one - ft2) * sqrtprod * term1fact
1159  term2 = dist2inv * (kar2inv * rsacb1 * ((one - ft2) * fv2 + ft2) &
1160  - rsacw1 * fwsa)
1161 
1162  dw(i, j, k, itu1) = dw(i, j, k, itu1) + (term1 + term2 * w(i, j, k, itu1)) * w(i, j, k, itu1)
1163 
1164  end do
1165  end do
1166  end do
1167  end subroutine sasource
1168 
1169  subroutine saviscous
1170  ! ---------------------------------------------
1171  ! SA Viscous Term
1172  ! ---------------------------------------------
1173 
1174  use constants
1175  use sa, only: cv13, kar2inv, cw36, cb3inv
1176  use paramturb
1177  implicit none
1178 
1179  ! Variables for sa Viscous
1180  real(kind=realtype) :: voli, volmi, volpi, xm, ym, zm, xp, yp, zp
1181  real(kind=realtype) :: xa, ya, za, ttm, ttp, cnud, cam, cap
1182  real(kind=realtype) :: nutm, nutp, num, nup, cdm, cdp
1183  real(kind=realtype) :: c1m, c1p, c10, b1, c1, d1, qs, nu
1184  integer(Kind=intType) :: i, j, k
1185 
1186  ! Set model constants
1187  cv13 = rsacv1**3
1188  kar2inv = one / (rsak**2)
1189  cw36 = rsacw3**6
1190  cb3inv = one / rsacb3
1191 
1192  !
1193  ! Viscous terms in k-direction.
1194  !
1195  do k = 2, kl
1196  do j = 2, jl
1197  do i = 2, il
1198 
1199  ! Compute the metrics in zeta-direction, i.e. along the
1200  ! line k = constant.
1201 
1202  voli = one / vol(i, j, k)
1203  volmi = two / (vol(i, j, k) + vol(i, j, k - 1))
1204  volpi = two / (vol(i, j, k) + vol(i, j, k + 1))
1205 
1206  xm = sk(i, j, k - 1, 1) * volmi
1207  ym = sk(i, j, k - 1, 2) * volmi
1208  zm = sk(i, j, k - 1, 3) * volmi
1209  xp = sk(i, j, k, 1) * volpi
1210  yp = sk(i, j, k, 2) * volpi
1211  zp = sk(i, j, k, 3) * volpi
1212 
1213  xa = half * (sk(i, j, k, 1) + sk(i, j, k - 1, 1)) * voli
1214  ya = half * (sk(i, j, k, 2) + sk(i, j, k - 1, 2)) * voli
1215  za = half * (sk(i, j, k, 3) + sk(i, j, k - 1, 3)) * voli
1216  ttm = xm * xa + ym * ya + zm * za
1217  ttp = xp * xa + yp * ya + zp * za
1218 
1219  ! Computation of the viscous terms in zeta-direction; note
1220  ! that cross-derivatives are neglected, i.e. the mesh is
1221  ! assumed to be orthogonal.
1222  ! Furthermore, the grad(nu)**2 has been rewritten as
1223  ! div(nu grad(nu)) - nu div(grad nu) to enhance stability.
1224  ! The second derivative in zeta-direction is constructed as
1225  ! the central difference of the first order derivatives, i.e.
1226  ! d^2/dzeta^2 = d/dzeta (d/dzeta k+1/2 - d/dzeta k-1/2).
1227  ! In this way the metric can be taken into account.
1228 
1229  ! Compute the diffusion coefficients multiplying the nodes
1230  ! k+1, k and k-1 in the second derivative. Make sure that
1231  ! these coefficients are nonnegative.
1232 
1233  cnud = -rsacb2 * w(i, j, k, itu1) * cb3inv
1234  cam = ttm * cnud
1235  cap = ttp * cnud
1236 
1237  nutm = half * (w(i, j, k - 1, itu1) + w(i, j, k, itu1))
1238  nutp = half * (w(i, j, k + 1, itu1) + w(i, j, k, itu1))
1239  nu = rlv(i, j, k) / w(i, j, k, irho)
1240  num = half * (rlv(i, j, k - 1) / w(i, j, k - 1, irho) + nu)
1241  nup = half * (rlv(i, j, k + 1) / w(i, j, k + 1, irho) + nu)
1242  cdm = (num + (one + rsacb2) * nutm) * ttm * cb3inv
1243  cdp = (nup + (one + rsacb2) * nutp) * ttp * cb3inv
1244 
1245  c1m = max(cdm + cam, zero)
1246  c1p = max(cdp + cap, zero)
1247  c10 = c1m + c1p
1248 
1249  ! Update the residual for this cell and store the possible
1250  ! coefficients for the matrix in b1, c1 and d1.
1251 
1252  dw(i, j, k, itu1) = dw(i, j, k, itu1) + c1m * w(i, j, k - 1, itu1) &
1253  - c10 * w(i, j, k, itu1) + c1p * w(i, j, k + 1, itu1)
1254  end do
1255  end do
1256  end do
1257  !
1258  ! Viscous terms in j-direction.
1259  !
1260  do k = 2, kl
1261  do j = 2, jl
1262  do i = 2, il
1263 
1264  ! Compute the metrics in eta-direction, i.e. along the
1265  ! line j = constant.
1266 
1267  voli = one / vol(i, j, k)
1268  volmi = two / (vol(i, j, k) + vol(i, j - 1, k))
1269  volpi = two / (vol(i, j, k) + vol(i, j + 1, k))
1270 
1271  xm = sj(i, j - 1, k, 1) * volmi
1272  ym = sj(i, j - 1, k, 2) * volmi
1273  zm = sj(i, j - 1, k, 3) * volmi
1274  xp = sj(i, j, k, 1) * volpi
1275  yp = sj(i, j, k, 2) * volpi
1276  zp = sj(i, j, k, 3) * volpi
1277 
1278  xa = half * (sj(i, j, k, 1) + sj(i, j - 1, k, 1)) * voli
1279  ya = half * (sj(i, j, k, 2) + sj(i, j - 1, k, 2)) * voli
1280  za = half * (sj(i, j, k, 3) + sj(i, j - 1, k, 3)) * voli
1281  ttm = xm * xa + ym * ya + zm * za
1282  ttp = xp * xa + yp * ya + zp * za
1283 
1284  ! Computation of the viscous terms in eta-direction; note
1285  ! that cross-derivatives are neglected, i.e. the mesh is
1286  ! assumed to be orthogonal.
1287  ! Furthermore, the grad(nu)**2 has been rewritten as
1288  ! div(nu grad(nu)) - nu div(grad nu) to enhance stability.
1289  ! The second derivative in eta-direction is constructed as
1290  ! the central difference of the first order derivatives, i.e.
1291  ! d^2/deta^2 = d/deta (d/deta j+1/2 - d/deta j-1/2).
1292  ! In this way the metric can be taken into account.
1293 
1294  ! Compute the diffusion coefficients multiplying the nodes
1295  ! j+1, j and j-1 in the second derivative. Make sure that
1296  ! these coefficients are nonnegative.
1297 
1298  cnud = -rsacb2 * w(i, j, k, itu1) * cb3inv
1299  cam = ttm * cnud
1300  cap = ttp * cnud
1301 
1302  nutm = half * (w(i, j - 1, k, itu1) + w(i, j, k, itu1))
1303  nutp = half * (w(i, j + 1, k, itu1) + w(i, j, k, itu1))
1304  nu = rlv(i, j, k) / w(i, j, k, irho)
1305  num = half * (rlv(i, j - 1, k) / w(i, j - 1, k, irho) + nu)
1306  nup = half * (rlv(i, j + 1, k) / w(i, j + 1, k, irho) + nu)
1307  cdm = (num + (one + rsacb2) * nutm) * ttm * cb3inv
1308  cdp = (nup + (one + rsacb2) * nutp) * ttp * cb3inv
1309 
1310  c1m = max(cdm + cam, zero)
1311  c1p = max(cdp + cap, zero)
1312  c10 = c1m + c1p
1313 
1314  ! Update the residual for this cell and store the possible
1315  ! coefficients for the matrix in b1, c1 and d1.
1316 
1317  dw(i, j, k, itu1) = dw(i, j, k, itu1) + c1m * w(i, j - 1, k, itu1) &
1318  - c10 * w(i, j, k, itu1) + c1p * w(i, j + 1, k, itu1)
1319 
1320  end do
1321  end do
1322  end do
1323  !
1324  ! Viscous terms in i-direction.
1325  !
1326  do k = 2, kl
1327  do j = 2, jl
1328  do i = 2, il
1329 
1330  ! Compute the metrics in xi-direction, i.e. along the
1331  ! line i = constant.
1332 
1333  voli = one / vol(i, j, k)
1334  volmi = two / (vol(i, j, k) + vol(i - 1, j, k))
1335  volpi = two / (vol(i, j, k) + vol(i + 1, j, k))
1336 
1337  xm = si(i - 1, j, k, 1) * volmi
1338  ym = si(i - 1, j, k, 2) * volmi
1339  zm = si(i - 1, j, k, 3) * volmi
1340  xp = si(i, j, k, 1) * volpi
1341  yp = si(i, j, k, 2) * volpi
1342  zp = si(i, j, k, 3) * volpi
1343 
1344  xa = half * (si(i, j, k, 1) + si(i - 1, j, k, 1)) * voli
1345  ya = half * (si(i, j, k, 2) + si(i - 1, j, k, 2)) * voli
1346  za = half * (si(i, j, k, 3) + si(i - 1, j, k, 3)) * voli
1347  ttm = xm * xa + ym * ya + zm * za
1348  ttp = xp * xa + yp * ya + zp * za
1349 
1350  ! Computation of the viscous terms in xi-direction; note
1351  ! that cross-derivatives are neglected, i.e. the mesh is
1352  ! assumed to be orthogonal.
1353  ! Furthermore, the grad(nu)**2 has been rewritten as
1354  ! div(nu grad(nu)) - nu div(grad nu) to enhance stability.
1355  ! The second derivative in xi-direction is constructed as
1356  ! the central difference of the first order derivatives, i.e.
1357  ! d^2/dxi^2 = d/dxi (d/dxi i+1/2 - d/dxi i-1/2).
1358  ! In this way the metric can be taken into account.
1359 
1360  ! Compute the diffusion coefficients multiplying the nodes
1361  ! i+1, i and i-1 in the second derivative. Make sure that
1362  ! these coefficients are nonnegative.
1363 
1364  cnud = -rsacb2 * w(i, j, k, itu1) * cb3inv
1365  cam = ttm * cnud
1366  cap = ttp * cnud
1367 
1368  nutm = half * (w(i - 1, j, k, itu1) + w(i, j, k, itu1))
1369  nutp = half * (w(i + 1, j, k, itu1) + w(i, j, k, itu1))
1370  nu = rlv(i, j, k) / w(i, j, k, irho)
1371  num = half * (rlv(i - 1, j, k) / w(i - 1, j, k, irho) + nu)
1372  nup = half * (rlv(i + 1, j, k) / w(i + 1, j, k, irho) + nu)
1373  cdm = (num + (one + rsacb2) * nutm) * ttm * cb3inv
1374  cdp = (nup + (one + rsacb2) * nutp) * ttp * cb3inv
1375 
1376  c1m = max(cdm + cam, zero)
1377  c1p = max(cdp + cap, zero)
1378  c10 = c1m + c1p
1379 
1380  ! Update the residual for this cell and store the possible
1381  ! coefficients for the matrix in b1, c1 and d1.
1382 
1383  dw(i, j, k, itu1) = dw(i, j, k, itu1) + c1m * w(i - 1, j, k, itu1) &
1384  - c10 * w(i, j, k, itu1) + c1p * w(i + 1, j, k, itu1)
1385  end do
1386  end do
1387  end do
1388  end subroutine saviscous
1389 
1390  subroutine saadvection
1391  ! ---------------------------------------------
1392  ! SA Advection
1393  ! ---------------------------------------------
1394  use constants
1395  use inputdiscretization, only: orderturb
1396  use iteration, only: groundlevel
1397  use turbmod, only: secondord
1398  implicit none
1399 
1400  ! Variables for sa Advection
1401  real(kind=realtype) :: uu, dwt, dwtm1, dwtp1, dwti, dwtj, dwtk, qs
1402  real(kind=realtype) :: voli, xa, ya, za
1403  integer(kind=intType), parameter :: nAdv = 1
1404  integer(kind=intType) :: offset, i, j, k, ii, jj
1405 
1406  ! Determine whether or not a second order discretization for the
1407  ! advective terms must be used.
1408  secondord = .false.
1409  if (groundlevel == 1_inttype .and. &
1410  orderturb == secondorder) secondord = .true.
1411 
1412  offset = itu1 - 1
1413  do k = 2, kl
1414  do j = 2, jl
1415  do i = 2, il
1416 
1417  ! Compute the grid velocity if present.
1418  ! It is taken as the average of k and k-1,
1419 
1420  voli = half / vol(i, j, k)
1421  qs = (sfacek(i, j, k) + sfacek(i, j, k - 1)) * voli
1422 
1423  ! Compute the normal velocity, where the normal direction
1424  ! is taken as the average of faces k and k-1.
1425 
1426  xa = (sk(i, j, k, 1) + sk(i, j, k - 1, 1)) * voli
1427  ya = (sk(i, j, k, 2) + sk(i, j, k - 1, 2)) * voli
1428  za = (sk(i, j, k, 3) + sk(i, j, k - 1, 3)) * voli
1429 
1430  uu = xa * w(i, j, k, ivx) + ya * w(i, j, k, ivy) + za * w(i, j, k, ivz) - qs
1431 
1432  ! Determine the situation we are having here, i.e. positive
1433  ! or negative normal velocity.
1434 
1435  velkdir: if (uu > zero) then
1436 
1437  ! Velocity has a component in positive k-direction.
1438  ! Loop over the number of advection equations.
1439 
1440  do ii = 1, nadv
1441 
1442  ! Set the value of jj such that it corresponds to the
1443  ! turbulent entry in w.
1444 
1445  jj = ii + offset
1446 
1447  ! Check whether a first or a second order discretization
1448  ! must be used.
1449 
1450  if (secondord) then
1451 
1452  ! Second order; store the three differences for the
1453  ! discretization of the derivative in k-direction.
1454 
1455  dwtm1 = w(i, j, k - 1, jj) - w(i, j, k - 2, jj)
1456  dwt = w(i, j, k, jj) - w(i, j, k - 1, jj)
1457  dwtp1 = w(i, j, k + 1, jj) - w(i, j, k, jj)
1458 
1459  ! Construct the derivative in this cell center. This
1460  ! is the first order upwind derivative with two
1461  ! nonlinear corrections.
1462 
1463  dwtk = dwt
1464 
1465  if (dwt * dwtp1 > zero) then
1466  if (abs(dwt) < abs(dwtp1)) then
1467  dwtk = dwtk + half * dwt
1468  else
1469  dwtk = dwtk + half * dwtp1
1470  end if
1471  end if
1472 
1473  if (dwt * dwtm1 > zero) then
1474  if (abs(dwt) < abs(dwtm1)) then
1475  dwtk = dwtk - half * dwt
1476  else
1477  dwtk = dwtk - half * dwtm1
1478  end if
1479  end if
1480 
1481  else
1482 
1483  ! 1st order upwind scheme.
1484 
1485  dwtk = w(i, j, k, jj) - w(i, j, k - 1, jj)
1486 
1487  end if
1488 
1489  ! Update the residual. The convective term must be
1490  ! substracted, because it appears on the other side of
1491  ! the equation as the source and viscous terms.
1492 
1493  dw(i, j, k, itu1 + ii - 1) = dw(i, j, k, itu1 + ii - 1) - uu * dwtk
1494  end do
1495 
1496  else velkdir
1497 
1498  ! Velocity has a component in negative k-direction.
1499  ! Loop over the number of advection equations
1500  do ii = 1, nadv
1501 
1502  ! Set the value of jj such that it corresponds to the
1503  ! turbulent entry in w.
1504 
1505  jj = ii + offset
1506 
1507  ! Check whether a first or a second order discretization
1508  ! must be used.
1509 
1510  if (secondord) then
1511 
1512  ! Store the three differences for the discretization of
1513  ! the derivative in k-direction.
1514 
1515  dwtm1 = w(i, j, k, jj) - w(i, j, k - 1, jj)
1516  dwt = w(i, j, k + 1, jj) - w(i, j, k, jj)
1517  dwtp1 = w(i, j, k + 2, jj) - w(i, j, k + 1, jj)
1518 
1519  ! Construct the derivative in this cell center. This is
1520  ! the first order upwind derivative with two nonlinear
1521  ! corrections.
1522 
1523  dwtk = dwt
1524 
1525  if (dwt * dwtp1 > zero) then
1526  if (abs(dwt) < abs(dwtp1)) then
1527  dwtk = dwtk - half * dwt
1528  else
1529  dwtk = dwtk - half * dwtp1
1530  end if
1531  end if
1532 
1533  if (dwt * dwtm1 > zero) then
1534  if (abs(dwt) < abs(dwtm1)) then
1535  dwtk = dwtk + half * dwt
1536  else
1537  dwtk = dwtk + half * dwtm1
1538  end if
1539  end if
1540 
1541  else
1542 
1543  ! 1st order upwind scheme.
1544 
1545  dwtk = w(i, j, k + 1, jj) - w(i, j, k, jj)
1546 
1547  end if
1548 
1549  ! Update the residual. The convective term must be
1550  ! substracted, because it appears on the other side
1551  ! of the equation as the source and viscous terms.
1552 
1553  dw(i, j, k, itu1 + ii - 1) = dw(i, j, k, itu1 + ii - 1) - uu * dwtk
1554  end do
1555  end if velkdir
1556  end do
1557  end do
1558  end do
1559 
1560  !
1561  ! Upwind discretization of the convective term in j (eta)
1562  ! direction. Either the 1st order upwind or the second order
1563  ! fully upwind interpolation scheme, kappa = -1, is used in
1564  ! combination with the minmod limiter.
1565  ! The possible grid velocity must be taken into account.
1566  !
1567  do k = 2, kl
1568  do j = 2, jl
1569  do i = 2, il
1570 
1571  ! Compute the grid velocity if present.
1572  ! It is taken as the average of j and j-1,
1573 
1574  voli = half / vol(i, j, k)
1575  qs = (sfacej(i, j, k) + sfacej(i, j - 1, k)) * voli
1576 
1577  ! Compute the normal velocity, where the normal direction
1578  ! is taken as the average of faces j and j-1.
1579 
1580  xa = (sj(i, j, k, 1) + sj(i, j - 1, k, 1)) * voli
1581  ya = (sj(i, j, k, 2) + sj(i, j - 1, k, 2)) * voli
1582  za = (sj(i, j, k, 3) + sj(i, j - 1, k, 3)) * voli
1583 
1584  uu = xa * w(i, j, k, ivx) + ya * w(i, j, k, ivy) + za * w(i, j, k, ivz) - qs
1585 
1586  ! Determine the situation we are having here, i.e. positive
1587  ! or negative normal velocity.
1588 
1589  veljdir: if (uu > zero) then
1590 
1591  ! Velocity has a component in positive j-direction.
1592  ! Loop over the number of advection equations.
1593  do ii = 1, nadv
1594 
1595  ! Set the value of jj such that it corresponds to the
1596  ! turbulent entry in w.
1597 
1598  jj = ii + offset
1599 
1600  ! Check whether a first or a second order discretization
1601  ! must be used.
1602 
1603  if (secondord) then
1604 
1605  ! Second order; store the three differences for the
1606  ! discretization of the derivative in j-direction.
1607 
1608  dwtm1 = w(i, j - 1, k, jj) - w(i, j - 2, k, jj)
1609  dwt = w(i, j, k, jj) - w(i, j - 1, k, jj)
1610  dwtp1 = w(i, j + 1, k, jj) - w(i, j, k, jj)
1611 
1612  ! Construct the derivative in this cell center. This is
1613  ! the first order upwind derivative with two nonlinear
1614  ! corrections.
1615 
1616  dwtj = dwt
1617 
1618  if (dwt * dwtp1 > zero) then
1619  if (abs(dwt) < abs(dwtp1)) then
1620  dwtj = dwtj + half * dwt
1621  else
1622  dwtj = dwtj + half * dwtp1
1623  end if
1624  end if
1625 
1626  if (dwt * dwtm1 > zero) then
1627  if (abs(dwt) < abs(dwtm1)) then
1628  dwtj = dwtj - half * dwt
1629  else
1630  dwtj = dwtj - half * dwtm1
1631  end if
1632  end if
1633 
1634  else
1635 
1636  ! 1st order upwind scheme.
1637 
1638  dwtj = w(i, j, k, jj) - w(i, j - 1, k, jj)
1639 
1640  end if
1641 
1642  ! Update the residual. The convective term must be
1643  ! substracted, because it appears on the other side of
1644  ! the equation as the source and viscous terms.
1645 
1646  dw(i, j, k, itu1 + ii - 1) = dw(i, j, k, itu1 + ii - 1) - uu * dwtj
1647  end do
1648 
1649  else veljdir
1650 
1651  ! Velocity has a component in negative j-direction.
1652  ! Loop over the number of advection equations.
1653  do ii = 1, nadv
1654 
1655  ! Set the value of jj such that it corresponds to the
1656  ! turbulent entry in w.
1657 
1658  jj = ii + offset
1659 
1660  ! Check whether a first or a second order discretization
1661  ! must be used.
1662 
1663  if (secondord) then
1664 
1665  ! Store the three differences for the discretization of
1666  ! the derivative in j-direction.
1667 
1668  dwtm1 = w(i, j, k, jj) - w(i, j - 1, k, jj)
1669  dwt = w(i, j + 1, k, jj) - w(i, j, k, jj)
1670  dwtp1 = w(i, j + 2, k, jj) - w(i, j + 1, k, jj)
1671 
1672  ! Construct the derivative in this cell center. This is
1673  ! the first order upwind derivative with two nonlinear
1674  ! corrections.
1675 
1676  dwtj = dwt
1677 
1678  if (dwt * dwtp1 > zero) then
1679  if (abs(dwt) < abs(dwtp1)) then
1680  dwtj = dwtj - half * dwt
1681  else
1682  dwtj = dwtj - half * dwtp1
1683  end if
1684  end if
1685 
1686  if (dwt * dwtm1 > zero) then
1687  if (abs(dwt) < abs(dwtm1)) then
1688  dwtj = dwtj + half * dwt
1689  else
1690  dwtj = dwtj + half * dwtm1
1691  end if
1692  end if
1693 
1694  else
1695 
1696  ! 1st order upwind scheme.
1697 
1698  dwtj = w(i, j + 1, k, jj) - w(i, j, k, jj)
1699 
1700  end if
1701 
1702  ! Update the residual. The convective term must be
1703  ! substracted, because it appears on the other side
1704  ! of the equation as the source and viscous terms.
1705 
1706  dw(i, j, k, itu1 + ii - 1) = dw(i, j, k, itu1 + ii - 1) - uu * dwtj
1707  end do
1708  end if veljdir
1709  end do
1710  end do
1711  end do
1712  !
1713  ! Upwind discretization of the convective term in i (xi)
1714  ! direction. Either the 1st order upwind or the second order
1715  ! fully upwind interpolation scheme, kappa = -1, is used in
1716  ! combination with the minmod limiter.
1717  ! The possible grid velocity must be taken into account.
1718  !
1719  qs = zero
1720  do k = 2, kl
1721  do j = 2, jl
1722  do i = 2, il
1723  ! Compute the grid velocity if present.
1724  ! It is taken as the average of i and i-1,
1725 
1726  voli = half / vol(i, j, k)
1727  qs = (sfacei(i, j, k) + sfacei(i - 1, j, k)) * voli
1728 
1729  ! Compute the normal velocity, where the normal direction
1730  ! is taken as the average of faces i and i-1.
1731 
1732  xa = (si(i, j, k, 1) + si(i - 1, j, k, 1)) * voli
1733  ya = (si(i, j, k, 2) + si(i - 1, j, k, 2)) * voli
1734  za = (si(i, j, k, 3) + si(i - 1, j, k, 3)) * voli
1735 
1736  uu = xa * w(i, j, k, ivx) + ya * w(i, j, k, ivy) + za * w(i, j, k, ivz) - qs
1737 
1738  ! Determine the situation we are having here, i.e. positive
1739  ! or negative normal velocity.
1740 
1741  velidir: if (uu > zero) then
1742 
1743  ! Velocity has a component in positive i-direction.
1744  ! Loop over the number of advection equations.
1745  do ii = 1, nadv
1746 
1747  ! Set the value of jj such that it corresponds to the
1748  ! turbulent entry in w.
1749 
1750  jj = ii + offset
1751 
1752  ! Check whether a first or a second order discretization
1753  ! must be used.
1754 
1755  if (secondord) then
1756 
1757  ! Second order; store the three differences for the
1758  ! discretization of the derivative in i-direction.
1759 
1760  dwtm1 = w(i - 1, j, k, jj) - w(i - 2, j, k, jj)
1761  dwt = w(i, j, k, jj) - w(i - 1, j, k, jj)
1762  dwtp1 = w(i + 1, j, k, jj) - w(i, j, k, jj)
1763 
1764  ! Construct the derivative in this cell center. This is
1765  ! the first order upwind derivative with two nonlinear
1766  ! corrections.
1767 
1768  dwti = dwt
1769 
1770  if (dwt * dwtp1 > zero) then
1771  if (abs(dwt) < abs(dwtp1)) then
1772  dwti = dwti + half * dwt
1773  else
1774  dwti = dwti + half * dwtp1
1775  end if
1776  end if
1777 
1778  if (dwt * dwtm1 > zero) then
1779  if (abs(dwt) < abs(dwtm1)) then
1780  dwti = dwti - half * dwt
1781  else
1782  dwti = dwti - half * dwtm1
1783  end if
1784  end if
1785 
1786  else
1787 
1788  ! 1st order upwind scheme.
1789 
1790  dwti = w(i, j, k, jj) - w(i - 1, j, k, jj)
1791 
1792  end if
1793 
1794  ! Update the residual. The convective term must be
1795  ! substracted, because it appears on the other side of
1796  ! the equation as the source and viscous terms.
1797 
1798  dw(i, j, k, itu1 + ii - 1) = dw(i, j, k, itu1 + ii - 1) - uu * dwti
1799  end do
1800 
1801  else velidir
1802 
1803  ! Velocity has a component in negative i-direction.
1804  ! Loop over the number of advection equations.
1805  do ii = 1, nadv
1806 
1807  ! Set the value of jj such that it corresponds to the
1808  ! turbulent entry in w.
1809 
1810  jj = ii + offset
1811 
1812  ! Check whether a first or a second order discretization
1813  ! must be used.
1814 
1815  if (secondord) then
1816 
1817  ! Second order; store the three differences for the
1818  ! discretization of the derivative in i-direction.
1819 
1820  dwtm1 = w(i, j, k, jj) - w(i - 1, j, k, jj)
1821  dwt = w(i + 1, j, k, jj) - w(i, j, k, jj)
1822  dwtp1 = w(i + 2, j, k, jj) - w(i + 1, j, k, jj)
1823 
1824  ! Construct the derivative in this cell center. This is
1825  ! the first order upwind derivative with two nonlinear
1826  ! corrections.
1827 
1828  dwti = dwt
1829 
1830  if (dwt * dwtp1 > zero) then
1831  if (abs(dwt) < abs(dwtp1)) then
1832  dwti = dwti - half * dwt
1833  else
1834  dwti = dwti - half * dwtp1
1835  end if
1836  end if
1837 
1838  if (dwt * dwtm1 > zero) then
1839  if (abs(dwt) < abs(dwtm1)) then
1840  dwti = dwti + half * dwt
1841  else
1842  dwti = dwti + half * dwtm1
1843  end if
1844  end if
1845 
1846  else
1847 
1848  ! 1st order upwind scheme.
1849 
1850  dwti = w(i + 1, j, k, jj) - w(i, j, k, jj)
1851 
1852  end if
1853 
1854  ! Update the residual. The convective term must be
1855  ! substracted, because it appears on the other side
1856  ! of the equation as the source and viscous terms.
1857 
1858  dw(i, j, k, itu1 + ii - 1) = dw(i, j, k, itu1 + ii - 1) - uu * dwti
1859 
1860  ! Update the central jacobian. First the term which is
1861  ! always present, i.e. -uu.
1862  end do
1863 
1864  end if velidir
1865  end do
1866  end do
1867  end do
1868  end subroutine saadvection
1869 
1870  subroutine saresscale
1871 
1872  !
1873  ! Multiply the residual by the volume and store this in dw; this
1874  ! * is done for monitoring reasons only. The multiplication with the
1875  ! * volume is present to be consistent with the flow residuals; also
1876  ! the negative value is taken, again to be consistent with the
1877  ! * flow equations. Also multiply by iblank so that no updates occur
1878  ! in holes or the overset boundary.
1879  use constants
1880  implicit none
1881 
1882  ! Local variables
1883  integer(kind=intType) :: i, j, k, ii
1884  real(kind=realtype) :: rblank
1885 
1886  do k = 2, kl
1887  do j = 2, jl
1888  do i = 2, il
1889  rblank = max(real(iblank(i, j, k), realtype), zero)
1890  dw(i, j, k, itu1) = -volref(i, j, k) * dw(i, j, k, itu1) * rblank
1891  end do
1892  end do
1893  end do
1894 
1895  end subroutine saresscale
1896 
1897  subroutine timestep(updateDtl)
1898  ! ---------------------------------------------
1899  ! Spectral Radius
1900  ! ---------------------------------------------
1901 
1902  use constants
1903  use blockpointers, only: sectionid
1905  use inputphysics, only: equationmode
1907  use section, only: sections
1909 
1910  implicit none
1911 
1912  ! Input
1913  logical, intent(in), optional :: updateDtl
1914 
1915  ! Local parameters.
1916  real(kind=realtype), parameter :: b = 2.0_realtype
1917 
1918  ! Variables for spectral Radius
1919  real(kind=realtype) :: plim, rlim, clim2
1920  real(kind=realtype) :: cc2, qsi, qsj, qsk, sx, sy, sz, rmu
1921  real(kind=realtype) :: ri, rj, rk, rij, rjk, rki
1922  real(kind=realtype) :: vsi, vsj, vsk, rfl, dpi, dpj, dpk
1923  real(kind=realtype) :: sface, tmp, uux, uuy, uuz
1924  logical :: doScaling, updateDt
1925  integer(kind=intType) :: i, j, k
1926 
1927  updatedt = .false.
1928  if (present(updatedtl)) then
1929  updatedt = .true.
1930  end if
1931 
1932  ! Set the value of plim. To be fully consistent this must have
1933  ! the dimension of a pressure. Therefore a fraction of pInfCorr
1934  ! is used. Idem for rlim; compute clim2 as well.
1935 
1936  plim = 0.001_realtype * pinfcorr
1937  rlim = 0.001_realtype * rhoinf
1938  clim2 = 0.000001_realtype * gammainf * pinfcorr / rhoinf
1939  doscaling = .true.
1940 
1941  ! Initialize sFace to zero. This value will be used if the
1942  ! block is not moving.
1943 
1944  sface = zero
1945  !
1946  ! Inviscid contribution, depending on the preconditioner.
1947  ! Compute the cell centered values of the spectral radii.
1948  !
1949  ! Note: DON'T change the ranges for i. It will mess up dtl.
1950  ! we don't copy the spectral-radii and dtl to keep the
1951  ! code simple, therefore this loop needs the full single
1952  ! halo range.
1953  do k = 1, ke
1954  do j = 1, je
1955  do i = 1, ie
1956 
1957  ! Compute the velocities and speed of sound squared.
1958 
1959  uux = w(i, j, k, ivx)
1960  uuy = w(i, j, k, ivy)
1961  uuz = w(i, j, k, ivz)
1962  cc2 = gamma(i, j, k) * p(i, j, k) / w(i, j, k, irho)
1963  cc2 = max(cc2, clim2)
1964 
1965  ! Set the dot product of the grid velocity and the
1966  ! normal in i-direction for a moving face. To avoid
1967  ! a number of multiplications by 0.5 simply the sum
1968  ! is taken.
1969 
1970  sface = sfacei(i - 1, j, k) + sfacei(i, j, k)
1971 
1972  ! Spectral radius in i-direction.
1973 
1974  sx = si(i - 1, j, k, 1) + si(i, j, k, 1)
1975  sy = si(i - 1, j, k, 2) + si(i, j, k, 2)
1976  sz = si(i - 1, j, k, 3) + si(i, j, k, 3)
1977 
1978  qsi = uux * sx + uuy * sy + uuz * sz - sface
1979 
1980  ri = half * (abs(qsi) &
1981  + acousticscalefactor * sqrt(cc2 * (sx**2 + sy**2 + sz**2)))
1982 
1983  ! The grid velocity in j-direction.
1984  sface = sfacej(i, j - 1, k) + sfacej(i, j, k)
1985 
1986  ! Spectral radius in j-direction.
1987 
1988  sx = sj(i, j - 1, k, 1) + sj(i, j, k, 1)
1989  sy = sj(i, j - 1, k, 2) + sj(i, j, k, 2)
1990  sz = sj(i, j - 1, k, 3) + sj(i, j, k, 3)
1991 
1992  qsj = uux * sx + uuy * sy + uuz * sz - sface
1993 
1994  rj = half * (abs(qsj) &
1995  + acousticscalefactor * sqrt(cc2 * (sx**2 + sy**2 + sz**2)))
1996 
1997  ! The grid velocity in k-direction.
1998  sface = sfacek(i, j, k - 1) + sfacek(i, j, k)
1999 
2000  ! Spectral radius in k-direction.
2001 
2002  sx = sk(i, j, k - 1, 1) + sk(i, j, k, 1)
2003  sy = sk(i, j, k - 1, 2) + sk(i, j, k, 2)
2004  sz = sk(i, j, k - 1, 3) + sk(i, j, k, 3)
2005 
2006  qsk = uux * sx + uuy * sy + uuz * sz - sface
2007 
2008  rk = half * (abs(qsk) &
2009  + acousticscalefactor * sqrt(cc2 * (sx**2 + sy**2 + sz**2)))
2010 
2011  ! Store in tdl if required
2012  if (updatedt) then
2013  dtl(i, j, k) = ri + rj + rk
2014  end if
2015 
2016  ! Avoid division by zero by clipping radi, radJ and
2017  ! radK.
2018 
2019  ri = max(ri, eps)
2020  rj = max(rj, eps)
2021  rk = max(rk, eps)
2022 
2023  ! Compute the scaling in the three coordinate
2024  ! directions.
2025 
2026  rij = (ri / rj)**adis
2027  rjk = (rj / rk)**adis
2028  rki = (rk / ri)**adis
2029 
2030  ! Create the scaled versions of the aspect ratios.
2031  ! Note that the multiplication is done with radi, radJ
2032  ! and radK, such that the influence of the clipping
2033  ! is negligible.
2034 
2035  radi(i, j, k) = ri * (one + one / rij + rki)
2036  radj(i, j, k) = rj * (one + one / rjk + rij)
2037  radk(i, j, k) = rk * (one + one / rki + rjk)
2038  end do
2039  end do
2040  end do
2041 
2042  ! The rest is only necessary if the timeStep needs to be computed
2043  if (updatedt) then
2044 
2045  viscousterm: if (viscous) then
2046 
2047  ! Loop over the owned cell centers.
2048 
2049  do k = 2, kl
2050  do j = 2, jl
2051  do i = 2, il
2052 
2053  ! Compute the effective viscosity coefficient. The
2054  ! factor 0.5 is a combination of two things. In the
2055  ! standard central discretization of a second
2056  ! derivative there is a factor 2 multiplying the
2057  ! central node. However in the code below not the
2058  ! average but the sum of the left and the right face
2059  ! is taken and squared. This leads to a factor 4.
2060  ! Combining both effects leads to 0.5. Furthermore,
2061  ! it is divided by the volume and density to obtain
2062  ! the correct dimensions and multiplied by the
2063  ! non-dimensional factor factVis.
2064 
2065  rmu = rlv(i, j, k)
2066  rmu = rmu + rev(i, j, k)
2067  rmu = half * rmu / (w(i, j, k, irho) * vol(i, j, k))
2068 
2069  ! Add the viscous contribution in i-direction to the
2070  ! (inverse) of the time step.
2071 
2072  sx = si(i, j, k, 1) + si(i - 1, j, k, 1)
2073  sy = si(i, j, k, 2) + si(i - 1, j, k, 2)
2074  sz = si(i, j, k, 3) + si(i - 1, j, k, 3)
2075 
2076  vsi = rmu * (sx * sx + sy * sy + sz * sz)
2077  dtl(i, j, k) = dtl(i, j, k) + vsi
2078 
2079  ! Add the viscous contribution in j-direction to the
2080  ! (inverse) of the time step.
2081 
2082  sx = sj(i, j, k, 1) + sj(i, j - 1, k, 1)
2083  sy = sj(i, j, k, 2) + sj(i, j - 1, k, 2)
2084  sz = sj(i, j, k, 3) + sj(i, j - 1, k, 3)
2085 
2086  vsj = rmu * (sx * sx + sy * sy + sz * sz)
2087  dtl(i, j, k) = dtl(i, j, k) + vsj
2088 
2089  ! Add the viscous contribution in k-direction to the
2090  ! (inverse) of the time step.
2091 
2092  sx = sk(i, j, k, 1) + sk(i, j, k - 1, 1)
2093  sy = sk(i, j, k, 2) + sk(i, j, k - 1, 2)
2094  sz = sk(i, j, k, 3) + sk(i, j, k - 1, 3)
2095 
2096  vsk = rmu * (sx * sx + sy * sy + sz * sz)
2097  dtl(i, j, k) = dtl(i, j, k) + vsk
2098 
2099  end do
2100  end do
2101  end do
2102  end if viscousterm
2103 
2104  ! For the spectral mode an additional term term must be
2105  ! taken into account, which corresponds to the contribution
2106  ! of the highest frequency.
2107 
2108  if (equationmode == timespectral) then
2109 
2110  tmp = ntimeintervalsspectral * pi * timeref &
2111  / sections(sectionid)%timePeriod
2112 
2113  ! Loop over the owned cell centers and add the term.
2114 
2115  do k = 2, kl
2116  do j = 2, jl
2117  do i = 2, il
2118  dtl(i, j, k) = dtl(i, j, k) + tmp * vol(i, j, k)
2119  end do
2120  end do
2121  end do
2122 
2123  end if
2124 
2125  ! Currently the inverse of dt/vol is stored in dtl. Invert
2126  ! this value such that the time step per unit cfl number is
2127  ! stored and correct in cases of high gradients.
2128 
2129  do k = 2, kl
2130  do j = 2, jl
2131  do i = 2, il
2132  dpi = abs(p(i + 1, j, k) - two * p(i, j, k) + p(i - 1, j, k)) &
2133  / (p(i + 1, j, k) + two * p(i, j, k) + p(i - 1, j, k) + plim)
2134  dpj = abs(p(i, j + 1, k) - two * p(i, j, k) + p(i, j - 1, k)) &
2135  / (p(i, j + 1, k) + two * p(i, j, k) + p(i, j - 1, k) + plim)
2136  dpk = abs(p(i, j, k + 1) - two * p(i, j, k) + p(i, j, k - 1)) &
2137  / (p(i, j, k + 1) + two * p(i, j, k) + p(i, j, k - 1) + plim)
2138  rfl = one / (one + b * (dpi + dpj + dpk))
2139 
2140  dtl(i, j, k) = rfl / dtl(i, j, k)
2141  end do
2142  end do
2143  end do
2144  end if
2145 
2146  end subroutine timestep
2147 
2149 
2150  ! ---------------------------------------------
2151  ! Inviscid central flux
2152  ! ---------------------------------------------
2153  use constants
2155  use flowvarrefstate, only: timeref
2156  use cgnsgrid, only: cgnsdoms
2157  use inputphysics, only: equationmode
2158  implicit none
2159 
2160  ! Variables for inviscid central flux
2161  real(kind=realtype) :: qsp, qsm, rqsp, rqsm, porvel, porflux
2162  real(kind=realtype) :: pa, vnp, vnm, fs, sface
2163  integer(kind=intType) :: i, j, k
2164  real(kind=realtype) :: wwx, wwy, wwz, rvol
2165 
2166  do k = 2, kl
2167  do j = 2, jl
2168  do i = 1, il
2169 
2170  ! Set the dot product of the grid velocity and the
2171  ! normal in i-direction for a moving face.
2172 
2173  sface = sfacei(i, j, k)
2174 
2175  ! Compute the normal velocities of the left and right state.
2176 
2177  vnp = w(i + 1, j, k, ivx) * si(i, j, k, 1) &
2178  + w(i + 1, j, k, ivy) * si(i, j, k, 2) &
2179  + w(i + 1, j, k, ivz) * si(i, j, k, 3)
2180  vnm = w(i, j, k, ivx) * si(i, j, k, 1) &
2181  + w(i, j, k, ivy) * si(i, j, k, 2) &
2182  + w(i, j, k, ivz) * si(i, j, k, 3)
2183  ! Set the values of the porosities for this face.
2184  ! porVel defines the porosity w.r.t. velocity;
2185  ! porFlux defines the porosity w.r.t. the entire flux.
2186  ! The latter is only zero for a discontinuous block
2187  ! boundary that must be treated conservatively.
2188  ! The default value of porFlux is 0.5, such that the
2189  ! correct central flux is scattered to both cells.
2190  ! In case of a boundFlux the normal velocity is set
2191  ! to sFace.
2192 
2193  porvel = one
2194  porflux = half
2195  if (pori(i, j, k) == noflux) porflux = zero
2196  if (pori(i, j, k) == boundflux) then
2197  porvel = zero
2198  vnp = sface
2199  vnm = sface
2200  end if
2201 
2202  ! Incorporate porFlux in porVel.
2203 
2204  porvel = porvel * porflux
2205 
2206  ! Compute the normal velocities relative to the grid for
2207  ! the face as well as the mass fluxes.
2208 
2209  qsp = (vnp - sface) * porvel
2210  qsm = (vnm - sface) * porvel
2211 
2212  rqsp = qsp * w(i + 1, j, k, irho)
2213  rqsm = qsm * w(i, j, k, irho)
2214 
2215  ! Compute the sum of the pressure multiplied by porFlux.
2216  ! For the default value of porFlux, 0.5, this leads to
2217  ! the average pressure.
2218 
2219  pa = porflux * (p(i + 1, j, k) + p(i, j, k))
2220 
2221  ! Compute the fluxes and scatter them to the cells
2222  ! i,j,k and i+1,j,k. Store the density flux in the
2223  ! mass flow of the appropriate sliding mesh interface.
2224 
2225  fs = rqsp + rqsm
2226  dw(i + 1, j, k, irho) = dw(i + 1, j, k, irho) - fs
2227  dw(i, j, k, irho) = dw(i, j, k, irho) + fs
2228 
2229  fs = rqsp * w(i + 1, j, k, ivx) + rqsm * w(i, j, k, ivx) &
2230  + pa * si(i, j, k, 1)
2231  dw(i + 1, j, k, imx) = dw(i + 1, j, k, imx) - fs
2232  dw(i, j, k, imx) = dw(i, j, k, imx) + fs
2233 
2234  fs = rqsp * w(i + 1, j, k, ivy) + rqsm * w(i, j, k, ivy) &
2235  + pa * si(i, j, k, 2)
2236  dw(i + 1, j, k, imy) = dw(i + 1, j, k, imy) - fs
2237  dw(i, j, k, imy) = dw(i, j, k, imy) + fs
2238 
2239  fs = rqsp * w(i + 1, j, k, ivz) + rqsm * w(i, j, k, ivz) &
2240  + pa * si(i, j, k, 3)
2241  dw(i + 1, j, k, imz) = dw(i + 1, j, k, imz) - fs
2242  dw(i, j, k, imz) = dw(i, j, k, imz) + fs
2243 
2244  fs = qsp * w(i + 1, j, k, irhoe) + qsm * w(i, j, k, irhoe) &
2245  + porflux * (vnp * p(i + 1, j, k) + vnm * p(i, j, k))
2246  dw(i + 1, j, k, irhoe) = dw(i + 1, j, k, irhoe) - fs
2247  dw(i, j, k, irhoe) = dw(i, j, k, irhoe) + fs
2248  end do
2249  end do
2250  end do
2251 
2252  do k = 2, kl
2253  do j = 1, jl
2254  do i = 2, il
2255 
2256  ! Set the dot product of the grid velocity and the
2257  ! normal in j-direction for a moving face.
2258 
2259  sface = sfacej(i, j, k)
2260 
2261  ! Compute the normal velocities of the left and right state.
2262 
2263  vnp = w(i, j + 1, k, ivx) * sj(i, j, k, 1) &
2264  + w(i, j + 1, k, ivy) * sj(i, j, k, 2) &
2265  + w(i, j + 1, k, ivz) * sj(i, j, k, 3)
2266  vnm = w(i, j, k, ivx) * sj(i, j, k, 1) &
2267  + w(i, j, k, ivy) * sj(i, j, k, 2) &
2268  + w(i, j, k, ivz) * sj(i, j, k, 3)
2269 
2270  ! Set the values of the porosities for this face.
2271  ! porVel defines the porosity w.r.t. velocity;
2272  ! porFlux defines the porosity w.r.t. the entire flux.
2273  ! The latter is only zero for a discontinuous block
2274  ! boundary that must be treated conservatively.
2275  ! The default value of porFlux is 0.5, such that the
2276  ! correct central flux is scattered to both cells.
2277  ! In case of a boundFlux the normal velocity is set
2278  ! to sFace.
2279 
2280  porvel = one
2281  porflux = half
2282  if (porj(i, j, k) == noflux) porflux = zero
2283  if (porj(i, j, k) == boundflux) then
2284  porvel = zero
2285  vnp = sface
2286  vnm = sface
2287  end if
2288 
2289  ! Incorporate porFlux in porVel.
2290 
2291  porvel = porvel * porflux
2292 
2293  ! Compute the normal velocities for the face as well as the
2294  ! mass fluxes.
2295 
2296  qsp = (vnp - sface) * porvel
2297  qsm = (vnm - sface) * porvel
2298 
2299  rqsp = qsp * w(i, j + 1, k, irho)
2300  rqsm = qsm * w(i, j, k, irho)
2301 
2302  ! Compute the sum of the pressure multiplied by porFlux.
2303  ! For the default value of porFlux, 0.5, this leads to
2304  ! the average pressure.
2305 
2306  pa = porflux * (p(i, j + 1, k) + p(i, j, k))
2307 
2308  ! Compute the fluxes and scatter them to the cells
2309  ! i,j,k and i,j+1,k. Store the density flux in the
2310  ! mass flow of the appropriate sliding mesh interface.
2311 
2312  fs = rqsp + rqsm
2313  dw(i, j + 1, k, irho) = dw(i, j + 1, k, irho) - fs
2314  dw(i, j, k, irho) = dw(i, j, k, irho) + fs
2315 
2316  fs = rqsp * w(i, j + 1, k, ivx) + rqsm * w(i, j, k, ivx) &
2317  + pa * sj(i, j, k, 1)
2318  dw(i, j + 1, k, imx) = dw(i, j + 1, k, imx) - fs
2319  dw(i, j, k, imx) = dw(i, j, k, imx) + fs
2320 
2321  fs = rqsp * w(i, j + 1, k, ivy) + rqsm * w(i, j, k, ivy) &
2322  + pa * sj(i, j, k, 2)
2323  dw(i, j + 1, k, imy) = dw(i, j + 1, k, imy) - fs
2324  dw(i, j, k, imy) = dw(i, j, k, imy) + fs
2325 
2326  fs = rqsp * w(i, j + 1, k, ivz) + rqsm * w(i, j, k, ivz) &
2327  + pa * sj(i, j, k, 3)
2328  dw(i, j + 1, k, imz) = dw(i, j + 1, k, imz) - fs
2329  dw(i, j, k, imz) = dw(i, j, k, imz) + fs
2330 
2331  fs = qsp * w(i, j + 1, k, irhoe) + qsm * w(i, j, k, irhoe) &
2332  + porflux * (vnp * p(i, j + 1, k) + vnm * p(i, j, k))
2333  dw(i, j + 1, k, irhoe) = dw(i, j + 1, k, irhoe) - fs
2334  dw(i, j, k, irhoe) = dw(i, j, k, irhoe) + fs
2335  end do
2336  end do
2337  end do
2338 
2339  do k = 1, kl
2340  do j = 2, jl
2341  do i = 2, il
2342 
2343  ! Set the dot product of the grid velocity and the
2344  ! normal in k-direction for a moving face.
2345 
2346  sface = sfacek(i, j, k)
2347 
2348  ! Compute the normal velocities of the left and right state.
2349 
2350  vnp = w(i, j, k + 1, ivx) * sk(i, j, k, 1) &
2351  + w(i, j, k + 1, ivy) * sk(i, j, k, 2) &
2352  + w(i, j, k + 1, ivz) * sk(i, j, k, 3)
2353  vnm = w(i, j, k, ivx) * sk(i, j, k, 1) &
2354  + w(i, j, k, ivy) * sk(i, j, k, 2) &
2355  + w(i, j, k, ivz) * sk(i, j, k, 3)
2356 
2357  ! Set the values of the porosities for this face.
2358  ! porVel defines the porosity w.r.t. velocity;
2359  ! porFlux defines the porosity w.r.t. the entire flux.
2360  ! The latter is only zero for a discontinuous block
2361  ! block boundary that must be treated conservatively.
2362  ! The default value of porFlux is 0.5, such that the
2363  ! correct central flux is scattered to both cells.
2364  ! In case of a boundFlux the normal velocity is set
2365  ! to sFace.
2366 
2367  porvel = one
2368  porflux = half
2369 
2370  if (pork(i, j, k) == noflux) porflux = zero
2371  if (pork(i, j, k) == boundflux) then
2372  porvel = zero
2373  vnp = sface
2374  vnm = sface
2375  end if
2376 
2377  ! Incorporate porFlux in porVel.
2378 
2379  porvel = porvel * porflux
2380 
2381  ! Compute the normal velocities for the face as well as the
2382  ! mass fluxes.
2383 
2384  qsp = (vnp - sface) * porvel
2385  qsm = (vnm - sface) * porvel
2386 
2387  rqsp = qsp * w(i, j, k + 1, irho)
2388  rqsm = qsm * w(i, j, k, irho)
2389 
2390  ! Compute the sum of the pressure multiplied by porFlux.
2391  ! For the default value of porFlux, 0.5, this leads to
2392  ! the average pressure.
2393 
2394  pa = porflux * (p(i, j, k + 1) + p(i, j, k))
2395 
2396  ! Compute the fluxes and scatter them to the cells
2397  ! i,j,k and i,j,k+1. Store the density flux in the
2398  ! mass flow of the appropriate sliding mesh interface.
2399 
2400  fs = rqsp + rqsm
2401  dw(i, j, k + 1, irho) = dw(i, j, k + 1, irho) - fs
2402  dw(i, j, k, irho) = dw(i, j, k, irho) + fs
2403 
2404  fs = rqsp * w(i, j, k + 1, ivx) + rqsm * w(i, j, k, ivx) &
2405  + pa * sk(i, j, k, 1)
2406  dw(i, j, k + 1, imx) = dw(i, j, k + 1, imx) - fs
2407  dw(i, j, k, imx) = dw(i, j, k, imx) + fs
2408 
2409  fs = rqsp * w(i, j, k + 1, ivy) + rqsm * w(i, j, k, ivy) &
2410  + pa * sk(i, j, k, 2)
2411  dw(i, j, k + 1, imy) = dw(i, j, k + 1, imy) - fs
2412  dw(i, j, k, imy) = dw(i, j, k, imy) + fs
2413 
2414  fs = rqsp * w(i, j, k + 1, ivz) + rqsm * w(i, j, k, ivz) &
2415  + pa * sk(i, j, k, 3)
2416  dw(i, j, k + 1, imz) = dw(i, j, k + 1, imz) - fs
2417  dw(i, j, k, imz) = dw(i, j, k, imz) + fs
2418 
2419  fs = qsp * w(i, j, k + 1, irhoe) + qsm * w(i, j, k, irhoe) &
2420  + porflux * (vnp * p(i, j, k + 1) + vnm * p(i, j, k))
2421  dw(i, j, k + 1, irhoe) = dw(i, j, k + 1, irhoe) - fs
2422  dw(i, j, k, irhoe) = dw(i, j, k, irhoe) + fs
2423 
2424  end do
2425  end do
2426  end do
2427 
2428  rotation: if (blockismoving .and. equationmode == steady) then
2429 
2430  ! Compute the three nonDimensional angular velocities.
2431 
2432  wwx = timeref * cgnsdoms(nbkglobal)%rotRate(1)
2433  wwy = timeref * cgnsdoms(nbkglobal)%rotRate(2)
2434  wwz = timeref * cgnsdoms(nbkglobal)%rotRate(3)
2435 
2436  ! Loop over the internal cells of this block to compute the
2437  ! rotational terms for the momentum equations.
2438  do k = 2, kl
2439  do j = 2, jl
2440  do i = 2, il
2441  rvol = w(i, j, k, irho) * vol(i, j, k)
2442  dw(i, j, k, imx) = dw(i, j, k, imx) &
2443  + rvol * (wwy * w(i, j, k, ivz) - wwz * w(i, j, k, ivy))
2444  dw(i, j, k, imy) = dw(i, j, k, imy) &
2445  + rvol * (wwz * w(i, j, k, ivx) - wwx * w(i, j, k, ivz))
2446  dw(i, j, k, imz) = dw(i, j, k, imz) &
2447  + rvol * (wwx * w(i, j, k, ivy) - wwy * w(i, j, k, ivx))
2448  end do
2449  end do
2450  end do
2451  end if rotation
2452 
2453  end subroutine inviscidcentralflux
2454 
2456  !
2457  ! inviscidDissFluxMatrix computes the matrix artificial
2458  ! dissipation term. Instead of the spectral radius, as used in
2459  ! the scalar dissipation scheme, the absolute value of the flux
2460  ! jacobian is used. This leads to a less diffusive and
2461  ! consequently more accurate scheme. It is assumed that the
2462  ! pointers in blockPointers already point to the correct block.
2463  !
2464  use constants
2465  use flowvarrefstate, only: pinfcorr
2466  use inputdiscretization, only: vis2, vis4
2467  use inputphysics, only: equations
2468  use iteration, only: rfil
2469  use utils, only: getcorrectfork, mydim
2470  implicit none
2471  !
2472  ! Local parameters.
2473  !
2474  real(kind=realtype), parameter :: dpmax = 0.25_realtype
2475  real(kind=realtype), parameter :: epsacoustic = 0.25_realtype
2476  real(kind=realtype), parameter :: epsshear = 0.025_realtype
2477  real(kind=realtype), parameter :: omega = 0.5_realtype
2478  real(kind=realtype), parameter :: oneminomega = one - omega
2479  !
2480  ! Local variables.
2481  !
2482  integer(kind=intType) :: i, j, k, ind, ii
2483 
2484  real(kind=realtype) :: plim, sface
2485  real(kind=realtype) :: sfil, fis2, fis4
2486  real(kind=realtype) :: gammaavg, gm1, ovgm1, gm53
2487  real(kind=realtype) :: ppor, rrad, dis2, dis4
2488  real(kind=realtype) :: dp1, dp2, tmp, fs
2489  real(kind=realtype) :: ddw1, ddw2, ddw3, ddw4, ddw5, ddw6
2490  real(kind=realtype) :: dr, dru, drv, drw, dre, drk, sx, sy, sz
2491  real(kind=realtype) :: uavg, vavg, wavg, a2avg, aavg, havg
2492  real(kind=realtype) :: alphaavg, unavg, ovaavg, ova2avg
2493  real(kind=realtype) :: kavg, lam1, lam2, lam3, area
2494  real(kind=realtype) :: abv1, abv2, abv3, abv4, abv5, abv6, abv7
2495  logical :: correctForK
2496 
2497  ! Set the value of plim. To be fully consistent this must have
2498  ! the dimension of a pressure. Therefore a fraction of pInfCorr
2499  ! is used.
2500 
2501  plim = 0.001_realtype * pinfcorr
2502 
2503  ! Determine whether or not the total energy must be corrected
2504  ! for the presence of the turbulent kinetic energy.
2505 
2506  correctfork = getcorrectfork()
2507 
2508  ! Initialize sface to zero. This value will be used if the
2509  ! block is not moving.
2510 
2511  sface = zero
2512 
2513  ! Set a couple of constants for the scheme.
2514 
2515  fis2 = rfil * vis2
2516  fis4 = rfil * vis4
2517  sfil = one - rfil
2518 
2519  ! Initialize the dissipative residual to a certain times,
2520  ! possibly zero, the previously stored value.
2521 
2522  fw = sfil * fw
2523 
2524  ! Compute the pressure sensor for each cell, in each direction:
2525  do k = 1, ke
2526  do j = 1, je
2527  do i = singlehalostart, ie
2528  dss(i, j, k, 1) = abs((p(i + 1, j, k) - two * p(i, j, k) + p(i - 1, j, k)) &
2529  / (omega * (p(i + 1, j, k) + two * p(i, j, k) + p(i - 1, j, k)) &
2530  + oneminomega * (abs(p(i + 1, j, k) - p(i, j, k)) &
2531  + abs(p(i, j, k) - p(i - 1, j, k))) + plim))
2532 
2533  dss(i, j, k, 2) = abs((p(i, j + 1, k) - two * p(i, j, k) + p(i, j - 1, k)) &
2534  / (omega * (p(i, j + 1, k) + two * p(i, j, k) + p(i, j - 1, k)) &
2535  + oneminomega * (abs(p(i, j + 1, k) - p(i, j, k)) &
2536  + abs(p(i, j, k) - p(i, j - 1, k))) + plim))
2537 
2538  dss(i, j, k, 3) = abs((p(i, j, k + 1) - two * p(i, j, k) + p(i, j, k - 1)) &
2539  / (omega * (p(i, j, k + 1) + two * p(i, j, k) + p(i, j, k - 1)) &
2540  + oneminomega * (abs(p(i, j, k + 1) - p(i, j, k)) &
2541  + abs(p(i, j, k) - p(i, j, k - 1))) + plim))
2542  end do
2543  end do
2544  end do
2545  !
2546  ! Dissipative fluxes in the i-direction.
2547  !
2548  do k = 2, kl
2549  do j = 2, jl
2550  do i = 1, il
2551 
2552  ! Compute the dissipation coefficients for this face.
2553 
2554  ppor = zero
2555  if (pori(i, j, k) == normalflux) ppor = one
2556  dis2 = ppor * fis2 * min(dpmax, max(dss(i, j, k, 1), dss(i + 1, j, k, 1)))
2557  dis4 = dim(ppor * fis4, dis2)
2558 
2559  ! Construct the vector of the first and third differences
2560  ! multiplied by the appropriate constants.
2561 
2562  ddw1 = w(i + 1, j, k, irho) - w(i, j, k, irho)
2563  dr = dis2 * ddw1 &
2564  - dis4 * (w(i + 2, j, k, irho) - w(i - 1, j, k, irho) - three * ddw1)
2565 
2566  ddw2 = w(i + 1, j, k, irho) * w(i + 1, j, k, ivx) &
2567  - w(i, j, k, irho) * w(i, j, k, ivx)
2568  dru = dis2 * ddw2 &
2569  - dis4 * (w(i + 2, j, k, irho) * w(i + 2, j, k, ivx) &
2570  - w(i - 1, j, k, irho) * w(i - 1, j, k, ivx) - three * ddw2)
2571 
2572  ddw3 = w(i + 1, j, k, irho) * w(i + 1, j, k, ivy) &
2573  - w(i, j, k, irho) * w(i, j, k, ivy)
2574  drv = dis2 * ddw3 &
2575  - dis4 * (w(i + 2, j, k, irho) * w(i + 2, j, k, ivy) &
2576  - w(i - 1, j, k, irho) * w(i - 1, j, k, ivy) - three * ddw3)
2577 
2578  ddw4 = w(i + 1, j, k, irho) * w(i + 1, j, k, ivz) &
2579  - w(i, j, k, irho) * w(i, j, k, ivz)
2580  drw = dis2 * ddw4 &
2581  - dis4 * (w(i + 2, j, k, irho) * w(i + 2, j, k, ivz) &
2582  - w(i - 1, j, k, irho) * w(i - 1, j, k, ivz) - three * ddw4)
2583 
2584  ddw5 = w(i + 1, j, k, irhoe) - w(i, j, k, irhoe)
2585  dre = dis2 * ddw5 &
2586  - dis4 * (w(i + 2, j, k, irhoe) - w(i - 1, j, k, irhoe) - three * ddw5)
2587 
2588  ! In case a k-equation is present, compute the difference
2589  ! of rhok and store the average value of k. If not present,
2590  ! set both these values to zero, such that later on no
2591  ! decision needs to be made anymore.
2592  drk = zero
2593  kavg = zero
2594 
2595  if (correctfork) then
2596  ddw6 = w(i + 1, j, k, irho) * w(i + 1, j, k, itu1) &
2597  - w(i, j, k, irho) * w(i, j, k, itu1)
2598  drk = dis2 * ddw6 &
2599  - dis4 * (w(i + 2, j, k, irho) * w(i + 2, j, k, itu1) &
2600  - w(i - 1, j, k, irho) * w(i - 1, j, k, itu1) - three * ddw6)
2601 
2602  kavg = half * (w(i, j, k, itu1) + w(i + 1, j, k, itu1))
2603  end if
2604 
2605  ! Compute the average value of gamma and compute some
2606  ! expressions in which it occurs.
2607 
2608  gammaavg = half * (gamma(i + 1, j, k) + gamma(i, j, k))
2609  gm1 = gammaavg - one
2610  ovgm1 = one / gm1
2611  gm53 = gammaavg - five * third
2612 
2613  ! Compute the average state at the interface.
2614 
2615  uavg = half * (w(i + 1, j, k, ivx) + w(i, j, k, ivx))
2616  vavg = half * (w(i + 1, j, k, ivy) + w(i, j, k, ivy))
2617  wavg = half * (w(i + 1, j, k, ivz) + w(i, j, k, ivz))
2618  a2avg = half * (gamma(i + 1, j, k) * p(i + 1, j, k) / w(i + 1, j, k, irho) &
2619  + gamma(i, j, k) * p(i, j, k) / w(i, j, k, irho))
2620 
2621  area = sqrt(si(i, j, k, 1)**2 + si(i, j, k, 2)**2 + si(i, j, k, 3)**2)
2622  tmp = one / max(1.e-25_realtype, area)
2623  sx = si(i, j, k, 1) * tmp
2624  sy = si(i, j, k, 2) * tmp
2625  sz = si(i, j, k, 3) * tmp
2626 
2627  alphaavg = half * (uavg**2 + vavg**2 + wavg**2)
2628  havg = alphaavg + ovgm1 * (a2avg - gm53 * kavg)
2629  aavg = sqrt(a2avg)
2630  unavg = uavg * sx + vavg * sy + wavg * sz
2631  ovaavg = one / aavg
2632  ova2avg = one / a2avg
2633 
2634  ! The mesh velocity if the face is moving. It must be
2635  ! divided by the area to obtain a true velocity.
2636 
2637  sface = sfacei(i, j, k) * tmp
2638 
2639  ! Compute the absolute values of the three eigenvalues
2640  ! and make sure they don't become zero by cutting them
2641  ! off to a certain minimum.
2642 
2643  lam1 = abs(unavg - sface + aavg)
2644  lam2 = abs(unavg - sface - aavg)
2645  lam3 = abs(unavg - sface)
2646 
2647  rrad = lam3 + aavg
2648 
2649  ! Multiply the eigenvalues by the area to obtain
2650  ! the correct values for the dissipation term.
2651 
2652  lam1 = max(lam1, epsacoustic * rrad) * area
2653  lam2 = max(lam2, epsacoustic * rrad) * area
2654  lam3 = max(lam3, epsshear * rrad) * area
2655 
2656  ! Some abbreviations, which occur quite often in the
2657  ! dissipation terms.
2658 
2659  abv1 = half * (lam1 + lam2)
2660  abv2 = half * (lam1 - lam2)
2661  abv3 = abv1 - lam3
2662 
2663  abv4 = gm1 * (alphaavg * dr - uavg * dru - vavg * drv &
2664  - wavg * drw + dre) - gm53 * drk
2665  abv5 = sx * dru + sy * drv + sz * drw - unavg * dr
2666 
2667  abv6 = abv3 * abv4 * ova2avg + abv2 * abv5 * ovaavg
2668  abv7 = abv2 * abv4 * ovaavg + abv3 * abv5
2669 
2670  ! Compute and scatter the dissipative flux.
2671  ! Density.
2672 
2673  fs = lam3 * dr + abv6
2674  fw(i + 1, j, k, irho) = fw(i + 1, j, k, irho) + fs
2675  fw(i, j, k, irho) = fw(i, j, k, irho) - fs
2676 
2677  ! X-momentum.
2678 
2679  fs = lam3 * dru + uavg * abv6 + sx * abv7
2680  fw(i + 1, j, k, imx) = fw(i + 1, j, k, imx) + fs
2681  fw(i, j, k, imx) = fw(i, j, k, imx) - fs
2682 
2683  ! Y-momentum.
2684 
2685  fs = lam3 * drv + vavg * abv6 + sy * abv7
2686  fw(i + 1, j, k, imy) = fw(i + 1, j, k, imy) + fs
2687  fw(i, j, k, imy) = fw(i, j, k, imy) - fs
2688 
2689  ! Z-momentum.
2690 
2691  fs = lam3 * drw + wavg * abv6 + sz * abv7
2692  fw(i + 1, j, k, imz) = fw(i + 1, j, k, imz) + fs
2693  fw(i, j, k, imz) = fw(i, j, k, imz) - fs
2694 
2695  ! Energy.
2696 
2697  fs = lam3 * dre + havg * abv6 + unavg * abv7
2698  fw(i + 1, j, k, irhoe) = fw(i + 1, j, k, irhoe) + fs
2699  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - fs
2700 
2701  end do
2702  end do
2703  end do
2704  !
2705  ! Dissipative fluxes in the j-direction.
2706  !
2707  do k = 2, kl
2708  do j = 1, jl
2709  do i = 2, il
2710 
2711  ! Compute the dissipation coefficients for this face.
2712 
2713  ppor = zero
2714  if (porj(i, j, k) == normalflux) ppor = one
2715 
2716  dis2 = ppor * fis2 * min(dpmax, max(dss(i, j, k, 2), dss(i, j + 1, k, 2)))
2717  dis4 = dim(ppor * fis4, dis2)
2718 
2719  ! Construct the vector of the first and third differences
2720  ! multiplied by the appropriate constants.
2721 
2722  ddw1 = w(i, j + 1, k, irho) - w(i, j, k, irho)
2723  dr = dis2 * ddw1 &
2724  - dis4 * (w(i, j + 2, k, irho) - w(i, j - 1, k, irho) - three * ddw1)
2725 
2726  ddw2 = w(i, j + 1, k, irho) * w(i, j + 1, k, ivx) &
2727  - w(i, j, k, irho) * w(i, j, k, ivx)
2728  dru = dis2 * ddw2 &
2729  - dis4 * (w(i, j + 2, k, irho) * w(i, j + 2, k, ivx) &
2730  - w(i, j - 1, k, irho) * w(i, j - 1, k, ivx) - three * ddw2)
2731 
2732  ddw3 = w(i, j + 1, k, irho) * w(i, j + 1, k, ivy) &
2733  - w(i, j, k, irho) * w(i, j, k, ivy)
2734  drv = dis2 * ddw3 &
2735  - dis4 * (w(i, j + 2, k, irho) * w(i, j + 2, k, ivy) &
2736  - w(i, j - 1, k, irho) * w(i, j - 1, k, ivy) - three * ddw3)
2737 
2738  ddw4 = w(i, j + 1, k, irho) * w(i, j + 1, k, ivz) &
2739  - w(i, j, k, irho) * w(i, j, k, ivz)
2740  drw = dis2 * ddw4 &
2741  - dis4 * (w(i, j + 2, k, irho) * w(i, j + 2, k, ivz) &
2742  - w(i, j - 1, k, irho) * w(i, j - 1, k, ivz) - three * ddw4)
2743 
2744  ddw5 = w(i, j + 1, k, irhoe) - w(i, j, k, irhoe)
2745  dre = dis2 * ddw5 &
2746  - dis4 * (w(i, j + 2, k, irhoe) - w(i, j - 1, k, irhoe) - three * ddw5)
2747 
2748  ! In case a k-equation is present, compute the difference
2749  ! of rhok and store the average value of k. If not present,
2750  ! set both these values to zero, such that later on no
2751  ! decision needs to be made anymore.
2752  drk = zero
2753  kavg = zero
2754 
2755  if (correctfork) then
2756  ddw6 = w(i, j + 1, k, irho) * w(i, j + 1, k, itu1) &
2757  - w(i, j, k, irho) * w(i, j, k, itu1)
2758  drk = dis2 * ddw6 &
2759  - dis4 * (w(i, j + 2, k, irho) * w(i, j + 2, k, itu1) &
2760  - w(i, j - 1, k, irho) * w(i, j - 1, k, itu1) - three * ddw6)
2761 
2762  kavg = half * (w(i, j, k, itu1) + w(i, j + 1, k, itu1))
2763  end if
2764 
2765  ! Compute the average value of gamma and compute some
2766  ! expressions in which it occurs.
2767 
2768  gammaavg = half * (gamma(i, j + 1, k) + gamma(i, j, k))
2769  gm1 = gammaavg - one
2770  ovgm1 = one / gm1
2771  gm53 = gammaavg - five * third
2772 
2773  ! Compute the average state at the interface.
2774 
2775  uavg = half * (w(i, j + 1, k, ivx) + w(i, j, k, ivx))
2776  vavg = half * (w(i, j + 1, k, ivy) + w(i, j, k, ivy))
2777  wavg = half * (w(i, j + 1, k, ivz) + w(i, j, k, ivz))
2778  a2avg = half * (gamma(i, j + 1, k) * p(i, j + 1, k) / w(i, j + 1, k, irho) &
2779  + gamma(i, j, k) * p(i, j, k) / w(i, j, k, irho))
2780 
2781  area = sqrt(sj(i, j, k, 1)**2 + sj(i, j, k, 2)**2 + sj(i, j, k, 3)**2)
2782  tmp = one / max(1.e-25_realtype, area)
2783  sx = sj(i, j, k, 1) * tmp
2784  sy = sj(i, j, k, 2) * tmp
2785  sz = sj(i, j, k, 3) * tmp
2786 
2787  alphaavg = half * (uavg**2 + vavg**2 + wavg**2)
2788  havg = alphaavg + ovgm1 * (a2avg - gm53 * kavg)
2789  aavg = sqrt(a2avg)
2790  unavg = uavg * sx + vavg * sy + wavg * sz
2791  ovaavg = one / aavg
2792  ova2avg = one / a2avg
2793 
2794  ! The mesh velocity if the face is moving. It must be
2795  ! divided by the area to obtain a true velocity.
2796 
2797  sface = sfacej(i, j, k) * tmp
2798 
2799  ! Compute the absolute values of the three eigenvalues
2800  ! and make sure they don't become zero by cutting them
2801  ! off to a certain minimum.
2802 
2803  lam1 = abs(unavg - sface + aavg)
2804  lam2 = abs(unavg - sface - aavg)
2805  lam3 = abs(unavg - sface)
2806 
2807  rrad = lam3 + aavg
2808 
2809  ! Multiply the eigenvalues by the area to obtain
2810  ! the correct values for the dissipation term.
2811 
2812  lam1 = max(lam1, epsacoustic * rrad) * area
2813  lam2 = max(lam2, epsacoustic * rrad) * area
2814  lam3 = max(lam3, epsshear * rrad) * area
2815 
2816  ! Some abbreviations, which occur quite often in the
2817  ! dissipation terms.
2818 
2819  abv1 = half * (lam1 + lam2)
2820  abv2 = half * (lam1 - lam2)
2821  abv3 = abv1 - lam3
2822 
2823  abv4 = gm1 * (alphaavg * dr - uavg * dru - vavg * drv &
2824  - wavg * drw + dre) - gm53 * drk
2825  abv5 = sx * dru + sy * drv + sz * drw - unavg * dr
2826 
2827  abv6 = abv3 * abv4 * ova2avg + abv2 * abv5 * ovaavg
2828  abv7 = abv2 * abv4 * ovaavg + abv3 * abv5
2829 
2830  ! Compute and scatter the dissipative flux.
2831  ! Density.
2832 
2833  fs = lam3 * dr + abv6
2834  fw(i, j + 1, k, irho) = fw(i, j + 1, k, irho) + fs
2835  fw(i, j, k, irho) = fw(i, j, k, irho) - fs
2836 
2837  ! X-momentum.
2838 
2839  fs = lam3 * dru + uavg * abv6 + sx * abv7
2840  fw(i, j + 1, k, imx) = fw(i, j + 1, k, imx) + fs
2841  fw(i, j, k, imx) = fw(i, j, k, imx) - fs
2842 
2843  ! Y-momentum.
2844 
2845  fs = lam3 * drv + vavg * abv6 + sy * abv7
2846  fw(i, j + 1, k, imy) = fw(i, j + 1, k, imy) + fs
2847  fw(i, j, k, imy) = fw(i, j, k, imy) - fs
2848 
2849  ! Z-momentum.
2850 
2851  fs = lam3 * drw + wavg * abv6 + sz * abv7
2852  fw(i, j + 1, k, imz) = fw(i, j + 1, k, imz) + fs
2853  fw(i, j, k, imz) = fw(i, j, k, imz) - fs
2854 
2855  ! Energy.
2856 
2857  fs = lam3 * dre + havg * abv6 + unavg * abv7
2858  fw(i, j + 1, k, irhoe) = fw(i, j + 1, k, irhoe) + fs
2859  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - fs
2860 
2861  end do
2862  end do
2863  end do
2864  !
2865  ! Dissipative fluxes in the k-direction.
2866  !
2867  do k = 1, kl
2868  do j = 2, jl
2869  do i = 2, il
2870 
2871  ! Compute the dissipation coefficients for this face.
2872 
2873  ppor = zero
2874  if (pork(i, j, k) == normalflux) ppor = one
2875 
2876  dis2 = ppor * fis2 * min(dpmax, max(dss(i, j, k, 3), dss(i, j, k + 1, 3)))
2877  dis4 = dim(ppor * fis4, dis2)
2878 
2879  ! Construct the vector of the first and third differences
2880  ! multiplied by the appropriate constants.
2881 
2882  ddw1 = w(i, j, k + 1, irho) - w(i, j, k, irho)
2883  dr = dis2 * ddw1 &
2884  - dis4 * (w(i, j, k + 2, irho) - w(i, j, k - 1, irho) - three * ddw1)
2885 
2886  ddw2 = w(i, j, k + 1, irho) * w(i, j, k + 1, ivx) &
2887  - w(i, j, k, irho) * w(i, j, k, ivx)
2888  dru = dis2 * ddw2 &
2889  - dis4 * (w(i, j, k + 2, irho) * w(i, j, k + 2, ivx) &
2890  - w(i, j, k - 1, irho) * w(i, j, k - 1, ivx) - three * ddw2)
2891 
2892  ddw3 = w(i, j, k + 1, irho) * w(i, j, k + 1, ivy) &
2893  - w(i, j, k, irho) * w(i, j, k, ivy)
2894  drv = dis2 * ddw3 &
2895  - dis4 * (w(i, j, k + 2, irho) * w(i, j, k + 2, ivy) &
2896  - w(i, j, k - 1, irho) * w(i, j, k - 1, ivy) - three * ddw3)
2897 
2898  ddw4 = w(i, j, k + 1, irho) * w(i, j, k + 1, ivz) &
2899  - w(i, j, k, irho) * w(i, j, k, ivz)
2900  drw = dis2 * ddw4 &
2901  - dis4 * (w(i, j, k + 2, irho) * w(i, j, k + 2, ivz) &
2902  - w(i, j, k - 1, irho) * w(i, j, k - 1, ivz) - three * ddw4)
2903 
2904  ddw5 = w(i, j, k + 1, irhoe) - w(i, j, k, irhoe)
2905  dre = dis2 * ddw5 &
2906  - dis4 * (w(i, j, k + 2, irhoe) - w(i, j, k - 1, irhoe) - three * ddw5)
2907 
2908  ! In case a k-equation is present, compute the difference
2909  ! of rhok and store the average value of k. If not present,
2910  ! set both these values to zero, such that later on no
2911  ! decision needs to be made anymore.
2912  drk = zero
2913  kavg = zero
2914 
2915  if (correctfork) then
2916  ddw6 = w(i, j, k + 1, irho) * w(i, j, k + 1, itu1) &
2917  - w(i, j, k, irho) * w(i, j, k, itu1)
2918  drk = dis2 * ddw6 &
2919  - dis4 * (w(i, j, k + 2, irho) * w(i, j, k + 2, itu1) &
2920  - w(i, j, k - 1, irho) * w(i, j, k - 1, itu1) - three * ddw6)
2921 
2922  kavg = half * (w(i, j, k + 1, itu1) + w(i, j, k, itu1))
2923  end if
2924 
2925  ! Compute the average value of gamma and compute some
2926  ! expressions in which it occurs.
2927 
2928  gammaavg = half * (gamma(i, j, k + 1) + gamma(i, j, k))
2929  gm1 = gammaavg - one
2930  ovgm1 = one / gm1
2931  gm53 = gammaavg - five * third
2932 
2933  ! Compute the average state at the interface.
2934 
2935  uavg = half * (w(i, j, k + 1, ivx) + w(i, j, k, ivx))
2936  vavg = half * (w(i, j, k + 1, ivy) + w(i, j, k, ivy))
2937  wavg = half * (w(i, j, k + 1, ivz) + w(i, j, k, ivz))
2938  a2avg = half * (gamma(i, j, k + 1) * p(i, j, k + 1) / w(i, j, k + 1, irho) &
2939  + gamma(i, j, k) * p(i, j, k) / w(i, j, k, irho))
2940 
2941  area = sqrt(sk(i, j, k, 1)**2 + sk(i, j, k, 2)**2 + sk(i, j, k, 3)**2)
2942  tmp = one / max(1.e-25_realtype, area)
2943  sx = sk(i, j, k, 1) * tmp
2944  sy = sk(i, j, k, 2) * tmp
2945  sz = sk(i, j, k, 3) * tmp
2946 
2947  alphaavg = half * (uavg**2 + vavg**2 + wavg**2)
2948  havg = alphaavg + ovgm1 * (a2avg - gm53 * kavg)
2949  aavg = sqrt(a2avg)
2950  unavg = uavg * sx + vavg * sy + wavg * sz
2951  ovaavg = one / aavg
2952  ova2avg = one / a2avg
2953 
2954  ! The mesh velocity if the face is moving. It must be
2955  ! divided by the area to obtain a true velocity.
2956 
2957  sface = sfacek(i, j, k) * tmp
2958 
2959  ! Compute the absolute values of the three eigenvalues
2960  ! and make sure they don't become zero by cutting them
2961  ! off to a certain minimum.
2962 
2963  lam1 = abs(unavg - sface + aavg)
2964  lam2 = abs(unavg - sface - aavg)
2965  lam3 = abs(unavg - sface)
2966 
2967  rrad = lam3 + aavg
2968 
2969  ! Multiply the eigenvalues by the area to obtain
2970  ! the correct values for the dissipation term.
2971 
2972  lam1 = max(lam1, epsacoustic * rrad) * area
2973  lam2 = max(lam2, epsacoustic * rrad) * area
2974  lam3 = max(lam3, epsshear * rrad) * area
2975 
2976  ! Some abbreviations, which occur quite often in the
2977  ! dissipation terms.
2978 
2979  abv1 = half * (lam1 + lam2)
2980  abv2 = half * (lam1 - lam2)
2981  abv3 = abv1 - lam3
2982 
2983  abv4 = gm1 * (alphaavg * dr - uavg * dru - vavg * drv &
2984  - wavg * drw + dre) - gm53 * drk
2985  abv5 = sx * dru + sy * drv + sz * drw - unavg * dr
2986 
2987  abv6 = abv3 * abv4 * ova2avg + abv2 * abv5 * ovaavg
2988  abv7 = abv2 * abv4 * ovaavg + abv3 * abv5
2989 
2990  ! Compute and scatter the dissipative flux.
2991  ! Density.
2992 
2993  fs = lam3 * dr + abv6
2994  fw(i, j, k + 1, irho) = fw(i, j, k + 1, irho) + fs
2995  fw(i, j, k, irho) = fw(i, j, k, irho) - fs
2996 
2997  ! X-momentum.
2998 
2999  fs = lam3 * dru + uavg * abv6 + sx * abv7
3000  fw(i, j, k + 1, imx) = fw(i, j, k + 1, imx) + fs
3001  fw(i, j, k, imx) = fw(i, j, k, imx) - fs
3002 
3003  ! Y-momentum.
3004 
3005  fs = lam3 * drv + vavg * abv6 + sy * abv7
3006  fw(i, j, k + 1, imy) = fw(i, j, k + 1, imy) + fs
3007  fw(i, j, k, imy) = fw(i, j, k, imy) - fs
3008 
3009  ! Z-momentum.
3010 
3011  fs = lam3 * drw + wavg * abv6 + sz * abv7
3012  fw(i, j, k + 1, imz) = fw(i, j, k + 1, imz) + fs
3013  fw(i, j, k, imz) = fw(i, j, k, imz) - fs
3014 
3015  ! Energy.
3016 
3017  fs = lam3 * dre + havg * abv6 + unavg * abv7
3018  fw(i, j, k + 1, irhoe) = fw(i, j, k + 1, irhoe) + fs
3019  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - fs
3020 
3021  end do
3022  end do
3023  end do
3024 
3025  end subroutine invisciddissfluxmatrix
3026 
3028  ! ---------------------------------------------
3029  ! Inviscid Diss Flux Scalar
3030  ! ---------------------------------------------
3031 
3032  use constants
3033  use flowvarrefstate, only: pinfcorr
3034  use inputdiscretization, only: vis2, vis4
3036  use inputphysics, only: equations
3037  use iteration, only: rfil, totalr0, totalr
3039  implicit none
3040 
3041  ! Variables for inviscid diss flux scalar
3042  real(kind=realtype), parameter :: dssmax = 0.25_realtype
3043  real(kind=realtype) :: sslim, rhoi
3044  real(kind=realtype) :: sfil, fis2, fis4
3045  real(kind=realtype) :: ppor, rrad, dis2, dis4, fs
3046  real(kind=realtype) :: ddw1, ddw2, ddw3, ddw4, ddw5
3047  integer(kind=intType) :: i, j, k
3048 
3049  ! Determine the variables used to compute the switch.
3050  ! For the inviscid case this is the pressure; for the viscous
3051  ! case it is the entropy.
3052 
3053  select case (equations)
3054  case (eulerequations)
3055 
3056  ! Inviscid case. Pressure switch is based on the pressure.
3057  ! Also set the value of sslim. To be fully consistent this
3058  ! must have the dimension of pressure and it is therefore
3059  ! set to a fraction of the free stream value.
3060 
3061  sslim = 0.001_realtype * pinfcorr
3062 
3063  ! Copy the pressure in ss. Only need the entries used in the
3064  ! discretization, i.e. not including the corner halo's, but we'll
3065  ! just copy all anyway.
3066 
3067  ss = p
3068  !===============================================================
3069 
3070  case (nsequations, ransequations)
3071 
3072  ! Viscous case. Pressure switch is based on the entropy.
3073  ! Also set the value of sslim. To be fully consistent this
3074  ! must have the dimension of entropy and it is therefore
3075  ! set to a fraction of the free stream value.
3076 
3077  sslim = 0.001_realtype * pinfcorr / (rhoinf**gammainf)
3078 
3079  ! Store the entropy in ss. See above.
3080  do k = 0, kb
3081  do j = 0, jb
3082  do i = doublehalostart, ib
3083  ss(i, j, k) = p(i, j, k) / (w(i, j, k, irho)**gamma(i, j, k))
3084  end do
3085  end do
3086  end do
3087  end select
3088 
3089  ! Compute the pressure sensor for each cell, in each direction:
3090  do k = 1, ke
3091  do j = 1, je
3092  do i = singlehalostart, ie
3093  dss(i, j, k, 1) = abs((ss(i + 1, j, k) - two * ss(i, j, k) + ss(i - 1, j, k)) &
3094  / (ss(i + 1, j, k) + two * ss(i, j, k) + ss(i - 1, j, k) + sslim))
3095 
3096  dss(i, j, k, 2) = abs((ss(i, j + 1, k) - two * ss(i, j, k) + ss(i, j - 1, k)) &
3097  / (ss(i, j + 1, k) + two * ss(i, j, k) + ss(i, j - 1, k) + sslim))
3098 
3099  dss(i, j, k, 3) = abs((ss(i, j, k + 1) - two * ss(i, j, k) + ss(i, j, k - 1)) &
3100  / (ss(i, j, k + 1) + two * ss(i, j, k) + ss(i, j, k - 1) + sslim))
3101  end do
3102  end do
3103  end do
3104 
3105  ! Set the dissipation constants for the scheme.
3106  ! rFil and sFil are fractions used by the Runge-Kutta solver to compute residuals at intermediate steps.
3107  ! For the blockette code, rFil is always one, so sFil==0, fis2==vis2, and fis4==vis4.
3108 
3109  ! The sigmoid function used for dissipation-based continuation is described in Eq. 28 and Eq. 29 from the paper:
3110  ! "Improving the Performance of a Compressible RANS Solver for Low and High Mach Number Flows" (Seraj2022c).
3111  ! The options documentation also has information on the parameters in this formulation.
3112  if (usedisscontinuation) then
3113  if (totalr == zero .or. totalr0 == zero) then
3114  fis2 = rfil * (vis2 + disscontmagnitude / (1 + exp(-disscontsharpness * disscontmidpoint)))
3115  else
3116  fis2 = rfil * (vis2 + disscontmagnitude / &
3117  (1 + exp(-disscontsharpness * (log10(totalr / totalr0) + disscontmidpoint))))
3118  end if
3119  else
3120  fis2 = rfil * vis2
3121  end if
3122  fis4 = rfil * vis4
3123  sfil = one - rfil
3124 
3125  ! Initialize the dissipative residual to a certain times,
3126  ! possibly zero, the previously stored value. Owned cells
3127  ! only, because the halo values do not matter.
3128 
3129  fw = sfil * fw
3130  !
3131  ! Dissipative fluxes in the i-direction.
3132  !
3133  do k = 2, kl
3134  do j = 2, jl
3135  do i = 1, il
3136 
3137  ! Compute the dissipation coefficients for this face.
3138 
3139  ppor = zero
3140  if (pori(i, j, k) == normalflux) ppor = half
3141  rrad = ppor * (radi(i, j, k) + radi(i + 1, j, k))
3142 
3143  dis2 = fis2 * rrad * min(dssmax, max(dss(i, j, k, 1), dss(i + 1, j, k, 1)))
3144  dis4 = dim(fis4 * rrad, dis2)
3145 
3146  ! Compute and scatter the dissipative flux.
3147  ! Density. Store it in the mass flow of the
3148  ! appropriate sliding mesh interface.
3149 
3150  ddw1 = w(i + 1, j, k, irho) - w(i, j, k, irho)
3151  fs = dis2 * ddw1 &
3152  - dis4 * (w(i + 2, j, k, irho) - w(i - 1, j, k, irho) - three * ddw1)
3153 
3154  fw(i + 1, j, k, irho) = fw(i + 1, j, k, irho) + fs
3155  fw(i, j, k, irho) = fw(i, j, k, irho) - fs
3156 
3157  ! X-momentum.
3158 
3159  ddw2 = w(i + 1, j, k, ivx) * w(i + 1, j, k, irho) - w(i, j, k, ivx) * w(i, j, k, irho)
3160  fs = dis2 * ddw2 &
3161  - dis4 * (w(i + 2, j, k, ivx) * w(i + 2, j, k, irho) - &
3162  w(i - 1, j, k, ivx) * w(i - 1, j, k, irho) - three * ddw2)
3163 
3164  fw(i + 1, j, k, imx) = fw(i + 1, j, k, imx) + fs
3165  fw(i, j, k, imx) = fw(i, j, k, imx) - fs
3166 
3167  ! Y-momentum.
3168 
3169  ddw3 = w(i + 1, j, k, ivy) * w(i + 1, j, k, irho) - w(i, j, k, ivy) * w(i, j, k, irho)
3170  fs = dis2 * ddw3 &
3171  - dis4 * (w(i + 2, j, k, ivy) * w(i + 2, j, k, irho) - &
3172  w(i - 1, j, k, ivy) * w(i - 1, j, k, irho) - three * ddw3)
3173 
3174  fw(i + 1, j, k, imy) = fw(i + 1, j, k, imy) + fs
3175  fw(i, j, k, imy) = fw(i, j, k, imy) - fs
3176 
3177  ! Z-momentum.
3178 
3179  ddw4 = w(i + 1, j, k, ivz) * w(i + 1, j, k, irho) - w(i, j, k, ivz) * w(i, j, k, irho)
3180  fs = dis2 * ddw4 &
3181  - dis4 * (w(i + 2, j, k, ivz) * w(i + 2, j, k, irho) - &
3182  w(i - 1, j, k, ivz) * w(i - 1, j, k, irho) - three * ddw4)
3183 
3184  fw(i + 1, j, k, imz) = fw(i + 1, j, k, imz) + fs
3185  fw(i, j, k, imz) = fw(i, j, k, imz) - fs
3186 
3187  ! Energy.
3188 
3189  ddw5 = (w(i + 1, j, k, irhoe) + p(i + 1, j, k)) - (w(i, j, k, irhoe) + p(i, j, k))
3190  fs = dis2 * ddw5 &
3191  - dis4 * ((w(i + 2, j, k, irhoe) + p(i + 2, j, k)) - &
3192  (w(i - 1, j, k, irhoe) + p(i - 1, j, k)) - three * ddw5)
3193 
3194  fw(i + 1, j, k, irhoe) = fw(i + 1, j, k, irhoe) + fs
3195  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - fs
3196  end do
3197  end do
3198  end do
3199  !
3200  ! Dissipative fluxes in the j-direction.
3201  !
3202  do k = 2, kl
3203  do j = 1, jl
3204  do i = 2, il
3205 
3206  ! Compute the dissipation coefficients for this face.
3207 
3208  ppor = zero
3209  if (porj(i, j, k) == normalflux) ppor = half
3210  rrad = ppor * (radj(i, j, k) + radj(i, j + 1, k))
3211 
3212  dis2 = fis2 * rrad * min(dssmax, max(dss(i, j, k, 2), dss(i, j + 1, k, 2)))
3213  dis4 = dim(fis4 * rrad, dis2)
3214 
3215  ! Compute and scatter the dissipative flux.
3216  ! Density. Store it in the mass flow of the
3217  ! appropriate sliding mesh interface.
3218 
3219  ddw1 = w(i, j + 1, k, irho) - w(i, j, k, irho)
3220  fs = dis2 * ddw1 &
3221  - dis4 * (w(i, j + 2, k, irho) - w(i, j - 1, k, irho) - three * ddw1)
3222 
3223  fw(i, j + 1, k, irho) = fw(i, j + 1, k, irho) + fs
3224  fw(i, j, k, irho) = fw(i, j, k, irho) - fs
3225 
3226  ! X-momentum.
3227 
3228  ddw2 = w(i, j + 1, k, ivx) * w(i, j + 1, k, irho) - w(i, j, k, ivx) * w(i, j, k, irho)
3229  fs = dis2 * ddw2 &
3230  - dis4 * (w(i, j + 2, k, ivx) * w(i, j + 2, k, irho) - &
3231  w(i, j - 1, k, ivx) * w(i, j - 1, k, irho) - three * ddw2)
3232 
3233  fw(i, j + 1, k, imx) = fw(i, j + 1, k, imx) + fs
3234  fw(i, j, k, imx) = fw(i, j, k, imx) - fs
3235 
3236  ! Y-momentum.
3237 
3238  ddw3 = w(i, j + 1, k, ivy) * w(i, j + 1, k, irho) - w(i, j, k, ivy) * w(i, j, k, irho)
3239  fs = dis2 * ddw3 &
3240  - dis4 * (w(i, j + 2, k, ivy) * w(i, j + 2, k, irho) - &
3241  w(i, j - 1, k, ivy) * w(i, j - 1, k, irho) - three * ddw3)
3242 
3243  fw(i, j + 1, k, imy) = fw(i, j + 1, k, imy) + fs
3244  fw(i, j, k, imy) = fw(i, j, k, imy) - fs
3245 
3246  ! Z-momentum.
3247 
3248  ddw4 = w(i, j + 1, k, ivz) * w(i, j + 1, k, irho) - w(i, j, k, ivz) * w(i, j, k, irho)
3249  fs = dis2 * ddw4 &
3250  - dis4 * (w(i, j + 2, k, ivz) * w(i, j + 2, k, irho) - &
3251  w(i, j - 1, k, ivz) * w(i, j - 1, k, irho) - three * ddw4)
3252 
3253  fw(i, j + 1, k, imz) = fw(i, j + 1, k, imz) + fs
3254  fw(i, j, k, imz) = fw(i, j, k, imz) - fs
3255 
3256  ! Energy.
3257 
3258  ddw5 = (w(i, j + 1, k, irhoe) + p(i, j + 1, k)) - (w(i, j, k, irhoe) + p(i, j, k))
3259  fs = dis2 * ddw5 &
3260  - dis4 * ((w(i, j + 2, k, irhoe) + p(i, j + 2, k)) - &
3261  (w(i, j - 1, k, irhoe) + p(i, j - 1, k)) - three * ddw5)
3262 
3263  fw(i, j + 1, k, irhoe) = fw(i, j + 1, k, irhoe) + fs
3264  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - fs
3265  end do
3266  end do
3267  end do
3268  !
3269  ! Dissipative fluxes in the k-direction.
3270  !
3271  do k = 1, kl
3272  do j = 2, jl
3273  do i = 2, il
3274 
3275  ! Compute the dissipation coefficients for this face.
3276 
3277  ppor = zero
3278  if (pork(i, j, k) == normalflux) ppor = half
3279  rrad = ppor * (radk(i, j, k) + radk(i, j, k + 1))
3280 
3281  dis2 = fis2 * rrad * min(dssmax, max(dss(i, j, k, 3), dss(i, j, k + 1, 3)))
3282  dis4 = dim(fis4 * rrad, dis2)
3283 
3284  ! Compute and scatter the dissipative flux.
3285  ! Density. Store it in the mass flow of the
3286  ! appropriate sliding mesh interface.
3287 
3288  ddw1 = w(i, j, k + 1, irho) - w(i, j, k, irho)
3289  fs = dis2 * ddw1 &
3290  - dis4 * (w(i, j, k + 2, irho) - w(i, j, k - 1, irho) - three * ddw1)
3291 
3292  fw(i, j, k + 1, irho) = fw(i, j, k + 1, irho) + fs
3293  fw(i, j, k, irho) = fw(i, j, k, irho) - fs
3294 
3295  ! X-momentum.
3296 
3297  ddw2 = w(i, j, k + 1, ivx) * w(i, j, k + 1, irho) - w(i, j, k, ivx) * w(i, j, k, irho)
3298  fs = dis2 * ddw2 &
3299  - dis4 * (w(i, j, k + 2, ivx) * w(i, j, k + 2, irho) - &
3300  w(i, j, k - 1, ivx) * w(i, j, k - 1, irho) - three * ddw2)
3301 
3302  fw(i, j, k + 1, imx) = fw(i, j, k + 1, imx) + fs
3303  fw(i, j, k, imx) = fw(i, j, k, imx) - fs
3304 
3305  ! Y-momentum.
3306 
3307  ddw3 = w(i, j, k + 1, ivy) * w(i, j, k + 1, irho) - w(i, j, k, ivy) * w(i, j, k, irho)
3308  fs = dis2 * ddw3 &
3309  - dis4 * (w(i, j, k + 2, ivy) * w(i, j, k + 2, irho) - &
3310  w(i, j, k - 1, ivy) * w(i, j, k - 1, irho) - three * ddw3)
3311 
3312  fw(i, j, k + 1, imy) = fw(i, j, k + 1, imy) + fs
3313  fw(i, j, k, imy) = fw(i, j, k, imy) - fs
3314 
3315  ! Z-momentum.
3316 
3317  ddw4 = w(i, j, k + 1, ivz) * w(i, j, k + 1, irho) - w(i, j, k, ivz) * w(i, j, k, irho)
3318  fs = dis2 * ddw4 &
3319  - dis4 * (w(i, j, k + 2, ivz) * w(i, j, k + 2, irho) - &
3320  w(i, j, k - 1, ivz) * w(i, j, k - 1, irho) - three * ddw4)
3321 
3322  fw(i, j, k + 1, imz) = fw(i, j, k + 1, imz) + fs
3323  fw(i, j, k, imz) = fw(i, j, k, imz) - fs
3324 
3325  ! Energy.
3326 
3327  ddw5 = (w(i, j, k + 1, irhoe) + p(i, j, k + 1)) - (w(i, j, k, irhoe) + p(i, j, k))
3328  fs = dis2 * ddw5 &
3329  - dis4 * ((w(i, j, k + 2, irhoe) + p(i, j, k + 2)) - &
3330  (w(i, j, k - 1, irhoe) + p(i, j, k - 1)) - three * ddw5)
3331 
3332  fw(i, j, k + 1, irhoe) = fw(i, j, k + 1, irhoe) + fs
3333  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - fs
3334  end do
3335  end do
3336  end do
3337  end subroutine invisciddissfluxscalar
3338 
3339  subroutine inviscidupwindflux(fineGrid)
3340  !
3341  ! inviscidUpwindFlux computes the artificial dissipation part of
3342  ! the Euler fluxes by means of an approximate solution of the 1D
3343  ! Riemann problem on the face. For first order schemes,
3344  ! fineGrid == .false., the states in the cells are assumed to
3345  ! be constant; for the second order schemes on the fine grid a
3346  ! nonlinear reconstruction of the left and right state is done
3347  ! for which several options exist.
3348  ! It is assumed that the pointers in blockPointers already
3349  ! point to the correct block.
3350  !
3351  use constants
3352  use flowvarrefstate, only: kpresent, nw, nwf, rgas, tref
3354  use inputdiscretization, only: limiter, precond, riemann, &
3356  use inputphysics, only: equations
3357  use iteration, only: rfil, currentlevel, groundlevel
3358  use utils, only: getcorrectfork, terminate
3359  use flowutils, only: etot
3360  implicit none
3361  !
3362  ! Subroutine arguments.
3363  !
3364  logical, intent(in) :: fineGrid
3365  !
3366  ! Local variables.
3367  !
3368  integer(kind=porType) :: por
3369 
3370  integer(kind=intType) :: nwInt
3371  integer(kind=intType) :: i, j, k, ind
3372  integer(kind=intType) :: limUsed, riemannUsed
3373 
3374  real(kind=realtype) :: sx, sy, sz, omk, opk, sfil, gammaface
3375  real(kind=realtype) :: factminmod, sface
3376 
3377  real(kind=realtype), dimension(nw) :: left, right
3378  real(kind=realtype), dimension(nw) :: du1, du2, du3
3379  real(kind=realtype), dimension(nwf) :: flux
3380 
3381  logical :: firstOrderK, correctForK, rotationalPeriodic
3382 
3383  ! Check if the formulation for rotational periodic problems
3384  ! must be used.
3385 
3386  if (associated(rotmatrixi)) then
3387  rotationalperiodic = .true.
3388  else
3389  rotationalperiodic = .false.
3390  end if
3391 
3392  ! Initialize the dissipative residual to a certain times,
3393  ! possibly zero, the previously stored value. Owned cells
3394  ! only, because the halo values do not matter.
3395 
3396  sfil = one - rfil
3397 
3398  do k = 2, kl
3399  do j = 2, jl
3400  do i = 2, il
3401  fw(i, j, k, irho) = sfil * fw(i, j, k, irho)
3402  fw(i, j, k, imx) = sfil * fw(i, j, k, imx)
3403  fw(i, j, k, imy) = sfil * fw(i, j, k, imy)
3404  fw(i, j, k, imz) = sfil * fw(i, j, k, imz)
3405  fw(i, j, k, irhoe) = sfil * fw(i, j, k, irhoe)
3406  end do
3407  end do
3408  end do
3409 
3410  ! Determine whether or not the total energy must be corrected
3411  ! for the presence of the turbulent kinetic energy.
3412  correctfork = getcorrectfork()
3413 
3414  ! Compute the factor used in the minmod limiter.
3415 
3416  factminmod = (three - kappacoef) &
3417  / max(1.e-10_realtype, one - kappacoef)
3418 
3419  ! Determine the limiter scheme to be used. On the fine grid the
3420  ! user specified scheme is used; on the coarse grid a first order
3421  ! scheme is computed.
3422 
3423  limused = firstorder
3424  if (finegrid) limused = limiter
3425 
3426  ! Determine the riemann solver which must be used.
3427 
3428  riemannused = riemanncoarse
3429  if (finegrid) riemannused = riemann
3430 
3431  ! Store 1-kappa and 1+kappa a bit easier and multiply it by 0.25.
3432 
3433  omk = fourth * (one - kappacoef)
3434  opk = fourth * (one + kappacoef)
3435 
3436  ! Set the number of variables to be interpolated depending
3437  ! whether or not a k-equation is present. If a k-equation is
3438  ! present also set the logical firstOrderK. This indicates
3439  ! whether or not only a first order approximation is to be used
3440  ! for the turbulent kinetic energy.
3441 
3442  if (correctfork) then
3443  if (orderturb == firstorder) then
3444  nwint = nwf
3445  firstorderk = .true.
3446  else
3447  nwint = itu1
3448  firstorderk = .false.
3449  end if
3450  else
3451  nwint = nwf
3452  firstorderk = .false.
3453  end if
3454  !
3455  ! Flux computation. A distinction is made between first and
3456  ! second order schemes to avoid the overhead for the first order
3457  ! scheme.
3458  !
3459  ordertest: if (limused == firstorder) then
3460  !
3461  ! First order reconstruction. The states in the cells are
3462  ! constant. The left and right states are constructed easily.
3463  !
3464  ! Fluxes in the i-direction.
3465 
3466  do k = 2, kl
3467  do j = 2, jl
3468  do i = 1, il
3469 
3470  ! Store the normal vector, the porosity and the
3471  ! mesh velocity if present.
3472 
3473  sx = si(i, j, k, 1); sy = si(i, j, k, 2); sz = si(i, j, k, 3)
3474  por = pori(i, j, k)
3475  sface = sfacei(i, j, k)
3476 
3477  ! Determine the left and right state.
3478 
3479  left(irho) = w(i, j, k, irho)
3480  left(ivx) = w(i, j, k, ivx)
3481  left(ivy) = w(i, j, k, ivy)
3482  left(ivz) = w(i, j, k, ivz)
3483  left(irhoe) = p(i, j, k)
3484  if (correctfork) left(itu1) = w(i, j, k, itu1)
3485 
3486  right(irho) = w(i + 1, j, k, irho)
3487  right(ivx) = w(i + 1, j, k, ivx)
3488  right(ivy) = w(i + 1, j, k, ivy)
3489  right(ivz) = w(i + 1, j, k, ivz)
3490  right(irhoe) = p(i + 1, j, k)
3491  if (correctfork) right(itu1) = w(i + 1, j, k, itu1)
3492 
3493  ! Compute the value of gamma on the face. Take an
3494  ! arithmetic average of the two states.
3495 
3496  gammaface = half * (gamma(i, j, k) + gamma(i + 1, j, k))
3497 
3498  ! Compute the dissipative flux across the interface.
3499 
3500  call riemannflux(left, right, flux)
3501 
3502  ! And scatter it to the left and right.
3503 
3504  fw(i, j, k, irho) = fw(i, j, k, irho) + flux(irho)
3505  fw(i, j, k, imx) = fw(i, j, k, imx) + flux(imx)
3506  fw(i, j, k, imy) = fw(i, j, k, imy) + flux(imy)
3507  fw(i, j, k, imz) = fw(i, j, k, imz) + flux(imz)
3508  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) + flux(irhoe)
3509 
3510  fw(i + 1, j, k, irho) = fw(i + 1, j, k, irho) - flux(irho)
3511  fw(i + 1, j, k, imx) = fw(i + 1, j, k, imx) - flux(imx)
3512  fw(i + 1, j, k, imy) = fw(i + 1, j, k, imy) - flux(imy)
3513  fw(i + 1, j, k, imz) = fw(i + 1, j, k, imz) - flux(imz)
3514  fw(i + 1, j, k, irhoe) = fw(i + 1, j, k, irhoe) - flux(irhoe)
3515 
3516  end do
3517  end do
3518  end do
3519 
3520  ! Fluxes in j-direction.
3521 
3522  do k = 2, kl
3523  do j = 1, jl
3524  do i = 2, il
3525 
3526  ! Store the normal vector, the porosity and the
3527  ! mesh velocity if present.
3528 
3529  sx = sj(i, j, k, 1); sy = sj(i, j, k, 2); sz = sj(i, j, k, 3)
3530  por = porj(i, j, k)
3531  sface = sfacej(i, j, k)
3532 
3533  ! Determine the left and right state.
3534 
3535  left(irho) = w(i, j, k, irho)
3536  left(ivx) = w(i, j, k, ivx)
3537  left(ivy) = w(i, j, k, ivy)
3538  left(ivz) = w(i, j, k, ivz)
3539  left(irhoe) = p(i, j, k)
3540  if (correctfork) left(itu1) = w(i, j, k, itu1)
3541 
3542  right(irho) = w(i, j + 1, k, irho)
3543  right(ivx) = w(i, j + 1, k, ivx)
3544  right(ivy) = w(i, j + 1, k, ivy)
3545  right(ivz) = w(i, j + 1, k, ivz)
3546  right(irhoe) = p(i, j + 1, k)
3547  if (correctfork) right(itu1) = w(i, j + 1, k, itu1)
3548 
3549  ! Compute the value of gamma on the face. Take an
3550  ! arithmetic average of the two states.
3551 
3552  gammaface = half * (gamma(i, j, k) + gamma(i, j + 1, k))
3553 
3554  ! Compute the dissipative flux across the interface.
3555 
3556  call riemannflux(left, right, flux)
3557 
3558  ! And scatter it to the left and right.
3559 
3560  fw(i, j, k, irho) = fw(i, j, k, irho) + flux(irho)
3561  fw(i, j, k, imx) = fw(i, j, k, imx) + flux(imx)
3562  fw(i, j, k, imy) = fw(i, j, k, imy) + flux(imy)
3563  fw(i, j, k, imz) = fw(i, j, k, imz) + flux(imz)
3564  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) + flux(irhoe)
3565 
3566  fw(i, j + 1, k, irho) = fw(i, j + 1, k, irho) - flux(irho)
3567  fw(i, j + 1, k, imx) = fw(i, j + 1, k, imx) - flux(imx)
3568  fw(i, j + 1, k, imy) = fw(i, j + 1, k, imy) - flux(imy)
3569  fw(i, j + 1, k, imz) = fw(i, j + 1, k, imz) - flux(imz)
3570  fw(i, j + 1, k, irhoe) = fw(i, j + 1, k, irhoe) - flux(irhoe)
3571  end do
3572  end do
3573  end do
3574 
3575  ! Fluxes in k-direction.
3576 
3577  do k = 1, kl
3578  do j = 2, jl
3579  do i = 2, il
3580 
3581  ! Store the normal vector, the porosity and the
3582  ! mesh velocity if present.
3583 
3584  sx = sk(i, j, k, 1); sy = sk(i, j, k, 2); sz = sk(i, j, k, 3)
3585  por = pork(i, j, k)
3586  sface = sfacek(i, j, k)
3587 
3588  ! Determine the left and right state.
3589 
3590  left(irho) = w(i, j, k, irho)
3591  left(ivx) = w(i, j, k, ivx)
3592  left(ivy) = w(i, j, k, ivy)
3593  left(ivz) = w(i, j, k, ivz)
3594  left(irhoe) = p(i, j, k)
3595  if (correctfork) left(itu1) = w(i, j, k, itu1)
3596 
3597  right(irho) = w(i, j, k + 1, irho)
3598  right(ivx) = w(i, j, k + 1, ivx)
3599  right(ivy) = w(i, j, k + 1, ivy)
3600  right(ivz) = w(i, j, k + 1, ivz)
3601  right(irhoe) = p(i, j, k + 1)
3602  if (correctfork) right(itu1) = w(i, j, k + 1, itu1)
3603 
3604  ! Compute the value of gamma on the face. Take an
3605  ! arithmetic average of the two states.
3606 
3607  gammaface = half * (gamma(i, j, k) + gamma(i, j, k + 1))
3608 
3609  ! Compute the dissipative flux across the interface.
3610 
3611  call riemannflux(left, right, flux)
3612 
3613  ! And scatter it the left and right.
3614 
3615  fw(i, j, k, irho) = fw(i, j, k, irho) + flux(irho)
3616  fw(i, j, k, imx) = fw(i, j, k, imx) + flux(imx)
3617  fw(i, j, k, imy) = fw(i, j, k, imy) + flux(imy)
3618  fw(i, j, k, imz) = fw(i, j, k, imz) + flux(imz)
3619  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) + flux(irhoe)
3620 
3621  fw(i, j, k + 1, irho) = fw(i, j, k + 1, irho) - flux(irho)
3622  fw(i, j, k + 1, imx) = fw(i, j, k + 1, imx) - flux(imx)
3623  fw(i, j, k + 1, imy) = fw(i, j, k + 1, imy) - flux(imy)
3624  fw(i, j, k + 1, imz) = fw(i, j, k + 1, imz) - flux(imz)
3625  fw(i, j, k + 1, irhoe) = fw(i, j, k + 1, irhoe) - flux(irhoe)
3626 
3627  end do
3628  end do
3629  end do
3630 
3631  ! ==================================================================
3632 
3633  else ordertest
3634 
3635  ! ==================================================================
3636  !
3637  ! Second order reconstruction of the left and right state.
3638  ! The three differences used in the, possibly nonlinear,
3639  ! interpolation are constructed here; the actual left and
3640  ! right states, or at least the differences from the first
3641  ! order interpolation, are computed in the subroutine
3642  ! leftRightState.
3643  !
3644  ! Fluxes in the i-direction.
3645 
3646  do k = 2, kl
3647  do j = 2, jl
3648  do i = 1, il
3649 
3650  ! Store the three differences used in the interpolation
3651  ! in du1, du2, du3.
3652 
3653  du1(irho) = w(i, j, k, irho) - w(i - 1, j, k, irho)
3654  du2(irho) = w(i + 1, j, k, irho) - w(i, j, k, irho)
3655  du3(irho) = w(i + 2, j, k, irho) - w(i + 1, j, k, irho)
3656 
3657  du1(ivx) = w(i, j, k, ivx) - w(i - 1, j, k, ivx)
3658  du2(ivx) = w(i + 1, j, k, ivx) - w(i, j, k, ivx)
3659  du3(ivx) = w(i + 2, j, k, ivx) - w(i + 1, j, k, ivx)
3660 
3661  du1(ivy) = w(i, j, k, ivy) - w(i - 1, j, k, ivy)
3662  du2(ivy) = w(i + 1, j, k, ivy) - w(i, j, k, ivy)
3663  du3(ivy) = w(i + 2, j, k, ivy) - w(i + 1, j, k, ivy)
3664 
3665  du1(ivz) = w(i, j, k, ivz) - w(i - 1, j, k, ivz)
3666  du2(ivz) = w(i + 1, j, k, ivz) - w(i, j, k, ivz)
3667  du3(ivz) = w(i + 2, j, k, ivz) - w(i + 1, j, k, ivz)
3668 
3669  du1(irhoe) = p(i, j, k) - p(i - 1, j, k)
3670  du2(irhoe) = p(i + 1, j, k) - p(i, j, k)
3671  du3(irhoe) = p(i + 2, j, k) - p(i + 1, j, k)
3672 
3673  if (correctfork) then
3674  du1(itu1) = w(i, j, k, itu1) - w(i - 1, j, k, itu1)
3675  du2(itu1) = w(i + 1, j, k, itu1) - w(i, j, k, itu1)
3676  du3(itu1) = w(i + 2, j, k, itu1) - w(i + 1, j, k, itu1)
3677  end if
3678 
3679  ! Compute the differences from the first order scheme.
3680 
3681  call leftrightstate(du1, du2, du3, rotmatrixi, &
3682  left, right)
3683 
3684  ! Add the first order part to the currently stored
3685  ! differences, such that the correct state vector
3686  ! is stored.
3687 
3688  left(irho) = left(irho) + w(i, j, k, irho)
3689  left(ivx) = left(ivx) + w(i, j, k, ivx)
3690  left(ivy) = left(ivy) + w(i, j, k, ivy)
3691  left(ivz) = left(ivz) + w(i, j, k, ivz)
3692  left(irhoe) = left(irhoe) + p(i, j, k)
3693 
3694  right(irho) = right(irho) + w(i + 1, j, k, irho)
3695  right(ivx) = right(ivx) + w(i + 1, j, k, ivx)
3696  right(ivy) = right(ivy) + w(i + 1, j, k, ivy)
3697  right(ivz) = right(ivz) + w(i + 1, j, k, ivz)
3698  right(irhoe) = right(irhoe) + p(i + 1, j, k)
3699 
3700  if (correctfork) then
3701  left(itu1) = left(itu1) + w(i, j, k, itu1)
3702  right(itu1) = right(itu1) + w(i + 1, j, k, itu1)
3703  end if
3704 
3705  ! Store the normal vector, the porosity and the
3706  ! mesh velocity if present.
3707 
3708  sx = si(i, j, k, 1); sy = si(i, j, k, 2); sz = si(i, j, k, 3)
3709  por = pori(i, j, k)
3710  sface = sfacei(i, j, k)
3711 
3712  ! Compute the value of gamma on the face. Take an
3713  ! arithmetic average of the two states.
3714 
3715  gammaface = half * (gamma(i, j, k) + gamma(i + 1, j, k))
3716 
3717  ! Compute the dissipative flux across the interface.
3718 
3719  call riemannflux(left, right, flux)
3720 
3721  ! And scatter it to the left and right.
3722 
3723  fw(i, j, k, irho) = fw(i, j, k, irho) + flux(irho)
3724  fw(i, j, k, imx) = fw(i, j, k, imx) + flux(imx)
3725  fw(i, j, k, imy) = fw(i, j, k, imy) + flux(imy)
3726  fw(i, j, k, imz) = fw(i, j, k, imz) + flux(imz)
3727  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) + flux(irhoe)
3728 
3729  fw(i + 1, j, k, irho) = fw(i + 1, j, k, irho) - flux(irho)
3730  fw(i + 1, j, k, imx) = fw(i + 1, j, k, imx) - flux(imx)
3731  fw(i + 1, j, k, imy) = fw(i + 1, j, k, imy) - flux(imy)
3732  fw(i + 1, j, k, imz) = fw(i + 1, j, k, imz) - flux(imz)
3733  fw(i + 1, j, k, irhoe) = fw(i + 1, j, k, irhoe) - flux(irhoe)
3734 
3735  end do
3736  end do
3737  end do
3738 
3739  ! Fluxes in the j-direction.
3740 
3741  do k = 2, kl
3742  do j = 1, jl
3743  do i = 2, il
3744 
3745  ! Store the three differences used in the interpolation
3746  ! in du1, du2, du3.
3747 
3748  du1(irho) = w(i, j, k, irho) - w(i, j - 1, k, irho)
3749  du2(irho) = w(i, j + 1, k, irho) - w(i, j, k, irho)
3750  du3(irho) = w(i, j + 2, k, irho) - w(i, j + 1, k, irho)
3751 
3752  du1(ivx) = w(i, j, k, ivx) - w(i, j - 1, k, ivx)
3753  du2(ivx) = w(i, j + 1, k, ivx) - w(i, j, k, ivx)
3754  du3(ivx) = w(i, j + 2, k, ivx) - w(i, j + 1, k, ivx)
3755 
3756  du1(ivy) = w(i, j, k, ivy) - w(i, j - 1, k, ivy)
3757  du2(ivy) = w(i, j + 1, k, ivy) - w(i, j, k, ivy)
3758  du3(ivy) = w(i, j + 2, k, ivy) - w(i, j + 1, k, ivy)
3759 
3760  du1(ivz) = w(i, j, k, ivz) - w(i, j - 1, k, ivz)
3761  du2(ivz) = w(i, j + 1, k, ivz) - w(i, j, k, ivz)
3762  du3(ivz) = w(i, j + 2, k, ivz) - w(i, j + 1, k, ivz)
3763 
3764  du1(irhoe) = p(i, j, k) - p(i, j - 1, k)
3765  du2(irhoe) = p(i, j + 1, k) - p(i, j, k)
3766  du3(irhoe) = p(i, j + 2, k) - p(i, j + 1, k)
3767 
3768  if (correctfork) then
3769  du1(itu1) = w(i, j, k, itu1) - w(i, j - 1, k, itu1)
3770  du2(itu1) = w(i, j + 1, k, itu1) - w(i, j, k, itu1)
3771  du3(itu1) = w(i, j + 2, k, itu1) - w(i, j + 1, k, itu1)
3772  end if
3773 
3774  ! Compute the differences from the first order scheme.
3775 
3776  call leftrightstate(du1, du2, du3, rotmatrixj, &
3777  left, right)
3778 
3779  ! Add the first order part to the currently stored
3780  ! differences, such that the correct state vector
3781  ! is stored.
3782 
3783  left(irho) = left(irho) + w(i, j, k, irho)
3784  left(ivx) = left(ivx) + w(i, j, k, ivx)
3785  left(ivy) = left(ivy) + w(i, j, k, ivy)
3786  left(ivz) = left(ivz) + w(i, j, k, ivz)
3787  left(irhoe) = left(irhoe) + p(i, j, k)
3788 
3789  right(irho) = right(irho) + w(i, j + 1, k, irho)
3790  right(ivx) = right(ivx) + w(i, j + 1, k, ivx)
3791  right(ivy) = right(ivy) + w(i, j + 1, k, ivy)
3792  right(ivz) = right(ivz) + w(i, j + 1, k, ivz)
3793  right(irhoe) = right(irhoe) + p(i, j + 1, k)
3794 
3795  if (correctfork) then
3796  left(itu1) = left(itu1) + w(i, j, k, itu1)
3797  right(itu1) = right(itu1) + w(i, j + 1, k, itu1)
3798  end if
3799 
3800  ! Store the normal vector, the porosity and the
3801  ! mesh velocity if present.
3802 
3803  sx = sj(i, j, k, 1); sy = sj(i, j, k, 2); sz = sj(i, j, k, 3)
3804  por = porj(i, j, k)
3805  sface = sfacej(i, j, k)
3806 
3807  ! Compute the value of gamma on the face. Take an
3808  ! arithmetic average of the two states.
3809 
3810  gammaface = half * (gamma(i, j, k) + gamma(i, j + 1, k))
3811 
3812  ! Compute the dissipative flux across the interface.
3813 
3814  call riemannflux(left, right, flux)
3815 
3816  ! And scatter it to the left and right.
3817 
3818  fw(i, j, k, irho) = fw(i, j, k, irho) + flux(irho)
3819  fw(i, j, k, imx) = fw(i, j, k, imx) + flux(imx)
3820  fw(i, j, k, imy) = fw(i, j, k, imy) + flux(imy)
3821  fw(i, j, k, imz) = fw(i, j, k, imz) + flux(imz)
3822  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) + flux(irhoe)
3823 
3824  fw(i, j + 1, k, irho) = fw(i, j + 1, k, irho) - flux(irho)
3825  fw(i, j + 1, k, imx) = fw(i, j + 1, k, imx) - flux(imx)
3826  fw(i, j + 1, k, imy) = fw(i, j + 1, k, imy) - flux(imy)
3827  fw(i, j + 1, k, imz) = fw(i, j + 1, k, imz) - flux(imz)
3828  fw(i, j + 1, k, irhoe) = fw(i, j + 1, k, irhoe) - flux(irhoe)
3829  end do
3830  end do
3831  end do
3832 
3833  ! Fluxes in the k-direction.
3834 
3835  do k = 1, kl
3836  do j = 2, jl
3837  do i = 2, il
3838 
3839  ! Store the three differences used in the interpolation
3840  ! in du1, du2, du3.
3841 
3842  du1(irho) = w(i, j, k, irho) - w(i, j, k - 1, irho)
3843  du2(irho) = w(i, j, k + 1, irho) - w(i, j, k, irho)
3844  du3(irho) = w(i, j, k + 2, irho) - w(i, j, k + 1, irho)
3845 
3846  du1(ivx) = w(i, j, k, ivx) - w(i, j, k - 1, ivx)
3847  du2(ivx) = w(i, j, k + 1, ivx) - w(i, j, k, ivx)
3848  du3(ivx) = w(i, j, k + 2, ivx) - w(i, j, k + 1, ivx)
3849 
3850  du1(ivy) = w(i, j, k, ivy) - w(i, j, k - 1, ivy)
3851  du2(ivy) = w(i, j, k + 1, ivy) - w(i, j, k, ivy)
3852  du3(ivy) = w(i, j, k + 2, ivy) - w(i, j, k + 1, ivy)
3853 
3854  du1(ivz) = w(i, j, k, ivz) - w(i, j, k - 1, ivz)
3855  du2(ivz) = w(i, j, k + 1, ivz) - w(i, j, k, ivz)
3856  du3(ivz) = w(i, j, k + 2, ivz) - w(i, j, k + 1, ivz)
3857 
3858  du1(irhoe) = p(i, j, k) - p(i, j, k - 1)
3859  du2(irhoe) = p(i, j, k + 1) - p(i, j, k)
3860  du3(irhoe) = p(i, j, k + 2) - p(i, j, k + 1)
3861 
3862  if (correctfork) then
3863  du1(itu1) = w(i, j, k, itu1) - w(i, j, k - 1, itu1)
3864  du2(itu1) = w(i, j, k + 1, itu1) - w(i, j, k, itu1)
3865  du3(itu1) = w(i, j, k + 2, itu1) - w(i, j, k + 1, itu1)
3866  end if
3867 
3868  ! Compute the differences from the first order scheme.
3869 
3870  call leftrightstate(du1, du2, du3, rotmatrixk, &
3871  left, right)
3872 
3873  ! Add the first order part to the currently stored
3874  ! differences, such that the correct state vector
3875  ! is stored.
3876 
3877  left(irho) = left(irho) + w(i, j, k, irho)
3878  left(ivx) = left(ivx) + w(i, j, k, ivx)
3879  left(ivy) = left(ivy) + w(i, j, k, ivy)
3880  left(ivz) = left(ivz) + w(i, j, k, ivz)
3881  left(irhoe) = left(irhoe) + p(i, j, k)
3882 
3883  right(irho) = right(irho) + w(i, j, k + 1, irho)
3884  right(ivx) = right(ivx) + w(i, j, k + 1, ivx)
3885  right(ivy) = right(ivy) + w(i, j, k + 1, ivy)
3886  right(ivz) = right(ivz) + w(i, j, k + 1, ivz)
3887  right(irhoe) = right(irhoe) + p(i, j, k + 1)
3888 
3889  if (correctfork) then
3890  left(itu1) = left(itu1) + w(i, j, k, itu1)
3891  right(itu1) = right(itu1) + w(i, j, k + 1, itu1)
3892  end if
3893 
3894  ! Store the normal vector, the porosity and the
3895  ! mesh velocity if present.
3896 
3897  sx = sk(i, j, k, 1); sy = sk(i, j, k, 2); sz = sk(i, j, k, 3)
3898  por = pork(i, j, k)
3899  sface = sfacek(i, j, k)
3900 
3901  ! Compute the value of gamma on the face. Take an
3902  ! arithmetic average of the two states.
3903 
3904  gammaface = half * (gamma(i, j, k) + gamma(i, j, k + 1))
3905 
3906  ! Compute the dissipative flux across the interface.
3907 
3908  call riemannflux(left, right, flux)
3909 
3910  ! And scatter it to the left and right.
3911 
3912  fw(i, j, k, irho) = fw(i, j, k, irho) + flux(irho)
3913  fw(i, j, k, imx) = fw(i, j, k, imx) + flux(imx)
3914  fw(i, j, k, imy) = fw(i, j, k, imy) + flux(imy)
3915  fw(i, j, k, imz) = fw(i, j, k, imz) + flux(imz)
3916  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) + flux(irhoe)
3917 
3918  fw(i, j, k + 1, irho) = fw(i, j, k + 1, irho) - flux(irho)
3919  fw(i, j, k + 1, imx) = fw(i, j, k + 1, imx) - flux(imx)
3920  fw(i, j, k + 1, imy) = fw(i, j, k + 1, imy) - flux(imy)
3921  fw(i, j, k + 1, imz) = fw(i, j, k + 1, imz) - flux(imz)
3922  fw(i, j, k + 1, irhoe) = fw(i, j, k + 1, irhoe) - flux(irhoe)
3923 
3924  end do
3925  end do
3926  end do
3927 
3928  end if ordertest
3929 
3930  ! ==================================================================
3931 
3932  contains
3933 
3934  subroutine leftrightstate(du1, du2, du3, rotMatrix, left, right)
3935  !
3936  ! leftRightState computes the differences in the left and
3937  ! right state compared to the first order interpolation. For a
3938  ! monotonic second order discretization the interpolations
3939  ! need to be nonlinear. The linear second order scheme can be
3940  ! stable (depending on the value of kappa), but it will have
3941  ! oscillations near discontinuities.
3942  !
3943  implicit none
3944  !
3945  ! Local parameter.
3946  !
3947  real(kind=realtype), parameter :: epslim = 1.e-10_realtype
3948  !
3949  ! Subroutine arguments.
3950  !
3951  real(kind=realtype), dimension(:), intent(inout) :: du1, du2, du3
3952  real(kind=realtype), dimension(:), intent(out) :: left, right
3953 
3954  real(kind=realtype), dimension(:, :, :, :, :), pointer :: rotmatrix
3955  !
3956  ! Local variables.
3957  !
3958  integer(kind=intType) :: l
3959 
3960  real(kind=realtype) :: rl1, rl2, rr1, rr2, tmp, dvx, dvy, dvz
3961 
3962  real(kind=realtype), dimension(3, 3) :: rot
3963 
3964  ! Check if the velocity components should be transformed to
3965  ! the cylindrical frame.
3966 
3967  if (rotationalperiodic) then
3968 
3969  ! Store the rotation matrix a bit easier. Note that the i,j,k
3970  ! come from the main subroutine.
3971 
3972  rot(1, 1) = rotmatrix(i + ii - 2, j + jj - 2, k + kk - 2, 1, 1)
3973  rot(1, 2) = rotmatrix(i + ii - 2, j + jj - 2, k + kk - 2, 1, 2)
3974  rot(1, 3) = rotmatrix(i + ii - 2, j + jj - 2, k + kk - 2, 1, 3)
3975 
3976  rot(2, 1) = rotmatrix(i + ii - 2, j + jj - 2, k + kk - 2, 2, 1)
3977  rot(2, 2) = rotmatrix(i + ii - 2, j + jj - 2, k + kk - 2, 2, 2)
3978  rot(2, 3) = rotmatrix(i + ii - 2, j + jj - 2, k + kk - 2, 2, 3)
3979 
3980  rot(3, 1) = rotmatrix(i + ii - 2, j + jj - 2, k + kk - 2, 3, 1)
3981  rot(3, 2) = rotmatrix(i + ii - 2, j + jj - 2, k + kk - 2, 3, 2)
3982  rot(3, 3) = rotmatrix(i + ii - 2, j + jj - 2, k + kk - 2, 3, 3)
3983 
3984  ! Apply the transformation to the velocity components
3985  ! of du1, du2 and du3.
3986 
3987  dvx = du1(ivx); dvy = du1(ivy); dvz = du1(ivz)
3988  du1(ivx) = rot(1, 1) * dvx + rot(1, 2) * dvy + rot(1, 3) * dvz
3989  du1(ivy) = rot(2, 1) * dvx + rot(2, 2) * dvy + rot(2, 3) * dvz
3990  du1(ivz) = rot(3, 1) * dvx + rot(3, 2) * dvy + rot(3, 3) * dvz
3991 
3992  dvx = du2(ivx); dvy = du2(ivy); dvz = du2(ivz)
3993  du2(ivx) = rot(1, 1) * dvx + rot(1, 2) * dvy + rot(1, 3) * dvz
3994  du2(ivy) = rot(2, 1) * dvx + rot(2, 2) * dvy + rot(2, 3) * dvz
3995  du2(ivz) = rot(3, 1) * dvx + rot(3, 2) * dvy + rot(3, 3) * dvz
3996 
3997  dvx = du3(ivx); dvy = du3(ivy); dvz = du3(ivz)
3998  du3(ivx) = rot(1, 1) * dvx + rot(1, 2) * dvy + rot(1, 3) * dvz
3999  du3(ivy) = rot(2, 1) * dvx + rot(2, 2) * dvy + rot(2, 3) * dvz
4000  du3(ivz) = rot(3, 1) * dvx + rot(3, 2) * dvy + rot(3, 3) * dvz
4001 
4002  end if
4003 
4004  ! Determine the limiter used.
4005 
4006  select case (limused)
4007 
4008  case (nolimiter)
4009 
4010  ! Linear interpolation; no limiter.
4011  ! Loop over the number of variables to be interpolated.
4012 
4013  do l = 1, nwint
4014  left(l) = omk * du1(l) + opk * du2(l)
4015  right(l) = -omk * du3(l) - opk * du2(l)
4016  end do
4017 
4018  ! ==============================================================
4019 
4020  case (vanalbeda)
4021 
4022  ! Nonlinear interpolation using the van albeda limiter.
4023  ! Loop over the number of variables to be interpolated.
4024 
4025  do l = 1, nwint
4026 
4027  ! Compute the limiter argument rl1, rl2, rr1 and rr2.
4028  ! Note the cut off to 0.0.
4029 
4030  tmp = one / sign(max(abs(du2(l)), epslim), du2(l))
4031  rl1 = max(zero, &
4032  du2(l) / sign(max(abs(du1(l)), epslim), du1(l)))
4033  rl2 = max(zero, du1(l) * tmp)
4034 
4035  rr1 = max(zero, du3(l) * tmp)
4036  rr2 = max(zero, &
4037  du2(l) / sign(max(abs(du3(l)), epslim), du3(l)))
4038 
4039  ! Compute the corresponding limiter values.
4040 
4041  rl1 = rl1 * (rl1 + one) / (rl1 * rl1 + one)
4042  rl2 = rl2 * (rl2 + one) / (rl2 * rl2 + one)
4043  rr1 = rr1 * (rr1 + one) / (rr1 * rr1 + one)
4044  rr2 = rr2 * (rr2 + one) / (rr2 * rr2 + one)
4045 
4046  ! Compute the nonlinear corrections to the first order
4047  ! scheme.
4048 
4049  left(l) = omk * rl1 * du1(l) + opk * rl2 * du2(l)
4050  right(l) = -opk * rr1 * du2(l) - omk * rr2 * du3(l)
4051 
4052  end do
4053 
4054  ! ==============================================================
4055 
4056  case (minmod)
4057 
4058  ! Nonlinear interpolation using the minmod limiter.
4059  ! Loop over the number of variables to be interpolated.
4060 
4061  do l = 1, nwint
4062 
4063  ! Compute the limiter argument rl1, rl2, rr1 and rr2.
4064  ! Note the cut off to 0.0.
4065 
4066  tmp = one / sign(max(abs(du2(l)), epslim), du2(l))
4067  rl1 = max(zero, &
4068  du2(l) / sign(max(abs(du1(l)), epslim), du1(l)))
4069  rl2 = max(zero, du1(l) * tmp)
4070 
4071  rr1 = max(zero, du3(l) * tmp)
4072  rr2 = max(zero, &
4073  du2(l) / sign(max(abs(du3(l)), epslim), du3(l)))
4074 
4075  ! Compute the corresponding limiter values.
4076 
4077  rl1 = min(one, factminmod * rl1)
4078  rl2 = min(one, factminmod * rl2)
4079  rr1 = min(one, factminmod * rr1)
4080  rr2 = min(one, factminmod * rr2)
4081 
4082  ! Compute the nonlinear corrections to the first order
4083  ! scheme.
4084 
4085  left(l) = omk * rl1 * du1(l) + opk * rl2 * du2(l)
4086  right(l) = -opk * rr1 * du2(l) - omk * rr2 * du3(l)
4087 
4088  end do
4089 
4090  end select
4091 
4092  ! In case only a first order scheme must be used for the
4093  ! turbulent transport equations, set the correction for the
4094  ! turbulent kinetic energy to 0.
4095 
4096  if (firstorderk) then
4097  left(itu1) = zero
4098  right(itu1) = zero
4099  end if
4100 
4101  ! For rotational periodic problems transform the velocity
4102  ! differences back to Cartesian again. Note that now the
4103  ! transpose of the rotation matrix must be used.
4104 
4105  if (rotationalperiodic) then
4106 
4107  ! Left state.
4108 
4109  dvx = left(ivx); dvy = left(ivy); dvz = left(ivz)
4110  left(ivx) = rot(1, 1) * dvx + rot(2, 1) * dvy + rot(3, 1) * dvz
4111  left(ivy) = rot(1, 2) * dvx + rot(2, 2) * dvy + rot(3, 2) * dvz
4112  left(ivz) = rot(1, 3) * dvx + rot(2, 3) * dvy + rot(3, 3) * dvz
4113 
4114  ! Right state.
4115 
4116  dvx = right(ivx); dvy = right(ivy); dvz = right(ivz)
4117  right(ivx) = rot(1, 1) * dvx + rot(2, 1) * dvy + rot(3, 1) * dvz
4118  right(ivy) = rot(1, 2) * dvx + rot(2, 2) * dvy + rot(3, 2) * dvz
4119  right(ivz) = rot(1, 3) * dvx + rot(2, 3) * dvy + rot(3, 3) * dvz
4120 
4121  end if
4122 
4123  end subroutine leftrightstate
4124 
4125  ! ================================================================
4126 
4127  subroutine riemannflux(left, right, flux)
4128  !
4129  ! riemannFlux computes the flux for the given face and left
4130  ! and right states.
4131  !
4132  implicit none
4133  !
4134  ! Subroutine arguments.
4135  !
4136  real(kind=realtype), dimension(*), intent(in) :: left, right
4137  real(kind=realtype), dimension(*), intent(out) :: flux
4138  !
4139  ! Local variables.
4140  !
4141  real(kind=realtype) :: porflux, rface
4142  real(kind=realtype) :: etl, etr, z1l, z1r, tmp
4143  real(kind=realtype) :: dr, dru, drv, drw, dre, drk
4144  real(kind=realtype) :: ravg, uavg, vavg, wavg, havg, kavg
4145  real(kind=realtype) :: alphaavg, a2avg, aavg, unavg
4146  real(kind=realtype) :: ovaavg, ova2avg, area, eta
4147  real(kind=realtype) :: gm1, gm53
4148  real(kind=realtype) :: lam1, lam2, lam3
4149  real(kind=realtype) :: abv1, abv2, abv3, abv4, abv5, abv6, abv7
4150  real(kind=realtype), dimension(2) :: ktmp
4151 
4152  ! Set the porosity for the flux. The default value, 0.5*rFil, is
4153  ! a scaling factor where an rFil != 1 is taken into account.
4154 
4155  porflux = half * rfil
4156  if (por == noflux .or. por == boundflux) porflux = zero
4157 
4158  ! Abbreviate some expressions in which gamma occurs.
4159 
4160  gm1 = gammaface - one
4161  gm53 = gammaface - five * third
4162 
4163  ! Determine which riemann solver must be solved.
4164 
4165  select case (riemannused)
4166 
4167  case (roe)
4168 
4169  ! Determine the preconditioner used.
4170 
4171  select case (precond)
4172 
4173  case (noprecond)
4174 
4175  ! No preconditioner used. Use the Roe scheme of the
4176  ! standard equations.
4177 
4178  ! Compute the square root of the left and right densities
4179  ! and the inverse of the sum.
4180 
4181  z1l = sqrt(left(irho))
4182  z1r = sqrt(right(irho))
4183  tmp = one / (z1l + z1r)
4184 
4185  ! Compute some variables depending whether or not a
4186  ! k-equation is present.
4187 
4188  if (correctfork) then
4189 
4190  ! Store the left and right kinetic energy in ktmp,
4191  ! which is needed to compute the total energy.
4192 
4193  ktmp(1) = left(itu1)
4194  ktmp(2) = right(itu1)
4195 
4196  ! Store the difference of the turbulent kinetic energy
4197  ! per unit volume, i.e. the conserved variable.
4198 
4199  drk = right(irho) * right(itu1) - left(irho) * left(itu1)
4200 
4201  ! Compute the average turbulent energy per unit mass
4202  ! using Roe averages.
4203 
4204  kavg = tmp * (z1l * left(itu1) + z1r * right(itu1))
4205 
4206  else
4207 
4208  ! Set the difference of the turbulent kinetic energy
4209  ! per unit volume and the averaged kinetic energy per
4210  ! unit mass to zero.
4211 
4212  drk = 0.0
4213  kavg = 0.0
4214 
4215  end if
4216 
4217  ! Compute the total energy of the left and right state.
4218  call etot(left(irho), left(ivx), left(ivy), left(ivz), &
4219  left(irhoe), ktmp(1), etl, correctfork)
4220 
4221  call etot(right(irho), right(ivx), right(ivy), right(ivz), &
4222  right(irhoe), ktmp(2), etr, correctfork)
4223 
4224  ! Compute the difference of the conservative mean
4225  ! flow variables.
4226 
4227  dr = right(irho) - left(irho)
4228  dru = right(irho) * right(ivx) - left(irho) * left(ivx)
4229  drv = right(irho) * right(ivy) - left(irho) * left(ivy)
4230  drw = right(irho) * right(ivz) - left(irho) * left(ivz)
4231  dre = etr - etl
4232 
4233  ! Compute the Roe average variables, which can be
4234  ! computed directly from the average Roe vector.
4235 
4236  ravg = fourth * (z1r + z1l)**2
4237  uavg = tmp * (z1l * left(ivx) + z1r * right(ivx))
4238  vavg = tmp * (z1l * left(ivy) + z1r * right(ivy))
4239  wavg = tmp * (z1l * left(ivz) + z1r * right(ivz))
4240  havg = tmp * ((etl + left(irhoe)) / z1l &
4241  + (etr + right(irhoe)) / z1r)
4242 
4243  ! Compute the unit vector and store the area of the
4244  ! normal. Also compute the unit normal velocity of the face.
4245 
4246  area = sqrt(sx**2 + sy**2 + sz**2)
4247  tmp = one / max(1.e-25_realtype, area)
4248  sx = sx * tmp
4249  sy = sy * tmp
4250  sz = sz * tmp
4251  rface = sface * tmp
4252 
4253  ! Compute some dependent variables at the Roe
4254  ! average state.
4255 
4256  alphaavg = half * (uavg**2 + vavg**2 + wavg**2)
4257  a2avg = abs(gm1 * (havg - alphaavg) - gm53 * kavg)
4258  aavg = sqrt(a2avg)
4259  unavg = uavg * sx + vavg * sy + wavg * sz
4260 
4261  ovaavg = one / aavg
4262  ova2avg = one / a2avg
4263 
4264  ! Set for a boundary the normal velocity to rFace, the
4265  ! normal velocity of the boundary.
4266 
4267  if (por == boundflux) unavg = rface
4268 
4269  ! Compute the coefficient eta for the entropy correction.
4270  ! At the moment a 1D entropy correction is used, which
4271  ! removes expansion shocks. Although it also reduces the
4272  ! carbuncle phenomenon, it does not remove it completely.
4273  ! In other to do that a multi-dimensional entropy fix is
4274  ! needed, see Sanders et. al, JCP, vol. 145, 1998,
4275  ! pp. 511 - 537. Although relatively easy to implement,
4276  ! an efficient implementation requires the storage of
4277  ! all the left and right states, which is rather
4278  ! expensive in terms of memory.
4279 
4280  eta = half * (abs((left(ivx) - right(ivx)) * sx &
4281  + (left(ivy) - right(ivy)) * sy &
4282  + (left(ivz) - right(ivz)) * sz) &
4283  + abs(sqrt(gammaface * left(irhoe) / left(irho)) &
4284  - sqrt(gammaface * right(irhoe) / right(irho))))
4285 
4286  ! Compute the absolute values of the three eigenvalues.
4287 
4288  lam1 = abs(unavg - rface + aavg)
4289  lam2 = abs(unavg - rface - aavg)
4290  lam3 = abs(unavg - rface)
4291 
4292  ! Apply the entropy correction to the eigenvalues.
4293 
4294  tmp = two * eta
4295  if (lam1 < tmp) lam1 = eta + fourth * lam1 * lam1 / eta
4296  if (lam2 < tmp) lam2 = eta + fourth * lam2 * lam2 / eta
4297  if (lam3 < tmp) lam3 = eta + fourth * lam3 * lam3 / eta
4298 
4299  ! Multiply the eigenvalues by the area to obtain
4300  ! the correct values for the dissipation term.
4301 
4302  lam1 = lam1 * area
4303  lam2 = lam2 * area
4304  lam3 = lam3 * area
4305 
4306  ! Some abbreviations, which occur quite often in the
4307  ! dissipation terms.
4308 
4309  abv1 = half * (lam1 + lam2)
4310  abv2 = half * (lam1 - lam2)
4311  abv3 = abv1 - lam3
4312 
4313  abv4 = gm1 * (alphaavg * dr - uavg * dru - vavg * drv &
4314  - wavg * drw + dre) - gm53 * drk
4315  abv5 = sx * dru + sy * drv + sz * drw - unavg * dr
4316 
4317  abv6 = abv3 * abv4 * ova2avg + abv2 * abv5 * ovaavg
4318  abv7 = abv2 * abv4 * ovaavg + abv3 * abv5
4319 
4320  ! Compute the dissipation term, -|a| (wr - wl), which is
4321  ! multiplied by porFlux. Note that porFlux is either
4322  ! 0.0 or 0.5*rFil.
4323 
4324  flux(irho) = -porflux * (lam3 * dr + abv6)
4325  flux(imx) = -porflux * (lam3 * dru + uavg * abv6 &
4326  + sx * abv7)
4327  flux(imy) = -porflux * (lam3 * drv + vavg * abv6 &
4328  + sy * abv7)
4329  flux(imz) = -porflux * (lam3 * drw + wavg * abv6 &
4330  + sz * abv7)
4331  flux(irhoe) = -porflux * (lam3 * dre + havg * abv6 &
4332  + unavg * abv7)
4333 
4334  ! tmp = max(lam1,lam2,lam3)
4335 
4336  ! flux(irho) = -porFlux*(tmp*dr)
4337  ! flux(imx) = -porFlux*(tmp*dru)
4338  ! flux(imy) = -porFlux*(tmp*drv)
4339  ! flux(imz) = -porFlux*(tmp*drw)
4340  ! flux(irhoE) = -porFlux*(tmp*drE)
4341 
4342  case (turkel)
4343  call terminate( &
4344  "riemannFlux", &
4345  "Turkel preconditioner not implemented yet")
4346 
4347  case (choimerkle)
4348  call terminate("riemannFlux", &
4349  "choi merkle preconditioner not implemented yet")
4350 
4351  end select
4352 
4353  case (vanleer)
4354  call terminate("riemannFlux", "van leer fvs not implemented yet")
4355 
4356  case (ausmdv)
4357  call terminate("riemannFlux", "ausmdv fvs not implemented yet")
4358 
4359  end select
4360 
4361  end subroutine riemannflux
4362 
4363  end subroutine inviscidupwindflux
4364 
4366  ! ---------------------------------------------
4367  ! Inviscid Diss Flux Scalar
4368  ! ---------------------------------------------
4369 
4370  use constants
4371  use flowvarrefstate, only: pinfcorr
4372  use inputdiscretization, only: vis2, vis4, sigma
4374  use inputphysics, only: equations
4375  use iteration, only: rfil, totalr0, totalr
4377  implicit none
4378 
4379  ! Variables for inviscid diss flux scalar
4380  real(kind=realtype), parameter :: dssmax = 0.25_realtype
4381  real(kind=realtype) :: sslim, rhoi
4382  real(kind=realtype) :: sfil, fis2, fis4
4383  real(kind=realtype) :: ppor, rrad, dis2, dis4, fs
4384  real(kind=realtype) :: ddw
4385  integer(kind=intType) :: i, j, k
4386  select case (equations)
4387  case (eulerequations)
4388 
4389  ! Inviscid case. Pressure switch is based on the pressure.
4390  ! Also set the value of sslim. To be fully consistent this
4391  ! must have the dimension of pressure and it is therefore
4392  ! set to a fraction of the free stream value.
4393 
4394  sslim = 0.001_realtype * pinfcorr
4395 
4396  !===============================================================
4397 
4398  case (nsequations, ransequations)
4399 
4400  ! Viscous case. Pressure switch is based on the entropy.
4401  ! Also set the value of sslim. To be fully consistent this
4402  ! must have the dimension of entropy and it is therefore
4403  ! set to a fraction of the free stream value.
4404 
4405  sslim = 0.001_realtype * pinfcorr / (rhoinf**gammainf)
4406 
4407  end select
4408 
4409  ! Compute the pressure sensor for each cell, in each direction:
4410  do k = 1, ke
4411  do j = 1, je
4412  do i = singlehalostart, ie
4413  dss(i, j, k, 1) = abs((ss(i + 1, j, k) - two * ss(i, j, k) + ss(i - 1, j, k)) &
4414  / (ss(i + 1, j, k) + two * ss(i, j, k) + ss(i - 1, j, k) + sslim))
4415 
4416  dss(i, j, k, 2) = abs((ss(i, j + 1, k) - two * ss(i, j, k) + ss(i, j - 1, k)) &
4417  / (ss(i, j + 1, k) + two * ss(i, j, k) + ss(i, j - 1, k) + sslim))
4418 
4419  dss(i, j, k, 3) = abs((ss(i, j, k + 1) - two * ss(i, j, k) + ss(i, j, k - 1)) &
4420  / (ss(i, j, k + 1) + two * ss(i, j, k) + ss(i, j, k - 1) + sslim))
4421  end do
4422  end do
4423  end do
4424 
4425  ! Set the dissipation constants for the scheme.
4426  ! rFil and sFil are fractions used by the Runge-Kutta solver to compute residuals at intermediate steps.
4427  ! For the blockette code, rFil is always one, so sFil==0, fis2==vis2, and fis4==vis4.
4428 
4429  ! The sigmoid function used for dissipation-based continuation is described in Eq. 28 and Eq. 29 from the paper:
4430  ! "Improving the Performance of a Compressible RANS Solver for Low and High Mach Number Flows" (Seraj2022c).
4431  ! The options documentation also has information on the parameters in this formulation.
4432  if (usedisscontinuation) then
4433  fis2 = vis2 + disscontmagnitude / &
4434  (1 + exp(-disscontsharpness * (log10(totalr / totalr0) + disscontmidpoint)))
4435  else
4436  fis2 = vis2
4437  end if
4438  fis4 = vis4
4439 
4440  !
4441  ! Dissipative fluxes in the i-direction.
4442  !
4443  do k = 2, kl
4444  do j = 2, jl
4445  do i = 1, il
4446 
4447  ! Compute the dissipation coefficients for this face.
4448 
4449  ppor = zero
4450  if (pori(i, j, k) == normalflux) ppor = half
4451  rrad = ppor * (radi(i, j, k) + radi(i + 1, j, k))
4452 
4453  dis2 = fis2 * rrad * min(dssmax, max(dss(i, j, k, 1), dss(i + 1, j, k, 1))) + sigma * fis4 * rrad
4454 
4455  ! Compute and scatter the dissipative flux.
4456  ! Density. Store it in the mass flow of the
4457  ! appropriate sliding mesh interface.
4458 
4459  ddw = w(i + 1, j, k, irho) - w(i, j, k, irho)
4460  fs = dis2 * ddw
4461 
4462  fw(i + 1, j, k, irho) = fw(i + 1, j, k, irho) + fs
4463  fw(i, j, k, irho) = fw(i, j, k, irho) - fs
4464 
4465  ! X-momentum.
4466 
4467  ddw = w(i + 1, j, k, ivx) * w(i + 1, j, k, irho) - w(i, j, k, ivx) * w(i, j, k, irho)
4468  fs = dis2 * ddw
4469 
4470  fw(i + 1, j, k, imx) = fw(i + 1, j, k, imx) + fs
4471  fw(i, j, k, imx) = fw(i, j, k, imx) - fs
4472 
4473  ! Y-momentum.
4474 
4475  ddw = w(i + 1, j, k, ivy) * w(i + 1, j, k, irho) - w(i, j, k, ivy) * w(i, j, k, irho)
4476  fs = dis2 * ddw
4477 
4478  fw(i + 1, j, k, imy) = fw(i + 1, j, k, imy) + fs
4479  fw(i, j, k, imy) = fw(i, j, k, imy) - fs
4480 
4481  ! Z-momentum.
4482  ddw = w(i + 1, j, k, ivz) * w(i + 1, j, k, irho) - w(i, j, k, ivz) * w(i, j, k, irho)
4483  fs = dis2 * ddw
4484 
4485  fw(i + 1, j, k, imz) = fw(i + 1, j, k, imz) + fs
4486  fw(i, j, k, imz) = fw(i, j, k, imz) - fs
4487 
4488  ! Energy.
4489  ddw = (w(i + 1, j, k, irhoe) + p(i + 1, j, k)) - (w(i, j, k, irhoe) + p(i, j, k))
4490  fs = dis2 * ddw
4491 
4492  fw(i + 1, j, k, irhoe) = fw(i + 1, j, k, irhoe) + fs
4493  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - fs
4494 
4495  end do
4496  end do
4497  end do
4498  !
4499  ! Dissipative fluxes in the j-direction.
4500  !
4501  do k = 2, kl
4502  do j = 1, jl
4503  do i = 2, il
4504 
4505  ! Compute the dissipation coefficients for this face.
4506 
4507  ppor = zero
4508  if (porj(i, j, k) == normalflux) ppor = half
4509  rrad = ppor * (radj(i, j, k) + radj(i, j + 1, k))
4510 
4511  dis2 = fis2 * rrad * min(dssmax, max(dss(i, j, k, 2), dss(i, j + 1, k, 2))) + sigma * fis4 * rrad
4512 
4513  ! Compute and scatter the dissipative flux.
4514  ! Density. Store it in the mass flow of the
4515  ! appropriate sliding mesh interface.
4516 
4517  ddw = w(i, j + 1, k, irho) - w(i, j, k, irho)
4518  fs = dis2 * ddw
4519 
4520  fw(i, j + 1, k, irho) = fw(i, j + 1, k, irho) + fs
4521  fw(i, j, k, irho) = fw(i, j, k, irho) - fs
4522 
4523  ! X-momentum.
4524 
4525  ddw = w(i, j + 1, k, ivx) * w(i, j + 1, k, irho) - w(i, j, k, ivx) * w(i, j, k, irho)
4526  fs = dis2 * ddw
4527 
4528  fw(i, j + 1, k, imx) = fw(i, j + 1, k, imx) + fs
4529  fw(i, j, k, imx) = fw(i, j, k, imx) - fs
4530 
4531  ! Y-momentum.
4532 
4533  ddw = w(i, j + 1, k, ivy) * w(i, j + 1, k, irho) - w(i, j, k, ivy) * w(i, j, k, irho)
4534  fs = dis2 * ddw
4535 
4536  fw(i, j + 1, k, imy) = fw(i, j + 1, k, imy) + fs
4537  fw(i, j, k, imy) = fw(i, j, k, imy) - fs
4538 
4539  ! Z-momentum.
4540 
4541  ddw = w(i, j + 1, k, ivz) * w(i, j + 1, k, irho) - w(i, j, k, ivz) * w(i, j, k, irho)
4542  fs = dis2 * ddw
4543 
4544  fw(i, j + 1, k, imz) = fw(i, j + 1, k, imz) + fs
4545  fw(i, j, k, imz) = fw(i, j, k, imz) - fs
4546 
4547  ! Energy.
4548 
4549  ddw = (w(i, j + 1, k, irhoe) + p(i, j + 1, k)) - (w(i, j, k, irhoe) + p(i, j, k))
4550  fs = dis2 * ddw
4551 
4552  fw(i, j + 1, k, irhoe) = fw(i, j + 1, k, irhoe) + fs
4553  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - fs
4554  end do
4555  end do
4556  end do
4557  !
4558  ! Dissipative fluxes in the k-direction.
4559  !
4560  do k = 1, kl
4561  do j = 2, jl
4562  do i = 2, il
4563 
4564  ! Compute the dissipation coefficients for this face.
4565 
4566  ppor = zero
4567  if (pork(i, j, k) == normalflux) ppor = half
4568  rrad = ppor * (radk(i, j, k) + radk(i, j, k + 1))
4569 
4570  dis2 = fis2 * rrad * min(dssmax, max(dss(i, j, k, 3), dss(i, j, k + 1, 3))) + sigma * fis4 * rrad
4571 
4572  ! Compute and scatter the dissipative flux.
4573  ! Density. Store it in the mass flow of the
4574  ! appropriate sliding mesh interface.
4575 
4576  ddw = w(i, j, k + 1, irho) - w(i, j, k, irho)
4577  fs = dis2 * ddw
4578 
4579  fw(i, j, k + 1, irho) = fw(i, j, k + 1, irho) + fs
4580  fw(i, j, k, irho) = fw(i, j, k, irho) - fs
4581 
4582  ! X-momentum.
4583 
4584  ddw = w(i, j, k + 1, ivx) * w(i, j, k + 1, irho) - w(i, j, k, ivx) * w(i, j, k, irho)
4585  fs = dis2 * ddw
4586 
4587  fw(i, j, k + 1, imx) = fw(i, j, k + 1, imx) + fs
4588  fw(i, j, k, imx) = fw(i, j, k, imx) - fs
4589 
4590  ! Y-momentum.
4591 
4592  ddw = w(i, j, k + 1, ivy) * w(i, j, k + 1, irho) - w(i, j, k, ivy) * w(i, j, k, irho)
4593  fs = dis2 * ddw
4594 
4595  fw(i, j, k + 1, imy) = fw(i, j, k + 1, imy) + fs
4596  fw(i, j, k, imy) = fw(i, j, k, imy) - fs
4597 
4598  ! Z-momentum.
4599 
4600  ddw = w(i, j, k + 1, ivz) * w(i, j, k + 1, irho) - w(i, j, k, ivz) * w(i, j, k, irho)
4601  fs = dis2 * ddw
4602 
4603  fw(i, j, k + 1, imz) = fw(i, j, k + 1, imz) + fs
4604  fw(i, j, k, imz) = fw(i, j, k, imz) - fs
4605 
4606  ! Energy.
4607  ddw = (w(i, j, k + 1, irhoe) + p(i, j, k + 1)) - (w(i, j, k, irhoe) + p(i, j, k))
4608  fs = dis2 * ddw
4609 
4610  fw(i, j, k + 1, irhoe) = fw(i, j, k + 1, irhoe) + fs
4611  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - fs
4612  end do
4613  end do
4614  end do
4615  end subroutine invisciddissfluxscalarapprox
4616 
4618  !
4619  ! inviscidDissFluxMatrix computes the matrix artificial
4620  ! dissipation term. Instead of the spectral radius, as used in
4621  ! the scalar dissipation scheme, the absolute value of the flux
4622  ! jacobian is used. This leads to a less diffusive and
4623  ! consequently more accurate scheme. It is assumed that the
4624  ! pointers in blockPointers already point to the correct block.
4625  !
4626  use constants
4627  use flowvarrefstate, only: pinfcorr
4628  use inputdiscretization, only: vis2, vis4, sigma
4629  use inputphysics, only: equations
4630  use iteration, only: rfil
4631  use utils, only: getcorrectfork, mydim
4632  implicit none
4633  !
4634  ! Local parameters.
4635  !
4636  real(kind=realtype), parameter :: dpmax = 0.25_realtype
4637  real(kind=realtype), parameter :: epsacoustic = 0.25_realtype
4638  real(kind=realtype), parameter :: epsshear = 0.025_realtype
4639  real(kind=realtype), parameter :: omega = 0.5_realtype
4640  real(kind=realtype), parameter :: oneminomega = one - omega
4641  !
4642  ! Local variables.
4643  !
4644  integer(kind=intType) :: i, j, k, ind, ii
4645 
4646  real(kind=realtype) :: plim, sface
4647  real(kind=realtype) :: sfil, fis2, fis4
4648  real(kind=realtype) :: gammaavg, gm1, ovgm1, gm53
4649  real(kind=realtype) :: ppor, rrad, dis2, dis4
4650  real(kind=realtype) :: dp1, dp2, tmp, fs
4651  real(kind=realtype) :: ddw, ddw6
4652  real(kind=realtype) :: dr, dru, drv, drw, dre, drk, sx, sy, sz
4653  real(kind=realtype) :: uavg, vavg, wavg, a2avg, aavg, havg
4654  real(kind=realtype) :: alphaavg, unavg, ovaavg, ova2avg
4655  real(kind=realtype) :: kavg, lam1, lam2, lam3, area
4656  real(kind=realtype) :: abv1, abv2, abv3, abv4, abv5, abv6, abv7
4657  logical :: correctForK
4658 
4659  ! Set the value of plim. To be fully consistent this must have
4660  ! the dimension of a pressure. Therefore a fraction of pInfCorr
4661  ! is used.
4662 
4663  plim = 0.001_realtype * pinfcorr
4664 
4665  ! Determine whether or not the total energy must be corrected
4666  ! for the presence of the turbulent kinetic energy.
4667 
4668  correctfork = getcorrectfork()
4669 
4670  ! Initialize sface to zero. This value will be used if the
4671  ! block is not moving.
4672 
4673  sface = zero
4674 
4675  ! Set a couple of constants for the scheme.
4676 
4677  fis2 = rfil * vis2
4678  fis4 = rfil * vis4
4679  sfil = one - rfil
4680 
4681  ! Initialize the dissipative residual to a certain times,
4682  ! possibly zero, the previously stored value.
4683 
4684  fw = sfil * fw
4685 
4686  ! Compute the pressure sensor for each cell, in each direction:
4687  do k = 1, ke
4688  do j = 1, je
4689  do i = singlehalostart, ie
4690  dss(i, j, k, 1) = abs((ss(i + 1, j, k) - two * ss(i, j, k) + ss(i - 1, j, k)) &
4691  / (omega * (ss(i + 1, j, k) + two * ss(i, j, k) + ss(i - 1, j, k)) &
4692  + oneminomega * (abs(ss(i + 1, j, k) - ss(i, j, k)) &
4693  + abs(ss(i, j, k) - ss(i - 1, j, k))) + plim))
4694 
4695  dss(i, j, k, 2) = abs((ss(i, j + 1, k) - two * ss(i, j, k) + ss(i, j - 1, k)) &
4696  / (omega * (ss(i, j + 1, k) + two * ss(i, j, k) + ss(i, j - 1, k)) &
4697  + oneminomega * (abs(ss(i, j + 1, k) - ss(i, j, k)) &
4698  + abs(ss(i, j, k) - ss(i, j - 1, k))) + plim))
4699 
4700  dss(i, j, k, 3) = abs((ss(i, j, k + 1) - two * ss(i, j, k) + ss(i, j, k - 1)) &
4701  / (omega * (ss(i, j, k + 1) + two * ss(i, j, k) + ss(i, j, k - 1)) &
4702  + oneminomega * (abs(ss(i, j, k + 1) - ss(i, j, k)) &
4703  + abs(ss(i, j, k) - ss(i, j, k - 1))) + plim))
4704  end do
4705  end do
4706  end do
4707  !
4708  ! Dissipative fluxes in the i-direction.
4709  !
4710  do k = 2, kl
4711  do j = 2, jl
4712  do i = 1, il
4713 
4714  ! Compute the dissipation coefficients for this face.
4715 
4716  ppor = zero
4717  if (pori(i, j, k) == normalflux) ppor = one
4718 
4719  dis2 = fis2 * ppor * min(dpmax, max(dss(i, j, k, 1), dss(i + 1, j, k, 1))) &
4720  + sigma * fis4 * ppor
4721 
4722  ! Construct the vector of the first and third differences
4723  ! multiplied by the appropriate constants.
4724 
4725  ddw = w(i + 1, j, k, irho) - w(i, j, k, irho)
4726  dr = dis2 * ddw
4727 
4728  ddw = w(i + 1, j, k, irho) * w(i + 1, j, k, ivx) &
4729  - w(i, j, k, irho) * w(i, j, k, ivx)
4730  dru = dis2 * ddw
4731 
4732  ddw = w(i + 1, j, k, irho) * w(i + 1, j, k, ivy) &
4733  - w(i, j, k, irho) * w(i, j, k, ivy)
4734  drv = dis2 * ddw
4735 
4736  ddw = w(i + 1, j, k, irho) * w(i + 1, j, k, ivz) &
4737  - w(i, j, k, irho) * w(i, j, k, ivz)
4738  drw = dis2 * ddw
4739 
4740  ddw = w(i + 1, j, k, irhoe) - w(i, j, k, irhoe)
4741  dre = dis2 * ddw
4742 
4743  ! In case a k-equation is present, compute the difference
4744  ! of rhok and store the average value of k. If not present,
4745  ! set both these values to zero, such that later on no
4746  ! decision needs to be made anymore.
4747  drk = zero
4748  kavg = zero
4749 
4750  if (correctfork) then
4751  ddw6 = w(i + 1, j, k, irho) * w(i + 1, j, k, itu1) &
4752  - w(i, j, k, irho) * w(i, j, k, itu1)
4753  drk = dis2 * ddw6 &
4754  - dis4 * (w(i + 2, j, k, irho) * w(i + 2, j, k, itu1) &
4755  - w(i - 1, j, k, irho) * w(i - 1, j, k, itu1) - three * ddw6)
4756 
4757  kavg = half * (w(i, j, k, itu1) + w(i + 1, j, k, itu1))
4758  end if
4759 
4760  ! Compute the average value of gamma and compute some
4761  ! expressions in which it occurs.
4762 
4763  gammaavg = half * (gamma(i + 1, j, k) + gamma(i, j, k))
4764  gm1 = gammaavg - one
4765  ovgm1 = one / gm1
4766  gm53 = gammaavg - five * third
4767 
4768  ! Compute the average state at the interface.
4769 
4770  uavg = half * (w(i + 1, j, k, ivx) + w(i, j, k, ivx))
4771  vavg = half * (w(i + 1, j, k, ivy) + w(i, j, k, ivy))
4772  wavg = half * (w(i + 1, j, k, ivz) + w(i, j, k, ivz))
4773  a2avg = half * (gamma(i + 1, j, k) * p(i + 1, j, k) / w(i + 1, j, k, irho) &
4774  + gamma(i, j, k) * p(i, j, k) / w(i, j, k, irho))
4775 
4776  area = sqrt(si(i, j, k, 1)**2 + si(i, j, k, 2)**2 + si(i, j, k, 3)**2)
4777  tmp = one / max(1.e-25_realtype, area)
4778  sx = si(i, j, k, 1) * tmp
4779  sy = si(i, j, k, 2) * tmp
4780  sz = si(i, j, k, 3) * tmp
4781 
4782  alphaavg = half * (uavg**2 + vavg**2 + wavg**2)
4783  havg = alphaavg + ovgm1 * (a2avg - gm53 * kavg)
4784  aavg = sqrt(a2avg)
4785  unavg = uavg * sx + vavg * sy + wavg * sz
4786  ovaavg = one / aavg
4787  ova2avg = one / a2avg
4788 
4789  ! The mesh velocity if the face is moving. It must be
4790  ! divided by the area to obtain a true velocity.
4791 
4792  sface = sfacei(i, j, k) * tmp
4793 
4794  ! Compute the absolute values of the three eigenvalues
4795  ! and make sure they don't become zero by cutting them
4796  ! off to a certain minimum.
4797 
4798  lam1 = abs(unavg - sface + aavg)
4799  lam2 = abs(unavg - sface - aavg)
4800  lam3 = abs(unavg - sface)
4801 
4802  rrad = lam3 + aavg
4803 
4804  ! Multiply the eigenvalues by the area to obtain
4805  ! the correct values for the dissipation term.
4806 
4807  lam1 = max(lam1, epsacoustic * rrad) * area
4808  lam2 = max(lam2, epsacoustic * rrad) * area
4809  lam3 = max(lam3, epsshear * rrad) * area
4810 
4811  ! Some abbreviations, which occur quite often in the
4812  ! dissipation terms.
4813 
4814  abv1 = half * (lam1 + lam2)
4815  abv2 = half * (lam1 - lam2)
4816  abv3 = abv1 - lam3
4817 
4818  abv4 = gm1 * (alphaavg * dr - uavg * dru - vavg * drv &
4819  - wavg * drw + dre) - gm53 * drk
4820  abv5 = sx * dru + sy * drv + sz * drw - unavg * dr
4821 
4822  abv6 = abv3 * abv4 * ova2avg + abv2 * abv5 * ovaavg
4823  abv7 = abv2 * abv4 * ovaavg + abv3 * abv5
4824 
4825  ! Compute and scatter the dissipative flux.
4826  ! Density.
4827 
4828  fs = lam3 * dr + abv6
4829  fw(i + 1, j, k, irho) = fw(i + 1, j, k, irho) + fs
4830  fw(i, j, k, irho) = fw(i, j, k, irho) - fs
4831 
4832  ! X-momentum.
4833 
4834  fs = lam3 * dru + uavg * abv6 + sx * abv7
4835  fw(i + 1, j, k, imx) = fw(i + 1, j, k, imx) + fs
4836  fw(i, j, k, imx) = fw(i, j, k, imx) - fs
4837 
4838  ! Y-momentum.
4839 
4840  fs = lam3 * drv + vavg * abv6 + sy * abv7
4841  fw(i + 1, j, k, imy) = fw(i + 1, j, k, imy) + fs
4842  fw(i, j, k, imy) = fw(i, j, k, imy) - fs
4843 
4844  ! Z-momentum.
4845 
4846  fs = lam3 * drw + wavg * abv6 + sz * abv7
4847  fw(i + 1, j, k, imz) = fw(i + 1, j, k, imz) + fs
4848  fw(i, j, k, imz) = fw(i, j, k, imz) - fs
4849 
4850  ! Energy.
4851 
4852  fs = lam3 * dre + havg * abv6 + unavg * abv7
4853  fw(i + 1, j, k, irhoe) = fw(i + 1, j, k, irhoe) + fs
4854  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - fs
4855 
4856  end do
4857  end do
4858  end do
4859  !
4860  ! Dissipative fluxes in the j-direction.
4861  !
4862  do k = 2, kl
4863  do j = 1, jl
4864  do i = 2, il
4865 
4866  ! Compute the dissipation coefficients for this face.
4867 
4868  ppor = zero
4869  if (porj(i, j, k) == normalflux) ppor = one
4870 
4871  dis2 = fis2 * ppor * min(dpmax, max(dss(i, j, k, 2), dss(i, j + 1, k, 2))) &
4872  + sigma * fis4 * ppor
4873 
4874  ! Construct the vector of the first and third differences
4875  ! multiplied by the appropriate constants.
4876 
4877  ddw = w(i, j + 1, k, irho) - w(i, j, k, irho)
4878  dr = dis2 * ddw
4879 
4880  ddw = w(i, j + 1, k, irho) * w(i, j + 1, k, ivx) &
4881  - w(i, j, k, irho) * w(i, j, k, ivx)
4882  dru = dis2 * ddw
4883 
4884  ddw = w(i, j + 1, k, irho) * w(i, j + 1, k, ivy) &
4885  - w(i, j, k, irho) * w(i, j, k, ivy)
4886  drv = dis2 * ddw
4887 
4888  ddw = w(i, j + 1, k, irho) * w(i, j + 1, k, ivz) &
4889  - w(i, j, k, irho) * w(i, j, k, ivz)
4890  drw = dis2 * ddw
4891 
4892  ddw = w(i, j + 1, k, irhoe) - w(i, j, k, irhoe)
4893  dre = dis2 * ddw
4894 
4895  ! In case a k-equation is present, compute the difference
4896  ! of rhok and store the average value of k. If not present,
4897  ! set both these values to zero, such that later on no
4898  ! decision needs to be made anymore.
4899  drk = zero
4900  kavg = zero
4901 
4902  if (correctfork) then
4903  ddw6 = w(i, j + 1, k, irho) * w(i, j + 1, k, itu1) &
4904  - w(i, j, k, irho) * w(i, j, k, itu1)
4905  drk = dis2 * ddw6 &
4906  - dis4 * (w(i, j + 2, k, irho) * w(i, j + 2, k, itu1) &
4907  - w(i, j - 1, k, irho) * w(i, j - 1, k, itu1) - three * ddw6)
4908 
4909  kavg = half * (w(i, j, k, itu1) + w(i, j + 1, k, itu1))
4910  end if
4911 
4912  ! Compute the average value of gamma and compute some
4913  ! expressions in which it occurs.
4914 
4915  gammaavg = half * (gamma(i, j + 1, k) + gamma(i, j, k))
4916  gm1 = gammaavg - one
4917  ovgm1 = one / gm1
4918  gm53 = gammaavg - five * third
4919 
4920  ! Compute the average state at the interface.
4921 
4922  uavg = half * (w(i, j + 1, k, ivx) + w(i, j, k, ivx))
4923  vavg = half * (w(i, j + 1, k, ivy) + w(i, j, k, ivy))
4924  wavg = half * (w(i, j + 1, k, ivz) + w(i, j, k, ivz))
4925  a2avg = half * (gamma(i, j + 1, k) * p(i, j + 1, k) / w(i, j + 1, k, irho) &
4926  + gamma(i, j, k) * p(i, j, k) / w(i, j, k, irho))
4927 
4928  area = sqrt(sj(i, j, k, 1)**2 + sj(i, j, k, 2)**2 + sj(i, j, k, 3)**2)
4929  tmp = one / max(1.e-25_realtype, area)
4930  sx = sj(i, j, k, 1) * tmp
4931  sy = sj(i, j, k, 2) * tmp
4932  sz = sj(i, j, k, 3) * tmp
4933 
4934  alphaavg = half * (uavg**2 + vavg**2 + wavg**2)
4935  havg = alphaavg + ovgm1 * (a2avg - gm53 * kavg)
4936  aavg = sqrt(a2avg)
4937  unavg = uavg * sx + vavg * sy + wavg * sz
4938  ovaavg = one / aavg
4939  ova2avg = one / a2avg
4940 
4941  ! The mesh velocity if the face is moving. It must be
4942  ! divided by the area to obtain a true velocity.
4943 
4944  sface = sfacej(i, j, k) * tmp
4945 
4946  ! Compute the absolute values of the three eigenvalues
4947  ! and make sure they don't become zero by cutting them
4948  ! off to a certain minimum.
4949 
4950  lam1 = abs(unavg - sface + aavg)
4951  lam2 = abs(unavg - sface - aavg)
4952  lam3 = abs(unavg - sface)
4953 
4954  rrad = lam3 + aavg
4955 
4956  ! Multiply the eigenvalues by the area to obtain
4957  ! the correct values for the dissipation term.
4958 
4959  lam1 = max(lam1, epsacoustic * rrad) * area
4960  lam2 = max(lam2, epsacoustic * rrad) * area
4961  lam3 = max(lam3, epsshear * rrad) * area
4962 
4963  ! Some abbreviations, which occur quite often in the
4964  ! dissipation terms.
4965 
4966  abv1 = half * (lam1 + lam2)
4967  abv2 = half * (lam1 - lam2)
4968  abv3 = abv1 - lam3
4969 
4970  abv4 = gm1 * (alphaavg * dr - uavg * dru - vavg * drv &
4971  - wavg * drw + dre) - gm53 * drk
4972  abv5 = sx * dru + sy * drv + sz * drw - unavg * dr
4973 
4974  abv6 = abv3 * abv4 * ova2avg + abv2 * abv5 * ovaavg
4975  abv7 = abv2 * abv4 * ovaavg + abv3 * abv5
4976 
4977  ! Compute and scatter the dissipative flux.
4978  ! Density.
4979 
4980  fs = lam3 * dr + abv6
4981  fw(i, j + 1, k, irho) = fw(i, j + 1, k, irho) + fs
4982  fw(i, j, k, irho) = fw(i, j, k, irho) - fs
4983 
4984  ! X-momentum.
4985 
4986  fs = lam3 * dru + uavg * abv6 + sx * abv7
4987  fw(i, j + 1, k, imx) = fw(i, j + 1, k, imx) + fs
4988  fw(i, j, k, imx) = fw(i, j, k, imx) - fs
4989 
4990  ! Y-momentum.
4991 
4992  fs = lam3 * drv + vavg * abv6 + sy * abv7
4993  fw(i, j + 1, k, imy) = fw(i, j + 1, k, imy) + fs
4994  fw(i, j, k, imy) = fw(i, j, k, imy) - fs
4995 
4996  ! Z-momentum.
4997 
4998  fs = lam3 * drw + wavg * abv6 + sz * abv7
4999  fw(i, j + 1, k, imz) = fw(i, j + 1, k, imz) + fs
5000  fw(i, j, k, imz) = fw(i, j, k, imz) - fs
5001 
5002  ! Energy.
5003 
5004  fs = lam3 * dre + havg * abv6 + unavg * abv7
5005  fw(i, j + 1, k, irhoe) = fw(i, j + 1, k, irhoe) + fs
5006  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - fs
5007 
5008  end do
5009  end do
5010  end do
5011  !
5012  ! Dissipative fluxes in the k-direction.
5013  !
5014  do k = 1, kl
5015  do j = 2, jl
5016  do i = 2, il
5017 
5018  ! Compute the dissipation coefficients for this face.
5019 
5020  ppor = zero
5021  if (pork(i, j, k) == normalflux) ppor = one
5022 
5023  dis2 = fis2 * ppor * min(dpmax, max(dss(i, j, k, 3), dss(i, j, k + 1, 3))) &
5024  + sigma * fis4 * ppor
5025 
5026  ! Construct the vector of the first and third differences
5027  ! multiplied by the appropriate constants.
5028 
5029  ddw = w(i, j, k + 1, irho) - w(i, j, k, irho)
5030  dr = dis2 * ddw
5031 
5032  ddw = w(i, j, k + 1, irho) * w(i, j, k + 1, ivx) &
5033  - w(i, j, k, irho) * w(i, j, k, ivx)
5034  dru = dis2 * ddw
5035 
5036  ddw = w(i, j, k + 1, irho) * w(i, j, k + 1, ivy) &
5037  - w(i, j, k, irho) * w(i, j, k, ivy)
5038  drv = dis2 * ddw
5039 
5040  ddw = w(i, j, k + 1, irho) * w(i, j, k + 1, ivz) &
5041  - w(i, j, k, irho) * w(i, j, k, ivz)
5042  drw = dis2 * ddw
5043 
5044  ddw = w(i, j, k + 1, irhoe) - w(i, j, k, irhoe)
5045  dre = dis2 * ddw
5046 
5047  ! In case a k-equation is present, compute the difference
5048  ! of rhok and store the average value of k. If not present,
5049  ! set both these values to zero, such that later on no
5050  ! decision needs to be made anymore.
5051  drk = zero
5052  kavg = zero
5053 
5054  if (correctfork) then
5055  ddw6 = w(i, j, k + 1, irho) * w(i, j, k + 1, itu1) &
5056  - w(i, j, k, irho) * w(i, j, k, itu1)
5057  drk = dis2 * ddw6 &
5058  - dis4 * (w(i, j, k + 2, irho) * w(i, j, k + 2, itu1) &
5059  - w(i, j, k - 1, irho) * w(i, j, k - 1, itu1) - three * ddw6)
5060 
5061  kavg = half * (w(i, j, k + 1, itu1) + w(i, j, k, itu1))
5062  end if
5063 
5064  ! Compute the average value of gamma and compute some
5065  ! expressions in which it occurs.
5066 
5067  gammaavg = half * (gamma(i, j, k + 1) + gamma(i, j, k))
5068  gm1 = gammaavg - one
5069  ovgm1 = one / gm1
5070  gm53 = gammaavg - five * third
5071 
5072  ! Compute the average state at the interface.
5073 
5074  uavg = half * (w(i, j, k + 1, ivx) + w(i, j, k, ivx))
5075  vavg = half * (w(i, j, k + 1, ivy) + w(i, j, k, ivy))
5076  wavg = half * (w(i, j, k + 1, ivz) + w(i, j, k, ivz))
5077  a2avg = half * (gamma(i, j, k + 1) * p(i, j, k + 1) / w(i, j, k + 1, irho) &
5078  + gamma(i, j, k) * p(i, j, k) / w(i, j, k, irho))
5079 
5080  area = sqrt(sk(i, j, k, 1)**2 + sk(i, j, k, 2)**2 + sk(i, j, k, 3)**2)
5081  tmp = one / max(1.e-25_realtype, area)
5082  sx = sk(i, j, k, 1) * tmp
5083  sy = sk(i, j, k, 2) * tmp
5084  sz = sk(i, j, k, 3) * tmp
5085 
5086  alphaavg = half * (uavg**2 + vavg**2 + wavg**2)
5087  havg = alphaavg + ovgm1 * (a2avg - gm53 * kavg)
5088  aavg = sqrt(a2avg)
5089  unavg = uavg * sx + vavg * sy + wavg * sz
5090  ovaavg = one / aavg
5091  ova2avg = one / a2avg
5092 
5093  ! The mesh velocity if the face is moving. It must be
5094  ! divided by the area to obtain a true velocity.
5095 
5096  sface = sfacek(i, j, k) * tmp
5097 
5098  ! Compute the absolute values of the three eigenvalues
5099  ! and make sure they don't become zero by cutting them
5100  ! off to a certain minimum.
5101 
5102  lam1 = abs(unavg - sface + aavg)
5103  lam2 = abs(unavg - sface - aavg)
5104  lam3 = abs(unavg - sface)
5105 
5106  rrad = lam3 + aavg
5107 
5108  ! Multiply the eigenvalues by the area to obtain
5109  ! the correct values for the dissipation term.
5110 
5111  lam1 = max(lam1, epsacoustic * rrad) * area
5112  lam2 = max(lam2, epsacoustic * rrad) * area
5113  lam3 = max(lam3, epsshear * rrad) * area
5114 
5115  ! Some abbreviations, which occur quite often in the
5116  ! dissipation terms.
5117 
5118  abv1 = half * (lam1 + lam2)
5119  abv2 = half * (lam1 - lam2)
5120  abv3 = abv1 - lam3
5121 
5122  abv4 = gm1 * (alphaavg * dr - uavg * dru - vavg * drv &
5123  - wavg * drw + dre) - gm53 * drk
5124  abv5 = sx * dru + sy * drv + sz * drw - unavg * dr
5125 
5126  abv6 = abv3 * abv4 * ova2avg + abv2 * abv5 * ovaavg
5127  abv7 = abv2 * abv4 * ovaavg + abv3 * abv5
5128 
5129  ! Compute and scatter the dissipative flux.
5130  ! Density.
5131 
5132  fs = lam3 * dr + abv6
5133  fw(i, j, k + 1, irho) = fw(i, j, k + 1, irho) + fs
5134  fw(i, j, k, irho) = fw(i, j, k, irho) - fs
5135 
5136  ! X-momentum.
5137 
5138  fs = lam3 * dru + uavg * abv6 + sx * abv7
5139  fw(i, j, k + 1, imx) = fw(i, j, k + 1, imx) + fs
5140  fw(i, j, k, imx) = fw(i, j, k, imx) - fs
5141 
5142  ! Y-momentum.
5143 
5144  fs = lam3 * drv + vavg * abv6 + sy * abv7
5145  fw(i, j, k + 1, imy) = fw(i, j, k + 1, imy) + fs
5146  fw(i, j, k, imy) = fw(i, j, k, imy) - fs
5147 
5148  ! Z-momentum.
5149 
5150  fs = lam3 * drw + wavg * abv6 + sz * abv7
5151  fw(i, j, k + 1, imz) = fw(i, j, k + 1, imz) + fs
5152  fw(i, j, k, imz) = fw(i, j, k, imz) - fs
5153 
5154  ! Energy.
5155 
5156  fs = lam3 * dre + havg * abv6 + unavg * abv7
5157  fw(i, j, k + 1, irhoe) = fw(i, j, k + 1, irhoe) + fs
5158  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - fs
5159 
5160  end do
5161  end do
5162  end do
5163 
5164  end subroutine invisciddissfluxmatrixapprox
5165 
5167  ! ---------------------------------------------
5168  ! Compute the speed of sound squared
5169  ! ---------------------------------------------
5170  use constants
5171  use utils, only: getcorrectfork
5172  implicit none
5173 
5174  ! Variables for speed of sound
5175  logical :: correctForK
5176  real(kind=realtype) :: pp
5177  real(kind=realtype), parameter :: twothird = two * third
5178  integer(kind=intType) :: i, j, k
5179 
5180  ! Determine if we need to correct for K
5181  correctfork = getcorrectfork()
5182 
5183  if (correctfork) then
5184  do k = 1, ke
5185  do j = 1, je
5186  do i = singlehalostart, ie
5187  pp = p(i, j, k) - twothird * w(i, j, k, irho) * w(i, j, k, itu1)
5188  aa(i, j, k) = gamma(i, j, k) * pp / w(i, j, k, irho)
5189  end do
5190  end do
5191  end do
5192  else
5193  do k = 1, ke
5194  do j = 1, je
5195  do i = singlehalostart, ie
5196  aa(i, j, k) = gamma(i, j, k) * p(i, j, k) / w(i, j, k, irho)
5197  end do
5198  end do
5199  end do
5200  end if
5201  end subroutine computespeedofsoundsquared
5202 
5204 
5205  ! ---------------------------------------------
5206  ! Compute nodal gradients
5207  ! ---------------------------------------------
5208  use constants
5209  implicit none
5210 
5211  ! Variables for nodal gradients
5212  real(kind=realtype) :: a2, ovol, ubar, vbar, wbar, sx, sy, sz
5213  integer(kind=intType) :: i, j, k
5214 
5215  ! Zero just the required part of the nodal gradients since the
5216  ! first value may be useful.
5217  ux(nodestart:, :, :) = zero
5218  uy(nodestart:, :, :) = zero
5219  uz(nodestart:, :, :) = zero
5220 
5221  vx(nodestart:, :, :) = zero
5222  vy(nodestart:, :, :) = zero
5223  vz(nodestart:, :, :) = zero
5224 
5225  wx(nodestart:, :, :) = zero
5226  wy(nodestart:, :, :) = zero
5227  wz(nodestart:, :, :) = zero
5228 
5229  qx(nodestart:, :, :) = zero
5230  qy(nodestart:, :, :) = zero
5231  qz(nodestart:, :, :) = zero
5232 
5233  ! First part. Contribution in the k-direction.
5234  ! The contribution is scattered to both the left and right node
5235  ! in k-direction.
5236 
5237  do k = 1, ke
5238  do j = 1, jl
5239  do i = nodestart, il
5240 
5241  ! Compute 8 times the average normal for this part of
5242  ! the control volume. The factor 8 is taken care of later
5243  ! on when the division by the volume takes place.
5244 
5245  sx = sk(i, j, k - 1, 1) + sk(i + 1, j, k - 1, 1) &
5246  + sk(i, j + 1, k - 1, 1) + sk(i + 1, j + 1, k - 1, 1) &
5247  + sk(i, j, k, 1) + sk(i + 1, j, k, 1) &
5248  + sk(i, j + 1, k, 1) + sk(i + 1, j + 1, k, 1)
5249  sy = sk(i, j, k - 1, 2) + sk(i + 1, j, k - 1, 2) &
5250  + sk(i, j + 1, k - 1, 2) + sk(i + 1, j + 1, k - 1, 2) &
5251  + sk(i, j, k, 2) + sk(i + 1, j, k, 2) &
5252  + sk(i, j + 1, k, 2) + sk(i + 1, j + 1, k, 2)
5253  sz = sk(i, j, k - 1, 3) + sk(i + 1, j, k - 1, 3) &
5254  + sk(i, j + 1, k - 1, 3) + sk(i + 1, j + 1, k - 1, 3) &
5255  + sk(i, j, k, 3) + sk(i + 1, j, k, 3) &
5256  + sk(i, j + 1, k, 3) + sk(i + 1, j + 1, k, 3)
5257 
5258  ! Compute the average velocities and speed of sound squared
5259  ! for this integration point. Node that these variables are
5260  ! stored in w(ivx), w(ivy), w(ivz) and p.
5261 
5262  ubar = fourth * (w(i, j, k, ivx) + w(i + 1, j, k, ivx) &
5263  + w(i, j + 1, k, ivx) + w(i + 1, j + 1, k, ivx))
5264  vbar = fourth * (w(i, j, k, ivy) + w(i + 1, j, k, ivy) &
5265  + w(i, j + 1, k, ivy) + w(i + 1, j + 1, k, ivy))
5266  wbar = fourth * (w(i, j, k, ivz) + w(i + 1, j, k, ivz) &
5267  + w(i, j + 1, k, ivz) + w(i + 1, j + 1, k, ivz))
5268 
5269  a2 = fourth * (aa(i, j, k) + aa(i + 1, j, k) + aa(i, j + 1, k) + aa(i + 1, j + 1, k))
5270 
5271  ! Add the contributions to the surface integral to the node
5272  ! j-1 and substract it from the node j. For the heat flux it
5273  ! is reversed, because the negative of the gradient of the
5274  ! speed of sound must be computed.
5275 
5276  if (k > 1) then
5277  ux(i, j, k - 1) = ux(i, j, k - 1) + ubar * sx
5278  uy(i, j, k - 1) = uy(i, j, k - 1) + ubar * sy
5279  uz(i, j, k - 1) = uz(i, j, k - 1) + ubar * sz
5280 
5281  vx(i, j, k - 1) = vx(i, j, k - 1) + vbar * sx
5282  vy(i, j, k - 1) = vy(i, j, k - 1) + vbar * sy
5283  vz(i, j, k - 1) = vz(i, j, k - 1) + vbar * sz
5284 
5285  wx(i, j, k - 1) = wx(i, j, k - 1) + wbar * sx
5286  wy(i, j, k - 1) = wy(i, j, k - 1) + wbar * sy
5287  wz(i, j, k - 1) = wz(i, j, k - 1) + wbar * sz
5288 
5289  qx(i, j, k - 1) = qx(i, j, k - 1) - a2 * sx
5290  qy(i, j, k - 1) = qy(i, j, k - 1) - a2 * sy
5291  qz(i, j, k - 1) = qz(i, j, k - 1) - a2 * sz
5292  end if
5293 
5294  if (k < ke) then
5295  ux(i, j, k) = ux(i, j, k) - ubar * sx
5296  uy(i, j, k) = uy(i, j, k) - ubar * sy
5297  uz(i, j, k) = uz(i, j, k) - ubar * sz
5298 
5299  vx(i, j, k) = vx(i, j, k) - vbar * sx
5300  vy(i, j, k) = vy(i, j, k) - vbar * sy
5301  vz(i, j, k) = vz(i, j, k) - vbar * sz
5302 
5303  wx(i, j, k) = wx(i, j, k) - wbar * sx
5304  wy(i, j, k) = wy(i, j, k) - wbar * sy
5305  wz(i, j, k) = wz(i, j, k) - wbar * sz
5306 
5307  qx(i, j, k) = qx(i, j, k) + a2 * sx
5308  qy(i, j, k) = qy(i, j, k) + a2 * sy
5309  qz(i, j, k) = qz(i, j, k) + a2 * sz
5310  end if
5311  end do
5312  end do
5313  end do
5314 
5315  ! Second part. Contribution in the j-direction.
5316  ! The contribution is scattered to both the left and right node
5317  ! in j-direction.
5318 
5319  do k = 1, kl
5320  do j = 1, je
5321  do i = nodestart, il
5322 
5323  ! Compute 8 times the average normal for this part of
5324  ! the control volume. The factor 8 is taken care of later
5325  ! on when the division by the volume takes place.
5326 
5327  sx = sj(i, j - 1, k, 1) + sj(i + 1, j - 1, k, 1) &
5328  + sj(i, j - 1, k + 1, 1) + sj(i + 1, j - 1, k + 1, 1) &
5329  + sj(i, j, k, 1) + sj(i + 1, j, k, 1) &
5330  + sj(i, j, k + 1, 1) + sj(i + 1, j, k + 1, 1)
5331  sy = sj(i, j - 1, k, 2) + sj(i + 1, j - 1, k, 2) &
5332  + sj(i, j - 1, k + 1, 2) + sj(i + 1, j - 1, k + 1, 2) &
5333  + sj(i, j, k, 2) + sj(i + 1, j, k, 2) &
5334  + sj(i, j, k + 1, 2) + sj(i + 1, j, k + 1, 2)
5335  sz = sj(i, j - 1, k, 3) + sj(i + 1, j - 1, k, 3) &
5336  + sj(i, j - 1, k + 1, 3) + sj(i + 1, j - 1, k + 1, 3) &
5337  + sj(i, j, k, 3) + sj(i + 1, j, k, 3) &
5338  + sj(i, j, k + 1, 3) + sj(i + 1, j, k + 1, 3)
5339 
5340  ! Compute the average velocities and speed of sound squared
5341  ! for this integration point. Node that these variables are
5342  ! stored in w(ivx), w(ivy), w(ivz) and p.
5343 
5344  ubar = fourth * (w(i, j, k, ivx) + w(i + 1, j, k, ivx) &
5345  + w(i, j, k + 1, ivx) + w(i + 1, j, k + 1, ivx))
5346  vbar = fourth * (w(i, j, k, ivy) + w(i + 1, j, k, ivy) &
5347  + w(i, j, k + 1, ivy) + w(i + 1, j, k + 1, ivy))
5348  wbar = fourth * (w(i, j, k, ivz) + w(i + 1, j, k, ivz) &
5349  + w(i, j, k + 1, ivz) + w(i + 1, j, k + 1, ivz))
5350 
5351  a2 = fourth * (aa(i, j, k) + aa(i + 1, j, k) + aa(i, j, k + 1) + aa(i + 1, j, k + 1))
5352 
5353  ! Add the contributions to the surface integral to the node
5354  ! j-1 and substract it from the node j. For the heat flux it
5355  ! is reversed, because the negative of the gradient of the
5356  ! speed of sound must be computed.
5357 
5358  if (j > 1) then
5359  ux(i, j - 1, k) = ux(i, j - 1, k) + ubar * sx
5360  uy(i, j - 1, k) = uy(i, j - 1, k) + ubar * sy
5361  uz(i, j - 1, k) = uz(i, j - 1, k) + ubar * sz
5362 
5363  vx(i, j - 1, k) = vx(i, j - 1, k) + vbar * sx
5364  vy(i, j - 1, k) = vy(i, j - 1, k) + vbar * sy
5365  vz(i, j - 1, k) = vz(i, j - 1, k) + vbar * sz
5366 
5367  wx(i, j - 1, k) = wx(i, j - 1, k) + wbar * sx
5368  wy(i, j - 1, k) = wy(i, j - 1, k) + wbar * sy
5369  wz(i, j - 1, k) = wz(i, j - 1, k) + wbar * sz
5370 
5371  qx(i, j - 1, k) = qx(i, j - 1, k) - a2 * sx
5372  qy(i, j - 1, k) = qy(i, j - 1, k) - a2 * sy
5373  qz(i, j - 1, k) = qz(i, j - 1, k) - a2 * sz
5374  end if
5375 
5376  if (j < je) then
5377  ux(i, j, k) = ux(i, j, k) - ubar * sx
5378  uy(i, j, k) = uy(i, j, k) - ubar * sy
5379  uz(i, j, k) = uz(i, j, k) - ubar * sz
5380 
5381  vx(i, j, k) = vx(i, j, k) - vbar * sx
5382  vy(i, j, k) = vy(i, j, k) - vbar * sy
5383  vz(i, j, k) = vz(i, j, k) - vbar * sz
5384 
5385  wx(i, j, k) = wx(i, j, k) - wbar * sx
5386  wy(i, j, k) = wy(i, j, k) - wbar * sy
5387  wz(i, j, k) = wz(i, j, k) - wbar * sz
5388 
5389  qx(i, j, k) = qx(i, j, k) + a2 * sx
5390  qy(i, j, k) = qy(i, j, k) + a2 * sy
5391  qz(i, j, k) = qz(i, j, k) + a2 * sz
5392  end if
5393  end do
5394  end do
5395  end do
5396  !
5397  ! Third part. Contribution in the i-direction.
5398  ! The contribution is scattered to both the left and right node
5399  ! in i-direction.
5400  !
5401  do k = 1, kl
5402  do j = 1, jl
5403  do i = nodestart, ie
5404 
5405  ! Compute 8 times the average normal for this part of
5406  ! the control volume. The factor 8 is taken care of later
5407  ! on when the division by the volume takes place.
5408 
5409  sx = si(i - 1, j, k, 1) + si(i - 1, j + 1, k, 1) &
5410  + si(i - 1, j, k + 1, 1) + si(i - 1, j + 1, k + 1, 1) &
5411  + si(i, j, k, 1) + si(i, j + 1, k, 1) &
5412  + si(i, j, k + 1, 1) + si(i, j + 1, k + 1, 1)
5413  sy = si(i - 1, j, k, 2) + si(i - 1, j + 1, k, 2) &
5414  + si(i - 1, j, k + 1, 2) + si(i - 1, j + 1, k + 1, 2) &
5415  + si(i, j, k, 2) + si(i, j + 1, k, 2) &
5416  + si(i, j, k + 1, 2) + si(i, j + 1, k + 1, 2)
5417  sz = si(i - 1, j, k, 3) + si(i - 1, j + 1, k, 3) &
5418  + si(i - 1, j, k + 1, 3) + si(i - 1, j + 1, k + 1, 3) &
5419  + si(i, j, k, 3) + si(i, j + 1, k, 3) &
5420  + si(i, j, k + 1, 3) + si(i, j + 1, k + 1, 3)
5421 
5422  ! Compute the average velocities and speed of sound squared
5423  ! for this integration point. Node that these variables are
5424  ! stored in w(ivx), w(ivy), w(ivz) and p.
5425 
5426  ubar = fourth * (w(i, j, k, ivx) + w(i, j + 1, k, ivx) &
5427  + w(i, j, k + 1, ivx) + w(i, j + 1, k + 1, ivx))
5428  vbar = fourth * (w(i, j, k, ivy) + w(i, j + 1, k, ivy) &
5429  + w(i, j, k + 1, ivy) + w(i, j + 1, k + 1, ivy))
5430  wbar = fourth * (w(i, j, k, ivz) + w(i, j + 1, k, ivz) &
5431  + w(i, j, k + 1, ivz) + w(i, j + 1, k + 1, ivz))
5432 
5433  a2 = fourth * (aa(i, j, k) + aa(i, j + 1, k) + aa(i, j, k + 1) + aa(i, j + 1, k + 1))
5434 
5435  ! Add the contributions to the surface integral to the node
5436  ! j-1 and substract it from the node j. For the heat flux it
5437  ! is reversed, because the negative of the gradient of the
5438  ! speed of sound must be computed.
5439 
5440  if (i > nodestart) then
5441  ux(i - 1, j, k) = ux(i - 1, j, k) + ubar * sx
5442  uy(i - 1, j, k) = uy(i - 1, j, k) + ubar * sy
5443  uz(i - 1, j, k) = uz(i - 1, j, k) + ubar * sz
5444 
5445  vx(i - 1, j, k) = vx(i - 1, j, k) + vbar * sx
5446  vy(i - 1, j, k) = vy(i - 1, j, k) + vbar * sy
5447  vz(i - 1, j, k) = vz(i - 1, j, k) + vbar * sz
5448 
5449  wx(i - 1, j, k) = wx(i - 1, j, k) + wbar * sx
5450  wy(i - 1, j, k) = wy(i - 1, j, k) + wbar * sy
5451  wz(i - 1, j, k) = wz(i - 1, j, k) + wbar * sz
5452 
5453  qx(i - 1, j, k) = qx(i - 1, j, k) - a2 * sx
5454  qy(i - 1, j, k) = qy(i - 1, j, k) - a2 * sy
5455  qz(i - 1, j, k) = qz(i - 1, j, k) - a2 * sz
5456  end if
5457 
5458  if (i < ie) then
5459  ux(i, j, k) = ux(i, j, k) - ubar * sx
5460  uy(i, j, k) = uy(i, j, k) - ubar * sy
5461  uz(i, j, k) = uz(i, j, k) - ubar * sz
5462 
5463  vx(i, j, k) = vx(i, j, k) - vbar * sx
5464  vy(i, j, k) = vy(i, j, k) - vbar * sy
5465  vz(i, j, k) = vz(i, j, k) - vbar * sz
5466 
5467  wx(i, j, k) = wx(i, j, k) - wbar * sx
5468  wy(i, j, k) = wy(i, j, k) - wbar * sy
5469  wz(i, j, k) = wz(i, j, k) - wbar * sz
5470 
5471  qx(i, j, k) = qx(i, j, k) + a2 * sx
5472  qy(i, j, k) = qy(i, j, k) + a2 * sy
5473  qz(i, j, k) = qz(i, j, k) + a2 * sz
5474  end if
5475  end do
5476  end do
5477  end do
5478 
5479  ! Divide by 8 times the volume to obtain the correct gradients.
5480 
5481  do k = 1, kl
5482  do j = 1, jl
5483  do i = nodestart, il
5484 
5485  ! Compute the inverse of 8 times the volume for this node.
5486 
5487  ovol = one / (vol(i, j, k) + vol(i, j, k + 1) &
5488  + vol(i + 1, j, k) + vol(i + 1, j, k + 1) &
5489  + vol(i, j + 1, k) + vol(i, j + 1, k + 1) &
5490  + vol(i + 1, j + 1, k) + vol(i + 1, j + 1, k + 1))
5491 
5492  ! Compute the correct velocity gradients and "unit" heat
5493  ! fluxes. The velocity gradients are stored in ux, etc.
5494 
5495  ux(i, j, k) = ux(i, j, k) * ovol
5496  uy(i, j, k) = uy(i, j, k) * ovol
5497  uz(i, j, k) = uz(i, j, k) * ovol
5498 
5499  vx(i, j, k) = vx(i, j, k) * ovol
5500  vy(i, j, k) = vy(i, j, k) * ovol
5501  vz(i, j, k) = vz(i, j, k) * ovol
5502 
5503  wx(i, j, k) = wx(i, j, k) * ovol
5504  wy(i, j, k) = wy(i, j, k) * ovol
5505  wz(i, j, k) = wz(i, j, k) * ovol
5506 
5507  qx(i, j, k) = qx(i, j, k) * ovol
5508  qy(i, j, k) = qy(i, j, k) * ovol
5509  qz(i, j, k) = qz(i, j, k) * ovol
5510  end do
5511  end do
5512  end do
5513  end subroutine allnodalgradients
5514 
5515  subroutine viscousflux(storeWallTensor)
5516  ! ---------------------------------------------
5517  ! Viscous Flux
5518  ! ---------------------------------------------
5519 
5520  use constants
5521  use inputphysics, only: useqcr, prandtl, prandtlturb
5522  use flowvarrefstate, only: eddymodel
5523  use iteration, only: rfil
5524  use blockpointers, only: bil => il, bjl => jl, bkl => kl, &
5528  implicit none
5529 
5530  ! Input
5531  logical, intent(in), optional :: storeWallTensor
5532 
5533  ! Variables for viscous flux
5534  real(kind=realtype) :: rfilv, por, mul, mue, mut, heatcoef
5535  real(kind=realtype) :: gm1, factlamheat, factturbheat
5536  real(kind=realtype) :: u_x, u_y, u_z, v_x, v_y, v_z, w_x, w_y, w_z
5537  real(kind=realtype) :: q_x, q_y, q_z
5538  real(kind=realtype) :: corr, ssx, ssy, ssz, fracdiv, snrm
5539  real(kind=realtype) :: tauxx, tauyy, tauzz
5540  real(kind=realtype) :: tauxy, tauxz, tauyz
5541  real(kind=realtype) :: tauxxs, tauyys, tauzzs
5542  real(kind=realtype) :: tauxys, tauxzs, tauyzs
5543  real(kind=realtype) :: ubar, vbar, wbar
5544  real(kind=realtype) :: exx, eyy, ezz
5545  real(kind=realtype) :: exy, exz, eyz
5546  real(kind=realtype) :: wxx, wyy, wzz
5547  real(kind=realtype) :: wxy, wxz, wyz, wyx, wzx, wzy
5548  real(kind=realtype) :: den, ccr1
5549  real(kind=realtype) :: fmx, fmy, fmz, frhoe, fact
5550  integer(kind=intType) :: i, j, k, io, jo, ko
5551  real(kind=realtype), parameter :: xminn = 1.e-10_realtype
5552  real(kind=realtype), parameter :: twothird = two * third
5553  real(kind=realtype), dimension(9, 2:max(il, jl), 2:max(jl, kl), 2) :: tmpstore
5554 
5555  logical :: storeWall
5556 
5557  storewall = .false.
5558  if (present(storewalltensor)) then
5559  storewall = storewalltensor
5560  end if
5561 
5562  ! Set QCR parameters
5563  ccr1 = 0.3_realtype
5564  rfilv = rfil
5565 
5566  ! The diagonals of the vorticity tensor components are always zero
5567  wxx = zero
5568  wyy = zero
5569  wzz = zero
5570  !
5571  ! viscous fluxes in the k-direction.
5572  !
5573  mue = zero
5574  do k = 1, kl
5575  do j = 2, jl
5576  do i = 2, il
5577 
5578  ! Set the value of the porosity. If not zero, it is set
5579  ! to average the eddy-viscosity and to take the factor
5580  ! rFilv into account.
5581 
5582  por = half * rfilv
5583  if (pork(i, j, k) == noflux) por = zero
5584 
5585  ! Compute the laminar and (if present) the eddy viscosities
5586  ! multiplied by the porosity. Compute the factor in front of
5587  ! the gradients of the speed of sound squared for the heat
5588  ! flux.
5589 
5590  mul = por * (rlv(i, j, k) + rlv(i, j, k + 1))
5591  mue = por * (rev(i, j, k) + rev(i, j, k + 1))
5592  mut = mul + mue
5593 
5594  gm1 = half * (gamma(i, j, k) + gamma(i, j, k + 1)) - one
5595  factlamheat = one / (prandtl * gm1)
5596  factturbheat = one / (prandtlturb * gm1)
5597 
5598  heatcoef = mul * factlamheat + mue * factturbheat
5599 
5600  ! Compute the gradients at the face by averaging the four
5601  ! nodal values.
5602 
5603  u_x = fourth * (ux(i - 1, j - 1, k) + ux(i, j - 1, k) &
5604  + ux(i - 1, j, k) + ux(i, j, k))
5605  u_y = fourth * (uy(i - 1, j - 1, k) + uy(i, j - 1, k) &
5606  + uy(i - 1, j, k) + uy(i, j, k))
5607  u_z = fourth * (uz(i - 1, j - 1, k) + uz(i, j - 1, k) &
5608  + uz(i - 1, j, k) + uz(i, j, k))
5609 
5610  v_x = fourth * (vx(i - 1, j - 1, k) + vx(i, j - 1, k) &
5611  + vx(i - 1, j, k) + vx(i, j, k))
5612  v_y = fourth * (vy(i - 1, j - 1, k) + vy(i, j - 1, k) &
5613  + vy(i - 1, j, k) + vy(i, j, k))
5614  v_z = fourth * (vz(i - 1, j - 1, k) + vz(i, j - 1, k) &
5615  + vz(i - 1, j, k) + vz(i, j, k))
5616 
5617  w_x = fourth * (wx(i - 1, j - 1, k) + wx(i, j - 1, k) &
5618  + wx(i - 1, j, k) + wx(i, j, k))
5619  w_y = fourth * (wy(i - 1, j - 1, k) + wy(i, j - 1, k) &
5620  + wy(i - 1, j, k) + wy(i, j, k))
5621  w_z = fourth * (wz(i - 1, j - 1, k) + wz(i, j - 1, k) &
5622  + wz(i - 1, j, k) + wz(i, j, k))
5623 
5624  q_x = fourth * (qx(i - 1, j - 1, k) + qx(i, j - 1, k) &
5625  + qx(i - 1, j, k) + qx(i, j, k))
5626  q_y = fourth * (qy(i - 1, j - 1, k) + qy(i, j - 1, k) &
5627  + qy(i - 1, j, k) + qy(i, j, k))
5628  q_z = fourth * (qz(i - 1, j - 1, k) + qz(i, j - 1, k) &
5629  + qz(i - 1, j, k) + qz(i, j, k))
5630 
5631  ! The gradients in the normal direction are corrected, such
5632  ! that no averaging takes places here.
5633  ! First determine the vector in the direction from the
5634  ! cell center k to cell center k+1.
5635 
5636  ssx = eighth * (x(i - 1, j - 1, k + 1, 1) - x(i - 1, j - 1, k - 1, 1) &
5637  + x(i - 1, j, k + 1, 1) - x(i - 1, j, k - 1, 1) &
5638  + x(i, j - 1, k + 1, 1) - x(i, j - 1, k - 1, 1) &
5639  + x(i, j, k + 1, 1) - x(i, j, k - 1, 1))
5640  ssy = eighth * (x(i - 1, j - 1, k + 1, 2) - x(i - 1, j - 1, k - 1, 2) &
5641  + x(i - 1, j, k + 1, 2) - x(i - 1, j, k - 1, 2) &
5642  + x(i, j - 1, k + 1, 2) - x(i, j - 1, k - 1, 2) &
5643  + x(i, j, k + 1, 2) - x(i, j, k - 1, 2))
5644  ssz = eighth * (x(i - 1, j - 1, k + 1, 3) - x(i - 1, j - 1, k - 1, 3) &
5645  + x(i - 1, j, k + 1, 3) - x(i - 1, j, k - 1, 3) &
5646  + x(i, j - 1, k + 1, 3) - x(i, j - 1, k - 1, 3) &
5647  + x(i, j, k + 1, 3) - x(i, j, k - 1, 3))
5648 
5649  ! Determine the length of this vector and create the
5650  ! unit normal.
5651 
5652  snrm = one / sqrt(ssx * ssx + ssy * ssy + ssz * ssz)
5653  ssx = snrm * ssx
5654  ssy = snrm * ssy
5655  ssz = snrm * ssz
5656 
5657  ! Correct the gradients.
5658 
5659  corr = u_x * ssx + u_y * ssy + u_z * ssz &
5660  - (w(i, j, k + 1, ivx) - w(i, j, k, ivx)) * snrm
5661  u_x = u_x - corr * ssx
5662  u_y = u_y - corr * ssy
5663  u_z = u_z - corr * ssz
5664 
5665  corr = v_x * ssx + v_y * ssy + v_z * ssz &
5666  - (w(i, j, k + 1, ivy) - w(i, j, k, ivy)) * snrm
5667  v_x = v_x - corr * ssx
5668  v_y = v_y - corr * ssy
5669  v_z = v_z - corr * ssz
5670 
5671  corr = w_x * ssx + w_y * ssy + w_z * ssz &
5672  - (w(i, j, k + 1, ivz) - w(i, j, k, ivz)) * snrm
5673  w_x = w_x - corr * ssx
5674  w_y = w_y - corr * ssy
5675  w_z = w_z - corr * ssz
5676 
5677  corr = q_x * ssx + q_y * ssy + q_z * ssz &
5678  + (aa(i, j, k + 1) - aa(i, j, k)) * snrm
5679  q_x = q_x - corr * ssx
5680  q_y = q_y - corr * ssy
5681  q_z = q_z - corr * ssz
5682 
5683  ! Compute the stress tensor and the heat flux vector.
5684  ! We remove the viscosity from the stress tensor (tau)
5685  ! to define tauS since we still need to separate between
5686  ! laminar and turbulent stress for QCR.
5687  ! Therefore, laminar tau = mue*tauS, turbulent
5688  ! tau = mue*tauS, and total tau = mut*tauS.
5689 
5690  fracdiv = twothird * (u_x + v_y + w_z)
5691 
5692  tauxxs = two * u_x - fracdiv
5693  tauyys = two * v_y - fracdiv
5694  tauzzs = two * w_z - fracdiv
5695 
5696  tauxys = u_y + v_x
5697  tauxzs = u_z + w_x
5698  tauyzs = v_z + w_y
5699 
5700  q_x = heatcoef * q_x
5701  q_y = heatcoef * q_y
5702  q_z = heatcoef * q_z
5703 
5704  ! Add QCR corrections if necessary
5705  if (useqcr) then
5706 
5707  ! In the QCR formulation, we add an extra term to the turbulent stress tensor:
5708  !
5709  ! tau_ij,QCR = tau_ij - e_ij
5710  !
5711  ! where, according to TMR website (http://turbmodels.larc.nasa.gov/spalart.html):
5712  !
5713  ! e_ij = Ccr1*(O_ik*tau_jk + O_jk*tau_ik)
5714  !
5715  ! We are computing O_ik as follows:
5716  !
5717  ! O_ik = 2*W_ik/den
5718  !
5719  ! Remember that the tau_ij in e_ij should use only the eddy viscosity!
5720 
5721  ! Compute denominator
5722  den = sqrt(u_x * u_x + u_y * u_y + u_z * u_z + &
5723  v_x * v_x + v_y * v_y + v_z * v_z + &
5724  w_x * w_x + w_y * w_y + w_z * w_z)
5725 
5726  ! Denominator should be limited to avoid division by zero in regions with
5727  ! no gradients
5728  den = max(den, xminn)
5729 
5730  ! Compute factor that will multiply all tensor components.
5731  ! Here we add the eddy viscosity that should multiply the stress tensor (tau)
5732  ! components as well.
5733  fact = mue * ccr1 / den
5734 
5735  ! Compute off-diagonal terms of vorticity tensor (we will ommit the 1/2)
5736  ! The diagonals of the vorticity tensor components are always zero
5737  wxy = u_y - v_x
5738  wxz = u_z - w_x
5739  wyz = v_z - w_y
5740  wyx = -wxy
5741  wzx = -wxz
5742  wzy = -wyz
5743 
5744  ! Compute the extra terms of the Boussinesq relation
5745  exx = fact * (wxy * tauxys + wxz * tauxzs) * two
5746  eyy = fact * (wyx * tauxys + wyz * tauyzs) * two
5747  ezz = fact * (wzx * tauxzs + wzy * tauyzs) * two
5748 
5749  exy = fact * (wxy * tauyys + wxz * tauyzs + &
5750  wyx * tauxxs + wyz * tauxzs)
5751  exz = fact * (wxy * tauyzs + wxz * tauzzs + &
5752  wzx * tauxxs + wzy * tauxys)
5753  eyz = fact * (wyx * tauxzs + wyz * tauzzs + &
5754  wzx * tauxys + wzy * tauyys)
5755 
5756  ! Apply the total viscosity to the stress tensor and add extra terms
5757  tauxx = mut * tauxxs - exx
5758  tauyy = mut * tauyys - eyy
5759  tauzz = mut * tauzzs - ezz
5760  tauxy = mut * tauxys - exy
5761  tauxz = mut * tauxzs - exz
5762  tauyz = mut * tauyzs - eyz
5763 
5764  else
5765 
5766  ! Just apply the total viscosity to the stress tensor
5767  tauxx = mut * tauxxs
5768  tauyy = mut * tauyys
5769  tauzz = mut * tauzzs
5770  tauxy = mut * tauxys
5771  tauxz = mut * tauxzs
5772  tauyz = mut * tauyzs
5773 
5774  end if
5775 
5776  ! Compute the average velocities for the face. Remember that
5777  ! the velocities are stored and not the momentum.
5778 
5779  ubar = half * (w(i, j, k, ivx) + w(i, j, k + 1, ivx))
5780  vbar = half * (w(i, j, k, ivy) + w(i, j, k + 1, ivy))
5781  wbar = half * (w(i, j, k, ivz) + w(i, j, k + 1, ivz))
5782 
5783  ! Compute the viscous fluxes for this k-face.
5784 
5785  fmx = tauxx * sk(i, j, k, 1) + tauxy * sk(i, j, k, 2) &
5786  + tauxz * sk(i, j, k, 3)
5787  fmy = tauxy * sk(i, j, k, 1) + tauyy * sk(i, j, k, 2) &
5788  + tauyz * sk(i, j, k, 3)
5789  fmz = tauxz * sk(i, j, k, 1) + tauyz * sk(i, j, k, 2) &
5790  + tauzz * sk(i, j, k, 3)
5791  frhoe = (ubar * tauxx + vbar * tauxy + wbar * tauxz) * sk(i, j, k, 1)
5792  frhoe = frhoe + (ubar * tauxy + vbar * tauyy + wbar * tauyz) * sk(i, j, k, 2)
5793  frhoe = frhoe + (ubar * tauxz + vbar * tauyz + wbar * tauzz) * sk(i, j, k, 3)
5794  frhoe = frhoe - q_x * sk(i, j, k, 1) - q_y * sk(i, j, k, 2) - q_z * sk(i, j, k, 3)
5795 
5796  ! Update the residuals of cell k and k+1.
5797 
5798  fw(i, j, k, imx) = fw(i, j, k, imx) - fmx
5799  fw(i, j, k, imy) = fw(i, j, k, imy) - fmy
5800  fw(i, j, k, imz) = fw(i, j, k, imz) - fmz
5801  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - frhoe
5802 
5803  fw(i, j, k + 1, imx) = fw(i, j, k + 1, imx) + fmx
5804  fw(i, j, k + 1, imy) = fw(i, j, k + 1, imy) + fmy
5805  fw(i, j, k + 1, imz) = fw(i, j, k + 1, imz) + fmz
5806  fw(i, j, k + 1, irhoe) = fw(i, j, k + 1, irhoe) + frhoe
5807 
5808  ! Temporarily store the shear stress and heat flux, even
5809  ! if we won't need it. This can still vectorize
5810 
5811  if (k == 1) then
5812  tmpstore(1, i, j, 1) = tauxx
5813  tmpstore(2, i, j, 1) = tauyy
5814  tmpstore(3, i, j, 1) = tauzz
5815  tmpstore(4, i, j, 1) = tauxy
5816  tmpstore(5, i, j, 1) = tauxz
5817  tmpstore(6, i, j, 1) = tauyz
5818 
5819  tmpstore(7, i, j, 1) = q_x
5820  tmpstore(8, i, j, 1) = q_y
5821  tmpstore(9, i, j, 1) = q_z
5822  end if
5823 
5824  if (k == kl) then
5825  tmpstore(1, i, j, 2) = tauxx
5826  tmpstore(2, i, j, 2) = tauyy
5827  tmpstore(3, i, j, 2) = tauzz
5828  tmpstore(4, i, j, 2) = tauxy
5829  tmpstore(5, i, j, 2) = tauxz
5830  tmpstore(6, i, j, 2) = tauyz
5831 
5832  tmpstore(7, i, j, 2) = q_x
5833  tmpstore(8, i, j, 2) = q_y
5834  tmpstore(9, i, j, 2) = q_z
5835  end if
5836 
5837  end do
5838  end do
5839  end do
5840 
5841  ! Save into the subface if necessary
5842  if (storewall) then
5843 
5844  origkmin: if (kk - 1 == 1) then
5845  do j = 2, jl
5846  do i = 2, il
5847  io = i + ii - 2
5848  jo = j + jj - 2
5849 
5850  if (visckminpointer(io, jo) > 0) then
5851  viscsubface(visckminpointer(io, jo))%tau(io, jo, :) = tmpstore(1:6, i, j, 1)
5852  viscsubface(visckminpointer(io, jo))%q(io, jo, :) = tmpstore(7:9, i, j, 1)
5853  end if
5854  end do
5855  end do
5856  end if origkmin
5857 
5858  origkmax: if (kk + nz - 1 == bkl) then
5859  do j = 2, jl
5860  do i = 2, il
5861  io = i + ii - 2
5862  jo = j + jj - 2
5863  if (visckmaxpointer(io, jo) > 0) then
5864  viscsubface(visckmaxpointer(io, jo))%tau(io, jo, :) = tmpstore(1:6, i, j, 2)
5865  viscsubface(visckmaxpointer(io, jo))%q(io, jo, :) = tmpstore(7:9, i, j, 2)
5866  end if
5867  end do
5868  end do
5869  end if origkmax
5870  end if
5871  !
5872  ! Viscous fluxes in the j-direction.
5873  !
5874  do k = 2, kl
5875  do j = 1, jl
5876  do i = 2, il
5877 
5878  ! Set the value of the porosity. If not zero, it is set
5879  ! to average the eddy-viscosity and to take the factor
5880  ! rFilv into account.
5881 
5882  por = half * rfilv
5883  if (porj(i, j, k) == noflux) por = zero
5884 
5885  ! Compute the laminar and (if present) the eddy viscosities
5886  ! multiplied by the porosity. Compute the factor in front of
5887  ! the gradients of the speed of sound squared for the heat
5888  ! flux.
5889 
5890  mul = por * (rlv(i, j, k) + rlv(i, j + 1, k))
5891  mue = por * (rev(i, j, k) + rev(i, j + 1, k))
5892  mut = mul + mue
5893 
5894  gm1 = half * (gamma(i, j, k) + gamma(i, j + 1, k)) - one
5895  factlamheat = one / (prandtl * gm1)
5896  factturbheat = one / (prandtlturb * gm1)
5897 
5898  heatcoef = mul * factlamheat + mue * factturbheat
5899 
5900  ! Compute the gradients at the face by averaging the four
5901  ! nodal values.
5902 
5903  u_x = fourth * (ux(i - 1, j, k - 1) + ux(i, j, k - 1) &
5904  + ux(i - 1, j, k) + ux(i, j, k))
5905  u_y = fourth * (uy(i - 1, j, k - 1) + uy(i, j, k - 1) &
5906  + uy(i - 1, j, k) + uy(i, j, k))
5907  u_z = fourth * (uz(i - 1, j, k - 1) + uz(i, j, k - 1) &
5908  + uz(i - 1, j, k) + uz(i, j, k))
5909 
5910  v_x = fourth * (vx(i - 1, j, k - 1) + vx(i, j, k - 1) &
5911  + vx(i - 1, j, k) + vx(i, j, k))
5912  v_y = fourth * (vy(i - 1, j, k - 1) + vy(i, j, k - 1) &
5913  + vy(i - 1, j, k) + vy(i, j, k))
5914  v_z = fourth * (vz(i - 1, j, k - 1) + vz(i, j, k - 1) &
5915  + vz(i - 1, j, k) + vz(i, j, k))
5916 
5917  w_x = fourth * (wx(i - 1, j, k - 1) + wx(i, j, k - 1) &
5918  + wx(i - 1, j, k) + wx(i, j, k))
5919  w_y = fourth * (wy(i - 1, j, k - 1) + wy(i, j, k - 1) &
5920  + wy(i - 1, j, k) + wy(i, j, k))
5921  w_z = fourth * (wz(i - 1, j, k - 1) + wz(i, j, k - 1) &
5922  + wz(i - 1, j, k) + wz(i, j, k))
5923 
5924  q_x = fourth * (qx(i - 1, j, k - 1) + qx(i, j, k - 1) &
5925  + qx(i - 1, j, k) + qx(i, j, k))
5926  q_y = fourth * (qy(i - 1, j, k - 1) + qy(i, j, k - 1) &
5927  + qy(i - 1, j, k) + qy(i, j, k))
5928  q_z = fourth * (qz(i - 1, j, k - 1) + qz(i, j, k - 1) &
5929  + qz(i - 1, j, k) + qz(i, j, k))
5930 
5931  ! The gradients in the normal direction are corrected, such
5932  ! that no averaging takes places here.
5933  ! First determine the vector in the direction from the
5934  ! cell center j to cell center j+1.
5935 
5936  ssx = eighth * (x(i - 1, j + 1, k - 1, 1) - x(i - 1, j - 1, k - 1, 1) &
5937  + x(i - 1, j + 1, k, 1) - x(i - 1, j - 1, k, 1) &
5938  + x(i, j + 1, k - 1, 1) - x(i, j - 1, k - 1, 1) &
5939  + x(i, j + 1, k, 1) - x(i, j - 1, k, 1))
5940  ssy = eighth * (x(i - 1, j + 1, k - 1, 2) - x(i - 1, j - 1, k - 1, 2) &
5941  + x(i - 1, j + 1, k, 2) - x(i - 1, j - 1, k, 2) &
5942  + x(i, j + 1, k - 1, 2) - x(i, j - 1, k - 1, 2) &
5943  + x(i, j + 1, k, 2) - x(i, j - 1, k, 2))
5944  ssz = eighth * (x(i - 1, j + 1, k - 1, 3) - x(i - 1, j - 1, k - 1, 3) &
5945  + x(i - 1, j + 1, k, 3) - x(i - 1, j - 1, k, 3) &
5946  + x(i, j + 1, k - 1, 3) - x(i, j - 1, k - 1, 3) &
5947  + x(i, j + 1, k, 3) - x(i, j - 1, k, 3))
5948 
5949  ! Determine the length of this vector and create the
5950  ! unit normal.
5951 
5952  snrm = one / sqrt(ssx * ssx + ssy * ssy + ssz * ssz)
5953  ssx = snrm * ssx
5954  ssy = snrm * ssy
5955  ssz = snrm * ssz
5956 
5957  ! Correct the gradients.
5958 
5959  corr = u_x * ssx + u_y * ssy + u_z * ssz &
5960  - (w(i, j + 1, k, ivx) - w(i, j, k, ivx)) * snrm
5961  u_x = u_x - corr * ssx
5962  u_y = u_y - corr * ssy
5963  u_z = u_z - corr * ssz
5964 
5965  corr = v_x * ssx + v_y * ssy + v_z * ssz &
5966  - (w(i, j + 1, k, ivy) - w(i, j, k, ivy)) * snrm
5967  v_x = v_x - corr * ssx
5968  v_y = v_y - corr * ssy
5969  v_z = v_z - corr * ssz
5970 
5971  corr = w_x * ssx + w_y * ssy + w_z * ssz &
5972  - (w(i, j + 1, k, ivz) - w(i, j, k, ivz)) * snrm
5973  w_x = w_x - corr * ssx
5974  w_y = w_y - corr * ssy
5975  w_z = w_z - corr * ssz
5976 
5977  corr = q_x * ssx + q_y * ssy + q_z * ssz &
5978  + (aa(i, j + 1, k) - aa(i, j, k)) * snrm
5979  q_x = q_x - corr * ssx
5980  q_y = q_y - corr * ssy
5981  q_z = q_z - corr * ssz
5982 
5983  ! Compute the stress tensor and the heat flux vector.
5984  ! We remove the viscosity from the stress tensor (tau)
5985  ! to define tauS since we still need to separate between
5986  ! laminar and turbulent stress for QCR.
5987  ! Therefore, laminar tau = mue*tauS, turbulent
5988  ! tau = mue*tauS, and total tau = mut*tauS.
5989 
5990  fracdiv = twothird * (u_x + v_y + w_z)
5991 
5992  tauxxs = two * u_x - fracdiv
5993  tauyys = two * v_y - fracdiv
5994  tauzzs = two * w_z - fracdiv
5995 
5996  tauxys = u_y + v_x
5997  tauxzs = u_z + w_x
5998  tauyzs = v_z + w_y
5999 
6000  q_x = heatcoef * q_x
6001  q_y = heatcoef * q_y
6002  q_z = heatcoef * q_z
6003 
6004  ! Add QCR corrections if necessary
6005  if (useqcr) then
6006 
6007  ! In the QCR formulation, we add an extra term to the turbulent stress tensor:
6008  !
6009  ! tau_ij,QCR = tau_ij - e_ij
6010  !
6011  ! where, according to TMR website (http://turbmodels.larc.nasa.gov/spalart.html):
6012  !
6013  ! e_ij = Ccr1*(O_ik*tau_jk + O_jk*tau_ik)
6014  !
6015  ! We are computing O_ik as follows:
6016  !
6017  ! O_ik = 2*W_ik/den
6018  !
6019  ! Remember that the tau_ij in e_ij should use only the eddy viscosity!
6020 
6021  ! Compute denominator
6022  den = sqrt(u_x * u_x + u_y * u_y + u_z * u_z + &
6023  v_x * v_x + v_y * v_y + v_z * v_z + &
6024  w_x * w_x + w_y * w_y + w_z * w_z)
6025 
6026  ! Denominator should be limited to avoid division by zero in regions with
6027  ! no gradients
6028  den = max(den, xminn)
6029 
6030  ! Compute factor that will multiply all tensor components.
6031  ! Here we add the eddy viscosity that should multiply the stress tensor (tau)
6032  ! components as well.
6033  fact = mue * ccr1 / den
6034 
6035  ! Compute off-diagonal terms of vorticity tensor (we will ommit the 1/2)
6036  ! The diagonals of the vorticity tensor components are always zero
6037  wxy = u_y - v_x
6038  wxz = u_z - w_x
6039  wyz = v_z - w_y
6040  wyx = -wxy
6041  wzx = -wxz
6042  wzy = -wyz
6043 
6044  ! Compute the extra terms of the Boussinesq relation
6045  exx = fact * (wxy * tauxys + wxz * tauxzs) * two
6046  eyy = fact * (wyx * tauxys + wyz * tauyzs) * two
6047  ezz = fact * (wzx * tauxzs + wzy * tauyzs) * two
6048 
6049  exy = fact * (wxy * tauyys + wxz * tauyzs + &
6050  wyx * tauxxs + wyz * tauxzs)
6051  exz = fact * (wxy * tauyzs + wxz * tauzzs + &
6052  wzx * tauxxs + wzy * tauxys)
6053  eyz = fact * (wyx * tauxzs + wyz * tauzzs + &
6054  wzx * tauxys + wzy * tauyys)
6055 
6056  ! Apply the total viscosity to the stress tensor and add extra terms
6057  tauxx = mut * tauxxs - exx
6058  tauyy = mut * tauyys - eyy
6059  tauzz = mut * tauzzs - ezz
6060  tauxy = mut * tauxys - exy
6061  tauxz = mut * tauxzs - exz
6062  tauyz = mut * tauyzs - eyz
6063 
6064  else
6065 
6066  ! Just apply the total viscosity to the stress tensor
6067  tauxx = mut * tauxxs
6068  tauyy = mut * tauyys
6069  tauzz = mut * tauzzs
6070  tauxy = mut * tauxys
6071  tauxz = mut * tauxzs
6072  tauyz = mut * tauyzs
6073 
6074  end if
6075 
6076  ! Compute the average velocities for the face. Remember that
6077  ! the velocities are stored and not the momentum.
6078 
6079  ubar = half * (w(i, j, k, ivx) + w(i, j + 1, k, ivx))
6080  vbar = half * (w(i, j, k, ivy) + w(i, j + 1, k, ivy))
6081  wbar = half * (w(i, j, k, ivz) + w(i, j + 1, k, ivz))
6082 
6083  ! Compute the viscous fluxes for this j-face.
6084 
6085  fmx = tauxx * sj(i, j, k, 1) + tauxy * sj(i, j, k, 2) &
6086  + tauxz * sj(i, j, k, 3)
6087  fmy = tauxy * sj(i, j, k, 1) + tauyy * sj(i, j, k, 2) &
6088  + tauyz * sj(i, j, k, 3)
6089  fmz = tauxz * sj(i, j, k, 1) + tauyz * sj(i, j, k, 2) &
6090  + tauzz * sj(i, j, k, 3)
6091  frhoe = (ubar * tauxx + vbar * tauxy + wbar * tauxz) * sj(i, j, k, 1) &
6092  + (ubar * tauxy + vbar * tauyy + wbar * tauyz) * sj(i, j, k, 2) &
6093  + (ubar * tauxz + vbar * tauyz + wbar * tauzz) * sj(i, j, k, 3) &
6094  - q_x * sj(i, j, k, 1) - q_y * sj(i, j, k, 2) - q_z * sj(i, j, k, 3)
6095 
6096  ! Update the residuals of cell j and j+1.
6097 
6098  fw(i, j, k, imx) = fw(i, j, k, imx) - fmx
6099  fw(i, j, k, imy) = fw(i, j, k, imy) - fmy
6100  fw(i, j, k, imz) = fw(i, j, k, imz) - fmz
6101  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - frhoe
6102 
6103  fw(i, j + 1, k, imx) = fw(i, j + 1, k, imx) + fmx
6104  fw(i, j + 1, k, imy) = fw(i, j + 1, k, imy) + fmy
6105  fw(i, j + 1, k, imz) = fw(i, j + 1, k, imz) + fmz
6106  fw(i, j + 1, k, irhoe) = fw(i, j + 1, k, irhoe) + frhoe
6107 
6108  ! Temporarily store the shear stress and heat flux, even
6109  ! if we won't need it. This can still vectorize
6110 
6111  if (j == 1) then
6112  tmpstore(1, i, k, 1) = tauxx
6113  tmpstore(2, i, k, 1) = tauyy
6114  tmpstore(3, i, k, 1) = tauzz
6115  tmpstore(4, i, k, 1) = tauxy
6116  tmpstore(5, i, k, 1) = tauxz
6117  tmpstore(6, i, k, 1) = tauyz
6118 
6119  tmpstore(7, i, k, 1) = q_x
6120  tmpstore(8, i, k, 1) = q_y
6121  tmpstore(9, i, k, 1) = q_z
6122  end if
6123 
6124  if (j == jl) then
6125  tmpstore(1, i, k, 2) = tauxx
6126  tmpstore(2, i, k, 2) = tauyy
6127  tmpstore(3, i, k, 2) = tauzz
6128  tmpstore(4, i, k, 2) = tauxy
6129  tmpstore(5, i, k, 2) = tauxz
6130  tmpstore(6, i, k, 2) = tauyz
6131 
6132  tmpstore(7, i, k, 2) = q_x
6133  tmpstore(8, i, k, 2) = q_y
6134  tmpstore(9, i, k, 2) = q_z
6135  end if
6136  end do
6137  end do
6138  end do
6139  ! Save into the subface if necessary
6140  if (storewall) then
6141  origjmin: if (jj - 1 == 1) then
6142  do k = 2, kl
6143  do i = 2, il
6144  io = i + ii - 2
6145  ko = k + kk - 2
6146 
6147  if (viscjminpointer(io, ko) > 0) then
6148  viscsubface(viscjminpointer(io, ko))%tau(io, ko, :) = tmpstore(1:6, i, k, 1)
6149  viscsubface(viscjminpointer(io, ko))%q(io, ko, :) = tmpstore(7:9, i, k, 1)
6150  end if
6151  end do
6152  end do
6153  end if origjmin
6154 
6155  origjmax: if (jj + ny - 1 == bjl) then
6156  do k = 2, kl
6157  do i = 2, il
6158  io = i + ii - 2
6159  ko = k + kk - 2
6160  if (viscjmaxpointer(io, ko) > 0) then
6161  viscsubface(viscjmaxpointer(io, ko))%tau(io, ko, :) = tmpstore(1:6, i, k, 2)
6162  viscsubface(viscjmaxpointer(io, ko))%q(io, ko, :) = tmpstore(7:9, i, k, 2)
6163  end if
6164  end do
6165  end do
6166  end if origjmax
6167  end if
6168  !
6169  ! Viscous fluxes in the i-direction.
6170  !
6171  do k = 2, kl
6172  do j = 2, jl
6173  do i = 1, il
6174  ! Set the value of the porosity. If not zero, it is set
6175  ! to average the eddy-viscosity and to take the factor
6176  ! rFilv into account.
6177 
6178  por = half * rfilv
6179  if (pori(i, j, k) == noflux) por = zero
6180 
6181  ! Compute the laminar and (if present) the eddy viscosities
6182  ! multiplied the porosity. Compute the factor in front of
6183  ! the gradients of the speed of sound squared for the heat
6184  ! flux.
6185 
6186  mul = por * (rlv(i, j, k) + rlv(i + 1, j, k))
6187  mue = por * (rev(i, j, k) + rev(i + 1, j, k))
6188  mut = mul + mue
6189 
6190  gm1 = half * (gamma(i, j, k) + gamma(i + 1, j, k)) - one
6191  factlamheat = one / (prandtl * gm1)
6192  factturbheat = one / (prandtlturb * gm1)
6193 
6194  heatcoef = mul * factlamheat + mue * factturbheat
6195 
6196  ! Compute the gradients at the face by averaging the four
6197  ! nodal values.
6198 
6199  u_x = fourth * (ux(i, j - 1, k - 1) + ux(i, j, k - 1) &
6200  + ux(i, j - 1, k) + ux(i, j, k))
6201  u_y = fourth * (uy(i, j - 1, k - 1) + uy(i, j, k - 1) &
6202  + uy(i, j - 1, k) + uy(i, j, k))
6203  u_z = fourth * (uz(i, j - 1, k - 1) + uz(i, j, k - 1) &
6204  + uz(i, j - 1, k) + uz(i, j, k))
6205 
6206  v_x = fourth * (vx(i, j - 1, k - 1) + vx(i, j, k - 1) &
6207  + vx(i, j - 1, k) + vx(i, j, k))
6208  v_y = fourth * (vy(i, j - 1, k - 1) + vy(i, j, k - 1) &
6209  + vy(i, j - 1, k) + vy(i, j, k))
6210  v_z = fourth * (vz(i, j - 1, k - 1) + vz(i, j, k - 1) &
6211  + vz(i, j - 1, k) + vz(i, j, k))
6212 
6213  w_x = fourth * (wx(i, j - 1, k - 1) + wx(i, j, k - 1) &
6214  + wx(i, j - 1, k) + wx(i, j, k))
6215  w_y = fourth * (wy(i, j - 1, k - 1) + wy(i, j, k - 1) &
6216  + wy(i, j - 1, k) + wy(i, j, k))
6217  w_z = fourth * (wz(i, j - 1, k - 1) + wz(i, j, k - 1) &
6218  + wz(i, j - 1, k) + wz(i, j, k))
6219 
6220  q_x = fourth * (qx(i, j - 1, k - 1) + qx(i, j, k - 1) &
6221  + qx(i, j - 1, k) + qx(i, j, k))
6222  q_y = fourth * (qy(i, j - 1, k - 1) + qy(i, j, k - 1) &
6223  + qy(i, j - 1, k) + qy(i, j, k))
6224  q_z = fourth * (qz(i, j - 1, k - 1) + qz(i, j, k - 1) &
6225  + qz(i, j - 1, k) + qz(i, j, k))
6226 
6227  ! The gradients in the normal direction are corrected, such
6228  ! that no averaging takes places here.
6229  ! First determine the vector in the direction from the
6230  ! cell center i to cell center i+1.
6231 
6232  ssx = eighth * (x(i + 1, j - 1, k - 1, 1) - x(i - 1, j - 1, k - 1, 1) &
6233  + x(i + 1, j - 1, k, 1) - x(i - 1, j - 1, k, 1) &
6234  + x(i + 1, j, k - 1, 1) - x(i - 1, j, k - 1, 1) &
6235  + x(i + 1, j, k, 1) - x(i - 1, j, k, 1))
6236  ssy = eighth * (x(i + 1, j - 1, k - 1, 2) - x(i - 1, j - 1, k - 1, 2) &
6237  + x(i + 1, j - 1, k, 2) - x(i - 1, j - 1, k, 2) &
6238  + x(i + 1, j, k - 1, 2) - x(i - 1, j, k - 1, 2) &
6239  + x(i + 1, j, k, 2) - x(i - 1, j, k, 2))
6240  ssz = eighth * (x(i + 1, j - 1, k - 1, 3) - x(i - 1, j - 1, k - 1, 3) &
6241  + x(i + 1, j - 1, k, 3) - x(i - 1, j - 1, k, 3) &
6242  + x(i + 1, j, k - 1, 3) - x(i - 1, j, k - 1, 3) &
6243  + x(i + 1, j, k, 3) - x(i - 1, j, k, 3))
6244 
6245  ! Determine the length of this vector and create the
6246  ! unit normal.
6247 
6248  snrm = one / sqrt(ssx * ssx + ssy * ssy + ssz * ssz)
6249  ssx = snrm * ssx
6250  ssy = snrm * ssy
6251  ssz = snrm * ssz
6252 
6253  ! Correct the gradients.
6254 
6255  corr = u_x * ssx + u_y * ssy + u_z * ssz &
6256  - (w(i + 1, j, k, ivx) - w(i, j, k, ivx)) * snrm
6257  u_x = u_x - corr * ssx
6258  u_y = u_y - corr * ssy
6259  u_z = u_z - corr * ssz
6260 
6261  corr = v_x * ssx + v_y * ssy + v_z * ssz &
6262  - (w(i + 1, j, k, ivy) - w(i, j, k, ivy)) * snrm
6263  v_x = v_x - corr * ssx
6264  v_y = v_y - corr * ssy
6265  v_z = v_z - corr * ssz
6266 
6267  corr = w_x * ssx + w_y * ssy + w_z * ssz &
6268  - (w(i + 1, j, k, ivz) - w(i, j, k, ivz)) * snrm
6269  w_x = w_x - corr * ssx
6270  w_y = w_y - corr * ssy
6271  w_z = w_z - corr * ssz
6272 
6273  corr = q_x * ssx + q_y * ssy + q_z * ssz &
6274  + (aa(i + 1, j, k) - aa(i, j, k)) * snrm
6275  q_x = q_x - corr * ssx
6276  q_y = q_y - corr * ssy
6277  q_z = q_z - corr * ssz
6278 
6279  ! Compute the stress tensor and the heat flux vector.
6280  ! We remove the viscosity from the stress tensor (tau)
6281  ! to define tauS since we still need to separate between
6282  ! laminar and turbulent stress for QCR.
6283  ! Therefore, laminar tau = mue*tauS, turbulent
6284  ! tau = mue*tauS, and total tau = mut*tauS.
6285 
6286  fracdiv = twothird * (u_x + v_y + w_z)
6287 
6288  tauxxs = two * u_x - fracdiv
6289  tauyys = two * v_y - fracdiv
6290  tauzzs = two * w_z - fracdiv
6291 
6292  tauxys = u_y + v_x
6293  tauxzs = u_z + w_x
6294  tauyzs = v_z + w_y
6295 
6296  q_x = heatcoef * q_x
6297  q_y = heatcoef * q_y
6298  q_z = heatcoef * q_z
6299 
6300  ! Add QCR corrections if necessary
6301  if (useqcr) then
6302 
6303  ! In the QCR formulation, we add an extra term to the turbulent stress tensor:
6304  !
6305  ! tau_ij,QCR = tau_ij - e_ij
6306  !
6307  ! where, according to TMR website (http://turbmodels.larc.nasa.gov/spalart.html):
6308  !
6309  ! e_ij = Ccr1*(O_ik*tau_jk + O_jk*tau_ik)
6310  !
6311  ! We are computing O_ik as follows:
6312  !
6313  ! O_ik = 2*W_ik/den
6314  !
6315  ! Remember that the tau_ij in e_ij should use only the eddy viscosity!
6316 
6317  ! Compute denominator
6318  den = sqrt(u_x * u_x + u_y * u_y + u_z * u_z + &
6319  v_x * v_x + v_y * v_y + v_z * v_z + &
6320  w_x * w_x + w_y * w_y + w_z * w_z)
6321 
6322  ! Denominator should be limited to avoid division by zero in regions with
6323  ! no gradients
6324  den = max(den, xminn)
6325 
6326  ! Compute factor that will multiply all tensor components.
6327  ! Here we add the eddy viscosity that should multiply the stress tensor (tau)
6328  ! components as well.
6329  fact = mue * ccr1 / den
6330 
6331  ! Compute off-diagonal terms of vorticity tensor (we will ommit the 1/2)
6332  ! The diagonals of the vorticity tensor components are always zero
6333  wxy = u_y - v_x
6334  wxz = u_z - w_x
6335  wyz = v_z - w_y
6336  wyx = -wxy
6337  wzx = -wxz
6338  wzy = -wyz
6339 
6340  ! Compute the extra terms of the Boussinesq relation
6341  exx = fact * (wxy * tauxys + wxz * tauxzs) * two
6342  eyy = fact * (wyx * tauxys + wyz * tauyzs) * two
6343  ezz = fact * (wzx * tauxzs + wzy * tauyzs) * two
6344 
6345  exy = fact * (wxy * tauyys + wxz * tauyzs + &
6346  wyx * tauxxs + wyz * tauxzs)
6347  exz = fact * (wxy * tauyzs + wxz * tauzzs + &
6348  wzx * tauxxs + wzy * tauxys)
6349  eyz = fact * (wyx * tauxzs + wyz * tauzzs + &
6350  wzx * tauxys + wzy * tauyys)
6351 
6352  ! Apply the total viscosity to the stress tensor and add extra terms
6353  tauxx = mut * tauxxs - exx
6354  tauyy = mut * tauyys - eyy
6355  tauzz = mut * tauzzs - ezz
6356  tauxy = mut * tauxys - exy
6357  tauxz = mut * tauxzs - exz
6358  tauyz = mut * tauyzs - eyz
6359 
6360  else
6361 
6362  ! Just apply the total viscosity to the stress tensor
6363  tauxx = mut * tauxxs
6364  tauyy = mut * tauyys
6365  tauzz = mut * tauzzs
6366  tauxy = mut * tauxys
6367  tauxz = mut * tauxzs
6368  tauyz = mut * tauyzs
6369 
6370  end if
6371 
6372  ! Compute the average velocities for the face. Remember that
6373  ! the velocities are stored and not the momentum.
6374 
6375  ubar = half * (w(i, j, k, ivx) + w(i + 1, j, k, ivx))
6376  vbar = half * (w(i, j, k, ivy) + w(i + 1, j, k, ivy))
6377  wbar = half * (w(i, j, k, ivz) + w(i + 1, j, k, ivz))
6378 
6379  ! Compute the viscous fluxes for this i-face.
6380 
6381  fmx = tauxx * si(i, j, k, 1) + tauxy * si(i, j, k, 2) &
6382  + tauxz * si(i, j, k, 3)
6383  fmy = tauxy * si(i, j, k, 1) + tauyy * si(i, j, k, 2) &
6384  + tauyz * si(i, j, k, 3)
6385  fmz = tauxz * si(i, j, k, 1) + tauyz * si(i, j, k, 2) &
6386  + tauzz * si(i, j, k, 3)
6387  frhoe = (ubar * tauxx + vbar * tauxy + wbar * tauxz) * si(i, j, k, 1) &
6388  + (ubar * tauxy + vbar * tauyy + wbar * tauyz) * si(i, j, k, 2) &
6389  + (ubar * tauxz + vbar * tauyz + wbar * tauzz) * si(i, j, k, 3) &
6390  - q_x * si(i, j, k, 1) - q_y * si(i, j, k, 2) - q_z * si(i, j, k, 3)
6391 
6392  ! Update the residuals of cell i and i+1.
6393  fw(i + 1, j, k, imx) = fw(i + 1, j, k, imx) + fmx
6394  fw(i + 1, j, k, imy) = fw(i + 1, j, k, imy) + fmy
6395  fw(i + 1, j, k, imz) = fw(i + 1, j, k, imz) + fmz
6396  fw(i + 1, j, k, irhoe) = fw(i + 1, j, k, irhoe) + frhoe
6397 
6398  fw(i, j, k, imx) = fw(i, j, k, imx) - fmx
6399  fw(i, j, k, imy) = fw(i, j, k, imy) - fmy
6400  fw(i, j, k, imz) = fw(i, j, k, imz) - fmz
6401  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - frhoe
6402 
6403  ! Temporarily store the shear stress and heat flux, even
6404  ! if we won't need it. This can still vectorize
6405 
6406  if (i == 1) then
6407  tmpstore(1, j, k, 1) = tauxx
6408  tmpstore(2, j, k, 1) = tauyy
6409  tmpstore(3, j, k, 1) = tauzz
6410  tmpstore(4, j, k, 1) = tauxy
6411  tmpstore(5, j, k, 1) = tauxz
6412  tmpstore(6, j, k, 1) = tauyz
6413 
6414  tmpstore(7, j, k, 1) = q_x
6415  tmpstore(8, j, k, 1) = q_y
6416  tmpstore(9, j, k, 1) = q_z
6417  end if
6418 
6419  if (i == il) then
6420  tmpstore(1, j, k, 2) = tauxx
6421  tmpstore(2, j, k, 2) = tauyy
6422  tmpstore(3, j, k, 2) = tauzz
6423  tmpstore(4, j, k, 2) = tauxy
6424  tmpstore(5, j, k, 2) = tauxz
6425  tmpstore(6, j, k, 2) = tauyz
6426 
6427  tmpstore(7, j, k, 2) = q_x
6428  tmpstore(8, j, k, 2) = q_y
6429  tmpstore(9, j, k, 2) = q_z
6430  end if
6431  end do
6432  end do
6433  end do
6434  ! Save into the subface if necessary
6435  if (storewall) then
6436  origimin: if (ii - 1 == 1) then
6437  do k = 2, kl
6438  do j = 2, jl
6439  jo = j + jj - 2
6440  ko = k + kk - 2
6441 
6442  if (visciminpointer(jo, ko) > 0) then
6443  viscsubface(visciminpointer(jo, ko))%tau(jo, ko, :) = tmpstore(1:6, j, k, 1)
6444  viscsubface(visciminpointer(jo, ko))%q(jo, ko, :) = tmpstore(7:9, j, k, 1)
6445  end if
6446  end do
6447  end do
6448  end if origimin
6449 
6450  origimax: if (ii + nx - 1 == bil) then
6451  do k = 2, kl
6452  do j = 2, jl
6453  jo = j + jj - 2
6454  ko = k + kk - 2
6455  if (viscimaxpointer(jo, ko) > 0) then
6456  viscsubface(viscimaxpointer(jo, ko))%tau(jo, ko, :) = tmpstore(1:6, j, k, 2)
6457  viscsubface(viscimaxpointer(jo, ko))%q(jo, ko, :) = tmpstore(7:9, j, k, 2)
6458  end if
6459  end do
6460  end do
6461  end if origimax
6462  end if
6463  end subroutine viscousflux
6464 
6466 
6467  use constants
6468  use flowvarrefstate
6469  use inputphysics
6470  use iteration
6471  implicit none
6472  !
6473  ! Local parameter.
6474  !
6475  real(kind=realtype), parameter :: twothird = two * third
6476  !
6477  ! Local variables.
6478  !
6479  integer(kind=intType) :: i, j, k
6480  integer(kind=intType) :: ii, jj, kk
6481 
6482  real(kind=realtype) :: rfilv, por, mul, mue, mut, heatcoef
6483  real(kind=realtype) :: gm1, factlamheat, factturbheat
6484  real(kind=realtype) :: u_x, u_y, u_z, v_x, v_y, v_z, w_x, w_y, w_z
6485  real(kind=realtype) :: q_x, q_y, q_z, ubar, vbar, wbar
6486  real(kind=realtype) :: corr, ssx, ssy, ssz, ss, fracdiv
6487  real(kind=realtype) :: tauxx, tauyy, tauzz
6488  real(kind=realtype) :: tauxy, tauxz, tauyz
6489  real(kind=realtype) :: fmx, fmy, fmz, frhoe
6490  real(kind=realtype) :: dd
6491  logical :: correctForK
6492 
6493  mue = zero
6494  rfilv = rfil
6495 
6496  ! Viscous fluxes in the I-direction
6497 
6498  do k = 2, kl
6499  do j = 2, jl
6500  do i = 1, il
6501 
6502  ! Compute the vector from the center of cell i to cell i+1
6503  ssx = eighth * (x(i + 1, j - 1, k - 1, 1) - x(i - 1, j - 1, k - 1, 1) &
6504  + x(i + 1, j - 1, k, 1) - x(i - 1, j - 1, k, 1) &
6505  + x(i + 1, j, k - 1, 1) - x(i - 1, j, k - 1, 1) &
6506  + x(i + 1, j, k, 1) - x(i - 1, j, k, 1))
6507  ssy = eighth * (x(i + 1, j - 1, k - 1, 2) - x(i - 1, j - 1, k - 1, 2) &
6508  + x(i + 1, j - 1, k, 2) - x(i - 1, j - 1, k, 2) &
6509  + x(i + 1, j, k - 1, 2) - x(i - 1, j, k - 1, 2) &
6510  + x(i + 1, j, k, 2) - x(i - 1, j, k, 2))
6511  ssz = eighth * (x(i + 1, j - 1, k - 1, 3) - x(i - 1, j - 1, k - 1, 3) &
6512  + x(i + 1, j - 1, k, 3) - x(i - 1, j - 1, k, 3) &
6513  + x(i + 1, j, k - 1, 3) - x(i - 1, j, k - 1, 3) &
6514  + x(i + 1, j, k, 3) - x(i - 1, j, k, 3))
6515 
6516  ! And determine one/ length of vector squared
6517  ss = one / (ssx * ssx + ssy * ssy + ssz * ssz)
6518  ssx = ss * ssx
6519  ssy = ss * ssy
6520  ssz = ss * ssz
6521 
6522  ! Now compute each gradient
6523  dd = w(i + 1, j, k, ivx) - w(i, j, k, ivx)
6524  u_x = dd * ssx
6525  u_y = dd * ssy
6526  u_z = dd * ssz
6527 
6528  dd = w(i + 1, j, k, ivy) - w(i, j, k, ivy)
6529  v_x = dd * ssx
6530  v_y = dd * ssy
6531  v_z = dd * ssz
6532 
6533  dd = w(i + 1, j, k, ivz) - w(i, j, k, ivz)
6534  w_x = dd * ssx
6535  w_y = dd * ssy
6536  w_z = dd * ssz
6537 
6538  dd = aa(i + 1, j, k) - aa(i, j, k)
6539  q_x = -dd * ssx
6540  q_y = -dd * ssy
6541  q_z = -dd * ssz
6542 
6543  por = half * rfilv
6544  if (pori(i, j, k) == noflux) por = zero
6545 
6546  ! Compute the laminar and (if present) the eddy viscosities
6547  ! multiplied by the porosity. Compute the factor in front of
6548  ! the gradients of the speed of sound squared for the heat
6549  ! flux.
6550 
6551  mul = por * (rlv(i, j, k) + rlv(i + 1, j, k))
6552  mue = por * (rev(i, j, k) + rev(i + 1, j, k))
6553  mut = mul + mue
6554 
6555  gm1 = half * (gamma(i, j, k) + gamma(i + 1, j, k)) - one
6556  factlamheat = one / (prandtl * gm1)
6557  factturbheat = one / (prandtlturb * gm1)
6558 
6559  heatcoef = mul * factlamheat + mue * factturbheat
6560 
6561  ! Compute the stress tensor and the heat flux vector.
6562 
6563  fracdiv = twothird * (u_x + v_y + w_z)
6564 
6565  tauxx = mut * (two * u_x - fracdiv)
6566  tauyy = mut * (two * v_y - fracdiv)
6567  tauzz = mut * (two * w_z - fracdiv)
6568 
6569  tauxy = mut * (u_y + v_x)
6570  tauxz = mut * (u_z + w_x)
6571  tauyz = mut * (v_z + w_y)
6572 
6573  q_x = heatcoef * q_x
6574  q_y = heatcoef * q_y
6575  q_z = heatcoef * q_z
6576 
6577  ! Compute the average velocities for the face. Remember that
6578  ! the velocities are stored and not the momentum.
6579 
6580  ubar = half * (w(i, j, k, ivx) + w(i + 1, j, k, ivx))
6581  vbar = half * (w(i, j, k, ivy) + w(i + 1, j, k, ivy))
6582  wbar = half * (w(i, j, k, ivz) + w(i + 1, j, k, ivz))
6583 
6584  ! Compute the viscous fluxes for this i-face.
6585 
6586  fmx = tauxx * si(i, j, k, 1) + tauxy * si(i, j, k, 2) + tauxz * si(i, j, k, 3)
6587  fmy = tauxy * si(i, j, k, 1) + tauyy * si(i, j, k, 2) + tauyz * si(i, j, k, 3)
6588  fmz = tauxz * si(i, j, k, 1) + tauyz * si(i, j, k, 2) + tauzz * si(i, j, k, 3)
6589  frhoe = (ubar * tauxx + vbar * tauxy + wbar * tauxz) * si(i, j, k, 1) &
6590  + (ubar * tauxy + vbar * tauyy + wbar * tauyz) * si(i, j, k, 2) &
6591  + (ubar * tauxz + vbar * tauyz + wbar * tauzz) * si(i, j, k, 3) &
6592  - q_x * si(i, j, k, 1) - q_y * si(i, j, k, 2) - q_z * si(i, j, k, 3)
6593 
6594  ! Update the residuals of cell i and i+1.
6595  fw(i + 1, j, k, imx) = fw(i + 1, j, k, imx) + fmx
6596  fw(i + 1, j, k, imy) = fw(i + 1, j, k, imy) + fmy
6597  fw(i + 1, j, k, imz) = fw(i + 1, j, k, imz) + fmz
6598  fw(i + 1, j, k, irhoe) = fw(i + 1, j, k, irhoe) + frhoe
6599 
6600  fw(i, j, k, imx) = fw(i, j, k, imx) - fmx
6601  fw(i, j, k, imy) = fw(i, j, k, imy) - fmy
6602  fw(i, j, k, imz) = fw(i, j, k, imz) - fmz
6603  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - frhoe
6604 
6605  end do
6606  end do
6607  end do
6608 
6609  ! Viscous fluxes in the J-direction
6610 
6611  do k = 2, kl
6612  do j = 1, jl
6613  do i = 2, il
6614 
6615  ! Compute the vector from the center of cell j to cell j+1
6616  ssx = eighth * (x(i - 1, j + 1, k - 1, 1) - x(i - 1, j - 1, k - 1, 1) &
6617  + x(i - 1, j + 1, k, 1) - x(i - 1, j - 1, k, 1) &
6618  + x(i, j + 1, k - 1, 1) - x(i, j - 1, k - 1, 1) &
6619  + x(i, j + 1, k, 1) - x(i, j - 1, k, 1))
6620  ssy = eighth * (x(i - 1, j + 1, k - 1, 2) - x(i - 1, j - 1, k - 1, 2) &
6621  + x(i - 1, j + 1, k, 2) - x(i - 1, j - 1, k, 2) &
6622  + x(i, j + 1, k - 1, 2) - x(i, j - 1, k - 1, 2) &
6623  + x(i, j + 1, k, 2) - x(i, j - 1, k, 2))
6624  ssz = eighth * (x(i - 1, j + 1, k - 1, 3) - x(i - 1, j - 1, k - 1, 3) &
6625  + x(i - 1, j + 1, k, 3) - x(i - 1, j - 1, k, 3) &
6626  + x(i, j + 1, k - 1, 3) - x(i, j - 1, k - 1, 3) &
6627  + x(i, j + 1, k, 3) - x(i, j - 1, k, 3))
6628 
6629  ! And determine one/ length of vector squared
6630  ss = one / (ssx * ssx + ssy * ssy + ssz * ssz)
6631  ssx = ss * ssx
6632  ssy = ss * ssy
6633  ssz = ss * ssz
6634 
6635  ! Now compute each gradient
6636  dd = w(i, j + 1, k, ivx) - w(i, j, k, ivx)
6637  u_x = dd * ssx
6638  u_y = dd * ssy
6639  u_z = dd * ssz
6640 
6641  dd = w(i, j + 1, k, ivy) - w(i, j, k, ivy)
6642  v_x = dd * ssx
6643  v_y = dd * ssy
6644  v_z = dd * ssz
6645 
6646  dd = w(i, j + 1, k, ivz) - w(i, j, k, ivz)
6647  w_x = dd * ssx
6648  w_y = dd * ssy
6649  w_z = dd * ssz
6650 
6651  dd = aa(i, j + 1, k) - aa(i, j, k)
6652  q_x = -dd * ssx
6653  q_y = -dd * ssy
6654  q_z = -dd * ssz
6655 
6656  por = half * rfilv
6657  if (porj(i, j, k) == noflux) por = zero
6658 
6659  ! Compute the laminar and (if present) the eddy viscosities
6660  ! multiplied by the porosity. Compute the factor in front of
6661  ! the gradients of the speed of sound squared for the heat
6662  ! flux.
6663 
6664  mul = por * (rlv(i, j, k) + rlv(i, j + 1, k))
6665  mue = por * (rev(i, j, k) + rev(i, j + 1, k))
6666  mut = mul + mue
6667 
6668  gm1 = half * (gamma(i, j, k) + gamma(i, j + 1, k)) - one
6669  factlamheat = one / (prandtl * gm1)
6670  factturbheat = one / (prandtlturb * gm1)
6671 
6672  heatcoef = mul * factlamheat + mue * factturbheat
6673 
6674  ! Compute the stress tensor and the heat flux vector.
6675 
6676  fracdiv = twothird * (u_x + v_y + w_z)
6677 
6678  tauxx = mut * (two * u_x - fracdiv)
6679  tauyy = mut * (two * v_y - fracdiv)
6680  tauzz = mut * (two * w_z - fracdiv)
6681 
6682  tauxy = mut * (u_y + v_x)
6683  tauxz = mut * (u_z + w_x)
6684  tauyz = mut * (v_z + w_y)
6685 
6686  q_x = heatcoef * q_x
6687  q_y = heatcoef * q_y
6688  q_z = heatcoef * q_z
6689 
6690  ! Compute the average velocities for the face. Remember that
6691  ! the velocities are stored and not the momentum.
6692 
6693  ubar = half * (w(i, j, k, ivx) + w(i, j + 1, k, ivx))
6694  vbar = half * (w(i, j, k, ivy) + w(i, j + 1, k, ivy))
6695  wbar = half * (w(i, j, k, ivz) + w(i, j + 1, k, ivz))
6696 
6697  ! Compute the viscous fluxes for this j-face.
6698 
6699  fmx = tauxx * sj(i, j, k, 1) + tauxy * sj(i, j, k, 2) + tauxz * sj(i, j, k, 3)
6700  fmy = tauxy * sj(i, j, k, 1) + tauyy * sj(i, j, k, 2) + tauyz * sj(i, j, k, 3)
6701  fmz = tauxz * sj(i, j, k, 1) + tauyz * sj(i, j, k, 2) + tauzz * sj(i, j, k, 3)
6702  frhoe = (ubar * tauxx + vbar * tauxy + wbar * tauxz) * sj(i, j, k, 1) &
6703  + (ubar * tauxy + vbar * tauyy + wbar * tauyz) * sj(i, j, k, 2) &
6704  + (ubar * tauxz + vbar * tauyz + wbar * tauzz) * sj(i, j, k, 3) &
6705  - q_x * sj(i, j, k, 1) - q_y * sj(i, j, k, 2) - q_z * sj(i, j, k, 3)
6706 
6707  ! Update the residuals of cell j and j+1.
6708 
6709  fw(i, j, k, imx) = fw(i, j, k, imx) - fmx
6710  fw(i, j, k, imy) = fw(i, j, k, imy) - fmy
6711  fw(i, j, k, imz) = fw(i, j, k, imz) - fmz
6712  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - frhoe
6713 
6714  fw(i, j + 1, k, imx) = fw(i, j + 1, k, imx) + fmx
6715  fw(i, j + 1, k, imy) = fw(i, j + 1, k, imy) + fmy
6716  fw(i, j + 1, k, imz) = fw(i, j + 1, k, imz) + fmz
6717  fw(i, j + 1, k, irhoe) = fw(i, j + 1, k, irhoe) + frhoe
6718 
6719  end do
6720  end do
6721  end do
6722 
6723  ! Viscous fluxes in the K-direction
6724 
6725  do k = 1, kl
6726  do j = 2, jl
6727  do i = 2, il
6728 
6729  ! Compute the vector from the center of cell k to cell k+1
6730  ssx = eighth * (x(i - 1, j - 1, k + 1, 1) - x(i - 1, j - 1, k - 1, 1) &
6731  + x(i - 1, j, k + 1, 1) - x(i - 1, j, k - 1, 1) &
6732  + x(i, j - 1, k + 1, 1) - x(i, j - 1, k - 1, 1) &
6733  + x(i, j, k + 1, 1) - x(i, j, k - 1, 1))
6734  ssy = eighth * (x(i - 1, j - 1, k + 1, 2) - x(i - 1, j - 1, k - 1, 2) &
6735  + x(i - 1, j, k + 1, 2) - x(i - 1, j, k - 1, 2) &
6736  + x(i, j - 1, k + 1, 2) - x(i, j - 1, k - 1, 2) &
6737  + x(i, j, k + 1, 2) - x(i, j, k - 1, 2))
6738  ssz = eighth * (x(i - 1, j - 1, k + 1, 3) - x(i - 1, j - 1, k - 1, 3) &
6739  + x(i - 1, j, k + 1, 3) - x(i - 1, j, k - 1, 3) &
6740  + x(i, j - 1, k + 1, 3) - x(i, j - 1, k - 1, 3) &
6741  + x(i, j, k + 1, 3) - x(i, j, k - 1, 3))
6742  ! And determine one/ length of vector squared
6743  ss = one / (ssx * ssx + ssy * ssy + ssz * ssz)
6744  ssx = ss * ssx
6745  ssy = ss * ssy
6746  ssz = ss * ssz
6747 
6748  ! Now compute each gradient
6749  dd = w(i, j, k + 1, ivx) - w(i, j, k, ivx)
6750  u_x = dd * ssx
6751  u_y = dd * ssy
6752  u_z = dd * ssz
6753 
6754  dd = w(i, j, k + 1, ivy) - w(i, j, k, ivy)
6755  v_x = dd * ssx
6756  v_y = dd * ssy
6757  v_z = dd * ssz
6758 
6759  dd = w(i, j, k + 1, ivz) - w(i, j, k, ivz)
6760  w_x = dd * ssx
6761  w_y = dd * ssy
6762  w_z = dd * ssz
6763 
6764  dd = aa(i, j, k + 1) - aa(i, j, k)
6765  q_x = -dd * ssx
6766  q_y = -dd * ssy
6767  q_z = -dd * ssz
6768 
6769  por = half * rfilv
6770  if (pork(i, j, k) == noflux) por = zero
6771 
6772  ! Compute the laminar and (if present) the eddy viscosities
6773  ! multiplied by the porosity. Compute the factor in front of
6774  ! the gradients of the speed of sound squared for the heat
6775  ! flux.
6776 
6777  mul = por * (rlv(i, j, k) + rlv(i, j, k + 1))
6778  mue = por * (rev(i, j, k) + rev(i, j, k + 1))
6779  mut = mul + mue
6780 
6781  gm1 = half * (gamma(i, j, k) + gamma(i, j, k + 1)) - one
6782  factlamheat = one / (prandtl * gm1)
6783  factturbheat = one / (prandtlturb * gm1)
6784 
6785  heatcoef = mul * factlamheat + mue * factturbheat
6786 
6787  ! Compute the stress tensor and the heat flux vector.
6788 
6789  fracdiv = twothird * (u_x + v_y + w_z)
6790 
6791  tauxx = mut * (two * u_x - fracdiv)
6792  tauyy = mut * (two * v_y - fracdiv)
6793  tauzz = mut * (two * w_z - fracdiv)
6794 
6795  tauxy = mut * (u_y + v_x)
6796  tauxz = mut * (u_z + w_x)
6797  tauyz = mut * (v_z + w_y)
6798 
6799  q_x = heatcoef * q_x
6800  q_y = heatcoef * q_y
6801  q_z = heatcoef * q_z
6802 
6803  ! Compute the average velocities for the face. Remember that
6804  ! the velocities are stored and not the momentum.
6805 
6806  ubar = half * (w(i, j, k, ivx) + w(i, j, k + 1, ivx))
6807  vbar = half * (w(i, j, k, ivy) + w(i, j, k + 1, ivy))
6808  wbar = half * (w(i, j, k, ivz) + w(i, j, k + 1, ivz))
6809 
6810  ! Compute the viscous fluxes for this j-face.
6811 
6812  fmx = tauxx * sk(i, j, k, 1) + tauxy * sk(i, j, k, 2) + tauxz * sk(i, j, k, 3)
6813  fmy = tauxy * sk(i, j, k, 1) + tauyy * sk(i, j, k, 2) + tauyz * sk(i, j, k, 3)
6814  fmz = tauxz * sk(i, j, k, 1) + tauyz * sk(i, j, k, 2) + tauzz * sk(i, j, k, 3)
6815  frhoe = (ubar * tauxx + vbar * tauxy + wbar * tauxz) * sk(i, j, k, 1) &
6816  + (ubar * tauxy + vbar * tauyy + wbar * tauyz) * sk(i, j, k, 2) &
6817  + (ubar * tauxz + vbar * tauyz + wbar * tauzz) * sk(i, j, k, 3) &
6818  - q_x * sk(i, j, k, 1) - q_y * sk(i, j, k, 2) - q_z * sk(i, j, k, 3)
6819 
6820  ! Update the residuals of cell j and j+1.
6821 
6822  fw(i, j, k, imx) = fw(i, j, k, imx) - fmx
6823  fw(i, j, k, imy) = fw(i, j, k, imy) - fmy
6824  fw(i, j, k, imz) = fw(i, j, k, imz) - fmz
6825  fw(i, j, k, irhoe) = fw(i, j, k, irhoe) - frhoe
6826 
6827  fw(i, j, k + 1, imx) = fw(i, j, k + 1, imx) + fmx
6828  fw(i, j, k + 1, imy) = fw(i, j, k + 1, imy) + fmy
6829  fw(i, j, k + 1, imz) = fw(i, j, k + 1, imz) + fmz
6830  fw(i, j, k + 1, irhoe) = fw(i, j, k + 1, irhoe) + frhoe
6831 
6832  end do
6833  end do
6834  end do
6835  end subroutine viscousfluxapprox
6836 
6837  subroutine sumdwandfw
6838 
6839  ! ---------------------------------------------
6840  ! Sum dw and fw/res scale
6841  ! ---------------------------------------------
6842  use constants
6843  use flowvarrefstate, only: nw, nwf, nt1, nt2
6844  use inputiteration, only: turbresscale
6845  implicit none
6846 
6847  ! Variables for final summing
6848  integer(kind=intType) :: nTurb, i, j, k, l
6849  real(kind=realtype) :: ovol, rblank
6850 
6851  nturb = nt2 - nt1 + 1
6852  do l = 1, nwf
6853  do k = 2, kl
6854  do j = 2, jl
6855  do i = 2, il
6856  rblank = max(real(iblank(i, j, k), realtype), zero)
6857  dw(i, j, k, l) = (dw(i, j, k, l) + fw(i, j, k, l)) * rblank
6858  end do
6859  end do
6860  end do
6861  end do
6862  end subroutine sumdwandfw
6863 
6864  subroutine resscale
6865 
6866  use constants
6867  use flowvarrefstate, only: nwf, nt1, nt2
6868  use inputiteration, only: turbresscale
6869  implicit none
6870 
6871  ! Local Variables
6872  integer(kind=intType) :: i, j, k, ii, nTurb
6873  real(kind=realtype) :: ovol
6874 
6875  ! Divide through by the reference volume
6876  nturb = nt2 - nt1 + 1
6877  do k = 2, kl
6878  do j = 2, jl
6879  do i = 2, il
6880 
6881  ovol = one / volref(i, j, k)
6882  dw(i, j, k, 1:nwf) = dw(i, j, k, 1:nwf) * ovol
6883  dw(i, j, k, nt1:nt2) = dw(i, j, k, nt1:nt2) * ovol * turbresscale(1:nturb)
6884  end do
6885  end do
6886  end do
6887 
6888  end subroutine resscale
6889 
6890 end module blockette
subroutine riemannflux(left, right, flux)
Definition: fluxes_d.f90:5366
subroutine leftrightstate(du1, du2, du3, rotmatrix, left, right)
Definition: fluxes_d.f90:4708
subroutine getforces(forces, npts, sps)
Definition: getForces.F90:3
integer(kind=inttype) nactuatorregions
subroutine volume_block
Definition: adjointExtra.F90:6
subroutine xhalo_block
subroutine sumdwandfw
subroutine boundarynormals
subroutine metric_block
Definition: BCData.F90:1
subroutine setbcdatafinegrid(initializationPart)
Definition: BCData.F90:2623
subroutine setbcdata(bcDataNamesIn, bcDataIn, famLists, sps, nVar, nFamMax)
Definition: BCData.F90:1405
subroutine applyallbc_block(secondHalo)
Definition: BCRoutines.F90:58
Definition: block.F90:1
integer(kind=inttype) ndom
Definition: block.F90:761
integer(kind=inttype), parameter bbkb
Definition: blockette.F90:12
subroutine viscousflux(storeWallTensor)
Definition: blockette.F90:5516
integer(kind=inttype) jb
Definition: blockette.F90:15
real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke) vol
Definition: blockette.F90:30
integer(kind=inttype), dimension(2:bbil, 2:bbjl, 2:bbkl) iblank
Definition: blockette.F90:36
subroutine sumdwandfw
Definition: blockette.F90:6838
integer(kind=inttype), parameter bbkl
Definition: blockette.F90:10
integer(kind=inttype), parameter bbjb
Definition: blockette.F90:12
real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke, 1:6) dw
Definition: blockette.F90:45
subroutine saadvection
Definition: blockette.F90:1391
real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) qz
Definition: blockette.F90:61
subroutine metrics
Definition: blockette.F90:855
subroutine timestep(updateDtl)
Definition: blockette.F90:1898
subroutine invisciddissfluxscalar
Definition: blockette.F90:3028
real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) wy
Definition: blockette.F90:60
subroutine blocketterescore(dissApprox, viscApprox, updateIntermed, flowRes, turbRes, storeWall)
Definition: blockette.F90:300
subroutine resscale
Definition: blockette.F90:6865
integer(kind=inttype), parameter bbie
Definition: blockette.F90:11
integer(kind=inttype), parameter bs
Definition: blockette.F90:9
integer(kind=inttype) jj
Definition: blockette.F90:21
real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke) rev
Definition: blockette.F90:30
subroutine sasource
Definition: blockette.F90:977
real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) vy
Definition: blockette.F90:59
real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) wz
Definition: blockette.F90:60
subroutine initres(varStart, varEnd)
Definition: blockette.F90:963
real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) vz
Definition: blockette.F90:59
subroutine invisciddissfluxmatrixapprox
Definition: blockette.F90:4618
integer(kind=inttype) ii
Definition: blockette.F90:21
real(kind=realtype), dimension(0:bbib, 0:bbjb, 0:bbkb) gamma
Definition: blockette.F90:25
real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) qx
Definition: blockette.F90:61
subroutine invisciddissfluxscalarapprox
Definition: blockette.F90:4366
integer(kind=inttype), parameter bbje
Definition: blockette.F90:11
real(kind=realtype), dimension(0:bbie, 0:bbje, 0:bbke, 3) x
Definition: blockette.F90:29
real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) uz
Definition: blockette.F90:58
integer(kind=inttype) je
Definition: blockette.F90:15
integer(kind=inttype), parameter bbib
Definition: blockette.F90:12
subroutine viscousfluxapprox
Definition: blockette.F90:6466
integer(kind=inttype) doublehalostart
Definition: blockette.F90:18
real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke, 1:5) fw
Definition: blockette.F90:44
integer(kind=inttype) kk
Definition: blockette.F90:21
subroutine inviscidcentralflux
Definition: blockette.F90:2149
real(kind=realtype), dimension(1:bbie, 0:bbje, 1:bbke) sfacej
Definition: blockette.F90:54
real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke) aa
Definition: blockette.F90:30
real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke) radi
Definition: blockette.F90:31
integer(kind=inttype) kl
Definition: blockette.F90:15
subroutine inviscidupwindflux(fineGrid)
Definition: blockette.F90:3340
real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke) radj
Definition: blockette.F90:31
real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke) rlv
Definition: blockette.F90:30
real(kind=realtype), dimension(0:bbie, 1:bbje, 1:bbke, 3) si
Definition: blockette.F90:48
integer(kind=inttype) jl
Definition: blockette.F90:15
integer(kind=inttype), parameter bbke
Definition: blockette.F90:11
real(kind=realtype), dimension(1:bbie, 0:bbje, 1:bbke, 3) sj
Definition: blockette.F90:49
subroutine invisciddissfluxmatrix
Definition: blockette.F90:2456
real(kind=realtype), dimension(2:bbil, 2:bbjl, 2:bbkl) volref
Definition: blockette.F90:35
integer(kind=inttype) nodestart
Definition: blockette.F90:18
subroutine computespeedofsoundsquared
Definition: blockette.F90:5167
integer(kind=inttype) nz
Definition: blockette.F90:15
integer(kind=inttype) ke
Definition: blockette.F90:15
real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke) dtl
Definition: blockette.F90:31
integer(kind=inttype), parameter bbil
Definition: blockette.F90:10
subroutine blockrescore(dissApprox, viscApprox, updateIntermed, flowRes, turbRes, storeWall, nn, sps)
Definition: blockette.F90:756
real(kind=realtype), dimension(0:bbib, 0:bbjb, 0:bbkb) p
Definition: blockette.F90:25
real(kind=realtype), dimension(0:bbib, 0:bbjb, 0:bbkb, 1:6) w
Definition: blockette.F90:24
integer(kind=inttype) ie
Definition: blockette.F90:15
real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke) radk
Definition: blockette.F90:31
integer(kind=inttype) ib
Definition: blockette.F90:15
real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) wx
Definition: blockette.F90:60
real(kind=realtype), dimension(2:bbil, 2:bbjl, 2:bbkl) d2wall
Definition: blockette.F90:35
real(kind=realtype), dimension(1:bbie, 1:bbje, 1:bbke, 3) dss
Definition: blockette.F90:32
real(kind=realtype), dimension(1:bbie, 1:bbje, 0:bbke) sfacek
Definition: blockette.F90:55
subroutine saviscous
Definition: blockette.F90:1170
real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) uy
Definition: blockette.F90:58
subroutine saresscale
Definition: blockette.F90:1871
subroutine allnodalgradients
Definition: blockette.F90:5204
integer(kind=inttype) singlehalostart
Definition: blockette.F90:18
real(kind=realtype), dimension(0:bbie, 1:bbje, 1:bbke) sfacei
Definition: blockette.F90:53
integer(kind=portype), dimension(2:bbil, 2:bbjl, 1:bbkl) pork
Definition: blockette.F90:41
real(kind=realtype), dimension(0:bbib, 0:bbjb, 0:bbkb) ss
Definition: blockette.F90:26
integer(kind=portype), dimension(1:bbil, 2:bbjl, 2:bbkl) pori
Definition: blockette.F90:39
subroutine blocketteres(useDissApprox, useViscApprox, useUpdateIntermed, useFlowRes, useTurbRes, useSpatial, useStoreWall, famLists, funcValues, forces, bcDataNames, bcDataValues, bcDataFamLists)
Definition: blockette.F90:72
integer(kind=inttype) nx
Definition: blockette.F90:15
real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) ux
Definition: blockette.F90:58
integer(kind=inttype) ny
Definition: blockette.F90:15
real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) vx
Definition: blockette.F90:59
integer(kind=inttype) il
Definition: blockette.F90:15
integer(kind=portype), dimension(2:bbil, 1:bbjl, 2:bbkl) porj
Definition: blockette.F90:40
real(kind=realtype), dimension(1:bbie, 1:bbje, 0:bbke, 3) sk
Definition: blockette.F90:50
integer(kind=inttype) kb
Definition: blockette.F90:15
integer(kind=inttype), parameter bbjl
Definition: blockette.F90:10
real(kind=realtype), dimension(1:bbil, 1:bbjl, 1:bbkl) qy
Definition: blockette.F90:61
real(kind=realtype), dimension(:, :, :), pointer sfacek
integer(kind=inttype), dimension(:, :), pointer viscjminpointer
real(kind=realtype), dimension(:, :, :), pointer gamma
real(kind=realtype), dimension(:, :, :), pointer qz
logical addgridvelocities
integer(kind=inttype) jl
real(kind=realtype), dimension(:, :, :), pointer radk
integer(kind=portype), dimension(:, :, :), pointer pork
integer(kind=inttype), dimension(:, :), pointer viscjmaxpointer
real(kind=realtype), dimension(:, :, :), pointer qy
real(kind=realtype), dimension(:, :, :), pointer aa
real(kind=realtype), dimension(:, :, :), pointer uz
logical blockismoving
logical righthanded
integer(kind=inttype) nx
real(kind=realtype), dimension(:, :, :), pointer p
real(kind=realtype), dimension(:, :, :), pointer radj
integer(kind=inttype) ny
integer(kind=inttype) ie
real(kind=realtype), dimension(:, :, :, :), pointer w
real(kind=realtype), dimension(:, :, :), pointer uy
real(kind=realtype), dimension(:, :, :), pointer sfacei
type(viscsubfacetype), dimension(:), pointer viscsubface
integer(kind=portype), dimension(:, :, :), pointer porj
real(kind=realtype), dimension(:, :, :), pointer d2wall
integer(kind=portype), dimension(:, :, :), pointer pori
integer(kind=inttype), dimension(:, :, :), pointer iblank
real(kind=realtype), dimension(:, :, :), pointer wx
integer(kind=inttype) nbkglobal
integer(kind=inttype), dimension(:, :), pointer viscimaxpointer
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 volref
real(kind=realtype), dimension(:, :, :, :), pointer sj
integer(kind=inttype), dimension(:, :), pointer visckminpointer
integer(kind=inttype) sectionid
real(kind=realtype), dimension(:, :, :), pointer qx
real(kind=realtype), dimension(:, :, :), pointer vz
real(kind=realtype), dimension(:, :, :, :, :), pointer rotmatrixj
real(kind=realtype), dimension(:, :, :), pointer rev
real(kind=realtype), dimension(:, :, :, :), pointer dw
real(kind=realtype), dimension(:, :, :, :), pointer sk
real(kind=realtype), dimension(:, :, :), pointer ux
real(kind=realtype), dimension(:, :, :), pointer shocksensor
real(kind=realtype), dimension(:, :, :), pointer wy
real(kind=realtype), dimension(:, :, :), pointer wz
real(kind=realtype), dimension(:, :, :), pointer vol
integer(kind=inttype) ib
real(kind=realtype), dimension(:, :, :), pointer dtl
real(kind=realtype), dimension(:, :, :), pointer sfacej
real(kind=realtype), dimension(:, :, :), pointer vy
real(kind=realtype), dimension(:, :, :, :), pointer fw
integer(kind=inttype) nz
real(kind=realtype), dimension(:, :, :), pointer vx
integer(kind=inttype) je
real(kind=realtype), dimension(:, :, :), pointer radi
integer(kind=inttype) ke
real(kind=realtype), dimension(:, :, :, :), pointer x
integer(kind=inttype), dimension(:, :), pointer visckmaxpointer
integer(kind=inttype), dimension(:, :), pointer visciminpointer
real(kind=realtype), dimension(:, :, :, :, :), pointer rotmatrixi
integer(kind=inttype) kl
integer(kind=inttype) il
real(kind=realtype), dimension(:, :, :, :, :), pointer rotmatrixk
type(cgnsblockinfotype), dimension(:), allocatable cgnsdoms
Definition: cgnsGrid.F90:495
integer(kind=inttype), parameter strain
Definition: constants.F90:137
integer(kind=inttype), parameter spalartallmaras
Definition: constants.F90:128
integer(kind=inttype), parameter roe
Definition: constants.F90:155
integer(kind=inttype), parameter vanleer
Definition: constants.F90:155
integer(kind=inttype), parameter firstorder
Definition: constants.F90:142
real(kind=realtype), parameter zero
Definition: constants.F90:71
real(kind=realtype), parameter three
Definition: constants.F90:74
real(kind=realtype), parameter third
Definition: constants.F90:81
real(kind=realtype), parameter pi
Definition: constants.F90:22
real(kind=realtype), parameter eps
Definition: constants.F90:23
integer(kind=inttype), parameter ausmdv
Definition: constants.F90:155
real(kind=realtype), parameter eighth
Definition: constants.F90:84
integer(kind=inttype), parameter turkel
Definition: constants.F90:165
integer, parameter itu1
Definition: constants.F90:40
integer, parameter irho
Definition: constants.F90:34
integer, parameter imx
Definition: constants.F90:65
integer(kind=inttype), parameter choimerkle
Definition: constants.F90:165
integer(kind=inttype), parameter vanalbeda
Definition: constants.F90:160
integer(kind=inttype), parameter upwind
Definition: constants.F90:149
integer(kind=portype), parameter boundflux
Definition: constants.F90:29
integer(kind=portype), parameter noflux
Definition: constants.F90:28
integer(kind=inttype), parameter eulerequations
Definition: constants.F90:110
integer(kind=inttype), parameter timespectral
Definition: constants.F90:115
integer, parameter ivx
Definition: constants.F90:35
integer(kind=portype), parameter normalflux
Definition: constants.F90:30
integer, parameter irhoe
Definition: constants.F90:38
real(kind=realtype), parameter five
Definition: constants.F90:76
integer(kind=inttype), parameter noprecond
Definition: constants.F90:165
real(kind=realtype), parameter one
Definition: constants.F90:72
real(kind=realtype), parameter half
Definition: constants.F90:80
integer(kind=inttype), parameter dissmatrix
Definition: constants.F90:149
integer(kind=inttype), parameter steady
Definition: constants.F90:115
integer, parameter ivz
Definition: constants.F90:37
real(kind=realtype), parameter two
Definition: constants.F90:73
integer(kind=inttype), parameter minmod
Definition: constants.F90:160
real(kind=realtype), parameter fourth
Definition: constants.F90:82
integer, parameter imz
Definition: constants.F90:67
integer(kind=inttype), parameter nolimiter
Definition: constants.F90:160
integer(kind=inttype), parameter updatefast
Definition: constants.F90:240
integer, parameter imy
Definition: constants.F90:66
integer(kind=inttype), parameter nsequations
Definition: constants.F90:110
integer(kind=inttype), parameter secondorder
Definition: constants.F90:142
integer, parameter ivy
Definition: constants.F90:36
integer(kind=inttype), parameter dissscalar
Definition: constants.F90:149
integer(kind=inttype), parameter ransequations
Definition: constants.F90:110
real(kind=realtype), parameter sixth
Definition: constants.F90:83
subroutine computepressuresimple(includeHalos)
Definition: flowUtils.F90:868
subroutine computelamviscosity(includeHalos)
Definition: flowUtils.F90:1202
subroutine adjustinflowangle()
Definition: flowUtils.F90:1326
subroutine etot(rho, u, v, w, p, k, etotal, correctForK)
Definition: flowUtils.F90:675
real(kind=realtype) gammainf
integer(kind=inttype) nt1
real(kind=realtype) pinfcorr
real(kind=realtype) rgas
integer(kind=inttype) nwf
real(kind=realtype) tref
integer(kind=inttype) nw
real(kind=realtype) rhoinf
real(kind=realtype) timeref
integer(kind=inttype) nt2
Definition: fluxes.F90:1
subroutine whalo2(level, start, end, commPressure, commGamma, commViscous)
subroutine exchangecoor(level)
subroutine referencestate
real(kind=realtype) vis2
Definition: inputParam.F90:78
real(kind=realtype) sigma
Definition: inputParam.F90:83
integer(kind=inttype) orderturb
Definition: inputParam.F90:73
real(kind=realtype) adis
Definition: inputParam.F90:78
real(kind=realtype) acousticscalefactor
Definition: inputParam.F90:79
integer(kind=inttype) riemanncoarse
Definition: inputParam.F90:74
logical useapproxwalldistance
Definition: inputParam.F90:94
logical lowspeedpreconditioner
Definition: inputParam.F90:96
real(kind=realtype) vis4
Definition: inputParam.F90:78
real(kind=realtype) kappacoef
Definition: inputParam.F90:80
integer(kind=inttype) riemann
Definition: inputParam.F90:74
integer(kind=inttype) limiter
Definition: inputParam.F90:73
integer(kind=inttype) precond
Definition: inputParam.F90:74
integer(kind=inttype) spacediscr
Definition: inputParam.F90:72
real(kind=realtype) disscontmidpoint
Definition: inputParam.F90:297
logical usedisscontinuation
Definition: inputParam.F90:296
real(kind=realtype), dimension(4) turbresscale
Definition: inputParam.F90:293
real(kind=realtype) disscontmagnitude
Definition: inputParam.F90:297
real(kind=realtype) disscontsharpness
Definition: inputParam.F90:297
integer(kind=inttype) oversetupdatemode
Definition: inputParam.F90:887
logical useft2sa
Definition: inputParam.F90:587
integer(kind=inttype) equations
Definition: inputParam.F90:583
integer(kind=inttype) equationmode
Definition: inputParam.F90:583
real(kind=realtype) prandtlturb
Definition: inputParam.F90:596
integer(kind=inttype) turbprod
Definition: inputParam.F90:584
integer(kind=inttype) turbmodel
Definition: inputParam.F90:584
logical useqcr
Definition: inputParam.F90:587
real(kind=realtype) prandtl
Definition: inputParam.F90:596
logical userotationsa
Definition: inputParam.F90:587
integer(kind=inttype) ntimeintervalsspectral
Definition: inputParam.F90:645
real(kind=realtype) totalr0
Definition: iteration.f90:126
integer(kind=inttype) currentlevel
Definition: iteration.f90:18
real(kind=realtype) totalr
Definition: iteration.f90:126
integer(kind=inttype) groundlevel
Definition: iteration.f90:18
real(kind=realtype) rfil
Definition: iteration.f90:36
subroutine updateoversetconnectivity(level, sps)
logical oversetpresent
Definition: overset.F90:373
real(kind=realtype), parameter rsacw1
Definition: paramTurb.F90:18
real(kind=realtype), parameter rsak
Definition: paramTurb.F90:13
real(kind=realtype), parameter rsact4
Definition: paramTurb.F90:25
real(kind=realtype), parameter rsacrot
Definition: paramTurb.F90:26
real(kind=realtype), parameter rsacb2
Definition: paramTurb.F90:15
real(kind=realtype), parameter rsact3
Definition: paramTurb.F90:24
real(kind=realtype), parameter rsacw3
Definition: paramTurb.F90:21
real(kind=realtype), parameter rsacw2
Definition: paramTurb.F90:20
real(kind=realtype), parameter rsacv1
Definition: paramTurb.F90:17
real(kind=realtype), parameter rsacb3
Definition: paramTurb.F90:16
real(kind=realtype), parameter rsacb1
Definition: paramTurb.F90:14
subroutine sourceterms_block(nn, res, iRegion, pLocal)
Definition: residuals.F90:349
subroutine initres_block(varStart, varEnd, nn, sps)
Definition: residuals.F90:428
Definition: sa.F90:5
real(kind=realtype) kar2inv
Definition: sa.F90:8
real(kind=realtype) cb3inv
Definition: sa.F90:8
real(kind=realtype) cw36
Definition: sa.F90:8
real(kind=realtype) cv13
Definition: sa.F90:8
subroutine sa_block(resOnly)
Definition: sa.F90:17
integer(kind=inttype) nsections
Definition: section.f90:44
type(sectiontype), dimension(:), allocatable sections
Definition: section.f90:46
subroutine timestep_block(onlyRadii)
Definition: solverUtils.F90:44
Definition: SST.F90:1
subroutine getsolution(famLists, funcValues, globalValues)
subroutine bcturbtreatment
subroutine applyallturbbcthisblock(secondHalo)
logical secondord
Definition: turbMod.F90:15
subroutine computeeddyviscosity(includeHalos)
Definition: turbUtils.F90:581
Definition: utils.F90:1
subroutine echk(errorcode, file, line)
Definition: utils.F90:5722
logical function getcorrectfork()
Definition: utils.F90:487
real(kind=realtype) function mydim(x, y)
Definition: utils.F90:473
subroutine setpointers(nn, mm, ll)
Definition: utils.F90:3237
subroutine terminate(routineName, errorMessage)
Definition: utils.F90:502
subroutine updatewalldistancesquickly(nn, level, sps)