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)
221 tem%ptr => data%items(5)%ptr%x(:,1,1,1)
222 n_scalar_fields = data%size() - 5
223 allocate(scalar_fields(n_scalar_fields))
224 do i = 1, n_scalar_fields
225 scalar_fields(i)%ptr => data%items(i+5)%ptr%x(:,1,1,1)
227 write_pressure = .true.
228 write_velocity = .true.
229 write_temperature = .true.
231 call neko_error(
'This many fields not supported yet, fld_file')
238 if (
associated(dof))
then
239 x%ptr => dof%x(:,1,1,1)
240 y%ptr => dof%y(:,1,1,1)
241 z%ptr => dof%z(:,1,1,1)
246 if (
associated(msh))
then
248 glb_nelv = msh%glb_nelv
249 offset_el = msh%offset_el
252 allocate(idx(msh%nelv))
254 idx(i) = msh%elements(i)%e%id()
258 if (
associated(xh))
then
267 if (this%dp_precision)
then
272 if (this%dp_precision)
then
283 call this%increment_counter()
284 write_mesh = (this%get_counter() .eq. this%get_start_counter())
285 call mpi_allreduce(mpi_in_place, write_mesh, 1, &
287 call mpi_allreduce(mpi_in_place, write_velocity, 1, &
289 call mpi_allreduce(mpi_in_place, write_pressure, 1, &
291 call mpi_allreduce(mpi_in_place, write_temperature, 1, &
293 call mpi_allreduce(mpi_in_place, n_scalar_fields, 1, &
304 if (write_velocity)
then
308 if (write_pressure)
then
312 if (write_temperature)
then
316 if (n_scalar_fields .gt. 0 )
then
319 write(rdcode(i),
'(i1)') (n_scalar_fields)/10
321 write(rdcode(i),
'(i1)') (n_scalar_fields) - 10*((n_scalar_fields)/10)
326 write(hdr, 1) fld_data_size, lx, ly, lz, glb_nelv, glb_nelv,&
327 time, this%get_counter(), 1, 1, (rdcode(i), i = 1, 10)
3281
format(
'#std', 1x, i1, 1x,
i2, 1x,
i2, 1x,
i2, 1x, i10, 1x, i10, &
329 1x, e20.13, 1x, i9, 1x, i6, 1x, i6, 1x, 10a)
332 fname = this%get_fld_fname()
334 call mpi_file_open(
neko_comm, trim(fname), &
335 mpi_mode_wronly + mpi_mode_create, mpi_info_null, fh, &
338 call mpi_file_write_all(fh, hdr, 132, mpi_character, status, ierr)
341 call mpi_file_write_all(fh, test_pattern, 1, mpi_real, status, ierr)
344 byte_offset = mpi_offset + &
346 call mpi_file_write_at_all(fh, byte_offset, idx, nelv, &
347 mpi_integer, status, ierr)
352 byte_offset = mpi_offset + int(offset_el,
i8) * &
353 (int(gdim*lxyz,
i8) * &
354 int(fld_data_size,
i8))
356 x%ptr, y%ptr, z%ptr, &
358 mpi_offset = mpi_offset + int(glb_nelv,
i8) * &
359 (int(gdim *lxyz,
i8) * &
360 int(fld_data_size,
i8))
362 if (write_velocity)
then
363 byte_offset = mpi_offset + int(offset_el,
i8) * &
364 (int(gdim * (lxyz),
i8) * int(fld_data_size,
i8))
366 u%ptr, v%ptr, w%ptr, n, gdim, lxyz, nelv)
368 mpi_offset = mpi_offset + int(glb_nelv,
i8) * &
369 (int(gdim * (lxyz),
i8) * &
370 int(fld_data_size,
i8))
374 if (write_pressure)
then
375 byte_offset = mpi_offset + int(offset_el,
i8) * &
376 (int((lxyz),
i8) * int(fld_data_size,
i8))
378 mpi_offset = mpi_offset + int(glb_nelv,
i8) * &
379 (int((lxyz),
i8) * int(fld_data_size,
i8))
382 if (write_temperature)
then
383 byte_offset = mpi_offset + int(offset_el,
i8) * &
385 int(fld_data_size,
i8))
387 mpi_offset = mpi_offset + int(glb_nelv,
i8) * &
389 int(fld_data_size,
i8))
392 temp_offset = mpi_offset
394 do i = 1, n_scalar_fields
398 mpi_offset = int(temp_offset,
i8) + int(1_i8*glb_nelv,
i8) * &
399 (int(lxyz,
i8) * int(fld_data_size,
i8))
401 byte_offset = int(mpi_offset,
i8) + int(offset_el,
i8) * &
403 int(fld_data_size,
i8))
405 mpi_offset = int(mpi_offset,
i8) + int(glb_nelv,
i8) * &
407 int(fld_data_size,
i8))
410 if (gdim .eq. 3)
then
417 byte_offset = int(mpi_offset,
i8) + &
418 int(offset_el,
i8) * &
423 x%ptr, y%ptr, z%ptr, gdim, lxyz, nelv)
424 mpi_offset = int(mpi_offset,
i8) + &
425 int(glb_nelv,
i8) * &
431 if (write_velocity)
then
432 byte_offset = int(mpi_offset,
i8) + &
433 int(offset_el,
i8) * &
438 u%ptr, v%ptr, w%ptr, gdim, lxyz, nelv)
439 mpi_offset = int(mpi_offset,
i8) + &
440 int(glb_nelv,
i8) * &
447 if (write_pressure)
then
448 byte_offset = int(mpi_offset,
i8) + &
449 int(offset_el,
i8) * &
454 mpi_offset = int(mpi_offset,
i8) + &
455 int(glb_nelv,
i8) * &
461 if (write_temperature)
then
462 byte_offset = int(mpi_offset,
i8) + &
463 int(offset_el,
i8) * &
468 mpi_offset = int(mpi_offset,
i8) + &
469 int(glb_nelv,
i8) * &
477 temp_offset = mpi_offset
479 do i = 1, n_scalar_fields
483 mpi_offset = int(temp_offset,
i8) + &
484 int(1_i8*glb_nelv,
i8) * &
489 byte_offset = int(mpi_offset,
i8) + &
490 int(offset_el,
i8) * &
494 scalar_fields(i)%ptr, lxyz, nelv)
495 mpi_offset = int(mpi_offset,
i8) + &
496 int(glb_nelv,
i8) * &
503 call mpi_file_sync(fh, ierr)
504 call mpi_file_close(fh, ierr)
509 open(newunit = file_unit, &
510 file = this%get_meta_fname(), status =
'replace')
517 write(file_unit, fmt =
'(A,A,A)')
'filetemplate: ', &
518 trim(name),
'%01d.f%05d'
519 write(file_unit, fmt =
'(A,i5)')
'firsttimestep: ', &
520 this%get_start_counter()
521 write(file_unit, fmt =
'(A,i5)')
'numtimesteps: ', &
522 (this%get_counter() + 1) - this%get_start_counter()
673 class(*),
target,
intent(inout) :: data
674 character(len= 132) :: hdr
675 integer :: ierr, suffix_pos, i, j
677 type(mpi_status) :: status
678 character(len= 1024) :: fname, base_fname, meta_fname, string, path
679 logical :: meta_file, read_mesh, read_velocity, read_pressure
681 character(len=6) :: suffix
682 integer (kind=MPI_OFFSET_KIND) :: mpi_offset, byte_offset
683 integer :: lx, ly, lz, glb_nelv, counter, lxyz
684 integer :: FLD_DATA_SIZE, n_scalars, n
686 real(kind=
rp) :: time
687 real(kind=
sp) :: temp
689 real(kind=
sp),
parameter :: test_pattern = 6.54321
690 character :: rdcode(10), temp_str(4)
691 character(len=LOG_SIZE) :: log_buf
697 inquire(
file = trim(meta_fname), exist = meta_file)
698 if (meta_file .and. data%meta_nsamples .eq. 0)
then
700 open(newunit = file_unit,
file = trim(meta_fname))
701 read(file_unit, fmt =
'(A)') string
702 read(string(14:), fmt =
'(A)') string
703 string = trim(string)
705 data%fld_series_fname = string(:scan(trim(string),
'%')-1)
706 data%fld_series_fname = adjustl(data%fld_series_fname)
707 data%fld_series_fname = trim(data%fld_series_fname)//
'0'
709 read(file_unit, fmt =
'(A)') string
710 read(string(scan(string,
':')+1:), *) data%meta_start_counter
711 read(file_unit, fmt =
'(A)') string
712 read(string(scan(string,
':')+1:), *) data%meta_nsamples
715 write(log_buf,*)
'Reading meta file for fld series'
717 write(log_buf,*)
'Name: ', trim(data%fld_series_fname)
719 write(log_buf,*)
'Start counter: ', data%meta_start_counter
721 write(log_buf,*)
'Nsamples: ', data%meta_nsamples
725 call mpi_bcast(data%fld_series_fname, 1024, mpi_character, 0, &
727 call mpi_bcast(data%meta_start_counter, 1, mpi_integer, 0, &
729 call mpi_bcast(data%meta_nsamples, 1, mpi_integer, 0, &
732 if (this%get_counter() .eq. -1)
then
733 call this%set_start_counter(data%meta_start_counter)
734 call this%set_counter(data%meta_start_counter)
740 write(suffix,
'(a,i5.5)')
'f', this%get_counter()
741 fname = trim(path) // trim(data%fld_series_fname) //
'.' // suffix
742 if (this%get_counter() .ge. &
743 data%meta_nsamples+data%meta_start_counter)
then
744 call neko_error(
'Trying to read more fld files than exist')
747 write(suffix,
'(a,i5.5)')
'f', this%get_counter()
750 call mpi_file_open(
neko_comm, trim(fname), &
751 mpi_mode_rdonly, mpi_info_null, fh, ierr)
753 if (ierr .ne. 0)
call neko_error(
"Could not read "//trim(fname))
755 call neko_log%message(
'Reading fld file ' // trim(fname))
757 call mpi_file_read_all(fh, hdr, 132, mpi_character, status, ierr)
761 read(hdr, 1) temp_str, fld_data_size, lx, ly, lz, glb_nelv, glb_nelv, &
762 time, counter, i, j, (rdcode(i), i = 1, 10)
7631
format(4a, 1x, i1, 1x,
i2, 1x,
i2, 1x,
i2, 1x, i10, 1x, i10, &
764 1x, e20.13, 1x, i9, 1x, i6, 1x, i6, 1x, 10a)
765 if (data%nelv .eq. 0)
then
767 data%nelv = dist%num_local()
768 data%offset_el = dist%start_idx()
773 data%glb_nelv = glb_nelv
774 data%t_counter = counter
787 this%dp_precision = .true.
789 this%dp_precision = .false.
791 if (this%dp_precision)
then
792 allocate(
tmp_dp(data%gdim*n))
794 allocate(
tmp_sp(data%gdim*n))
800 read_velocity = .false.
801 read_pressure = .false.
803 if (rdcode(i) .eq.
'X')
then
810 if (rdcode(i) .eq.
'U')
then
811 read_velocity = .true.
817 if (rdcode(i) .eq.
'P')
then
818 read_pressure = .true.
822 if (rdcode(i) .eq.
'T')
then
828 if (rdcode(i) .eq.
'S')
then
830 read(rdcode(i),*) n_scalars
831 n_scalars = n_scalars*10
834 n_scalars = n_scalars+j
836 if (
allocated(data%s))
then
837 if (data%n_scalars .ne. n_scalars)
then
838 do j = 1, data%n_scalars
839 call data%s(j)%free()
842 data%n_scalars = n_scalars
843 allocate(data%s(n_scalars))
844 do j = 1, data%n_scalars
845 call data%s(j)%init(n)
849 data%n_scalars = n_scalars
850 allocate(data%s(data%n_scalars))
851 do j = 1, data%n_scalars
852 call data%s(j)%init(n)
859 call mpi_file_read_at_all(fh, mpi_offset, temp, 1, &
860 mpi_real, status, ierr)
861 if (.not.
sabscmp(temp, test_pattern, epsilon(1.0_sp)))
then
862 call neko_error(
'Incorrect format for fld file, &
863 &test pattern does not match.')
868 if (
allocated(data%idx))
then
869 if (
size(data%idx) .ne. data%nelv)
then
871 allocate(data%idx(data%nelv))
874 allocate(data%idx(data%nelv))
877 byte_offset = mpi_offset + &
880 call mpi_file_read_at_all(fh, byte_offset, data%idx, data%nelv, &
881 mpi_integer, status, ierr)
883 mpi_offset = mpi_offset + &
887 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
888 (int(data%gdim*lxyz,
i8) * &
889 int(fld_data_size,
i8))
891 data%x, data%y, data%z, data)
892 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
893 (int(data%gdim *lxyz,
i8) * &
894 int(fld_data_size,
i8))
897 if (read_velocity)
then
898 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
899 (int(data%gdim*lxyz,
i8) * &
900 int(fld_data_size,
i8))
902 data%u, data%v, data%w, data)
903 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
904 (int(data%gdim *lxyz,
i8) * &
905 int(fld_data_size,
i8))
908 if (read_pressure)
then
909 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
911 int(fld_data_size,
i8))
913 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
915 int(fld_data_size,
i8))
919 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
921 int(fld_data_size,
i8))
923 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
925 int(fld_data_size,
i8))
929 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
931 int(fld_data_size,
i8))
933 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
935 int(fld_data_size,
i8))
938 call this%increment_counter()
943 call neko_error(
'Currently we only read into fld_file_data_t, &
944 &please use that data structure instead.')