ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
solverUtils_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 ! differentiation of timestep_block in reverse (adjoint) mode (with options noisize i4 dr8 r8):
9 ! gradient of useful results: *p *w *radi *radj *radk
10 ! with respect to varying inputs: *p *w *radi *radj *radk
11 ! rw status of diff variables: *p:incr *w:incr *radi:in-out *radj:in-out
12 ! *radk:in-out
13 ! plus diff mem management of: p:in w:in radi:in radj:in radk:in
14  subroutine timestep_block_fast_b(onlyradii)
15 !
16 ! timestep computes the time step, or more precisely the time
17 ! step divided by the volume per unit cfl, in the owned cells.
18 ! however, for the artificial dissipation schemes, the spectral
19 ! radii in the halo's are needed. therefore the loop is taken
20 ! over the the first level of halo cells. the spectral radii are
21 ! stored and possibly modified for high aspect ratio cells.
22 !
23  use constants
24  use blockpointers, only : ie, je, ke, il, jl, kl, w, wd, p, &
25 & pd, rlv, rlvd, rev, revd, radi, radid, radj, radjd, radk, radkd, si,&
27 & sectionid
29 & viscous, rhoinf
32  use inputphysics, only : equationmode
34  use section, only : sections
36  use utils_fast_b, only : terminate
37  implicit none
38 !
39 ! subroutine argument.
40 !
41  logical, intent(in) :: onlyradii
42 !
43 ! local parameters.
44 !
45  real(kind=realtype), parameter :: b=2.0_realtype
46 !
47 ! local variables.
48 !
49  integer(kind=inttype) :: i, j, k, ii
50  real(kind=realtype) :: plim, rlim, clim2
51  real(kind=realtype) :: uux, uuy, uuz, cc2, qsi, qsj, qsk, sx, sy, sz&
52 & , rmu
53  real(kind=realtype) :: uuxd, uuyd, uuzd, cc2d, qsid, qsjd, qskd
54  real(kind=realtype) :: ri, rj, rk, rij, rjk, rki
55  real(kind=realtype) :: rid, rjd, rkd, rijd, rjkd, rkid
56  real(kind=realtype) :: vsi, vsj, vsk, rfl, dpi, dpj, dpk
57  real(kind=realtype) :: sface, tmp
58  logical :: radiineeded, doscaling
59  intrinsic mod
60  intrinsic max
61  intrinsic abs
62  intrinsic sqrt
63  real(kind=realtype) :: abs0
64  real(kind=realtype) :: abs0d
65  real(kind=realtype) :: abs1
66  real(kind=realtype) :: abs1d
67  real(kind=realtype) :: abs2
68  real(kind=realtype) :: abs2d
69  real(kind=realtype) :: abs3
70  real(kind=realtype) :: abs4
71  real(kind=realtype) :: abs5
72  real(kind=realtype) :: temp
73  real(kind=realtype) :: temp0
74  real(kind=realtype) :: tempd
75  integer :: branch
76 ! determine whether or not the spectral radii are needed for the
77 ! flux computation.
78  radiineeded = radiineededcoarse
79  if (currentlevel .le. groundlevel) radiineeded = radiineededfine
80 ! return immediately if only the spectral radii must be computed
81 ! and these are not needed for the flux computation.
82  if (.not.(onlyradii .and. (.not.radiineeded))) then
83 ! set the value of plim. to be fully consistent this must have
84 ! the dimension of a pressure. therefore a fraction of pinfcorr
85 ! is used. idem for rlim; compute clim2 as well.
86  clim2 = 0.000001_realtype*gammainf*pinfcorr/rhoinf
87  doscaling = dirscaling .and. currentlevel .le. groundlevel
88 ! initialize sface to zero. this value will be used if the
89 ! block is not moving.
90  sface = zero
91 !
92 ! inviscid contribution, depending on the preconditioner.
93 ! compute the cell centered values of the spectral radii.
94 !
95  select case (precond)
96  case (noprecond)
97 !$bwd-of ii-loop
98  do ii=0,ie*je*ke-1
99  i = mod(ii, ie) + 1
100  j = mod(ii/ie, je) + 1
101  k = ii/(ie*je) + 1
102 ! compute the velocities and speed of sound squared.
103  uux = w(i, j, k, ivx)
104  uuy = w(i, j, k, ivy)
105  uuz = w(i, j, k, ivz)
106  cc2 = gamma(i, j, k)*p(i, j, k)/w(i, j, k, irho)
107  if (cc2 .lt. clim2) then
108  cc2 = clim2
109 myintptr = myintptr + 1
110  myintstack(myintptr) = 0
111  else
112 myintptr = myintptr + 1
113  myintstack(myintptr) = 1
114  cc2 = cc2
115  end if
116 ! set the dot product of the grid velocity and the
117 ! normal in i-direction for a moving face. to avoid
118 ! a number of multiplications by 0.5 simply the sum
119 ! is taken.
120  if (addgridvelocities) sface = sfacei(i-1, j, k) + sfacei(i, j&
121 & , k)
122 ! spectral radius in i-direction.
123  sx = si(i-1, j, k, 1) + si(i, j, k, 1)
124  sy = si(i-1, j, k, 2) + si(i, j, k, 2)
125  sz = si(i-1, j, k, 3) + si(i, j, k, 3)
126  qsi = uux*sx + uuy*sy + uuz*sz - sface
127  if (qsi .ge. 0.) then
128  abs0 = qsi
129 myintptr = myintptr + 1
130  myintstack(myintptr) = 0
131  else
132  abs0 = -qsi
133 myintptr = myintptr + 1
134  myintstack(myintptr) = 1
135  end if
136  ri = half*(abs0+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz**&
137 & 2)))
138 ! the grid velocity in j-direction.
139  if (addgridvelocities) sface = sfacej(i, j-1, k) + sfacej(i, j&
140 & , k)
141 ! spectral radius in j-direction.
142  sx = sj(i, j-1, k, 1) + sj(i, j, k, 1)
143  sy = sj(i, j-1, k, 2) + sj(i, j, k, 2)
144  sz = sj(i, j-1, k, 3) + sj(i, j, k, 3)
145  qsj = uux*sx + uuy*sy + uuz*sz - sface
146  if (qsj .ge. 0.) then
147  abs1 = qsj
148 myintptr = myintptr + 1
149  myintstack(myintptr) = 0
150  else
151  abs1 = -qsj
152 myintptr = myintptr + 1
153  myintstack(myintptr) = 1
154  end if
155  rj = half*(abs1+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz**&
156 & 2)))
157 ! the grid velocity in k-direction.
158  if (addgridvelocities) sface = sfacek(i, j, k-1) + sfacek(i, j&
159 & , k)
160 ! spectral radius in k-direction.
161  sx = sk(i, j, k-1, 1) + sk(i, j, k, 1)
162  sy = sk(i, j, k-1, 2) + sk(i, j, k, 2)
163  sz = sk(i, j, k-1, 3) + sk(i, j, k, 3)
164  qsk = uux*sx + uuy*sy + uuz*sz - sface
165  if (qsk .ge. 0.) then
166  abs2 = qsk
167 myintptr = myintptr + 1
168  myintstack(myintptr) = 0
169  else
170  abs2 = -qsk
171 myintptr = myintptr + 1
172  myintstack(myintptr) = 1
173  end if
174  rk = half*(abs2+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz**&
175 & 2)))
176 ! compute the inviscid contribution to the time step.
177 !
178 ! adapt the spectral radii if directional scaling must be
179 ! applied.
180 !
181  if (doscaling) then
182  if (ri .lt. eps) then
183  ri = eps
184 myintptr = myintptr + 1
185  myintstack(myintptr) = 0
186  else
187 myintptr = myintptr + 1
188  myintstack(myintptr) = 1
189  ri = ri
190  end if
191  if (rj .lt. eps) then
192  rj = eps
193 myintptr = myintptr + 1
194  myintstack(myintptr) = 0
195  else
196 myintptr = myintptr + 1
197  myintstack(myintptr) = 1
198  rj = rj
199  end if
200  if (rk .lt. eps) then
201  rk = eps
202 myintptr = myintptr + 1
203  myintstack(myintptr) = 0
204  else
205 myintptr = myintptr + 1
206  myintstack(myintptr) = 1
207  rk = rk
208  end if
209 ! compute the scaling in the three coordinate
210 ! directions.
211  rij = (ri/rj)**adis
212  rjk = (rj/rk)**adis
213  rki = (rk/ri)**adis
214 ! create the scaled versions of the aspect ratios.
215 ! note that the multiplication is done with radi, radj
216 ! and radk, such that the influence of the clipping
217 ! is negligible.
218  rkid = ri*radid(i, j, k) - one*rk*radkd(i, j, k)/rki**2
219  temp0 = rk/ri
220  if (temp0 .le. 0.0_8 .and. (adis .eq. 0.0_8 .or. adis .ne. &
221 & int(adis))) then
222  tempd = 0.0_8
223  else
224  tempd = adis*temp0**(adis-1)*rkid/ri
225  end if
226  rkd = (one+one/rki+rjk)*radkd(i, j, k) + tempd
227  rjkd = rk*radkd(i, j, k) - one*rj*radjd(i, j, k)/rjk**2
228  radkd(i, j, k) = 0.0_8
229  rijd = rj*radjd(i, j, k) - one*ri*radid(i, j, k)/rij**2
230  rid = (one+one/rij+rki)*radid(i, j, k) - temp0*tempd
231  radid(i, j, k) = 0.0_8
232  temp0 = rj/rk
233  if (temp0 .le. 0.0_8 .and. (adis .eq. 0.0_8 .or. adis .ne. &
234 & int(adis))) then
235  tempd = 0.0_8
236  else
237  tempd = adis*temp0**(adis-1)*rjkd/rk
238  end if
239  rjd = (one+one/rjk+rij)*radjd(i, j, k) + tempd
240  radjd(i, j, k) = 0.0_8
241  rkd = rkd - temp0*tempd
242  temp0 = ri/rj
243  if (temp0 .le. 0.0_8 .and. (adis .eq. 0.0_8 .or. adis .ne. &
244 & int(adis))) then
245  tempd = 0.0_8
246  else
247  tempd = adis*temp0**(adis-1)*rijd/rj
248  end if
249  rid = rid + tempd
250  rjd = rjd - temp0*tempd
251 branch = myintstack(myintptr)
252  myintptr = myintptr - 1
253  if (branch .eq. 0) rkd = 0.0_8
254 branch = myintstack(myintptr)
255  myintptr = myintptr - 1
256  if (branch .eq. 0) rjd = 0.0_8
257 branch = myintstack(myintptr)
258  myintptr = myintptr - 1
259  if (branch .eq. 0) rid = 0.0_8
260  else
261  rkd = radkd(i, j, k)
262  radkd(i, j, k) = 0.0_8
263  rjd = radjd(i, j, k)
264  radjd(i, j, k) = 0.0_8
265  rid = radid(i, j, k)
266  radid(i, j, k) = 0.0_8
267  end if
268  temp0 = sx*sx + sy*sy + sz*sz
269  abs2d = half*rkd
270  if (temp0*cc2 .eq. 0.0_8) then
271  cc2d = 0.0_8
272  else
273  cc2d = temp0*acousticscalefactor*half*rkd/(2.0*sqrt(temp0*&
274 & cc2))
275  end if
276 branch = myintstack(myintptr)
277  myintptr = myintptr - 1
278  if (branch .eq. 0) then
279  qskd = abs2d
280  else
281  qskd = -abs2d
282  end if
283  uuxd = sx*qskd
284  uuyd = sy*qskd
285  uuzd = sz*qskd
286  sx = sj(i, j-1, k, 1) + sj(i, j, k, 1)
287  sy = sj(i, j-1, k, 2) + sj(i, j, k, 2)
288  sz = sj(i, j-1, k, 3) + sj(i, j, k, 3)
289  temp0 = sx*sx + sy*sy + sz*sz
290  abs1d = half*rjd
291  if (.not.temp0*cc2 .eq. 0.0_8) cc2d = cc2d + temp0*&
292 & acousticscalefactor*half*rjd/(2.0*sqrt(temp0*cc2))
293 branch = myintstack(myintptr)
294  myintptr = myintptr - 1
295  if (branch .eq. 0) then
296  qsjd = abs1d
297  else
298  qsjd = -abs1d
299  end if
300  uuxd = uuxd + sx*qsjd
301  uuyd = uuyd + sy*qsjd
302  uuzd = uuzd + sz*qsjd
303  sx = si(i-1, j, k, 1) + si(i, j, k, 1)
304  sy = si(i-1, j, k, 2) + si(i, j, k, 2)
305  sz = si(i-1, j, k, 3) + si(i, j, k, 3)
306  temp0 = sx*sx + sy*sy + sz*sz
307  abs0d = half*rid
308  if (.not.temp0*cc2 .eq. 0.0_8) cc2d = cc2d + temp0*&
309 & acousticscalefactor*half*rid/(2.0*sqrt(temp0*cc2))
310 branch = myintstack(myintptr)
311  myintptr = myintptr - 1
312  if (branch .eq. 0) then
313  qsid = abs0d
314  else
315  qsid = -abs0d
316  end if
317  uuxd = uuxd + sx*qsid
318  uuyd = uuyd + sy*qsid
319  uuzd = uuzd + sz*qsid
320 branch = myintstack(myintptr)
321  myintptr = myintptr - 1
322  if (branch .eq. 0) cc2d = 0.0_8
323  temp = w(i, j, k, irho)
324  tempd = gamma(i, j, k)*cc2d/temp
325  pd(i, j, k) = pd(i, j, k) + tempd
326  wd(i, j, k, irho) = wd(i, j, k, irho) - p(i, j, k)*tempd/temp
327  wd(i, j, k, ivz) = wd(i, j, k, ivz) + uuzd
328  wd(i, j, k, ivy) = wd(i, j, k, ivy) + uuyd
329  wd(i, j, k, ivx) = wd(i, j, k, ivx) + uuxd
330  end do
331  end select
332  end if
333  end subroutine timestep_block_fast_b
334 
335  subroutine timestep_block(onlyradii)
336 !
337 ! timestep computes the time step, or more precisely the time
338 ! step divided by the volume per unit cfl, in the owned cells.
339 ! however, for the artificial dissipation schemes, the spectral
340 ! radii in the halo's are needed. therefore the loop is taken
341 ! over the the first level of halo cells. the spectral radii are
342 ! stored and possibly modified for high aspect ratio cells.
343 !
344  use constants
345  use blockpointers, only : ie, je, ke, il, jl, kl, w, p, rlv, &
346 & rev, radi, radj, radk, si, sj, sk, sfacei, sfacej, sfacek, dtl, &
349 & viscous, rhoinf
352  use inputphysics, only : equationmode
353  use iteration, only : groundlevel, currentlevel
354  use section, only : sections
356  use utils_fast_b, only : terminate
357  implicit none
358 !
359 ! subroutine argument.
360 !
361  logical, intent(in) :: onlyradii
362 !
363 ! local parameters.
364 !
365  real(kind=realtype), parameter :: b=2.0_realtype
366 !
367 ! local variables.
368 !
369  integer(kind=inttype) :: i, j, k, ii
370  real(kind=realtype) :: plim, rlim, clim2
371  real(kind=realtype) :: uux, uuy, uuz, cc2, qsi, qsj, qsk, sx, sy, sz&
372 & , rmu
373  real(kind=realtype) :: ri, rj, rk, rij, rjk, rki
374  real(kind=realtype) :: vsi, vsj, vsk, rfl, dpi, dpj, dpk
375  real(kind=realtype) :: sface, tmp
376  logical :: radiineeded, doscaling
377  intrinsic mod
378  intrinsic max
379  intrinsic abs
380  intrinsic sqrt
381  real(kind=realtype) :: abs0
382  real(kind=realtype) :: abs1
383  real(kind=realtype) :: abs2
384  real(kind=realtype) :: abs3
385  real(kind=realtype) :: abs4
386  real(kind=realtype) :: abs5
387 ! determine whether or not the spectral radii are needed for the
388 ! flux computation.
389  radiineeded = radiineededcoarse
390  if (currentlevel .le. groundlevel) radiineeded = radiineededfine
391 ! return immediately if only the spectral radii must be computed
392 ! and these are not needed for the flux computation.
393  if (onlyradii .and. (.not.radiineeded)) then
394  return
395  else
396 ! set the value of plim. to be fully consistent this must have
397 ! the dimension of a pressure. therefore a fraction of pinfcorr
398 ! is used. idem for rlim; compute clim2 as well.
399  plim = 0.001_realtype*pinfcorr
400  rlim = 0.001_realtype*rhoinf
401  clim2 = 0.000001_realtype*gammainf*pinfcorr/rhoinf
402  doscaling = dirscaling .and. currentlevel .le. groundlevel
403 ! initialize sface to zero. this value will be used if the
404 ! block is not moving.
405  sface = zero
406 !
407 ! inviscid contribution, depending on the preconditioner.
408 ! compute the cell centered values of the spectral radii.
409 !
410  select case (precond)
411  case (noprecond)
412 !$ad ii-loop
413 ! no preconditioner. simply the standard spectral radius.
414 ! loop over the cells, including the first level halo.
415  do ii=0,ie*je*ke-1
416  i = mod(ii, ie) + 1
417  j = mod(ii/ie, je) + 1
418  k = ii/(ie*je) + 1
419 ! compute the velocities and speed of sound squared.
420  uux = w(i, j, k, ivx)
421  uuy = w(i, j, k, ivy)
422  uuz = w(i, j, k, ivz)
423  cc2 = gamma(i, j, k)*p(i, j, k)/w(i, j, k, irho)
424  if (cc2 .lt. clim2) then
425  cc2 = clim2
426  else
427  cc2 = cc2
428  end if
429 ! set the dot product of the grid velocity and the
430 ! normal in i-direction for a moving face. to avoid
431 ! a number of multiplications by 0.5 simply the sum
432 ! is taken.
433  if (addgridvelocities) sface = sfacei(i-1, j, k) + sfacei(i, j&
434 & , k)
435 ! spectral radius in i-direction.
436  sx = si(i-1, j, k, 1) + si(i, j, k, 1)
437  sy = si(i-1, j, k, 2) + si(i, j, k, 2)
438  sz = si(i-1, j, k, 3) + si(i, j, k, 3)
439  qsi = uux*sx + uuy*sy + uuz*sz - sface
440  if (qsi .ge. 0.) then
441  abs0 = qsi
442  else
443  abs0 = -qsi
444  end if
445  ri = half*(abs0+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz**&
446 & 2)))
447 ! the grid velocity in j-direction.
448  if (addgridvelocities) sface = sfacej(i, j-1, k) + sfacej(i, j&
449 & , k)
450 ! spectral radius in j-direction.
451  sx = sj(i, j-1, k, 1) + sj(i, j, k, 1)
452  sy = sj(i, j-1, k, 2) + sj(i, j, k, 2)
453  sz = sj(i, j-1, k, 3) + sj(i, j, k, 3)
454  qsj = uux*sx + uuy*sy + uuz*sz - sface
455  if (qsj .ge. 0.) then
456  abs1 = qsj
457  else
458  abs1 = -qsj
459  end if
460  rj = half*(abs1+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz**&
461 & 2)))
462 ! the grid velocity in k-direction.
463  if (addgridvelocities) sface = sfacek(i, j, k-1) + sfacek(i, j&
464 & , k)
465 ! spectral radius in k-direction.
466  sx = sk(i, j, k-1, 1) + sk(i, j, k, 1)
467  sy = sk(i, j, k-1, 2) + sk(i, j, k, 2)
468  sz = sk(i, j, k-1, 3) + sk(i, j, k, 3)
469  qsk = uux*sx + uuy*sy + uuz*sz - sface
470  if (qsk .ge. 0.) then
471  abs2 = qsk
472  else
473  abs2 = -qsk
474  end if
475  rk = half*(abs2+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz**&
476 & 2)))
477 ! compute the inviscid contribution to the time step.
478  if (.not.onlyradii) dtl(i, j, k) = ri + rj + rk
479 !
480 ! adapt the spectral radii if directional scaling must be
481 ! applied.
482 !
483  if (doscaling) then
484  if (ri .lt. eps) then
485  ri = eps
486  else
487  ri = ri
488  end if
489  if (rj .lt. eps) then
490  rj = eps
491  else
492  rj = rj
493  end if
494  if (rk .lt. eps) then
495  rk = eps
496  else
497  rk = rk
498  end if
499 ! compute the scaling in the three coordinate
500 ! directions.
501  rij = (ri/rj)**adis
502  rjk = (rj/rk)**adis
503  rki = (rk/ri)**adis
504 ! create the scaled versions of the aspect ratios.
505 ! note that the multiplication is done with radi, radj
506 ! and radk, such that the influence of the clipping
507 ! is negligible.
508  radi(i, j, k) = ri*(one+one/rij+rki)
509  radj(i, j, k) = rj*(one+one/rjk+rij)
510  radk(i, j, k) = rk*(one+one/rki+rjk)
511  else
512  radi(i, j, k) = ri
513  radj(i, j, k) = rj
514  radk(i, j, k) = rk
515  end if
516  end do
517  case (turkel)
518  call terminate('timestep', &
519 & 'turkel preconditioner not implemented yet')
520  case (choimerkle)
521  call terminate('timestep', &
522 & 'choi merkle preconditioner not implemented yet')
523  end select
524 ! the rest of this file can be skipped if only the spectral
525 ! radii need to be computed.
526  if (.not.onlyradii) then
527 ! the viscous contribution, if needed.
528  if (viscous) then
529 ! loop over the owned cell centers.
530  do k=2,kl
531  do j=2,jl
532  do i=2,il
533 ! compute the effective viscosity coefficient. the
534 ! factor 0.5 is a combination of two things. in the
535 ! standard central discretization of a second
536 ! derivative there is a factor 2 multiplying the
537 ! central node. however in the code below not the
538 ! average but the sum of the left and the right face
539 ! is taken and squared. this leads to a factor 4.
540 ! combining both effects leads to 0.5. furthermore,
541 ! it is divided by the volume and density to obtain
542 ! the correct dimensions and multiplied by the
543 ! non-dimensional factor factvis.
544  rmu = rlv(i, j, k)
545  if (eddymodel) rmu = rmu + rev(i, j, k)
546  rmu = half*rmu/(w(i, j, k, irho)*vol(i, j, k))
547 ! add the viscous contribution in i-direction to the
548 ! (inverse) of the time step.
549  sx = si(i, j, k, 1) + si(i-1, j, k, 1)
550  sy = si(i, j, k, 2) + si(i-1, j, k, 2)
551  sz = si(i, j, k, 3) + si(i-1, j, k, 3)
552  vsi = rmu*(sx*sx+sy*sy+sz*sz)
553  dtl(i, j, k) = dtl(i, j, k) + vsi
554 ! add the viscous contribution in j-direction to the
555 ! (inverse) of the time step.
556  sx = sj(i, j, k, 1) + sj(i, j-1, k, 1)
557  sy = sj(i, j, k, 2) + sj(i, j-1, k, 2)
558  sz = sj(i, j, k, 3) + sj(i, j-1, k, 3)
559  vsj = rmu*(sx*sx+sy*sy+sz*sz)
560  dtl(i, j, k) = dtl(i, j, k) + vsj
561 ! add the viscous contribution in k-direction to the
562 ! (inverse) of the time step.
563  sx = sk(i, j, k, 1) + sk(i, j, k-1, 1)
564  sy = sk(i, j, k, 2) + sk(i, j, k-1, 2)
565  sz = sk(i, j, k, 3) + sk(i, j, k-1, 3)
566  vsk = rmu*(sx*sx+sy*sy+sz*sz)
567  dtl(i, j, k) = dtl(i, j, k) + vsk
568  end do
569  end do
570  end do
571  end if
572 ! for the spectral mode an additional term term must be
573 ! taken into account, which corresponds to the contribution
574 ! of the highest frequency.
575  if (equationmode .eq. timespectral) then
577 & timeperiod
578 ! loop over the owned cell centers and add the term.
579  do k=2,kl
580  do j=2,jl
581  do i=2,il
582  dtl(i, j, k) = dtl(i, j, k) + tmp*vol(i, j, k)
583  end do
584  end do
585  end do
586  end if
587 ! currently the inverse of dt/vol is stored in dtl. invert
588 ! this value such that the time step per unit cfl number is
589 ! stored and correct in cases of high gradients.
590  do k=2,kl
591  do j=2,jl
592  do i=2,il
593  if (p(i+1, j, k) - two*p(i, j, k) + p(i-1, j, k) .ge. 0.) &
594 & then
595  abs3 = p(i+1, j, k) - two*p(i, j, k) + p(i-1, j, k)
596  else
597  abs3 = -(p(i+1, j, k)-two*p(i, j, k)+p(i-1, j, k))
598  end if
599  dpi = abs3/(p(i+1, j, k)+two*p(i, j, k)+p(i-1, j, k)+plim)
600  if (p(i, j+1, k) - two*p(i, j, k) + p(i, j-1, k) .ge. 0.) &
601 & then
602  abs4 = p(i, j+1, k) - two*p(i, j, k) + p(i, j-1, k)
603  else
604  abs4 = -(p(i, j+1, k)-two*p(i, j, k)+p(i, j-1, k))
605  end if
606  dpj = abs4/(p(i, j+1, k)+two*p(i, j, k)+p(i, j-1, k)+plim)
607  if (p(i, j, k+1) - two*p(i, j, k) + p(i, j, k-1) .ge. 0.) &
608 & then
609  abs5 = p(i, j, k+1) - two*p(i, j, k) + p(i, j, k-1)
610  else
611  abs5 = -(p(i, j, k+1)-two*p(i, j, k)+p(i, j, k-1))
612  end if
613  dpk = abs5/(p(i, j, k+1)+two*p(i, j, k)+p(i, j, k-1)+plim)
614  rfl = one/(one+b*(dpi+dpj+dpk))
615  dtl(i, j, k) = rfl/dtl(i, j, k)
616  end do
617  end do
618  end do
619  end if
620  end if
621  end subroutine timestep_block
622 
623  subroutine gridvelocitiesfinelevel_block(useoldcoor, t, sps, nn)
624 !
625 ! gridvelocitiesfinelevel computes the grid velocities for
626 ! the cell centers and the normal grid velocities for the faces
627 ! of moving blocks for the currently finest grid, i.e.
628 ! groundlevel. the velocities are computed at time t for
629 ! spectral mode sps. if useoldcoor is .true. the velocities
630 ! are determined using the unsteady time integrator in
631 ! combination with the old coordinates; otherwise the analytic
632 ! form is used.
633 !
634  use blockpointers
635  use cgnsgrid
636  use flowvarrefstate
637  use inputmotion
638  use inputunsteady
639  use iteration
640  use inputphysics
641  use inputtsstabderiv
642  use monitor
643  use communication
647  implicit none
648 !
649 ! subroutine arguments.
650 !
651  integer(kind=inttype), intent(in) :: sps, nn
652  logical, intent(in) :: useoldcoor
653  real(kind=realtype), dimension(*), intent(in) :: t
654 !
655 ! local variables.
656 !
657  integer(kind=inttype) :: mm
658  integer(kind=inttype) :: i, j, k, ii, iie, jje, kke
659  real(kind=realtype) :: oneover4dt, oneover8dt
660  real(kind=realtype) :: velxgrid, velygrid, velzgrid, ainf
661  real(kind=realtype) :: velxgrid0, velygrid0, velzgrid0
662  real(kind=realtype), dimension(3) :: sc, xc, xxc
663  real(kind=realtype), dimension(3) :: rotcenter, rotrate
664  real(kind=realtype), dimension(3) :: rotationpoint
665  real(kind=realtype), dimension(3, 3) :: rotationmatrix, &
666 & derivrotationmatrix
667  real(kind=realtype) :: tnew, told
668  real(kind=realtype), dimension(:, :), pointer :: sface
669  real(kind=realtype), dimension(:, :, :), pointer :: xx, ss
670  real(kind=realtype), dimension(:, :, :, :), pointer :: xxold
671  real(kind=realtype) :: intervalmach, alphats, alphaincrement, betats&
672 & , betaincrement
673  real(kind=realtype), dimension(3) :: veldir
674  real(kind=realtype), dimension(3) :: refdirection
675  intrinsic sqrt
676 ! compute the mesh velocity from the given mesh mach number.
677 ! vel{x,y,z}grid0 is the actual velocity you want at the
678 ! geometry.
679  ainf = sqrt(gammainf*pinf/rhoinf)
680  velxgrid0 = ainf*machgrid*(-veldirfreestream(1))
681  velygrid0 = ainf*machgrid*(-veldirfreestream(2))
682  velzgrid0 = ainf*machgrid*(-veldirfreestream(3))
683 ! compute the derivative of the rotation matrix and the rotation
684 ! point; needed for velocity due to the rigid body rotation of
685 ! the entire grid. it is assumed that the rigid body motion of
686 ! the grid is only specified if there is only 1 section present.
687  call derivativerotmatrixrigid(derivrotationmatrix, rotationpoint, t(&
688 & 1))
689 !compute the rotation matrix to update the velocities for the time
690 !spectral stability derivative case...
691  if (blockismoving) then
692 ! determine the situation we are having here.
693  if (.not.useoldcoor) then
694 !
695 ! the velocities must be determined analytically.
696 !
697 ! store the rotation center and determine the
698 ! nondimensional rotation rate of this block. as the
699 ! reference length is 1 timeref == 1/uref and at the end
700 ! the nondimensional velocity is computed.
701  j = nbkglobal
702  rotcenter = cgnsdoms(j)%rotcenter
703  rotrate = timeref*cgnsdoms(j)%rotrate
704  velxgrid = velxgrid0
705  velygrid = velygrid0
706  velzgrid = velzgrid0
707 !
708 ! grid velocities of the cell centers, including the
709 ! 1st level halo cells.
710 !
711 ! loop over the cells, including the 1st level halo's.
712  do k=1,ke
713  do j=1,je
714  do i=1,ie
715 ! determine the coordinates of the cell center,
716 ! which are stored in xc.
717  xc(1) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
718 & , k-1, 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
719 & 1)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 1)+&
720 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+flowdoms(&
721 & nn, groundlevel, sps)%x(i-1, j-1, k, 1)+flowdoms(nn, &
722 & groundlevel, sps)%x(i, j-1, k, 1)+flowdoms(nn, &
723 & groundlevel, sps)%x(i-1, j, k, 1)+flowdoms(nn, &
724 & groundlevel, sps)%x(i, j, k, 1))
725  xc(2) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
726 & , k-1, 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
727 & 2)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 2)+&
728 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+flowdoms(&
729 & nn, groundlevel, sps)%x(i-1, j-1, k, 2)+flowdoms(nn, &
730 & groundlevel, sps)%x(i, j-1, k, 2)+flowdoms(nn, &
731 & groundlevel, sps)%x(i-1, j, k, 2)+flowdoms(nn, &
732 & groundlevel, sps)%x(i, j, k, 2))
733  xc(3) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
734 & , k-1, 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
735 & 3)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 3)+&
736 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+flowdoms(&
737 & nn, groundlevel, sps)%x(i-1, j-1, k, 3)+flowdoms(nn, &
738 & groundlevel, sps)%x(i, j-1, k, 3)+flowdoms(nn, &
739 & groundlevel, sps)%x(i-1, j, k, 3)+flowdoms(nn, &
740 & groundlevel, sps)%x(i, j, k, 3))
741 ! determine the coordinates relative to the
742 ! center of rotation.
743  xxc(1) = xc(1) - rotcenter(1)
744  xxc(2) = xc(2) - rotcenter(2)
745  xxc(3) = xc(3) - rotcenter(3)
746 ! determine the rotation speed of the cell center,
747 ! which is omega*r.
748  sc(1) = rotrate(2)*xxc(3) - rotrate(3)*xxc(2)
749  sc(2) = rotrate(3)*xxc(1) - rotrate(1)*xxc(3)
750  sc(3) = rotrate(1)*xxc(2) - rotrate(2)*xxc(1)
751 ! determine the coordinates relative to the
752 ! rigid body rotation point.
753  xxc(1) = xc(1) - rotationpoint(1)
754  xxc(2) = xc(2) - rotationpoint(2)
755  xxc(3) = xc(3) - rotationpoint(3)
756 ! determine the total velocity of the cell center.
757 ! this is a combination of rotation speed of this
758 ! block and the entire rigid body rotation.
759  s(i, j, k, 1) = sc(1) + velxgrid + derivrotationmatrix(1, &
760 & 1)*xxc(1) + derivrotationmatrix(1, 2)*xxc(2) + &
761 & derivrotationmatrix(1, 3)*xxc(3)
762  s(i, j, k, 2) = sc(2) + velygrid + derivrotationmatrix(2, &
763 & 1)*xxc(1) + derivrotationmatrix(2, 2)*xxc(2) + &
764 & derivrotationmatrix(2, 3)*xxc(3)
765  s(i, j, k, 3) = sc(3) + velzgrid + derivrotationmatrix(3, &
766 & 1)*xxc(1) + derivrotationmatrix(3, 2)*xxc(2) + &
767 & derivrotationmatrix(3, 3)*xxc(3)
768  end do
769  end do
770  end do
771 !
772 ! normal grid velocities of the faces.
773 !
774 ! loop over the three directions.
775 ! the original code is elegant but the tapenade has a difficult time
776 ! to understand it. thus, we unfold it and make it easier for the
777 ! tapenade.
778 ! i-direction
779  do k=1,ke
780  do j=1,je
781  do i=0,ie
782 ! determine the coordinates of the face center,
783 ! which are stored in xc.
784  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
785 & -1, 1)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+&
786 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 1)+flowdoms(&
787 & nn, groundlevel, sps)%x(i, j, k, 1))
788  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
789 & -1, 2)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+&
790 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 2)+flowdoms(&
791 & nn, groundlevel, sps)%x(i, j, k, 2))
792  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
793 & -1, 3)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+&
794 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 3)+flowdoms(&
795 & nn, groundlevel, sps)%x(i, j, k, 3))
796  call cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
797 & velygrid, velzgrid, derivrotationmatrix&
798 & , sc)
799 ! store the dot product of grid velocity sc and
800 ! the normal ss in sface.
801  sfacei(i, j, k) = sc(1)*si(i, j, k, 1) + sc(2)*si(i, j, k&
802 & , 2) + sc(3)*si(i, j, k, 3)
803  end do
804  end do
805  end do
806 ! j-direction
807  do k=1,ke
808  do j=0,je
809  do i=1,ie
810 ! determine the coordinates of the face center,
811 ! which are stored in xc.
812  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
813 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+&
814 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 1)+&
815 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 1))
816  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
817 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+&
818 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 2)+&
819 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 2))
820  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
821 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+&
822 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 3)+&
823 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 3))
824  call cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
825 & velygrid, velzgrid, derivrotationmatrix&
826 & , sc)
827 ! store the dot product of grid velocity sc and
828 ! the normal ss in sface.
829  sfacej(i, j, k) = sc(1)*sj(i, j, k, 1) + sc(2)*sj(i, j, k&
830 & , 2) + sc(3)*sj(i, j, k, 3)
831  end do
832  end do
833  end do
834 ! k-direction
835  do k=0,ke
836  do j=1,je
837  do i=1,ie
838 ! determine the coordinates of the face center,
839 ! which are stored in xc.
840  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
841 & , 1)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 1)+&
842 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 1)+&
843 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 1))
844  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
845 & , 2)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 2)+&
846 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 2)+&
847 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 2))
848  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
849 & , 3)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 3)+&
850 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 3)+&
851 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 3))
852  call cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
853 & velygrid, velzgrid, derivrotationmatrix&
854 & , sc)
855 ! store the dot product of grid velocity sc and
856 ! the normal ss in sface.
857  sfacek(i, j, k) = sc(1)*sk(i, j, k, 1) + sc(2)*sk(i, j, k&
858 & , 2) + sc(3)*sk(i, j, k, 3)
859  end do
860  end do
861  end do
862  end if
863  end if
864  end subroutine gridvelocitiesfinelevel_block
865 
866  subroutine cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
867 & velygrid, velzgrid, derivrotationmatrix, sc)
868 !
869 ! returns the cell face velocities for a given face center
870 !
871  use constants
872  implicit none
873 !
874 ! subroutine arguments.
875 !
876  real(kind=realtype), dimension(3), intent(in) :: xc, rotcenter, &
877 & rotrate
878  real(kind=realtype), intent(in) :: velxgrid, velygrid, velzgrid
879  real(kind=realtype), dimension(3, 3), intent(in) :: &
880 & derivrotationmatrix
881  real(kind=realtype), dimension(3), intent(out) :: sc
882 !
883 ! local variables.
884 !
885  real(kind=realtype), dimension(3) :: rotationpoint, xxc
886 ! determine the coordinates relative to the
887 ! center of rotation.
888  xxc(1) = xc(1) - rotcenter(1)
889  xxc(2) = xc(2) - rotcenter(2)
890  xxc(3) = xc(3) - rotcenter(3)
891 ! determine the rotation speed of the face center,
892 ! which is omega*r.
893  sc(1) = rotrate(2)*xxc(3) - rotrate(3)*xxc(2)
894  sc(2) = rotrate(3)*xxc(1) - rotrate(1)*xxc(3)
895  sc(3) = rotrate(1)*xxc(2) - rotrate(2)*xxc(1)
896 ! determine the coordinates relative to the
897 ! rigid body rotation point.
898  xxc(1) = xc(1) - rotationpoint(1)
899  xxc(2) = xc(2) - rotationpoint(2)
900  xxc(3) = xc(3) - rotationpoint(3)
901 ! determine the total velocity of the cell face.
902 ! this is a combination of rotation speed of this
903 ! block and the entire rigid body rotation.
904  sc(1) = sc(1) + velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
905 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1, 3)*xxc(3&
906 & )
907  sc(2) = sc(2) + velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
908 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2, 3)*xxc(3&
909 & )
910  sc(3) = sc(3) + velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
911 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3, 3)*xxc(3&
912 & )
913  end subroutine cellfacevelocities
914 
915  subroutine slipvelocitiesfinelevel_block(useoldcoor, t, sps, nn)
916 !
917 ! slipvelocitiesfinelevel computes the slip velocities for
918 ! viscous subfaces on all viscous boundaries on groundlevel for
919 ! the given spectral solution. if useoldcoor is .true. the
920 ! velocities are determined using the unsteady time integrator;
921 ! otherwise the analytic form is used.
922 !
923  use constants
925  use blockpointers
926  use cgnsgrid
927  use flowvarrefstate
928  use inputmotion
929  use inputunsteady
930  use iteration
931  use inputphysics
932  use inputtsstabderiv
933  use monitor
934  use communication
936  use utils_fast_b, only : tsalpha, tsbeta, tsmach, terminate, &
938  implicit none
939 !
940 ! subroutine arguments.
941 !
942  integer(kind=inttype), intent(in) :: sps, nn
943  logical, intent(in) :: useoldcoor
944  real(kind=realtype), dimension(*), intent(in) :: t
945 !
946 ! local variables.
947 !
948  integer(kind=inttype) :: mm, i, j, level, ii
949  real(kind=realtype) :: oneover4dt
950  real(kind=realtype) :: velxgrid, velygrid, velzgrid, ainf
951  real(kind=realtype) :: velxgrid0, velygrid0, velzgrid0
952  real(kind=realtype), dimension(3) :: xc, xxc
953  real(kind=realtype), dimension(3) :: rotcenter, rotrate
954  real(kind=realtype), dimension(3) :: rotationpoint
955  real(kind=realtype), dimension(3, 3) :: rotationmatrix, &
956 & derivrotationmatrix
957  real(kind=realtype) :: tnew, told
958  real(kind=realtype), dimension(:, :, :), pointer :: uslip
959  real(kind=realtype), dimension(:, :, :), pointer :: xface
960  real(kind=realtype), dimension(:, :, :, :), pointer :: xfaceold
961  real(kind=realtype) :: intervalmach, alphats, alphaincrement, betats&
962 & , betaincrement
963  real(kind=realtype), dimension(3) :: veldir
964  real(kind=realtype), dimension(3) :: refdirection
965  intrinsic sqrt
966 ! determine the situation we are having here.
967  if (.not.useoldcoor) then
968 ! the velocities must be determined analytically.
969 ! compute the mesh velocity from the given mesh mach number.
970 ! ainf = sqrt(gammainf*pinf/rhoinf)
971 ! velxgrid = ainf*machgrid(1)
972 ! velygrid = ainf*machgrid(2)
973 ! velzgrid = ainf*machgrid(3)
974  ainf = sqrt(gammainf*pinf/rhoinf)
975  velxgrid0 = ainf*machgrid*(-veldirfreestream(1))
976  velygrid0 = ainf*machgrid*(-veldirfreestream(2))
977  velzgrid0 = ainf*machgrid*(-veldirfreestream(3))
978 ! compute the derivative of the rotation matrix and the rotation
979 ! point; needed for velocity due to the rigid body rotation of
980 ! the entire grid. it is assumed that the rigid body motion of
981 ! the grid is only specified if there is only 1 section present.
982  call derivativerotmatrixrigid(derivrotationmatrix, rotationpoint, &
983 & t(1))
984 !compute the rotation matrix to update the velocities for the time
985 !spectral stability derivative case...
986 ! loop over the number of viscous subfaces.
987 bocoloop2:do mm=1,nviscbocos
988 ! store the rotation center and the rotation rate
989 ! for this subface.
990  ii = cgnssubface(mm)
991  rotcenter = cgnsdoms(nbkglobal)%bocoinfo(ii)%rotcenter
992  rotrate = timeref*cgnsdoms(nbkglobal)%bocoinfo(ii)%rotrate
993 ! usewindaxis should go back here!
994  velxgrid = velxgrid0
995  velygrid = velygrid0
996  velzgrid = velzgrid0
997 ! loop over the quadrilateral faces of the viscous
998 ! subface.
999 ! the new procedure is less elegant as the previous one.
1000 ! but the new stands up to tapenade.
1001  if (bcfaceid(mm) .eq. imin) then
1002  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1003  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1004 ! compute the coordinates of the centroid of the face.
1005 ! normally this would be an average of i-1 and i, but
1006 ! due to the usage of the pointer xface and the fact
1007 ! that x starts at index 0 this is shifted 1 index.
1008  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
1009 & 1)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 1)+&
1010 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 1)+flowdoms(&
1011 & nn, groundlevel, sps)%x(1, i-1, j-1, 1))
1012  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
1013 & 2)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 2)+&
1014 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 2)+flowdoms(&
1015 & nn, groundlevel, sps)%x(1, i-1, j-1, 2))
1016  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
1017 & 3)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 3)+&
1018 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 3)+flowdoms(&
1019 & nn, groundlevel, sps)%x(1, i-1, j-1, 3))
1020 ! determine the coordinates relative to the center
1021 ! of rotation.
1022  xxc(1) = xc(1) - rotcenter(1)
1023  xxc(2) = xc(2) - rotcenter(2)
1024  xxc(3) = xc(3) - rotcenter(3)
1025 ! compute the velocity, which is the cross product
1026 ! of rotrate and xc.
1027  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
1028 & *xxc(2)
1029  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
1030 & *xxc(3)
1031  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
1032 & *xxc(1)
1033 ! determine the coordinates relative to the
1034 ! rigid body rotation point.
1035  xxc(1) = xc(1) - rotationpoint(1)
1036  xxc(2) = xc(2) - rotationpoint(2)
1037  xxc(3) = xc(3) - rotationpoint(3)
1038 ! determine the total velocity of the cell center.
1039 ! this is a combination of rotation speed of this
1040 ! block and the entire rigid body rotation.
1041  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
1042 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
1043 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
1044 & , 3)*xxc(3)
1045  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
1046 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
1047 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
1048 & , 3)*xxc(3)
1049  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
1050 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
1051 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
1052 & , 3)*xxc(3)
1053  end do
1054  end do
1055  else if (bcfaceid(mm) .eq. imax) then
1056  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1057  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1058 ! compute the coordinates of the centroid of the face.
1059 ! normally this would be an average of i-1 and i, but
1060 ! due to the usage of the pointer xface and the fact
1061 ! that x starts at index 0 this is shifted 1 index.
1062  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
1063 & , 1)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 1)+&
1064 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 1)+flowdoms&
1065 & (nn, groundlevel, sps)%x(il, i-1, j-1, 1))
1066  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
1067 & , 2)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 2)+&
1068 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 2)+flowdoms&
1069 & (nn, groundlevel, sps)%x(il, i-1, j-1, 2))
1070  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
1071 & , 3)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 3)+&
1072 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 3)+flowdoms&
1073 & (nn, groundlevel, sps)%x(il, i-1, j-1, 3))
1074 ! determine the coordinates relative to the center
1075 ! of rotation.
1076  xxc(1) = xc(1) - rotcenter(1)
1077  xxc(2) = xc(2) - rotcenter(2)
1078  xxc(3) = xc(3) - rotcenter(3)
1079 ! compute the velocity, which is the cross product
1080 ! of rotrate and xc.
1081  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
1082 & *xxc(2)
1083  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
1084 & *xxc(3)
1085  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
1086 & *xxc(1)
1087 ! determine the coordinates relative to the
1088 ! rigid body rotation point.
1089  xxc(1) = xc(1) - rotationpoint(1)
1090  xxc(2) = xc(2) - rotationpoint(2)
1091  xxc(3) = xc(3) - rotationpoint(3)
1092 ! determine the total velocity of the cell center.
1093 ! this is a combination of rotation speed of this
1094 ! block and the entire rigid body rotation.
1095  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
1096 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
1097 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
1098 & , 3)*xxc(3)
1099  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
1100 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
1101 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
1102 & , 3)*xxc(3)
1103  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
1104 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
1105 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
1106 & , 3)*xxc(3)
1107  end do
1108  end do
1109  else if (bcfaceid(mm) .eq. jmin) then
1110  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1111  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1112 ! compute the coordinates of the centroid of the face.
1113 ! normally this would be an average of i-1 and i, but
1114 ! due to the usage of the pointer xface and the fact
1115 ! that x starts at index 0 this is shifted 1 index.
1116  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
1117 & 1)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 1)+&
1118 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 1)+flowdoms(&
1119 & nn, groundlevel, sps)%x(i-1, 1, j-1, 1))
1120  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
1121 & 2)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 2)+&
1122 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 2)+flowdoms(&
1123 & nn, groundlevel, sps)%x(i-1, 1, j-1, 2))
1124  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
1125 & 3)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 3)+&
1126 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 3)+flowdoms(&
1127 & nn, groundlevel, sps)%x(i-1, 1, j-1, 3))
1128 ! determine the coordinates relative to the center
1129 ! of rotation.
1130  xxc(1) = xc(1) - rotcenter(1)
1131  xxc(2) = xc(2) - rotcenter(2)
1132  xxc(3) = xc(3) - rotcenter(3)
1133 ! compute the velocity, which is the cross product
1134 ! of rotrate and xc.
1135  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
1136 & *xxc(2)
1137  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
1138 & *xxc(3)
1139  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
1140 & *xxc(1)
1141 ! determine the coordinates relative to the
1142 ! rigid body rotation point.
1143  xxc(1) = xc(1) - rotationpoint(1)
1144  xxc(2) = xc(2) - rotationpoint(2)
1145  xxc(3) = xc(3) - rotationpoint(3)
1146 ! determine the total velocity of the cell center.
1147 ! this is a combination of rotation speed of this
1148 ! block and the entire rigid body rotation.
1149  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
1150 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
1151 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
1152 & , 3)*xxc(3)
1153  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
1154 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
1155 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
1156 & , 3)*xxc(3)
1157  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
1158 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
1159 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
1160 & , 3)*xxc(3)
1161  end do
1162  end do
1163  else if (bcfaceid(mm) .eq. jmax) then
1164  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1165  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1166 ! compute the coordinates of the centroid of the face.
1167 ! normally this would be an average of i-1 and i, but
1168 ! due to the usage of the pointer xface and the fact
1169 ! that x starts at index 0 this is shifted 1 index.
1170  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
1171 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 1)+&
1172 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 1)+flowdoms&
1173 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 1))
1174  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
1175 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 2)+&
1176 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 2)+flowdoms&
1177 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 2))
1178  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
1179 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 3)+&
1180 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 3)+flowdoms&
1181 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 3))
1182 ! determine the coordinates relative to the center
1183 ! of rotation.
1184  xxc(1) = xc(1) - rotcenter(1)
1185  xxc(2) = xc(2) - rotcenter(2)
1186  xxc(3) = xc(3) - rotcenter(3)
1187 ! compute the velocity, which is the cross product
1188 ! of rotrate and xc.
1189  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
1190 & *xxc(2)
1191  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
1192 & *xxc(3)
1193  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
1194 & *xxc(1)
1195 ! determine the coordinates relative to the
1196 ! rigid body rotation point.
1197  xxc(1) = xc(1) - rotationpoint(1)
1198  xxc(2) = xc(2) - rotationpoint(2)
1199  xxc(3) = xc(3) - rotationpoint(3)
1200 ! determine the total velocity of the cell center.
1201 ! this is a combination of rotation speed of this
1202 ! block and the entire rigid body rotation.
1203  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
1204 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
1205 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
1206 & , 3)*xxc(3)
1207  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
1208 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
1209 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
1210 & , 3)*xxc(3)
1211  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
1212 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
1213 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
1214 & , 3)*xxc(3)
1215  end do
1216  end do
1217  else if (bcfaceid(mm) .eq. kmin) then
1218  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1219  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1220 ! compute the coordinates of the centroid of the face.
1221 ! normally this would be an average of i-1 and i, but
1222 ! due to the usage of the pointer xface and the fact
1223 ! that x starts at index 0 this is shifted 1 index.
1224  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
1225 & 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 1)+&
1226 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 1)+flowdoms(&
1227 & nn, groundlevel, sps)%x(i-1, j-1, 1, 1))
1228  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
1229 & 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 2)+&
1230 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 2)+flowdoms(&
1231 & nn, groundlevel, sps)%x(i-1, j-1, 1, 2))
1232  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
1233 & 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 3)+&
1234 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 3)+flowdoms(&
1235 & nn, groundlevel, sps)%x(i-1, j-1, 1, 3))
1236 ! determine the coordinates relative to the center
1237 ! of rotation.
1238  xxc(1) = xc(1) - rotcenter(1)
1239  xxc(2) = xc(2) - rotcenter(2)
1240  xxc(3) = xc(3) - rotcenter(3)
1241 ! compute the velocity, which is the cross product
1242 ! of rotrate and xc.
1243  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
1244 & *xxc(2)
1245  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
1246 & *xxc(3)
1247  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
1248 & *xxc(1)
1249 ! determine the coordinates relative to the
1250 ! rigid body rotation point.
1251  xxc(1) = xc(1) - rotationpoint(1)
1252  xxc(2) = xc(2) - rotationpoint(2)
1253  xxc(3) = xc(3) - rotationpoint(3)
1254 ! determine the total velocity of the cell center.
1255 ! this is a combination of rotation speed of this
1256 ! block and the entire rigid body rotation.
1257  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
1258 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
1259 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
1260 & , 3)*xxc(3)
1261  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
1262 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
1263 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
1264 & , 3)*xxc(3)
1265  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
1266 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
1267 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
1268 & , 3)*xxc(3)
1269  end do
1270  end do
1271  else if (bcfaceid(mm) .eq. kmax) then
1272  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1273  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1274 ! compute the coordinates of the centroid of the face.
1275 ! normally this would be an average of i-1 and i, but
1276 ! due to the usage of the pointer xface and the fact
1277 ! that x starts at index 0 this is shifted 1 index.
1278  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
1279 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 1)+&
1280 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 1)+flowdoms&
1281 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 1))
1282  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
1283 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 2)+&
1284 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 2)+flowdoms&
1285 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 2))
1286  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
1287 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 3)+&
1288 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 3)+flowdoms&
1289 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 3))
1290 ! determine the coordinates relative to the center
1291 ! of rotation.
1292  xxc(1) = xc(1) - rotcenter(1)
1293  xxc(2) = xc(2) - rotcenter(2)
1294  xxc(3) = xc(3) - rotcenter(3)
1295 ! compute the velocity, which is the cross product
1296 ! of rotrate and xc.
1297  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
1298 & *xxc(2)
1299  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
1300 & *xxc(3)
1301  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
1302 & *xxc(1)
1303 ! determine the coordinates relative to the
1304 ! rigid body rotation point.
1305  xxc(1) = xc(1) - rotationpoint(1)
1306  xxc(2) = xc(2) - rotationpoint(2)
1307  xxc(3) = xc(3) - rotationpoint(3)
1308 ! determine the total velocity of the cell center.
1309 ! this is a combination of rotation speed of this
1310 ! block and the entire rigid body rotation.
1311  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
1312 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
1313 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
1314 & , 3)*xxc(3)
1315  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
1316 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
1317 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
1318 & , 3)*xxc(3)
1319  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
1320 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
1321 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
1322 & , 3)*xxc(3)
1323  end do
1324  end do
1325  end if
1326  end do bocoloop2
1327  end if
1328  end subroutine slipvelocitiesfinelevel_block
1329 
1330  subroutine normalvelocities_block(sps)
1331 !
1332 ! normalvelocitiesalllevels computes the normal grid
1333 ! velocities of some boundary faces of the moving blocks for
1334 ! spectral mode sps. all grid levels from ground level to the
1335 ! coarsest level are considered.
1336 !
1337  use constants
1338  use blockpointers, only : il, jl, kl, addgridvelocities, &
1340  implicit none
1341 !
1342 ! subroutine arguments.
1343 !
1344  integer(kind=inttype), intent(in) :: sps
1345 !
1346 ! local variables.
1347 !
1348  integer(kind=inttype) :: mm
1349  integer(kind=inttype) :: i, j
1350  real(kind=realtype) :: weight, mult
1351  real(kind=realtype), dimension(:, :), pointer :: sface
1352  real(kind=realtype), dimension(:, :, :), pointer :: ss
1353  intrinsic associated
1354  intrinsic sqrt
1355 ! check for a moving block. as it is possible that in a
1356 ! multidisicplinary environment additional grid velocities
1357 ! are set, the test should be done on addgridvelocities
1358 ! and not on blockismoving.
1359  if (addgridvelocities) then
1360 !
1361 ! determine the normal grid velocities of the boundaries.
1362 ! as these values are based on the unit normal. a division
1363 ! by the length of the normal is needed.
1364 ! furthermore the boundary unit normals are per definition
1365 ! outward pointing, while on the imin, jmin and kmin
1366 ! boundaries the face normals are inward pointing. this
1367 ! is taken into account by the factor mult.
1368 !
1369 ! loop over the boundary subfaces.
1370 bocoloop:do mm=1,nbocos
1371 ! check whether rface is allocated.
1372  if (associated(bcdata(mm)%rface)) then
1373 ! determine the block face on which the subface is
1374 ! located and set some variables accordingly.
1375 ! the new procedure is less elegant as the previous one.
1376 ! but the new stands up to tapenade.
1377  if (bcfaceid(mm) .eq. imin) then
1378  mult = -one
1379  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1380  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1381 ! compute the inverse of the length of the normal
1382 ! vector and possibly correct for inward pointing.
1383  weight = sqrt(si(1, i, j, 1)**2 + si(1, i, j, 2)**2 + si&
1384 & (1, i, j, 3)**2)
1385  if (weight .gt. zero) weight = mult/weight
1386 ! compute the normal velocity based on the outward
1387 ! pointing unit normal.
1388  bcdata(mm)%rface(i, j) = weight*sfacei(1, i, j)
1389  end do
1390  end do
1391  else if (bcfaceid(mm) .eq. imax) then
1392  mult = one
1393  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1394  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1395 ! compute the inverse of the length of the normal
1396 ! vector and possibly correct for inward pointing.
1397  weight = sqrt(si(il, i, j, 1)**2 + si(il, i, j, 2)**2 + &
1398 & si(il, i, j, 3)**2)
1399  if (weight .gt. zero) weight = mult/weight
1400 ! compute the normal velocity based on the outward
1401 ! pointing unit normal.
1402  bcdata(mm)%rface(i, j) = weight*sfacei(il, i, j)
1403  end do
1404  end do
1405  else if (bcfaceid(mm) .eq. jmin) then
1406  mult = -one
1407  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1408  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1409 ! compute the inverse of the length of the normal
1410 ! vector and possibly correct for inward pointing.
1411  weight = sqrt(sj(i, 1, j, 1)**2 + sj(i, 1, j, 2)**2 + sj&
1412 & (i, 1, j, 3)**2)
1413  if (weight .gt. zero) weight = mult/weight
1414 ! compute the normal velocity based on the outward
1415 ! pointing unit normal.
1416  bcdata(mm)%rface(i, j) = weight*sfacej(i, 1, j)
1417  end do
1418  end do
1419  else if (bcfaceid(mm) .eq. jmax) then
1420  mult = one
1421  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1422  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1423 ! compute the inverse of the length of the normal
1424 ! vector and possibly correct for inward pointing.
1425  weight = sqrt(sj(i, jl, j, 1)**2 + sj(i, jl, j, 2)**2 + &
1426 & sj(i, jl, j, 3)**2)
1427  if (weight .gt. zero) weight = mult/weight
1428 ! compute the normal velocity based on the outward
1429 ! pointing unit normal.
1430  bcdata(mm)%rface(i, j) = weight*sfacej(i, jl, j)
1431  end do
1432  end do
1433  else if (bcfaceid(mm) .eq. kmin) then
1434  mult = -one
1435  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1436  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1437 ! compute the inverse of the length of the normal
1438 ! vector and possibly correct for inward pointing.
1439  weight = sqrt(sk(i, j, 1, 1)**2 + sk(i, j, 1, 2)**2 + sk&
1440 & (i, j, 1, 3)**2)
1441  if (weight .gt. zero) weight = mult/weight
1442 ! compute the normal velocity based on the outward
1443 ! pointing unit normal.
1444  bcdata(mm)%rface(i, j) = weight*sfacek(i, j, 1)
1445  end do
1446  end do
1447  else if (bcfaceid(mm) .eq. kmax) then
1448  mult = one
1449  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1450  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1451 ! compute the inverse of the length of the normal
1452 ! vector and possibly correct for inward pointing.
1453  weight = sqrt(sk(i, j, kl, 1)**2 + sk(i, j, kl, 2)**2 + &
1454 & sk(i, j, kl, 3)**2)
1455  if (weight .gt. zero) weight = mult/weight
1456 ! compute the normal velocity based on the outward
1457 ! pointing unit normal.
1458  bcdata(mm)%rface(i, j) = weight*sfacek(i, j, kl)
1459  end do
1460  end do
1461  end if
1462  end if
1463  end do bocoloop
1464  else
1465 ! block is not moving. loop over the boundary faces and set
1466 ! the normal grid velocity to zero if allocated.
1467  do mm=1,nbocos
1468  if (associated(bcdata(mm)%rface)) bcdata(mm)%rface = zero
1469  end do
1470  end if
1471  end subroutine normalvelocities_block
1472 ! ----------------------------------------------------------------------
1473 ! |
1474 ! no tapenade routine below this line |
1475 ! |
1476 ! ----------------------------------------------------------------------
1477 
1478 end module solverutils_fast_b
1479 
Definition: BCData.F90:1
real(kind=realtype), dimension(:, :, :), pointer sfacek
real(kind=realtype), dimension(:, :, :), pointer gamma
real(kind=realtype), dimension(:, :, :), pointer radid
logical addgridvelocities
integer(kind=inttype) jl
real(kind=realtype), dimension(:, :, :), pointer radk
real(kind=realtype), dimension(:, :, :, :), pointer wd
integer(kind=inttype) nviscbocos
logical blockismoving
real(kind=realtype), dimension(:, :, :), pointer p
real(kind=realtype), dimension(:, :, :), pointer radj
integer(kind=inttype) ie
real(kind=realtype), dimension(:, :, :, :), pointer w
real(kind=realtype), dimension(:, :, :), pointer sfacei
integer(kind=inttype), dimension(:), pointer cgnssubface
real(kind=realtype), dimension(:, :, :), pointer revd
real(kind=realtype), dimension(:, :, :), pointer radjd
integer(kind=inttype) nbkglobal
real(kind=realtype), dimension(:, :, :), pointer rlv
integer(kind=inttype), dimension(:), pointer bcfaceid
real(kind=realtype), dimension(:, :, :, :), pointer si
real(kind=realtype), dimension(:, :, :), pointer radkd
integer(kind=inttype) nbocos
real(kind=realtype), dimension(:, :, :, :), pointer sj
integer(kind=inttype) sectionid
real(kind=realtype), dimension(:, :, :, :), pointer s
real(kind=realtype), dimension(:, :, :), pointer rev
real(kind=realtype), dimension(:, :, :, :), pointer sk
real(kind=realtype), dimension(:, :, :), pointer rlvd
real(kind=realtype), dimension(:, :, :), pointer vol
real(kind=realtype), dimension(:, :, :), pointer dtl
real(kind=realtype), dimension(:, :, :), pointer sfacej
integer(kind=inttype) je
real(kind=realtype), dimension(:, :, :), pointer radi
integer(kind=inttype) ke
real(kind=realtype), dimension(:, :, :), pointer pd
integer(kind=inttype) kl
integer(kind=inttype) il
type(cgnsblockinfotype), dimension(:), allocatable cgnsdoms
Definition: cgnsGrid.F90:495
real(kind=realtype), parameter zero
Definition: constants.F90:71
integer(kind=inttype), parameter imax
Definition: constants.F90:293
integer(kind=inttype), parameter kmin
Definition: constants.F90:296
real(kind=realtype), parameter pi
Definition: constants.F90:22
integer(kind=inttype), parameter jmax
Definition: constants.F90:295
real(kind=realtype), parameter eps
Definition: constants.F90:23
integer(kind=inttype), parameter turkel
Definition: constants.F90:165
integer, parameter irho
Definition: constants.F90:34
integer(kind=inttype), parameter choimerkle
Definition: constants.F90:165
integer(kind=inttype), parameter timespectral
Definition: constants.F90:115
integer, parameter ivx
Definition: constants.F90:35
integer(kind=inttype), dimension(32) myintstack
Definition: constants.F90:299
integer(kind=inttype) myintptr
Definition: constants.F90:300
integer(kind=inttype), parameter noprecond
Definition: constants.F90:165
real(kind=realtype), parameter one
Definition: constants.F90:72
real(kind=realtype), parameter half
Definition: constants.F90:80
integer(kind=inttype), parameter imin
Definition: constants.F90:292
integer, parameter ivz
Definition: constants.F90:37
real(kind=realtype), parameter two
Definition: constants.F90:73
real(kind=realtype), parameter fourth
Definition: constants.F90:82
integer(kind=inttype), parameter kmax
Definition: constants.F90:297
integer, parameter ivy
Definition: constants.F90:36
integer(kind=inttype), parameter jmin
Definition: constants.F90:294
subroutine derivativerotmatrixrigid(rotationmatrix, rotationpoint, t)
subroutine getdirvector(refdirection, alpha, beta, winddirection, liftindex)
real(kind=realtype) gammainf
real(kind=realtype) pinfcorr
real(kind=realtype) pinf
real(kind=realtype) rhoinf
real(kind=realtype) timeref
logical radiineededcoarse
Definition: inputParam.F90:92
real(kind=realtype) adis
Definition: inputParam.F90:78
real(kind=realtype) acousticscalefactor
Definition: inputParam.F90:79
integer(kind=inttype) precond
Definition: inputParam.F90:74
integer(kind=inttype) equationmode
Definition: inputParam.F90:583
real(kind=realtype) machgrid
Definition: inputParam.F90:593
real(kind=realtype), dimension(3) veldirfreestream
Definition: inputParam.F90:599
integer(kind=inttype) ntimeintervalsspectral
Definition: inputParam.F90:645
integer(kind=inttype) currentlevel
Definition: iteration.f90:18
integer(kind=inttype) groundlevel
Definition: iteration.f90:18
type(sectiontype), dimension(:), allocatable sections
Definition: section.f90:46
subroutine slipvelocitiesfinelevel_block(useoldcoor, t, sps, nn)
subroutine normalvelocities_block(sps)
subroutine cellfacevelocities(xc, rotcenter, rotrate, velxgrid, velygrid, velzgrid, derivrotationmatrix, sc)
subroutine timestep_block(onlyradii)
subroutine timestep_block_fast_b(onlyradii)
subroutine gridvelocitiesfinelevel_block(useoldcoor, t, sps, nn)
subroutine terminate(routinename, errormessage)
subroutine rotmatrixrigidbody(tnew, told, rotationmatrix, rotationpoint)
subroutine setcoeftimeintegrator()
real(kind=realtype) function tsmach(degreepolmach, coefpolmach, degreefourmach, omegafourmach, coscoeffourmach, sincoeffourmach, t)
subroutine getdirangle(freestreamaxis, liftaxis, liftindex, alpha, beta)
real(kind=realtype) function tsalpha(degreepolalpha, coefpolalpha, degreefouralpha, omegafouralpha, coscoeffouralpha, sincoeffouralpha, t)
real(kind=realtype) function tsbeta(degreepolbeta, coefpolbeta, degreefourbeta, omegafourbeta, coscoeffourbeta, sincoeffourbeta, t)