From 7f66d4e975d9f54dc03ad17590144401dac96231 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 23 Jan 2020 11:21:42 +0100 Subject: [PATCH 1/4] avoid fixed string length solved issues with wrong trim and is more robust --- src/DAMASK_marc.f90 | 6 +++--- src/FEsolving.f90 | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DAMASK_marc.f90 b/src/DAMASK_marc.f90 index 678d87e60..32ec08e83 100644 --- a/src/DAMASK_marc.f90 +++ b/src/DAMASK_marc.f90 @@ -95,13 +95,13 @@ end subroutine DAMASK_interface_init !-------------------------------------------------------------------------------------------------- !> @brief solver job name (no extension) as combination of geometry and load case name !-------------------------------------------------------------------------------------------------- -function getSolverJobName() +function getSolverJobName - character(1024) :: getSolverJobName, inputName + character(len=:), allocatable :: getSolverJobName + character(1024) :: inputName character(len=*), parameter :: pathSep = achar(47)//achar(92) ! forward and backward slash integer :: extPos - getSolverJobName='' inputName='' inquire(5, name=inputName) ! determine inputfile extPos = len_trim(inputName)-4 diff --git a/src/FEsolving.f90 b/src/FEsolving.f90 index 8057c37e0..070b05a28 100644 --- a/src/FEsolving.f90 +++ b/src/FEsolving.f90 @@ -43,7 +43,7 @@ subroutine FE_init character(len=pStringLen) :: line integer :: myStat,fileUnit integer, allocatable, dimension(:) :: chunkPos - open(newunit=fileUnit, file=trim(getSolverJobName()//INPUTFILEEXTENSION), & + open(newunit=fileUnit, file=getSolverJobName()//INPUTFILEEXTENSION, & status='old', position='rewind', action='read',iostat=myStat) do read (fileUnit,'(A)',END=100) line From bd67d2bb6a4c9dd62ad24e6f95f93e1a9384faf7 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 23 Jan 2020 12:48:18 +0100 Subject: [PATCH 2/4] new mappings have clear name, not (1,2) --- src/damage_local.f90 | 4 ++-- src/damage_nonlocal.f90 | 2 +- src/homogenization.f90 | 36 ++++++++++++++++----------------- src/homogenization_mech_RGC.f90 | 4 ++-- src/material.f90 | 21 ++----------------- src/thermal_adiabatic.f90 | 4 ++-- src/thermal_conduction.f90 | 4 ++-- 7 files changed, 29 insertions(+), 46 deletions(-) diff --git a/src/damage_local.f90 b/src/damage_local.f90 index 6cb45a391..6296631e5 100644 --- a/src/damage_local.f90 +++ b/src/damage_local.f90 @@ -74,7 +74,7 @@ subroutine damage_local_init allocate(damageState(h)%state (1,NofMyHomog), source=damage_initialPhi(h)) nullify(damageMapping(h)%p) - damageMapping(h)%p => mappingHomogenization(1,:,:) + damageMapping(h)%p => material_homogenizationMemberAt deallocate(damage(h)%p) damage(h)%p => damageState(h)%state(1,:) @@ -103,7 +103,7 @@ function damage_local_updateState(subdt, ip, el) phi, phiDot, dPhiDot_dPhi homog = material_homogenizationAt(el) - offset = mappingHomogenization(1,ip,el) + offset = material_homogenizationMemberAt(ip,el) phi = damageState(homog)%subState0(1,offset) call damage_local_getSourceAndItsTangent(phiDot, dPhiDot_dPhi, phi, ip, el) phi = max(residualStiffness,min(1.0_pReal,phi + subdt*phiDot)) diff --git a/src/damage_nonlocal.f90 b/src/damage_nonlocal.f90 index 17bdecaca..4587857aa 100644 --- a/src/damage_nonlocal.f90 +++ b/src/damage_nonlocal.f90 @@ -79,7 +79,7 @@ subroutine damage_nonlocal_init allocate(damageState(h)%state (1,NofMyHomog), source=damage_initialPhi(h)) nullify(damageMapping(h)%p) - damageMapping(h)%p => mappingHomogenization(1,:,:) + damageMapping(h)%p => material_homogenizationMemberAt deallocate(damage(h)%p) damage(h)%p => damageState(h)%state(1,:) diff --git a/src/homogenization.f90 b/src/homogenization.f90 index 18148e1e0..ba98f87f1 100644 --- a/src/homogenization.f90 +++ b/src/homogenization.f90 @@ -242,16 +242,16 @@ subroutine materialpoint_stressAndItsTangent(updateJaco,dt) materialpoint_requested(i,e) = .true. ! everybody requires calculation if (homogState(material_homogenizationAt(e))%sizeState > 0) & - homogState(material_homogenizationAt(e))%subState0(:,mappingHomogenization(1,i,e)) = & - homogState(material_homogenizationAt(e))%State0( :,mappingHomogenization(1,i,e)) ! ...internal homogenization state + homogState(material_homogenizationAt(e))%subState0(:,material_homogenizationMemberAt(i,e)) = & + homogState(material_homogenizationAt(e))%State0( :,material_homogenizationMemberAt(i,e)) ! ...internal homogenization state if (thermalState(material_homogenizationAt(e))%sizeState > 0) & - thermalState(material_homogenizationAt(e))%subState0(:,mappingHomogenization(1,i,e)) = & - thermalState(material_homogenizationAt(e))%State0( :,mappingHomogenization(1,i,e)) ! ...internal thermal state + thermalState(material_homogenizationAt(e))%subState0(:,material_homogenizationMemberAt(i,e)) = & + thermalState(material_homogenizationAt(e))%State0( :,material_homogenizationMemberAt(i,e)) ! ...internal thermal state if (damageState(material_homogenizationAt(e))%sizeState > 0) & - damageState(material_homogenizationAt(e))%subState0(:,mappingHomogenization(1,i,e)) = & - damageState(material_homogenizationAt(e))%State0( :,mappingHomogenization(1,i,e)) ! ...internal damage state + damageState(material_homogenizationAt(e))%subState0(:,material_homogenizationMemberAt(i,e)) = & + damageState(material_homogenizationAt(e))%State0( :,material_homogenizationMemberAt(i,e)) ! ...internal damage state enddo enddo @@ -313,14 +313,14 @@ subroutine materialpoint_stressAndItsTangent(updateJaco,dt) enddo if(homogState(material_homogenizationAt(e))%sizeState > 0) & - homogState(material_homogenizationAt(e))%subState0(:,mappingHomogenization(1,i,e)) = & - homogState(material_homogenizationAt(e))%State (:,mappingHomogenization(1,i,e)) + homogState(material_homogenizationAt(e))%subState0(:,material_homogenizationMemberAt(i,e)) = & + homogState(material_homogenizationAt(e))%State (:,material_homogenizationMemberAt(i,e)) if(thermalState(material_homogenizationAt(e))%sizeState > 0) & - thermalState(material_homogenizationAt(e))%subState0(:,mappingHomogenization(1,i,e)) = & - thermalState(material_homogenizationAt(e))%State (:,mappingHomogenization(1,i,e)) + thermalState(material_homogenizationAt(e))%subState0(:,material_homogenizationMemberAt(i,e)) = & + thermalState(material_homogenizationAt(e))%State (:,material_homogenizationMemberAt(i,e)) if(damageState(material_homogenizationAt(e))%sizeState > 0) & - damageState(material_homogenizationAt(e))%subState0(:,mappingHomogenization(1,i,e)) = & - damageState(material_homogenizationAt(e))%State (:,mappingHomogenization(1,i,e)) + damageState(material_homogenizationAt(e))%subState0(:,material_homogenizationMemberAt(i,e)) = & + damageState(material_homogenizationAt(e))%State (:,material_homogenizationMemberAt(i,e)) materialpoint_subF0(1:3,1:3,i,e) = materialpoint_subF(1:3,1:3,i,e) @@ -375,14 +375,14 @@ subroutine materialpoint_stressAndItsTangent(updateJaco,dt) enddo enddo if(homogState(material_homogenizationAt(e))%sizeState > 0) & - homogState(material_homogenizationAt(e))%State( :,mappingHomogenization(1,i,e)) = & - homogState(material_homogenizationAt(e))%subState0(:,mappingHomogenization(1,i,e)) + homogState(material_homogenizationAt(e))%State( :,material_homogenizationMemberAt(i,e)) = & + homogState(material_homogenizationAt(e))%subState0(:,material_homogenizationMemberAt(i,e)) if(thermalState(material_homogenizationAt(e))%sizeState > 0) & - thermalState(material_homogenizationAt(e))%State( :,mappingHomogenization(1,i,e)) = & - thermalState(material_homogenizationAt(e))%subState0(:,mappingHomogenization(1,i,e)) + thermalState(material_homogenizationAt(e))%State( :,material_homogenizationMemberAt(i,e)) = & + thermalState(material_homogenizationAt(e))%subState0(:,material_homogenizationMemberAt(i,e)) if(damageState(material_homogenizationAt(e))%sizeState > 0) & - damageState(material_homogenizationAt(e))%State( :,mappingHomogenization(1,i,e)) = & - damageState(material_homogenizationAt(e))%subState0(:,mappingHomogenization(1,i,e)) + damageState(material_homogenizationAt(e))%State( :,material_homogenizationMemberAt(i,e)) = & + damageState(material_homogenizationAt(e))%subState0(:,material_homogenizationMemberAt(i,e)) endif endif converged diff --git a/src/homogenization_mech_RGC.f90 b/src/homogenization_mech_RGC.f90 index c493c4190..ec9b94df9 100644 --- a/src/homogenization_mech_RGC.f90 +++ b/src/homogenization_mech_RGC.f90 @@ -108,7 +108,7 @@ module subroutine mech_RGC_init #ifdef DEBUG if (h==material_homogenizationAt(debug_e)) then - prm%of_debug = mappingHomogenization(1,debug_i,debug_e) + prm%of_debug = material_homogenizationMemberAt(debug_i,debug_e) endif #endif @@ -261,7 +261,7 @@ module procedure mech_RGC_updateState endif zeroTimeStep instance = homogenization_typeInstance(material_homogenizationAt(el)) - of = mappingHomogenization(1,ip,el) + of = material_homogenizationMemberAt(ip,el) associate(stt => state(instance), st0 => state0(instance), dst => dependentState(instance), prm => param(instance)) diff --git a/src/material.f90 b/src/material.f90 index a4494ed6e..1d756f7f6 100644 --- a/src/material.f90 +++ b/src/material.f90 @@ -113,11 +113,9 @@ module material phase_Nsources, & !< number of source mechanisms active in each phase phase_Nkinematics, & !< number of kinematic mechanisms active in each phase phase_NstiffnessDegradations, & !< number of stiffness degradation mechanisms active in each phase - phase_Noutput, & !< number of '(output)' items per phase phase_elasticityInstance, & !< instance of particular elasticity of each phase phase_plasticityInstance, & !< instance of particular plasticity of each phase homogenization_Ngrains, & !< number of grains in each homogenization - homogenization_Noutput, & !< number of '(output)' items per homogenization homogenization_typeInstance, & !< instance of particular type of each homogenization thermal_typeInstance, & !< instance of particular type of each thermal transport damage_typeInstance !< instance of particular type of each nonlocal damage @@ -129,7 +127,7 @@ module material ! NEW MAPPINGS integer, dimension(:), allocatable, public, protected :: & ! (elem) material_homogenizationAt !< homogenization ID of each element (copy of discretization_homogenizationAt) - integer, dimension(:,:), allocatable, public, protected :: & ! (ip,elem) + integer, dimension(:,:), allocatable, public, target :: & ! (ip,elem) ToDo: ugly target for mapping hack material_homogenizationMemberAt !< position of the element within its homogenization instance integer, dimension(:,:), allocatable, public, protected :: & ! (constituent,elem) material_phaseAt !< phase ID of each element @@ -177,7 +175,6 @@ module material homogenization_active ! BEGIN DEPRECATED - integer, dimension(:,:,:), allocatable, public, target :: mappingHomogenization !< mapping from material points to offset in heterogenous state/field integer, dimension(:,:), allocatable, private, target :: mappingHomogenizationConst !< mapping from material points to offset in constant state/field ! END DEPRECATED @@ -362,18 +359,8 @@ subroutine material_init !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! BEGIN DEPRECATED - allocate(mappingHomogenization (2,discretization_nIP,discretization_nElem),source=0) allocate(mappingHomogenizationConst( discretization_nIP,discretization_nElem),source=1) - - CounterHomogenization=0 - do e = 1,discretization_nElem - myHomog = discretization_homogenizationAt(e) - do i = 1, discretization_nIP - CounterHomogenization(myHomog) = CounterHomogenization(myHomog) + 1 - mappingHomogenization(1:2,i,e) = [CounterHomogenization(myHomog),huge(1)] - enddo - enddo - + ! hack needed to initialize field values used during constitutive and crystallite initializations do myHomog = 1,size(config_homogenization) thermalMapping (myHomog)%p => mappingHomogenizationConst @@ -401,7 +388,6 @@ subroutine material_parseHomogenization allocate(thermal_typeInstance(size(config_homogenization)), source=0) allocate(damage_typeInstance(size(config_homogenization)), source=0) allocate(homogenization_Ngrains(size(config_homogenization)), source=0) - allocate(homogenization_Noutput(size(config_homogenization)), source=0) allocate(homogenization_active(size(config_homogenization)), source=.false.) !!!!!!!!!!!!!!! allocate(thermal_initialT(size(config_homogenization)), source=300.0_pReal) allocate(damage_initialPhi(size(config_homogenization)), source=1.0_pReal) @@ -411,7 +397,6 @@ subroutine material_parseHomogenization do h=1, size(config_homogenization) - homogenization_Noutput(h) = config_homogenization(h)%countKeys('(output)') tag = config_homogenization(h)%getString('mech') select case (trim(tag)) @@ -548,11 +533,9 @@ subroutine material_parsePhase allocate(phase_Nsources(size(config_phase)), source=0) allocate(phase_Nkinematics(size(config_phase)), source=0) allocate(phase_NstiffnessDegradations(size(config_phase)),source=0) - allocate(phase_Noutput(size(config_phase)), source=0) allocate(phase_localPlasticity(size(config_phase)), source=.false.) do p=1, size(config_phase) - phase_Noutput(p) = config_phase(p)%countKeys('(output)') phase_Nsources(p) = config_phase(p)%countKeys('(source)') phase_Nkinematics(p) = config_phase(p)%countKeys('(kinematics)') phase_NstiffnessDegradations(p) = config_phase(p)%countKeys('(stiffness_degradation)') diff --git a/src/thermal_adiabatic.f90 b/src/thermal_adiabatic.f90 index d96604e59..c6c18a60e 100644 --- a/src/thermal_adiabatic.f90 +++ b/src/thermal_adiabatic.f90 @@ -77,7 +77,7 @@ subroutine thermal_adiabatic_init allocate(thermalState(h)%state (1,NofMyHomog), source=thermal_initialT(h)) nullify(thermalMapping(h)%p) - thermalMapping(h)%p => mappingHomogenization(1,:,:) + thermalMapping(h)%p => material_homogenizationMemberAt deallocate(temperature(h)%p) temperature(h)%p => thermalState(h)%state(1,:) deallocate(temperatureRate(h)%p) @@ -109,7 +109,7 @@ function thermal_adiabatic_updateState(subdt, ip, el) T, Tdot, dTdot_dT homog = material_homogenizationAt(el) - offset = mappingHomogenization(1,ip,el) + offset = material_homogenizationMemberAt(ip,el) T = thermalState(homog)%subState0(1,offset) call thermal_adiabatic_getSourceAndItsTangent(Tdot, dTdot_dT, T, ip, el) diff --git a/src/thermal_conduction.f90 b/src/thermal_conduction.f90 index 537b0366b..b182f21ac 100644 --- a/src/thermal_conduction.f90 +++ b/src/thermal_conduction.f90 @@ -79,7 +79,7 @@ subroutine thermal_conduction_init allocate(thermalState(h)%state (0,NofMyHomog)) nullify(thermalMapping(h)%p) - thermalMapping(h)%p => mappingHomogenization(1,:,:) + thermalMapping(h)%p => material_homogenizationMemberAt deallocate(temperature (h)%p) allocate (temperature (h)%p(NofMyHomog), source=thermal_initialT(h)) deallocate(temperatureRate(h)%p) @@ -114,7 +114,7 @@ subroutine thermal_conduction_getSourceAndItsTangent(Tdot, dTdot_dT, T, ip, el) constituent homog = material_homogenizationAt(el) - offset = mappingHomogenization(1,ip,el) + offset = material_homogenizationMemberAt(ip,el) instance = thermal_typeInstance(homog) Tdot = 0.0_pReal From f0ad18102daf89cfceca80f15d6524afde3e285b Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 23 Jan 2020 13:49:12 +0100 Subject: [PATCH 3/4] preparing to clean FEsolving should not have solver dependent functionality --- src/FEsolving.f90 | 26 ++++++++++++++++++++++++-- src/IO.f90 | 4 ++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/FEsolving.f90 b/src/FEsolving.f90 index 070b05a28..bb2fe04ed 100644 --- a/src/FEsolving.f90 +++ b/src/FEsolving.f90 @@ -47,8 +47,7 @@ subroutine FE_init status='old', position='rewind', action='read',iostat=myStat) do read (fileUnit,'(A)',END=100) line - chunkPos = IO_stringPos(line) - if(IO_lc(IO_stringValue(line,chunkPos,1)) == 'solver') then + if(index(trim(lc(line)),'solver') == 1) then read (fileUnit,'(A)',END=100) line ! next line chunkPos = IO_stringPos(line) symmetricSolver = (IO_intValue(line,chunkPos,2) /= 1) @@ -56,6 +55,29 @@ subroutine FE_init enddo 100 close(fileUnit) end block + contains + + !-------------------------------------------------------------------------------------------------- + !> @brief changes characters in string to lower case + !> @details copied from IO_lc + !-------------------------------------------------------------------------------------------------- + function lc(string) + + character(len=*), intent(in) :: string !< string to convert + character(len=len(string)) :: lc + + character(26), parameter :: LOWER = 'abcdefghijklmnopqrstuvwxyz' + character(26), parameter :: UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + + integer :: i,n + + do i=1,len(string) + lc(i:i) = string(i:i) + n = index(UPPER,lc(i:i)) + if (n/=0) lc(i:i) = LOWER(n:n) + enddo + end function lc + #endif end subroutine FE_init diff --git a/src/IO.f90 b/src/IO.f90 index 867173a52..a0ba1e07d 100644 --- a/src/IO.f90 +++ b/src/IO.f90 @@ -452,10 +452,10 @@ pure function IO_lc(string) character(26), parameter :: LOWER = 'abcdefghijklmnopqrstuvwxyz' character(26), parameter :: UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' - integer :: i,n + integer :: i,n - IO_lc = string do i=1,len(string) + IO_lc(i:i) = string(i:i) n = index(UPPER,IO_lc(i:i)) if (n/=0) IO_lc(i:i) = LOWER(n:n) enddo From b807406a7004fbfbaad1f920e293aab216ffa0fe Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 23 Jan 2020 14:00:56 +0100 Subject: [PATCH 4/4] avoid public variables --- src/material.f90 | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/material.f90 b/src/material.f90 index 1d756f7f6..560f8d1ec 100644 --- a/src/material.f90 +++ b/src/material.f90 @@ -151,12 +151,8 @@ module material material_orientation0 !< initial orientation of each grain,IP,element logical, dimension(:), allocatable, public, protected :: & - microstructure_active, & phase_localPlasticity !< flags phases with local constitutive law - integer, private :: & - microstructure_maxNconstituents !< max number of constituents in any phase - integer, dimension(:), allocatable, private :: & microstructure_Nconstituents !< number of constituents in each microstructure @@ -168,11 +164,7 @@ module material material_Eulers type(Rotation), dimension(:), allocatable, private :: & texture_orientation !< Euler angles in material.config (possibly rotated for alignment) - real(pReal), dimension(:,:), allocatable, private :: & - microstructure_fraction !< vol fraction of each constituent in microstructure - logical, dimension(:), allocatable, private :: & - homogenization_active ! BEGIN DEPRECATED integer, dimension(:,:), allocatable, private, target :: mappingHomogenizationConst !< mapping from material points to offset in constant state/field @@ -291,9 +283,8 @@ subroutine material_init microstructure_Nconstituents(m) if (microstructure_Nconstituents(m) > 0) then do c = 1,microstructure_Nconstituents(m) - write(6,'(a1,1x,a32,1x,a32,1x,f7.4)') '>',config_name_phase(microstructure_phase(c,m)),& - config_name_texture(microstructure_texture(c,m)),& - microstructure_fraction(c,m) + write(6,'(a1,1x,a32,1x,a32)') '>',config_name_phase(microstructure_phase(c,m)),& + config_name_texture(microstructure_texture(c,m)) enddo write(6,*) endif @@ -380,6 +371,8 @@ subroutine material_parseHomogenization integer :: h character(len=pStringLen) :: tag + + logical, dimension(:), allocatable :: homogenization_active allocate(homogenization_type(size(config_homogenization)), source=HOMOGENIZATION_undefined_ID) allocate(thermal_type(size(config_homogenization)), source=THERMAL_isothermal_ID) @@ -473,16 +466,16 @@ subroutine material_parseMicrostructure integer :: e, m, c, i character(len=pStringLen) :: & tag + real(pReal), dimension(:,:), allocatable :: & + microstructure_fraction !< vol fraction of each constituent in microstructure + integer :: & + microstructure_maxNconstituents !< max number of constituents in any phase allocate(microstructure_Nconstituents(size(config_microstructure)), source=0) - allocate(microstructure_active(size(config_microstructure)), source=.false.) if(any(discretization_microstructureAt > size(config_microstructure))) & call IO_error(155,ext_msg='More microstructures in geometry than sections in material.config') - forall (e = 1:discretization_nElem) & - microstructure_active(discretization_microstructureAt(e)) = .true. ! current microstructure used in model? Elementwise view, maximum N operations for N elements - do m=1, size(config_microstructure) microstructure_Nconstituents(m) = config_microstructure(m)%countKeys('(constituent)') enddo