ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
solverUtils_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: rhoinf pinfcorr *rev *dtl *p
10 ! *sfacei *sfacej *sfacek *w *rlv *vol *si *sj *sk
11 ! *radi *radj *radk
12 ! with respect to varying inputs: rhoinf pinfcorr *rev *dtl *p
13 ! *sfacei *sfacej *sfacek *w *rlv *vol *si *sj *sk
14 ! *radi *radj *radk
15 ! rw status of diff variables: rhoinf:incr pinfcorr:incr *rev:incr
16 ! *dtl:in-out *p:incr *sfacei:incr *sfacej:incr
17 ! *sfacek:incr *w:incr *rlv:incr *vol:incr *si:incr
18 ! *sj:incr *sk:incr *radi:in-out *radj:in-out *radk:in-out
19 ! plus diff mem management of: rev:in dtl:in p:in sfacei:in sfacej:in
20 ! sfacek:in w:in rlv:in vol:in si:in sj:in sk:in
21 ! radi:in radj:in radk:in
22  subroutine timestep_block_b(onlyradii)
23 !
24 ! timestep computes the time step, or more precisely the time
25 ! step divided by the volume per unit cfl, in the owned cells.
26 ! however, for the artificial dissipation schemes, the spectral
27 ! radii in the halo's are needed. therefore the loop is taken
28 ! over the the first level of halo cells. the spectral radii are
29 ! stored and possibly modified for high aspect ratio cells.
30 !
31  use constants
32  use blockpointers, only : ie, je, ke, il, jl, kl, w, wd, p, pd, &
34 & , sj, sjd, sk, skd, sfacei, sfaceid, sfacej, sfacejd, sfacek, &
40  use inputphysics, only : equationmode
42  use section, only : sections
44  use utils_b, only : terminate
45  implicit none
46 !
47 ! subroutine argument.
48 !
49  logical, intent(in) :: onlyradii
50 !
51 ! local parameters.
52 !
53  real(kind=realtype), parameter :: b=2.0_realtype
54 !
55 ! local variables.
56 !
57  integer(kind=inttype) :: i, j, k, ii
58  real(kind=realtype) :: plim, rlim, clim2
59  real(kind=realtype) :: plimd, clim2d
60  real(kind=realtype) :: uux, uuy, uuz, cc2, qsi, qsj, qsk, sx, sy, sz&
61 & , rmu
62  real(kind=realtype) :: uuxd, uuyd, uuzd, cc2d, qsid, qsjd, qskd, sxd&
63 & , syd, szd, rmud
64  real(kind=realtype) :: ri, rj, rk, rij, rjk, rki
65  real(kind=realtype) :: rid, rjd, rkd, rijd, rjkd, rkid
66  real(kind=realtype) :: vsi, vsj, vsk, rfl, dpi, dpj, dpk
67  real(kind=realtype) :: vsid, vsjd, vskd, rfld, dpid, dpjd, dpkd
68  real(kind=realtype) :: sface, tmp
69  real(kind=realtype) :: sfaced
70  logical :: radiineeded, doscaling
71  intrinsic mod
72  intrinsic max
73  intrinsic abs
74  intrinsic sqrt
75  real(kind=realtype) :: abs0
76  real(kind=realtype) :: abs0d
77  real(kind=realtype) :: abs1
78  real(kind=realtype) :: abs1d
79  real(kind=realtype) :: abs2
80  real(kind=realtype) :: abs2d
81  real(kind=realtype) :: abs3
82  real(kind=realtype) :: abs3d
83  real(kind=realtype) :: abs4
84  real(kind=realtype) :: abs4d
85  real(kind=realtype) :: abs5
86  real(kind=realtype) :: abs5d
87  real(kind=realtype) :: temp
88  real(kind=realtype) :: tempd
89  real(kind=realtype) :: temp0
90  real(kind=realtype) :: temp1
91  real(kind=realtype) :: tempd0
92  real(kind=realtype) :: tempd1
93  integer :: branch
94 ! determine whether or not the spectral radii are needed for the
95 ! flux computation.
96  radiineeded = radiineededcoarse
97  if (currentlevel .le. groundlevel) radiineeded = radiineededfine
98 ! return immediately if only the spectral radii must be computed
99 ! and these are not needed for the flux computation.
100  if (.not.(onlyradii .and. (.not.radiineeded))) then
101 ! set the value of plim. to be fully consistent this must have
102 ! the dimension of a pressure. therefore a fraction of pinfcorr
103 ! is used. idem for rlim; compute clim2 as well.
104  plim = 0.001_realtype*pinfcorr
105  clim2 = 0.000001_realtype*gammainf*pinfcorr/rhoinf
106  doscaling = dirscaling .and. currentlevel .le. groundlevel
107 ! initialize sface to zero. this value will be used if the
108 ! block is not moving.
109  sface = zero
110 !
111 ! inviscid contribution, depending on the preconditioner.
112 ! compute the cell centered values of the spectral radii.
113 !
114  select case (precond)
115  case (noprecond)
116  call pushreal8(sface)
117 !$fwd-of ii-loop
118 ! no preconditioner. simply the standard spectral radius.
119 ! loop over the cells, including the first level halo.
120  do ii=0,ie*je*ke-1
121  i = mod(ii, ie) + 1
122  j = mod(ii/ie, je) + 1
123  k = ii/(ie*je) + 1
124 ! compute the velocities and speed of sound squared.
125  uux = w(i, j, k, ivx)
126  uuy = w(i, j, k, ivy)
127  uuz = w(i, j, k, ivz)
128  cc2 = gamma(i, j, k)*p(i, j, k)/w(i, j, k, irho)
129  if (cc2 .lt. clim2) then
130  cc2 = clim2
131  else
132  cc2 = cc2
133  end if
134 ! set the dot product of the grid velocity and the
135 ! normal in i-direction for a moving face. to avoid
136 ! a number of multiplications by 0.5 simply the sum
137 ! is taken.
138  if (addgridvelocities) sface = sfacei(i-1, j, k) + sfacei(i, j&
139 & , k)
140 ! spectral radius in i-direction.
141  sx = si(i-1, j, k, 1) + si(i, j, k, 1)
142  sy = si(i-1, j, k, 2) + si(i, j, k, 2)
143  sz = si(i-1, j, k, 3) + si(i, j, k, 3)
144  qsi = uux*sx + uuy*sy + uuz*sz - sface
145  if (qsi .ge. 0.) then
146  abs0 = qsi
147  else
148  abs0 = -qsi
149  end if
150  ri = half*(abs0+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz**&
151 & 2)))
152 ! the grid velocity in j-direction.
153  if (addgridvelocities) sface = sfacej(i, j-1, k) + sfacej(i, j&
154 & , k)
155 ! spectral radius in j-direction.
156  sx = sj(i, j-1, k, 1) + sj(i, j, k, 1)
157  sy = sj(i, j-1, k, 2) + sj(i, j, k, 2)
158  sz = sj(i, j-1, k, 3) + sj(i, j, k, 3)
159  qsj = uux*sx + uuy*sy + uuz*sz - sface
160  if (qsj .ge. 0.) then
161  abs1 = qsj
162  else
163  abs1 = -qsj
164  end if
165  rj = half*(abs1+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz**&
166 & 2)))
167 ! the grid velocity in k-direction.
168  if (addgridvelocities) sface = sfacek(i, j, k-1) + sfacek(i, j&
169 & , k)
170 ! spectral radius in k-direction.
171  sx = sk(i, j, k-1, 1) + sk(i, j, k, 1)
172  sy = sk(i, j, k-1, 2) + sk(i, j, k, 2)
173  sz = sk(i, j, k-1, 3) + sk(i, j, k, 3)
174  qsk = uux*sx + uuy*sy + uuz*sz - sface
175  if (qsk .ge. 0.) then
176  abs2 = qsk
177  else
178  abs2 = -qsk
179  end if
180  rk = half*(abs2+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz**&
181 & 2)))
182 ! compute the inviscid contribution to the time step.
183  if (.not.onlyradii) dtl(i, j, k) = ri + rj + rk
184 !
185 ! adapt the spectral radii if directional scaling must be
186 ! applied.
187 !
188  if (doscaling) then
189  if (ri .lt. eps) then
190  ri = eps
191  else
192  ri = ri
193  end if
194  if (rj .lt. eps) then
195  rj = eps
196  else
197  rj = rj
198  end if
199  if (rk .lt. eps) then
200  rk = eps
201  else
202  rk = rk
203  end if
204 ! compute the scaling in the three coordinate
205 ! directions.
206  rij = (ri/rj)**adis
207  rjk = (rj/rk)**adis
208  rki = (rk/ri)**adis
209 ! create the scaled versions of the aspect ratios.
210 ! note that the multiplication is done with radi, radj
211 ! and radk, such that the influence of the clipping
212 ! is negligible.
213  radi(i, j, k) = ri*(one+one/rij+rki)
214  radj(i, j, k) = rj*(one+one/rjk+rij)
215  radk(i, j, k) = rk*(one+one/rki+rjk)
216  else
217  radi(i, j, k) = ri
218  radj(i, j, k) = rj
219  radk(i, j, k) = rk
220  end if
221  end do
222  call pushcontrol2b(1)
223  case (turkel)
224  call pushcontrol2b(2)
225  case (choimerkle)
226  call pushcontrol2b(3)
227  case default
228  call pushcontrol2b(0)
229  end select
230 ! the rest of this file can be skipped if only the spectral
231 ! radii need to be computed.
232  if (.not.onlyradii) then
233 ! the viscous contribution, if needed.
234  if (viscous) then
235 ! loop over the owned cell centers.
236  do k=2,kl
237  do j=2,jl
238  do i=2,il
239 ! compute the effective viscosity coefficient. the
240 ! factor 0.5 is a combination of two things. in the
241 ! standard central discretization of a second
242 ! derivative there is a factor 2 multiplying the
243 ! central node. however in the code below not the
244 ! average but the sum of the left and the right face
245 ! is taken and squared. this leads to a factor 4.
246 ! combining both effects leads to 0.5. furthermore,
247 ! it is divided by the volume and density to obtain
248 ! the correct dimensions and multiplied by the
249 ! non-dimensional factor factvis.
250  call pushreal8(rmu)
251  rmu = rlv(i, j, k)
252  if (eddymodel) then
253  rmu = rmu + rev(i, j, k)
254  call pushcontrol1b(0)
255  else
256  call pushcontrol1b(1)
257  end if
258  call pushreal8(rmu)
259  rmu = half*rmu/(w(i, j, k, irho)*vol(i, j, k))
260 ! add the viscous contribution in i-direction to the
261 ! (inverse) of the time step.
262  call pushreal8(sx)
263  sx = si(i, j, k, 1) + si(i-1, j, k, 1)
264  call pushreal8(sy)
265  sy = si(i, j, k, 2) + si(i-1, j, k, 2)
266  call pushreal8(sz)
267  sz = si(i, j, k, 3) + si(i-1, j, k, 3)
268  vsi = rmu*(sx*sx+sy*sy+sz*sz)
269  dtl(i, j, k) = dtl(i, j, k) + vsi
270 ! add the viscous contribution in j-direction to the
271 ! (inverse) of the time step.
272  sx = sj(i, j, k, 1) + sj(i, j-1, k, 1)
273  sy = sj(i, j, k, 2) + sj(i, j-1, k, 2)
274  sz = sj(i, j, k, 3) + sj(i, j-1, k, 3)
275  vsj = rmu*(sx*sx+sy*sy+sz*sz)
276  dtl(i, j, k) = dtl(i, j, k) + vsj
277 ! add the viscous contribution in k-direction to the
278 ! (inverse) of the time step.
279  sx = sk(i, j, k, 1) + sk(i, j, k-1, 1)
280  sy = sk(i, j, k, 2) + sk(i, j, k-1, 2)
281  sz = sk(i, j, k, 3) + sk(i, j, k-1, 3)
282  vsk = rmu*(sx*sx+sy*sy+sz*sz)
283  dtl(i, j, k) = dtl(i, j, k) + vsk
284  end do
285  end do
286  end do
287  call pushcontrol1b(0)
288  else
289  call pushcontrol1b(1)
290  end if
291 ! for the spectral mode an additional term term must be
292 ! taken into account, which corresponds to the contribution
293 ! of the highest frequency.
294  if (equationmode .eq. timespectral) then
296 & timeperiod
297 ! loop over the owned cell centers and add the term.
298  do k=2,kl
299  do j=2,jl
300  do i=2,il
301  dtl(i, j, k) = dtl(i, j, k) + tmp*vol(i, j, k)
302  end do
303  end do
304  end do
305  call pushcontrol1b(1)
306  else
307  call pushcontrol1b(0)
308  end if
309 ! currently the inverse of dt/vol is stored in dtl. invert
310 ! this value such that the time step per unit cfl number is
311 ! stored and correct in cases of high gradients.
312  do k=2,kl
313  do j=2,jl
314  do i=2,il
315  if (p(i+1, j, k) - two*p(i, j, k) + p(i-1, j, k) .ge. 0.) &
316 & then
317  call pushreal8(abs3)
318  abs3 = p(i+1, j, k) - two*p(i, j, k) + p(i-1, j, k)
319  call pushcontrol1b(0)
320  else
321  call pushreal8(abs3)
322  abs3 = -(p(i+1, j, k)-two*p(i, j, k)+p(i-1, j, k))
323  call pushcontrol1b(1)
324  end if
325  call pushreal8(dpi)
326  dpi = abs3/(p(i+1, j, k)+two*p(i, j, k)+p(i-1, j, k)+plim)
327  if (p(i, j+1, k) - two*p(i, j, k) + p(i, j-1, k) .ge. 0.) &
328 & then
329  call pushreal8(abs4)
330  abs4 = p(i, j+1, k) - two*p(i, j, k) + p(i, j-1, k)
331  call pushcontrol1b(0)
332  else
333  call pushreal8(abs4)
334  abs4 = -(p(i, j+1, k)-two*p(i, j, k)+p(i, j-1, k))
335  call pushcontrol1b(1)
336  end if
337  call pushreal8(dpj)
338  dpj = abs4/(p(i, j+1, k)+two*p(i, j, k)+p(i, j-1, k)+plim)
339  if (p(i, j, k+1) - two*p(i, j, k) + p(i, j, k-1) .ge. 0.) &
340 & then
341  call pushreal8(abs5)
342  abs5 = p(i, j, k+1) - two*p(i, j, k) + p(i, j, k-1)
343  call pushcontrol1b(0)
344  else
345  call pushreal8(abs5)
346  abs5 = -(p(i, j, k+1)-two*p(i, j, k)+p(i, j, k-1))
347  call pushcontrol1b(1)
348  end if
349  call pushreal8(dpk)
350  dpk = abs5/(p(i, j, k+1)+two*p(i, j, k)+p(i, j, k-1)+plim)
351  rfl = one/(one+b*(dpi+dpj+dpk))
352  call pushreal8(dtl(i, j, k))
353  dtl(i, j, k) = rfl/dtl(i, j, k)
354  end do
355  end do
356  end do
357  plimd = 0.0_8
358  do k=kl,2,-1
359  do j=jl,2,-1
360  do i=il,2,-1
361  rfl = one/(one+b*(dpi+dpj+dpk))
362  call popreal8(dtl(i, j, k))
363  tempd0 = dtld(i, j, k)/dtl(i, j, k)
364  dtld(i, j, k) = -(rfl*tempd0/dtl(i, j, k))
365  rfld = tempd0
366  temp1 = one + b*(dpi+dpj+dpk)
367  tempd1 = -(b*one*rfld/temp1**2)
368  dpid = tempd1
369  dpjd = tempd1
370  dpkd = tempd1
371  call popreal8(dpk)
372  temp1 = p(i, j, k+1) + two*p(i, j, k) + p(i, j, k-1) + &
373 & plim
374  abs5d = dpkd/temp1
375  tempd0 = -(abs5*dpkd/temp1**2)
376  pd(i, j, k+1) = pd(i, j, k+1) + tempd0
377  pd(i, j, k) = pd(i, j, k) + two*tempd0
378  pd(i, j, k-1) = pd(i, j, k-1) + tempd0
379  plimd = plimd + tempd0
380  call popcontrol1b(branch)
381  if (branch .eq. 0) then
382  call popreal8(abs5)
383  pd(i, j, k+1) = pd(i, j, k+1) + abs5d
384  pd(i, j, k) = pd(i, j, k) - two*abs5d
385  pd(i, j, k-1) = pd(i, j, k-1) + abs5d
386  else
387  call popreal8(abs5)
388  pd(i, j, k) = pd(i, j, k) + two*abs5d
389  pd(i, j, k+1) = pd(i, j, k+1) - abs5d
390  pd(i, j, k-1) = pd(i, j, k-1) - abs5d
391  end if
392  call popreal8(dpj)
393  temp1 = p(i, j+1, k) + two*p(i, j, k) + p(i, j-1, k) + &
394 & plim
395  abs4d = dpjd/temp1
396  tempd0 = -(abs4*dpjd/temp1**2)
397  pd(i, j+1, k) = pd(i, j+1, k) + tempd0
398  pd(i, j, k) = pd(i, j, k) + two*tempd0
399  pd(i, j-1, k) = pd(i, j-1, k) + tempd0
400  plimd = plimd + tempd0
401  call popcontrol1b(branch)
402  if (branch .eq. 0) then
403  call popreal8(abs4)
404  pd(i, j+1, k) = pd(i, j+1, k) + abs4d
405  pd(i, j, k) = pd(i, j, k) - two*abs4d
406  pd(i, j-1, k) = pd(i, j-1, k) + abs4d
407  else
408  call popreal8(abs4)
409  pd(i, j, k) = pd(i, j, k) + two*abs4d
410  pd(i, j+1, k) = pd(i, j+1, k) - abs4d
411  pd(i, j-1, k) = pd(i, j-1, k) - abs4d
412  end if
413  call popreal8(dpi)
414  temp1 = p(i+1, j, k) + two*p(i, j, k) + p(i-1, j, k) + &
415 & plim
416  abs3d = dpid/temp1
417  tempd0 = -(abs3*dpid/temp1**2)
418  pd(i+1, j, k) = pd(i+1, j, k) + tempd0
419  pd(i, j, k) = pd(i, j, k) + two*tempd0
420  pd(i-1, j, k) = pd(i-1, j, k) + tempd0
421  plimd = plimd + tempd0
422  call popcontrol1b(branch)
423  if (branch .eq. 0) then
424  call popreal8(abs3)
425  pd(i+1, j, k) = pd(i+1, j, k) + abs3d
426  pd(i, j, k) = pd(i, j, k) - two*abs3d
427  pd(i-1, j, k) = pd(i-1, j, k) + abs3d
428  else
429  call popreal8(abs3)
430  pd(i, j, k) = pd(i, j, k) + two*abs3d
431  pd(i+1, j, k) = pd(i+1, j, k) - abs3d
432  pd(i-1, j, k) = pd(i-1, j, k) - abs3d
433  end if
434  end do
435  end do
436  end do
437  call popcontrol1b(branch)
438  if (branch .ne. 0) then
439  do k=kl,2,-1
440  do j=jl,2,-1
441  do i=il,2,-1
442  vold(i, j, k) = vold(i, j, k) + tmp*dtld(i, j, k)
443  end do
444  end do
445  end do
446  end if
447  call popcontrol1b(branch)
448  if (branch .eq. 0) then
449  do k=kl,2,-1
450  do j=jl,2,-1
451  do i=il,2,-1
452  vskd = dtld(i, j, k)
453  rmud = (sx**2+sy**2+sz**2)*vskd
454  tempd0 = rmu*vskd
455  sxd = 2*sx*tempd0
456  syd = 2*sy*tempd0
457  szd = 2*sz*tempd0
458  skd(i, j, k, 3) = skd(i, j, k, 3) + szd
459  skd(i, j, k-1, 3) = skd(i, j, k-1, 3) + szd
460  skd(i, j, k, 2) = skd(i, j, k, 2) + syd
461  skd(i, j, k-1, 2) = skd(i, j, k-1, 2) + syd
462  skd(i, j, k, 1) = skd(i, j, k, 1) + sxd
463  skd(i, j, k-1, 1) = skd(i, j, k-1, 1) + sxd
464  sy = sj(i, j, k, 2) + sj(i, j-1, k, 2)
465  sz = sj(i, j, k, 3) + sj(i, j-1, k, 3)
466  sx = sj(i, j, k, 1) + sj(i, j-1, k, 1)
467  vsjd = dtld(i, j, k)
468  rmud = rmud + (sx**2+sy**2+sz**2)*vsjd
469  tempd0 = rmu*vsjd
470  sxd = 2*sx*tempd0
471  syd = 2*sy*tempd0
472  szd = 2*sz*tempd0
473  sjd(i, j, k, 3) = sjd(i, j, k, 3) + szd
474  sjd(i, j-1, k, 3) = sjd(i, j-1, k, 3) + szd
475  sjd(i, j, k, 2) = sjd(i, j, k, 2) + syd
476  sjd(i, j-1, k, 2) = sjd(i, j-1, k, 2) + syd
477  sjd(i, j, k, 1) = sjd(i, j, k, 1) + sxd
478  sjd(i, j-1, k, 1) = sjd(i, j-1, k, 1) + sxd
479  sy = si(i, j, k, 2) + si(i-1, j, k, 2)
480  sz = si(i, j, k, 3) + si(i-1, j, k, 3)
481  sx = si(i, j, k, 1) + si(i-1, j, k, 1)
482  vsid = dtld(i, j, k)
483  rmud = rmud + (sx**2+sy**2+sz**2)*vsid
484  tempd0 = rmu*vsid
485  sxd = 2*sx*tempd0
486  syd = 2*sy*tempd0
487  szd = 2*sz*tempd0
488  call popreal8(sz)
489  sid(i, j, k, 3) = sid(i, j, k, 3) + szd
490  sid(i-1, j, k, 3) = sid(i-1, j, k, 3) + szd
491  call popreal8(sy)
492  sid(i, j, k, 2) = sid(i, j, k, 2) + syd
493  sid(i-1, j, k, 2) = sid(i-1, j, k, 2) + syd
494  call popreal8(sx)
495  sid(i, j, k, 1) = sid(i, j, k, 1) + sxd
496  sid(i-1, j, k, 1) = sid(i-1, j, k, 1) + sxd
497  call popreal8(rmu)
498  temp = w(i, j, k, irho)
499  temp0 = temp*vol(i, j, k)
500  tempd0 = half*rmud/temp0
501  rmud = tempd0
502  tempd1 = -(rmu*tempd0/temp0)
503  wd(i, j, k, irho) = wd(i, j, k, irho) + vol(i, j, k)*&
504 & tempd1
505  vold(i, j, k) = vold(i, j, k) + temp*tempd1
506  call popcontrol1b(branch)
507  if (branch .eq. 0) revd(i, j, k) = revd(i, j, k) + rmud
508  call popreal8(rmu)
509  rlvd(i, j, k) = rlvd(i, j, k) + rmud
510  end do
511  end do
512  end do
513  end if
514  else
515  plimd = 0.0_8
516  end if
517  call popcontrol2b(branch)
518  if (branch .lt. 2) then
519  if (branch .eq. 0) then
520  clim2d = 0.0_8
521  else
522  clim2d = 0.0_8
523  sfaced = 0.0_8
524  call popreal8(sface)
525 !$bwd-of ii-loop
526  do ii=0,ie*je*ke-1
527  i = mod(ii, ie) + 1
528  j = mod(ii/ie, je) + 1
529  k = ii/(ie*je) + 1
530 ! compute the velocities and speed of sound squared.
531  uux = w(i, j, k, ivx)
532  uuy = w(i, j, k, ivy)
533  uuz = w(i, j, k, ivz)
534  cc2 = gamma(i, j, k)*p(i, j, k)/w(i, j, k, irho)
535  if (cc2 .lt. clim2) then
536  cc2 = clim2
537  call pushcontrol1b(0)
538  else
539  call pushcontrol1b(1)
540  cc2 = cc2
541  end if
542 ! set the dot product of the grid velocity and the
543 ! normal in i-direction for a moving face. to avoid
544 ! a number of multiplications by 0.5 simply the sum
545 ! is taken.
546  if (addgridvelocities) then
547  sface = sfacei(i-1, j, k) + sfacei(i, j, k)
548  call pushcontrol1b(1)
549  else
550  call pushcontrol1b(0)
551  end if
552 ! spectral radius in i-direction.
553  sx = si(i-1, j, k, 1) + si(i, j, k, 1)
554  sy = si(i-1, j, k, 2) + si(i, j, k, 2)
555  sz = si(i-1, j, k, 3) + si(i, j, k, 3)
556  qsi = uux*sx + uuy*sy + uuz*sz - sface
557  if (qsi .ge. 0.) then
558  abs0 = qsi
559  call pushcontrol1b(0)
560  else
561  abs0 = -qsi
562  call pushcontrol1b(1)
563  end if
564  ri = half*(abs0+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz&
565 & **2)))
566 ! the grid velocity in j-direction.
567  if (addgridvelocities) then
568  sface = sfacej(i, j-1, k) + sfacej(i, j, k)
569  call pushcontrol1b(1)
570  else
571  call pushcontrol1b(0)
572  end if
573 ! spectral radius in j-direction.
574  sx = sj(i, j-1, k, 1) + sj(i, j, k, 1)
575  sy = sj(i, j-1, k, 2) + sj(i, j, k, 2)
576  sz = sj(i, j-1, k, 3) + sj(i, j, k, 3)
577  qsj = uux*sx + uuy*sy + uuz*sz - sface
578  if (qsj .ge. 0.) then
579  abs1 = qsj
580  call pushcontrol1b(0)
581  else
582  abs1 = -qsj
583  call pushcontrol1b(1)
584  end if
585  rj = half*(abs1+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz&
586 & **2)))
587 ! the grid velocity in k-direction.
588  if (addgridvelocities) then
589  sface = sfacek(i, j, k-1) + sfacek(i, j, k)
590  call pushcontrol1b(1)
591  else
592  call pushcontrol1b(0)
593  end if
594 ! spectral radius in k-direction.
595  sx = sk(i, j, k-1, 1) + sk(i, j, k, 1)
596  sy = sk(i, j, k-1, 2) + sk(i, j, k, 2)
597  sz = sk(i, j, k-1, 3) + sk(i, j, k, 3)
598  qsk = uux*sx + uuy*sy + uuz*sz - sface
599  if (qsk .ge. 0.) then
600  abs2 = qsk
601  call pushcontrol1b(0)
602  else
603  abs2 = -qsk
604  call pushcontrol1b(1)
605  end if
606  rk = half*(abs2+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz&
607 & **2)))
608 ! compute the inviscid contribution to the time step.
609  if (.not.onlyradii) then
610  call pushcontrol1b(0)
611  else
612  call pushcontrol1b(1)
613  end if
614 !
615 ! adapt the spectral radii if directional scaling must be
616 ! applied.
617 !
618  if (doscaling) then
619  if (ri .lt. eps) then
620  ri = eps
621  call pushcontrol1b(0)
622  else
623  call pushcontrol1b(1)
624  ri = ri
625  end if
626  if (rj .lt. eps) then
627  rj = eps
628  call pushcontrol1b(0)
629  else
630  call pushcontrol1b(1)
631  rj = rj
632  end if
633  if (rk .lt. eps) then
634  rk = eps
635  call pushcontrol1b(0)
636  else
637  call pushcontrol1b(1)
638  rk = rk
639  end if
640 ! compute the scaling in the three coordinate
641 ! directions.
642  rij = (ri/rj)**adis
643  rjk = (rj/rk)**adis
644  rki = (rk/ri)**adis
645 ! create the scaled versions of the aspect ratios.
646 ! note that the multiplication is done with radi, radj
647 ! and radk, such that the influence of the clipping
648 ! is negligible.
649  rkid = ri*radid(i, j, k) - one*rk*radkd(i, j, k)/rki**2
650  temp1 = rk/ri
651  if (temp1 .le. 0.0_8 .and. (adis .eq. 0.0_8 .or. adis .ne.&
652 & int(adis))) then
653  tempd0 = 0.0_8
654  else
655  tempd0 = adis*temp1**(adis-1)*rkid/ri
656  end if
657  rkd = (one+one/rki+rjk)*radkd(i, j, k) + tempd0
658  rjkd = rk*radkd(i, j, k) - one*rj*radjd(i, j, k)/rjk**2
659  radkd(i, j, k) = 0.0_8
660  rijd = rj*radjd(i, j, k) - one*ri*radid(i, j, k)/rij**2
661  rid = (one+one/rij+rki)*radid(i, j, k) - temp1*tempd0
662  radid(i, j, k) = 0.0_8
663  temp1 = rj/rk
664  if (temp1 .le. 0.0_8 .and. (adis .eq. 0.0_8 .or. adis .ne.&
665 & int(adis))) then
666  tempd0 = 0.0_8
667  else
668  tempd0 = adis*temp1**(adis-1)*rjkd/rk
669  end if
670  rjd = (one+one/rjk+rij)*radjd(i, j, k) + tempd0
671  radjd(i, j, k) = 0.0_8
672  rkd = rkd - temp1*tempd0
673  temp1 = ri/rj
674  if (temp1 .le. 0.0_8 .and. (adis .eq. 0.0_8 .or. adis .ne.&
675 & int(adis))) then
676  tempd0 = 0.0_8
677  else
678  tempd0 = adis*temp1**(adis-1)*rijd/rj
679  end if
680  rid = rid + tempd0
681  rjd = rjd - temp1*tempd0
682  call popcontrol1b(branch)
683  if (branch .eq. 0) rkd = 0.0_8
684  call popcontrol1b(branch)
685  if (branch .eq. 0) rjd = 0.0_8
686  call popcontrol1b(branch)
687  if (branch .eq. 0) rid = 0.0_8
688  else
689  rkd = radkd(i, j, k)
690  radkd(i, j, k) = 0.0_8
691  rjd = radjd(i, j, k)
692  radjd(i, j, k) = 0.0_8
693  rid = radid(i, j, k)
694  radid(i, j, k) = 0.0_8
695  end if
696  call popcontrol1b(branch)
697  if (branch .eq. 0) then
698  rid = rid + dtld(i, j, k)
699  rjd = rjd + dtld(i, j, k)
700  rkd = rkd + dtld(i, j, k)
701  dtld(i, j, k) = 0.0_8
702  end if
703  temp1 = sx*sx + sy*sy + sz*sz
704  abs2d = half*rkd
705  if (cc2*temp1 .eq. 0.0_8) then
706  tempd1 = 0.0_8
707  else
708  tempd1 = acousticscalefactor*half*rkd/(2.0*sqrt(cc2*temp1)&
709 & )
710  end if
711  cc2d = temp1*tempd1
712  tempd0 = cc2*tempd1
713  sxd = 2*sx*tempd0
714  syd = 2*sy*tempd0
715  szd = 2*sz*tempd0
716  call popcontrol1b(branch)
717  if (branch .eq. 0) then
718  qskd = abs2d
719  else
720  qskd = -abs2d
721  end if
722  uuxd = sx*qskd
723  sxd = sxd + uux*qskd
724  uuyd = sy*qskd
725  syd = syd + uuy*qskd
726  uuzd = sz*qskd
727  szd = szd + uuz*qskd
728  sfaced = sfaced - qskd
729  skd(i, j, k-1, 3) = skd(i, j, k-1, 3) + szd
730  skd(i, j, k, 3) = skd(i, j, k, 3) + szd
731  skd(i, j, k-1, 2) = skd(i, j, k-1, 2) + syd
732  skd(i, j, k, 2) = skd(i, j, k, 2) + syd
733  skd(i, j, k-1, 1) = skd(i, j, k-1, 1) + sxd
734  skd(i, j, k, 1) = skd(i, j, k, 1) + sxd
735  call popcontrol1b(branch)
736  if (branch .ne. 0) then
737  sfacekd(i, j, k-1) = sfacekd(i, j, k-1) + sfaced
738  sfacekd(i, j, k) = sfacekd(i, j, k) + sfaced
739  sfaced = 0.0_8
740  end if
741  sx = sj(i, j-1, k, 1) + sj(i, j, k, 1)
742  sy = sj(i, j-1, k, 2) + sj(i, j, k, 2)
743  sz = sj(i, j-1, k, 3) + sj(i, j, k, 3)
744  temp1 = sx*sx + sy*sy + sz*sz
745  abs1d = half*rjd
746  if (cc2*temp1 .eq. 0.0_8) then
747  tempd1 = 0.0_8
748  else
749  tempd1 = acousticscalefactor*half*rjd/(2.0*sqrt(cc2*temp1)&
750 & )
751  end if
752  cc2d = cc2d + temp1*tempd1
753  tempd0 = cc2*tempd1
754  sxd = 2*sx*tempd0
755  syd = 2*sy*tempd0
756  szd = 2*sz*tempd0
757  call popcontrol1b(branch)
758  if (branch .eq. 0) then
759  qsjd = abs1d
760  else
761  qsjd = -abs1d
762  end if
763  uuxd = uuxd + sx*qsjd
764  sxd = sxd + uux*qsjd
765  uuyd = uuyd + sy*qsjd
766  syd = syd + uuy*qsjd
767  uuzd = uuzd + sz*qsjd
768  szd = szd + uuz*qsjd
769  sfaced = sfaced - qsjd
770  sjd(i, j-1, k, 3) = sjd(i, j-1, k, 3) + szd
771  sjd(i, j, k, 3) = sjd(i, j, k, 3) + szd
772  sjd(i, j-1, k, 2) = sjd(i, j-1, k, 2) + syd
773  sjd(i, j, k, 2) = sjd(i, j, k, 2) + syd
774  sjd(i, j-1, k, 1) = sjd(i, j-1, k, 1) + sxd
775  sjd(i, j, k, 1) = sjd(i, j, k, 1) + sxd
776  call popcontrol1b(branch)
777  if (branch .ne. 0) then
778  sfacejd(i, j-1, k) = sfacejd(i, j-1, k) + sfaced
779  sfacejd(i, j, k) = sfacejd(i, j, k) + sfaced
780  sfaced = 0.0_8
781  end if
782  sx = si(i-1, j, k, 1) + si(i, j, k, 1)
783  sy = si(i-1, j, k, 2) + si(i, j, k, 2)
784  sz = si(i-1, j, k, 3) + si(i, j, k, 3)
785  temp1 = sx*sx + sy*sy + sz*sz
786  abs0d = half*rid
787  if (cc2*temp1 .eq. 0.0_8) then
788  tempd1 = 0.0_8
789  else
790  tempd1 = acousticscalefactor*half*rid/(2.0*sqrt(cc2*temp1)&
791 & )
792  end if
793  cc2d = cc2d + temp1*tempd1
794  tempd0 = cc2*tempd1
795  sxd = 2*sx*tempd0
796  syd = 2*sy*tempd0
797  szd = 2*sz*tempd0
798  call popcontrol1b(branch)
799  if (branch .eq. 0) then
800  qsid = abs0d
801  else
802  qsid = -abs0d
803  end if
804  uuxd = uuxd + sx*qsid
805  sxd = sxd + uux*qsid
806  uuyd = uuyd + sy*qsid
807  syd = syd + uuy*qsid
808  uuzd = uuzd + sz*qsid
809  szd = szd + uuz*qsid
810  sfaced = sfaced - qsid
811  sid(i-1, j, k, 3) = sid(i-1, j, k, 3) + szd
812  sid(i, j, k, 3) = sid(i, j, k, 3) + szd
813  sid(i-1, j, k, 2) = sid(i-1, j, k, 2) + syd
814  sid(i, j, k, 2) = sid(i, j, k, 2) + syd
815  sid(i-1, j, k, 1) = sid(i-1, j, k, 1) + sxd
816  sid(i, j, k, 1) = sid(i, j, k, 1) + sxd
817  call popcontrol1b(branch)
818  if (branch .ne. 0) then
819  sfaceid(i-1, j, k) = sfaceid(i-1, j, k) + sfaced
820  sfaceid(i, j, k) = sfaceid(i, j, k) + sfaced
821  sfaced = 0.0_8
822  end if
823  call popcontrol1b(branch)
824  if (branch .eq. 0) then
825  clim2d = clim2d + cc2d
826  cc2d = 0.0_8
827  end if
828  temp1 = w(i, j, k, irho)
829  tempd1 = gamma(i, j, k)*cc2d/temp1
830  pd(i, j, k) = pd(i, j, k) + tempd1
831  wd(i, j, k, irho) = wd(i, j, k, irho) - p(i, j, k)*tempd1/&
832 & temp1
833  wd(i, j, k, ivz) = wd(i, j, k, ivz) + uuzd
834  wd(i, j, k, ivy) = wd(i, j, k, ivy) + uuyd
835  wd(i, j, k, ivx) = wd(i, j, k, ivx) + uuxd
836  end do
837  end if
838  else if (branch .eq. 2) then
839  clim2d = 0.0_8
840  else
841  clim2d = 0.0_8
842  end if
843  tempd = gammainf*0.000001_realtype*clim2d/rhoinf
844  pinfcorrd = pinfcorrd + tempd + 0.001_realtype*plimd
845  rhoinfd = rhoinfd - pinfcorr*tempd/rhoinf
846  end if
847  end subroutine timestep_block_b
848 
849  subroutine timestep_block(onlyradii)
850 !
851 ! timestep computes the time step, or more precisely the time
852 ! step divided by the volume per unit cfl, in the owned cells.
853 ! however, for the artificial dissipation schemes, the spectral
854 ! radii in the halo's are needed. therefore the loop is taken
855 ! over the the first level of halo cells. the spectral radii are
856 ! stored and possibly modified for high aspect ratio cells.
857 !
858  use constants
859  use blockpointers, only : ie, je, ke, il, jl, kl, w, p, rlv, rev, &
860 & radi, radj, radk, si, sj, sk, sfacei, sfacej, sfacek, dtl, gamma, &
863 & , viscous, rhoinf
866  use inputphysics, only : equationmode
867  use iteration, only : groundlevel, currentlevel
868  use section, only : sections
870  use utils_b, only : terminate
871  implicit none
872 !
873 ! subroutine argument.
874 !
875  logical, intent(in) :: onlyradii
876 !
877 ! local parameters.
878 !
879  real(kind=realtype), parameter :: b=2.0_realtype
880 !
881 ! local variables.
882 !
883  integer(kind=inttype) :: i, j, k, ii
884  real(kind=realtype) :: plim, rlim, clim2
885  real(kind=realtype) :: uux, uuy, uuz, cc2, qsi, qsj, qsk, sx, sy, sz&
886 & , rmu
887  real(kind=realtype) :: ri, rj, rk, rij, rjk, rki
888  real(kind=realtype) :: vsi, vsj, vsk, rfl, dpi, dpj, dpk
889  real(kind=realtype) :: sface, tmp
890  logical :: radiineeded, doscaling
891  intrinsic mod
892  intrinsic max
893  intrinsic abs
894  intrinsic sqrt
895  real(kind=realtype) :: abs0
896  real(kind=realtype) :: abs1
897  real(kind=realtype) :: abs2
898  real(kind=realtype) :: abs3
899  real(kind=realtype) :: abs4
900  real(kind=realtype) :: abs5
901 ! determine whether or not the spectral radii are needed for the
902 ! flux computation.
903  radiineeded = radiineededcoarse
904  if (currentlevel .le. groundlevel) radiineeded = radiineededfine
905 ! return immediately if only the spectral radii must be computed
906 ! and these are not needed for the flux computation.
907  if (onlyradii .and. (.not.radiineeded)) then
908  return
909  else
910 ! set the value of plim. to be fully consistent this must have
911 ! the dimension of a pressure. therefore a fraction of pinfcorr
912 ! is used. idem for rlim; compute clim2 as well.
913  plim = 0.001_realtype*pinfcorr
914  rlim = 0.001_realtype*rhoinf
915  clim2 = 0.000001_realtype*gammainf*pinfcorr/rhoinf
916  doscaling = dirscaling .and. currentlevel .le. groundlevel
917 ! initialize sface to zero. this value will be used if the
918 ! block is not moving.
919  sface = zero
920 !
921 ! inviscid contribution, depending on the preconditioner.
922 ! compute the cell centered values of the spectral radii.
923 !
924  select case (precond)
925  case (noprecond)
926 !$ad ii-loop
927 ! no preconditioner. simply the standard spectral radius.
928 ! loop over the cells, including the first level halo.
929  do ii=0,ie*je*ke-1
930  i = mod(ii, ie) + 1
931  j = mod(ii/ie, je) + 1
932  k = ii/(ie*je) + 1
933 ! compute the velocities and speed of sound squared.
934  uux = w(i, j, k, ivx)
935  uuy = w(i, j, k, ivy)
936  uuz = w(i, j, k, ivz)
937  cc2 = gamma(i, j, k)*p(i, j, k)/w(i, j, k, irho)
938  if (cc2 .lt. clim2) then
939  cc2 = clim2
940  else
941  cc2 = cc2
942  end if
943 ! set the dot product of the grid velocity and the
944 ! normal in i-direction for a moving face. to avoid
945 ! a number of multiplications by 0.5 simply the sum
946 ! is taken.
947  if (addgridvelocities) sface = sfacei(i-1, j, k) + sfacei(i, j&
948 & , k)
949 ! spectral radius in i-direction.
950  sx = si(i-1, j, k, 1) + si(i, j, k, 1)
951  sy = si(i-1, j, k, 2) + si(i, j, k, 2)
952  sz = si(i-1, j, k, 3) + si(i, j, k, 3)
953  qsi = uux*sx + uuy*sy + uuz*sz - sface
954  if (qsi .ge. 0.) then
955  abs0 = qsi
956  else
957  abs0 = -qsi
958  end if
959  ri = half*(abs0+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz**&
960 & 2)))
961 ! the grid velocity in j-direction.
962  if (addgridvelocities) sface = sfacej(i, j-1, k) + sfacej(i, j&
963 & , k)
964 ! spectral radius in j-direction.
965  sx = sj(i, j-1, k, 1) + sj(i, j, k, 1)
966  sy = sj(i, j-1, k, 2) + sj(i, j, k, 2)
967  sz = sj(i, j-1, k, 3) + sj(i, j, k, 3)
968  qsj = uux*sx + uuy*sy + uuz*sz - sface
969  if (qsj .ge. 0.) then
970  abs1 = qsj
971  else
972  abs1 = -qsj
973  end if
974  rj = half*(abs1+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz**&
975 & 2)))
976 ! the grid velocity in k-direction.
977  if (addgridvelocities) sface = sfacek(i, j, k-1) + sfacek(i, j&
978 & , k)
979 ! spectral radius in k-direction.
980  sx = sk(i, j, k-1, 1) + sk(i, j, k, 1)
981  sy = sk(i, j, k-1, 2) + sk(i, j, k, 2)
982  sz = sk(i, j, k-1, 3) + sk(i, j, k, 3)
983  qsk = uux*sx + uuy*sy + uuz*sz - sface
984  if (qsk .ge. 0.) then
985  abs2 = qsk
986  else
987  abs2 = -qsk
988  end if
989  rk = half*(abs2+acousticscalefactor*sqrt(cc2*(sx**2+sy**2+sz**&
990 & 2)))
991 ! compute the inviscid contribution to the time step.
992  if (.not.onlyradii) dtl(i, j, k) = ri + rj + rk
993 !
994 ! adapt the spectral radii if directional scaling must be
995 ! applied.
996 !
997  if (doscaling) then
998  if (ri .lt. eps) then
999  ri = eps
1000  else
1001  ri = ri
1002  end if
1003  if (rj .lt. eps) then
1004  rj = eps
1005  else
1006  rj = rj
1007  end if
1008  if (rk .lt. eps) then
1009  rk = eps
1010  else
1011  rk = rk
1012  end if
1013 ! compute the scaling in the three coordinate
1014 ! directions.
1015  rij = (ri/rj)**adis
1016  rjk = (rj/rk)**adis
1017  rki = (rk/ri)**adis
1018 ! create the scaled versions of the aspect ratios.
1019 ! note that the multiplication is done with radi, radj
1020 ! and radk, such that the influence of the clipping
1021 ! is negligible.
1022  radi(i, j, k) = ri*(one+one/rij+rki)
1023  radj(i, j, k) = rj*(one+one/rjk+rij)
1024  radk(i, j, k) = rk*(one+one/rki+rjk)
1025  else
1026  radi(i, j, k) = ri
1027  radj(i, j, k) = rj
1028  radk(i, j, k) = rk
1029  end if
1030  end do
1031  case (turkel)
1032  call terminate('timestep', &
1033 & 'turkel preconditioner not implemented yet')
1034  case (choimerkle)
1035  call terminate('timestep', &
1036 & 'choi merkle preconditioner not implemented yet')
1037  end select
1038 ! the rest of this file can be skipped if only the spectral
1039 ! radii need to be computed.
1040  if (.not.onlyradii) then
1041 ! the viscous contribution, if needed.
1042  if (viscous) then
1043 ! loop over the owned cell centers.
1044  do k=2,kl
1045  do j=2,jl
1046  do i=2,il
1047 ! compute the effective viscosity coefficient. the
1048 ! factor 0.5 is a combination of two things. in the
1049 ! standard central discretization of a second
1050 ! derivative there is a factor 2 multiplying the
1051 ! central node. however in the code below not the
1052 ! average but the sum of the left and the right face
1053 ! is taken and squared. this leads to a factor 4.
1054 ! combining both effects leads to 0.5. furthermore,
1055 ! it is divided by the volume and density to obtain
1056 ! the correct dimensions and multiplied by the
1057 ! non-dimensional factor factvis.
1058  rmu = rlv(i, j, k)
1059  if (eddymodel) rmu = rmu + rev(i, j, k)
1060  rmu = half*rmu/(w(i, j, k, irho)*vol(i, j, k))
1061 ! add the viscous contribution in i-direction to the
1062 ! (inverse) of the time step.
1063  sx = si(i, j, k, 1) + si(i-1, j, k, 1)
1064  sy = si(i, j, k, 2) + si(i-1, j, k, 2)
1065  sz = si(i, j, k, 3) + si(i-1, j, k, 3)
1066  vsi = rmu*(sx*sx+sy*sy+sz*sz)
1067  dtl(i, j, k) = dtl(i, j, k) + vsi
1068 ! add the viscous contribution in j-direction to the
1069 ! (inverse) of the time step.
1070  sx = sj(i, j, k, 1) + sj(i, j-1, k, 1)
1071  sy = sj(i, j, k, 2) + sj(i, j-1, k, 2)
1072  sz = sj(i, j, k, 3) + sj(i, j-1, k, 3)
1073  vsj = rmu*(sx*sx+sy*sy+sz*sz)
1074  dtl(i, j, k) = dtl(i, j, k) + vsj
1075 ! add the viscous contribution in k-direction to the
1076 ! (inverse) of the time step.
1077  sx = sk(i, j, k, 1) + sk(i, j, k-1, 1)
1078  sy = sk(i, j, k, 2) + sk(i, j, k-1, 2)
1079  sz = sk(i, j, k, 3) + sk(i, j, k-1, 3)
1080  vsk = rmu*(sx*sx+sy*sy+sz*sz)
1081  dtl(i, j, k) = dtl(i, j, k) + vsk
1082  end do
1083  end do
1084  end do
1085  end if
1086 ! for the spectral mode an additional term term must be
1087 ! taken into account, which corresponds to the contribution
1088 ! of the highest frequency.
1089  if (equationmode .eq. timespectral) then
1091 & timeperiod
1092 ! loop over the owned cell centers and add the term.
1093  do k=2,kl
1094  do j=2,jl
1095  do i=2,il
1096  dtl(i, j, k) = dtl(i, j, k) + tmp*vol(i, j, k)
1097  end do
1098  end do
1099  end do
1100  end if
1101 ! currently the inverse of dt/vol is stored in dtl. invert
1102 ! this value such that the time step per unit cfl number is
1103 ! stored and correct in cases of high gradients.
1104  do k=2,kl
1105  do j=2,jl
1106  do i=2,il
1107  if (p(i+1, j, k) - two*p(i, j, k) + p(i-1, j, k) .ge. 0.) &
1108 & then
1109  abs3 = p(i+1, j, k) - two*p(i, j, k) + p(i-1, j, k)
1110  else
1111  abs3 = -(p(i+1, j, k)-two*p(i, j, k)+p(i-1, j, k))
1112  end if
1113  dpi = abs3/(p(i+1, j, k)+two*p(i, j, k)+p(i-1, j, k)+plim)
1114  if (p(i, j+1, k) - two*p(i, j, k) + p(i, j-1, k) .ge. 0.) &
1115 & then
1116  abs4 = p(i, j+1, k) - two*p(i, j, k) + p(i, j-1, k)
1117  else
1118  abs4 = -(p(i, j+1, k)-two*p(i, j, k)+p(i, j-1, k))
1119  end if
1120  dpj = abs4/(p(i, j+1, k)+two*p(i, j, k)+p(i, j-1, k)+plim)
1121  if (p(i, j, k+1) - two*p(i, j, k) + p(i, j, k-1) .ge. 0.) &
1122 & then
1123  abs5 = p(i, j, k+1) - two*p(i, j, k) + p(i, j, k-1)
1124  else
1125  abs5 = -(p(i, j, k+1)-two*p(i, j, k)+p(i, j, k-1))
1126  end if
1127  dpk = abs5/(p(i, j, k+1)+two*p(i, j, k)+p(i, j, k-1)+plim)
1128  rfl = one/(one+b*(dpi+dpj+dpk))
1129  dtl(i, j, k) = rfl/dtl(i, j, k)
1130  end do
1131  end do
1132  end do
1133  end if
1134  end if
1135  end subroutine timestep_block
1136 
1137 ! differentiation of gridvelocitiesfinelevel_block in reverse (adjoint) mode (with options noisize i4 dr8 r8):
1138 ! gradient of useful results: *(flowdoms.x) veldirfreestream
1139 ! *sfacei *sfacej *sfacek *s *si *sj *sk
1140 ! with respect to varying inputs: pinf timeref rhoinf *(flowdoms.x)
1141 ! veldirfreestream machgrid *sfacei *sfacej *sfacek
1142 ! *s *si *sj *sk
1143 ! rw status of diff variables: pinf:out timeref:out rhoinf:out
1144 ! *(flowdoms.x):incr veldirfreestream:incr machgrid:out
1145 ! *sfacei:in-out *sfacej:in-out *sfacek:in-out *s:in-out
1146 ! *si:incr *sj:incr *sk:incr
1147 ! plus diff mem management of: flowdoms.x:in sfacei:in sfacej:in
1148 ! sfacek:in s:in si:in sj:in sk:in
1149  subroutine gridvelocitiesfinelevel_block_b(useoldcoor, t, sps, nn)
1150 !
1151 ! gridvelocitiesfinelevel computes the grid velocities for
1152 ! the cell centers and the normal grid velocities for the faces
1153 ! of moving blocks for the currently finest grid, i.e.
1154 ! groundlevel. the velocities are computed at time t for
1155 ! spectral mode sps. if useoldcoor is .true. the velocities
1156 ! are determined using the unsteady time integrator in
1157 ! combination with the old coordinates; otherwise the analytic
1158 ! form is used.
1159 !
1160  use blockpointers
1161  use cgnsgrid
1162  use flowvarrefstate
1163  use inputmotion
1164  use inputunsteady
1165  use iteration
1166  use inputphysics
1167  use inputtsstabderiv
1168  use monitor
1169  use communication
1170  use flowutils_b, only : derivativerotmatrixrigid, &
1174  implicit none
1175 !
1176 ! subroutine arguments.
1177 !
1178  integer(kind=inttype), intent(in) :: sps, nn
1179  logical, intent(in) :: useoldcoor
1180  real(kind=realtype), dimension(*), intent(in) :: t
1181 !
1182 ! local variables.
1183 !
1184  integer(kind=inttype) :: mm
1185  integer(kind=inttype) :: i, j, k, ii, iie, jje, kke
1186  real(kind=realtype) :: oneover4dt, oneover8dt
1187  real(kind=realtype) :: velxgrid, velygrid, velzgrid, ainf
1188  real(kind=realtype) :: velxgridd, velygridd, velzgridd, ainfd
1189  real(kind=realtype) :: velxgrid0, velygrid0, velzgrid0
1190  real(kind=realtype) :: velxgrid0d, velygrid0d, velzgrid0d
1191  real(kind=realtype), dimension(3) :: sc, xc, xxc
1192  real(kind=realtype), dimension(3) :: scd, xcd, xxcd
1193  real(kind=realtype), dimension(3) :: rotcenter, rotrate
1194  real(kind=realtype), dimension(3) :: rotcenterd, rotrated
1195  real(kind=realtype), dimension(3) :: rotationpoint
1196  real(kind=realtype), dimension(3, 3) :: rotationmatrix, &
1197 & derivrotationmatrix
1198  real(kind=realtype), dimension(3, 3) :: derivrotationmatrixd
1199  real(kind=realtype) :: tnew, told
1200  real(kind=realtype), dimension(:, :), pointer :: sface
1201  real(kind=realtype), dimension(:, :, :), pointer :: xx, ss
1202  real(kind=realtype), dimension(:, :, :, :), pointer :: xxold
1203  real(kind=realtype) :: intervalmach, alphats, alphaincrement, betats&
1204 & , betaincrement
1205  real(kind=realtype), dimension(3) :: veldir
1206  real(kind=realtype), dimension(3) :: refdirection
1207  intrinsic sqrt
1208  real(kind=realtype) :: tempd
1209 ! compute the mesh velocity from the given mesh mach number.
1210 ! vel{x,y,z}grid0 is the actual velocity you want at the
1211 ! geometry.
1212  ainf = sqrt(gammainf*pinf/rhoinf)
1213  velxgrid0 = ainf*machgrid*(-veldirfreestream(1))
1214  velygrid0 = ainf*machgrid*(-veldirfreestream(2))
1215  velzgrid0 = ainf*machgrid*(-veldirfreestream(3))
1216 ! compute the derivative of the rotation matrix and the rotation
1217 ! point; needed for velocity due to the rigid body rotation of
1218 ! the entire grid. it is assumed that the rigid body motion of
1219 ! the grid is only specified if there is only 1 section present.
1220  call derivativerotmatrixrigid(derivrotationmatrix, rotationpoint, t(&
1221 & 1))
1222 !compute the rotation matrix to update the velocities for the time
1223 !spectral stability derivative case...
1224  if (blockismoving) then
1225 ! determine the situation we are having here.
1226  if (useoldcoor) then
1227  timerefd = 0.0_8
1228  velxgrid0d = 0.0_8
1229  velzgrid0d = 0.0_8
1230  derivrotationmatrixd = 0.0_8
1231  velygrid0d = 0.0_8
1232  else
1233 !
1234 ! the velocities must be determined analytically.
1235 !
1236 ! store the rotation center and determine the
1237 ! nondimensional rotation rate of this block. as the
1238 ! reference length is 1 timeref == 1/uref and at the end
1239 ! the nondimensional velocity is computed.
1240  j = nbkglobal
1241  rotcenter = cgnsdoms(j)%rotcenter
1242  rotrate = timeref*cgnsdoms(j)%rotrate
1243  velxgrid = velxgrid0
1244  velygrid = velygrid0
1245  velzgrid = velzgrid0
1246 !
1247 ! grid velocities of the cell centers, including the
1248 ! 1st level halo cells.
1249 !
1250 ! loop over the cells, including the 1st level halo's.
1251  do k=1,ke
1252  call pushinteger4(j)
1253  do j=1,je
1254  do i=1,ie
1255 ! determine the coordinates of the cell center,
1256 ! which are stored in xc.
1257  xc(1) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
1258 & , k-1, 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
1259 & 1)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 1)+&
1260 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+flowdoms(&
1261 & nn, groundlevel, sps)%x(i-1, j-1, k, 1)+flowdoms(nn, &
1262 & groundlevel, sps)%x(i, j-1, k, 1)+flowdoms(nn, &
1263 & groundlevel, sps)%x(i-1, j, k, 1)+flowdoms(nn, &
1264 & groundlevel, sps)%x(i, j, k, 1))
1265  xc(2) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
1266 & , k-1, 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
1267 & 2)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 2)+&
1268 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+flowdoms(&
1269 & nn, groundlevel, sps)%x(i-1, j-1, k, 2)+flowdoms(nn, &
1270 & groundlevel, sps)%x(i, j-1, k, 2)+flowdoms(nn, &
1271 & groundlevel, sps)%x(i-1, j, k, 2)+flowdoms(nn, &
1272 & groundlevel, sps)%x(i, j, k, 2))
1273  xc(3) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
1274 & , k-1, 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
1275 & 3)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 3)+&
1276 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+flowdoms(&
1277 & nn, groundlevel, sps)%x(i-1, j-1, k, 3)+flowdoms(nn, &
1278 & groundlevel, sps)%x(i, j-1, k, 3)+flowdoms(nn, &
1279 & groundlevel, sps)%x(i-1, j, k, 3)+flowdoms(nn, &
1280 & groundlevel, sps)%x(i, j, k, 3))
1281 ! determine the coordinates relative to the
1282 ! center of rotation.
1283  call pushreal8(xxc(1))
1284  xxc(1) = xc(1) - rotcenter(1)
1285  call pushreal8(xxc(2))
1286  xxc(2) = xc(2) - rotcenter(2)
1287  call pushreal8(xxc(3))
1288  xxc(3) = xc(3) - rotcenter(3)
1289 ! determine the rotation speed of the cell center,
1290 ! which is omega*r.
1291  sc(1) = rotrate(2)*xxc(3) - rotrate(3)*xxc(2)
1292  sc(2) = rotrate(3)*xxc(1) - rotrate(1)*xxc(3)
1293  sc(3) = rotrate(1)*xxc(2) - rotrate(2)*xxc(1)
1294 ! determine the coordinates relative to the
1295 ! rigid body rotation point.
1296  call pushreal8(xxc(1))
1297  xxc(1) = xc(1) - rotationpoint(1)
1298  call pushreal8(xxc(2))
1299  xxc(2) = xc(2) - rotationpoint(2)
1300  call pushreal8(xxc(3))
1301  xxc(3) = xc(3) - rotationpoint(3)
1302 ! determine the total velocity of the cell center.
1303 ! this is a combination of rotation speed of this
1304 ! block and the entire rigid body rotation.
1305  end do
1306  end do
1307  end do
1308 !
1309 ! normal grid velocities of the faces.
1310 !
1311 ! loop over the three directions.
1312 ! the original code is elegant but the tapenade has a difficult time
1313 ! to understand it. thus, we unfold it and make it easier for the
1314 ! tapenade.
1315 ! i-direction
1316  do k=1,ke
1317  call pushinteger4(j)
1318  do j=1,je
1319  do i=0,ie
1320 ! determine the coordinates of the face center,
1321 ! which are stored in xc.
1322  call pushreal8(xc(1))
1323  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1324 & -1, 1)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+&
1325 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 1)+flowdoms(&
1326 & nn, groundlevel, sps)%x(i, j, k, 1))
1327  call pushreal8(xc(2))
1328  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1329 & -1, 2)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+&
1330 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 2)+flowdoms(&
1331 & nn, groundlevel, sps)%x(i, j, k, 2))
1332  call pushreal8(xc(3))
1333  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1334 & -1, 3)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+&
1335 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 3)+flowdoms(&
1336 & nn, groundlevel, sps)%x(i, j, k, 3))
1337  call pushreal8array(sc, 3)
1338  call cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
1339 & velygrid, velzgrid, derivrotationmatrix&
1340 & , sc)
1341 ! store the dot product of grid velocity sc and
1342 ! the normal ss in sface.
1343  end do
1344  end do
1345  end do
1346 ! j-direction
1347  do k=1,ke
1348  call pushinteger4(j)
1349  do j=0,je
1350  do i=1,ie
1351 ! determine the coordinates of the face center,
1352 ! which are stored in xc.
1353  call pushreal8(xc(1))
1354  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
1355 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+&
1356 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 1)+&
1357 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 1))
1358  call pushreal8(xc(2))
1359  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
1360 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+&
1361 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 2)+&
1362 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 2))
1363  call pushreal8(xc(3))
1364  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
1365 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+&
1366 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 3)+&
1367 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 3))
1368  call pushreal8array(sc, 3)
1369  call cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
1370 & velygrid, velzgrid, derivrotationmatrix&
1371 & , sc)
1372 ! store the dot product of grid velocity sc and
1373 ! the normal ss in sface.
1374  end do
1375  end do
1376  end do
1377 ! k-direction
1378  do k=0,ke
1379  call pushinteger4(j)
1380  do j=1,je
1381  do i=1,ie
1382 ! determine the coordinates of the face center,
1383 ! which are stored in xc.
1384  call pushreal8(xc(1))
1385  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1386 & , 1)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 1)+&
1387 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 1)+&
1388 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 1))
1389  call pushreal8(xc(2))
1390  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1391 & , 2)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 2)+&
1392 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 2)+&
1393 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 2))
1394  call pushreal8(xc(3))
1395  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1396 & , 3)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 3)+&
1397 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 3)+&
1398 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 3))
1399  call pushreal8array(sc, 3)
1400  call cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
1401 & velygrid, velzgrid, derivrotationmatrix&
1402 & , sc)
1403 ! store the dot product of grid velocity sc and
1404 ! the normal ss in sface.
1405  end do
1406  end do
1407  end do
1408  rotrated = 0.0_8
1409  velygridd = 0.0_8
1410  xcd = 0.0_8
1411  velzgridd = 0.0_8
1412  derivrotationmatrixd = 0.0_8
1413  scd = 0.0_8
1414  velxgridd = 0.0_8
1415  do k=ke,0,-1
1416  do j=je,1,-1
1417  do i=ie,1,-1
1418  scd(1) = scd(1) + sk(i, j, k, 1)*sfacekd(i, j, k)
1419  skd(i, j, k, 1) = skd(i, j, k, 1) + sc(1)*sfacekd(i, j, k)
1420  scd(2) = scd(2) + sk(i, j, k, 2)*sfacekd(i, j, k)
1421  skd(i, j, k, 2) = skd(i, j, k, 2) + sc(2)*sfacekd(i, j, k)
1422  scd(3) = scd(3) + sk(i, j, k, 3)*sfacekd(i, j, k)
1423  skd(i, j, k, 3) = skd(i, j, k, 3) + sc(3)*sfacekd(i, j, k)
1424  sfacekd(i, j, k) = 0.0_8
1425  call popreal8array(sc, 3)
1426  call cellfacevelocities_b(xc, xcd, rotcenter, rotcenterd, &
1427 & rotrate, rotrated, velxgrid, velxgridd&
1428 & , velygrid, velygridd, velzgrid, &
1429 & velzgridd, derivrotationmatrix, &
1430 & derivrotationmatrixd, sc, scd)
1431  call popreal8(xc(3))
1432  tempd = fourth*xcd(3)
1433  xcd(3) = 0.0_8
1434  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 3) = &
1435 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 3) + tempd
1436  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 3) = &
1437 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 3) + tempd
1438  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 3) = &
1439 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 3) + &
1440 & tempd
1441  flowdomsd(nn, groundlevel, sps)%x(i, j, k, 3) = flowdomsd(&
1442 & nn, groundlevel, sps)%x(i, j, k, 3) + tempd
1443  call popreal8(xc(2))
1444  tempd = fourth*xcd(2)
1445  xcd(2) = 0.0_8
1446  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 2) = &
1447 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 2) + tempd
1448  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 2) = &
1449 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 2) + tempd
1450  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 2) = &
1451 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 2) + &
1452 & tempd
1453  flowdomsd(nn, groundlevel, sps)%x(i, j, k, 2) = flowdomsd(&
1454 & nn, groundlevel, sps)%x(i, j, k, 2) + tempd
1455  call popreal8(xc(1))
1456  tempd = fourth*xcd(1)
1457  xcd(1) = 0.0_8
1458  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 1) = &
1459 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 1) + tempd
1460  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 1) = &
1461 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 1) + tempd
1462  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 1) = &
1463 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 1) + &
1464 & tempd
1465  flowdomsd(nn, groundlevel, sps)%x(i, j, k, 1) = flowdomsd(&
1466 & nn, groundlevel, sps)%x(i, j, k, 1) + tempd
1467  end do
1468  end do
1469  call popinteger4(j)
1470  end do
1471  do k=ke,1,-1
1472  do j=je,0,-1
1473  do i=ie,1,-1
1474  scd(1) = scd(1) + sj(i, j, k, 1)*sfacejd(i, j, k)
1475  sjd(i, j, k, 1) = sjd(i, j, k, 1) + sc(1)*sfacejd(i, j, k)
1476  scd(2) = scd(2) + sj(i, j, k, 2)*sfacejd(i, j, k)
1477  sjd(i, j, k, 2) = sjd(i, j, k, 2) + sc(2)*sfacejd(i, j, k)
1478  scd(3) = scd(3) + sj(i, j, k, 3)*sfacejd(i, j, k)
1479  sjd(i, j, k, 3) = sjd(i, j, k, 3) + sc(3)*sfacejd(i, j, k)
1480  sfacejd(i, j, k) = 0.0_8
1481  call popreal8array(sc, 3)
1482  call cellfacevelocities_b(xc, xcd, rotcenter, rotcenterd, &
1483 & rotrate, rotrated, velxgrid, velxgridd&
1484 & , velygrid, velygridd, velzgrid, &
1485 & velzgridd, derivrotationmatrix, &
1486 & derivrotationmatrixd, sc, scd)
1487  call popreal8(xc(3))
1488  tempd = fourth*xcd(3)
1489  xcd(3) = 0.0_8
1490  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 3) = &
1491 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 3) + tempd
1492  flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 3) = &
1493 & flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 3) + tempd
1494  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 3) = &
1495 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 3) + &
1496 & tempd
1497  flowdomsd(nn, groundlevel, sps)%x(i, j, k, 3) = flowdomsd(&
1498 & nn, groundlevel, sps)%x(i, j, k, 3) + tempd
1499  call popreal8(xc(2))
1500  tempd = fourth*xcd(2)
1501  xcd(2) = 0.0_8
1502  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 2) = &
1503 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 2) + tempd
1504  flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 2) = &
1505 & flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 2) + tempd
1506  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 2) = &
1507 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 2) + &
1508 & tempd
1509  flowdomsd(nn, groundlevel, sps)%x(i, j, k, 2) = flowdomsd(&
1510 & nn, groundlevel, sps)%x(i, j, k, 2) + tempd
1511  call popreal8(xc(1))
1512  tempd = fourth*xcd(1)
1513  xcd(1) = 0.0_8
1514  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 1) = &
1515 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 1) + tempd
1516  flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 1) = &
1517 & flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 1) + tempd
1518  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 1) = &
1519 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 1) + &
1520 & tempd
1521  flowdomsd(nn, groundlevel, sps)%x(i, j, k, 1) = flowdomsd(&
1522 & nn, groundlevel, sps)%x(i, j, k, 1) + tempd
1523  end do
1524  end do
1525  call popinteger4(j)
1526  end do
1527  do k=ke,1,-1
1528  do j=je,1,-1
1529  do i=ie,0,-1
1530  scd(1) = scd(1) + si(i, j, k, 1)*sfaceid(i, j, k)
1531  sid(i, j, k, 1) = sid(i, j, k, 1) + sc(1)*sfaceid(i, j, k)
1532  scd(2) = scd(2) + si(i, j, k, 2)*sfaceid(i, j, k)
1533  sid(i, j, k, 2) = sid(i, j, k, 2) + sc(2)*sfaceid(i, j, k)
1534  scd(3) = scd(3) + si(i, j, k, 3)*sfaceid(i, j, k)
1535  sid(i, j, k, 3) = sid(i, j, k, 3) + sc(3)*sfaceid(i, j, k)
1536  sfaceid(i, j, k) = 0.0_8
1537  call popreal8array(sc, 3)
1538  call cellfacevelocities_b(xc, xcd, rotcenter, rotcenterd, &
1539 & rotrate, rotrated, velxgrid, velxgridd&
1540 & , velygrid, velygridd, velzgrid, &
1541 & velzgridd, derivrotationmatrix, &
1542 & derivrotationmatrixd, sc, scd)
1543  call popreal8(xc(3))
1544  tempd = fourth*xcd(3)
1545  xcd(3) = 0.0_8
1546  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1, 3) = &
1547 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1, 3) + &
1548 & tempd
1549  flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 3) = &
1550 & flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 3) + tempd
1551  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 3) = &
1552 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 3) + tempd
1553  flowdomsd(nn, groundlevel, sps)%x(i, j, k, 3) = flowdomsd(&
1554 & nn, groundlevel, sps)%x(i, j, k, 3) + tempd
1555  call popreal8(xc(2))
1556  tempd = fourth*xcd(2)
1557  xcd(2) = 0.0_8
1558  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1, 2) = &
1559 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1, 2) + &
1560 & tempd
1561  flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 2) = &
1562 & flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 2) + tempd
1563  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 2) = &
1564 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 2) + tempd
1565  flowdomsd(nn, groundlevel, sps)%x(i, j, k, 2) = flowdomsd(&
1566 & nn, groundlevel, sps)%x(i, j, k, 2) + tempd
1567  call popreal8(xc(1))
1568  tempd = fourth*xcd(1)
1569  xcd(1) = 0.0_8
1570  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1, 1) = &
1571 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1, 1) + &
1572 & tempd
1573  flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 1) = &
1574 & flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 1) + tempd
1575  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 1) = &
1576 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 1) + tempd
1577  flowdomsd(nn, groundlevel, sps)%x(i, j, k, 1) = flowdomsd(&
1578 & nn, groundlevel, sps)%x(i, j, k, 1) + tempd
1579  end do
1580  end do
1581  call popinteger4(j)
1582  end do
1583  xxcd = 0.0_8
1584  do k=ke,1,-1
1585  do j=je,1,-1
1586  do i=ie,1,-1
1587  scd(3) = scd(3) + sd(i, j, k, 3)
1588  velzgridd = velzgridd + sd(i, j, k, 3)
1589  derivrotationmatrixd(3, 1) = derivrotationmatrixd(3, 1) + &
1590 & xxc(1)*sd(i, j, k, 3)
1591  xxcd(1) = xxcd(1) + derivrotationmatrix(3, 1)*sd(i, j, k, &
1592 & 3)
1593  derivrotationmatrixd(3, 2) = derivrotationmatrixd(3, 2) + &
1594 & xxc(2)*sd(i, j, k, 3)
1595  xxcd(2) = xxcd(2) + derivrotationmatrix(3, 2)*sd(i, j, k, &
1596 & 3)
1597  derivrotationmatrixd(3, 3) = derivrotationmatrixd(3, 3) + &
1598 & xxc(3)*sd(i, j, k, 3)
1599  xxcd(3) = xxcd(3) + derivrotationmatrix(3, 3)*sd(i, j, k, &
1600 & 3)
1601  sd(i, j, k, 3) = 0.0_8
1602  scd(2) = scd(2) + sd(i, j, k, 2)
1603  velygridd = velygridd + sd(i, j, k, 2)
1604  derivrotationmatrixd(2, 1) = derivrotationmatrixd(2, 1) + &
1605 & xxc(1)*sd(i, j, k, 2)
1606  xxcd(1) = xxcd(1) + derivrotationmatrix(2, 1)*sd(i, j, k, &
1607 & 2)
1608  derivrotationmatrixd(2, 2) = derivrotationmatrixd(2, 2) + &
1609 & xxc(2)*sd(i, j, k, 2)
1610  xxcd(2) = xxcd(2) + derivrotationmatrix(2, 2)*sd(i, j, k, &
1611 & 2)
1612  derivrotationmatrixd(2, 3) = derivrotationmatrixd(2, 3) + &
1613 & xxc(3)*sd(i, j, k, 2)
1614  xxcd(3) = xxcd(3) + derivrotationmatrix(2, 3)*sd(i, j, k, &
1615 & 2)
1616  sd(i, j, k, 2) = 0.0_8
1617  scd(1) = scd(1) + sd(i, j, k, 1)
1618  velxgridd = velxgridd + sd(i, j, k, 1)
1619  derivrotationmatrixd(1, 1) = derivrotationmatrixd(1, 1) + &
1620 & xxc(1)*sd(i, j, k, 1)
1621  xxcd(1) = xxcd(1) + derivrotationmatrix(1, 1)*sd(i, j, k, &
1622 & 1)
1623  derivrotationmatrixd(1, 2) = derivrotationmatrixd(1, 2) + &
1624 & xxc(2)*sd(i, j, k, 1)
1625  xxcd(2) = xxcd(2) + derivrotationmatrix(1, 2)*sd(i, j, k, &
1626 & 1)
1627  derivrotationmatrixd(1, 3) = derivrotationmatrixd(1, 3) + &
1628 & xxc(3)*sd(i, j, k, 1)
1629  xxcd(3) = xxcd(3) + derivrotationmatrix(1, 3)*sd(i, j, k, &
1630 & 1)
1631  sd(i, j, k, 1) = 0.0_8
1632  call popreal8(xxc(3))
1633  xcd(3) = xcd(3) + xxcd(3)
1634  xxcd(3) = rotrate(2)*scd(1) - rotrate(1)*scd(2)
1635  call popreal8(xxc(2))
1636  xcd(2) = xcd(2) + xxcd(2)
1637  xxcd(2) = rotrate(1)*scd(3) - rotrate(3)*scd(1)
1638  call popreal8(xxc(1))
1639  xcd(1) = xcd(1) + xxcd(1)
1640  xxcd(1) = rotrate(3)*scd(2) - rotrate(2)*scd(3)
1641  rotrated(1) = rotrated(1) + xxc(2)*scd(3) - xxc(3)*scd(2)
1642  rotrated(2) = rotrated(2) + xxc(3)*scd(1) - xxc(1)*scd(3)
1643  scd(3) = 0.0_8
1644  rotrated(3) = rotrated(3) + xxc(1)*scd(2) - xxc(2)*scd(1)
1645  scd(2) = 0.0_8
1646  scd(1) = 0.0_8
1647  call popreal8(xxc(3))
1648  xcd(3) = xcd(3) + xxcd(3)
1649  xxcd(3) = 0.0_8
1650  call popreal8(xxc(2))
1651  xcd(2) = xcd(2) + xxcd(2)
1652  xxcd(2) = 0.0_8
1653  call popreal8(xxc(1))
1654  xcd(1) = xcd(1) + xxcd(1)
1655  xxcd(1) = 0.0_8
1656  tempd = eighth*xcd(3)
1657  xcd(3) = 0.0_8
1658  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k-1, 3) = &
1659 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k-1, 3) + &
1660 & tempd
1661  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1, 3) = &
1662 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1, 3) + &
1663 & tempd
1664  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 3) = &
1665 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 3) + &
1666 & tempd
1667  flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 3) = &
1668 & flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 3) + tempd
1669  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 3) = &
1670 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 3) + &
1671 & tempd
1672  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 3) = &
1673 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 3) + tempd
1674  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 3) = &
1675 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 3) + tempd
1676  flowdomsd(nn, groundlevel, sps)%x(i, j, k, 3) = flowdomsd(&
1677 & nn, groundlevel, sps)%x(i, j, k, 3) + tempd
1678  tempd = eighth*xcd(2)
1679  xcd(2) = 0.0_8
1680  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k-1, 2) = &
1681 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k-1, 2) + &
1682 & tempd
1683  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1, 2) = &
1684 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1, 2) + &
1685 & tempd
1686  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 2) = &
1687 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 2) + &
1688 & tempd
1689  flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 2) = &
1690 & flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 2) + tempd
1691  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 2) = &
1692 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 2) + &
1693 & tempd
1694  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 2) = &
1695 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 2) + tempd
1696  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 2) = &
1697 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 2) + tempd
1698  flowdomsd(nn, groundlevel, sps)%x(i, j, k, 2) = flowdomsd(&
1699 & nn, groundlevel, sps)%x(i, j, k, 2) + tempd
1700  tempd = eighth*xcd(1)
1701  xcd(1) = 0.0_8
1702  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k-1, 1) = &
1703 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k-1, 1) + &
1704 & tempd
1705  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1, 1) = &
1706 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1, 1) + &
1707 & tempd
1708  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 1) = &
1709 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 1) + &
1710 & tempd
1711  flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 1) = &
1712 & flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 1) + tempd
1713  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 1) = &
1714 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 1) + &
1715 & tempd
1716  flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 1) = &
1717 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 1) + tempd
1718  flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 1) = &
1719 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 1) + tempd
1720  flowdomsd(nn, groundlevel, sps)%x(i, j, k, 1) = flowdomsd(&
1721 & nn, groundlevel, sps)%x(i, j, k, 1) + tempd
1722  end do
1723  end do
1724  call popinteger4(j)
1725  end do
1726  velzgrid0d = velzgridd
1727  velygrid0d = velygridd
1728  velxgrid0d = velxgridd
1729  timerefd = sum(cgnsdoms(j)%rotrate*rotrated)
1730  end if
1731  else
1732  timerefd = 0.0_8
1733  velxgrid0d = 0.0_8
1734  velzgrid0d = 0.0_8
1735  derivrotationmatrixd = 0.0_8
1736  velygrid0d = 0.0_8
1737  end if
1738  call derivativerotmatrixrigid_b(derivrotationmatrix, &
1739 & derivrotationmatrixd, rotationpoint, t(1))
1740  ainfd = -(machgrid*veldirfreestream(3)*velzgrid0d) - machgrid*&
1741 & veldirfreestream(2)*velygrid0d - machgrid*veldirfreestream(1)*&
1742 & velxgrid0d
1743  machgridd = -(ainf*veldirfreestream(3)*velzgrid0d) - ainf*&
1744 & veldirfreestream(2)*velygrid0d - ainf*veldirfreestream(1)*&
1745 & velxgrid0d
1747 & velzgrid0d
1749 & velygrid0d
1751 & velxgrid0d
1752  if (gammainf*(pinf/rhoinf) .eq. 0.0_8) then
1753  tempd = 0.0_8
1754  else
1755  tempd = gammainf*ainfd/(rhoinf*2.0*sqrt(gammainf*(pinf/rhoinf)))
1756  end if
1757  pinfd = tempd
1758  rhoinfd = -(pinf*tempd/rhoinf)
1759  end subroutine gridvelocitiesfinelevel_block_b
1760 
1761  subroutine gridvelocitiesfinelevel_block(useoldcoor, t, sps, nn)
1762 !
1763 ! gridvelocitiesfinelevel computes the grid velocities for
1764 ! the cell centers and the normal grid velocities for the faces
1765 ! of moving blocks for the currently finest grid, i.e.
1766 ! groundlevel. the velocities are computed at time t for
1767 ! spectral mode sps. if useoldcoor is .true. the velocities
1768 ! are determined using the unsteady time integrator in
1769 ! combination with the old coordinates; otherwise the analytic
1770 ! form is used.
1771 !
1772  use blockpointers
1773  use cgnsgrid
1774  use flowvarrefstate
1775  use inputmotion
1776  use inputunsteady
1777  use iteration
1778  use inputphysics
1779  use inputtsstabderiv
1780  use monitor
1781  use communication
1785  implicit none
1786 !
1787 ! subroutine arguments.
1788 !
1789  integer(kind=inttype), intent(in) :: sps, nn
1790  logical, intent(in) :: useoldcoor
1791  real(kind=realtype), dimension(*), intent(in) :: t
1792 !
1793 ! local variables.
1794 !
1795  integer(kind=inttype) :: mm
1796  integer(kind=inttype) :: i, j, k, ii, iie, jje, kke
1797  real(kind=realtype) :: oneover4dt, oneover8dt
1798  real(kind=realtype) :: velxgrid, velygrid, velzgrid, ainf
1799  real(kind=realtype) :: velxgrid0, velygrid0, velzgrid0
1800  real(kind=realtype), dimension(3) :: sc, xc, xxc
1801  real(kind=realtype), dimension(3) :: rotcenter, rotrate
1802  real(kind=realtype), dimension(3) :: rotationpoint
1803  real(kind=realtype), dimension(3, 3) :: rotationmatrix, &
1804 & derivrotationmatrix
1805  real(kind=realtype) :: tnew, told
1806  real(kind=realtype), dimension(:, :), pointer :: sface
1807  real(kind=realtype), dimension(:, :, :), pointer :: xx, ss
1808  real(kind=realtype), dimension(:, :, :, :), pointer :: xxold
1809  real(kind=realtype) :: intervalmach, alphats, alphaincrement, betats&
1810 & , betaincrement
1811  real(kind=realtype), dimension(3) :: veldir
1812  real(kind=realtype), dimension(3) :: refdirection
1813  intrinsic sqrt
1814 ! compute the mesh velocity from the given mesh mach number.
1815 ! vel{x,y,z}grid0 is the actual velocity you want at the
1816 ! geometry.
1817  ainf = sqrt(gammainf*pinf/rhoinf)
1818  velxgrid0 = ainf*machgrid*(-veldirfreestream(1))
1819  velygrid0 = ainf*machgrid*(-veldirfreestream(2))
1820  velzgrid0 = ainf*machgrid*(-veldirfreestream(3))
1821 ! compute the derivative of the rotation matrix and the rotation
1822 ! point; needed for velocity due to the rigid body rotation of
1823 ! the entire grid. it is assumed that the rigid body motion of
1824 ! the grid is only specified if there is only 1 section present.
1825  call derivativerotmatrixrigid(derivrotationmatrix, rotationpoint, t(&
1826 & 1))
1827 !compute the rotation matrix to update the velocities for the time
1828 !spectral stability derivative case...
1829  if (blockismoving) then
1830 ! determine the situation we are having here.
1831  if (.not.useoldcoor) then
1832 !
1833 ! the velocities must be determined analytically.
1834 !
1835 ! store the rotation center and determine the
1836 ! nondimensional rotation rate of this block. as the
1837 ! reference length is 1 timeref == 1/uref and at the end
1838 ! the nondimensional velocity is computed.
1839  j = nbkglobal
1840  rotcenter = cgnsdoms(j)%rotcenter
1841  rotrate = timeref*cgnsdoms(j)%rotrate
1842  velxgrid = velxgrid0
1843  velygrid = velygrid0
1844  velzgrid = velzgrid0
1845 !
1846 ! grid velocities of the cell centers, including the
1847 ! 1st level halo cells.
1848 !
1849 ! loop over the cells, including the 1st level halo's.
1850  do k=1,ke
1851  do j=1,je
1852  do i=1,ie
1853 ! determine the coordinates of the cell center,
1854 ! which are stored in xc.
1855  xc(1) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
1856 & , k-1, 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
1857 & 1)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 1)+&
1858 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+flowdoms(&
1859 & nn, groundlevel, sps)%x(i-1, j-1, k, 1)+flowdoms(nn, &
1860 & groundlevel, sps)%x(i, j-1, k, 1)+flowdoms(nn, &
1861 & groundlevel, sps)%x(i-1, j, k, 1)+flowdoms(nn, &
1862 & groundlevel, sps)%x(i, j, k, 1))
1863  xc(2) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
1864 & , k-1, 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
1865 & 2)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 2)+&
1866 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+flowdoms(&
1867 & nn, groundlevel, sps)%x(i-1, j-1, k, 2)+flowdoms(nn, &
1868 & groundlevel, sps)%x(i, j-1, k, 2)+flowdoms(nn, &
1869 & groundlevel, sps)%x(i-1, j, k, 2)+flowdoms(nn, &
1870 & groundlevel, sps)%x(i, j, k, 2))
1871  xc(3) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
1872 & , k-1, 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
1873 & 3)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 3)+&
1874 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+flowdoms(&
1875 & nn, groundlevel, sps)%x(i-1, j-1, k, 3)+flowdoms(nn, &
1876 & groundlevel, sps)%x(i, j-1, k, 3)+flowdoms(nn, &
1877 & groundlevel, sps)%x(i-1, j, k, 3)+flowdoms(nn, &
1878 & groundlevel, sps)%x(i, j, k, 3))
1879 ! determine the coordinates relative to the
1880 ! center of rotation.
1881  xxc(1) = xc(1) - rotcenter(1)
1882  xxc(2) = xc(2) - rotcenter(2)
1883  xxc(3) = xc(3) - rotcenter(3)
1884 ! determine the rotation speed of the cell center,
1885 ! which is omega*r.
1886  sc(1) = rotrate(2)*xxc(3) - rotrate(3)*xxc(2)
1887  sc(2) = rotrate(3)*xxc(1) - rotrate(1)*xxc(3)
1888  sc(3) = rotrate(1)*xxc(2) - rotrate(2)*xxc(1)
1889 ! determine the coordinates relative to the
1890 ! rigid body rotation point.
1891  xxc(1) = xc(1) - rotationpoint(1)
1892  xxc(2) = xc(2) - rotationpoint(2)
1893  xxc(3) = xc(3) - rotationpoint(3)
1894 ! determine the total velocity of the cell center.
1895 ! this is a combination of rotation speed of this
1896 ! block and the entire rigid body rotation.
1897  s(i, j, k, 1) = sc(1) + velxgrid + derivrotationmatrix(1, &
1898 & 1)*xxc(1) + derivrotationmatrix(1, 2)*xxc(2) + &
1899 & derivrotationmatrix(1, 3)*xxc(3)
1900  s(i, j, k, 2) = sc(2) + velygrid + derivrotationmatrix(2, &
1901 & 1)*xxc(1) + derivrotationmatrix(2, 2)*xxc(2) + &
1902 & derivrotationmatrix(2, 3)*xxc(3)
1903  s(i, j, k, 3) = sc(3) + velzgrid + derivrotationmatrix(3, &
1904 & 1)*xxc(1) + derivrotationmatrix(3, 2)*xxc(2) + &
1905 & derivrotationmatrix(3, 3)*xxc(3)
1906  end do
1907  end do
1908  end do
1909 !
1910 ! normal grid velocities of the faces.
1911 !
1912 ! loop over the three directions.
1913 ! the original code is elegant but the tapenade has a difficult time
1914 ! to understand it. thus, we unfold it and make it easier for the
1915 ! tapenade.
1916 ! i-direction
1917  do k=1,ke
1918  do j=1,je
1919  do i=0,ie
1920 ! determine the coordinates of the face center,
1921 ! which are stored in xc.
1922  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1923 & -1, 1)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+&
1924 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 1)+flowdoms(&
1925 & nn, groundlevel, sps)%x(i, j, k, 1))
1926  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1927 & -1, 2)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+&
1928 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 2)+flowdoms(&
1929 & nn, groundlevel, sps)%x(i, j, k, 2))
1930  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1931 & -1, 3)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+&
1932 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 3)+flowdoms(&
1933 & nn, groundlevel, sps)%x(i, j, k, 3))
1934  call cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
1935 & velygrid, velzgrid, derivrotationmatrix&
1936 & , sc)
1937 ! store the dot product of grid velocity sc and
1938 ! the normal ss in sface.
1939  sfacei(i, j, k) = sc(1)*si(i, j, k, 1) + sc(2)*si(i, j, k&
1940 & , 2) + sc(3)*si(i, j, k, 3)
1941  end do
1942  end do
1943  end do
1944 ! j-direction
1945  do k=1,ke
1946  do j=0,je
1947  do i=1,ie
1948 ! determine the coordinates of the face center,
1949 ! which are stored in xc.
1950  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
1951 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+&
1952 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 1)+&
1953 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 1))
1954  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
1955 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+&
1956 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 2)+&
1957 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 2))
1958  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
1959 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+&
1960 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 3)+&
1961 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 3))
1962  call cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
1963 & velygrid, velzgrid, derivrotationmatrix&
1964 & , sc)
1965 ! store the dot product of grid velocity sc and
1966 ! the normal ss in sface.
1967  sfacej(i, j, k) = sc(1)*sj(i, j, k, 1) + sc(2)*sj(i, j, k&
1968 & , 2) + sc(3)*sj(i, j, k, 3)
1969  end do
1970  end do
1971  end do
1972 ! k-direction
1973  do k=0,ke
1974  do j=1,je
1975  do i=1,ie
1976 ! determine the coordinates of the face center,
1977 ! which are stored in xc.
1978  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1979 & , 1)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 1)+&
1980 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 1)+&
1981 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 1))
1982  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1983 & , 2)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 2)+&
1984 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 2)+&
1985 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 2))
1986  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1987 & , 3)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 3)+&
1988 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 3)+&
1989 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 3))
1990  call cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
1991 & velygrid, velzgrid, derivrotationmatrix&
1992 & , sc)
1993 ! store the dot product of grid velocity sc and
1994 ! the normal ss in sface.
1995  sfacek(i, j, k) = sc(1)*sk(i, j, k, 1) + sc(2)*sk(i, j, k&
1996 & , 2) + sc(3)*sk(i, j, k, 3)
1997  end do
1998  end do
1999  end do
2000  end if
2001  end if
2002  end subroutine gridvelocitiesfinelevel_block
2003 
2004 ! differentiation of cellfacevelocities in reverse (adjoint) mode (with options noisize i4 dr8 r8):
2005 ! gradient of useful results: rotrate velygrid xc velzgrid
2006 ! derivrotationmatrix sc velxgrid
2007 ! with respect to varying inputs: rotrate velygrid xc velzgrid
2008 ! derivrotationmatrix sc rotcenter velxgrid
2009 ! rw status of diff variables: rotrate:incr velygrid:incr xc:incr
2010 ! velzgrid:incr derivrotationmatrix:incr sc:in-out
2011 ! rotcenter:out velxgrid:incr
2012  subroutine cellfacevelocities_b(xc, xcd, rotcenter, rotcenterd, &
2013 & rotrate, rotrated, velxgrid, velxgridd, velygrid, velygridd, &
2014 & velzgrid, velzgridd, derivrotationmatrix, derivrotationmatrixd, sc, &
2015 & scd)
2016 !
2017 ! returns the cell face velocities for a given face center
2018 !
2019  use constants
2020  implicit none
2021 !
2022 ! subroutine arguments.
2023 !
2024  real(kind=realtype), dimension(3), intent(in) :: xc, rotcenter, &
2025 & rotrate
2026  real(kind=realtype), dimension(3) :: xcd, rotcenterd, rotrated
2027  real(kind=realtype), intent(in) :: velxgrid, velygrid, velzgrid
2028  real(kind=realtype) :: velxgridd, velygridd, velzgridd
2029  real(kind=realtype), dimension(3, 3), intent(in) :: &
2030 & derivrotationmatrix
2031  real(kind=realtype), dimension(3, 3) :: derivrotationmatrixd
2032  real(kind=realtype), dimension(3) :: sc
2033  real(kind=realtype), dimension(3) :: scd
2034 !
2035 ! local variables.
2036 !
2037  real(kind=realtype), dimension(3) :: rotationpoint, xxc
2038  real(kind=realtype), dimension(3) :: xxcd
2039 ! determine the coordinates relative to the
2040 ! center of rotation.
2041  xxc(1) = xc(1) - rotcenter(1)
2042  xxc(2) = xc(2) - rotcenter(2)
2043  xxc(3) = xc(3) - rotcenter(3)
2044 ! determine the rotation speed of the face center,
2045 ! which is omega*r.
2046 ! determine the coordinates relative to the
2047 ! rigid body rotation point.
2048  call pushreal8(xxc(1))
2049  xxc(1) = xc(1) - rotationpoint(1)
2050  call pushreal8(xxc(2))
2051  xxc(2) = xc(2) - rotationpoint(2)
2052  call pushreal8(xxc(3))
2053  xxc(3) = xc(3) - rotationpoint(3)
2054 ! determine the total velocity of the cell face.
2055 ! this is a combination of rotation speed of this
2056 ! block and the entire rigid body rotation.
2057  xxcd = 0.0_8
2058  velzgridd = velzgridd + scd(3)
2059  derivrotationmatrixd(3, 1) = derivrotationmatrixd(3, 1) + xxc(1)*scd&
2060 & (3)
2061  xxcd(1) = xxcd(1) + derivrotationmatrix(3, 1)*scd(3) + &
2062 & derivrotationmatrix(2, 1)*scd(2) + derivrotationmatrix(1, 1)*scd(1&
2063 & )
2064  derivrotationmatrixd(3, 2) = derivrotationmatrixd(3, 2) + xxc(2)*scd&
2065 & (3)
2066  xxcd(2) = xxcd(2) + derivrotationmatrix(3, 2)*scd(3) + &
2067 & derivrotationmatrix(2, 2)*scd(2) + derivrotationmatrix(1, 2)*scd(1&
2068 & )
2069  derivrotationmatrixd(3, 3) = derivrotationmatrixd(3, 3) + xxc(3)*scd&
2070 & (3)
2071  xxcd(3) = xxcd(3) + derivrotationmatrix(3, 3)*scd(3) + &
2072 & derivrotationmatrix(2, 3)*scd(2) + derivrotationmatrix(1, 3)*scd(1&
2073 & )
2074  velygridd = velygridd + scd(2)
2075  derivrotationmatrixd(2, 1) = derivrotationmatrixd(2, 1) + xxc(1)*scd&
2076 & (2)
2077  derivrotationmatrixd(2, 2) = derivrotationmatrixd(2, 2) + xxc(2)*scd&
2078 & (2)
2079  derivrotationmatrixd(2, 3) = derivrotationmatrixd(2, 3) + xxc(3)*scd&
2080 & (2)
2081  velxgridd = velxgridd + scd(1)
2082  derivrotationmatrixd(1, 1) = derivrotationmatrixd(1, 1) + xxc(1)*scd&
2083 & (1)
2084  derivrotationmatrixd(1, 2) = derivrotationmatrixd(1, 2) + xxc(2)*scd&
2085 & (1)
2086  derivrotationmatrixd(1, 3) = derivrotationmatrixd(1, 3) + xxc(3)*scd&
2087 & (1)
2088  call popreal8(xxc(3))
2089  xcd(3) = xcd(3) + xxcd(3)
2090  xxcd(3) = rotrate(2)*scd(1) - rotrate(1)*scd(2)
2091  call popreal8(xxc(2))
2092  xcd(2) = xcd(2) + xxcd(2)
2093  xxcd(2) = rotrate(1)*scd(3) - rotrate(3)*scd(1)
2094  call popreal8(xxc(1))
2095  xcd(1) = xcd(1) + xxcd(1)
2096  xxcd(1) = rotrate(3)*scd(2) - rotrate(2)*scd(3)
2097  rotrated(1) = rotrated(1) + xxc(2)*scd(3) - xxc(3)*scd(2)
2098  rotrated(2) = rotrated(2) + xxc(3)*scd(1) - xxc(1)*scd(3)
2099  scd(3) = 0.0_8
2100  rotrated(3) = rotrated(3) + xxc(1)*scd(2) - xxc(2)*scd(1)
2101  scd(2) = 0.0_8
2102  scd(1) = 0.0_8
2103  rotcenterd = 0.0_8
2104  xcd(3) = xcd(3) + xxcd(3)
2105  rotcenterd(3) = rotcenterd(3) - xxcd(3)
2106  xxcd(3) = 0.0_8
2107  xcd(2) = xcd(2) + xxcd(2)
2108  rotcenterd(2) = rotcenterd(2) - xxcd(2)
2109  xxcd(2) = 0.0_8
2110  xcd(1) = xcd(1) + xxcd(1)
2111  rotcenterd(1) = rotcenterd(1) - xxcd(1)
2112  end subroutine cellfacevelocities_b
2113 
2114  subroutine cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
2115 & velygrid, velzgrid, derivrotationmatrix, sc)
2116 !
2117 ! returns the cell face velocities for a given face center
2118 !
2119  use constants
2120  implicit none
2121 !
2122 ! subroutine arguments.
2123 !
2124  real(kind=realtype), dimension(3), intent(in) :: xc, rotcenter, &
2125 & rotrate
2126  real(kind=realtype), intent(in) :: velxgrid, velygrid, velzgrid
2127  real(kind=realtype), dimension(3, 3), intent(in) :: &
2128 & derivrotationmatrix
2129  real(kind=realtype), dimension(3), intent(out) :: sc
2130 !
2131 ! local variables.
2132 !
2133  real(kind=realtype), dimension(3) :: rotationpoint, xxc
2134 ! determine the coordinates relative to the
2135 ! center of rotation.
2136  xxc(1) = xc(1) - rotcenter(1)
2137  xxc(2) = xc(2) - rotcenter(2)
2138  xxc(3) = xc(3) - rotcenter(3)
2139 ! determine the rotation speed of the face center,
2140 ! which is omega*r.
2141  sc(1) = rotrate(2)*xxc(3) - rotrate(3)*xxc(2)
2142  sc(2) = rotrate(3)*xxc(1) - rotrate(1)*xxc(3)
2143  sc(3) = rotrate(1)*xxc(2) - rotrate(2)*xxc(1)
2144 ! determine the coordinates relative to the
2145 ! rigid body rotation point.
2146  xxc(1) = xc(1) - rotationpoint(1)
2147  xxc(2) = xc(2) - rotationpoint(2)
2148  xxc(3) = xc(3) - rotationpoint(3)
2149 ! determine the total velocity of the cell face.
2150 ! this is a combination of rotation speed of this
2151 ! block and the entire rigid body rotation.
2152  sc(1) = sc(1) + velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
2153 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1, 3)*xxc(3&
2154 & )
2155  sc(2) = sc(2) + velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
2156 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2, 3)*xxc(3&
2157 & )
2158  sc(3) = sc(3) + velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
2159 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3, 3)*xxc(3&
2160 & )
2161  end subroutine cellfacevelocities
2162 
2163 ! differentiation of slipvelocitiesfinelevel_block in reverse (adjoint) mode (with options noisize i4 dr8 r8):
2164 ! gradient of useful results: *(flowdoms.x) veldirfreestream
2165 ! *(*bcdata.uslip)
2166 ! with respect to varying inputs: pinf timeref rhoinf *(flowdoms.x)
2167 ! veldirfreestream machgrid *(*bcdata.uslip)
2168 ! rw status of diff variables: pinf:out timeref:out rhoinf:out
2169 ! *(flowdoms.x):incr veldirfreestream:incr machgrid:out
2170 ! *(*bcdata.uslip):in-out
2171 ! plus diff mem management of: flowdoms.x:in bcdata:in *bcdata.uslip:in
2172  subroutine slipvelocitiesfinelevel_block_b(useoldcoor, t, sps, nn)
2173 !
2174 ! slipvelocitiesfinelevel computes the slip velocities for
2175 ! viscous subfaces on all viscous boundaries on groundlevel for
2176 ! the given spectral solution. if useoldcoor is .true. the
2177 ! velocities are determined using the unsteady time integrator;
2178 ! otherwise the analytic form is used.
2179 !
2180  use constants
2181  use inputtimespectral
2182  use blockpointers
2183  use cgnsgrid
2184  use flowvarrefstate
2185  use inputmotion
2186  use inputunsteady
2187  use iteration
2188  use inputphysics
2189  use inputtsstabderiv
2190  use monitor
2191  use communication
2192  use flowutils_b, only : derivativerotmatrixrigid, &
2194  use utils_b, only : tsalpha, tsbeta, tsmach, terminate, &
2196  implicit none
2197 !
2198 ! subroutine arguments.
2199 !
2200  integer(kind=inttype), intent(in) :: sps, nn
2201  logical, intent(in) :: useoldcoor
2202  real(kind=realtype), dimension(*), intent(in) :: t
2203 !
2204 ! local variables.
2205 !
2206  integer(kind=inttype) :: mm, i, j, level, ii
2207  real(kind=realtype) :: oneover4dt
2208  real(kind=realtype) :: velxgrid, velygrid, velzgrid, ainf
2209  real(kind=realtype) :: velxgridd, velygridd, velzgridd, ainfd
2210  real(kind=realtype) :: velxgrid0, velygrid0, velzgrid0
2211  real(kind=realtype) :: velxgrid0d, velygrid0d, velzgrid0d
2212  real(kind=realtype), dimension(3) :: xc, xxc
2213  real(kind=realtype), dimension(3) :: xcd, xxcd
2214  real(kind=realtype), dimension(3) :: rotcenter, rotrate
2215  real(kind=realtype), dimension(3) :: rotrated
2216  real(kind=realtype), dimension(3) :: rotationpoint
2217  real(kind=realtype), dimension(3, 3) :: rotationmatrix, &
2218 & derivrotationmatrix
2219  real(kind=realtype), dimension(3, 3) :: derivrotationmatrixd
2220  real(kind=realtype) :: tnew, told
2221  real(kind=realtype), dimension(:, :, :), pointer :: uslip
2222  real(kind=realtype), dimension(:, :, :), pointer :: xface
2223  real(kind=realtype), dimension(:, :, :, :), pointer :: xfaceold
2224  real(kind=realtype) :: intervalmach, alphats, alphaincrement, betats&
2225 & , betaincrement
2226  real(kind=realtype), dimension(3) :: veldir
2227  real(kind=realtype), dimension(3) :: refdirection
2228  intrinsic sqrt
2229  real(kind=realtype) :: tempd
2230  integer :: ad_from
2231  integer :: ad_to
2232  integer :: ad_from0
2233  integer :: ad_to0
2234  integer :: ad_from1
2235  integer :: ad_to1
2236  integer :: ad_from2
2237  integer :: ad_to2
2238  integer :: ad_from3
2239  integer :: ad_to3
2240  integer :: ad_from4
2241  integer :: ad_to4
2242  integer :: ad_from5
2243  integer :: ad_to5
2244  integer :: ad_from6
2245  integer :: ad_to6
2246  integer :: ad_from7
2247  integer :: ad_to7
2248  integer :: ad_from8
2249  integer :: ad_to8
2250  integer :: ad_from9
2251  integer :: ad_to9
2252  integer :: ad_from10
2253  integer :: ad_to10
2254  integer :: branch
2255 ! determine the situation we are having here.
2256  if (useoldcoor) then
2257  pinfd = 0.0_8
2258  timerefd = 0.0_8
2259  rhoinfd = 0.0_8
2260  machgridd = 0.0_8
2261  else
2262 ! the velocities must be determined analytically.
2263 ! compute the mesh velocity from the given mesh mach number.
2264 ! ainf = sqrt(gammainf*pinf/rhoinf)
2265 ! velxgrid = ainf*machgrid(1)
2266 ! velygrid = ainf*machgrid(2)
2267 ! velzgrid = ainf*machgrid(3)
2268  ainf = sqrt(gammainf*pinf/rhoinf)
2269 ! compute the derivative of the rotation matrix and the rotation
2270 ! point; needed for velocity due to the rigid body rotation of
2271 ! the entire grid. it is assumed that the rigid body motion of
2272 ! the grid is only specified if there is only 1 section present.
2273  call derivativerotmatrixrigid(derivrotationmatrix, rotationpoint, &
2274 & t(1))
2275 !compute the rotation matrix to update the velocities for the time
2276 !spectral stability derivative case...
2277 ! loop over the number of viscous subfaces.
2278 bocoloop2:do mm=1,nviscbocos
2279 ! store the rotation center and the rotation rate
2280 ! for this subface.
2281  call pushinteger4(ii)
2282  ii = cgnssubface(mm)
2283  rotcenter = cgnsdoms(nbkglobal)%bocoinfo(ii)%rotcenter
2284  call pushreal8array(rotrate, 3)
2285  rotrate = timeref*cgnsdoms(nbkglobal)%bocoinfo(ii)%rotrate
2286 ! usewindaxis should go back here!
2287 ! loop over the quadrilateral faces of the viscous
2288 ! subface.
2289 ! the new procedure is less elegant as the previous one.
2290 ! but the new stands up to tapenade.
2291  if (bcfaceid(mm) .eq. imin) then
2292  ad_from0 = bcdata(mm)%jcbeg
2293  do j=ad_from0,bcdata(mm)%jcend
2294  ad_from = bcdata(mm)%icbeg
2295  do i=ad_from,bcdata(mm)%icend
2296 ! compute the coordinates of the centroid of the face.
2297 ! normally this would be an average of i-1 and i, but
2298 ! due to the usage of the pointer xface and the fact
2299 ! that x starts at index 0 this is shifted 1 index.
2300  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
2301 & 1)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 1)+&
2302 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 1)+flowdoms(&
2303 & nn, groundlevel, sps)%x(1, i-1, j-1, 1))
2304  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
2305 & 2)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 2)+&
2306 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 2)+flowdoms(&
2307 & nn, groundlevel, sps)%x(1, i-1, j-1, 2))
2308  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
2309 & 3)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 3)+&
2310 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 3)+flowdoms(&
2311 & nn, groundlevel, sps)%x(1, i-1, j-1, 3))
2312 ! determine the coordinates relative to the center
2313 ! of rotation.
2314  call pushreal8(xxc(1))
2315  xxc(1) = xc(1) - rotcenter(1)
2316  call pushreal8(xxc(2))
2317  xxc(2) = xc(2) - rotcenter(2)
2318  call pushreal8(xxc(3))
2319  xxc(3) = xc(3) - rotcenter(3)
2320 ! compute the velocity, which is the cross product
2321 ! of rotrate and xc.
2322 ! determine the coordinates relative to the
2323 ! rigid body rotation point.
2324  call pushreal8(xxc(1))
2325  xxc(1) = xc(1) - rotationpoint(1)
2326  call pushreal8(xxc(2))
2327  xxc(2) = xc(2) - rotationpoint(2)
2328  call pushreal8(xxc(3))
2329  xxc(3) = xc(3) - rotationpoint(3)
2330 ! determine the total velocity of the cell center.
2331 ! this is a combination of rotation speed of this
2332 ! block and the entire rigid body rotation.
2333  end do
2334  call pushinteger4(i - 1)
2335  call pushinteger4(ad_from)
2336  end do
2337  call pushinteger4(j - 1)
2338  call pushinteger4(ad_from0)
2339  call pushcontrol3b(6)
2340  else if (bcfaceid(mm) .eq. imax) then
2341  ad_from2 = bcdata(mm)%jcbeg
2342  do j=ad_from2,bcdata(mm)%jcend
2343  ad_from1 = bcdata(mm)%icbeg
2344  do i=ad_from1,bcdata(mm)%icend
2345 ! compute the coordinates of the centroid of the face.
2346 ! normally this would be an average of i-1 and i, but
2347 ! due to the usage of the pointer xface and the fact
2348 ! that x starts at index 0 this is shifted 1 index.
2349  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
2350 & , 1)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 1)+&
2351 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 1)+flowdoms&
2352 & (nn, groundlevel, sps)%x(il, i-1, j-1, 1))
2353  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
2354 & , 2)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 2)+&
2355 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 2)+flowdoms&
2356 & (nn, groundlevel, sps)%x(il, i-1, j-1, 2))
2357  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
2358 & , 3)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 3)+&
2359 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 3)+flowdoms&
2360 & (nn, groundlevel, sps)%x(il, i-1, j-1, 3))
2361 ! determine the coordinates relative to the center
2362 ! of rotation.
2363  call pushreal8(xxc(1))
2364  xxc(1) = xc(1) - rotcenter(1)
2365  call pushreal8(xxc(2))
2366  xxc(2) = xc(2) - rotcenter(2)
2367  call pushreal8(xxc(3))
2368  xxc(3) = xc(3) - rotcenter(3)
2369 ! compute the velocity, which is the cross product
2370 ! of rotrate and xc.
2371 ! determine the coordinates relative to the
2372 ! rigid body rotation point.
2373  call pushreal8(xxc(1))
2374  xxc(1) = xc(1) - rotationpoint(1)
2375  call pushreal8(xxc(2))
2376  xxc(2) = xc(2) - rotationpoint(2)
2377  call pushreal8(xxc(3))
2378  xxc(3) = xc(3) - rotationpoint(3)
2379 ! determine the total velocity of the cell center.
2380 ! this is a combination of rotation speed of this
2381 ! block and the entire rigid body rotation.
2382  end do
2383  call pushinteger4(i - 1)
2384  call pushinteger4(ad_from1)
2385  end do
2386  call pushinteger4(j - 1)
2387  call pushinteger4(ad_from2)
2388  call pushcontrol3b(5)
2389  else if (bcfaceid(mm) .eq. jmin) then
2390  ad_from4 = bcdata(mm)%jcbeg
2391  do j=ad_from4,bcdata(mm)%jcend
2392  ad_from3 = bcdata(mm)%icbeg
2393  do i=ad_from3,bcdata(mm)%icend
2394 ! compute the coordinates of the centroid of the face.
2395 ! normally this would be an average of i-1 and i, but
2396 ! due to the usage of the pointer xface and the fact
2397 ! that x starts at index 0 this is shifted 1 index.
2398  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
2399 & 1)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 1)+&
2400 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 1)+flowdoms(&
2401 & nn, groundlevel, sps)%x(i-1, 1, j-1, 1))
2402  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
2403 & 2)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 2)+&
2404 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 2)+flowdoms(&
2405 & nn, groundlevel, sps)%x(i-1, 1, j-1, 2))
2406  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
2407 & 3)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 3)+&
2408 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 3)+flowdoms(&
2409 & nn, groundlevel, sps)%x(i-1, 1, j-1, 3))
2410 ! determine the coordinates relative to the center
2411 ! of rotation.
2412  call pushreal8(xxc(1))
2413  xxc(1) = xc(1) - rotcenter(1)
2414  call pushreal8(xxc(2))
2415  xxc(2) = xc(2) - rotcenter(2)
2416  call pushreal8(xxc(3))
2417  xxc(3) = xc(3) - rotcenter(3)
2418 ! compute the velocity, which is the cross product
2419 ! of rotrate and xc.
2420 ! determine the coordinates relative to the
2421 ! rigid body rotation point.
2422  call pushreal8(xxc(1))
2423  xxc(1) = xc(1) - rotationpoint(1)
2424  call pushreal8(xxc(2))
2425  xxc(2) = xc(2) - rotationpoint(2)
2426  call pushreal8(xxc(3))
2427  xxc(3) = xc(3) - rotationpoint(3)
2428 ! determine the total velocity of the cell center.
2429 ! this is a combination of rotation speed of this
2430 ! block and the entire rigid body rotation.
2431  end do
2432  call pushinteger4(i - 1)
2433  call pushinteger4(ad_from3)
2434  end do
2435  call pushinteger4(j - 1)
2436  call pushinteger4(ad_from4)
2437  call pushcontrol3b(4)
2438  else if (bcfaceid(mm) .eq. jmax) then
2439  ad_from6 = bcdata(mm)%jcbeg
2440  do j=ad_from6,bcdata(mm)%jcend
2441  ad_from5 = bcdata(mm)%icbeg
2442  do i=ad_from5,bcdata(mm)%icend
2443 ! compute the coordinates of the centroid of the face.
2444 ! normally this would be an average of i-1 and i, but
2445 ! due to the usage of the pointer xface and the fact
2446 ! that x starts at index 0 this is shifted 1 index.
2447  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
2448 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 1)+&
2449 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 1)+flowdoms&
2450 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 1))
2451  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
2452 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 2)+&
2453 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 2)+flowdoms&
2454 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 2))
2455  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
2456 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 3)+&
2457 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 3)+flowdoms&
2458 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 3))
2459 ! determine the coordinates relative to the center
2460 ! of rotation.
2461  call pushreal8(xxc(1))
2462  xxc(1) = xc(1) - rotcenter(1)
2463  call pushreal8(xxc(2))
2464  xxc(2) = xc(2) - rotcenter(2)
2465  call pushreal8(xxc(3))
2466  xxc(3) = xc(3) - rotcenter(3)
2467 ! compute the velocity, which is the cross product
2468 ! of rotrate and xc.
2469 ! determine the coordinates relative to the
2470 ! rigid body rotation point.
2471  call pushreal8(xxc(1))
2472  xxc(1) = xc(1) - rotationpoint(1)
2473  call pushreal8(xxc(2))
2474  xxc(2) = xc(2) - rotationpoint(2)
2475  call pushreal8(xxc(3))
2476  xxc(3) = xc(3) - rotationpoint(3)
2477 ! determine the total velocity of the cell center.
2478 ! this is a combination of rotation speed of this
2479 ! block and the entire rigid body rotation.
2480  end do
2481  call pushinteger4(i - 1)
2482  call pushinteger4(ad_from5)
2483  end do
2484  call pushinteger4(j - 1)
2485  call pushinteger4(ad_from6)
2486  call pushcontrol3b(3)
2487  else if (bcfaceid(mm) .eq. kmin) then
2488  ad_from8 = bcdata(mm)%jcbeg
2489  do j=ad_from8,bcdata(mm)%jcend
2490  ad_from7 = bcdata(mm)%icbeg
2491  do i=ad_from7,bcdata(mm)%icend
2492 ! compute the coordinates of the centroid of the face.
2493 ! normally this would be an average of i-1 and i, but
2494 ! due to the usage of the pointer xface and the fact
2495 ! that x starts at index 0 this is shifted 1 index.
2496  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
2497 & 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 1)+&
2498 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 1)+flowdoms(&
2499 & nn, groundlevel, sps)%x(i-1, j-1, 1, 1))
2500  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
2501 & 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 2)+&
2502 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 2)+flowdoms(&
2503 & nn, groundlevel, sps)%x(i-1, j-1, 1, 2))
2504  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
2505 & 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 3)+&
2506 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 3)+flowdoms(&
2507 & nn, groundlevel, sps)%x(i-1, j-1, 1, 3))
2508 ! determine the coordinates relative to the center
2509 ! of rotation.
2510  call pushreal8(xxc(1))
2511  xxc(1) = xc(1) - rotcenter(1)
2512  call pushreal8(xxc(2))
2513  xxc(2) = xc(2) - rotcenter(2)
2514  call pushreal8(xxc(3))
2515  xxc(3) = xc(3) - rotcenter(3)
2516 ! compute the velocity, which is the cross product
2517 ! of rotrate and xc.
2518 ! determine the coordinates relative to the
2519 ! rigid body rotation point.
2520  call pushreal8(xxc(1))
2521  xxc(1) = xc(1) - rotationpoint(1)
2522  call pushreal8(xxc(2))
2523  xxc(2) = xc(2) - rotationpoint(2)
2524  call pushreal8(xxc(3))
2525  xxc(3) = xc(3) - rotationpoint(3)
2526 ! determine the total velocity of the cell center.
2527 ! this is a combination of rotation speed of this
2528 ! block and the entire rigid body rotation.
2529  end do
2530  call pushinteger4(i - 1)
2531  call pushinteger4(ad_from7)
2532  end do
2533  call pushinteger4(j - 1)
2534  call pushinteger4(ad_from8)
2535  call pushcontrol3b(2)
2536  else if (bcfaceid(mm) .eq. kmax) then
2537  ad_from10 = bcdata(mm)%jcbeg
2538  do j=ad_from10,bcdata(mm)%jcend
2539  ad_from9 = bcdata(mm)%icbeg
2540  do i=ad_from9,bcdata(mm)%icend
2541 ! compute the coordinates of the centroid of the face.
2542 ! normally this would be an average of i-1 and i, but
2543 ! due to the usage of the pointer xface and the fact
2544 ! that x starts at index 0 this is shifted 1 index.
2545  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
2546 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 1)+&
2547 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 1)+flowdoms&
2548 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 1))
2549  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
2550 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 2)+&
2551 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 2)+flowdoms&
2552 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 2))
2553  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
2554 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 3)+&
2555 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 3)+flowdoms&
2556 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 3))
2557 ! determine the coordinates relative to the center
2558 ! of rotation.
2559  call pushreal8(xxc(1))
2560  xxc(1) = xc(1) - rotcenter(1)
2561  call pushreal8(xxc(2))
2562  xxc(2) = xc(2) - rotcenter(2)
2563  call pushreal8(xxc(3))
2564  xxc(3) = xc(3) - rotcenter(3)
2565 ! compute the velocity, which is the cross product
2566 ! of rotrate and xc.
2567 ! determine the coordinates relative to the
2568 ! rigid body rotation point.
2569  call pushreal8(xxc(1))
2570  xxc(1) = xc(1) - rotationpoint(1)
2571  call pushreal8(xxc(2))
2572  xxc(2) = xc(2) - rotationpoint(2)
2573  call pushreal8(xxc(3))
2574  xxc(3) = xc(3) - rotationpoint(3)
2575 ! determine the total velocity of the cell center.
2576 ! this is a combination of rotation speed of this
2577 ! block and the entire rigid body rotation.
2578  end do
2579  call pushinteger4(i - 1)
2580  call pushinteger4(ad_from9)
2581  end do
2582  call pushinteger4(j - 1)
2583  call pushinteger4(ad_from10)
2584  call pushcontrol3b(1)
2585  else
2586  call pushcontrol3b(0)
2587  end if
2588  end do bocoloop2
2589  timerefd = 0.0_8
2590  velxgrid0d = 0.0_8
2591  velzgrid0d = 0.0_8
2592  xcd = 0.0_8
2593  xxcd = 0.0_8
2594  derivrotationmatrixd = 0.0_8
2595  velygrid0d = 0.0_8
2596  do mm=nviscbocos,1,-1
2597  call popcontrol3b(branch)
2598  if (branch .lt. 3) then
2599  if (branch .eq. 0) then
2600  rotrated = 0.0_8
2601  velygridd = 0.0_8
2602  velzgridd = 0.0_8
2603  velxgridd = 0.0_8
2604  else if (branch .eq. 1) then
2605  rotrated = 0.0_8
2606  velygridd = 0.0_8
2607  velzgridd = 0.0_8
2608  velxgridd = 0.0_8
2609  call popinteger4(ad_from10)
2610  call popinteger4(ad_to10)
2611  do j=ad_to10,ad_from10,-1
2612  call popinteger4(ad_from9)
2613  call popinteger4(ad_to9)
2614  do i=ad_to9,ad_from9,-1
2615  velzgridd = velzgridd + bcdatad(mm)%uslip(i, j, 3)
2616  derivrotationmatrixd(3, 1) = derivrotationmatrixd(3, 1) &
2617 & + xxc(1)*bcdatad(mm)%uslip(i, j, 3)
2618  xxcd(1) = xxcd(1) + derivrotationmatrix(3, 1)*bcdatad(mm&
2619 & )%uslip(i, j, 3) + derivrotationmatrix(2, 1)*bcdatad(&
2620 & mm)%uslip(i, j, 2) + derivrotationmatrix(1, 1)*bcdatad&
2621 & (mm)%uslip(i, j, 1)
2622  derivrotationmatrixd(3, 2) = derivrotationmatrixd(3, 2) &
2623 & + xxc(2)*bcdatad(mm)%uslip(i, j, 3)
2624  xxcd(2) = xxcd(2) + derivrotationmatrix(3, 2)*bcdatad(mm&
2625 & )%uslip(i, j, 3) + derivrotationmatrix(2, 2)*bcdatad(&
2626 & mm)%uslip(i, j, 2) + derivrotationmatrix(1, 2)*bcdatad&
2627 & (mm)%uslip(i, j, 1)
2628  derivrotationmatrixd(3, 3) = derivrotationmatrixd(3, 3) &
2629 & + xxc(3)*bcdatad(mm)%uslip(i, j, 3)
2630  xxcd(3) = xxcd(3) + derivrotationmatrix(3, 3)*bcdatad(mm&
2631 & )%uslip(i, j, 3) + derivrotationmatrix(2, 3)*bcdatad(&
2632 & mm)%uslip(i, j, 2) + derivrotationmatrix(1, 3)*bcdatad&
2633 & (mm)%uslip(i, j, 1)
2634  velygridd = velygridd + bcdatad(mm)%uslip(i, j, 2)
2635  derivrotationmatrixd(2, 1) = derivrotationmatrixd(2, 1) &
2636 & + xxc(1)*bcdatad(mm)%uslip(i, j, 2)
2637  derivrotationmatrixd(2, 2) = derivrotationmatrixd(2, 2) &
2638 & + xxc(2)*bcdatad(mm)%uslip(i, j, 2)
2639  derivrotationmatrixd(2, 3) = derivrotationmatrixd(2, 3) &
2640 & + xxc(3)*bcdatad(mm)%uslip(i, j, 2)
2641  velxgridd = velxgridd + bcdatad(mm)%uslip(i, j, 1)
2642  derivrotationmatrixd(1, 1) = derivrotationmatrixd(1, 1) &
2643 & + xxc(1)*bcdatad(mm)%uslip(i, j, 1)
2644  derivrotationmatrixd(1, 2) = derivrotationmatrixd(1, 2) &
2645 & + xxc(2)*bcdatad(mm)%uslip(i, j, 1)
2646  derivrotationmatrixd(1, 3) = derivrotationmatrixd(1, 3) &
2647 & + xxc(3)*bcdatad(mm)%uslip(i, j, 1)
2648  call popreal8(xxc(3))
2649  xcd(3) = xcd(3) + xxcd(3)
2650  call popreal8(xxc(2))
2651  xcd(2) = xcd(2) + xxcd(2)
2652  xxcd(2) = rotrate(1)*bcdatad(mm)%uslip(i, j, 3)
2653  call popreal8(xxc(1))
2654  xcd(1) = xcd(1) + xxcd(1)
2655  xxcd(1) = -(rotrate(2)*bcdatad(mm)%uslip(i, j, 3))
2656  rotrated(1) = rotrated(1) + xxc(2)*bcdatad(mm)%uslip(i, &
2657 & j, 3)
2658  rotrated(2) = rotrated(2) - xxc(1)*bcdatad(mm)%uslip(i, &
2659 & j, 3)
2660  bcdatad(mm)%uslip(i, j, 3) = 0.0_8
2661  xxcd(3) = -(rotrate(1)*bcdatad(mm)%uslip(i, j, 2))
2662  rotrated(3) = rotrated(3) + xxc(1)*bcdatad(mm)%uslip(i, &
2663 & j, 2)
2664  xxcd(1) = xxcd(1) + rotrate(3)*bcdatad(mm)%uslip(i, j, 2&
2665 & )
2666  rotrated(1) = rotrated(1) - xxc(3)*bcdatad(mm)%uslip(i, &
2667 & j, 2)
2668  bcdatad(mm)%uslip(i, j, 2) = 0.0_8
2669  rotrated(2) = rotrated(2) + xxc(3)*bcdatad(mm)%uslip(i, &
2670 & j, 1)
2671  xxcd(3) = xxcd(3) + rotrate(2)*bcdatad(mm)%uslip(i, j, 1&
2672 & )
2673  rotrated(3) = rotrated(3) - xxc(2)*bcdatad(mm)%uslip(i, &
2674 & j, 1)
2675  xxcd(2) = xxcd(2) - rotrate(3)*bcdatad(mm)%uslip(i, j, 1&
2676 & )
2677  bcdatad(mm)%uslip(i, j, 1) = 0.0_8
2678  call popreal8(xxc(3))
2679  xcd(3) = xcd(3) + xxcd(3)
2680  xxcd(3) = 0.0_8
2681  call popreal8(xxc(2))
2682  xcd(2) = xcd(2) + xxcd(2)
2683  xxcd(2) = 0.0_8
2684  call popreal8(xxc(1))
2685  xcd(1) = xcd(1) + xxcd(1)
2686  xxcd(1) = 0.0_8
2687  tempd = fourth*xcd(3)
2688  xcd(3) = 0.0_8
2689  flowdomsd(nn, groundlevel, sps)%x(i, j, kl, 3) = &
2690 & flowdomsd(nn, groundlevel, sps)%x(i, j, kl, 3) + tempd
2691  flowdomsd(nn, groundlevel, sps)%x(i, j-1, kl, 3) = &
2692 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, kl, 3) + &
2693 & tempd
2694  flowdomsd(nn, groundlevel, sps)%x(i-1, j, kl, 3) = &
2695 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, kl, 3) + &
2696 & tempd
2697  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, kl, 3) = &
2698 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, kl, 3) + &
2699 & tempd
2700  tempd = fourth*xcd(2)
2701  xcd(2) = 0.0_8
2702  flowdomsd(nn, groundlevel, sps)%x(i, j, kl, 2) = &
2703 & flowdomsd(nn, groundlevel, sps)%x(i, j, kl, 2) + tempd
2704  flowdomsd(nn, groundlevel, sps)%x(i, j-1, kl, 2) = &
2705 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, kl, 2) + &
2706 & tempd
2707  flowdomsd(nn, groundlevel, sps)%x(i-1, j, kl, 2) = &
2708 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, kl, 2) + &
2709 & tempd
2710  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, kl, 2) = &
2711 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, kl, 2) + &
2712 & tempd
2713  tempd = fourth*xcd(1)
2714  xcd(1) = 0.0_8
2715  flowdomsd(nn, groundlevel, sps)%x(i, j, kl, 1) = &
2716 & flowdomsd(nn, groundlevel, sps)%x(i, j, kl, 1) + tempd
2717  flowdomsd(nn, groundlevel, sps)%x(i, j-1, kl, 1) = &
2718 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, kl, 1) + &
2719 & tempd
2720  flowdomsd(nn, groundlevel, sps)%x(i-1, j, kl, 1) = &
2721 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, kl, 1) + &
2722 & tempd
2723  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, kl, 1) = &
2724 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, kl, 1) + &
2725 & tempd
2726  end do
2727  end do
2728  else
2729  rotrated = 0.0_8
2730  velygridd = 0.0_8
2731  velzgridd = 0.0_8
2732  velxgridd = 0.0_8
2733  call popinteger4(ad_from8)
2734  call popinteger4(ad_to8)
2735  do j=ad_to8,ad_from8,-1
2736  call popinteger4(ad_from7)
2737  call popinteger4(ad_to7)
2738  do i=ad_to7,ad_from7,-1
2739  velzgridd = velzgridd + bcdatad(mm)%uslip(i, j, 3)
2740  derivrotationmatrixd(3, 1) = derivrotationmatrixd(3, 1) &
2741 & + xxc(1)*bcdatad(mm)%uslip(i, j, 3)
2742  xxcd(1) = xxcd(1) + derivrotationmatrix(3, 1)*bcdatad(mm&
2743 & )%uslip(i, j, 3) + derivrotationmatrix(2, 1)*bcdatad(&
2744 & mm)%uslip(i, j, 2) + derivrotationmatrix(1, 1)*bcdatad&
2745 & (mm)%uslip(i, j, 1)
2746  derivrotationmatrixd(3, 2) = derivrotationmatrixd(3, 2) &
2747 & + xxc(2)*bcdatad(mm)%uslip(i, j, 3)
2748  xxcd(2) = xxcd(2) + derivrotationmatrix(3, 2)*bcdatad(mm&
2749 & )%uslip(i, j, 3) + derivrotationmatrix(2, 2)*bcdatad(&
2750 & mm)%uslip(i, j, 2) + derivrotationmatrix(1, 2)*bcdatad&
2751 & (mm)%uslip(i, j, 1)
2752  derivrotationmatrixd(3, 3) = derivrotationmatrixd(3, 3) &
2753 & + xxc(3)*bcdatad(mm)%uslip(i, j, 3)
2754  xxcd(3) = xxcd(3) + derivrotationmatrix(3, 3)*bcdatad(mm&
2755 & )%uslip(i, j, 3) + derivrotationmatrix(2, 3)*bcdatad(&
2756 & mm)%uslip(i, j, 2) + derivrotationmatrix(1, 3)*bcdatad&
2757 & (mm)%uslip(i, j, 1)
2758  velygridd = velygridd + bcdatad(mm)%uslip(i, j, 2)
2759  derivrotationmatrixd(2, 1) = derivrotationmatrixd(2, 1) &
2760 & + xxc(1)*bcdatad(mm)%uslip(i, j, 2)
2761  derivrotationmatrixd(2, 2) = derivrotationmatrixd(2, 2) &
2762 & + xxc(2)*bcdatad(mm)%uslip(i, j, 2)
2763  derivrotationmatrixd(2, 3) = derivrotationmatrixd(2, 3) &
2764 & + xxc(3)*bcdatad(mm)%uslip(i, j, 2)
2765  velxgridd = velxgridd + bcdatad(mm)%uslip(i, j, 1)
2766  derivrotationmatrixd(1, 1) = derivrotationmatrixd(1, 1) &
2767 & + xxc(1)*bcdatad(mm)%uslip(i, j, 1)
2768  derivrotationmatrixd(1, 2) = derivrotationmatrixd(1, 2) &
2769 & + xxc(2)*bcdatad(mm)%uslip(i, j, 1)
2770  derivrotationmatrixd(1, 3) = derivrotationmatrixd(1, 3) &
2771 & + xxc(3)*bcdatad(mm)%uslip(i, j, 1)
2772  call popreal8(xxc(3))
2773  xcd(3) = xcd(3) + xxcd(3)
2774  call popreal8(xxc(2))
2775  xcd(2) = xcd(2) + xxcd(2)
2776  xxcd(2) = rotrate(1)*bcdatad(mm)%uslip(i, j, 3)
2777  call popreal8(xxc(1))
2778  xcd(1) = xcd(1) + xxcd(1)
2779  xxcd(1) = -(rotrate(2)*bcdatad(mm)%uslip(i, j, 3))
2780  rotrated(1) = rotrated(1) + xxc(2)*bcdatad(mm)%uslip(i, &
2781 & j, 3)
2782  rotrated(2) = rotrated(2) - xxc(1)*bcdatad(mm)%uslip(i, &
2783 & j, 3)
2784  bcdatad(mm)%uslip(i, j, 3) = 0.0_8
2785  xxcd(3) = -(rotrate(1)*bcdatad(mm)%uslip(i, j, 2))
2786  rotrated(3) = rotrated(3) + xxc(1)*bcdatad(mm)%uslip(i, &
2787 & j, 2)
2788  xxcd(1) = xxcd(1) + rotrate(3)*bcdatad(mm)%uslip(i, j, 2&
2789 & )
2790  rotrated(1) = rotrated(1) - xxc(3)*bcdatad(mm)%uslip(i, &
2791 & j, 2)
2792  bcdatad(mm)%uslip(i, j, 2) = 0.0_8
2793  rotrated(2) = rotrated(2) + xxc(3)*bcdatad(mm)%uslip(i, &
2794 & j, 1)
2795  xxcd(3) = xxcd(3) + rotrate(2)*bcdatad(mm)%uslip(i, j, 1&
2796 & )
2797  rotrated(3) = rotrated(3) - xxc(2)*bcdatad(mm)%uslip(i, &
2798 & j, 1)
2799  xxcd(2) = xxcd(2) - rotrate(3)*bcdatad(mm)%uslip(i, j, 1&
2800 & )
2801  bcdatad(mm)%uslip(i, j, 1) = 0.0_8
2802  call popreal8(xxc(3))
2803  xcd(3) = xcd(3) + xxcd(3)
2804  xxcd(3) = 0.0_8
2805  call popreal8(xxc(2))
2806  xcd(2) = xcd(2) + xxcd(2)
2807  xxcd(2) = 0.0_8
2808  call popreal8(xxc(1))
2809  xcd(1) = xcd(1) + xxcd(1)
2810  xxcd(1) = 0.0_8
2811  tempd = fourth*xcd(3)
2812  xcd(3) = 0.0_8
2813  flowdomsd(nn, groundlevel, sps)%x(i, j, 1, 3) = &
2814 & flowdomsd(nn, groundlevel, sps)%x(i, j, 1, 3) + tempd
2815  flowdomsd(nn, groundlevel, sps)%x(i, j-1, 1, 3) = &
2816 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, 1, 3) + &
2817 & tempd
2818  flowdomsd(nn, groundlevel, sps)%x(i-1, j, 1, 3) = &
2819 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, 1, 3) + &
2820 & tempd
2821  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, 1, 3) = &
2822 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, 1, 3) + &
2823 & tempd
2824  tempd = fourth*xcd(2)
2825  xcd(2) = 0.0_8
2826  flowdomsd(nn, groundlevel, sps)%x(i, j, 1, 2) = &
2827 & flowdomsd(nn, groundlevel, sps)%x(i, j, 1, 2) + tempd
2828  flowdomsd(nn, groundlevel, sps)%x(i, j-1, 1, 2) = &
2829 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, 1, 2) + &
2830 & tempd
2831  flowdomsd(nn, groundlevel, sps)%x(i-1, j, 1, 2) = &
2832 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, 1, 2) + &
2833 & tempd
2834  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, 1, 2) = &
2835 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, 1, 2) + &
2836 & tempd
2837  tempd = fourth*xcd(1)
2838  xcd(1) = 0.0_8
2839  flowdomsd(nn, groundlevel, sps)%x(i, j, 1, 1) = &
2840 & flowdomsd(nn, groundlevel, sps)%x(i, j, 1, 1) + tempd
2841  flowdomsd(nn, groundlevel, sps)%x(i, j-1, 1, 1) = &
2842 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, 1, 1) + &
2843 & tempd
2844  flowdomsd(nn, groundlevel, sps)%x(i-1, j, 1, 1) = &
2845 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, 1, 1) + &
2846 & tempd
2847  flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, 1, 1) = &
2848 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, 1, 1) + &
2849 & tempd
2850  end do
2851  end do
2852  end if
2853  else if (branch .lt. 5) then
2854  if (branch .eq. 3) then
2855  rotrated = 0.0_8
2856  velygridd = 0.0_8
2857  velzgridd = 0.0_8
2858  velxgridd = 0.0_8
2859  call popinteger4(ad_from6)
2860  call popinteger4(ad_to6)
2861  do j=ad_to6,ad_from6,-1
2862  call popinteger4(ad_from5)
2863  call popinteger4(ad_to5)
2864  do i=ad_to5,ad_from5,-1
2865  velzgridd = velzgridd + bcdatad(mm)%uslip(i, j, 3)
2866  derivrotationmatrixd(3, 1) = derivrotationmatrixd(3, 1) &
2867 & + xxc(1)*bcdatad(mm)%uslip(i, j, 3)
2868  xxcd(1) = xxcd(1) + derivrotationmatrix(3, 1)*bcdatad(mm&
2869 & )%uslip(i, j, 3) + derivrotationmatrix(2, 1)*bcdatad(&
2870 & mm)%uslip(i, j, 2) + derivrotationmatrix(1, 1)*bcdatad&
2871 & (mm)%uslip(i, j, 1)
2872  derivrotationmatrixd(3, 2) = derivrotationmatrixd(3, 2) &
2873 & + xxc(2)*bcdatad(mm)%uslip(i, j, 3)
2874  xxcd(2) = xxcd(2) + derivrotationmatrix(3, 2)*bcdatad(mm&
2875 & )%uslip(i, j, 3) + derivrotationmatrix(2, 2)*bcdatad(&
2876 & mm)%uslip(i, j, 2) + derivrotationmatrix(1, 2)*bcdatad&
2877 & (mm)%uslip(i, j, 1)
2878  derivrotationmatrixd(3, 3) = derivrotationmatrixd(3, 3) &
2879 & + xxc(3)*bcdatad(mm)%uslip(i, j, 3)
2880  xxcd(3) = xxcd(3) + derivrotationmatrix(3, 3)*bcdatad(mm&
2881 & )%uslip(i, j, 3) + derivrotationmatrix(2, 3)*bcdatad(&
2882 & mm)%uslip(i, j, 2) + derivrotationmatrix(1, 3)*bcdatad&
2883 & (mm)%uslip(i, j, 1)
2884  velygridd = velygridd + bcdatad(mm)%uslip(i, j, 2)
2885  derivrotationmatrixd(2, 1) = derivrotationmatrixd(2, 1) &
2886 & + xxc(1)*bcdatad(mm)%uslip(i, j, 2)
2887  derivrotationmatrixd(2, 2) = derivrotationmatrixd(2, 2) &
2888 & + xxc(2)*bcdatad(mm)%uslip(i, j, 2)
2889  derivrotationmatrixd(2, 3) = derivrotationmatrixd(2, 3) &
2890 & + xxc(3)*bcdatad(mm)%uslip(i, j, 2)
2891  velxgridd = velxgridd + bcdatad(mm)%uslip(i, j, 1)
2892  derivrotationmatrixd(1, 1) = derivrotationmatrixd(1, 1) &
2893 & + xxc(1)*bcdatad(mm)%uslip(i, j, 1)
2894  derivrotationmatrixd(1, 2) = derivrotationmatrixd(1, 2) &
2895 & + xxc(2)*bcdatad(mm)%uslip(i, j, 1)
2896  derivrotationmatrixd(1, 3) = derivrotationmatrixd(1, 3) &
2897 & + xxc(3)*bcdatad(mm)%uslip(i, j, 1)
2898  call popreal8(xxc(3))
2899  xcd(3) = xcd(3) + xxcd(3)
2900  call popreal8(xxc(2))
2901  xcd(2) = xcd(2) + xxcd(2)
2902  xxcd(2) = rotrate(1)*bcdatad(mm)%uslip(i, j, 3)
2903  call popreal8(xxc(1))
2904  xcd(1) = xcd(1) + xxcd(1)
2905  xxcd(1) = -(rotrate(2)*bcdatad(mm)%uslip(i, j, 3))
2906  rotrated(1) = rotrated(1) + xxc(2)*bcdatad(mm)%uslip(i, &
2907 & j, 3)
2908  rotrated(2) = rotrated(2) - xxc(1)*bcdatad(mm)%uslip(i, &
2909 & j, 3)
2910  bcdatad(mm)%uslip(i, j, 3) = 0.0_8
2911  xxcd(3) = -(rotrate(1)*bcdatad(mm)%uslip(i, j, 2))
2912  rotrated(3) = rotrated(3) + xxc(1)*bcdatad(mm)%uslip(i, &
2913 & j, 2)
2914  xxcd(1) = xxcd(1) + rotrate(3)*bcdatad(mm)%uslip(i, j, 2&
2915 & )
2916  rotrated(1) = rotrated(1) - xxc(3)*bcdatad(mm)%uslip(i, &
2917 & j, 2)
2918  bcdatad(mm)%uslip(i, j, 2) = 0.0_8
2919  rotrated(2) = rotrated(2) + xxc(3)*bcdatad(mm)%uslip(i, &
2920 & j, 1)
2921  xxcd(3) = xxcd(3) + rotrate(2)*bcdatad(mm)%uslip(i, j, 1&
2922 & )
2923  rotrated(3) = rotrated(3) - xxc(2)*bcdatad(mm)%uslip(i, &
2924 & j, 1)
2925  xxcd(2) = xxcd(2) - rotrate(3)*bcdatad(mm)%uslip(i, j, 1&
2926 & )
2927  bcdatad(mm)%uslip(i, j, 1) = 0.0_8
2928  call popreal8(xxc(3))
2929  xcd(3) = xcd(3) + xxcd(3)
2930  xxcd(3) = 0.0_8
2931  call popreal8(xxc(2))
2932  xcd(2) = xcd(2) + xxcd(2)
2933  xxcd(2) = 0.0_8
2934  call popreal8(xxc(1))
2935  xcd(1) = xcd(1) + xxcd(1)
2936  xxcd(1) = 0.0_8
2937  tempd = fourth*xcd(3)
2938  xcd(3) = 0.0_8
2939  flowdomsd(nn, groundlevel, sps)%x(i, jl, j, 3) = &
2940 & flowdomsd(nn, groundlevel, sps)%x(i, jl, j, 3) + tempd
2941  flowdomsd(nn, groundlevel, sps)%x(i, jl, j-1, 3) = &
2942 & flowdomsd(nn, groundlevel, sps)%x(i, jl, j-1, 3) + &
2943 & tempd
2944  flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j, 3) = &
2945 & flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j, 3) + &
2946 & tempd
2947  flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j-1, 3) = &
2948 & flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j-1, 3) + &
2949 & tempd
2950  tempd = fourth*xcd(2)
2951  xcd(2) = 0.0_8
2952  flowdomsd(nn, groundlevel, sps)%x(i, jl, j, 2) = &
2953 & flowdomsd(nn, groundlevel, sps)%x(i, jl, j, 2) + tempd
2954  flowdomsd(nn, groundlevel, sps)%x(i, jl, j-1, 2) = &
2955 & flowdomsd(nn, groundlevel, sps)%x(i, jl, j-1, 2) + &
2956 & tempd
2957  flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j, 2) = &
2958 & flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j, 2) + &
2959 & tempd
2960  flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j-1, 2) = &
2961 & flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j-1, 2) + &
2962 & tempd
2963  tempd = fourth*xcd(1)
2964  xcd(1) = 0.0_8
2965  flowdomsd(nn, groundlevel, sps)%x(i, jl, j, 1) = &
2966 & flowdomsd(nn, groundlevel, sps)%x(i, jl, j, 1) + tempd
2967  flowdomsd(nn, groundlevel, sps)%x(i, jl, j-1, 1) = &
2968 & flowdomsd(nn, groundlevel, sps)%x(i, jl, j-1, 1) + &
2969 & tempd
2970  flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j, 1) = &
2971 & flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j, 1) + &
2972 & tempd
2973  flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j-1, 1) = &
2974 & flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j-1, 1) + &
2975 & tempd
2976  end do
2977  end do
2978  else
2979  rotrated = 0.0_8
2980  velygridd = 0.0_8
2981  velzgridd = 0.0_8
2982  velxgridd = 0.0_8
2983  call popinteger4(ad_from4)
2984  call popinteger4(ad_to4)
2985  do j=ad_to4,ad_from4,-1
2986  call popinteger4(ad_from3)
2987  call popinteger4(ad_to3)
2988  do i=ad_to3,ad_from3,-1
2989  velzgridd = velzgridd + bcdatad(mm)%uslip(i, j, 3)
2990  derivrotationmatrixd(3, 1) = derivrotationmatrixd(3, 1) &
2991 & + xxc(1)*bcdatad(mm)%uslip(i, j, 3)
2992  xxcd(1) = xxcd(1) + derivrotationmatrix(3, 1)*bcdatad(mm&
2993 & )%uslip(i, j, 3) + derivrotationmatrix(2, 1)*bcdatad(&
2994 & mm)%uslip(i, j, 2) + derivrotationmatrix(1, 1)*bcdatad&
2995 & (mm)%uslip(i, j, 1)
2996  derivrotationmatrixd(3, 2) = derivrotationmatrixd(3, 2) &
2997 & + xxc(2)*bcdatad(mm)%uslip(i, j, 3)
2998  xxcd(2) = xxcd(2) + derivrotationmatrix(3, 2)*bcdatad(mm&
2999 & )%uslip(i, j, 3) + derivrotationmatrix(2, 2)*bcdatad(&
3000 & mm)%uslip(i, j, 2) + derivrotationmatrix(1, 2)*bcdatad&
3001 & (mm)%uslip(i, j, 1)
3002  derivrotationmatrixd(3, 3) = derivrotationmatrixd(3, 3) &
3003 & + xxc(3)*bcdatad(mm)%uslip(i, j, 3)
3004  xxcd(3) = xxcd(3) + derivrotationmatrix(3, 3)*bcdatad(mm&
3005 & )%uslip(i, j, 3) + derivrotationmatrix(2, 3)*bcdatad(&
3006 & mm)%uslip(i, j, 2) + derivrotationmatrix(1, 3)*bcdatad&
3007 & (mm)%uslip(i, j, 1)
3008  velygridd = velygridd + bcdatad(mm)%uslip(i, j, 2)
3009  derivrotationmatrixd(2, 1) = derivrotationmatrixd(2, 1) &
3010 & + xxc(1)*bcdatad(mm)%uslip(i, j, 2)
3011  derivrotationmatrixd(2, 2) = derivrotationmatrixd(2, 2) &
3012 & + xxc(2)*bcdatad(mm)%uslip(i, j, 2)
3013  derivrotationmatrixd(2, 3) = derivrotationmatrixd(2, 3) &
3014 & + xxc(3)*bcdatad(mm)%uslip(i, j, 2)
3015  velxgridd = velxgridd + bcdatad(mm)%uslip(i, j, 1)
3016  derivrotationmatrixd(1, 1) = derivrotationmatrixd(1, 1) &
3017 & + xxc(1)*bcdatad(mm)%uslip(i, j, 1)
3018  derivrotationmatrixd(1, 2) = derivrotationmatrixd(1, 2) &
3019 & + xxc(2)*bcdatad(mm)%uslip(i, j, 1)
3020  derivrotationmatrixd(1, 3) = derivrotationmatrixd(1, 3) &
3021 & + xxc(3)*bcdatad(mm)%uslip(i, j, 1)
3022  call popreal8(xxc(3))
3023  xcd(3) = xcd(3) + xxcd(3)
3024  call popreal8(xxc(2))
3025  xcd(2) = xcd(2) + xxcd(2)
3026  xxcd(2) = rotrate(1)*bcdatad(mm)%uslip(i, j, 3)
3027  call popreal8(xxc(1))
3028  xcd(1) = xcd(1) + xxcd(1)
3029  xxcd(1) = -(rotrate(2)*bcdatad(mm)%uslip(i, j, 3))
3030  rotrated(1) = rotrated(1) + xxc(2)*bcdatad(mm)%uslip(i, &
3031 & j, 3)
3032  rotrated(2) = rotrated(2) - xxc(1)*bcdatad(mm)%uslip(i, &
3033 & j, 3)
3034  bcdatad(mm)%uslip(i, j, 3) = 0.0_8
3035  xxcd(3) = -(rotrate(1)*bcdatad(mm)%uslip(i, j, 2))
3036  rotrated(3) = rotrated(3) + xxc(1)*bcdatad(mm)%uslip(i, &
3037 & j, 2)
3038  xxcd(1) = xxcd(1) + rotrate(3)*bcdatad(mm)%uslip(i, j, 2&
3039 & )
3040  rotrated(1) = rotrated(1) - xxc(3)*bcdatad(mm)%uslip(i, &
3041 & j, 2)
3042  bcdatad(mm)%uslip(i, j, 2) = 0.0_8
3043  rotrated(2) = rotrated(2) + xxc(3)*bcdatad(mm)%uslip(i, &
3044 & j, 1)
3045  xxcd(3) = xxcd(3) + rotrate(2)*bcdatad(mm)%uslip(i, j, 1&
3046 & )
3047  rotrated(3) = rotrated(3) - xxc(2)*bcdatad(mm)%uslip(i, &
3048 & j, 1)
3049  xxcd(2) = xxcd(2) - rotrate(3)*bcdatad(mm)%uslip(i, j, 1&
3050 & )
3051  bcdatad(mm)%uslip(i, j, 1) = 0.0_8
3052  call popreal8(xxc(3))
3053  xcd(3) = xcd(3) + xxcd(3)
3054  xxcd(3) = 0.0_8
3055  call popreal8(xxc(2))
3056  xcd(2) = xcd(2) + xxcd(2)
3057  xxcd(2) = 0.0_8
3058  call popreal8(xxc(1))
3059  xcd(1) = xcd(1) + xxcd(1)
3060  xxcd(1) = 0.0_8
3061  tempd = fourth*xcd(3)
3062  xcd(3) = 0.0_8
3063  flowdomsd(nn, groundlevel, sps)%x(i, 1, j, 3) = &
3064 & flowdomsd(nn, groundlevel, sps)%x(i, 1, j, 3) + tempd
3065  flowdomsd(nn, groundlevel, sps)%x(i, 1, j-1, 3) = &
3066 & flowdomsd(nn, groundlevel, sps)%x(i, 1, j-1, 3) + &
3067 & tempd
3068  flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j, 3) = &
3069 & flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j, 3) + &
3070 & tempd
3071  flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j-1, 3) = &
3072 & flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j-1, 3) + &
3073 & tempd
3074  tempd = fourth*xcd(2)
3075  xcd(2) = 0.0_8
3076  flowdomsd(nn, groundlevel, sps)%x(i, 1, j, 2) = &
3077 & flowdomsd(nn, groundlevel, sps)%x(i, 1, j, 2) + tempd
3078  flowdomsd(nn, groundlevel, sps)%x(i, 1, j-1, 2) = &
3079 & flowdomsd(nn, groundlevel, sps)%x(i, 1, j-1, 2) + &
3080 & tempd
3081  flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j, 2) = &
3082 & flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j, 2) + &
3083 & tempd
3084  flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j-1, 2) = &
3085 & flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j-1, 2) + &
3086 & tempd
3087  tempd = fourth*xcd(1)
3088  xcd(1) = 0.0_8
3089  flowdomsd(nn, groundlevel, sps)%x(i, 1, j, 1) = &
3090 & flowdomsd(nn, groundlevel, sps)%x(i, 1, j, 1) + tempd
3091  flowdomsd(nn, groundlevel, sps)%x(i, 1, j-1, 1) = &
3092 & flowdomsd(nn, groundlevel, sps)%x(i, 1, j-1, 1) + &
3093 & tempd
3094  flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j, 1) = &
3095 & flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j, 1) + &
3096 & tempd
3097  flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j-1, 1) = &
3098 & flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j-1, 1) + &
3099 & tempd
3100  end do
3101  end do
3102  end if
3103  else if (branch .eq. 5) then
3104  rotrated = 0.0_8
3105  velygridd = 0.0_8
3106  velzgridd = 0.0_8
3107  velxgridd = 0.0_8
3108  call popinteger4(ad_from2)
3109  call popinteger4(ad_to2)
3110  do j=ad_to2,ad_from2,-1
3111  call popinteger4(ad_from1)
3112  call popinteger4(ad_to1)
3113  do i=ad_to1,ad_from1,-1
3114  velzgridd = velzgridd + bcdatad(mm)%uslip(i, j, 3)
3115  derivrotationmatrixd(3, 1) = derivrotationmatrixd(3, 1) + &
3116 & xxc(1)*bcdatad(mm)%uslip(i, j, 3)
3117  xxcd(1) = xxcd(1) + derivrotationmatrix(3, 1)*bcdatad(mm)%&
3118 & uslip(i, j, 3) + derivrotationmatrix(2, 1)*bcdatad(mm)%&
3119 & uslip(i, j, 2) + derivrotationmatrix(1, 1)*bcdatad(mm)%&
3120 & uslip(i, j, 1)
3121  derivrotationmatrixd(3, 2) = derivrotationmatrixd(3, 2) + &
3122 & xxc(2)*bcdatad(mm)%uslip(i, j, 3)
3123  xxcd(2) = xxcd(2) + derivrotationmatrix(3, 2)*bcdatad(mm)%&
3124 & uslip(i, j, 3) + derivrotationmatrix(2, 2)*bcdatad(mm)%&
3125 & uslip(i, j, 2) + derivrotationmatrix(1, 2)*bcdatad(mm)%&
3126 & uslip(i, j, 1)
3127  derivrotationmatrixd(3, 3) = derivrotationmatrixd(3, 3) + &
3128 & xxc(3)*bcdatad(mm)%uslip(i, j, 3)
3129  xxcd(3) = xxcd(3) + derivrotationmatrix(3, 3)*bcdatad(mm)%&
3130 & uslip(i, j, 3) + derivrotationmatrix(2, 3)*bcdatad(mm)%&
3131 & uslip(i, j, 2) + derivrotationmatrix(1, 3)*bcdatad(mm)%&
3132 & uslip(i, j, 1)
3133  velygridd = velygridd + bcdatad(mm)%uslip(i, j, 2)
3134  derivrotationmatrixd(2, 1) = derivrotationmatrixd(2, 1) + &
3135 & xxc(1)*bcdatad(mm)%uslip(i, j, 2)
3136  derivrotationmatrixd(2, 2) = derivrotationmatrixd(2, 2) + &
3137 & xxc(2)*bcdatad(mm)%uslip(i, j, 2)
3138  derivrotationmatrixd(2, 3) = derivrotationmatrixd(2, 3) + &
3139 & xxc(3)*bcdatad(mm)%uslip(i, j, 2)
3140  velxgridd = velxgridd + bcdatad(mm)%uslip(i, j, 1)
3141  derivrotationmatrixd(1, 1) = derivrotationmatrixd(1, 1) + &
3142 & xxc(1)*bcdatad(mm)%uslip(i, j, 1)
3143  derivrotationmatrixd(1, 2) = derivrotationmatrixd(1, 2) + &
3144 & xxc(2)*bcdatad(mm)%uslip(i, j, 1)
3145  derivrotationmatrixd(1, 3) = derivrotationmatrixd(1, 3) + &
3146 & xxc(3)*bcdatad(mm)%uslip(i, j, 1)
3147  call popreal8(xxc(3))
3148  xcd(3) = xcd(3) + xxcd(3)
3149  call popreal8(xxc(2))
3150  xcd(2) = xcd(2) + xxcd(2)
3151  xxcd(2) = rotrate(1)*bcdatad(mm)%uslip(i, j, 3)
3152  call popreal8(xxc(1))
3153  xcd(1) = xcd(1) + xxcd(1)
3154  xxcd(1) = -(rotrate(2)*bcdatad(mm)%uslip(i, j, 3))
3155  rotrated(1) = rotrated(1) + xxc(2)*bcdatad(mm)%uslip(i, j&
3156 & , 3)
3157  rotrated(2) = rotrated(2) - xxc(1)*bcdatad(mm)%uslip(i, j&
3158 & , 3)
3159  bcdatad(mm)%uslip(i, j, 3) = 0.0_8
3160  xxcd(3) = -(rotrate(1)*bcdatad(mm)%uslip(i, j, 2))
3161  rotrated(3) = rotrated(3) + xxc(1)*bcdatad(mm)%uslip(i, j&
3162 & , 2)
3163  xxcd(1) = xxcd(1) + rotrate(3)*bcdatad(mm)%uslip(i, j, 2)
3164  rotrated(1) = rotrated(1) - xxc(3)*bcdatad(mm)%uslip(i, j&
3165 & , 2)
3166  bcdatad(mm)%uslip(i, j, 2) = 0.0_8
3167  rotrated(2) = rotrated(2) + xxc(3)*bcdatad(mm)%uslip(i, j&
3168 & , 1)
3169  xxcd(3) = xxcd(3) + rotrate(2)*bcdatad(mm)%uslip(i, j, 1)
3170  rotrated(3) = rotrated(3) - xxc(2)*bcdatad(mm)%uslip(i, j&
3171 & , 1)
3172  xxcd(2) = xxcd(2) - rotrate(3)*bcdatad(mm)%uslip(i, j, 1)
3173  bcdatad(mm)%uslip(i, j, 1) = 0.0_8
3174  call popreal8(xxc(3))
3175  xcd(3) = xcd(3) + xxcd(3)
3176  xxcd(3) = 0.0_8
3177  call popreal8(xxc(2))
3178  xcd(2) = xcd(2) + xxcd(2)
3179  xxcd(2) = 0.0_8
3180  call popreal8(xxc(1))
3181  xcd(1) = xcd(1) + xxcd(1)
3182  xxcd(1) = 0.0_8
3183  tempd = fourth*xcd(3)
3184  xcd(3) = 0.0_8
3185  flowdomsd(nn, groundlevel, sps)%x(il, i, j, 3) = flowdomsd&
3186 & (nn, groundlevel, sps)%x(il, i, j, 3) + tempd
3187  flowdomsd(nn, groundlevel, sps)%x(il, i, j-1, 3) = &
3188 & flowdomsd(nn, groundlevel, sps)%x(il, i, j-1, 3) + tempd
3189  flowdomsd(nn, groundlevel, sps)%x(il, i-1, j, 3) = &
3190 & flowdomsd(nn, groundlevel, sps)%x(il, i-1, j, 3) + tempd
3191  flowdomsd(nn, groundlevel, sps)%x(il, i-1, j-1, 3) = &
3192 & flowdomsd(nn, groundlevel, sps)%x(il, i-1, j-1, 3) + &
3193 & tempd
3194  tempd = fourth*xcd(2)
3195  xcd(2) = 0.0_8
3196  flowdomsd(nn, groundlevel, sps)%x(il, i, j, 2) = flowdomsd&
3197 & (nn, groundlevel, sps)%x(il, i, j, 2) + tempd
3198  flowdomsd(nn, groundlevel, sps)%x(il, i, j-1, 2) = &
3199 & flowdomsd(nn, groundlevel, sps)%x(il, i, j-1, 2) + tempd
3200  flowdomsd(nn, groundlevel, sps)%x(il, i-1, j, 2) = &
3201 & flowdomsd(nn, groundlevel, sps)%x(il, i-1, j, 2) + tempd
3202  flowdomsd(nn, groundlevel, sps)%x(il, i-1, j-1, 2) = &
3203 & flowdomsd(nn, groundlevel, sps)%x(il, i-1, j-1, 2) + &
3204 & tempd
3205  tempd = fourth*xcd(1)
3206  xcd(1) = 0.0_8
3207  flowdomsd(nn, groundlevel, sps)%x(il, i, j, 1) = flowdomsd&
3208 & (nn, groundlevel, sps)%x(il, i, j, 1) + tempd
3209  flowdomsd(nn, groundlevel, sps)%x(il, i, j-1, 1) = &
3210 & flowdomsd(nn, groundlevel, sps)%x(il, i, j-1, 1) + tempd
3211  flowdomsd(nn, groundlevel, sps)%x(il, i-1, j, 1) = &
3212 & flowdomsd(nn, groundlevel, sps)%x(il, i-1, j, 1) + tempd
3213  flowdomsd(nn, groundlevel, sps)%x(il, i-1, j-1, 1) = &
3214 & flowdomsd(nn, groundlevel, sps)%x(il, i-1, j-1, 1) + &
3215 & tempd
3216  end do
3217  end do
3218  else
3219  rotrated = 0.0_8
3220  velygridd = 0.0_8
3221  velzgridd = 0.0_8
3222  velxgridd = 0.0_8
3223  call popinteger4(ad_from0)
3224  call popinteger4(ad_to0)
3225  do j=ad_to0,ad_from0,-1
3226  call popinteger4(ad_from)
3227  call popinteger4(ad_to)
3228  do i=ad_to,ad_from,-1
3229  velzgridd = velzgridd + bcdatad(mm)%uslip(i, j, 3)
3230  derivrotationmatrixd(3, 1) = derivrotationmatrixd(3, 1) + &
3231 & xxc(1)*bcdatad(mm)%uslip(i, j, 3)
3232  xxcd(1) = xxcd(1) + derivrotationmatrix(3, 1)*bcdatad(mm)%&
3233 & uslip(i, j, 3) + derivrotationmatrix(2, 1)*bcdatad(mm)%&
3234 & uslip(i, j, 2) + derivrotationmatrix(1, 1)*bcdatad(mm)%&
3235 & uslip(i, j, 1)
3236  derivrotationmatrixd(3, 2) = derivrotationmatrixd(3, 2) + &
3237 & xxc(2)*bcdatad(mm)%uslip(i, j, 3)
3238  xxcd(2) = xxcd(2) + derivrotationmatrix(3, 2)*bcdatad(mm)%&
3239 & uslip(i, j, 3) + derivrotationmatrix(2, 2)*bcdatad(mm)%&
3240 & uslip(i, j, 2) + derivrotationmatrix(1, 2)*bcdatad(mm)%&
3241 & uslip(i, j, 1)
3242  derivrotationmatrixd(3, 3) = derivrotationmatrixd(3, 3) + &
3243 & xxc(3)*bcdatad(mm)%uslip(i, j, 3)
3244  xxcd(3) = xxcd(3) + derivrotationmatrix(3, 3)*bcdatad(mm)%&
3245 & uslip(i, j, 3) + derivrotationmatrix(2, 3)*bcdatad(mm)%&
3246 & uslip(i, j, 2) + derivrotationmatrix(1, 3)*bcdatad(mm)%&
3247 & uslip(i, j, 1)
3248  velygridd = velygridd + bcdatad(mm)%uslip(i, j, 2)
3249  derivrotationmatrixd(2, 1) = derivrotationmatrixd(2, 1) + &
3250 & xxc(1)*bcdatad(mm)%uslip(i, j, 2)
3251  derivrotationmatrixd(2, 2) = derivrotationmatrixd(2, 2) + &
3252 & xxc(2)*bcdatad(mm)%uslip(i, j, 2)
3253  derivrotationmatrixd(2, 3) = derivrotationmatrixd(2, 3) + &
3254 & xxc(3)*bcdatad(mm)%uslip(i, j, 2)
3255  velxgridd = velxgridd + bcdatad(mm)%uslip(i, j, 1)
3256  derivrotationmatrixd(1, 1) = derivrotationmatrixd(1, 1) + &
3257 & xxc(1)*bcdatad(mm)%uslip(i, j, 1)
3258  derivrotationmatrixd(1, 2) = derivrotationmatrixd(1, 2) + &
3259 & xxc(2)*bcdatad(mm)%uslip(i, j, 1)
3260  derivrotationmatrixd(1, 3) = derivrotationmatrixd(1, 3) + &
3261 & xxc(3)*bcdatad(mm)%uslip(i, j, 1)
3262  call popreal8(xxc(3))
3263  xcd(3) = xcd(3) + xxcd(3)
3264  call popreal8(xxc(2))
3265  xcd(2) = xcd(2) + xxcd(2)
3266  xxcd(2) = rotrate(1)*bcdatad(mm)%uslip(i, j, 3)
3267  call popreal8(xxc(1))
3268  xcd(1) = xcd(1) + xxcd(1)
3269  xxcd(1) = -(rotrate(2)*bcdatad(mm)%uslip(i, j, 3))
3270  rotrated(1) = rotrated(1) + xxc(2)*bcdatad(mm)%uslip(i, j&
3271 & , 3)
3272  rotrated(2) = rotrated(2) - xxc(1)*bcdatad(mm)%uslip(i, j&
3273 & , 3)
3274  bcdatad(mm)%uslip(i, j, 3) = 0.0_8
3275  xxcd(3) = -(rotrate(1)*bcdatad(mm)%uslip(i, j, 2))
3276  rotrated(3) = rotrated(3) + xxc(1)*bcdatad(mm)%uslip(i, j&
3277 & , 2)
3278  xxcd(1) = xxcd(1) + rotrate(3)*bcdatad(mm)%uslip(i, j, 2)
3279  rotrated(1) = rotrated(1) - xxc(3)*bcdatad(mm)%uslip(i, j&
3280 & , 2)
3281  bcdatad(mm)%uslip(i, j, 2) = 0.0_8
3282  rotrated(2) = rotrated(2) + xxc(3)*bcdatad(mm)%uslip(i, j&
3283 & , 1)
3284  xxcd(3) = xxcd(3) + rotrate(2)*bcdatad(mm)%uslip(i, j, 1)
3285  rotrated(3) = rotrated(3) - xxc(2)*bcdatad(mm)%uslip(i, j&
3286 & , 1)
3287  xxcd(2) = xxcd(2) - rotrate(3)*bcdatad(mm)%uslip(i, j, 1)
3288  bcdatad(mm)%uslip(i, j, 1) = 0.0_8
3289  call popreal8(xxc(3))
3290  xcd(3) = xcd(3) + xxcd(3)
3291  xxcd(3) = 0.0_8
3292  call popreal8(xxc(2))
3293  xcd(2) = xcd(2) + xxcd(2)
3294  xxcd(2) = 0.0_8
3295  call popreal8(xxc(1))
3296  xcd(1) = xcd(1) + xxcd(1)
3297  xxcd(1) = 0.0_8
3298  tempd = fourth*xcd(3)
3299  xcd(3) = 0.0_8
3300  flowdomsd(nn, groundlevel, sps)%x(1, i, j, 3) = flowdomsd(&
3301 & nn, groundlevel, sps)%x(1, i, j, 3) + tempd
3302  flowdomsd(nn, groundlevel, sps)%x(1, i, j-1, 3) = &
3303 & flowdomsd(nn, groundlevel, sps)%x(1, i, j-1, 3) + tempd
3304  flowdomsd(nn, groundlevel, sps)%x(1, i-1, j, 3) = &
3305 & flowdomsd(nn, groundlevel, sps)%x(1, i-1, j, 3) + tempd
3306  flowdomsd(nn, groundlevel, sps)%x(1, i-1, j-1, 3) = &
3307 & flowdomsd(nn, groundlevel, sps)%x(1, i-1, j-1, 3) + &
3308 & tempd
3309  tempd = fourth*xcd(2)
3310  xcd(2) = 0.0_8
3311  flowdomsd(nn, groundlevel, sps)%x(1, i, j, 2) = flowdomsd(&
3312 & nn, groundlevel, sps)%x(1, i, j, 2) + tempd
3313  flowdomsd(nn, groundlevel, sps)%x(1, i, j-1, 2) = &
3314 & flowdomsd(nn, groundlevel, sps)%x(1, i, j-1, 2) + tempd
3315  flowdomsd(nn, groundlevel, sps)%x(1, i-1, j, 2) = &
3316 & flowdomsd(nn, groundlevel, sps)%x(1, i-1, j, 2) + tempd
3317  flowdomsd(nn, groundlevel, sps)%x(1, i-1, j-1, 2) = &
3318 & flowdomsd(nn, groundlevel, sps)%x(1, i-1, j-1, 2) + &
3319 & tempd
3320  tempd = fourth*xcd(1)
3321  xcd(1) = 0.0_8
3322  flowdomsd(nn, groundlevel, sps)%x(1, i, j, 1) = flowdomsd(&
3323 & nn, groundlevel, sps)%x(1, i, j, 1) + tempd
3324  flowdomsd(nn, groundlevel, sps)%x(1, i, j-1, 1) = &
3325 & flowdomsd(nn, groundlevel, sps)%x(1, i, j-1, 1) + tempd
3326  flowdomsd(nn, groundlevel, sps)%x(1, i-1, j, 1) = &
3327 & flowdomsd(nn, groundlevel, sps)%x(1, i-1, j, 1) + tempd
3328  flowdomsd(nn, groundlevel, sps)%x(1, i-1, j-1, 1) = &
3329 & flowdomsd(nn, groundlevel, sps)%x(1, i-1, j-1, 1) + &
3330 & tempd
3331  end do
3332  end do
3333  end if
3334  velzgrid0d = velzgrid0d + velzgridd
3335  velygrid0d = velygrid0d + velygridd
3336  velxgrid0d = velxgrid0d + velxgridd
3337  call popreal8array(rotrate, 3)
3338  timerefd = timerefd + sum(cgnsdoms(nbkglobal)%bocoinfo(ii)%&
3339 & rotrate*rotrated)
3340  call popinteger4(ii)
3341  end do
3342  call derivativerotmatrixrigid_b(derivrotationmatrix, &
3343 & derivrotationmatrixd, rotationpoint, t(1&
3344 & ))
3345  ainfd = -(machgrid*veldirfreestream(3)*velzgrid0d) - machgrid*&
3346 & veldirfreestream(2)*velygrid0d - machgrid*veldirfreestream(1)*&
3347 & velxgrid0d
3348  machgridd = -(ainf*veldirfreestream(3)*velzgrid0d) - ainf*&
3349 & veldirfreestream(2)*velygrid0d - ainf*veldirfreestream(1)*&
3350 & velxgrid0d
3352 & velzgrid0d
3354 & velygrid0d
3356 & velxgrid0d
3357  if (gammainf*(pinf/rhoinf) .eq. 0.0_8) then
3358  tempd = 0.0_8
3359  else
3360  tempd = gammainf*ainfd/(rhoinf*2.0*sqrt(gammainf*(pinf/rhoinf)))
3361  end if
3362  pinfd = tempd
3363  rhoinfd = -(pinf*tempd/rhoinf)
3364  end if
3365  end subroutine slipvelocitiesfinelevel_block_b
3366 
3367  subroutine slipvelocitiesfinelevel_block(useoldcoor, t, sps, nn)
3368 !
3369 ! slipvelocitiesfinelevel computes the slip velocities for
3370 ! viscous subfaces on all viscous boundaries on groundlevel for
3371 ! the given spectral solution. if useoldcoor is .true. the
3372 ! velocities are determined using the unsteady time integrator;
3373 ! otherwise the analytic form is used.
3374 !
3375  use constants
3376  use inputtimespectral
3377  use blockpointers
3378  use cgnsgrid
3379  use flowvarrefstate
3380  use inputmotion
3381  use inputunsteady
3382  use iteration
3383  use inputphysics
3384  use inputtsstabderiv
3385  use monitor
3386  use communication
3388  use utils_b, only : tsalpha, tsbeta, tsmach, terminate, &
3390  implicit none
3391 !
3392 ! subroutine arguments.
3393 !
3394  integer(kind=inttype), intent(in) :: sps, nn
3395  logical, intent(in) :: useoldcoor
3396  real(kind=realtype), dimension(*), intent(in) :: t
3397 !
3398 ! local variables.
3399 !
3400  integer(kind=inttype) :: mm, i, j, level, ii
3401  real(kind=realtype) :: oneover4dt
3402  real(kind=realtype) :: velxgrid, velygrid, velzgrid, ainf
3403  real(kind=realtype) :: velxgrid0, velygrid0, velzgrid0
3404  real(kind=realtype), dimension(3) :: xc, xxc
3405  real(kind=realtype), dimension(3) :: rotcenter, rotrate
3406  real(kind=realtype), dimension(3) :: rotationpoint
3407  real(kind=realtype), dimension(3, 3) :: rotationmatrix, &
3408 & derivrotationmatrix
3409  real(kind=realtype) :: tnew, told
3410  real(kind=realtype), dimension(:, :, :), pointer :: uslip
3411  real(kind=realtype), dimension(:, :, :), pointer :: xface
3412  real(kind=realtype), dimension(:, :, :, :), pointer :: xfaceold
3413  real(kind=realtype) :: intervalmach, alphats, alphaincrement, betats&
3414 & , betaincrement
3415  real(kind=realtype), dimension(3) :: veldir
3416  real(kind=realtype), dimension(3) :: refdirection
3417  intrinsic sqrt
3418 ! determine the situation we are having here.
3419  if (.not.useoldcoor) then
3420 ! the velocities must be determined analytically.
3421 ! compute the mesh velocity from the given mesh mach number.
3422 ! ainf = sqrt(gammainf*pinf/rhoinf)
3423 ! velxgrid = ainf*machgrid(1)
3424 ! velygrid = ainf*machgrid(2)
3425 ! velzgrid = ainf*machgrid(3)
3426  ainf = sqrt(gammainf*pinf/rhoinf)
3427  velxgrid0 = ainf*machgrid*(-veldirfreestream(1))
3428  velygrid0 = ainf*machgrid*(-veldirfreestream(2))
3429  velzgrid0 = ainf*machgrid*(-veldirfreestream(3))
3430 ! compute the derivative of the rotation matrix and the rotation
3431 ! point; needed for velocity due to the rigid body rotation of
3432 ! the entire grid. it is assumed that the rigid body motion of
3433 ! the grid is only specified if there is only 1 section present.
3434  call derivativerotmatrixrigid(derivrotationmatrix, rotationpoint, &
3435 & t(1))
3436 !compute the rotation matrix to update the velocities for the time
3437 !spectral stability derivative case...
3438 ! loop over the number of viscous subfaces.
3439 bocoloop2:do mm=1,nviscbocos
3440 ! store the rotation center and the rotation rate
3441 ! for this subface.
3442  ii = cgnssubface(mm)
3443  rotcenter = cgnsdoms(nbkglobal)%bocoinfo(ii)%rotcenter
3444  rotrate = timeref*cgnsdoms(nbkglobal)%bocoinfo(ii)%rotrate
3445 ! usewindaxis should go back here!
3446  velxgrid = velxgrid0
3447  velygrid = velygrid0
3448  velzgrid = velzgrid0
3449 ! loop over the quadrilateral faces of the viscous
3450 ! subface.
3451 ! the new procedure is less elegant as the previous one.
3452 ! but the new stands up to tapenade.
3453  if (bcfaceid(mm) .eq. imin) then
3454  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
3455  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
3456 ! compute the coordinates of the centroid of the face.
3457 ! normally this would be an average of i-1 and i, but
3458 ! due to the usage of the pointer xface and the fact
3459 ! that x starts at index 0 this is shifted 1 index.
3460  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
3461 & 1)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 1)+&
3462 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 1)+flowdoms(&
3463 & nn, groundlevel, sps)%x(1, i-1, j-1, 1))
3464  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
3465 & 2)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 2)+&
3466 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 2)+flowdoms(&
3467 & nn, groundlevel, sps)%x(1, i-1, j-1, 2))
3468  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
3469 & 3)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 3)+&
3470 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 3)+flowdoms(&
3471 & nn, groundlevel, sps)%x(1, i-1, j-1, 3))
3472 ! determine the coordinates relative to the center
3473 ! of rotation.
3474  xxc(1) = xc(1) - rotcenter(1)
3475  xxc(2) = xc(2) - rotcenter(2)
3476  xxc(3) = xc(3) - rotcenter(3)
3477 ! compute the velocity, which is the cross product
3478 ! of rotrate and xc.
3479  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
3480 & *xxc(2)
3481  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
3482 & *xxc(3)
3483  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
3484 & *xxc(1)
3485 ! determine the coordinates relative to the
3486 ! rigid body rotation point.
3487  xxc(1) = xc(1) - rotationpoint(1)
3488  xxc(2) = xc(2) - rotationpoint(2)
3489  xxc(3) = xc(3) - rotationpoint(3)
3490 ! determine the total velocity of the cell center.
3491 ! this is a combination of rotation speed of this
3492 ! block and the entire rigid body rotation.
3493  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
3494 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
3495 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
3496 & , 3)*xxc(3)
3497  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
3498 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
3499 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
3500 & , 3)*xxc(3)
3501  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
3502 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
3503 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
3504 & , 3)*xxc(3)
3505  end do
3506  end do
3507  else if (bcfaceid(mm) .eq. imax) then
3508  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
3509  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
3510 ! compute the coordinates of the centroid of the face.
3511 ! normally this would be an average of i-1 and i, but
3512 ! due to the usage of the pointer xface and the fact
3513 ! that x starts at index 0 this is shifted 1 index.
3514  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
3515 & , 1)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 1)+&
3516 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 1)+flowdoms&
3517 & (nn, groundlevel, sps)%x(il, i-1, j-1, 1))
3518  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
3519 & , 2)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 2)+&
3520 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 2)+flowdoms&
3521 & (nn, groundlevel, sps)%x(il, i-1, j-1, 2))
3522  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
3523 & , 3)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 3)+&
3524 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 3)+flowdoms&
3525 & (nn, groundlevel, sps)%x(il, i-1, j-1, 3))
3526 ! determine the coordinates relative to the center
3527 ! of rotation.
3528  xxc(1) = xc(1) - rotcenter(1)
3529  xxc(2) = xc(2) - rotcenter(2)
3530  xxc(3) = xc(3) - rotcenter(3)
3531 ! compute the velocity, which is the cross product
3532 ! of rotrate and xc.
3533  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
3534 & *xxc(2)
3535  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
3536 & *xxc(3)
3537  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
3538 & *xxc(1)
3539 ! determine the coordinates relative to the
3540 ! rigid body rotation point.
3541  xxc(1) = xc(1) - rotationpoint(1)
3542  xxc(2) = xc(2) - rotationpoint(2)
3543  xxc(3) = xc(3) - rotationpoint(3)
3544 ! determine the total velocity of the cell center.
3545 ! this is a combination of rotation speed of this
3546 ! block and the entire rigid body rotation.
3547  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
3548 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
3549 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
3550 & , 3)*xxc(3)
3551  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
3552 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
3553 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
3554 & , 3)*xxc(3)
3555  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
3556 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
3557 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
3558 & , 3)*xxc(3)
3559  end do
3560  end do
3561  else if (bcfaceid(mm) .eq. jmin) then
3562  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
3563  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
3564 ! compute the coordinates of the centroid of the face.
3565 ! normally this would be an average of i-1 and i, but
3566 ! due to the usage of the pointer xface and the fact
3567 ! that x starts at index 0 this is shifted 1 index.
3568  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
3569 & 1)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 1)+&
3570 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 1)+flowdoms(&
3571 & nn, groundlevel, sps)%x(i-1, 1, j-1, 1))
3572  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
3573 & 2)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 2)+&
3574 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 2)+flowdoms(&
3575 & nn, groundlevel, sps)%x(i-1, 1, j-1, 2))
3576  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
3577 & 3)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 3)+&
3578 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 3)+flowdoms(&
3579 & nn, groundlevel, sps)%x(i-1, 1, j-1, 3))
3580 ! determine the coordinates relative to the center
3581 ! of rotation.
3582  xxc(1) = xc(1) - rotcenter(1)
3583  xxc(2) = xc(2) - rotcenter(2)
3584  xxc(3) = xc(3) - rotcenter(3)
3585 ! compute the velocity, which is the cross product
3586 ! of rotrate and xc.
3587  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
3588 & *xxc(2)
3589  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
3590 & *xxc(3)
3591  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
3592 & *xxc(1)
3593 ! determine the coordinates relative to the
3594 ! rigid body rotation point.
3595  xxc(1) = xc(1) - rotationpoint(1)
3596  xxc(2) = xc(2) - rotationpoint(2)
3597  xxc(3) = xc(3) - rotationpoint(3)
3598 ! determine the total velocity of the cell center.
3599 ! this is a combination of rotation speed of this
3600 ! block and the entire rigid body rotation.
3601  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
3602 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
3603 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
3604 & , 3)*xxc(3)
3605  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
3606 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
3607 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
3608 & , 3)*xxc(3)
3609  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
3610 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
3611 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
3612 & , 3)*xxc(3)
3613  end do
3614  end do
3615  else if (bcfaceid(mm) .eq. jmax) then
3616  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
3617  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
3618 ! compute the coordinates of the centroid of the face.
3619 ! normally this would be an average of i-1 and i, but
3620 ! due to the usage of the pointer xface and the fact
3621 ! that x starts at index 0 this is shifted 1 index.
3622  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
3623 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 1)+&
3624 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 1)+flowdoms&
3625 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 1))
3626  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
3627 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 2)+&
3628 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 2)+flowdoms&
3629 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 2))
3630  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
3631 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 3)+&
3632 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 3)+flowdoms&
3633 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 3))
3634 ! determine the coordinates relative to the center
3635 ! of rotation.
3636  xxc(1) = xc(1) - rotcenter(1)
3637  xxc(2) = xc(2) - rotcenter(2)
3638  xxc(3) = xc(3) - rotcenter(3)
3639 ! compute the velocity, which is the cross product
3640 ! of rotrate and xc.
3641  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
3642 & *xxc(2)
3643  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
3644 & *xxc(3)
3645  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
3646 & *xxc(1)
3647 ! determine the coordinates relative to the
3648 ! rigid body rotation point.
3649  xxc(1) = xc(1) - rotationpoint(1)
3650  xxc(2) = xc(2) - rotationpoint(2)
3651  xxc(3) = xc(3) - rotationpoint(3)
3652 ! determine the total velocity of the cell center.
3653 ! this is a combination of rotation speed of this
3654 ! block and the entire rigid body rotation.
3655  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
3656 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
3657 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
3658 & , 3)*xxc(3)
3659  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
3660 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
3661 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
3662 & , 3)*xxc(3)
3663  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
3664 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
3665 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
3666 & , 3)*xxc(3)
3667  end do
3668  end do
3669  else if (bcfaceid(mm) .eq. kmin) then
3670  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
3671  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
3672 ! compute the coordinates of the centroid of the face.
3673 ! normally this would be an average of i-1 and i, but
3674 ! due to the usage of the pointer xface and the fact
3675 ! that x starts at index 0 this is shifted 1 index.
3676  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
3677 & 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 1)+&
3678 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 1)+flowdoms(&
3679 & nn, groundlevel, sps)%x(i-1, j-1, 1, 1))
3680  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
3681 & 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 2)+&
3682 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 2)+flowdoms(&
3683 & nn, groundlevel, sps)%x(i-1, j-1, 1, 2))
3684  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
3685 & 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 3)+&
3686 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 3)+flowdoms(&
3687 & nn, groundlevel, sps)%x(i-1, j-1, 1, 3))
3688 ! determine the coordinates relative to the center
3689 ! of rotation.
3690  xxc(1) = xc(1) - rotcenter(1)
3691  xxc(2) = xc(2) - rotcenter(2)
3692  xxc(3) = xc(3) - rotcenter(3)
3693 ! compute the velocity, which is the cross product
3694 ! of rotrate and xc.
3695  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
3696 & *xxc(2)
3697  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
3698 & *xxc(3)
3699  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
3700 & *xxc(1)
3701 ! determine the coordinates relative to the
3702 ! rigid body rotation point.
3703  xxc(1) = xc(1) - rotationpoint(1)
3704  xxc(2) = xc(2) - rotationpoint(2)
3705  xxc(3) = xc(3) - rotationpoint(3)
3706 ! determine the total velocity of the cell center.
3707 ! this is a combination of rotation speed of this
3708 ! block and the entire rigid body rotation.
3709  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
3710 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
3711 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
3712 & , 3)*xxc(3)
3713  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
3714 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
3715 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
3716 & , 3)*xxc(3)
3717  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
3718 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
3719 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
3720 & , 3)*xxc(3)
3721  end do
3722  end do
3723  else if (bcfaceid(mm) .eq. kmax) then
3724  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
3725  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
3726 ! compute the coordinates of the centroid of the face.
3727 ! normally this would be an average of i-1 and i, but
3728 ! due to the usage of the pointer xface and the fact
3729 ! that x starts at index 0 this is shifted 1 index.
3730  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
3731 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 1)+&
3732 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 1)+flowdoms&
3733 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 1))
3734  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
3735 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 2)+&
3736 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 2)+flowdoms&
3737 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 2))
3738  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
3739 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 3)+&
3740 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 3)+flowdoms&
3741 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 3))
3742 ! determine the coordinates relative to the center
3743 ! of rotation.
3744  xxc(1) = xc(1) - rotcenter(1)
3745  xxc(2) = xc(2) - rotcenter(2)
3746  xxc(3) = xc(3) - rotcenter(3)
3747 ! compute the velocity, which is the cross product
3748 ! of rotrate and xc.
3749  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
3750 & *xxc(2)
3751  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
3752 & *xxc(3)
3753  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
3754 & *xxc(1)
3755 ! determine the coordinates relative to the
3756 ! rigid body rotation point.
3757  xxc(1) = xc(1) - rotationpoint(1)
3758  xxc(2) = xc(2) - rotationpoint(2)
3759  xxc(3) = xc(3) - rotationpoint(3)
3760 ! determine the total velocity of the cell center.
3761 ! this is a combination of rotation speed of this
3762 ! block and the entire rigid body rotation.
3763  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
3764 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
3765 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
3766 & , 3)*xxc(3)
3767  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
3768 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
3769 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
3770 & , 3)*xxc(3)
3771  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
3772 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
3773 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
3774 & , 3)*xxc(3)
3775  end do
3776  end do
3777  end if
3778  end do bocoloop2
3779  end if
3780  end subroutine slipvelocitiesfinelevel_block
3781 
3782 ! differentiation of normalvelocities_block in reverse (adjoint) mode (with options noisize i4 dr8 r8):
3783 ! gradient of useful results: *sfacei *sfacej *sfacek *si
3784 ! *sj *sk *(*bcdata.rface)
3785 ! with respect to varying inputs: *sfacei *sfacej *sfacek *si
3786 ! *sj *sk *(*bcdata.rface)
3787 ! rw status of diff variables: *sfacei:incr *sfacej:incr *sfacek:incr
3788 ! *si:incr *sj:incr *sk:incr *(*bcdata.rface):in-out
3789 ! plus diff mem management of: sfacei:in sfacej:in sfacek:in
3790 ! si:in sj:in sk:in bcdata:in *bcdata.rface:in
3792 !
3793 ! normalvelocitiesalllevels computes the normal grid
3794 ! velocities of some boundary faces of the moving blocks for
3795 ! spectral mode sps. all grid levels from ground level to the
3796 ! coarsest level are considered.
3797 !
3798  use constants
3799  use blockpointers, only : il, jl, kl, addgridvelocities, nbocos, &
3801 & bcfaceid, si, sid, sj, sjd, sk, skd
3802  implicit none
3803 !
3804 ! subroutine arguments.
3805 !
3806  integer(kind=inttype), intent(in) :: sps
3807 !
3808 ! local variables.
3809 !
3810  integer(kind=inttype) :: mm
3811  integer(kind=inttype) :: i, j
3812  real(kind=realtype) :: weight, mult
3813  real(kind=realtype) :: weightd
3814  real(kind=realtype), dimension(:, :), pointer :: sface
3815  real(kind=realtype), dimension(:, :, :), pointer :: ss
3816  intrinsic associated
3817  intrinsic sqrt
3818  real(kind=realtype) :: temp
3819  real(kind=realtype) :: tempd
3820  real(kind=realtype) :: temp0
3821  real(kind=realtype) :: temp1
3822  real(kind=realtype) :: temp2
3823  real(kind=realtype) :: tempd0
3824  integer :: branch
3825  integer :: ad_from
3826  integer :: ad_to
3827  integer :: ad_from0
3828  integer :: ad_to0
3829  integer :: ad_from1
3830  integer :: ad_to1
3831  integer :: ad_from2
3832  integer :: ad_to2
3833  integer :: ad_from3
3834  integer :: ad_to3
3835  integer :: ad_from4
3836  integer :: ad_to4
3837  integer :: ad_from5
3838  integer :: ad_to5
3839  integer :: ad_from6
3840  integer :: ad_to6
3841  integer :: ad_from7
3842  integer :: ad_to7
3843  integer :: ad_from8
3844  integer :: ad_to8
3845  integer :: ad_from9
3846  integer :: ad_to9
3847  integer :: ad_from10
3848  integer :: ad_to10
3849 ! check for a moving block. as it is possible that in a
3850 ! multidisicplinary environment additional grid velocities
3851 ! are set, the test should be done on addgridvelocities
3852 ! and not on blockismoving.
3853  if (addgridvelocities) then
3854 !
3855 ! determine the normal grid velocities of the boundaries.
3856 ! as these values are based on the unit normal. a division
3857 ! by the length of the normal is needed.
3858 ! furthermore the boundary unit normals are per definition
3859 ! outward pointing, while on the imin, jmin and kmin
3860 ! boundaries the face normals are inward pointing. this
3861 ! is taken into account by the factor mult.
3862 !
3863 ! loop over the boundary subfaces.
3864 bocoloop:do mm=1,nbocos
3865 ! check whether rface is allocated.
3866  if (associated(bcdata(mm)%rface)) then
3867 ! determine the block face on which the subface is
3868 ! located and set some variables accordingly.
3869 ! the new procedure is less elegant as the previous one.
3870 ! but the new stands up to tapenade.
3871  if (bcfaceid(mm) .eq. imin) then
3872  call pushreal8(mult)
3873  mult = -one
3874  ad_from0 = bcdata(mm)%jcbeg
3875  do j=ad_from0,bcdata(mm)%jcend
3876  ad_from = bcdata(mm)%icbeg
3877  do i=ad_from,bcdata(mm)%icend
3878 ! compute the inverse of the length of the normal
3879 ! vector and possibly correct for inward pointing.
3880  call pushreal8(weight)
3881  weight = sqrt(si(1, i, j, 1)**2 + si(1, i, j, 2)**2 + si&
3882 & (1, i, j, 3)**2)
3883  if (weight .gt. zero) then
3884  call pushreal8(weight)
3885  weight = mult/weight
3886  call pushcontrol1b(0)
3887  else
3888  call pushcontrol1b(1)
3889  end if
3890  end do
3891  call pushinteger4(i - 1)
3892  call pushinteger4(ad_from)
3893  end do
3894  call pushinteger4(j - 1)
3895  call pushinteger4(ad_from0)
3896  call pushcontrol3b(7)
3897  else if (bcfaceid(mm) .eq. imax) then
3898  call pushreal8(mult)
3899  mult = one
3900  ad_from2 = bcdata(mm)%jcbeg
3901  do j=ad_from2,bcdata(mm)%jcend
3902  ad_from1 = bcdata(mm)%icbeg
3903  do i=ad_from1,bcdata(mm)%icend
3904 ! compute the inverse of the length of the normal
3905 ! vector and possibly correct for inward pointing.
3906  call pushreal8(weight)
3907  weight = sqrt(si(il, i, j, 1)**2 + si(il, i, j, 2)**2 + &
3908 & si(il, i, j, 3)**2)
3909  if (weight .gt. zero) then
3910  call pushreal8(weight)
3911  weight = mult/weight
3912  call pushcontrol1b(0)
3913  else
3914  call pushcontrol1b(1)
3915  end if
3916  end do
3917  call pushinteger4(i - 1)
3918  call pushinteger4(ad_from1)
3919  end do
3920  call pushinteger4(j - 1)
3921  call pushinteger4(ad_from2)
3922  call pushcontrol3b(6)
3923  else if (bcfaceid(mm) .eq. jmin) then
3924  call pushreal8(mult)
3925  mult = -one
3926  ad_from4 = bcdata(mm)%jcbeg
3927  do j=ad_from4,bcdata(mm)%jcend
3928  ad_from3 = bcdata(mm)%icbeg
3929  do i=ad_from3,bcdata(mm)%icend
3930 ! compute the inverse of the length of the normal
3931 ! vector and possibly correct for inward pointing.
3932  call pushreal8(weight)
3933  weight = sqrt(sj(i, 1, j, 1)**2 + sj(i, 1, j, 2)**2 + sj&
3934 & (i, 1, j, 3)**2)
3935  if (weight .gt. zero) then
3936  call pushreal8(weight)
3937  weight = mult/weight
3938  call pushcontrol1b(0)
3939  else
3940  call pushcontrol1b(1)
3941  end if
3942  end do
3943  call pushinteger4(i - 1)
3944  call pushinteger4(ad_from3)
3945  end do
3946  call pushinteger4(j - 1)
3947  call pushinteger4(ad_from4)
3948  call pushcontrol3b(5)
3949  else if (bcfaceid(mm) .eq. jmax) then
3950  call pushreal8(mult)
3951  mult = one
3952  ad_from6 = bcdata(mm)%jcbeg
3953  do j=ad_from6,bcdata(mm)%jcend
3954  ad_from5 = bcdata(mm)%icbeg
3955  do i=ad_from5,bcdata(mm)%icend
3956 ! compute the inverse of the length of the normal
3957 ! vector and possibly correct for inward pointing.
3958  call pushreal8(weight)
3959  weight = sqrt(sj(i, jl, j, 1)**2 + sj(i, jl, j, 2)**2 + &
3960 & sj(i, jl, j, 3)**2)
3961  if (weight .gt. zero) then
3962  call pushreal8(weight)
3963  weight = mult/weight
3964  call pushcontrol1b(0)
3965  else
3966  call pushcontrol1b(1)
3967  end if
3968  end do
3969  call pushinteger4(i - 1)
3970  call pushinteger4(ad_from5)
3971  end do
3972  call pushinteger4(j - 1)
3973  call pushinteger4(ad_from6)
3974  call pushcontrol3b(4)
3975  else if (bcfaceid(mm) .eq. kmin) then
3976  call pushreal8(mult)
3977  mult = -one
3978  ad_from8 = bcdata(mm)%jcbeg
3979  do j=ad_from8,bcdata(mm)%jcend
3980  ad_from7 = bcdata(mm)%icbeg
3981  do i=ad_from7,bcdata(mm)%icend
3982 ! compute the inverse of the length of the normal
3983 ! vector and possibly correct for inward pointing.
3984  call pushreal8(weight)
3985  weight = sqrt(sk(i, j, 1, 1)**2 + sk(i, j, 1, 2)**2 + sk&
3986 & (i, j, 1, 3)**2)
3987  if (weight .gt. zero) then
3988  call pushreal8(weight)
3989  weight = mult/weight
3990  call pushcontrol1b(0)
3991  else
3992  call pushcontrol1b(1)
3993  end if
3994  end do
3995  call pushinteger4(i - 1)
3996  call pushinteger4(ad_from7)
3997  end do
3998  call pushinteger4(j - 1)
3999  call pushinteger4(ad_from8)
4000  call pushcontrol3b(3)
4001  else if (bcfaceid(mm) .eq. kmax) then
4002  call pushreal8(mult)
4003  mult = one
4004  ad_from10 = bcdata(mm)%jcbeg
4005  do j=ad_from10,bcdata(mm)%jcend
4006  ad_from9 = bcdata(mm)%icbeg
4007  do i=ad_from9,bcdata(mm)%icend
4008 ! compute the inverse of the length of the normal
4009 ! vector and possibly correct for inward pointing.
4010  call pushreal8(weight)
4011  weight = sqrt(sk(i, j, kl, 1)**2 + sk(i, j, kl, 2)**2 + &
4012 & sk(i, j, kl, 3)**2)
4013  if (weight .gt. zero) then
4014  call pushreal8(weight)
4015  weight = mult/weight
4016  call pushcontrol1b(0)
4017  else
4018  call pushcontrol1b(1)
4019  end if
4020  end do
4021  call pushinteger4(i - 1)
4022  call pushinteger4(ad_from9)
4023  end do
4024  call pushinteger4(j - 1)
4025  call pushinteger4(ad_from10)
4026  call pushcontrol3b(2)
4027  else
4028  call pushcontrol3b(1)
4029  end if
4030  else
4031  call pushcontrol3b(0)
4032  end if
4033  end do bocoloop
4034  do mm=nbocos,1,-1
4035  call popcontrol3b(branch)
4036  if (branch .lt. 4) then
4037  if (branch .ge. 2) then
4038  if (branch .eq. 2) then
4039  call popinteger4(ad_from10)
4040  call popinteger4(ad_to10)
4041  do j=ad_to10,ad_from10,-1
4042  call popinteger4(ad_from9)
4043  call popinteger4(ad_to9)
4044  do i=ad_to9,ad_from9,-1
4045  weightd = sfacek(i, j, kl)*bcdatad(mm)%rface(i, j)
4046  sfacekd(i, j, kl) = sfacekd(i, j, kl) + weight*bcdatad&
4047 & (mm)%rface(i, j)
4048  bcdatad(mm)%rface(i, j) = 0.0_8
4049  call popcontrol1b(branch)
4050  if (branch .eq. 0) then
4051  call popreal8(weight)
4052  weightd = -(mult*weightd/weight**2)
4053  end if
4054  call popreal8(weight)
4055  temp2 = sk(i, j, kl, 3)
4056  temp1 = sk(i, j, kl, 2)
4057  temp0 = sk(i, j, kl, 1)
4058  if (temp0**2 + temp1**2 + temp2**2 .eq. 0.0_8) then
4059  tempd = 0.0_8
4060  else
4061  tempd = weightd/(2.0*sqrt(temp0**2+temp1**2+temp2**2&
4062 & ))
4063  end if
4064  skd(i, j, kl, 1) = skd(i, j, kl, 1) + 2*temp0*tempd
4065  skd(i, j, kl, 2) = skd(i, j, kl, 2) + 2*temp1*tempd
4066  skd(i, j, kl, 3) = skd(i, j, kl, 3) + 2*temp2*tempd
4067  end do
4068  end do
4069  call popreal8(mult)
4070  else
4071  call popinteger4(ad_from8)
4072  call popinteger4(ad_to8)
4073  do j=ad_to8,ad_from8,-1
4074  call popinteger4(ad_from7)
4075  call popinteger4(ad_to7)
4076  do i=ad_to7,ad_from7,-1
4077  weightd = sfacek(i, j, 1)*bcdatad(mm)%rface(i, j)
4078  sfacekd(i, j, 1) = sfacekd(i, j, 1) + weight*bcdatad(&
4079 & mm)%rface(i, j)
4080  bcdatad(mm)%rface(i, j) = 0.0_8
4081  call popcontrol1b(branch)
4082  if (branch .eq. 0) then
4083  call popreal8(weight)
4084  weightd = -(mult*weightd/weight**2)
4085  end if
4086  call popreal8(weight)
4087  if (sk(i, j, 1, 1)**2 + sk(i, j, 1, 2)**2 + sk(i, j, 1&
4088 & , 3)**2 .eq. 0.0_8) then
4089  tempd0 = 0.0_8
4090  else
4091  tempd0 = weightd/(2.0*sqrt(sk(i, j, 1, 1)**2+sk(i, j&
4092 & , 1, 2)**2+sk(i, j, 1, 3)**2))
4093  end if
4094  skd(i, j, 1, 1) = skd(i, j, 1, 1) + 2*sk(i, j, 1, 1)*&
4095 & tempd0
4096  skd(i, j, 1, 2) = skd(i, j, 1, 2) + 2*sk(i, j, 1, 2)*&
4097 & tempd0
4098  skd(i, j, 1, 3) = skd(i, j, 1, 3) + 2*sk(i, j, 1, 3)*&
4099 & tempd0
4100  end do
4101  end do
4102  call popreal8(mult)
4103  end if
4104  end if
4105  else if (branch .lt. 6) then
4106  if (branch .eq. 4) then
4107  call popinteger4(ad_from6)
4108  call popinteger4(ad_to6)
4109  do j=ad_to6,ad_from6,-1
4110  call popinteger4(ad_from5)
4111  call popinteger4(ad_to5)
4112  do i=ad_to5,ad_from5,-1
4113  weightd = sfacej(i, jl, j)*bcdatad(mm)%rface(i, j)
4114  sfacejd(i, jl, j) = sfacejd(i, jl, j) + weight*bcdatad(&
4115 & mm)%rface(i, j)
4116  bcdatad(mm)%rface(i, j) = 0.0_8
4117  call popcontrol1b(branch)
4118  if (branch .eq. 0) then
4119  call popreal8(weight)
4120  weightd = -(mult*weightd/weight**2)
4121  end if
4122  call popreal8(weight)
4123  temp2 = sj(i, jl, j, 3)
4124  temp1 = sj(i, jl, j, 2)
4125  temp0 = sj(i, jl, j, 1)
4126  if (temp0**2 + temp1**2 + temp2**2 .eq. 0.0_8) then
4127  tempd = 0.0_8
4128  else
4129  tempd = weightd/(2.0*sqrt(temp0**2+temp1**2+temp2**2))
4130  end if
4131  sjd(i, jl, j, 1) = sjd(i, jl, j, 1) + 2*temp0*tempd
4132  sjd(i, jl, j, 2) = sjd(i, jl, j, 2) + 2*temp1*tempd
4133  sjd(i, jl, j, 3) = sjd(i, jl, j, 3) + 2*temp2*tempd
4134  end do
4135  end do
4136  call popreal8(mult)
4137  else
4138  call popinteger4(ad_from4)
4139  call popinteger4(ad_to4)
4140  do j=ad_to4,ad_from4,-1
4141  call popinteger4(ad_from3)
4142  call popinteger4(ad_to3)
4143  do i=ad_to3,ad_from3,-1
4144  weightd = sfacej(i, 1, j)*bcdatad(mm)%rface(i, j)
4145  sfacejd(i, 1, j) = sfacejd(i, 1, j) + weight*bcdatad(mm)&
4146 & %rface(i, j)
4147  bcdatad(mm)%rface(i, j) = 0.0_8
4148  call popcontrol1b(branch)
4149  if (branch .eq. 0) then
4150  call popreal8(weight)
4151  weightd = -(mult*weightd/weight**2)
4152  end if
4153  call popreal8(weight)
4154  if (sj(i, 1, j, 1)**2 + sj(i, 1, j, 2)**2 + sj(i, 1, j, &
4155 & 3)**2 .eq. 0.0_8) then
4156  tempd0 = 0.0_8
4157  else
4158  tempd0 = weightd/(2.0*sqrt(sj(i, 1, j, 1)**2+sj(i, 1, &
4159 & j, 2)**2+sj(i, 1, j, 3)**2))
4160  end if
4161  sjd(i, 1, j, 1) = sjd(i, 1, j, 1) + 2*sj(i, 1, j, 1)*&
4162 & tempd0
4163  sjd(i, 1, j, 2) = sjd(i, 1, j, 2) + 2*sj(i, 1, j, 2)*&
4164 & tempd0
4165  sjd(i, 1, j, 3) = sjd(i, 1, j, 3) + 2*sj(i, 1, j, 3)*&
4166 & tempd0
4167  end do
4168  end do
4169  call popreal8(mult)
4170  end if
4171  else if (branch .eq. 6) then
4172  call popinteger4(ad_from2)
4173  call popinteger4(ad_to2)
4174  do j=ad_to2,ad_from2,-1
4175  call popinteger4(ad_from1)
4176  call popinteger4(ad_to1)
4177  do i=ad_to1,ad_from1,-1
4178  weightd = sfacei(il, i, j)*bcdatad(mm)%rface(i, j)
4179  sfaceid(il, i, j) = sfaceid(il, i, j) + weight*bcdatad(mm)&
4180 & %rface(i, j)
4181  bcdatad(mm)%rface(i, j) = 0.0_8
4182  call popcontrol1b(branch)
4183  if (branch .eq. 0) then
4184  call popreal8(weight)
4185  weightd = -(mult*weightd/weight**2)
4186  end if
4187  call popreal8(weight)
4188  temp = si(il, i, j, 3)
4189  temp0 = si(il, i, j, 2)
4190  temp1 = si(il, i, j, 1)
4191  if (temp1**2 + temp0**2 + temp**2 .eq. 0.0_8) then
4192  tempd0 = 0.0_8
4193  else
4194  tempd0 = weightd/(2.0*sqrt(temp1**2+temp0**2+temp**2))
4195  end if
4196  sid(il, i, j, 1) = sid(il, i, j, 1) + 2*temp1*tempd0
4197  sid(il, i, j, 2) = sid(il, i, j, 2) + 2*temp0*tempd0
4198  sid(il, i, j, 3) = sid(il, i, j, 3) + 2*temp*tempd0
4199  end do
4200  end do
4201  call popreal8(mult)
4202  else
4203  call popinteger4(ad_from0)
4204  call popinteger4(ad_to0)
4205  do j=ad_to0,ad_from0,-1
4206  call popinteger4(ad_from)
4207  call popinteger4(ad_to)
4208  do i=ad_to,ad_from,-1
4209  weightd = sfacei(1, i, j)*bcdatad(mm)%rface(i, j)
4210  sfaceid(1, i, j) = sfaceid(1, i, j) + weight*bcdatad(mm)%&
4211 & rface(i, j)
4212  bcdatad(mm)%rface(i, j) = 0.0_8
4213  call popcontrol1b(branch)
4214  if (branch .eq. 0) then
4215  call popreal8(weight)
4216  weightd = -(mult*weightd/weight**2)
4217  end if
4218  call popreal8(weight)
4219  if (si(1, i, j, 1)**2 + si(1, i, j, 2)**2 + si(1, i, j, 3)&
4220 & **2 .eq. 0.0_8) then
4221  tempd = 0.0_8
4222  else
4223  tempd = weightd/(2.0*sqrt(si(1, i, j, 1)**2+si(1, i, j, &
4224 & 2)**2+si(1, i, j, 3)**2))
4225  end if
4226  sid(1, i, j, 1) = sid(1, i, j, 1) + 2*si(1, i, j, 1)*tempd
4227  sid(1, i, j, 2) = sid(1, i, j, 2) + 2*si(1, i, j, 2)*tempd
4228  sid(1, i, j, 3) = sid(1, i, j, 3) + 2*si(1, i, j, 3)*tempd
4229  end do
4230  end do
4231  call popreal8(mult)
4232  end if
4233  end do
4234  else
4235 ! block is not moving. loop over the boundary faces and set
4236 ! the normal grid velocity to zero if allocated.
4237  do mm=1,nbocos
4238  if (associated(bcdata(mm)%rface)) then
4239  call pushcontrol1b(1)
4240  else
4241  call pushcontrol1b(0)
4242  end if
4243  end do
4244  do mm=nbocos,1,-1
4245  call popcontrol1b(branch)
4246  if (branch .ne. 0) bcdatad(mm)%rface = 0.0_8
4247  end do
4248  end if
4249  end subroutine normalvelocities_block_b
4250 
4251  subroutine normalvelocities_block(sps)
4252 !
4253 ! normalvelocitiesalllevels computes the normal grid
4254 ! velocities of some boundary faces of the moving blocks for
4255 ! spectral mode sps. all grid levels from ground level to the
4256 ! coarsest level are considered.
4257 !
4258  use constants
4259  use blockpointers, only : il, jl, kl, addgridvelocities, nbocos, &
4261  implicit none
4262 !
4263 ! subroutine arguments.
4264 !
4265  integer(kind=inttype), intent(in) :: sps
4266 !
4267 ! local variables.
4268 !
4269  integer(kind=inttype) :: mm
4270  integer(kind=inttype) :: i, j
4271  real(kind=realtype) :: weight, mult
4272  real(kind=realtype), dimension(:, :), pointer :: sface
4273  real(kind=realtype), dimension(:, :, :), pointer :: ss
4274  intrinsic associated
4275  intrinsic sqrt
4276 ! check for a moving block. as it is possible that in a
4277 ! multidisicplinary environment additional grid velocities
4278 ! are set, the test should be done on addgridvelocities
4279 ! and not on blockismoving.
4280  if (addgridvelocities) then
4281 !
4282 ! determine the normal grid velocities of the boundaries.
4283 ! as these values are based on the unit normal. a division
4284 ! by the length of the normal is needed.
4285 ! furthermore the boundary unit normals are per definition
4286 ! outward pointing, while on the imin, jmin and kmin
4287 ! boundaries the face normals are inward pointing. this
4288 ! is taken into account by the factor mult.
4289 !
4290 ! loop over the boundary subfaces.
4291 bocoloop:do mm=1,nbocos
4292 ! check whether rface is allocated.
4293  if (associated(bcdata(mm)%rface)) then
4294 ! determine the block face on which the subface is
4295 ! located and set some variables accordingly.
4296 ! the new procedure is less elegant as the previous one.
4297 ! but the new stands up to tapenade.
4298  if (bcfaceid(mm) .eq. imin) then
4299  mult = -one
4300  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
4301  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
4302 ! compute the inverse of the length of the normal
4303 ! vector and possibly correct for inward pointing.
4304  weight = sqrt(si(1, i, j, 1)**2 + si(1, i, j, 2)**2 + si&
4305 & (1, i, j, 3)**2)
4306  if (weight .gt. zero) weight = mult/weight
4307 ! compute the normal velocity based on the outward
4308 ! pointing unit normal.
4309  bcdata(mm)%rface(i, j) = weight*sfacei(1, i, j)
4310  end do
4311  end do
4312  else if (bcfaceid(mm) .eq. imax) then
4313  mult = one
4314  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
4315  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
4316 ! compute the inverse of the length of the normal
4317 ! vector and possibly correct for inward pointing.
4318  weight = sqrt(si(il, i, j, 1)**2 + si(il, i, j, 2)**2 + &
4319 & si(il, i, j, 3)**2)
4320  if (weight .gt. zero) weight = mult/weight
4321 ! compute the normal velocity based on the outward
4322 ! pointing unit normal.
4323  bcdata(mm)%rface(i, j) = weight*sfacei(il, i, j)
4324  end do
4325  end do
4326  else if (bcfaceid(mm) .eq. jmin) then
4327  mult = -one
4328  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
4329  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
4330 ! compute the inverse of the length of the normal
4331 ! vector and possibly correct for inward pointing.
4332  weight = sqrt(sj(i, 1, j, 1)**2 + sj(i, 1, j, 2)**2 + sj&
4333 & (i, 1, j, 3)**2)
4334  if (weight .gt. zero) weight = mult/weight
4335 ! compute the normal velocity based on the outward
4336 ! pointing unit normal.
4337  bcdata(mm)%rface(i, j) = weight*sfacej(i, 1, j)
4338  end do
4339  end do
4340  else if (bcfaceid(mm) .eq. jmax) then
4341  mult = one
4342  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
4343  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
4344 ! compute the inverse of the length of the normal
4345 ! vector and possibly correct for inward pointing.
4346  weight = sqrt(sj(i, jl, j, 1)**2 + sj(i, jl, j, 2)**2 + &
4347 & sj(i, jl, j, 3)**2)
4348  if (weight .gt. zero) weight = mult/weight
4349 ! compute the normal velocity based on the outward
4350 ! pointing unit normal.
4351  bcdata(mm)%rface(i, j) = weight*sfacej(i, jl, j)
4352  end do
4353  end do
4354  else if (bcfaceid(mm) .eq. kmin) then
4355  mult = -one
4356  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
4357  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
4358 ! compute the inverse of the length of the normal
4359 ! vector and possibly correct for inward pointing.
4360  weight = sqrt(sk(i, j, 1, 1)**2 + sk(i, j, 1, 2)**2 + sk&
4361 & (i, j, 1, 3)**2)
4362  if (weight .gt. zero) weight = mult/weight
4363 ! compute the normal velocity based on the outward
4364 ! pointing unit normal.
4365  bcdata(mm)%rface(i, j) = weight*sfacek(i, j, 1)
4366  end do
4367  end do
4368  else if (bcfaceid(mm) .eq. kmax) then
4369  mult = one
4370  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
4371  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
4372 ! compute the inverse of the length of the normal
4373 ! vector and possibly correct for inward pointing.
4374  weight = sqrt(sk(i, j, kl, 1)**2 + sk(i, j, kl, 2)**2 + &
4375 & sk(i, j, kl, 3)**2)
4376  if (weight .gt. zero) weight = mult/weight
4377 ! compute the normal velocity based on the outward
4378 ! pointing unit normal.
4379  bcdata(mm)%rface(i, j) = weight*sfacek(i, j, kl)
4380  end do
4381  end do
4382  end if
4383  end if
4384  end do bocoloop
4385  else
4386 ! block is not moving. loop over the boundary faces and set
4387 ! the normal grid velocity to zero if allocated.
4388  do mm=1,nbocos
4389  if (associated(bcdata(mm)%rface)) bcdata(mm)%rface = zero
4390  end do
4391  end if
4392  end subroutine normalvelocities_block
4393 ! ----------------------------------------------------------------------
4394 ! |
4395 ! no tapenade routine below this line |
4396 ! |
4397 ! ----------------------------------------------------------------------
4398 
4399 end module solverutils_b
4400 
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 sjd
real(kind=realtype), dimension(:, :, :, :), pointer wd
integer(kind=inttype) nviscbocos
real(kind=realtype), dimension(:, :, :), pointer vold
logical blockismoving
real(kind=realtype), dimension(:, :, :), pointer p
real(kind=realtype), dimension(:, :, :), pointer radj
real(kind=realtype), dimension(:, :, :), pointer dtld
integer(kind=inttype) ie
real(kind=realtype), dimension(:, :, :, :), pointer w
real(kind=realtype), dimension(:, :, :), pointer sfacei
integer(kind=inttype), dimension(:), pointer cgnssubface
type(bcdatatype), dimension(:), pointer bcdatad
real(kind=realtype), dimension(:, :, :), pointer revd
real(kind=realtype), dimension(:, :, :), pointer radjd
integer(kind=inttype) nbkglobal
real(kind=realtype), dimension(:, :, :, :), pointer skd
real(kind=realtype), dimension(:, :, :), pointer sfacejd
real(kind=realtype), dimension(:, :, :), pointer rlv
integer(kind=inttype), dimension(:), pointer bcfaceid
real(kind=realtype), dimension(:, :, :, :), pointer si
real(kind=realtype), dimension(:, :, :, :), pointer sid
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
real(kind=realtype), dimension(:, :, :), pointer sfacekd
integer(kind=inttype) ke
real(kind=realtype), dimension(:, :, :), pointer sfaceid
real(kind=realtype), dimension(:, :, :, :), pointer sd
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), 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)
subroutine derivativerotmatrixrigid_b(rotationmatrix, rotationmatrixd, rotationpoint, t)
real(kind=realtype) gammainf
real(kind=realtype) rhoinfd
real(kind=realtype) pinfcorr
real(kind=realtype) pinfcorrd
real(kind=realtype) pinf
real(kind=realtype) pinfd
real(kind=realtype) rhoinf
real(kind=realtype) timeref
real(kind=realtype) timerefd
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), dimension(3) veldirfreestreamd
Definition: inputParam.F90:613
real(kind=realtype) machgridd
Definition: inputParam.F90:618
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 normalvelocities_block_b(sps)
subroutine timestep_block(onlyradii)
subroutine slipvelocitiesfinelevel_block_b(useoldcoor, t, sps, nn)
subroutine cellfacevelocities(xc, rotcenter, rotrate, velxgrid, velygrid, velzgrid, derivrotationmatrix, sc)
subroutine gridvelocitiesfinelevel_block(useoldcoor, t, sps, nn)
subroutine normalvelocities_block(sps)
subroutine gridvelocitiesfinelevel_block_b(useoldcoor, t, sps, nn)
subroutine timestep_block_b(onlyradii)
subroutine cellfacevelocities_b(xc, xcd, rotcenter, rotcenterd, rotrate, rotrated, velxgrid, velxgridd, velygrid, velygridd, velzgrid, velzgridd, derivrotationmatrix, derivrotationmatrixd, sc, scd)
subroutine slipvelocitiesfinelevel_block(useoldcoor, t, sps, nn)
subroutine getdirangle(freestreamaxis, liftaxis, liftindex, alpha, beta)
Definition: utils_b.f90:1186
subroutine rotmatrixrigidbody(tnew, told, rotationmatrix, rotationpoint)
Definition: utils_b.f90:509
subroutine setcoeftimeintegrator()
Definition: utils_b.f90:1332
real(kind=realtype) function tsalpha(degreepolalpha, coefpolalpha, degreefouralpha, omegafouralpha, coscoeffouralpha, sincoeffouralpha, t)
Definition: utils_b.f90:242
subroutine terminate(routinename, errormessage)
Definition: utils_b.f90:493
real(kind=realtype) function tsbeta(degreepolbeta, coefpolbeta, degreefourbeta, omegafourbeta, coscoeffourbeta, sincoeffourbeta, t)
Definition: utils_b.f90:31
real(kind=realtype) function tsmach(degreepolmach, coefpolmach, degreefourmach, omegafourmach, coscoeffourmach, sincoeffourmach, t)
Definition: utils_b.f90:136