Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
io_mod.F90
Go to the documentation of this file.
1 !==============================================================================
9 module io
10  implicit none
11 
12  character(132) :: load_name = 'NONE' !>
13 
14  public load_ic, load_name
15  private
16 
17 contains
18 
19 !--------------------------------------------------------------------
21 subroutine load_ic()
22  use kinds, only : dp
23  use parallel, only : nid
24  use soln, only : vx, vy, vz, pr, t
25  use restart, only : pid0, fid0
26  use size_m, only : nx1, ny1, nz1
27  use tstep, only : time
28 
29  integer :: nelo !>
30  integer :: word_size_load !>
31 
32  integer :: ierr, i
33  integer, parameter :: pad_size = 1
34  real(DP), allocatable :: padding(:,:,:,:)
35  logical :: skip_x
36 
37  if (load_name == 'NONE') then
38  call get_restart_name(load_name)
39  endif
40 
41  if (nid == pid0) then
42  call mbyte_open(load_name, fid0, ierr)
43  endif
44 
45  ! read and seek past header
46  call mfo_read_header(nelo, word_size_load, time, skip_x)
47 
48  ! seek past positions
49  if (nid == pid0 .and. skip_x) then
50  allocate(padding(nx1, ny1, nz1, pad_size))
51  do i = 1, nelo, pad_size
52  call byte_read(padding, word_size_load * size(padding) / 4, ierr)
53  call byte_read(padding, word_size_load * size(padding) / 4, ierr)
54  call byte_read(padding, word_size_load * size(padding) / 4, ierr)
55  enddo
56  endif
57 
58  ! read velocities
59  call mfo_read_vector(vx, vy, vz, size(vx,4), size(vx,1), size(vx,2), size(vx,3), word_size_load)
60 
61  ! read pressure
62  call mfo_read_scalar(pr(:,:,:,:), size(pr, 4), size(pr,1), size(pr,2), size(pr,3), word_size_load)
63  call mfo_read_scalar(t(:,:,:,:,1), size(t, 4), size(t,1), size(t,2), size(t,3), word_size_load)
64 
65  if (nid == pid0) then
66  call byte_close(ierr)
67  endif
68 
69 end subroutine load_ic
70 
71 subroutine get_restart_name(fname)
72  use kinds, only : dp
73  use input, only : ifreguo, series, param
74  use restart, only : nfileo, ifdiro
75  use string, only : ltrunc
76  implicit none
77 
78  character(132) :: fname
79  character(1) :: fnam1(132)
80 
81  character(6), save :: six = "??????"
82  character(6) :: str
83 
84  character(1), save :: slash = '/', dot = '.'
85 
86  integer :: k, len, ndigit
87  integer, external :: i_find_prefix, mod1
88  real(DP) :: rfileo
89 
90  fname = ''
91 
92 #ifdef MPIIO
93  rfileo = 1
94 #else
95  rfileo = nfileo
96 #endif
97  ndigit = int(log10(rfileo) + 1)
98 
99  k = 1
100  if (ifdiro) then ! Add directory
101  call chcopy(fnam1(1),'A',1)
102  call chcopy(fnam1(2),six,ndigit) ! put ???? in string
103  k = 2 + ndigit
104  call chcopy(fnam1(k),slash,1)
105  k = k+1
106  endif
107 
108  len=ltrunc(series,132) ! Add SESSION
109  call chcopy(fnam1(k),series,len)
110  k = k+len
111 
112  if (ifreguo) then
113  len=4
114  call chcopy(fnam1(k),'_reg',len)
115  k = k+len
116  endif
117 
118  call chcopy(fnam1(k),six,ndigit) ! Add file-id holder
119  k = k + ndigit
120 
121  call chcopy(fnam1(k ),dot,1) ! Add .f appendix
122  call chcopy(fnam1(k+1),'f',1)
123  k = k + 2
124 
125  write(str,4) int(param(69)) ! Add nfld number
126  4 format(i5.5)
127  call chcopy(fnam1(k),str,5)
128  k = k + 5
129 
130  call chcopy(fname(1:132),fnam1(1),k-1)
131 
132 end subroutine get_restart_name
133 
134 !-----------------------------------------------------------------------
136 subroutine mfo_read_header(nelo, word_size_file, time, skip_x)
137  use kinds, only : r4, dp
138  use size_m, only : nid, nelt, lelt
139  use parallel, only : lglel, isize
140  use restart, only : nfileo, pid0, pid1
141  use restart, only : iheadersize
142  implicit none
143 
144  integer, intent(out) :: nelo
145  integer, intent(out) :: word_size_file ! (intent out)
146  real(DP), intent(out) :: time
147  logical, intent(out) :: skip_x
148 
149  integer :: nelo_file !>
150  real(r4) :: test_pattern
151  real(r4), allocatable :: padding(:)
152  integer :: lglist(0:lelt)
153  character(1) :: rdcode1(10)
154  integer :: fid0, istep, nelgt
155  character(132) :: hdr
156 
157  integer :: idum, nfileoo, j, mtype, inelp, ierr, i
158  integer :: len
159  integer :: pad_size
160  integer :: nxo, nyo, nzo
161 
162  call nekgsync()
163  idum = 1
164 
165  nfileoo = nfileo
166  if(nid == pid0) then ! how many elements to dump
167  nelo = nelt
168  do j = pid0+1,pid1
169  mtype = j
170  call csend(mtype,idum,4,j,0) ! handshake
171  call crecv(mtype,inelp,4)
172  nelo = nelo + inelp
173  enddo
174  else
175  mtype = nid
176  call crecv(mtype,idum,4) ! hand-shake
177  call csend(mtype,nelt,4,pid0,0) ! u4 :=: u8
178  endif
179 
180  ierr = 0
181  if(nid == pid0) then
182  pad_size = (8 * (2**20) - (iheadersize + 4) ) / 4
183  allocate(padding(pad_size)); padding = 0.
184  call byte_read(hdr,iheadersize/4,ierr)
185  read(hdr, 1) word_size_file,nxo,nyo,nzo,nelo_file,nelgt,time,istep,fid0,nfileoo &
186  , (rdcode1(i),i=1,10)
187  1 format(5x,i1,1x,i2,1x,i2,1x,i2,1x,i10,1x,i10,1x,e20.13, &
188  & 1x,i9,1x,i6,1x,i6,1x,10a)
189  call byte_read(test_pattern,1,ierr)
190  ! pad up to 8MB
191  call byte_read(padding, pad_size, ierr)
192  deallocate(padding)
193  endif
194  if (rdcode1(1) == 'X') then
195  skip_x = .true.
196  else
197  skip_x = .false.
198  endif
199  call bcast(word_size_file, isize)
200  call bcast(time, 8)
201 
202  call err_chk(ierr,'Error writing header in mfo_write_hdr. $')
203 
204  if(nid == pid0) then
205  call byte_read(lglist,nelt,ierr)
206  pad_size = -nelt
207  do j = pid0+1,pid1
208  mtype = j
209  call csend(mtype,idum,4,j,0) ! handshake
210  len = 4*(lelt+1)
211  call crecv(mtype,lglist,len)
212  if(ierr == 0) then
213  call byte_read(lglist(1),lglist(0),ierr)
214  pad_size = pad_size - lglist(0)
215  endif
216  enddo
217 
218  ! pad up to 8MB
219  do while (pad_size < 0)
220  pad_size = pad_size + (8 * (2**20)) / 4
221  enddo
222  allocate(padding(pad_size)); padding = 0.
223  call byte_read(padding, pad_size, ierr)
224  deallocate(padding)
225 
226  else
227  mtype = nid
228  call crecv(mtype,idum,4) ! hand-shake
229 
230  lglist(0) = nelt
231  do j = 1, nelt
232  lglist(j) = lglel(j)
233  enddo
234 
235  len = 4*(nelt+1)
236  call csend(mtype,lglist,len,pid0,0)
237  endif
238 
239  call err_chk(ierr,'Error reading global nums in mfo_write_hdr$')
240  return
241 end subroutine mfo_read_header
242 
243 !-----------------------------------------------------------------------
245 subroutine mfo_read_scalar(u,nel,mx,my,mz, wdsizo)
246  use kinds, only : dp, r4
247  use size_m, only : nid, lelt, lxo
248  use restart, only : pid0, pid1
249  implicit none
250 
251  integer, intent(in) :: nel, mx, my, mz, wdsizo
252  real(DP), intent(in) :: u(mx,my,mz,1)
253 
254  real(r4), allocatable :: u4(:)
255  real(DP), allocatable :: u8(:)
256 
257  integer :: nxyz, ntot, idum, ierr, nout, k, mtype
258 
259  call nekgsync() ! clear outstanding message queues.
260  if(mx > lxo .OR. my > lxo .OR. mz > lxo) then
261  if(nid == 0) write(6,*) 'ABORT: lxo too small'
262  call exitt
263  endif
264 
265  nxyz = mx*my*mz
266  ntot = nxyz*nel
267 
268  idum = 1
269  ierr = 0
270 
271  if (wdsizo == 4) then
272  allocate(u4(2+lxo*lxo*lxo*2*lelt))
273  else
274  allocate(u8(1+lxo*lxo*lxo*1*lelt))
275  endif
276 
277  if (nid == pid0) then
278  idum = nel
279  nout = wdsizo/4 * nxyz * idum
280  if(wdsizo == 4 .and. ierr == 0) then
281  call byte_read(u4,nout,ierr) ! u4 :=: u8
282  elseif(ierr == 0) then
283  call byte_read(u8,nout,ierr) ! u4 :=: u8
284  endif
285 
286  if (wdsizo == 4) then ! 32-bit output
287  call copy4r(u,u4,nxyz * idum)
288  else
289  call copy(u,u8,nxyz * idum)
290  endif
291 
292 
293  ! read in the data of my childs
294  idum = 1
295  do k=pid0+1,pid1
296  mtype = k
297  call csend(mtype,idum,4,k,0) ! handshake
298  call crecv(mtype,idum,4) ! handshake
299 
300  nout = wdsizo/4 * nxyz * idum
301  if (wdsizo == 4 .AND. ierr == 0) then
302  call byte_read(u4,nout,ierr)
303  call csend(mtype, u4, nout*4, k, 0)
304  elseif(ierr == 0) then
305  call byte_read(u8,nout,ierr)
306  call csend(mtype, u8, nout*4, k, 0)
307  endif
308  enddo
309 
310  else
311  mtype = nid
312  call crecv(mtype,idum,4) ! hand-shake
313  call csend(mtype, nel, 4, pid0, 0)
314 
315  if (wdsizo == 4) then ! 32-bit output
316  call crecv(mtype, u4, nxyz * nel *wdsizo)
317  call copy4r(u, u4, nxyz * nel)
318  else
319  call crecv(mtype, u8, nxyz * nel *wdsizo)
320  call copy(u, u8, nxyz * nel)
321  endif
322 
323  endif
324 
325  call err_chk(ierr,'Error writing data to .f00 in mfo_outs. $')
326 
327  return
328 end subroutine mfo_read_scalar
329 
330 !-----------------------------------------------------------------------
332 subroutine mfo_read_vector(u,v,w,nel,mx,my,mz, wdsizo)
333  use kinds, only : dp, r4
334  use size_m, only : nid, ndim, lxo, lelt
335  use input, only : if3d
336  use restart, only : pid0, pid1
337  implicit none
338 
339  integer, intent(in) :: mx, my, mz, wdsizo
340  real(DP), intent(in) :: u(mx*my*mz,*),v(mx*my*mz,*),w(mx*my*mz,*)
341 
342  real(r4), allocatable :: u4(:)
343  real(DP), allocatable :: u8(:)
344 
345  integer :: nxyz, nel, idum, ierr
346  integer :: j, iel, nout, k, mtype
347 
348  call nekgsync() ! clear outstanding message queues.
349  if(mx > lxo .OR. my > lxo .OR. mz > lxo) then
350  if(nid == 0) write(6,*) 'ABORT: lxo too small'
351  call exitt
352  endif
353 
354  nxyz = mx*my*mz
355  idum = 1
356  ierr = 0
357 
358  if (wdsizo == 4) then
359  allocate(u4(2+lxo*lxo*lxo*6*lelt))
360  else
361  allocate(u8(1+lxo*lxo*lxo*3*lelt))
362  endif
363 
364  if (nid == pid0) then
365  nout = wdsizo/4 * ndim * nel * nxyz
366  if (wdsizo == 4 .and. ierr == 0) then
367  call byte_read(u4,nout,ierr) ! u4 :=: u8
368  elseif (ierr == 0) then
369  call byte_read(u8,nout,ierr) ! u4 :=: u8
370  endif
371 
372  j = 0
373  if (wdsizo == 4) then ! 32-bit output
374  do iel = 1,nel
375  call copy4r(u(1,iel), u4(j+1),nxyz)
376  j = j + nxyz
377  call copy4r(v(1,iel), u4(j+1),nxyz)
378  j = j + nxyz
379  if(if3d) then
380  call copy4r(w(1, iel), u4(j+1),nxyz)
381  j = j + nxyz
382  endif
383  enddo
384  else
385  do iel = 1,nel
386  call copy(u(1,iel), u8(j+1),nxyz)
387  j = j + nxyz
388  call copy(v(1,iel), u8(j+1),nxyz)
389  j = j + nxyz
390  if(if3d) then
391  call copy(w(1,iel), u8(j+1),nxyz)
392  j = j + nxyz
393  endif
394  enddo
395  endif
396 
397  ! read in the data of my childs
398  do k=pid0+1,pid1
399  mtype = k
400  call csend(mtype,idum,4,k,0) ! handshake
401  call crecv(mtype,idum,4) ! hand-shake
402 
403  nout = wdsizo/4 * ndim*nxyz * idum
404  if (wdsizo == 4 .AND. ierr == 0) then
405  call byte_read(u4,nout,ierr)
406  call csend(mtype,u4,nout*4, k, 0)
407  elseif(ierr == 0) then
408  call byte_read(u8,nout,ierr)
409  call csend(mtype,u8,nout*4, k, 0)
410  endif
411  enddo
412  else
413  mtype = nid
414  call crecv(mtype,idum,4) ! hand-shake
415  call csend(mtype,nel,4,pid0,0) ! u4 :=: u8
416 
417  if (wdsizo == 4) then ! 32-bit output
418  call crecv(mtype,u4,wdsizo*(nel*nxyz*ndim)) ! u4 :=: u8
419 
420  j = 0
421  do iel = 1,nel
422  call copy4r(u(1,iel), u4(j+1),nxyz)
423  j = j + nxyz
424  call copy4r(v(1,iel), u4(j+1),nxyz)
425  j = j + nxyz
426  if(if3d) then
427  call copy4r(w(1,iel), u4(j+1),nxyz)
428  j = j + nxyz
429  endif
430  enddo
431 
432  else
433  call crecv(mtype,u8,wdsizo*(nel*nxyz*ndim)) ! u4 :=: u8
434  j = 0
435  do iel = 1,nel
436  call copy(u(1,iel), u8(j+1),nxyz)
437  j = j + nxyz
438  call copy(v(1,iel), u8(j+1),nxyz)
439  j = j + nxyz
440  if(if3d) then
441  call copy(w(1,iel), u8(j+1),nxyz)
442  j = j + nxyz
443  endif
444  enddo
445  endif
446  endif
447 
448  call err_chk(ierr,'Error writing data to .f00 in mfo_outv. $')
449  return
450 end subroutine mfo_read_vector
451 
452 end module io
453 
subroutine mfo_read_vector(u, v, w, nel, mx, my, mz, wdsizo)
Read a vector field.
Definition: io_mod.F90:332
subroutine bcast(buf, len)
Definition: comm_mpi.F90:289
#define byte_close
Definition: byte.c:36
cleaned
Definition: tstep_mod.F90:2
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
subroutine mbyte_open(hname, fid, ierr)
open blah000.fldnn
Definition: ic.F90:1592
subroutine crecv(mtype, buf, lenm)
Definition: comm_mpi.F90:223
subroutine get_restart_name(fname)
Definition: io_mod.F90:71
void exitt()
Definition: comm_mpi.F90:411
#define byte_read
Definition: byte.c:38
subroutine mfo_read_scalar(u, nel, mx, my, mz, wdsizo)
Read a scalar field.
Definition: io_mod.F90:245
subroutine mfo_read_header(nelo, word_size_file, time, skip_x)
Read header and return number of elements and word size.
Definition: io_mod.F90:136
integer function lglel(iel)
subroutine copy(a, b, n)
Definition: math.F90:52
cleaned
Definition: parallel_mod.F90:2
cleaned
Definition: restart_mod.F90:2
subroutine nekgsync()
Definition: comm_mpi.F90:318
subroutine copy4r(a, b, n)
Definition: prepost.F90:644
subroutine chcopy(a, b, n)
Definition: math.F90:63
subroutine err_chk(ierr, istring)
Definition: comm_mpi.F90:356
integer function ltrunc(string, l)
Definition: string_mod.F90:260
subroutine csend(mtype, buf, len, jnid, jpid)
Definition: comm_mpi.F90:209
Definition: io_mod.F90:9