ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
adjointDebug.F90
Go to the documentation of this file.
1 ! This module is used for debugging and testing only
2 
4 
5 contains
6 
7 #ifndef USE_COMPLEX
8 
9  subroutine computematrixfreeproductfwdfd(xvdot, extradot, wdot, bcDataValuesdot, &
10  useSpatial, useState, famLists, &
11  bcDataNames, bcDataValues, bcDataFamLists, bcVarsEmpty, &
12  dwdot, funcsDot, fDot, &
13  costSize, fSize, nTime, h)
14 
15  ! This routine is used to debug master_d. It uses the forward seeds to set perturbations
16  ! and then computes the value of the derivatives using forward finite diffenece
17 
18  use constants
19  use adjointvars
20  use blockpointers, only: ndom
27  use blockpointers, only: ndom, il, jl, kl, wd, x, w, dw, dwd, nbocos, nviscbocos
28 
30  use masterroutines, only: master
32  use flowvarrefstate, only: nw, nwf
33  use walldistancedata, only: xsurf, xsurfvec
34  use walldistance, only: updatexsurf
35  implicit none
36  !
37  ! Input Variables
38  !
39  ! derivative seeds
40  real(kind=realtype), dimension(:), intent(in) :: xvdot
41  real(kind=realtype), dimension(:), intent(in) :: extradot
42  real(kind=realtype), dimension(:), intent(in) :: wdot
43 
44  ! size data
45  logical, intent(in) :: useSpatial, useState
46  integer(kind=intType), dimension(:, :) :: famLists
47  integer(kind=intType) :: costSize, fSize, nTime
48 
49  character, dimension(:, :), intent(in) :: bcDataNames
50  real(kind=realtype), dimension(:), intent(inout) :: bcdatavalues, bcdatavaluesdot
51  integer(kind=intType), dimension(:, :) :: bcDataFamLists
52  logical, intent(in) :: BCVarsEmpty
53 
54  ! Finite difference parameters
55  real(kind=realtype), intent(in) :: h ! step size for Finite Difference
56 
57  !
58  ! Ouput Variables
59  !
60  ! Output derivative seeds
61  real(kind=realtype), dimension(size(wDot)), intent(out) :: dwdot
62  real(kind=realtype), dimension(costSize, size(famLists, 1)), intent(out) :: funcsdot
63  real(kind=realtype), dimension(3, fSize, nTime), intent(out) :: fdot
64 
65  !
66  ! Working Variables
67  !
68  integer(kind=intType) :: nn, sps, level
69  integer(kind=intType) :: ierr, mm, i, j, k, l, ii, jj, iRegion
70 
71  real(kind=realtype), dimension(costSize, size(famLists, 1)) :: funcs
72 
73  ! Input Arguments for master:
74  real(kind=realtype), dimension(costSize, size(famLists, 1)) :: funcvalues
75  real(kind=realtype), dimension(:, :, :), allocatable :: forces
76 
77  fsize = size(fdot, 2)
78  allocate (forces(3, fsize, ntimeintervalsspectral))
79 
80  ! Need to trick the residual evalution to use coupled (mean flow and
81  ! turbulent) together.
82  level = 1
83  currentlevel = level
84  groundlevel = level
85 
86  ! Allocate the memory we need for derivatives if not done so
87  ! already. Note this isn't deallocated until the adflow is
88  ! destroyed.
89 
90  ! a bit over kill for our needs, but so values are stored in the seeds
91  if (.not. derivvarsallocated) then
92  call allocderivativevalues(level)
93  end if
94 
95  ! Zero all AD seesd.
96  do nn = 1, ndom
97  do sps = 1, ntimeintervalsspectral
98  call zeroadseeds(nn, level, sps)
99  end do
100  end do
101 
102  ! ----------------------------- Run Master ---------------------------------
103  ! Run the super-dee-duper master rotuine
104  if (bcvarsempty) then
105  call master(usespatial, &
106  famlists, funcvalues, &
107  forces)
108 
109  else
110  call master(usespatial, &
111  famlists, funcvalues, &
112  forces, &
113  bcdatanames, bcdatavalues, bcdatafamlists)
114  end if
115 
116  ! Copy base val (f) into variables for the final vals (f(x+dx) - f)/dx
117  ! we add the negative sign here instead of doing it later
118 
119  ii = 0
120  do nn = 1, ndom
121  do sps = 1, ntimeintervalsspectral
122  call setpointers_d(nn, 1, sps)
123  do k = 2, kl
124  do j = 2, jl
125  do i = 2, il
126  do l = 1, nw
127  ii = ii + 1
128  dwd(i, j, k, l) = -dw(i, j, k, l)
129  end do
130  end do
131  end do
132  end do
133  end do
134  end do
135 
136  fdot = -forces
137  funcsdot = -funcvalues
138 
139  ! --------------------- apply the perturbations ----------------------------
140  ! Set the extra seeds now do the extra ones. Note that we are assuming the
141  ! machNumber used for the coefficients follows the Mach number,
142  ! not the grid mach number.
143 
144  alpha = alpha + h * extradot(ialpha)
145  beta = beta + h * extradot(ibeta)
146  mach = mach + h * extradot(imach)
147  machcoef = machcoef + h * extradot(imach)
148  machgrid = machgrid + h * extradot(imachgrid)
149  pinfdim = pinfdim + h * extradot(ipressure)
150  rhoinfdim = rhoinfdim + h * extradot(idensity)
151  tinfdim = tinfdim + h * extradot(itemperature)
152  pointref(1) = pointref(1) + h * extradot(ipointrefx)
153  pointref(2) = pointref(2) + h * extradot(ipointrefy)
154  pointref(3) = pointref(3) + h * extradot(ipointrefz)
155  rgasdim = rgasdim + h * zero
156 
157  ! Set the provided w and x seeds:
158  ii = 0
159  jj = 0
160  domainloop1: do nn = 1, ndom
161  spectalloop1: do sps = 1, ntimeintervalsspectral
162  call setpointers(nn, 1, sps)
163  do k = 1, kl
164  do j = 1, jl
165  do i = 1, il
166  do l = 1, 3
167  ii = ii + 1
168  x(i, j, k, l) = x(i, j, k, l) + xvdot(ii) * h
169  end do
170  end do
171  end do
172  end do
173  do k = 2, kl
174  do j = 2, jl
175  do i = 2, il
176  do l = 1, nw
177  jj = jj + 1
178  w(i, j, k, l) = w(i, j, k, l) + wdot(jj) * h
179  end do
180  end do
181  end do
182  end do
183  end do spectalloop1
184  end do domainloop1
185 
186  bcdatavalues = bcdatavalues + bcdatavaluesdot * h
187 
188  ! The xvolume that is set by used by update Xsurf is only allocated with
189  ! rans
190  if (equations == ransequations) then
191  call updatexsurf(level)
192  end if
193 
194  ! ----------------------------- Run Master ---------------------------------
195  ! Run the super-dee-duper master rotuine
196  if (bcvarsempty) then
197  call master(usespatial, &
198  famlists, funcvalues, &
199  forces)
200 
201  else
202  call master(usespatial, &
203  famlists, funcvalues, &
204  forces, &
205  bcdatanames, bcdatavalues, bcdatafamlists)
206 
207  end if
208 
209  ! ------------------------- set the output vectors ----------------------
210  ! Set the extra seeds now do the extra ones. Note that we are assuming the
211  ! machNumber used for the coefficients follows the Mach number,
212  ! not the grid mach number.
213 
214  alpha = alpha - h * extradot(ialpha)
215  beta = beta - h * extradot(ibeta)
216  mach = mach - h * extradot(imach)
217  machcoef = machcoef - h * extradot(imach)
218  machgrid = machgrid - h * extradot(imachgrid)
219  pinfdim = pinfdim - h * extradot(ipressure)
220  rhoinfdim = rhoinfdim - h * extradot(idensity)
221  tinfdim = tinfdim - h * extradot(itemperature)
222  pointref(1) = pointref(1) - h * extradot(ipointrefx)
223  pointref(2) = pointref(2) - h * extradot(ipointrefy)
224  pointref(3) = pointref(3) - h * extradot(ipointrefz)
225  rgasdim = rgasdim - h * zero
226 
227  ! Copy out the residual derivative into the provided dwDot and remove the
228  ! perturbation
229  ii = 0
230  jj = 0
231  do nn = 1, ndom
232  do sps = 1, ntimeintervalsspectral
233  call setpointers_d(nn, 1, sps)
234  do k = 1, kl
235  do j = 1, jl
236  do i = 1, il
237  do l = 1, 3
238  ii = ii + 1
239  x(i, j, k, l) = x(i, j, k, l) - xvdot(ii) * h
240  end do
241  end do
242  end do
243  end do
244  do k = 2, kl
245  do j = 2, jl
246  do i = 2, il
247  do l = 1, nw
248  jj = jj + 1
249  w(i, j, k, l) = w(i, j, k, l) - wdot(jj) * h
250  dwd(i, j, k, l) = (dwd(i, j, k, l) + dw(i, j, k, l)) / h
251  dwdot(jj) = dwd(i, j, k, l) ! copy values to output
252  end do
253  end do
254  end do
255  end do
256 
257  end do
258  end do
259 
260  if (equations == ransequations) then
261  call updatexsurf(level)
262  end if
263  bcdatavalues = bcdatavalues - bcdatavaluesdot * h
264 
265  fdot = (fdot + forces) / h
266  funcsdot = (funcsdot + funcvalues) / h
267 
268  end subroutine computematrixfreeproductfwdfd
269 
270  subroutine printadseeds(nn, level, sps)
271 !DIR$ NOOPTIMIZE
272  ! this routine is used for debugging master_d, and master_b.
273  ! it prints all the AD seeds used
274  ! it is useful to save the output and compare it with a diff tool
275 
276  use constants
277  use block, only: flowdomsd, flowdoms
278  use blockpointers
280  use flowvarrefstate
281  use inputphysics
282  use bcpointers_b
283  use communication
284  use oversetdata, only: oversetpresent
285  use cgnsgrid, only: cgnsdoms, cgnsdomsd, cgnsndom
287  implicit none
288 
289  ! Input parameters
290  integer(kind=intType) :: nn, level, sps
291 
292  ! Working parameters
293  integer(kind=intType) :: mm, i, iDom
294  integer(kind=intType) :: iBoco, iData, iDirichlet
295  write (*, *) 'ADSeeds for block', nn, ' at level ', level, ' at sps ', sps
296  write (*, *) 'd2wall ', minval(flowdomsd(nn, level, sps)%d2wall), &
297  maxval(flowdomsd(nn, level, sps)%d2wall), &
298  norm2(flowdomsd(nn, level, sps)%d2wall)
299  write (*, *) 'x ', minval(flowdomsd(nn, level, sps)%x), &
300  maxval(flowdomsd(nn, level, sps)%x), &
301  norm2(flowdomsd(nn, level, sps)%x)
302  write (*, *) 'si ', minval(flowdomsd(nn, level, sps)%si), &
303  maxval(flowdomsd(nn, level, sps)%si), &
304  norm2(flowdomsd(nn, level, sps)%si)
305  write (*, *) 'sj ', minval(flowdomsd(nn, level, sps)%sj), &
306  maxval(flowdomsd(nn, level, sps)%sj), &
307  norm2(flowdomsd(nn, level, sps)%sj)
308  write (*, *) 'sk ', minval(flowdomsd(nn, level, sps)%sk), &
309  maxval(flowdomsd(nn, level, sps)%sk), &
310  norm2(flowdomsd(nn, level, sps)%sk)
311  write (*, *) 'vol ', minval(flowdomsd(nn, level, sps)%vol), &
312  maxval(flowdomsd(nn, level, sps)%vol), &
313  norm2(flowdomsd(nn, level, sps)%vol)
314 
315  write (*, *) 's ', minval(flowdomsd(nn, level, sps)%s), &
316  maxval(flowdomsd(nn, level, sps)%s), &
317  norm2(flowdomsd(nn, level, sps)%s)
318  write (*, *) 'sFaceI ', minval(flowdomsd(nn, level, sps)%sFaceI), &
319  maxval(flowdomsd(nn, level, sps)%sFaceI), &
320  norm2(flowdomsd(nn, level, sps)%sFaceI)
321  write (*, *) 'sFaceJ ', minval(flowdomsd(nn, level, sps)%sFaceJ), &
322  maxval(flowdomsd(nn, level, sps)%sFaceJ), &
323  norm2(flowdomsd(nn, level, sps)%sFaceJ)
324  write (*, *) 'sFaceK ', minval(flowdomsd(nn, level, sps)%sFaceK), &
325  maxval(flowdomsd(nn, level, sps)%sFaceK), &
326  norm2(flowdomsd(nn, level, sps)%sFaceK)
327 
328  write (*, *) 'w ', minval(flowdomsd(nn, level, sps)%w), &
329  maxval(flowdomsd(nn, level, sps)%w), &
330  norm2(flowdomsd(nn, level, sps)%w)
331  write (*, *) 'dw ', minval(flowdomsd(nn, level, sps)%dw), &
332  maxval(flowdomsd(nn, level, sps)%dw), &
333  norm2(flowdomsd(nn, level, sps)%dw)
334  write (*, *) 'fw ', minval(flowdomsd(nn, level, sps)%fw), &
335  maxval(flowdomsd(nn, level, sps)%fw), &
336  norm2(flowdomsd(nn, level, sps)%fw)
337  write (*, *) 'scratch ', minval(flowdomsd(nn, level, sps)%scratch), &
338  maxval(flowdomsd(nn, level, sps)%scratch), &
339  norm2(flowdomsd(nn, level, sps)%scratch)
340 
341  write (*, *) 'p ', minval(flowdomsd(nn, level, sps)%p), &
342  maxval(flowdomsd(nn, level, sps)%p), &
343  norm2(flowdomsd(nn, level, sps)%p)
344  write (*, *) 'gamma ', minval(flowdomsd(nn, level, sps)%gamma), &
345  maxval(flowdomsd(nn, level, sps)%gamma), &
346  norm2(flowdomsd(nn, level, sps)%gamma)
347  write (*, *) 'aa ', minval(flowdomsd(nn, level, sps)%aa), &
348  maxval(flowdomsd(nn, level, sps)%aa), &
349  norm2(flowdomsd(nn, level, sps)%aa)
350 
351  write (*, *) 'rlv ', minval(flowdomsd(nn, level, sps)%rlv), &
352  maxval(flowdomsd(nn, level, sps)%rlv), &
353  norm2(flowdomsd(nn, level, sps)%rlv)
354  write (*, *) 'rev ', minval(flowdomsd(nn, level, sps)%rev), &
355  maxval(flowdomsd(nn, level, sps)%rev), &
356  norm2(flowdomsd(nn, level, sps)%rev)
357 
358  write (*, *) 'radI ', minval(flowdomsd(nn, level, sps)%radI), &
359  maxval(flowdomsd(nn, level, sps)%radI), &
360  norm2(flowdomsd(nn, level, sps)%radI)
361  write (*, *) 'radJ ', minval(flowdomsd(nn, level, sps)%radJ), &
362  maxval(flowdomsd(nn, level, sps)%radJ), &
363  norm2(flowdomsd(nn, level, sps)%radJ)
364  write (*, *) 'radK ', minval(flowdomsd(nn, level, sps)%radK), &
365  maxval(flowdomsd(nn, level, sps)%radK), &
366  norm2(flowdomsd(nn, level, sps)%radK)
367 
368  write (*, *) 'ux ', minval(flowdomsd(nn, level, sps)%ux), &
369  maxval(flowdomsd(nn, level, sps)%ux), &
370  norm2(flowdomsd(nn, level, sps)%ux)
371  write (*, *) 'uy ', minval(flowdomsd(nn, level, sps)%uy), &
372  maxval(flowdomsd(nn, level, sps)%uy), &
373  norm2(flowdomsd(nn, level, sps)%uy)
374  write (*, *) 'uz ', minval(flowdomsd(nn, level, sps)%uz), &
375  maxval(flowdomsd(nn, level, sps)%uz), &
376  norm2(flowdomsd(nn, level, sps)%uz)
377  write (*, *) 'vx ', minval(flowdomsd(nn, level, sps)%vx), &
378  maxval(flowdomsd(nn, level, sps)%vx), &
379  norm2(flowdomsd(nn, level, sps)%vx)
380  write (*, *) 'vy ', minval(flowdomsd(nn, level, sps)%vy), &
381  maxval(flowdomsd(nn, level, sps)%vy), &
382  norm2(flowdomsd(nn, level, sps)%vy)
383  write (*, *) 'vz ', minval(flowdomsd(nn, level, sps)%vz), &
384  maxval(flowdomsd(nn, level, sps)%vz), &
385  norm2(flowdomsd(nn, level, sps)%vz)
386  write (*, *) 'wx ', minval(flowdomsd(nn, level, sps)%wx), &
387  maxval(flowdomsd(nn, level, sps)%wx), &
388  norm2(flowdomsd(nn, level, sps)%wx)
389  write (*, *) 'wy ', minval(flowdomsd(nn, level, sps)%wy), &
390  maxval(flowdomsd(nn, level, sps)%wy), &
391  norm2(flowdomsd(nn, level, sps)%wy)
392  write (*, *) 'wz ', minval(flowdomsd(nn, level, sps)%wz), &
393  maxval(flowdomsd(nn, level, sps)%wz), &
394  norm2(flowdomsd(nn, level, sps)%wz)
395  write (*, *) 'qx ', minval(flowdomsd(nn, level, sps)%qx), &
396  maxval(flowdomsd(nn, level, sps)%qx), &
397  norm2(flowdomsd(nn, level, sps)%qx)
398  write (*, *) 'qy ', minval(flowdomsd(nn, level, sps)%qy), &
399  maxval(flowdomsd(nn, level, sps)%qy), &
400  norm2(flowdomsd(nn, level, sps)%qy)
401  write (*, *) 'qz ', minval(flowdomsd(nn, level, sps)%qz), &
402  maxval(flowdomsd(nn, level, sps)%qz), &
403  norm2(flowdomsd(nn, level, sps)%qz)
404 
405  write (*, *) 'bmti1 ', minval(flowdomsd(nn, level, sps)%bmti1), &
406  maxval(flowdomsd(nn, level, sps)%bmti1), &
407  norm2(flowdomsd(nn, level, sps)%bmti1)
408  write (*, *) 'bmti2 ', minval(flowdomsd(nn, level, sps)%bmti2), &
409  maxval(flowdomsd(nn, level, sps)%bmti2), &
410  norm2(flowdomsd(nn, level, sps)%bmti2)
411  write (*, *) 'bmtj1 ', minval(flowdomsd(nn, level, sps)%bmtj1), &
412  maxval(flowdomsd(nn, level, sps)%bmtj1), &
413  norm2(flowdomsd(nn, level, sps)%bmtj1)
414  write (*, *) 'bmtj2 ', minval(flowdomsd(nn, level, sps)%bmtj2), &
415  maxval(flowdomsd(nn, level, sps)%bmtj2), &
416  norm2(flowdomsd(nn, level, sps)%bmtj2)
417  write (*, *) 'bmtk1 ', minval(flowdomsd(nn, level, sps)%bmtk1), &
418  maxval(flowdomsd(nn, level, sps)%bmtk1), &
419  norm2(flowdomsd(nn, level, sps)%bmtk1)
420  write (*, *) 'bmtk2 ', minval(flowdomsd(nn, level, sps)%bmtk2), &
421  maxval(flowdomsd(nn, level, sps)%bmtk2), &
422  norm2(flowdomsd(nn, level, sps)%bmtk2)
423  write (*, *) 'bvti1 ', minval(flowdomsd(nn, level, sps)%bvti1), &
424  maxval(flowdomsd(nn, level, sps)%bvti1), &
425  norm2(flowdomsd(nn, level, sps)%bvti1)
426  write (*, *) 'bvti2 ', minval(flowdomsd(nn, level, sps)%bvti2), &
427  maxval(flowdomsd(nn, level, sps)%bvti2), &
428  norm2(flowdomsd(nn, level, sps)%bvti2)
429  write (*, *) 'bvtj1 ', minval(flowdomsd(nn, level, sps)%bvtj1), &
430  maxval(flowdomsd(nn, level, sps)%bvtj1), &
431  norm2(flowdomsd(nn, level, sps)%bvtj1)
432  write (*, *) 'bvtj2 ', minval(flowdomsd(nn, level, sps)%bvtj2), &
433  maxval(flowdomsd(nn, level, sps)%bvtj2), &
434  norm2(flowdomsd(nn, level, sps)%bvtj2)
435  write (*, *) 'bvtk1 ', minval(flowdomsd(nn, level, sps)%bvtk1), &
436  maxval(flowdomsd(nn, level, sps)%bvtk1), &
437  norm2(flowdomsd(nn, level, sps)%bvtk1)
438  write (*, *) 'bvtk2 ', minval(flowdomsd(nn, level, sps)%bvtk2), &
439  maxval(flowdomsd(nn, level, sps)%bvtk2), &
440  norm2(flowdomsd(nn, level, sps)%bvtk2)
441 
442  bocoloop: do mm = 1, flowdoms(nn, level, sps)%nBocos
443  write (*, *) 'mm', mm, 'BCData(mm)%norm', minval(flowdomsd(nn, level, sps)%BCData(mm)%norm), &
444  maxval(flowdomsd(nn, level, sps)%BCData(mm)%norm), &
445  norm2(flowdomsd(nn, level, sps)%BCData(mm)%norm)
446  write (*, *) 'mm', mm, 'bcData(mm)%rface ', minval(flowdomsd(nn, level, sps)%bcData(mm)%rface), &
447  maxval(flowdomsd(nn, level, sps)%bcData(mm)%rface), &
448  norm2(flowdomsd(nn, level, sps)%bcData(mm)%rface)
449  write (*, *) 'mm', mm, 'bcData(mm)%Fv ', minval(flowdomsd(nn, level, sps)%bcData(mm)%Fv), &
450  maxval(flowdomsd(nn, level, sps)%bcData(mm)%Fv), &
451  norm2(flowdomsd(nn, level, sps)%bcData(mm)%Fv)
452  write (*, *) 'mm', mm, 'bcData(mm)%Fp ', minval(flowdomsd(nn, level, sps)%bcData(mm)%Fp), &
453  maxval(flowdomsd(nn, level, sps)%bcData(mm)%Fp), &
454  norm2(flowdomsd(nn, level, sps)%bcData(mm)%Fp)
455  write (*, *) 'mm', mm, 'bcData(mm)%Tv ', minval(flowdomsd(nn, level, sps)%bcData(mm)%Tv), &
456  maxval(flowdomsd(nn, level, sps)%bcData(mm)%Tv), &
457  norm2(flowdomsd(nn, level, sps)%bcData(mm)%Tv)
458  write (*, *) 'mm', mm, 'bcData(mm)%Tp ', minval(flowdomsd(nn, level, sps)%bcData(mm)%Tp), &
459  maxval(flowdomsd(nn, level, sps)%bcData(mm)%Tp), &
460  norm2(flowdomsd(nn, level, sps)%bcData(mm)%Tp)
461  write (*, *) 'mm', mm, 'bcData(mm)%area ', minval(flowdomsd(nn, level, sps)%bcData(mm)%area), &
462  maxval(flowdomsd(nn, level, sps)%bcData(mm)%area), &
463  norm2(flowdomsd(nn, level, sps)%bcData(mm)%area)
464  write (*, *) 'mm', mm, 'BCData(mm)%uSlip ', minval(flowdomsd(nn, level, sps)%BCData(mm)%uSlip), &
465  maxval(flowdomsd(nn, level, sps)%BCData(mm)%uSlip), &
466  norm2(flowdomsd(nn, level, sps)%BCData(mm)%uSlip)
467  write (*, *) 'mm', mm, 'BCData(mm)%TNS_Wall ', minval(flowdomsd(nn, level, sps)%BCData(mm)%TNS_Wall), &
468  maxval(flowdomsd(nn, level, sps)%BCData(mm)%TNS_Wall), &
469  norm2(flowdomsd(nn, level, sps)%BCData(mm)%TNS_Wall)
470  write (*, *) 'mm', mm, 'BCData(mm)%ptInlet ', minval(flowdomsd(nn, level, sps)%BCData(mm)%ptInlet), &
471  maxval(flowdomsd(nn, level, sps)%BCData(mm)%ptInlet), &
472  norm2(flowdomsd(nn, level, sps)%BCData(mm)%ptInlet)
473  write (*, *) 'mm', mm, 'BCData(mm)%htInlet ', minval(flowdomsd(nn, level, sps)%BCData(mm)%htInlet), &
474  maxval(flowdomsd(nn, level, sps)%BCData(mm)%htInlet), &
475  norm2(flowdomsd(nn, level, sps)%BCData(mm)%htInlet)
476  write (*, *) 'mm', mm, 'BCData(mm)%ttInlet ', minval(flowdomsd(nn, level, sps)%BCData(mm)%ttInlet), &
477  maxval(flowdomsd(nn, level, sps)%BCData(mm)%ttInlet), &
478  norm2(flowdomsd(nn, level, sps)%BCData(mm)%ttInlet)
479  write (*, *) 'mm', mm, 'BCData(mm)%turbInlet ', minval(flowdomsd(nn, level, sps)%BCData(mm)%turbInlet), &
480  maxval(flowdomsd(nn, level, sps)%BCData(mm)%turbInlet), &
481  norm2(flowdomsd(nn, level, sps)%BCData(mm)%turbInlet)
482  write (*, *) 'mm', mm, 'BCData(mm)%ps ', minval(flowdomsd(nn, level, sps)%BCData(mm)%ps), &
483  maxval(flowdomsd(nn, level, sps)%BCData(mm)%ps), &
484  norm2(flowdomsd(nn, level, sps)%BCData(mm)%ps)
485 
486  end do bocoloop
487 
488  viscbocoloop: do mm = 1, flowdoms(nn, level, sps)%nViscBocos
489  write (*, *) 'mm', mm, 'viscSubface(mm)%tau ', minval(flowdomsd(nn, level, sps)%viscSubface(mm)%tau), &
490  maxval(flowdomsd(nn, level, sps)%viscSubface(mm)%tau), &
491  norm2(flowdomsd(nn, level, sps)%viscSubface(mm)%tau)
492  write (*, *) 'mm', mm, 'viscSubface(mm)%q ', minval(flowdomsd(nn, level, sps)%viscSubface(mm)%q), &
493  maxval(flowdomsd(nn, level, sps)%viscSubface(mm)%q), &
494  norm2(flowdomsd(nn, level, sps)%viscSubface(mm)%q)
495  end do viscbocoloop
496 
497  ! For overset, the weights may be active in the comm structure. We
498  ! need to zero them before we can accumulate.
499  if (oversetpresent) then
500  ! Pointers to the overset comms to make it easier to read
501  sends: do i = 1, commpatternoverset(level, sps)%nProcSend
502  write (*, *) 'commPatternOverset(level, sps)%sendList(i)%interpd ', &
503  minval(commpatternoverset(level, sps)%sendList(i)%interpd), &
504  maxval(commpatternoverset(level, sps)%sendList(i)%interpd), &
505  norm2(commpatternoverset(level, sps)%sendList(i)%interpd)
506  end do sends
507  write (*, *) 'internalOverset(level, sps)%donorInterpd ', &
508  minval(internaloverset(level, sps)%donorInterpd), &
509  maxval(internaloverset(level, sps)%donorInterpd), &
510  norm2(internaloverset(level, sps)%donorInterpd)
511  end if
512 
513  write (*, *) 'alphad ', alphad
514  write (*, *) 'betad ', betad
515  write (*, *) 'machd ', machd
516  write (*, *) 'machGridd ', machgridd
517  write (*, *) 'machCoefd ', machcoefd
518  write (*, *) 'pinfdimd ', pinfdimd
519  write (*, *) 'tinfdimd ', tinfdimd
520  write (*, *) 'rhoinfdimd ', rhoinfdimd
521  write (*, *) 'rgasdimd ', rgasdimd
522  write (*, *) 'pointrefd ', pointrefd
523  write (*, *) 'prefd ', prefd
524  write (*, *) 'rhoRefd ', rhorefd
525  write (*, *) 'Trefd ', trefd
526  write (*, *) 'murefd ', murefd
527  write (*, *) 'urefd ', urefd
528  write (*, *) 'hrefd ', hrefd
529  write (*, *) 'timerefd ', timerefd
530  write (*, *) 'pinfd ', pinfd
531  write (*, *) 'pinfCorrd ', pinfcorrd
532  write (*, *) 'rhoinfd ', rhoinfd
533  write (*, *) 'uinfd ', uinfd
534  write (*, *) 'rgasd ', rgasd
535  write (*, *) 'muinfd ', muinfd
536  write (*, *) 'gammainfd ', gammainfd
537  write (*, *) 'winfd ', winfd
538  write (*, *) 'veldirfreestreamd ', veldirfreestreamd
539  write (*, *) 'liftdirectiond ', liftdirectiond
540  write (*, *) 'dragdirectiond ', dragdirectiond
541 
542  ! Zero all the reverse seeds in the dirichlet input arrays
543  do idom = 1, cgnsndom
544  do iboco = 1, cgnsdoms(idom)%nBocos
545  if (associated(cgnsdoms(idom)%bocoInfo(iboco)%dataSet)) then
546  do idata = 1, size(cgnsdoms(idom)%bocoInfo(iboco)%dataSet)
547  if (associated(cgnsdoms(idom)%bocoInfo(iboco)%dataSet(idata)%dirichletArrays)) then
548  do idirichlet = 1, size(cgnsdoms(idom)%bocoInfo(iboco)%dataSet(idata)%dirichletArrays)
549  write (*, *) idom, iboco, idata, idirichlet, 'dataArr(:) ' &
550  , cgnsdomsd(idom)%bocoInfo(iboco)%dataSet(idata)% &
551  dirichletarrays(idirichlet)%dataArr(:)
552  end do
553  end if
554  end do
555  end if
556  end do
557  end do
558 
559  ! And the reverse seeds in the actuator zones
560  do i = 1, nactuatorregions
561  write (*, *) 'actuatorRegionsd(i)%Force ', actuatorregionsd(i)%force
562  write (*, *) 'actuatorRegionsd(i)%Torque ', actuatorregionsd(i)%torque
563  end do
564 
565  end subroutine printadseeds
566 
567 #else
568 
569  subroutine computematrixfreeproductfwdcs(xvdot, extradot, wdot, bcDataValuesdot, &
570  useSpatial, useState, famLists, &
571  bcDataNames, bcDataValues, bcDataFamLists, bcVarsEmpty, &
572  dwdot, funcsDot, fDot, &
573  costSize, fSize, nTime, h_mag)
574 
575  ! This routine is used to debug master_d. It uses the forward seeds to set perturbations
576  ! and then computes the value of the derivatives using forward complex step
577 
578  use constants
579  use adjointvars
580  use blockpointers, only: ndom
587  use blockpointers, only: ndom, il, jl, kl, wd, x, w, dw, dwd, nbocos, nviscbocos
588 
590  use masterroutines, only: master
592  use flowvarrefstate, only: nw, nwf
593  use walldistancedata, only: xsurf, xsurfvec
594  use walldistance, only: updatexsurf
595 
596  implicit none
597 
598  ! Input Variables
599  complex(kind=realType), dimension(:), intent(in) :: xvdot
600  complex(kind=realType), dimension(:), intent(in) :: extradot
601  complex(kind=realType), dimension(:), intent(in) :: wdot
602 
603  logical, intent(in) :: useSpatial, useState
604  integer(kind=intType), dimension(:, :) :: famLists
605  integer(kind=intType) :: costSize, fSize, nTime
606 
607  character, dimension(:, :), intent(in) :: bcDataNames
608  real(kind=realtype), dimension(:), intent(inout) :: bcdatavalues, bcdatavaluesdot
609  integer(kind=intType), dimension(:, :) :: bcDataFamLists
610  logical, intent(in) :: BCVarsEmpty
611 
612  ! step parameters
613  real(kind=alwaysrealtype), intent(in) :: h_mag ! step size for step
614 
615  ! Ouput Variables
616  complex(kind=realType), dimension(size(wdot)), intent(out) :: dwDot
617  complex(kind=realType), dimension(costSize, size(famLists, 1)), intent(out) :: funcsDot
618  complex(kind=realType), dimension(3, fSize, nTime), intent(out) :: fDot
619 
620  ! Working Variables
621  integer(kind=intType) :: nn, sps, level
622  integer(kind=intType) :: ierr, mm, i, j, k, l, ii, jj, iRegion
623 
624  complex(kind=realType), dimension(costSize, size(famLists, 1)) :: funcs
625 
626  ! Input Arguments for master:
627  complex(kind=realType), dimension(costSize, size(famLists, 1)) :: funcValues
628 
629  ! Working Variables
630  complex(kind=realType), dimension(:, :, :), allocatable :: forces
631  complex(kind=realType) :: h ! step size for Finite Difference
632 
633  ! note that h_mag does not have to be complex
634  ! it is just the magnitude of the complex perturbation
635  h = cmplx(0, h_mag)
636 
637  fsize = size(fdot, 2)
638  allocate (forces(3, fsize, ntimeintervalsspectral))
639 
640  ! Need to trick the residual evalution to use coupled (mean flow and
641  ! turbulent) together.
642  level = 1
643  currentlevel = level
644  groundlevel = level
645 
646  ! Allocate the memory we need for derivatives if not done so
647  ! already. Note this isn't deallocated until the adflow is
648  ! destroyed.
649  if (.not. derivvarsallocated) then
650  call allocderivativevalues(level)
651  end if
652 
653  ! Zero all AD seesd.
654  do nn = 1, ndom
655  do sps = 1, ntimeintervalsspectral
656  call zeroadseeds(nn, level, sps)
657  end do
658  end do
659 
660  ! Set the extra seeds now do the extra ones. Note that we are assuming the
661  ! machNumber used for the coefficients follows the Mach number,
662  ! not the grid mach number.
663 
664  alpha = alpha + h * extradot(ialpha)
665  beta = beta + h * extradot(ibeta)
666  mach = mach + h * extradot(imach)
667  machcoef = machcoef + h * extradot(imach)
668  machgrid = machgrid + h * extradot(imachgrid)
669  pinfdim = pinfdim + h * extradot(ipressure)
670  rhoinfdim = rhoinfdim + h * extradot(idensity)
671  tinfdim = tinfdim + h * extradot(itemperature)
672  pointref(1) = pointref(1) + h * extradot(ipointrefx)
673  pointref(2) = pointref(2) + h * extradot(ipointrefy)
674  pointref(3) = pointref(3) + h * extradot(ipointrefz)
675  rgasdim = rgasdim + h * zero
676 
677  ! --------------------- apply the perturbations ----------------------------
678  ! Set the provided w and x seeds:
679  ii = 0
680  jj = 0
681  domainloop1: do nn = 1, ndom
682  spectalloop1: do sps = 1, ntimeintervalsspectral
683  call setpointers(nn, 1, sps)
684  do k = 1, kl
685  do j = 1, jl
686  do i = 1, il
687  do l = 1, 3
688  ii = ii + 1
689  x(i, j, k, l) = x(i, j, k, l) + xvdot(ii) * h
690  end do
691  end do
692  end do
693  end do
694  do k = 2, kl
695  do j = 2, jl
696  do i = 2, il
697  do l = 1, nw
698  jj = jj + 1
699  w(i, j, k, l) = w(i, j, k, l) + wdot(jj) * h
700  end do
701  end do
702  end do
703  end do
704  end do spectalloop1
705  end do domainloop1
706 
707  bcdatavalues = bcdatavalues + bcdatavaluesdot * h
708 
709  if (equations == ransequations) then
710  call updatexsurf(level)
711  end if
712 
713  ! ----------------------------- Run Master ---------------------------------
714  ! Run the super-dee-duper master rotuine
715  if (bcvarsempty) then
716  call master(usespatial, &
717  famlists, funcvalues, &
718  forces)
719  else
720  call master(usespatial, &
721  famlists, funcvalues, &
722  forces, &
723  bcdatanames, bcdatavalues, bcdatafamlists)
724  end if
725 
726  ! Copy out the residual derivative into the provided dwDot and remove the
727  ! perturbation
728  ii = 0
729  jj = 0
730  do nn = 1, ndom
731  do sps = 1, ntimeintervalsspectral
732  call setpointers_d(nn, 1, sps)
733  do k = 1, kl
734  do j = 1, jl
735  do i = 1, il
736  do l = 1, 3
737  ii = ii + 1
738  x(i, j, k, l) = x(i, j, k, l) - xvdot(ii) * h
739  end do
740  end do
741  end do
742  end do
743  do k = 2, kl
744  do j = 2, jl
745  do i = 2, il
746  do l = 1, nw
747  jj = jj + 1
748  w(i, j, k, l) = w(i, j, k, l) - wdot(jj) * h
749  dwd(i, j, k, l) = aimag(dw(i, j, k, l)) / aimag(h)
750  dwdot(jj) = dwd(i, j, k, l) ! copy values to output
751  end do
752  end do
753  end do
754  end do
755 
756  end do
757  end do
758 
759  alpha = alpha - h * extradot(ialpha)
760  beta = beta - h * extradot(ibeta)
761  mach = mach - h * extradot(imach)
762  machcoef = machcoef - h * extradot(imach)
763  machgrid = machgrid - h * extradot(imachgrid)
764  pinfdim = pinfdim - h * extradot(ipressure)
765  rhoinfdim = rhoinfdim - h * extradot(idensity)
766  tinfdim = tinfdim - h * extradot(itemperature)
767  pointref(1) = pointref(1) - h * extradot(ipointrefx)
768  pointref(2) = pointref(2) - h * extradot(ipointrefy)
769  pointref(3) = pointref(3) - h * extradot(ipointrefz)
770  rgasdim = rgasdim - h * zero
771 
772  bcdatavalues = bcdatavalues - bcdatavaluesdot * h
773  if (equations == ransequations) then
774  call updatexsurf(level)
775  end if
776 
777  fdot = aimag(forces) / aimag(h)
778  funcsdot = aimag(funcvalues) / aimag(h)
779 
780  end subroutine computematrixfreeproductfwdcs
781 
782 #endif
783 
784 end module adjointdebug
type(actuatorregiontype), dimension(nactuatorregionsmax), target actuatorregionsd
integer(kind=inttype) nactuatorregions
subroutine computematrixfreeproductfwdfd(xvdot, extradot, wdot, bcDataValuesdot, useSpatial, useState, famLists, bcDataNames, bcDataValues, bcDataFamLists, bcVarsEmpty, dwdot, funcsDot, fDot, costSize, fSize, nTime, h)
subroutine printadseeds(nn, level, sps)
subroutine computematrixfreeproductfwdcs(xvdot, extradot, wdot, bcDataValuesdot, useSpatial, useState, famLists, bcDataNames, bcDataValues, bcDataFamLists, bcVarsEmpty, dwdot, funcsDot, fDot, costSize, fSize, nTime, h_mag)
subroutine zeroadseeds(nn, level, sps)
subroutine allocderivativevalues(level)
integer(kind=inttype), parameter imach
Definition: ADjointVars.F90:10
integer(kind=inttype), parameter ipointrefy
Definition: ADjointVars.F90:19
integer(kind=inttype), parameter imachgrid
Definition: ADjointVars.F90:11
integer(kind=inttype), parameter ipointrefz
Definition: ADjointVars.F90:20
integer(kind=inttype), parameter ipointrefx
Definition: ADjointVars.F90:18
logical derivvarsallocated
Definition: ADjointVars.F90:41
integer(kind=inttype), parameter ibeta
Definition: ADjointVars.F90:9
integer(kind=inttype), parameter ipressure
Definition: ADjointVars.F90:21
integer(kind=inttype), parameter itemperature
Definition: ADjointVars.F90:22
integer(kind=inttype), parameter ialpha
Definition: ADjointVars.F90:8
integer(kind=inttype), parameter idensity
Definition: ADjointVars.F90:23
Definition: block.F90:1
type(blocktype), dimension(:, :, :), allocatable, target flowdomsd
Definition: block.F90:772
type(blocktype), dimension(:, :, :), allocatable, target flowdoms
Definition: block.F90:771
integer(kind=inttype) jl
real(kind=realtype), dimension(:, :, :, :), pointer wd
integer(kind=inttype) nviscbocos
real(kind=realtype), dimension(:, :, :, :), pointer w
integer(kind=inttype) nbocos
real(kind=realtype), dimension(:, :, :, :), pointer dw
real(kind=realtype), dimension(:, :, :, :), pointer x
real(kind=realtype), dimension(:, :, :, :), pointer dwd
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(kind=inttype), parameter ransequations
Definition: constants.F90:110
real(kind=realtype) rhoinfdim
real(kind=realtype), dimension(:), allocatable winfd
real(kind=realtype) rhoinfd
real(kind=realtype) muinfd
real(kind=realtype) pinfdim
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) tinfdim
real(kind=realtype) prefd
real(kind=realtype) tinfdimd
integer(kind=inttype) nwf
real(kind=realtype) gammainfd
real(kind=realtype) urefd
real(kind=realtype) rhoinfdimd
real(kind=realtype) pinfd
integer(kind=inttype) nw
real(kind=realtype) murefd
real(kind=realtype) rhorefd
real(kind=realtype) timerefd
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) pointref
Definition: inputParam.F90:602
real(kind=realtype), dimension(3) dragdirectiond
Definition: inputParam.F90:615
real(kind=realtype), dimension(3) pointrefd
Definition: inputParam.F90:616
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) beta
Definition: inputParam.F90:591
real(kind=realtype) machgrid
Definition: inputParam.F90:593
real(kind=realtype) rgasdimd
Definition: inputParam.F90:622
real(kind=realtype) machcoef
Definition: inputParam.F90:593
real(kind=realtype) machcoefd
Definition: inputParam.F90:618
real(kind=realtype) mach
Definition: inputParam.F90:593
real(kind=realtype) rgasdim
Definition: inputParam.F90:595
real(kind=realtype) alpha
Definition: inputParam.F90:591
integer(kind=inttype) ntimeintervalsspectral
Definition: inputParam.F90:645
integer(kind=inttype) currentlevel
Definition: iteration.f90:18
integer(kind=inttype) groundlevel
Definition: iteration.f90:18
subroutine master(useSpatial, famLists, funcValues, forces, bcDataNames, bcDataValues, bcDataFamLists)
logical oversetpresent
Definition: overset.F90:373
Definition: utils.F90:1
logical function iswalltype(bType)
Definition: utils.F90:1705
subroutine setpointers_d(nn, level, sps)
Definition: utils.F90:3564
subroutine echk(errorcode, file, line)
Definition: utils.F90:5722
subroutine setpointers(nn, mm, ll)
Definition: utils.F90:3237
subroutine updatexsurf(level)
real(kind=realtype), dimension(:), pointer xsurf