From fdbbb94aacadbddb40e4c4854c2b197fbb13b692 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 26 Mar 2020 21:46:28 +0100 Subject: [PATCH] takeover from RKCK45 --- src/crystallite.f90 | 172 ++++++++++++++++++++++++++++++++++---------- src/material.f90 | 4 +- src/prec.f90 | 12 ++-- 3 files changed, 142 insertions(+), 46 deletions(-) diff --git a/src/crystallite.f90 b/src/crystallite.f90 index ea7442a30..30b2920f1 100644 --- a/src/crystallite.f90 +++ b/src/crystallite.f90 @@ -1346,55 +1346,151 @@ end subroutine integrateStateAdaptiveEuler !-------------------------------------------------------------------------------------------------- subroutine integrateStateRK4 + real(pReal), dimension(3,3), parameter :: & + A = reshape([& + 0.5_pReal, 0.0_pReal, 0.0_pReal, & + 0.0_pReal, 0.5_pReal, 0.0_pReal, & + 0.0_pReal, 0.0_pReal, 1.0_pReal], & + [3,3]) + real(pReal), dimension(3), parameter :: & + CC = [0.5_pReal, 0.5_pReal, 1.0_pReal] ! factor giving the fraction of the original timestep used for Runge Kutta Integration real(pReal), dimension(4), parameter :: & - CC = [0.5_pReal, 0.5_pReal, 1.0_pReal, 1.0_pReal] ! factor giving the fraction of the original timestep used for Runge Kutta Integration - real(pReal), dimension(4), parameter :: & - B = [1.0_pReal, 2.0_pReal, 2.0_pReal, 1.0_pReal/6.0_pReal] ! weight of slope used for Runge Kutta integration (final weight divided by 6) + B = [1.0_pReal/6.0_pReal, 1.0_pReal/3.0_pReal, 1.0_pReal/3.0_pReal, 1.0_pReal/6.0_pReal] ! weight of slope used for Runge Kutta integration (final weight divided by 6) - integer :: e, & ! element index in element loop - i, & ! integration point index in ip loop - g, & ! grain index in grain loop - p, & ! phase loop - c, & - n, & - s + integer :: & + e, & ! element index in element loop + i, & ! integration point index in ip loop + g, & ! grain index in grain loop + stage, & ! stage index in integration stage loop + n, & + p, & + c, & + s, & + sizeDotState + logical :: & + nonlocalBroken - call update_dotState(1.0_pReal) + nonlocalBroken = .false. + !$OMP PARALLEL DO PRIVATE(sizeDotState,p,c) + do e = FEsolving_execElem(1),FEsolving_execElem(2) + do i = FEsolving_execIP(1),FEsolving_execIP(2) + do g = 1,homogenization_Ngrains(material_homogenizationAt(e)) + if(crystallite_todo(g,i,e) .and. (.not. nonlocalBroken .or. crystallite_localPlasticity(g,i,e)) ) then + p = material_phaseAt(g,e); c = material_phaseMemberAt(g,i,e) - do n = 1,4 + call constitutive_collectDotState(crystallite_S(1:3,1:3,g,i,e), & + crystallite_partionedF0, & + crystallite_Fi(1:3,1:3,g,i,e), & + crystallite_partionedFp0, & + crystallite_subdt(g,i,e), g,i,e) + crystallite_todo(g,i,e) = all(.not. IEEE_is_NaN(plasticState(p)%dotState(:,c))) + do s = 1, phase_Nsources(p) + crystallite_todo(g,i,e) = crystallite_todo(g,i,e) .and. all(.not. IEEE_is_NaN(sourceState(p)%p(s)%dotState(:,c))) + enddo + if(.not. (crystallite_todo(g,i,e) .or. crystallite_localPlasticity(g,i,e))) & + nonlocalBroken = .true. + if(.not. crystallite_todo(g,i,e)) cycle - !$OMP PARALLEL DO PRIVATE(p,c) - do e = FEsolving_execElem(1),FEsolving_execElem(2) - do i = FEsolving_execIP(1),FEsolving_execIP(2) - do g = 1,homogenization_Ngrains(material_homogenizationAt(e)) - if (crystallite_todo(g,i,e)) then - p = material_phaseAt(g,e); c = material_phaseMemberAt(g,i,e) + do stage = 1,3 - plasticState(p)%RK4dotState(:,c) = B(n)*plasticState(p)%dotState(:,c) & - + merge(plasticState(p)%RK4dotState(:,c),0.0_pReal,n>1) - do s = 1, phase_Nsources(p) - sourceState(p)%p(s)%RK4dotState(:,c) = B(n)*sourceState(p)%p(s)%dotState(:,c) & - + merge(sourceState(p)%p(s)%RK4dotState(:,c),0.0_pReal,n>1) - enddo - endif - enddo; enddo; enddo - !$OMP END PARALLEL DO + plasticState(p)%RK4dotState(stage,:,c) = plasticState(p)%dotState(:,c) + plasticState(p)%dotState(:,c) = A(1,stage) * plasticState(p)%RK4dotState(1,:,c) + do s = 1, phase_Nsources(p) + sourceState(p)%p(s)%RK4dotState(stage,:,c) = sourceState(p)%p(s)%dotState(:,c) + sourceState(p)%p(s)%dotState(:,c) = A(1,stage) * sourceState(p)%p(s)%RK4dotState(1,:,c) + enddo - call update_state(CC(n)) - call update_deltaState - call update_dependentState - call update_stress(CC(n)) - ! --- dot state and RK dot state--- + do n = 2, stage + plasticState(p)%dotState(:,c) = plasticState(p)%dotState(:,c) & + + A(n,stage) * plasticState(p)%RK4dotState(n,:,c) + do s = 1, phase_Nsources(p) + sourceState(p)%p(s)%dotState(:,c) = sourceState(p)%p(s)%dotState(:,c) & + + A(n,stage) * sourceState(p)%p(s)%RK4dotState(n,:,c) + enddo + enddo - first3steps: if (n < 4) then - call update_dotState(CC(n)) - endif first3steps + sizeDotState = plasticState(p)%sizeDotState + plasticState(p)%state(1:sizeDotState,c) = plasticState(p)%subState0(1:sizeDotState,c) & + + plasticState(p)%dotState (1:sizeDotState,c) & + * crystallite_subdt(g,i,e) + do s = 1, phase_Nsources(p) + sizeDotState = sourceState(p)%p(s)%sizeDotState + sourceState(p)%p(s)%state(1:sizeDotState,c) = sourceState(p)%p(s)%subState0(1:sizeDotState,c) & + + sourceState(p)%p(s)%dotState (1:sizeDotState,c) & + * crystallite_subdt(g,i,e) + enddo - enddo + call constitutive_dependentState(crystallite_partionedF(1:3,1:3,g,i,e), & + crystallite_Fp(1:3,1:3,g,i,e), & + g, i, e) - call setConvergenceFlag - if (any(plasticState(:)%nonlocal)) call nonlocalConvergenceCheck + crystallite_todo(g,i,e) = integrateStress(g,i,e,CC(stage)) + if(.not. (crystallite_todo(g,i,e) .or. crystallite_localPlasticity(g,i,e))) & + nonlocalBroken = .true. + if(.not. crystallite_todo(g,i,e)) exit + + call constitutive_collectDotState(crystallite_S(1:3,1:3,g,i,e), & + crystallite_partionedF0, & + crystallite_Fi(1:3,1:3,g,i,e), & + crystallite_partionedFp0, & + crystallite_subdt(g,i,e)*CC(stage), g,i,e) + crystallite_todo(g,i,e) = all(.not. IEEE_is_NaN(plasticState(p)%dotState(:,c))) + do s = 1, phase_Nsources(p) + crystallite_todo(g,i,e) = crystallite_todo(g,i,e) .and. all(.not. IEEE_is_NaN(sourceState(p)%p(s)%dotState(:,c))) + enddo + if(.not. (crystallite_todo(g,i,e) .or. crystallite_localPlasticity(g,i,e))) & + nonlocalBroken = .true. + if(.not. crystallite_todo(g,i,e)) exit + + enddo + + if(.not. crystallite_todo(g,i,e)) cycle + + sizeDotState = plasticState(p)%sizeDotState + + plasticState(p)%RK4dotState(4,:,c) = plasticState (p)%dotState(:,c) + + plasticState(p)%dotState(:,c) = matmul(B,plasticState(p)%RK4dotState(1:4,1:sizeDotState,c)) + plasticState(p)%state(1:sizeDotState,c) = plasticState(p)%subState0(1:sizeDotState,c) & + + plasticState(p)%dotState (1:sizeDotState,c) & + * crystallite_subdt(g,i,e) + + do s = 1, phase_Nsources(p) + sizeDotState = sourceState(p)%p(s)%sizeDotState + + sourceState(p)%p(s)%RK4dotState(4,:,c) = sourceState(p)%p(s)%dotState(:,c) + + sourceState(p)%p(s)%dotState(:,c) = matmul(B,sourceState(p)%p(s)%RK4dotState(1:4,1:sizeDotState,c)) + sourceState(p)%p(s)%state(1:sizeDotState,c) = sourceState(p)%p(s)%subState0(1:sizeDotState,c) & + + sourceState(p)%p(s)%dotState (1:sizeDotState,c) & + * crystallite_subdt(g,i,e) + enddo + + crystallite_todo(g,i,e) = stateJump(g,i,e) + if(.not. (crystallite_todo(g,i,e) .or. crystallite_localPlasticity(g,i,e))) & + nonlocalBroken = .true. + if(.not. crystallite_todo(g,i,e)) cycle + + call constitutive_dependentState(crystallite_partionedF(1:3,1:3,g,i,e), & + crystallite_Fp(1:3,1:3,g,i,e), & + g, i, e) + + if(.not. (crystallite_todo(g,i,e) .or. crystallite_localPlasticity(g,i,e))) & + nonlocalBroken = .true. + if(.not. crystallite_todo(g,i,e)) cycle + + crystallite_todo(g,i,e) = integrateStress(g,i,e) + if(.not. (crystallite_todo(g,i,e) .or. crystallite_localPlasticity(g,i,e))) & + nonlocalBroken = .true. + crystallite_converged(g,i,e) = crystallite_todo(g,i,e) ! consider converged if not broken + + endif + enddo; enddo; enddo + !$OMP END PARALLEL DO + + if(nonlocalBroken) where(.not. crystallite_localPlasticity) crystallite_todo = .false. + if (any(plasticState(:)%nonlocal)) call nonlocalConvergenceCheck end subroutine integrateStateRK4 diff --git a/src/material.f90 b/src/material.f90 index 14a16a2ed..4461ca958 100644 --- a/src/material.f90 +++ b/src/material.f90 @@ -729,7 +729,7 @@ subroutine material_allocatePlasticState(phase,NipcMyPhase,& allocate(plasticState(phase)%previousDotState2 (sizeDotState,NipcMyPhase),source=0.0_pReal) endif if (numerics_integrator == 4) & - allocate(plasticState(phase)%RK4dotState (sizeDotState,NipcMyPhase),source=0.0_pReal) + allocate(plasticState(phase)%RK4dotState (4,sizeDotState,NipcMyPhase),source=0.0_pReal) if (numerics_integrator == 5) & allocate(plasticState(phase)%RKCK45dotState (6,sizeDotState,NipcMyPhase),source=0.0_pReal) @@ -767,7 +767,7 @@ subroutine material_allocateSourceState(phase,of,NipcMyPhase,& allocate(sourceState(phase)%p(of)%previousDotState2 (sizeDotState,NipcMyPhase),source=0.0_pReal) endif if (numerics_integrator == 4) & - allocate(sourceState(phase)%p(of)%RK4dotState (sizeDotState,NipcMyPhase),source=0.0_pReal) + allocate(sourceState(phase)%p(of)%RK4dotState (4,sizeDotState,NipcMyPhase),source=0.0_pReal) if (numerics_integrator == 5) & allocate(sourceState(phase)%p(of)%RKCK45dotState (6,sizeDotState,NipcMyPhase),source=0.0_pReal) diff --git a/src/prec.f90 b/src/prec.f90 index b3e2c2747..a8d7d9e33 100644 --- a/src/prec.f90 +++ b/src/prec.f90 @@ -51,10 +51,10 @@ module prec real(pReal), allocatable, dimension(:,:) :: & partionedState0, & subState0, & - previousDotState, & !< state rate of previous xxxx - previousDotState2, & !< state rate two xxxx ago - RK4dotState + previousDotState, & + previousDotState2 real(pReal), allocatable, dimension(:,:,:) :: & + RK4dotState, & RKCK45dotState end type @@ -249,16 +249,16 @@ subroutine unitTest real(pReal), dimension(2) :: r external :: & quit - + call random_number(r) r = r/minval(r) if(.not. all(dEq(r,r+PREAL_EPSILON))) call quit(9000) if(dEq(r(1),r(2)) .and. dNeq(r(1),r(2))) call quit(9000) if(.not. all(dEq0(r-(r+PREAL_MIN)))) call quit(9000) - + realloc_lhs_test = [1,2] if (any(realloc_lhs_test/=[1,2])) call quit(9000) - + end subroutine unitTest end module prec