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