ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
variableReading.F90
Go to the documentation of this file.
2 
3  use constants, only: inttype, maxcgnsnamelen, cgnsrealtype, realtype, maxstringlen
4  use su_cgns, only: cgsize_t
5  ! halosRead:Determines if the halos where read or not.
6  logical :: halosread
7 
8  ! cgnsInd: File index of the CGNS file.
9  ! cgnsBase: Base of the CGNS file, always set to 1.
10  ! cgnsZone: Zone ID in the CGNS file.
11  ! cgnsSol: Solution ID in the zone ID of the CGNS file.
12  ! location: Location where the variables are stored in CGNS.
13  ! Supported possibilities are Vertex and CellCentered.
14 
16 
17  ! zoneNumbers: Corresponding zoneNumbers of the sorted
18  ! zoneNames.
19  ! zoneNames: Zone names, sorted in increasing order, of the
20  ! zones in the CGNS restart file.
21  ! varNames: Variable names, sorted in increasing order,
22  ! of the variables.
23 
24  integer(kind=intType), allocatable, dimension(:) :: zonenumbers
25  character(len=maxCGNSNameLen), allocatable, dimension(:) :: zonenames
26  character(len=maxCGNSNameLen), allocatable, dimension(:) :: varnames
27 
28  ! rangeMin(3): Lower index in i, j and k direction of the
29  ! range to be read.
30  ! rangeMax(3): Upper index in i, j and k direction of the
31  ! range to be read.
32  integer(kind=cgsize_t), dimension(3) :: rangemin, rangemax
33 
34  ! nVar: Number of variables stored in the solution file.
35  ! solID: Loop variables for the number of solutions to be read.
36 
37  integer :: nvar
38  integer(kind=intType) :: solid
39 
40  ! interpolSpectral: Whether or not to interpolate the
41  ! coordinates/solutions for the time
42  ! spectral mode.
43  ! copySpectral: Whether or not to copy the solutions
44  ! for the time spectral mode.
46 
47  ! rhoScale: Scale factor for the density.
48  ! velScale: Scale factor for the velocity.
49  ! pScale: Scale factor for the pressure.
50  ! muScale: Scale factor for the molecular viscosity.
51 
52  real(kind=realtype) :: rhoscale, velscale, pscale, muscale
53 
54  ! nSolsRead: Number of solution files to read.
55  ! solFiles(nSolsRead): Names of the solution files to be read.
56 
57  integer(kind=intType) :: nsolsread
58  character(len=maxStringLen), dimension(:), allocatable :: solfiles
59 
60  ! varTypes(nVar): Variable types of the variables stored.
61  integer, allocatable, dimension(:) :: vartypes
62 
63  ! buffer(2:il,2:jl,2:kl): Buffer to read and store the cell
64  ! centered values.
65  ! bufferVertex(:): Additional buffer needed to read
66  ! vertex data and transform them into
67  ! cell centered values.
68 
69  real(kind=cgnsrealtype), dimension(:, :, :), allocatable :: buffer
70  real(kind=cgnsrealtype), dimension(:, :, :), allocatable :: buffervertex
71 
72 contains
73  subroutine readdensity(nTypeMismatch)
74  !
75  ! readDensity reads the density from the given place in the
76  ! cgns file. If the density itself is not stored (unlikely),
77  ! then it is tried to construct the density from other
78  ! variables. If this is not possible an error message is printed
79  ! and the program will stop.
80  ! It is assumed that the pointers in blockPointers already
81  ! point to the correct block.
82  !
83  use constants
84  use cgnsnames
85  use blockpointers, only: w, nbklocal
86  use iomodule, only: iovar
87  use utils, only: setcgnsrealtype, terminate
88  use sorting, only: bsearchstrings
89  implicit none
90  !
91  ! Subroutine argument.
92  !
93  integer(kind=intType), intent(inout) :: nTypeMismatch
94  !
95  ! Local variables
96  !
97  integer :: realTypeCGNS
98 
99  integer(kind=intType) :: i, j, k, nn, po, ip, jp, kp
100  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, kBeg, kEnd
101 
102  ! Set the cell range to be copied from the buffer.
103 
104  ibeg = lbound(buffer, 1); iend = ubound(buffer, 1)
105  jbeg = lbound(buffer, 2); jend = ubound(buffer, 2)
106  kbeg = lbound(buffer, 3); kend = ubound(buffer, 3)
107 
108  ! Set the cgns real type and abbreviate the solution variable and
109  ! the pointer offset to improve readability.
110 
111  realtypecgns = setcgnsrealtype()
112 
113  po = iovar(nbklocal, solid)%pointerOffset
114  w => iovar(nbklocal, solid)%w
115 
116  ! Find out if the density is present in the solution file.
117 
119  if (nn > 0) then
120 
121  ! Density is present. First determine whether or not a type
122  ! mismatch occurs. If so, update nTypeMismatch.
123 
124  if (realtypecgns /= vartypes(nn)) &
125  ntypemismatch = ntypemismatch + 1
126 
127  ! Read the density from the restart file and store it in buffer.
128 
129  call readrestartvariable(varnames(nn))
130 
131  ! Copy the variables from buffer into w. Multiply by the
132  ! scaling factor to obtain to correct nondimensional value and
133  ! take the possible pointer offset into account.
134 
135  do k = kbeg, kend
136  kp = k + po
137  do j = jbeg, jend
138  jp = j + po
139  do i = ibeg, iend
140  ip = i + po
141  w(ip, jp, kp, irho) = buffer(i, j, k) * rhoscale
142  end do
143  end do
144  end do
145 
146  ! Density is read, so a return can be made.
147 
148  return
149 
150  end if
151 
152  ! Not able to determine the density.
153  ! Print an error message and exit.
154 
155  call terminate("readDensity", &
156  "Not able to retrieve density from the &
157  &variables in the restart file.")
158 
159  end subroutine readdensity
160 
161  subroutine readenergy(nTypeMismatch)
162  !
163  ! readEnergy reads the energy variable from the given place in
164  ! the cgns file. If the energy is not stored then it is tried to
165  ! construct it from the pressure, density and velocities. If it
166  ! is not possible to create the energy an error message is
167  ! printed and the program will stop. It is assumed that the
168  ! pointers in blockPointers already point to the correct block.
169  !
170  use constants
171  use cgnsnames
172  use blockpointers, only: w, nbklocal
173  use iomodule, only: iovar
174  use utils, only: setcgnsrealtype, terminate
175  use sorting, only: bsearchstrings
176  use flowutils, only: etot
177  use flowvarrefstate, only: kpresent
178  implicit none
179  !
180  ! Subroutine argument.
181  !
182  integer(kind=intType), intent(inout) :: nTypeMismatch
183  !
184  ! Local variables
185  !
186  integer :: realTypeCGNS
187 
188  integer(kind=intType) :: i, j, k, nn, po, ip, jp, kp
189  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, kBeg, kEnd
190 
191  real(kind=realtype) :: vvx, vvy, vvz, dummyk, pres, rhoinv
192 
193  ! Set the cell range to be copied from the buffer.
194 
195  ibeg = lbound(buffer, 1); iend = ubound(buffer, 1)
196  jbeg = lbound(buffer, 2); jend = ubound(buffer, 2)
197  kbeg = lbound(buffer, 3); kend = ubound(buffer, 3)
198 
199  ! Set the cgns real type and abbreviate the solution variable and
200  ! the pointer offset to improve readability.
201 
202  realtypecgns = setcgnsrealtype()
203 
204  po = iovar(nbklocal, solid)%pointerOffset
205  w => iovar(nbklocal, solid)%w
206 
207  ! Find out if the total energy is present in the solution file.
208 
210 
211  testrhoepresent: if (nn > 0) then
212 
213  ! Total energy is present. First determine whether or not a type
214  ! mismatch occurs. If so, update nTypeMismatch.
215 
216  if (realtypecgns /= vartypes(nn)) &
217  ntypemismatch = ntypemismatch + 1
218 
219  ! Read the energy from the restart file and store it in buffer.
220 
221  call readrestartvariable(varnames(nn))
222 
223  ! Copy the variables from buffer into w. Multiply by the scaling
224  ! factor to obtain to correct non-dimensional value and take the
225  ! possible pointer offset into account.
226 
227  do k = kbeg, kend
228  kp = k + po
229  do j = jbeg, jend
230  jp = j + po
231  do i = ibeg, iend
232  ip = i + po
233  w(ip, jp, kp, irhoe) = buffer(i, j, k) * pscale
234  end do
235  end do
236  end do
237 
238  ! Energy has been read, so a return can be made.
239 
240  return
241 
242  end if testrhoepresent
243 
244  ! Total energy is not present. Check for the pressure.
245 
247 
248  testpressure: if (nn > 0) then
249 
250  ! Pressure is present. First determine whether or not a type
251  ! mismatch occurs. If so, update nTypeMismatch.
252 
253  if (realtypecgns /= vartypes(nn)) &
254  ntypemismatch = ntypemismatch + 1
255 
256  ! Read the pressure from the restart file and store it in buffer.
257 
258  call readrestartvariable(varnames(nn))
259 
260  ! Compute the total energy. This depends whether or not
261  ! a turbulent kinetic energy is present. Take the possible
262  ! pointer offset into account.
263  ! As this routine is only called to construct the states in
264  ! the past for a time accurate computation, the momentum is
265  ! stored and not the velocity.
266 
267  if (kpresent) then
268 
269  do k = kbeg, kend
270  kp = k + po
271  do j = jbeg, jend
272  jp = j + po
273  do i = ibeg, iend
274  ip = i + po
275  rhoinv = one / w(ip, jp, kp, irho)
276  vvx = w(ip, jp, kp, imx) * rhoinv
277  vvy = w(ip, jp, kp, imy) * rhoinv
278  vvz = w(ip, jp, kp, imz) * rhoinv
279  pres = buffer(i, j, k) * pscale
280  call etot(w(ip, jp, kp, irho), vvx, vvy, vvz, pres, &
281  w(ip, jp, kp, itu1), w(ip, jp, kp, irhoe), &
282  kpresent)
283  end do
284  end do
285  end do
286 
287  else
288 
289  dummyk = zero
290 
291  do k = kbeg, kend
292  kp = k + po
293  do j = jbeg, jend
294  jp = j + po
295  do i = ibeg, iend
296  ip = i + po
297  rhoinv = one / w(ip, jp, kp, irho)
298  vvx = w(ip, jp, kp, imx) * rhoinv
299  vvy = w(ip, jp, kp, imy) * rhoinv
300  vvz = w(ip, jp, kp, imz) * rhoinv
301  pres = buffer(i, j, k) * pscale
302  call etot(w(ip, jp, kp, irho), vvx, vvy, vvz, pres, &
303  dummyk, w(ip, jp, kp, irhoe), kpresent)
304  end do
305  end do
306  end do
307 
308  end if
309 
310  ! Energy has been created. So a return can be made.
311 
312  return
313 
314  end if testpressure
315 
316  ! Energy could not be created. Terminate.
317 
318  call terminate("readEnergy", &
319  "Energy could not be created")
320 
321  end subroutine readenergy
322 
323  subroutine readpressure(nTypeMismatch)
324  !
325  ! readPressure reads the pressure variable from the given place
326  ! in the cgns file. If the pressure itself is not present it is
327  ! tried to construct if from other variables. In that case it is
328  ! assumed that the density, velocity and turbulent variables are
329  ! already stored in the pointer variable w.
330  ! If it is not possible to create the pressure an error message
331  ! is printed and the program will stop.
332  ! It is assumed that the pointers in blockPointers already
333  ! point to the correct block.
334  !
335  use constants
336  use cgnsnames
337  use blockpointers, only: w, nbklocal
338  use iomodule, only: iovar
339  use utils, only: setcgnsrealtype, terminate
340  use flowutils, only: computepressure
341  use sorting, only: bsearchstrings
342  implicit none
343  !
344  ! Subroutine argument.
345  !
346  integer(kind=intType), intent(inout) :: nTypeMismatch
347  !
348  ! Local variables
349  !
350  integer :: realTypeCGNS
351 
352  integer(kind=intType) :: i, j, k, nn, po, ip, jp, kp
353  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, kBeg, kEnd
354 
355  ! Set the cell range to be copied from the buffer.
356 
357  ibeg = lbound(buffer, 1); iend = ubound(buffer, 1)
358  jbeg = lbound(buffer, 2); jend = ubound(buffer, 2)
359  kbeg = lbound(buffer, 3); kend = ubound(buffer, 3)
360 
361  ! Set the cgns real type and abbreviate the solution variable and
362  ! the pointer offset to improve readability.
363 
364  realtypecgns = setcgnsrealtype()
365 
366  po = iovar(nbklocal, solid)%pointerOffset
367  w => iovar(nbklocal, solid)%w
368 
369  ! Find out if the pressure is present in the solution file.
370 
372  if (nn > 0) then
373 
374  ! Pressure is present. First determine whether or not a type
375  ! mismatch occurs. If so, update nTypeMismatch.
376 
377  if (realtypecgns /= vartypes(nn)) &
378  ntypemismatch = ntypemismatch + 1
379 
380  ! Read the pressure from the restart file and store
381  ! it in buffer.
382 
383  call readrestartvariable(varnames(nn))
384 
385  ! Copy the variables from buffer into the position of rhoE
386  ! in w. Multiply by the pressure scale factor to obtain the
387  ! correct nondimensional value and take the possible pointer
388  ! offset into account.
389 
390  do k = kbeg, kend
391  kp = k + po
392  do j = jbeg, jend
393  jp = j + po
394  do i = ibeg, iend
395  ip = i + po
396  w(ip, jp, kp, irhoe) = buffer(i, j, k) * pscale
397  end do
398  end do
399  end do
400 
401  ! Pressure is read, so a return can be made.
402 
403  return
404 
405  end if
406 
407  ! Pressure is not present. Check for the total energy.
408 
410  if (nn > 0) then
411 
412  ! Total energy is present. First determine whether or not a type
413  ! mismatch occurs. If so, update nTypeMismatch.
414 
415  if (realtypecgns /= vartypes(nn)) &
416  ntypemismatch = ntypemismatch + 1
417 
418  ! Read the total energy from the restart file and store
419  ! it in buffer.
420 
421  call readrestartvariable(varnames(nn))
422 
423  ! Copy the variables from buffer into w. Multiply by the
424  ! pressure scale factor to obtain the correct nondimensional
425  ! value and take the possible pointer offset into account.
426 
427  do k = kbeg, kend
428  kp = k + po
429  do j = jbeg, jend
430  jp = j + po
431  do i = ibeg, iend
432  ip = i + po
433  w(ip, jp, kp, irhoe) = buffer(i, j, k) * pscale
434  end do
435  end do
436  end do
437 
438  ! Compute the pressure from energy, density and velocities.
439  ! This will still be stored in the irhoE position of w.
440 
441  call computepressure(ibeg, iend, jbeg, jend, kbeg, kend, po)
442 
443  ! Pressure is constructed, so a return can be made.
444 
445  return
446 
447  end if
448 
449  ! Not able to determine the pressure.
450  ! Print an error message and exit.
451 
452  call terminate("readPressure", &
453  "Not able to retrieve the pressure from &
454  &the variables in the restart file.")
455 
456  end subroutine readpressure
457 
458  subroutine readturbeddyvis(nTypeMismatch, eddyVisPresent)
459  !
460  ! readTurbEddyVis tries to read the eddy viscosity from the
461  ! restart file.
462  !
463  use constants
464  use cgnsnames
465  use blockpointers, only: w, nbklocal, il, jl, kl, rev
466  use utils, only: setcgnsrealtype, terminate
467  use sorting, only: bsearchstrings
468  use flowvarrefstate, only: muinf
469  use inputphysics, only: eddyvisinfratio
470  implicit none
471  !
472  ! Subroutine arguments.
473  !
474  integer(kind=intType), intent(inout) :: nTypeMismatch
475  logical, intent(out) :: eddyVisPresent
476  !
477  ! Local variables.
478  !
479  integer :: realTypeCGNS
480 
481  integer(kind=intType) :: i, j, k, nn
482 
483  ! Set the cgns real type
484 
485  realtypecgns = setcgnsrealtype()
486 
487  ! Check if the eddy viscosity is present. If so, read it.
488 
490 
491  if (nn > 0) then
492 
493  ! Eddy viscosity is present. Determine if a type mismatch
494  ! occured, read the buffer from the file and set
495  ! eddyVisPresent to .true.
496 
497  if (realtypecgns /= vartypes(nn)) &
498  ntypemismatch = ntypemismatch + 1
499 
500  call readrestartvariable(varnames(nn))
501 
502  eddyvispresent = .true.
503 
504  ! Scale the eddy viscosity such that it contains the
505  ! correct nonDimensional value.
506 
507  do k = 2, kl
508  do j = 2, jl
509  do i = 2, il
510  rev(i, j, k) = muscale * buffer(i, j, k)
511  end do
512  end do
513  end do
514 
515  ! Eddy viscosity has been read, so make a return.
516 
517  return
518 
519  end if
520 
521  ! Eddy viscosity is not present. Check if the eddy viscosity
522  ! ratio is present. If so read it and construct the eddy
523  ! viscosity from it.
524 
526 
527  if (nn > 0) then
528 
529  ! Eddy viscosity ratio is present. Determine if a type
530  ! mismatch occured, read the buffer from the file and set
531  ! eddyVisPresent to .true.
532 
533  if (realtypecgns /= vartypes(nn)) &
534  ntypemismatch = ntypemismatch + 1
535 
536  call readrestartvariable(varnames(nn))
537 
538  eddyvispresent = .true.
539 
540  ! Multiply the eddy viscosity by the laminar viscosity such
541  ! that it contains the correct nonDimensional value.
542  ! As the laminar viscosity is not yet know, use the free
543  ! stream viscosity.
544 
545  do k = 2, kl
546  do j = 2, jl
547  do i = 2, il
548  rev(i, j, k) = muinf * buffer(i, j, k)
549  end do
550  end do
551  end do
552 
553  ! Eddy viscosity has been read, so make a return.
554 
555  return
556 
557  end if
558 
559  ! Eddy viscosity cannot be constructed. Set it to the
560  ! free stream eddy viscosity.
561 
562  do k = 2, kl
563  do j = 2, jl
564  do i = 2, il
565  rev(i, j, k) = muinf * eddyvisinfratio
566  end do
567  end do
568  end do
569 
570  ! Eddy viscosity is not present, so set it to .false.
571 
572  eddyvispresent = .false.
573 
574  end subroutine readturbeddyvis
575 
576  subroutine readturbkwtype(nTypeMismatch)
577  !
578  ! readTurbKwType reads or constructs the k and omega values
579  ! for two-equations turbulence models of the k-omega type.
580  ! If no information could be retrieved some engineering guess of
581  ! the turbulent variables is made.
582  !
583  use constants
584  use cgnsnames
585  use communication, only: myid
586  use blockpointers, only: w, nbklocal, il, jl, kl, rlv, rev
587  use iomodule, only: iovar
588  use utils, only: setcgnsrealtype, terminate
589  use sorting, only: bsearchstrings
590  use flowvarrefstate, only: muinf
591  use inputphysics, only: turbmodel
592  use turbutils, only: initkomega
593  implicit none
594  !
595  ! Subroutine argument.
596  !
597  integer(kind=intType), intent(inout) :: nTypeMismatch
598  !
599  ! Local variables.
600  !
601  integer :: realTypeCGNS
602 
603  integer(kind=intType) :: i, j, k, nn, po, ip, jp, kp
604  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, kBeg, kEnd
605 
606  real(kind=realtype) :: nuscale, kscale, omegascale, val
607 
608  logical :: turbKPresent, omegaPresent, eddyVisPresent
609 
610  ! Set the cell range to be copied from the buffer.
611 
612  ibeg = lbound(buffer, 1); iend = ubound(buffer, 1)
613  jbeg = lbound(buffer, 2); jend = ubound(buffer, 2)
614  kbeg = lbound(buffer, 3); kend = ubound(buffer, 3)
615 
616  ! Set the cgns real type and abbreviate the solution variable and
617  ! the pointer offset to improve readability.
618 
619  realtypecgns = setcgnsrealtype()
620 
621  po = iovar(nbklocal, solid)%pointerOffset
622  w => iovar(nbklocal, solid)%w
623 
624  ! Compute the scales for nu, k and omega.
625 
626  nuscale = muscale / rhoscale
627  kscale = velscale**2
628  omegascale = kscale / nuscale
629 
630  ! First check if k is present.
631 
632  turbkpresent = .false.
633 
635 
636  if (nn > 0) then
637 
638  ! K is present. First determine whether or not a type
639  ! mismatch occurs. If so, update nTypeMismatch.
640 
641  if (realtypecgns /= vartypes(nn)) &
642  ntypemismatch = ntypemismatch + 1
643 
644  ! Read k from the restart file and store it in buffer.
645 
646  call readrestartvariable(varnames(nn))
647 
648  ! Copy the variables from buffer into w. Multiply by the scale
649  ! factor to obtain the correct non-dimensional value and take
650  ! the possible pointer offset into account.
651 
652  do k = kbeg, kend
653  kp = k + po
654  do j = jbeg, jend
655  jp = j + po
656  do i = ibeg, iend
657  ip = i + po
658  w(ip, jp, kp, itu1) = kscale * buffer(i, j, k)
659  end do
660  end do
661  end do
662 
663  ! Set turbKPresent to .true.
664 
665  turbkpresent = .true.
666 
667  end if
668 
669  ! Check if omega is present.
670 
671  omegapresent = .false.
672 
674 
675  if (nn > 0) then
676 
677  ! Omega is present. First determine whether or not a type
678  ! mismatch occurs. If so, update nTypeMismatch.
679 
680  if (realtypecgns /= vartypes(nn)) &
681  ntypemismatch = ntypemismatch + 1
682 
683  ! Read omega from the restart file and store it in buffer.
684 
685  call readrestartvariable(varnames(nn))
686 
687  ! Copy the variables from buffer into w. Multiply by the scale
688  ! factor to obtain the correct non-dimensional value and take
689  ! the possible pointer offset into account.
690 
691  do k = kbeg, kend
692  kp = k + po
693  do j = jbeg, jend
694  jp = j + po
695  do i = ibeg, iend
696  ip = i + po
697  w(ip, jp, kp, itu2) = omegascale * buffer(i, j, k)
698  end do
699  end do
700  end do
701 
702  ! Set omegaPresent to .true.
703 
704  omegapresent = .true.
705 
706  end if
707 
708  ! If omega is not present, check if tau is present and
709  ! initialize omega accordingly.
710 
711  if (.not. omegapresent) then
712 
714 
715  if (nn > 0) then
716 
717  ! Tau is present. First determine whether or not a type
718  ! mismatch occurs. If so, update nTypeMismatch.
719 
720  if (realtypecgns /= vartypes(nn)) &
721  ntypemismatch = ntypemismatch + 1
722 
723  ! Read tau from the restart file and store it in buffer.
724 
725  call readrestartvariable(varnames(nn))
726 
727  ! Transform tau to omega and copy the variables from buffer
728  ! into w. Multiply by the scale factor to obtain the correct
729  ! non-dimensional value and take the possible pointer offset
730  ! into account.
731 
732  do k = kbeg, kend
733  kp = k + po
734  do j = jbeg, jend
735  jp = j + po
736  do i = ibeg, iend
737  ip = i + po
738 
739  val = buffer(i, j, k)
740  w(ip, jp, kp, itu2) = omegascale / max(eps, val)
741  end do
742  end do
743  end do
744 
745  ! Set omegaPresent to .true.
746 
747  omegapresent = .true.
748 
749  end if
750 
751  end if
752 
753  ! Check if both variables were present.
754  ! If so go to the check to transform omega to tau.
755 
756  if (turbkpresent .and. omegapresent) goto 1001
757 
758  ! K and omega are not both present. It is tried to construct
759  ! their values with the information that is present.
760 
761  ! Try to read the eddy viscosity.
762 
763  call readturbeddyvis(ntypemismatch, eddyvispresent)
764 
765  ! The eddy viscosity is either known or still initialized
766  ! to the free stream value. In any case determine the
767  ! situation we are dealing with and try to initialize k and
768  ! omega accordingly.
769 
770  if (turbkpresent) then
771 
772  ! K is present. Compute omega using the eddy viscosity.
773  ! Assume that the standard k-omega formula is also valid
774  ! for the SST-model.
775  ! Take the possible pointer offset into account.
776 
777  do k = kbeg, kend
778  kp = k + po
779  do j = jbeg, jend
780  jp = j + po
781  do i = ibeg, iend
782  ip = i + po
783  w(ip, jp, kp, itu2) = w(ip, jp, kp, irho) * w(ip, jp, kp, itu1) &
784  / rev(i, j, k)
785  end do
786  end do
787  end do
788 
789  ! Print a warning that omega was not present and has been
790  ! constructed. Only processor 0 does this for block 1.
791 
792  if ((myid == 0) .and. (nbklocal == 1)) then
793 
794  print "(a)", "#"
795  print "(a)", "# Warning"
796  print "(a)", "# Omega is not present in the restart file."
797  if (eddyvispresent) then
798  print "(a)", "# It is initialized using the turbulent &
799  &kinetic energy and eddy viscosity."
800  else
801  print "(a)", "# It is initialized using the turbulent &
802  &kinetic energy and free stream eddy &
803  &viscosity."
804  end if
805  print "(a)", "#"
806 
807  end if
808 
809  ! K and omega are initialized.
810  ! Go to the check to transform omega to tau.
811 
812  goto 1001
813 
814  end if
815 
816  if (omegapresent) then
817 
818  ! Omega is present. Compute k using the eddy viscosity.
819  ! Assume that the standard k-omega formula is also valid
820  ! for the SST-model.
821  ! Take the possible pointer offset into account.
822 
823  do k = kbeg, kend
824  kp = k + po
825  do j = jbeg, jend
826  jp = j + po
827  do i = ibeg, iend
828  ip = i + po
829  w(ip, jp, kp, itu1) = rev(i, j, k) * w(ip, jp, kp, itu2) &
830  / w(ip, jp, kp, irho)
831  end do
832  end do
833  end do
834 
835  ! Print a warning that k was not present and has been
836  ! constructed. Only processor 0 does this for block 1.
837 
838  if ((myid == 0) .and. (nbklocal == 1)) then
839 
840  print "(a)", "#"
841  print "(a)", "# Warning"
842  print "(a)", "# Turbulent kinetic energy is not present &
843  &in the restart file."
844  if (eddyvispresent) then
845  print "(a)", "# It is initialized using omega and &
846  &the eddy viscosity."
847  else
848  print "(a)", "# It is initialized using omega and &
849  &the free stream eddy viscosity."
850  end if
851  print "(a)", "#"
852 
853  end if
854 
855  ! K and omega are initialized.
856  ! Go to the check to transform omega to tau.
857 
858  goto 1001
859 
860  end if
861 
862  ! Both k and omega are not present. Use a guess for omega
863  ! and compute k using the known value of the eddy viscosity.
864  ! As the laminar viscosity is not yet known, set it to the
865  ! free-stream value.
866 
867  rlv = muinf
868  call initkomega(po)
869 
870  ! Print a warning that both k and omega are not present in
871  ! the restart file. Only processor 0 does this for block 1.
872 
873  if ((myid == 0) .and. (nbklocal == 1)) then
874 
875  print "(a)", "#"
876  print "(a)", "# Warning"
877  print "(a)", "# The turbulent kinetic energy and omega are &
878  &not present in the restart file."
879  if (eddyvispresent) then
880  print "(a)", "# They have been initialized using the &
881  &eddy viscosity."
882  else
883  print "(a)", "# The default initialization has been used."
884  end if
885 
886  print "(a)", "#"
887 
888  end if
889 
890  ! For the k-tau model omega must be transformed to tau.
891  ! Take the possible pointer offset into account.
892 
893 1001 select case (turbmodel)
894 
895  case (ktau)
896 
897  do k = kbeg, kend
898  kp = k + po
899  do j = jbeg, jend
900  jp = j + po
901  do i = ibeg, iend
902  ip = i + po
903  w(ip, jp, kp, itu2) = one / w(ip, jp, kp, itu2)
904  end do
905  end do
906  end do
907 
908  end select
909 
910  end subroutine readturbkwtype
911 
912  subroutine readturbsa(nTypeMismatch)
913  !
914  ! readTurbSA reads or constructs the nu tilde transport
915  ! variable for the Spalart-Allmaras type turbulence models.
916  ! If no information could be retrieved some engineering guess of
917  ! the turbulent variables is made.
918  !
919  use constants
920  use cgnsnames
921  use communication, only: myid
922  use blockpointers, only: w, nbklocal, rlv, rev
923  use iomodule, only: iovar
924  use utils, only: setcgnsrealtype, terminate
925  use sorting, only: bsearchstrings
926  use flowvarrefstate, only: muinf, winf
927  use turbutils, only: sanuknowneddyratio
928  implicit none
929  !
930  ! Subroutine argument.
931  !
932  integer(kind=intType), intent(inout) :: nTypeMismatch
933  !
934  ! Local variables.
935  !
936  integer :: realTypeCGNS
937 
938  integer(kind=intType) :: i, j, k, nn, po, ip, jp, kp
939  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, kBeg, kEnd
940 
941  real(kind=realtype) :: nuscale, ratio, nu
942 
943  logical :: eddyVisPresent
944 
945  ! Set the cell range to be copied from the buffer.
946 
947  ibeg = lbound(buffer, 1); iend = ubound(buffer, 1)
948  jbeg = lbound(buffer, 2); jend = ubound(buffer, 2)
949  kbeg = lbound(buffer, 3); kend = ubound(buffer, 3)
950 
951  ! Set the cgns real type and abbreviate the solution variable and
952  ! the pointer offset to improve readability.
953  ! Also compute the kinematic viscosity scale.
954 
955  realtypecgns = setcgnsrealtype()
956 
957  po = iovar(nbklocal, solid)%pointerOffset
958  w => iovar(nbklocal, solid)%w
959 
960  nuscale = muscale / rhoscale
961 
962  ! Check if the nu tilde variable is present.
963 
965 
966  nutildepresent: if (nn > 0) then
967 
968  ! Nu tilde is present. First determine whether or not a type
969  ! mismatch occurs. If so, update nTypeMismatch.
970 
971  if (realtypecgns /= vartypes(nn)) &
972  ntypemismatch = ntypemismatch + 1
973 
974  ! Read nu tilde from the restart file and store
975  ! it in buffer.
976 
977  call readrestartvariable(varnames(nn))
978 
979  ! Copy the variables from buffer into w and take the possible
980  ! pointer offset into account.
981 
982  do k = kbeg, kend
983  kp = k + po
984  do j = jbeg, jend
985  jp = j + po
986  do i = ibeg, iend
987  ip = i + po
988  w(ip, jp, kp, itu1) = nuscale * buffer(i, j, k)
989  end do
990  end do
991  end do
992 
993  ! Variable is read, so a return can be made.
994 
995  return
996 
997  end if nutildepresent
998 
999  ! NuTilde is not present. Try to construct the eddy viscosity.
1000 
1001  call readturbeddyvis(ntypemismatch, eddyvispresent)
1002 
1003  ! Check if the eddy viscosity has been constructed.
1004 
1005  eddypresent: if (eddyvispresent) then
1006 
1007  ! Eddy viscosity is present. As the laminar viscosity is not
1008  ! yet known, set it to the free-stream value.
1009 
1010  rlv = muinf
1011 
1012  ! Compute nuTilde from the known ratio of eddy and laminar
1013  ! viscosity. Take the possible pointer offset into account.
1014 
1015  do k = kbeg, kend
1016  kp = k + po
1017  do j = jbeg, jend
1018  jp = j + po
1019  do i = ibeg, iend
1020  ip = i + po
1021 
1022  ! Compute the eddy viscosity ratio and the laminar
1023  ! kinematic viscosity and call the function to
1024  ! compute the nu tilde variable.
1025 
1026  ratio = rev(i, j, k) / rlv(i, j, k)
1027  nu = rlv(i, j, k) / w(ip, jp, kp, irho)
1028  w(ip, jp, kp, itu1) = sanuknowneddyratio(ratio, nu)
1029 
1030  end do
1031  end do
1032  end do
1033 
1034  ! Print a warning that nu tilde has been constructed and
1035  ! not read. Only processor 0 does this for block 1.
1036 
1037  if ((myid == 0) .and. (nbklocal == 1)) then
1038 
1039  print "(a)", "#"
1040  print "(a)", "# Warning"
1041  print "(a)", "# Nu tilde for Spalart-Allmaras model not &
1042  &present in the restart file."
1043  print "(a)", "# Variable has been reconstructed from &
1044  &the eddy viscosity ratio."
1045  print "(a)", "#"
1046 
1047  end if
1048 
1049  ! Variable is constructed, so a return can be made.
1050 
1051  return
1052 
1053  end if eddypresent
1054 
1055  ! No turbulence info is present in the restart file.
1056  ! Initialize nu tilde to the free stream value.
1057  ! Take the possible pointer offset into account.
1058 
1059  do k = kbeg, kend
1060  kp = k + po
1061  do j = jbeg, jend
1062  jp = j + po
1063  do i = ibeg, iend
1064  ip = i + po
1065  w(ip, jp, kp, itu1) = winf(itu1)
1066  end do
1067  end do
1068  end do
1069 
1070  ! Print a warning that nu tilde has been set to the
1071  ! free stream values. Only processor 0 does this for block 1.
1072 
1073  if ((myid == 0) .and. (nbklocal == 1)) then
1074 
1075  print "(a)", "#"
1076  print "(a)", "# Warning"
1077  print "(a)", "# No turbulent info present in the restart file."
1078  print "(a)", "# Nu tilde for Spalart-Allmaras model has &
1079  &been set to the free stream value."
1080  print "(a)", "#"
1081 
1082  end if
1083 
1084  end subroutine readturbsa
1085  subroutine readturbv2f(nTypeMismatch)
1086  !
1087  ! readTurbV2f reads or constructs the four transport variables
1088  ! for the v2f model. If no information could be retrieved some
1089  ! engineering guess of the turbulent variables is made.
1090  !
1091  use constants
1092  use cgnsnames
1093  use communication, only: myid
1094  use blockpointers, only: w, nbklocal
1095  use iomodule, only: iovar
1096  use utils, only: setcgnsrealtype, terminate
1097  use sorting, only: bsearchstrings
1098  use flowvarrefstate, only: winf, nt1, nt2
1099  implicit none
1100  !
1101  ! Subroutine argument.
1102  !
1103  integer(kind=intType), intent(inout) :: nTypeMismatch
1104  !
1105  ! Local variables.
1106  !
1107  integer :: realTypeCGNS, itu
1108  integer, dimension(4) :: indW
1109 
1110  integer(kind=intType) :: i, j, k, ii, nn, po, ip, jp, kp
1111  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, kBeg, kEnd
1112 
1113  real(kind=realtype) :: nuscale, kscale, epsscale, fscale
1114 
1115  real(kind=realtype), dimension(4) :: turbscale
1116 
1117  character(len=maxCGNSNameLen), dimension(4) :: namesVar
1118 
1119  ! Set the cell range to be copied from the buffer.
1120 
1121  ibeg = lbound(buffer, 1); iend = ubound(buffer, 1)
1122  jbeg = lbound(buffer, 2); jend = ubound(buffer, 2)
1123  kbeg = lbound(buffer, 3); kend = ubound(buffer, 3)
1124 
1125  ! Set the cgns real type and abbreviate the solution variable and
1126  ! the pointer offset to improve readability.
1127 
1128  realtypecgns = setcgnsrealtype()
1129 
1130  po = iovar(nbklocal, solid)%pointerOffset
1131  w => iovar(nbklocal, solid)%w
1132 
1133  ! Set the names and indices for the four variables.
1134 
1135  indw(1) = itu1; namesvar(1) = cgnsturbk
1136  indw(2) = itu2; namesvar(2) = cgnsturbepsilon
1137  indw(3) = itu3; namesvar(3) = cgnsturbv2
1138  indw(4) = itu4; namesvar(4) = cgnsturbf
1139 
1140  ! Compute the scales for nu, k, epsilon and f; v2 has the same
1141  ! scaling as k.
1142 
1143  nuscale = muscale / rhoscale
1144  kscale = velscale**2
1145  fscale = kscale / nuscale
1146  epsscale = kscale * fscale
1147 
1148  turbscale(1) = kscale
1149  turbscale(2) = epsscale
1150  turbscale(3) = kscale
1151  turbscale(4) = fscale
1152 
1153  ! Loop over the four variables of the v2f model.
1154 
1155  varloop: do ii = 1, 4
1156 
1157  ! Find the index of the variable in the solution file and check
1158  ! if it is present. If not exit the loop.
1159 
1160  nn = bsearchstrings(namesvar(ii), varnames)
1161 
1162  if (nn == 0) exit
1163 
1164  ! Variable is present. First determine whether or not a type
1165  ! mismatch occurs. If so, update nTypeMismatch.
1166 
1167  if (realtypecgns /= vartypes(nn)) &
1168  ntypemismatch = ntypemismatch + 1
1169 
1170  ! Read the variable from the restart file and store
1171  ! it in buffer.
1172 
1173  call readrestartvariable(varnames(nn))
1174 
1175  ! Copy the variables from buffer into w.
1176  ! Take the possible pointer offset into account.
1177 
1178  itu = indw(ii)
1179 
1180  do k = kbeg, kend
1181  kp = k + po
1182  do j = jbeg, jend
1183  jp = j + po
1184  do i = ibeg, iend
1185  ip = i + po
1186  w(ip, jp, kp, itu) = turbscale(ii) * buffer(i, j, k)
1187  end do
1188  end do
1189  end do
1190 
1191  end do varloop
1192 
1193  ! Check if all variables were present. If not, set all turbulence
1194  ! variables to the free-stream values.
1195 
1196  testpresent: if (ii <= 4) then
1197 
1198  ! Not all variables are present. Set all 4 to the free-stream
1199  ! values. Take the possible pointer offset into account.
1200 
1201  do ii = nt1, nt2
1202  do k = kbeg, kend
1203  kp = k + po
1204  do j = jbeg, jend
1205  jp = j + po
1206  do i = ibeg, iend
1207  ip = i + po
1208  w(ip, jp, kp, ii) = winf(ii)
1209  end do
1210  end do
1211  end do
1212  end do
1213 
1214  ! Print a warning that the turbulence has been initialized to
1215  ! the free-stream. Only processor 0 does this for block 1.
1216 
1217  if ((myid == 0) .and. (nbklocal == 1)) then
1218 
1219  print "(a)", "#"
1220  print "(a)", "# Warning"
1221  print "(a)", "# Not all turbulence variables are present &
1222  &for the v2f model."
1223  print "(a)", "# They have been initialized to the free &
1224  &stream values."
1225  print "(a)", "#"
1226 
1227  end if
1228 
1229  end if testpresent
1230 
1231  end subroutine readturbv2f
1232 
1233  subroutine readturbvar(nTypeMismatch)
1234  !
1235  ! readTurbvar controls the reading of the turbulent variables
1236  ! for a restart. It calls the routine, which corresponds to the
1237  ! turbulence model used.
1238  !
1239  use constants
1241  use inputphysics, only: equations, turbmodel
1242  use utils, only: terminate
1243  implicit none
1244  !
1245  ! Subroutine argument.
1246  !
1247  integer(kind=intType), intent(inout) :: nTypeMismatch
1248  !
1249  ! Local variables.
1250  !
1251  integer :: ierr
1252 
1253  ! Check if the rans equations must be solved. If not return.
1254 
1255  if (equations /= ransequations) return
1256 
1257  ! Determine the turbulence model to be used and call the
1258  ! appropriate subroutine.
1259 
1260  select case (turbmodel)
1261 
1263  call readturbsa(ntypemismatch)
1264 
1265  ! !===============================================================
1266 
1267  ! case (komegaWilcox, komegaModified, menterSST, ktau)
1268  ! call readTurbKwType(nTypeMismatch)
1269 
1270  ! !===============================================================
1271 
1272  ! case (v2f)
1273  ! call readTurbV2f(nTypeMismatch)
1274 
1275  !===============================================================
1276 
1277  case default
1278  if (myid == 0) &
1279  call terminate("readTurbvar", "Restart not implemented &
1280  &for this turbulence model.")
1281  call mpi_barrier(adflow_comm_world, ierr)
1282 
1283  end select
1284 
1285  end subroutine readturbvar
1286 
1287  subroutine readxmomentum(nTypeMismatch)
1288  !
1289  ! readXmomentum reads the x-momentum variable from the given
1290  ! place in the cgns file. If the x-momentum itself is not stored
1291  ! then it is tried to construct it from the x-velocity and
1292  ! density; it is assumed that the latter is already stored in
1293  ! the pointer variable w.
1294  ! If it is not possible to create the x-velocity an error
1295  ! message is printed and the program will stop.
1296  ! It is assumed that the pointers in blockPointers already
1297  ! point to the correct block.
1298  !
1299  use constants
1300  use cgnsnames
1301  use blockpointers, only: w, nbklocal
1302  use iomodule, only: iovar
1303  use utils, only: setcgnsrealtype, terminate
1304  use sorting, only: bsearchstrings
1305 
1306  implicit none
1307  !
1308  ! Subroutine argument.
1309  !
1310  integer(kind=intType), intent(inout) :: nTypeMismatch
1311  !
1312  ! Local variables
1313  !
1314  integer :: realTypeCGNS
1315 
1316  integer(kind=intType) :: i, j, k, nn, mm, po, ip, jp, kp
1317  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, kBeg, kEnd
1318 
1319  real(kind=realtype) :: momscale
1320 
1321  ! Set the cell range to be copied from the buffer.
1322 
1323  ibeg = lbound(buffer, 1); iend = ubound(buffer, 1)
1324  jbeg = lbound(buffer, 2); jend = ubound(buffer, 2)
1325  kbeg = lbound(buffer, 3); kend = ubound(buffer, 3)
1326 
1327  ! Compute the momentum scaling factor, set the cgns real type and
1328  ! abbreviate the solution variable and the pointer offset to
1329  ! improve readability.
1330 
1331  momscale = rhoscale * velscale
1332  realtypecgns = setcgnsrealtype()
1333 
1334  po = iovar(nbklocal, solid)%pointerOffset
1335  w => iovar(nbklocal, solid)%w
1336 
1337  ! Find out if the X-momentum is present in the solution file.
1338 
1340 
1341  testmxpresent: if (nn > 0) then
1342 
1343  ! X-momentum is present. First determine whether or not a type
1344  ! mismatch occurs. If so, update nTypeMismatch.
1345 
1346  if (realtypecgns /= vartypes(nn)) &
1347  ntypemismatch = ntypemismatch + 1
1348 
1349  ! Read the x-momentum from the restart file and store it in buffer.
1350 
1351  call readrestartvariable(varnames(nn))
1352 
1353  ! Copy the variables from buffer into w. Multiply by the scale
1354  ! factor to obtain the correct non-dimensional value and take
1355  ! the possible pointer offset into account.
1356 
1357  do k = kbeg, kend
1358  kp = k + po
1359  do j = jbeg, jend
1360  jp = j + po
1361  do i = ibeg, iend
1362  ip = i + po
1363  w(ip, jp, kp, imx) = buffer(i, j, k) * momscale
1364  end do
1365  end do
1366  end do
1367 
1368  ! X-momentum is read, so a return can be made.
1369 
1370  return
1371 
1372  end if testmxpresent
1373 
1374  ! X-momentum is not present. Check for x-velocity.
1375 
1377 
1378  testvxpresent: if (nn > 0) then
1379 
1380  ! X-velocity is present. First determine whether or not a type
1381  ! mismatch occurs. If so, update nTypeMismatch.
1382 
1383  if (realtypecgns /= vartypes(nn)) &
1384  ntypemismatch = ntypemismatch + 1
1385 
1386  ! Read the x-velocity from the restart file and store it in buffer.
1387 
1388  call readrestartvariable(varnames(nn))
1389 
1390  ! Copy the variables from buffer into w. Multiply by the
1391  ! density and velocity scaling factor to obtain to correct
1392  ! non-dimensional value. Take the possible pointer offset
1393  ! into account.
1394 
1395  do k = kbeg, kend
1396  kp = k + po
1397  do j = jbeg, jend
1398  jp = j + po
1399  do i = ibeg, iend
1400  ip = i + po
1401  w(ip, jp, kp, imx) = buffer(i, j, k) * w(ip, jp, kp, irho) * velscale
1402  end do
1403  end do
1404  end do
1405 
1406  ! X-momentum is constructed, so a return can be made.
1407 
1408  return
1409 
1410  end if testvxpresent
1411 
1412  ! X-momentum could not be created. Terminate.
1413 
1414  call terminate("readXmomentum", &
1415  "X-Momentum could not be created")
1416 
1417  end subroutine readxmomentum
1418 
1419  subroutine readxvelocity(nTypeMismatch)
1420  !
1421  ! readXvelocity reads the x-velocity variable from the given
1422  ! place in the cgns file. If the x-velocity itself is not stored
1423  ! then it is tried to construct it from the x-momentum and
1424  ! density; it is assumed that the latter is already stored in
1425  ! the pointer variable w.
1426  ! If it is not possible to create the x-velocity an error
1427  ! message is printed and the program will stop.
1428  ! It is assumed that the pointers in blockPointers already
1429  ! point to the correct block.
1430  !
1431  use constants
1432  use cgnsnames
1433  use blockpointers, only: w, nbklocal
1434  use iomodule, only: iovar
1435  use utils, only: setcgnsrealtype, terminate
1436  use sorting, only: bsearchstrings
1437  !
1438  ! Subroutine argument.
1439  !
1440  integer(kind=intType), intent(inout) :: nTypeMismatch
1441  !
1442  ! Local variables
1443  !
1444  integer :: realTypeCGNS
1445 
1446  integer(kind=intType) :: i, j, k, nn, po, ip, jp, kp
1447  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, kBeg, kEnd
1448 
1449  real(kind=realtype) :: scale
1450 
1451  ! Set the cell range to be copied from the buffer.
1452 
1453  ibeg = lbound(buffer, 1); iend = ubound(buffer, 1)
1454  jbeg = lbound(buffer, 2); jend = ubound(buffer, 2)
1455  kbeg = lbound(buffer, 3); kend = ubound(buffer, 3)
1456 
1457  ! Set the cgns real type and abbreviate the solution variable and
1458  ! the pointer offset to improve readability.
1459 
1460  realtypecgns = setcgnsrealtype()
1461 
1462  po = iovar(nbklocal, solid)%pointerOffset
1463  w => iovar(nbklocal, solid)%w
1464 
1465  ! Find out if the x-velocity is present in the solution file.
1466 
1468  if (nn > 0) then
1469 
1470  ! X-velocity is present. First determine whether or not a type
1471  ! mismatch occurs. If so, update nTypeMismatch.
1472 
1473  if (realtypecgns /= vartypes(nn)) &
1474  ntypemismatch = ntypemismatch + 1
1475 
1476  ! Read the x-velocity from the restart file and store it
1477  ! in buffer.
1478 
1479  call readrestartvariable(varnames(nn))
1480 
1481  ! Copy the variables from buffer into w. Multiply by the scale
1482  ! factor to obtain the correct nondimensional value and take
1483  ! the possible pointer offset into account.
1484 
1485  do k = kbeg, kend
1486  kp = k + po
1487  do j = jbeg, jend
1488  jp = j + po
1489  do i = ibeg, iend
1490  ip = i + po
1491  w(ip, jp, kp, ivx) = buffer(i, j, k) * velscale
1492  end do
1493  end do
1494  end do
1495 
1496  ! X-velocity is read, so a return can be made.
1497 
1498  return
1499 
1500  end if
1501 
1502  ! X-velocity not present. Check for x-momentum.
1503 
1505  if (nn > 0) then
1506 
1507  ! X-momentum is present. First determine whether or not a type
1508  ! mismatch occurs. If so, update nTypeMismatch.
1509 
1510  if (realtypecgns /= vartypes(nn)) &
1511  ntypemismatch = ntypemismatch + 1
1512 
1513  ! Read the x-momentum from the restart file and store
1514  ! it in buffer.
1515 
1516  call readrestartvariable(varnames(nn))
1517 
1518  ! Construct the x-velocity; it is assumed that the density is
1519  ! already stored in w. Multiply by the momentum scale factor
1520  ! to obtain the correct nondimensional value and take the
1521  ! possible pointer offset into account.
1522 
1523  scale = rhoscale * velscale
1524 
1525  do k = kbeg, kend
1526  kp = k + po
1527  do j = jbeg, jend
1528  jp = j + po
1529  do i = ibeg, iend
1530  ip = i + po
1531  w(ip, jp, kp, ivx) = buffer(i, j, k) * scale / w(ip, jp, kp, irho)
1532  end do
1533  end do
1534  end do
1535 
1536  ! X-velocity is constructed, so a return can be made.
1537 
1538  return
1539 
1540  end if
1541 
1542  ! Not able to determine the x-velocity.
1543  ! Print an error message and exit.
1544 
1545  call terminate("readXvelocity", &
1546  "Not able to retrieve x-velocity from the &
1547  &variables in the restart file.")
1548 
1549  end subroutine readxvelocity
1550 
1551  subroutine readymomentum(nTypeMismatch)
1552  !
1553  ! readYmomentum reads the y-momentum variable from the given
1554  ! place in the cgns file. If the y-momentum itself is not stored
1555  ! then it is tried to construct it from the y-velocity and
1556  ! density; it is assumed that the latter is already stored in
1557  ! the pointer variable w.
1558  ! If it is not possible to create the y-velocity an error
1559  ! message is printed and the program will stop.
1560  ! It is assumed that the pointers in blockPointers already
1561  ! point to the correct block.
1562  !
1563  use constants
1564  use cgnsnames
1565  use blockpointers, only: w, nbklocal
1566  use iomodule, only: iovar
1567  use utils, only: setcgnsrealtype, terminate
1568  use sorting, only: bsearchstrings
1569  implicit none
1570  !
1571  ! Subroutine argument.
1572  !
1573  integer(kind=intType), intent(inout) :: nTypeMismatch
1574  !
1575  ! Local variables
1576  !
1577  integer :: realTypeCGNS
1578 
1579  integer(kind=intType) :: i, j, k, nn, po, ip, jp, kp
1580  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, kBeg, kEnd
1581 
1582  real(kind=realtype) :: momscale
1583 
1584  ! Set the cell range to be copied from the buffer.
1585 
1586  ibeg = lbound(buffer, 1); iend = ubound(buffer, 1)
1587  jbeg = lbound(buffer, 2); jend = ubound(buffer, 2)
1588  kbeg = lbound(buffer, 3); kend = ubound(buffer, 3)
1589 
1590  ! Compute the momentum scaling factor, set the cgns real type and
1591  ! abbreviate the solution variable and the pointer offset to
1592  ! improve readability.
1593 
1594  momscale = rhoscale * velscale
1595  realtypecgns = setcgnsrealtype()
1596 
1597  po = iovar(nbklocal, solid)%pointerOffset
1598  w => iovar(nbklocal, solid)%w
1599 
1600  ! Find out if the Y-momentum is present in the solution file.
1601 
1603 
1604  testmypresent: if (nn > 0) then
1605 
1606  ! Y-momentum is present. First determine whether or not a type
1607  ! mismatch occurs. If so, update nTypeMismatch.
1608 
1609  if (realtypecgns /= vartypes(nn)) &
1610  ntypemismatch = ntypemismatch + 1
1611 
1612  ! Read the y-momentum from the restart file and store it in buffer.
1613 
1614  call readrestartvariable(varnames(nn))
1615 
1616  ! Copy the variables from buffer into w. Multiply by the scale
1617  ! factor to obtain the correct non-dimensional value and take
1618  ! the possible pointer offset into account.
1619 
1620  do k = kbeg, kend
1621  kp = k + po
1622  do j = jbeg, jend
1623  jp = j + po
1624  do i = ibeg, iend
1625  ip = i + po
1626  w(ip, jp, kp, imy) = buffer(i, j, k) * momscale
1627  end do
1628  end do
1629  end do
1630 
1631  ! Y-momentum is read, so a return can be made.
1632 
1633  return
1634 
1635  end if testmypresent
1636 
1637  ! Y-momentum is not present. Check for y-velocity.
1638 
1640 
1641  testvypresent: if (nn > 0) then
1642 
1643  ! Y-velocity is present. First determine whether or not a type
1644  ! mismatch occurs. If so, update nTypeMismatch.
1645 
1646  if (realtypecgns /= vartypes(nn)) &
1647  ntypemismatch = ntypemismatch + 1
1648 
1649  ! Read the y-velocity from the restart file and store it in buffer.
1650 
1651  call readrestartvariable(varnames(nn))
1652 
1653  ! Copy the variables from buffer into w. Multiply by the
1654  ! density and velocity scaling factor to obtain to correct
1655  ! non-dimensional value. Take the possible pointer offset
1656  ! into account.
1657 
1658  do k = kbeg, kend
1659  kp = k + po
1660  do j = jbeg, jend
1661  jp = j + po
1662  do i = ibeg, iend
1663  ip = i + po
1664  w(ip, jp, kp, imy) = buffer(i, j, k) * w(ip, jp, kp, irho) * velscale
1665  end do
1666  end do
1667  end do
1668 
1669  ! Y-momentum is constructed, so a return can be made.
1670 
1671  return
1672 
1673  end if testvypresent
1674 
1675  ! Y-momentum could not be created. Terminate.
1676 
1677  call terminate("readYmomentum", &
1678  "Y-Momentum could not be created")
1679 
1680  end subroutine readymomentum
1681 
1682  subroutine readyvelocity(nTypeMismatch)
1683  !
1684  ! readYvelocity reads the y-velocity variable from the given
1685  ! place in the cgns file. If the y-velocity itself is not stored
1686  ! then it is tried to construct it from the y-momentum and
1687  ! density; it is assumed that the latter is already stored in
1688  ! the pointer variable w.
1689  ! If it is not possible to create the y-velocity an error
1690  ! message is printed and the program will stop.
1691  ! It is assumed that the pointers in blockPointers already
1692  ! point to the correct block.
1693  !
1694  use constants
1695  use cgnsnames
1696  use blockpointers, only: w, nbklocal
1697  use iomodule, only: iovar
1698  use utils, only: setcgnsrealtype, terminate
1699  use sorting, only: bsearchstrings
1700 
1701  implicit none
1702  !
1703  ! Subroutine argument.
1704  !
1705  integer(kind=intType), intent(inout) :: nTypeMismatch
1706  !
1707  ! Local variables
1708  !
1709  integer :: realTypeCGNS
1710 
1711  integer(kind=intType) :: i, j, k, nn, po, ip, jp, kp
1712  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, kBeg, kEnd
1713 
1714  real(kind=realtype) :: scale
1715 
1716  ! Set the cell range to be copied from the buffer.
1717 
1718  ibeg = lbound(buffer, 1); iend = ubound(buffer, 1)
1719  jbeg = lbound(buffer, 2); jend = ubound(buffer, 2)
1720  kbeg = lbound(buffer, 3); kend = ubound(buffer, 3)
1721 
1722  ! Set the cgns real type and abbreviate the solution variable and
1723  ! the pointer offset to improve readability.
1724 
1725  realtypecgns = setcgnsrealtype()
1726 
1727  po = iovar(nbklocal, solid)%pointerOffset
1728  w => iovar(nbklocal, solid)%w
1729 
1730  ! Find out if the y-velocity is present in the solution file.
1731 
1733  if (nn > 0) then
1734 
1735  ! Y-velocity is present. First determine whether or not a type
1736  ! mismatch occurs. If so, update nTypeMismatch.
1737 
1738  if (realtypecgns /= vartypes(nn)) &
1739  ntypemismatch = ntypemismatch + 1
1740 
1741  ! Read the y-velocity from the restart file and store it
1742  ! in buffer.
1743 
1744  call readrestartvariable(varnames(nn))
1745 
1746  ! Copy the variables from buffer into w. Multiply by the scale
1747  ! factor to obtain the correct nondimensional value and take
1748  ! the possible pointer offset into account.
1749 
1750  do k = kbeg, kend
1751  kp = k + po
1752  do j = jbeg, jend
1753  jp = j + po
1754  do i = ibeg, iend
1755  ip = i + po
1756  w(ip, jp, kp, ivy) = buffer(i, j, k) * velscale
1757  end do
1758  end do
1759  end do
1760 
1761  ! Y-velocity is read, so a return can be made.
1762 
1763  return
1764 
1765  end if
1766 
1767  ! Y-velocity not present. Check for y-momentum.
1768 
1770  if (nn > 0) then
1771 
1772  ! Y-momentum is present. First determine whether or not a type
1773  ! mismatch occurs. If so, update nTypeMismatch.
1774 
1775  if (realtypecgns /= vartypes(nn)) &
1776  ntypemismatch = ntypemismatch + 1
1777 
1778  ! Read the y-momentum from the restart file and store
1779  ! it in buffer.
1780 
1781  call readrestartvariable(varnames(nn))
1782 
1783  ! Construct the y-velocity; it is assumed that the density is
1784  ! already stored in w. Multiply by the momentum scale factor
1785  ! to obtain the correct nondimensional value and take the
1786  ! possible pointer offset into account.
1787 
1788  scale = rhoscale * velscale
1789 
1790  do k = kbeg, kend
1791  kp = k + po
1792  do j = jbeg, jend
1793  jp = j + po
1794  do i = ibeg, iend
1795  ip = i + po
1796  w(ip, jp, kp, ivy) = buffer(i, j, k) * scale / w(ip, jp, kp, irho)
1797  end do
1798  end do
1799  end do
1800 
1801  ! Y-velocity is constructed, so a return can be made.
1802 
1803  return
1804 
1805  end if
1806 
1807  ! Not able to determine the y-velocity.
1808  ! Print an error message and exit.
1809 
1810  call terminate("readYvelocity", &
1811  "Not able to retrieve y-velocity from the &
1812  &variables in the restart file.")
1813 
1814  end subroutine readyvelocity
1815  subroutine readzmomentum(nTypeMismatch)
1816  !
1817  ! readZmomentum reads the z-momentum variable from the given
1818  ! place in the cgns file. If the z-momentum itself is not stored
1819  ! then it is tried to construct it from the z-velocity and
1820  ! density; it is assumed that the latter is already stored in
1821  ! the pointer variable w.
1822  ! If it is not possible to create the z-velocity an error
1823  ! message is printed and the program will stop.
1824  ! It is assumed that the pointers in blockPointers already
1825  ! point to the correct block.
1826  !
1827  use constants
1828  use cgnsnames
1829  use blockpointers, only: w, nbklocal
1830  use iomodule, only: iovar
1831  use utils, only: setcgnsrealtype, terminate
1832  use sorting, only: bsearchstrings
1833  implicit none
1834  !
1835  ! Subroutine argument.
1836  !
1837  integer(kind=intType), intent(inout) :: nTypeMismatch
1838  !
1839  ! Local variables
1840  !
1841  integer :: realTypeCGNS
1842 
1843  integer(kind=intType) :: i, j, k, nn, po, ip, jp, kp
1844  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, kBeg, kEnd
1845 
1846  real(kind=realtype) :: momscale
1847 
1848  ! Set the cell range to be copied from the buffer.
1849 
1850  ibeg = lbound(buffer, 1); iend = ubound(buffer, 1)
1851  jbeg = lbound(buffer, 2); jend = ubound(buffer, 2)
1852  kbeg = lbound(buffer, 3); kend = ubound(buffer, 3)
1853 
1854  ! Compute the momentum scaling factor, set the cgns real type and
1855  ! abbreviate the solution variable and the pointer offset to
1856  ! improve readability.
1857 
1858  momscale = rhoscale * velscale
1859  realtypecgns = setcgnsrealtype()
1860 
1861  po = iovar(nbklocal, solid)%pointerOffset
1862  w => iovar(nbklocal, solid)%w
1863 
1864  ! Find out if the Z-momentum is present in the solution file.
1865 
1867 
1868  testmzpresent: if (nn > 0) then
1869 
1870  ! Z-momentum is present. First determine whether or not a type
1871  ! mismatch occurs. If so, update nTypeMismatch.
1872 
1873  if (realtypecgns /= vartypes(nn)) &
1874  ntypemismatch = ntypemismatch + 1
1875 
1876  ! Read the z-momentum from the restart file and store it in buffer.
1877 
1878  call readrestartvariable(varnames(nn))
1879 
1880  ! Copy the variables from buffer into w. Multiply by the scale
1881  ! factor to obtain the correct non-dimensional value and take
1882  ! the possible pointer offset into account.
1883 
1884  do k = kbeg, kend
1885  kp = k + po
1886  do j = jbeg, jend
1887  jp = j + po
1888  do i = ibeg, iend
1889  ip = i + po
1890  w(ip, jp, kp, imz) = buffer(i, j, k) * momscale
1891  end do
1892  end do
1893  end do
1894 
1895  ! Z-momentum is read, so a return can be made.
1896 
1897  return
1898 
1899  end if testmzpresent
1900 
1901  ! Z-momentum is not present. Check for z-velocity.
1902 
1904 
1905  testvzpresent: if (nn > 0) then
1906 
1907  ! Z-velocity is present. First determine whether or not a type
1908  ! mismatch occurs. If so, update nTypeMismatch.
1909 
1910  if (realtypecgns /= vartypes(nn)) &
1911  ntypemismatch = ntypemismatch + 1
1912 
1913  ! Read the z-velocity from the restart file and store it in buffer.
1914 
1915  call readrestartvariable(varnames(nn))
1916 
1917  ! Copy the variables from buffer into w. Multiply by the
1918  ! density and velocity scaling factor to obtain to correct
1919  ! non-dimensional value. Take the possible pointer offset
1920  ! into account.
1921 
1922  do k = kbeg, kend
1923  kp = k + po
1924  do j = jbeg, jend
1925  jp = j + po
1926  do i = ibeg, iend
1927  ip = i + po
1928  w(ip, jp, kp, imz) = buffer(i, j, k) * w(ip, jp, kp, irho) * velscale
1929  end do
1930  end do
1931  end do
1932 
1933  ! Z-momentum is constructed, so a return can be made.
1934 
1935  return
1936 
1937  end if testvzpresent
1938 
1939  ! Z-momentum could not be created. Terminate.
1940 
1941  call terminate("readZmomentum", &
1942  "Z-Momentum could not be created")
1943 
1944  end subroutine readzmomentum
1945  subroutine readzvelocity(nTypeMismatch)
1946  !
1947  ! readZvelocity reads the z-velocity variable from the given
1948  ! place in the cgns file. If the z-velocity itself is not stored
1949  ! then it is tried to construct it from the z-momentum and
1950  ! density; it is assumed that the latter is already stored in
1951  ! the pointer variable w.
1952  ! If it is not possible to create the z-velocity an error
1953  ! message is printed and the program will stop.
1954  ! It is assumed that the pointers in blockPointers already
1955  ! point to the correct block.
1956  !
1957  use constants
1958  use cgnsnames
1959  use blockpointers, only: w, nbklocal
1960  use iomodule, only: iovar
1961  use utils, only: setcgnsrealtype, terminate
1962  use sorting, only: bsearchstrings
1963  implicit none
1964  !
1965  ! Subroutine argument.
1966  !
1967  integer(kind=intType), intent(inout) :: nTypeMismatch
1968  !
1969  ! Local variables
1970  !
1971  integer :: realTypeCGNS
1972 
1973  integer(kind=intType) :: i, j, k, nn, po, ip, jp, kp
1974  integer(kind=intType) :: iBeg, iEnd, jBeg, jEnd, kBeg, kEnd
1975 
1976  real(kind=realtype) :: scale
1977 
1978  ! Set the cell range to be copied from the buffer.
1979 
1980  ibeg = lbound(buffer, 1); iend = ubound(buffer, 1)
1981  jbeg = lbound(buffer, 2); jend = ubound(buffer, 2)
1982  kbeg = lbound(buffer, 3); kend = ubound(buffer, 3)
1983 
1984  ! Set the cgns real type and abbreviate the solution variable and
1985  ! the pointer offset to improve readability.
1986 
1987  realtypecgns = setcgnsrealtype()
1988 
1989  po = iovar(nbklocal, solid)%pointerOffset
1990  w => iovar(nbklocal, solid)%w
1991 
1992  ! Find out if the z-velocity is present in the solution file.
1993 
1995  if (nn > 0) then
1996 
1997  ! Z-velocity is present. First determine whether or not a type
1998  ! mismatch occurs. If so, update nTypeMismatch.
1999 
2000  if (realtypecgns /= vartypes(nn)) &
2001  ntypemismatch = ntypemismatch + 1
2002 
2003  ! Read the z-velocity from the restart file and store it
2004  ! in buffer.
2005 
2006  call readrestartvariable(varnames(nn))
2007 
2008  ! Copy the variables from buffer into w. Multiply by the scale
2009  ! factor to obtain the correct nondimensional value and take
2010  ! the possible pointer offset into account.
2011 
2012  do k = kbeg, kend
2013  kp = k + po
2014  do j = jbeg, jend
2015  jp = j + po
2016  do i = ibeg, iend
2017  ip = i + po
2018  w(ip, jp, kp, ivz) = buffer(i, j, k) * velscale
2019  end do
2020  end do
2021  end do
2022 
2023  ! Z-velocity is read, so a return can be made.
2024 
2025  return
2026 
2027  end if
2028 
2029  ! Z-velocity not present. Check for z-momentum.
2030 
2032  if (nn > 0) then
2033 
2034  ! Z-momentum is present. First determine whether or not a type
2035  ! mismatch occurs. If so, update nTypeMismatch.
2036 
2037  if (realtypecgns /= vartypes(nn)) &
2038  ntypemismatch = ntypemismatch + 1
2039 
2040  ! Read the z-momentum from the restart file and store
2041  ! it in buffer.
2042 
2043  call readrestartvariable(varnames(nn))
2044 
2045  ! Construct the z-velocity; it is assumed that the density is
2046  ! already stored in w. Multiply by the momentum scale factor
2047  ! to obtain the correct nondimensional value and take the
2048  ! possible pointer offset into account.
2049 
2050  scale = rhoscale * velscale
2051 
2052  do k = kbeg, kend
2053  kp = k + po
2054  do j = jbeg, jend
2055  jp = j + po
2056  do i = ibeg, iend
2057  ip = i + po
2058  w(ip, jp, kp, ivz) = buffer(i, j, k) * scale / w(ip, jp, kp, irho)
2059  end do
2060  end do
2061  end do
2062 
2063  ! Z-velocity is constructed, so a return can be made.
2064 
2065  return
2066 
2067  end if
2068 
2069  ! Not able to determine the z-velocity.
2070  ! Print an error message and exit.
2071 
2072  call terminate("readZvelocity", &
2073  "Not able to retrieve z-velocity from the &
2074  &variables in the restart file.")
2075 
2076  end subroutine readzvelocity
2077 
2078  subroutine readtimehistory(fileIDs)
2079  !
2080  ! readTimeHistory attempts to read the time history of an
2081  ! unsteady computation from the given cgns restart file.
2082  ! If present it will be stored in the arrays timeArray and
2083  ! timeDataArray, for which memory is allocated.
2084  !
2085  use constants
2086  use cgnsnames
2087  use su_cgns
2088  use inputunsteady, only: ntimestepsfine
2091  use sorting, only: qsortstrings, bsearchstrings
2093  use commonformats, only: strings
2094  implicit none
2095  !
2096  ! Subroutine arguments.
2097  !
2098  integer, dimension(nSolsRead), intent(in) :: fileIDs
2099 
2100  !
2101  ! Local variables.
2102  !
2103  integer :: ierr, realTypeCGNS, dummyInt
2104  integer :: i, nConv, nDim
2105  integer(kind=cgsize_t) :: nSize(1)
2106 
2107  integer(kind=intType) :: j, ii, nn
2108 
2109  integer(kind=intType), dimension(:), allocatable :: ind
2110 
2111  character(len=maxCGNSNameLen) :: cgnsName
2112  character(len=maxCGNSNameLen), allocatable, dimension(:) :: &
2113  convNames, tmpNames
2114 
2115  logical :: allConvInfo
2116 
2117  ! Store the file ID and the base a bit easier. Note that the time
2118  ! history only needs to be present in the first solution file.
2119 
2120  cgnsind = fileids(1)
2121  cgnsbase = 1
2122 
2123  ! Set the cgns real type.
2124 
2125  realtypecgns = setcgnsrealtype()
2126 
2127  ! Check if the time history is present by trying to read it.
2128 
2129  call cg_biter_read_f(cgnsind, cgnsbase, cgnsname, &
2130  dummyint, ierr)
2131  if (ierr /= all_ok) then
2132 
2133  ! No time history present. Set nTimeStepsRestart and
2134  ! timeUnsteadyRestart to zero, allocate the memory for the
2135  ! time history of the monitoring variables, print a warning
2136  ! and return.
2137 
2138  ntimestepsrestart = 0
2140 
2142 
2143  print "(a)", "#"
2144  print "(a)", "# Warning"
2145  print "(a)", "# No time history found in restart file."
2146  print "(a)", "# Starting at timestep 1 on the finest level."
2147  print "(a)", "#"
2148 
2149  return
2150 
2151  end if
2152 
2153  ! Store the number of old time levels.
2154 
2155  ntimestepsrestart = dummyint
2156 
2157  ! Go to the place in the cgns file where the time history
2158  ! should be stored.
2159 
2160  call cg_goto_f(cgnsind, cgnsbase, ierr, &
2161  "BaseIterativeData_t", 1, "end")
2162  if (ierr /= all_ok) &
2163  call terminate("readTimeHistory", &
2164  "Something wrong when calling cg_goto_f")
2165 
2166  ! Find out how many convergence variables are stored.
2167 
2168  call cg_narrays_f(nconv, ierr)
2169  if (ierr /= all_ok) &
2170  call terminate("readTimeHistory", &
2171  "Something wrong when calling cg_narrays_f")
2172 
2173  ! Allocate the memory for convNames, tmpNames and ind.
2174 
2175  allocate (convnames(nconv), tmpnames(nconv), ind(nconv), &
2176  stat=ierr)
2177  if (ierr /= 0) &
2178  call terminate("readTimeHistory", &
2179  "Memory allocation failure for convNames, etc.")
2180 
2181  ! Read the names of the convergence variables. Store them in
2182  ! tmpNames as well. Furthermore check the dimension of the
2183  ! data stored.
2184 
2185  do i = 1, nconv
2186  call cg_array_info_f(i, convnames(i), dummyint, ndim, &
2187  nsize, ierr)
2188  if (ierr /= all_ok) &
2189  call terminate("readConvHistory", &
2190  "Something wrong when calling cg_array_info_f")
2191 
2192  if (ndim /= 1) then
2193  print "(a)", "#"
2194  print "(a)", "# Warning"
2195  print strings, "# Dimension of time history for ", trim(convnames(i)), " is not 1."
2196  print "(a)", "# Information is ignored."
2197  print "(a)", "#"
2198 
2199  ! Screw up the string such that it does not correspond to
2200  ! a legal name. It is appended, because it is important that
2201  ! all strings differ.
2202 
2203  convnames(i) = convnames(i)//"#$@&^!#$%!"
2204  end if
2205 
2206  if (nsize(1) /= ntimestepsrestart) then
2207  print "(a)", "#"
2208  print "(a)", "# Warning"
2209  print strings, "# Inconsistent time history for ", trim(convnames(i)), "."
2210  print "(a)", "# Displayed information might be incorrect."
2211  print "(a)", "#"
2212  end if
2213 
2214  ! Copy the name in tmpNames for the sorting.
2215 
2216  tmpnames(i) = convnames(i)
2217  end do
2218 
2219  ! Sort convNames in increasing order.
2220 
2221  nn = nconv
2222  call qsortstrings(convnames, nn)
2223 
2224  ! Find the numbers for the just sorted convergence names.
2225 
2226  do i = 1, nconv
2227  ii = bsearchstrings(tmpnames(i), convnames)
2228  ind(ii) = i
2229  end do
2230 
2231  ! Find out whether the old time values are present.
2232  ! If not the time history stored will be ignored.
2233 
2234  ii = bsearchstrings(cgnstimevalue, convnames)
2235  if (ii == 0) then
2236  print "(a)", "#"
2237  print "(a)", "# Warning"
2238  print "(a)", "# No time values found in the time history &
2239  &in the restart file."
2240  print "(a)", "# The rest of the time history is ignored."
2241  print "(a)", "# Starting at timestep 1 on the finest level."
2242  print "(a)", "#"
2243 
2244  ! Set nTimeStepsRestart and timeUnsteadyRestart to 0.
2245 
2246  ntimestepsrestart = 0
2248  end if
2249 
2250  ! Determine the total number of time levels and allocate the
2251  ! memory for the time history arrays.
2252 
2254  call alloctimearrays(j)
2255 
2256  ! If the time values are not present, jump to the place where
2257  ! the memory of the variables used in this routine is released.
2258 
2259  if (ii == 0) goto 99
2260 
2261  ! Read the time values.
2262 
2263  i = ind(ii)
2264  call cg_array_read_as_f(i, realtypecgns, timearray, ierr)
2265  if (ierr /= all_ok) &
2266  call terminate("readTimeHistory", &
2267  "Something wrong when calling &
2268  &cg_array_read_as_f")
2269 
2270  ! Set the value of timeUnsteadyRestart to the last value in
2271  ! timeArray.
2272 
2274 
2275  ! Initialize allConvInfo to .true. and perform the loop over
2276  ! the number of monitoring variables.
2277 
2278  allconvinfo = .true.
2279 
2280  do j = 1, nmon
2281 
2282  ! Search for the monitoring name in the sorted
2283  ! convergence names present in the restart file.
2284 
2285  ii = bsearchstrings(monnames(j), convnames)
2286 
2287  ! Check if the name was found.
2288 
2289  if (ii == 0) then
2290 
2291  ! Name not present in the restart file. Set allConvInfo
2292  ! to .false. and the corresponding entries in timeDataArray
2293  ! to zero
2294 
2295  allconvinfo = .false.
2296  do i = 1, ntimestepsrestart
2297  timedataarray(i, j) = zero
2298  end do
2299 
2300  else
2301 
2302  ! Name is present in the restart file. Read the corresponding
2303  ! time history.
2304 
2305  i = ind(ii)
2306  call cg_array_read_as_f(i, realtypecgns, &
2307  timedataarray(1, j), ierr)
2308  if (ierr /= all_ok) &
2309  call terminate("readTimeHistory", &
2310  "Something wrong when calling &
2311  &cg_array_read_as_f")
2312  end if
2313 
2314  end do
2315 
2316  ! Print a warning in case not all the time history could
2317  ! be retrieved from the restart file.
2318 
2319  if (.not. allconvinfo) then
2320 
2321  print "(a)", "#"
2322  print "(a)", "# Warning"
2323  print "(a)", "# Not all the time history could be &
2324  &retrieved from the restart file."
2325  print "(a)", "# Missing information is initialized to zero."
2326  print "(a)", "#"
2327 
2328  end if
2329 
2330 99 continue
2331 
2332  ! Release the memory of the variables allocated in this routine.
2333 
2334  deallocate (convnames, tmpnames, ind, stat=ierr)
2335  if (ierr /= 0) &
2336  call terminate("readTimeHistory", &
2337  "Deallocation error for convNames, etc.")
2338 
2339  end subroutine readtimehistory
2340 
2341  subroutine scalefactors(fileIDs)
2342  !
2343  ! scaleFactors determines the scale factors for the density,
2344  ! pressure and velocity from either the reference state in the
2345  ! given cgns file or they are simply set to 1.0; the latter
2346  ! occurs if the input parameter checkRestartSol is .false.
2347  ! If no reference state is present checkRestartSol is .true.
2348  ! An error message will be printed and the program terminates.
2349  !
2350  use constants
2351  use cgnsnames
2352  use su_cgns
2354  use flowvarrefstate, only: pref, muref, rhoref
2355  use inputio, only: checkrestartsol
2356  use sorting, only: bsearchstrings, qsortstrings
2357  use utils, only: setcgnsrealtype, terminate
2358  implicit none
2359  !
2360  ! Subroutine arguments.
2361  !
2362  integer, dimension(nSolsRead), intent(in) :: fileIDs
2363 
2364  ! Local variables.
2365  !
2366  integer :: ierr, realTypeCGNS, typeCGNS
2367  integer :: i, nDim, nRef
2368  integer :: nsize
2369  integer(kind=cgsize_t) :: nsize2(1)
2370  integer(kind=intType) :: ii, nn
2371 
2372  integer(kind=intType), dimension(:), allocatable :: ind
2373 
2374  real(kind=cgnsrealtype) :: tmpscale
2375 
2376  character(len=maxCGNSNameLen), allocatable, dimension(:) :: &
2377  refNames, tmpNames
2378 
2379  logical :: muScalePresent
2380 
2381  ! Store the file ID and the base a bit easier. Note that the
2382  ! reference state only needs to be present in the first file.
2383 
2384  cgnsind = fileids(1)
2385  cgnsbase = 1
2386 
2387  ! Set the cgns real type.
2388 
2389  realtypecgns = setcgnsrealtype()
2390 
2391  ! Initialize the scale factors to 1.0, i.e. assume that the
2392  ! correct non-dimensional solution is stored in the restart file.
2393 
2394  rhoscale = one
2395  velscale = one
2396  pscale = one
2397  muscale = one
2398 
2399  ! Go to the place in the cgns file where the reference state
2400  ! should be stored.
2401 
2402  call cg_goto_f(cgnsind, cgnsbase, ierr, "end")
2403  if (ierr /= all_ok) &
2404  call terminate("scaleFactors", &
2405  "Something wrong when calling cg_goto_f")
2406 
2407  ! Try going to the reference state node. If we get an error code,
2408  ! it doesn't exist.
2409 
2410  call cg_goto_f(cgnsind, cgnsbase, ierr, &
2411  "ReferenceState_t", 1, "end")
2412  if (ierr /= all_ok) then
2413 
2414  ! Reference state does not exist. Check if the restart solution
2415  ! must be checked. If not, return; otherwise print an error
2416  ! message and terminate the execution. This error message is
2417  ! only printed by processor 0 to avoid a messy output.
2418 
2419  if (.not. checkrestartsol) return
2420 
2421  if (myid == 0) &
2422  call terminate("scaleFactors", &
2423  "Reference state not presented in restart &
2424  &file. Scaling factors cannot be determined.")
2425 
2426  ! The other processors will wait until they are killed.
2427 
2428  call mpi_barrier(adflow_comm_world, ierr)
2429 
2430  end if
2431 
2432  ! Go to the reference state node.
2433 
2434  call cg_goto_f(cgnsind, cgnsbase, ierr, &
2435  "ReferenceState_t", 1, "end")
2436  if (ierr /= all_ok) &
2437  call terminate("scaleFactors", &
2438  "Something wrong when calling cg_goto_f")
2439 
2440  ! Found out how many reference variables are stored.
2441 
2442  call cg_narrays_f(nref, ierr)
2443  if (ierr /= all_ok) &
2444  call terminate("scaleFactors", &
2445  "Something wrong when calling cg_narrays_f")
2446 
2447  ! Allocate the memory for refNames, tmpNames and ind.
2448 
2449  allocate (refnames(nref), tmpnames(nref), ind(nref), &
2450  stat=ierr)
2451  if (ierr /= 0) &
2452  call terminate("scaleFactors", &
2453  "Memory allocation failure for refNames, etc.")
2454 
2455  ! Read the names of the reference variables. Store them in
2456  ! tmpNames as well.
2457 
2458  do i = 1, nref
2459  call cg_array_info_f(i, refnames(i), typecgns, ndim, &
2460  nsize2, ierr)
2461  if (ierr /= all_ok) &
2462  call terminate("scaleFactors", &
2463  "Something wrong when calling cg_array_info_f")
2464 
2465  ! Check the dimension and the size of the array.
2466  ! Both should be 1. If not, screw up the name such that it
2467  ! will never be found in the search later on.
2468 
2469  if (ndim /= 1 .or. nsize2(1) /= 1) &
2470  refnames(i) = refnames(i)//"#$@&^!#$%!"
2471 
2472  ! And copy it in tmpNames.
2473 
2474  tmpnames(i) = refnames(i)
2475  end do
2476 
2477  ! Sort refNames in increasing order.
2478 
2479  nn = nref
2480  call qsortstrings(refnames, nn)
2481 
2482  ! Find the numbers for the just sorted reference names.
2483 
2484  do i = 1, nref
2485  ii = bsearchstrings(tmpnames(i), refnames)
2486  ind(ii) = i
2487  end do
2488 
2489  ! Determine the scale factors if these must be determined.
2490 
2491  if (checkrestartsol) then
2492 
2493  ! Read the reference density from the restart file.
2494 
2495  ii = bsearchstrings(cgnsdensity, refnames)
2496  if (ii == 0) then
2497  if (myid == 0) &
2498  call terminate("scaleFactors", &
2499  "No reference density found in restart file")
2500 
2501  ! The other processors will wait until they are killed.
2502 
2503  call mpi_barrier(adflow_comm_world, ierr)
2504  end if
2505 
2506  i = ind(ii)
2507  call cg_array_read_as_f(i, realtypecgns, tmpscale, ierr)
2508  if (ierr /= all_ok) &
2509  call terminate("scaleFactors", &
2510  "Something wrong when calling &
2511  &cg_array_read_as_f")
2512  rhoscale = tmpscale
2513 
2514  ! Read the reference pressure from the restart file.
2515 
2516  ii = bsearchstrings(cgnspressure, refnames)
2517  if (ii == 0) then
2518  if (myid == 0) &
2519  call terminate("scaleFactors", &
2520  "No reference pressure found in &
2521  &restart file")
2522 
2523  ! The other processors will wait until they are killed.
2524 
2525  call mpi_barrier(adflow_comm_world, ierr)
2526  end if
2527 
2528  i = ind(ii)
2529  call cg_array_read_as_f(i, realtypecgns, tmpscale, ierr)
2530  if (ierr /= all_ok) &
2531  call terminate("scaleFactors", &
2532  "Something wrong when calling &
2533  &cg_array_read_as_f")
2534  pscale = tmpscale
2535 
2536  ! Read the reference velocity from the restart file.
2537 
2538  ii = bsearchstrings(cgnsvelocity, refnames)
2539  if (ii == 0) then
2540  if (myid == 0) &
2541  call terminate("scaleFactors", &
2542  "No reference velocity found in &
2543  &restart file")
2544 
2545  ! The other processors will wait until they are killed.
2546 
2547  call mpi_barrier(adflow_comm_world, ierr)
2548  end if
2549 
2550  i = ind(ii)
2551  call cg_array_read_as_f(i, realtypecgns, tmpscale, ierr)
2552  if (ierr /= all_ok) &
2553  call terminate("scaleFactors", &
2554  "Something wrong when calling &
2555  &cg_array_read_as_f")
2556  velscale = tmpscale
2557 
2558  ! Set muScalePresent to .true. to indicate that it is present
2559  ! and read or construct the reference molecular viscosity.
2560 
2561  muscalepresent = .true.
2562 
2563  ii = bsearchstrings(cgnsviscmol, refnames)
2564  if (ii > 0) then
2565 
2566  ! Scale is present; read the value.
2567 
2568  i = ind(ii)
2569  call cg_array_read_as_f(i, realtypecgns, tmpscale, ierr)
2570  if (ierr /= all_ok) &
2571  call terminate("scaleFactors", &
2572  "Something wrong when calling &
2573  &cg_array_read_as_f")
2574  muscale = tmpscale
2575 
2576  else
2577 
2578  ! Try to read the kinematic viscosity.
2579 
2580  ii = bsearchstrings(cgnsvisckin, refnames)
2581  if (ii > 0) then
2582 
2583  ! Scale is present; read the value and multiply it by the
2584  ! density.
2585 
2586  i = ind(ii)
2587  call cg_array_read_as_f(i, realtypecgns, tmpscale, ierr)
2588  if (ierr /= all_ok) &
2589  call terminate("scaleFactors", &
2590  "Something wrong when calling &
2591  &cg_array_read_as_f")
2592 
2593  muscale = tmpscale * rhoscale
2594 
2595  else
2596 
2597  ! Final possibility. Try to read the length scale.
2598 
2599  ii = bsearchstrings(cgnslength, refnames)
2600  if (ii > 0) then
2601 
2602  ! Scale is present; read the value and create the
2603  ! reference viscosity.
2604 
2605  i = ind(ii)
2606  call cg_array_read_as_f(i, realtypecgns, tmpscale, ierr)
2607  if (ierr /= all_ok) &
2608  call terminate("scaleFactors", &
2609  "Something wrong when calling &
2610  &cg_array_read_as_f")
2611 
2612  muscale = tmpscale * sqrt(pscale * rhoscale)
2613 
2614  else
2615 
2616  ! Set the logical muScalePresent to .false.
2617 
2618  muscalepresent = .false.
2619 
2620  end if
2621  end if
2622  end if
2623 
2624  ! Create the correct scaling factors for density, pressure,
2625  ! velocity and possibly viscosity.
2626 
2628  pscale = pscale / pref
2629  velscale = velscale / sqrt(pref / rhoref)
2630 
2631  if (muscalepresent) muscale = muscale / muref
2632 
2633  end if
2634 
2635  ! Release the memory of refNames, tmpNames and ind.
2636 
2637  deallocate (refnames, tmpnames, ind, stat=ierr)
2638  if (ierr /= 0) &
2639  call terminate("scaleFactors", &
2640  "Deallocation error for convNames, etc.")
2641 
2642  end subroutine scalefactors
2643 
2644  subroutine readrestartvariable(cgnsVarName)
2645 
2646  ! readRestartVariable reads the given variable name from the
2647  ! cgns restart file.
2648  !
2649  use constants
2650  use blockpointers, only: il, jl, kl
2651  use utils, only: terminate, setcgnsrealtype
2652  use su_cgns
2653  implicit none
2654  !
2655  ! Subroutine arguments.
2656  !
2657  character(len=*), intent(in) :: cgnsVarName
2658  !
2659  ! Local variables.
2660  !
2661  integer :: ierr, realTypeCGNS
2662 
2663  integer(kind=intType) :: i, j, k
2664 
2665  ! Set the cgns real type.
2666 
2667  realtypecgns = setcgnsrealtype()
2668 
2669  ! Check where the solution variables are stored.
2670 
2671  locationtest: if (location == cellcenter) then
2672 
2673  ! Cell centered values. Read the values directly in the buffer.
2674 
2675  call cg_field_read_f(cgnsind, cgnsbase, cgnszone, cgnssol, &
2676  cgnsvarname, realtypecgns, rangemin, &
2677  rangemax, buffer, ierr)
2678  if (ierr /= all_ok) &
2679  call terminate("readRestartVariable", &
2680  "Something wrong when calling cg_field_read_f")
2681  else locationtest
2682 
2683  ! Vertex centered values. First read the solution in the
2684  ! array bufferVertex.
2685 
2686  call cg_field_read_f(cgnsind, cgnsbase, cgnszone, cgnssol, &
2687  cgnsvarname, realtypecgns, rangemin, &
2688  rangemax, buffervertex, ierr)
2689  if (ierr /= all_ok) &
2690  call terminate("readRestartVariable", &
2691  "Something wrong when calling cg_field_read_f")
2692 
2693  ! Create the cell centered values by averaging the vertex values.
2694 
2695  do k = 2, kl
2696  do j = 2, jl
2697  do i = 2, il
2698  buffer(i, j, k) = eighth * (buffervertex(i - 1, j - 1, k - 1) &
2699  + buffervertex(i, j - 1, k - 1) &
2700  + buffervertex(i - 1, j, k - 1) &
2701  + buffervertex(i, j, k - 1) &
2702  + buffervertex(i - 1, j - 1, k) &
2703  + buffervertex(i, j - 1, k) &
2704  + buffervertex(i - 1, j, k) &
2705  + buffervertex(i, j, k))
2706  end do
2707  end do
2708  end do
2709 
2710  end if locationtest
2711  end subroutine readrestartvariable
2712 
2713 end module variablereading
integer(kind=inttype) jl
real(kind=realtype), dimension(:, :, :, :), pointer w
integer(kind=inttype) nbklocal
real(kind=realtype), dimension(:, :, :), pointer rlv
real(kind=realtype), dimension(:, :, :), pointer rev
integer(kind=inttype) kl
integer(kind=inttype) il
character(len=maxcgnsnamelen), parameter cgnsmomz
Definition: cgnsNames.f90:33
character(len=maxcgnsnamelen), parameter cgnsturbomega
Definition: cgnsNames.f90:41
character(len=maxcgnsnamelen), parameter cgnsdensity
Definition: cgnsNames.f90:27
character(len=maxcgnsnamelen), parameter cgnsturbtau
Definition: cgnsNames.f90:43
character(len=maxcgnsnamelen), parameter cgnsvelocity
Definition: cgnsNames.f90:125
character(len=maxcgnsnamelen), parameter cgnsvelz
Definition: cgnsNames.f90:56
character(len=maxcgnsnamelen), parameter cgnseddyratio
Definition: cgnsNames.f90:86
character(len=maxcgnsnamelen), parameter cgnsmomy
Definition: cgnsNames.f90:31
character(len=maxcgnsnamelen), parameter cgnsvely
Definition: cgnsNames.f90:54
character(len=maxcgnsnamelen), parameter cgnseddy
Definition: cgnsNames.f90:84
character(len=maxcgnsnamelen), parameter cgnslength
Definition: cgnsNames.f90:129
character(len=maxcgnsnamelen), parameter cgnsvelx
Definition: cgnsNames.f90:52
character(len=maxcgnsnamelen), parameter cgnsturbepsilon
Definition: cgnsNames.f90:45
character(len=maxcgnsnamelen), parameter cgnsmomx
Definition: cgnsNames.f90:29
character(len=maxcgnsnamelen), parameter cgnsviscmol
Definition: cgnsNames.f90:80
character(len=maxcgnsnamelen), parameter cgnsvisckin
Definition: cgnsNames.f90:82
character(len=maxcgnsnamelen), parameter cgnsturbk
Definition: cgnsNames.f90:39
character(len=maxcgnsnamelen), parameter cgnsenergy
Definition: cgnsNames.f90:35
character(len=maxcgnsnamelen), parameter cgnsturbsanu
Definition: cgnsNames.f90:37
character(len=maxcgnsnamelen), parameter cgnsturbf
Definition: cgnsNames.f90:49
character(len=maxcgnsnamelen), parameter cgnspressure
Definition: cgnsNames.f90:68
character(len=maxcgnsnamelen), parameter cgnsturbv2
Definition: cgnsNames.f90:47
character(len=maxcgnsnamelen), parameter cgnstimevalue
Definition: cgnsNames.f90:11
character(len=maxstringlen) strings
integer adflow_comm_world
integer(kind=inttype), parameter spalartallmarasedwards
Definition: constants.F90:128
integer(kind=inttype), parameter spalartallmaras
Definition: constants.F90:128
real(kind=realtype), parameter zero
Definition: constants.F90:71
integer, parameter itu3
Definition: constants.F90:43
integer, parameter itu2
Definition: constants.F90:42
real(kind=realtype), parameter eps
Definition: constants.F90:23
real(kind=realtype), parameter eighth
Definition: constants.F90:84
integer(kind=inttype), parameter ktau
Definition: constants.F90:128
integer, parameter itu1
Definition: constants.F90:40
integer, parameter irho
Definition: constants.F90:34
integer, parameter imx
Definition: constants.F90:65
integer, parameter ivx
Definition: constants.F90:35
integer, parameter irhoe
Definition: constants.F90:38
real(kind=realtype), parameter one
Definition: constants.F90:72
integer, parameter maxstringlen
Definition: constants.F90:16
integer, parameter maxcgnsnamelen
Definition: constants.F90:17
integer, parameter ivz
Definition: constants.F90:37
integer, parameter itu4
Definition: constants.F90:44
integer, parameter imz
Definition: constants.F90:67
integer, parameter imy
Definition: constants.F90:66
integer, parameter ivy
Definition: constants.F90:36
integer(kind=inttype), parameter ransequations
Definition: constants.F90:110
subroutine computepressure(iBeg, iEnd, jBeg, jEnd, kBeg, kEnd, pointerOffset)
Definition: flowUtils.F90:934
subroutine etot(rho, u, v, w, p, k, etotal, correctForK)
Definition: flowUtils.F90:675
integer(kind=inttype) nt1
real(kind=realtype) muref
real(kind=realtype) rhoref
real(kind=realtype), dimension(:), allocatable winf
real(kind=realtype) muinf
real(kind=realtype) pref
integer(kind=inttype) nt2
logical checkrestartsol
Definition: inputParam.F90:164
real(kind=realtype) eddyvisinfratio
Definition: inputParam.F90:597
integer(kind=inttype) equations
Definition: inputParam.F90:583
integer(kind=inttype) turbmodel
Definition: inputParam.F90:584
integer(kind=inttype) ntimestepsfine
Definition: inputParam.F90:731
type(iotype), dimension(:, :), allocatable iovar
Definition: IOModule.f90:49
integer nmon
Definition: monitor.f90:30
real(kind=cgnsrealtype), dimension(:), allocatable timearray
Definition: monitor.f90:107
character(len=maxcgnsnamelen), dimension(:), allocatable monnames
Definition: monitor.f90:46
real(kind=realtype) timeunsteadyrestart
Definition: monitor.f90:98
integer(kind=inttype) ntimestepsrestart
Definition: monitor.f90:97
real(kind=cgnsrealtype), dimension(:, :), allocatable timedataarray
Definition: monitor.f90:109
integer(kind=inttype) function bsearchstrings(key, base)
Definition: sorting.F90:812
subroutine qsortstrings(arr, nn)
Definition: sorting.F90:525
subroutine initkomega(pOffset)
Definition: turbUtils.F90:2014
real(kind=realtype) function sanuknowneddyratio(eddyRatio, nuLam)
Definition: turbUtils.F90:334
Definition: utils.F90:1
subroutine alloctimearrays(nTimeTot)
Definition: utils.F90:5886
integer function setcgnsrealtype()
Definition: utils.F90:5578
subroutine terminate(routineName, errorMessage)
Definition: utils.F90:502
real(kind=cgnsrealtype), dimension(:, :, :), allocatable buffer
subroutine readturbeddyvis(nTypeMismatch, eddyVisPresent)
subroutine readymomentum(nTypeMismatch)
subroutine readturbv2f(nTypeMismatch)
integer(kind=inttype) nsolsread
subroutine readyvelocity(nTypeMismatch)
integer(kind=inttype) solid
subroutine readtimehistory(fileIDs)
subroutine readturbvar(nTypeMismatch)
real(kind=realtype) muscale
integer, dimension(:), allocatable vartypes
subroutine readzvelocity(nTypeMismatch)
integer(kind=inttype), dimension(:), allocatable zonenumbers
real(kind=realtype) rhoscale
real(kind=cgnsrealtype), dimension(:, :, :), allocatable buffervertex
subroutine readdensity(nTypeMismatch)
subroutine readzmomentum(nTypeMismatch)
character(len=maxstringlen), dimension(:), allocatable solfiles
subroutine readxvelocity(nTypeMismatch)
subroutine readpressure(nTypeMismatch)
subroutine readenergy(nTypeMismatch)
character(len=maxcgnsnamelen), dimension(:), allocatable zonenames
real(kind=realtype) velscale
subroutine readrestartvariable(cgnsVarName)
subroutine readturbkwtype(nTypeMismatch)
real(kind=realtype) pscale
subroutine readxmomentum(nTypeMismatch)
subroutine readturbsa(nTypeMismatch)
integer(kind=cgsize_t), dimension(3) rangemax
character(len=maxcgnsnamelen), dimension(:), allocatable varnames
integer(kind=cgsize_t), dimension(3) rangemin
subroutine scalefactors(fileIDs)