creating hdf5 file to contain restart information

first quick and dirty implementation to get started. needs polishing and
renaming
This commit is contained in:
Martin Diehl 2018-09-20 19:42:58 +02:00
parent af3081a6cd
commit bd9a02bfe2
2 changed files with 86 additions and 4 deletions

View File

@ -243,12 +243,20 @@ subroutine CPFEM_age()
use IO, only: & use IO, only: &
IO_write_jobRealFile, & IO_write_jobRealFile, &
IO_warning IO_warning
use DAMASK_interface use HDF5_utilities, only: &
HDF5_createFile, &
HDF5_closeFile, &
HDF5_closeGroup, &
HDF5_addGroup2
use HDF5
use DAMASK_interface, only: &
getSolverJobName
implicit none implicit none
integer(pInt) :: i, k, l, m, ph, homog, mySource integer(pInt) :: i, k, l, m, ph, homog, mySource
character(len=32) :: rankStr character(len=32) :: rankStr
integer(HID_T) :: fileHandle
if (iand(debug_level(debug_CPFEM), debug_levelBasic) /= 0_pInt) & if (iand(debug_level(debug_CPFEM), debug_levelBasic) /= 0_pInt) &
write(6,'(a)') '<< CPFEM >> aging states' write(6,'(a)') '<< CPFEM >> aging states'
@ -282,6 +290,11 @@ if (restartWrite) then
write(rankStr,'(a1,i0)')'_',worldrank write(rankStr,'(a1,i0)')'_',worldrank
fileHandle = HDF5_createFile(trim(getSolverJobName())//trim(rankStr)//'.hdf5_restart')
call HDF5_closeGroup(HDF5_addGroup2(fileHandle,'HelloWorld'))
call HDF5_closeFile(fileHandle)
call IO_write_jobRealFile(777,'recordedPhase'//trim(rankStr),size(material_phase)) call IO_write_jobRealFile(777,'recordedPhase'//trim(rankStr),size(material_phase))
write (777,rec=1) material_phase; close (777) write (777,rec=1) material_phase; close (777)

View File

@ -27,7 +27,10 @@ module HDF5_Utilities
HDF5_writeScalarDataset, & HDF5_writeScalarDataset, &
HDF5_writeTensorDataset, & HDF5_writeTensorDataset, &
HDF5_closeJobFile, & HDF5_closeJobFile, &
HDF5_removeLink HDF5_removeLink, &
HDF5_createFile, &
HDF5_closeFile, &
HDF5_addGroup2
contains contains
subroutine HDF5_Utilities_init subroutine HDF5_Utilities_init
@ -93,6 +96,41 @@ subroutine HDF5_createJobFile
end subroutine HDF5_createJobFile end subroutine HDF5_createJobFile
!--------------------------------------------------------------------------------------------------
!> @brief creates and initializes HDF5 output files
!--------------------------------------------------------------------------------------------------
integer(HID_T) function HDF5_createFile(path)
use hdf5
use DAMASK_interface, only: &
getSolverJobName
implicit none
integer :: hdferr
integer(SIZE_T) :: typeSize
character(len=*), intent(in) :: path
#ifdef PETSc
#include <petsc/finclude/petscsys.h>
#endif
call h5open_f(hdferr) !############################################################ DANGEROUS
#ifdef PETSC
call h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, hdferr)
if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_Utilities_init: h5pcreate_f')
call h5pset_fapl_mpio_f(plist_id, PETSC_COMM_WORLD, MPI_INFO_NULL, hdferr)
if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_Utilities_init: h5pset_fapl_mpio_f')
#endif
!--------------------------------------------------------------------------------------------------
! open file
!call h5fcreate_f(path,H5F_ACC_TRUNC_F,resultsFile,hdferr)
call h5fcreate_f(path,H5F_ACC_TRUNC_F,HDF5_createFile,hdferr,access_prp = plist_id)
if (hdferr < 0) call IO_error(100_pInt,ext_msg=path)
!call HDF5_addStringAttribute(HDF5_createFile,'createdBy',DAMASKVERSION)
call h5pclose_f(plist_id, hdferr) !neu
end function HDF5_createFile
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
!> @brief creates and initializes HDF5 output file !> @brief creates and initializes HDF5 output file
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
@ -104,11 +142,28 @@ subroutine HDF5_closeJobFile()
call HDF5_removeLink('current') call HDF5_removeLink('current')
call h5fclose_f(resultsFile,hdferr) call h5fclose_f(resultsFile,hdferr)
if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_closeJobFile: h5fclose_f',el=hdferr) if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_closeJobFile: h5fclose_f',el=hdferr)
CALL h5close_f(hdferr) call h5close_f(hdferr)
end subroutine HDF5_closeJobFile end subroutine HDF5_closeJobFile
!--------------------------------------------------------------------------------------------------
!> @brief creates and initializes HDF5 output file
!--------------------------------------------------------------------------------------------------
subroutine HDF5_closeFile(fileHandle)
use hdf5
implicit none
integer :: hdferr
integer(HID_T), intent(in) :: fileHandle
call h5fclose_f(fileHandle,hdferr)
if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_closeFile: h5fclose_f',el=hdferr)
call h5close_f(hdferr)!############################################################ DANGEROUS
if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_closeFile: h5close_f',el=hdferr)
end subroutine HDF5_closeFile
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
!> @brief adds a new group to the results file, or if loc is present at the given location !> @brief adds a new group to the results file, or if loc is present at the given location
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
@ -125,6 +180,21 @@ integer(HID_T) function HDF5_addGroup(path)
end function HDF5_addGroup end function HDF5_addGroup
!--------------------------------------------------------------------------------------------------
!> @brief adds a new group to the results file, or if loc is present at the given location
!--------------------------------------------------------------------------------------------------
integer(HID_T) function HDF5_addGroup2(fileHandle,path)
use hdf5
implicit none
character(len=*), intent(in) :: path
integer(HID_T), intent(in) :: fileHandle
integer :: hdferr
call h5gcreate_f(fileHandle, trim(path), HDF5_addGroup2, hdferr)
if (hdferr < 0) call IO_error(1_pInt,ext_msg = 'HDF5_addGroup2: h5gcreate_f ('//trim(path)//')')
end function HDF5_addGroup2
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
!> @brief adds a new group to the results file !> @brief adds a new group to the results file
@ -1214,7 +1284,6 @@ subroutine HDF5_addVectorDataset(group,nnodes,vectorSize,label,SIunit)
end subroutine HDF5_addVectorDataset end subroutine HDF5_addVectorDataset
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
!> @brief creates a new scalar dataset in the given group location !> @brief creates a new scalar dataset in the given group location
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------