67 class(*),
target,
intent(in) :: data
68 real(kind=
rp),
intent(in),
optional :: t
69 type(
mesh_t),
pointer :: msh
73 real(kind=
rp),
pointer :: dtlag(:)
74 real(kind=
rp),
pointer :: tlag(:)
75 integer :: ierr, info, drank, i, j
76 integer(hid_t) :: plist_id, file_id, dset_id, grp_id, attr_id
77 integer(hid_t) :: filespace, memspace
78 integer(hsize_t),
dimension(1) :: ddim, dcount, doffset
80 character(len=5) :: id_str
81 character(len=1024) :: fname
83 call hdf5_file_determine_data(
data, msh, dof, fp, fsp, dtlag, tlag)
86 write(id_str,
'(i5.5)') this%counter
87 fname = trim(this%fname(1:suffix_pos-1))//id_str//
'.h5'
90 call h5pcreate_f(h5p_file_access_f, plist_id, ierr)
91 info = mpi_info_null%mpi_val
92 call h5pset_fapl_mpio_f(plist_id,
neko_comm%mpi_val, info, ierr)
94 call h5fcreate_f(fname, h5f_acc_trunc_f, &
95 file_id, ierr, access_prp = plist_id)
97 call h5pcreate_f(h5p_dataset_xfer_f, plist_id, ierr)
98 call h5pset_dxpl_mpio_f(plist_id, h5fd_mpio_collective_f, ierr)
100 call h5screate_f(h5s_scalar_f, filespace, ierr)
104 call h5acreate_f(file_id,
"Time", h5t_native_double, filespace, attr_id, &
105 ierr, h5p_default_f, h5p_default_f)
106 call h5awrite_f(attr_id, h5t_native_double, t, ddim, ierr)
107 call h5aclose_f(attr_id, ierr)
110 if (
associated(dof))
then
111 call h5acreate_f(file_id,
"Lx", h5t_native_integer, filespace, attr_id, &
112 ierr, h5p_default_f, h5p_default_f)
113 call h5awrite_f(attr_id, h5t_native_integer, dof%Xh%lx, ddim, ierr)
114 call h5aclose_f(attr_id, ierr)
117 if (
associated(msh))
then
118 call h5gcreate_f(file_id,
"Mesh", grp_id, ierr, lcpl_id=h5p_default_f, &
119 gcpl_id=h5p_default_f, gapl_id=h5p_default_f)
121 call h5acreate_f(grp_id,
"Elements", h5t_native_integer, filespace, attr_id, &
122 ierr, h5p_default_f, h5p_default_f)
123 call h5awrite_f(attr_id, h5t_native_integer, msh%glb_nelv, ddim, ierr)
124 call h5aclose_f(attr_id, ierr)
126 call h5acreate_f(grp_id,
"Dimension", h5t_native_integer, filespace, attr_id, &
127 ierr, h5p_default_f, h5p_default_f)
128 call h5awrite_f(attr_id, h5t_native_integer, msh%gdim, ddim, ierr)
129 call h5aclose_f(attr_id, ierr)
131 call h5gclose_f(grp_id, ierr)
135 call h5sclose_f(filespace, ierr)
140 if (
associated(tlag) .and.
associated(dtlag))
then
141 call h5gcreate_f(file_id,
"Restart", grp_id, ierr, lcpl_id=h5p_default_f, &
142 gcpl_id=h5p_default_f, gapl_id=h5p_default_f)
153 call h5screate_simple_f(drank, ddim, filespace, ierr)
155 call h5dcreate_f(grp_id,
'tlag', h5t_native_double, &
156 filespace, dset_id, ierr)
157 call h5dget_space_f(dset_id, filespace, ierr)
158 call h5sselect_hyperslab_f (filespace, h5s_select_set_f, &
159 doffset, dcount, ierr)
160 call h5dwrite_f(dset_id, h5t_native_double, tlag, &
161 ddim, ierr, xfer_prp = plist_id)
162 call h5dclose_f(dset_id, ierr)
164 call h5dcreate_f(grp_id,
'dtlag', h5t_native_double, &
165 filespace, dset_id, ierr)
166 call h5dget_space_f(dset_id, filespace, ierr)
167 call h5sselect_hyperslab_f (filespace, h5s_select_set_f, &
168 doffset, dcount, ierr)
169 call h5dwrite_f(dset_id, h5t_native_double, dtlag, &
170 ddim, ierr, xfer_prp = plist_id)
171 call h5dclose_f(dset_id, ierr)
173 call h5sclose_f(filespace, ierr)
174 call h5gclose_f(grp_id, ierr)
182 if (
allocated(fp) .or.
allocated(fsp))
then
183 call h5gcreate_f(file_id,
"Fields", grp_id, ierr, lcpl_id=h5p_default_f, &
184 gcpl_id=h5p_default_f, gapl_id=h5p_default_f)
186 dcount(1) = int(dof%size(), 8)
187 doffset(1) = int(msh%offset_el, 8) * int((dof%Xh%lx**3),8)
188 ddim = int(dof%size(), 8)
190 call mpi_allreduce(mpi_in_place, ddim(1), 1, &
193 call h5screate_simple_f(drank, ddim, filespace, ierr)
194 call h5screate_simple_f(drank, dcount, memspace, ierr)
197 if (
allocated(fp))
then
199 call h5dcreate_f(grp_id, fp(i)%ptr%name, h5t_native_double, &
200 filespace, dset_id, ierr)
201 call h5dget_space_f(dset_id, filespace, ierr)
202 call h5sselect_hyperslab_f(filespace, h5s_select_set_f, &
203 doffset, dcount, ierr)
204 call h5dwrite_f(dset_id, h5t_native_double, &
205 fp(i)%ptr%x(1,1,1,1), &
206 ddim, ierr, file_space_id = filespace, &
207 mem_space_id = memspace, xfer_prp = plist_id)
208 call h5dclose_f(dset_id, ierr)
213 if (
allocated(fsp))
then
215 do j = 1, fsp(i)%ptr%size()
216 call h5dcreate_f(grp_id, fsp(i)%ptr%lf(j)%name, &
217 h5t_native_double, filespace, dset_id, ierr)
218 call h5dget_space_f(dset_id, filespace, ierr)
219 call h5sselect_hyperslab_f(filespace, h5s_select_set_f, &
220 doffset, dcount, ierr)
221 call h5dwrite_f(dset_id, h5t_native_double, &
222 fsp(i)%ptr%lf(j)%x(1,1,1,1), &
223 ddim, ierr, file_space_id = filespace, &
224 mem_space_id = memspace, xfer_prp = plist_id)
225 call h5dclose_f(dset_id, ierr)
231 call h5gclose_f(grp_id, ierr)
232 call h5sclose_f(filespace, ierr)
233 call h5sclose_f(memspace, ierr)
236 call h5pclose_f(plist_id, ierr)
237 call h5fclose_f(file_id, ierr)
241 this%counter = this%counter + 1
248 class(*),
target,
intent(inout) :: data
249 integer(hid_t) :: plist_id, file_id, dset_id, grp_id, attr_id
250 integer(hid_t) :: filespace, memspace
251 integer(hsize_t),
dimension(1) :: ddim, dcount, doffset
252 integer :: i,j, ierr, info, glb_nelv, gdim, lx, drank
253 type(
mesh_t),
pointer :: msh
257 real(kind=
rp),
pointer :: dtlag(:)
258 real(kind=
rp),
pointer :: tlag(:)
261 call hdf5_file_determine_data(
data, msh, dof, fp, fsp, dtlag, tlag)
264 call h5pcreate_f(h5p_file_access_f, plist_id, ierr)
265 info = mpi_info_null%mpi_val
266 call h5pset_fapl_mpio_f(plist_id,
neko_comm%mpi_val, info, ierr)
268 call h5fopen_f(trim(this%fname), h5f_acc_rdonly_f, &
269 file_id, ierr, access_prp = plist_id)
271 call h5pcreate_f(h5p_dataset_xfer_f, plist_id, ierr)
272 call h5pset_dxpl_mpio_f(plist_id, h5fd_mpio_collective_f, ierr)
275 call h5aopen_name_f(file_id,
'Time', attr_id, ierr)
276 call h5aread_f(attr_id, h5t_native_double, t, ddim, ierr)
277 call h5aclose_f(attr_id, ierr)
284 call h5aopen_name_f(file_id,
'Lx', attr_id, ierr)
285 call h5aread_f(attr_id, h5t_native_integer, lx, ddim, ierr)
286 call h5aclose_f(attr_id, ierr)
288 call h5gopen_f(file_id,
'Mesh', grp_id, ierr, gapl_id=h5p_default_f)
290 call h5aopen_name_f(grp_id,
'Elements', attr_id, ierr)
291 call h5aread_f(attr_id, h5t_native_integer, glb_nelv, ddim, ierr)
292 call h5aclose_f(attr_id, ierr)
294 call h5aopen_name_f(grp_id,
'Dimension', attr_id, ierr)
295 call h5aread_f(attr_id, h5t_native_integer, gdim, ddim, ierr)
296 call h5aclose_f(attr_id, ierr)
297 call h5gclose_f(grp_id, ierr)
300 if (
associated(tlag) .and.
associated(dtlag))
then
310 call h5gopen_f(file_id,
'Restart', grp_id, ierr, gapl_id=h5p_default_f)
311 call h5dopen_f(grp_id,
'tlag', dset_id, ierr)
312 call h5dget_space_f(dset_id, filespace, ierr)
313 call h5sselect_hyperslab_f (filespace, h5s_select_set_f, &
314 doffset, dcount, ierr)
315 call h5dread_f(dset_id, h5t_native_double, tlag, ddim, ierr, xfer_prp=plist_id)
316 call h5dclose_f(dset_id, ierr)
317 call h5sclose_f(filespace, ierr)
319 call h5dopen_f(grp_id,
'dtlag', dset_id, ierr)
320 call h5dget_space_f(dset_id, filespace, ierr)
321 call h5sselect_hyperslab_f (filespace, h5s_select_set_f, &
322 doffset, dcount, ierr)
323 call h5dread_f(dset_id, h5t_native_double, dtlag, ddim, ierr, xfer_prp=plist_id)
324 call h5dclose_f(dset_id, ierr)
325 call h5sclose_f(filespace, ierr)
327 call h5gclose_f(grp_id, ierr)
330 if (
allocated(fp) .or.
allocated(fsp))
then
331 call h5gopen_f(file_id,
'Fields', grp_id, ierr, gapl_id=h5p_default_f)
333 dcount(1) = int(dof%size(), 8)
334 doffset(1) = int(msh%offset_el, 8) * int((dof%Xh%lx**3),8)
335 ddim = int(dof%size(), 8)
338 dcount(1) = int(dof%size(), 8)
339 doffset(1) = int(msh%offset_el, 8) * int((dof%Xh%lx**3),8)
340 ddim = int(dof%size(), 8)
342 call mpi_allreduce(mpi_in_place, ddim(1), 1, &
345 call h5screate_simple_f(drank, dcount, memspace, ierr)
347 if (
allocated(fp))
then
349 call h5dopen_f(grp_id, fp(i)%ptr%name, dset_id, ierr)
350 call h5dget_space_f(dset_id, filespace, ierr)
351 call h5sselect_hyperslab_f (filespace, h5s_select_set_f, &
352 doffset, dcount, ierr)
353 call h5dread_f(dset_id, h5t_native_double, &
354 fp(i)%ptr%x(1,1,1,1), &
355 ddim, ierr, file_space_id = filespace, &
356 mem_space_id = memspace, xfer_prp=plist_id)
357 call h5dclose_f(dset_id, ierr)
358 call h5sclose_f(filespace, ierr)
362 if (
allocated(fsp))
then
364 do j = 1, fsp(i)%ptr%size()
365 call h5dopen_f(grp_id, fsp(i)%ptr%lf(j)%name, dset_id, ierr)
366 call h5dget_space_f(dset_id, filespace, ierr)
367 call h5sselect_hyperslab_f (filespace, h5s_select_set_f, &
368 doffset, dcount, ierr)
369 call h5dread_f(dset_id, h5t_native_double, &
370 fsp(i)%ptr%lf(j)%x(1,1,1,1), &
371 ddim, ierr, file_space_id = filespace, &
372 mem_space_id = memspace, xfer_prp=plist_id)
373 call h5dclose_f(dset_id, ierr)
374 call h5sclose_f(filespace, ierr)
378 call h5sclose_f(memspace, ierr)
379 call h5gclose_f(grp_id, ierr)
382 call h5pclose_f(plist_id, ierr)
383 call h5fclose_f(file_id, ierr)
390 subroutine hdf5_file_determine_data(data, msh, dof, fp, fsp, dtlag, tlag)
391 class(*),
target,
intent(in) :: data
392 type(
mesh_t),
pointer,
intent(inout) :: msh
393 type(
dofmap_t),
pointer,
intent(inout) :: dof
394 type(
field_ptr_t),
allocatable,
intent(inout) :: fp(:)
396 real(kind=
rp),
pointer,
intent(inout) :: dtlag(:)
397 real(kind=
rp),
pointer,
intent(inout) :: tlag(:)
398 integer :: i, j, fp_size, fp_cur, fsp_size, fsp_cur
405 allocate(fp(fp_size))
413 if (data%size() .gt. 0)
then
414 allocate(fp(data%size()))
419 do i = 1, data%size()
420 fp(i)%ptr => data%items(i)%ptr
431 if ( .not.
associated(data%u) .or. &
432 .not.
associated(data%v) .or. &
433 .not.
associated(data%w) .or. &
434 .not.
associated(data%p) )
then
440 if (
associated(data%s))
then
441 fp_size = fp_size + 1
444 if (
associated(data%abx1))
then
445 fp_size = fp_size + 6
448 if (
associated(data%abs1))
then
449 fp_size = fp_size + 2
452 allocate(fp(fp_size))
455 if (
associated(data%ulag))
then
456 fsp_size = fsp_size + 3
459 if (
associated(data%slag))
then
460 fsp_size = fsp_size + 1
463 if (fsp_size .gt. 0)
then
464 allocate(fsp(fsp_size))
477 if (
associated(data%s))
then
478 fp(fp_cur)%ptr => data%s
482 if (
associated(data%abx1))
then
483 fp(fp_cur)%ptr => data%abx1
484 fp(fp_cur+1)%ptr => data%abx2
485 fp(fp_cur+2)%ptr => data%aby1
486 fp(fp_cur+3)%ptr => data%aby2
487 fp(fp_cur+4)%ptr => data%abz1
488 fp(fp_cur+5)%ptr => data%abz2
492 if (
associated(data%abs1))
then
493 fp(fp_cur)%ptr => data%abs1
494 fp(fp_cur+1)%ptr => data%abs2
498 if (
associated(data%ulag))
then
499 fsp(fsp_cur)%ptr => data%ulag
500 fsp(fsp_cur+1)%ptr => data%vlag
501 fsp(fsp_cur+2)%ptr => data%wlag
502 fsp_cur = fsp_cur + 3
505 if (
associated(data%slag))
then
506 fsp(fsp_cur)%ptr => data%slag
507 fsp_cur = fsp_cur + 1
510 if (
associated(data%tlag))
then
519 end subroutine hdf5_file_determine_data
526 class(*),
target,
intent(in) :: data
527 real(kind=
rp),
intent(in),
optional :: t
528 call neko_error(
'Neko needs to be built with HDF5 support')
534 class(*),
target,
intent(inout) :: data
535 call neko_error(
'Neko needs to be built with HDF5 support')
type(mpi_comm) neko_comm
MPI communicator.
Defines a mapping of the degrees of freedom.
subroutine hdf5_file_read(this, data)
Read data in HDF5 format.
subroutine hdf5_file_write(this, data, t)
Write data in HDF5 format.
type(log_t), public neko_log
Global log stream.
integer, parameter, public rp
Global precision used in computations.
pure integer function, public filename_suffix_pos(fname)
Find position (in the string) of a filename's suffix.
field_ptr_t, To easily obtain a pointer to a field
field_list_t, To be able to group fields together
field_series_ptr_t, To easily obtain a pointer to a field series
Interface for HDF5 files.