ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
adjointUtils.F90
Go to the documentation of this file.
1 ! This is a special function that is sued to alloc derivative values
2 ! in blockpointers_d for use with the AD code.
4 
5 contains
6 
7  subroutine setupstateresidualmatrix(matrix, useAD, usePC, useTranspose, &
8  useObjective, frozenTurb, level, useTurbOnly, useCoarseMats)
9 
10  ! Compute the state derivative matrix using a forward mode calc
11  ! There are three different flags that determine how this
12  ! routine is run:
13  ! useAD: if True, AD is used for derivative calculation, if
14  ! False, FD is used.
15  ! usePC: if True, the reduced 1st order stencil with dissipation
16  ! lumping is assembled instead of the actual exact
17  ! full stencil jacobian
18  ! useTranspose: If true, the transpose of dRdw is assembled.
19  ! For use with the adjoint this must be true.
20  ! useObjective: If true, the force matrix is assembled
21  ! level : What level to use to form the matrix. Level 1 is
22  ! always the finest level
23  !
24  use block, only: flowdomsd
25  use blockpointers
28  use inputphysics
29  use iteration
30  use flowvarrefstate
31  use inputadjoint
32  use stencils
33  use diffsizes
34  use communication
35  use adjointvars
36  use turbmod
37  use surfacefamilies, only: fullfamlist
40  use haloexchange, only: whalo2
43 #ifndef USE_COMPLEX
45 #endif
46 #include <petsc/finclude/petsc.h>
47  use petsc
48  implicit none
49 
50  ! PETSc Matrix Variable
51  mat :: matrix
52 
53  ! Input Variables
54  logical, intent(in) :: useAD, usePC, useTranspose, useObjective, frozenTurb
55  logical, intent(in), optional :: useTurbOnly, useCoarseMats
56  integer(kind=intType), intent(in) :: level
57 
58  ! Local variables.
59  integer(kind=intType) :: ierr, nn, sps, sps2, i, j, k, l, ll, ii, jj, kk
60  integer(kind=intType) :: nColor, iColor, jColor, irow, icol, fmDim, frow
61  integer(kind=intType) :: nTransfer, nState, lStart, lEnd, tmp, icount, cols(8), nCol
62  integer(kind=intType) :: n_stencil, i_stencil, m, iFringe, fInd, lvl, orderturbsave
63  integer(kind=intType), dimension(:, :), pointer :: stencil
64  real(kind=alwaysrealtype) :: delta_x, one_over_dx
65  real(kind=realtype) :: weights(8), acousticscalesave
66  real(kind=realtype), dimension(:, :), allocatable :: blk
67  integer(kind=intType), dimension(2:10) :: coarseRows
68  integer(kind=intType), dimension(8, 2:10) :: coarseCols
69  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, mm, colInd
70  logical :: resetToRANS, turbOnly, flowRes, turbRes, buildCoarseMats
71 
72  ! Determine if we are assembling a turb only PC
73  turbonly = .false.
74  if (present(useturbonly)) then
75  turbonly = useturbonly
76  end if
77 
78  buildcoarsemats = .false.
79  if (present(usecoarsemats)) then
80  buildcoarsemats = usecoarsemats
81  end if
82 
83  if (turbonly) then
84  ! we are making a PC for turbulence only KSP
85  flowres = .false.
86  turbres = .true.
87  lstart = nt1
88  lend = nt2
89  nstate = nt2 - nt1 + 1
90  else
91  ! We are making a "matrix" for either NK or adjoint
92  ! Setup number of state variable based on turbulence assumption
93  if (frozenturb) then
94  flowres = .true.
95  turbres = .false.
96  lstart = 1
97  lend = nwf
98  nstate = nwf
99  else
100  flowres = .true.
101  turbres = .true.
102  lstart = 1
103  lend = nw
104  nstate = nw
105  end if
106  end if
107 
108  ! Generic block to use while setting values
109  allocate (blk(nstate, nstate))
110 
111  ! Exchange data and call the residual to make sure its up to date
112  ! withe current w
113  call whalo2(1_inttype, 1_inttype, nw, .true., .true., .true.)
114 
115  ! This routine will not use the extra variables to block_res or the
116  ! extra outputs, so we must zero them here
117  alphad = zero
118  betad = zero
119  machd = zero
120  machgridd = zero
121  machcoefd = zero
122  pointrefd = zero
123  lengthrefd = zero
124  pinfdimd = zero
125  rhoinfdimd = zero
126  tinfdimd = zero
127 
128  rkstage = 0
129 
130  ! Zero out the matrix before we start
131  call matzeroentries(matrix, ierr)
132  call echk(ierr, __file__, __line__)
133 
134  ! Set the diagonal to 1 if the cell is not a compute cell:
135 
136  ! Make an identity block
137  blk = zero
138  do i = 1, nstate
139  blk(i, i) = one
140  end do
141 
142  do nn = 1, ndom
143  do sps = 1, ntimeintervalsspectral
144  call setpointers(nn, level, sps)
145  do k = 2, kl
146  do j = 2, jl
147  do i = 2, il
148  if (iblank(i, j, k) /= 1) then
149  irow = flowdoms(nn, level, sps)%globalCell(i, j, k)
150  cols(1) = irow
151  ncol = 1
152 
153  if (buildcoarsemats) then
154  do lvl = 1, amglevels - 1
155  coarserows(lvl + 1) = coarseindices(nn, lvl)%arr(i, j, k)
156  coarsecols(1, lvl + 1) = coarserows(lvl + 1)
157  end do
158  end if
159 
160  call setblock(blk)
161  end if
162  end do
163  end do
164  end do
165  end do
166  end do
167 
168  ! Set a pointer to the correct set of stencil depending on if we are
169  ! using the first order stencil or the full jacobian
170 
171  if (usepc) then
172  if (viscous .and. viscpc) then
173  stencil => visc_pc_stencil
174  n_stencil = n_visc_pc
175  else
176  stencil => euler_pc_stencil
177  n_stencil = n_euler_pc
178  end if
179 
180  ! Very important to use only Second-Order dissipation for PC
181  lumpeddiss = .true.
182  ! We also do not apply acoustic scaling because artificial dissipation stabilizes the ILU factorization.
183  ! This is mentioned in "Newton-Krylov-Schwarz Methods for Aerodynamics Problems: Compressible
184  ! and Incompressible Flows on Unstructured Grids" by D. K. Kaushik, D. E. Keyes, and B. F. Smith (1998).
185  ! The linear system will not converge if we reduce the artificial dissipation for the PC.
186  acousticscalesave = acousticscalefactor
187  acousticscalefactor = one
188  ! also use first order advection terms for turbulence
189  orderturbsave = orderturb
190  orderturb = firstorder
191  else
192  if (viscous) then
193  stencil => visc_drdw_stencil
194  n_stencil = n_visc_drdw
195  else
196  stencil => euler_drdw_stencil
197  n_stencil = n_euler_drdw
198  end if
199  end if
200 
201  ! Need to trick the residual evalution to use coupled (mean flow and
202  ! turbulent) together.
203 
204  ! If we want to do the matrix on a coarser level, we must first
205  ! restrict the fine grid solutions, since it is possible the
206  ! NKsolver was used an the coarse grid solutions are (very!) out of
207  ! date.
208 
209  ! Assembling matrix on coarser levels is not entirely implemented yet.
210  currentlevel = level
211  groundlevel = level
212 
213  ! Set delta_x
214  delta_x = 1e-9_realtype
215  one_over_dx = one / delta_x
216  rkstage = 0
217 
218  ! Determine if we want to use frozenTurbulent Adjoint
219  resettorans = .false.
220  if (frozenturb .and. equations == ransequations) then
221  equations = nsequations
222  resettorans = .true.
223  end if
224 
225  ! Allocate the additional memory we need for doing forward mode AD
226  ! derivatives and copy any required reference values:
227  if (.not. derivvarsallocated .and. usead) then
228  call allocderivativevalues(level)
229  end if
230 
231  ! For AD the initial seeds must all be zeroed.
232  if (usead) then
233  do nn = 1, ndom
234  do sps = 1, ntimeintervalsspectral
235  call setpointers(nn, level, sps)
236  call zeroadseeds(nn, level, sps)
237  end do
238  end do
239  end if
240 
241  do nn = 1, ndom
242  do sps = 1, ntimeintervalsspectral
243  call setpointers(nn, level, sps)
244 
245  ! Allocate some extra routines used only for assembly
246  allocate ( &
247  flowdoms(nn, level, sps)%dw_deriv(2:il, 2:jl, 2:kl, 1:nw, 1:nw), &
248  flowdoms(nn, level, sps)%wtmp(0:ib, 0:jb, 0:kb, 1:nw), &
249  flowdoms(nn, level, sps)%dwtmp(0:ib, 0:jb, 0:kb, 1:nw), &
250  flowdoms(nn, level, sps)%dwtmp2(0:ib, 0:jb, 0:kb, 1:nw), &
251  stat=ierr)
252  call echk(ierr, __file__, __line__)
253 
254  if (sps == 1) then
255  allocate (flowdoms(nn, level, sps)%color(0:ib, 0:jb, 0:kb), stat=ierr)
256  call echk(ierr, __file__, __line__)
257  end if
258  end do
259  end do
260 
261  ! For the PC we don't linearize the shock sensor so it must be
262  ! computed here.
263 
264  if (usepc) then
266  end if
267 
268  ! For FD, the initial reference values must be computed and stored.
269  if (.not. usead) then
270  call setfdreference(level)
271  end if
272 
273  ! Master Domain Loop
274  domainloopad: do nn = 1, ndom
275 
276  ! Set pointers to the first timeInstance...just to getSizes
277  call setpointers(nn, level, 1)
278  ! Set unknown sizes in diffSizes for AD routine
281 
282  ! Setup the coloring for this block depending on if its
283  ! drdw or a PC
284 
285  ! List of all Coloring Routines:
286  ! Debugging Colorings Below:
287  ! call setup_3x3x3_coloring(nn, level, nColor)
288  ! call setup_5x5x5_coloring(nn, level, nColor)
289  ! call setup_BF_coloring(nn, level, nColor)
290  ! Regular:
291  ! call setup_PC_coloring(nn, level, nColor)
292  ! call setup_dRdw_euler_coloring(nn, level, nColor)
293  ! call setup_dRdw_visc_coloring(nn, level, nColor)
294 
295  if (usepc) then
296  if (viscous .and. viscpc) then
297  call setup_3x3x3_coloring(nn, level, ncolor) ! dense 3x3x3 coloring
298  else
299  call setup_pc_coloring(nn, level, ncolor) ! Euler Colorings
300  end if
301  else
302  if (viscous) then
303  !call setup_5x5x5_coloring(nn, level, nColor)
304  call setup_drdw_visc_coloring(nn, level, ncolor)! Viscous/RANS
305  else
306  call setup_drdw_euler_coloring(nn, level, ncolor) ! Euler Colorings
307  end if
308  end if
309 
310  spectralloop: do sps = 1, ntimeintervalsspectral
311  ! Set pointers and (possibly derivative pointers)
312  if (usead) then
313  call setpointers_d(nn, level, sps)
314  else
315  call setpointers(nn, level, sps)
316  end if
317 
318  ! Do Coloring and perturb states
319  colorloop: do icolor = 1, ncolor
320  do sps2 = 1, ntimeintervalsspectral
321  flowdoms(nn, 1, sps2)%dw_deriv(:, :, :, :, :) = zero
322  end do
323 
324  ! Master State Loop
325  stateloop: do l = lstart, lend
326 
327  ! Reset All States and possibe AD seeds
328  do sps2 = 1, ntimeintervalsspectral
329  if (.not. usead) then
330  do ll = 1, nw
331  do k = 0, kb
332  do j = 0, jb
333  do i = 0, ib
334  flowdoms(nn, level, sps2)%w(i, j, k, ll) = &
335  flowdoms(nn, 1, sps2)%wtmp(i, j, k, ll)
336  end do
337  end do
338  end do
339  end do
340  end if
341 
342  if (usead) then
343  flowdomsd(nn, 1, sps2)%w = zero ! This is actually w seed
344  end if
345  end do
346 
347  ! Peturb w or set AD Seed according to iColor. Note:
348  ! Do NOT try to putt he useAD if check inside the
349  ! color if check. ifort barfs hard-core on that and it
350  ! segfaults with AVX2
351  if (usead) then
352  do k = 0, kb
353  do j = 0, jb
354  do i = 0, ib
355  if (flowdoms(nn, 1, 1)%color(i, j, k) == icolor) then
356  flowdomsd(nn, 1, sps)%w(i, j, k, l) = one
357  end if
358  end do
359  end do
360  end do
361  else
362  do k = 0, kb
363  do j = 0, jb
364  do i = 0, ib
365  if (flowdoms(nn, 1, 1)%color(i, j, k) == icolor) then
366  w(i, j, k, l) = w(i, j, k, l) + delta_x
367  end if
368  end do
369  end do
370  end do
371  end if
372 
373  ! Run Block-based residual
374  if (usead) then
375 #ifndef USE_COMPLEX
376  call block_res_state_d(nn, sps)
377 #else
378  print *, 'Forward AD routines are not complexified'
379  stop
380 #endif
381  else
382  call block_res_state(nn, sps, useflowres=flowres, useturbres=turbres)
383  end if
384 
385  ! Set the computed residual in dw_deriv. If using FD,
386  ! actually do the FD calculation if AD, just copy out dw
387  ! in flowdomsd
388 
389  ! Compute/Copy all derivatives
390  do sps2 = 1, ntimeintervalsspectral
391  do ll = lstart, lend
392  do k = 2, kl
393  do j = 2, jl
394  do i = 2, il
395  if (usead) then
396  flowdoms(nn, 1, sps2)%dw_deriv(i, j, k, ll, l) = &
397  flowdomsd(nn, 1, sps2)%dw(i, j, k, ll)
398  else
399  if (sps2 == sps) then
400  ! If the peturbation is on this
401  ! instance, we've computed the spatial
402  ! contribution so subtrace dwtmp
403 
404  flowdoms(nn, 1, sps2)%dw_deriv(i, j, k, ll, l) = &
405  one_over_dx * &
406  (flowdoms(nn, 1, sps2)%dw(i, j, k, ll) - &
407  flowdoms(nn, 1, sps2)%dwtmp(i, j, k, ll))
408  else
409  ! If the peturbation is on an off
410  ! instance, only subtract dwtmp2
411  ! which is the reference result
412  ! after initres
413 
414  flowdoms(nn, 1, sps2)%dw_deriv(i, j, k, ll, l) = &
415  one_over_dx * ( &
416  flowdoms(nn, 1, sps2)%dw(i, j, k, ll) - &
417  flowdoms(nn, 1, sps2)%dwtmp2(i, j, k, ll))
418  end if
419  end if
420  end do
421  end do
422  end do
423  end do
424  end do
425  end do stateloop
426 
427  ! Set derivatives by block in "matrix" after we've peturbed
428  ! all states in "color"
429 
430  kloop: do k = 0, kb
431  jloop: do j = 0, jb
432  iloop: do i = 0, ib
433  colblank: if (flowdoms(nn, level, sps)%iblank(i, j, k) == 1 .or. &
434  flowdoms(nn, level, sps)%iBlank(i, j, k) == -1) then
435 
436  ! If the cell we perturned ('iCol') is an
437  ! interpolated cell, we don't actually use
438  ! iCol, rather we use the 8 real donors that
439  ! comprise the cell's value.
440  if (flowdoms(nn, level, sps)%iblank(i, j, k) == 1) then
441  cols(1) = flowdoms(nn, level, sps)%globalCell(i, j, k)
442  ncol = 1
443 
444  if (buildcoarsemats) then
445  do lvl = 1, amglevels - 1
446  coarsecols(1, lvl + 1) = coarseindices(nn, lvl)%arr(i, j, k)
447  end do
448  end if
449 
450  else
451  do m = 1, 8
452  cols(m) = flowdoms(nn, level, sps)%gInd(m, i, j, k)
453 
454  if (buildcoarsemats) then
455  do lvl = 1, amglevels - 1
456  coarsecols(m, lvl + 1) = &
457  coarseoversetindices(nn, lvl)%arr(m, i, j, k)
458  end do
459  end if
460  end do
461 
462  find = fringeptr(1, i, j, k)
463  call fractoweights(flowdoms(nn, level, sps)%fringes(find)%donorFrac, &
464  weights)
465  ncol = 8
466  end if
467 
468  colorcheck: if (flowdoms(nn, 1, 1)%color(i, j, k) == icolor) then
469 
470  ! i, j, k are now the "Center" cell that we
471  ! actually petrubed. From knowledge of the
472  ! stencil, we can simply take this cell and
473  ! using the stencil, set the values around it
474  ! in PETSc
475 
476  stencilloop: do i_stencil = 1, n_stencil
477  ii = stencil(i_stencil, 1)
478  jj = stencil(i_stencil, 2)
479  kk = stencil(i_stencil, 3)
480 
481  ! Check to see if the cell in this
482  ! sentcil is on a physical cell, not a
483  ! halo/BC halo
484  onblock: if (i + ii >= 2 .and. i + ii <= il .and. &
485  j + jj >= 2 .and. j + jj <= jl .and. &
486  k + kk >= 2 .and. k + kk <= kl) then
487 
488  irow = flowdoms(nn, level, sps)%globalCell( &
489  i + ii, j + jj, k + kk)
490 
491  if (buildcoarsemats) then
492  do lvl = 1, amglevels - 1
493  coarserows(lvl + 1) = &
494  coarseindices(nn, lvl)%arr(i + ii, j + jj, k + kk)
495  end do
496  end if
497 
498  rowblank: if (flowdoms(nn, level, sps)% &
499  iblank(i + ii, j + jj, k + kk) == 1) then
500 
501  centercell: if (ii == 0 .and. jj == 0 .and. kk == 0) then
502  usediagpc: if (usepc .and. usediagtspc) then
503  ! If we're doing the PC and we want
504  ! to use TS diagonal form, only set
505  ! values for on-time insintance
506  blk = flowdoms(nn, 1, sps)%dw_deriv(i + ii, &
507  j + jj, k + kk, &
508  lstart:lend, &
509  lstart:lend)
510  call setblock(blk)
511  else
512  ! Otherwise loop over spectral
513  ! instances and set all.
514  do sps2 = 1, ntimeintervalsspectral
515  irow = flowdoms(nn, level, sps2)% &
516  globalcell(i + ii, &
517  j + jj, k + kk)
518  blk = flowdoms(nn, 1, sps2)% &
519  dw_deriv(i + ii, &
520  j + jj, k + kk, &
521  lstart:lend, lstart:lend)
522  call setblock(blk)
523  end do
524  end if usediagpc
525  else
526  ! ALl other cells just set.
527  blk = flowdoms(nn, 1, sps)%dw_deriv(i + ii, j + jj, k + kk, &
528  lstart:lend, lstart:lend)
529  call setblock(blk)
530  end if centercell
531  end if rowblank
532  end if onblock
533  end do stencilloop
534  end if colorcheck
535  end if colblank
536  end do iloop
537  end do jloop
538  end do kloop
539  end do colorloop
540  end do spectralloop
541  end do domainloopad
542 
543  ! PETSc Matrix Assembly begin
544  call matassemblybegin(matrix, mat_final_assembly, ierr)
545  call echk(ierr, __file__, __line__)
546 
547  if (buildcoarsemats) then
548  do lvl = 2, amglevels
549  call matassemblybegin(a(lvl), mat_final_assembly, ierr)
550  call echk(ierr, __file__, __line__)
551  end do
552  end if
553 
554  ! Maybe we can do something useful while the communication happens?
555  ! Deallocate the temporary memory used in this routine.
556 
557  ! Deallocate and reset values
558  if (.not. usead) then
559  call resetfdreference(level)
560  end if
561 
562  do nn = 1, ndom
563  do sps = 1, ntimeintervalsspectral
564  deallocate ( &
565  flowdoms(nn, 1, sps)%dw_deriv, &
566  flowdoms(nn, 1, sps)%wTmp, &
567  flowdoms(nn, 1, sps)%dwTmp, &
568  flowdoms(nn, 1, sps)%dwTmp2)
569  if (sps == 1) then
570  deallocate (flowdoms(nn, 1, 1)%color)
571  end if
572  end do
573  end do
574 
575  ! Return dissipation Parameters to normal -> VERY VERY IMPORTANT
576  if (usepc) then
577  lumpeddiss = .false.
578  acousticscalefactor = acousticscalesave
579  ! also recover the turbulence advection order
580  orderturb = orderturbsave
581  end if
582 
583  ! Reset the correct equation parameters if we were useing the frozen
584  ! Turbulent
585  if (resettorans) then
586  equations = ransequations
587  end if
588 
589  deallocate (blk)
590 
591  ! Complete the matrix assembly.
592  call matassemblyend(matrix, mat_final_assembly, ierr)
593  call echk(ierr, __file__, __line__)
594 
595  if (buildcoarsemats) then
596  do lvl = 2, amglevels
597  call matassemblyend(a(lvl), mat_final_assembly, ierr)
598  call echk(ierr, __file__, __line__)
599  end do
600  end if
601 
602  call matsetoption(matrix, mat_new_nonzero_locations, petsc_false, ierr)
603  call echk(ierr, __file__, __line__)
604 
605  ! ================= Important ===================
606 
607  ! We must run the residual computation to make sure that all
608  ! intermediate variables are up to date. We can just call master
609  ! for this. No need to recompute spatial terms.
610  call master(.false.)
611 
612  contains
613 
614  subroutine setblock(blk)
615  ! Sets a block at irow, icol, if useTranspose is False
616  ! Sets a block at icol, irow with transpose of blk if useTranspose is True
617 
618  use genericisnan, only: myisnan
619  implicit none
620  real(kind=realtype), dimension(nState, nState) :: blk
621 
622  ! local variables
623  integer(kind=intType) :: i, j, tmp, iRowSet, iColSet
624  logical :: zeroFlag
625  zeroflag = .false.
626 
627 #ifndef USE_COMPLEX
628  ! Check if the blk is all zeros
629 
630  zeroflag = .true.
631  do i = 1, nstate
632  do j = 1, nstate
633  if (.not. blk(i, j) == zero) then
634  zeroflag = .false.
635  end if
636  end do
637  end do
638 
639  ! Check if the blk has nan
640  if (myisnan(sum(blk))) then
641  print *, 'Bad Block:', blk
642  print *, 'irow:', irow
643  print *, 'icol', cols(1:ncol)
644  print *, 'nn:', nn
645  print *, 'ijk:', i, j, k
646  call echk(1, __file__, __line__)
647  end if
648 #endif
649 
650  if (.not. zeroflag) then
651  if (ncol == 1) then
652  if (usetranspose) then
653  blk = transpose(blk)
654  call matsetvaluesblocked(matrix, 1, cols(1), 1, irow, blk, &
655  add_values, ierr)
656  call echk(ierr, __file__, __line__)
657  else
658  call matsetvaluesblocked(matrix, 1, irow, 1, cols(1), blk, &
659  add_values, ierr)
660  call echk(ierr, __file__, __line__)
661  end if
662  else
663  if (usetranspose) then
664  blk = transpose(blk)
665  do m = 1, ncol
666  if (cols(m) >= 0) then
667  call matsetvaluesblocked(matrix, 1, cols(m), 1, irow, blk * weights(m), &
668  add_values, ierr)
669  call echk(ierr, __file__, __line__)
670  end if
671  end do
672  else
673  do m = 1, ncol
674  if (cols(m) >= 0) then
675  call matsetvaluesblocked(matrix, 1, irow, 1, cols(m), blk * weights(m), &
676  add_values, ierr)
677  call echk(ierr, __file__, __line__)
678  end if
679  end do
680  end if
681  end if
682 
683  ! Extension for setting coarse grids:
684  if (buildcoarsemats) then
685  if (ncol == 1) then
686  do lvl = 2, amglevels
687  if (usetranspose) then
688  ! Loop over the coarser levels
689  call matsetvaluesblocked(a(lvl), 1, coarsecols(1, lvl), 1, coarserows(lvl), &
690  blk, add_values, ierr)
691  else
692  call matsetvaluesblocked(a(lvl), 1, coarserows(lvl), 1, coarsecols(1, lvl), &
693  blk, add_values, ierr)
694  end if
695  end do
696  else
697  do m = 1, ncol
698  do lvl = 2, amglevels
699  if (coarsecols(m, lvl) >= 0) then
700  if (usetranspose) then
701  ! Loop over the coarser levels
702  call matsetvaluesblocked(a(lvl), 1, coarsecols(m, lvl), 1, coarserows(lvl), &
703  blk * weights(m), add_values, ierr)
704  else
705  call matsetvaluesblocked(a(lvl), 1, coarserows(lvl), 1, coarsecols(m, lvl), &
706  blk * weights(m), add_values, ierr)
707  end if
708  end if
709  end do
710  end do
711  end if
712  end if
713  end if
714  end subroutine setblock
715  end subroutine setupstateresidualmatrix
716 
717  subroutine allocderivativevalues(level)
718 
719  use constants
720  use block, only: flowdoms, flowdomsd
721  use blockpointers, only: ndom, il, jl, kl, ie, je, ke, ib, jb, kb, bcdata, &
724  use flowvarrefstate, only: winf, winfd, nw, nt1, nt2
728  use walldistancedata, only: xsurfvec, xsurfvecd!, PETSC_DETERMINE
729  use bcpointers_b
731  use utils, only: echk, setpointers, getdirangle
732  use cgnsgrid, only: cgnsdoms, cgnsdomsd, cgnsndom
733  implicit none
734 
735  ! Input parameters
736  integer(kind=intType) :: level
737 
738  ! Local variables
739  integer(kind=intType) :: sps, ierr, i, j, k, l, mm, nn
740  integer(kind=intType) :: iBeg, jBeg, iStop, jStop, isizemax, jsizemax
741  integer(kind=intType) :: inBeg, jnBeg, inStop, jnStop
742  integer(kind=intType) :: massShape(2), max_face_size
743  integer(kind=intType) :: iBoco, nDataset, iData, nDirichlet, iDirichlet, nArray
744  ! First create the derivative flowdoms structure flowDomsd. Note we
745  ! only allocate information for the finest grid.
746 
747  allocate (flowdomsd(ndom, 1, ntimeintervalsspectral), stat=ierr)
748  call echk(ierr, __file__, __line__)
749 
750  ! winfd hasn't be allocated so we'll do it here
751  allocate (winfd(size(winf)))
752 
753  ! If we are not using RANS with walDistance create a dummy xSurfVec
754  ! since one does not yet exist
755  if (.not. walldistanceneeded .or. .not. useapproxwalldistance) then
756  do sps = 1, ntimeintervalsspectral
757  call veccreatempi(adflow_comm_world, 1, petsc_determine, xsurfvec(1, sps), ierr)
758  call echk(ierr, __file__, __line__)
759  end do
760  end if
761 
762  ! Duplicate the PETSc Xsurf Vec, but only on the first level:
763  allocate (xsurfvecd(ntimeintervalsspectral))
764  do sps = 1, ntimeintervalsspectral
765  call vecduplicate(xsurfvec(1, sps), xsurfvecd(sps), ierr)
766  call echk(ierr, __file__, __line__)
767  end do
768 
769  do nn = 1, ndom
770  do sps = 1, ntimeintervalsspectral
771  call setpointers(nn, level, sps)
772 
773  ! Allocate d2wall if not already done so
774  if (.not. associated(flowdoms(nn, 1, sps)%d2wall)) then
775  allocate (flowdoms(nn, 1, sps)%d2wall(2:il, 2:jl, 2:kl))
776  call echk(ierr, __file__, __line__)
777  end if
778 
779  ! Now allocate all valus that have a differentiable
780  ! dependence.
781  allocate ( &
782  flowdomsd(nn, level, sps)%x(0:ie, 0:je, 0:ke, 3), &
783  flowdomsd(nn, level, sps)%vol(0:ib, 0:jb, 0:kb), &
784  flowdomsd(nn, level, sps)%si(0:ie, 1:je, 1:ke, 3), &
785  flowdomsd(nn, level, sps)%sj(1:ie, 0:je, 1:ke, 3), &
786  flowdomsd(nn, level, sps)%sk(1:ie, 1:je, 0:ke, 3), &
787  flowdomsd(nn, level, sps)%rotMatrixI(il, 2:jl, 2:kl, 3, 3), &
788  flowdomsd(nn, level, sps)%rotMatrixJ(2:il, jl, 2:kl, 3, 3), &
789  flowdomsd(nn, level, sps)%rotMatrixK(2:il, 2:jl, kl, 3, 3), &
790  flowdomsd(nn, level, sps)%s(ie, je, ke, 3), &
791  flowdomsd(nn, level, sps)%sFaceI(0:ie, je, ke), &
792  flowdomsd(nn, level, sps)%sFaceJ(ie, 0:je, ke), &
793  flowdomsd(nn, level, sps)%sFaceK(ie, je, 0:ke), &
794  flowdomsd(nn, level, sps)%w(0:ib, 0:jb, 0:kb, 1:nw), &
795  flowdomsd(nn, level, sps)%dw(0:ib, 0:jb, 0:kb, 1:nw), &
796  flowdomsd(nn, level, sps)%fw(0:ib, 0:jb, 0:kb, 1:nw), &
797  flowdomsd(nn, level, sps)%scratch(0:ib, 0:jb, 0:kb, 5), &
798  flowdomsd(nn, level, sps)%p(0:ib, 0:jb, 0:kb), &
799  flowdomsd(nn, level, sps)%gamma(0:ib, 0:jb, 0:kb), &
800  flowdomsd(nn, level, sps)%aa(0:ib, 0:jb, 0:kb), &
801  flowdomsd(nn, level, sps)%ux(il, jl, kl), &
802  flowdomsd(nn, level, sps)%uy(il, jl, kl), &
803  flowdomsd(nn, level, sps)%uz(il, jl, kl), &
804  flowdomsd(nn, level, sps)%vx(il, jl, kl), &
805  flowdomsd(nn, level, sps)%vy(il, jl, kl), &
806  flowdomsd(nn, level, sps)%vz(il, jl, kl), &
807  flowdomsd(nn, level, sps)%wx(il, jl, kl), &
808  flowdomsd(nn, level, sps)%wy(il, jl, kl), &
809  flowdomsd(nn, level, sps)%wz(il, jl, kl), &
810  flowdomsd(nn, level, sps)%qx(il, jl, kl), &
811  flowdomsd(nn, level, sps)%qy(il, jl, kl), &
812  flowdomsd(nn, level, sps)%qz(il, jl, kl), &
813  flowdomsd(nn, level, sps)%rlv(0:ib, 0:jb, 0:kb), &
814  flowdomsd(nn, level, sps)%rev(0:ib, 0:jb, 0:kb), &
815  flowdomsd(nn, level, sps)%dtl(1:ie, 1:je, 1:ke), &
816  flowdomsd(nn, level, sps)%radI(1:ie, 1:je, 1:ke), &
817  flowdomsd(nn, level, sps)%radJ(1:ie, 1:je, 1:ke), &
818  flowdomsd(nn, level, sps)%radK(1:ie, 1:je, 1:ke), &
819  flowdomsd(nn, level, sps)%BCData(nbocos), &
820  flowdomsd(nn, level, sps)%bmti1(je, ke, nt1:nt2, nt1:nt2), &
821  flowdomsd(nn, level, sps)%bmti2(je, ke, nt1:nt2, nt1:nt2), &
822  flowdomsd(nn, level, sps)%bmtj1(ie, ke, nt1:nt2, nt1:nt2), &
823  flowdomsd(nn, level, sps)%bmtj2(ie, ke, nt1:nt2, nt1:nt2), &
824  flowdomsd(nn, level, sps)%bmtk1(ie, je, nt1:nt2, nt1:nt2), &
825  flowdomsd(nn, level, sps)%bmtk2(ie, je, nt1:nt2, nt1:nt2), &
826  flowdomsd(nn, level, sps)%bvti1(je, ke, nt1:nt2), &
827  flowdomsd(nn, level, sps)%bvti2(je, ke, nt1:nt2), &
828  flowdomsd(nn, level, sps)%bvtj1(ie, ke, nt1:nt2), &
829  flowdomsd(nn, level, sps)%bvtj2(ie, ke, nt1:nt2), &
830  flowdomsd(nn, level, sps)%bvtk1(ie, je, nt1:nt2), &
831  flowdomsd(nn, level, sps)%bvtk2(ie, je, nt1:nt2), &
832  flowdomsd(nn, level, sps)%d2Wall(2:il, 2:jl, 2:kl), &
833  stat=ierr)
834  call echk(ierr, __file__, __line__)
835 
836  allocate (flowdomsd(nn, level, sps)%viscSubface(nviscbocos), &
837  stat=ierr)
838  call echk(ierr, __file__, __line__)
839 
840  ! Set the number of bocos/viscbocs
841  flowdomsd(nn, level, sps)%nBocos = flowdoms(nn, level, sps)%nbocos
842  flowdomsd(nn, level, sps)%nViscBocos = flowdoms(nn, level, sps)%nViscBocos
843  bocoloop: do mm = 1, nbocos
844 
845  ! Store the cell range of the boundary subface
846  ! a bit easier.
847 
848  ibeg = bcdata(mm)%icbeg; istop = bcdata(mm)%icend
849  jbeg = bcdata(mm)%jcbeg; jstop = bcdata(mm)%jcend
850 
851  inbeg = bcdata(mm)%inBeg; instop = bcdata(mm)%inEnd
852  jnbeg = bcdata(mm)%jnBeg; jnstop = bcdata(mm)%jnEnd
853  allocate ( &
854  flowdomsd(nn, level, sps)%BCData(mm)%norm(ibeg:istop, jbeg:jstop, 3), &
855  flowdomsd(nn, level, sps)%BCData(mm)%rface(ibeg:istop, jbeg:jstop), &
856  flowdomsd(nn, level, sps)%BCData(mm)%Fp(inbeg + 1:instop, jnbeg + 1:jnstop, 3), &
857  flowdomsd(nn, level, sps)%BCData(mm)%Fv(inbeg + 1:instop, jnbeg + 1:jnstop, 3), &
858  flowdomsd(nn, level, sps)%BCData(mm)%Tp(inbeg:instop, jnbeg:jnstop, 3), &
859  flowdomsd(nn, level, sps)%BCData(mm)%Tv(inbeg:instop, jnbeg:jnstop, 3), &
860  flowdomsd(nn, level, sps)%BCData(mm)%F(inbeg:instop, jnbeg:jnstop, 3), &
861  flowdomsd(nn, level, sps)%BCData(mm)%T(inbeg:instop, jnbeg:jnstop, 3), &
862  flowdomsd(nn, level, sps)%BCData(mm)%area(inbeg + 1:instop, jnbeg + 1:jnstop), &
863  flowdomsd(nn, level, sps)%BCData(mm)%uSlip(ibeg:istop, jbeg:jstop, 3), &
864  flowdomsd(nn, level, sps)%BCData(mm)%TNS_Wall(ibeg:istop, jbeg:jstop), &
865  flowdomsd(nn, level, sps)%BCData(mm)%ptInlet(ibeg:istop, jbeg:jstop), &
866  flowdomsd(nn, level, sps)%BCData(mm)%htInlet(ibeg:istop, jbeg:jstop), &
867  flowdomsd(nn, level, sps)%BCData(mm)%ttInlet(ibeg:istop, jbeg:jstop), &
868  flowdomsd(nn, level, sps)%BCData(mm)%turbInlet(ibeg:istop, jbeg:jstop, nt1:nt2), &
869  flowdomsd(nn, level, sps)%BCData(mm)%ps(ibeg:istop, jbeg:jstop), stat=ierr)
870 
871  call echk(ierr, __file__, __line__)
872  end do bocoloop
873 
874  viscbocoloop: do mm = 1, nviscbocos
875 
876  ibeg = bcdata(mm)%inBeg + 1; istop = bcdata(mm)%inEnd
877  jbeg = bcdata(mm)%jnBeg + 1; jstop = bcdata(mm)%jnEnd
878 
879  allocate ( &
880  flowdomsd(nn, level, sps)%viscSubface(mm)%tau(ibeg:istop, jbeg:jstop, 6), &
881  flowdomsd(nn, level, sps)%viscSubface(mm)%q(ibeg:istop, jbeg:jstop, 6), &
882  stat=ierr)
883  call echk(ierr, __file__, __line__)
884  end do viscbocoloop
885  end do
886  end do
887 
888  ! Allocate the derivatives values for the CGNS data structure used
889  ! to store boundary condition values
890  do nn = 1, cgnsndom
891  nbocos = cgnsdoms(nn)%nBocos
892  allocate (cgnsdomsd(nn)%bocoInfo(nbocos))
893  do iboco = 1, nbocos
894  if (associated(cgnsdoms(nn)%bocoInfo(iboco)%dataSet)) then
895  ndataset = size(cgnsdoms(nn)%bocoInfo(iboco)%dataSet)
896  allocate (cgnsdomsd(nn)%bocoInfo(iboco)%dataSet(ndataset))
897 
898  do idata = 1, ndataset
899  if (associated(cgnsdoms(nn)%bocoInfo(iboco)%dataSet(idata)%dirichletArrays)) then
900  ndirichlet = size(cgnsdoms(nn)%bocoInfo(iboco)%dataSet(idata)%dirichletArrays)
901  allocate (cgnsdomsd(nn)%bocoInfo(iboco)%dataSet(idata)%dirichletArrays(ndirichlet))
902 
903  do idirichlet = 1, ndirichlet
904  narray = size(cgnsdoms(nn)%bocoInfo(iboco)%dataSet(idata) &
905  %dirichletArrays(idirichlet)%dataArr)
906  allocate (cgnsdomsd(nn)%bocoInfo(iboco)% &
907  dataset(idata)%dirichletArrays(idirichlet)%dataArr(narray))
908  cgnsdomsd(nn)%bocoInfo(iboco)%dataSet(idata)% &
909  dirichletarrays(idirichlet)%dataArr(narray) = zero
910  end do
911  end if
912  end do
913  end if
914  end do
915  end do
916 
917  derivvarsallocated = .true.
918  end subroutine allocderivativevalues
919 
920  subroutine zeroadseeds(nn, level, sps)
921 
922  use constants
923  use block, only: flowdomsd, flowdoms
924  use blockpointers
926  use flowvarrefstate
927  use inputphysics
928  use bcpointers_b
929  use communication
930  use oversetdata, only: oversetpresent
931  use cgnsgrid, only: cgnsdoms, cgnsdomsd, cgnsndom
933  implicit none
934 
935  ! Input parameters
936  integer(kind=intType) :: nn, level, sps
937 
938  ! Working parameters
939  integer(kind=intType) :: mm, i, iDom
940  integer(kind=intType) :: iBoco, iData, iDirichlet
941  flowdomsd(nn, level, sps)%d2wall = zero
942  flowdomsd(nn, level, sps)%x = zero
943  flowdomsd(nn, level, sps)%si = zero
944  flowdomsd(nn, level, sps)%sj = zero
945  flowdomsd(nn, level, sps)%sk = zero
946  flowdomsd(nn, level, sps)%vol = zero
947 
948  flowdomsd(nn, level, sps)%s = zero
949  flowdomsd(nn, level, sps)%sFaceI = zero
950  flowdomsd(nn, level, sps)%sFaceJ = zero
951  flowdomsd(nn, level, sps)%sFaceK = zero
952 
953  flowdomsd(nn, level, sps)%w = zero
954  flowdomsd(nn, level, sps)%dw = zero
955  flowdomsd(nn, level, sps)%fw = zero
956  flowdomsd(nn, level, sps)%scratch = zero
957 
958  flowdomsd(nn, level, sps)%p = zero
959  flowdomsd(nn, level, sps)%gamma = zero
960  flowdomsd(nn, level, sps)%aa = zero
961 
962  flowdomsd(nn, level, sps)%rlv = zero
963  flowdomsd(nn, level, sps)%rev = zero
964 
965  flowdomsd(nn, level, sps)%dtl = zero
966 
967  flowdomsd(nn, level, sps)%radI = zero
968  flowdomsd(nn, level, sps)%radJ = zero
969  flowdomsd(nn, level, sps)%radK = zero
970 
971  flowdomsd(nn, level, sps)%ux = zero
972  flowdomsd(nn, level, sps)%uy = zero
973  flowdomsd(nn, level, sps)%uz = zero
974  flowdomsd(nn, level, sps)%vx = zero
975  flowdomsd(nn, level, sps)%vy = zero
976  flowdomsd(nn, level, sps)%vz = zero
977  flowdomsd(nn, level, sps)%wx = zero
978  flowdomsd(nn, level, sps)%wy = zero
979  flowdomsd(nn, level, sps)%wz = zero
980  flowdomsd(nn, level, sps)%qx = zero
981  flowdomsd(nn, level, sps)%qy = zero
982  flowdomsd(nn, level, sps)%qz = zero
983 
984  flowdomsd(nn, level, sps)%bmti1 = zero
985  flowdomsd(nn, level, sps)%bmti2 = zero
986  flowdomsd(nn, level, sps)%bmtj1 = zero
987  flowdomsd(nn, level, sps)%bmtj2 = zero
988  flowdomsd(nn, level, sps)%bmtk1 = zero
989  flowdomsd(nn, level, sps)%bmtk2 = zero
990  flowdomsd(nn, level, sps)%bvti1 = zero
991  flowdomsd(nn, level, sps)%bvti2 = zero
992  flowdomsd(nn, level, sps)%bvtj1 = zero
993  flowdomsd(nn, level, sps)%bvtj2 = zero
994  flowdomsd(nn, level, sps)%bvtk1 = zero
995  flowdomsd(nn, level, sps)%bvtk2 = zero
996 
997  bocoloop: do mm = 1, flowdoms(nn, level, sps)%nBocos
998  flowdomsd(nn, level, sps)%BCData(mm)%norm = zero
999  flowdomsd(nn, level, sps)%bcData(mm)%rface = zero
1000  flowdomsd(nn, level, sps)%bcData(mm)%Fv = zero
1001  flowdomsd(nn, level, sps)%bcData(mm)%Fp = zero
1002  flowdomsd(nn, level, sps)%bcData(mm)%Tv = zero
1003  flowdomsd(nn, level, sps)%bcData(mm)%Tp = zero
1004  flowdomsd(nn, level, sps)%bcData(mm)%area = zero
1005  flowdomsd(nn, level, sps)%BCData(mm)%uSlip = zero
1006  flowdomsd(nn, level, sps)%BCData(mm)%TNS_Wall = zero
1007  flowdomsd(nn, level, sps)%BCData(mm)%ptInlet = zero
1008  flowdomsd(nn, level, sps)%BCData(mm)%htInlet = zero
1009  flowdomsd(nn, level, sps)%BCData(mm)%ttInlet = zero
1010  flowdomsd(nn, level, sps)%BCData(mm)%turbInlet = zero
1011  flowdomsd(nn, level, sps)%BCData(mm)%ps = zero
1012  end do bocoloop
1013 
1014  viscbocoloop: do mm = 1, flowdoms(nn, level, sps)%nViscBocos
1015  flowdomsd(nn, level, sps)%viscSubface(mm)%tau = zero
1016  flowdomsd(nn, level, sps)%viscSubface(mm)%q = zero
1017  end do viscbocoloop
1018 
1019  ! For overset, the weights may be active in the comm structure. We
1020  ! need to zero them before we can accumulate.
1021  if (oversetpresent) then
1022  ! Pointers to the overset comms to make it easier to read
1023  sends: do i = 1, commpatternoverset(level, sps)%nProcSend
1024  commpatternoverset(level, sps)%sendList(i)%interpd = zero
1025  end do sends
1026  internaloverset(level, sps)%donorInterpd = zero
1027  end if
1028 
1029  alphad = zero
1030  betad = zero
1031  machd = zero
1032  machgridd = zero
1033  machcoefd = zero
1034  pinfdimd = zero
1035  tinfdimd = zero
1036  rhoinfdimd = zero
1037  rgasdimd = zero
1038  pointrefd = zero
1039  prefd = zero
1040  rhorefd = zero
1041  trefd = zero
1042  murefd = zero
1043  urefd = zero
1044  hrefd = zero
1045  timerefd = zero
1046  pinfd = zero
1047  pinfcorrd = zero
1048  rhoinfd = zero
1049  uinfd = zero
1050  rgasd = zero
1051  muinfd = zero
1052  gammainfd = zero
1053  winfd = zero
1057 
1058  ! Zero all the reverse seeds in the dirichlet input arrays
1059  do idom = 1, cgnsndom
1060  do iboco = 1, cgnsdoms(idom)%nBocos
1061  if (associated(cgnsdoms(idom)%bocoInfo(iboco)%dataSet)) then
1062  do idata = 1, size(cgnsdoms(idom)%bocoInfo(iboco)%dataSet)
1063  if (associated(cgnsdoms(idom)%bocoInfo(iboco)%dataSet(idata)%dirichletArrays)) then
1064  do idirichlet = 1, &
1065  size(cgnsdoms(idom)%bocoInfo(iboco)%dataSet(idata)%dirichletArrays)
1066  cgnsdomsd(idom)%bocoInfo(iboco)%dataSet(idata)%dirichletArrays(idirichlet)%dataArr(:) &
1067  = zero
1068  end do
1069  end if
1070  end do
1071  end if
1072  end do
1073  end do
1074 
1075  ! And the reverse seeds in the actuator zones
1076  do i = 1, nactuatorregions
1077  actuatorregionsd(i)%force = zero
1078  actuatorregionsd(i)%torque = zero
1079  actuatorregionsd(i)%heat = zero
1080  actuatorregionsd(i)%volume = zero
1081  end do
1082 
1083  end subroutine zeroadseeds
1084  ! This is a special function that is sued to dealloc derivative values
1085  ! in blockpointers_d for use with the AD code.
1086 
1087  ! This routine setups "coloring" stencils for various sizes
1088 
1089  subroutine setup_pc_coloring(nn, level, nColor)
1090 
1091  use constants
1092  use blockpointers, only: flowdoms, ib, jb, kb
1093  use utils, only: setpointers
1094  implicit none
1095 
1096  ! Input parameters
1097  integer(kind=intType), intent(in) :: nn, level
1098 
1099  ! Output parameters
1100  integer(kind=intTYpe), intent(out) :: nColor
1101 
1102  ! Working
1103  integer(kind=intType) :: i, j, k
1104 
1105  call setpointers(nn, level, 1)
1106  !DIR$ NOVECTOR
1107  do k = 0, kb
1108  do j = 0, jb
1109  do i = 0, ib
1110  ! Add the extra one for 1-based numbering (as opposed to zero-based)
1111  flowdoms(nn, level, 1)%color(i, j, k) = &
1112  mod(i + 5 * j + 4 * k, 7) + 1
1113  end do
1114  end do
1115  end do
1116 
1117  ncolor = 7
1118 
1119  end subroutine setup_pc_coloring
1120 
1121  subroutine setup_drdw_euler_coloring(nn, level, nColor)
1122 
1123  use constants
1124  use blockpointers, only: flowdoms, ib, jb, kb
1125  use utils, only: setpointers
1126  implicit none
1127 
1128  ! Input parameters
1129  integer(kind=intType), intent(in) :: nn, level
1130 
1131  ! Output parameters
1132  integer(kind=intTYpe), intent(out) :: nColor
1133 
1134  ! Working
1135  integer(kind=intType) :: i, j, k
1136 
1137  call setpointers(nn, level, 1)
1138  !DIR$ NOVECTOR
1139  do k = 0, kb
1140  do j = 0, jb
1141  do i = 0, ib
1142  ! Add the extra one for 1-based numbering (as opposed to zero-based)
1143  flowdoms(nn, level, 1)%color(i, j, k) = &
1144  mod(i + 3 * j + 4 * k, 13) + 1
1145  end do
1146  end do
1147  end do
1148 
1149  ncolor = 13
1150 
1151  end subroutine setup_drdw_euler_coloring
1152 
1153  subroutine setup_drdw_visc_coloring(nn, level, nColor)
1154 
1155  use constants
1156  use blockpointers, only: flowdoms, ib, jb, kb
1157  use utils, only: setpointers
1158  implicit none
1159 
1160  ! Input parameters
1161  integer(kind=intType), intent(in) :: nn, level
1162 
1163  ! Output parameters
1164  integer(kind=intTYpe), intent(out) :: nColor
1165 
1166  ! Working
1167  integer(kind=intType) :: i, j, k
1168 
1169  call setpointers(nn, level, 1) ! Just to get the correct sizes
1170  !DIR$ NOVECTOR
1171  do k = 0, kb
1172  do j = 0, jb
1173  do i = 0, ib
1174  ! Add the extra one for 1-based numbering (as opposed to zero-based)
1175  flowdoms(nn, level, 1)%color(i, j, k) = &
1176  mod(i + 19 * j + 11 * k, 35) + 1
1177  end do
1178  end do
1179  end do
1180 
1181  ncolor = 35
1182 
1183  end subroutine setup_drdw_visc_coloring
1184 
1185  ! -------------------------------------------------------------
1186  ! Debugging Color Colorings
1187  ! -------------------------------------------------------------
1188 
1189  subroutine setup_3x3x3_coloring(nn, level, nColor)
1190 
1191  use constants
1192  use blockpointers, only: flowdoms, ib, jb, kb
1193  use utils, only: setpointers
1194  implicit none
1195 
1196  ! This is a dense 3x3x3 cube for debugging only
1197  ! Input parameters
1198  integer(kind=intType), intent(in) :: nn, level
1199 
1200  ! Output parameters
1201  integer(kind=intTYpe), intent(out) :: nColor
1202 
1203  ! Working
1204  integer(kind=intType) :: i, j, k, modi, modj, modk
1205 
1206  call setpointers(nn, level, 1)
1207  !DIR$ NOVECTOR
1208  do k = 0, kb
1209  do j = 0, jb
1210  do i = 0, ib
1211  ! Add the extra one for 1-based numbering (as opposed to zero-based)
1212  modi = mod(i, 3)
1213  modj = mod(j, 3)
1214  modk = mod(k, 3)
1215 
1216  flowdoms(nn, level, 1)%color(i, j, k) = modi + 3 * modj + 9 * modk + 1
1217 
1218  end do
1219  end do
1220  end do
1221 
1222  ncolor = 27
1223  end subroutine setup_3x3x3_coloring
1224 
1225  subroutine setup_5x5x5_coloring(nn, level, nColor)
1226 
1227  use constants
1228  use blockpointers, only: flowdoms, ib, jb, kb
1229  use utils, only: setpointers
1230  implicit none
1231 
1232  ! This is a dense 5x5x5 cube for debugging only
1233  ! Input parameters
1234  integer(kind=intType), intent(in) :: nn, level
1235 
1236  ! Output parameters
1237  integer(kind=intTYpe), intent(out) :: nColor
1238 
1239  ! Working
1240  integer(kind=intType) :: i, j, k, modi, modj, modk
1241 
1242  call setpointers(nn, level, 1)
1243  !DIR$ NOVECTOR
1244  do k = 0, kb
1245  do j = 0, jb
1246  do i = 0, ib
1247  ! Add the extra one for 1-based numbering (as opposed to zero-based)
1248  modi = mod(i, 5)
1249  modj = mod(j, 5)
1250  modk = mod(k, 5)
1251 
1252  flowdoms(nn, level, 1)%color(i, j, k) = modi + 5 * modj + 25 * modk + 1
1253 
1254  end do
1255  end do
1256  end do
1257 
1258  ncolor = 125
1259  end subroutine setup_5x5x5_coloring
1260 
1261  subroutine setup_bf_coloring(nn, level, nColor)
1262 
1263  use constants
1264  use blockpointers, only: flowdoms, ib, jb, kb
1265  use utils, only: setpointers
1266  implicit none
1267 
1268  ! Input parameters
1269  integer(kind=intType), intent(in) :: nn, level
1270 
1271  ! Output parameters
1272  integer(kind=intTYpe), intent(out) :: nColor
1273 
1274  ! Working
1275  integer(kind=intType) :: i, j, k
1276 
1277  ! This is a REALLY brute force coloring for debugging
1278 
1279  call setpointers(nn, level, 1)
1280  !DIR$ NOVECTOR
1281  do k = 0, kb
1282  do j = 0, jb
1283  do i = 0, ib
1284  ! Add the extra one for 1-based numbering (as opposed to zero-based)
1285 
1286  flowdoms(nn, level, 1)%color(i, j, k) = i + j * (ib + 1) + k * ((ib + 1) * (jb + 1)) + 1
1287  end do
1288  end do
1289  end do
1290 
1291  ncolor = (ib + 1) * (jb + 1) * (kb + 1)
1292  end subroutine setup_bf_coloring
1293 
1294  subroutine mymatcreate(matrix, blockSize, m, n, nnzDiagonal, nnzOffDiag, &
1295  file, line)
1296  ! Function to create petsc matrix to make stuff a little cleaner in
1297  ! the code above. Also, PETSc always thinks is a good idea to
1298  ! RANDOMLY change syntax between versions so this way there is only
1299  ! one place to make a change based on petsc version.
1300 
1301  use constants
1302  use communication, only: adflow_comm_world
1303  use utils, only: echk, setpointers
1304 #include <petsc/finclude/petsc.h>
1305  use petsc
1306  implicit none
1307 
1308  mat matrix
1309  integer(kind=intType), intent(in) :: blockSize, m, n
1310  integer(kind=intType), intent(in), dimension(*) :: nnzDiagonal, nnzOffDiag
1311  character(len=*) :: file
1312  integer(kind=intType) :: ierr, line
1313  ! if (blockSize > 1) then
1314  call matcreatebaij(adflow_comm_world, blocksize, &
1315  m, n, petsc_determine, petsc_determine, &
1316  0, nnzdiagonal, 0, nnzoffdiag, matrix, ierr)
1317  ! else
1318  ! call MatCreateAIJ(ADFLOW_COMM_WORLD,&
1319  ! m, n, PETSC_DETERMINE, PETSC_DETERMINE, &
1320  ! 0, nnzDiagonal, 0, nnzOffDiag, matrix, ierr)
1321  call echk(ierr, file, line)
1322  ! end if
1323 
1324  ! Warning: The array values is logically two-dimensional,
1325  ! containing the values that are to be inserted. By default the
1326  ! values are given in row major order, which is the opposite of
1327  ! the Fortran convention, meaning that the value to be put in row
1328  ! idxm[i] and column idxn[j] is located in values[i*n+j]. To allow
1329  ! the insertion of values in column major order, one can call the
1330  ! command MatSetOption(Mat A, MAT COLUMN ORIENTED);
1331 
1332  call matsetoption(matrix, mat_row_oriented, petsc_false, ierr)
1333  call echk(ierr, __file__, __line__)
1334 
1335  call matsetoption(matrix, mat_new_nonzero_allocation_err, petsc_false, ierr)
1336  call echk(ierr, __file__, __line__)
1337 
1338  end subroutine mymatcreate
1339 
1340  subroutine mykspmonitor(myKsp, n, rnorm, dummy, ierr)
1341  !
1342  ! This is a user-defined routine for monitoring the KSP
1343  ! iterative solvers. Instead of outputing the L2-norm at every
1344  ! iteration (default PETSc monitor), it only does it every
1345  ! 'adjMonStep' iterations.
1346  !
1347  use adjointpetsc
1348  use inputadjoint
1349  use communication
1350  implicit none
1351  !
1352  ! Subroutine arguments.
1353  !
1354  ! myKsp - Iterative context
1355  ! n - Iteration number
1356  ! rnorm - 2-norm (preconditioned) residual value
1357  ! dummy - Optional user-defined monitor context (unused here)
1358  ! ierr - Return error code
1359 
1360  real(kind=realtype), pointer, dimension(:, :) :: myksp
1361  integer(kind=intType) :: n, dummy, ierr
1362  real(kind=realtype) :: rnorm
1363 
1364  ! Write the residual norm to stdout every adjMonStep iterations.
1365 
1366  if (mod(n, adjmonstep) == 0) then
1367  if (myid == 0) write (*, "(I4, 1X, A, 1X, ES16.10)") n, 'KSP Residual norm', rnorm
1368  end if
1369 
1370  ierr = 0
1371 
1372  end subroutine mykspmonitor
1373 
1374  subroutine setupstandardksp(kspObject, kspObjectType, gmresRestart, preConSide, &
1375  globalPCType, ASMOverlap, globalPreConIts, localPCType, &
1376  localMatrixOrdering, localFillLevel, localPreConIts)
1377 
1378  ! This function sets up the supplied kspObject in the following
1379  ! specific fashion. The reason this setup is in
1380  ! its own function is that it is used in the following places:
1381  ! 1. Setting up the preconditioner to use for the ANK and NK solvers
1382  ! 2. Setting up the preconditioner to use for the adjoint solver
1383  ! 3. Setting up the smoothers on the coarse levels for algebraic multigrid
1384  !
1385  ! The hierarchy of the setup is:
1386  ! kspObject --> Supplied KSP object
1387  ! |
1388  ! --> master_PC --> Preconditioner type set to KSP
1389  ! |
1390  ! --> master_PC_KSP --> KSP type set to Richardson with 'globalPreConIts'
1391  ! |
1392  ! --> globalPC --> PC type set to 'globalPCType'
1393  ! | Usually Additive Schwarz and overlap is set
1394  ! | with 'ASMOverlap'. Use 0 to get BlockJacobi
1395  ! |
1396  ! --> subKSP --> KSP type set to Richardon with 'LocalPreConIts'
1397  ! |
1398  ! --> subPC --> PC type set to 'loclaPCType'.
1399  ! Usually ILU. 'localFillLevel' is
1400  ! set and 'localMatrixOrder' is used.
1401  !
1402  ! Note that if globalPreConIts=1 then maser_PC_KSP is NOT created and master_PC=globalPC
1403  ! and if localPreConIts=1 then subKSP is set to preOnly.
1404  use constants
1405  use utils, only: echk
1406  use inputadjoint, only: gmresorthogtype
1407 #include <petsc/finclude/petsc.h>
1408  use petsc
1409  implicit none
1410 
1411  ! Input Params
1412  ksp kspobject
1413  character(len=*), intent(in) :: kspObjectType, preConSide
1414  character(len=*), intent(in) :: globalPCType, localPCType
1415  character(len=*), intent(in) :: localMatrixOrdering
1416  integer(kind=intType), intent(in) :: ASMOverlap, localFillLevel, gmresRestart
1417  integer(kind=intType), intent(in) :: globalPreConIts, localPreConIts
1418 
1419  ! Working Variables
1420  pc master_pc, globalpc, subpc
1421  ksp master_pc_ksp, subksp
1422  integer(kind=intType) :: nlocal, first, ierr
1423 
1424  ! First, KSPSetFromOptions MUST be called
1425  call kspsetfromoptions(kspobject, ierr)
1426  call echk(ierr, __file__, __line__)
1427 
1428  ! Set the type of solver to use:
1429  call kspsettype(kspobject, kspobjecttype, ierr)
1430  call echk(ierr, __file__, __line__)
1431 
1432  ! If we're using GMRES set the possible gmres restart
1433  call kspgmressetrestart(kspobject, gmresrestart, ierr)
1434  call echk(ierr, __file__, __line__)
1435 
1436  ! Set the orthogonalization method for GMRES
1437  select case (gmresorthogtype)
1438  case ('modified_gram_schmidt')
1439  ! Use modified Gram-Schmidt
1440  call kspgmressetorthogonalization(kspobject, kspgmresmodifiedgramschmidtorthogonalization, ierr)
1441  case ('cgs_never_refine')
1442  ! Use classical Gram-Schmidt with no refinement
1443  call kspgmressetcgsrefinementtype(kspobject, ksp_gmres_cgs_refine_never, ierr)
1444  case ('cgs_refine_if_needed')
1445  ! Use classical Gram-Schmidt with refinement if needed
1446  call kspgmressetcgsrefinementtype(kspobject, ksp_gmres_cgs_refine_ifneeded, ierr)
1447  case ('cgs_always_refine')
1448  ! Use classical Gram-Schmidt with refinement at every iteration
1449  call kspgmressetcgsrefinementtype(kspobject, ksp_gmres_cgs_refine_always, ierr)
1450  end select
1451  call echk(ierr, __file__, __line__)
1452 
1453  ! Set the preconditioner side from option:
1454  if (trim(preconside) == 'right') then
1455  call kspsetpcside(kspobject, pc_right, ierr)
1456  else
1457  call kspsetpcside(kspobject, pc_left, ierr)
1458  end if
1459  call echk(ierr, __file__, __line__)
1460 
1461  if (trim(kspobjecttype) == 'richardson') then
1462  call kspsetpcside(kspobject, pc_left, ierr)
1463  call echk(ierr, __file__, __line__)
1464  end if
1465 
1466  ! Since there is an extra matMult required when using the Richardson preconditioner
1467  ! with only 1 iteration, only use it when we need to do more than 1 iteration.
1468  if (globalpreconits > 1) then
1469  ! Extract preconditioning context for main KSP solver: (master_PC)
1470  call kspgetpc(kspobject, master_pc, ierr)
1471  call echk(ierr, __file__, __line__)
1472 
1473  ! Set the type of master_PC to ksp. This lets us do multiple
1474  ! iterations of preconditioner application
1475  call pcsettype(master_pc, 'ksp', ierr)
1476  call echk(ierr, __file__, __line__)
1477 
1478  ! Get the ksp context from master_PC which is the actual preconditioner:
1479  call pckspgetksp(master_pc, master_pc_ksp, ierr)
1480  call echk(ierr, __file__, __line__)
1481 
1482  ! master_PC_KSP type will always be of type richardson. If the
1483  ! number of iterations is set to 1, this ksp object is transparent.
1484 
1485  call kspsettype(master_pc_ksp, 'richardson', ierr)
1486  call echk(ierr, __file__, __line__)
1487 
1488  ! Important to set the norm-type to None for efficiency.
1489  call kspsetnormtype(master_pc_ksp, ksp_norm_none, ierr)
1490  call echk(ierr, __file__, __line__)
1491 
1492  ! Do one iteration of the outer ksp preconditioners. Note the
1493  ! tolerances are unsued since we have set KSP_NORM_NON
1494  call kspsettolerances(master_pc_ksp, petsc_default_real, &
1495  petsc_default_real, petsc_default_real, &
1496  globalpreconits, ierr)
1497  call echk(ierr, __file__, __line__)
1498 
1499  ! Get the 'preconditioner for master_PC_KSP, called 'globalPC'. This
1500  ! preconditioner is potentially run multiple times.
1501  call kspgetpc(master_pc_ksp, globalpc, ierr)
1502  call echk(ierr, __file__, __line__)
1503  else
1504  ! Just pull out the pc-object if we are not using kspRichardson
1505  call kspgetpc(kspobject, globalpc, ierr)
1506  call echk(ierr, __file__, __line__)
1507  end if
1508 
1509  ! Set the 'globalPC' to additive Schwarz
1510  call pcsettype(globalpc, 'asm', ierr)
1511  call echk(ierr, __file__, __line__)
1512 
1513  ! Set the overlap required
1514  call pcasmsetoverlap(globalpc, asmoverlap, ierr)
1515  call echk(ierr, __file__, __line__)
1516 
1517  !Setup the main ksp context before extracting the subdomains
1518  call kspsetup(kspobject, ierr)
1519  call echk(ierr, __file__, __line__)
1520 
1521  ! Extract the ksp objects for each subdomain
1522  call pcasmgetsubksp(globalpc, nlocal, first, subksp, ierr)
1523  call echk(ierr, __file__, __line__)
1524 
1525  ! Since there is an extra matMult required when using the Richardson preconditioner
1526  ! with only 1 iteration, only use it when we need to do more than 1 iteration.
1527  if (localpreconits > 1) then
1528  ! Set the subksp object to Richardson so we can do multiple iterations on the sub-domains
1529  call kspsettype(subksp, 'richardson', ierr)
1530  call echk(ierr, __file__, __line__)
1531 
1532  ! Set the number of iterations to do on local blocks. Tolerances are ignored.
1533  call kspsettolerances(subksp, petsc_default_real, petsc_default_real, petsc_default_real, &
1534  localpreconits, ierr)
1535  call echk(ierr, __file__, __line__)
1536 
1537  ! normtype is NONE because we don't want to check error
1538  call kspsetnormtype(subksp, ksp_norm_none, ierr)
1539  call echk(ierr, __file__, __line__)
1540  else
1541  ! Set the subksp object to preonly because we are only doing one iteration
1542  call kspsettype(subksp, 'preonly', ierr)
1543  call echk(ierr, __file__, __line__)
1544  end if
1545 
1546  ! Extract the preconditioner for subksp object.
1547  call kspgetpc(subksp, subpc, ierr)
1548  call echk(ierr, __file__, __line__)
1549 
1550  ! Set the subpc type; only ILU is currently supported
1551  call pcsettype(subpc, localpctype, ierr)
1552  call echk(ierr, __file__, __line__)
1553 
1554  ! Setup the matrix ordering for the subpc object:
1555  call pcfactorsetmatorderingtype(subpc, localmatrixordering, ierr)
1556  call echk(ierr, __file__, __line__)
1557 
1558  ! Set the ILU parameters
1559  call pcfactorsetlevels(subpc, localfilllevel, ierr)
1560  call echk(ierr, __file__, __line__)
1561 
1562  end subroutine setupstandardksp
1563 
1564  subroutine setupstandardmultigrid(kspObject, kspObjectType, gmresRestart, preConSide, &
1565  ASMOverlap, outerPreconIts, localMatrixOrdering, fillLevel, localPreConIts, &
1566  ASMOverlapCoarse, fillLevelCoarse, localPreConItsCoarse)
1567 
1568  use constants
1569  use utils, only: echk
1570  use inputadjoint, only: gmresorthogtype
1574 #include <petsc/finclude/petsc.h>
1575  use petsc
1576  implicit none
1577 
1578  ! Inputs
1579  ksp kspobject
1580  character(len=*), intent(in) :: kspObjectType, preConSide, localMatrixOrdering
1581  integer(kind=intType), intent(in) :: ASMOverlap, fillLevel, gmresRestart, outerPreconIts, localPreConIts
1582  integer(kind=intType), intent(in) :: ASMOverlapCoarse, fillLevelCoarse, localPreConItsCoarse
1583 
1584  ! Working Variables
1585  pc shellpc
1586  integer(kind=intType) :: ierr
1587 
1588  call kspsettype(kspobject, kspobjecttype, ierr)
1589  call echk(ierr, __file__, __line__)
1590 
1591  ! Set the preconditioner side from option:
1592  if (trim(preconside) == 'right') then
1593  call kspsetpcside(kspobject, pc_right, ierr)
1594  else
1595  call kspsetpcside(kspobject, pc_left, ierr)
1596  end if
1597  call echk(ierr, __file__, __line__)
1598 
1599  call kspgmressetrestart(kspobject, gmresrestart, ierr)
1600  call echk(ierr, __file__, __line__)
1601 
1602  ! Set the orthogonalization method for GMRES
1603  select case (gmresorthogtype)
1604  case ('modified_gram_schmidt')
1605  ! Use modified Gram-Schmidt
1606  call kspgmressetorthogonalization(kspobject, kspgmresmodifiedgramschmidtorthogonalization, ierr)
1607  case ('cgs_never_refine')
1608  ! Use classical Gram-Schmidt with no refinement
1609  call kspgmressetcgsrefinementtype(kspobject, ksp_gmres_cgs_refine_never, ierr)
1610  case ('cgs_refine_if_needed')
1611  ! Use classical Gram-Schmidt with refinement if needed
1612  call kspgmressetcgsrefinementtype(kspobject, ksp_gmres_cgs_refine_ifneeded, ierr)
1613  case ('cgs_always_refine')
1614  ! Use classical Gram-Schmidt with refinement at every iteration
1615  call kspgmressetcgsrefinementtype(kspobject, ksp_gmres_cgs_refine_always, ierr)
1616  end select
1617  call echk(ierr, __file__, __line__)
1618 
1619  call kspgetpc(kspobject, shellpc, ierr)
1620  call echk(ierr, __file__, __line__)
1621 
1622  call pcsettype(shellpc, pcshell, ierr)
1623  call echk(ierr, __file__, __line__)
1624 
1625  call pcshellsetsetup(shellpc, setupshellpc, ierr)
1626  call echk(ierr, __file__, __line__)
1627 
1628  call pcshellsetdestroy(shellpc, destroyshellpc, ierr)
1629  call echk(ierr, __file__, __line__)
1630 
1631  call pcshellsetapply(shellpc, applyshellpc, ierr)
1632  call echk(ierr, __file__, __line__)
1633 
1634  ! Save the remaining variables in the AMG module
1635  amgouterits = outerpreconits
1636  amgmatrixordering = localmatrixordering
1637  amgasmoverlapfine = asmoverlap
1638  amgfilllevelfine = filllevel
1639  amglocalpreconitsfine = localpreconits
1640  amgasmoverlapcoarse = asmoverlapcoarse
1641  amgfilllevelcoarse = filllevelcoarse
1642  amglocalpreconitscoarse = localpreconitscoarse
1643 
1644  end subroutine setupstandardmultigrid
1645 
1646  subroutine destroypetscvars
1647 
1648  use constants
1649  use adjointpetsc, only: drdwt, drdwpret, adjointksp, adjointpetscvarsallocated
1650  use inputadjoint, only: approxpc
1651  use amg, only: destroyamg
1652  use utils, only: echk
1653  implicit none
1654 
1655  integer(kind=intType) :: ierr
1656 
1657  if (adjointpetscvarsallocated) then
1658 
1659  ! Matrices
1660  call matdestroy(drdwt, ierr)
1661  call echk(ierr, __file__, __line__)
1662 
1663  if (approxpc) then
1664  call matdestroy(drdwpret, ierr)
1665  call echk(ierr, __file__, __line__)
1666  end if
1667 
1668  call kspdestroy(adjointksp, ierr)
1669  call echk(ierr, __file__, __line__)
1670 
1671  call destroyamg()
1672 
1673  adjointpetscvarsallocated = .false.
1674  end if
1675 
1676  end subroutine destroypetscvars
1677 
1678  subroutine initializepetsc
1679 
1680  ! Call the C-version of the petsc initialize routine
1681 
1682  use adjointpetsc, only: petsc_comm_world
1683  use communication, only: adflow_comm_world
1684  implicit none
1685 
1686  petsc_comm_world = adflow_comm_world
1687  call initpetscwrap()
1688 
1689  end subroutine initializepetsc
1690 
1691  subroutine finalizepetsc
1692  !
1693  ! Finalize PETSc by calling the appropriate routine
1694  ! PetscFinalize provided in the PETSc library. This
1695  ! automatically calls MPI_Finalize().
1696  !
1697  use adjointpetsc, only: petscierr
1698  implicit none
1699  call petscfinalize(petscierr)
1700  end subroutine finalizepetsc
1701 
1702  subroutine statepreallocation(onProc, offProc, wSize, stencil, N_stencil, &
1703  level, transposed)
1704 
1705  ! This is a generic function that determines the correct
1706  ! pre-allocation for on and off processor parts of the TRANSPOSED
1707  ! matrix. With overset, it is quite tricky to determine the
1708  ! transpose sparsity structure exactly, so we use an alternative
1709  ! approach. We proceed to determine the non-zeros of the untranposed
1710  ! matrix, but instead of assigning a non-zero the row we're looping
1711  ! over, we assign it to the column, which will become a row in the
1712  ! tranposed matrix. Since this requires communication we use a petsc
1713  ! vector for doing off processor values. This is not strictly
1714  ! correct since we will be using the real values as floats, but
1715  ! since the number of non-zeros per row is always going to be
1716  ! bounded, we don't have to worry about the integer/floating point
1717  ! conversions.
1718 
1719  use constants
1720  use blockpointers, only: ndom, il, jl, kl, fringes, flowdoms, globalcell, &
1721  iblank, gind
1722  use communication, only: adflow_comm_world
1724  use utils, only: setpointers, echk
1725  use sorting, only: unique
1726 #include <petsc/finclude/petsc.h>
1727  use petsc
1728  implicit none
1729 
1730  ! Subroutine Arguments
1731  integer(kind=intType), intent(in) :: wSize
1732  integer(kind=intType), intent(in) :: N_stencil
1733  integer(kind=intType), intent(in) :: stencil(N_stencil, 3)
1734  integer(kind=intType), intent(out) :: onProc(wSize), offProc(wSize)
1735  integer(kind=intType), intent(in) :: level
1736  logical, intent(in) :: transposed
1737 
1738  ! Local Variables
1739  integer(kind=intType) :: nn, i, j, k, sps, ii, jj, kk, iii, jjj, kkk, n, m, gc
1740  integer(kind=intType) :: iRowStart, iRowEnd, ierr, fInd
1741  integer(kind=intType), dimension((N_stencil - 1)*8 + 1) :: cellBuffer, dummy
1742  vec offprocvec
1743  logical :: overset
1744  real(kind=realtype), pointer :: tmppointer(:)
1745 
1746  call veccreatempi(adflow_comm_world, wsize, petsc_determine, offprocvec, ierr)
1747  call echk(ierr, __file__, __line__)
1748 
1749  ! Zero the cell movement counter
1750  ii = 0
1751 
1752  ! Set the onProc values for each cell to the number of "OFF" time
1753  ! spectral instances. The "on" spectral instances are accounted for
1754  ! in the stencil
1755  onproc(:) = ntimeintervalsspectral - 1
1756  offproc(:) = 0
1757  ! Determine the range of onProc in dRdwT
1758  irowstart = flowdoms(1, 1, 1)%globalCell(2, 2, 2)
1759  call setpointers(ndom, 1, ntimeintervalsspectral)
1760  irowend = flowdoms(ndom, 1, ntimeintervalsspectral)%globalCell(il, jl, kl)
1761 
1762  do nn = 1, ndom
1763  do sps = 1, ntimeintervalsspectral
1764  call setpointers(nn, level, sps)
1765  ! Loop over each real cell
1766  do k = 2, kl
1767  do j = 2, jl
1768  do i = 2, il
1769 
1770  ! Increment the running ii counter ONLY for each each
1771  ! movement of center cell
1772  ii = ii + 1
1773 
1774  ! Reset the running tally of the number of neighbours
1775  n = 0
1776 
1777  blankedtest: if (iblank(i, j, k) == 1) then
1778 
1779  ! Short-cut flag for cells without interpolated
1780  ! cells in it's stencil
1781  overset = .false.
1782 
1783  ! Loop over the cells in the provided stencil:
1784  do jj = 1, n_stencil
1785 
1786  ! Determine the cell we are dealing with
1787  iii = stencil(jj, 1) + i
1788  jjj = stencil(jj, 2) + j
1789  kkk = stencil(jj, 3) + k
1790 
1791  ! Index of the cell we are dealing with. Make
1792  ! code easier to read
1793  gc = globalcell(iii, jjj, kkk)
1794 
1795  ! Check if the cell in question is a fringe or not:
1796  if (iblank(iii, jjj, kkk) == 1) then
1797  ! regular cell, add to our list, if it is
1798  ! not a boundary
1799  if (gc >= 0) then
1800  n = n + 1
1801  cellbuffer(n) = gc
1802  end if
1803 
1804  else if (iblank(iii, jjj, kkk) == -1) then
1805  ! Fringe cell. What we do here is loop over
1806  ! the donors for this cell and add any
1807  ! entries that are real cells
1808  overset = .true.
1809  do kk = 1, 8
1810  gc = gind(kk, iii, jjj, kkk)
1811  if (gc >= 0) then
1812  n = n + 1
1813  cellbuffer(n) = gc
1814  end if
1815  end do
1816  end if
1817  end do
1818 
1819  ! We have now added 'n' cells to our buffer. For
1820  ! the overset interpolation case, it is possible
1821  ! (actually highly likely) that the same donor
1822  ! cells are used in multiple fringes. To avoid
1823  ! allocating more space than necessary, we
1824  ! unique-ify the values, producing 'm' unique
1825  ! values. If overset wasn't present, we can be
1826  ! sure that m=n and we simply don't do the unique
1827  ! operation.
1828 
1829  if (overset) then
1830  call unique(cellbuffer, n, m, dummy)
1831  else
1832  m = n
1833  end if
1834 
1835  ! -------------------- Non-transposed code ----------------
1836  if (.not. transposed) then
1837  ! Now we loop over the total number of
1838  ! (unique) neighbours we have and assign them
1839  ! to either an on-proc or an off-proc entry:
1840  do jj = 1, m
1841  gc = cellbuffer(jj)
1842 
1843  if (gc >= irowstart .and. gc <= irowend) then
1844  onproc(ii) = onproc(ii) + 1
1845  else
1846  offproc(ii) = offproc(ii) + 1
1847  end if
1848  end do
1849  else
1850  ! -------------------- Ttransposed code ----------------
1851 
1852  ! Now we ALSO loop over the total number of
1853  ! (unique) neighbours. However, instead of
1854  ! adding to the non-zeros to the on/offproc for
1855  ! row 'ii', we add them to the column index
1856  ! which will be the row index for the
1857  ! transposed matrix.
1858  do jj = 1, m
1859  gc = cellbuffer(jj)
1860 
1861  if (gc >= irowstart .and. gc <= irowend) then
1862  ! On processor values can be dealt with
1863  ! directly since the diagonal part is square.
1864  onproc(gc - irowstart + 1) = onproc(gc - irowstart + 1) + 1
1865  else
1866  ! The offproc values need to be sent to
1867  ! the other processors and summed.
1868  call vecsetvalue(offprocvec, gc, real(1), add_values, ierr)
1869  call echk(ierr, __file__, __line__)
1870  end if
1871  end do
1872  end if
1873  else
1874  ! Blanked and interpolated cells only need a single
1875  ! non-zero per row for the identity on the diagonal.
1876  onproc(ii) = onproc(ii) + 1
1877  end if blankedtest
1878  end do ! I loop
1879  end do ! J loop
1880  end do ! K loop
1881  end do ! sps loop
1882  end do ! Domain Loop
1883 
1884  ! Assemble the offproc vector. This doesn't take any time for the
1885  ! non-transposed operation.
1886  call vecassemblybegin(offprocvec, ierr)
1887  call echk(ierr, __file__, __line__)
1888 
1889  call vecassemblyend(offprocvec, ierr)
1890  call echk(ierr, __file__, __line__)
1891 
1892  if (transposed) then
1893  ! Pull the local vector out and convert it back to integers.
1894  call vecgetarrayf90(offprocvec, tmppointer, ierr)
1895  call echk(ierr, __file__, __line__)
1896  do i = 1, wsize
1897  offproc(i) = int(tmppointer(i) + half) ! Make sure, say 14.99999 is 15.
1898  end do
1899 
1900  call vecrestorearrayf90(offprocvec, tmppointer, ierr)
1901  call echk(ierr, __file__, __line__)
1902  end if
1903 
1904  ! Done with the temporary offProcVec
1905  call vecdestroy(offprocvec, ierr)
1906  call echk(ierr, __file__, __line__)
1907 
1908  end subroutine statepreallocation
1910 
1911  ! Compute the reference shock sensor for PC computations
1912  use constants
1913  use blockpointers, only: ib, jb, kb, il, jl, kl, ie, je, ke, shocksensor, &
1914  w, gamma, p, ndom, flowdoms
1916  use inputphysics, only: equations
1917  use inputdiscretization, only: spacediscr
1918  use utils, only: setpointers, echk
1919  implicit none
1920 
1921  ! Working variables
1922  integer(kind=intType) :: nn, level, sps, i, j, k
1923 
1924  level = 1
1925 
1926  do nn = 1, ndom
1927  do sps = 1, ntimeintervalsspectral
1928  call setpointers(nn, level, sps)
1929 
1930  if (equations == eulerequations .or. spacediscr == dissmatrix) then
1931  !shockSensor is Pressure
1932  do k = 0, kb
1933  do j = 0, jb
1934  do i = 0, ib
1935  shocksensor(i, j, k) = p(i, j, k)
1936  end do
1937  end do
1938  end do
1939  else
1940  ! Enthalpy is used instead
1941  do k = 0, kb
1942  do j = 2, jl
1943  do i = 2, il
1944  shocksensor(i, j, k) = p(i, j, k) / (w(i, j, k, irho)**gamma(i, j, k))
1945  end do
1946  end do
1947  end do
1948 
1949  do k = 2, kl
1950  do j = 2, jl
1951  shocksensor(0, j, k) = p(0, j, k) / (w(0, j, k, irho)**gamma(0, j, k))
1952  shocksensor(1, j, k) = p(1, j, k) / (w(1, j, k, irho)**gamma(1, j, k))
1953  shocksensor(ie, j, k) = p(ie, j, k) / (w(ie, j, k, irho)**gamma(ie, j, k))
1954  shocksensor(ib, j, k) = p(ib, j, k) / (w(ib, j, k, irho)**gamma(ib, j, k))
1955  end do
1956  end do
1957 
1958  do k = 2, kl
1959  do i = 2, il
1960  shocksensor(i, 0, k) = p(i, 0, k) / (w(i, 0, k, irho)**gamma(i, 0, k))
1961  shocksensor(i, 1, k) = p(i, 1, k) / (w(i, 1, k, irho)**gamma(i, 1, k))
1962  shocksensor(i, je, k) = p(i, je, k) / (w(i, je, k, irho)**gamma(i, je, k))
1963  shocksensor(i, jb, k) = p(i, jb, k) / (w(i, jb, k, irho)**gamma(i, jb, k))
1964  end do
1965  end do
1966  end if
1967  end do
1968  end do
1969  end subroutine referenceshocksensor
1970 
1971  subroutine setfdreference(level)
1972  use constants
1973  use blockpointers, only: ndom, flowdoms, ib, jb, kb, il, jl, kl, &
1974  shocksensor, w, volref, dw
1976  use flowvarrefstate, only: nw, nwf
1978  use utils, only: echk, setpointers, getdirangle
1979  use residuals, only: initres_block
1980  use masterroutines, only: block_res_state
1981 
1982  implicit none
1983 
1984  ! Input Parameters
1985  integer(kind=intType) :: level
1986  ! Working Parameters
1987  integer(kind=intType) :: i, j, k, l, nn, sps
1988 
1989  ! Compute the reference values for doing jacobian with FD
1990  do nn = 1, ndom
1991  do sps = 1, ntimeintervalsspectral
1992 
1993  call setpointers(nn, level, sps)
1994  call block_res_state(nn, sps)
1995  ! Set the values
1996  do l = 1, nw
1997  do k = 0, kb
1998  do j = 0, jb
1999  do i = 0, ib
2000  flowdoms(nn, 1, sps)%wtmp(i, j, k, l) = w(i, j, k, l)
2001  flowdoms(nn, 1, sps)%dwtmp(i, j, k, l) = dw(i, j, k, l)
2002  end do
2003  end do
2004  end do
2005  end do
2006 
2007  call initres_block(1, nwf, nn, sps)
2008 
2009  ! Note: we have to divide by the volume for dwtmp2 since
2010  ! normally, dw would have been mulitpiled by 1/Vol in block_res_state
2011 
2012  do l = 1, nw
2013  do k = 0, kb
2014  do j = 0, jb
2015  do i = 0, ib
2016  flowdoms(nn, 1, sps)%dwtmp2(i, j, k, l) = &
2017  dw(i, j, k, l) / volref(i, j, k)
2018  end do
2019  end do
2020  end do
2021  end do
2022  end do
2023  end do
2024  end subroutine setfdreference
2025 
2026  subroutine resetfdreference(level)
2027 
2028  use constants
2029  use blockpointers, only: ndom, flowdoms, ib, jb, kb, w, dw
2030  use flowvarrefstate, only: nw, nwf
2032  use utils, only: setpointers
2033  implicit none
2034 
2035  ! Input Parameters
2036  integer(kind=intType) :: level
2037 
2038  ! Working Parameters
2039  integer(kind=intType) :: i, j, k, l, nn, sps
2040  real(kind=realtype) :: sepsensor, cavitation, axismoment
2041 
2042  do nn = 1, ndom
2043  do sps = 1, ntimeintervalsspectral
2044  call setpointers(nn, level, sps)
2045  ! Reset w and dw
2046  do l = 1, nw
2047  do k = 0, kb
2048  do j = 0, jb
2049  do i = 0, ib
2050  w(i, j, k, l) = flowdoms(nn, 1, sps)%wtmp(i, j, k, l)
2051  dw(i, j, k, l) = flowdoms(nn, 1, sps)%dwtmp(i, j, k, l)
2052  end do
2053  end do
2054  end do
2055  end do
2056  end do
2057  end do
2058  end subroutine resetfdreference
2059 
2060  subroutine setdiffsizes
2061  !
2062  ! This routine set the sizes for the pointers that will be
2063  ! used in the forward debug mode and reverse mode AD.
2064  !
2065  use constants
2066  use blockpointers, only: flowdoms, ib, jb, kb, ie, je, ke, ib, jb, ke, &
2067  nbocos, nviscbocos, ndom
2068  use flowvarrefstate, only: nw, nwf, nt1, nt2
2070  use inputphysics, only: equations
2071  use diffsizes
2072  implicit none
2073 
2074  ! local variables
2075  integer(kind=intType) :: nLevels
2076 
2077  ! Compute nlevels
2078  nlevels = ubound(flowdoms, 2)
2079 
2080  ! Set the size for dynamic pointers to zero for debug purpose
2081  ! bcdata%norm
2085 
2086  ! bcdata%rface
2089 
2090  ! bcdata%m
2094 
2095  ! bcdata%fp
2099 
2100  ! bcdata%fv
2104 
2105  ! bcdata%fp
2109 
2110  ! sepSensor
2113 
2114  ! sepSensorKs
2117 
2118  ! sepSensorKsArea
2121 
2122  ! Cavitation
2125 
2126  ! AxisMoment
2129 
2130  ! viscsubface%tau
2134 
2135  ! prod
2136  isize1ofdrfprod = 0
2137  isize2ofdrfprod = 0
2138  isize3ofdrfprod = 0
2139 
2140  ! vort
2141  isize1ofdrfvort = 0
2142  isize2ofdrfvort = 0
2143  isize3ofdrfvort = 0
2144 
2145  ! dvt
2146  isize1ofdrfdvt = 0
2147  isize2ofdrfdvt = 0
2148  isize3ofdrfdvt = 0
2149  isize4ofdrfdvt = 0
2150 
2151  ! vol
2152  isize1ofdrfvol = 0
2153  isize2ofdrfvol = 0
2154  isize3ofdrfvol = 0
2155 
2156  ! rho,etot,u,v,w,p,k
2157  isize1ofrho = 0
2158  isize1ofetot = 0
2159  isize1ofu = 0
2160  isize1ofv = 0
2161  isize1ofw = 0
2162  isize1ofp = 0
2163  isize1ofk = 0
2164 
2165  ! Du1, Du2, Du3
2166  isize1ofdu1 = 0
2167  isize1ofdu2 = 0
2168  isize1ofdu3 = 0
2169 
2170  ! Left, Right, Flux
2171  isize1ofleft = 0
2172  isize1ofright = 0
2173  isize1offlux = 0
2174 
2175  ! bcdata
2176  isize1ofdrfbcdata = 0!nbocos
2177 
2178  ! s
2179  isize1ofdrfs = 0!ie
2180  isize2ofdrfs = je
2181  isize3ofdrfs = ke
2182  isize4ofdrfs = 3
2183 
2184  ! sfacei
2185  isize3ofdrfsfacei = 0!ie + 1
2188 
2189  ! sfacej
2190  isize3ofdrfsfacej = 0!ie
2191  isize2ofdrfsfacej = je + 1
2193 
2194  ! sfacek
2195  isize3ofdrfsfacek = 0!ie
2197  isize1ofdrfsfacek = ke + 1
2198 
2199  ! Define size for the pointers
2200  ! flowdoms
2201  isize1ofdrfflowdoms = ndom
2202  isize2ofdrfflowdoms = nlevels
2204 
2205  !viscSubface
2208 
2209  ! x
2210  isize4ofdrfx = 3
2211  isize1ofdrfx = ie + 1
2212  isize2ofdrfx = je + 1
2213  isize3ofdrfx = ke + 1
2214 
2215  ! flowdoms_x
2220 
2221  if (equations == ransequations) then
2222  ! rev
2223  isize1ofdrfrev = ib + 1
2224  isize2ofdrfrev = jb + 1
2225  isize3ofdrfrev = kb + 1
2226  else
2227  ! rev
2228  isize1ofdrfrev = 0
2229  isize2ofdrfrev = 0
2230  isize3ofdrfrev = 0
2231  end if
2232 
2233  ! rlv
2234  isize1ofdrfrlv = ib + 1
2235  isize2ofdrfrlv = jb + 1
2236  isize3ofdrfrlv = kb + 1
2237 
2238  ! w
2239  isize4ofdrfw = nw
2240  isize1ofdrfw = ib + 1
2241  isize2ofdrfw = jb + 1
2242  isize3ofdrfw = kb + 1
2243 
2244  ! flowdoms_x
2249 
2250  ! flowdoms_dw
2255 
2256  ! flowdoms_vol
2260 
2261  ! fw
2262  isize4ofdrffw = nwf
2263  isize1ofdrffw = ib + 1
2264  isize2ofdrffw = jb + 1
2265  isize3ofdrffw = kb + 1
2266 
2267  ! dw
2268  isize4ofdrfdw = nw
2269  isize1ofdrfdw = ib + 1
2270  isize2ofdrfdw = jb + 1
2271  isize3ofdrfdw = kb + 1
2272 
2273  ! p
2274  isize1ofdrfp = ib + 1
2275  isize2ofdrfp = jb + 1
2276  isize3ofdrfp = kb + 1
2277 
2278  ! gamma
2279  isize1ofdrfgamma = ib + 1
2280  isize2ofdrfgamma = jb + 1
2281  isize3ofdrfgamma = kb + 1
2282 
2283  ! dtl
2284  isize1ofdrfdtl = ie
2285  isize2ofdrfdtl = je
2286  isize3ofdrfdtl = ke
2287 
2288  ! radI
2292 
2293  ! radJ
2297 
2298  ! radK
2302 
2303  ! sI
2304  isize1ofdrfsi = ie + 1
2305  isize2ofdrfsi = je
2306  isize3ofdrfsi = ke
2307  isize4ofdrfsi = 3
2308 
2309  ! sJ
2310  isize1ofdrfsj = ie
2311  isize2ofdrfsj = je + 1
2312  isize3ofdrfsj = ke
2313  isize4ofdrfsj = 3
2314 
2315  ! sK
2316  isize1ofdrfsk = ie
2317  isize2ofdrfsk = je
2318  isize3ofdrfsk = ke + 1
2319  isize4ofdrfsk = 3
2320 
2321  !bmti1
2324  isize3ofdrfbmti1 = nt2 - nt1 + 1
2325  isize4ofdrfbmti1 = nt2 - nt1 + 1
2326 
2327  !bmti2
2330  isize3ofdrfbmti2 = nt2 - nt1 + 1
2331  isize4ofdrfbmti2 = nt2 - nt1 + 1
2332 
2333  !bmtj1
2336  isize3ofdrfbmtj1 = nt2 - nt1 + 1
2337  isize4ofdrfbmtj1 = nt2 - nt1 + 1
2338 
2339  !bmtj2
2342  isize3ofdrfbmtj2 = nt2 - nt1 + 1
2343  isize4ofdrfbmtj2 = nt2 - nt1 + 1
2344 
2345  !bmtk1
2348  isize3ofdrfbmtk1 = nt2 - nt1 + 1
2349  isize4ofdrfbmtk1 = nt2 - nt1 + 1
2350 
2351  !bmtk2
2354  isize3ofdrfbmtk2 = nt2 - nt1 + 1
2355  isize4ofdrfbmtk2 = nt2 - nt1 + 1
2356 
2357  !bvti1
2360  isize3ofdrfbvti1 = nt2 - nt1 + 1
2361 
2362  !bvti2
2365  isize3ofdrfbvti2 = nt2 - nt1 + 1
2366  !bvti1
2369  isize3ofdrfbvti1 = nt2 - nt1 + 1
2370 
2371  !bvti2
2374  isize3ofdrfbvti2 = nt2 - nt1 + 1
2375 
2376  !bvtk1
2379  isize3ofdrfbvtk1 = nt2 - nt1 + 1
2380 
2381  !bvtk2
2384  isize3ofdrfbvtk2 = nt2 - nt1 + 1
2385 
2386  end subroutine setdiffsizes
2387 
2388 end module adjointutils
subroutine setblock(blk)
logical function onblock(i, j, k)
Definition: fortranPC.F90:450
type(actuatorregiontype), dimension(nactuatorregionsmax), target actuatorregionsd
integer(kind=inttype) nactuatorregions
logical adjointpetscvarsallocated
subroutine setupstandardmultigrid(kspObject, kspObjectType, gmresRestart, preConSide, ASMOverlap, outerPreconIts, localMatrixOrdering, fillLevel, localPreConIts, ASMOverlapCoarse, fillLevelCoarse, localPreConItsCoarse)
subroutine initializepetsc
subroutine setup_3x3x3_coloring(nn, level, nColor)
subroutine mymatcreate(matrix, blockSize, m, n, nnzDiagonal, nnzOffDiag, file, line)
subroutine mykspmonitor(myKsp, n, rnorm, dummy, ierr)
subroutine zeroadseeds(nn, level, sps)
subroutine resetfdreference(level)
subroutine setup_bf_coloring(nn, level, nColor)
subroutine destroypetscvars
subroutine setup_drdw_visc_coloring(nn, level, nColor)
subroutine setdiffsizes
subroutine finalizepetsc
subroutine setupstateresidualmatrix(matrix, useAD, usePC, useTranspose, useObjective, frozenTurb, level, useTurbOnly, useCoarseMats)
Definition: adjointUtils.F90:9
subroutine statepreallocation(onProc, offProc, wSize, stencil, N_stencil, level, transposed)
subroutine allocderivativevalues(level)
subroutine setupstandardksp(kspObject, kspObjectType, gmresRestart, preConSide, globalPCType, ASMOverlap, globalPreConIts, localPCType, localMatrixOrdering, localFillLevel, localPreConIts)
subroutine referenceshocksensor
subroutine setfdreference(level)
subroutine setup_5x5x5_coloring(nn, level, nColor)
subroutine setup_drdw_euler_coloring(nn, level, nColor)
subroutine setup_pc_coloring(nn, level, nColor)
logical derivvarsallocated
Definition: ADjointVars.F90:41
Definition: amg.F90:6
type(arr3int4), dimension(:, :), allocatable, target coarseindices
Definition: amg.F90:68
integer(kind=inttype) amgouterits
Definition: amg.F90:33
integer(kind=inttype) amglevels
Definition: amg.F90:30
type(arr4int4), dimension(:, :), allocatable, target coarseoversetindices
Definition: amg.F90:69
subroutine setupshellpc(pc, ierr)
Definition: amg.F90:520
subroutine destroyamg
Definition: amg.F90:434
integer(kind=inttype) amgfilllevelfine
Definition: amg.F90:50
integer(kind=inttype) amglocalpreconitsfine
Definition: amg.F90:40
integer(kind=inttype) amglocalpreconitscoarse
Definition: amg.F90:41
subroutine applyshellpc(pc, x, y, ierr)
Definition: amg.F90:468
integer(kind=inttype) amgasmoverlapcoarse
Definition: amg.F90:46
character(len=maxstringlen) amgmatrixordering
Definition: amg.F90:54
integer(kind=inttype) amgasmoverlapfine
Definition: amg.F90:45
integer(kind=inttype) amgfilllevelcoarse
Definition: amg.F90:51
subroutine destroyshellpc(pc, ierr)
Definition: amg.F90:620
Definition: BCData.F90:1
Definition: block.F90:1
type(blocktype), dimension(:, :, :), allocatable, target flowdomsd
Definition: block.F90:772
type(blocktype), dimension(:, :, :), allocatable, target flowdoms
Definition: block.F90:771
type(fringetype), dimension(:), pointer fringes
real(kind=realtype), dimension(:, :, :), pointer gamma
integer(kind=inttype) jl
integer(kind=inttype) nviscbocos
real(kind=realtype), dimension(:, :, :), pointer p
integer(kind=inttype), dimension(:, :, :, :), pointer fringeptr
integer(kind=inttype) ie
real(kind=realtype), dimension(:, :, :, :), pointer w
integer(kind=inttype), dimension(:, :, :), pointer iblank
integer(kind=inttype), dimension(:, :, :), pointer globalcell
integer(kind=inttype) jb
integer(kind=inttype) kb
integer(kind=inttype) nbocos
real(kind=realtype), dimension(:, :, :), pointer volref
real(kind=realtype), dimension(:, :, :, :), pointer dw
real(kind=realtype), dimension(:, :, :), pointer shocksensor
integer(kind=inttype) ib
integer(kind=inttype), dimension(:, :, :, :), pointer gind
integer(kind=inttype) je
integer(kind=inttype) ke
integer(kind=inttype) kl
integer(kind=inttype) il
type(cgnsblockinfotype), dimension(:), allocatable cgnsdoms
Definition: cgnsGrid.F90:495
type(cgnsblockinfotype), dimension(:), allocatable cgnsdomsd
Definition: cgnsGrid.F90:496
integer(kind=inttype) cgnsndom
Definition: cgnsGrid.F90:491
type(internalcommtype), dimension(:, :), allocatable, target internaloverset
type(commtype), dimension(:, :), allocatable, target commpatternoverset
integer adflow_comm_world
real(kind=realtype), parameter zero
Definition: constants.F90:71
integer, parameter irho
Definition: constants.F90:34
integer(kind=inttype), parameter eulerequations
Definition: constants.F90:110
real(kind=realtype), parameter half
Definition: constants.F90:80
integer(kind=inttype), parameter dissmatrix
Definition: constants.F90:149
integer(kind=inttype), parameter ransequations
Definition: constants.F90:110
integer(kind=inttype) isize3ofdrfsfacek
Definition: diffSizes.f90:26
integer(kind=inttype) isize2ofdrfdw
Definition: diffSizes.f90:20
integer(kind=inttype) isize4ofdrfw
Definition: diffSizes.f90:18
integer(kind=inttype) isize4ofdrfdvt
Definition: diffSizes.f90:85
integer(kind=inttype) isize4ofdrfbmtk1
Definition: diffSizes.f90:66
integer(kind=inttype) isize1ofdrfradi
Definition: diffSizes.f90:27
integer(kind=inttype) isize3ofdrfbmtj1
Definition: diffSizes.f90:47
integer(kind=inttype) isize1ofdrfviscsubface
Definition: diffSizes.f90:10
integer(kind=inttype) isize1ofdrfdrfbcdata_cavitation
Definition: diffSizes.f90:80
integer(kind=inttype) isize2ofdrfradk
Definition: diffSizes.f90:29
integer(kind=inttype) isize2ofdrfbvtk1
Definition: diffSizes.f90:68
integer(kind=inttype) isize3ofdrfdw
Definition: diffSizes.f90:20
integer(kind=inttype) isize1ofdrfgamma
Definition: diffSizes.f90:21
integer(kind=inttype) isize4ofdrfbmti2
Definition: diffSizes.f90:51
integer(kind=inttype) isize2ofdrfvol
Definition: diffSizes.f90:87
integer(kind=inttype) isize2ofdrfsfacej
Definition: diffSizes.f90:25
integer(kind=inttype) isize2ofdrfdrfbcdata_rface
Definition: diffSizes.f90:82
integer(kind=inttype) isize3ofdrfbvti1
Definition: diffSizes.f90:57
integer(kind=inttype) isize1ofdrfdvt
Definition: diffSizes.f90:85
integer(kind=inttype) isize3ofdrfgamma
Definition: diffSizes.f90:21
integer(kind=inttype) isize1ofdrfbmti1
Definition: diffSizes.f90:59
integer(kind=inttype) isize1ofdu1
Definition: diffSizes.f90:107
integer(kind=inttype) isize2ofdrfdrfbcdata_oarea
Definition: diffSizes.f90:76
integer(kind=inttype) isize1ofdrfbvtk2
Definition: diffSizes.f90:64
integer(kind=inttype) isize2ofdrfradj
Definition: diffSizes.f90:28
integer(kind=inttype) isize1ofdrfsi
Definition: diffSizes.f90:31
integer(kind=inttype) isize2ofdrfsfacei
Definition: diffSizes.f90:24
integer(kind=inttype) isize2ofdrfrev
Definition: diffSizes.f90:23
integer(kind=inttype) isize3ofdrfsfacei
Definition: diffSizes.f90:24
integer(kind=inttype) isize3ofdrfdtl
Definition: diffSizes.f90:112
integer(kind=inttype) isize1ofdrfbmtk2
Definition: diffSizes.f90:64
integer(kind=inttype) isize1ofdrfflowdoms_vol
Definition: diffSizes.f90:95
integer(kind=inttype) isize2ofdrfsi
Definition: diffSizes.f90:31
integer(kind=inttype) isize1ofdrfdrfbcdata_norm
Definition: diffSizes.f90:75
integer(kind=inttype) isize2ofdrfs
Definition: diffSizes.f90:102
integer(kind=inttype) isize1ofv
Definition: diffSizes.f90:104
integer(kind=inttype) isize3ofdrfdrfbcdata_oarea
Definition: diffSizes.f90:76
integer(kind=inttype) isize2ofdrfflowdoms_x
Definition: diffSizes.f90:36
integer(kind=inttype) isize4ofdrfs
Definition: diffSizes.f90:101
integer(kind=inttype) isize1ofdrfx
Definition: diffSizes.f90:99
integer(kind=inttype) isize2ofdrfdrfbcdata_sepsensorksarea
Definition: diffSizes.f90:79
integer(kind=inttype) isize1ofdu3
Definition: diffSizes.f90:107
integer(kind=inttype) isize3ofdrfflowdoms_w
Definition: diffSizes.f90:38
integer(kind=inttype) isize1ofdrfdrfviscsubface_tau
Definition: diffSizes.f90:89
integer(kind=inttype) isize2ofdrfsj
Definition: diffSizes.f90:32
integer(kind=inttype) isize2ofdrfdrfviscsubface_tau
Definition: diffSizes.f90:89
integer(kind=inttype) isize3ofdrfradj
Definition: diffSizes.f90:28
integer(kind=inttype) isize3ofdrfdrfbcdata_fv
Definition: diffSizes.f90:74
integer(kind=inttype) isize4ofdrfbmti1
Definition: diffSizes.f90:56
integer(kind=inttype) isize1ofrho
Definition: diffSizes.f90:104
integer(kind=inttype) isize1ofdrfprod
Definition: diffSizes.f90:84
integer(kind=inttype) isize1ofdrfsk
Definition: diffSizes.f90:33
integer(kind=inttype) isize1ofdrfw
Definition: diffSizes.f90:18
integer(kind=inttype) isize2ofdrfsfacek
Definition: diffSizes.f90:26
integer(kind=inttype) isize2ofdrfdrfbcdata_cavitation
Definition: diffSizes.f90:80
integer(kind=inttype) isize3ofdrfbmtk1
Definition: diffSizes.f90:67
integer(kind=inttype) isize1ofdrfsj
Definition: diffSizes.f90:32
integer(kind=inttype) isize1ofdrfdrfbcdata_fp
Definition: diffSizes.f90:73
integer(kind=inttype) isize1offlux
Definition: diffSizes.f90:108
integer(kind=inttype) isize1ofdrfflowdoms_bcdata
Definition: diffSizes.f90:14
integer(kind=inttype) isize1ofdrfradj
Definition: diffSizes.f90:28
integer(kind=inttype) isize1ofdu2
Definition: diffSizes.f90:107
integer(kind=inttype) isize3ofdrfradk
Definition: diffSizes.f90:29
integer(kind=inttype) isize1ofdrfsfacej
Definition: diffSizes.f90:25
integer(kind=inttype) isize3ofdrfbvtk2
Definition: diffSizes.f90:62
integer(kind=inttype) isize3ofdrfdrfbcdata_fp
Definition: diffSizes.f90:73
integer(kind=inttype) isize2ofdrfvort
Definition: diffSizes.f90:86
integer(kind=inttype) isize3ofdrfbmtj2
Definition: diffSizes.f90:42
integer(kind=inttype) isize3ofdrfdrfviscsubface_tau
Definition: diffSizes.f90:90
integer(kind=inttype) isize1ofdrfdrfbcdata_sepsensorksarea
Definition: diffSizes.f90:79
integer(kind=inttype) isize1ofw
Definition: diffSizes.f90:105
integer(kind=inttype) isize3ofdrfp
Definition: diffSizes.f90:22
integer(kind=inttype) isize1ofdrfdrfbcdata_sepsensorks
Definition: diffSizes.f90:78
integer(kind=inttype) isize1ofdrfflowdoms
Definition: diffSizes.f90:11
integer(kind=inttype) isize1ofdrfbvti2
Definition: diffSizes.f90:54
integer(kind=inttype) isize1ofdrfdtl
Definition: diffSizes.f90:112
integer(kind=inttype) isize2ofdrfbmtj2
Definition: diffSizes.f90:43
integer(kind=inttype) isize2ofdrfprod
Definition: diffSizes.f90:84
integer(kind=inttype) isize3ofdrfrlv
Definition: diffSizes.f90:17
integer(kind=inttype) isize1ofdrfdrfbcdata_m
Definition: diffSizes.f90:72
integer(kind=inttype) isize1ofdrfdrfbcdata_sepsensor
Definition: diffSizes.f90:77
integer(kind=inttype) isize4ofdrfflowdoms_x
Definition: diffSizes.f90:35
integer(kind=inttype) isize1ofdrfvort
Definition: diffSizes.f90:86
integer(kind=inttype) isize2ofdrfflowdoms
Definition: diffSizes.f90:12
integer(kind=inttype) isize3ofdrfvol
Definition: diffSizes.f90:87
integer(kind=inttype) isize4ofdrffw
Definition: diffSizes.f90:19
integer(kind=inttype) isize3ofdrfflowdoms_x
Definition: diffSizes.f90:35
integer(kind=inttype) isize1ofdrfs
Definition: diffSizes.f90:102
integer(kind=inttype) isize3ofdrfbvtk1
Definition: diffSizes.f90:67
integer(kind=inttype) isize1ofdrfsfacei
Definition: diffSizes.f90:24
integer(kind=inttype) isize2ofdrfbvti2
Definition: diffSizes.f90:53
integer(kind=inttype) isize2ofdrffw
Definition: diffSizes.f90:19
integer(kind=inttype) isize3ofdrfflowdoms_vol
Definition: diffSizes.f90:96
integer(kind=inttype) isize1ofdrfbvti1
Definition: diffSizes.f90:59
integer(kind=inttype) isize3ofdrfbvti2
Definition: diffSizes.f90:52
integer(kind=inttype) isize2ofdrfbmtk1
Definition: diffSizes.f90:68
integer(kind=inttype) isize1ofright
Definition: diffSizes.f90:108
integer(kind=inttype) isize2ofdrfbmtj1
Definition: diffSizes.f90:48
integer(kind=inttype) isize4ofdrfsj
Definition: diffSizes.f90:32
integer(kind=inttype) isize1ofdrffw
Definition: diffSizes.f90:19
integer(kind=inttype) isize3ofdrfflowdoms
Definition: diffSizes.f90:13
integer(kind=inttype) isize3ofdrfsfacej
Definition: diffSizes.f90:25
integer(kind=inttype) isize4ofdrfdw
Definition: diffSizes.f90:20
integer(kind=inttype) isize3ofdrfw
Definition: diffSizes.f90:18
integer(kind=inttype) isize4ofdrfx
Definition: diffSizes.f90:98
integer(kind=inttype) isize2ofdrfdvt
Definition: diffSizes.f90:85
integer(kind=inttype) isize4ofdrfflowdoms_w
Definition: diffSizes.f90:38
integer(kind=inttype) isize2ofdrfflowdoms_vol
Definition: diffSizes.f90:95
integer(kind=inttype) isize2ofdrfdrfbcdata_m
Definition: diffSizes.f90:72
integer(kind=inttype) isize1ofdrfdrfbcdata_oarea
Definition: diffSizes.f90:76
integer(kind=inttype) isize2ofdrfbmtk2
Definition: diffSizes.f90:63
integer(kind=inttype) isize1ofp
Definition: diffSizes.f90:105
integer(kind=inttype) isize1ofdrfdrfbcdata_rface
Definition: diffSizes.f90:82
integer(kind=inttype) isize2ofdrfflowdoms_w
Definition: diffSizes.f90:39
integer(kind=inttype) isize1ofdrfp
Definition: diffSizes.f90:22
integer(kind=inttype) isize1ofdrfbcdata
Definition: diffSizes.f90:8
integer(kind=inttype) isize1ofdrfsfacek
Definition: diffSizes.f90:26
integer(kind=inttype) isize2ofdrfbvti1
Definition: diffSizes.f90:58
integer(kind=inttype) isize1ofdrfdrfbcdata_axismoment
Definition: diffSizes.f90:81
integer(kind=inttype) isize1ofdrfdw
Definition: diffSizes.f90:20
integer(kind=inttype) isize2ofdrfdrfbcdata_axismoment
Definition: diffSizes.f90:81
integer(kind=inttype) isize3ofdrfx
Definition: diffSizes.f90:98
integer(kind=inttype) isize2ofdrfdrfbcdata_fp
Definition: diffSizes.f90:73
integer(kind=inttype) isize1ofdrfrlv
Definition: diffSizes.f90:17
integer(kind=inttype) isize2ofdrfdrfbcdata_sepsensor
Definition: diffSizes.f90:77
integer(kind=inttype) isize4ofdrfsi
Definition: diffSizes.f90:31
integer(kind=inttype) isize2ofdrfw
Definition: diffSizes.f90:18
integer(kind=inttype) isize4ofdrfbmtj1
Definition: diffSizes.f90:46
integer(kind=inttype) isize1ofk
Definition: diffSizes.f90:105
integer(kind=inttype) isize2ofdrfdrfbcdata_sepsensorks
Definition: diffSizes.f90:78
integer(kind=inttype) isize1ofdrfflowdoms_dw
Definition: diffSizes.f90:92
integer(kind=inttype) isize2ofdrfflowdoms_dw
Definition: diffSizes.f90:92
integer(kind=inttype) isize1ofdrfdrfbcdata_fv
Definition: diffSizes.f90:74
integer(kind=inttype) isize2ofdrfsk
Definition: diffSizes.f90:33
integer(kind=inttype) isize3ofdrfdrfbcdata_m
Definition: diffSizes.f90:72
integer(kind=inttype) isize1ofdrfbmti2
Definition: diffSizes.f90:54
integer(kind=inttype) isize2ofdrfradi
Definition: diffSizes.f90:27
integer(kind=inttype) isize3ofdrfbmti1
Definition: diffSizes.f90:57
integer(kind=inttype) isize1ofdrfrev
Definition: diffSizes.f90:23
integer(kind=inttype) isize1ofu
Definition: diffSizes.f90:104
integer(kind=inttype) isize3ofdrfsk
Definition: diffSizes.f90:33
integer(kind=inttype) isize3ofdrfdvt
Definition: diffSizes.f90:85
integer(kind=inttype) isize1ofleft
Definition: diffSizes.f90:108
integer(kind=inttype) isize3ofdrfradi
Definition: diffSizes.f90:27
integer(kind=inttype) isize2ofdrfp
Definition: diffSizes.f90:22
integer(kind=inttype) isize2ofdrfdrfbcdata_norm
Definition: diffSizes.f90:75
integer(kind=inttype) isize3ofdrfbmtk2
Definition: diffSizes.f90:62
integer(kind=inttype) isize1ofdrfbmtk1
Definition: diffSizes.f90:69
integer(kind=inttype) isize3ofdrfrev
Definition: diffSizes.f90:23
integer(kind=inttype) isize3ofdrfsj
Definition: diffSizes.f90:32
integer(kind=inttype) isize2ofdrfx
Definition: diffSizes.f90:99
integer(kind=inttype) isize1ofdrfflowdoms_w
Definition: diffSizes.f90:39
integer(kind=inttype) isize3ofdrfflowdoms_dw
Definition: diffSizes.f90:93
integer(kind=inttype) isize1ofdrfbvtk1
Definition: diffSizes.f90:69
integer(kind=inttype) isize3ofdrfvort
Definition: diffSizes.f90:86
integer(kind=inttype) isize1ofdrfbmtj1
Definition: diffSizes.f90:49
integer(kind=inttype) isize4ofdrfbmtj2
Definition: diffSizes.f90:41
integer(kind=inttype) isize4ofdrfbmtk2
Definition: diffSizes.f90:61
integer(kind=inttype) isize3ofdrfsi
Definition: diffSizes.f90:31
integer(kind=inttype) isize1ofdrfflowdoms_x
Definition: diffSizes.f90:36
integer(kind=inttype) isize2ofdrfdrfbcdata_fv
Definition: diffSizes.f90:74
integer(kind=inttype) isize3ofdrfprod
Definition: diffSizes.f90:84
integer(kind=inttype) isize2ofdrfdtl
Definition: diffSizes.f90:112
integer(kind=inttype) isize3ofdrffw
Definition: diffSizes.f90:19
integer(kind=inttype) isize3ofdrfbmti2
Definition: diffSizes.f90:52
integer(kind=inttype) isize2ofdrfbmti1
Definition: diffSizes.f90:58
integer(kind=inttype) isize2ofdrfbmti2
Definition: diffSizes.f90:53
integer(kind=inttype) isize1ofdrfradk
Definition: diffSizes.f90:29
integer(kind=inttype) isize4ofdrfsk
Definition: diffSizes.f90:33
integer(kind=inttype) isize1ofdrfbmtj2
Definition: diffSizes.f90:44
integer(kind=inttype) isize2ofdrfbvtk2
Definition: diffSizes.f90:63
integer(kind=inttype) isize2ofdrfrlv
Definition: diffSizes.f90:17
integer(kind=inttype) isize1ofetot
Definition: diffSizes.f90:104
integer(kind=inttype) isize2ofdrfgamma
Definition: diffSizes.f90:21
integer(kind=inttype) isize1ofdrfvol
Definition: diffSizes.f90:87
integer(kind=inttype) isize4ofdrfflowdoms_dw
Definition: diffSizes.f90:93
integer(kind=inttype) isize3ofdrfdrfbcdata_norm
Definition: diffSizes.f90:75
integer(kind=inttype) isize3ofdrfs
Definition: diffSizes.f90:101
real(kind=realtype), dimension(:), allocatable winfd
real(kind=realtype) rhoinfd
integer(kind=inttype) nt1
real(kind=realtype) muinfd
real(kind=realtype) pinfcorrd
real(kind=realtype) trefd
real(kind=realtype) uinfd
real(kind=realtype) rgasd
real(kind=realtype) hrefd
real(kind=realtype) pinfdimd
real(kind=realtype) prefd
real(kind=realtype) tinfdimd
integer(kind=inttype) nwf
real(kind=realtype) gammainfd
real(kind=realtype), dimension(:), allocatable winf
real(kind=realtype) urefd
real(kind=realtype) rhoinfdimd
real(kind=realtype) pinfd
integer(kind=inttype) nw
real(kind=realtype) murefd
real(kind=realtype) rhorefd
integer(kind=inttype) nt2
real(kind=realtype) timerefd
subroutine whalo2(level, start, end, commPressure, commGamma, commViscous)
logical approxpc
Definition: inputParam.F90:792
logical viscpc
Definition: inputParam.F90:793
integer(kind=inttype) adjmonstep
Definition: inputParam.F90:826
logical usediagtspc
Definition: inputParam.F90:792
character(maxstringlen) gmresorthogtype
Definition: inputParam.F90:800
integer(kind=inttype) orderturb
Definition: inputParam.F90:73
real(kind=realtype) acousticscalefactor
Definition: inputParam.F90:79
logical useapproxwalldistance
Definition: inputParam.F90:94
integer(kind=inttype) spacediscr
Definition: inputParam.F90:72
real(kind=realtype) lengthrefd
Definition: inputParam.F90:621
integer(kind=inttype) equations
Definition: inputParam.F90:583
real(kind=realtype) betad
Definition: inputParam.F90:612
real(kind=realtype), dimension(3) liftdirectiond
Definition: inputParam.F90:614
real(kind=realtype), dimension(3) dragdirectiond
Definition: inputParam.F90:615
real(kind=realtype), dimension(3) pointrefd
Definition: inputParam.F90:616
logical walldistanceneeded
Definition: inputParam.F90:589
real(kind=realtype), dimension(3) veldirfreestreamd
Definition: inputParam.F90:613
real(kind=realtype) machd
Definition: inputParam.F90:618
real(kind=realtype) alphad
Definition: inputParam.F90:612
real(kind=realtype) machgridd
Definition: inputParam.F90:618
real(kind=realtype) rgasdimd
Definition: inputParam.F90:622
real(kind=realtype), dimension(3) liftdirection
Definition: inputParam.F90:600
real(kind=realtype) machcoefd
Definition: inputParam.F90:618
real(kind=realtype), dimension(3) veldirfreestream
Definition: inputParam.F90:599
integer(kind=inttype) ntimeintervalsspectral
Definition: inputParam.F90:645
integer(kind=inttype) currentlevel
Definition: iteration.f90:18
integer(kind=inttype) groundlevel
Definition: iteration.f90:18
integer(kind=inttype) rkstage
Definition: iteration.f90:19
subroutine block_res_state(nn, sps, useFlowRes, useTurbRes)
subroutine block_res_state_d(nn, sps)
subroutine master(useSpatial, famLists, funcValues, forces, bcDataNames, bcDataValues, bcDataFamLists)
logical oversetpresent
Definition: overset.F90:373
subroutine fractoweights(frac, weights)
subroutine initres_block(varStart, varEnd, nn, sps)
Definition: residuals.F90:428
subroutine unique(arr, nn, n_unique, inverse)
Definition: sorting.F90:899
integer(kind=inttype), parameter n_visc_drdw
Definition: stencils.f90:19
integer(kind=inttype), dimension(7, 3), target euler_pc_stencil
Definition: stencils.f90:14
integer(kind=inttype), dimension(13, 3), target euler_drdw_stencil
Definition: stencils.f90:15
integer(kind=inttype), parameter n_euler_drdw
Definition: stencils.f90:12
integer(kind=inttype), parameter n_euler_pc
Definition: stencils.f90:11
integer(kind=inttype), dimension(27, 3), target visc_pc_stencil
Definition: stencils.f90:21
integer(kind=inttype), dimension(33, 3), target visc_drdw_stencil
Definition: stencils.f90:22
integer(kind=inttype), parameter n_visc_pc
Definition: stencils.f90:18
integer(kind=inttype), dimension(:), allocatable fullfamlist
Definition: utils.F90:1
subroutine setpointers_d(nn, level, sps)
Definition: utils.F90:3564
subroutine getdirangle(freeStreamAxis, liftAxis, liftIndex, alpha, beta)
Definition: utils.F90:1428
subroutine echk(errorcode, file, line)
Definition: utils.F90:5722
subroutine setpointers(nn, mm, ll)
Definition: utils.F90:3237