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()
528 if (
allocated(tempo))
deallocate(tempo)
529 if (
allocated(scalar_fields))
deallocate(scalar_fields)
676 class(*),
target,
intent(inout) :: data
677 character(len= 132) :: hdr
678 integer :: ierr, suffix_pos, i, j
680 type(mpi_status) :: status
681 character(len= 1024) :: fname, base_fname, meta_fname, string, path
682 logical :: meta_file, read_mesh, read_velocity, read_pressure
684 character(len=6) :: suffix
685 integer (kind=MPI_OFFSET_KIND) :: mpi_offset, byte_offset
686 integer :: lx, ly, lz, glb_nelv, counter, lxyz
687 integer :: FLD_DATA_SIZE, n_scalars, n
689 real(kind=
rp) :: time
690 real(kind=
sp) :: temp
692 real(kind=
sp),
parameter :: test_pattern = 6.54321
693 character :: rdcode(10), temp_str(4)
694 character(len=LOG_SIZE) :: log_buf
700 inquire(
file = trim(meta_fname), exist = meta_file)
701 if (meta_file .and. data%meta_nsamples .eq. 0)
then
703 open(newunit = file_unit,
file = trim(meta_fname))
704 read(file_unit, fmt =
'(A)') string
705 read(string(14:), fmt =
'(A)') string
706 string = trim(string)
708 data%fld_series_fname = string(:scan(trim(string),
'%')-1)
709 data%fld_series_fname = adjustl(data%fld_series_fname)
710 data%fld_series_fname = trim(data%fld_series_fname)//
'0'
712 read(file_unit, fmt =
'(A)') string
713 read(string(scan(string,
':')+1:), *) data%meta_start_counter
714 read(file_unit, fmt =
'(A)') string
715 read(string(scan(string,
':')+1:), *) data%meta_nsamples
718 write(log_buf,*)
'Reading meta file for fld series'
720 write(log_buf,*)
'Name: ', trim(data%fld_series_fname)
722 write(log_buf,*)
'Start counter: ', data%meta_start_counter
724 write(log_buf,*)
'Nsamples: ', data%meta_nsamples
728 call mpi_bcast(data%fld_series_fname, 1024, mpi_character, 0, &
730 call mpi_bcast(data%meta_start_counter, 1, mpi_integer, 0, &
732 call mpi_bcast(data%meta_nsamples, 1, mpi_integer, 0, &
735 if (this%get_counter() .eq. -1)
then
736 call this%set_start_counter(data%meta_start_counter)
737 call this%set_counter(data%meta_start_counter)
743 write(suffix,
'(a,i5.5)')
'f', this%get_counter()
744 fname = trim(path) // trim(data%fld_series_fname) //
'.' // suffix
745 if (this%get_counter() .ge. &
746 data%meta_nsamples+data%meta_start_counter)
then
747 call neko_error(
'Trying to read more fld files than exist')
750 write(suffix,
'(a,i5.5)')
'f', this%get_counter()
753 call mpi_file_open(
neko_comm, trim(fname), &
754 mpi_mode_rdonly, mpi_info_null, fh, ierr)
756 if (ierr .ne. 0)
call neko_error(
"Could not read "//trim(fname))
758 call neko_log%message(
'Reading fld file ' // trim(fname))
760 call mpi_file_read_all(fh, hdr, 132, mpi_character, status, ierr)
764 read(hdr, 1) temp_str, fld_data_size, lx, ly, lz, glb_nelv, glb_nelv, &
765 time, counter, i, j, (rdcode(i), i = 1, 10)
7661
format(4a, 1x, i1, 1x,
i2, 1x,
i2, 1x,
i2, 1x, i10, 1x, i10, &
767 1x, e20.13, 1x, i9, 1x, i6, 1x, i6, 1x, 10a)
768 if (data%nelv .eq. 0)
then
770 data%nelv = dist%num_local()
771 data%offset_el = dist%start_idx()
776 data%glb_nelv = glb_nelv
777 data%t_counter = counter
790 this%dp_precision = .true.
792 this%dp_precision = .false.
794 if (this%dp_precision)
then
795 allocate(
tmp_dp(data%gdim*n))
797 allocate(
tmp_sp(data%gdim*n))
803 read_velocity = .false.
804 read_pressure = .false.
806 if (rdcode(i) .eq.
'X')
then
813 if (rdcode(i) .eq.
'U')
then
814 read_velocity = .true.
820 if (rdcode(i) .eq.
'P')
then
821 read_pressure = .true.
825 if (rdcode(i) .eq.
'T')
then
831 if (rdcode(i) .eq.
'S')
then
833 read(rdcode(i),*) n_scalars
834 n_scalars = n_scalars*10
837 n_scalars = n_scalars+j
839 if (
allocated(data%s))
then
840 if (data%n_scalars .ne. n_scalars)
then
841 do j = 1, data%n_scalars
842 call data%s(j)%free()
845 data%n_scalars = n_scalars
846 allocate(data%s(n_scalars))
847 do j = 1, data%n_scalars
848 call data%s(j)%init(n)
852 data%n_scalars = n_scalars
853 allocate(data%s(data%n_scalars))
854 do j = 1, data%n_scalars
855 call data%s(j)%init(n)
862 call mpi_file_read_at_all(fh, mpi_offset, temp, 1, &
863 mpi_real, status, ierr)
864 if (.not.
sabscmp(temp, test_pattern, epsilon(1.0_sp)))
then
865 call neko_error(
'Incorrect format for fld file, &
866 &test pattern does not match.')
871 if (
allocated(data%idx))
then
872 if (
size(data%idx) .ne. data%nelv)
then
874 allocate(data%idx(data%nelv))
877 allocate(data%idx(data%nelv))
880 byte_offset = mpi_offset + &
883 call mpi_file_read_at_all(fh, byte_offset, data%idx, data%nelv, &
884 mpi_integer, status, ierr)
886 mpi_offset = mpi_offset + &
890 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
891 (int(data%gdim*lxyz,
i8) * &
892 int(fld_data_size,
i8))
894 data%x, data%y, data%z, data)
895 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
896 (int(data%gdim *lxyz,
i8) * &
897 int(fld_data_size,
i8))
900 if (read_velocity)
then
901 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
902 (int(data%gdim*lxyz,
i8) * &
903 int(fld_data_size,
i8))
905 data%u, data%v, data%w, data)
906 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
907 (int(data%gdim *lxyz,
i8) * &
908 int(fld_data_size,
i8))
911 if (read_pressure)
then
912 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
914 int(fld_data_size,
i8))
916 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
918 int(fld_data_size,
i8))
922 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
924 int(fld_data_size,
i8))
926 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
928 int(fld_data_size,
i8))
932 byte_offset = mpi_offset + int(data%offset_el,
i8) * &
934 int(fld_data_size,
i8))
936 mpi_offset = mpi_offset + int(data%glb_nelv,
i8) * &
938 int(fld_data_size,
i8))
941 call this%increment_counter()
946 call neko_error(
'Currently we only read into fld_file_data_t, &
947 &please use that data structure instead.')