ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
solverUtils_d.f90
Go to the documentation of this file.
1 ! generated by tapenade (inria, ecuador team)
2 ! tapenade 3.16 (develop) - 22 aug 2023 15:51
3 !
5  implicit none
6 
7 contains
8 ! differentiation of timestep_block in forward (tangent) mode (with options i4 dr8 r8):
9 ! variations of useful results: *dtl *radi *radj *radk
10 ! with respect to varying inputs: rhoinf pinfcorr *rev *dtl *p
11 ! *sfacei *sfacej *sfacek *w *rlv *vol *si *sj *sk
12 ! *radi *radj *radk
13 ! rw status of diff variables: rhoinf:in pinfcorr:in *rev:in
14 ! *dtl:in-out *p:in *sfacei:in *sfacej:in *sfacek:in
15 ! *w:in *rlv:in *vol:in *si:in *sj:in *sk:in *radi:in-out
16 ! *radj:in-out *radk:in-out
17 ! plus diff mem management of: rev:in dtl:in p:in sfacei:in sfacej:in
18 ! sfacek:in w:in rlv:in vol:in si:in sj:in sk:in
19 ! radi:in radj:in radk:in
20  subroutine timestep_block_d(onlyradii)
21 !
22 ! timestep computes the time step, or more precisely the time
23 ! step divided by the volume per unit cfl, in the owned cells.
24 ! however, for the artificial dissipation schemes, the spectral
25 ! radii in the halo's are needed. therefore the loop is taken
26 ! over the the first level of halo cells. the spectral radii are
27 ! stored and possibly modified for high aspect ratio cells.
28 !
29  use constants
30  use blockpointers, only : ie, je, ke, il, jl, kl, w, wd, p, pd, &
32 & , sj, sjd, sk, skd, sfacei, sfaceid, sfacej, sfacejd, sfacek, &
38  use inputphysics, only : equationmode
40  use section, only : sections
42  use utils_d, only : terminate
43  implicit none
44 !
45 ! subroutine argument.
46 !
47  logical, intent(in) :: onlyradii
48 !
49 ! local parameters.
50 !
51  real(kind=realtype), parameter :: b=2.0_realtype
52 !
53 ! local variables.
54 !
55  integer(kind=inttype) :: i, j, k, ii
56  real(kind=realtype) :: plim, rlim, clim2
57  real(kind=realtype) :: plimd, clim2d
58  real(kind=realtype) :: uux, uuy, uuz, cc2, qsi, qsj, qsk, sx, sy, sz&
59 & , rmu
60  real(kind=realtype) :: uuxd, uuyd, uuzd, cc2d, qsid, qsjd, qskd, sxd&
61 & , syd, szd, rmud
62  real(kind=realtype) :: ri, rj, rk, rij, rjk, rki
63  real(kind=realtype) :: rid, rjd, rkd, rijd, rjkd, rkid
64  real(kind=realtype) :: vsi, vsj, vsk, rfl, dpi, dpj, dpk
65  real(kind=realtype) :: vsid, vsjd, vskd, rfld, dpid, dpjd, dpkd
66  real(kind=realtype) :: sface, tmp
67  real(kind=realtype) :: sfaced
68  logical :: radiineeded, doscaling
69  intrinsic max
70  intrinsic abs
71  intrinsic sqrt
72  real(kind=realtype) :: abs0
73  real(kind=realtype) :: abs0d
74  real(kind=realtype) :: abs1
75  real(kind=realtype) :: abs1d
76  real(kind=realtype) :: abs2
77  real(kind=realtype) :: abs2d
78  real(kind=realtype) :: abs3
79  real(kind=realtype) :: abs3d
80  real(kind=realtype) :: abs4
81  real(kind=realtype) :: abs4d
82  real(kind=realtype) :: abs5
83  real(kind=realtype) :: abs5d
84  real(kind=realtype) :: arg1
85  real(kind=realtype) :: arg1d
86  real(kind=realtype) :: result1
87  real(kind=realtype) :: result1d
88  real(kind=realtype) :: temp
89  real(kind=realtype) :: temp0
90 ! determine whether or not the spectral radii are needed for the
91 ! flux computation.
92  radiineeded = radiineededcoarse
93  if (currentlevel .le. groundlevel) radiineeded = radiineededfine
94 ! return immediately if only the spectral radii must be computed
95 ! and these are not needed for the flux computation.
96  if (onlyradii .and. (.not.radiineeded)) then
97  return
98  else
99 ! set the value of plim. to be fully consistent this must have
100 ! the dimension of a pressure. therefore a fraction of pinfcorr
101 ! is used. idem for rlim; compute clim2 as well.
102  plimd = 0.001_realtype*pinfcorrd
103  plim = 0.001_realtype*pinfcorr
104  rlim = 0.001_realtype*rhoinf
105  clim2d = gammainf*0.000001_realtype*(pinfcorrd-pinfcorr*rhoinfd/&
106 & rhoinf)/rhoinf
107  clim2 = 0.000001_realtype*gammainf*pinfcorr/rhoinf
108  doscaling = dirscaling .and. currentlevel .le. groundlevel
109 ! initialize sface to zero. this value will be used if the
110 ! block is not moving.
111  sface = zero
112 !
113 ! inviscid contribution, depending on the preconditioner.
114 ! compute the cell centered values of the spectral radii.
115 !
116  select case (precond)
117  case (noprecond)
118  sfaced = 0.0_8
119 ! no preconditioner. simply the standard spectral radius.
120 ! loop over the cells, including the first level halo.
121  do k=1,ke
122  do j=1,je
123  do i=1,ie
124 ! compute the velocities and speed of sound squared.
125  uuxd = wd(i, j, k, ivx)
126  uux = w(i, j, k, ivx)
127  uuyd = wd(i, j, k, ivy)
128  uuy = w(i, j, k, ivy)
129  uuzd = wd(i, j, k, ivz)
130  uuz = w(i, j, k, ivz)
131  temp = w(i, j, k, irho)
132  temp0 = p(i, j, k)/temp
133  cc2d = gamma(i, j, k)*(pd(i, j, k)-temp0*wd(i, j, k, irho)&
134 & )/temp
135  cc2 = gamma(i, j, k)*temp0
136  if (cc2 .lt. clim2) then
137  cc2d = clim2d
138  cc2 = clim2
139  else
140  cc2 = cc2
141  end if
142 ! set the dot product of the grid velocity and the
143 ! normal in i-direction for a moving face. to avoid
144 ! a number of multiplications by 0.5 simply the sum
145 ! is taken.
146  if (addgridvelocities) then
147  sfaced = sfaceid(i-1, j, k) + sfaceid(i, j, k)
148  sface = sfacei(i-1, j, k) + sfacei(i, j, k)
149  end if
150 ! spectral radius in i-direction.
151  sxd = sid(i-1, j, k, 1) + sid(i, j, k, 1)
152  sx = si(i-1, j, k, 1) + si(i, j, k, 1)
153  syd = sid(i-1, j, k, 2) + sid(i, j, k, 2)
154  sy = si(i-1, j, k, 2) + si(i, j, k, 2)
155  szd = sid(i-1, j, k, 3) + sid(i, j, k, 3)
156  sz = si(i-1, j, k, 3) + si(i, j, k, 3)
157  qsid = sx*uuxd + uux*sxd + sy*uuyd + uuy*syd + sz*uuzd + &
158 & uuz*szd - sfaced
159  qsi = uux*sx + uuy*sy + uuz*sz - sface
160  if (qsi .ge. 0.) then
161  abs0d = qsid
162  abs0 = qsi
163  else
164  abs0d = -qsid
165  abs0 = -qsi
166  end if
167  temp0 = sx*sx + sy*sy + sz*sz
168  arg1d = temp0*cc2d + cc2*(2*sx*sxd+2*sy*syd+2*sz*szd)
169  arg1 = cc2*temp0
170  temp0 = sqrt(arg1)
171  if (arg1 .eq. 0.0_8) then
172  result1d = 0.0_8
173  else
174  result1d = arg1d/(2.0*temp0)
175  end if
176  result1 = temp0
177  rid = half*(abs0d+acousticscalefactor*result1d)
178  ri = half*(abs0+acousticscalefactor*result1)
179 ! the grid velocity in j-direction.
180  if (addgridvelocities) then
181  sfaced = sfacejd(i, j-1, k) + sfacejd(i, j, k)
182  sface = sfacej(i, j-1, k) + sfacej(i, j, k)
183  end if
184 ! spectral radius in j-direction.
185  sxd = sjd(i, j-1, k, 1) + sjd(i, j, k, 1)
186  sx = sj(i, j-1, k, 1) + sj(i, j, k, 1)
187  syd = sjd(i, j-1, k, 2) + sjd(i, j, k, 2)
188  sy = sj(i, j-1, k, 2) + sj(i, j, k, 2)
189  szd = sjd(i, j-1, k, 3) + sjd(i, j, k, 3)
190  sz = sj(i, j-1, k, 3) + sj(i, j, k, 3)
191  qsjd = sx*uuxd + uux*sxd + sy*uuyd + uuy*syd + sz*uuzd + &
192 & uuz*szd - sfaced
193  qsj = uux*sx + uuy*sy + uuz*sz - sface
194  if (qsj .ge. 0.) then
195  abs1d = qsjd
196  abs1 = qsj
197  else
198  abs1d = -qsjd
199  abs1 = -qsj
200  end if
201  temp0 = sx*sx + sy*sy + sz*sz
202  arg1d = temp0*cc2d + cc2*(2*sx*sxd+2*sy*syd+2*sz*szd)
203  arg1 = cc2*temp0
204  temp0 = sqrt(arg1)
205  if (arg1 .eq. 0.0_8) then
206  result1d = 0.0_8
207  else
208  result1d = arg1d/(2.0*temp0)
209  end if
210  result1 = temp0
211  rjd = half*(abs1d+acousticscalefactor*result1d)
212  rj = half*(abs1+acousticscalefactor*result1)
213 ! the grid velocity in k-direction.
214  if (addgridvelocities) then
215  sfaced = sfacekd(i, j, k-1) + sfacekd(i, j, k)
216  sface = sfacek(i, j, k-1) + sfacek(i, j, k)
217  end if
218 ! spectral radius in k-direction.
219  sxd = skd(i, j, k-1, 1) + skd(i, j, k, 1)
220  sx = sk(i, j, k-1, 1) + sk(i, j, k, 1)
221  syd = skd(i, j, k-1, 2) + skd(i, j, k, 2)
222  sy = sk(i, j, k-1, 2) + sk(i, j, k, 2)
223  szd = skd(i, j, k-1, 3) + skd(i, j, k, 3)
224  sz = sk(i, j, k-1, 3) + sk(i, j, k, 3)
225  qskd = sx*uuxd + uux*sxd + sy*uuyd + uuy*syd + sz*uuzd + &
226 & uuz*szd - sfaced
227  qsk = uux*sx + uuy*sy + uuz*sz - sface
228  if (qsk .ge. 0.) then
229  abs2d = qskd
230  abs2 = qsk
231  else
232  abs2d = -qskd
233  abs2 = -qsk
234  end if
235  temp0 = sx*sx + sy*sy + sz*sz
236  arg1d = temp0*cc2d + cc2*(2*sx*sxd+2*sy*syd+2*sz*szd)
237  arg1 = cc2*temp0
238  temp0 = sqrt(arg1)
239  if (arg1 .eq. 0.0_8) then
240  result1d = 0.0_8
241  else
242  result1d = arg1d/(2.0*temp0)
243  end if
244  result1 = temp0
245  rkd = half*(abs2d+acousticscalefactor*result1d)
246  rk = half*(abs2+acousticscalefactor*result1)
247 ! compute the inviscid contribution to the time step.
248  if (.not.onlyradii) then
249  dtld(i, j, k) = rid + rjd + rkd
250  dtl(i, j, k) = ri + rj + rk
251  end if
252 !
253 ! adapt the spectral radii if directional scaling must be
254 ! applied.
255 !
256  if (doscaling) then
257  if (ri .lt. eps) then
258  ri = eps
259  rid = 0.0_8
260  else
261  ri = ri
262  end if
263  if (rj .lt. eps) then
264  rj = eps
265  rjd = 0.0_8
266  else
267  rj = rj
268  end if
269  if (rk .lt. eps) then
270  rk = eps
271  rkd = 0.0_8
272  else
273  rk = rk
274  end if
275 ! compute the scaling in the three coordinate
276 ! directions.
277  temp0 = ri/rj
278  if (temp0 .le. 0.0_8 .and. (adis .eq. 0.0_8 .or. adis &
279 & .ne. int(adis))) then
280  rijd = 0.0_8
281  else
282  rijd = adis*temp0**(adis-1)*(rid-temp0*rjd)/rj
283  end if
284  rij = temp0**adis
285  temp0 = rj/rk
286  if (temp0 .le. 0.0_8 .and. (adis .eq. 0.0_8 .or. adis &
287 & .ne. int(adis))) then
288  rjkd = 0.0_8
289  else
290  rjkd = adis*temp0**(adis-1)*(rjd-temp0*rkd)/rk
291  end if
292  rjk = temp0**adis
293  temp0 = rk/ri
294  if (temp0 .le. 0.0_8 .and. (adis .eq. 0.0_8 .or. adis &
295 & .ne. int(adis))) then
296  rkid = 0.0_8
297  else
298  rkid = adis*temp0**(adis-1)*(rkd-temp0*rid)/ri
299  end if
300  rki = temp0**adis
301 ! create the scaled versions of the aspect ratios.
302 ! note that the multiplication is done with radi, radj
303 ! and radk, such that the influence of the clipping
304 ! is negligible.
305  temp0 = one/rij
306  radid(i, j, k) = (one+temp0+rki)*rid + ri*(rkid-temp0*&
307 & rijd/rij)
308  radi(i, j, k) = ri*(one+temp0+rki)
309  temp0 = one/rjk
310  radjd(i, j, k) = (one+temp0+rij)*rjd + rj*(rijd-temp0*&
311 & rjkd/rjk)
312  radj(i, j, k) = rj*(one+temp0+rij)
313  temp0 = one/rki
314  radkd(i, j, k) = (one+temp0+rjk)*rkd + rk*(rjkd-temp0*&
315 & rkid/rki)
316  radk(i, j, k) = rk*(one+temp0+rjk)
317  else
318  radid(i, j, k) = rid
319  radi(i, j, k) = ri
320  radjd(i, j, k) = rjd
321  radj(i, j, k) = rj
322  radkd(i, j, k) = rkd
323  radk(i, j, k) = rk
324  end if
325  end do
326  end do
327  end do
328  case (turkel)
329  call terminate('timestep', &
330 & 'turkel preconditioner not implemented yet')
331  case (choimerkle)
332  call terminate('timestep', &
333 & 'choi merkle preconditioner not implemented yet')
334  end select
335 ! the rest of this file can be skipped if only the spectral
336 ! radii need to be computed.
337  if (.not.onlyradii) then
338 ! the viscous contribution, if needed.
339  if (viscous) then
340 ! loop over the owned cell centers.
341  do k=2,kl
342  do j=2,jl
343  do i=2,il
344 ! compute the effective viscosity coefficient. the
345 ! factor 0.5 is a combination of two things. in the
346 ! standard central discretization of a second
347 ! derivative there is a factor 2 multiplying the
348 ! central node. however in the code below not the
349 ! average but the sum of the left and the right face
350 ! is taken and squared. this leads to a factor 4.
351 ! combining both effects leads to 0.5. furthermore,
352 ! it is divided by the volume and density to obtain
353 ! the correct dimensions and multiplied by the
354 ! non-dimensional factor factvis.
355  rmud = rlvd(i, j, k)
356  rmu = rlv(i, j, k)
357  if (eddymodel) then
358  rmud = rmud + revd(i, j, k)
359  rmu = rmu + rev(i, j, k)
360  end if
361  temp0 = w(i, j, k, irho)
362  temp = temp0*vol(i, j, k)
363  rmud = half*(rmud-rmu*(vol(i, j, k)*wd(i, j, k, irho)+&
364 & temp0*vold(i, j, k))/temp)/temp
365  rmu = half*(rmu/temp)
366 ! add the viscous contribution in i-direction to the
367 ! (inverse) of the time step.
368  sxd = sid(i, j, k, 1) + sid(i-1, j, k, 1)
369  sx = si(i, j, k, 1) + si(i-1, j, k, 1)
370  syd = sid(i, j, k, 2) + sid(i-1, j, k, 2)
371  sy = si(i, j, k, 2) + si(i-1, j, k, 2)
372  szd = sid(i, j, k, 3) + sid(i-1, j, k, 3)
373  sz = si(i, j, k, 3) + si(i-1, j, k, 3)
374  temp0 = sx*sx + sy*sy + sz*sz
375  vsid = temp0*rmud + rmu*(2*sx*sxd+2*sy*syd+2*sz*szd)
376  vsi = rmu*temp0
377  dtld(i, j, k) = dtld(i, j, k) + vsid
378  dtl(i, j, k) = dtl(i, j, k) + vsi
379 ! add the viscous contribution in j-direction to the
380 ! (inverse) of the time step.
381  sxd = sjd(i, j, k, 1) + sjd(i, j-1, k, 1)
382  sx = sj(i, j, k, 1) + sj(i, j-1, k, 1)
383  syd = sjd(i, j, k, 2) + sjd(i, j-1, k, 2)
384  sy = sj(i, j, k, 2) + sj(i, j-1, k, 2)
385  szd = sjd(i, j, k, 3) + sjd(i, j-1, k, 3)
386  sz = sj(i, j, k, 3) + sj(i, j-1, k, 3)
387  temp0 = sx*sx + sy*sy + sz*sz
388  vsjd = temp0*rmud + rmu*(2*sx*sxd+2*sy*syd+2*sz*szd)
389  vsj = rmu*temp0
390  dtld(i, j, k) = dtld(i, j, k) + vsjd
391  dtl(i, j, k) = dtl(i, j, k) + vsj
392 ! add the viscous contribution in k-direction to the
393 ! (inverse) of the time step.
394  sxd = skd(i, j, k, 1) + skd(i, j, k-1, 1)
395  sx = sk(i, j, k, 1) + sk(i, j, k-1, 1)
396  syd = skd(i, j, k, 2) + skd(i, j, k-1, 2)
397  sy = sk(i, j, k, 2) + sk(i, j, k-1, 2)
398  szd = skd(i, j, k, 3) + skd(i, j, k-1, 3)
399  sz = sk(i, j, k, 3) + sk(i, j, k-1, 3)
400  temp0 = sx*sx + sy*sy + sz*sz
401  vskd = temp0*rmud + rmu*(2*sx*sxd+2*sy*syd+2*sz*szd)
402  vsk = rmu*temp0
403  dtld(i, j, k) = dtld(i, j, k) + vskd
404  dtl(i, j, k) = dtl(i, j, k) + vsk
405  end do
406  end do
407  end do
408  end if
409 ! for the spectral mode an additional term term must be
410 ! taken into account, which corresponds to the contribution
411 ! of the highest frequency.
412  if (equationmode .eq. timespectral) then
414 & timeperiod
415 ! loop over the owned cell centers and add the term.
416  do k=2,kl
417  do j=2,jl
418  do i=2,il
419  dtld(i, j, k) = dtld(i, j, k) + tmp*vold(i, j, k)
420  dtl(i, j, k) = dtl(i, j, k) + tmp*vol(i, j, k)
421  end do
422  end do
423  end do
424  end if
425 ! currently the inverse of dt/vol is stored in dtl. invert
426 ! this value such that the time step per unit cfl number is
427 ! stored and correct in cases of high gradients.
428  do k=2,kl
429  do j=2,jl
430  do i=2,il
431  if (p(i+1, j, k) - two*p(i, j, k) + p(i-1, j, k) .ge. 0.) &
432 & then
433  abs3d = pd(i+1, j, k) - two*pd(i, j, k) + pd(i-1, j, k)
434  abs3 = p(i+1, j, k) - two*p(i, j, k) + p(i-1, j, k)
435  else
436  abs3d = two*pd(i, j, k) - pd(i+1, j, k) - pd(i-1, j, k)
437  abs3 = -(p(i+1, j, k)-two*p(i, j, k)+p(i-1, j, k))
438  end if
439  temp0 = p(i+1, j, k) + two*p(i, j, k) + p(i-1, j, k) + &
440 & plim
441  dpid = (abs3d-abs3*(pd(i+1, j, k)+two*pd(i, j, k)+pd(i-1, &
442 & j, k)+plimd)/temp0)/temp0
443  dpi = abs3/temp0
444  if (p(i, j+1, k) - two*p(i, j, k) + p(i, j-1, k) .ge. 0.) &
445 & then
446  abs4d = pd(i, j+1, k) - two*pd(i, j, k) + pd(i, j-1, k)
447  abs4 = p(i, j+1, k) - two*p(i, j, k) + p(i, j-1, k)
448  else
449  abs4d = two*pd(i, j, k) - pd(i, j+1, k) - pd(i, j-1, k)
450  abs4 = -(p(i, j+1, k)-two*p(i, j, k)+p(i, j-1, k))
451  end if
452  temp0 = p(i, j+1, k) + two*p(i, j, k) + p(i, j-1, k) + &
453 & plim
454  dpjd = (abs4d-abs4*(pd(i, j+1, k)+two*pd(i, j, k)+pd(i, j-&
455 & 1, k)+plimd)/temp0)/temp0
456  dpj = abs4/temp0
457  if (p(i, j, k+1) - two*p(i, j, k) + p(i, j, k-1) .ge. 0.) &
458 & then
459  abs5d = pd(i, j, k+1) - two*pd(i, j, k) + pd(i, j, k-1)
460  abs5 = p(i, j, k+1) - two*p(i, j, k) + p(i, j, k-1)
461  else
462  abs5d = two*pd(i, j, k) - pd(i, j, k+1) - pd(i, j, k-1)
463  abs5 = -(p(i, j, k+1)-two*p(i, j, k)+p(i, j, k-1))
464  end if
465  temp0 = p(i, j, k+1) + two*p(i, j, k) + p(i, j, k-1) + &
466 & plim
467  dpkd = (abs5d-abs5*(pd(i, j, k+1)+two*pd(i, j, k)+pd(i, j&
468 & , k-1)+plimd)/temp0)/temp0
469  dpk = abs5/temp0
470  temp0 = one/(one+b*(dpi+dpj+dpk))
471  rfld = -(temp0*b*(dpid+dpjd+dpkd)/(one+b*(dpi+dpj+dpk)))
472  rfl = temp0
473  temp0 = rfl/dtl(i, j, k)
474  dtld(i, j, k) = (rfld-temp0*dtld(i, j, k))/dtl(i, j, k)
475  dtl(i, j, k) = temp0
476  end do
477  end do
478  end do
479  end if
480  end if
481  end subroutine timestep_block_d
482 
483  subroutine timestep_block(onlyradii)
484 !
485 ! timestep computes the time step, or more precisely the time
486 ! step divided by the volume per unit cfl, in the owned cells.
487 ! however, for the artificial dissipation schemes, the spectral
488 ! radii in the halo's are needed. therefore the loop is taken
489 ! over the the first level of halo cells. the spectral radii are
490 ! stored and possibly modified for high aspect ratio cells.
491 !
492  use constants
493  use blockpointers, only : ie, je, ke, il, jl, kl, w, p, rlv, rev, &
494 & radi, radj, radk, si, sj, sk, sfacei, sfacej, sfacek, dtl, gamma, &
497 & , viscous, rhoinf
500  use inputphysics, only : equationmode
501  use iteration, only : groundlevel, currentlevel
502  use section, only : sections
504  use utils_d, only : terminate
505  implicit none
506 !
507 ! subroutine argument.
508 !
509  logical, intent(in) :: onlyradii
510 !
511 ! local parameters.
512 !
513  real(kind=realtype), parameter :: b=2.0_realtype
514 !
515 ! local variables.
516 !
517  integer(kind=inttype) :: i, j, k, ii
518  real(kind=realtype) :: plim, rlim, clim2
519  real(kind=realtype) :: uux, uuy, uuz, cc2, qsi, qsj, qsk, sx, sy, sz&
520 & , rmu
521  real(kind=realtype) :: ri, rj, rk, rij, rjk, rki
522  real(kind=realtype) :: vsi, vsj, vsk, rfl, dpi, dpj, dpk
523  real(kind=realtype) :: sface, tmp
524  logical :: radiineeded, doscaling
525  intrinsic max
526  intrinsic abs
527  intrinsic sqrt
528  real(kind=realtype) :: abs0
529  real(kind=realtype) :: abs1
530  real(kind=realtype) :: abs2
531  real(kind=realtype) :: abs3
532  real(kind=realtype) :: abs4
533  real(kind=realtype) :: abs5
534  real(kind=realtype) :: arg1
535  real(kind=realtype) :: result1
536 ! determine whether or not the spectral radii are needed for the
537 ! flux computation.
538  radiineeded = radiineededcoarse
539  if (currentlevel .le. groundlevel) radiineeded = radiineededfine
540 ! return immediately if only the spectral radii must be computed
541 ! and these are not needed for the flux computation.
542  if (onlyradii .and. (.not.radiineeded)) then
543  return
544  else
545 ! set the value of plim. to be fully consistent this must have
546 ! the dimension of a pressure. therefore a fraction of pinfcorr
547 ! is used. idem for rlim; compute clim2 as well.
548  plim = 0.001_realtype*pinfcorr
549  rlim = 0.001_realtype*rhoinf
550  clim2 = 0.000001_realtype*gammainf*pinfcorr/rhoinf
551  doscaling = dirscaling .and. currentlevel .le. groundlevel
552 ! initialize sface to zero. this value will be used if the
553 ! block is not moving.
554  sface = zero
555 !
556 ! inviscid contribution, depending on the preconditioner.
557 ! compute the cell centered values of the spectral radii.
558 !
559  select case (precond)
560  case (noprecond)
561 ! no preconditioner. simply the standard spectral radius.
562 ! loop over the cells, including the first level halo.
563  do k=1,ke
564  do j=1,je
565  do i=1,ie
566 ! compute the velocities and speed of sound squared.
567  uux = w(i, j, k, ivx)
568  uuy = w(i, j, k, ivy)
569  uuz = w(i, j, k, ivz)
570  cc2 = gamma(i, j, k)*p(i, j, k)/w(i, j, k, irho)
571  if (cc2 .lt. clim2) then
572  cc2 = clim2
573  else
574  cc2 = cc2
575  end if
576 ! set the dot product of the grid velocity and the
577 ! normal in i-direction for a moving face. to avoid
578 ! a number of multiplications by 0.5 simply the sum
579 ! is taken.
580  if (addgridvelocities) sface = sfacei(i-1, j, k) + sfacei(&
581 & i, j, k)
582 ! spectral radius in i-direction.
583  sx = si(i-1, j, k, 1) + si(i, j, k, 1)
584  sy = si(i-1, j, k, 2) + si(i, j, k, 2)
585  sz = si(i-1, j, k, 3) + si(i, j, k, 3)
586  qsi = uux*sx + uuy*sy + uuz*sz - sface
587  if (qsi .ge. 0.) then
588  abs0 = qsi
589  else
590  abs0 = -qsi
591  end if
592  arg1 = cc2*(sx**2+sy**2+sz**2)
593  result1 = sqrt(arg1)
594  ri = half*(abs0+acousticscalefactor*result1)
595 ! the grid velocity in j-direction.
596  if (addgridvelocities) sface = sfacej(i, j-1, k) + sfacej(&
597 & i, j, k)
598 ! spectral radius in j-direction.
599  sx = sj(i, j-1, k, 1) + sj(i, j, k, 1)
600  sy = sj(i, j-1, k, 2) + sj(i, j, k, 2)
601  sz = sj(i, j-1, k, 3) + sj(i, j, k, 3)
602  qsj = uux*sx + uuy*sy + uuz*sz - sface
603  if (qsj .ge. 0.) then
604  abs1 = qsj
605  else
606  abs1 = -qsj
607  end if
608  arg1 = cc2*(sx**2+sy**2+sz**2)
609  result1 = sqrt(arg1)
610  rj = half*(abs1+acousticscalefactor*result1)
611 ! the grid velocity in k-direction.
612  if (addgridvelocities) sface = sfacek(i, j, k-1) + sfacek(&
613 & i, j, k)
614 ! spectral radius in k-direction.
615  sx = sk(i, j, k-1, 1) + sk(i, j, k, 1)
616  sy = sk(i, j, k-1, 2) + sk(i, j, k, 2)
617  sz = sk(i, j, k-1, 3) + sk(i, j, k, 3)
618  qsk = uux*sx + uuy*sy + uuz*sz - sface
619  if (qsk .ge. 0.) then
620  abs2 = qsk
621  else
622  abs2 = -qsk
623  end if
624  arg1 = cc2*(sx**2+sy**2+sz**2)
625  result1 = sqrt(arg1)
626  rk = half*(abs2+acousticscalefactor*result1)
627 ! compute the inviscid contribution to the time step.
628  if (.not.onlyradii) dtl(i, j, k) = ri + rj + rk
629 !
630 ! adapt the spectral radii if directional scaling must be
631 ! applied.
632 !
633  if (doscaling) then
634  if (ri .lt. eps) then
635  ri = eps
636  else
637  ri = ri
638  end if
639  if (rj .lt. eps) then
640  rj = eps
641  else
642  rj = rj
643  end if
644  if (rk .lt. eps) then
645  rk = eps
646  else
647  rk = rk
648  end if
649 ! compute the scaling in the three coordinate
650 ! directions.
651  rij = (ri/rj)**adis
652  rjk = (rj/rk)**adis
653  rki = (rk/ri)**adis
654 ! create the scaled versions of the aspect ratios.
655 ! note that the multiplication is done with radi, radj
656 ! and radk, such that the influence of the clipping
657 ! is negligible.
658  radi(i, j, k) = ri*(one+one/rij+rki)
659  radj(i, j, k) = rj*(one+one/rjk+rij)
660  radk(i, j, k) = rk*(one+one/rki+rjk)
661  else
662  radi(i, j, k) = ri
663  radj(i, j, k) = rj
664  radk(i, j, k) = rk
665  end if
666  end do
667  end do
668  end do
669  case (turkel)
670  call terminate('timestep', &
671 & 'turkel preconditioner not implemented yet')
672  case (choimerkle)
673  call terminate('timestep', &
674 & 'choi merkle preconditioner not implemented yet')
675  end select
676 ! the rest of this file can be skipped if only the spectral
677 ! radii need to be computed.
678  if (.not.onlyradii) then
679 ! the viscous contribution, if needed.
680  if (viscous) then
681 ! loop over the owned cell centers.
682  do k=2,kl
683  do j=2,jl
684  do i=2,il
685 ! compute the effective viscosity coefficient. the
686 ! factor 0.5 is a combination of two things. in the
687 ! standard central discretization of a second
688 ! derivative there is a factor 2 multiplying the
689 ! central node. however in the code below not the
690 ! average but the sum of the left and the right face
691 ! is taken and squared. this leads to a factor 4.
692 ! combining both effects leads to 0.5. furthermore,
693 ! it is divided by the volume and density to obtain
694 ! the correct dimensions and multiplied by the
695 ! non-dimensional factor factvis.
696  rmu = rlv(i, j, k)
697  if (eddymodel) rmu = rmu + rev(i, j, k)
698  rmu = half*rmu/(w(i, j, k, irho)*vol(i, j, k))
699 ! add the viscous contribution in i-direction to the
700 ! (inverse) of the time step.
701  sx = si(i, j, k, 1) + si(i-1, j, k, 1)
702  sy = si(i, j, k, 2) + si(i-1, j, k, 2)
703  sz = si(i, j, k, 3) + si(i-1, j, k, 3)
704  vsi = rmu*(sx*sx+sy*sy+sz*sz)
705  dtl(i, j, k) = dtl(i, j, k) + vsi
706 ! add the viscous contribution in j-direction to the
707 ! (inverse) of the time step.
708  sx = sj(i, j, k, 1) + sj(i, j-1, k, 1)
709  sy = sj(i, j, k, 2) + sj(i, j-1, k, 2)
710  sz = sj(i, j, k, 3) + sj(i, j-1, k, 3)
711  vsj = rmu*(sx*sx+sy*sy+sz*sz)
712  dtl(i, j, k) = dtl(i, j, k) + vsj
713 ! add the viscous contribution in k-direction to the
714 ! (inverse) of the time step.
715  sx = sk(i, j, k, 1) + sk(i, j, k-1, 1)
716  sy = sk(i, j, k, 2) + sk(i, j, k-1, 2)
717  sz = sk(i, j, k, 3) + sk(i, j, k-1, 3)
718  vsk = rmu*(sx*sx+sy*sy+sz*sz)
719  dtl(i, j, k) = dtl(i, j, k) + vsk
720  end do
721  end do
722  end do
723  end if
724 ! for the spectral mode an additional term term must be
725 ! taken into account, which corresponds to the contribution
726 ! of the highest frequency.
727  if (equationmode .eq. timespectral) then
729 & timeperiod
730 ! loop over the owned cell centers and add the term.
731  do k=2,kl
732  do j=2,jl
733  do i=2,il
734  dtl(i, j, k) = dtl(i, j, k) + tmp*vol(i, j, k)
735  end do
736  end do
737  end do
738  end if
739 ! currently the inverse of dt/vol is stored in dtl. invert
740 ! this value such that the time step per unit cfl number is
741 ! stored and correct in cases of high gradients.
742  do k=2,kl
743  do j=2,jl
744  do i=2,il
745  if (p(i+1, j, k) - two*p(i, j, k) + p(i-1, j, k) .ge. 0.) &
746 & then
747  abs3 = p(i+1, j, k) - two*p(i, j, k) + p(i-1, j, k)
748  else
749  abs3 = -(p(i+1, j, k)-two*p(i, j, k)+p(i-1, j, k))
750  end if
751  dpi = abs3/(p(i+1, j, k)+two*p(i, j, k)+p(i-1, j, k)+plim)
752  if (p(i, j+1, k) - two*p(i, j, k) + p(i, j-1, k) .ge. 0.) &
753 & then
754  abs4 = p(i, j+1, k) - two*p(i, j, k) + p(i, j-1, k)
755  else
756  abs4 = -(p(i, j+1, k)-two*p(i, j, k)+p(i, j-1, k))
757  end if
758  dpj = abs4/(p(i, j+1, k)+two*p(i, j, k)+p(i, j-1, k)+plim)
759  if (p(i, j, k+1) - two*p(i, j, k) + p(i, j, k-1) .ge. 0.) &
760 & then
761  abs5 = p(i, j, k+1) - two*p(i, j, k) + p(i, j, k-1)
762  else
763  abs5 = -(p(i, j, k+1)-two*p(i, j, k)+p(i, j, k-1))
764  end if
765  dpk = abs5/(p(i, j, k+1)+two*p(i, j, k)+p(i, j, k-1)+plim)
766  rfl = one/(one+b*(dpi+dpj+dpk))
767  dtl(i, j, k) = rfl/dtl(i, j, k)
768  end do
769  end do
770  end do
771  end if
772  end if
773  end subroutine timestep_block
774 
775 ! differentiation of gridvelocitiesfinelevel_block in forward (tangent) mode (with options i4 dr8 r8):
776 ! variations of useful results: *sfacei *sfacej *sfacek *s
777 ! with respect to varying inputs: pinf timeref rhoinf *(flowdoms.x)
778 ! veldirfreestream machgrid *sfacei *sfacej *sfacek
779 ! *s *si *sj *sk
780 ! rw status of diff variables: pinf:in timeref:in rhoinf:in *(flowdoms.x):in
781 ! veldirfreestream:in machgrid:in *sfacei:in-out
782 ! *sfacej:in-out *sfacek:in-out *s:in-out *si:in
783 ! *sj:in *sk:in
784 ! plus diff mem management of: flowdoms.x:in sfacei:in sfacej:in
785 ! sfacek:in s:in si:in sj:in sk:in
786  subroutine gridvelocitiesfinelevel_block_d(useoldcoor, t, sps, nn)
787 !
788 ! gridvelocitiesfinelevel computes the grid velocities for
789 ! the cell centers and the normal grid velocities for the faces
790 ! of moving blocks for the currently finest grid, i.e.
791 ! groundlevel. the velocities are computed at time t for
792 ! spectral mode sps. if useoldcoor is .true. the velocities
793 ! are determined using the unsteady time integrator in
794 ! combination with the old coordinates; otherwise the analytic
795 ! form is used.
796 !
797  use blockpointers
798  use cgnsgrid
799  use flowvarrefstate
800  use inputmotion
801  use inputunsteady
802  use iteration
803  use inputphysics
804  use inputtsstabderiv
805  use monitor
806  use communication
811  implicit none
812 !
813 ! subroutine arguments.
814 !
815  integer(kind=inttype), intent(in) :: sps, nn
816  logical, intent(in) :: useoldcoor
817  real(kind=realtype), dimension(*), intent(in) :: t
818 !
819 ! local variables.
820 !
821  integer(kind=inttype) :: mm
822  integer(kind=inttype) :: i, j, k, ii, iie, jje, kke
823  real(kind=realtype) :: oneover4dt, oneover8dt
824  real(kind=realtype) :: velxgrid, velygrid, velzgrid, ainf
825  real(kind=realtype) :: velxgridd, velygridd, velzgridd, ainfd
826  real(kind=realtype) :: velxgrid0, velygrid0, velzgrid0
827  real(kind=realtype) :: velxgrid0d, velygrid0d, velzgrid0d
828  real(kind=realtype), dimension(3) :: sc, xc, xxc
829  real(kind=realtype), dimension(3) :: scd, xcd, xxcd
830  real(kind=realtype), dimension(3) :: rotcenter, rotrate
831  real(kind=realtype), dimension(3) :: rotcenterd, rotrated
832  real(kind=realtype), dimension(3) :: rotationpoint
833  real(kind=realtype), dimension(3, 3) :: rotationmatrix, &
834 & derivrotationmatrix
835  real(kind=realtype), dimension(3, 3) :: derivrotationmatrixd
836  real(kind=realtype) :: tnew, told
837  real(kind=realtype), dimension(:, :), pointer :: sface
838  real(kind=realtype), dimension(:, :, :), pointer :: xx, ss
839  real(kind=realtype), dimension(:, :, :, :), pointer :: xxold
840  real(kind=realtype) :: intervalmach, alphats, alphaincrement, betats&
841 & , betaincrement
842  real(kind=realtype), dimension(3) :: veldir
843  real(kind=realtype), dimension(3) :: refdirection
844  intrinsic sqrt
845  real(kind=realtype) :: arg1
846  real(kind=realtype) :: arg1d
847  real(kind=realtype) :: temp
848  real(kind=realtype) :: temp0
849  real(kind=realtype) :: temp1
850 ! compute the mesh velocity from the given mesh mach number.
851 ! vel{x,y,z}grid0 is the actual velocity you want at the
852 ! geometry.
854  arg1 = gammainf*pinf/rhoinf
855  temp = sqrt(arg1)
856  if (arg1 .eq. 0.0_8) then
857  ainfd = 0.0_8
858  else
859  ainfd = arg1d/(2.0*temp)
860  end if
861  ainf = temp
862  velxgrid0d = -(veldirfreestream(1)*(machgrid*ainfd+ainf*machgridd)+&
863 & ainf*machgrid*veldirfreestreamd(1))
864  velxgrid0 = ainf*machgrid*(-veldirfreestream(1))
865  velygrid0d = -(veldirfreestream(2)*(machgrid*ainfd+ainf*machgridd)+&
866 & ainf*machgrid*veldirfreestreamd(2))
867  velygrid0 = ainf*machgrid*(-veldirfreestream(2))
868  velzgrid0d = -(veldirfreestream(3)*(machgrid*ainfd+ainf*machgridd)+&
869 & ainf*machgrid*veldirfreestreamd(3))
870  velzgrid0 = ainf*machgrid*(-veldirfreestream(3))
871 ! compute the derivative of the rotation matrix and the rotation
872 ! point; needed for velocity due to the rigid body rotation of
873 ! the entire grid. it is assumed that the rigid body motion of
874 ! the grid is only specified if there is only 1 section present.
875  derivrotationmatrixd = 0.0_8
876  call derivativerotmatrixrigid_d(derivrotationmatrix, &
877 & derivrotationmatrixd, rotationpoint, t(1))
878 !compute the rotation matrix to update the velocities for the time
879 !spectral stability derivative case...
880  if (blockismoving) then
881 ! determine the situation we are having here.
882  if (.not.useoldcoor) then
883 !
884 ! the velocities must be determined analytically.
885 !
886 ! store the rotation center and determine the
887 ! nondimensional rotation rate of this block. as the
888 ! reference length is 1 timeref == 1/uref and at the end
889 ! the nondimensional velocity is computed.
890  j = nbkglobal
891  rotcenter = cgnsdoms(j)%rotcenter
892  rotrated = cgnsdoms(j)%rotrate*timerefd
893  rotrate = timeref*cgnsdoms(j)%rotrate
894  velxgridd = velxgrid0d
895  velxgrid = velxgrid0
896  velygridd = velygrid0d
897  velygrid = velygrid0
898  velzgridd = velzgrid0d
899  velzgrid = velzgrid0
900  xcd = 0.0_8
901  xxcd = 0.0_8
902  scd = 0.0_8
903 !
904 ! grid velocities of the cell centers, including the
905 ! 1st level halo cells.
906 !
907 ! loop over the cells, including the 1st level halo's.
908  do k=1,ke
909  do j=1,je
910  do i=1,ie
911 ! determine the coordinates of the cell center,
912 ! which are stored in xc.
913  xcd(1) = eighth*(flowdomsd(nn, groundlevel, sps)%x(i-1, j-&
914 & 1, k-1, 1)+flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1&
915 & , 1)+flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 1)+&
916 & flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 1)+&
917 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 1)+&
918 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 1)+&
919 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 1)+&
920 & flowdomsd(nn, groundlevel, sps)%x(i, j, k, 1))
921  xc(1) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
922 & , k-1, 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
923 & 1)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 1)+&
924 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+flowdoms(&
925 & nn, groundlevel, sps)%x(i-1, j-1, k, 1)+flowdoms(nn, &
926 & groundlevel, sps)%x(i, j-1, k, 1)+flowdoms(nn, &
927 & groundlevel, sps)%x(i-1, j, k, 1)+flowdoms(nn, &
928 & groundlevel, sps)%x(i, j, k, 1))
929  xcd(2) = eighth*(flowdomsd(nn, groundlevel, sps)%x(i-1, j-&
930 & 1, k-1, 2)+flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1&
931 & , 2)+flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 2)+&
932 & flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 2)+&
933 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 2)+&
934 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 2)+&
935 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 2)+&
936 & flowdomsd(nn, groundlevel, sps)%x(i, j, k, 2))
937  xc(2) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
938 & , k-1, 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
939 & 2)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 2)+&
940 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+flowdoms(&
941 & nn, groundlevel, sps)%x(i-1, j-1, k, 2)+flowdoms(nn, &
942 & groundlevel, sps)%x(i, j-1, k, 2)+flowdoms(nn, &
943 & groundlevel, sps)%x(i-1, j, k, 2)+flowdoms(nn, &
944 & groundlevel, sps)%x(i, j, k, 2))
945  xcd(3) = eighth*(flowdomsd(nn, groundlevel, sps)%x(i-1, j-&
946 & 1, k-1, 3)+flowdomsd(nn, groundlevel, sps)%x(i, j-1, k-1&
947 & , 3)+flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 3)+&
948 & flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 3)+&
949 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 3)+&
950 & flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 3)+&
951 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 3)+&
952 & flowdomsd(nn, groundlevel, sps)%x(i, j, k, 3))
953  xc(3) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
954 & , k-1, 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
955 & 3)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 3)+&
956 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+flowdoms(&
957 & nn, groundlevel, sps)%x(i-1, j-1, k, 3)+flowdoms(nn, &
958 & groundlevel, sps)%x(i, j-1, k, 3)+flowdoms(nn, &
959 & groundlevel, sps)%x(i-1, j, k, 3)+flowdoms(nn, &
960 & groundlevel, sps)%x(i, j, k, 3))
961 ! determine the coordinates relative to the
962 ! center of rotation.
963  xxcd(1) = xcd(1)
964  xxc(1) = xc(1) - rotcenter(1)
965  xxcd(2) = xcd(2)
966  xxc(2) = xc(2) - rotcenter(2)
967  xxcd(3) = xcd(3)
968  xxc(3) = xc(3) - rotcenter(3)
969 ! determine the rotation speed of the cell center,
970 ! which is omega*r.
971  scd(1) = xxc(3)*rotrated(2) + rotrate(2)*xxcd(3) - xxc(2)*&
972 & rotrated(3) - rotrate(3)*xxcd(2)
973  sc(1) = rotrate(2)*xxc(3) - rotrate(3)*xxc(2)
974  scd(2) = xxc(1)*rotrated(3) + rotrate(3)*xxcd(1) - xxc(3)*&
975 & rotrated(1) - rotrate(1)*xxcd(3)
976  sc(2) = rotrate(3)*xxc(1) - rotrate(1)*xxc(3)
977  scd(3) = xxc(2)*rotrated(1) + rotrate(1)*xxcd(2) - xxc(1)*&
978 & rotrated(2) - rotrate(2)*xxcd(1)
979  sc(3) = rotrate(1)*xxc(2) - rotrate(2)*xxc(1)
980 ! determine the coordinates relative to the
981 ! rigid body rotation point.
982  xxcd(1) = xcd(1)
983  xxc(1) = xc(1) - rotationpoint(1)
984  xxcd(2) = xcd(2)
985  xxc(2) = xc(2) - rotationpoint(2)
986  xxcd(3) = xcd(3)
987  xxc(3) = xc(3) - rotationpoint(3)
988 ! determine the total velocity of the cell center.
989 ! this is a combination of rotation speed of this
990 ! block and the entire rigid body rotation.
991  sd(i, j, k, 1) = scd(1) + velxgridd + xxc(1)*&
992 & derivrotationmatrixd(1, 1) + derivrotationmatrix(1, 1)*&
993 & xxcd(1) + xxc(2)*derivrotationmatrixd(1, 2) + &
994 & derivrotationmatrix(1, 2)*xxcd(2) + xxc(3)*&
995 & derivrotationmatrixd(1, 3) + derivrotationmatrix(1, 3)*&
996 & xxcd(3)
997  s(i, j, k, 1) = sc(1) + velxgrid + derivrotationmatrix(1, &
998 & 1)*xxc(1) + derivrotationmatrix(1, 2)*xxc(2) + &
999 & derivrotationmatrix(1, 3)*xxc(3)
1000  sd(i, j, k, 2) = scd(2) + velygridd + xxc(1)*&
1001 & derivrotationmatrixd(2, 1) + derivrotationmatrix(2, 1)*&
1002 & xxcd(1) + xxc(2)*derivrotationmatrixd(2, 2) + &
1003 & derivrotationmatrix(2, 2)*xxcd(2) + xxc(3)*&
1004 & derivrotationmatrixd(2, 3) + derivrotationmatrix(2, 3)*&
1005 & xxcd(3)
1006  s(i, j, k, 2) = sc(2) + velygrid + derivrotationmatrix(2, &
1007 & 1)*xxc(1) + derivrotationmatrix(2, 2)*xxc(2) + &
1008 & derivrotationmatrix(2, 3)*xxc(3)
1009  sd(i, j, k, 3) = scd(3) + velzgridd + xxc(1)*&
1010 & derivrotationmatrixd(3, 1) + derivrotationmatrix(3, 1)*&
1011 & xxcd(1) + xxc(2)*derivrotationmatrixd(3, 2) + &
1012 & derivrotationmatrix(3, 2)*xxcd(2) + xxc(3)*&
1013 & derivrotationmatrixd(3, 3) + derivrotationmatrix(3, 3)*&
1014 & xxcd(3)
1015  s(i, j, k, 3) = sc(3) + velzgrid + derivrotationmatrix(3, &
1016 & 1)*xxc(1) + derivrotationmatrix(3, 2)*xxc(2) + &
1017 & derivrotationmatrix(3, 3)*xxc(3)
1018  end do
1019  end do
1020  end do
1021 !
1022 ! normal grid velocities of the faces.
1023 !
1024 ! loop over the three directions.
1025 ! the original code is elegant but the tapenade has a difficult time
1026 ! to understand it. thus, we unfold it and make it easier for the
1027 ! tapenade.
1028 ! i-direction
1029  do k=1,ke
1030  do j=1,je
1031  do i=0,ie
1032 ! determine the coordinates of the face center,
1033 ! which are stored in xc.
1034  xcd(1) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, j-1&
1035 & , k-1, 1)+flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 1&
1036 & )+flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 1)+&
1037 & flowdomsd(nn, groundlevel, sps)%x(i, j, k, 1))
1038  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1039 & -1, 1)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+&
1040 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 1)+flowdoms(&
1041 & nn, groundlevel, sps)%x(i, j, k, 1))
1042  xcd(2) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, j-1&
1043 & , k-1, 2)+flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 2&
1044 & )+flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 2)+&
1045 & flowdomsd(nn, groundlevel, sps)%x(i, j, k, 2))
1046  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1047 & -1, 2)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+&
1048 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 2)+flowdoms(&
1049 & nn, groundlevel, sps)%x(i, j, k, 2))
1050  xcd(3) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, j-1&
1051 & , k-1, 3)+flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 3&
1052 & )+flowdomsd(nn, groundlevel, sps)%x(i, j-1, k, 3)+&
1053 & flowdomsd(nn, groundlevel, sps)%x(i, j, k, 3))
1054  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1055 & -1, 3)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+&
1056 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 3)+flowdoms(&
1057 & nn, groundlevel, sps)%x(i, j, k, 3))
1058  rotcenterd = 0.0_8
1059  call cellfacevelocities_d(xc, xcd, rotcenter, rotcenterd, &
1060 & rotrate, rotrated, velxgrid, velxgridd&
1061 & , velygrid, velygridd, velzgrid, &
1062 & velzgridd, derivrotationmatrix, &
1063 & derivrotationmatrixd, sc, scd)
1064 ! store the dot product of grid velocity sc and
1065 ! the normal ss in sface.
1066  temp = si(i, j, k, 1)
1067  temp0 = si(i, j, k, 2)
1068  temp1 = si(i, j, k, 3)
1069  sfaceid(i, j, k) = temp*scd(1) + sc(1)*sid(i, j, k, 1) + &
1070 & temp0*scd(2) + sc(2)*sid(i, j, k, 2) + temp1*scd(3) + sc&
1071 & (3)*sid(i, j, k, 3)
1072  sfacei(i, j, k) = sc(1)*temp + sc(2)*temp0 + sc(3)*temp1
1073  end do
1074  end do
1075  end do
1076 ! j-direction
1077  do k=1,ke
1078  do j=0,je
1079  do i=1,ie
1080 ! determine the coordinates of the face center,
1081 ! which are stored in xc.
1082  xcd(1) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i-1, j&
1083 & , k, 1)+flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 1)+&
1084 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 1)+&
1085 & flowdomsd(nn, groundlevel, sps)%x(i, j, k, 1))
1086  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
1087 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+&
1088 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 1)+&
1089 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 1))
1090  xcd(2) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i-1, j&
1091 & , k, 2)+flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 2)+&
1092 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 2)+&
1093 & flowdomsd(nn, groundlevel, sps)%x(i, j, k, 2))
1094  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
1095 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+&
1096 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 2)+&
1097 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 2))
1098  xcd(3) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i-1, j&
1099 & , k, 3)+flowdomsd(nn, groundlevel, sps)%x(i, j, k-1, 3)+&
1100 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, k-1, 3)+&
1101 & flowdomsd(nn, groundlevel, sps)%x(i, j, k, 3))
1102  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
1103 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+&
1104 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 3)+&
1105 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 3))
1106  rotcenterd = 0.0_8
1107  call cellfacevelocities_d(xc, xcd, rotcenter, rotcenterd, &
1108 & rotrate, rotrated, velxgrid, velxgridd&
1109 & , velygrid, velygridd, velzgrid, &
1110 & velzgridd, derivrotationmatrix, &
1111 & derivrotationmatrixd, sc, scd)
1112 ! store the dot product of grid velocity sc and
1113 ! the normal ss in sface.
1114  temp1 = sj(i, j, k, 1)
1115  temp0 = sj(i, j, k, 2)
1116  temp = sj(i, j, k, 3)
1117  sfacejd(i, j, k) = temp1*scd(1) + sc(1)*sjd(i, j, k, 1) + &
1118 & temp0*scd(2) + sc(2)*sjd(i, j, k, 2) + temp*scd(3) + sc(&
1119 & 3)*sjd(i, j, k, 3)
1120  sfacej(i, j, k) = sc(1)*temp1 + sc(2)*temp0 + sc(3)*temp
1121  end do
1122  end do
1123  end do
1124 ! k-direction
1125  do k=0,ke
1126  do j=1,je
1127  do i=1,ie
1128 ! determine the coordinates of the face center,
1129 ! which are stored in xc.
1130  xcd(1) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, j-1&
1131 & , k, 1)+flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 1)+&
1132 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 1)+&
1133 & flowdomsd(nn, groundlevel, sps)%x(i, j, k, 1))
1134  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1135 & , 1)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 1)+&
1136 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 1)+&
1137 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 1))
1138  xcd(2) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, j-1&
1139 & , k, 2)+flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 2)+&
1140 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 2)+&
1141 & flowdomsd(nn, groundlevel, sps)%x(i, j, k, 2))
1142  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1143 & , 2)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 2)+&
1144 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 2)+&
1145 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 2))
1146  xcd(3) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, j-1&
1147 & , k, 3)+flowdomsd(nn, groundlevel, sps)%x(i-1, j, k, 3)+&
1148 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, k, 3)+&
1149 & flowdomsd(nn, groundlevel, sps)%x(i, j, k, 3))
1150  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1151 & , 3)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 3)+&
1152 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 3)+&
1153 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 3))
1154  rotcenterd = 0.0_8
1155  call cellfacevelocities_d(xc, xcd, rotcenter, rotcenterd, &
1156 & rotrate, rotrated, velxgrid, velxgridd&
1157 & , velygrid, velygridd, velzgrid, &
1158 & velzgridd, derivrotationmatrix, &
1159 & derivrotationmatrixd, sc, scd)
1160 ! store the dot product of grid velocity sc and
1161 ! the normal ss in sface.
1162  temp1 = sk(i, j, k, 1)
1163  temp0 = sk(i, j, k, 2)
1164  temp = sk(i, j, k, 3)
1165  sfacekd(i, j, k) = temp1*scd(1) + sc(1)*skd(i, j, k, 1) + &
1166 & temp0*scd(2) + sc(2)*skd(i, j, k, 2) + temp*scd(3) + sc(&
1167 & 3)*skd(i, j, k, 3)
1168  sfacek(i, j, k) = sc(1)*temp1 + sc(2)*temp0 + sc(3)*temp
1169  end do
1170  end do
1171  end do
1172  end if
1173  end if
1174  end subroutine gridvelocitiesfinelevel_block_d
1175 
1176  subroutine gridvelocitiesfinelevel_block(useoldcoor, t, sps, nn)
1177 !
1178 ! gridvelocitiesfinelevel computes the grid velocities for
1179 ! the cell centers and the normal grid velocities for the faces
1180 ! of moving blocks for the currently finest grid, i.e.
1181 ! groundlevel. the velocities are computed at time t for
1182 ! spectral mode sps. if useoldcoor is .true. the velocities
1183 ! are determined using the unsteady time integrator in
1184 ! combination with the old coordinates; otherwise the analytic
1185 ! form is used.
1186 !
1187  use blockpointers
1188  use cgnsgrid
1189  use flowvarrefstate
1190  use inputmotion
1191  use inputunsteady
1192  use iteration
1193  use inputphysics
1194  use inputtsstabderiv
1195  use monitor
1196  use communication
1200  implicit none
1201 !
1202 ! subroutine arguments.
1203 !
1204  integer(kind=inttype), intent(in) :: sps, nn
1205  logical, intent(in) :: useoldcoor
1206  real(kind=realtype), dimension(*), intent(in) :: t
1207 !
1208 ! local variables.
1209 !
1210  integer(kind=inttype) :: mm
1211  integer(kind=inttype) :: i, j, k, ii, iie, jje, kke
1212  real(kind=realtype) :: oneover4dt, oneover8dt
1213  real(kind=realtype) :: velxgrid, velygrid, velzgrid, ainf
1214  real(kind=realtype) :: velxgrid0, velygrid0, velzgrid0
1215  real(kind=realtype), dimension(3) :: sc, xc, xxc
1216  real(kind=realtype), dimension(3) :: rotcenter, rotrate
1217  real(kind=realtype), dimension(3) :: rotationpoint
1218  real(kind=realtype), dimension(3, 3) :: rotationmatrix, &
1219 & derivrotationmatrix
1220  real(kind=realtype) :: tnew, told
1221  real(kind=realtype), dimension(:, :), pointer :: sface
1222  real(kind=realtype), dimension(:, :, :), pointer :: xx, ss
1223  real(kind=realtype), dimension(:, :, :, :), pointer :: xxold
1224  real(kind=realtype) :: intervalmach, alphats, alphaincrement, betats&
1225 & , betaincrement
1226  real(kind=realtype), dimension(3) :: veldir
1227  real(kind=realtype), dimension(3) :: refdirection
1228  intrinsic sqrt
1229  real(kind=realtype) :: arg1
1230 ! compute the mesh velocity from the given mesh mach number.
1231 ! vel{x,y,z}grid0 is the actual velocity you want at the
1232 ! geometry.
1233  arg1 = gammainf*pinf/rhoinf
1234  ainf = sqrt(arg1)
1235  velxgrid0 = ainf*machgrid*(-veldirfreestream(1))
1236  velygrid0 = ainf*machgrid*(-veldirfreestream(2))
1237  velzgrid0 = ainf*machgrid*(-veldirfreestream(3))
1238 ! compute the derivative of the rotation matrix and the rotation
1239 ! point; needed for velocity due to the rigid body rotation of
1240 ! the entire grid. it is assumed that the rigid body motion of
1241 ! the grid is only specified if there is only 1 section present.
1242  call derivativerotmatrixrigid(derivrotationmatrix, rotationpoint, t(&
1243 & 1))
1244 !compute the rotation matrix to update the velocities for the time
1245 !spectral stability derivative case...
1246  if (blockismoving) then
1247 ! determine the situation we are having here.
1248  if (.not.useoldcoor) then
1249 !
1250 ! the velocities must be determined analytically.
1251 !
1252 ! store the rotation center and determine the
1253 ! nondimensional rotation rate of this block. as the
1254 ! reference length is 1 timeref == 1/uref and at the end
1255 ! the nondimensional velocity is computed.
1256  j = nbkglobal
1257  rotcenter = cgnsdoms(j)%rotcenter
1258  rotrate = timeref*cgnsdoms(j)%rotrate
1259  velxgrid = velxgrid0
1260  velygrid = velygrid0
1261  velzgrid = velzgrid0
1262 !
1263 ! grid velocities of the cell centers, including the
1264 ! 1st level halo cells.
1265 !
1266 ! loop over the cells, including the 1st level halo's.
1267  do k=1,ke
1268  do j=1,je
1269  do i=1,ie
1270 ! determine the coordinates of the cell center,
1271 ! which are stored in xc.
1272  xc(1) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
1273 & , k-1, 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
1274 & 1)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 1)+&
1275 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+flowdoms(&
1276 & nn, groundlevel, sps)%x(i-1, j-1, k, 1)+flowdoms(nn, &
1277 & groundlevel, sps)%x(i, j-1, k, 1)+flowdoms(nn, &
1278 & groundlevel, sps)%x(i-1, j, k, 1)+flowdoms(nn, &
1279 & groundlevel, sps)%x(i, j, k, 1))
1280  xc(2) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
1281 & , k-1, 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
1282 & 2)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 2)+&
1283 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+flowdoms(&
1284 & nn, groundlevel, sps)%x(i-1, j-1, k, 2)+flowdoms(nn, &
1285 & groundlevel, sps)%x(i, j-1, k, 2)+flowdoms(nn, &
1286 & groundlevel, sps)%x(i-1, j, k, 2)+flowdoms(nn, &
1287 & groundlevel, sps)%x(i, j, k, 2))
1288  xc(3) = eighth*(flowdoms(nn, groundlevel, sps)%x(i-1, j-1&
1289 & , k-1, 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, k-1, &
1290 & 3)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 3)+&
1291 & flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+flowdoms(&
1292 & nn, groundlevel, sps)%x(i-1, j-1, k, 3)+flowdoms(nn, &
1293 & groundlevel, sps)%x(i, j-1, k, 3)+flowdoms(nn, &
1294 & groundlevel, sps)%x(i-1, j, k, 3)+flowdoms(nn, &
1295 & groundlevel, sps)%x(i, j, k, 3))
1296 ! determine the coordinates relative to the
1297 ! center of rotation.
1298  xxc(1) = xc(1) - rotcenter(1)
1299  xxc(2) = xc(2) - rotcenter(2)
1300  xxc(3) = xc(3) - rotcenter(3)
1301 ! determine the rotation speed of the cell center,
1302 ! which is omega*r.
1303  sc(1) = rotrate(2)*xxc(3) - rotrate(3)*xxc(2)
1304  sc(2) = rotrate(3)*xxc(1) - rotrate(1)*xxc(3)
1305  sc(3) = rotrate(1)*xxc(2) - rotrate(2)*xxc(1)
1306 ! determine the coordinates relative to the
1307 ! rigid body rotation point.
1308  xxc(1) = xc(1) - rotationpoint(1)
1309  xxc(2) = xc(2) - rotationpoint(2)
1310  xxc(3) = xc(3) - rotationpoint(3)
1311 ! determine the total velocity of the cell center.
1312 ! this is a combination of rotation speed of this
1313 ! block and the entire rigid body rotation.
1314  s(i, j, k, 1) = sc(1) + velxgrid + derivrotationmatrix(1, &
1315 & 1)*xxc(1) + derivrotationmatrix(1, 2)*xxc(2) + &
1316 & derivrotationmatrix(1, 3)*xxc(3)
1317  s(i, j, k, 2) = sc(2) + velygrid + derivrotationmatrix(2, &
1318 & 1)*xxc(1) + derivrotationmatrix(2, 2)*xxc(2) + &
1319 & derivrotationmatrix(2, 3)*xxc(3)
1320  s(i, j, k, 3) = sc(3) + velzgrid + derivrotationmatrix(3, &
1321 & 1)*xxc(1) + derivrotationmatrix(3, 2)*xxc(2) + &
1322 & derivrotationmatrix(3, 3)*xxc(3)
1323  end do
1324  end do
1325  end do
1326 !
1327 ! normal grid velocities of the faces.
1328 !
1329 ! loop over the three directions.
1330 ! the original code is elegant but the tapenade has a difficult time
1331 ! to understand it. thus, we unfold it and make it easier for the
1332 ! tapenade.
1333 ! i-direction
1334  do k=1,ke
1335  do j=1,je
1336  do i=0,ie
1337 ! determine the coordinates of the face center,
1338 ! which are stored in xc.
1339  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1340 & -1, 1)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+&
1341 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 1)+flowdoms(&
1342 & nn, groundlevel, sps)%x(i, j, k, 1))
1343  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1344 & -1, 2)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+&
1345 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 2)+flowdoms(&
1346 & nn, groundlevel, sps)%x(i, j, k, 2))
1347  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1348 & -1, 3)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+&
1349 & flowdoms(nn, groundlevel, sps)%x(i, j-1, k, 3)+flowdoms(&
1350 & nn, groundlevel, sps)%x(i, j, k, 3))
1351  call cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
1352 & velygrid, velzgrid, derivrotationmatrix&
1353 & , sc)
1354 ! store the dot product of grid velocity sc and
1355 ! the normal ss in sface.
1356  sfacei(i, j, k) = sc(1)*si(i, j, k, 1) + sc(2)*si(i, j, k&
1357 & , 2) + sc(3)*si(i, j, k, 3)
1358  end do
1359  end do
1360  end do
1361 ! j-direction
1362  do k=1,ke
1363  do j=0,je
1364  do i=1,ie
1365 ! determine the coordinates of the face center,
1366 ! which are stored in xc.
1367  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
1368 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 1)+&
1369 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 1)+&
1370 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 1))
1371  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
1372 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 2)+&
1373 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 2)+&
1374 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 2))
1375  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i-1, j, k&
1376 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, j, k-1, 3)+&
1377 & flowdoms(nn, groundlevel, sps)%x(i-1, j, k-1, 3)+&
1378 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 3))
1379  call cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
1380 & velygrid, velzgrid, derivrotationmatrix&
1381 & , sc)
1382 ! store the dot product of grid velocity sc and
1383 ! the normal ss in sface.
1384  sfacej(i, j, k) = sc(1)*sj(i, j, k, 1) + sc(2)*sj(i, j, k&
1385 & , 2) + sc(3)*sj(i, j, k, 3)
1386  end do
1387  end do
1388  end do
1389 ! k-direction
1390  do k=0,ke
1391  do j=1,je
1392  do i=1,ie
1393 ! determine the coordinates of the face center,
1394 ! which are stored in xc.
1395  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1396 & , 1)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 1)+&
1397 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 1)+&
1398 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 1))
1399  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1400 & , 2)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 2)+&
1401 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 2)+&
1402 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 2))
1403  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j-1, k&
1404 & , 3)+flowdoms(nn, groundlevel, sps)%x(i-1, j, k, 3)+&
1405 & flowdoms(nn, groundlevel, sps)%x(i-1, j-1, k, 3)+&
1406 & flowdoms(nn, groundlevel, sps)%x(i, j, k, 3))
1407  call cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
1408 & velygrid, velzgrid, derivrotationmatrix&
1409 & , sc)
1410 ! store the dot product of grid velocity sc and
1411 ! the normal ss in sface.
1412  sfacek(i, j, k) = sc(1)*sk(i, j, k, 1) + sc(2)*sk(i, j, k&
1413 & , 2) + sc(3)*sk(i, j, k, 3)
1414  end do
1415  end do
1416  end do
1417  end if
1418  end if
1419  end subroutine gridvelocitiesfinelevel_block
1420 
1421 ! differentiation of cellfacevelocities in forward (tangent) mode (with options i4 dr8 r8):
1422 ! variations of useful results: sc
1423 ! with respect to varying inputs: rotrate velygrid xc velzgrid
1424 ! derivrotationmatrix sc rotcenter velxgrid
1425 ! rw status of diff variables: rotrate:in velygrid:in xc:in velzgrid:in
1426 ! derivrotationmatrix:in sc:in-out rotcenter:in
1427 ! velxgrid:in
1428  subroutine cellfacevelocities_d(xc, xcd, rotcenter, rotcenterd, &
1429 & rotrate, rotrated, velxgrid, velxgridd, velygrid, velygridd, &
1430 & velzgrid, velzgridd, derivrotationmatrix, derivrotationmatrixd, sc, &
1431 & scd)
1432 !
1433 ! returns the cell face velocities for a given face center
1434 !
1435  use constants
1436  implicit none
1437 !
1438 ! subroutine arguments.
1439 !
1440  real(kind=realtype), dimension(3), intent(in) :: xc, rotcenter, &
1441 & rotrate
1442  real(kind=realtype), dimension(3), intent(in) :: xcd, rotcenterd, &
1443 & rotrated
1444  real(kind=realtype), intent(in) :: velxgrid, velygrid, velzgrid
1445  real(kind=realtype), intent(in) :: velxgridd, velygridd, velzgridd
1446  real(kind=realtype), dimension(3, 3), intent(in) :: &
1447 & derivrotationmatrix
1448  real(kind=realtype), dimension(3, 3), intent(in) :: &
1449 & derivrotationmatrixd
1450  real(kind=realtype), dimension(3), intent(out) :: sc
1451  real(kind=realtype), dimension(3), intent(out) :: scd
1452 !
1453 ! local variables.
1454 !
1455  real(kind=realtype), dimension(3) :: rotationpoint, xxc
1456  real(kind=realtype), dimension(3) :: xxcd
1457 ! determine the coordinates relative to the
1458 ! center of rotation.
1459  xxcd = 0.0_8
1460  xxcd(1) = xcd(1) - rotcenterd(1)
1461  xxc(1) = xc(1) - rotcenter(1)
1462  xxcd(2) = xcd(2) - rotcenterd(2)
1463  xxc(2) = xc(2) - rotcenter(2)
1464  xxcd(3) = xcd(3) - rotcenterd(3)
1465  xxc(3) = xc(3) - rotcenter(3)
1466 ! determine the rotation speed of the face center,
1467 ! which is omega*r.
1468  scd(1) = xxc(3)*rotrated(2) + rotrate(2)*xxcd(3) - xxc(2)*rotrated(3&
1469 & ) - rotrate(3)*xxcd(2)
1470  sc(1) = rotrate(2)*xxc(3) - rotrate(3)*xxc(2)
1471  scd(2) = xxc(1)*rotrated(3) + rotrate(3)*xxcd(1) - xxc(3)*rotrated(1&
1472 & ) - rotrate(1)*xxcd(3)
1473  sc(2) = rotrate(3)*xxc(1) - rotrate(1)*xxc(3)
1474  scd(3) = xxc(2)*rotrated(1) + rotrate(1)*xxcd(2) - xxc(1)*rotrated(2&
1475 & ) - rotrate(2)*xxcd(1)
1476  sc(3) = rotrate(1)*xxc(2) - rotrate(2)*xxc(1)
1477 ! determine the coordinates relative to the
1478 ! rigid body rotation point.
1479  xxcd(1) = xcd(1)
1480  xxc(1) = xc(1) - rotationpoint(1)
1481  xxcd(2) = xcd(2)
1482  xxc(2) = xc(2) - rotationpoint(2)
1483  xxcd(3) = xcd(3)
1484  xxc(3) = xc(3) - rotationpoint(3)
1485 ! determine the total velocity of the cell face.
1486 ! this is a combination of rotation speed of this
1487 ! block and the entire rigid body rotation.
1488  scd(1) = scd(1) + velxgridd + xxc(1)*derivrotationmatrixd(1, 1) + &
1489 & derivrotationmatrix(1, 1)*xxcd(1) + xxc(2)*derivrotationmatrixd(1&
1490 & , 2) + derivrotationmatrix(1, 2)*xxcd(2) + xxc(3)*&
1491 & derivrotationmatrixd(1, 3) + derivrotationmatrix(1, 3)*xxcd(3)
1492  sc(1) = sc(1) + velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
1493 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1, 3)*xxc(3&
1494 & )
1495  scd(2) = scd(2) + velygridd + xxc(1)*derivrotationmatrixd(2, 1) + &
1496 & derivrotationmatrix(2, 1)*xxcd(1) + xxc(2)*derivrotationmatrixd(2&
1497 & , 2) + derivrotationmatrix(2, 2)*xxcd(2) + xxc(3)*&
1498 & derivrotationmatrixd(2, 3) + derivrotationmatrix(2, 3)*xxcd(3)
1499  sc(2) = sc(2) + velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
1500 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2, 3)*xxc(3&
1501 & )
1502  scd(3) = scd(3) + velzgridd + xxc(1)*derivrotationmatrixd(3, 1) + &
1503 & derivrotationmatrix(3, 1)*xxcd(1) + xxc(2)*derivrotationmatrixd(3&
1504 & , 2) + derivrotationmatrix(3, 2)*xxcd(2) + xxc(3)*&
1505 & derivrotationmatrixd(3, 3) + derivrotationmatrix(3, 3)*xxcd(3)
1506  sc(3) = sc(3) + velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
1507 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3, 3)*xxc(3&
1508 & )
1509  end subroutine cellfacevelocities_d
1510 
1511  subroutine cellfacevelocities(xc, rotcenter, rotrate, velxgrid, &
1512 & velygrid, velzgrid, derivrotationmatrix, sc)
1513 !
1514 ! returns the cell face velocities for a given face center
1515 !
1516  use constants
1517  implicit none
1518 !
1519 ! subroutine arguments.
1520 !
1521  real(kind=realtype), dimension(3), intent(in) :: xc, rotcenter, &
1522 & rotrate
1523  real(kind=realtype), intent(in) :: velxgrid, velygrid, velzgrid
1524  real(kind=realtype), dimension(3, 3), intent(in) :: &
1525 & derivrotationmatrix
1526  real(kind=realtype), dimension(3), intent(out) :: sc
1527 !
1528 ! local variables.
1529 !
1530  real(kind=realtype), dimension(3) :: rotationpoint, xxc
1531 ! determine the coordinates relative to the
1532 ! center of rotation.
1533  xxc(1) = xc(1) - rotcenter(1)
1534  xxc(2) = xc(2) - rotcenter(2)
1535  xxc(3) = xc(3) - rotcenter(3)
1536 ! determine the rotation speed of the face center,
1537 ! which is omega*r.
1538  sc(1) = rotrate(2)*xxc(3) - rotrate(3)*xxc(2)
1539  sc(2) = rotrate(3)*xxc(1) - rotrate(1)*xxc(3)
1540  sc(3) = rotrate(1)*xxc(2) - rotrate(2)*xxc(1)
1541 ! determine the coordinates relative to the
1542 ! rigid body rotation point.
1543  xxc(1) = xc(1) - rotationpoint(1)
1544  xxc(2) = xc(2) - rotationpoint(2)
1545  xxc(3) = xc(3) - rotationpoint(3)
1546 ! determine the total velocity of the cell face.
1547 ! this is a combination of rotation speed of this
1548 ! block and the entire rigid body rotation.
1549  sc(1) = sc(1) + velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
1550 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1, 3)*xxc(3&
1551 & )
1552  sc(2) = sc(2) + velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
1553 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2, 3)*xxc(3&
1554 & )
1555  sc(3) = sc(3) + velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
1556 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3, 3)*xxc(3&
1557 & )
1558  end subroutine cellfacevelocities
1559 
1560 ! differentiation of slipvelocitiesfinelevel_block in forward (tangent) mode (with options i4 dr8 r8):
1561 ! variations of useful results: *(*bcdata.uslip)
1562 ! with respect to varying inputs: pinf timeref rhoinf *(flowdoms.x)
1563 ! veldirfreestream machgrid *(*bcdata.uslip)
1564 ! rw status of diff variables: pinf:in timeref:in rhoinf:in *(flowdoms.x):in
1565 ! veldirfreestream:in machgrid:in *(*bcdata.uslip):in-out
1566 ! plus diff mem management of: flowdoms.x:in bcdata:in *bcdata.uslip:in
1567  subroutine slipvelocitiesfinelevel_block_d(useoldcoor, t, sps, nn)
1568 !
1569 ! slipvelocitiesfinelevel computes the slip velocities for
1570 ! viscous subfaces on all viscous boundaries on groundlevel for
1571 ! the given spectral solution. if useoldcoor is .true. the
1572 ! velocities are determined using the unsteady time integrator;
1573 ! otherwise the analytic form is used.
1574 !
1575  use constants
1576  use inputtimespectral
1577  use blockpointers
1578  use cgnsgrid
1579  use flowvarrefstate
1580  use inputmotion
1581  use inputunsteady
1582  use iteration
1583  use inputphysics
1584  use inputtsstabderiv
1585  use monitor
1586  use communication
1587  use flowutils_d, only : derivativerotmatrixrigid, &
1589  use utils_d, only : tsalpha, tsbeta, tsmach, terminate, &
1591  implicit none
1592 !
1593 ! subroutine arguments.
1594 !
1595  integer(kind=inttype), intent(in) :: sps, nn
1596  logical, intent(in) :: useoldcoor
1597  real(kind=realtype), dimension(*), intent(in) :: t
1598 !
1599 ! local variables.
1600 !
1601  integer(kind=inttype) :: mm, i, j, level, ii
1602  real(kind=realtype) :: oneover4dt
1603  real(kind=realtype) :: velxgrid, velygrid, velzgrid, ainf
1604  real(kind=realtype) :: velxgridd, velygridd, velzgridd, ainfd
1605  real(kind=realtype) :: velxgrid0, velygrid0, velzgrid0
1606  real(kind=realtype) :: velxgrid0d, velygrid0d, velzgrid0d
1607  real(kind=realtype), dimension(3) :: xc, xxc
1608  real(kind=realtype), dimension(3) :: xcd, xxcd
1609  real(kind=realtype), dimension(3) :: rotcenter, rotrate
1610  real(kind=realtype), dimension(3) :: rotrated
1611  real(kind=realtype), dimension(3) :: rotationpoint
1612  real(kind=realtype), dimension(3, 3) :: rotationmatrix, &
1613 & derivrotationmatrix
1614  real(kind=realtype), dimension(3, 3) :: derivrotationmatrixd
1615  real(kind=realtype) :: tnew, told
1616  real(kind=realtype), dimension(:, :, :), pointer :: uslip
1617  real(kind=realtype), dimension(:, :, :), pointer :: xface
1618  real(kind=realtype), dimension(:, :, :, :), pointer :: xfaceold
1619  real(kind=realtype) :: intervalmach, alphats, alphaincrement, betats&
1620 & , betaincrement
1621  real(kind=realtype), dimension(3) :: veldir
1622  real(kind=realtype), dimension(3) :: refdirection
1623  intrinsic sqrt
1624  real(kind=realtype) :: arg1
1625  real(kind=realtype) :: arg1d
1626  real(kind=realtype) :: temp
1627 ! determine the situation we are having here.
1628  if (.not.useoldcoor) then
1629 ! the velocities must be determined analytically.
1630 ! compute the mesh velocity from the given mesh mach number.
1631 ! ainf = sqrt(gammainf*pinf/rhoinf)
1632 ! velxgrid = ainf*machgrid(1)
1633 ! velygrid = ainf*machgrid(2)
1634 ! velzgrid = ainf*machgrid(3)
1636  arg1 = gammainf*pinf/rhoinf
1637  temp = sqrt(arg1)
1638  if (arg1 .eq. 0.0_8) then
1639  ainfd = 0.0_8
1640  else
1641  ainfd = arg1d/(2.0*temp)
1642  end if
1643  ainf = temp
1644  velxgrid0d = -(veldirfreestream(1)*(machgrid*ainfd+ainf*machgridd)&
1645 & +ainf*machgrid*veldirfreestreamd(1))
1646  velxgrid0 = ainf*machgrid*(-veldirfreestream(1))
1647  velygrid0d = -(veldirfreestream(2)*(machgrid*ainfd+ainf*machgridd)&
1648 & +ainf*machgrid*veldirfreestreamd(2))
1649  velygrid0 = ainf*machgrid*(-veldirfreestream(2))
1650  velzgrid0d = -(veldirfreestream(3)*(machgrid*ainfd+ainf*machgridd)&
1651 & +ainf*machgrid*veldirfreestreamd(3))
1652  velzgrid0 = ainf*machgrid*(-veldirfreestream(3))
1653 ! compute the derivative of the rotation matrix and the rotation
1654 ! point; needed for velocity due to the rigid body rotation of
1655 ! the entire grid. it is assumed that the rigid body motion of
1656 ! the grid is only specified if there is only 1 section present.
1657  derivrotationmatrixd = 0.0_8
1658  call derivativerotmatrixrigid_d(derivrotationmatrix, &
1659 & derivrotationmatrixd, rotationpoint, t(1&
1660 & ))
1661  xcd = 0.0_8
1662  xxcd = 0.0_8
1663 !compute the rotation matrix to update the velocities for the time
1664 !spectral stability derivative case...
1665 ! loop over the number of viscous subfaces.
1666 bocoloop2:do mm=1,nviscbocos
1667 ! store the rotation center and the rotation rate
1668 ! for this subface.
1669  ii = cgnssubface(mm)
1670  rotcenter = cgnsdoms(nbkglobal)%bocoinfo(ii)%rotcenter
1671  rotrated = cgnsdoms(nbkglobal)%bocoinfo(ii)%rotrate*timerefd
1672  rotrate = timeref*cgnsdoms(nbkglobal)%bocoinfo(ii)%rotrate
1673 ! usewindaxis should go back here!
1674  velxgridd = velxgrid0d
1675  velxgrid = velxgrid0
1676  velygridd = velygrid0d
1677  velygrid = velygrid0
1678  velzgridd = velzgrid0d
1679  velzgrid = velzgrid0
1680 ! loop over the quadrilateral faces of the viscous
1681 ! subface.
1682 ! the new procedure is less elegant as the previous one.
1683 ! but the new stands up to tapenade.
1684  if (bcfaceid(mm) .eq. imin) then
1685  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1686  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1687 ! compute the coordinates of the centroid of the face.
1688 ! normally this would be an average of i-1 and i, but
1689 ! due to the usage of the pointer xface and the fact
1690 ! that x starts at index 0 this is shifted 1 index.
1691  xcd(1) = fourth*(flowdomsd(nn, groundlevel, sps)%x(1, i, j&
1692 & , 1)+flowdomsd(nn, groundlevel, sps)%x(1, i, j-1, 1)+&
1693 & flowdomsd(nn, groundlevel, sps)%x(1, i-1, j, 1)+&
1694 & flowdomsd(nn, groundlevel, sps)%x(1, i-1, j-1, 1))
1695  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
1696 & 1)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 1)+&
1697 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 1)+flowdoms(&
1698 & nn, groundlevel, sps)%x(1, i-1, j-1, 1))
1699  xcd(2) = fourth*(flowdomsd(nn, groundlevel, sps)%x(1, i, j&
1700 & , 2)+flowdomsd(nn, groundlevel, sps)%x(1, i, j-1, 2)+&
1701 & flowdomsd(nn, groundlevel, sps)%x(1, i-1, j, 2)+&
1702 & flowdomsd(nn, groundlevel, sps)%x(1, i-1, j-1, 2))
1703  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
1704 & 2)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 2)+&
1705 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 2)+flowdoms(&
1706 & nn, groundlevel, sps)%x(1, i-1, j-1, 2))
1707  xcd(3) = fourth*(flowdomsd(nn, groundlevel, sps)%x(1, i, j&
1708 & , 3)+flowdomsd(nn, groundlevel, sps)%x(1, i, j-1, 3)+&
1709 & flowdomsd(nn, groundlevel, sps)%x(1, i-1, j, 3)+&
1710 & flowdomsd(nn, groundlevel, sps)%x(1, i-1, j-1, 3))
1711  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
1712 & 3)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 3)+&
1713 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 3)+flowdoms(&
1714 & nn, groundlevel, sps)%x(1, i-1, j-1, 3))
1715 ! determine the coordinates relative to the center
1716 ! of rotation.
1717  xxcd(1) = xcd(1)
1718  xxc(1) = xc(1) - rotcenter(1)
1719  xxcd(2) = xcd(2)
1720  xxc(2) = xc(2) - rotcenter(2)
1721  xxcd(3) = xcd(3)
1722  xxc(3) = xc(3) - rotcenter(3)
1723 ! compute the velocity, which is the cross product
1724 ! of rotrate and xc.
1725  bcdatad(mm)%uslip(i, j, 1) = xxc(3)*rotrated(2) + rotrate(&
1726 & 2)*xxcd(3) - xxc(2)*rotrated(3) - rotrate(3)*xxcd(2)
1727  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
1728 & *xxc(2)
1729  bcdatad(mm)%uslip(i, j, 2) = xxc(1)*rotrated(3) + rotrate(&
1730 & 3)*xxcd(1) - xxc(3)*rotrated(1) - rotrate(1)*xxcd(3)
1731  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
1732 & *xxc(3)
1733  bcdatad(mm)%uslip(i, j, 3) = xxc(2)*rotrated(1) + rotrate(&
1734 & 1)*xxcd(2) - xxc(1)*rotrated(2) - rotrate(2)*xxcd(1)
1735  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
1736 & *xxc(1)
1737 ! determine the coordinates relative to the
1738 ! rigid body rotation point.
1739  xxcd(1) = xcd(1)
1740  xxc(1) = xc(1) - rotationpoint(1)
1741  xxcd(2) = xcd(2)
1742  xxc(2) = xc(2) - rotationpoint(2)
1743  xxcd(3) = xcd(3)
1744  xxc(3) = xc(3) - rotationpoint(3)
1745 ! determine the total velocity of the cell center.
1746 ! this is a combination of rotation speed of this
1747 ! block and the entire rigid body rotation.
1748  bcdatad(mm)%uslip(i, j, 1) = bcdatad(mm)%uslip(i, j, 1) + &
1749 & velxgridd + xxc(1)*derivrotationmatrixd(1, 1) + &
1750 & derivrotationmatrix(1, 1)*xxcd(1) + xxc(2)*&
1751 & derivrotationmatrixd(1, 2) + derivrotationmatrix(1, 2)*&
1752 & xxcd(2) + xxc(3)*derivrotationmatrixd(1, 3) + &
1753 & derivrotationmatrix(1, 3)*xxcd(3)
1754  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
1755 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
1756 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
1757 & , 3)*xxc(3)
1758  bcdatad(mm)%uslip(i, j, 2) = bcdatad(mm)%uslip(i, j, 2) + &
1759 & velygridd + xxc(1)*derivrotationmatrixd(2, 1) + &
1760 & derivrotationmatrix(2, 1)*xxcd(1) + xxc(2)*&
1761 & derivrotationmatrixd(2, 2) + derivrotationmatrix(2, 2)*&
1762 & xxcd(2) + xxc(3)*derivrotationmatrixd(2, 3) + &
1763 & derivrotationmatrix(2, 3)*xxcd(3)
1764  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
1765 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
1766 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
1767 & , 3)*xxc(3)
1768  bcdatad(mm)%uslip(i, j, 3) = bcdatad(mm)%uslip(i, j, 3) + &
1769 & velzgridd + xxc(1)*derivrotationmatrixd(3, 1) + &
1770 & derivrotationmatrix(3, 1)*xxcd(1) + xxc(2)*&
1771 & derivrotationmatrixd(3, 2) + derivrotationmatrix(3, 2)*&
1772 & xxcd(2) + xxc(3)*derivrotationmatrixd(3, 3) + &
1773 & derivrotationmatrix(3, 3)*xxcd(3)
1774  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
1775 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
1776 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
1777 & , 3)*xxc(3)
1778  end do
1779  end do
1780  else if (bcfaceid(mm) .eq. imax) then
1781  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1782  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1783 ! compute the coordinates of the centroid of the face.
1784 ! normally this would be an average of i-1 and i, but
1785 ! due to the usage of the pointer xface and the fact
1786 ! that x starts at index 0 this is shifted 1 index.
1787  xcd(1) = fourth*(flowdomsd(nn, groundlevel, sps)%x(il, i, &
1788 & j, 1)+flowdomsd(nn, groundlevel, sps)%x(il, i, j-1, 1)+&
1789 & flowdomsd(nn, groundlevel, sps)%x(il, i-1, j, 1)+&
1790 & flowdomsd(nn, groundlevel, sps)%x(il, i-1, j-1, 1))
1791  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
1792 & , 1)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 1)+&
1793 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 1)+flowdoms&
1794 & (nn, groundlevel, sps)%x(il, i-1, j-1, 1))
1795  xcd(2) = fourth*(flowdomsd(nn, groundlevel, sps)%x(il, i, &
1796 & j, 2)+flowdomsd(nn, groundlevel, sps)%x(il, i, j-1, 2)+&
1797 & flowdomsd(nn, groundlevel, sps)%x(il, i-1, j, 2)+&
1798 & flowdomsd(nn, groundlevel, sps)%x(il, i-1, j-1, 2))
1799  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
1800 & , 2)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 2)+&
1801 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 2)+flowdoms&
1802 & (nn, groundlevel, sps)%x(il, i-1, j-1, 2))
1803  xcd(3) = fourth*(flowdomsd(nn, groundlevel, sps)%x(il, i, &
1804 & j, 3)+flowdomsd(nn, groundlevel, sps)%x(il, i, j-1, 3)+&
1805 & flowdomsd(nn, groundlevel, sps)%x(il, i-1, j, 3)+&
1806 & flowdomsd(nn, groundlevel, sps)%x(il, i-1, j-1, 3))
1807  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
1808 & , 3)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 3)+&
1809 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 3)+flowdoms&
1810 & (nn, groundlevel, sps)%x(il, i-1, j-1, 3))
1811 ! determine the coordinates relative to the center
1812 ! of rotation.
1813  xxcd(1) = xcd(1)
1814  xxc(1) = xc(1) - rotcenter(1)
1815  xxcd(2) = xcd(2)
1816  xxc(2) = xc(2) - rotcenter(2)
1817  xxcd(3) = xcd(3)
1818  xxc(3) = xc(3) - rotcenter(3)
1819 ! compute the velocity, which is the cross product
1820 ! of rotrate and xc.
1821  bcdatad(mm)%uslip(i, j, 1) = xxc(3)*rotrated(2) + rotrate(&
1822 & 2)*xxcd(3) - xxc(2)*rotrated(3) - rotrate(3)*xxcd(2)
1823  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
1824 & *xxc(2)
1825  bcdatad(mm)%uslip(i, j, 2) = xxc(1)*rotrated(3) + rotrate(&
1826 & 3)*xxcd(1) - xxc(3)*rotrated(1) - rotrate(1)*xxcd(3)
1827  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
1828 & *xxc(3)
1829  bcdatad(mm)%uslip(i, j, 3) = xxc(2)*rotrated(1) + rotrate(&
1830 & 1)*xxcd(2) - xxc(1)*rotrated(2) - rotrate(2)*xxcd(1)
1831  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
1832 & *xxc(1)
1833 ! determine the coordinates relative to the
1834 ! rigid body rotation point.
1835  xxcd(1) = xcd(1)
1836  xxc(1) = xc(1) - rotationpoint(1)
1837  xxcd(2) = xcd(2)
1838  xxc(2) = xc(2) - rotationpoint(2)
1839  xxcd(3) = xcd(3)
1840  xxc(3) = xc(3) - rotationpoint(3)
1841 ! determine the total velocity of the cell center.
1842 ! this is a combination of rotation speed of this
1843 ! block and the entire rigid body rotation.
1844  bcdatad(mm)%uslip(i, j, 1) = bcdatad(mm)%uslip(i, j, 1) + &
1845 & velxgridd + xxc(1)*derivrotationmatrixd(1, 1) + &
1846 & derivrotationmatrix(1, 1)*xxcd(1) + xxc(2)*&
1847 & derivrotationmatrixd(1, 2) + derivrotationmatrix(1, 2)*&
1848 & xxcd(2) + xxc(3)*derivrotationmatrixd(1, 3) + &
1849 & derivrotationmatrix(1, 3)*xxcd(3)
1850  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
1851 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
1852 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
1853 & , 3)*xxc(3)
1854  bcdatad(mm)%uslip(i, j, 2) = bcdatad(mm)%uslip(i, j, 2) + &
1855 & velygridd + xxc(1)*derivrotationmatrixd(2, 1) + &
1856 & derivrotationmatrix(2, 1)*xxcd(1) + xxc(2)*&
1857 & derivrotationmatrixd(2, 2) + derivrotationmatrix(2, 2)*&
1858 & xxcd(2) + xxc(3)*derivrotationmatrixd(2, 3) + &
1859 & derivrotationmatrix(2, 3)*xxcd(3)
1860  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
1861 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
1862 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
1863 & , 3)*xxc(3)
1864  bcdatad(mm)%uslip(i, j, 3) = bcdatad(mm)%uslip(i, j, 3) + &
1865 & velzgridd + xxc(1)*derivrotationmatrixd(3, 1) + &
1866 & derivrotationmatrix(3, 1)*xxcd(1) + xxc(2)*&
1867 & derivrotationmatrixd(3, 2) + derivrotationmatrix(3, 2)*&
1868 & xxcd(2) + xxc(3)*derivrotationmatrixd(3, 3) + &
1869 & derivrotationmatrix(3, 3)*xxcd(3)
1870  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
1871 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
1872 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
1873 & , 3)*xxc(3)
1874  end do
1875  end do
1876  else if (bcfaceid(mm) .eq. jmin) then
1877  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1878  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1879 ! compute the coordinates of the centroid of the face.
1880 ! normally this would be an average of i-1 and i, but
1881 ! due to the usage of the pointer xface and the fact
1882 ! that x starts at index 0 this is shifted 1 index.
1883  xcd(1) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, 1, j&
1884 & , 1)+flowdomsd(nn, groundlevel, sps)%x(i, 1, j-1, 1)+&
1885 & flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j, 1)+&
1886 & flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j-1, 1))
1887  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
1888 & 1)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 1)+&
1889 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 1)+flowdoms(&
1890 & nn, groundlevel, sps)%x(i-1, 1, j-1, 1))
1891  xcd(2) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, 1, j&
1892 & , 2)+flowdomsd(nn, groundlevel, sps)%x(i, 1, j-1, 2)+&
1893 & flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j, 2)+&
1894 & flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j-1, 2))
1895  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
1896 & 2)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 2)+&
1897 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 2)+flowdoms(&
1898 & nn, groundlevel, sps)%x(i-1, 1, j-1, 2))
1899  xcd(3) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, 1, j&
1900 & , 3)+flowdomsd(nn, groundlevel, sps)%x(i, 1, j-1, 3)+&
1901 & flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j, 3)+&
1902 & flowdomsd(nn, groundlevel, sps)%x(i-1, 1, j-1, 3))
1903  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
1904 & 3)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 3)+&
1905 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 3)+flowdoms(&
1906 & nn, groundlevel, sps)%x(i-1, 1, j-1, 3))
1907 ! determine the coordinates relative to the center
1908 ! of rotation.
1909  xxcd(1) = xcd(1)
1910  xxc(1) = xc(1) - rotcenter(1)
1911  xxcd(2) = xcd(2)
1912  xxc(2) = xc(2) - rotcenter(2)
1913  xxcd(3) = xcd(3)
1914  xxc(3) = xc(3) - rotcenter(3)
1915 ! compute the velocity, which is the cross product
1916 ! of rotrate and xc.
1917  bcdatad(mm)%uslip(i, j, 1) = xxc(3)*rotrated(2) + rotrate(&
1918 & 2)*xxcd(3) - xxc(2)*rotrated(3) - rotrate(3)*xxcd(2)
1919  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
1920 & *xxc(2)
1921  bcdatad(mm)%uslip(i, j, 2) = xxc(1)*rotrated(3) + rotrate(&
1922 & 3)*xxcd(1) - xxc(3)*rotrated(1) - rotrate(1)*xxcd(3)
1923  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
1924 & *xxc(3)
1925  bcdatad(mm)%uslip(i, j, 3) = xxc(2)*rotrated(1) + rotrate(&
1926 & 1)*xxcd(2) - xxc(1)*rotrated(2) - rotrate(2)*xxcd(1)
1927  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
1928 & *xxc(1)
1929 ! determine the coordinates relative to the
1930 ! rigid body rotation point.
1931  xxcd(1) = xcd(1)
1932  xxc(1) = xc(1) - rotationpoint(1)
1933  xxcd(2) = xcd(2)
1934  xxc(2) = xc(2) - rotationpoint(2)
1935  xxcd(3) = xcd(3)
1936  xxc(3) = xc(3) - rotationpoint(3)
1937 ! determine the total velocity of the cell center.
1938 ! this is a combination of rotation speed of this
1939 ! block and the entire rigid body rotation.
1940  bcdatad(mm)%uslip(i, j, 1) = bcdatad(mm)%uslip(i, j, 1) + &
1941 & velxgridd + xxc(1)*derivrotationmatrixd(1, 1) + &
1942 & derivrotationmatrix(1, 1)*xxcd(1) + xxc(2)*&
1943 & derivrotationmatrixd(1, 2) + derivrotationmatrix(1, 2)*&
1944 & xxcd(2) + xxc(3)*derivrotationmatrixd(1, 3) + &
1945 & derivrotationmatrix(1, 3)*xxcd(3)
1946  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
1947 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
1948 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
1949 & , 3)*xxc(3)
1950  bcdatad(mm)%uslip(i, j, 2) = bcdatad(mm)%uslip(i, j, 2) + &
1951 & velygridd + xxc(1)*derivrotationmatrixd(2, 1) + &
1952 & derivrotationmatrix(2, 1)*xxcd(1) + xxc(2)*&
1953 & derivrotationmatrixd(2, 2) + derivrotationmatrix(2, 2)*&
1954 & xxcd(2) + xxc(3)*derivrotationmatrixd(2, 3) + &
1955 & derivrotationmatrix(2, 3)*xxcd(3)
1956  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
1957 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
1958 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
1959 & , 3)*xxc(3)
1960  bcdatad(mm)%uslip(i, j, 3) = bcdatad(mm)%uslip(i, j, 3) + &
1961 & velzgridd + xxc(1)*derivrotationmatrixd(3, 1) + &
1962 & derivrotationmatrix(3, 1)*xxcd(1) + xxc(2)*&
1963 & derivrotationmatrixd(3, 2) + derivrotationmatrix(3, 2)*&
1964 & xxcd(2) + xxc(3)*derivrotationmatrixd(3, 3) + &
1965 & derivrotationmatrix(3, 3)*xxcd(3)
1966  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
1967 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
1968 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
1969 & , 3)*xxc(3)
1970  end do
1971  end do
1972  else if (bcfaceid(mm) .eq. jmax) then
1973  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
1974  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
1975 ! compute the coordinates of the centroid of the face.
1976 ! normally this would be an average of i-1 and i, but
1977 ! due to the usage of the pointer xface and the fact
1978 ! that x starts at index 0 this is shifted 1 index.
1979  xcd(1) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, jl, &
1980 & j, 1)+flowdomsd(nn, groundlevel, sps)%x(i, jl, j-1, 1)+&
1981 & flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j, 1)+&
1982 & flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j-1, 1))
1983  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
1984 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 1)+&
1985 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 1)+flowdoms&
1986 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 1))
1987  xcd(2) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, jl, &
1988 & j, 2)+flowdomsd(nn, groundlevel, sps)%x(i, jl, j-1, 2)+&
1989 & flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j, 2)+&
1990 & flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j-1, 2))
1991  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
1992 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 2)+&
1993 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 2)+flowdoms&
1994 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 2))
1995  xcd(3) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, jl, &
1996 & j, 3)+flowdomsd(nn, groundlevel, sps)%x(i, jl, j-1, 3)+&
1997 & flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j, 3)+&
1998 & flowdomsd(nn, groundlevel, sps)%x(i-1, jl, j-1, 3))
1999  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
2000 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 3)+&
2001 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 3)+flowdoms&
2002 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 3))
2003 ! determine the coordinates relative to the center
2004 ! of rotation.
2005  xxcd(1) = xcd(1)
2006  xxc(1) = xc(1) - rotcenter(1)
2007  xxcd(2) = xcd(2)
2008  xxc(2) = xc(2) - rotcenter(2)
2009  xxcd(3) = xcd(3)
2010  xxc(3) = xc(3) - rotcenter(3)
2011 ! compute the velocity, which is the cross product
2012 ! of rotrate and xc.
2013  bcdatad(mm)%uslip(i, j, 1) = xxc(3)*rotrated(2) + rotrate(&
2014 & 2)*xxcd(3) - xxc(2)*rotrated(3) - rotrate(3)*xxcd(2)
2015  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
2016 & *xxc(2)
2017  bcdatad(mm)%uslip(i, j, 2) = xxc(1)*rotrated(3) + rotrate(&
2018 & 3)*xxcd(1) - xxc(3)*rotrated(1) - rotrate(1)*xxcd(3)
2019  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
2020 & *xxc(3)
2021  bcdatad(mm)%uslip(i, j, 3) = xxc(2)*rotrated(1) + rotrate(&
2022 & 1)*xxcd(2) - xxc(1)*rotrated(2) - rotrate(2)*xxcd(1)
2023  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
2024 & *xxc(1)
2025 ! determine the coordinates relative to the
2026 ! rigid body rotation point.
2027  xxcd(1) = xcd(1)
2028  xxc(1) = xc(1) - rotationpoint(1)
2029  xxcd(2) = xcd(2)
2030  xxc(2) = xc(2) - rotationpoint(2)
2031  xxcd(3) = xcd(3)
2032  xxc(3) = xc(3) - rotationpoint(3)
2033 ! determine the total velocity of the cell center.
2034 ! this is a combination of rotation speed of this
2035 ! block and the entire rigid body rotation.
2036  bcdatad(mm)%uslip(i, j, 1) = bcdatad(mm)%uslip(i, j, 1) + &
2037 & velxgridd + xxc(1)*derivrotationmatrixd(1, 1) + &
2038 & derivrotationmatrix(1, 1)*xxcd(1) + xxc(2)*&
2039 & derivrotationmatrixd(1, 2) + derivrotationmatrix(1, 2)*&
2040 & xxcd(2) + xxc(3)*derivrotationmatrixd(1, 3) + &
2041 & derivrotationmatrix(1, 3)*xxcd(3)
2042  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
2043 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
2044 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
2045 & , 3)*xxc(3)
2046  bcdatad(mm)%uslip(i, j, 2) = bcdatad(mm)%uslip(i, j, 2) + &
2047 & velygridd + xxc(1)*derivrotationmatrixd(2, 1) + &
2048 & derivrotationmatrix(2, 1)*xxcd(1) + xxc(2)*&
2049 & derivrotationmatrixd(2, 2) + derivrotationmatrix(2, 2)*&
2050 & xxcd(2) + xxc(3)*derivrotationmatrixd(2, 3) + &
2051 & derivrotationmatrix(2, 3)*xxcd(3)
2052  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
2053 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
2054 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
2055 & , 3)*xxc(3)
2056  bcdatad(mm)%uslip(i, j, 3) = bcdatad(mm)%uslip(i, j, 3) + &
2057 & velzgridd + xxc(1)*derivrotationmatrixd(3, 1) + &
2058 & derivrotationmatrix(3, 1)*xxcd(1) + xxc(2)*&
2059 & derivrotationmatrixd(3, 2) + derivrotationmatrix(3, 2)*&
2060 & xxcd(2) + xxc(3)*derivrotationmatrixd(3, 3) + &
2061 & derivrotationmatrix(3, 3)*xxcd(3)
2062  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
2063 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
2064 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
2065 & , 3)*xxc(3)
2066  end do
2067  end do
2068  else if (bcfaceid(mm) .eq. kmin) then
2069  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2070  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2071 ! compute the coordinates of the centroid of the face.
2072 ! normally this would be an average of i-1 and i, but
2073 ! due to the usage of the pointer xface and the fact
2074 ! that x starts at index 0 this is shifted 1 index.
2075  xcd(1) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, j, 1&
2076 & , 1)+flowdomsd(nn, groundlevel, sps)%x(i, j-1, 1, 1)+&
2077 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, 1, 1)+&
2078 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, 1, 1))
2079  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
2080 & 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 1)+&
2081 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 1)+flowdoms(&
2082 & nn, groundlevel, sps)%x(i-1, j-1, 1, 1))
2083  xcd(2) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, j, 1&
2084 & , 2)+flowdomsd(nn, groundlevel, sps)%x(i, j-1, 1, 2)+&
2085 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, 1, 2)+&
2086 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, 1, 2))
2087  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
2088 & 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 2)+&
2089 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 2)+flowdoms(&
2090 & nn, groundlevel, sps)%x(i-1, j-1, 1, 2))
2091  xcd(3) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, j, 1&
2092 & , 3)+flowdomsd(nn, groundlevel, sps)%x(i, j-1, 1, 3)+&
2093 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, 1, 3)+&
2094 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, 1, 3))
2095  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
2096 & 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 3)+&
2097 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 3)+flowdoms(&
2098 & nn, groundlevel, sps)%x(i-1, j-1, 1, 3))
2099 ! determine the coordinates relative to the center
2100 ! of rotation.
2101  xxcd(1) = xcd(1)
2102  xxc(1) = xc(1) - rotcenter(1)
2103  xxcd(2) = xcd(2)
2104  xxc(2) = xc(2) - rotcenter(2)
2105  xxcd(3) = xcd(3)
2106  xxc(3) = xc(3) - rotcenter(3)
2107 ! compute the velocity, which is the cross product
2108 ! of rotrate and xc.
2109  bcdatad(mm)%uslip(i, j, 1) = xxc(3)*rotrated(2) + rotrate(&
2110 & 2)*xxcd(3) - xxc(2)*rotrated(3) - rotrate(3)*xxcd(2)
2111  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
2112 & *xxc(2)
2113  bcdatad(mm)%uslip(i, j, 2) = xxc(1)*rotrated(3) + rotrate(&
2114 & 3)*xxcd(1) - xxc(3)*rotrated(1) - rotrate(1)*xxcd(3)
2115  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
2116 & *xxc(3)
2117  bcdatad(mm)%uslip(i, j, 3) = xxc(2)*rotrated(1) + rotrate(&
2118 & 1)*xxcd(2) - xxc(1)*rotrated(2) - rotrate(2)*xxcd(1)
2119  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
2120 & *xxc(1)
2121 ! determine the coordinates relative to the
2122 ! rigid body rotation point.
2123  xxcd(1) = xcd(1)
2124  xxc(1) = xc(1) - rotationpoint(1)
2125  xxcd(2) = xcd(2)
2126  xxc(2) = xc(2) - rotationpoint(2)
2127  xxcd(3) = xcd(3)
2128  xxc(3) = xc(3) - rotationpoint(3)
2129 ! determine the total velocity of the cell center.
2130 ! this is a combination of rotation speed of this
2131 ! block and the entire rigid body rotation.
2132  bcdatad(mm)%uslip(i, j, 1) = bcdatad(mm)%uslip(i, j, 1) + &
2133 & velxgridd + xxc(1)*derivrotationmatrixd(1, 1) + &
2134 & derivrotationmatrix(1, 1)*xxcd(1) + xxc(2)*&
2135 & derivrotationmatrixd(1, 2) + derivrotationmatrix(1, 2)*&
2136 & xxcd(2) + xxc(3)*derivrotationmatrixd(1, 3) + &
2137 & derivrotationmatrix(1, 3)*xxcd(3)
2138  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
2139 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
2140 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
2141 & , 3)*xxc(3)
2142  bcdatad(mm)%uslip(i, j, 2) = bcdatad(mm)%uslip(i, j, 2) + &
2143 & velygridd + xxc(1)*derivrotationmatrixd(2, 1) + &
2144 & derivrotationmatrix(2, 1)*xxcd(1) + xxc(2)*&
2145 & derivrotationmatrixd(2, 2) + derivrotationmatrix(2, 2)*&
2146 & xxcd(2) + xxc(3)*derivrotationmatrixd(2, 3) + &
2147 & derivrotationmatrix(2, 3)*xxcd(3)
2148  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
2149 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
2150 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
2151 & , 3)*xxc(3)
2152  bcdatad(mm)%uslip(i, j, 3) = bcdatad(mm)%uslip(i, j, 3) + &
2153 & velzgridd + xxc(1)*derivrotationmatrixd(3, 1) + &
2154 & derivrotationmatrix(3, 1)*xxcd(1) + xxc(2)*&
2155 & derivrotationmatrixd(3, 2) + derivrotationmatrix(3, 2)*&
2156 & xxcd(2) + xxc(3)*derivrotationmatrixd(3, 3) + &
2157 & derivrotationmatrix(3, 3)*xxcd(3)
2158  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
2159 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
2160 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
2161 & , 3)*xxc(3)
2162  end do
2163  end do
2164  else if (bcfaceid(mm) .eq. kmax) then
2165  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2166  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2167 ! compute the coordinates of the centroid of the face.
2168 ! normally this would be an average of i-1 and i, but
2169 ! due to the usage of the pointer xface and the fact
2170 ! that x starts at index 0 this is shifted 1 index.
2171  xcd(1) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, j, &
2172 & kl, 1)+flowdomsd(nn, groundlevel, sps)%x(i, j-1, kl, 1)+&
2173 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, kl, 1)+&
2174 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, kl, 1))
2175  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
2176 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 1)+&
2177 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 1)+flowdoms&
2178 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 1))
2179  xcd(2) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, j, &
2180 & kl, 2)+flowdomsd(nn, groundlevel, sps)%x(i, j-1, kl, 2)+&
2181 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, kl, 2)+&
2182 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, kl, 2))
2183  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
2184 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 2)+&
2185 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 2)+flowdoms&
2186 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 2))
2187  xcd(3) = fourth*(flowdomsd(nn, groundlevel, sps)%x(i, j, &
2188 & kl, 3)+flowdomsd(nn, groundlevel, sps)%x(i, j-1, kl, 3)+&
2189 & flowdomsd(nn, groundlevel, sps)%x(i-1, j, kl, 3)+&
2190 & flowdomsd(nn, groundlevel, sps)%x(i-1, j-1, kl, 3))
2191  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
2192 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 3)+&
2193 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 3)+flowdoms&
2194 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 3))
2195 ! determine the coordinates relative to the center
2196 ! of rotation.
2197  xxcd(1) = xcd(1)
2198  xxc(1) = xc(1) - rotcenter(1)
2199  xxcd(2) = xcd(2)
2200  xxc(2) = xc(2) - rotcenter(2)
2201  xxcd(3) = xcd(3)
2202  xxc(3) = xc(3) - rotcenter(3)
2203 ! compute the velocity, which is the cross product
2204 ! of rotrate and xc.
2205  bcdatad(mm)%uslip(i, j, 1) = xxc(3)*rotrated(2) + rotrate(&
2206 & 2)*xxcd(3) - xxc(2)*rotrated(3) - rotrate(3)*xxcd(2)
2207  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
2208 & *xxc(2)
2209  bcdatad(mm)%uslip(i, j, 2) = xxc(1)*rotrated(3) + rotrate(&
2210 & 3)*xxcd(1) - xxc(3)*rotrated(1) - rotrate(1)*xxcd(3)
2211  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
2212 & *xxc(3)
2213  bcdatad(mm)%uslip(i, j, 3) = xxc(2)*rotrated(1) + rotrate(&
2214 & 1)*xxcd(2) - xxc(1)*rotrated(2) - rotrate(2)*xxcd(1)
2215  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
2216 & *xxc(1)
2217 ! determine the coordinates relative to the
2218 ! rigid body rotation point.
2219  xxcd(1) = xcd(1)
2220  xxc(1) = xc(1) - rotationpoint(1)
2221  xxcd(2) = xcd(2)
2222  xxc(2) = xc(2) - rotationpoint(2)
2223  xxcd(3) = xcd(3)
2224  xxc(3) = xc(3) - rotationpoint(3)
2225 ! determine the total velocity of the cell center.
2226 ! this is a combination of rotation speed of this
2227 ! block and the entire rigid body rotation.
2228  bcdatad(mm)%uslip(i, j, 1) = bcdatad(mm)%uslip(i, j, 1) + &
2229 & velxgridd + xxc(1)*derivrotationmatrixd(1, 1) + &
2230 & derivrotationmatrix(1, 1)*xxcd(1) + xxc(2)*&
2231 & derivrotationmatrixd(1, 2) + derivrotationmatrix(1, 2)*&
2232 & xxcd(2) + xxc(3)*derivrotationmatrixd(1, 3) + &
2233 & derivrotationmatrix(1, 3)*xxcd(3)
2234  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
2235 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
2236 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
2237 & , 3)*xxc(3)
2238  bcdatad(mm)%uslip(i, j, 2) = bcdatad(mm)%uslip(i, j, 2) + &
2239 & velygridd + xxc(1)*derivrotationmatrixd(2, 1) + &
2240 & derivrotationmatrix(2, 1)*xxcd(1) + xxc(2)*&
2241 & derivrotationmatrixd(2, 2) + derivrotationmatrix(2, 2)*&
2242 & xxcd(2) + xxc(3)*derivrotationmatrixd(2, 3) + &
2243 & derivrotationmatrix(2, 3)*xxcd(3)
2244  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
2245 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
2246 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
2247 & , 3)*xxc(3)
2248  bcdatad(mm)%uslip(i, j, 3) = bcdatad(mm)%uslip(i, j, 3) + &
2249 & velzgridd + xxc(1)*derivrotationmatrixd(3, 1) + &
2250 & derivrotationmatrix(3, 1)*xxcd(1) + xxc(2)*&
2251 & derivrotationmatrixd(3, 2) + derivrotationmatrix(3, 2)*&
2252 & xxcd(2) + xxc(3)*derivrotationmatrixd(3, 3) + &
2253 & derivrotationmatrix(3, 3)*xxcd(3)
2254  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
2255 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
2256 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
2257 & , 3)*xxc(3)
2258  end do
2259  end do
2260  end if
2261  end do bocoloop2
2262  end if
2263  end subroutine slipvelocitiesfinelevel_block_d
2264 
2265  subroutine slipvelocitiesfinelevel_block(useoldcoor, t, sps, nn)
2266 !
2267 ! slipvelocitiesfinelevel computes the slip velocities for
2268 ! viscous subfaces on all viscous boundaries on groundlevel for
2269 ! the given spectral solution. if useoldcoor is .true. the
2270 ! velocities are determined using the unsteady time integrator;
2271 ! otherwise the analytic form is used.
2272 !
2273  use constants
2274  use inputtimespectral
2275  use blockpointers
2276  use cgnsgrid
2277  use flowvarrefstate
2278  use inputmotion
2279  use inputunsteady
2280  use iteration
2281  use inputphysics
2282  use inputtsstabderiv
2283  use monitor
2284  use communication
2286  use utils_d, only : tsalpha, tsbeta, tsmach, terminate, &
2288  implicit none
2289 !
2290 ! subroutine arguments.
2291 !
2292  integer(kind=inttype), intent(in) :: sps, nn
2293  logical, intent(in) :: useoldcoor
2294  real(kind=realtype), dimension(*), intent(in) :: t
2295 !
2296 ! local variables.
2297 !
2298  integer(kind=inttype) :: mm, i, j, level, ii
2299  real(kind=realtype) :: oneover4dt
2300  real(kind=realtype) :: velxgrid, velygrid, velzgrid, ainf
2301  real(kind=realtype) :: velxgrid0, velygrid0, velzgrid0
2302  real(kind=realtype), dimension(3) :: xc, xxc
2303  real(kind=realtype), dimension(3) :: rotcenter, rotrate
2304  real(kind=realtype), dimension(3) :: rotationpoint
2305  real(kind=realtype), dimension(3, 3) :: rotationmatrix, &
2306 & derivrotationmatrix
2307  real(kind=realtype) :: tnew, told
2308  real(kind=realtype), dimension(:, :, :), pointer :: uslip
2309  real(kind=realtype), dimension(:, :, :), pointer :: xface
2310  real(kind=realtype), dimension(:, :, :, :), pointer :: xfaceold
2311  real(kind=realtype) :: intervalmach, alphats, alphaincrement, betats&
2312 & , betaincrement
2313  real(kind=realtype), dimension(3) :: veldir
2314  real(kind=realtype), dimension(3) :: refdirection
2315  intrinsic sqrt
2316  real(kind=realtype) :: arg1
2317 ! determine the situation we are having here.
2318  if (.not.useoldcoor) then
2319 ! the velocities must be determined analytically.
2320 ! compute the mesh velocity from the given mesh mach number.
2321 ! ainf = sqrt(gammainf*pinf/rhoinf)
2322 ! velxgrid = ainf*machgrid(1)
2323 ! velygrid = ainf*machgrid(2)
2324 ! velzgrid = ainf*machgrid(3)
2325  arg1 = gammainf*pinf/rhoinf
2326  ainf = sqrt(arg1)
2327  velxgrid0 = ainf*machgrid*(-veldirfreestream(1))
2328  velygrid0 = ainf*machgrid*(-veldirfreestream(2))
2329  velzgrid0 = ainf*machgrid*(-veldirfreestream(3))
2330 ! compute the derivative of the rotation matrix and the rotation
2331 ! point; needed for velocity due to the rigid body rotation of
2332 ! the entire grid. it is assumed that the rigid body motion of
2333 ! the grid is only specified if there is only 1 section present.
2334  call derivativerotmatrixrigid(derivrotationmatrix, rotationpoint, &
2335 & t(1))
2336 !compute the rotation matrix to update the velocities for the time
2337 !spectral stability derivative case...
2338 ! loop over the number of viscous subfaces.
2339 bocoloop2:do mm=1,nviscbocos
2340 ! store the rotation center and the rotation rate
2341 ! for this subface.
2342  ii = cgnssubface(mm)
2343  rotcenter = cgnsdoms(nbkglobal)%bocoinfo(ii)%rotcenter
2344  rotrate = timeref*cgnsdoms(nbkglobal)%bocoinfo(ii)%rotrate
2345 ! usewindaxis should go back here!
2346  velxgrid = velxgrid0
2347  velygrid = velygrid0
2348  velzgrid = velzgrid0
2349 ! loop over the quadrilateral faces of the viscous
2350 ! subface.
2351 ! the new procedure is less elegant as the previous one.
2352 ! but the new stands up to tapenade.
2353  if (bcfaceid(mm) .eq. imin) then
2354  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2355  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2356 ! compute the coordinates of the centroid of the face.
2357 ! normally this would be an average of i-1 and i, but
2358 ! due to the usage of the pointer xface and the fact
2359 ! that x starts at index 0 this is shifted 1 index.
2360  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
2361 & 1)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 1)+&
2362 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 1)+flowdoms(&
2363 & nn, groundlevel, sps)%x(1, i-1, j-1, 1))
2364  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
2365 & 2)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 2)+&
2366 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 2)+flowdoms(&
2367 & nn, groundlevel, sps)%x(1, i-1, j-1, 2))
2368  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(1, i, j, &
2369 & 3)+flowdoms(nn, groundlevel, sps)%x(1, i, j-1, 3)+&
2370 & flowdoms(nn, groundlevel, sps)%x(1, i-1, j, 3)+flowdoms(&
2371 & nn, groundlevel, sps)%x(1, i-1, j-1, 3))
2372 ! determine the coordinates relative to the center
2373 ! of rotation.
2374  xxc(1) = xc(1) - rotcenter(1)
2375  xxc(2) = xc(2) - rotcenter(2)
2376  xxc(3) = xc(3) - rotcenter(3)
2377 ! compute the velocity, which is the cross product
2378 ! of rotrate and xc.
2379  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
2380 & *xxc(2)
2381  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
2382 & *xxc(3)
2383  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
2384 & *xxc(1)
2385 ! determine the coordinates relative to the
2386 ! rigid body rotation point.
2387  xxc(1) = xc(1) - rotationpoint(1)
2388  xxc(2) = xc(2) - rotationpoint(2)
2389  xxc(3) = xc(3) - rotationpoint(3)
2390 ! determine the total velocity of the cell center.
2391 ! this is a combination of rotation speed of this
2392 ! block and the entire rigid body rotation.
2393  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
2394 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
2395 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
2396 & , 3)*xxc(3)
2397  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
2398 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
2399 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
2400 & , 3)*xxc(3)
2401  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
2402 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
2403 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
2404 & , 3)*xxc(3)
2405  end do
2406  end do
2407  else if (bcfaceid(mm) .eq. imax) then
2408  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2409  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2410 ! compute the coordinates of the centroid of the face.
2411 ! normally this would be an average of i-1 and i, but
2412 ! due to the usage of the pointer xface and the fact
2413 ! that x starts at index 0 this is shifted 1 index.
2414  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
2415 & , 1)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 1)+&
2416 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 1)+flowdoms&
2417 & (nn, groundlevel, sps)%x(il, i-1, j-1, 1))
2418  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
2419 & , 2)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 2)+&
2420 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 2)+flowdoms&
2421 & (nn, groundlevel, sps)%x(il, i-1, j-1, 2))
2422  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(il, i, j&
2423 & , 3)+flowdoms(nn, groundlevel, sps)%x(il, i, j-1, 3)+&
2424 & flowdoms(nn, groundlevel, sps)%x(il, i-1, j, 3)+flowdoms&
2425 & (nn, groundlevel, sps)%x(il, i-1, j-1, 3))
2426 ! determine the coordinates relative to the center
2427 ! of rotation.
2428  xxc(1) = xc(1) - rotcenter(1)
2429  xxc(2) = xc(2) - rotcenter(2)
2430  xxc(3) = xc(3) - rotcenter(3)
2431 ! compute the velocity, which is the cross product
2432 ! of rotrate and xc.
2433  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
2434 & *xxc(2)
2435  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
2436 & *xxc(3)
2437  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
2438 & *xxc(1)
2439 ! determine the coordinates relative to the
2440 ! rigid body rotation point.
2441  xxc(1) = xc(1) - rotationpoint(1)
2442  xxc(2) = xc(2) - rotationpoint(2)
2443  xxc(3) = xc(3) - rotationpoint(3)
2444 ! determine the total velocity of the cell center.
2445 ! this is a combination of rotation speed of this
2446 ! block and the entire rigid body rotation.
2447  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
2448 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
2449 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
2450 & , 3)*xxc(3)
2451  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
2452 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
2453 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
2454 & , 3)*xxc(3)
2455  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
2456 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
2457 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
2458 & , 3)*xxc(3)
2459  end do
2460  end do
2461  else if (bcfaceid(mm) .eq. jmin) then
2462  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2463  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2464 ! compute the coordinates of the centroid of the face.
2465 ! normally this would be an average of i-1 and i, but
2466 ! due to the usage of the pointer xface and the fact
2467 ! that x starts at index 0 this is shifted 1 index.
2468  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
2469 & 1)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 1)+&
2470 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 1)+flowdoms(&
2471 & nn, groundlevel, sps)%x(i-1, 1, j-1, 1))
2472  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
2473 & 2)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 2)+&
2474 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 2)+flowdoms(&
2475 & nn, groundlevel, sps)%x(i-1, 1, j-1, 2))
2476  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, 1, j, &
2477 & 3)+flowdoms(nn, groundlevel, sps)%x(i, 1, j-1, 3)+&
2478 & flowdoms(nn, groundlevel, sps)%x(i-1, 1, j, 3)+flowdoms(&
2479 & nn, groundlevel, sps)%x(i-1, 1, j-1, 3))
2480 ! determine the coordinates relative to the center
2481 ! of rotation.
2482  xxc(1) = xc(1) - rotcenter(1)
2483  xxc(2) = xc(2) - rotcenter(2)
2484  xxc(3) = xc(3) - rotcenter(3)
2485 ! compute the velocity, which is the cross product
2486 ! of rotrate and xc.
2487  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
2488 & *xxc(2)
2489  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
2490 & *xxc(3)
2491  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
2492 & *xxc(1)
2493 ! determine the coordinates relative to the
2494 ! rigid body rotation point.
2495  xxc(1) = xc(1) - rotationpoint(1)
2496  xxc(2) = xc(2) - rotationpoint(2)
2497  xxc(3) = xc(3) - rotationpoint(3)
2498 ! determine the total velocity of the cell center.
2499 ! this is a combination of rotation speed of this
2500 ! block and the entire rigid body rotation.
2501  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
2502 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
2503 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
2504 & , 3)*xxc(3)
2505  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
2506 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
2507 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
2508 & , 3)*xxc(3)
2509  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
2510 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
2511 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
2512 & , 3)*xxc(3)
2513  end do
2514  end do
2515  else if (bcfaceid(mm) .eq. jmax) then
2516  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2517  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2518 ! compute the coordinates of the centroid of the face.
2519 ! normally this would be an average of i-1 and i, but
2520 ! due to the usage of the pointer xface and the fact
2521 ! that x starts at index 0 this is shifted 1 index.
2522  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
2523 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 1)+&
2524 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 1)+flowdoms&
2525 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 1))
2526  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
2527 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 2)+&
2528 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 2)+flowdoms&
2529 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 2))
2530  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, jl, j&
2531 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, jl, j-1, 3)+&
2532 & flowdoms(nn, groundlevel, sps)%x(i-1, jl, j, 3)+flowdoms&
2533 & (nn, groundlevel, sps)%x(i-1, jl, j-1, 3))
2534 ! determine the coordinates relative to the center
2535 ! of rotation.
2536  xxc(1) = xc(1) - rotcenter(1)
2537  xxc(2) = xc(2) - rotcenter(2)
2538  xxc(3) = xc(3) - rotcenter(3)
2539 ! compute the velocity, which is the cross product
2540 ! of rotrate and xc.
2541  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
2542 & *xxc(2)
2543  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
2544 & *xxc(3)
2545  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
2546 & *xxc(1)
2547 ! determine the coordinates relative to the
2548 ! rigid body rotation point.
2549  xxc(1) = xc(1) - rotationpoint(1)
2550  xxc(2) = xc(2) - rotationpoint(2)
2551  xxc(3) = xc(3) - rotationpoint(3)
2552 ! determine the total velocity of the cell center.
2553 ! this is a combination of rotation speed of this
2554 ! block and the entire rigid body rotation.
2555  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
2556 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
2557 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
2558 & , 3)*xxc(3)
2559  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
2560 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
2561 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
2562 & , 3)*xxc(3)
2563  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
2564 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
2565 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
2566 & , 3)*xxc(3)
2567  end do
2568  end do
2569  else if (bcfaceid(mm) .eq. kmin) then
2570  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2571  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2572 ! compute the coordinates of the centroid of the face.
2573 ! normally this would be an average of i-1 and i, but
2574 ! due to the usage of the pointer xface and the fact
2575 ! that x starts at index 0 this is shifted 1 index.
2576  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
2577 & 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 1)+&
2578 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 1)+flowdoms(&
2579 & nn, groundlevel, sps)%x(i-1, j-1, 1, 1))
2580  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
2581 & 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 2)+&
2582 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 2)+flowdoms(&
2583 & nn, groundlevel, sps)%x(i-1, j-1, 1, 2))
2584  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, 1, &
2585 & 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, 1, 3)+&
2586 & flowdoms(nn, groundlevel, sps)%x(i-1, j, 1, 3)+flowdoms(&
2587 & nn, groundlevel, sps)%x(i-1, j-1, 1, 3))
2588 ! determine the coordinates relative to the center
2589 ! of rotation.
2590  xxc(1) = xc(1) - rotcenter(1)
2591  xxc(2) = xc(2) - rotcenter(2)
2592  xxc(3) = xc(3) - rotcenter(3)
2593 ! compute the velocity, which is the cross product
2594 ! of rotrate and xc.
2595  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
2596 & *xxc(2)
2597  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
2598 & *xxc(3)
2599  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
2600 & *xxc(1)
2601 ! determine the coordinates relative to the
2602 ! rigid body rotation point.
2603  xxc(1) = xc(1) - rotationpoint(1)
2604  xxc(2) = xc(2) - rotationpoint(2)
2605  xxc(3) = xc(3) - rotationpoint(3)
2606 ! determine the total velocity of the cell center.
2607 ! this is a combination of rotation speed of this
2608 ! block and the entire rigid body rotation.
2609  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
2610 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
2611 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
2612 & , 3)*xxc(3)
2613  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
2614 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
2615 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
2616 & , 3)*xxc(3)
2617  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
2618 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
2619 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
2620 & , 3)*xxc(3)
2621  end do
2622  end do
2623  else if (bcfaceid(mm) .eq. kmax) then
2624  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2625  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2626 ! compute the coordinates of the centroid of the face.
2627 ! normally this would be an average of i-1 and i, but
2628 ! due to the usage of the pointer xface and the fact
2629 ! that x starts at index 0 this is shifted 1 index.
2630  xc(1) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
2631 & , 1)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 1)+&
2632 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 1)+flowdoms&
2633 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 1))
2634  xc(2) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
2635 & , 2)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 2)+&
2636 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 2)+flowdoms&
2637 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 2))
2638  xc(3) = fourth*(flowdoms(nn, groundlevel, sps)%x(i, j, kl&
2639 & , 3)+flowdoms(nn, groundlevel, sps)%x(i, j-1, kl, 3)+&
2640 & flowdoms(nn, groundlevel, sps)%x(i-1, j, kl, 3)+flowdoms&
2641 & (nn, groundlevel, sps)%x(i-1, j-1, kl, 3))
2642 ! determine the coordinates relative to the center
2643 ! of rotation.
2644  xxc(1) = xc(1) - rotcenter(1)
2645  xxc(2) = xc(2) - rotcenter(2)
2646  xxc(3) = xc(3) - rotcenter(3)
2647 ! compute the velocity, which is the cross product
2648 ! of rotrate and xc.
2649  bcdata(mm)%uslip(i, j, 1) = rotrate(2)*xxc(3) - rotrate(3)&
2650 & *xxc(2)
2651  bcdata(mm)%uslip(i, j, 2) = rotrate(3)*xxc(1) - rotrate(1)&
2652 & *xxc(3)
2653  bcdata(mm)%uslip(i, j, 3) = rotrate(1)*xxc(2) - rotrate(2)&
2654 & *xxc(1)
2655 ! determine the coordinates relative to the
2656 ! rigid body rotation point.
2657  xxc(1) = xc(1) - rotationpoint(1)
2658  xxc(2) = xc(2) - rotationpoint(2)
2659  xxc(3) = xc(3) - rotationpoint(3)
2660 ! determine the total velocity of the cell center.
2661 ! this is a combination of rotation speed of this
2662 ! block and the entire rigid body rotation.
2663  bcdata(mm)%uslip(i, j, 1) = bcdata(mm)%uslip(i, j, 1) + &
2664 & velxgrid + derivrotationmatrix(1, 1)*xxc(1) + &
2665 & derivrotationmatrix(1, 2)*xxc(2) + derivrotationmatrix(1&
2666 & , 3)*xxc(3)
2667  bcdata(mm)%uslip(i, j, 2) = bcdata(mm)%uslip(i, j, 2) + &
2668 & velygrid + derivrotationmatrix(2, 1)*xxc(1) + &
2669 & derivrotationmatrix(2, 2)*xxc(2) + derivrotationmatrix(2&
2670 & , 3)*xxc(3)
2671  bcdata(mm)%uslip(i, j, 3) = bcdata(mm)%uslip(i, j, 3) + &
2672 & velzgrid + derivrotationmatrix(3, 1)*xxc(1) + &
2673 & derivrotationmatrix(3, 2)*xxc(2) + derivrotationmatrix(3&
2674 & , 3)*xxc(3)
2675  end do
2676  end do
2677  end if
2678  end do bocoloop2
2679  end if
2680  end subroutine slipvelocitiesfinelevel_block
2681 
2682 ! differentiation of normalvelocities_block in forward (tangent) mode (with options i4 dr8 r8):
2683 ! variations of useful results: *(*bcdata.rface)
2684 ! with respect to varying inputs: *sfacei *sfacej *sfacek *si
2685 ! *sj *sk *(*bcdata.rface)
2686 ! rw status of diff variables: *sfacei:in *sfacej:in *sfacek:in
2687 ! *si:in *sj:in *sk:in *(*bcdata.rface):in-out
2688 ! plus diff mem management of: sfacei:in sfacej:in sfacek:in
2689 ! si:in sj:in sk:in bcdata:in *bcdata.rface:in
2691 !
2692 ! normalvelocitiesalllevels computes the normal grid
2693 ! velocities of some boundary faces of the moving blocks for
2694 ! spectral mode sps. all grid levels from ground level to the
2695 ! coarsest level are considered.
2696 !
2697  use constants
2698  use blockpointers, only : il, jl, kl, addgridvelocities, nbocos, &
2700 & bcfaceid, si, sid, sj, sjd, sk, skd
2701  implicit none
2702 !
2703 ! subroutine arguments.
2704 !
2705  integer(kind=inttype), intent(in) :: sps
2706 !
2707 ! local variables.
2708 !
2709  integer(kind=inttype) :: mm
2710  integer(kind=inttype) :: i, j
2711  real(kind=realtype) :: weight, mult
2712  real(kind=realtype) :: weightd
2713  real(kind=realtype), dimension(:, :), pointer :: sface
2714  real(kind=realtype), dimension(:, :, :), pointer :: ss
2715  intrinsic associated
2716  intrinsic sqrt
2717  real(kind=realtype) :: arg1
2718  real(kind=realtype) :: arg1d
2719  real(kind=realtype) :: temp
2720  real(kind=realtype) :: temp0
2721  real(kind=realtype) :: temp1
2722 ! check for a moving block. as it is possible that in a
2723 ! multidisicplinary environment additional grid velocities
2724 ! are set, the test should be done on addgridvelocities
2725 ! and not on blockismoving.
2726  if (addgridvelocities) then
2727 !
2728 ! determine the normal grid velocities of the boundaries.
2729 ! as these values are based on the unit normal. a division
2730 ! by the length of the normal is needed.
2731 ! furthermore the boundary unit normals are per definition
2732 ! outward pointing, while on the imin, jmin and kmin
2733 ! boundaries the face normals are inward pointing. this
2734 ! is taken into account by the factor mult.
2735 !
2736 ! loop over the boundary subfaces.
2737 bocoloop:do mm=1,nbocos
2738 ! check whether rface is allocated.
2739  if (associated(bcdata(mm)%rface)) then
2740 ! determine the block face on which the subface is
2741 ! located and set some variables accordingly.
2742 ! the new procedure is less elegant as the previous one.
2743 ! but the new stands up to tapenade.
2744  if (bcfaceid(mm) .eq. imin) then
2745  mult = -one
2746  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2747  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2748 ! compute the inverse of the length of the normal
2749 ! vector and possibly correct for inward pointing.
2750  arg1d = 2*si(1, i, j, 1)*sid(1, i, j, 1) + 2*si(1, i, j&
2751 & , 2)*sid(1, i, j, 2) + 2*si(1, i, j, 3)*sid(1, i, j, 3&
2752 & )
2753  arg1 = si(1, i, j, 1)**2 + si(1, i, j, 2)**2 + si(1, i, &
2754 & j, 3)**2
2755  temp = sqrt(arg1)
2756  if (arg1 .eq. 0.0_8) then
2757  weightd = 0.0_8
2758  else
2759  weightd = arg1d/(2.0*temp)
2760  end if
2761  weight = temp
2762  if (weight .gt. zero) then
2763  weightd = -(mult*weightd/weight**2)
2764  weight = mult/weight
2765  end if
2766 ! compute the normal velocity based on the outward
2767 ! pointing unit normal.
2768  bcdatad(mm)%rface(i, j) = sfacei(1, i, j)*weightd + &
2769 & weight*sfaceid(1, i, j)
2770  bcdata(mm)%rface(i, j) = weight*sfacei(1, i, j)
2771  end do
2772  end do
2773  else if (bcfaceid(mm) .eq. imax) then
2774  mult = one
2775  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2776  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2777 ! compute the inverse of the length of the normal
2778 ! vector and possibly correct for inward pointing.
2779  temp = si(il, i, j, 1)
2780  temp0 = si(il, i, j, 2)
2781  temp1 = si(il, i, j, 3)
2782  arg1d = 2*temp*sid(il, i, j, 1) + 2*temp0*sid(il, i, j, &
2783 & 2) + 2*temp1*sid(il, i, j, 3)
2784  arg1 = temp*temp + temp0*temp0 + temp1*temp1
2785  temp1 = sqrt(arg1)
2786  if (arg1 .eq. 0.0_8) then
2787  weightd = 0.0_8
2788  else
2789  weightd = arg1d/(2.0*temp1)
2790  end if
2791  weight = temp1
2792  if (weight .gt. zero) then
2793  weightd = -(mult*weightd/weight**2)
2794  weight = mult/weight
2795  end if
2796 ! compute the normal velocity based on the outward
2797 ! pointing unit normal.
2798  bcdatad(mm)%rface(i, j) = sfacei(il, i, j)*weightd + &
2799 & weight*sfaceid(il, i, j)
2800  bcdata(mm)%rface(i, j) = weight*sfacei(il, i, j)
2801  end do
2802  end do
2803  else if (bcfaceid(mm) .eq. jmin) then
2804  mult = -one
2805  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2806  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2807 ! compute the inverse of the length of the normal
2808 ! vector and possibly correct for inward pointing.
2809  arg1d = 2*sj(i, 1, j, 1)*sjd(i, 1, j, 1) + 2*sj(i, 1, j&
2810 & , 2)*sjd(i, 1, j, 2) + 2*sj(i, 1, j, 3)*sjd(i, 1, j, 3&
2811 & )
2812  arg1 = sj(i, 1, j, 1)**2 + sj(i, 1, j, 2)**2 + sj(i, 1, &
2813 & j, 3)**2
2814  temp1 = sqrt(arg1)
2815  if (arg1 .eq. 0.0_8) then
2816  weightd = 0.0_8
2817  else
2818  weightd = arg1d/(2.0*temp1)
2819  end if
2820  weight = temp1
2821  if (weight .gt. zero) then
2822  weightd = -(mult*weightd/weight**2)
2823  weight = mult/weight
2824  end if
2825 ! compute the normal velocity based on the outward
2826 ! pointing unit normal.
2827  bcdatad(mm)%rface(i, j) = sfacej(i, 1, j)*weightd + &
2828 & weight*sfacejd(i, 1, j)
2829  bcdata(mm)%rface(i, j) = weight*sfacej(i, 1, j)
2830  end do
2831  end do
2832  else if (bcfaceid(mm) .eq. jmax) then
2833  mult = one
2834  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2835  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2836 ! compute the inverse of the length of the normal
2837 ! vector and possibly correct for inward pointing.
2838  temp1 = sj(i, jl, j, 1)
2839  temp0 = sj(i, jl, j, 2)
2840  temp = sj(i, jl, j, 3)
2841  arg1d = 2*temp1*sjd(i, jl, j, 1) + 2*temp0*sjd(i, jl, j&
2842 & , 2) + 2*temp*sjd(i, jl, j, 3)
2843  arg1 = temp1*temp1 + temp0*temp0 + temp*temp
2844  temp1 = sqrt(arg1)
2845  if (arg1 .eq. 0.0_8) then
2846  weightd = 0.0_8
2847  else
2848  weightd = arg1d/(2.0*temp1)
2849  end if
2850  weight = temp1
2851  if (weight .gt. zero) then
2852  weightd = -(mult*weightd/weight**2)
2853  weight = mult/weight
2854  end if
2855 ! compute the normal velocity based on the outward
2856 ! pointing unit normal.
2857  bcdatad(mm)%rface(i, j) = sfacej(i, jl, j)*weightd + &
2858 & weight*sfacejd(i, jl, j)
2859  bcdata(mm)%rface(i, j) = weight*sfacej(i, jl, j)
2860  end do
2861  end do
2862  else if (bcfaceid(mm) .eq. kmin) then
2863  mult = -one
2864  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2865  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2866 ! compute the inverse of the length of the normal
2867 ! vector and possibly correct for inward pointing.
2868  arg1d = 2*sk(i, j, 1, 1)*skd(i, j, 1, 1) + 2*sk(i, j, 1&
2869 & , 2)*skd(i, j, 1, 2) + 2*sk(i, j, 1, 3)*skd(i, j, 1, 3&
2870 & )
2871  arg1 = sk(i, j, 1, 1)**2 + sk(i, j, 1, 2)**2 + sk(i, j, &
2872 & 1, 3)**2
2873  temp1 = sqrt(arg1)
2874  if (arg1 .eq. 0.0_8) then
2875  weightd = 0.0_8
2876  else
2877  weightd = arg1d/(2.0*temp1)
2878  end if
2879  weight = temp1
2880  if (weight .gt. zero) then
2881  weightd = -(mult*weightd/weight**2)
2882  weight = mult/weight
2883  end if
2884 ! compute the normal velocity based on the outward
2885 ! pointing unit normal.
2886  bcdatad(mm)%rface(i, j) = sfacek(i, j, 1)*weightd + &
2887 & weight*sfacekd(i, j, 1)
2888  bcdata(mm)%rface(i, j) = weight*sfacek(i, j, 1)
2889  end do
2890  end do
2891  else if (bcfaceid(mm) .eq. kmax) then
2892  mult = one
2893  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2894  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2895 ! compute the inverse of the length of the normal
2896 ! vector and possibly correct for inward pointing.
2897  temp1 = sk(i, j, kl, 1)
2898  temp0 = sk(i, j, kl, 2)
2899  temp = sk(i, j, kl, 3)
2900  arg1d = 2*temp1*skd(i, j, kl, 1) + 2*temp0*skd(i, j, kl&
2901 & , 2) + 2*temp*skd(i, j, kl, 3)
2902  arg1 = temp1*temp1 + temp0*temp0 + temp*temp
2903  temp1 = sqrt(arg1)
2904  if (arg1 .eq. 0.0_8) then
2905  weightd = 0.0_8
2906  else
2907  weightd = arg1d/(2.0*temp1)
2908  end if
2909  weight = temp1
2910  if (weight .gt. zero) then
2911  weightd = -(mult*weightd/weight**2)
2912  weight = mult/weight
2913  end if
2914 ! compute the normal velocity based on the outward
2915 ! pointing unit normal.
2916  bcdatad(mm)%rface(i, j) = sfacek(i, j, kl)*weightd + &
2917 & weight*sfacekd(i, j, kl)
2918  bcdata(mm)%rface(i, j) = weight*sfacek(i, j, kl)
2919  end do
2920  end do
2921  end if
2922  end if
2923  end do bocoloop
2924  else
2925 ! block is not moving. loop over the boundary faces and set
2926 ! the normal grid velocity to zero if allocated.
2927  do mm=1,nbocos
2928  if (associated(bcdata(mm)%rface)) then
2929  bcdatad(mm)%rface = 0.0_8
2930  bcdata(mm)%rface = zero
2931  end if
2932  end do
2933  end if
2934  end subroutine normalvelocities_block_d
2935 
2936  subroutine normalvelocities_block(sps)
2937 !
2938 ! normalvelocitiesalllevels computes the normal grid
2939 ! velocities of some boundary faces of the moving blocks for
2940 ! spectral mode sps. all grid levels from ground level to the
2941 ! coarsest level are considered.
2942 !
2943  use constants
2944  use blockpointers, only : il, jl, kl, addgridvelocities, nbocos, &
2946  implicit none
2947 !
2948 ! subroutine arguments.
2949 !
2950  integer(kind=inttype), intent(in) :: sps
2951 !
2952 ! local variables.
2953 !
2954  integer(kind=inttype) :: mm
2955  integer(kind=inttype) :: i, j
2956  real(kind=realtype) :: weight, mult
2957  real(kind=realtype), dimension(:, :), pointer :: sface
2958  real(kind=realtype), dimension(:, :, :), pointer :: ss
2959  intrinsic associated
2960  intrinsic sqrt
2961  real(kind=realtype) :: arg1
2962 ! check for a moving block. as it is possible that in a
2963 ! multidisicplinary environment additional grid velocities
2964 ! are set, the test should be done on addgridvelocities
2965 ! and not on blockismoving.
2966  if (addgridvelocities) then
2967 !
2968 ! determine the normal grid velocities of the boundaries.
2969 ! as these values are based on the unit normal. a division
2970 ! by the length of the normal is needed.
2971 ! furthermore the boundary unit normals are per definition
2972 ! outward pointing, while on the imin, jmin and kmin
2973 ! boundaries the face normals are inward pointing. this
2974 ! is taken into account by the factor mult.
2975 !
2976 ! loop over the boundary subfaces.
2977 bocoloop:do mm=1,nbocos
2978 ! check whether rface is allocated.
2979  if (associated(bcdata(mm)%rface)) then
2980 ! determine the block face on which the subface is
2981 ! located and set some variables accordingly.
2982 ! the new procedure is less elegant as the previous one.
2983 ! but the new stands up to tapenade.
2984  if (bcfaceid(mm) .eq. imin) then
2985  mult = -one
2986  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
2987  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
2988 ! compute the inverse of the length of the normal
2989 ! vector and possibly correct for inward pointing.
2990  arg1 = si(1, i, j, 1)**2 + si(1, i, j, 2)**2 + si(1, i, &
2991 & j, 3)**2
2992  weight = sqrt(arg1)
2993  if (weight .gt. zero) weight = mult/weight
2994 ! compute the normal velocity based on the outward
2995 ! pointing unit normal.
2996  bcdata(mm)%rface(i, j) = weight*sfacei(1, i, j)
2997  end do
2998  end do
2999  else if (bcfaceid(mm) .eq. imax) then
3000  mult = one
3001  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
3002  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
3003 ! compute the inverse of the length of the normal
3004 ! vector and possibly correct for inward pointing.
3005  arg1 = si(il, i, j, 1)**2 + si(il, i, j, 2)**2 + si(il, &
3006 & i, j, 3)**2
3007  weight = sqrt(arg1)
3008  if (weight .gt. zero) weight = mult/weight
3009 ! compute the normal velocity based on the outward
3010 ! pointing unit normal.
3011  bcdata(mm)%rface(i, j) = weight*sfacei(il, i, j)
3012  end do
3013  end do
3014  else if (bcfaceid(mm) .eq. jmin) then
3015  mult = -one
3016  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
3017  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
3018 ! compute the inverse of the length of the normal
3019 ! vector and possibly correct for inward pointing.
3020  arg1 = sj(i, 1, j, 1)**2 + sj(i, 1, j, 2)**2 + sj(i, 1, &
3021 & j, 3)**2
3022  weight = sqrt(arg1)
3023  if (weight .gt. zero) weight = mult/weight
3024 ! compute the normal velocity based on the outward
3025 ! pointing unit normal.
3026  bcdata(mm)%rface(i, j) = weight*sfacej(i, 1, j)
3027  end do
3028  end do
3029  else if (bcfaceid(mm) .eq. jmax) then
3030  mult = one
3031  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
3032  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
3033 ! compute the inverse of the length of the normal
3034 ! vector and possibly correct for inward pointing.
3035  arg1 = sj(i, jl, j, 1)**2 + sj(i, jl, j, 2)**2 + sj(i, &
3036 & jl, j, 3)**2
3037  weight = sqrt(arg1)
3038  if (weight .gt. zero) weight = mult/weight
3039 ! compute the normal velocity based on the outward
3040 ! pointing unit normal.
3041  bcdata(mm)%rface(i, j) = weight*sfacej(i, jl, j)
3042  end do
3043  end do
3044  else if (bcfaceid(mm) .eq. kmin) then
3045  mult = -one
3046  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
3047  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
3048 ! compute the inverse of the length of the normal
3049 ! vector and possibly correct for inward pointing.
3050  arg1 = sk(i, j, 1, 1)**2 + sk(i, j, 1, 2)**2 + sk(i, j, &
3051 & 1, 3)**2
3052  weight = sqrt(arg1)
3053  if (weight .gt. zero) weight = mult/weight
3054 ! compute the normal velocity based on the outward
3055 ! pointing unit normal.
3056  bcdata(mm)%rface(i, j) = weight*sfacek(i, j, 1)
3057  end do
3058  end do
3059  else if (bcfaceid(mm) .eq. kmax) then
3060  mult = one
3061  do j=bcdata(mm)%jcbeg,bcdata(mm)%jcend
3062  do i=bcdata(mm)%icbeg,bcdata(mm)%icend
3063 ! compute the inverse of the length of the normal
3064 ! vector and possibly correct for inward pointing.
3065  arg1 = sk(i, j, kl, 1)**2 + sk(i, j, kl, 2)**2 + sk(i, j&
3066 & , kl, 3)**2
3067  weight = sqrt(arg1)
3068  if (weight .gt. zero) weight = mult/weight
3069 ! compute the normal velocity based on the outward
3070 ! pointing unit normal.
3071  bcdata(mm)%rface(i, j) = weight*sfacek(i, j, kl)
3072  end do
3073  end do
3074  end if
3075  end if
3076  end do bocoloop
3077  else
3078 ! block is not moving. loop over the boundary faces and set
3079 ! the normal grid velocity to zero if allocated.
3080  do mm=1,nbocos
3081  if (associated(bcdata(mm)%rface)) bcdata(mm)%rface = zero
3082  end do
3083  end if
3084  end subroutine normalvelocities_block
3085 ! ----------------------------------------------------------------------
3086 ! |
3087 ! no tapenade routine below this line |
3088 ! |
3089 ! ----------------------------------------------------------------------
3090 
3091 end module solverutils_d
3092 
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 getdirvector(refdirection, alpha, beta, winddirection, liftindex)
subroutine derivativerotmatrixrigid(rotationmatrix, rotationpoint, t)
subroutine derivativerotmatrixrigid_d(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_d(sps)
subroutine gridvelocitiesfinelevel_block(useoldcoor, t, sps, nn)
subroutine cellfacevelocities_d(xc, xcd, rotcenter, rotcenterd, rotrate, rotrated, velxgrid, velxgridd, velygrid, velygridd, velzgrid, velzgridd, derivrotationmatrix, derivrotationmatrixd, sc, scd)
subroutine slipvelocitiesfinelevel_block(useoldcoor, t, sps, nn)
subroutine cellfacevelocities(xc, rotcenter, rotrate, velxgrid, velygrid, velzgrid, derivrotationmatrix, sc)
subroutine timestep_block(onlyradii)
subroutine slipvelocitiesfinelevel_block_d(useoldcoor, t, sps, nn)
subroutine timestep_block_d(onlyradii)
subroutine normalvelocities_block(sps)
subroutine gridvelocitiesfinelevel_block_d(useoldcoor, t, sps, nn)
subroutine setcoeftimeintegrator()
Definition: utils_d.f90:1346
subroutine getdirangle(freestreamaxis, liftaxis, liftindex, alpha, beta)
Definition: utils_d.f90:1198
subroutine rotmatrixrigidbody(tnew, told, rotationmatrix, rotationpoint)
Definition: utils_d.f90:516
real(kind=realtype) function tsbeta(degreepolbeta, coefpolbeta, degreefourbeta, omegafourbeta, coscoeffourbeta, sincoeffourbeta, t)
Definition: utils_d.f90:31
real(kind=realtype) function tsalpha(degreepolalpha, coefpolalpha, degreefouralpha, omegafouralpha, coscoeffouralpha, sincoeffouralpha, t)
Definition: utils_d.f90:242
real(kind=realtype) function tsmach(degreepolmach, coefpolmach, degreefourmach, omegafourmach, coscoeffourmach, sincoeffourmach, t)
Definition: utils_d.f90:136
subroutine terminate(routinename, errormessage)
Definition: utils_d.f90:500