From 6c2ab1f1f8745ea6a7f7f15a7dfb4aa8f1bfa076 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 27 Nov 2013 11:39:28 +0000 Subject: [PATCH] added ID (integer, enum) case switching for phenopowerlaw and isostrain --- code/constitutive_phenopowerlaw.f90 | 84 +++++++++++++++++++++-------- code/homogenization_isostrain.f90 | 70 +++++++++++++++++------- 2 files changed, 112 insertions(+), 42 deletions(-) diff --git a/code/constitutive_phenopowerlaw.f90 b/code/constitutive_phenopowerlaw.f90 index 529b218db..4dc2db523 100644 --- a/code/constitutive_phenopowerlaw.f90 +++ b/code/constitutive_phenopowerlaw.f90 @@ -93,7 +93,21 @@ module constitutive_phenopowerlaw constitutive_phenopowerlaw_hardeningMatrix_TwinSlip, & constitutive_phenopowerlaw_hardeningMatrix_TwinTwin, & constitutive_phenopowerlaw_Cslip_66 - + enum, bind(c) + enumerator :: resistance_slip_ID, & + accumulatedshear_slip_ID, & + shearrate_slip_ID, & + resolvedstress_slip_ID, & + totalshear_ID, & + resistance_twin_ID, & + accumulatedshear_twin_ID, & + shearrate_twin_ID, & + resolvedstress_twin_ID, & + totalvolfrac_ID + end enum + integer(kind(resistance_slip_ID)), dimension(:,:), allocatable, private :: & + constitutive_phenopowerlaw_outputID !< ID of each post result output + public :: & constitutive_phenopowerlaw_init, & constitutive_phenopowerlaw_stateInit, & @@ -171,6 +185,8 @@ subroutine constitutive_phenopowerlaw_init(myFile) constitutive_phenopowerlaw_sizePostResult = 0_pInt allocate(constitutive_phenopowerlaw_output(maxval(phase_Noutput),maxNinstance)) constitutive_phenopowerlaw_output = '' + allocate(constitutive_phenopowerlaw_outputID(maxval(phase_Noutput),maxNinstance)) + constitutive_phenopowerlaw_outputID = -1 allocate(constitutive_phenopowerlaw_Noutput(maxNinstance)) constitutive_phenopowerlaw_Noutput = 0_pInt allocate(constitutive_phenopowerlaw_structureName(maxNinstance)) @@ -264,6 +280,28 @@ subroutine constitutive_phenopowerlaw_init(myFile) constitutive_phenopowerlaw_Noutput(i) = constitutive_phenopowerlaw_Noutput(i) + 1_pInt constitutive_phenopowerlaw_output(constitutive_phenopowerlaw_Noutput(i),i) = & IO_lc(IO_stringValue(line,positions,2_pInt)) + select case(IO_lc(IO_stringValue(line,positions,2_pInt))) + case ('resistance_slip') + constitutive_phenopowerlaw_outputID(constitutive_phenopowerlaw_Noutput(i),i) = resistance_slip_ID + case ('accumulatedshear_slip') + constitutive_phenopowerlaw_outputID(constitutive_phenopowerlaw_Noutput(i),i) = accumulatedshear_slip_ID + case ('shearrate_slip') + constitutive_phenopowerlaw_outputID(constitutive_phenopowerlaw_Noutput(i),i) = shearrate_slip_ID + case ('resolvedstress_slip') + constitutive_phenopowerlaw_outputID(constitutive_phenopowerlaw_Noutput(i),i) = resolvedstress_slip_ID + case ('totalshear') + constitutive_phenopowerlaw_outputID(constitutive_phenopowerlaw_Noutput(i),i) = totalshear_ID + case ('resistance_twin') + constitutive_phenopowerlaw_outputID(constitutive_phenopowerlaw_Noutput(i),i) = resistance_twin_ID + case ('accumulatedshear_twin') + constitutive_phenopowerlaw_outputID(constitutive_phenopowerlaw_Noutput(i),i) = accumulatedshear_twin_ID + case ('shearrate_twin') + constitutive_phenopowerlaw_outputID(constitutive_phenopowerlaw_Noutput(i),i) = shearrate_twin_ID + case ('resolvedstress_twin') + constitutive_phenopowerlaw_outputID(constitutive_phenopowerlaw_Noutput(i),i) = resolvedstress_twin_ID + case ('totalvolfrac') + constitutive_phenopowerlaw_outputID(constitutive_phenopowerlaw_Noutput(i),i) = totalvolfrac_ID + end select case ('lattice_structure') constitutive_phenopowerlaw_structureName(i) = IO_lc(IO_stringValue(line,positions,2_pInt)) configNchunks = lattice_configNchunks(constitutive_phenopowerlaw_structureName(i)) @@ -476,21 +514,21 @@ subroutine constitutive_phenopowerlaw_init(myFile) instancesLoop: do i = 1_pInt,maxNinstance outputsLoop: do o = 1_pInt,constitutive_phenopowerlaw_Noutput(i) - select case(constitutive_phenopowerlaw_output(o,i)) - case('resistance_slip', & - 'shearrate_slip', & - 'accumulatedshear_slip', & - 'resolvedstress_slip' & + select case(constitutive_phenopowerlaw_outputID(o,i)) + case(resistance_slip_ID, & + shearrate_slip_ID, & + accumulatedshear_slip_ID, & + resolvedstress_slip_ID & ) mySize = constitutive_phenopowerlaw_totalNslip(i) - case('resistance_twin', & - 'shearrate_twin', & - 'accumulatedshear_twin', & - 'resolvedstress_twin' & + case(resistance_twin_ID, & + shearrate_twin_ID, & + accumulatedshear_twin_ID, & + resolvedstress_twin_ID & ) mySize = constitutive_phenopowerlaw_totalNtwin(i) - case('totalshear', & - 'totalvolfrac' & + case(totalshear_ID, & + totalvolfrac_ID & ) mySize = 1_pInt case default @@ -1053,17 +1091,17 @@ pure function constitutive_phenopowerlaw_postResults(Tstar_v,state,ipc,ip,el) c = 0_pInt outputsLoop: do o = 1_pInt,phase_Noutput(material_phase(ipc,ip,el)) - select case(constitutive_phenopowerlaw_output(o,matID)) - case ('resistance_slip') + select case(constitutive_phenopowerlaw_outputID(o,matID)) + case (resistance_slip_ID) constitutive_phenopowerlaw_postResults(c+1_pInt:c+nSlip) = state(ipc,ip,el)%p(1:nSlip) c = c + nSlip - case ('accumulatedshear_slip') + case (accumulatedshear_slip_ID) constitutive_phenopowerlaw_postResults(c+1_pInt:c+nSlip) = state(ipc,ip,el)%p(index_accshear_slip:& index_accshear_slip+nSlip) c = c + nSlip - case ('shearrate_slip') + case (shearrate_slip_ID) j = 0_pInt slipFamiliesLoop1: do f = 1_pInt,lattice_maxNslipFamily index_myFamily = sum(lattice_NslipSystem(1:f-1_pInt,structID)) ! at which index starts my family @@ -1085,7 +1123,7 @@ pure function constitutive_phenopowerlaw_postResults(Tstar_v,state,ipc,ip,el) enddo slipFamiliesLoop1 c = c + nSlip - case ('resolvedstress_slip') + case (resolvedstress_slip_ID) j = 0_pInt slipFamiliesLoop2: do f = 1_pInt,lattice_maxNslipFamily index_myFamily = sum(lattice_NslipSystem(1:f-1_pInt,structID)) ! at which index starts my family @@ -1097,22 +1135,22 @@ pure function constitutive_phenopowerlaw_postResults(Tstar_v,state,ipc,ip,el) enddo slipFamiliesLoop2 c = c + nSlip - case ('totalshear') + case (totalshear_ID) constitutive_phenopowerlaw_postResults(c+1_pInt) = & state(ipc,ip,el)%p(index_Gamma) c = c + 1_pInt - case ('resistance_twin') + case (resistance_twin_ID) constitutive_phenopowerlaw_postResults(c+1_pInt:c+nTwin) = & state(ipc,ip,el)%p(1_pInt+nSlip:nTwin+nSlip) c = c + nTwin - case ('accumulatedshear_twin') + case (accumulatedshear_twin_ID) constitutive_phenopowerlaw_postResults(c+1_pInt:c+nTwin) = & state(ipc,ip,el)%p(index_accshear_twin:index_accshear_twin+nTwin) c = c + nTwin - case ('shearrate_twin') + case (shearrate_twin_ID) j = 0_pInt twinFamiliesLoop1: do f = 1_pInt,lattice_maxNtwinFamily index_myFamily = sum(lattice_NtwinSystem(1:f-1_pInt,structID)) ! at which index starts my family @@ -1127,7 +1165,7 @@ pure function constitutive_phenopowerlaw_postResults(Tstar_v,state,ipc,ip,el) enddo twinFamiliesLoop1 c = c + nTwin - case ('resolvedstress_twin') + case (resolvedstress_twin_ID) j = 0_pInt twinFamiliesLoop2: do f = 1_pInt,lattice_maxNtwinFamily index_myFamily = sum(lattice_NtwinSystem(1:f-1_pInt,structID)) ! at which index starts my family @@ -1139,7 +1177,7 @@ pure function constitutive_phenopowerlaw_postResults(Tstar_v,state,ipc,ip,el) enddo twinFamiliesLoop2 c = c + nTwin - case ('totalvolfrac') + case (totalvolfrac_ID) constitutive_phenopowerlaw_postResults(c+1_pInt) = state(ipc,ip,el)%p(index_F) c = c + 1_pInt diff --git a/code/homogenization_isostrain.f90 b/code/homogenization_isostrain.f90 index ce008631c..c94d0511d 100644 --- a/code/homogenization_isostrain.f90 +++ b/code/homogenization_isostrain.f90 @@ -37,10 +37,22 @@ module homogenization_isostrain character(len=64), dimension(:,:), allocatable, target, public :: & homogenization_isostrain_output !< name of each post result output - character(len=64), dimension(:), allocatable, private :: & - homogenization_isostrain_mapping integer(pInt), dimension(:), allocatable, private :: & homogenization_isostrain_Ngrains + enum, bind(c) + enumerator :: ncomponents, & + temperature, & + ipcoords, & + avgdefgrad, & + avgfirstpiola + enumerator :: parallel, & + average + end enum + integer(kind(ncomponents)), dimension(:,:), allocatable, private :: & + homogenization_isostrain_outputID !< ID of each post result output + integer(kind(average)), dimension(:), allocatable, private :: & + homogenization_isostrain_mapping !< ID of each post result output + public :: & homogenization_isostrain_init, & @@ -90,9 +102,11 @@ subroutine homogenization_isostrain_init(myUnit) allocate(homogenization_isostrain_Ngrains(maxNinstance)) homogenization_isostrain_Ngrains = 0_pInt allocate(homogenization_isostrain_mapping(maxNinstance)) - homogenization_isostrain_mapping = 'avg' + homogenization_isostrain_mapping = average allocate(homogenization_isostrain_output(maxval(homogenization_Noutput),maxNinstance)) homogenization_isostrain_output = '' + allocate(homogenization_isostrain_outputID(maxval(homogenization_Noutput),maxNinstance)) + homogenization_isostrain_outputID = -1 rewind(myUnit) section = 0_pInt @@ -118,10 +132,31 @@ subroutine homogenization_isostrain_init(myUnit) case ('(output)') output = output + 1_pInt homogenization_isostrain_output(output,i) = IO_lc(IO_stringValue(line,positions,2_pInt)) + select case(homogenization_isostrain_output(output,i)) + case('ngrains','ncomponents') + homogenization_isostrain_outputID(output,i) = ncomponents + case('temperature') + homogenization_isostrain_outputID(output,i) = temperature + case('ipcoords') + homogenization_isostrain_outputID(output,i) = ipcoords + case('avgdefgrad','avgf') + homogenization_isostrain_outputID(output,i) = avgdefgrad + case('avgp','avgfirstpiola','avg1stpiola') + homogenization_isostrain_outputID(output,i) = avgfirstpiola + case default + mySize = 0_pInt + end select case ('ngrains','ncomponents') homogenization_isostrain_Ngrains(i) = IO_intValue(line,positions,2_pInt) case ('mapping') - homogenization_isostrain_mapping(i) = IO_lc(IO_stringValue(line,positions,2_pInt)) + select case(IO_lc(IO_stringValue(line,positions,2_pInt))) + case ('parallel','sum') + homogenization_isostrain_mapping(i) = parallel + case ('average','mean','avg') + homogenization_isostrain_mapping(i) = average + case default + print*, 'There should be an error here' + end select end select endif endif @@ -131,12 +166,12 @@ subroutine homogenization_isostrain_init(myUnit) homogenization_isostrain_sizeState(i) = 0_pInt do j = 1_pInt,maxval(homogenization_Noutput) - select case(homogenization_isostrain_output(j,i)) - case('ngrains','ncomponents','temperature') + select case(homogenization_isostrain_outputID(j,i)) + case(ncomponents, temperature) mySize = 1_pInt - case('ipcoords') + case(ipcoords) mySize = 3_pInt - case('avgdefgrad','avgf','avgp','avgfirstpiola','avg1stpiola') + case(avgdefgrad, avgfirstpiola) mySize = 9_pInt case default mySize = 0_pInt @@ -203,13 +238,10 @@ subroutine homogenization_isostrain_averageStressAndItsTangent(avgP,dAvgPdAvgF,P Ngrains = homogenization_Ngrains(mesh_element(3,el)) select case (homogenization_isostrain_mapping(homID)) - case ('parallel','sum') + case (parallel) avgP = sum(P,3) dAvgPdAvgF = sum(dPdF,5) - case ('average','mean','avg') - avgP = sum(P,3) /real(Ngrains,pReal) - dAvgPdAvgF = sum(dPdF,5)/real(Ngrains,pReal) - case default + case (average) avgP = sum(P,3) /real(Ngrains,pReal) dAvgPdAvgF = sum(dPdF,5)/real(Ngrains,pReal) end select @@ -252,20 +284,20 @@ pure function homogenization_isostrain_postResults(ip,el,avgP,avgF) homogenization_isostrain_postResults = 0.0_pReal do o = 1_pInt,homogenization_Noutput(mesh_element(3,el)) - select case(homogenization_isostrain_output(o,homID)) - case ('ngrains','ncomponents') + select case(homogenization_isostrain_outputID(o,homID)) + case (ncomponents) homogenization_isostrain_postResults(c+1_pInt) = real(homogenization_isostrain_Ngrains(homID),pReal) c = c + 1_pInt - case ('temperature') + case (temperature) homogenization_isostrain_postResults(c+1_pInt) = crystallite_temperature(ip,el) c = c + 1_pInt - case ('avgdefgrad','avgf') + case (avgdefgrad) homogenization_isostrain_postResults(c+1_pInt:c+9_pInt) = reshape(avgF,[9]) c = c + 9_pInt - case ('avgp','avgfirstpiola','avg1stpiola') + case (avgfirstpiola) homogenization_isostrain_postResults(c+1_pInt:c+9_pInt) = reshape(avgP,[9]) c = c + 9_pInt - case ('ipcoords') + case (ipcoords) homogenization_isostrain_postResults(c+1_pInt:c+3_pInt) = mesh_ipCoordinates(1:3,ip,el) ! current ip coordinates c = c + 3_pInt end select