KTH framework for Nek5000 toolboxes; testing version  0.0.1
ic.f
Go to the documentation of this file.
1 c-----------------------------------------------------------------------
2  subroutine setics
3 C-----------------------------------------------------------------------
4 C
5 C Set initial conditions.
6 C
7 C-----------------------------------------------------------------------
8  include 'SIZE'
9  include 'DEALIAS'
10  include 'INPUT'
11  include 'IXYZ'
12  include 'GEOM'
13  include 'SOLN'
14  include 'MASS'
15  include 'MVGEOM'
16  include 'PARALLEL'
17  include 'TSTEP'
18 
19  logical iffort( ldimt1,0:lpert)
20  $ , ifrest(0:ldimt1,0:lpert)
21  $ , ifprsl( ldimt1,0:lpert)
22 
23  LOGICAL IFANYP
24  common /inelr/ nelrr
25  common /ctmp1/ work(lx1,ly1,lz1,lelv)
26  $ , ta1(lx2,ly1,lz1)
27  $ , ta2(lx2,ly2,lz1)
28  integer*8 ntotg,nn
29 
30  real psmax(ldimt)
31 
32  if(nio.eq.0) write(6,*) 'set initial conditions'
33 
34 
35  nxyz2=lx2*ly2*lz2 ! Initialize all fields:
36  ntot2=nxyz2*nelv
37  nxyz1=lx1*ly1*lz1
38  ntott=nelt*nxyz1
39  ntotv=nelv*nxyz1
40  ltott=lelt*nxyz1
41 
42  call rzero(vx,ntott)
43  call rzero(vy,ntott)
44  call rzero(vz,ntott)
45  call rzero(pr,nxyz2*nelt)
46  do 10 ifld=1,ldimt
47  call rzero(t(1,1,1,1,ifld),ntott)
48  10 continue
49 
50  jp = 0 ! Set counter for perturbation analysis
51 
52  irst = param(46) ! for lee's restart (rarely used)
53  if (irst.gt.0) call setup_convect(2)
54 
55 c If moving geometry then add a perturbation to the
56 c mesh coordinates (see Subroutine INIGEOM)
57 
58  if (ifmvbd) call ptbgeom
59 
60 C Find out what type of i.c. is requested
61 C Current options:
62 C
63 C (1) - User specified fortran function (default is zero i.c.)
64 C (2) - Restart from file(s)
65 C (3) - Activate pre-solver => steady diffusion / steady Stokes
66 C
67 C If option (2) is requested, also return with the name of the
68 C restart file(s) together with the associated dump number
69 
70  call slogic (iffort,ifrest,ifprsl,nfiles)
71 
72 C ***** TEMPERATURE AND PASSIVE SCALARS ******
73 C
74 C Check if any pre-solv necessary for temperature/passive scalars
75 
76  ifanyp = .false.
77  DO 100 ifield=2,nfield
78  IF (ifprsl(ifield,jp)) THEN
79  IF (nio.EQ.0) WRITE(6,101) ifield
80  ifanyp = .true.
81  ENDIF
82  100 CONTINUE
83  101 FORMAT(2x,'Using PRESOLVE option for field',i2,'.')
84 
85 C Fortran function initial conditions for temp/pass. scalars.
86  maxfld = nfield
87  if (ifmhd) maxfld = npscal+3
88 
89 c Always call nekuic (pff, 12/7/11)
90  do ifield=1,maxfld
91  if (nio.eq.0) write(6,*) 'nekuic (1) for ifld ', ifield
92  call nekuic
93  enddo
94 
95 C If any pre-solv, do pre-solv for all temperatur/passive scalar fields
96  if (ifanyp) call prsolvt
97 
98  jp = 0 ! jp=0 --> base field, not perturbation field
99  do 200 ifield=2,maxfld
100  if (iffort(ifield,jp)) then
101  if (nio.eq.0) write(6,*) 'call nekuic for ifld ', ifield
102  call nekuic
103  endif
104  200 continue
105 
106  if (ifpert) then
107  ifield=2
108  do jp=1,npert
109  if (nio.eq.0) write(6,*) 'nekuicP',ifield,jp,iffort(ifield,jp)
110  if (iffort(ifield,jp)) call nekuic
111  enddo
112  endif
113  jp = 0
114 
115 
116  call nekgsync()
117  call restart(nfiles) ! Check restart files
118  call nekgsync()
119 
120 
121 C ***** VELOCITY ******
122 C (If restarting for V, we're done,
123 C ...else, do pre-solv for fluid if requested.)
124 
125  ifield = 1
126  if (ifprsl(ifield,jp)) call prsolvv
127 
128 
129 C Fortran function initial conditions for velocity.
130  ifield = 1
131  if (iffort(ifield,jp)) then
132  if (nio.eq.0) write(6,*) 'call nekuic for vel '
133  call nekuic
134  endif
135 c
136  if (ifpert) then
137  ifield=1
138  do jp=1,npert
139  if (iffort(ifield,jp)) call nekuic
140  if (nio.eq.0) write(6,*) 'ic vel pert:',iffort(1,jp),jp
141  enddo
142  endif
143  jp = 0
144 
145  ntotv = lx1*ly1*lz1*nelv
146 
147 C Initial mesh velocities
148  if (ifmvbd) call opcopy (wx,wy,wz,vx,vy,vz)
149  if (ifmvbd.and..not.ifrest(0,jp)) call meshv (2)
150 
151 C If convection-diffusion of a passive scalar with a fixed velocity field,
152 C make sure to fill up lagged arrays since this will not be done in
153 C the time-stepping procedure (no flow calculation) (01/18/91 -EMR).
154 
155  if (.not.ifflow.and.ifheat) then
156  itest=0
157  DO 400 ifield=2,nfield
158  IF (ifadvc(ifield)) itest=1
159  400 CONTINUE
160  IF (itest.EQ.1) THEN
161  nbdmax = 3
162  nbdsav = nbdinp
163  nbdinp = nbdmax
164  DO 500 i=1,nbdmax
165  CALL lagvel
166  500 CONTINUE
167  nbdinp = nbdsav
168  ENDIF
169  ENDIF
170 
171 C Ensure that all processors have the same time as node 0.
172  if (nid.ne.0) time=0.0
173  time=glsum(time,1)
174 
175  nxyz1=lx1*ly1*lz1
176  ntott=nelt*nxyz1
177  ntotv=nelv*nxyz1
178  nn = nxyz1
179  ntotg=nelgv*nn
180 
181  if (.not.ifdg) then
182  ifield = 2
183  if (ifflow) ifield = 1
184  call rone(work,ntotv)
185  ifield = 1
186  call dssum (work,lx1,ly1,lz1)
187  call col2 (work,vmult,ntotv)
188  rdif = glsum(work,ntotv)
189  rtotg = ntotg
190  rdif = (rdif-rtotg)/rtotg
191  if (abs(rdif).gt.1e-14) then
192  if(nid.eq.0)write(*,*)'ERROR: dssum test has failed!',rdif
193  call exitt
194  endif
195  endif
196 
197  call projfld_c0 ! ensure fields are contiguous
198 
199 C print min values
200  xxmax = glmin(xm1,ntott)
201  yymax = glmin(ym1,ntott)
202  zzmax = glmin(zm1,ntott)
203 
204  vxmax = glmin(vx,ntotv)
205  vymax = glmin(vy,ntotv)
206  vzmax = glmin(vz,ntotv)
207  prmax = glmin(pr,ntot2)
208 
209  ntot = nxyz1*nelfld(2)
210  ttmax = glmin(t ,ntott)
211 
212  do i=1,ldimt-1
213  ntot = nxyz1*nelfld(i+2)
214  psmax(i) = glmin(t(1,1,1,1,i+1),ntot)
215  enddo
216 
217  if (nio.eq.0) then
218  write(6,19) xxmax,yymax,zzmax
219  19 format(' xyz min ',5g13.5)
220  endif
221  if (nio.eq.0) then
222  write(6,20) vxmax,vymax,vzmax,prmax,ttmax
223  20 format(' uvwpt min',5g13.5)
224  endif
225  if (ldimt-1.gt.0) then
226  if (nio.eq.0) write(6,21) (psmax(i),i=1,ldimt-1)
227  21 format(' PS min ',50g13.5)
228  endif
229 
230 c print max values
231  xxmax = glmax(xm1,ntott)
232  yymax = glmax(ym1,ntott)
233  zzmax = glmax(zm1,ntott)
234 
235  vxmax = glmax(vx,ntotv)
236  vymax = glmax(vy,ntotv)
237  vzmax = glmax(vz,ntotv)
238  prmax = glmax(pr,ntot2)
239 
240  ntot = nxyz1*nelfld(2)
241  ttmax = glmax(t ,ntott)
242 
243  do i=1,ldimt-1
244  ntot = nxyz1*nelfld(i+2)
245  psmax(i) = glmax(t(1,1,1,1,i+1),ntot)
246  enddo
247 
248  if (nio.eq.0) then
249  write(6,16) xxmax,yymax,zzmax
250  16 format(' xyz max ',5g13.5)
251  endif
252 
253  if (nio.eq.0) then
254  write(6,17) vxmax,vymax,vzmax,prmax,ttmax
255  17 format(' uvwpt max',5g13.5)
256  endif
257 
258  if (ldimt-1.gt.0) then
259  if (nio.eq.0) then
260  write(6,18) (psmax(i),i=1,ldimt-1)
261  18 format(' PS max ',50g13.5)
262  endif
263  endif
264 
265  if (iflomach .and. ifdp0dt) then
266  if (p0th.le.0) call exitti('Invalid thermodynamic pressure!$',1)
267  if (gamma0.lt.0) call exitti('Invalid gamma0!$',1)
268  endif
269 
270  if (ifrest(0,jp)) then ! mesh has been read in.
271  if (nio.eq.0) write(6,*) 'Restart: recompute geom. factors.'
272  call geom_reset(1) ! recompute geometric factors
273  endif
274 
275  if(nio.eq.0) then
276  write(6,*) 'done :: set initial conditions'
277  write(6,*) ' '
278  endif
279 
280  return
281  end
282 c-----------------------------------------------------------------------
283  subroutine slogic (iffort,ifrest,ifprsl,nfiles)
284 C---------------------------------------------------------------------
285 C
286 C Set up logicals for initial conditions.
287 C
288 C---------------------------------------------------------------------
289  include 'SIZE'
290  include 'INPUT'
291  include 'RESTART'
292 c
293  logical iffort( ldimt1,0:lpert)
294  $ , ifrest(0:ldimt1,0:lpert)
295  $ , ifprsl( ldimt1,0:lpert)
296 c
297  character*132 line,fname,cdum
298  character*2 s2
299  character*1 line1(132)
300  equivalence(line1,line)
301 C
302 C Default is user specified fortran function (=0 if not specified)
303 C
304  nfldt = nfield
305  if (ifmhd) nfldt = nfield+1
306 
307  do jp=0,npert
308  ifrest(0,jp) = .false.
309  do ifld=1,nfldt
310  iffort(ifld,jp) = .true.
311  ifrest(ifld,jp) = .false.
312  ifprsl(ifld,jp) = .false.
313  enddo
314  enddo
315 
316  jp = 0
317  nfiles=0
318 
319 c Check for Presolve options
320 
321  DO 1000 iline=1,15
322  line=initc(iline)
323  CALL capit(line,132)
324  IF (indx1(line,'PRESOLV',7).NE.0) THEN
325 C found a presolve request
326  CALL blank(initc(iline),132)
327  CALL ljust(line)
328  CALL csplit(cdum,line,' ',1)
329 C
330  IF (ltrunc(line,132).EQ.0) THEN
331  IF (nio.EQ.0) WRITE(6,700)
332  700 FORMAT(/,2x,'Presolve options: ALL')
333 C default - all fields are presolved.
334  DO 800 ifield=1,nfldt
335  ifprsl(ifield,jp) = .true.
336  iffort(ifield,jp) = .false.
337  800 CONTINUE
338  ELSE
339 C check line for arguments
340 C
341  ll=ltrunc(line,132)
342  IF (nio.EQ.0) WRITE(6,810) (line1(l),l=1,ll)
343  810 FORMAT(/,2x,'Presolve options: ',132a1)
344 C
345  IF (indx_cut(line,'U',1).NE.0) THEN
346  ifprsl(1,jp) = .true.
347  iffort(1,jp) = .false.
348  ENDIF
349 C
350  IF (indx_cut(line,'T',1).NE.0) THEN
351  ifprsl(2,jp) = .true.
352  iffort(2,jp) = .false.
353  ENDIF
354 C
355  DO 900 ifield=3,npscal+2
356  ip=ifield-2
357  WRITE(s2,901) ip
358  IF (indx_cut(line,s2,2).NE.0) THEN
359  ifprsl(ifield,jp) = .true.
360  iffort(ifield,jp) = .false.
361  ENDIF
362  900 CONTINUE
363  901 FORMAT('P',i1)
364  ENDIF
365  ENDIF
366  1000 CONTINUE
367 C
368 C Check for restart options
369 C
370  jp = 0
371  DO 2000 iline=1,15
372  if (ifpert) jp=iline-1
373  line=initc(iline)
374  IF (ltrunc(line,132).NE.0) THEN
375 C found a filename
376  nfiles=nfiles+1
377  initc(nfiles)=line
378 C
379 C IF (NIO.EQ.0.AND.NFILES.EQ.1) WRITE(6,1010) LINE
380  IF (nio.EQ.0.) WRITE(6,1010) line
381  1010 FORMAT(1x,'Checking restart options: ',a132)
382 c IF (NID.EQ.0) WRITE(6,'(A132)') LINE
383 C
384 C Parse restart options
385 
386  call sioflag(ndumps,fname,line)
387 
388  if (ifgetx) then
389  ifrest(0,jp) = .true.
390  endif
391  if (ifgetu) then
392  iffort(1,jp) = .false.
393  ifprsl(1,jp) = .false.
394  ifrest(1,jp) = .true.
395  endif
396  if (ifgett) then
397  iffort(2,jp) = .false.
398  ifprsl(2,jp) = .false.
399  ifrest(2,jp) = .true.
400  endif
401  do 1900 ifield=3,nfldt
402 c write(6,*) 'ifgetps:',(ifgtps(k),k=1,ldimt-1)
403  if (ifgtps(ifield-2)) then
404  iffort(ifield,jp) = .false.
405  ifprsl(ifield,jp) = .false.
406  ifrest(ifield,jp) = .true.
407  endif
408  1900 continue
409  endif
410  2000 continue
411 
412  return
413  end
414 c-----------------------------------------------------------------------
415  subroutine restart(nfiles)
416 C----------------------------------------------------------------------
417 C
418 C (1) Open restart file(s)
419 C (2) Check previous spatial discretization
420 C (3) Map (K1,N1) => (K2,N2) if necessary
421 C
422 C nfiles > 1 has several implications:
423 C
424 C i. For std. run, data is taken from last file in list, unless
425 C explicitly specified in argument list of filename
426 C
427 C ii. For MHD and perturbation cases, 1st file is for U,P,T;
428 C subsequent files are for B-field or perturbation fields
429 C
430 C
431 C----------------------------------------------------------------------
432  include 'SIZE'
433  include 'TOTAL'
434  include 'RESTART'
435 
436  common /inelr/ nelrr
437 
438  parameter(lxr=lx1+6)
439  parameter(lyr=ly1+6)
440  parameter(lzr=lz1+6)
441  parameter(lxyzr=lxr*lyr*lzr)
442  parameter(lxyzt=lx1*ly1*lz1*lelt)
443  parameter(lpsc9=ldimt+9)
444 
445  common /scrcg/ pm1(lx1*ly1*lz1,lelv)
446  COMMON /scrns/ sdump(lxyzt,7)
447  integer mesg(40)
448 
449 C note, this usage of CTMP1 will be less than elsewhere if NELT ~> 9.
450  COMMON /ctmp1/ tdump(lxyzr,lpsc9)
451  real*4 tdump
452 c
453  REAL SDMP2(LXYZT,LDIMT)
454 
455 c cdump comes in via PARALLEL (->TOTAL)
456 
457  character*30 excoder
458  character*1 excoder1(30)
459  equivalence(excoder,excoder1)
460 
461 
462  character*132 fname
463  character*1 fname1(132)
464  equivalence(fname1,fname)
465 
466  integer hnami (30)
467  character*132 hname
468  character*1 hname1(132)
469  equivalence(hname,hname1)
470  equivalence(hname,hnami )
471 
472  CHARACTER*132 header
473 
474 C Local logical flags to determine whether to copy data or not.
475  logical ifok,iffmat
476  integer iposx,iposz,iposu,iposw,iposp,ipost,ipsps(ldimt1)
477 
478  logical ifbytsw, if_byte_swap_test
479  real*4 bytetest
480 
481 c
482  ifok=.false.
483  ifbytsw = .false.
484 
485  if(nfiles.lt.1) return
486 
487  if(nio.eq.0) write(6,*) 'Reading checkpoint data '
488 
489 c use new reader (only binary support)
490  p67 = abs(param(67))
491  if (p67.eq.6.0) then
492  do ifile=1,nfiles
493  call sioflag(ndumps,fname,initc(ifile))
494  call mfi(fname,ifile)
495  enddo
496  call bcast(time,wdsize)! Sync time across processors
497  return
498  endif
499 
500 c use old reader (for ASCII + old binary support)
501 
502  if (param(67).lt.1.0) then ! zero only. should be abs.
503  iffmat=.true. ! ascii
504  else
505  iffmat=.false. ! binary
506  endif
507 
508  do 6000 ifile=1,nfiles
509  call sioflag(ndumps,fname,initc(ifile))
510  ierr = 0
511  if (nid.eq.0) then
512 
513  if (iffmat) then
514  open (unit=91,file=fname,status='old',err=500)
515  else
516  len= ltrunc(fname,79)
517  call izero (hnami,20)
518  call chcopy(hname1,fname,len)
519 c test for presence of file
520  open (unit=91,file=hname
521  $ ,form='unformatted',status='old',err=500)
522  close(unit=91)
523  call byte_open(hname,ierr)
524  if(ierr.ne.0) goto 500
525  ENDIF
526  ifok = .true.
527  endif
528 
529  500 continue
530  call lbcast(ifok)
531  if (.not.ifok) goto 5000
532 
533  ndumps = 1
534 C
535 C Only NODE 0 reads from the disk.
536 C
537  DO 1000 idump=1,ndumps
538 
539  IF (nid.EQ.0) THEN
540  ! read header
541  if (iffmat) then
542  ierr = 2
543  if(mod(param(67),1.0).eq.0) then ! old header format
544  if(nelgt.lt.10000) then
545  read(91,91,err=10,end=10)
546  $ neltr,nxr,nyr,nzr,rstime,istepr,(excoder1(i),i=1,30)
547  91 format(4i4,1x,g13.4,i5,1x,30a1)
548  ierr=0
549  else
550  read(91,92,err=10,end=10)
551  $ neltr,nxr,nyr,nzr,rstime,istepr,(excoder1(i),i=1,30)
552  92 format(i10,3i4,1p1e18.9,i9,1x,30a1)
553  ierr=0
554  endif
555  else ! new head format
556  read(91,'(A132)',err=10,end=10) header
557  read(header,*)
558  & neltr,nxr,nyr,nzr,rstime,istepr,excoder
559  ierr=0
560  endif
561  else
562  if(mod(param(67),1.0).eq.0) then ! old header format
563  call byte_read(hnami,20,ierr)
564  if(ierr.ne.0) goto 10
565  icase = 2
566  if (nelgt.lt.10000) icase = 1
567  ipass = 0
568  93 continue ! test each possible case UGLY (7/31/07)
569  if(ipass.lt.2) then
570  ipass = ipass+1
571  if(icase.eq.1) then
572  read(hname,'(4i4,1x,g13.4,i5,1x,30a1)',
573  $ err=94,end=94)
574  $ neltr,nxr,nyr,nzr,rstime,istepr,
575  $ (excoder1(i),i=1,30)
576  goto 95
577  else
578  read(hname,'(i10,3i4,1P1e18.9,i9,1x,30a1)',
579  $ err=94,end=94)
580  $ neltr,nxr,nyr,nzr,rstime,istepr,
581  $ (excoder1(i),i=1,30)
582  goto 95
583  endif
584  94 icase = 3-icase ! toggle: 2-->1 1-->2
585  goto 93
586  else
587  ierr=2
588  goto 10
589  endif
590  95 continue
591  else ! new head format
592  call byte_read(header,20,ierr)
593  if(ierr.ne.0) goto 10
594  read(header,*)
595  & neltr,nxr,nyr,nzr,rstime,istepr,excoder
596  endif
597  call byte_read(bytetest,1,ierr)
598 c call byte_read2(bytetest,1,ierr)
599  if(ierr.ne.0) goto 10
600  ifbytsw = if_byte_swap_test(bytetest,ierr)
601  if(ierr.ne.0) goto 10
602  endif
603  mesg(1) = neltr
604  mesg(2) = nxr
605  mesg(3) = nyr
606  mesg(4) = nzr
607  write(6,*) 'Read mode: ', param(67)
608  write(6,333)'neltr,nxr,nyr,nzr: ', neltr,nxr,nyr,nzr
609  333 format(a,i9,3i4)
610  call chcopy(mesg(5),excoder1,20)
611  len = 14*isize
612  endif
613  10 call err_chk(ierr,'Error reading restart header. Abort.$')
614 
615  IF (idump.EQ.1) THEN
616  len = 14*isize
617  call bcast(mesg,len)
618  neltr = mesg(1)
619  nxr = mesg(2)
620  nyr = mesg(3)
621  nzr = mesg(4)
622  call chcopy(excoder1,mesg(5),20)
623 
624  call lbcast(ifbytsw)
625 
626 C Bounds checking on mapped data.
627  IF (nxr.GT.lxr) THEN
628  WRITE(6,20) nxr,lx1
629  20 FORMAT(//,2x,
630  $ 'ABORT: Attempt to map from',i3,
631  $ ' to N=',i3,'.',/,2x,
632  $ 'NEK5000 currently supports mapping from N+6 or less.'
633  $ ,/,2x,'Increase N or LXR in IC.FOR.')
634  CALL exitt
635  ENDIF
636 C
637 C Figure out position of data in file "IFILE"
638 C
639  nouts=0
640  iposx=0
641  iposy=0
642  iposz=0
643  iposu=0
644  iposv=0
645  iposw=0
646  iposp=0
647  ipost=0
648  DO 40 i=1,npscal
649  ipsps(i)=0
650  40 CONTINUE
651 
652  ips = 0
653  nps = 0
654  DO 50 i=1, 30
655  IF (excoder1(i).EQ.'X') THEN
656  nouts=nouts + 1
657  iposx=nouts
658  nouts=nouts+1
659  iposy=nouts
660  IF (if3d) THEN
661  nouts=nouts + 1
662  iposz=nouts
663  ENDIF
664  ENDIF
665  IF (excoder1(i).EQ.'U') THEN
666  nouts=nouts + 1
667  iposu=nouts
668  nouts=nouts+1
669  iposv=nouts
670  IF (if3d) THEN
671  nouts=nouts + 1
672  iposw=nouts
673  ENDIF
674  ENDIF
675  IF (excoder1(i).EQ.'P') THEN
676  nouts=nouts + 1
677  iposp=nouts
678  ENDIF
679  IF (excoder1(i).EQ.'T') THEN
680  nouts=nouts + 1
681  ipost=nouts
682  ENDIF
683  IF(mod(param(67),1.0).eq.0.0) THEN
684  i1 = i1_from_char(excoder1(i))
685  if (0.lt.i1.and.i1.lt.10) then
686  if (i1.le.ldimt1) then
687  nouts=nouts + 1
688  ipsps(i1)=nouts
689  else
690  if (nid.eq.0) write(6,2) i1,i,excoder1(i)
691  2 format(2i4,a1,' PROBLEM W/ RESTART DATA')
692  endif
693  endif
694  ELSE
695  IF(excoder1(i).EQ.'S') THEN
696  READ(excoder1(i+1),'(I1)') nps1
697  READ(excoder1(i+2),'(I1)') nps0
698  nps=10*nps1 + nps0
699  DO is = 1, nps
700  nouts=nouts + 1
701  ipsps(is)=nouts
702  ENDDO
703  GOTO 50
704  ENDIF
705  ENDIF
706  50 CONTINUE
707 
708  IF (nps.GT.(ldimt-1)) THEN
709  IF (nid.EQ.0) THEN
710  WRITE(*,'(A)')
711  & 'ERROR: restart file has a NSPCAL > LDIMT'
712  WRITE(*,'(A,I2)')
713  & 'Change LDIMT in SIZE'
714  ENDIF
715  CALL exitt
716  ENDIF
717 
718  lname=ltrunc(fname,132)
719  if (nio.eq.0) write(6,61) (fname1(i),i=1,lname)
720  if (nio.eq.0) write(6,62)
721  $ iposu,iposv,iposw,iposp,ipost,nps,nouts
722  61 FORMAT(/,2x,'Restarting from file ',132a1)
723  62 FORMAT(2x,'Columns for restart data U,V,W,P,T,S,N: ',7i4)
724 
725 C Make sure the requested data is present in this file....
726  if (iposx.eq.0) ifgetx=.false.
727  if (iposy.eq.0) ifgetx=.false.
728  if (iposz.eq.0) ifgetz=.false.
729  if (iposu.eq.0) ifgetu=.false.
730  if (iposv.eq.0) ifgetu=.false.
731  if (iposw.eq.0) ifgetw=.false.
732  if (iposp.eq.0) ifgetp=.false.
733  if (ipost.eq.0) ifgett=.false.
734  do 65 i=1,npscal
735  if (ipsps(i).eq.0) ifgtps(i)=.false.
736  65 continue
737 
738 C End of restart file header evaluation.
739 
740  ENDIF
741 C
742 C Read the error estimators
743 C not supported at the moment => just do dummy reading
744 C
745  ifok = .false.
746  IF(nid.EQ.0)THEN
747  if (iffmat)
748  & READ(91,'(6G11.4)',END=15)(CDUMP,I=1,NELTR)
749  ifok = .true.
750  ENDIF
751  15 continue
752  call lbcast(ifok)
753  if(.not.ifok) goto 1600
754 C
755 C Read the current dump, double buffer so that we can
756 C fit the data on a distributed memory machine,
757 C and so we won't have to read the restart file twice
758 C in case of an incomplete data file.
759 C
760  nxyzr = nxr*nyr*nzr
761 C
762 C Read the data
763 C
764  nelrr = min(nelgt,neltr) ! # of elements to _really_read
765  ! why not just neltr?
766  do 200 ieg=1,nelrr
767  ifok = .false.
768  IF (nid.EQ.0) THEN
769  IF (mod(ieg,10000).EQ.1) WRITE(6,*) 'Reading',ieg
770  IF (iffmat) THEN
771  READ(91,*,err=70,END=70)
772  $ ((tdump(ixyz,ii),ii=1,nouts),ixyz=1,nxyzr)
773  ELSE
774  do ii=1,nouts
775  call byte_read(tdump(1,ii),nxyzr,ierr)
776  if(ierr.ne.0) then
777  write(6,*) "Error reading xyz restart data"
778  goto 70
779  endif
780  enddo
781  ENDIF
782  ifok=.true.
783  ENDIF
784 C
785 C Notify other processors that we've read the data OK.
786 C
787  70 continue
788  call lbcast(ifok)
789  IF (.NOT.ifok) GOTO 1600
790 C
791 C MAPDMP maps data from NXR to lx1
792 C (and sends data to the appropriate processor.)
793 C
794 C The buffer SDUMP is used so that if an incomplete dump
795 C file is found (e.g. due to UNIX io buffering!), then
796 C the previous read data stored in VX,VY,.., is not corrupted.
797 C
798  IF (ifgetx) CALL mapdmp
799  $ (sdump(1,1),tdump(1,iposx),ieg,nxr,nyr,nzr,ifbytsw)
800  IF (ifgetx) CALL mapdmp
801  $ (sdump(1,2),tdump(1,iposy),ieg,nxr,nyr,nzr,ifbytsw)
802  IF (ifgetz) CALL mapdmp
803  $ (sdump(1,3),tdump(1,iposz),ieg,nxr,nyr,nzr,ifbytsw)
804  IF (ifgetu) CALL mapdmp
805  $ (sdump(1,4),tdump(1,iposu),ieg,nxr,nyr,nzr,ifbytsw)
806  IF (ifgetu) CALL mapdmp
807  $ (sdump(1,5),tdump(1,iposv),ieg,nxr,nyr,nzr,ifbytsw)
808  IF (ifgetw) CALL mapdmp
809  $ (sdump(1,6),tdump(1,iposw),ieg,nxr,nyr,nzr,ifbytsw)
810  IF (ifgetp) CALL mapdmp
811  $ (sdump(1,7),tdump(1,iposp),ieg,nxr,nyr,nzr,ifbytsw)
812  if (ifgett) call mapdmp
813  $ (sdmp2(1,1),tdump(1,ipost),ieg,nxr,nyr,nzr,ifbytsw)
814 
815 C passive scalars
816  do 100 ips=1,npscal
817  if (ifgtps(ips)) call mapdmp(sdmp2(1,ips+1)
818  $ ,tdump(1,ipsps(ips)),ieg,nxr,nyr,nzr,ifbytsw)
819  100 continue
820 
821  200 continue
822 C
823 C Successfully read a complete field, store it.
824 C
825  nerr = 0 ! Count number of elements rec'd by nid
826  do ieg=1,nelrr
827  mid = gllnid(ieg)
828  if (mid.eq.nid) nerr = nerr+1
829  enddo
830 
831  nxyz2=lx2*ly2*lz2
832  nxyz1=lx1*ly1*lz1
833  ntott=nerr*nxyz1
834  ntotv=nerr*nxyz1 ! Problem for differing Vel. and Temp. counts!
835  ! for now we read nelt dataset
836 
837  if (ifmhd.and.ifile.eq.2) then
838  if (ifgetu) call copy(bx,sdump(1,4),ntott)
839  if (ifgetu) call copy(by,sdump(1,5),ntott)
840  if (ifgetw) call copy(bz,sdump(1,6),ntott)
841  if (ifgetp) then
842  if (nio.eq.0) write(6,*) 'getting restart pressure'
843  if (ifsplit) then
844  call copy( pm,sdump(1,7),ntotv)
845  else
846  do iel=1,nelv
847  iiel = (iel-1)*nxyz1+1
848  call map12 (pm(1,1,1,iel),sdump(iiel,7),iel)
849  enddo
850  endif
851  endif
852  if (ifaxis.and.ifgett)
853  $ call copy(t(1,1,1,1,2),sdmp2(1,1),ntott)
854  elseif (ifpert.and.ifile.ge.2) then
855  j=ifile-1 ! pointer to perturbation field
856  if (ifgetu) call copy(vxp(1,j),sdump(1,4),ntotv)
857  if (ifgetu) call copy(vyp(1,j),sdump(1,5),ntotv)
858  if (ifgetw) call copy(vzp(1,j),sdump(1,6),ntotv)
859  if (ifgetp) then
860  if (nio.eq.0) write(6,*) 'getting restart pressure'
861  if (ifsplit) then
862  call copy(prp(1,j),sdump(1,7),ntotv)
863  else
864  do ie=1,nelv
865  ie1 = (ie-1)*nxyz1+1
866  ie2 = (ie-1)*nxyz2+1
867  call map12 (prp(ie2,j),sdump(ie1,7),ie)
868  enddo
869  endif
870  endif
871  if (ifgett) call copy(tp(1,1,j),sdmp2(1,1),ntott)
872 C passive scalars
873  do ips=1,npscal
874  if (ifgtps(ips))
875  $ call copy(tp(1,ips+1,j),sdmp2(1,ips+1),ntott)
876  enddo
877 
878  else ! Std. Case
879  if (ifgetx) call copy(xm1,sdump(1,1),ntott)
880  if (ifgetx) call copy(ym1,sdump(1,2),ntott)
881  if (ifgetz) call copy(zm1,sdump(1,3),ntott)
882  if (ifgetu) call copy(vx ,sdump(1,4),ntotv)
883  if (ifgetu) call copy(vy ,sdump(1,5),ntotv)
884  if (ifgetw) call copy(vz ,sdump(1,6),ntotv)
885  if (ifgetp) call copy(pm1,sdump(1,7),ntotv)
886  if (ifgett) call copy(t,sdmp2(1,1),ntott)
887 C passive scalars
888  do i=1,npscal
889  if (ifgtps(i))
890  $ call copy(t(1,1,1,1,i+1),sdmp2(1,i+1),ntott)
891  enddo
892 
893  if (ifaxis) call axis_interp_ic(pm1) ! Interpolate to axi mesh
894  if (ifgetp) call map_pm1_to_pr(pm1,ifile) ! Interpolate pressure
895 
896  if (ifgtim) time=rstime
897  endif
898 
899  1000 CONTINUE
900  GOTO 1600
901 
902  1600 CONTINUE
903 C
904  IF (idump.EQ.1.AND.nid.EQ.0) THEN
905  write(6,1700) fname
906  write(6,1701) ieg,ixyz
907  write(6,1702)
908  $ ((tdump(jxyz,ii),ii=1,nouts),jxyz=ixyz-1,ixyz)
909  1700 FORMAT(5x,'WARNING: No data read in for file ',a132)
910  1701 FORMAT(5x,'Failed on element',i4,', point',i5,'.')
911  1702 FORMAT(5x,'Last read dump:',/,5g15.7)
912  write(6,*) nid,'call exitt 1702a',idump
913  call exitt
914  ELSEIF (idump.EQ.1) THEN
915  write(6,*) nid,'call exitt 1702b',idump
916  call exitt
917  ELSE
918  idump=idump-1
919  IF (nio.EQ.0) WRITE(6,1800) idump
920  1800 FORMAT(2x,'Successfully read data from dump number',i3,'.')
921  ENDIF
922  if (iffmat) then
923  if (nid.eq.0) close(unit=91)
924  else
925  ierr = 0
926  if (nid.eq.0) call byte_close(ierr)
927  call err_chk(ierr,'Error closing restart file in restart$')
928  endif
929  GOTO 6000
930 
931 C Can't open file...
932  5000 CONTINUE
933  if (nid.eq.0) write(6,5001) fname
934  5001 FORMAT(2x,' ******* ERROR ******* '
935  $ ,/,2x,' ******* ERROR ******* '
936  $ ,/,2x,' Could not open restart file:'
937  $ ,/,a132
938  $ ,//,2x,'Quitting in routine RESTART.')
939  CLOSE(unit=91)
940  call exitt
941  5002 CONTINUE
942  IF (nio.EQ.0) WRITE(6,5001) hname
943  call exitt
944 C
945 C
946 C End of IFILE loop
947  6000 CONTINUE
948 C
949  return
950  end
951 C
952 c-----------------------------------------------------------------------
953  subroutine sioflag(ndumps,fname,rsopts)
954 C
955 C Set IO flags according to Restart Options File, RSOPTS
956 C
957  include 'SIZE'
958  include 'INPUT'
959  include 'RESTART'
960  include 'TSTEP'
961 
962  character*132 rsopts,fname
963  character*2 s2
964  logical ifgtrl
965 
966 C Scratch variables..
967  logical ifdeft,ifanyc
968  CHARACTER*132 RSOPT ,LINE
969  CHARACTER*1 RSOPT1(132),LINE1(132)
970  equivalence(rsopt1,rsopt)
971  equivalence(line1,line)
972 C
973 C Parse filename
974 C
975 C CSPLIT splits S1 into two parts, delimited by S2.
976 C S1 returns with 2nd part of S1. CSPLIT returns 1st part.
977 C
978  rsopt=rsopts
979  call ljust(rsopt)
980  call csplit(fname,rsopt,' ',1)
981 C check fname for user supplied extension.
982  if (indx1(fname,'.',1).eq.0) then
983  len=ltrunc(fname,132)
984  len1=len+1
985  len4=len+4
986  fname(len1:len4)='.fld'
987  endif
988 C
989 C Parse restart options
990 C
991 C set default flags
992 C
993  ifgetx=.false.
994  ifgetz=.false.
995  ifgetu=.false.
996  ifgetw=.false.
997  ifgetp=.false.
998  ifgett=.false.
999  do 100 i=1,ldimt-1
1000  ifgtps(i)=.false.
1001  100 continue
1002  ifgtim=.true.
1003  ndumps=0
1004 C
1005 C Check for default case - just a filename given, no i/o options specified
1006 C
1007  ifdeft=.true.
1008 C
1009 C Parse file for i/o options and/or dump number
1010 C
1011  CALL capit(rsopt,132)
1012 
1013  IF (ltrunc(rsopt,132).NE.0) THEN
1014 C
1015 C Check for explicit specification of restart TIME.
1016 C
1017  ito=indx_cut(rsopt,'TIME',4)
1018  ifgtim=.true.
1019  IF (ito.NE.0) THEN
1020 C user has specified the time explicitly.
1021  it1=indx_cut(rsopt,'=',1)
1022  it8=132-it1
1023  CALL blank(line,132)
1024  CALL chcopy(line,rsopt1(it1),it8)
1025  IF (ifgtrl(ttime,line)) THEN
1026  ifgtim=.false.
1027  time=ttime
1028  ENDIF
1029 C remove the user specified time from the RS options line.
1030  ita=132-ito+1
1031  CALL blank(rsopt1(ito),ita)
1032  CALL ljust(line)
1033  it1=indx1(line,' ',1)
1034  itb=132-it1+1
1035  CALL chcopy(rsopt1(ito),line1(it1),itb)
1036  ENDIF
1037 
1038 C Parse field specifications.
1039 
1040  ixo=indx_cut(rsopt,'X',1)
1041  IF (ixo.NE.0) THEN
1042  ifdeft=.false.
1043  ifgetx=.true.
1044  IF (if3d) ifgetz=.true.
1045  ENDIF
1046 
1047  ivo=indx_cut(rsopt,'U',1)
1048  IF (ivo.NE.0) THEN
1049  ifdeft=.false.
1050  ifgetu=.true.
1051  IF (if3d) ifgetw=.true.
1052  ENDIF
1053 
1054  ipo=indx_cut(rsopt,'P',1)
1055  IF (ipo.NE.0) THEN
1056  ifdeft=.false.
1057  ifgetp=.true.
1058  ENDIF
1059 
1060  ito=indx_cut(rsopt,'T',1)
1061  IF (ito.NE.0) THEN
1062  ifdeft=.false.
1063  ifgett=.true.
1064  ENDIF
1065 
1066  do 300 i=1,ldimt-1
1067  write (s2,301) i
1068  ipo=indx_cut(rsopt,s2,2)
1069  if (ipo.ne.0) then
1070  ifdeft=.false.
1071  ifgtps(i)=.true.
1072  endif
1073  300 continue
1074  301 format('S',i1)
1075 
1076 C Get number of dumps from remainder of user supplied line.
1077  if (ifgtrl(tdumps,rsopt)) ndumps=int(tdumps)
1078  endif
1079 
1080 C If no fields were explicitly specified, assume getting all fields.
1081  if (ifdeft) then
1082  ifgetx=.true.
1083  IF (if3d) ifgetz=.true.
1084  ifanyc=.false.
1085  DO 400 i=1,nfield
1086  IF (ifadvc(i)) ifanyc=.true.
1087  400 CONTINUE
1088  IF (ifflow.OR.ifanyc) THEN
1089  ifgetu=.true.
1090  IF (if3d) ifgetw=.true.
1091  ENDIF
1092  if (ifflow) ifgetp=.true.
1093  if (ifheat) ifgett=.true.
1094 #ifdef CMTNEK
1095  ifgett=.true. ! CMT-nek still not compatible with IFHEAT
1096 #endif
1097  do 410 i=1,ldimt-1
1098  ifgtps(i)=.true.
1099  410 continue
1100  endif
1101 
1102 
1103 
1104 
1105  return
1106  END
1107 c-----------------------------------------------------------------------
1108  subroutine mapdmp(sdump,tdump,ieg,nxr,nyr,nzr,if_byte_sw)
1109 C----------------------------------------------------------------------
1110 C
1111 C----------------------------------------------------------------------
1112  include 'SIZE'
1113  include 'PARALLEL'
1114 C
1115  parameter(lxyz1=lx1*ly1*lz1)
1116  parameter(lxr=lx1+6)
1117  parameter(lyr=ly1+6)
1118  parameter(lzr=lz1+6)
1119  parameter(lxyzr=lxr*lyr*lzr)
1120 C
1121  REAL SDUMP(LXYZ1,LELT)
1122  real*4 tdump(lxyzr)
1123 c
1124  logical if_byte_sw
1125 c
1126  nxyz=lx1*ly1*lz1
1127  nxyr=nxr*nyr*nzr
1128  ierr=0
1129 C
1130 C Serial processor code:
1131 C
1132  IF (np.EQ.1) THEN
1133 
1134  IF (if_byte_sw) call byte_reverse(tdump,nxyr,ierr)
1135  if(ierr.ne.0) call exitti("Error in mapdmp")
1136  IF (nxr.EQ.lx1.AND.nyr.EQ.ly1.AND.nzr.EQ.lz1) THEN
1137  CALL copy4r(sdump(1,ieg),tdump,nxyz)
1138  ELSE
1139 C do the map (assumes that NX=NY=NZ, or NX=NY, NZ=1)
1140  call mapab4r(sdump(1,ieg),tdump,nxr,1)
1141  ENDIF
1142 
1143  ELSE
1144 C
1145 C Parallel code - send data to appropriate processor and map.
1146 C
1147  jnid=gllnid(ieg)
1148  mtype=3333+gllel(ieg)
1149  len=4*nxyr
1150  le1=4
1151  IF (nid.EQ.0.AND.jnid.NE.0) THEN
1152 c hand-shake
1153  CALL csend(mtype,tdump,le1,jnid,nullpid)
1154  CALL crecv2(mtype,dummy,le1,jnid)
1155  CALL csend(mtype,tdump,len,jnid,nullpid)
1156  ELSEIF (nid.NE.0.AND.jnid.EQ.nid) THEN
1157 C Receive data from node 0
1158  CALL crecv2(mtype,dummy,le1,0)
1159  CALL csend(mtype,tdump,le1,0,nullpid)
1160  CALL crecv2(mtype,tdump,len,0)
1161  ENDIF
1162 C
1163 C If the data is targeted for this processor, then map
1164 C to appropriate element.
1165 C
1166  IF (jnid.EQ.nid) THEN
1167  ie=gllel(ieg)
1168  IF (if_byte_sw) call byte_reverse(tdump,nxyr,ierr)
1169  IF (nxr.EQ.lx1.AND.nyr.EQ.ly1.AND.nzr.EQ.lz1) THEN
1170  CALL copy4r(sdump(1,ie),tdump,nxyz)
1171  ELSE
1172  call mapab4r(sdump(1,ie),tdump,nxr,1)
1173  ENDIF
1174  ENDIF
1175  call err_chk(ierr,'Error using byte_reverse in mapdmp.$')
1176 C
1177 C End of parallel distribution/map routine.
1178 C
1179  ENDIF
1180  return
1181  END
1182 c-----------------------------------------------------------------------
1183  subroutine mapab(x,y,nxr,nel)
1184 C---------------------------------------------------------------
1185 C
1186 C Interpolate Y(NXR,NYR,NZR,NEL) to X(lx1,ly1,lz1,NEL)
1187 C (assumes that NXR=NYR=NZR, or NXR=NYR, NZR=1)
1188 C---------------------------------------------------------------
1189 C
1190  include 'SIZE'
1191  include 'IXYZ'
1192  include 'WZ'
1193 C
1194  parameter(lxr=lx1+6)
1195  parameter(lyr=ly1+6)
1196  parameter(lzr=lz1+6)
1197  parameter(lxyzr=lxr*lyr*lzr)
1198  parameter(lxyz1=lx1*ly1*lz1)
1199  dimension x(lx1,ly1,lz1,nel)
1200  dimension y(nxr,nxr,nxr,nel)
1201 
1202  common /ctmp0/ xa(lxyzr) ,xb(lx1,ly1,lzr) ,xc(lxyzr)
1203  $ , zgmr(lxr) ,wgtr(lxr)
1204  common /ctmpab/ ires(lxr,lxr) ,itres(lxr,lxr)
1205  real ires,itres
1206 
1207  INTEGER NOLD
1208  SAVE nold
1209  DATA nold /0/
1210 
1211 C Bounds checking on mapped data.
1212  if (nxr.gt.lxr) then
1213  if (nid.eq.0) write(6,20) nxr,lx1
1214  20 FORMAT(//,2x,
1215  $ 'ABORT: Attempt to map from',i3,
1216  $ ' to N=',i3,'.',/,2x,
1217  $ 'NEK5000 currently supports mapping from N+6 or less.'
1218  $ ,/,2x,'Increase N')
1219  call exitt
1220  endif
1221 
1222  nzr = nxr
1223  IF(lz1.EQ.1) nzr=1
1224  nyzr = nxr*nzr
1225  nxy1 = lx1*ly1
1226 
1227  IF (nxr.NE.nold) THEN
1228  nold=nxr
1229  CALL zwgll (zgmr,wgtr,nxr)
1230  CALL igllm (ires,itres,zgmr,zgm1,nxr,lx1,nxr,lx1)
1231  IF (nio.EQ.0) WRITE(6,10) nxr,lx1
1232  10 FORMAT(2x,'Mapping restart data from Nold=',i2
1233  $ ,' to Nnew=',i2,'.')
1234  ENDIF
1235 C
1236  DO 1000 ie=1,nel
1237  CALL mxm (ires,lx1,y(1,1,1,ie),nxr,xa,nyzr)
1238  DO 100 iz=1,nzr
1239  izoff = 1 + (iz-1)*lx1*nxr
1240  CALL mxm (xa(izoff),lx1,itres,nxr,xb(1,1,iz),ly1)
1241  100 CONTINUE
1242  IF (ldim.EQ.3) THEN
1243  CALL mxm (xb,nxy1,itres,nzr,x(1,1,1,ie),lz1)
1244  ELSE
1245  CALL copy(x(1,1,1,ie),xb,nxy1)
1246  ENDIF
1247  1000 CONTINUE
1248 C
1249  return
1250  END
1251 c-----------------------------------------------------------------------
1252  subroutine mapab4r(x,y,nxr,nel)
1253 C---------------------------------------------------------------
1254 C
1255 C Interpolate Y(NXR,NYR,NZR,NEL) to X(lx1,ly1,lz1,NEL)
1256 C (assumes that NXR=NYR=NZR, or NXR=NYR, NZR=1)
1257 c
1258 c Input: real*4, Output: default precision
1259 c
1260 C---------------------------------------------------------------
1261 C
1262  include 'SIZE'
1263  include 'IXYZ'
1264  include 'WZ'
1265 C
1266  parameter(lxr=lx1+6)
1267  parameter(lyr=ly1+6)
1268  parameter(lzr=lz1+6)
1269  parameter(lxyzr=lxr*lyr*lzr)
1270  parameter(lxyz1=lx1*ly1*lz1)
1271  real*4 x(lx1,ly1,lz1,nel)
1272  REAL Y(NXR,NXR,NXR,NEL)
1273 
1274  common /ctmp0/ xa(lxyzr) ,xb(lx1,ly1,lzr) ,xc(lxyzr)
1275  $ , zgmr(lxr) ,wgtr(lxr)
1276  common /ctmpa4/ ires(lxr,lxr) ,itres(lxr,lxr)
1277  real ires,itres
1278 
1279  INTEGER NOLD
1280  SAVE nold
1281  DATA nold /0/
1282 
1283 C Bounds checking on mapped data.
1284  if (nxr.gt.lxr) then
1285  if (nid.eq.0) write(6,20) nxr,lx1
1286  20 FORMAT(//,2x,
1287  $ 'ABORT: Attempt to map from',i3,
1288  $ ' to N=',i3,'.',/,2x,
1289  $ 'NEK5000 currently supports mapping from N+6 or less.'
1290  $ ,/,2x,'Increase N')
1291  call exitt
1292  endif
1293 
1294  nzr = nxr
1295  IF(lz1.EQ.1) nzr=1
1296  nyzr = nxr*nzr
1297  nxy1 = lx1*ly1
1298  nxyzr = nxr*nxr*nzr
1299 
1300  IF (nxr.NE.nold) THEN
1301  nold=nxr
1302  CALL zwgll (zgmr,wgtr,nxr)
1303  CALL igllm (ires,itres,zgmr,zgm1,nxr,lx1,nxr,lx1)
1304  IF (nio.EQ.0) WRITE(6,10) nxr,lx1
1305  10 FORMAT(2x,'Mapping restart data from Nold=',i2
1306  $ ,' to Nnew=',i2,'.')
1307  ENDIF
1308 C
1309  DO 1000 ie=1,nel
1310  call copy4r(xc,y(1,1,1,ie),nxyzr)
1311  CALL mxm (ires,lx1,xc,nxr,xa,nyzr)
1312  DO 100 iz=1,nzr
1313  izoff = 1 + (iz-1)*lx1*nxr
1314  CALL mxm (xa(izoff),lx1,itres,nxr,xb(1,1,iz),ly1)
1315  100 CONTINUE
1316  IF (ldim.EQ.3) THEN
1317  CALL mxm (xb,nxy1,itres,nzr,x(1,1,1,ie),lz1)
1318  ELSE
1319  CALL copy(x(1,1,1,ie),xb,nxy1)
1320  ENDIF
1321  1000 CONTINUE
1322 C
1323  return
1324  END
1325 c-----------------------------------------------------------------------
1326  function i1_from_char(s1)
1327  character*1 s1
1328 
1329  character*10 n10
1330  save n10
1331  data n10 / '0123456789' /
1332 
1333  i1_from_char = indx2(n10,10,s1,1)-1
1334 
1335  return
1336  end
1337 c-----------------------------------------------------------------------
1338  integer function indx2(s1,l1,s2,l2)
1339  character*132 s1,s2
1340 
1341  n1=l1-l2+1
1342  indx2=0
1343  if (n1.lt.1) return
1344 
1345  do i=1,n1
1346  i2=i+l2-1
1347  if (s1(i:i2).eq.s2(1:l2)) then
1348  indx2=i
1349  return
1350  endif
1351  enddo
1352 
1353  return
1354  end
1355 c-----------------------------------------------------------------------
1356  INTEGER FUNCTION indx1(S1,S2,L2)
1357  CHARACTER*132 s1,s2
1358 C
1359  n1=132-l2+1
1360  indx1=0
1361  IF (n1.LT.1) return
1362 C
1363  DO 100 i=1,n1
1364  i2=i+l2-1
1365  IF (s1(i:i2).EQ.s2(1:l2)) THEN
1366  indx1=i
1367  return
1368  ENDIF
1369  100 CONTINUE
1370 C
1371  return
1372  END
1373 c-----------------------------------------------------------------------
1374  INTEGER FUNCTION indx_cut(S1,S2,L2)
1375 C
1376 C INDX_CUT is returned with the location of S2 in S1 (0 if not found)
1377 C S1 is returned with 1st occurance of S2 removed.
1378 C
1379  CHARACTER*1 s1(132),s2(132)
1380 C
1381  i1=indx1(s1,s2,l2)
1382 C
1383  IF (i1.NE.0) THEN
1384 C
1385  n1=132-l2
1386  DO 100 i=i1,n1
1387  i2=i+l2
1388 C remove the 1st occurance of S2 from S1.
1389  s1(i)=s1(i2)
1390  100 CONTINUE
1391  n2=n1+1
1392  DO 200 i=n2,132
1393  s1(i)=' '
1394  200 CONTINUE
1395  ENDIF
1396 C
1397  indx_cut=i1
1398  return
1399  END
1400 c-----------------------------------------------------------------------
1401  subroutine csplit(s0,s1,s2,l0)
1402  CHARACTER*132 S0,S1,S2
1403 C split string S1 into two parts, delimited by S2.
1404 C
1405  i2=indx_cut(s1,s2,l0)
1406  IF (i2.EQ.0) return
1407 C
1408  i1=i2-1
1409  CALL blank(s0,132)
1410  s0(1:i1)=s1(1:i1)
1411  CALL lshft(s1,i2)
1412 C
1413  return
1414  END
1415 c-----------------------------------------------------------------------
1416  subroutine lshft(string,ipt)
1417 C shift string from IPT to the left
1418 C INPUT : "abcde...... test "
1419 C OUTPUT: "e...... test " if ipt.eq.5
1420  CHARACTER*1 STRING(132)
1421 C
1422  DO 20 j=1,133-ipt
1423  ij=ipt+j-1
1424  string(j)=string(ij)
1425  20 CONTINUE
1426  DO 30 j=134-ipt,132
1427  string(j)=' '
1428  30 CONTINUE
1429  return
1430  END
1431 c-----------------------------------------------------------------------
1432  subroutine ljust(string)
1433 C left justify string
1434  CHARACTER*1 STRING(132)
1435 C
1436  IF (string(1).NE.' ') return
1437 C
1438  DO 100 i=2,132
1439 C
1440  IF (string(i).NE.' ') THEN
1441  DO 20 j=1,133-i
1442  ij=i+j-1
1443  string(j)=string(ij)
1444  20 CONTINUE
1445  DO 30 j=134-i,132
1446  string(j)=' '
1447  30 CONTINUE
1448  return
1449  ENDIF
1450 C
1451  100 CONTINUE
1452  return
1453  END
1454 c-----------------------------------------------------------------------
1455  subroutine chknorm (ifzero)
1456 C----------------------------------------------------------------------
1457 C
1458 C Check if trivial user specified initial conditions
1459 C
1460 C----------------------------------------------------------------------
1461  include 'SIZE'
1462  include 'INPUT'
1463  include 'TSTEP'
1464  LOGICAL IFZERO
1465 C
1466  ifzero = .true.
1467 C
1468  IF (ifflow) THEN
1469  ifield = 1
1470  imesh = 1
1471  CALL unorm
1472  IF (vnrml8.GT.0.) ifzero = .false.
1473  ENDIF
1474  IF (ifheat) THEN
1475  DO 100 ifield=2,nfield
1476  imesh = 1
1477  IF (iftmsh(ifield)) imesh = 2
1478  CALL unorm
1479  IF (tnrml8(ifield).GT.0.) ifzero = .false.
1480  100 CONTINUE
1481  ENDIF
1482 c
1483  return
1484  END
1485 C
1486 c-----------------------------------------------------------------------
1487  subroutine prsolvt
1488 C----------------------------------------------------------------------
1489 C
1490 C Use steady state solution as initial condition
1491 C for temperatur/passive scalar
1492 C
1493 C----------------------------------------------------------------------
1494  include 'SIZE'
1495  include 'INPUT'
1496  include 'TSTEP'
1497  LOGICAL IFSAV1,IFSAV2(LDIMT1)
1498 C
1499  IF (nio.EQ.0) WRITE(6,*) ' '
1500  IF (nio.EQ.0) WRITE(6,*) 'Conduction pre-solver activated'
1501 C
1502 C Set logical IFTRAN to false (steady state)
1503 C Save logicals for convection
1504 C Turn convection off
1505 C
1506  ifsav1 = iftran
1507  iftran = .false.
1508  DO 100 ifield=2,nfield
1509  ifsav2(ifield) = ifadvc(ifield)
1510  ifadvc(ifield) = .false.
1511  100 CONTINUE
1512 C
1513  CALL setprop
1514  CALL setsolv
1515 C
1516  IF(nio.EQ.0)WRITE(6,*)'Steady conduction/passive scalar problem'
1517 C
1518  DO 200 igeom=1,2
1519  CALL heat (igeom)
1520  200 CONTINUE
1521 C
1522 C Set IFTRAN to true again
1523 C Turn convection on again
1524 C
1525  iftran = ifsav1
1526  DO 300 ifield=2,nfield
1527  ifadvc(ifield) = ifsav2(ifield)
1528  300 CONTINUE
1529 C
1530  return
1531  END
1532 C
1533 c-----------------------------------------------------------------------
1534  subroutine prsolvv
1535 C----------------------------------------------------------------------
1536 C
1537 C Use steady Stokes solution as initial condition
1538 C for flow problem
1539 C
1540 C----------------------------------------------------------------------
1541  include 'SIZE'
1542  include 'INPUT'
1543  include 'SOLN'
1544  include 'TSTEP'
1545  LOGICAL IFSAV1,IFSAV2
1546 C
1547  IF (nio.EQ.0) WRITE(6,*) ' '
1548  IF (nio.EQ.0) WRITE(6,*) 'Velocity pre-solver activated'
1549 C
1550 C Initialize velocity to some non-trivial RHS to avoid FP trap in i860.
1551 C
1552  IF (param(60).NE.0.0) THEN
1553  small=10.0e-10
1554  CALL cfill(vx,small,ntotv)
1555  CALL cfill(vy,small,ntotv)
1556  CALL cfill(vz,small,ntotv)
1557  ENDIF
1558 C
1559 C Set logical IFTRAN to false (steady state)
1560 C Save logicals for convection
1561 C Turn convection off
1562 C
1563  IF (ifsplit) THEN
1564  WRITE(6,10)
1565  10 FORMAT(
1566  $ /,2x,'ERROR: Steady Stokes Flow initial condition cannot'
1567  $,/,2x,' be computed using the splitting formulation.'
1568  $,/,2x,' Either compute using UZAWA, or remove PRESOLVE'
1569  $,/,2x,' request for velocity.'
1570  $,/,2x
1571  $,/,2x,' ABORTING IN PRSOLVV.')
1572  CALL exitt
1573  ENDIF
1574 C
1575  ifsav1 = iftran
1576  ifsav2 = ifadvc(ifield)
1577  iftran = .false.
1578  ifadvc(ifield) = .false.
1579 C
1580  CALL setprop
1581  CALL setsolv
1582 C
1583  IF (nio.EQ.0) WRITE (6,*) 'Steady Stokes problem'
1584  DO 100 igeom=1,2
1585  IF (.NOT.ifsplit) CALL fluid (igeom)
1586  100 CONTINUE
1587 C
1588 C Set IFTRAN to true again
1589 C Turn convection on again
1590 C
1591  iftran = ifsav1
1592  ifadvc(ifield) = ifsav2
1593 C
1594  return
1595  END
1596 C
1597 c-----------------------------------------------------------------------
1598  subroutine nekuic ! user specified fortran function (=0 if not specified)
1599 
1600  include 'SIZE'
1601  include 'INPUT'
1602  include 'SOLN'
1603  include 'TSTEP'
1604  include 'PARALLEL'
1605  include 'NEKUSE'
1606 
1607  integer e,eg
1608 
1609  nel = nelfld(ifield)
1610 
1611  do e=1,nel
1612  eg = lglel(e)
1613  do 300 k=1,lz1
1614  do 300 j=1,ly1
1615  do 300 i=1,lx1
1616  call nekasgn (i,j,k,e)
1617  call useric (i,j,k,eg)
1618  if (jp.eq.0) then
1619  if (ifield.eq.1) then
1620  vx(i,j,k,e) = ux
1621  vy(i,j,k,e) = uy
1622  vz(i,j,k,e) = uz
1623  elseif (ifield.eq.ifldmhd .and. ifmhd) then
1624  bx(i,j,k,e) = ux
1625  by(i,j,k,e) = uy
1626  bz(i,j,k,e) = uz
1627  else
1628  t(i,j,k,e,ifield-1) = temp
1629  endif
1630  else
1631  ijke = i+lx1*((j-1)+ly1*((k-1) + lz1*(e-1)))
1632  if (ifield.eq.1) then
1633  vxp(ijke,jp) = ux
1634  vyp(ijke,jp) = uy
1635  vzp(ijke,jp) = uz
1636  else
1637  tp(ijke,ifield-1,jp) = temp
1638  endif
1639  endif
1640 
1641  300 continue
1642  enddo
1643 
1644  return
1645  END
1646 c-----------------------------------------------------------------------
1647  subroutine capit(lettrs,n)
1648 C Capitalizes string of length n
1649  CHARACTER LETTRS(N)
1650 C
1651  DO 5 i=1,n
1652  int=ichar(lettrs(i))
1653  IF(int.GE.97 .AND. int.LE.122) THEN
1654  int=int-32
1655  lettrs(i)=char(int)
1656  ENDIF
1657 5 CONTINUE
1658  return
1659  END
1660 c-----------------------------------------------------------------------
1661  LOGICAL FUNCTION ifgtrl(VALUE,LINE)
1662 C
1663 C Read VALUE from LINE and set IFGTRL to .TRUE. if successful,
1664 C IFGTRL to .FALSE. otherwise.
1665 C
1666 C This complicated function is necessary thanks to the Ardent,
1667 C which won't allow free formatted reads (*) from internal strings!
1668 C
1669  CHARACTER*132 line
1670  CHARACTER*132 work
1671  CHARACTER*8 fmat
1672 C
1673 C Note that the format Fn.0 is appropriate for fields of type:
1674 C 34 34.0 34.0e+00
1675 C The only difficulty would be with '34' but since we identify
1676 C the field width exactly, there is no problem.
1677 C
1678  ifgtrl=.false.
1679  VALUE=0.0
1680 C
1681  work=line
1682  CALL ljust(work)
1683  ifldw=indx1(work,' ',1)-1
1684 C
1685  IF (ifldw.GT.0) THEN
1686  WRITE(fmat,10) ifldw
1687  10 FORMAT('(F',i3.3,'.0)')
1688  READ(work,fmat,err=100,END=100) tval
1689  VALUE=tval
1690  ifgtrl=.true.
1691  return
1692  ENDIF
1693 C
1694  100 CONTINUE
1695  return
1696  END
1697 c-----------------------------------------------------------------------
1698  LOGICAL FUNCTION ifgtil(IVALUE,LINE)
1699 C
1700 C Read IVALUE from LINE and set IFGTIL to .TRUE. if successful,
1701 C IFGTIL to .FALSE. otherwise.
1702 C
1703 C This complicated function is necessary thanks to the Ardent,
1704 C which won't allow free formatted reads (*) from internal strings!
1705 C
1706  CHARACTER*132 line
1707  CHARACTER*132 work
1708  CHARACTER*8 fmat
1709 C
1710  ifgtil=.false.
1711  ivalue=0
1712 C
1713  work=line
1714  CALL ljust(work)
1715  ifldw=indx1(work,' ',1)-1
1716 C
1717  IF (ifldw.GT.0) THEN
1718  WRITE(fmat,10) ifldw
1719  10 FORMAT('(F',i3.3,'.0)')
1720  READ(work,fmat,err=100,END=100) tval
1721  ivalue=int(tval)
1722  ifgtil=.true.
1723  return
1724  ENDIF
1725 C
1726  100 CONTINUE
1727  return
1728  END
1729 c-----------------------------------------------------------------------
1730  subroutine perturb(tt,ifld,eps)
1731  include 'SIZE'
1732  include 'TOTAL'
1733 c
1734  real tt(1)
1735  integer ifld
1736 
1737  ifield = ifld
1738 
1739  n = lx1*ly1*lz1*nelfld(ifield)
1740  call vcospf(tt,bm1,n)
1741  call cmult(tt,eps,n)
1742  call dssum(tt,lx1,ly1,lz1)
1743 
1744  return
1745  end
1746 c-----------------------------------------------------------------------
1747  subroutine vcospf(x,y,n)
1748  real x(1),y(1)
1749  do i=1,n
1750  x(i) = cos(1000.*y(i))
1751  enddo
1752  return
1753  end
1754 c-----------------------------------------------------------------------
1755  subroutine vbyte_swap(x,n)
1756  character*1 x(0:3,1),tmp0,tmp1
1757  character*1 in (0:3), out(0:3)
1758  real*4 in4 , out4
1759  equivalence(in ,in4 )
1760  equivalence(out,out4)
1761 c
1762  do i=1,n
1763  do j=0,3
1764  in(j) = x(j,i)
1765  enddo
1766  tmp0 = x(0,i)
1767  tmp1 = x(1,i)
1768  x(0,i) = x(3,i)
1769  x(1,i) = x(2,i)
1770  x(2,i) = tmp1
1771  x(3,i) = tmp0
1772  do j=0,3
1773  out(j) = x(j,i)
1774  enddo
1775  write(6,*) 'swap:',i,in4,out4
1776  enddo
1777 c
1778  return
1779  end
1780 c-----------------------------------------------------------------------
1781  logical function if_byte_swap_test(bytetest,ierr)
1782  include 'SIZE'
1783 
1784  real*4 bytetest,test2
1785  real*4 test_pattern
1786  save test_pattern
1787 
1788  test_pattern = 6.54321
1789  eps = 0.00020
1790  etest = abs(test_pattern-bytetest)
1791  if_byte_swap_test = .true.
1792  if (etest.le.eps) if_byte_swap_test = .false.
1793 
1794  test2 = bytetest
1795  call byte_reverse(test2,1,ierr)
1796  if (nid.eq.0 .and. loglevel.gt.2)
1797  $ write(6,*) 'byte swap:',if_byte_swap_test,bytetest,test2
1798  return
1799  end
1800 c-----------------------------------------------------------------------
1801  subroutine geom_reset(icall)
1802 C
1803 C Generate geometry data
1804 C
1805  include 'SIZE'
1806  include 'INPUT'
1807  include 'GEOM'
1808  include 'SOLN'
1809  include 'TSTEP'
1810  include 'WZ'
1811 c
1812  COMMON /scruz/ xm3(lx1,ly1,lz1,lelt)
1813  $ , ym3(lx1,ly1,lz1,lelt)
1814  $ , zm3(lx1,ly1,lz1,lelt)
1815 C
1816 c
1817  if(nio.eq.0) write(6,*) 'regenerate geometry data',icall
1818 
1819  ntot = lx1*ly1*lz1*nelt
1820 c
1821  if (lx3.eq.lx1) then
1822  call copy(xm3,xm1,ntot)
1823  call copy(ym3,ym1,ntot)
1824  call copy(zm3,zm1,ntot)
1825  else
1826  call map13_all(xm3,xm1)
1827  call map13_all(ym3,ym1)
1828  if (if3d) call map13_all(zm3,zm1)
1829  endif
1830 c
1831  CALL geom1 (xm3,ym3,zm3)
1832  CALL geom2
1833  CALL updmsys (1)
1834  CALL volume
1835  CALL setinvm
1836  CALL setdef
1837  CALL sfastax
1838 c
1839  do ie = 1,nelt
1840  ! x
1841  xc(1,ie) = xm1(1 ,1 ,1 ,ie)
1842  xc(2,ie) = xm1(lx1,1 ,1 ,ie)
1843  xc(3,ie) = xm1(lx1,ly1,1 ,ie)
1844  xc(4,ie) = xm1(1 ,ly1,1 ,ie)
1845  xc(5,ie) = xm1(1 ,1 ,lz1,ie)
1846  xc(6,ie) = xm1(lx1,1 ,lz1,ie)
1847  xc(7,ie) = xm1(lx1,ly1,lz1,ie)
1848  xc(8,ie) = xm1(1 ,ly1,lz1,ie)
1849  ! y
1850  yc(1,ie) = ym1(1 ,1 ,1 ,ie)
1851  yc(2,ie) = ym1(lx1,1 ,1 ,ie)
1852  yc(3,ie) = ym1(lx1,ly1,1 ,ie)
1853  yc(4,ie) = ym1(1 ,ly1,1 ,ie)
1854  yc(5,ie) = ym1(1 ,1 ,lz1,ie)
1855  yc(6,ie) = ym1(lx1,1 ,lz1,ie)
1856  yc(7,ie) = ym1(lx1,ly1,lz1,ie)
1857  yc(8,ie) = ym1(1 ,ly1,lz1,ie)
1858  ! z
1859  zc(1,ie) = zm1(1 ,1 ,1 ,ie)
1860  zc(2,ie) = zm1(lx1,1 ,1 ,ie)
1861  zc(3,ie) = zm1(lx1,ly1,1 ,ie)
1862  zc(4,ie) = zm1(1 ,ly1,1 ,ie)
1863  zc(5,ie) = zm1(1 ,1 ,lz1,ie)
1864  zc(6,ie) = zm1(lx1,1 ,lz1,ie)
1865  zc(7,ie) = zm1(lx1,ly1,lz1,ie)
1866  zc(8,ie) = zm1(1 ,ly1,lz1,ie)
1867  enddo
1868 
1869  if(nio.eq.0) then
1870  write(6,*) 'done :: regenerate geometry data',icall
1871  write(6,*) ' '
1872  endif
1873 
1874  return
1875  end
1876 c-----------------------------------------------------------------------
1877  subroutine dsavg(u)
1878 c
1879 c
1880  include 'SIZE'
1881  include 'TOTAL'
1882  real u(lx1,ly1,lz1,lelt)
1883 c
1884 c
1885 c Take direct stiffness avg of u
1886 c
1887 c
1888  ifieldo = ifield
1889  if (ifflow) then
1890  ifield = 1
1891  ntot = lx1*ly1*lz1*nelv
1892  call dssum(u,lx1,ly1,lz1)
1893  call col2 (u,vmult,ntot)
1894  else
1895  ifield = 2
1896  ntot = lx1*ly1*lz1*nelt
1897  call dssum(u,lx1,ly1,lz1)
1898  call col2 (u,tmult,ntot)
1899  endif
1900  ifield = ifieldo
1901 c
1902  return
1903  end
1904 c-----------------------------------------------------------------------
1905  subroutine map13_all(x3,x1)
1906 c
1907  include 'SIZE'
1908  include 'TOTAL'
1909 c
1910  real x3(lx3,ly3,lz3,lelt)
1911  real x1(lx1,ly1,lz1,lelt)
1912 c
1913  integer e
1914 c
1915  do e=1,nelt
1916  call map13 (x3(1,1,1,e),x1(1,1,1,e),e)
1917  enddo
1918 c
1919  return
1920  end
1921 c-----------------------------------------------------------------------
1922  subroutine mfi_gets(u,wk,lwk,iskip)
1923 
1924  include 'SIZE'
1925  include 'INPUT'
1926  include 'PARALLEL'
1927  include 'RESTART'
1928 
1929 
1930  real u(lx1*ly1*lz1,1)
1931 
1932  real*4 wk(2*lwk) ! message buffer
1933  parameter(lrbs=20*lx1*ly1*lz1*lelt)
1934  common /vrthov/ w2(lrbs) ! read buffer
1935  real*4 w2
1936 
1937  integer e,ei,eg,msg_id(lelt)
1938  logical iskip
1939  integer*8 i8tmp
1940 
1941  call nekgsync() ! clear outstanding message queues.
1942 
1943  nxyzr = nxr*nyr*nzr
1944  dnxyzr = nxyzr
1945  len = nxyzr*wdsizr ! message length
1946  if (wdsizr.eq.8) nxyzr = 2*nxyzr
1947 
1948  ! check message buffer wk
1949  num_recv = nxyzr*nelt
1950  num_avail = size(wk)
1951  call lim_chk(num_recv,num_avail,' ',' ','mfi_gets a')
1952 
1953  ! setup read buffer
1954  if (nid.eq.pid0r) then
1955  i8tmp = int(nxyzr,8)*int(nelr,8)
1956  nread = i8tmp/int(lrbs,8)
1957  if (mod(i8tmp,int(lrbs,8)).ne.0) nread = nread + 1
1958  if(ifmpiio) nread = iglmax(nread,1) ! needed because of collective read
1959  nelrr = nelr/nread
1960  endif
1961  call bcast(nelrr,4)
1962  call lim_chk(nxyzr*nelrr,lrbs,' ',' ','mfi_gets b')
1963 
1964  ! pre-post recieves
1965  if (np.gt.1) then
1966  l = 1
1967  do e=1,nelt
1968  msg_id(e) = irecv(e,wk(l),len)
1969  l = l+nxyzr
1970  enddo
1971  endif
1972 
1973  ierr = 0
1974  if (nid.eq.pid0r.and.np.gt.1) then ! only i/o nodes will read
1975  ! read blocks of size nelrr
1976  k = 0
1977  do i = 1,nread
1978  if(i.eq.nread) then ! clean-up
1979  nelrr = nelr - (nread-1)*nelrr
1980  if(nelrr.lt.0) nelrr = 0
1981  endif
1982 
1983  if(ierr.eq.0) then
1984  if(ifmpiio) then
1985  call byte_read_mpi(w2,nxyzr*nelrr,-1,ifh_mbyte,ierr)
1986  else
1987  call byte_read (w2,nxyzr*nelrr,ierr)
1988  endif
1989  endif
1990 
1991  ! distribute data across target processors
1992  l = 1
1993  do e = k+1,k+nelrr
1994  jnid = gllnid(er(e)) ! where is er(e) now?
1995  jeln = gllel(er(e))
1996  if(ierr.ne.0) call rzero(w2(l),len)
1997  call csend(jeln,w2(l),len,jnid,0) ! blocking send
1998  l = l+nxyzr
1999  enddo
2000  k = k + nelrr
2001  enddo
2002  elseif (np.eq.1) then
2003  if(ifmpiio) then
2004  call byte_read_mpi(wk,nxyzr*nelr,-1,ifh_mbyte,ierr)
2005  else
2006  call byte_read(wk,nxyzr*nelr,ierr)
2007  endif
2008  endif
2009 
2010  if (iskip) then
2011  call nekgsync() ! clear outstanding message queues.
2012  goto 100 ! don't use the data
2013  endif
2014 
2015  nxyzr = nxr*nyr*nzr
2016  nxyzv = nxr*nyr*nzr
2017  nxyzw = nxr*nyr*nzr
2018  if (wdsizr.eq.8) nxyzw = 2*nxyzw
2019 
2020  l = 1
2021  do e=1,nelt
2022  if (np.gt.1) then
2023  call msgwait(msg_id(e))
2024  ei = e
2025  elseif(np.eq.1) then
2026  ei = er(e)
2027  endif
2028  if (if_byte_sw) then
2029  if(wdsizr.eq.8) then
2030  call byte_reverse8(wk(l),nxyzv*2,ierr)
2031  else
2032  call byte_reverse(wk(l),nxyzv,ierr)
2033  endif
2034  endif
2035  if (nxr.eq.lx1.and.nyr.eq.ly1.and.nzr.eq.lz1) then
2036  if (wdsizr.eq.4) then ! COPY
2037  call copy4r(u(1,ei),wk(l ),nxyzr)
2038  else
2039  call copy (u(1,ei),wk(l ),nxyzr)
2040  endif
2041  else ! INTERPOLATE
2042  if (wdsizr.eq.4) then
2043  call mapab4r(u(1,ei),wk(l ),nxr,1)
2044  else
2045  call mapab (u(1,ei),wk(l ),nxr,1)
2046  endif
2047  endif
2048  l = l+nxyzw
2049  enddo
2050 
2051 
2052  100 call err_chk(ierr,'Error reading restart data,in gets.$')
2053  return
2054  end
2055 c-----------------------------------------------------------------------
2056  subroutine mfi_getv(u,v,w,wk,lwk,iskip)
2057 
2058  include 'SIZE'
2059  include 'INPUT'
2060  include 'PARALLEL'
2061  include 'RESTART'
2062 
2063  real u(lx1*ly1*lz1,1),v(lx1*ly1*lz1,1),w(lx1*ly1*lz1,1)
2064  logical iskip
2065 
2066  real*4 wk(2*lwk) ! message buffer
2067  parameter(lrbs=20*lx1*ly1*lz1*lelt)
2068  common /vrthov/ w2(lrbs) ! read buffer
2069  real*4 w2
2070 
2071  integer e,ei,eg,msg_id(lelt)
2072  integer*8 i8tmp
2073 
2074  call nekgsync() ! clear outstanding message queues.
2075 
2076  nxyzr = ldim*nxr*nyr*nzr
2077  len = nxyzr*wdsizr ! message length in bytes
2078  if (wdsizr.eq.8) nxyzr = 2*nxyzr
2079 
2080  ! check message buffer wk
2081  num_recv = nxyzr*nelt
2082  num_avail = size(wk)
2083  call lim_chk(num_recv,num_avail,' ',' ','mfi_getv a')
2084 
2085  ! setup read buffer
2086  if(nid.eq.pid0r) then
2087  i8tmp = int(nxyzr,8)*int(nelr,8)
2088  nread = i8tmp/int(lrbs,8)
2089  if (mod(i8tmp,int(lrbs,8)).ne.0) nread = nread + 1
2090  if(ifmpiio) nread = iglmax(nread,1) ! needed because of collective read
2091  nelrr = nelr/nread
2092  endif
2093  call bcast(nelrr,4)
2094  call lim_chk(nxyzr*nelrr,lrbs,' ',' ','mfi_getv b')
2095 
2096  ! pre-post recieves (one mesg per element)
2097  ! this assumes we never pre post more messages than supported
2098  if (np.gt.1) then
2099  l = 1
2100  do e=1,nelt
2101  msg_id(e) = irecv(e,wk(l),len)
2102  l = l+nxyzr
2103  enddo
2104  endif
2105 
2106  ierr = 0
2107  if (nid.eq.pid0r .and. np.gt.1) then ! only i/o nodes
2108  k = 0
2109  do i = 1,nread
2110  if(i.eq.nread) then ! clean-up
2111  nelrr = nelr - (nread-1)*nelrr
2112  if(nelrr.lt.0) nelrr = 0
2113  endif
2114 
2115  if(ierr.eq.0) then
2116  if(ifmpiio) then
2117  call byte_read_mpi(w2,nxyzr*nelrr,-1,ifh_mbyte,ierr)
2118  else
2119  call byte_read (w2,nxyzr*nelrr,ierr)
2120  endif
2121  endif
2122 
2123  ! redistribute data based on the current el-proc map
2124  l = 1
2125  do e = k+1,k+nelrr
2126  jnid = gllnid(er(e)) ! where is er(e) now?
2127  jeln = gllel(er(e))
2128  if(ierr.ne.0) call rzero(w2(l),len)
2129  call csend(jeln,w2(l),len,jnid,0) ! blocking send
2130  l = l+nxyzr
2131  enddo
2132  k = k + nelrr
2133  enddo
2134  elseif (np.eq.1) then
2135  if(ifmpiio) then
2136  call byte_read_mpi(wk,nxyzr*nelr,-1,ifh_mbyte,ierr)
2137  else
2138  call byte_read(wk,nxyzr*nelr,ierr)
2139  endif
2140  endif
2141 
2142  if (iskip) then
2143  call nekgsync() ! clear outstanding message queues.
2144  goto 100 ! don't assign the data we just read
2145  endif
2146 
2147  nxyzr = nxr*nyr*nzr
2148  nxyzv = ldim*nxr*nyr*nzr
2149  nxyzw = nxr*nyr*nzr
2150  if (wdsizr.eq.8) nxyzw = 2*nxyzw
2151 
2152  l = 1
2153  do e=1,nelt
2154  if (np.gt.1) then
2155  call msgwait(msg_id(e))
2156  ei = e
2157  else if(np.eq.1) then
2158  ei = er(e)
2159  endif
2160  if (if_byte_sw) then
2161  if(wdsizr.eq.8) then
2162  call byte_reverse8(wk(l),nxyzv*2,ierr)
2163  else
2164  call byte_reverse(wk(l),nxyzv,ierr)
2165  endif
2166  endif
2167  if (nxr.eq.lx1.and.nyr.eq.ly1.and.nzr.eq.lz1) then
2168  if (wdsizr.eq.4) then ! COPY
2169  call copy4r(u(1,ei),wk(l ),nxyzr)
2170  call copy4r(v(1,ei),wk(l+ nxyzw),nxyzr)
2171  if (if3d)
2172  $ call copy4r(w(1,ei),wk(l+2*nxyzw),nxyzr)
2173  else
2174  call copy (u(1,ei),wk(l ),nxyzr)
2175  call copy (v(1,ei),wk(l+ nxyzw),nxyzr)
2176  if (if3d)
2177  $ call copy (w(1,ei),wk(l+2*nxyzw),nxyzr)
2178  endif
2179  else ! INTERPOLATE
2180  if (wdsizr.eq.4) then
2181  call mapab4r(u(1,ei),wk(l ),nxr,1)
2182  call mapab4r(v(1,ei),wk(l+ nxyzw),nxr,1)
2183  if (if3d)
2184  $ call mapab4r(w(1,ei),wk(l+2*nxyzw),nxr,1)
2185  else
2186  call mapab (u(1,ei),wk(l ),nxr,1)
2187  call mapab (v(1,ei),wk(l+ nxyzw),nxr,1)
2188  if (if3d)
2189  $ call mapab (w(1,ei),wk(l+2*nxyzw),nxr,1)
2190  endif
2191  endif
2192  l = l+ldim*nxyzw
2193  enddo
2194 
2195  100 call err_chk(ierr,'Error reading restart data, in getv.$')
2196  return
2197  end
2198 c-----------------------------------------------------------------------
2199  subroutine mfi_parse_hdr(hdr,ierr)
2200  include 'SIZE'
2201 
2202  character*132 hdr
2203 
2204  if (indx2(hdr,132,'#std',4).eq.1) then
2205  call parse_std_hdr(hdr)
2206  else
2207  if (nio.eq.0) write(6,80) hdr
2208  if (nio.eq.0) write(6,80) 'NONSTD HDR, parse_hdr, abort.'
2209  80 format(a132)
2210  ierr = 1
2211  endif
2212 
2213  return
2214  end
2215 c-----------------------------------------------------------------------
2216  subroutine parse_std_hdr(hdr)
2217  include 'SIZE'
2218  include 'INPUT'
2219  include 'SOLN'
2220  include 'PARALLEL'
2221  include 'RESTART'
2222  include 'TSTEP'
2223 
2224  character*132 hdr
2225  character*4 dummy
2226  logical if_press_mesh
2227 
2228  p0thr = -1
2229  if_press_mesh = .false.
2230 
2231  read(hdr,*,iostat=ierr) dummy
2232  $ , wdsizr,nxr,nyr,nzr,nelr,nelgr,timer,istpr
2233  $ , ifiler,nfiler
2234  $ , rdcode ! 74+20=94
2235  $ , p0thr, if_press_mesh
2236 
2237  if (ierr.gt.0) then ! try again without pressure format flag
2238  read(hdr,*,iostat=ierr) dummy
2239  $ , wdsizr,nxr,nyr,nzr,nelr,nelgr,timer,istpr
2240  $ , ifiler,nfiler
2241  $ , rdcode ! 74+20=94
2242  $ , p0thr
2243  endif
2244 
2245  if (ierr.gt.0) then ! try again without mean pressure
2246  read(hdr,*,err=99) dummy
2247  $ , wdsizr,nxr,nyr,nzr,nelr,nelgr,timer,istpr
2248  $ , ifiler,nfiler
2249  $ , rdcode ! 74+20=94
2250  endif
2251 
2252 c set if_full_pres flag
2253  if_full_pres = .false.
2254  if (.not.ifsplit) if_full_pres = if_press_mesh
2255 
2256 c ifgtim = .true. ! always get time
2257  ifgetxr = .false.
2258  ifgetur = .false.
2259  ifgetpr = .false.
2260  ifgettr = .false.
2261  do k=1,ldimt-1
2262  ifgtpsr(k) = .false.
2263  enddo
2264 
2265  npsr = 0
2266  nps = 0
2267  do i=1,10
2268  if (rdcode1(i).eq.'X') ifgetxr = .true.
2269  if (rdcode1(i).eq.'U') ifgetur = .true.
2270  if (rdcode1(i).eq.'P') ifgetpr = .true.
2271  if (rdcode1(i).eq.'T') ifgettr = .true.
2272  if (rdcode1(i).eq.'S') then
2273  read(rdcode1(i+1),'(I1)') nps1
2274  read(rdcode1(i+2),'(I1)') nps0
2275  npsr = 10*nps1+nps0
2276  nps = npsr
2277  if(npsr.gt.ldimt-1) nps=ldimt-1
2278  do k=1,nps
2279  ifgtpsr(k) = .true.
2280  enddo
2281  ! nothing will follow
2282  GOTO 50
2283  endif
2284  enddo
2285 
2286  50 if (nps.lt.npsr) then
2287  if (nid.eq.0) then
2288  write(*,'(A,/,A)')
2289  & 'WARNING: restart file has a NSPCAL > LDIMT',
2290  & 'read only part of the fld-data!'
2291  endif
2292  endif
2293 
2294  if (nps.lt.npscal) then
2295  if (nid.eq.0) then
2296  write(*,'(A,/,A)')
2297  & 'WARNING: NPSCAL read from restart file differs from ',
2298  & 'currently used NPSCAL!'
2299  endif
2300  endif
2301 
2302  p0th = 1
2303  if (p0thr.gt.0) p0th = p0thr
2304 
2305  return
2306 
2307  99 continue ! If we got here, then the May 2008 variant of std hdr
2308  ! failed and we may have an older input file.
2309 
2310  call parse_std_hdr_2006(hdr,rdcode) ! try the original header format
2311 
2312  return
2313  end
2314 c-----------------------------------------------------------------------
2315  subroutine parse_std_hdr_2006(hdr,rlcode)
2316  include 'SIZE'
2317  include 'INPUT'
2318  include 'RESTART'
2319 
2320  character*132 hdr
2321  character*1 rlcode(20)
2322 
2323 c 4 7 10 13 23 33 53 62 68 74
2324  read(hdr,1) wdsizr,nxr,nyr,nzr,nelr,nelgr,timer,istpr
2325  $ , ifiler,nfiler
2326  $ , (rlcode(k),k=1,20) ! 74+20=94
2327  1 format(4x,i2,3i3,2i10,e20.13,i9,2i6,20a1)
2328 
2329  if (nid.eq.0) write(6,*) 'WARNING: reading depreacted header!'
2330 
2331 c Assign read conditions, according to rdcode
2332 c NOTE: In the old hdr format: what you see in file is what you get.
2333 c ifgtim = .true. ! always get time
2334  ifgetxr = .false.
2335  ifgetur = .false.
2336  ifgetpr = .false.
2337  ifgettr = .false.
2338  do k=1,npscal
2339  ifgtpsr(k) = .false.
2340  enddo
2341 
2342  if (rlcode(1).eq.'X') ifgetxr = .true.
2343  if (rlcode(2).eq.'U') ifgetur = .true.
2344  if (rlcode(3).eq.'P') ifgetpr = .true.
2345  if (rlcode(4).eq.'T') ifgettr = .true.
2346  do k=1,npscal
2347  if (rlcode(4+k).ne.' ') ifgtpsr(k) = .true.
2348  enddo
2349 
2350 
2351  return
2352  end
2353 c-----------------------------------------------------------------------
2354  subroutine mfi(fname_in,ifile)
2355 c
2356 c (1) Open restart file(s)
2357 c (2) Check previous spatial discretization
2358 c (3) Map (K1,N1) => (K2,N2) if necessary
2359 c
2360 c nfiles > 1 has several implications:
2361 c
2362 c i. For std. run, data is taken from last file in list, unless
2363 c explicitly specified in argument list of filename
2364 c
2365 c ii. For MHD and perturbation cases, 1st file is for U,P,T;
2366 c subsequent files are for B-field or perturbation fields
2367 c
2368 c
2369  include 'SIZE'
2370  include 'TOTAL'
2371  include 'RESTART'
2372  character*132 hdr
2373  character*132 fname_in
2374 
2375  character*132 fname
2376  character*1 fnam1(132)
2377  equivalence(fnam1,fname)
2378 
2379  character*1 frontc
2380 
2381  parameter(lwk = 7*lx1*ly1*lz1*lelt)
2382  common /scrns/ wk(lwk)
2383  common /scrcg/ pm1(lx1*ly1*lz1,lelv)
2384  integer e
2385 
2386  integer*8 offs0,offs,nbyte,stride,strideB,nxyzr8
2387 
2388  tiostart=dnekclock()
2389 
2390  ! add full path if required
2391  call blank(fname,132)
2392  call chcopy(frontc, fname_in, 1)
2393  if (frontc .ne. '/') then
2394  lenp = ltrunc(path,132)
2395  lenf = ltrunc(fname_in,132)
2396  call chcopy(fnam1(1),path,lenp)
2397  call chcopy(fnam1(lenp+1),fname_in,lenf)
2398  else
2399  lenf = ltrunc(fname_in,132)
2400  call chcopy(fnam1(1),fname_in,lenf)
2401  endif
2402 
2403  call mfi_prepare(fname) ! determine reader nodes +
2404  ! read hdr + element mapping
2405 
2406  offs0 = iheadersize + 4 + isize*nelgr
2407  nxyzr8 = nxr*nyr*nzr
2408  strideb = nelbr* nxyzr8*wdsizr
2409  stride = nelgr* nxyzr8*wdsizr
2410 
2411  iofldsr = 0
2412  if (ifgetxr) then ! if available
2413  offs = offs0 + ldim*strideb
2414  call byte_set_view(offs,ifh_mbyte)
2415  if (ifgetx) then
2416 c if(nid.eq.0) write(6,*) 'Reading mesh'
2417  call mfi_getv(xm1,ym1,zm1,wk,lwk,.false.)
2418  else ! skip the data
2419  call mfi_getv(xm1,ym1,zm1,wk,lwk,.true.)
2420  endif
2421  iofldsr = iofldsr + ldim
2422  endif
2423 
2424  if (ifgetur) then
2425  offs = offs0 + iofldsr*stride + ldim*strideb
2426  call byte_set_view(offs,ifh_mbyte)
2427  if (ifgetu) then
2428  if (ifmhd.and.ifile.eq.2) then
2429 c if(nid.eq.0) write(6,*) 'Reading B field'
2430  call mfi_getv(bx,by,bz,wk,lwk,.false.)
2431  else
2432 c if(nid.eq.0) write(6,*) 'Reading velocity field'
2433  call mfi_getv(vx,vy,vz,wk,lwk,.false.)
2434  endif
2435  else
2436  call mfi_getv(vx,vy,vz,wk,lwk,.true.)
2437  endif
2438  iofldsr = iofldsr + ldim
2439  endif
2440 
2441  if (ifgetpr) then
2442  offs = offs0 + iofldsr*stride + strideb
2443  call byte_set_view(offs,ifh_mbyte)
2444  if (ifgetp) then
2445 c if(nid.eq.0) write(6,*) 'Reading pressure field'
2446  call mfi_gets(pm1,wk,lwk,.false.)
2447  else
2448  call mfi_gets(pm1,wk,lwk,.true.)
2449  endif
2450  iofldsr = iofldsr + 1
2451  endif
2452 
2453  if (ifgettr) then
2454  offs = offs0 + iofldsr*stride + strideb
2455  call byte_set_view(offs,ifh_mbyte)
2456  if (ifgett) then
2457 c if(nid.eq.0) write(6,*) 'Reading temperature field'
2458  call mfi_gets(t,wk,lwk,.false.)
2459  else
2460  call mfi_gets(t,wk,lwk,.true.)
2461  endif
2462  iofldsr = iofldsr + 1
2463  endif
2464 
2465  ierr = 0
2466  do k=1,ldimt-1
2467  if (ifgtpsr(k)) then
2468  offs = offs0 + iofldsr*stride + strideb
2469  call byte_set_view(offs,ifh_mbyte)
2470  if (ifgtps(k)) then
2471 c if(nid.eq.0) write(6,'(A,I2,A)') ' Reading ps',k,' field'
2472  call mfi_gets(t(1,1,1,1,k+1),wk,lwk,.false.)
2473  else
2474  call mfi_gets(t(1,1,1,1,k+1),wk,lwk,.true.)
2475  endif
2476  iofldsr = iofldsr + 1
2477  endif
2478  enddo
2479  nbyte = 0
2480  if(nid.eq.pid0r) nbyte = iofldsr*nelr*wdsizr*nxr*nyr*nzr
2481 
2482  if (ifgtim) time = timer
2483 
2484  if(ifmpiio) then
2485  if(nid.eq.pid0r) call byte_close_mpi(ifh_mbyte,ierr)
2486  else
2487  if(nid.eq.pid0r) call byte_close(ierr)
2488  endif
2489  call err_chk(ierr,'Error closing restart file, in mfi.$')
2490  tio = dnekclock()-tiostart
2491 
2492  dnbyte = nbyte
2493  nbyte = glsum(dnbyte,1)
2494  nbyte = nbyte + iheadersize + 4 + isize*nelgr
2495 
2496  if (tio.eq.0) tio=1
2497  if (nio.eq.0) write(6,7) istep,time,
2498  & nbyte/tio/1024/1024/10,
2499  & nfiler
2500  7 format(/,i9,1pe12.4,' done :: Read checkpoint data',/,
2501  & 30x,'avg data-throughput = ',f7.1,'MBps',/,
2502  & 30x,'io-nodes = ',i5,/)
2503 
2504 
2505  if (ifaxis) call axis_interp_ic(pm1) ! Interpolate to axi mesh
2506  if (ifgetp) call map_pm1_to_pr(pm1,ifile) ! Interpolate pressure
2507 
2508  return
2509  end
2510 c-----------------------------------------------------------------------
2511  subroutine addfid(fname,fid)
2512  include 'SIZE'
2513  include 'TSTEP'
2514  include 'INPUT'
2515  include 'RESTART'
2516 
2517 
2518  character*1 fname(132)
2519  integer fid
2520 
2521  character*8 eight,fmt,s8
2522  save eight
2523  data eight / "????????" /
2524 
2525  do ipass=1,2 ! 2nd pass, in case 1 file/directory
2526  do k=8,1,-1
2527  i1 = indx1(fname,eight,k)
2528  if (i1.ne.0) then ! found k??? string
2529  write(fmt,1) k,k
2530  1 format('(i',i1,'.',i1,')')
2531  write(s8,fmt) fid
2532  call chcopy(fname(i1),s8,k)
2533  goto 10
2534  endif
2535  enddo
2536  10 continue
2537  enddo
2538 
2539  return
2540  end
2541 c-----------------------------------------------------------------------
2542  subroutine mfi_prepare(hname) ! determine which nodes are readers
2543  character*132 hname
2544 
2545  include 'SIZE'
2546  include 'PARALLEL'
2547  include 'RESTART'
2548  include 'INPUT'
2549 
2550  integer stride
2551  character*132 hdr, hname_
2552  logical if_byte_swap_test
2553  real*4 bytetest
2554 
2555  integer*8 offs0,offs
2556 
2557  ierr = 0
2558  ! rank0 (i/o master) will do a pre-read to get some infos
2559  ! we need to have in advance
2560  if (nid.eq.0) then
2561  call chcopy(hname_,hname,132)
2562  call addfid(hname_,0)
2563  call byte_open(hname_,ierr)
2564 
2565  if(ierr.ne.0) goto 101
2566  call blank (hdr,iheadersize)
2567  call byte_read (hdr,iheadersize/4,ierr)
2568  if(ierr.ne.0) goto 101
2569  call byte_read (bytetest,1,ierr)
2570  if(ierr.ne.0) goto 101
2571  if_byte_sw = if_byte_swap_test(bytetest,ierr) ! determine endianess
2572  if(ierr.ne.0) goto 101
2573  call byte_close(ierr)
2574  endif
2575 
2576  101 continue
2577  call err_chk(ierr,'Error reading restart header in mfi_prepare$')
2578 
2579  call bcast(if_byte_sw,lsize)
2580  call bcast(hdr,iheadersize)
2581  call mfi_parse_hdr(hdr,ierr)
2582 
2583  ifmpiio = .false.
2584  if (nfiler.eq.1 .and. abs(param(67)).eq.6) ifmpiio = .true.
2585 #ifdef NOMPIIO
2586  ifmpiio = .false.
2587 #endif
2588 
2589  if(.not.ifmpiio) then
2590 
2591  stride = np / nfiler
2592  if (stride.lt.1) then
2593  write(6,*) nfiler,np,' TOO MANY FILES, mfi_prepare'
2594  call exitt
2595  endif
2596 
2597  if (mod(nid,stride).eq.0) then ! i/o clients
2598  pid0r = nid
2599  pid1r = nid + stride
2600  fid0r = nid / stride
2601  call blank(hdr,iheadersize)
2602 
2603  call addfid(hname,fid0r)
2604  if(nid.eq.pid0r) write(6,*) ' FILE:',hname
2605  call byte_open(hname,ierr)
2606 
2607  if(ierr.ne.0) goto 102
2608  call byte_read (hdr, iheadersize/4,ierr)
2609  if(ierr.ne.0) goto 102
2610  call byte_read (bytetest,1,ierr)
2611  if(ierr.ne.0) goto 102
2612  call mfi_parse_hdr (hdr,ierr) ! replace hdr with correct one
2613  if (nelr.gt.lelr) then
2614  write(6,*) 'ERROR: increase lelr in SIZE to ', nelr
2615  call exitt
2616  endif
2617  call byte_read (er,nelr,ierr) ! get element mapping
2618  if(if_byte_sw) call byte_reverse(er,nelr,ierr)
2619  else
2620  pid0r = 0
2621  pid1r = 0
2622  fid0r = 0
2623  endif
2624 
2625  else
2626 
2627  pid0r = nid
2628  pid1r = nid
2629  offs0 = iheadersize + 4
2630  nfiler = np
2631 
2632  ! number of elements to read
2633  nelr = nelgr/np
2634  do i = 0,mod(nelgr,np)-1
2635  if(i.eq.nid) nelr = nelr + 1
2636  enddo
2637  nelbr = igl_running_sum(nelr) - nelr
2638  offs = offs0 + nelbr*isize
2639 
2640  call addfid(hname,fid0r)
2641  if(nio.eq.0) write(6,*) ' FILE:',hname
2642  call byte_open_mpi(hname,ifh_mbyte,.true.,ierr)
2643 
2644  if(ierr.ne.0) goto 102
2645  call byte_set_view(offs,ifh_mbyte)
2646  if (nelr.gt.lelr) then
2647  write(6,*) 'ERROR: increase lelr in SIZE to ', nelr
2648  call exitt
2649  endif
2650  call byte_read_mpi(er,nelr,-1,ifh_mbyte,ierr)
2651  if(ierr.ne.0) goto 102
2652  if(if_byte_sw) call byte_reverse(er,nelr,ierr)
2653 
2654  endif
2655 
2656  102 continue
2657  call err_chk(ierr,'Error reading header/element map.$')
2658 
2659  return
2660  end
2661 c-----------------------------------------------------------------------
2662  subroutine axis_interp_ic(pm1)
2663 
2664  include 'SIZE'
2665  include 'TOTAL'
2666  include 'RESTART'
2667 
2668  real pm1(lx1,ly1,lz1,lelv)
2669 
2670  common /ctmp0/ axism1(lx1,ly1)
2671  integer e
2672 
2673  if (.not.ifaxis) return
2674 
2675  do e=1,nelv
2676  if (ifrzer(e)) then
2677  if (ifgetx) then
2678  call mxm (xm1(1,1,1,e),lx1,iatlj1,ly1,axism1,ly1)
2679  call copy (xm1(1,1,1,e),axism1,lx1*ly1)
2680  call mxm (ym1(1,1,1,e),lx1,iatlj1,ly1,axism1,ly1)
2681  call copy (ym1(1,1,1,e),axism1,lx1*ly1)
2682  endif
2683  if (ifgetu) then
2684  call mxm (vx(1,1,1,e),lx1,iatlj1,ly1,axism1,ly1)
2685  call copy (vx(1,1,1,e),axism1,lx1*ly1)
2686  call mxm (vy(1,1,1,e),lx1,iatlj1,ly1,axism1,ly1)
2687  call copy (vy(1,1,1,e),axism1,lx1*ly1)
2688  endif
2689  if (ifgetw) then
2690  call mxm (vz(1,1,1,e),lx1,iatlj1,ly1,axism1,ly1)
2691  call copy (vz(1,1,1,e),axism1,lx1*ly1)
2692  endif
2693  if (ifgetp) then
2694  call mxm (pm1(1,1,1,e),lx1,iatlj1,ly1,axism1,ly1)
2695  call copy (pm1(1,1,1,e),axism1,lx1*ly1)
2696  endif
2697  if (ifgett) then
2698  call mxm (t(1,1,1,e,1),lx1,iatlj1,ly1,axism1,ly1)
2699  call copy (t(1,1,1,e,1),axism1,lx1*ly1)
2700  endif
2701  do ips=1,npscal
2702  is1 = ips + 1
2703  if (ifgtps(ips)) then
2704  call mxm (t(1,1,1,e,is1),lx1,iatlj1,ly1,axism1,ly1)
2705  call copy(t(1,1,1,e,is1),axism1,lx1*ly1)
2706  endif
2707  enddo
2708  endif
2709  enddo
2710 
2711  return
2712  end
2713 c-----------------------------------------------------------------------
2714  subroutine map_pm1_to_pr(pm1,ifile)
2715 
2716  include 'SIZE'
2717  include 'TOTAL'
2718  include 'RESTART'
2719 
2720  real pm1(lx1*ly1*lz1,lelv)
2721  integer e
2722 
2723  nxyz2 = lx2*ly2*lz2
2724 
2725  if (ifmhd.and.ifile.eq.2) then
2726  do e=1,nelv
2727  if (if_full_pres) then
2728  call copy (pm(1,1,1,e),pm1(1,e),nxyz2)
2729  else
2730  call map12 (pm(1,1,1,e),pm1(1,e),e)
2731  endif
2732  enddo
2733  elseif (ifsplit) then
2734  call copy (pr,pm1,lx1*ly1*lz1*nelv)
2735  else
2736  do e=1,nelv
2737  if (if_full_pres) then
2738  call copy (pr(1,1,1,e),pm1(1,e),nxyz2)
2739  else
2740  call map12 (pr(1,1,1,e),pm1(1,e),e)
2741  endif
2742  enddo
2743  endif
2744 
2745  return
2746  end
2747 c-----------------------------------------------------------------------
2748  subroutine full_restart(fnames,n_restart)
2749  include 'SIZE'
2750  include 'TOTAL'
2751 
2752  character *(*) fnames(*)
2753 
2754  ifile = istep+1 ! istep=0,1,...
2755 
2756  if (ifile.le.n_restart) then
2757  p67 = param(67)
2758  param(67) = 6.00
2759  call chcopy (initc,fnames(ifile),80)
2760  call bcast (initc,80)
2761  call restart(1)
2762  call setprop
2763  param(67)=p67
2764  endif
2765 
2766  return
2767  end
2768 c-----------------------------------------------------------------------
2769  subroutine projfld_c0()
2770 
2771  include 'SIZE'
2772  include 'TOTAL'
2773 
2774  nxyz1 = lx1*ly1*lz1
2775  ntott = nelt*nxyz1
2776  ntotv = nelv*nxyz1
2777 
2778  if(nid.eq.0 .and. loglevel.gt.2) write(6,*) 'projfld_c0'
2779 
2780 c if (ifflow.and..not.ifdg) then ! Current dg is for scalars only
2781  if (ifflow) then
2782  ifield = 1
2783  call opdssum(vx,vy,vz)
2784  call opcolv (vx,vy,vz,vmult)
2785  if (ifsplit) call dsavg(pr) ! continuous pressure
2786  if (ifvcor) call ortho(pr) ! remove any mean
2787  endif
2788 
2789 c if (ifmhd.and..not.ifdg) then ! Current dg is for scalars only
2790  if (ifmhd) then
2791  ifield = ifldmhd
2792  call opdssum(bx,by,bz)
2793  call opcolv (bx,by,bz,vmult)
2794  endif
2795 
2796  if (ifheat.and..not.ifdg) then ! Don't project if using DG
2797  ifield = 2
2798  call dssum(t ,lx1,ly1,lz1)
2799  call col2 (t ,tmult,ntott)
2800  do ifield=3,nfield
2801  if(gsh_fld(ifield).ge.0) then
2802  call dssum(t(1,1,1,1,ifield-1),lx1,ly1,lz1)
2803  if(iftmsh(ifield)) then
2804  call col2 (t(1,1,1,1,ifield-1),tmult,ntott)
2805  else
2806  call col2 (t(1,1,1,1,ifield-1),vmult,ntotv)
2807  endif
2808  endif
2809  enddo
2810  endif
2811 
2812 c if (ifpert.and..not.ifdg) then ! Still not DG
2813  if (ifpert) then
2814  do jp=1,npert
2815  ifield = 1
2816  call opdssum(vxp(1,jp),vyp(1,jp),vzp(1,jp))
2817  call opcolv (vxp(1,jp),vyp(1,jp),vzp(1,jp),vmult)
2818 
2819  if (.not.ifdg) then
2820  do ifield=2,nfield
2821  call dssum(tp(1,ifield-1,jp),lx1,ly1,lz1)
2822  if(iftmsh(ifield)) then
2823  call col2 (tp(1,ifield-1,jp),tmult,ntott)
2824  else
2825  call col2 (tp(1,ifield-1,jp),vmult,ntotv)
2826  endif
2827  enddo
2828  endif
2829  enddo
2830  endif
2831  jp = 0
2832 
2833  return
2834  end
subroutine nekasgn(ix, iy, iz, e)
Definition: bdry.f:1121
#define byte_reverse8
Definition: byte.c:34
#define byte_open
Definition: byte.c:35
#define byte_reverse
Definition: byte.c:33
void exitt()
Definition: comm_mpi.f:604
#define byte_close
Definition: byte.c:36
#define byte_read
Definition: byte.c:38
subroutine byte_open_mpi(fnamei, mpi_fh, ifro, ierr)
Definition: byte_mpi.f:13
subroutine byte_read_mpi(buf, icount, iorank, mpi_fh, ierr)
Definition: byte_mpi.f:48
subroutine byte_close_mpi(mpi_fh, ierr)
Definition: byte_mpi.f:84
subroutine byte_set_view(ioff_in, mpi_fh)
Definition: byte_mpi.f:97
subroutine setinvm
Definition: coef.f:1334
subroutine geom1(xm3, ym3, zm3)
Definition: coef.f:361
subroutine volume
Definition: coef.f:1003
subroutine geom2
Definition: coef.f:823
subroutine map12(y, x, iel)
Definition: coef.f:1530
subroutine map13(y, x, iel)
Definition: coef.f:1493
subroutine crecv2(mtype, buf, lenm, jnid)
Definition: comm_mpi.f:333
function igl_running_sum(in)
Definition: comm_mpi.f:700
subroutine msgwait(imsg)
Definition: comm_mpi.f:489
subroutine nekgsync()
Definition: comm_mpi.f:502
subroutine exitti(stringi, idata)
Definition: comm_mpi.f:535
subroutine lbcast(ifif)
Definition: comm_mpi.f:410
subroutine csend(mtype, buf, len, jnid, jpid)
Definition: comm_mpi.f:303
subroutine bcast(buf, len)
Definition: comm_mpi.f:431
function irecv(msgtag, x, len)
Definition: comm_mpi.f:471
subroutine err_chk(ierr, string)
Definition: comm_mpi.f:558
real *8 function dnekclock()
Definition: comm_mpi.f:393
subroutine setup_convect(igeom)
Definition: convect2.f:17
subroutine lim_chk(n, m, avar5, lvar5, sub_name10)
Definition: convect.f:454
integer function gllel(ieg)
Definition: dprocmap.f:183
integer function gllnid(ieg)
Definition: dprocmap.f:161
subroutine meshv(igeom)
Definition: drive2.f:812
subroutine fluid(igeom)
Definition: drive2.f:658
subroutine heat(igeom)
Definition: drive2.f:744
subroutine dssum(u, nx, ny, nz)
Definition: dssum.f:34
subroutine setdef
Definition: genxyz.f:352
subroutine sfastax
Definition: hmholtz.f:311
subroutine mfi(fname_in, ifile)
Definition: ic.f:2355
subroutine slogic(iffort, ifrest, ifprsl, nfiles)
Definition: ic.f:284
integer function indx2(s1, l1, s2, l2)
Definition: ic.f:1339
subroutine prsolvt
Definition: ic.f:1488
subroutine dsavg(u)
Definition: ic.f:1878
subroutine csplit(s0, s1, s2, l0)
Definition: ic.f:1402
subroutine mapab4r(x, y, nxr, nel)
Definition: ic.f:1253
subroutine full_restart(fnames, n_restart)
Definition: ic.f:2749
function i1_from_char(s1)
Definition: ic.f:1327
subroutine restart(nfiles)
Definition: ic.f:416
logical function ifgtil(IVALUE, LINE)
Definition: ic.f:1699
subroutine mfi_parse_hdr(hdr, ierr)
Definition: ic.f:2200
subroutine parse_std_hdr(hdr)
Definition: ic.f:2217
subroutine mapab(x, y, nxr, nel)
Definition: ic.f:1184
subroutine map13_all(x3, x1)
Definition: ic.f:1906
subroutine mapdmp(sdump, tdump, ieg, nxr, nyr, nzr, if_byte_sw)
Definition: ic.f:1109
subroutine parse_std_hdr_2006(hdr, rlcode)
Definition: ic.f:2316
subroutine nekuic
Definition: ic.f:1599
subroutine vcospf(x, y, n)
Definition: ic.f:1748
subroutine capit(lettrs, n)
Definition: ic.f:1648
subroutine addfid(fname, fid)
Definition: ic.f:2512
subroutine ljust(string)
Definition: ic.f:1433
subroutine sioflag(ndumps, fname, rsopts)
Definition: ic.f:954
logical function ifgtrl(VALUE, LINE)
Definition: ic.f:1662
subroutine geom_reset(icall)
Definition: ic.f:1802
subroutine axis_interp_ic(pm1)
Definition: ic.f:2663
subroutine vbyte_swap(x, n)
Definition: ic.f:1756
logical function if_byte_swap_test(bytetest, ierr)
Definition: ic.f:1782
subroutine chknorm(ifzero)
Definition: ic.f:1456
subroutine setics
Definition: ic.f:3
integer function indx1(S1, S2, L2)
Definition: ic.f:1357
subroutine prsolvv
Definition: ic.f:1535
integer function indx_cut(S1, S2, L2)
Definition: ic.f:1375
subroutine lshft(string, ipt)
Definition: ic.f:1417
subroutine map_pm1_to_pr(pm1, ifile)
Definition: ic.f:2715
subroutine mfi_getv(u, v, w, wk, lwk, iskip)
Definition: ic.f:2057
subroutine mfi_gets(u, wk, lwk, iskip)
Definition: ic.f:1923
subroutine mfi_prepare(hname)
Definition: ic.f:2543
subroutine perturb(tt, ifld, eps)
Definition: ic.f:1731
subroutine projfld_c0()
Definition: ic.f:2770
function glmin(a, n)
Definition: math.f:973
subroutine col2(a, b, n)
Definition: math.f:564
subroutine copy(a, b, n)
Definition: math.f:260
subroutine blank(A, N)
Definition: math.f:19
function iglmax(a, n)
Definition: math.f:913
subroutine izero(a, n)
Definition: math.f:215
function ltrunc(string, l)
Definition: math.f:494
function glsum(x, n)
Definition: math.f:861
subroutine cmult(a, const, n)
Definition: math.f:315
subroutine chcopy(a, b, n)
Definition: math.f:281
subroutine cfill(a, b, n)
Definition: math.f:244
subroutine rone(a, n)
Definition: math.f:230
subroutine rzero(a, n)
Definition: math.f:208
function glmax(a, n)
Definition: math.f:960
subroutine ptbgeom
Definition: mvmesh.f:950
subroutine mxm(a, n1, b, n2, c, n3)
Definition: mxm_wrapper.f:2
subroutine opdssum(a, b, c)
Definition: navier1.f:2582
subroutine ortho(respr)
Definition: navier1.f:224
subroutine opcopy(a1, a2, a3, b1, b2, b3)
Definition: navier1.f:2474
subroutine lagvel
Definition: navier1.f:1930
subroutine opcolv(a1, a2, a3, c)
Definition: navier1.f:2418
subroutine copy4r(a, b, n)
Definition: prepost.f:568
subroutine zwgll(Z, W, NP)
Definition: speclib.f:108
subroutine igllm(I12, IT12, Z1, Z2, lz1, lz2, ND1, ND2)
Definition: speclib.f:1102
subroutine unorm
Definition: subs1.f:352
subroutine setsolv
Definition: subs1.f:1083
subroutine setprop
Definition: subs1.f:2618
subroutine updmsys(IFLD)
Definition: subs2.f:712