Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ic.F90
Go to the documentation of this file.
1 #define SIMPLE_IO
2 !-----------------------------------------------------------------------
4 !-----------------------------------------------------------------------
5 subroutine setics
6  use kinds, only : dp, i8
7  use size_m, only : lx1, ly1, lz1, lelv, ldimt, ldimt1
8  use size_m, only : nx1, ny1, nz1, nelt, nx2, ny2, nz2, nelv
9  use size_m, only : nid, lpert, nfield
10  use geom, only : ifvcor, xm1, ym1, zm1
11  use input, only : ifheat, ifsplit, ifflow, ifmhd, ifpert, ifmodel, ifkeps
12  use input, only : param, ifmvbd, npscal
13  use input, only : iftmsh, ifldmhd, ifadvc
14  use mvgeom, only : wx, wy, wz
15  use parallel, only : nelgv
16  use soln, only : vx, vy, vz, pr, t, jp, vmult, bx, by, bz
17  use soln, only : tmult
18  use tstep, only : ifield, nbdinp, time, timeio, nelfld, ntdump
19  use io, only : load_ic
20  implicit none
21 
22  logical iffort( ldimt1,0:lpert) &
23  , ifrest(0:ldimt1,0:lpert) &
24  , ifprsl( ldimt1,0:lpert)
25 
26  LOGICAL :: IFANYP
27  real(DP), allocatable :: work(:,:,:,:)
28  integer(i8) :: ntotg,nn
29 
30  real(DP) :: psmax(ldimt)
31 
32  integer :: nxyz2, ntot2, nxyz1, ntott, ntotv, irst, maxfld, mfldt
33  integer :: itest, nbdmax, nbdsav, i, ntot, ifldsave, nfiles
34  real(DP) :: rdif, rtotg, vxmax, vymax, vzmax, prmax, ttmax, small
35  real(DP) :: xxmax, yymax, zzmax
36  real(DP), external :: glsum, glamax, glmin, glmax
37 
38  if(nid == 0) write(6,*) 'set initial conditions'
39 
40 ! Initialize all fields:
41  nxyz2=nx2*ny2*nz2
42  ntot2=nxyz2*nelv
43  nxyz1=nx1*ny1*nz1
44  ntott=nelt*nxyz1
45  ntotv=nelv*nxyz1
46 
47  vx = 0._dp; vy = 0._dp; vz = 0._dp; pr = 0._dp; t = 0._dp
48 
49  jp = 0 ! set counter for perturbation analysis
50 
51  irst = int(param(46)) ! for lee's restart (rarely used)
52  if (irst > 0) call setup_convect(2)
53 
54 
55 ! If moving geometry then add a perturbation to the
56 ! mesh coordinates (see Subroutine INIGEOM)
57 
58 !max if (ifmvbd) call ptbgeom
59 
60 ! Find out what type of i.c. is requested
61 ! Current options:
62 
63 ! (1) - User specified fortran function (default is zero i.c.)
64 ! (2) - Restart from file(s)
65 ! (3) - Activate pre-solver => steady diffusion / steady Stokes
66 
67 ! If option (2) is requested, also return with the name of the
68 ! restart file(s) together with the associated dump number
69 
70  call slogic(iffort,ifrest,ifprsl,nfiles)
71 
72 
73 ! Set up proper initial values for turbulence model arrays
74 #if 0
75  IF (ifmodel) CALL pretmic
76 #endif
77 
78 ! ***** TEMPERATURE AND PASSIVE SCALARS ******
79 
80 ! Check if any pre-solv necessary for temperature/passive scalars
81 
82  ifanyp = .false.
83  DO 100 ifield=2,nfield
84  IF (ifprsl(ifield,jp)) THEN
85  IF (nid == 0) WRITE(6,101) ifield
86  ifanyp = .true.
87  ENDIF
88  100 END DO
89  101 FORMAT(2x,'Using PRESOLVE option for field',i2,'.')
90 
91 ! Fortran function initial conditions for temp/pass. scalars.
92  maxfld = nfield
93  if (ifmodel .AND. ifkeps) maxfld = nfield-2
94  if (ifmhd) maxfld = npscal+3
95 
96 ! Always call nekuic (pff, 12/7/11)
97 #ifndef SIMPLE_IO
98  do ifield=1,maxfld
99  call nekuic
100  enddo
101 
102 
103 ! If any pre-solv, do pre-solv for all temperatur/passive scalar fields
104 !max if (ifanyp) call prsolvt
105 
106  jp = 0 ! jp=0 --> base field, not perturbation field
107  do 200 ifield=2,maxfld
108  if (iffort(ifield,jp)) then
109  if (nid == 0) write(6,*) 'call nekuic for ifld ', ifield
110  call nekuic
111  endif
112  200 END DO
113 
114  if (ifpert) then
115  ifield=2
116  do jp=1,npert
117  if (nid == 0) write(6,*) 'nekuicP',ifield,jp,iffort(ifield,jp)
118  if (iffort(ifield,jp)) call nekuic
119  enddo
120  endif
121 #endif
122  jp = 0
123 
124 
125  call nekgsync()
126  call restart_driver(nfiles) ! Check restart files
127  call nekgsync()
128 
129 
130 ! ***** VELOCITY ******
131 ! (If restarting for V, we're done,
132 ! ...else, do pre-solv for fluid if requested.)
133 
134  ifield = 1
135 !max if (ifprsl(ifield,jp)) call prsolvv
136 
137 
138 ! Fortran function initial conditions for velocity.
139 #ifdef SIMPLE_IO
140 
141  if (param(69) > 0) then
142  if (nid == 0) write(6,*) 'trying to load restart files'
143  call load_ic()
144  else
145  if (nid == 0) write(6,*) 'call nekuic for all fields'
146  call nekuic
147  endif
148 
149 #else
150 
151  ifield = 1
152  if (iffort(ifield,jp)) then
153  if (nid == 0) write(6,*) 'call nekuic for vel '
154  call nekuic
155  endif
156 
157  if (ifpert) then
158  ifield=1
159  do jp=1,npert
160  if (iffort(ifield,jp)) call nekuic
161  if (nid == 0) write(6,*) 'ic vel pert:',iffort(1,jp),jp
162  enddo
163  endif
164 #endif
165  jp = 0
166 
167  ntotv = nx1*ny1*nz1*nelv
168 
169 ! Fortran function initial conditions for turbulence k-e model
170  if (ifmodel .AND. ifkeps) then
171  mfldt = nfield - 1
172  do 300 ifield=mfldt,nfield
173  if (iffort(ifield,jp)) call nekuic
174  300 END DO
175  endif
176 
177 ! Initial mesh velocities
178  if (ifmvbd) call opcopy(wx,wy,wz,vx,vy,vz)
179 
180 !max if (ifmvbd .AND. .NOT. ifrest(0,jp)) call meshv (2)
181 
182 ! Compute additional initial values for turbulence model arrays
183 ! based on I.C.
184 #if 0
185  if (ifmodel) call postmic
186 #endif
187 
188 ! If convection-diffusion of a passive scalar with a fixed velocity field,
189 ! make sure to fill up lagged arrays since this will not be done in
190 ! the time-stepping procedure (no flow calculation) (01/18/91 -EMR).
191 
192  if ( .NOT. ifflow .AND. ifheat) then
193  itest=0
194  DO 400 ifield=2,nfield
195  IF (ifadvc(ifield)) itest=1
196  400 END DO
197  IF (itest == 1) THEN
198  nbdmax = 3
199  nbdsav = nbdinp
200  nbdinp = nbdmax
201  DO 500 i=1,nbdmax
202  CALL lagvel
203  500 END DO
204  nbdinp = nbdsav
205  ENDIF
206  ENDIF
207 
208 ! Ensure that all processors have the same time as node 0.
209  if (nid /= 0) time=0.0
210  time=glsum(time,1)
211  ntdump=0
212  if (timeio /= 0.0) ntdump = int( time/timeio )
213 
214 ! Ensure that initial field is continuous!
215 
216  nxyz1=nx1*ny1*nz1
217  ntott=nelt*nxyz1
218  ntotv=nelv*nxyz1
219  nn = nxyz1
220  ntotg=nelgv*nn
221 
222  ifield = 2
223  if (ifflow) ifield = 1
224  allocate(work(lx1,ly1,lz1,lelv))
225  work = 1._dp
226  ifield = 1
227  call dssum(work)
228  work = work * vmult
229  rdif = glsum(work,ntotv)
230  deallocate(work)
231  rtotg = ntotg
232  rdif = (rdif-rtotg)/rtotg
233  if (abs(rdif) > 1e-14) then
234  if (nid == 0) write(*,*) 'ERROR: dssum test has failed!',rdif
235  call exitt
236  endif
237 
238  vxmax = glamax(vx,ntotv)
239  vymax = glamax(vy,ntotv)
240  vzmax = glamax(vz,ntotv)
241  prmax = glamax(pr,ntot2)
242 
243  ntot = nxyz1*nelfld(2)
244  ttmax = glamax(t ,ntot)
245 
246  do i=1,npscal
247  ntot = nx1*ny1*nz1*nelfld(i+2)
248  psmax(i) = glamax(t(1,1,1,1,i+1),ntot)
249  enddo
250 
251  small=1.0e-20
252  ifldsave = ifield
253 ! if (vxmax == 0.0) call perturb(vx,1,small)
254 ! if (vymax == 0.0) call perturb(vy,1,small)
255 ! if (vzmax == 0.0) call perturb(vz,1,small)
256 ! if (prmax == 0.0 .AND. ifsplit) call perturb(pr,1,small)
257 ! if (ttmax == 0.0) call perturb(t ,2,small)
258 
259  do i=1,npscal
260  ntot = nxyz1*nelfld(i+2)
261 ! if(psmax(i) == 0) call perturb(t(1,1,1,1,1+i),i+2,small)
262  enddo
263  ifield = ifldsave
264 
265  if(ifflow) then
266  ifield = 1
267  call opdssum(vx,vy,vz)
268  vx = vx * vmult; vy = vy * vmult; vz = vz * vmult
269  if (ifsplit) call dsavg(pr) ! continuous pressure
270  if (ifvcor) call ortho(pr) ! remove any mean
271  endif
272 
273 
274  if (ifmhd) then
275  ifield = ifldmhd
276  call opdssum(bx,by,bz)
277  bx = bx * vmult; by = by * vmult; bz = bz * vmult
278  endif
279 
280  if (ifheat) then
281  ifield = 2
282  call dssum(t)
283  t = t * tmult
284  do ifield=3,nfield
285  call dssum(t(1,1,1,1,i-1))
286  if(iftmsh(ifield)) then
287  t(:,:,:,:,i-1) = t(:,:,:,:,i-1) * tmult(:,:,:,:,1)
288 ! call col2 (t(1,1,1,1,i-1),tmult,ntott)
289  else
290  t(:,:,:,:,i-1) = t(:,:,:,:,i-1) * vmult
291 ! call col2 (t(1,1,1,1,i-1),vmult,ntotv)
292  endif
293  enddo
294  endif
295 
296  if (ifpert) then
297 #if 0
298  do jp=1,npert
299  ifield = 1
300  call opdssum(vxp(1,jp),vyp(1,jp),vzp(1,jp))
301  call opcolv(vxp(1,jp),vyp(1,jp),vzp(1,jp),vmult)
302  ifield = 2
303  call dssum(tp(1,1,jp))
304  call col2(tp(1,1,jp),tmult,ntotv)
305  ! note... must be updated for addl pass. scal's. pff 4/26/04
306  vxmax = glamax(vxp(1,jp),ntotv)
307  vymax = glamax(vyp(1,jp),ntotv)
308  if (nid == 0) write(6,111) jp,vxmax,vymax
309  111 format(i5,1p2e12.4,' max pert vel')
310  enddo
311 #endif
312  endif
313  jp = 0
314 
315 ! print min values
316  xxmax = glmin(xm1,ntott)
317  yymax = glmin(ym1,ntott)
318  zzmax = glmin(zm1,ntott)
319 
320  vxmax = glmin(vx,ntotv)
321  vymax = glmin(vy,ntotv)
322  vzmax = glmin(vz,ntotv)
323  prmax = glmin(pr,ntot2)
324 
325  ntot = nxyz1*nelfld(2)
326  ttmax = glmin(t ,ntott)
327 
328  do i=1,ldimt-1
329  ntot = nxyz1*nelfld(i+2)
330  psmax(i) = glmin(t(1,1,1,1,i+1),ntot)
331  enddo
332 
333  if (nid == 0) then
334  write(6,19) xxmax,yymax,zzmax
335  19 format(' xyz min ',5g13.5)
336  endif
337  if (nid == 0) then
338  write(6,20) vxmax,vymax,vzmax,prmax,ttmax
339  20 format(' uvwpt min',5g13.5)
340  endif
341  if (ldimt-1 > 0) then
342  if (nid == 0) write(6,21) (psmax(i),i=1,ldimt-1)
343  21 format(' PS min ',50g13.5)
344  endif
345 
346 ! print max values
347  xxmax = glmax(xm1,ntott)
348  yymax = glmax(ym1,ntott)
349  zzmax = glmax(zm1,ntott)
350 
351  vxmax = glmax(vx,ntotv)
352  vymax = glmax(vy,ntotv)
353  vzmax = glmax(vz,ntotv)
354  prmax = glmax(pr,ntot2)
355 
356  ntot = nxyz1*nelfld(2)
357  ttmax = glmax(t ,ntott)
358 
359  do i=1,ldimt-1
360  ntot = nxyz1*nelfld(i+2)
361  psmax(i) = glmax(t(1,1,1,1,i+1),ntot)
362  enddo
363 
364  if (nid == 0) then
365  write(6,16) xxmax,yymax,zzmax
366  16 format(' xyz max ',5g13.5)
367  endif
368 
369  if (nid == 0) then
370  write(6,17) vxmax,vymax,vzmax,prmax,ttmax
371  17 format(' uvwpt max',5g13.5)
372  endif
373 
374  if (ldimt-1 > 0) then
375  if (nid == 0) then
376  write(6,18) (psmax(i),i=1,ldimt-1)
377  18 format(' PS max ',50g13.5)
378  endif
379  endif
380 
381 
382  if (ifrest(0,jp)) then ! mesh has been read in.
383  if (nid == 0) write(6,*) 'Restart: recompute geom. factors.'
384  call geom_reset(1) ! recompute geometric factors
385  endif
386 
387 
388 ! ! save velocity on fine mesh for dealiasing
389  call setup_convect(2)
390 
391 
392 ! call outpost(vx,vy,vz,pr,t,' ')
393 ! call exitti('setic exit$',nelv)
394 
395  if(nid == 0) then
396  write(6,*) 'done :: set initial conditions'
397  write(6,*) ' '
398  endif
399 
400  return
401 end subroutine setics
402 
403 !---------------------------------------------------------------------
405 !---------------------------------------------------------------------
406 subroutine slogic (iffort,ifrest,ifprsl,nfiles)
407  use size_m, only : nfield, npert, nid, ldimt1, lpert
408  use input, only : ifmhd, initc, npscal, ifpert
409  use restart, only : ifgetx, ifgetu, ifgett, ifgtps
410  use string, only : indx1, ltrunc, indx_cut, csplit, ljust, capit
411  implicit none
412 
413  logical iffort( ldimt1,0:lpert) &
414  , ifrest(0:ldimt1,0:lpert) &
415  , ifprsl( ldimt1,0:lpert)
416 
417  character(132) :: line,fname,cdum
418  character(2) :: s2
419  character(1) :: line1(132)
420  equivalence(line1,line)
421 
422  integer :: ifield, ndumps, iline, ip, ll, l, nfldt, jp, ifld, nfiles
423 
424 ! Default is user specified fortran function (=0 if not specified)
425 
426  nfldt = nfield
427  if (ifmhd) nfldt = nfield+1
428 
429  do jp=0,npert
430  ifrest(0,jp) = .false.
431  do ifld=1,nfldt
432  iffort(ifld,jp) = .true.
433  ifrest(ifld,jp) = .false.
434  ifprsl(ifld,jp) = .false.
435  enddo
436  enddo
437 
438  jp = 0
439  nfiles=0
440 
441 ! Check for Presolve options
442 
443  DO 1000 iline=1,15
444  line=initc(iline)
445  CALL capit(line,132)
446  IF (indx1(line,'PRESOLV',7) /= 0) THEN
447  ! found a presolve request
448  CALL blank(initc(iline),132)
449  CALL ljust(line)
450  CALL csplit(cdum,line,' ',1)
451 
452  IF (ltrunc(line,132) == 0) THEN
453  IF (nid == 0) WRITE(6,700)
454  700 FORMAT(/,2x,'Presolve options: ALL')
455  ! default - all fields are presolved.
456  DO 800 ifield=1,nfldt
457  ifprsl(ifield,jp) = .true.
458  iffort(ifield,jp) = .false.
459  800 END DO
460  ELSE
461  ! check line for arguments
462 
463  ll=ltrunc(line,132)
464  IF (nid == 0) WRITE(6,810) (line1(l),l=1,ll)
465  810 FORMAT(/,2x,'Presolve options: ',132a1)
466 
467  IF (indx_cut(line,'U',1) /= 0) THEN
468  ifprsl(1,jp) = .true.
469  iffort(1,jp) = .false.
470  ENDIF
471 
472  IF (indx_cut(line,'T',1) /= 0) THEN
473  ifprsl(2,jp) = .true.
474  iffort(2,jp) = .false.
475  ENDIF
476 
477  DO 900 ifield=3,npscal+2
478  ip=ifield-2
479  WRITE(s2,901) ip
480  IF (indx_cut(line,s2,2) /= 0) THEN
481  ifprsl(ifield,jp) = .true.
482  iffort(ifield,jp) = .false.
483  ENDIF
484  900 END DO
485  901 FORMAT('P',i1)
486  ENDIF
487  ENDIF
488  1000 END DO
489 
490 ! Check for restart options
491 
492  jp = 0
493  DO 2000 iline=1,15
494  if (ifpert) jp=iline-1
495  line=initc(iline)
496  IF (ltrunc(line,132) /= 0) THEN
497  ! found a filename
498  nfiles=nfiles+1
499  initc(nfiles)=line
500 
501  IF (nid == 0 .AND. nfiles == 1) WRITE(6,1010) line
502  1010 FORMAT(1x,'Checking restart options: ',a132)
503  ! IF (NID.EQ.0) WRITE(6,'(A132)') LINE
504 
505  ! Parse restart options
506 
507  call sioflag(ndumps,fname,line)
508 
509  if (ifgetx) then
510  ifrest(0,jp) = .true.
511  endif
512  if (ifgetu) then
513  iffort(1,jp) = .false.
514  ifprsl(1,jp) = .false.
515  ifrest(1,jp) = .true.
516  endif
517  if (ifgett) then
518  iffort(2,jp) = .false.
519  ifprsl(2,jp) = .false.
520  ifrest(2,jp) = .true.
521  endif
522  do 1900 ifield=3,nfldt
523  ! write(6,*) 'ifgetps:',(ifgtps(k),k=1,ldimt-1)
524  if (ifgtps(ifield-2)) then
525  iffort(ifield,jp) = .false.
526  ifprsl(ifield,jp) = .false.
527  ifrest(ifield,jp) = .true.
528  endif
529  1900 END DO
530  endif
531  2000 END DO
532 
533  return
534 end subroutine slogic
535 
536 !-----------------------------------------------------------------------
546 !----------------------------------------------------------------------
547 subroutine restart_driver(nfiles)
548  use kinds, only : dp, r4
549  use size_m, only : lx1, ly1, lz1, lelt, ldimt, ldimt1
550  use size_m, only : nid, nx1, ny1, nz1, nx2, ny2, nz2
551  use restart, only : nxr, nyr, nzr
552  use restart, only : ifgetx, ifgetz, ifgetu, ifgetw, ifgetp, ifgett, ifgtim
553  use restart, only : ifgtps
554  use geom, only : xm1, ym1, zm1
555  use input, only : ifpert, ifmhd, if3d, npscal, param, initc
556  use parallel, only : nelgt, isize, gllnid
557  use soln, only : vx, vy, vz, t
558  use string, only : ltrunc, i1_from_char
559  use tstep, only : time
560  implicit none
561 
562  integer, intent(in) :: nfiles
563 
564  integer :: nelrr
565 
566  integer, parameter :: LXR=LX1+6
567  integer, parameter :: LYR=LY1+6
568  integer, parameter :: LZR=LZ1+6
569  integer, parameter :: LXYZR=LXR*LYR*LZR
570  integer, parameter :: LXYZT=LX1*LY1*LZ1*LELT
571  integer, parameter :: LPSC9=LDIMT+9
572 
573  real(DP), allocatable :: sdump(:,:)
574  integer :: mesg(40)
575 
576  real(r4), allocatable :: tdump(:,:)
577 
578  REAL(DP), allocatable :: SDMP2(:,:)
579 
580 ! cdump comes in via PARALLEL (->TOTAL)
581 
582  character(30) :: excoder
583  character(1) :: excoder1(30)
584  equivalence(excoder,excoder1)
585 
586  character(132) :: fname
587  character(1) :: fname1(132)
588  equivalence(fname1,fname)
589 
590  integer :: hnami (30)
591  character(132) :: hname
592 
593  CHARACTER(132) :: header
594 
595 ! Local logical flags to determine whether to copy data or not.
596  logical :: ifok,iffmat
597  integer :: iposx,iposz,iposu,iposw,iposp,ipost,ipsps(ldimt1)
598 
599  logical :: ifbytsw, if_byte_swap_test
600  real(r4) :: bytetest
601 
602  real(DP) :: p67, rstime, cdump
603  integer :: ifile, ndumps, ierr, len, idump, neltr, istepr, i, icase, ipass
604  integer :: nxyz2, mid, ieg, nerr, ips, ii, nxyzr, ixyzz, nouts
605  integer :: jxyz, ntotv, ntott
606  integer :: nxyz1, lname, is, nps0, nps1, i1, iposv, iposy, nps
607 
608 
609  ifok= .false.
610  ifbytsw = .false.
611 
612  if(nfiles < 1) return
613 
614  if(nid == 0) write(6,*) 'Reading checkpoint data'
615  allocate(tdump(lxyzr,lpsc9))
616 
617 ! use new reader (only binary support)
618  p67 = abs(param(67))
619  if (p67 == 6.0) then
620  write(*,*) "Oops: p67"
621 #if 0
622  do ifile=1,nfiles
623  call sioflag(ndumps,fname,initc(ifile))
624  call mfi(fname,ifile)
625  enddo
626  call setup_convect(3)
627  if (nid /= 0) time=0
628  time = glmax(time,1) ! Sync time across processors
629 #endif
630  return
631  endif
632 
633 ! use old reader (for ASCII + old binary support)
634 
635  if (param(67) < 1.0) then ! zero only. should be abs.
636  iffmat= .true. ! ascii
637  else
638  iffmat= .false. ! binary
639  endif
640 
641  do 6000 ifile=1,nfiles
642  call sioflag(ndumps,fname,initc(ifile))
643  ierr = 0
644  if (nid == 0) then
645 
646  if (iffmat) then
647  open (unit=91,file=fname,status='old',err=500)
648  else
649  len= ltrunc(fname,79)
650  ! test for presence of file
651  open (unit=91,file=hname &
652  ,form='unformatted',status='old',err=500)
653  close(unit=91)
654  call byte_open(hname,ierr)
655  if(ierr /= 0) goto 500
656  ENDIF
657  ifok = .true.
658  endif
659 
660  500 continue
661  call lbcast(ifok)
662  if ( .NOT. ifok) goto 5000
663 
664  ndumps = 1
665 
666  ! Only NODE 0 reads from the disk.
667 
668  DO 1000 idump=1,ndumps
669 
670  IF (nid == 0) THEN
671  ! read header
672  if (iffmat) then
673  ierr = 2
674  if(mod(param(67),1._dp) == 0) then ! old header format
675  if(nelgt < 10000) then
676  read(91,91,err=10,end=10) &
677  neltr,nxr,nyr,nzr,rstime,istepr,(excoder1(i),i=1,30)
678  91 format(4i4,1x,g13.4,i5,1x,30a1)
679  ierr=0
680  else
681  read(91,92,err=10,end=10) &
682  neltr,nxr,nyr,nzr,rstime,istepr,(excoder1(i),i=1,30)
683  92 format(i10,3i4,1p1e18.9,i9,1x,30a1)
684  ierr=0
685  endif
686  else ! new head format
687  read(91,'(A132)',err=10,end=10) header
688  read(header,*) &
689  neltr,nxr,nyr,nzr,rstime,istepr,excoder
690  ierr=0
691  endif
692  else
693  if(mod(param(67),1._dp) == 0) then ! old header format
694  call byte_read(hnami,20,ierr)
695  if(ierr /= 0) goto 10
696  icase = 2
697  if (nelgt < 10000) icase = 1
698  ipass = 0
699  93 continue ! test each possible case UGLY (7/31/07)
700  if(ipass < 2) then
701  ipass = ipass+1
702  if(icase == 1) then
703  read(hname,'(4i4,1x,g13.4,i5,1x,30a1)', &
704  err=94,end=94) &
705  neltr,nxr,nyr,nzr,rstime,istepr, &
706  (excoder1(i),i=1,30)
707  goto 95
708  else
709  read(hname,'(i10,3i4,1P1e18.9,i9,1x,30a1)', &
710  err=94,end=94) &
711  neltr,nxr,nyr,nzr,rstime,istepr, &
712  (excoder1(i),i=1,30)
713  goto 95
714  endif
715  94 icase = 3-icase ! toggle: 2-->1 1-->2
716  goto 93
717  else
718  ierr=2
719  goto 10
720  endif
721  95 continue
722  else ! new head format
723  call byte_read(header,20,ierr)
724  if(ierr /= 0) goto 10
725  read(header,*) &
726  neltr,nxr,nyr,nzr,rstime,istepr,excoder
727  endif
728  call byte_read(bytetest,1,ierr)
729  ! call byte_read2(bytetest,1,ierr)
730  if(ierr /= 0) goto 10
731  ifbytsw = if_byte_swap_test(bytetest,ierr)
732  if(ierr /= 0) goto 10
733  endif
734  mesg(1) = neltr
735  mesg(2) = nxr
736  mesg(3) = nyr
737  mesg(4) = nzr
738  write(6,*) 'Read mode: ', param(67)
739  write(6,333)'neltr,nxr,nyr,nzr: ', neltr,nxr,nyr,nzr
740  333 format(a,i9,3i4)
741  call chcopy(mesg(5),excoder1,20)
742  len = 14*isize
743  endif
744  10 call err_chk(ierr,'Error reading restart header. Abort.$')
745 
746  IF (idump == 1) THEN
747  len = 14*isize
748  call bcast(mesg,len)
749  neltr = mesg(1)
750  nxr = mesg(2)
751  nyr = mesg(3)
752  nzr = mesg(4)
753  call chcopy(excoder1,mesg(5),20)
754 
755  call lbcast(ifbytsw)
756 
757  ! Bounds checking on mapped data.
758  IF (nxr > lxr) THEN
759  WRITE(6,20) nxr,nx1
760  20 FORMAT(//,2x, &
761  'ABORT: Attempt to map from',i3, &
762  ' to N=',i3,'.',/,2x, &
763  'NEK5000 currently supports mapping from N+6 or less.' &
764  ,/,2x,'Increase N or LXR in IC.FOR.')
765  CALL exitt
766  ENDIF
767 
768  ! Figure out position of data in file "IFILE"
769 
770  nouts=0
771  iposx=0
772  iposy=0
773  iposz=0
774  iposu=0
775  iposv=0
776  iposw=0
777  iposp=0
778  ipost=0
779  DO 40 i=1,npscal
780  ipsps(i)=0
781  40 END DO
782 
783  ips = 0
784  nps = 0
785  DO 50 i=1, 30
786  IF (excoder1(i) == 'X') THEN
787  nouts=nouts + 1
788  iposx=nouts
789  nouts=nouts+1
790  iposy=nouts
791  IF (if3d) THEN
792  nouts=nouts + 1
793  iposz=nouts
794  ENDIF
795  ENDIF
796  IF (excoder1(i) == 'U') THEN
797  nouts=nouts + 1
798  iposu=nouts
799  nouts=nouts+1
800  iposv=nouts
801  IF (if3d) THEN
802  nouts=nouts + 1
803  iposw=nouts
804  ENDIF
805  ENDIF
806  IF (excoder1(i) == 'P') THEN
807  nouts=nouts + 1
808  iposp=nouts
809  ENDIF
810  IF (excoder1(i) == 'T') THEN
811  nouts=nouts + 1
812  ipost=nouts
813  ENDIF
814  IF(mod(param(67),1._dp) == 0.0) THEN
815  i1 = i1_from_char(excoder1(i))
816  if (0 < i1 .AND. i1 < 10) then
817  if (i1 <= ldimt1) then
818  nouts=nouts + 1
819  ipsps(i1)=nouts
820  else
821  if (nid == 0) write(6,2) i1,i,excoder1(i)
822  2 format(2i4,a1,' PROBLEM W/ RESTART DATA')
823  endif
824  endif
825  ELSE
826  IF(excoder1(i) == 'S') THEN
827  READ(excoder1(i+1),'(I1)') nps1
828  READ(excoder1(i+2),'(I1)') nps0
829  nps=10*nps1 + nps0
830  DO is = 1, nps
831  nouts=nouts + 1
832  ipsps(is)=nouts
833  ENDDO
834  goto 50
835  ENDIF
836  ENDIF
837  50 END DO
838 
839  IF (nps > (ldimt-1)) THEN
840  IF (nid == 0) THEN
841  WRITE(*,'(A)') &
842  'ERROR: restart file has a NSPCAL > LDIMT'
843  WRITE(*,'(A,I2)') &
844  'Change LDIMT in SIZE'
845  ENDIF
846  CALL exitt
847  ENDIF
848 
849  lname=ltrunc(fname,132)
850  if (nid == 0) write(6,61) (fname1(i),i=1,lname)
851  if (nid == 0) write(6,62) &
852  iposu,iposv,iposw,iposp,ipost,nps,nouts
853  61 FORMAT(/,2x,'Restarting from file ',132a1)
854  62 FORMAT(2x,'Columns for restart data U,V,W,P,T,S,N: ',7i4)
855 
856  ! Make sure the requested data is present in this file....
857  if (iposx == 0) ifgetx= .false.
858  if (iposy == 0) ifgetx= .false.
859  if (iposz == 0) ifgetz= .false.
860  if (iposu == 0) ifgetu= .false.
861  if (iposv == 0) ifgetu= .false.
862  if (iposw == 0) ifgetw= .false.
863  if (iposp == 0) ifgetp= .false.
864  if (ipost == 0) ifgett= .false.
865  do 65 i=1,npscal
866  if (ipsps(i) == 0) ifgtps(i)= .false.
867  65 END DO
868 
869  ! End of restart file header evaluation.
870 
871  ENDIF
872 
873  ! Read the error estimators
874  ! not supported at the moment => just do dummy reading
875 
876  ifok = .false.
877  IF(nid == 0)THEN
878  if (iffmat) &
879  READ(91,'(6G11.4)',end=15)(cdump,i=1,neltr)
880  ifok = .true.
881  ENDIF
882  15 continue
883  call lbcast(ifok)
884  if( .NOT. ifok) goto 1600
885 
886  ! Read the current dump, double buffer so that we can
887  ! fit the data on a distributed memory machine,
888  ! and so we won't have to read the restart file twice
889  ! in case of an incomplete data file.
890 
891  nxyzr = nxr*nyr*nzr
892 
893  ! Read the data
894 
895  nelrr = min(nelgt,neltr) ! # of elements to _really_read
896  ! why not just neltr?
897  do 200 ieg=1,nelrr
898  ifok = .false.
899  IF (nid == 0) THEN
900  IF (mod(ieg,10000) == 1) WRITE(6,*) 'Reading',ieg
901  IF (iffmat) THEN
902  READ(91,*,err=70,end=70) &
903  ((tdump(ixyzz,ii),ii=1,nouts),ixyzz=1,nxyzr)
904  ELSE
905  do ii=1,nouts
906  call byte_read(tdump(1,ii),nxyzr,ierr)
907  if(ierr /= 0) then
908  write(6,*) "Error reading xyz restart data"
909  goto 70
910  endif
911  enddo
912  ENDIF
913  ifok= .true.
914  ENDIF
915 
916  ! Notify other processors that we've read the data OK.
917 
918  70 continue
919  call lbcast(ifok)
920  IF ( .NOT. ifok) goto 1600
921  write(*,*) "Oops: ifok"
922 #if 0
923  ! MAPDMP maps data from NXR to NX1
924  ! (and sends data to the appropriate processor.)
925 
926  ! The buffer SDUMP is used so that if an incomplete dump
927  ! file is found (e.g. due to UNIX io buffering!), then
928  ! the previous read data stored in VX,VY,.., is not corrupted.
929 
930  IF (ifgetx) CALL mapdmp &
931  (sdump(1,1),tdump(1,iposx),ieg,nxr,nyr,nzr,ifbytsw)
932  IF (ifgetx) CALL mapdmp &
933  (sdump(1,2),tdump(1,iposy),ieg,nxr,nyr,nzr,ifbytsw)
934  IF (ifgetz) CALL mapdmp &
935  (sdump(1,3),tdump(1,iposz),ieg,nxr,nyr,nzr,ifbytsw)
936  IF (ifgetu) CALL mapdmp &
937  (sdump(1,4),tdump(1,iposu),ieg,nxr,nyr,nzr,ifbytsw)
938  IF (ifgetu) CALL mapdmp &
939  (sdump(1,5),tdump(1,iposv),ieg,nxr,nyr,nzr,ifbytsw)
940  IF (ifgetw) CALL mapdmp &
941  (sdump(1,6),tdump(1,iposw),ieg,nxr,nyr,nzr,ifbytsw)
942  IF (ifgetp) CALL mapdmp &
943  (sdump(1,7),tdump(1,iposp),ieg,nxr,nyr,nzr,ifbytsw)
944  IF (ifgett) CALL mapdmp &
945  (sdmp2(1,1),tdump(1,ipost),ieg,nxr,nyr,nzr,ifbytsw)
946 
947  ! passive scalars
948  do 100 ips=1,npscal
949  if (ifgtps(ips)) call mapdmp(sdmp2(1,ips+1) &
950  ,tdump(1,ipsps(ips)),ieg,nxr,nyr,nzr,ifbytsw)
951  100 END DO
952 #endif
953  200 END DO
954 
955  ! Successfully read a complete field, store it.
956 
957  nerr = 0 ! Count number of elements rec'd by nid
958  do ieg=1,nelrr
959  mid = gllnid(ieg)
960  if (mid == nid) nerr = nerr+1
961  enddo
962 
963  nxyz2=nx2*ny2*nz2
964  nxyz1=nx1*ny1*nz1
965  ntott=nerr*nxyz1
966  ntotv=nerr*nxyz1 ! Problem for differing Vel. and Temp. counts!
967  ! for now we read nelt dataset
968 
969  if (ifmhd .AND. ifile == 2) then
970  write(*,*) "Oops: ifmhd"
971 #if 0
972  if (ifgetu) call copy(bx,sdump(1,4),ntott)
973  if (ifgetu) call copy(by,sdump(1,5),ntott)
974  if (ifgetw) call copy(bz,sdump(1,6),ntott)
975  if (ifgetp) then
976  if (nid == 0) write(6,*) 'getting restart pressure'
977  if (ifsplit) then
978  call copy( pm,sdump(1,7),ntotv)
979  else
980  do iel=1,nelv
981  iiel = (iel-1)*nxyz1+1
982  call map12(pm(1,1,1,iel),sdump(iiel,7),iel)
983  enddo
984  endif
985  endif
986  if (ifaxis .AND. ifgett) &
987  call copy(t(1,1,1,1,2),sdmp2(1,1),ntott)
988 #endif
989  elseif (ifpert .AND. ifile >= 2) then
990  write(*,*) "Oops: ifpert"
991 #if 0
992  j=ifile-1 ! pointer to perturbation field
993  if (ifgetu) call copy(vxp(1,j),sdump(1,4),ntotv)
994  if (ifgetu) call copy(vyp(1,j),sdump(1,5),ntotv)
995  if (ifgetw) call copy(vzp(1,j),sdump(1,6),ntotv)
996  if (ifgetp) then
997  if (nid == 0) write(6,*) 'getting restart pressure'
998  if (ifsplit) then
999  call copy(prp(1,j),sdump(1,7),ntotv)
1000  else
1001  do ie=1,nelv
1002  ie1 = (ie-1)*nxyz1+1
1003  ie2 = (ie-1)*nxyz2+1
1004  call map12(prp(ie2,j),sdump(ie1,7),ie)
1005  enddo
1006  endif
1007  endif
1008  if (ifgett) call copy(tp(1,1,j),sdmp2(1,1),ntott)
1009  ! passive scalars
1010  do ips=1,npscal
1011  if (ifgtps(ips)) &
1012  call copy(tp(1,ips+1,j),sdmp2(1,ips+1),ntott)
1013  enddo
1014 #endif
1015  else ! Std. Case
1016  allocate(sdump(lxyzt,7))
1017  if (ifgetx) call copy(xm1,sdump(1,1),ntott)
1018  if (ifgetx) call copy(ym1,sdump(1,2),ntott)
1019  if (ifgetz) call copy(zm1,sdump(1,3),ntott)
1020  if (ifgetu) call copy(vx ,sdump(1,4),ntotv)
1021  if (ifgetu) call copy(vy ,sdump(1,5),ntotv)
1022  if (ifgetw) call copy(vz ,sdump(1,6),ntotv)
1023 !max if (ifgetp) call copy(pm1,sdump(1,7),ntotv)
1024  if (ifgett) call copy(t,sdmp2(1,1),ntott)
1025  ! passive scalars
1026  allocate(sdmp2(lxyzt,ldimt))
1027  do i=1,npscal
1028  if (ifgtps(i)) &
1029  call copy(t(1,1,1,1,i+1),sdmp2(1,i+1),ntott)
1030  enddo
1031 
1032 !max if (ifaxis) call axis_interp_ic(pm1) ! Interpolate to axi mesh
1033 !max if (ifgetp) call map_pm1_to_pr(pm1,ifile) ! Interpolate pressure
1034 
1035  if (ifgtim) time=rstime
1036  endif
1037 
1038  1000 END DO
1039  goto 1600
1040 
1041  1600 CONTINUE
1042 
1043  IF (idump == 1 .AND. nid == 0) THEN
1044  write(6,1700) fname
1045  write(6,1701) ieg,ixyzz
1046  write(6,1702) &
1047  ((tdump(jxyz,ii),ii=1,nouts),jxyz=ixyzz-1,ixyzz)
1048  1700 FORMAT(5x,'WARNING: No data read in for file ',a132)
1049  1701 FORMAT(5x,'Failed on element',i4,', point',i5,'.')
1050  1702 FORMAT(5x,'Last read dump:',/,5g15.7)
1051  write(6,*) nid,'call exitt 1702a',idump
1052  call exitt
1053  ELSEIF (idump == 1) THEN
1054  write(6,*) nid,'call exitt 1702b',idump
1055  call exitt
1056  ELSE
1057  idump=idump-1
1058  IF (nid == 0) WRITE(6,1800) idump
1059  1800 FORMAT(2x,'Successfully read data from dump number',i3,'.')
1060  ENDIF
1061  if (iffmat) then
1062  if (nid == 0) close(unit=91)
1063  else
1064  ierr = 0
1065  if (nid == 0) call byte_close(ierr)
1066  call err_chk(ierr,'Error closing restart file in restart$')
1067  endif
1068  goto 6000
1069 
1070  ! Can't open file...
1071  5000 CONTINUE
1072  if (nid == 0) write(6,5001) fname
1073  5001 FORMAT(2x,' ******* ERROR ******* ' &
1074  ,/,2x,' ******* ERROR ******* ' &
1075  ,/,2x,' Could not open restart file:' &
1076  ,/,a132 &
1077  ,//,2x,'Quitting in routine RESTART.')
1078  CLOSE(unit=91)
1079  call exitt
1080  IF (nid == 0) WRITE(6,5001) hname
1081  call exitt
1082 
1083 
1084  ! End of IFILE loop
1085  6000 END DO
1086 
1087  return
1088 end subroutine restart_driver
1089 
1090 !-----------------------------------------------------------------------
1092 subroutine sioflag(ndumps,fname,rsopts)
1093  use kinds, only : dp
1094  use size_m, only : ldimt, nfield
1095  use input, only : if3d, ifadvc, ifflow, ifheat
1096  use restart, only : ifgetx, ifgetu, ifgett, ifgetp, ifgetz, ifgetw
1097  use restart, only : ifgtps, ifgtim
1098  use string, only : indx1, ltrunc, indx_cut, ifgtrl, ljust, capit, csplit
1099  use tstep, only : time
1100  implicit none
1101 
1102  character(132) :: rsopts,fname
1103  character(2) :: s2
1104 
1105 ! Scratch variables..
1106  logical :: ifdeft,ifanyc
1107  CHARACTER(132) :: RSOPT ,LINE
1108  CHARACTER(1) :: RSOPT1(132),LINE1(132)
1109  equivalence(rsopt1,rsopt)
1110  equivalence(line1,line)
1111 
1112  integer :: len, len1, len4
1113  integer :: i, ndumps, ito, it1, it8, ita, itb, ixo, ivo, ipo
1114  real(DP) :: ttime, tdumps
1115 
1116 ! Parse filename
1117 
1118 ! CSPLIT splits S1 into two parts, delimited by S2.
1119 ! S1 returns with 2nd part of S1. CSPLIT returns 1st part.
1120 
1121  rsopt=rsopts
1122  call ljust(rsopt)
1123  call csplit(fname,rsopt,' ',1)
1124 ! check fname for user supplied extension.
1125  if (indx1(fname,'.',1) == 0) then
1126  len=ltrunc(fname,132)
1127  len1=len+1
1128  len4=len+4
1129  fname(len1:len4)='.fld'
1130  endif
1131 
1132 ! Parse restart options
1133 
1134 ! set default flags
1135 
1136  ifgetx= .false.
1137  ifgetz= .false.
1138  ifgetu= .false.
1139  ifgetw= .false.
1140  ifgetp= .false.
1141  ifgett= .false.
1142  do 100 i=1,ldimt-1
1143  ifgtps(i)= .false.
1144  100 END DO
1145  ifgtim= .true.
1146  ndumps=0
1147 
1148 ! Check for default case - just a filename given, no i/o options specified
1149 
1150  ifdeft= .true.
1151 
1152 ! Parse file for i/o options and/or dump number
1153 
1154  CALL capit(rsopt,132)
1155 
1156  IF (ltrunc(rsopt,132) /= 0) THEN
1157 
1158  ! Check for explicit specification of restart TIME.
1159 
1160  ito=indx_cut(rsopt,'TIME',4)
1161  ifgtim= .true.
1162  IF (ito /= 0) THEN
1163  ! user has specified the time explicitly.
1164  it1=indx_cut(rsopt,'=',1)
1165  it8=132-it1
1166  CALL blank(line,132)
1167  CALL chcopy(line,rsopt1(it1),it8)
1168  IF (ifgtrl(ttime,line)) THEN
1169  ifgtim= .false.
1170  time=ttime
1171  ENDIF
1172  ! remove the user specified time from the RS options line.
1173  ita=132-ito+1
1174  CALL blank(rsopt1(ito),ita)
1175  CALL ljust(line)
1176  it1=indx1(line,' ',1)
1177  itb=132-it1+1
1178  CALL chcopy(rsopt1(ito),line1(it1),itb)
1179  ENDIF
1180 
1181  ! Parse field specifications.
1182 
1183  ixo=indx_cut(rsopt,'X',1)
1184  IF (ixo /= 0) THEN
1185  ifdeft= .false.
1186  ifgetx= .true.
1187  IF (if3d) ifgetz= .true.
1188  ENDIF
1189 
1190  ivo=indx_cut(rsopt,'U',1)
1191  IF (ivo /= 0) THEN
1192  ifdeft= .false.
1193  ifgetu= .true.
1194  IF (if3d) ifgetw= .true.
1195  ENDIF
1196 
1197  ipo=indx_cut(rsopt,'P',1)
1198  IF (ipo /= 0) THEN
1199  ifdeft= .false.
1200  ifgetp= .true.
1201  ENDIF
1202 
1203  ito=indx_cut(rsopt,'T',1)
1204  IF (ito /= 0) THEN
1205  ifdeft= .false.
1206  ifgett= .true.
1207  ENDIF
1208 
1209  do 300 i=1,ldimt-1
1210  write (s2,301) i
1211  ipo=indx_cut(rsopt,s2,2)
1212  if (ipo /= 0) then
1213  ifdeft= .false.
1214  ifgtps(i)= .true.
1215  endif
1216  300 END DO
1217  301 format('P',i1)
1218 
1219  ! Get number of dumps from remainder of user supplied line.
1220  if (ifgtrl(tdumps,rsopt)) ndumps=int(tdumps)
1221  endif
1222 
1223 ! If no fields were explicitly specified, assume getting all fields.
1224  if (ifdeft) then
1225  ifgetx= .true.
1226  IF (if3d) ifgetz= .true.
1227  ifanyc= .false.
1228  DO 400 i=1,nfield
1229  IF (ifadvc(i)) ifanyc= .true.
1230  400 END DO
1231  IF (ifflow .OR. ifanyc) THEN
1232  ifgetu= .true.
1233  IF (if3d) ifgetw= .true.
1234  ENDIF
1235  IF (ifflow) ifgetp= .true.
1236  IF (ifheat) ifgett= .true.
1237  do 410 i=1,ldimt-1
1238  ifgtps(i)= .true.
1239  410 END DO
1240  ENDIF
1241 
1242  return
1243 end subroutine sioflag
1244 
1245 !----------------------------------------------------------------------
1246 subroutine mapdmp(sdump,tdump,ieg,nxr,nyr,nzr,if_byte_sw)
1247  use kinds, only : dp, r4
1248  use size_m, only : lx1, ly1, lz1, nx1, ny1, nz1, nid, lelt
1249  use parallel, only : np, gllnid, nullpid, gllel
1250  implicit none
1251 
1252  integer, parameter :: LXYZ1=LX1*LY1*LZ1
1253  integer, PARAMETER :: LXR=LX1+6
1254  integer, PARAMETER :: LYR=LY1+6
1255  integer, PARAMETER :: LZR=LZ1+6
1256  integer, PARAMETER :: LXYZR=LXR*LYR*LZR
1257 
1258  REAL(DP), allocatable :: SDUMP(:,:)
1259  REAL(r4) :: TDUMP(lxyzr)
1260  integer :: ieg, nxr, nyr, nzr
1261  logical :: if_byte_sw
1262 
1263  integer :: nxyz, nxyr, ierr, jnid, mtype, len, le1, ie
1264  real(DP) :: dummy
1265 
1266 
1267  nxyz=nx1*ny1*nz1
1268  nxyr=nxr*nyr*nzr
1269  ierr=0
1270 
1271 ! Serial processor code:
1272 
1273  IF (np == 1) THEN
1274  allocate(sdump(lxyz1,lelt))
1275 
1276  IF (if_byte_sw) call byte_reverse(tdump,nxyr,ierr)
1277  if(ierr /= 0) call exitti("Error in mapdmp")
1278  IF (nxr == nx1 .AND. nyr == ny1 .AND. nzr == nz1) THEN
1279  CALL copy4r(sdump(1,ieg),tdump,nxyz)
1280  ELSE
1281  ! do the map (assumes that NX=NY=NZ, or NX=NY, NZ=1)
1282  call mapab4r(sdump(1,ieg),tdump,nxr,1)
1283  ENDIF
1284 
1285  ELSE
1286 
1287  ! Parallel code - send data to appropriate processor and map.
1288 
1289  jnid=gllnid(ieg)
1290  mtype=3333+ieg
1291  len=4*nxyr
1292  le1=4
1293  IF (nid == 0 .AND. jnid /= 0) THEN
1294  ! hand-shake
1295  CALL csend(mtype,tdump,le1,jnid,nullpid)
1296  CALL crecv(mtype,dummy,le1)
1297  CALL csend(mtype,tdump,len,jnid,nullpid)
1298  ELSEIF (nid /= 0 .AND. jnid == nid) THEN
1299  ! Receive data from node 0
1300  CALL crecv(mtype,dummy,le1)
1301  CALL csend(mtype,tdump,le1,0,nullpid)
1302  CALL crecv(mtype,tdump,len)
1303  ENDIF
1304 
1305  ! If the data is targeted for this processor, then map
1306  ! to appropriate element.
1307 
1308  IF (jnid == nid) THEN
1309  allocate(sdump(lxyz1,lelt))
1310  ie=gllel(ieg)
1311  IF (if_byte_sw) call byte_reverse(tdump,nxyr,ierr)
1312  IF (nxr == nx1 .AND. nyr == ny1 .AND. nzr == nz1) THEN
1313  CALL copy4r(sdump(1,ie),tdump,nxyz)
1314  ELSE
1315  call mapab4r(sdump(1,ie),tdump,nxr,1)
1316  ENDIF
1317  ENDIF
1318  call err_chk(ierr,'Error using byte_reverse in mapdmp.$')
1319 
1320  ! End of parallel distribution/map routine.
1321 
1322  ENDIF
1323  return
1324 end subroutine mapdmp
1325 
1326 !---------------------------------------------------------------
1330 !---------------------------------------------------------------
1331 subroutine mapab4r(x,y,nxr,nel)
1332  use kinds, only : dp, r4
1333  use size_m, only : nid, ndim
1334  use size_m, only : nx1, ny1, nz1, lx1, ly1, lz1
1335  use wz_m, only : zgm1
1336  use speclib, only : zwgll, igllm
1337  implicit none
1338 
1339  integer :: nxr, nel
1340  REAL(DP) :: X(nx1,ny1,nz1,nel)
1341  REAL(r4) :: Y(nxr,nxr,nxr,nel)
1342 
1343  integer, parameter :: LXR=LX1+6
1344  integer, parameter :: LYR=LY1+6
1345  integer, parameter :: LZR=LZ1+6
1346  integer, parameter :: LXYZR=LXR*LYR*LZR
1347 
1348  real(DP) :: xa(lxyzr) ,xb(lx1,ly1,lzr) ,xc(lxyzr) &
1349  , zgmr(lxr) ,wgtr(lxr)
1350  real(DP), allocatable :: ires(:,:), itres(:,:)
1351 
1352  integer :: nzr, nyzr, nxy1, nxyzr
1353  integer :: ie, iz, izoff
1354  integer, save :: NOLD = 0
1355 
1356  allocate(ires(lxr,lxr), itres(lxr,lxr))
1357 
1358  nzr = nxr
1359  IF(nz1 == 1) nzr=1
1360  nyzr = nxr*nzr
1361  nxy1 = nx1*ny1
1362  nxyzr = nxr*nxr*nzr
1363 
1364  IF (nxr /= nold) THEN
1365  nold=nxr
1366  CALL zwgll(zgmr,wgtr,nxr)
1367  CALL igllm(ires,itres,zgmr,zgm1,nxr,nx1,nxr,nx1)
1368  IF (nid == 0) WRITE(6,10) nxr,nx1
1369  10 FORMAT(2x,'Mapping restart data from Nold=',i2 &
1370  ,' to Nnew=',i2,'.')
1371  ENDIF
1372 
1373  DO 1000 ie=1,nel
1374  call copy4r(xc,y(1,1,1,ie),nxyzr)
1375  CALL mxm(ires,nx1,xc,nxr,xa,nyzr)
1376  DO 100 iz=1,nzr
1377  izoff = 1 + (iz-1)*nx1*nxr
1378  CALL mxm(xa(izoff),nx1,itres,nxr,xb(1,1,iz),ny1)
1379  100 END DO
1380  IF (ndim == 3) THEN
1381  CALL mxm(xb,nxy1,itres,nzr,x(1,1,1,ie),nz1)
1382  ELSE
1383  CALL copy(x(1,1,1,ie),xb,nxy1)
1384  ENDIF
1385  1000 END DO
1386 
1387  return
1388 end subroutine mapab4r
1389 
1390 !------------------------------------------------------------------
1392 !------------------------------------------------------------------
1393 subroutine nekuic
1394  use size_m, only : nx1, ny1, nz1
1395  use input, only : ifmodel, ifkeps
1396  use nekuse, only : turbk, turbe, ux, uy, uz, temp
1397  use parallel, only : lglel
1398  use soln, only : vx, vy, vz, t, vxp, vyp, vzp, tp, jp
1399  use tstep, only : ifield, nelfld
1400  use turbo, only : ifldk, iflde
1401  implicit none
1402 
1403  integer :: nel, ijke, i, j, k, iel, ieg
1404 
1405  nel = nelfld(ifield)
1406 
1407  IF (ifmodel .AND. ifkeps .AND. ifield == ifldk) THEN
1408 
1409  DO iel=1,nel
1410  ieg = lglel(iel)
1411  DO k=1,nz1
1412  DO j=1,ny1
1413  DO i=1,nx1
1414  CALL nekasgn(i,j,k,iel)
1415  CALL useric(i,j,k,ieg)
1416  t(i,j,k,iel,ifield-1) = turbk
1417  enddo
1418  enddo
1419  enddo
1420  END DO
1421 
1422  ELSEIF (ifmodel .AND. ifkeps .AND. ifield == iflde) THEN
1423 
1424  DO iel=1,nel
1425  ieg = lglel(iel)
1426  DO k=1,nz1
1427  DO j=1,ny1
1428  DO i=1,nx1
1429  CALL nekasgn(i,j,k,iel)
1430  CALL useric(i,j,k,ieg)
1431  t(i,j,k,iel,ifield-1) = turbe
1432  enddo
1433  enddo
1434  enddo
1435  END DO
1436 
1437  ELSE
1438 
1439  DO iel=1,nel
1440  ieg = lglel(iel)
1441  DO k=1,nz1
1442  DO j=1,ny1
1443  DO i=1,nx1
1444  CALL nekasgn(i,j,k,iel)
1445  CALL useric(i,j,k,ieg)
1446  if (jp == 0) then
1447 #ifdef SIMPLE_IO
1448  vx(i,j,k,iel) = ux
1449  vy(i,j,k,iel) = uy
1450  vz(i,j,k,iel) = uz
1451  t(i,j,k,iel,1) = temp
1452 #else
1453  IF (ifield == 1) THEN
1454  vx(i,j,k,iel) = ux
1455  vy(i,j,k,iel) = uy
1456  vz(i,j,k,iel) = uz
1457  ELSEIF (ifield == ifldmhd) THEN
1458  bx(i,j,k,iel) = ux
1459  by(i,j,k,iel) = uy
1460  bz(i,j,k,iel) = uz
1461  ELSE
1462  t(i,j,k,iel,ifield-1) = temp
1463  ENDIF
1464 #endif
1465  else
1466  ijke = i+nx1*((j-1)+ny1*((k-1) + nz1*(iel-1)))
1467  IF (ifield == 1) THEN
1468  vxp(ijke,jp) = ux
1469  vyp(ijke,jp) = uy
1470  vzp(ijke,jp) = uz
1471  ELSE
1472  tp(ijke,ifield-1,jp) = temp
1473  ENDIF
1474  endif
1475  enddo
1476  enddo
1477  enddo
1478  END DO
1479 
1480  ENDIF
1481 
1482  return
1483 end subroutine nekuic
1484 
1485 !-----------------------------------------------------------------------
1486 logical function if_byte_swap_test(bytetest,ierr)
1487  use kinds, only : dp, r4
1488  use size_m
1489  implicit none
1490 
1491  real(r4) :: bytetest
1492  integer :: ierr
1493 
1494  real(r4) :: test2
1495  real(r4), save :: test_pattern
1496  real(DP) :: eps, etest
1497 
1498  test_pattern = 6.54321_r4
1499  eps = 0.00020
1500  etest = abs(test_pattern-bytetest)
1501  if_byte_swap_test = .true.
1502  if (etest <= eps) if_byte_swap_test = .false.
1503 
1504  test2 = bytetest
1505  call byte_reverse(test2,1,ierr)
1506  if (nid == 0) &
1507  write(6,*) 'byte swap:',if_byte_swap_test,bytetest,test2
1508  return
1509 end function if_byte_swap_test
1510 
1511 !-----------------------------------------------------------------------
1513 subroutine geom_reset(icall)
1514  use kinds, only : dp
1515  use size_m, only : lx1, ly1, lz1, lelt, lx3
1516  use size_m, only : nx1, ny1, nz1, nelt, nid
1517  implicit none
1518 
1519  integer :: icall
1520 
1521  real(DP), allocatable :: XM3 (:,:,:,:), YM3(:,:,:,:), ZM3(:,:,:,:)
1522 
1523  integer :: ntot
1524 
1525  if(nid == 0) write(6,*) 'regenerate geometry data',icall
1526 
1527  ntot = nx1*ny1*nz1*nelt
1528 
1529  if (lx3 == lx1) then
1530  CALL geom1()!XM1,YM1,ZM1)
1531  else
1532  allocate(xm3(lx1,ly1,lz1,lelt), ym3(lx1,ly1,lz1,lelt), zm3(lx1,ly1,lz1,lelt))
1533 #if 0
1534  call map13_all(xm3,xm1)
1535  call map13_all(ym3,ym1)
1536  if (if3d) call map13_all(zm3,zm1)
1537  CALL geom1(xm3,ym3,zm3)
1538 #endif
1539  deallocate(xm3,ym3,zm3)
1540  endif
1541 
1542  CALL geom2
1543  CALL updmsys(1)
1544  CALL volume
1545  CALL setinvm
1546  CALL setdef
1547  CALL sfastax
1548 
1549  if(nid == 0) then
1550  write(6,*) 'done :: regenerate geometry data',icall
1551  write(6,*) ' '
1552  endif
1553 
1554  return
1555 end subroutine geom_reset
1556 
1557 !-----------------------------------------------------------------------
1559 subroutine dsavg(u)
1560  use kinds, only : dp
1561  use size_m, only : nx1, ny1, nz1, nelv, nelt
1562  use size_m, only : lx1, ly1, lz1, lelt
1563  use input, only : ifflow
1564  use soln, ONLY : vmult, tmult
1565  use tstep, only : ifield
1566 
1567  implicit none
1568  real(DP) :: u(lx1,ly1,lz1,lelt)
1569 
1570  integer :: ifieldo, ntot
1571 
1572 
1573  ifieldo = ifield
1574  if (ifflow) then
1575  ifield = 1
1576  ntot = nx1*ny1*nz1*nelv
1577  call dssum(u)
1578  u = u * vmult
1579  else
1580  ifield = 2
1581  ntot = nx1*ny1*nz1*nelt
1582  call dssum(u)
1583  u = u * tmult(:,:,:,:,1)
1584  endif
1585  ifield = ifieldo
1586 
1587  return
1588 end subroutine dsavg
1589 
1590 !-----------------------------------------------------------------------
1592 subroutine mbyte_open(hname,fid,ierr)
1593  use size_m, only : nid
1594  use iso_c_binding, only : c_null_char
1595  use string, only : ltrunc, indx1
1596  use tstep, only : istep
1597  use parallel, only : np
1598  implicit none
1599 
1600  integer :: fid
1601  character(132) :: hname
1602 
1603  character(8) :: fmt,s8
1604  character(8), save :: eight = "????????"
1605 
1606  character(132) :: fname
1607 
1608  integer :: len, ipass, k, i1, ierr
1609 
1610  len = ltrunc(hname,132)
1611  call chcopy(fname,hname,len)
1612  fname(len+1:len+1) = c_null_char
1613 
1614  do ipass=1,2 ! 2nd pass, in case 1 file/directory
1615  do k=8,1,-1
1616  i1 = indx1(fname,eight,k)
1617  if (i1 /= 0) then ! found k??? string
1618  write(fmt,1) k,k
1619  1 format('(i',i1,'.',i1,')')
1620  write(s8,fmt) fid
1621  call chcopy(fname(i1:),s8,k)
1622  goto 10
1623  endif
1624  enddo
1625  10 continue
1626  enddo
1627 
1628 #ifdef MPIIO
1629  call byte_open_mpi(fname,ifh_mbyte,ierr)
1630  if(nid == 0) write(6,6) istep,(fname(k:k),k=1,len)
1631  6 format(1i8,' OPEN: ',132a1)
1632 #else
1633  call byte_open(fname,ierr)
1634  if (np < 1024) then
1635  write(6,6) nid,istep,(fname(k:k),k=1,len)
1636  6 format(2i8,' OPEN: ',132a1)
1637  endif
1638 #endif
1639 
1640  return
1641 end subroutine mbyte_open
1642 !-----------------------------------------------------------------------
integer function gllel(ieg)
subroutine nekuic
User specified fortran function (=0 if not specified)
Definition: ic.F90:1393
subroutine mapab4r(x, y, nxr, nel)
Interpolate Y(NXR,NYR,NZR,NEL) to X(NX1,NY1,NZ1,NEL) (assumes that NXR=NYR=NZR, or NXR=NYR...
Definition: ic.F90:1331
subroutine dssum(u)
Direct stiffness sum.
Definition: dssum.F90:54
subroutine bcast(buf, len)
Definition: comm_mpi.F90:289
#define byte_close
Definition: byte.c:36
subroutine lbcast(ifif)
Broadcast logical variable to all processors.
Definition: comm_mpi.F90:270
integer function i1_from_char(s1)
Definition: string_mod.F90:9
cleaned
Definition: tstep_mod.F90:2
subroutine slogic(iffort, ifrest, ifprsl, nfiles)
Set up logicals for initial conditions.
Definition: ic.F90:406
Input parameters from preprocessors.
Definition: input_mod.F90:11
subroutine, public load_ic()
Load initial condition from a previous multi-file output.
Definition: io_mod.F90:21
Definition: soln_mod.F90:1
cleaned
Definition: wz_mod.F90:2
subroutine mxm(a, n1, b, n2, c, n3)
Compute matrix-matrix product C = A*B.
Definition: mxm_wrapper.F90:7
real(dp) function glmax(a, n)
Definition: math.F90:363
subroutine mbyte_open(hname, fid, ierr)
open blah000.fldnn
Definition: ic.F90:1592
subroutine crecv(mtype, buf, lenm)
Definition: comm_mpi.F90:223
subroutine geom_reset(icall)
Generate geometry data.
Definition: ic.F90:1513
#define byte_read
Definition: byte.c:38
void exitt()
Definition: comm_mpi.F90:411
subroutine dsavg(u)
Take direct stiffness avg of u.
Definition: ic.F90:1559
logical function if_byte_swap_test(bytetest, ierr)
Definition: ic.F90:1486
integer function indx1(S1, S2, L2)
Definition: string_mod.F90:43
subroutine setics
Set initial conditions.
Definition: ic.F90:5
#define byte_open
Definition: byte.c:35
subroutine setup_convect(igeom)
Definition: convect.F90:11
integer function indx_cut(S1, S2, L2)
INDX_CUT is returned with the location of S2 in S1 (0 if not found) S1 is returned with 1st occurance...
Definition: string_mod.F90:67
integer function lglel(iel)
subroutine copy(a, b, n)
Definition: math.F90:52
#define byte_reverse
Definition: byte.c:33
subroutine sfastax()
For undeformed elements, set up appropriate elemental matrices and geometric factors for fast evaluat...
Definition: hmholtz.F90:387
integer function gllnid(ieg)
subroutine sioflag(ndumps, fname, rsopts)
Set IO flags according to Restart Options File, RSOPTS.
Definition: ic.F90:1092
logical function ifgtrl(VALUE, LINE)
Read VALUE from LINE and set IFGTRL to .TRUE. if successful, IFGTRL to .FALSE. otherwise. This complicated function is necessary thanks to the Ardent, which won't allow free formatted reads (*) from internal strings!
Definition: string_mod.F90:188
subroutine updmsys(IFLD)
Definition: subs1.F90:962
cleaned
Definition: parallel_mod.F90:2
cleaned
Definition: restart_mod.F90:2
subroutine capit(lettrs, n)
Capitalizes string of length n.
Definition: string_mod.F90:161
cleaned
Definition: turbo_mod.F90:2
subroutine blank(A, N)
blank a string
Definition: math.F90:38
subroutine restart_driver(nfiles)
driver for restarts (1) Open restart file(s) (2) Check previous spatial discretization (3) Map (K1...
Definition: ic.F90:547
subroutine nekgsync()
Definition: comm_mpi.F90:318
cleaned
Definition: mvgeom_mod.F90:2
subroutine copy4r(a, b, n)
Definition: prepost.F90:644
Geometry arrays.
Definition: geom_mod.F90:2
subroutine, public zwgll(Z, W, NP)
Definition: speclib.F90:95
subroutine csplit(s0, s1, s2, l0)
split string S1 into two parts, delimited by S2.
Definition: string_mod.F90:95
subroutine setinvm()
Invert the mass matrix. 1) Copy BM1 to BINVM1 2) Perform direct stiffness summation on BINVM1 3) Comp...
Definition: coef.F90:1168
subroutine nekasgn(IX, IY, IZ, IEL)
Assign NEKTON variables for definition (by user) of boundary conditions at collocation point (IX...
Definition: bdry.F90:1014
subroutine mapdmp(sdump, tdump, ieg, nxr, nyr, nzr, if_byte_sw)
Definition: ic.F90:1246
subroutine volume
Compute the volume based on mesh M1 and mesh M2.
Definition: coef.F90:914
subroutine geom2
Routine to generate all elemental geometric data for mesh 2 (Gauss-Legendre mesh). RXM2, RYM2, RZM2 - dr/dx, dr/dy, dr/dz SXM2, SYM2, SZM2 - ds/dx, ds/dy, ds/dz TXM2, TYM2, TZM2 - dt/dx, dt/dy, dt/dz JACM2 - Jacobian BM2 - Mass matrix.
Definition: coef.F90:725
subroutine chcopy(a, b, n)
Definition: math.F90:63
subroutine err_chk(ierr, istring)
Definition: comm_mpi.F90:356
cleaned
Definition: nekuse_mod.F90:2
static uint np
Definition: findpts_test.c:63
subroutine ljust(string)
left justify string
Definition: string_mod.F90:134
integer function ltrunc(string, l)
Definition: string_mod.F90:260
subroutine geom1()
Routine to generate all elemental geometric data for mesh 1. Velocity formulation : global-to-local m...
Definition: coef.F90:383
subroutine setdef()
Set up deformed element logical switches.
Definition: genxyz.F90:4
subroutine exitti(stringi, idata)
Definition: comm_mpi.F90:328
subroutine csend(mtype, buf, len, jnid, jpid)
Definition: comm_mpi.F90:209
subroutine byte_open_mpi(fname, mpi_fh, ierr)
Definition: byte_mpi.F90:13
subroutine, public igllm(I12, IT12, Z1, Z2, NZ1, NZ2, ND1, ND2)
Definition: speclib.F90:1197
Definition: io_mod.F90:9