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

@ -157,77 +157,25 @@ subroutine CPFEM_init
fileReadID = HDF5_openFile(trim(getSolverJobName())//trim(rankStr)//'.hdf5')
call HDF5_read(material_phase,fileReadID,'recordedPhase')
!write(6,*) material_phase
call HDF5_read(crystallite_F0,fileReadID,'convergedF')
!write(6,*) crystallite_F0
call HDF5_read(crystallite_Fp0,fileReadID,'convergedFp')
call HDF5_read(crystallite_Fi0,fileReadID,'convergedFi')
call HDF5_read(crystallite_Lp0,fileReadID,'convergedLp')
call HDF5_read(crystallite_Li0,fileReadID,'convergedLi')
call HDF5_read(crystallite_dPdF0,fileReadID,'convergeddPdF')
call HDF5_read(material_phase, fileReadID,'recordedPhase')
call HDF5_read(crystallite_F0, fileReadID,'convergedF')
call HDF5_read(crystallite_Fp0, fileReadID,'convergedFp')
call HDF5_read(crystallite_Fi0, fileReadID,'convergedFi')
call HDF5_read(crystallite_Lp0, fileReadID,'convergedLp')
call HDF5_read(crystallite_Li0, fileReadID,'convergedLi')
call HDF5_read(crystallite_dPdF0, fileReadID,'convergeddPdF')
call HDF5_read(crystallite_Tstar0_v,fileReadID,'convergedTstar')
groupPlasticID = HDF5_openGroup2(fileReadID,'PlasticPhases')
write(6,*) groupPlasticID
do ph = 1_pInt,size(phase_plasticity)
call HDF5_read(plasticState(ph)%state0,groupPlasticID,'convergedStateConst')
write(6,*) plasticState(ph)%state0
enddo
groupHomogID = HDF5_openGroup2(fileReadID,'material_Nhomogenization')
write(6,*) groupHomogID
do homog = 1_pInt, material_Nhomogenization
call HDF5_read(homogState(homog)%state0, groupHomogID,'convergedStateHomog')
write(6,*) homogState(homog)%state0
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.
endif
@ -283,13 +231,11 @@ subroutine CPFEM_age()
IO_write_jobRealFile, &
IO_warning
use HDF5_utilities, only: &
HDF5_createFile, &
HDF5_openFile, &
HDF5_closeFile, &
HDF5_closeGroup, &
HDF5_addGroup2, &
!HDF5_writeScalarDataset3, &
HDF5_write
!HDF5_addScalarDataset2
use hdf5
use DAMASK_interface, only: &
getSolverJobName
@ -302,110 +248,63 @@ subroutine CPFEM_age()
integer :: hdferr
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) &
write(6,'(a)') '<< CPFEM >> aging states'
crystallite_F0 = crystallite_partionedF ! crystallite deformation (_subF is perturbed...)
crystallite_Fp0 = crystallite_Fp ! crystallite plastic deformation
crystallite_Lp0 = crystallite_Lp ! crystallite plastic velocity
crystallite_Fi0 = crystallite_Fi ! crystallite intermediate deformation
crystallite_Li0 = crystallite_Li ! crystallite intermediate velocity
crystallite_dPdF0 = crystallite_dPdF ! crystallite stiffness
crystallite_Tstar0_v = crystallite_Tstar_v ! crystallite 2nd Piola Kirchhoff stress
crystallite_F0 = crystallite_partionedF ! crystallite deformation (_subF is perturbed...)
crystallite_Fp0 = crystallite_Fp ! crystallite plastic deformation
crystallite_Lp0 = crystallite_Lp ! crystallite plastic velocity
crystallite_Fi0 = crystallite_Fi ! crystallite intermediate deformation
crystallite_Li0 = crystallite_Li ! crystallite intermediate velocity
crystallite_dPdF0 = crystallite_dPdF ! crystallite stiffness
crystallite_Tstar0_v = crystallite_Tstar_v ! crystallite 2nd Piola Kirchhoff stress
forall (i = 1:size(plasticState)) plasticState(i)%state0 = plasticState(i)%state ! copy state in this lengthy way because: A component cannot be an array if the encompassing structure is an array
forall (i = 1:size(plasticState)) plasticState(i)%state0 = plasticState(i)%state ! copy state in this lengthy way because: A component cannot be an array if the encompassing structure is an array
do i = 1, size(sourceState)
do mySource = 1,phase_Nsources(i)
sourceState(i)%p(mySource)%state0 = sourceState(i)%p(mySource)%state ! copy state in this lengthy way because: A component cannot be an array if the encompassing structure is an array
enddo; enddo
do i = 1, size(sourceState)
do mySource = 1,phase_Nsources(i)
sourceState(i)%p(mySource)%state0 = sourceState(i)%p(mySource)%state ! copy state in this lengthy way because: A component cannot be an array if the encompassing structure is an array
enddo; enddo
do homog = 1_pInt, material_Nhomogenization
homogState (homog)%state0 = homogState (homog)%state
thermalState (homog)%state0 = thermalState (homog)%state
damageState (homog)%state0 = damageState (homog)%state
vacancyfluxState (homog)%state0 = vacancyfluxState (homog)%state
hydrogenfluxState(homog)%state0 = hydrogenfluxState(homog)%state
enddo
do homog = 1_pInt, material_Nhomogenization
homogState (homog)%state0 = homogState (homog)%state
thermalState (homog)%state0 = thermalState (homog)%state
damageState (homog)%state0 = damageState (homog)%state
vacancyfluxState (homog)%state0 = vacancyfluxState (homog)%state
hydrogenfluxState(homog)%state0 = hydrogenfluxState(homog)%state
enddo
if (restartWrite) then
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
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(crystallite_F0,fileHandle,'convergedF')
call HDF5_write(crystallite_Fp0,fileHandle,'convergedFp')
call HDF5_write(crystallite_Fi0,fileHandle,'convergedFi')
call HDF5_write(crystallite_Lp0,fileHandle,'convergedLp')
call HDF5_write(crystallite_Li0,fileHandle,'convergedLi')
call HDF5_write(crystallite_dPdF0,fileHandle,'convergeddPdF')
call HDF5_write(material_phase, fileHandle,'recordedPhase')
call HDF5_write(crystallite_F0, fileHandle,'convergedF')
call HDF5_write(crystallite_Fp0, fileHandle,'convergedFp')
call HDF5_write(crystallite_Fi0, fileHandle,'convergedFi')
call HDF5_write(crystallite_Lp0, fileHandle,'convergedLp')
call HDF5_write(crystallite_Li0, fileHandle,'convergedLi')
call HDF5_write(crystallite_dPdF0, fileHandle,'convergeddPdF')
call HDF5_write(crystallite_Tstar0_v,fileHandle,'convergedTstar')
groupPlastic = HDF5_addGroup2(fileHandle,'PlasticPhases')
do ph = 1_pInt,size(phase_plasticity)
call HDF5_write(plasticState(ph)%state0,groupPlastic,'convergedStateConst')
enddo
call HDF5_closeGroup(groupPlastic)
groupHomog = HDF5_addGroup2(fileHandle,'material_Nhomogenization')
do homog = 1_pInt, material_Nhomogenization
call HDF5_write(homogState(homog)%state0,groupHomog,'convergedStateHomog')
enddo
call HDF5_closeGroup(groupHomog)
call HDF5_closeFile(fileHandle)
! 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)
restartWrite = .false.
endif
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
!--------------------------------------------------------------------------------------------------
integer(HID_T) function HDF5_openFile(filePath,mode)
integer(HID_T) function HDF5_openFile(fileName,mode)
implicit none
character(len=*), intent(in) :: filePath
character(len=*), intent(in) :: fileName
character, intent(in), optional :: mode
character :: m
integer :: hdferr
@ -192,11 +192,14 @@ integer(HID_T) function HDF5_openFile(filePath,mode)
m = 'r'
endif
if (m == 'w' .or. m == 'a') then
call h5fopen_f(filePath,H5F_ACC_RDWR_F,HDF5_openFile,hdferr)
if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_openFile: h5fopen_f (w/a)',el=hdferr)
if ( m == 'w') then
call h5fcreate_f(fileName,H5F_ACC_TRUNC_F,HDF5_openFile,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
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)
else
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
!--------------------------------------------------------------------------------------------------
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