From 4cac2448d42fd64e91e6dff599576f941353e9fb Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 4 Apr 2019 07:52:36 +0200 Subject: [PATCH] writing more results out --- src/constitutive.f90 | 2 +- src/plastic_disloUCLA.f90 | 29 ++++-- src/plastic_isotropic.f90 | 19 ++-- src/plastic_phenopowerlaw.f90 | 42 ++++---- src/results.f90 | 181 ++++++++++++++++++++++++++++++---- 5 files changed, 219 insertions(+), 54 deletions(-) diff --git a/src/constitutive.f90 b/src/constitutive.f90 index 23ae3f07b..c6978915f 100644 --- a/src/constitutive.f90 +++ b/src/constitutive.f90 @@ -1085,7 +1085,7 @@ subroutine constitutive_results() PLASTICITY_DISLOTWIN_ID, & PLASTICITY_DISLOUCLA_ID, & PLASTICITY_NONLOCAL_ID -#if defined(PETSc) || defined(DAMASKHDF5) +#if defined(PETSc) || defined(DAMASK_HDF5) use results use HDF5_utilities use config, only: & diff --git a/src/plastic_disloUCLA.f90 b/src/plastic_disloUCLA.f90 index 88aa27432..99444421b 100644 --- a/src/plastic_disloUCLA.f90 +++ b/src/plastic_disloUCLA.f90 @@ -560,23 +560,40 @@ end function plastic_disloUCLA_postResults !> @brief writes results to HDF5 output file !-------------------------------------------------------------------------------------------------- subroutine plastic_disloUCLA_results(instance,group) -#if defined(PETSc) || defined(DAMASKHDF5) +#if defined(PETSc) || defined(DAMASK_HDF5) use results implicit none - integer, intent(in) :: instance - character(len=*) :: group + integer, intent(in) :: instance + character(len=*), intent(in) :: group + integer :: o - associate(prm => param(instance), stt => state(instance)) + associate(prm => param(instance), stt => state(instance), dst => dependentState(instance)) outputsLoop: do o = 1,size(prm%outputID) select case(prm%outputID(o)) + case (rho_mob_ID) + call results_writeDataset(group,stt%rho_mob,'rho_mob',& + 'mobile dislocation density','1/m^2') + case (rho_dip_ID) + call results_writeDataset(group,stt%rho_dip,'rho_dip',& + 'dislocation dipole density''1/m^2') + case (dot_gamma_sl_ID) + call results_writeDataset(group,stt%gamma_sl,'dot_gamma_sl',& + 'plastic slip','1') + case (Lambda_sl_ID) + call results_writeDataset(group,dst%Lambda_sl,'Lambda_sl',& + 'mean free path for slip','m') + case (thresholdstress_ID) + call results_writeDataset(group,dst%threshold_stress,'threshold_stress',& + 'threshold stress for slip','Pa') end select enddo outputsLoop end associate + #else - integer, intent(in) :: instance - character(len=*) :: group + integer, intent(in) :: instance + character(len=*), intent(in) :: group #endif end subroutine plastic_disloUCLA_results diff --git a/src/plastic_isotropic.f90 b/src/plastic_isotropic.f90 index 05a31ab75..984e13f0e 100644 --- a/src/plastic_isotropic.f90 +++ b/src/plastic_isotropic.f90 @@ -409,8 +409,7 @@ subroutine plastic_isotropic_dotState(Mp,instance,of) xi_inf_star = prm%xi_inf else xi_inf_star = prm%xi_inf & - + asinh( (dot_gamma / prm%c_1)**(1.0_pReal / prm%c_2) & - )**(1.0_pReal / prm%c_3) & + + asinh( (dot_gamma / prm%c_1)**(1.0_pReal / prm%c_2))**(1.0_pReal / prm%c_3) & / prm%c_4 * (dot_gamma / prm%dot_gamma_0)**(1.0_pReal / prm%n) endif dot%xi(of) = dot_gamma & @@ -469,7 +468,7 @@ function plastic_isotropic_postResults(Mp,instance,of) result(postResults) c = c + 1 case (dot_gamma_ID) postResults(c+1) = prm%dot_gamma_0 & - * (sqrt(1.5_pReal) * norm_Mp /(prm%M * stt%xi(of)))**prm%n + * (sqrt(1.5_pReal) * norm_Mp /(prm%M * stt%xi(of)))**prm%n c = c + 1 end select @@ -484,23 +483,27 @@ end function plastic_isotropic_postResults !> @brief writes results to HDF5 output file !-------------------------------------------------------------------------------------------------- subroutine plastic_isotropic_results(instance,group) -#if defined(PETSc) || defined(DAMASKHDF5) +#if defined(PETSc) || defined(DAMASK_HDF5) use results implicit none - integer, intent(in) :: instance - character(len=*) :: group + integer, intent(in) :: instance + character(len=*), intent(in) :: group + integer :: o associate(prm => param(instance), stt => state(instance)) outputsLoop: do o = 1,size(prm%outputID) select case(prm%outputID(o)) + case (xi_ID) + call results_writeDataset(group,stt%xi,'xi','resistance against plastic flow','Pa') end select enddo outputsLoop end associate + #else - integer, intent(in) :: instance - character(len=*) :: group + integer, intent(in) :: instance + character(len=*), intent(in) :: group #endif end subroutine plastic_isotropic_results diff --git a/src/plastic_phenopowerlaw.f90 b/src/plastic_phenopowerlaw.f90 index 4124856d1..c2a4843f2 100644 --- a/src/plastic_phenopowerlaw.f90 +++ b/src/plastic_phenopowerlaw.f90 @@ -563,28 +563,34 @@ end function plastic_phenopowerlaw_postResults !> @brief writes results to HDF5 output file !-------------------------------------------------------------------------------------------------- subroutine plastic_phenopowerlaw_results(instance,group) -#if defined(PETSc) || defined(DAMASKHDF5) - use results +#if defined(PETSc) || defined(DAMASK_HDF5) + use results - implicit none - integer, intent(in) :: instance - character(len=*) :: group - integer :: o + implicit none + integer, intent(in) :: instance + character(len=*), intent(in) :: group + + integer :: o - associate(prm => param(instance), stt => state(instance)) - outputsLoop: do o = 1,size(prm%outputID) - select case(prm%outputID(o)) - case (resistance_slip_ID) - call results_writeVectorDataset(group,stt%xi_slip,'xi_slip','Pa') - case (accumulatedshear_slip_ID) - call results_writeVectorDataset(group,stt%gamma_slip,'gamma_slip','-') - end select - enddo outputsLoop - end associate + associate(prm => param(instance), stt => state(instance)) + outputsLoop: do o = 1,size(prm%outputID) + select case(prm%outputID(o)) + case (resistance_slip_ID) + call results_writeDataset(group,stt%xi_slip, 'xi_slip', & + 'resistance against plastic slip','Pa') + case (accumulatedshear_slip_ID) + call results_writeDataset(group,stt%gamma_slip,'gamma_slip', & + 'plastic slip','1') + + end select + enddo outputsLoop + end associate + #else - integer, intent(in) :: instance - character(len=*) :: group + integer, intent(in) :: instance + character(len=*), intent(in) :: group #endif + end subroutine plastic_phenopowerlaw_results diff --git a/src/results.f90 b/src/results.f90 index f70e124f8..cd4a15cef 100644 --- a/src/results.f90 +++ b/src/results.f90 @@ -18,6 +18,13 @@ module results integer(HID_T), public, protected :: tempCoordinates, tempResults integer(HID_T), private :: resultsFile, currentIncID, plist_id + interface results_writeDataset + module procedure results_writeTensorDataset_real + module procedure results_writeTensorDataset_int + module procedure results_writeVectorDataset_real + module procedure results_writeVectorDataset_int + module procedure results_writeScalarDataset_real + end interface results_writeDataset public :: & results_init, & @@ -26,8 +33,9 @@ module results results_addIncrement, & results_addGroup, & results_openGroup, & - results_writeVectorDataset, & + results_writeDataset, & results_setLink, & + results_addAttribute, & results_removeLink contains @@ -36,13 +44,21 @@ subroutine results_init getSolverJobName implicit none + character(len=pStringLen) :: commandLine write(6,'(/,a)') ' <<<+- results init -+>>>' write(6,'(/,a)') ' Diehl et al., Integrating Materials and Manufacturing Innovation 6(1):83–91, 2017' write(6,'(a)') ' https://doi.org/10.1007/s40192-018-0118-7' - call HDF5_closeFile(HDF5_openFile(trim(getSolverJobName())//'.hdf5','w',.true.)) + resultsFile = HDF5_openFile(trim(getSolverJobName())//'.hdf5','w',.true.) + call HDF5_addAttribute(resultsFile,'DADF5-version',0.1) + call HDF5_addAttribute(resultsFile,'DADF5-major',0) + call HDF5_addAttribute(resultsFile,'DADF5-minor',1) + call HDF5_addAttribute(resultsFile,'DAMASK',DAMASKVERSION) + call get_command(commandLine) + call HDF5_addAttribute(resultsFile,'call',trim(commandLine)) + call HDF5_closeFile(resultsFile) end subroutine results_init @@ -50,18 +66,13 @@ end subroutine results_init !-------------------------------------------------------------------------------------------------- !> @brief opens the results file to append data !-------------------------------------------------------------------------------------------------- -subroutine results_openJobFile() +subroutine results_openJobFile use DAMASK_interface, only: & getSolverJobName implicit none - character(len=pStringLen) :: commandLine resultsFile = HDF5_openFile(trim(getSolverJobName())//'.hdf5','a',.true.) - call HDF5_addAttribute(resultsFile,'DADF5',0.1_pReal) - call HDF5_addAttribute(resultsFile,'DAMASK',DAMASKVERSION) - call get_command(commandLine) - call HDF5_addAttribute(resultsFile,'call',trim(commandLine)) end subroutine results_openJobFile @@ -69,7 +80,7 @@ end subroutine results_openJobFile !-------------------------------------------------------------------------------------------------- !> @brief closes the results file !-------------------------------------------------------------------------------------------------- -subroutine results_closeJobFile() +subroutine results_closeJobFile implicit none call HDF5_closeFile(resultsFile) @@ -87,7 +98,7 @@ subroutine results_addIncrement(inc,time) real(pReal), intent(in) :: time character(len=pStringLen) :: incChar - write(incChar,*) inc + write(incChar,'(i5.5)') inc ! allow up to 99999 increments call HDF5_closeGroup(results_addGroup(trim('inc'//trim(adjustl(incChar))))) call results_setLink(trim('inc'//trim(adjustl(incChar))),'current') call HDF5_addAttribute(resultsFile,'time/s',time,trim('inc'//trim(adjustl(incChar)))) @@ -135,6 +146,19 @@ subroutine results_setLink(path,link) end subroutine results_setLink +!-------------------------------------------------------------------------------------------------- +!> @brief adds an attribute to an object +!-------------------------------------------------------------------------------------------------- +subroutine results_addAttribute(attrLabel,attrValue,path) + + implicit none + character(len=*), intent(in) :: attrLabel, attrValue, path + + call HDF5_addAttribute_str(resultsFile,attrLabel, attrValue, path) + +end subroutine results_addAttribute + + !-------------------------------------------------------------------------------------------------- !> @brief remove link to an object !-------------------------------------------------------------------------------------------------- @@ -151,23 +175,138 @@ subroutine results_removeLink(link) end subroutine results_removeLink +!-------------------------------------------------------------------------------------------------- +!> @brief stores a scalar dataset in a group +!-------------------------------------------------------------------------------------------------- +subroutine results_writeScalarDataset_real(group,dataset,label,description,SIunit) + + implicit none + character(len=*), intent(in) :: label,group,description + character(len=*), intent(in), optional :: SIunit + real(pReal), intent(inout), dimension(:) :: dataset + + integer(HID_T) :: groupHandle + + groupHandle = results_openGroup(group) + +#ifdef PETSc + call HDF5_write(groupHandle,dataset,label,.true.) +#endif + + if (HDF5_objectExists(groupHandle,label)) & + call HDF5_addAttribute(groupHandle,'Description',description,label) + if (HDF5_objectExists(groupHandle,label) .and. present(SIunit)) & + call HDF5_addAttribute(groupHandle,'Unit',SIunit,label) + call HDF5_closeGroup(groupHandle) + +end subroutine results_writeScalarDataset_real + !-------------------------------------------------------------------------------------------------- !> @brief stores a vector dataset in a group !-------------------------------------------------------------------------------------------------- -subroutine results_writeVectorDataset(group,dataset,label,SIunit) +subroutine results_writeVectorDataset_real(group,dataset,label,description,SIunit) - implicit none - character(len=*), intent(in) :: SIunit,label,group - real(pReal), intent(inout), dimension(:,:) :: dataset - integer(HID_T) :: groupHandle + implicit none + character(len=*), intent(in) :: label,group,description + character(len=*), intent(in), optional :: SIunit + real(pReal), intent(inout), dimension(:,:) :: dataset + + integer(HID_T) :: groupHandle - groupHandle = results_openGroup(group) - call HDF5_write(groupHandle,dataset,label) - if (HDF5_objectExists(groupHandle,label)) & - call HDF5_addAttribute(groupHandle,'Unit',SIunit,label) - call HDF5_closeGroup(groupHandle) + groupHandle = results_openGroup(group) + +#ifdef PETSc + call HDF5_write(groupHandle,dataset,label,.true.) +#endif + + if (HDF5_objectExists(groupHandle,label)) & + call HDF5_addAttribute(groupHandle,'Description',description,label) + if (HDF5_objectExists(groupHandle,label) .and. present(SIunit)) & + call HDF5_addAttribute(groupHandle,'Unit',SIunit,label) + call HDF5_closeGroup(groupHandle) -end subroutine results_writeVectorDataset +end subroutine results_writeVectorDataset_real + + +!-------------------------------------------------------------------------------------------------- +!> @brief stores a tensor dataset in a group +!-------------------------------------------------------------------------------------------------- +subroutine results_writeTensorDataset_real(group,dataset,label,description,SIunit) + + implicit none + character(len=*), intent(in) :: label,group,description + character(len=*), intent(in), optional :: SIunit + real(pReal), intent(inout), dimension(:,:,:) :: dataset + + integer(HID_T) :: groupHandle + + groupHandle = results_openGroup(group) + +#ifdef PETSc + call HDF5_write(groupHandle,dataset,label,.true.) +#endif + + if (HDF5_objectExists(groupHandle,label)) & + call HDF5_addAttribute(groupHandle,'Description',description,label) + if (HDF5_objectExists(groupHandle,label) .and. present(SIunit)) & + call HDF5_addAttribute(groupHandle,'Unit',SIunit,label) + call HDF5_closeGroup(groupHandle) + +end subroutine results_writeTensorDataset_real + + +!-------------------------------------------------------------------------------------------------- +!> @brief stores a vector dataset in a group +!-------------------------------------------------------------------------------------------------- +subroutine results_writeVectorDataset_int(group,dataset,label,description,SIunit) + + implicit none + character(len=*), intent(in) :: label,group,description + character(len=*), intent(in), optional :: SIunit + integer, intent(inout), dimension(:,:) :: dataset + + integer(HID_T) :: groupHandle + + groupHandle = results_openGroup(group) + +#ifdef PETSc + call HDF5_write(groupHandle,dataset,label,.true.) +#endif + + if (HDF5_objectExists(groupHandle,label)) & + call HDF5_addAttribute(groupHandle,'Description',description,label) + if (HDF5_objectExists(groupHandle,label) .and. present(SIunit)) & + call HDF5_addAttribute(groupHandle,'Unit',SIunit,label) + call HDF5_closeGroup(groupHandle) + +end subroutine results_writeVectorDataset_int + + +!-------------------------------------------------------------------------------------------------- +!> @brief stores a vector dataset in a group +!-------------------------------------------------------------------------------------------------- +subroutine results_writeTensorDataset_int(group,dataset,label,description,SIunit) + + implicit none + character(len=*), intent(in) :: label,group,description + character(len=*), intent(in), optional :: SIunit + integer, intent(inout), dimension(:,:,:) :: dataset + + integer(HID_T) :: groupHandle + + groupHandle = results_openGroup(group) + +#ifdef PETSc + call HDF5_write(groupHandle,dataset,label,.true.) +#endif + + if (HDF5_objectExists(groupHandle,label)) & + call HDF5_addAttribute(groupHandle,'Description',description,label) + if (HDF5_objectExists(groupHandle,label) .and. present(SIunit)) & + call HDF5_addAttribute(groupHandle,'Unit',SIunit,label) + call HDF5_closeGroup(groupHandle) + +end subroutine results_writeTensorDataset_int !--------------------------------------------------------------------------------------------------