From b9ee401ff5c4a8d6997257be347e77982d67b7b4 Mon Sep 17 00:00:00 2001 From: Yi Hu Date: Mon, 5 Dec 2022 10:52:59 +0000 Subject: [PATCH] add damage restart functionality and associated tests --- PRIVATE | 2 +- src/grid/DAMASK_grid.f90 | 2 ++ src/grid/grid_damage_spectral.f90 | 51 ++++++++++++++++++++++++++++-- src/grid/grid_thermal_spectral.f90 | 6 ++-- src/homogenization.f90 | 6 ++++ src/homogenization_damage.f90 | 6 +++- src/phase.f90 | 12 +++++++ src/phase_damage.f90 | 33 +++++++++++++++++-- 8 files changed, 109 insertions(+), 9 deletions(-) diff --git a/PRIVATE b/PRIVATE index ecfe3b3f0..e4ac967b2 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit ecfe3b3f057f4f81b3b1a12399bf238bc2546de7 +Subproject commit e4ac967b2fbbe91242ecbbfa41e1c019dd1c3316 diff --git a/src/grid/DAMASK_grid.f90 b/src/grid/DAMASK_grid.f90 index 08d29cd4e..2e21dec8d 100644 --- a/src/grid/DAMASK_grid.f90 +++ b/src/grid/DAMASK_grid.f90 @@ -482,6 +482,8 @@ program DAMASK_grid call mechanical_restartWrite case(FIELD_THERMAL_ID) call grid_thermal_spectral_restartWrite + case(FIELD_DAMAGE_ID) + call grid_damage_spectral_restartWrite end select end do call materialpoint_restartWrite diff --git a/src/grid/grid_damage_spectral.f90 b/src/grid/grid_damage_spectral.f90 index 41422bce2..6cf7defdf 100644 --- a/src/grid/grid_damage_spectral.f90 +++ b/src/grid/grid_damage_spectral.f90 @@ -16,6 +16,9 @@ module grid_damage_spectral use prec use parallelization use IO + use CLI + use HDF5_utilities + use HDF5 use spectral_utilities use discretization_grid use homogenization @@ -59,13 +62,13 @@ module grid_damage_spectral public :: & grid_damage_spectral_init, & grid_damage_spectral_solution, & + grid_damage_spectral_restartWrite, & grid_damage_spectral_forward contains !-------------------------------------------------------------------------------------------------- !> @brief allocates all neccessary fields and fills them with data -! ToDo: Restart not implemented !-------------------------------------------------------------------------------------------------- subroutine grid_damage_spectral_init() @@ -76,6 +79,8 @@ subroutine grid_damage_spectral_init() Vec :: uBound, lBound integer(MPI_INTEGER_KIND) :: err_MPI PetscErrorCode :: err_PETSc + integer(HID_T) :: fileHandle, groupHandle + real(pReal), dimension(1,product(cells(1:2))*cells3) :: tempN type(tDict), pointer :: & num_grid, & num_generic @@ -167,6 +172,18 @@ subroutine grid_damage_spectral_init() CHKERRQ(err_PETSc) end if + restartRead: if (CLI_restartInc > 0) then + print'(/,1x,a,i0,a)', 'reading restart data of increment ', CLI_restartInc, ' from file' + + fileHandle = HDF5_openFile(getSolverJobName()//'_restart.hdf5','r') + groupHandle = HDF5_openGroup(fileHandle,'solver') + + call HDF5_read(tempN,groupHandle,'phi',.false.) + phi = reshape(tempN,[cells(1),cells(2),cells3]) + call HDF5_read(tempN,groupHandle,'phi_lastInc',.false.) + phi_lastInc = reshape(tempN,[cells(1),cells(2),cells3]) + end if restartRead + ce = 0 do k = 1, cells3; do j = 1, cells(2); do i = 1, cells(1) ce = ce + 1 @@ -285,6 +302,36 @@ subroutine grid_damage_spectral_forward(cutBack) end subroutine grid_damage_spectral_forward +!-------------------------------------------------------------------------------------------------- +!> @brief Write current solver and constitutive data for restart to file. +!-------------------------------------------------------------------------------------------------- +subroutine grid_damage_spectral_restartWrite + + PetscErrorCode :: err_PETSc + DM :: dm_local + integer(HID_T) :: fileHandle, groupHandle + PetscScalar, dimension(:,:,:), pointer :: phi + + call SNESGetDM(SNES_damage,dm_local,err_PETSc); + CHKERRQ(err_PETSc) + call DMDAVecGetArrayF90(dm_local,solution_vec,phi,err_PETSc); + CHKERRQ(err_PETSc) + + print'(1x,a)', 'writing damage solver data required for restart to file'; flush(IO_STDOUT) + + fileHandle = HDF5_openFile(getSolverJobName()//'_restart.hdf5','a') + groupHandle = HDF5_openGroup(fileHandle,'solver') + call HDF5_write(reshape(phi,[1,product(cells(1:2))*cells3]),groupHandle,'phi') + call HDF5_write(reshape(phi_lastInc,[1,product(cells(1:2))*cells3]),groupHandle,'phi_lastInc') + call HDF5_closeGroup(groupHandle) + call HDF5_closeFile(fileHandle) + + call DMDAVecRestoreArrayF90(dm_local,solution_vec,phi,err_PETSc); + CHKERRQ(err_PETSc) + +end subroutine grid_damage_spectral_restartWrite + + !-------------------------------------------------------------------------------------------------- !> @brief Construct the residual vector. !-------------------------------------------------------------------------------------------------- @@ -329,7 +376,7 @@ end subroutine formResidual !-------------------------------------------------------------------------------------------------- -!> @brief update reference viscosity and conductivity +!> @brief Update reference viscosity and conductivity. !-------------------------------------------------------------------------------------------------- subroutine updateReference() diff --git a/src/grid/grid_thermal_spectral.f90 b/src/grid/grid_thermal_spectral.f90 index 0c3a2b3ee..347867578 100644 --- a/src/grid/grid_thermal_spectral.f90 +++ b/src/grid/grid_thermal_spectral.f90 @@ -281,7 +281,7 @@ end subroutine grid_thermal_spectral_forward !-------------------------------------------------------------------------------------------------- -!> @brief Write current solver and constitutive data for restart to file +!> @brief Write current solver and constitutive data for restart to file. !-------------------------------------------------------------------------------------------------- subroutine grid_thermal_spectral_restartWrite @@ -313,7 +313,7 @@ end subroutine grid_thermal_spectral_restartWrite !-------------------------------------------------------------------------------------------------- -!> @brief forms the spectral thermal residual vector +!> @brief Construct the residual vector. !-------------------------------------------------------------------------------------------------- subroutine formResidual(in,x_scal,r,dummy,err_PETSc) @@ -356,7 +356,7 @@ end subroutine formResidual !-------------------------------------------------------------------------------------------------- -!> @brief update reference viscosity and conductivity +!> @brief Update reference viscosity and conductivity. !-------------------------------------------------------------------------------------------------- subroutine updateReference() diff --git a/src/homogenization.f90 b/src/homogenization.f90 index 6f6270403..6e6034567 100644 --- a/src/homogenization.f90 +++ b/src/homogenization.f90 @@ -406,6 +406,9 @@ subroutine homogenization_restartWrite(fileHandle) call HDF5_write(homogState(ho)%state,groupHandle(2),'omega_mechanical') ! ToDo: should be done by mech + if(damageState_h(ho)%sizeState > 0) & + call HDF5_write(damageState_h(ho)%state,groupHandle(2),'omega_damage') ! ToDo: should be done by mech + call HDF5_closeGroup(groupHandle(2)) end do @@ -433,6 +436,9 @@ subroutine homogenization_restartRead(fileHandle) call HDF5_read(homogState(ho)%state0,groupHandle(2),'omega_mechanical') ! ToDo: should be done by mech + if(damageState_h(ho)%sizeState > 0) & + call HDF5_read(damageState_h(ho)%state0,groupHandle(2),'omega_damage') ! ToDo: should be done by mech + call HDF5_closeGroup(groupHandle(2)) end do diff --git a/src/homogenization_damage.f90 b/src/homogenization_damage.f90 index dd438b3c4..885ff9090 100644 --- a/src/homogenization_damage.f90 +++ b/src/homogenization_damage.f90 @@ -80,11 +80,15 @@ module subroutine damage_partition(ce) integer, intent(in) :: ce real(pReal) :: phi + integer :: co if(damageState_h(material_homogenizationID(ce))%sizeState < 1) return phi = damagestate_h(material_homogenizationID(ce))%state(1,material_homogenizationEntry(ce)) - call phase_set_phi(phi,1,ce) + do co = 1, homogenization_Nconstituents(material_homogenizationID(ce)) + call phase_set_phi(phi,co,ce) + end do + end subroutine damage_partition diff --git a/src/phase.f90 b/src/phase.f90 index fdafd8f35..12e5ea924 100644 --- a/src/phase.f90 +++ b/src/phase.f90 @@ -160,6 +160,11 @@ module phase integer, intent(in) :: ph end subroutine thermal_restartWrite + module subroutine damage_restartWrite(groupHandle,ph) + integer(HID_T), intent(in) :: groupHandle + integer, intent(in) :: ph + end subroutine damage_restartWrite + module subroutine mechanical_restartRead(groupHandle,ph) integer(HID_T), intent(in) :: groupHandle integer, intent(in) :: ph @@ -170,6 +175,11 @@ module phase integer, intent(in) :: ph end subroutine thermal_restartRead + module subroutine damage_restartRead(groupHandle,ph) + integer(HID_T), intent(in) :: groupHandle + integer, intent(in) :: ph + end subroutine damage_restartRead + module function mechanical_S(ph,en) result(S) integer, intent(in) :: ph,en real(pReal), dimension(3,3) :: S @@ -674,6 +684,7 @@ subroutine phase_restartWrite(fileHandle) call mechanical_restartWrite(groupHandle(2),ph) call thermal_restartWrite(groupHandle(2),ph) + call damage_restartWrite(groupHandle(2),ph) call HDF5_closeGroup(groupHandle(2)) @@ -703,6 +714,7 @@ subroutine phase_restartRead(fileHandle) call mechanical_restartRead(groupHandle(2),ph) call thermal_restartRead(groupHandle(2),ph) + call damage_restartRead(groupHandle(2),ph) call HDF5_closeGroup(groupHandle(2)) diff --git a/src/phase_damage.f90 b/src/phase_damage.f90 index 0bf13fcae..ff262bc41 100644 --- a/src/phase_damage.f90 +++ b/src/phase_damage.f90 @@ -1,6 +1,6 @@ -!---------------------------------------------------------------------------------------------------- +!-------------------------------------------------------------------------------------------------- !> @brief internal microstructure state for all damage sources and kinematics constitutive models -!---------------------------------------------------------------------------------------------------- +!-------------------------------------------------------------------------------------------------- submodule(phase) damage type :: tDamageParameters @@ -310,6 +310,35 @@ function integrateDamageState(Delta_t,ph,en) result(broken) end function integrateDamageState +module subroutine damage_restartWrite(groupHandle,ph) + + integer(HID_T), intent(in) :: groupHandle + integer, intent(in) :: ph + + + select case(phase_damage(ph)) + case(DAMAGE_ISOBRITTLE_ID,DAMAGE_ANISOBRITTLE_ID) + call HDF5_write(damageState(ph)%state,groupHandle,'omega_damage') + end select + +end subroutine damage_restartWrite + + +module subroutine damage_restartRead(groupHandle,ph) + + integer(HID_T), intent(in) :: groupHandle + integer, intent(in) :: ph + + + select case(phase_damage(ph)) + case(DAMAGE_ISOBRITTLE_ID,DAMAGE_ANISOBRITTLE_ID) + call HDF5_read(damageState(ph)%state0,groupHandle,'omega_damage') + end select + + +end subroutine damage_restartRead + + !---------------------------------------------------------------------------------------------- !< @brief writes damage sources results to HDF5 output file !----------------------------------------------------------------------------------------------