ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
residuals_fast_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 !
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_fast_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: *w *dw
339 ! with respect to varying inputs: *w *dw
340 ! rw status of diff variables: *w:incr *dw:in-out
341 ! plus diff mem management of: w:in dw:in
342  subroutine sourceterms_block_fast_b(nn, res, iregion, plocal)
343 ! apply the source terms for the given block. assume that the
344 ! block pointers are already set.
345  use constants
347  use blockpointers, only : vol, dw, dwd, w, wd
348  use flowvarrefstate, only : pref, uref, lref
349  use communication
350  use iteration, only : ordersconverged
351  implicit none
352 ! input
353  integer(kind=inttype), intent(in) :: nn, iregion
354  logical, intent(in) :: res
355  real(kind=realtype), intent(inout) :: plocal
356 ! working
357  integer(kind=inttype) :: i, j, k, ii, istart, iend
358  real(kind=realtype) :: ftmp(3), vx, vy, vz, f_fact(3), q_fact, qtmp&
359 & , redim, factor, ostart, oend
360  real(kind=realtype) :: vxd, vyd, vzd
361  integer :: branch
362 ! compute the relaxation factor based on the ordersconverged
363 ! how far we are into the ramp:
364  if (ordersconverged .lt. actuatorregions(iregion)%relaxstart) then
365 myintptr = myintptr + 1
366  myintstack(myintptr) = 0
367  factor = zero
368  else if (ordersconverged .gt. actuatorregions(iregion)%relaxend) &
369 & then
370 myintptr = myintptr + 1
371  myintstack(myintptr) = 1
372  factor = one
373  else
374 myintptr = myintptr + 1
375  myintstack(myintptr) = 1
376 ! in between
377  ostart = actuatorregions(iregion)%relaxstart
378  oend = actuatorregions(iregion)%relaxend
379  factor = (ordersconverged-ostart)/(oend-ostart)
380  end if
381 ! compute the constant force factor
382  f_fact = factor*actuatorregions(iregion)%force/actuatorregions(&
383 & iregion)%volume/pref
384 ! heat factor. this is heat added per unit volume per unit time
385 ! loop over the ranges for this block
386  istart = actuatorregions(iregion)%blkptr(nn-1) + 1
387  iend = actuatorregions(iregion)%blkptr(nn)
388 !$bwd-of ii-loop
389  do ii=istart,iend
390 ! extract the cell id.
391  i = actuatorregions(iregion)%cellids(1, ii)
392  j = actuatorregions(iregion)%cellids(2, ii)
393  k = actuatorregions(iregion)%cellids(3, ii)
394 ! this actually gets the force
395  ftmp = vol(i, j, k)*f_fact
396 ! this gets the heat addition rate
397  if (res) then
398  vxd = -(ftmp(1)*dwd(i, j, k, irhoe))
399  vyd = -(ftmp(2)*dwd(i, j, k, irhoe))
400  vzd = -(ftmp(3)*dwd(i, j, k, irhoe))
401  else
402  vxd = 0.0_8
403  vyd = 0.0_8
404  vzd = 0.0_8
405  end if
406  wd(i, j, k, ivz) = wd(i, j, k, ivz) + vzd
407  wd(i, j, k, ivy) = wd(i, j, k, ivy) + vyd
408  wd(i, j, k, ivx) = wd(i, j, k, ivx) + vxd
409  end do
410 branch = myintstack(myintptr)
411  myintptr = myintptr - 1
412  end subroutine sourceterms_block_fast_b
413 
414  subroutine sourceterms_block(nn, res, iregion, plocal)
415 ! apply the source terms for the given block. assume that the
416 ! block pointers are already set.
417  use constants
419  use blockpointers, only : vol, dw, w
420  use flowvarrefstate, only : pref, uref, lref
421  use communication
422  use iteration, only : ordersconverged
423  implicit none
424 ! input
425  integer(kind=inttype), intent(in) :: nn, iregion
426  logical, intent(in) :: res
427  real(kind=realtype), intent(inout) :: plocal
428 ! working
429  integer(kind=inttype) :: i, j, k, ii, istart, iend
430  real(kind=realtype) :: ftmp(3), vx, vy, vz, f_fact(3), q_fact, qtmp&
431 & , redim, factor, ostart, oend
432  redim = pref*uref
433 ! compute the relaxation factor based on the ordersconverged
434 ! how far we are into the ramp:
435  if (ordersconverged .lt. actuatorregions(iregion)%relaxstart) then
436  factor = zero
437  else if (ordersconverged .gt. actuatorregions(iregion)%relaxend) &
438 & then
439  factor = one
440  else
441 ! in between
442  ostart = actuatorregions(iregion)%relaxstart
443  oend = actuatorregions(iregion)%relaxend
444  factor = (ordersconverged-ostart)/(oend-ostart)
445  end if
446 ! compute the constant force factor
447  f_fact = factor*actuatorregions(iregion)%force/actuatorregions(&
448 & iregion)%volume/pref
449 ! heat factor. this is heat added per unit volume per unit time
450  q_fact = factor*actuatorregions(iregion)%heat/actuatorregions(&
451 & iregion)%volume/(pref*uref*lref*lref)
452 ! loop over the ranges for this block
453  istart = actuatorregions(iregion)%blkptr(nn-1) + 1
454  iend = actuatorregions(iregion)%blkptr(nn)
455 !$ad ii-loop
456  do ii=istart,iend
457 ! extract the cell id.
458  i = actuatorregions(iregion)%cellids(1, ii)
459  j = actuatorregions(iregion)%cellids(2, ii)
460  k = actuatorregions(iregion)%cellids(3, ii)
461 ! this actually gets the force
462  ftmp = vol(i, j, k)*f_fact
463  vx = w(i, j, k, ivx)
464  vy = w(i, j, k, ivy)
465  vz = w(i, j, k, ivz)
466 ! this gets the heat addition rate
467  qtmp = vol(i, j, k)*q_fact
468  if (res) then
469 ! momentum residuals
470  dw(i, j, k, imx:imz) = dw(i, j, k, imx:imz) - ftmp
471 ! energy residuals
472  dw(i, j, k, irhoe) = dw(i, j, k, irhoe) - ftmp(1)*vx - ftmp(2)*&
473 & vy - ftmp(3)*vz - qtmp
474  else
475 ! add in the local power contribution:
476  plocal = plocal + (vx*ftmp(1)+vy*ftmp(2)+vz*ftmp(3))*redim
477  end if
478  end do
479  end subroutine sourceterms_block
480 
481 ! differentiation of initres_block in reverse (adjoint) mode (with options noisize i4 dr8 r8):
482 ! gradient of useful results: *dw
483 ! with respect to varying inputs: *dw
484 ! rw status of diff variables: *dw:in-out
485 ! plus diff mem management of: dw:in
486  subroutine initres_block_fast_b(varstart, varend, nn, sps)
487 !
488 ! initres initializes the given range of the residual. either to
489 ! zero, steady computation, or to an unsteady term for the time
490 ! spectral and unsteady modes. for the coarser grid levels the
491 ! residual forcing term is taken into account.
492 !
493  use blockpointers
494  use flowvarrefstate
495  use inputiteration
496  use inputphysics
498  use inputunsteady
499  use iteration
500  implicit none
501 !
502 ! subroutine arguments.
503 !
504  integer(kind=inttype), intent(in) :: varstart, varend, nn, sps
505 !
506 ! local variables.
507 !
508  integer(kind=inttype) :: mm, ll, ii, jj, i, j, k, l, m
509  real(kind=realtype) :: oneoverdt, tmp
510  real(kind=realtype), dimension(:, :, :, :), pointer :: ww, wsp, wsp1
511  real(kind=realtype), dimension(:, :, :), pointer :: volsp
512  integer :: branch
513 ! return immediately of no variables are in the range.
514  if (varend .ge. varstart) then
515 ! determine the equation mode and act accordingly.
516  select case (equationmode)
517  case (steady)
518 ! steady state computation.
519 ! determine the currently active multigrid level.
520  if (currentlevel .eq. groundlevel) then
521  call pushcontrol2b(1)
522  else
523  call pushcontrol2b(0)
524  end if
525  case default
526  call pushcontrol2b(2)
527  end select
528  do l=varend,varstart,-1
529  do j=jl,2,-1
530  do i=il,2,-1
531  dwd(i, j, kb, l) = 0.0_8
532  dwd(i, j, ke, l) = 0.0_8
533  dwd(i, j, 1, l) = 0.0_8
534  dwd(i, j, 0, l) = 0.0_8
535  end do
536  end do
537  do k=kb,0,-1
538  do i=il,2,-1
539  dwd(i, jb, k, l) = 0.0_8
540  dwd(i, je, k, l) = 0.0_8
541  dwd(i, 1, k, l) = 0.0_8
542  dwd(i, 0, k, l) = 0.0_8
543  end do
544  end do
545  do k=kb,0,-1
546  do j=jb,0,-1
547  dwd(ib, j, k, l) = 0.0_8
548  dwd(ie, j, k, l) = 0.0_8
549  dwd(1, j, k, l) = 0.0_8
550  dwd(0, j, k, l) = 0.0_8
551  end do
552  end do
553  end do
554  call popcontrol2b(branch)
555  if (branch .eq. 0) then
556  do l=varend,varstart,-1
557  do k=kl,2,-1
558  do j=jl,2,-1
559  do i=il,2,-1
560  dwd(i, j, k, l) = 0.0_8
561  end do
562  end do
563  end do
564  end do
565  else if (branch .eq. 1) then
566  do l=varend,varstart,-1
567  do k=kl,2,-1
568  do j=jl,2,-1
569  do i=il,2,-1
570  dwd(i, j, k, l) = 0.0_8
571  end do
572  end do
573  end do
574  end do
575  end if
576  end if
577  end subroutine initres_block_fast_b
578 
579  subroutine initres_block(varstart, varend, nn, sps)
580 !
581 ! initres initializes the given range of the residual. either to
582 ! zero, steady computation, or to an unsteady term for the time
583 ! spectral and unsteady modes. for the coarser grid levels the
584 ! residual forcing term is taken into account.
585 !
586  use blockpointers
587  use flowvarrefstate
588  use inputiteration
589  use inputphysics
591  use inputunsteady
592  use iteration
593  implicit none
594 !
595 ! subroutine arguments.
596 !
597  integer(kind=inttype), intent(in) :: varstart, varend, nn, sps
598 !
599 ! local variables.
600 !
601  integer(kind=inttype) :: mm, ll, ii, jj, i, j, k, l, m
602  real(kind=realtype) :: oneoverdt, tmp
603  real(kind=realtype), dimension(:, :, :, :), pointer :: ww, wsp, wsp1
604  real(kind=realtype), dimension(:, :, :), pointer :: volsp
605 ! return immediately of no variables are in the range.
606  if (varend .lt. varstart) then
607  return
608  else
609 ! determine the equation mode and act accordingly.
610  select case (equationmode)
611  case (steady)
612 ! steady state computation.
613 ! determine the currently active multigrid level.
614  if (currentlevel .eq. groundlevel) then
615 ! ground level of the multigrid cycle. initialize the
616 ! owned residuals to zero.
617  do l=varstart,varend
618  do k=2,kl
619  do j=2,jl
620  do i=2,il
621  dw(i, j, k, l) = zero
622  end do
623  end do
624  end do
625  end do
626  else
627 ! coarse grid level. initialize the owned cells to the
628 ! residual forcing terms.
629  do l=varstart,varend
630  do k=2,kl
631  do j=2,jl
632  do i=2,il
633  dw(i, j, k, l) = wr(i, j, k, l)
634  end do
635  end do
636  end do
637  end do
638  end if
639  end select
640 ! set the residual in the halo cells to zero. this is just
641 ! to avoid possible problems. their values do not matter.
642  do l=varstart,varend
643  do k=0,kb
644  do j=0,jb
645  dw(0, j, k, l) = zero
646  dw(1, j, k, l) = zero
647  dw(ie, j, k, l) = zero
648  dw(ib, j, k, l) = zero
649  end do
650  end do
651  do k=0,kb
652  do i=2,il
653  dw(i, 0, k, l) = zero
654  dw(i, 1, k, l) = zero
655  dw(i, je, k, l) = zero
656  dw(i, jb, k, l) = zero
657  end do
658  end do
659  do j=2,jl
660  do i=2,il
661  dw(i, j, 0, l) = zero
662  dw(i, j, 1, l) = zero
663  dw(i, j, ke, l) = zero
664  dw(i, j, kb, l) = zero
665  end do
666  end do
667  end do
668  end if
669  end subroutine initres_block
670 ! ----------------------------------------------------------------------
671 ! |
672 ! no tapenade routine below this line |
673 ! |
674 ! ----------------------------------------------------------------------
675 
676 end module residuals_fast_b
677 
type(actuatorregiontype), dimension(nactuatorregionsmax), target actuatorregions
real(kind=realtype), dimension(:, :, :), pointer gamma
integer(kind=inttype) jl
real(kind=realtype), dimension(:, :, :, :), pointer wd
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(kind=inttype), dimension(32) myintstack
Definition: constants.F90:299
integer, parameter irhoe
Definition: constants.F90:38
integer(kind=inttype) myintptr
Definition: constants.F90:300
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 allnodalgradients()
subroutine computespeedofsoundsquared()
real(kind=realtype) uref
integer(kind=inttype) nwf
real(kind=realtype), dimension(:), allocatable winf
real(kind=realtype) lref
real(kind=realtype) pref
subroutine invisciddissfluxscalar()
subroutine inviscidcentralflux()
subroutine viscousfluxapprox()
subroutine invisciddissfluxscalarapprox()
subroutine invisciddissfluxmatrix()
subroutine inviscidupwindflux(finegrid)
subroutine invisciddissfluxmatrixapprox()
subroutine viscousflux()
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_fast_b(varstart, varend, nn, sps)
subroutine sourceterms_block(nn, res, iregion, plocal)
subroutine sourceterms_block_fast_b(nn, res, iregion, plocal)
subroutine initres_block(varstart, varend, nn, sps)
subroutine residual_block()