ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
residuals_b.f90
Go to the documentation of this file.
1 ! generated by tapenade (inria, ecuador team)
2 ! tapenade 3.16 (develop) - 22 aug 2023 15:51
3 !
4 module residuals_b
5  implicit none
6 
7 contains
8  subroutine residual_block()
9 !
10 ! residual computes the residual of the mean flow equations on
11 ! the current mg level.
12 !
13  use blockpointers
14  use cgnsgrid
15  use flowvarrefstate
16  use inputiteration
19 ! added by hdn
20  use inputunsteady
21  use iteration
22  use inputadjoint
25  use fluxes_b
26  implicit none
27 !
28 ! local variables.
29 !
30  integer(kind=inttype) :: discr
31  integer(kind=inttype) :: i, j, k, l
32 ! for loops of ale
33  integer(kind=inttype) :: iale, jale, kale, lale, male
34  real(kind=realtype), parameter :: k1=1.05_realtype
35 ! the line below is only used for the low-speed preconditioner part of this routine
36 ! random given number
37  real(kind=realtype), parameter :: k2=0.6_realtype
38 ! mach number preconditioner activation
39  real(kind=realtype), parameter :: m0=0.2_realtype
40  real(kind=realtype), parameter :: alpha=0_realtype
41  real(kind=realtype), parameter :: delta=0_realtype
42 !real(kind=realtype), parameter :: hinf = 2_realtype ! test phase
43 ! test phase
44  real(kind=realtype), parameter :: cpres=4.18_realtype
45  real(kind=realtype), parameter :: temp=297.15_realtype
46 !
47 ! local variables
48 !
49  real(kind=realtype) :: k3, h, velxrho, velyrho, velzrho, sos, hinf
50  real(kind=realtype) :: resm, a11, a12, a13, a14, a15, a21, a22, a23&
51 & , a24, a25, a31, a32, a33, a34, a35
52  real(kind=realtype) :: a41, a42, a43, a44, a45, a51, a52, a53, a54, &
53 & a55, b11, b12, b13, b14, b15
54  real(kind=realtype) :: b21, b22, b23, b24, b25, b31, b32, b33, b34, &
55 & b35
56  real(kind=realtype) :: b41, b42, b43, b44, b45, b51, b52, b53, b54, &
57 & b55
58  real(kind=realtype) :: rhohdash, betamr2
59  real(kind=realtype) :: g, q
60  real(kind=realtype) :: b1, b2, b3, b4, b5
61  real(kind=realtype) :: dwo(nwf)
62  logical :: finegrid
63  intrinsic abs
64  intrinsic sqrt
65  intrinsic max
66  intrinsic min
67  intrinsic real
68  real(kind=realtype) :: x1
69  real(realtype) :: x2
70  real(realtype) :: x3
71  real(kind=realtype) :: abs0
72  real(realtype) :: max1
73  real(realtype) :: max2
74 ! set the value of rfil, which controls the fraction of the old
75 ! dissipation residual to be used. this is only for the runge-kutta
76 ! schemes; for other smoothers rfil is simply set to 1.0.
77 ! note the index rkstage+1 for cdisrk. the reason is that the
78 ! residual computation is performed before rkstage is incremented.
79  if (smoother .eq. rungekutta) then
80  rfil = cdisrk(rkstage+1)
81  else
82  rfil = one
83  end if
84 ! set the value of the discretization, depending on the grid level,
85 ! and the logical finegrid, which indicates whether or not this
86 ! is the finest grid level of the current mg cycle.
87  discr = spacediscrcoarse
88  if (currentlevel .eq. 1) discr = spacediscr
89  finegrid = .false.
90  if (currentlevel .eq. groundlevel) finegrid = .true.
91 ! ===========================================================
92 !
93 ! assuming ale has nothing to do with mg
94 ! the geometric data will be interpolated if in md mode
95 !
96 ! ===========================================================
97 ! ===========================================================
98 !
99 ! the fluxes are calculated as usual
100 !
101 ! ===========================================================
102  call inviscidcentralflux()
103  select case (discr)
104  case (dissscalar)
105 ! standard scalar dissipation scheme.
106  if (finegrid) then
107  if (.not.lumpeddiss) then
109  else
111  end if
112  end if
113  case (dissmatrix)
114 !===========================================================
115 ! matrix dissipation scheme.
116  if (finegrid) then
117  if (.not.lumpeddiss) then
119  else
121  end if
122  end if
123  case (upwind)
124 !===========================================================
125 ! dissipation via an upwind scheme.
126  call inviscidupwindflux(finegrid)
127  end select
128 !-------------------------------------------------------
129 ! lastly, recover the old s[i,j,k], sface[i,j,k]
130 ! this shall be done before difussive and source terms
131 ! are computed.
132 !-------------------------------------------------------
133  if (viscous) then
134  if (rfil .ge. 0.) then
135  abs0 = rfil
136  else
137  abs0 = -rfil
138  end if
139 ! only compute viscous fluxes if rfil > 0
140  if (abs0 .gt. thresholdreal) then
141 ! not lumpeddiss means it isn't the pc...call the vicousflux
142  if (.not.lumpeddiss) then
144  call allnodalgradients()
145  call viscousflux()
146  else
147 ! this is a pc calc...only include viscous fluxes if viscpc
148 ! is used
149 ! if full visc is true, also need full viscous terms, even if
150 ! lumpeddiss is true
152  if (viscpc) then
153  call allnodalgradients()
154  call viscousflux()
155  else
156  call viscousfluxapprox()
157  end if
158  end if
159  end if
160  end if
161 !===========================================================
162 ! add the dissipative and possibly viscous fluxes to the
163 ! euler fluxes. loop over the owned cells and add fw to dw.
164 ! also multiply by iblank so that no updates occur in holes
165  if (lowspeedpreconditioner) then
166  do k=2,kl
167  do j=2,jl
168  do i=2,il
169 ! compute speed of sound
170  sos = sqrt(gamma(i, j, k)*p(i, j, k)/w(i, j, k, irho))
171 ! compute velocities without rho from state vector
172 ! (w is pointer.. see type blocktype setup in block.f90)
173 ! w(0:ib,0:jb,0:kb,1:nw) is allocated in block.f90
174 ! these are per definition nw=[rho,u,v,w,rhoee]
175 ! so the velocity is simply just taken out below...
176 ! we do not have to divide with rho since it is already
177 ! without rho...
178 ! ivx: l. 60 in constants.f90
179  velxrho = w(i, j, k, ivx)
180  velyrho = w(i, j, k, ivy)
181  velzrho = w(i, j, k, ivz)
182  q = velxrho**2 + velyrho**2 + velzrho**2
183  resm = sqrt(q)/sos
184 ! resm above is used as m_a (thesis) and m (paper 2015)
185 ! and is the free stream mach number
186 ! see routine setup above:
187 ! l. 30: real(kind=realtype), parameter :: k1 = 1.05_realtype
188 ! random given number for k2:
189 ! l. 31: real(kind=realtype), parameter :: k2 = 0.6_realtype
190 ! mach number preconditioner activation for k3:
191 ! l. 32: real(kind=realtype), parameter :: m0 = 0.2_realtype
192 !
193 ! compute k3
194 ! eq. 2.7 in garg 2015. k1, m0 and resm are scalars
195 !
196 ! unfortunately, garg has switched the k1 and k3 here in the
197 ! code. in both paper and thesis it is k3 that is used to det-
198 ! ermine k1 below
199 !
200 ! compute k3
201  k3 = k1*(1+(1-k1*m0**2)*resm**2/(k1*m0**4))
202  if (k3*(velxrho**2+velyrho**2+velzrho**2) .lt. k2*(winf(ivx)&
203 & **2+winf(ivy)**2+winf(ivz)**2)) then
204  x1 = k2*(winf(ivx)**2+winf(ivy)**2+winf(ivz)**2)
205  else
206  x1 = k3*(velxrho**2+velyrho**2+velzrho**2)
207  end if
208  if (x1 .gt. sos**2) then
209  betamr2 = sos**2
210  else
211  betamr2 = x1
212  end if
213 ! above, the winf is the free stream velocity
214 !
215 ! should this first line's first element have sos^4 or sos^2
216  a11 = betamr2*(1/sos**4)
217  a12 = zero
218  a13 = zero
219  a14 = zero
220  a15 = (-betamr2)/sos**4
221  a21 = one*velxrho/sos**2
222  a22 = one*w(i, j, k, irho)
223  a23 = zero
224  a24 = zero
225  a25 = one*(-velxrho)/sos**2
226  a31 = one*velyrho/sos**2
227  a32 = zero
228  a33 = one*w(i, j, k, irho)
229  a34 = zero
230  a35 = one*(-velyrho)/sos**2
231  a41 = one*velzrho/sos**2
232  a42 = zero
233  a43 = zero
234  a44 = one*w(i, j, k, irho)
235  a45 = zero + one*(-velzrho)/sos**2
236 ! mham: seems he fixed the above line an irregular way?
237  a51 = one*(1/(gamma(i, j, k)-1)+resm**2/2)
238  a52 = one*w(i, j, k, irho)*velxrho
239  a53 = one*w(i, j, k, irho)*velyrho
240  a54 = one*w(i, j, k, irho)*velzrho
241  a55 = one*((-(resm**2))/2)
242  b11 = a11*(gamma(i, j, k)-1)*q/2 + a12*(-velxrho)/w(i, j, k&
243 & , irho) + a13*(-velyrho)/w(i, j, k, irho) + a14*(-velzrho)&
244 & /w(i, j, k, irho) + a15*((gamma(i, j, k)-1)*q/2-sos**2)
245  b12 = a11*(1-gamma(i, j, k))*velxrho + a12*1/w(i, j, k, irho&
246 & ) + a15*(1-gamma(i, j, k))*velxrho
247  b13 = a11*(1-gamma(i, j, k))*velyrho + a13/w(i, j, k, irho) &
248 & + a15*(1-gamma(i, j, k))*velyrho
249  b14 = a11*(1-gamma(i, j, k))*velzrho + a14/w(i, j, k, irho) &
250 & + a15*(1-gamma(i, j, k))*velzrho
251  b15 = a11*(gamma(i, j, k)-1) + a15*(gamma(i, j, k)-1)
252  b21 = a21*(gamma(i, j, k)-1)*q/2 + a22*(-velxrho)/w(i, j, k&
253 & , irho) + a23*(-velyrho)/w(i, j, k, irho) + a24*(-velzrho)&
254 & /w(i, j, k, irho) + a25*((gamma(i, j, k)-1)*q/2-sos**2)
255  b22 = a21*(1-gamma(i, j, k))*velxrho + a22/w(i, j, k, irho) &
256 & + a25*(1-gamma(i, j, k))*velxrho
257  b23 = a21*(1-gamma(i, j, k))*velyrho + a23*1/w(i, j, k, irho&
258 & ) + a25*(1-gamma(i, j, k))*velyrho
259  b24 = a21*(1-gamma(i, j, k))*velzrho + a24*1/w(i, j, k, irho&
260 & ) + a25*(1-gamma(i, j, k))*velzrho
261  b25 = a21*(gamma(i, j, k)-1) + a25*(gamma(i, j, k)-1)
262  b31 = a31*(gamma(i, j, k)-1)*q/2 + a32*(-velxrho)/w(i, j, k&
263 & , irho) + a33*(-velyrho)/w(i, j, k, irho) + a34*(-velzrho)&
264 & /w(i, j, k, irho) + a35*((gamma(i, j, k)-1)*q/2-sos**2)
265  b32 = a31*(1-gamma(i, j, k))*velxrho + a32/w(i, j, k, irho) &
266 & + a35*(1-gamma(i, j, k))*velxrho
267  b33 = a31*(1-gamma(i, j, k))*velyrho + a33*1/w(i, j, k, irho&
268 & ) + a35*(1-gamma(i, j, k))*velyrho
269  b34 = a31*(1-gamma(i, j, k))*velzrho + a34*1/w(i, j, k, irho&
270 & ) + a35*(1-gamma(i, j, k))*velzrho
271  b35 = a31*(gamma(i, j, k)-1) + a35*(gamma(i, j, k)-1)
272  b41 = a41*(gamma(i, j, k)-1)*q/2 + a42*(-velxrho)/w(i, j, k&
273 & , irho) + a43*(-velyrho)/w(i, j, k, irho) + a44*(-velzrho)&
274 & /w(i, j, k, irho) + a45*((gamma(i, j, k)-1)*q/2-sos**2)
275  b42 = a41*(1-gamma(i, j, k))*velxrho + a42/w(i, j, k, irho) &
276 & + a45*(1-gamma(i, j, k))*velxrho
277  b43 = a41*(1-gamma(i, j, k))*velyrho + a43*1/w(i, j, k, irho&
278 & ) + a45*(1-gamma(i, j, k))*velyrho
279  b44 = a41*(1-gamma(i, j, k))*velzrho + a44*1/w(i, j, k, irho&
280 & ) + a45*(1-gamma(i, j, k))*velzrho
281  b45 = a41*(gamma(i, j, k)-1) + a45*(gamma(i, j, k)-1)
282  b51 = a51*(gamma(i, j, k)-1)*q/2 + a52*(-velxrho)/w(i, j, k&
283 & , irho) + a53*(-velyrho)/w(i, j, k, irho) + a54*(-velzrho)&
284 & /w(i, j, k, irho) + a55*((gamma(i, j, k)-1)*q/2-sos**2)
285  b52 = a51*(1-gamma(i, j, k))*velxrho + a52/w(i, j, k, irho) &
286 & + a55*(1-gamma(i, j, k))*velxrho
287  b53 = a51*(1-gamma(i, j, k))*velyrho + a53*1/w(i, j, k, irho&
288 & ) + a55*(1-gamma(i, j, k))*velyrho
289  b54 = a51*(1-gamma(i, j, k))*velzrho + a54*1/w(i, j, k, irho&
290 & ) + a55*(1-gamma(i, j, k))*velzrho
291  b55 = a51*(gamma(i, j, k)-1) + a55*(gamma(i, j, k)-1)
292 ! dwo is the orginal redisual
293  do l=1,nwf
294  x2 = real(iblank(i, j, k), realtype)
295  if (x2 .lt. zero) then
296  max1 = zero
297  else
298  max1 = x2
299  end if
300  dwo(l) = (dw(i, j, k, l)+fw(i, j, k, l))*max1
301  end do
302  dw(i, j, k, 1) = b11*dwo(1) + b12*dwo(2) + b13*dwo(3) + b14*&
303 & dwo(4) + b15*dwo(5)
304  dw(i, j, k, 2) = b21*dwo(1) + b22*dwo(2) + b23*dwo(3) + b24*&
305 & dwo(4) + b25*dwo(5)
306  dw(i, j, k, 3) = b31*dwo(1) + b32*dwo(2) + b33*dwo(3) + b34*&
307 & dwo(4) + b35*dwo(5)
308  dw(i, j, k, 4) = b41*dwo(1) + b42*dwo(2) + b43*dwo(3) + b44*&
309 & dwo(4) + b45*dwo(5)
310  dw(i, j, k, 5) = b51*dwo(1) + b52*dwo(2) + b53*dwo(3) + b54*&
311 & dwo(4) + b55*dwo(5)
312  end do
313  end do
314 ! end of lowspeedpreconditioners three cells loops
315 
316  end do
317  else
318 ! else.. i.e. if we do not have preconditioner turned on...
319  do l=1,nwf
320  do k=2,kl
321  do j=2,jl
322  do i=2,il
323  x3 = real(iblank(i, j, k), realtype)
324  if (x3 .lt. zero) then
325  max2 = zero
326  else
327  max2 = x3
328  end if
329  dw(i, j, k, l) = (dw(i, j, k, l)+fw(i, j, k, l))*max2
330  end do
331  end do
332  end do
333  end do
334  end if
335  end subroutine residual_block
336 
337 ! differentiation of sourceterms_block in reverse (adjoint) mode (with options noisize i4 dr8 r8):
338 ! gradient of useful results: uref pref *w *dw *vol actuatorregions.force
339 ! actuatorregions.heat actuatorregions.volume plocal
340 ! with respect to varying inputs: uref pref *w *dw *vol actuatorregions.force
341 ! actuatorregions.heat actuatorregions.volume plocal
342 ! rw status of diff variables: uref:incr pref:incr *w:incr *dw:in-out
343 ! *vol:incr actuatorregions.force:incr actuatorregions.heat:incr
344 ! actuatorregions.volume:incr plocal:in-out
345 ! plus diff mem management of: w:in dw:in vol:in
346  subroutine sourceterms_block_b(nn, res, iregion, plocal, plocald)
347 ! apply the source terms for the given block. assume that the
348 ! block pointers are already set.
349  use constants
351  use blockpointers, only : vol, vold, dw, dwd, w, wd
352  use flowvarrefstate, only : pref, prefd, uref, urefd, lref
353  use communication
354  use iteration, only : ordersconverged
355  implicit none
356 ! input
357  integer(kind=inttype), intent(in) :: nn, iregion
358  logical, intent(in) :: res
359  real(kind=realtype), intent(inout) :: plocal
360  real(kind=realtype), intent(inout) :: plocald
361 ! working
362  integer(kind=inttype) :: i, j, k, ii, istart, iend
363  real(kind=realtype) :: ftmp(3), vx, vy, vz, f_fact(3), q_fact, qtmp&
364 & , redim, factor, ostart, oend
365  real(kind=realtype) :: ftmpd(3), vxd, vyd, vzd, f_factd(3), q_factd&
366 & , qtmpd, redimd
367  real(kind=realtype), dimension(3) :: tempd
368  real(kind=realtype) :: temp
369  real(kind=realtype) :: tempd0
370  real(kind=realtype) :: temp0
371  real(kind=realtype) :: tempd1
372  real(kind=realtype) :: tempd2
373  integer :: branch
374  redim = pref*uref
375 ! compute the relaxation factor based on the ordersconverged
376 ! how far we are into the ramp:
377  if (ordersconverged .lt. actuatorregions(iregion)%relaxstart) then
378  call pushcontrol1b(0)
379  factor = zero
380  else if (ordersconverged .gt. actuatorregions(iregion)%relaxend) &
381 & then
382  call pushcontrol1b(1)
383  factor = one
384  else
385  call pushcontrol1b(1)
386 ! in between
387  ostart = actuatorregions(iregion)%relaxstart
388  oend = actuatorregions(iregion)%relaxend
389  factor = (ordersconverged-ostart)/(oend-ostart)
390  end if
391 ! compute the constant force factor
392  f_fact = factor*actuatorregions(iregion)%force/actuatorregions(&
393 & iregion)%volume/pref
394 ! heat factor. this is heat added per unit volume per unit time
395  q_fact = factor*actuatorregions(iregion)%heat/actuatorregions(&
396 & iregion)%volume/(pref*uref*lref*lref)
397 ! loop over the ranges for this block
398  istart = actuatorregions(iregion)%blkptr(nn-1) + 1
399  iend = actuatorregions(iregion)%blkptr(nn)
400  q_factd = 0.0_8
401  redimd = 0.0_8
402  f_factd = 0.0_8
403 !$bwd-of ii-loop
404  do ii=istart,iend
405 ! extract the cell id.
406  i = actuatorregions(iregion)%cellids(1, ii)
407  j = actuatorregions(iregion)%cellids(2, ii)
408  k = actuatorregions(iregion)%cellids(3, ii)
409 ! this actually gets the force
410  ftmp = vol(i, j, k)*f_fact
411  vx = w(i, j, k, ivx)
412  vy = w(i, j, k, ivy)
413  vz = w(i, j, k, ivz)
414 ! this gets the heat addition rate
415  if (res) then
416  ftmpd = 0.0_8
417  ftmpd(1) = ftmpd(1) - vx*dwd(i, j, k, irhoe)
418  vxd = -(ftmp(1)*dwd(i, j, k, irhoe))
419  ftmpd(2) = ftmpd(2) - vy*dwd(i, j, k, irhoe)
420  vyd = -(ftmp(2)*dwd(i, j, k, irhoe))
421  ftmpd(3) = ftmpd(3) - vz*dwd(i, j, k, irhoe)
422  vzd = -(ftmp(3)*dwd(i, j, k, irhoe))
423  qtmpd = -dwd(i, j, k, irhoe)
424  ftmpd = ftmpd - dwd(i, j, k, imx:imz)
425  else
426  ftmpd = 0.0_8
427  tempd1 = redim*plocald
428  redimd = redimd + (vx*ftmp(1)+vy*ftmp(2)+vz*ftmp(3))*plocald
429  vxd = ftmp(1)*tempd1
430  ftmpd(1) = ftmpd(1) + vx*tempd1
431  vyd = ftmp(2)*tempd1
432  ftmpd(2) = ftmpd(2) + vy*tempd1
433  vzd = ftmp(3)*tempd1
434  ftmpd(3) = ftmpd(3) + vz*tempd1
435  qtmpd = 0.0_8
436  end if
437  vold(i, j, k) = vold(i, j, k) + q_fact*qtmpd + sum(f_fact*ftmpd)
438  q_factd = q_factd + vol(i, j, k)*qtmpd
439  wd(i, j, k, ivz) = wd(i, j, k, ivz) + vzd
440  wd(i, j, k, ivy) = wd(i, j, k, ivy) + vyd
441  wd(i, j, k, ivx) = wd(i, j, k, ivx) + vxd
442  f_factd = f_factd + vol(i, j, k)*ftmpd
443  end do
444  tempd = factor*f_factd/(actuatorregions(iregion)%volume*pref)
445  tempd0 = -(sum(actuatorregions(iregion)%force*tempd)/(&
446 & actuatorregions(iregion)%volume*pref))
447  temp = lref*lref*actuatorregions(iregion)%volume
448  temp0 = temp*pref*uref
449  tempd1 = factor*q_factd/temp0
450  actuatorregionsd(iregion)%heat = actuatorregionsd(iregion)%heat + &
451 & tempd1
452  tempd2 = -(actuatorregions(iregion)%heat*tempd1/temp0)
453  actuatorregionsd(iregion)%volume = actuatorregionsd(iregion)%volume &
454 & + lref**2*pref*uref*tempd2 + pref*tempd0
455  prefd = prefd + uref*temp*tempd2 + actuatorregions(iregion)%volume*&
456 & tempd0
457  urefd = urefd + pref*temp*tempd2
458  actuatorregionsd(iregion)%force = actuatorregionsd(iregion)%force + &
459 & tempd
460  call popcontrol1b(branch)
461  prefd = prefd + uref*redimd
462  urefd = urefd + pref*redimd
463  end subroutine sourceterms_block_b
464 
465  subroutine sourceterms_block(nn, res, iregion, plocal)
466 ! apply the source terms for the given block. assume that the
467 ! block pointers are already set.
468  use constants
470  use blockpointers, only : vol, dw, w
471  use flowvarrefstate, only : pref, uref, lref
472  use communication
473  use iteration, only : ordersconverged
474  implicit none
475 ! input
476  integer(kind=inttype), intent(in) :: nn, iregion
477  logical, intent(in) :: res
478  real(kind=realtype), intent(inout) :: plocal
479 ! working
480  integer(kind=inttype) :: i, j, k, ii, istart, iend
481  real(kind=realtype) :: ftmp(3), vx, vy, vz, f_fact(3), q_fact, qtmp&
482 & , redim, factor, ostart, oend
483  redim = pref*uref
484 ! compute the relaxation factor based on the ordersconverged
485 ! how far we are into the ramp:
486  if (ordersconverged .lt. actuatorregions(iregion)%relaxstart) then
487  factor = zero
488  else if (ordersconverged .gt. actuatorregions(iregion)%relaxend) &
489 & then
490  factor = one
491  else
492 ! in between
493  ostart = actuatorregions(iregion)%relaxstart
494  oend = actuatorregions(iregion)%relaxend
495  factor = (ordersconverged-ostart)/(oend-ostart)
496  end if
497 ! compute the constant force factor
498  f_fact = factor*actuatorregions(iregion)%force/actuatorregions(&
499 & iregion)%volume/pref
500 ! heat factor. this is heat added per unit volume per unit time
501  q_fact = factor*actuatorregions(iregion)%heat/actuatorregions(&
502 & iregion)%volume/(pref*uref*lref*lref)
503 ! loop over the ranges for this block
504  istart = actuatorregions(iregion)%blkptr(nn-1) + 1
505  iend = actuatorregions(iregion)%blkptr(nn)
506 !$ad ii-loop
507  do ii=istart,iend
508 ! extract the cell id.
509  i = actuatorregions(iregion)%cellids(1, ii)
510  j = actuatorregions(iregion)%cellids(2, ii)
511  k = actuatorregions(iregion)%cellids(3, ii)
512 ! this actually gets the force
513  ftmp = vol(i, j, k)*f_fact
514  vx = w(i, j, k, ivx)
515  vy = w(i, j, k, ivy)
516  vz = w(i, j, k, ivz)
517 ! this gets the heat addition rate
518  qtmp = vol(i, j, k)*q_fact
519  if (res) then
520 ! momentum residuals
521  dw(i, j, k, imx:imz) = dw(i, j, k, imx:imz) - ftmp
522 ! energy residuals
523  dw(i, j, k, irhoe) = dw(i, j, k, irhoe) - ftmp(1)*vx - ftmp(2)*&
524 & vy - ftmp(3)*vz - qtmp
525  else
526 ! add in the local power contribution:
527  plocal = plocal + (vx*ftmp(1)+vy*ftmp(2)+vz*ftmp(3))*redim
528  end if
529  end do
530  end subroutine sourceterms_block
531 
532 ! differentiation of initres_block in reverse (adjoint) mode (with options noisize i4 dr8 r8):
533 ! gradient of useful results: *dw
534 ! with respect to varying inputs: *dw
535 ! rw status of diff variables: *dw:in-out
536 ! plus diff mem management of: dw:in
537  subroutine initres_block_b(varstart, varend, nn, sps)
538 !
539 ! initres initializes the given range of the residual. either to
540 ! zero, steady computation, or to an unsteady term for the time
541 ! spectral and unsteady modes. for the coarser grid levels the
542 ! residual forcing term is taken into account.
543 !
544  use blockpointers
545  use flowvarrefstate
546  use inputiteration
547  use inputphysics
549  use inputunsteady
550  use iteration
551  implicit none
552 !
553 ! subroutine arguments.
554 !
555  integer(kind=inttype), intent(in) :: varstart, varend, nn, sps
556 !
557 ! local variables.
558 !
559  integer(kind=inttype) :: mm, ll, ii, jj, i, j, k, l, m
560  real(kind=realtype) :: oneoverdt, tmp
561  real(kind=realtype), dimension(:, :, :, :), pointer :: ww, wsp, wsp1
562  real(kind=realtype), dimension(:, :, :), pointer :: volsp
563  integer :: branch
564 ! return immediately of no variables are in the range.
565  if (varend .ge. varstart) then
566 ! determine the equation mode and act accordingly.
567  select case (equationmode)
568  case (steady)
569 ! steady state computation.
570 ! determine the currently active multigrid level.
571  if (currentlevel .eq. groundlevel) then
572  call pushcontrol2b(1)
573  else
574  call pushcontrol2b(0)
575  end if
576  case default
577  call pushcontrol2b(2)
578  end select
579  do l=varend,varstart,-1
580  do j=jl,2,-1
581  do i=il,2,-1
582  dwd(i, j, kb, l) = 0.0_8
583  dwd(i, j, ke, l) = 0.0_8
584  dwd(i, j, 1, l) = 0.0_8
585  dwd(i, j, 0, l) = 0.0_8
586  end do
587  end do
588  do k=kb,0,-1
589  do i=il,2,-1
590  dwd(i, jb, k, l) = 0.0_8
591  dwd(i, je, k, l) = 0.0_8
592  dwd(i, 1, k, l) = 0.0_8
593  dwd(i, 0, k, l) = 0.0_8
594  end do
595  end do
596  do k=kb,0,-1
597  do j=jb,0,-1
598  dwd(ib, j, k, l) = 0.0_8
599  dwd(ie, j, k, l) = 0.0_8
600  dwd(1, j, k, l) = 0.0_8
601  dwd(0, j, k, l) = 0.0_8
602  end do
603  end do
604  end do
605  call popcontrol2b(branch)
606  if (branch .eq. 0) then
607  do l=varend,varstart,-1
608  do k=kl,2,-1
609  do j=jl,2,-1
610  do i=il,2,-1
611  dwd(i, j, k, l) = 0.0_8
612  end do
613  end do
614  end do
615  end do
616  else if (branch .eq. 1) then
617  do l=varend,varstart,-1
618  do k=kl,2,-1
619  do j=jl,2,-1
620  do i=il,2,-1
621  dwd(i, j, k, l) = 0.0_8
622  end do
623  end do
624  end do
625  end do
626  end if
627  end if
628  end subroutine initres_block_b
629 
630  subroutine initres_block(varstart, varend, nn, sps)
631 !
632 ! initres initializes the given range of the residual. either to
633 ! zero, steady computation, or to an unsteady term for the time
634 ! spectral and unsteady modes. for the coarser grid levels the
635 ! residual forcing term is taken into account.
636 !
637  use blockpointers
638  use flowvarrefstate
639  use inputiteration
640  use inputphysics
642  use inputunsteady
643  use iteration
644  implicit none
645 !
646 ! subroutine arguments.
647 !
648  integer(kind=inttype), intent(in) :: varstart, varend, nn, sps
649 !
650 ! local variables.
651 !
652  integer(kind=inttype) :: mm, ll, ii, jj, i, j, k, l, m
653  real(kind=realtype) :: oneoverdt, tmp
654  real(kind=realtype), dimension(:, :, :, :), pointer :: ww, wsp, wsp1
655  real(kind=realtype), dimension(:, :, :), pointer :: volsp
656 ! return immediately of no variables are in the range.
657  if (varend .lt. varstart) then
658  return
659  else
660 ! determine the equation mode and act accordingly.
661  select case (equationmode)
662  case (steady)
663 ! steady state computation.
664 ! determine the currently active multigrid level.
665  if (currentlevel .eq. groundlevel) then
666 ! ground level of the multigrid cycle. initialize the
667 ! owned residuals to zero.
668  do l=varstart,varend
669  do k=2,kl
670  do j=2,jl
671  do i=2,il
672  dw(i, j, k, l) = zero
673  end do
674  end do
675  end do
676  end do
677  else
678 ! coarse grid level. initialize the owned cells to the
679 ! residual forcing terms.
680  do l=varstart,varend
681  do k=2,kl
682  do j=2,jl
683  do i=2,il
684  dw(i, j, k, l) = wr(i, j, k, l)
685  end do
686  end do
687  end do
688  end do
689  end if
690  end select
691 ! set the residual in the halo cells to zero. this is just
692 ! to avoid possible problems. their values do not matter.
693  do l=varstart,varend
694  do k=0,kb
695  do j=0,jb
696  dw(0, j, k, l) = zero
697  dw(1, j, k, l) = zero
698  dw(ie, j, k, l) = zero
699  dw(ib, j, k, l) = zero
700  end do
701  end do
702  do k=0,kb
703  do i=2,il
704  dw(i, 0, k, l) = zero
705  dw(i, 1, k, l) = zero
706  dw(i, je, k, l) = zero
707  dw(i, jb, k, l) = zero
708  end do
709  end do
710  do j=2,jl
711  do i=2,il
712  dw(i, j, 0, l) = zero
713  dw(i, j, 1, l) = zero
714  dw(i, j, ke, l) = zero
715  dw(i, j, kb, l) = zero
716  end do
717  end do
718  end do
719  end if
720  end subroutine initres_block
721 ! ----------------------------------------------------------------------
722 ! |
723 ! no tapenade routine below this line |
724 ! |
725 ! ----------------------------------------------------------------------
726 
727 end module residuals_b
728 
type(actuatorregiontype), dimension(nactuatorregionsmax), target actuatorregions
type(actuatorregiontype), dimension(nactuatorregionsmax), target actuatorregionsd
real(kind=realtype), dimension(:, :, :), pointer gamma
integer(kind=inttype) jl
real(kind=realtype), dimension(:, :, :, :), pointer wd
real(kind=realtype), dimension(:, :, :), pointer vold
real(kind=realtype), dimension(:, :, :, :), pointer wr
real(kind=realtype), dimension(:, :, :), pointer p
integer(kind=inttype) ie
real(kind=realtype), dimension(:, :, :, :), pointer w
integer(kind=inttype), dimension(:, :, :), pointer iblank
integer(kind=inttype) jb
integer(kind=inttype) kb
real(kind=realtype), dimension(:, :, :, :), pointer dw
real(kind=realtype), dimension(:, :, :), pointer vol
integer(kind=inttype) ib
real(kind=realtype), dimension(:, :, :, :), pointer fw
integer(kind=inttype) je
integer(kind=inttype) ke
real(kind=realtype), dimension(:, :, :, :), pointer dwd
integer(kind=inttype) kl
integer(kind=inttype) il
real(kind=realtype), parameter zero
Definition: constants.F90:71
integer, parameter imx
Definition: constants.F90:65
integer, parameter ivx
Definition: constants.F90:35
integer, parameter irhoe
Definition: constants.F90:38
real(kind=realtype), parameter one
Definition: constants.F90:72
integer, parameter ivz
Definition: constants.F90:37
integer, parameter imz
Definition: constants.F90:67
integer, parameter ivy
Definition: constants.F90:36
subroutine computespeedofsoundsquared()
subroutine allnodalgradients()
real(kind=realtype) uref
real(kind=realtype) prefd
integer(kind=inttype) nwf
real(kind=realtype), dimension(:), allocatable winf
real(kind=realtype) urefd
real(kind=realtype) lref
real(kind=realtype) pref
subroutine viscousflux()
Definition: fluxes_b.f90:10267
subroutine inviscidcentralflux()
Definition: fluxes_b.f90:457
subroutine viscousfluxapprox()
Definition: fluxes_b.f90:11859
subroutine invisciddissfluxmatrixapprox()
Definition: fluxes_b.f90:15695
subroutine invisciddissfluxscalarapprox()
Definition: fluxes_b.f90:13351
subroutine invisciddissfluxmatrix()
Definition: fluxes_b.f90:2792
subroutine invisciddissfluxscalar()
Definition: fluxes_b.f90:4149
subroutine inviscidupwindflux(finegrid)
Definition: fluxes_b.f90:7342
logical viscpc
Definition: inputParam.F90:793
logical lowspeedpreconditioner
Definition: inputParam.F90:96
integer(kind=inttype) spacediscrcoarse
Definition: inputParam.F90:72
integer(kind=inttype) spacediscr
Definition: inputParam.F90:72
integer(kind=inttype) smoother
Definition: inputParam.F90:264
real(kind=realtype), dimension(:), allocatable cdisrk
Definition: inputParam.F90:283
integer(kind=inttype) equationmode
Definition: inputParam.F90:583
integer(kind=inttype) currentlevel
Definition: iteration.f90:18
integer(kind=inttype) groundlevel
Definition: iteration.f90:18
integer(kind=inttype) rkstage
Definition: iteration.f90:19
real(kind=realtype) rfil
Definition: iteration.f90:36
real(kind=realtype) ordersconverged
Definition: iteration.f90:128
subroutine initres_block_b(varstart, varend, nn, sps)
subroutine sourceterms_block_b(nn, res, iregion, plocal, plocald)
subroutine sourceterms_block(nn, res, iregion, plocal)
subroutine initres_block(varstart, varend, nn, sps)
subroutine residual_block()
Definition: residuals_b.f90:9