81 class(*),
target,
intent(in) :: data
82 real(kind=
rp),
intent(in),
optional :: t
84 real(kind=
rp),
allocatable,
target :: tempo(:)
85 type(
mesh_t),
pointer :: msh
89 character(len= 132) :: hdr
90 character :: rdcode(10)
91 character(len=6) :: id_str
92 character(len= 1024) :: fname
93 character(len= 1024) :: name
95 integer :: i, ierr, n, suffix_pos, tslash_pos
96 integer :: lx, ly, lz, lxyz, gdim, glb_nelv, nelv, offset_el
97 integer,
allocatable :: idx(:)
98 type(mpi_status) :: status
100 integer (kind=MPI_OFFSET_KIND) :: mpi_offset, byte_offset, temp_offset
101 real(kind=
sp),
parameter :: test_pattern = 6.54321
103 logical :: write_mesh, write_velocity, write_pressure, write_temperature
104 integer :: fld_data_size, n_scalar_fields
116 write_pressure = .false.
117 write_velocity = .false.
118 write_temperature = .false.
127 glb_nelv = data%glb_nelv
128 offset_el = data%offset_el
130 if (data%x%size() .gt. 0) x%ptr => data%x%x
131 if (data%y%size() .gt. 0) y%ptr => data%y%x
132 if (data%z%size() .gt. 0) z%ptr => data%z%x
133 if (gdim .eq. 2) z%ptr => data%y%x
134 if (data%u%size() .gt. 0)
then
138 if (data%v%size() .le. 0) v%ptr => data%u%x
139 if (data%w%size() .le. 0) w%ptr => data%u%x
140 write_velocity = .true.
142 if (data%v%size() .gt. 0) v%ptr => data%v%x
143 if (data%w%size() .gt. 0) w%ptr => data%w%x
144 if (data%p%size() .gt. 0)
then
146 write_pressure = .true.
148 if (data%t%size() .gt. 0)
then
149 write_temperature = .true.
154 if (gdim .eq. 2 .and. data%w%size() .gt. 0)
then
155 n_scalar_fields = data%n_scalars + 1
156 allocate(scalar_fields(n_scalar_fields))
157 do i = 1, n_scalar_fields -1
158 scalar_fields(i)%ptr => data%s(i)%x
160 scalar_fields(n_scalar_fields)%ptr => data%w%x
162 n_scalar_fields = data%n_scalars
163 allocate(scalar_fields(n_scalar_fields+1))
164 do i = 1, n_scalar_fields
165 scalar_fields(i)%ptr => data%s(i)%x
167 scalar_fields(n_scalar_fields+1)%ptr => data%w%x
172 if (nelv .eq. 0)
then
189 p%ptr => data%x(:,1,1,1)
191 write_pressure = .true.
192 write_velocity = .false.
194 select case (data%size())
196 p%ptr => data%items(1)%ptr%x(:,1,1,1)
197 write_pressure = .true.
198 write_velocity = .false.
200 p%ptr => data%items(1)%ptr%x(:,1,1,1)
201 tem%ptr => data%items(2)%ptr%x(:,1,1,1)
202 write_pressure = .true.
203 write_temperature = .true.
205 u%ptr => data%items(1)%ptr%x(:,1,1,1)
206 v%ptr => data%items(2)%ptr%x(:,1,1,1)
207 w%ptr => data%items(3)%ptr%x(:,1,1,1)
208 write_velocity = .true.
210 p%ptr => data%items(1)%ptr%x(:,1,1,1)
211 u%ptr => data%items(2)%ptr%x(:,1,1,1)
212 v%ptr => data%items(3)%ptr%x(:,1,1,1)
213 w%ptr => data%items(4)%ptr%x(:,1,1,1)
214 write_pressure = .true.
215 write_velocity = .true.
217 p%ptr => data%items(1)%ptr%x(:,1,1,1)
218 u%ptr => data%items(2)%ptr%x(:,1,1,1)
219 v%ptr => data%items(3)%ptr%x(:,1,1,1)
220 w%ptr => data%items(4)%ptr%x(:,1,1,1)
222 if (trim(data%name(5)) .eq.
'temperature')
then
224 tem%ptr => data%items(5)%ptr%x(:,1,1,1)
225 n_scalar_fields = data%size() - 5
226 allocate(scalar_fields(n_scalar_fields))
227 do i = 1, n_scalar_fields
228 scalar_fields(i)%ptr => data%items(i+5)%ptr%x(:,1,1,1)
230 write_temperature = .true.
233 n_scalar_fields = data%size() - 4
234 allocate(scalar_fields(n_scalar_fields))
235 do i = 1, n_scalar_fields
236 scalar_fields(i)%ptr => data%items(i+4)%ptr%x(:,1,1,1)
238 write_temperature = .false.
240 write_pressure = .true.
241 write_velocity = .true.
243 call neko_error(
'This many fields not supported yet, fld_file')
250 if (
associated(dof))
then
251 x%ptr => dof%x(:,1,1,1)
252 y%ptr => dof%y(:,1,1,1)
253 z%ptr => dof%z(:,1,1,1)
258 if (
associated(msh))
then
260 glb_nelv = msh%glb_nelv
261 offset_el = msh%offset_el
264 allocate(idx(msh%nelv))
266 idx(i) = msh%elements(i)%e%id()
270 if (
associated(xh))
then
279 if (this%dp_precision)
then
284 if (this%dp_precision)
then
295 call this%increment_counter()
296 write_mesh = (this%get_counter() .eq. this%get_start_counter())
297 call mpi_allreduce(mpi_in_place, write_mesh, 1, &
299 call mpi_allreduce(mpi_in_place, write_velocity, 1, &
301 call mpi_allreduce(mpi_in_place, write_pressure, 1, &
303 call mpi_allreduce(mpi_in_place, write_temperature, 1, &
305 call mpi_allreduce(mpi_in_place, n_scalar_fields, 1, &
316 if (write_velocity)
then
320 if (write_pressure)
then
324 if (write_temperature)
then
328 if (n_scalar_fields .gt. 0 )
then
331 write(rdcode(i),
'(i1)') (n_scalar_fields)/10
333 write(rdcode(i),
'(i1)') (n_scalar_fields) - 10*((n_scalar_fields)/10)
338 write(hdr, 1) fld_data_size, lx, ly, lz, glb_nelv, glb_nelv,&
339 time, this%get_counter(), 1, 1, (rdcode(i), i = 1, 10)
3401
format(
'#std', 1x, i1, 1x,
i2, 1x,
i2, 1x,
i2, 1x, i10, 1x, i10, &
341 1x, e20.13, 1x, i9, 1x, i6, 1x, i6, 1x, 10a)
344 fname = this%get_fld_fname()
346 call mpi_file_open(
neko_comm, trim(fname), &
347 mpi_mode_wronly + mpi_mode_create, mpi_info_null, fh, &
350 call mpi_file_write_all(fh, hdr, 132, mpi_character, status, ierr)
353 call mpi_file_write_all(fh, test_pattern, 1, mpi_real, status, ierr)
356 byte_offset = mpi_offset + &
358 call mpi_file_write_at_all(fh, byte_offset, idx, nelv, &
359 mpi_integer, status, ierr)
364 byte_offset = mpi_offset + int(offset_el,
i8) * &
365 (int(gdim*lxyz,
i8) * &
366 int(fld_data_size,
i8))
368 x%ptr, y%ptr, z%ptr, &
370 mpi_offset = mpi_offset + int(glb_nelv,
i8) * &
371 (int(gdim *lxyz,
i8) * &
372 int(fld_data_size,
i8))
374 if (write_velocity)
then
375 byte_offset = mpi_offset + int(offset_el,
i8) * &
376 (int(gdim * (lxyz),
i8) * int(fld_data_size,
i8))
378 u%ptr, v%ptr, w%ptr, n, gdim, lxyz, nelv)
380 mpi_offset = mpi_offset + int(glb_nelv,
i8) * &
381 (int(gdim * (lxyz),
i8) * &
382 int(fld_data_size,
i8))
386 if (write_pressure)
then
387 byte_offset = mpi_offset + int(offset_el,
i8) * &
388 (int((lxyz),
i8) * int(fld_data_size,
i8))
390 mpi_offset = mpi_offset + int(glb_nelv,
i8) * &
391 (int((lxyz),
i8) * int(fld_data_size,
i8))
394 if (write_temperature)
then
395 byte_offset = mpi_offset + int(offset_el,
i8) * &
397 int(fld_data_size,
i8))
399 mpi_offset = mpi_offset + int(glb_nelv,
i8) * &
401 int(fld_data_size,
i8))
404 temp_offset = mpi_offset
406 do i = 1, n_scalar_fields
410 mpi_offset = int(temp_offset,
i8) + int(1_i8*glb_nelv,
i8) * &
411 (int(lxyz,
i8) * int(fld_data_size,
i8))
413 byte_offset = int(mpi_offset,
i8) + int(offset_el,
i8) * &
415 int(fld_data_size,
i8))
417 mpi_offset = int(mpi_offset,
i8) + int(glb_nelv,
i8) * &
419 int(fld_data_size,
i8))
422 if (gdim .eq. 3)
then
429 byte_offset = int(mpi_offset,
i8) + &
430 int(offset_el,
i8) * &
435 x%ptr, y%ptr, z%ptr, gdim, lxyz, nelv)
436 mpi_offset = int(mpi_offset,
i8) + &
437 int(glb_nelv,
i8) * &
443 if (write_velocity)
then
444 byte_offset = int(mpi_offset,
i8) + &
445 int(offset_el,
i8) * &
450 u%ptr, v%ptr, w%ptr, gdim, lxyz, nelv)
451 mpi_offset = int(mpi_offset,
i8) + &
452 int(glb_nelv,
i8) * &
459 if (write_pressure)
then
460 byte_offset = int(mpi_offset,
i8) + &
461 int(offset_el,
i8) * &
466 mpi_offset = int(mpi_offset,
i8) + &
467 int(glb_nelv,
i8) * &
473 if (write_temperature)
then
474 byte_offset = int(mpi_offset,
i8) + &
475 int(offset_el,
i8) * &
480 mpi_offset = int(mpi_offset,
i8) + &
481 int(glb_nelv,
i8) * &
489 temp_offset = mpi_offset
491 do i = 1, n_scalar_fields
495 mpi_offset = int(temp_offset,
i8) + &
496 int(1_i8*glb_nelv,
i8) * &
501 byte_offset = int(mpi_offset,
i8) + &
502 int(offset_el,
i8) * &
506 scalar_fields(i)%ptr, lxyz, nelv)
507 mpi_offset = int(mpi_offset,
i8) + &
508 int(glb_nelv,
i8) * &
515 call mpi_file_sync(fh, ierr)
516 call mpi_file_close(fh, ierr)
521 open(newunit = file_unit, &
522 file = this%get_meta_fname(), status =
'replace')
529 write(file_unit, fmt =
'(A,A,A)')
'filetemplate: ', &
530 trim(name),
'%01d.f%05d'
531 write(file_unit, fmt =
'(A,i5)')
'firsttimestep: ', &
532 this%get_start_counter()
533 write(file_unit, fmt =
'(A,i5)')
'numtimesteps: ', &
534 (this%get_counter() + 1) - this%get_start_counter()
685 class(*),
target,
intent(inout) :: data
686 character(len= 132) :: hdr
687 integer :: ierr, suffix_pos, i, j
689 type(mpi_status) :: status
690 character(len= 1024) :: fname, base_fname, meta_fname, string, path
691 logical :: meta_file, read_mesh, read_velocity, read_pressure
693 character(len=6) :: suffix
694 integer (kind=MPI_OFFSET_KIND) :: mpi_offset, byte_offset
695 integer :: lx, ly, lz, glb_nelv, counter, lxyz
696 integer :: FLD_DATA_SIZE, n_scalars, n
698 real(kind=
rp) :: time
699 real(kind=
sp) :: temp
701 real(kind=
sp),
parameter :: test_pattern = 6.54321
702 character :: rdcode(10), temp_str(4)
703 character(len=LOG_SIZE) :: log_buf
709 inquire(
file = trim(meta_fname), exist = meta_file)
710 if (meta_file .and. data%meta_nsamples .eq. 0)
then
712 open(newunit = file_unit,
file = trim(meta_fname))
713 read(file_unit, fmt =
'(A)') string
714 read(string(14:), fmt =
'(A)') string
715 string = trim(string)
717 data%fld_series_fname = string(:scan(trim(string),
'%')-1)
718 data%fld_series_fname = adjustl(data%fld_series_fname)
719 data%fld_series_fname = trim(data%fld_series_fname)//
'0'
721 read(file_unit, fmt =
'(A)') string
722 read(string(scan(string,
':')+1:), *) data%meta_start_counter
723 read(file_unit, fmt =
'(A)') string
724 read(string(scan(string,
':')+1:), *) data%meta_nsamples
727 write(log_buf,*)
'Reading meta file for fld series'
729 write(log_buf,*)
'Name: ', trim(data%fld_series_fname)
731 write(log_buf,*)
'Start counter: ', data%meta_start_counter
733 write(log_buf,*)
'Nsamples: ', data%meta_nsamples
737 call mpi_bcast(data%fld_series_fname, 1024, mpi_character, 0, &
739 call mpi_bcast(data%meta_start_counter, 1, mpi_integer, 0, &
741 call mpi_bcast(data%meta_nsamples, 1, mpi_integer, 0, &
744 if (this%get_counter() .eq. -1)
then
745 call this%set_start_counter(data%meta_start_counter)
746 call this%set_counter(data%meta_start_counter)
752 write(suffix,
'(a,i5.5)')
'f', this%get_counter()
753 fname = trim(path) // trim(data%fld_series_fname) //
'.' // suffix
754 if (this%get_counter() .ge. &
755 data%meta_nsamples+data%meta_start_counter)
then
756 call neko_error(
'Trying to read more fld files than exist')
759 write(suffix,
'(a,i5.5)')
'f', this%get_counter()
762 call mpi_file_open(
neko_comm, trim(fname), &
763 mpi_mode_rdonly, mpi_info_null, fh, ierr)
765 if (ierr .ne. 0)
call neko_error(
"Could not read "//trim(fname))
767 call neko_log%message(
'Reading fld file ' // trim(fname))
769 call mpi_file_read_all(fh, hdr, 132, mpi_character, status, ierr)
773 read(hdr, 1) temp_str, fld_data_size, lx, ly, lz, glb_nelv, glb_nelv, &
774 time, counter, i, j, (rdcode(i), i = 1, 10)
7751
format(4a, 1x, i1, 1x,
i2, 1x,
i2, 1x,
i2, 1x, i10, 1x, i10, &
776 1x, e20.13, 1x, i9, 1x, i6, 1x, i6, 1x, 10a)
777 if (data%nelv .eq. 0)
then
779 data%nelv = dist%num_local()
780 data%offset_el = dist%start_idx()
785 data%glb_nelv = glb_nelv
786 data%t_counter = counter
799 this%dp_precision = .true.
801 this%dp_precision = .false.
803 if (this%dp_precision)
then
804 allocate(
tmp_dp(data%gdim*n))
806 allocate(
tmp_sp(data%gdim*n))
812 read_velocity = .false.
813 read_pressure = .false.
815 if (rdcode(i) .eq.
'X')
then
822 if (rdcode(i) .eq.
'U')
then
823 read_velocity = .true.
829 if (rdcode(i) .eq.
'P')
then
830 read_pressure = .true.
834 if (rdcode(i) .eq.
'T')
then
840 if (rdcode(i) .eq.
'S')
then
842 read(rdcode(i),*) n_scalars
843 n_scalars = n_scalars*10
846 n_scalars = n_scalars+j
848 if (
allocated(data%s))
then
849 if (data%n_scalars .ne. n_scalars)
then
850 do j = 1, data%n_scalars
851 call data%s(j)%free()
854 data%n_scalars = n_scalars
855 allocate(data%s(n_scalars))
856 do j = 1, data%n_scalars
857 call data%s(j)%init(n)
861 data%n_scalars = n_scalars
862 allocate(data%s(data%n_scalars))
863 do j = 1, data%n_scalars
864 call data%s(j)%init(n)
871 call mpi_file_read_at_all(fh, mpi_offset, temp, 1, &
872 mpi_real, status, ierr)
873 if (temp .ne. test_pattern)
then
874 call neko_error(
'Incorrect format for fld file, &
875 &test pattern does not match.')
880 if (
allocated(data%idx))
then
881 if (
size(data%idx) .ne. data%nelv)
then
883 allocate(data%idx(data%nelv))
886 allocate(data%idx(data%nelv))
889 byte_offset = mpi_offset + &
892 call mpi_file_read_at_all(fh, byte_offset, data%idx, data%nelv, &
893 mpi_integer, status, ierr)
895 mpi_offset = mpi_offset + &
899 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
900 (int(data%gdim*lxyz,
i8) * &
901 int(fld_data_size,
i8))
903 data%x, data%y, data%z, data)
904 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
905 (int(data%gdim *lxyz,
i8) * &
906 int(fld_data_size,
i8))
909 if (read_velocity)
then
910 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
911 (int(data%gdim*lxyz,
i8) * &
912 int(fld_data_size,
i8))
914 data%u, data%v, data%w, data)
915 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
916 (int(data%gdim *lxyz,
i8) * &
917 int(fld_data_size,
i8))
920 if (read_pressure)
then
921 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
923 int(fld_data_size,
i8))
925 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
927 int(fld_data_size,
i8))
931 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
933 int(fld_data_size,
i8))
935 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
937 int(fld_data_size,
i8))
941 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
943 int(fld_data_size,
i8))
945 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
947 int(fld_data_size,
i8))
950 call this%increment_counter()
955 call neko_error(
'Currently we only read into fld_file_data_t, &
956 &please use that data structure instead.')