7.1 2D Realization under Plane Strain State
7.3 Implementation
7.3.1 Implementation of the Forward Equation
In this section we will present some details on the implementation of the thermoviscoplastic system (7.4)–(7.9) in 3D and 2D, respectively. Note that we assume for the two-dimensional problem a plane strain state of the material, cf. Section 7.1. We will denote the geometric dimension of the problem by gdim (2 or 3).
After generating the two- or three-dimensional mesh using the FEniCS module mshr we have to determine the type of finite elements for the displacement ui, the plastic strain pi and the temperature θi for
i = 0, . . . , N and ∞, respectively. We choose piecewise linear and continuous elements for the displacement uias well as the temperature θi and piecewise constant and discontinuous elements for the plastic strain pi. Moreover, we represent the displacement ui as a two or three-dimensional vector and the temperature θi as a scalar.
# I n i t i a l i z e f u n c t i o n s p a c e for d i s p l a c e m e n t
V = V e c t o r F u n c t i o n S p a c e ( mesh , " L a g r a n g e " , 1 , dim = g d i m )
# I n i t i a l i z e f u n c t i o n s p a c e for t e m p e r a t u r e T = F u n c t i o n S p a c e ( mesh , " L a g r a n g e " , 1)
Since the plastic strain pi∈ R3×3
dev is a symmetric and trace-free 3 × 3
matrix we can use a vector of the length 5 in the three-dimensional case and of the length 3 in the two-dimensional case, respectively.
# I n i t i a l i z e f u n c t i o n s p a c e for p l a s t i c s t r a i n
Q = V e c t o r F u n c t i o n S p a c e ( mesh , " DG " , 0 , dim = ( 2 * gdim -1) )
# B u i l d a m a t r i x in R _ d e v f r o m a v e c t o r def v e c t o r _ t o _ p l a s t i c _ s t r a i n ( p ) : # 3 d i m e n s i o n a l c a s e if len ( p ) == 5: # ( p [0] p [2] p [3] ) # ( p [2] p [1] p [4] ) # ( p [3] p [4] - p [0] - p [1] ) r e t u r n p [ 0 ] * a s _ m a t r i x (((1 ,0 ,0) ,(0 ,0 ,0) ,(0 ,0 ,0) ) ) \ + p [ 1 ] * a s _ m a t r i x (((0 ,0 ,0) ,(0 ,1 ,0) ,(0 ,0 ,0) ) ) \ - ( p [ 0 ] + p [ 1 ] ) * a s _ m a t r i x (((0 ,0 ,0) ,(0 ,0 ,0) ,(0 ,0 ,1) ) ) \ + p [ 2 ] * a s _ m a t r i x (((0 ,1 ,0) ,(1 ,0 ,0) ,(0 ,0 ,0) ) ) \ + p [ 3 ] * a s _ m a t r i x (((0 ,0 ,1) ,(0 ,0 ,0) ,(1 ,0 ,0) ) ) \ + p [ 4 ] * a s _ m a t r i x (((0 ,0 ,0) ,(0 ,0 ,1) ,(0 ,1 ,0) ) ) # 2 d i m e n s i o n a l c a s e
e l s e : # len ( p ) == 3 # ( p [0] p [2] 0 ) # ( p [2] p [1] 0 ) # ( 0 0 - p [0] - p [1] ) r e t u r n p [ 0 ] * a s _ m a t r i x (((1 ,0 ,0) ,(0 ,0 ,0) ,(0 ,0 ,0) ) ) \ + p [ 1 ] * a s _ m a t r i x (((0 ,0 ,0) ,(0 ,1 ,0) ,(0 ,0 ,0) ) ) \ - ( p [ 0 ] + p [ 1 ] ) * a s _ m a t r i x (((0 ,0 ,0) ,(0 ,0 ,0) ,(0 ,0 ,1) ) ) \ + p [ 2 ] * a s _ m a t r i x (((0 ,1 ,0) ,(1 ,0 ,0) ,(0 ,0 ,0) ) )
Thanks to the UFL component of the FEniCS Project it remains to implement the variational equalities related to the weak formulation of our time-discretization of the thermoviscoplastic system (7.4)–(7.9), see Section 7.2. As we have already discussed in Section 7.2, the mechanical part (7.4)–(7.7) and the heat equation (7.8) decouple. That means we can solve in every time step first the mechanical part and afterwards the heat equation. The structure of our forward solver related to the time- discrete thermoviscoplastic system (7.4)–(7.9) is given in Algorithm 1. Note that due to the nonlinearities and the high dimensions we solve the mechanical part (7.4)–(7.7) itself by using a fixed-point method. This strategy can be found in the literature as a simple predictor-corrector method, see for example [Han and Reddy, 1999, Chapter 12.2]. To be more precise, we start with solving the balance of momentum (7.6) and replace the unknown iterates of the plastic strain with information from the previous time step. Next, we solve the viscoplastic flow rule (7.7) with the current iterate for the displacement. We repeat these steps until the displacement and the plastic strain are converged. The structure of this fixed-point method is depicted in Figure 7.1. For the stopping criteria we have chosen the norm kuik2
C:=
R
Ωε(u i
):C ε(ui) dx
related to the problem for the displacement and for the plastic strain the norm kpik2 H := R Ωp i : H pidx.
Next, we will give an example for the UFL forms of the time-discrete viscoplastic flow rule (7.7) and its solution routine. In the code snippets strain represents the linearized strain, dev the deviatoric part of a matrix, C the isotropic and homogeneous material, sigma tilde the temperature dependent yield stress and t the thermal strain. The other required functions for the UFL form are defined as follows.
# D e f i n e the m i n i m u m f u n c t i o n def u f l _ m i n ( a , b ) :
r e t u r n c o n d i t i o n a l ( gt ( a , b ) , b , a )
7.3 Implementation 143 def n o r m _ f r o b ( A ) : r e t u r n s q r t ( i n n e r ( A , A ) ) # D e f i n e the F r o b e n i u s n o r m of a m a t r i x ; # Add D O L F I N _ E P S *10 in o r d e r o b t a i n d i f f e r e n t i a b i l i t y # in A = 0 def n o r m _ f r o b _ e p s ( A ) : r e t u r n s q r t ( i n n e r ( A , A ) + D O L F I N _ E P S * 1 0 ) # D e f i n e the f u n c t i o n s i g m a + chi def tau ( u , p , t e m p = 2 9 3 ) : r e t u r n C ( s t r a i n ( u ) - p - t ( t e m p ) ) - m * p # D e f i n e the f u n c t i o n ( s i g m a + chi ) ^ D def t a u _ d e v ( u , p , t e m p ) : r e t u r n dev ( C ( s t r a i n ( u ) - p - t ( t e m p ) ) - m * p )
Since the time-discretization of the thermoviscoplastic flow rule (7.7) is nonlinear w.r.t. the unkown next plastic strain pi(which corresponds
old iterates: ui−1, pi−1, θi−1 load: `i
ui= Balance of Momentum(ui−1, pold, θi−1, `i)
via (7.6), (7.4), (7.5) + boundary conditions
pi = Viscoplastic Flow Rule(ui, pi−1, θi−1)
via (7.7), (7.4), (7.5)
kui− uoldk
C< tolu and kpi− poldkH< tolp
new iterates: ui, pi
uold:= ui−1, pold:= pi−1
false uold:= ui
pold:= pi true
Figure 7.1. Idea of solving the time-discrete mechanical system (7.4)–(7.7) during one time step.
Algorithm 1. Calculation of the Thermoviscoplastic States Input: controls {`i}N
i=1, {r i}N
i=1, initial conditions u
0, p0, θ0
Output: states {ui}N,∞ i=0 , {p
i}N
i=0, {θi}Ni=0
1: procedure Forward({`i}Ni=1, {ri}N
i=1, u0, p0, θ0)
2: for i in 1 : N do
3: . Calculate mechanical iterates
4: Set uold:= ui−1, pold:= pi−1
5: Set stop := False
6: while not stop do
7: Set ui := balance of momentum(ui−1, pold, θi−1, `i
)
8: . via (7.6), (7.4), (7.5) + boundary conditions
9: Set pi := viscoplastic flow rule(ui, pi−1, θi−1)
10: . via (7.7), (7.4), (7.5)
11:
12: Set stop := kui− uoldkC< tolu and kpi− poldkH< tolp
13: Set uold:= ui, pold:= pi . Save current iterates
14: end while
15: Set θi:= heat equation(ui, pi, θi−1, ri)
16: . Calculate temperature via (7.8), (7.4), (7.5) + boundary conditions
17:
18: end for
19: Set u∞:= cooling phase(pN)
20: . Calculate displacement via (7.9) + boundary conditions
21: return {ui}N,∞i=0 , {pi}N
i=0, {θi}Ni=0 . Return states
22: end procedure
to p next in the code snippet below) we apply the NonlinearVariati- onalSolver in order to solve the nonlinear algebraic equation.
# I n i t i a l i z e m e a s u r e dX = dx ( d o m a i n = m e s h ) # I n i t i a l i z e t e s t f u n c t i o n q for v i s c o p l a s t i c # f l o w r u l e q = T e s t F u n c t i o n ( Q ) qm = v e c t o r _ t o _ p l a s t i c _ s t r a i n ( q ) # V a r i a t i o n a l e q u a t i o n for v i s c o p l a s t i c f l o w r u l e
7.3 Implementation 145 F_p = ( i n n e r ( p _ n e x t _ m - p_m , qm ) * dX + ( t i m e s t e p l e n g t h / e p s i l o n ) * u f l _ m i n ( s q r t ( 2 . 0 / 3 . 0 ) *( s i g m a _ t i l d e ( t e m p ) ) /( n o r m _ f r o b _ e p s ( t a u _ d e v ( u_next , p _ n e x t _ m , t e m p ) ) ) - 1.0 , 0) * i n n e r ( tau ( u_next , p _ n e x t _ m , t e m p ) , qm ) * dX ) dp = T r i a l F u n c t i o n ( Q ) J _ d p = d e r i v a t i v e ( F_p , p_next , dp ) # C r e a t e n o n l i n e a r p r o b l e m for # the v i s c o p l a s t i c f l o w r u l e p r o b l e m _ p = N o n l i n e a r V a r i a t i o n a l P r o b l e m ( F_p , p_next , bcs = None , J = J _ d p ) s o l v e r _ p = N o n l i n e a r V a r i a t i o n a l S o l v e r ( p r o b l e m _ p ) # Set s o m e p a r a m e t e r s prm = s o l v e r _ p . p a r a m e t e r s prm [ " n e w t o n _ s o l v e r " ][ " a b s o l u t e _ t o l e r a n c e " ] = 1 E -7 prm [ " n e w t o n _ s o l v e r " ][ " r e l a t i v e _ t o l e r a n c e " ] = 1 E -7 prm [ " n e w t o n _ s o l v e r " ][ " m a x i m u m _ i t e r a t i o n s " ] = 100 prm [ " n e w t o n _ s o l v e r " ][ " r e l a x a t i o n _ p a r a m e t e r " ] = 1.0 # S o l v e the v i s c o p l a s t i c f l o w r u l e # and s a v e the r e s u l t i n t o p _ n e x t s o l v e r _ p . s o l v e ()
The balance of momentum (7.6), the heat equation (7.8) as well as the cooling phase (7.9) can be implemented analogously. Note that there is also a LinearVariationalSolver in the FEniCS Project which can be used for solving linear problems; for example the time-discrete balance of momentum (7.6) is linear w.r.t. the unknown next displacement ui. Finally, we would like to mention that experiments regarding the forward equation can be found in Subsection 7.4.1.1. There we will study in particular the dependence of the displacement u∞ after cooling the material from the choice of the time point T where we make the prediction.