avoid errors by consistently closing objects

general bugfixes, works now
This commit is contained in:
Martin Diehl 2018-10-09 16:12:32 +02:00
parent 2064ed80fd
commit d81c9f744e
2 changed files with 52 additions and 153 deletions

View File

@ -158,9 +158,7 @@ subroutine CPFEM_init
fileReadID = HDF5_openFile(trim(getSolverJobName())//trim(rankStr)//'.hdf5') fileReadID = HDF5_openFile(trim(getSolverJobName())//trim(rankStr)//'.hdf5')
call HDF5_read(material_phase, fileReadID,'recordedPhase') call HDF5_read(material_phase, fileReadID,'recordedPhase')
!write(6,*) material_phase
call HDF5_read(crystallite_F0, fileReadID,'convergedF') call HDF5_read(crystallite_F0, fileReadID,'convergedF')
!write(6,*) crystallite_F0
call HDF5_read(crystallite_Fp0, fileReadID,'convergedFp') call HDF5_read(crystallite_Fp0, fileReadID,'convergedFp')
call HDF5_read(crystallite_Fi0, fileReadID,'convergedFi') call HDF5_read(crystallite_Fi0, fileReadID,'convergedFi')
call HDF5_read(crystallite_Lp0, fileReadID,'convergedLp') call HDF5_read(crystallite_Lp0, fileReadID,'convergedLp')
@ -169,65 +167,15 @@ subroutine CPFEM_init
call HDF5_read(crystallite_Tstar0_v,fileReadID,'convergedTstar') call HDF5_read(crystallite_Tstar0_v,fileReadID,'convergedTstar')
groupPlasticID = HDF5_openGroup2(fileReadID,'PlasticPhases') groupPlasticID = HDF5_openGroup2(fileReadID,'PlasticPhases')
write(6,*) groupPlasticID
do ph = 1_pInt,size(phase_plasticity) do ph = 1_pInt,size(phase_plasticity)
call HDF5_read(plasticState(ph)%state0,groupPlasticID,'convergedStateConst') call HDF5_read(plasticState(ph)%state0,groupPlasticID,'convergedStateConst')
write(6,*) plasticState(ph)%state0
enddo enddo
groupHomogID = HDF5_openGroup2(fileReadID,'material_Nhomogenization') groupHomogID = HDF5_openGroup2(fileReadID,'material_Nhomogenization')
write(6,*) groupHomogID
do homog = 1_pInt, material_Nhomogenization do homog = 1_pInt, material_Nhomogenization
call HDF5_read(homogState(homog)%state0, groupHomogID,'convergedStateHomog') call HDF5_read(homogState(homog)%state0, groupHomogID,'convergedStateHomog')
write(6,*) homogState(homog)%state0
enddo enddo
! call IO_read_intFile(777,'recordedPhase'//trim(rankStr),modelName,size(material_phase))
! read (777,rec=1) material_phase; close (777)
! call IO_read_realFile(777,'convergedF'//trim(rankStr),modelName,size(crystallite_F0))
! read (777,rec=1) crystallite_F0; close (777)
! call IO_read_realFile(777,'convergedFp'//trim(rankStr),modelName,size(crystallite_Fp0))
! read (777,rec=1) crystallite_Fp0; close (777)
! call IO_read_realFile(777,'convergedFi'//trim(rankStr),modelName,size(crystallite_Fi0))
! read (777,rec=1) crystallite_Fi0; close (777)
! call IO_read_realFile(777,'convergedLp'//trim(rankStr),modelName,size(crystallite_Lp0))
! read (777,rec=1) crystallite_Lp0; close (777)
! call IO_read_realFile(777,'convergedLi'//trim(rankStr),modelName,size(crystallite_Li0))
! read (777,rec=1) crystallite_Li0; close (777)
! call IO_read_realFile(777,'convergeddPdF'//trim(rankStr),modelName,size(crystallite_dPdF0))
! read (777,rec=1) crystallite_dPdF0; close (777)
! call IO_read_realFile(777,'convergedTstar'//trim(rankStr),modelName,size(crystallite_Tstar0_v))
! read (777,rec=1) crystallite_Tstar0_v; close (777)
! call IO_read_realFile(777,'convergedStateConst'//trim(rankStr),modelName)
! m = 0_pInt
! readPlasticityInstances: do ph = 1_pInt, size(phase_plasticity)
! do k = 1_pInt, plasticState(ph)%sizeState
! do l = 1, size(plasticState(ph)%state0(1,:))
! m = m+1_pInt
! read(777,rec=m) plasticState(ph)%state0(k,l)
! enddo; enddo
! enddo readPlasticityInstances
! close (777)
! call IO_read_realFile(777,'convergedStateHomog'//trim(rankStr),modelName)
! m = 0_pInt
! readHomogInstances: do homog = 1_pInt, material_Nhomogenization
! do k = 1_pInt, homogState(homog)%sizeState
! do l = 1, size(homogState(homog)%state0(1,:))
! m = m+1_pInt
! read(777,rec=m) homogState(homog)%state0(k,l)
! enddo; enddo
! enddo readHomogInstances
! close (777)
restartRead = .false. restartRead = .false.
endif endif
@ -283,13 +231,11 @@ subroutine CPFEM_age()
IO_write_jobRealFile, & IO_write_jobRealFile, &
IO_warning IO_warning
use HDF5_utilities, only: & use HDF5_utilities, only: &
HDF5_createFile, & HDF5_openFile, &
HDF5_closeFile, & HDF5_closeFile, &
HDF5_closeGroup, & HDF5_closeGroup, &
HDF5_addGroup2, & HDF5_addGroup2, &
!HDF5_writeScalarDataset3, &
HDF5_write HDF5_write
!HDF5_addScalarDataset2
use hdf5 use hdf5
use DAMASK_interface, only: & use DAMASK_interface, only: &
getSolverJobName getSolverJobName
@ -302,8 +248,6 @@ subroutine CPFEM_age()
integer :: hdferr integer :: hdferr
integer(HSIZE_T) :: hdfsize integer(HSIZE_T) :: hdfsize
real(pReal), dimension(4,1,1,3,2) :: testData = reshape(real([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, &
16,17,18,19,20,21,22,23,24],pReal),[4,1,1,3,2])
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'
@ -333,11 +277,10 @@ enddo
if (restartWrite) then if (restartWrite) then
if (iand(debug_level(debug_CPFEM), debug_levelBasic) /= 0_pInt) & if (iand(debug_level(debug_CPFEM), debug_levelBasic) /= 0_pInt) &
write(6,'(a)') '<< CPFEM >> writing state variables of last converged step to binary files' write(6,'(a)') '<< CPFEM >> writing restart variables of last converged step to hdf5 file'
write(rankStr,'(a1,i0)')'_',worldrank write(rankStr,'(a1,i0)')'_',worldrank
fileHandle = HDF5_createFile(trim(getSolverJobName())//trim(rankStr)//'.hdf5') fileHandle = HDF5_openFile(trim(getSolverJobName())//trim(rankStr)//'.hdf5','w')
call HDF5_write(material_phase, fileHandle,'recordedPhase') call HDF5_write(material_phase, fileHandle,'recordedPhase')
call HDF5_write(crystallite_F0, fileHandle,'convergedF') call HDF5_write(crystallite_F0, fileHandle,'convergedF')
@ -352,60 +295,16 @@ if (restartWrite) then
do ph = 1_pInt,size(phase_plasticity) do ph = 1_pInt,size(phase_plasticity)
call HDF5_write(plasticState(ph)%state0,groupPlastic,'convergedStateConst') call HDF5_write(plasticState(ph)%state0,groupPlastic,'convergedStateConst')
enddo enddo
call HDF5_closeGroup(groupPlastic)
groupHomog = HDF5_addGroup2(fileHandle,'material_Nhomogenization') groupHomog = HDF5_addGroup2(fileHandle,'material_Nhomogenization')
do homog = 1_pInt, material_Nhomogenization do homog = 1_pInt, material_Nhomogenization
call HDF5_write(homogState(homog)%state0,groupHomog,'convergedStateHomog') call HDF5_write(homogState(homog)%state0,groupHomog,'convergedStateHomog')
enddo enddo
call HDF5_closeGroup(groupHomog)
call HDF5_closeFile(fileHandle) call HDF5_closeFile(fileHandle)
restartWrite = .false.
! call IO_write_jobRealFile(777,'recordedPhase'//trim(rankStr),size(material_phase))
! write (777,rec=1) material_phase; close (777)
! call IO_write_jobRealFile(777,'convergedF'//trim(rankStr),size(crystallite_F0))
! write (777,rec=1) crystallite_F0; close (777)
! call IO_write_jobRealFile(777,'convergedFp'//trim(rankStr),size(crystallite_Fp0))
! write (777,rec=1) crystallite_Fp0; close (777)
! call IO_write_jobRealFile(777,'convergedFi'//trim(rankStr),size(crystallite_Fi0))
! write (777,rec=1) crystallite_Fi0; close (777)
! call IO_write_jobRealFile(777,'convergedLp'//trim(rankStr),size(crystallite_Lp0))
! write (777,rec=1) crystallite_Lp0; close (777)
! call IO_write_jobRealFile(777,'convergedLi'//trim(rankStr),size(crystallite_Li0))
! write (777,rec=1) crystallite_Li0; close (777)
! call IO_write_jobRealFile(777,'convergeddPdF'//trim(rankStr),size(crystallite_dPdF0))
! write (777,rec=1) crystallite_dPdF0; close (777)
! call IO_write_jobRealFile(777,'convergedTstar'//trim(rankStr),size(crystallite_Tstar0_v))
! write (777,rec=1) crystallite_Tstar0_v; close (777)
! call IO_write_jobRealFile(777,'convergedStateConst'//trim(rankStr))
! m = 0_pInt
! writePlasticityInstances: do ph = 1_pInt, size(phase_plasticity)
! do k = 1_pInt, plasticState(ph)%sizeState
! do l = 1, size(plasticState(ph)%state0(1,:))
! m = m+1_pInt
! write(777,rec=m) plasticState(ph)%state0(k,l)
! enddo; enddo
! enddo writePlasticityInstances
! close (777)
! call IO_write_jobRealFile(777,'convergedStateHomog'//trim(rankStr))
! m = 0_pInt
! writeHomogInstances: do homog = 1_pInt, material_Nhomogenization
! do k = 1_pInt, homogState(homog)%sizeState
! do l = 1, size(homogState(homog)%state0(1,:))
! m = m+1_pInt
! write(777,rec=m) homogState(homog)%state0(k,l)
! enddo; enddo
! enddo writeHomogInstances
! close (777)
endif endif
if (iand(debug_level(debug_CPFEM), debug_levelBasic) /= 0_pInt) & if (iand(debug_level(debug_CPFEM), debug_levelBasic) /= 0_pInt) &

View File

@ -178,10 +178,10 @@ end subroutine HDF5_closeJobFile
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
!> @brief open and initializes HDF5 output file !> @brief open and initializes HDF5 output file
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
integer(HID_T) function HDF5_openFile(filePath,mode) integer(HID_T) function HDF5_openFile(fileName,mode)
implicit none implicit none
character(len=*), intent(in) :: filePath character(len=*), intent(in) :: fileName
character, intent(in), optional :: mode character, intent(in), optional :: mode
character :: m character :: m
integer :: hdferr integer :: hdferr
@ -192,11 +192,14 @@ integer(HID_T) function HDF5_openFile(filePath,mode)
m = 'r' m = 'r'
endif endif
if (m == 'w' .or. m == 'a') then if ( m == 'w') then
call h5fopen_f(filePath,H5F_ACC_RDWR_F,HDF5_openFile,hdferr) call h5fcreate_f(fileName,H5F_ACC_TRUNC_F,HDF5_openFile,hdferr)
if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_openFile: h5fopen_f (w/a)',el=hdferr) if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_openFile: h5fcreate_f',el=hdferr)
elseif(m == 'a') then
call h5fopen_f(fileName,H5F_ACC_RDWR_F,HDF5_openFile,hdferr)
if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_openFile: h5fopen_f (a)',el=hdferr)
elseif(m == 'r') then elseif(m == 'r') then
call h5fopen_f(filePath,H5F_ACC_RDONLY_F,HDF5_openFile,hdferr) call h5fopen_f(fileName,H5F_ACC_RDONLY_F,HDF5_openFile,hdferr)
if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_openFile: h5fopen_f (r)',el=hdferr) if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_openFile: h5fopen_f (r)',el=hdferr)
else else
call IO_error(1_pInt,ext_msg='HDF5_openFile: h5fopen_f unknown access mode',el=hdferr) call IO_error(1_pInt,ext_msg='HDF5_openFile: h5fopen_f unknown access mode',el=hdferr)
@ -209,15 +212,12 @@ end function HDF5_openFile
!> @brief close the opened HDF5 output file !> @brief close the opened HDF5 output file
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
subroutine HDF5_closeFile(fileHandle) subroutine HDF5_closeFile(fileHandle)
use hdf5
implicit none implicit none
integer :: hdferr integer :: hdferr
integer(HID_T), intent(in) :: fileHandle integer(HID_T), intent(in) :: fileHandle
call h5fclose_f(fileHandle,hdferr) call h5fclose_f(fileHandle,hdferr)
if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_closeFile: h5fclose_f',el=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 end subroutine HDF5_closeFile