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