From 8700d7784c3ca8d2fec6de2fd1103db3dbb322fe Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 29 Feb 2020 11:10:23 +0100 Subject: [PATCH] avoid global variables --- src/kinematics_thermal_expansion.f90 | 32 +++++++++++++++++----------- src/lattice.f90 | 5 +---- src/source_thermal_externalheat.f90 | 2 +- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/kinematics_thermal_expansion.f90 b/src/kinematics_thermal_expansion.f90 index faf72b344..7a57e9614 100644 --- a/src/kinematics_thermal_expansion.f90 +++ b/src/kinematics_thermal_expansion.f90 @@ -18,6 +18,8 @@ module kinematics_thermal_expansion integer, dimension(:), allocatable :: kinematics_thermal_expansion_instance type :: tParameters + real(pReal) :: & + T_ref real(pReal), allocatable, dimension(:,:,:) :: & expansion end type tParameters @@ -54,8 +56,11 @@ subroutine kinematics_thermal_expansion_init do p = 1, size(config_phase) kinematics_thermal_expansion_instance(p) = count(phase_kinematics(:,1:p) == KINEMATICS_thermal_expansion_ID) if (all(phase_kinematics(:,p) /= KINEMATICS_thermal_expansion_ID)) cycle - associate(config => config_phase(p)) + associate(prm => param(kinematics_thermal_expansion_instance(p)), & + config => config_phase(p)) + + prm%T_ref = config%getFloat('reference_temperature', defaultVal=0.0_pReal) ! read up to three parameters (constant, linear, quadratic with T) temp = config%getFloats('thermal_expansion11') !lattice_thermalExpansion33(1,1,1:size(temp),p) = temp @@ -82,13 +87,15 @@ pure function kinematics_thermal_expansion_initialStrain(homog,phase,offset) real(pReal), dimension(3,3) :: & kinematics_thermal_expansion_initialStrain !< initial thermal strain (should be small strain, though) + associate(prm => param(kinematics_thermal_expansion_instance(phase))) kinematics_thermal_expansion_initialStrain = & - (temperature(homog)%p(offset) - lattice_referenceTemperature(phase))**1 / 1. * & + (temperature(homog)%p(offset) - prm%T_ref)**1 / 1. * & lattice_thermalExpansion33(1:3,1:3,1,phase) + & ! constant coefficient - (temperature(homog)%p(offset) - lattice_referenceTemperature(phase))**2 / 2. * & + (temperature(homog)%p(offset) - prm%T_ref)**2 / 2. * & lattice_thermalExpansion33(1:3,1:3,2,phase) + & ! linear coefficient - (temperature(homog)%p(offset) - lattice_referenceTemperature(phase))**3 / 3. * & + (temperature(homog)%p(offset) - prm%T_ref)**3 / 3. * & lattice_thermalExpansion33(1:3,1:3,3,phase) ! quadratic coefficient + end associate end function kinematics_thermal_expansion_initialStrain @@ -111,24 +118,25 @@ subroutine kinematics_thermal_expansion_LiAndItsTangent(Li, dLi_dTstar, ipc, ip, phase, & homog real(pReal) :: & - T, TRef, TDot + T, TDot phase = material_phaseAt(ipc,el) homog = material_homogenizationAt(el) T = temperature(homog)%p(thermalMapping(homog)%p(ip,el)) TDot = temperatureRate(homog)%p(thermalMapping(homog)%p(ip,el)) - TRef = lattice_referenceTemperature(phase) + associate(prm => param(kinematics_thermal_expansion_instance(phase))) Li = TDot * ( & - lattice_thermalExpansion33(1:3,1:3,1,phase)*(T - TRef)**0 & ! constant coefficient - + lattice_thermalExpansion33(1:3,1:3,2,phase)*(T - TRef)**1 & ! linear coefficient - + lattice_thermalExpansion33(1:3,1:3,3,phase)*(T - TRef)**2 & ! quadratic coefficient + lattice_thermalExpansion33(1:3,1:3,1,phase)*(T - prm%T_ref)**0 & ! constant coefficient + + lattice_thermalExpansion33(1:3,1:3,2,phase)*(T - prm%T_ref)**1 & ! linear coefficient + + lattice_thermalExpansion33(1:3,1:3,3,phase)*(T - prm%T_ref)**2 & ! quadratic coefficient ) / & (1.0_pReal & - + lattice_thermalExpansion33(1:3,1:3,1,phase)*(T - TRef)**1 / 1. & - + lattice_thermalExpansion33(1:3,1:3,2,phase)*(T - TRef)**2 / 2. & - + lattice_thermalExpansion33(1:3,1:3,3,phase)*(T - TRef)**3 / 3. & + + lattice_thermalExpansion33(1:3,1:3,1,phase)*(T - prm%T_ref)**1 / 1. & + + lattice_thermalExpansion33(1:3,1:3,2,phase)*(T - prm%T_ref)**2 / 2. & + + lattice_thermalExpansion33(1:3,1:3,3,phase)*(T - prm%T_ref)**3 / 3. & ) + end associate dLi_dTstar = 0.0_pReal end subroutine kinematics_thermal_expansion_LiAndItsTangent diff --git a/src/lattice.f90 b/src/lattice.f90 index df52825c4..cb31c3935 100644 --- a/src/lattice.f90 +++ b/src/lattice.f90 @@ -395,8 +395,7 @@ module lattice real(pReal), dimension(:), allocatable, public, protected :: & lattice_damageMobility, & lattice_massDensity, & - lattice_specificHeat, & - lattice_referenceTemperature + lattice_specificHeat ! SHOULD NOT BE PART OF LATTICE END enum, bind(c) @@ -476,7 +475,6 @@ subroutine lattice_init allocate(lattice_damageMobility ( Nphases), source=0.0_pReal) allocate(lattice_massDensity ( Nphases), source=0.0_pReal) allocate(lattice_specificHeat ( Nphases), source=0.0_pReal) - allocate(lattice_referenceTemperature ( Nphases), source=300.0_pReal) allocate(lattice_mu(Nphases), source=0.0_pReal) allocate(lattice_nu(Nphases), source=0.0_pReal) @@ -539,7 +537,6 @@ subroutine lattice_init lattice_specificHeat(p) = config_phase(p)%getFloat( 'specific_heat',defaultVal=0.0_pReal) lattice_massDensity(p) = config_phase(p)%getFloat( 'mass_density',defaultVal=0.0_pReal) - lattice_referenceTemperature(p) = config_phase(p)%getFloat( 'reference_temperature',defaultVal=0.0_pReal) lattice_DamageDiffusion33(1,1,p) = config_phase(p)%getFloat( 'damage_diffusion11',defaultVal=0.0_pReal) lattice_DamageDiffusion33(2,2,p) = config_phase(p)%getFloat( 'damage_diffusion22',defaultVal=0.0_pReal) lattice_DamageDiffusion33(3,3,p) = config_phase(p)%getFloat( 'damage_diffusion33',defaultVal=0.0_pReal) diff --git a/src/source_thermal_externalheat.f90 b/src/source_thermal_externalheat.f90 index 1cf69b8a5..0380a2be3 100644 --- a/src/source_thermal_externalheat.f90 +++ b/src/source_thermal_externalheat.f90 @@ -60,7 +60,7 @@ subroutine source_thermal_externalheat_init do sourceOffset = 1, phase_Nsources(p) if (phase_source(sourceOffset,p) == SOURCE_thermal_externalheat_ID) then source_thermal_externalheat_offset(p) = sourceOffset - exit + exit endif enddo