diff --git a/src/CPFEM2.f90 b/src/CPFEM2.f90 index 89e65f5fd..ed356d5b6 100644 --- a/src/CPFEM2.f90 +++ b/src/CPFEM2.f90 @@ -243,12 +243,20 @@ subroutine CPFEM_age() use IO, only: & IO_write_jobRealFile, & 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 integer(pInt) :: i, k, l, m, ph, homog, mySource character(len=32) :: rankStr + integer(HID_T) :: fileHandle if (iand(debug_level(debug_CPFEM), debug_levelBasic) /= 0_pInt) & write(6,'(a)') '<< CPFEM >> aging states' @@ -282,6 +290,11 @@ if (restartWrite) then 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)) write (777,rec=1) material_phase; close (777) diff --git a/src/HDF5_utilities.f90 b/src/HDF5_utilities.f90 index e2b0c2450..7cd02e46e 100644 --- a/src/HDF5_utilities.f90 +++ b/src/HDF5_utilities.f90 @@ -27,7 +27,10 @@ module HDF5_Utilities HDF5_writeScalarDataset, & HDF5_writeTensorDataset, & HDF5_closeJobFile, & - HDF5_removeLink + HDF5_removeLink, & + HDF5_createFile, & + HDF5_closeFile, & + HDF5_addGroup2 contains subroutine HDF5_Utilities_init @@ -93,6 +96,41 @@ 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 +#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 !-------------------------------------------------------------------------------------------------- @@ -104,11 +142,28 @@ subroutine HDF5_closeJobFile() call HDF5_removeLink('current') call h5fclose_f(resultsFile,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 +!-------------------------------------------------------------------------------------------------- +!> @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 !-------------------------------------------------------------------------------------------------- @@ -125,6 +180,21 @@ integer(HID_T) function HDF5_addGroup(path) 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 @@ -1214,7 +1284,6 @@ subroutine HDF5_addVectorDataset(group,nnodes,vectorSize,label,SIunit) end subroutine HDF5_addVectorDataset - !-------------------------------------------------------------------------------------------------- !> @brief creates a new scalar dataset in the given group location !--------------------------------------------------------------------------------------------------