82 class(*),
target,
intent(in) :: data
83 real(kind=
rp),
intent(in),
optional :: t
85 real(kind=
rp),
allocatable,
target :: tempo(:)
86 type(
mesh_t),
pointer :: msh
90 character(len= 132) :: hdr
91 character :: rdcode(10)
92 character(len=6) :: id_str
93 character(len= 1024) :: fname
94 character(len= 1024) :: name
96 integer :: i, ierr, n, suffix_pos, tslash_pos
97 integer :: lx, ly, lz, lxyz, gdim, glb_nelv, nelv, offset_el
98 integer,
allocatable :: idx(:)
99 type(mpi_status) :: status
101 integer (kind=MPI_OFFSET_KIND) :: mpi_offset, byte_offset, temp_offset
102 real(kind=
sp),
parameter :: test_pattern = 6.54321
104 logical :: write_mesh, write_velocity, write_pressure, write_temperature
105 integer :: fld_data_size, n_scalar_fields
117 write_pressure = .false.
118 write_velocity = .false.
119 write_temperature = .false.
128 glb_nelv = data%glb_nelv
129 offset_el = data%offset_el
131 if (data%x%size() .gt. 0) x%ptr => data%x%x
132 if (data%y%size() .gt. 0) y%ptr => data%y%x
133 if (data%z%size() .gt. 0) z%ptr => data%z%x
134 if (gdim .eq. 2) z%ptr => data%y%x
135 if (data%u%size() .gt. 0)
then
139 if (data%v%size() .le. 0) v%ptr => data%u%x
140 if (data%w%size() .le. 0) w%ptr => data%u%x
141 write_velocity = .true.
143 if (data%v%size() .gt. 0) v%ptr => data%v%x
144 if (data%w%size() .gt. 0) w%ptr => data%w%x
145 if (data%p%size() .gt. 0)
then
147 write_pressure = .true.
149 if (data%t%size() .gt. 0)
then
150 write_temperature = .true.
155 if (gdim .eq. 2 .and. data%w%size() .gt. 0)
then
156 n_scalar_fields = data%n_scalars + 1
157 allocate(scalar_fields(n_scalar_fields))
158 do i = 1, n_scalar_fields -1
159 scalar_fields(i)%ptr => data%s(i)%x
161 scalar_fields(n_scalar_fields)%ptr => data%w%x
163 n_scalar_fields = data%n_scalars
164 allocate(scalar_fields(n_scalar_fields+1))
165 do i = 1, n_scalar_fields
166 scalar_fields(i)%ptr => data%s(i)%x
168 scalar_fields(n_scalar_fields+1)%ptr => data%w%x
173 if (nelv .eq. 0)
then
190 p%ptr => data%x(:,1,1,1)
192 write_pressure = .true.
193 write_velocity = .false.
195 select case (data%size())
197 p%ptr => data%items(1)%ptr%x(:,1,1,1)
198 write_pressure = .true.
199 write_velocity = .false.
201 p%ptr => data%items(1)%ptr%x(:,1,1,1)
202 tem%ptr => data%items(2)%ptr%x(:,1,1,1)
203 write_pressure = .true.
204 write_temperature = .true.
206 u%ptr => data%items(1)%ptr%x(:,1,1,1)
207 v%ptr => data%items(2)%ptr%x(:,1,1,1)
208 w%ptr => data%items(3)%ptr%x(:,1,1,1)
209 write_velocity = .true.
211 p%ptr => data%items(1)%ptr%x(:,1,1,1)
212 u%ptr => data%items(2)%ptr%x(:,1,1,1)
213 v%ptr => data%items(3)%ptr%x(:,1,1,1)
214 w%ptr => data%items(4)%ptr%x(:,1,1,1)
215 write_pressure = .true.
216 write_velocity = .true.
218 p%ptr => data%items(1)%ptr%x(:,1,1,1)
219 u%ptr => data%items(2)%ptr%x(:,1,1,1)
220 v%ptr => data%items(3)%ptr%x(:,1,1,1)
221 w%ptr => data%items(4)%ptr%x(:,1,1,1)
222 tem%ptr => data%items(5)%ptr%x(:,1,1,1)
223 n_scalar_fields = data%size() - 5
224 allocate(scalar_fields(n_scalar_fields))
225 do i = 1, n_scalar_fields
226 scalar_fields(i)%ptr => data%items(i+5)%ptr%x(:,1,1,1)
228 write_pressure = .true.
229 write_velocity = .true.
230 write_temperature = .true.
232 call neko_error(
'This many fields not supported yet, fld_file')
239 if (
associated(dof))
then
240 x%ptr => dof%x(:,1,1,1)
241 y%ptr => dof%y(:,1,1,1)
242 z%ptr => dof%z(:,1,1,1)
247 if (
associated(msh))
then
249 glb_nelv = msh%glb_nelv
250 offset_el = msh%offset_el
253 allocate(idx(msh%nelv))
255 idx(i) = msh%elements(i)%e%id()
259 if (
associated(xh))
then
268 if (this%dp_precision)
then
273 if (this%dp_precision)
then
284 call this%increment_counter()
286 if (.not. this%write_mesh)
then
287 write_mesh = (this%get_counter() .eq. this%get_start_counter())
289 write_mesh = this%write_mesh
291 call mpi_allreduce(mpi_in_place, write_mesh, 1, &
293 call mpi_allreduce(mpi_in_place, write_velocity, 1, &
295 call mpi_allreduce(mpi_in_place, write_pressure, 1, &
297 call mpi_allreduce(mpi_in_place, write_temperature, 1, &
299 call mpi_allreduce(mpi_in_place, n_scalar_fields, 1, &
310 if (write_velocity)
then
314 if (write_pressure)
then
318 if (write_temperature)
then
322 if (n_scalar_fields .gt. 0 )
then
325 write(rdcode(i),
'(i1)') (n_scalar_fields)/10
327 write(rdcode(i),
'(i1)') (n_scalar_fields) - 10*((n_scalar_fields)/10)
332 write(hdr, 1) fld_data_size, lx, ly, lz, glb_nelv, glb_nelv,&
333 time, this%get_counter(), 1, 1, (rdcode(i), i = 1, 10)
3341
format(
'#std', 1x, i1, 1x,
i2, 1x,
i2, 1x,
i2, 1x, i10, 1x, i10, &
335 1x, e20.13, 1x, i9, 1x, i6, 1x, i6, 1x, 10a)
338 fname = this%get_fld_fname()
340 call mpi_file_open(
neko_comm, trim(fname), &
341 mpi_mode_wronly + mpi_mode_create, mpi_info_null, fh, &
344 call mpi_file_write_all(fh, hdr, 132, mpi_character, status, ierr)
347 call mpi_file_write_all(fh, test_pattern, 1, mpi_real, status, ierr)
350 byte_offset = mpi_offset + &
352 call mpi_file_write_at_all(fh, byte_offset, idx, nelv, &
353 mpi_integer, status, ierr)
358 byte_offset = mpi_offset + int(offset_el,
i8) * &
359 (int(gdim*lxyz,
i8) * &
360 int(fld_data_size,
i8))
362 x%ptr, y%ptr, z%ptr, &
364 mpi_offset = mpi_offset + int(glb_nelv,
i8) * &
365 (int(gdim *lxyz,
i8) * &
366 int(fld_data_size,
i8))
368 if (write_velocity)
then
369 byte_offset = mpi_offset + int(offset_el,
i8) * &
370 (int(gdim * (lxyz),
i8) * int(fld_data_size,
i8))
372 u%ptr, v%ptr, w%ptr, n, gdim, lxyz, nelv)
374 mpi_offset = mpi_offset + int(glb_nelv,
i8) * &
375 (int(gdim * (lxyz),
i8) * &
376 int(fld_data_size,
i8))
380 if (write_pressure)
then
381 byte_offset = mpi_offset + int(offset_el,
i8) * &
382 (int((lxyz),
i8) * int(fld_data_size,
i8))
384 mpi_offset = mpi_offset + int(glb_nelv,
i8) * &
385 (int((lxyz),
i8) * int(fld_data_size,
i8))
388 if (write_temperature)
then
389 byte_offset = mpi_offset + int(offset_el,
i8) * &
391 int(fld_data_size,
i8))
393 mpi_offset = mpi_offset + int(glb_nelv,
i8) * &
395 int(fld_data_size,
i8))
398 temp_offset = mpi_offset
400 do i = 1, n_scalar_fields
404 mpi_offset = int(temp_offset,
i8) + int(1_i8*glb_nelv,
i8) * &
405 (int(lxyz,
i8) * int(fld_data_size,
i8))
407 byte_offset = int(mpi_offset,
i8) + int(offset_el,
i8) * &
409 int(fld_data_size,
i8))
411 mpi_offset = int(mpi_offset,
i8) + int(glb_nelv,
i8) * &
413 int(fld_data_size,
i8))
416 if (gdim .eq. 3)
then
423 byte_offset = int(mpi_offset,
i8) + &
424 int(offset_el,
i8) * &
429 x%ptr, y%ptr, z%ptr, gdim, lxyz, nelv)
430 mpi_offset = int(mpi_offset,
i8) + &
431 int(glb_nelv,
i8) * &
437 if (write_velocity)
then
438 byte_offset = int(mpi_offset,
i8) + &
439 int(offset_el,
i8) * &
444 u%ptr, v%ptr, w%ptr, gdim, lxyz, nelv)
445 mpi_offset = int(mpi_offset,
i8) + &
446 int(glb_nelv,
i8) * &
453 if (write_pressure)
then
454 byte_offset = int(mpi_offset,
i8) + &
455 int(offset_el,
i8) * &
460 mpi_offset = int(mpi_offset,
i8) + &
461 int(glb_nelv,
i8) * &
467 if (write_temperature)
then
468 byte_offset = int(mpi_offset,
i8) + &
469 int(offset_el,
i8) * &
474 mpi_offset = int(mpi_offset,
i8) + &
475 int(glb_nelv,
i8) * &
483 temp_offset = mpi_offset
485 do i = 1, n_scalar_fields
489 mpi_offset = int(temp_offset,
i8) + &
490 int(1_i8*glb_nelv,
i8) * &
495 byte_offset = int(mpi_offset,
i8) + &
496 int(offset_el,
i8) * &
500 scalar_fields(i)%ptr, lxyz, nelv)
501 mpi_offset = int(mpi_offset,
i8) + &
502 int(glb_nelv,
i8) * &
509 call mpi_file_sync(fh, ierr)
510 call mpi_file_close(fh, ierr)
515 open(newunit = file_unit, &
516 file = this%get_meta_fname(), status =
'replace')
523 write(file_unit, fmt =
'(A,A,A)')
'filetemplate: ', &
524 trim(name),
'%01d.f%05d'
525 write(file_unit, fmt =
'(A,i5)')
'firsttimestep: ', &
526 this%get_start_counter()
527 write(file_unit, fmt =
'(A,i5)')
'numtimesteps: ', &
528 (this%get_counter() + 1) - this%get_start_counter()
534 if (
allocated(tempo))
deallocate(tempo)
535 if (
allocated(scalar_fields))
deallocate(scalar_fields)
682 class(*),
target,
intent(inout) :: data
683 character(len= 132) :: hdr
684 integer :: ierr, suffix_pos, i, j
686 type(mpi_status) :: status
687 character(len= 1024) :: fname, base_fname, meta_fname, string, path
688 logical :: meta_file, read_mesh, read_velocity, read_pressure
690 character(len=6) :: suffix
691 integer (kind=MPI_OFFSET_KIND) :: mpi_offset, byte_offset
692 integer :: lx, ly, lz, glb_nelv, counter, lxyz
693 integer :: FLD_DATA_SIZE, n_scalars, n
695 real(kind=
rp) :: time
696 real(kind=
sp) :: temp
698 real(kind=
sp),
parameter :: test_pattern = 6.54321
699 character :: rdcode(10), temp_str(4)
700 character(len=LOG_SIZE) :: log_buf
706 inquire(
file = trim(meta_fname), exist = meta_file)
707 if (meta_file .and. data%meta_nsamples .eq. 0)
then
709 open(newunit = file_unit,
file = trim(meta_fname))
710 read(file_unit, fmt =
'(A)') string
711 read(string(14:), fmt =
'(A)') string
712 string = trim(string)
714 data%fld_series_fname = string(:scan(trim(string),
'%')-1)
715 data%fld_series_fname = adjustl(data%fld_series_fname)
716 data%fld_series_fname = trim(data%fld_series_fname)//
'0'
718 read(file_unit, fmt =
'(A)') string
719 read(string(scan(string,
':')+1:), *) data%meta_start_counter
720 read(file_unit, fmt =
'(A)') string
721 read(string(scan(string,
':')+1:), *) data%meta_nsamples
724 write(log_buf,*)
'Reading meta file for fld series'
726 write(log_buf,*)
'Name: ', trim(data%fld_series_fname)
728 write(log_buf,*)
'Start counter: ', data%meta_start_counter
730 write(log_buf,*)
'Nsamples: ', data%meta_nsamples
734 call mpi_bcast(data%fld_series_fname, 1024, mpi_character, 0, &
736 call mpi_bcast(data%meta_start_counter, 1, mpi_integer, 0, &
738 call mpi_bcast(data%meta_nsamples, 1, mpi_integer, 0, &
741 if (this%get_counter() .eq. -1)
then
742 call this%set_start_counter(data%meta_start_counter)
743 call this%set_counter(data%meta_start_counter)
749 write(suffix,
'(a,i5.5)')
'f', this%get_counter()
750 fname = trim(path) // trim(data%fld_series_fname) //
'.' // suffix
751 if (this%get_counter() .ge. &
752 data%meta_nsamples+data%meta_start_counter)
then
753 call neko_error(
'Trying to read more fld files than exist')
756 write(suffix,
'(a,i5.5)')
'f', this%get_counter()
759 call mpi_file_open(
neko_comm, trim(fname), &
760 mpi_mode_rdonly, mpi_info_null, fh, ierr)
762 if (ierr .ne. 0)
call neko_error(
"Could not read "//trim(fname))
764 call neko_log%message(
'Reading fld file ' // trim(fname))
766 call mpi_file_read_all(fh, hdr, 132, mpi_character, status, ierr)
770 read(hdr, 1) temp_str, fld_data_size, lx, ly, lz, glb_nelv, glb_nelv, &
771 time, counter, i, j, (rdcode(i), i = 1, 10)
7721
format(4a, 1x, i1, 1x,
i2, 1x,
i2, 1x,
i2, 1x, i10, 1x, i10, &
773 1x, e20.13, 1x, i9, 1x, i6, 1x, i6, 1x, 10a)
774 if (data%nelv .eq. 0)
then
776 data%nelv = dist%num_local()
777 data%offset_el = dist%start_idx()
782 data%glb_nelv = glb_nelv
783 data%t_counter = counter
796 this%dp_precision = .true.
798 this%dp_precision = .false.
800 if (this%dp_precision)
then
801 allocate(
tmp_dp(data%gdim*n))
803 allocate(
tmp_sp(data%gdim*n))
809 read_velocity = .false.
810 read_pressure = .false.
812 if (rdcode(i) .eq.
'X')
then
819 if (rdcode(i) .eq.
'U')
then
820 read_velocity = .true.
826 if (rdcode(i) .eq.
'P')
then
827 read_pressure = .true.
831 if (rdcode(i) .eq.
'T')
then
837 if (rdcode(i) .eq.
'S')
then
839 read(rdcode(i),*) n_scalars
840 n_scalars = n_scalars*10
843 n_scalars = n_scalars+j
845 if (
allocated(data%s))
then
846 if (data%n_scalars .ne. n_scalars)
then
847 do j = 1, data%n_scalars
848 call data%s(j)%free()
851 data%n_scalars = n_scalars
852 allocate(data%s(n_scalars))
853 do j = 1, data%n_scalars
854 call data%s(j)%init(n)
858 data%n_scalars = n_scalars
859 allocate(data%s(data%n_scalars))
860 do j = 1, data%n_scalars
861 call data%s(j)%init(n)
868 call mpi_file_read_at_all(fh, mpi_offset, temp, 1, &
869 mpi_real, status, ierr)
870 if (.not.
sabscmp(temp, test_pattern, epsilon(1.0_sp)))
then
871 call neko_error(
'Incorrect format for fld file, &
872 &test pattern does not match.')
877 if (
allocated(data%idx))
then
878 if (
size(data%idx) .ne. data%nelv)
then
880 allocate(data%idx(data%nelv))
883 allocate(data%idx(data%nelv))
886 byte_offset = mpi_offset + &
889 call mpi_file_read_at_all(fh, byte_offset, data%idx, data%nelv, &
890 mpi_integer, status, ierr)
892 mpi_offset = mpi_offset + &
896 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
897 (int(data%gdim*lxyz,
i8) * &
898 int(fld_data_size,
i8))
900 data%x, data%y, data%z, data)
901 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
902 (int(data%gdim *lxyz,
i8) * &
903 int(fld_data_size,
i8))
906 if (read_velocity)
then
907 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
908 (int(data%gdim*lxyz,
i8) * &
909 int(fld_data_size,
i8))
911 data%u, data%v, data%w, data)
912 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
913 (int(data%gdim *lxyz,
i8) * &
914 int(fld_data_size,
i8))
917 if (read_pressure)
then
918 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
920 int(fld_data_size,
i8))
922 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
924 int(fld_data_size,
i8))
928 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
930 int(fld_data_size,
i8))
932 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
934 int(fld_data_size,
i8))
938 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
940 int(fld_data_size,
i8))
942 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
944 int(fld_data_size,
i8))
947 call this%increment_counter()
952 call neko_error(
'Currently we only read into fld_file_data_t, &
953 &please use that data structure instead.')