High-Order Implicit Runge–Kutta Methods for Discontinuous Mechatronical Systems Johannes Gerstmayr, Michael Stangl
[email protected] Abstract An arbitrary order implicit Runge–Kutta time integration algorithm for the solution of stiff, differential-algebraic, discontinuous and nonlinear dynamic problems is presented. A large number of industrial applications are known which include discontinuities, like contact, friction, plasticity, hydraulics, switching external forces, control, electronic and electric devices. Effective strategies for high order time-integration methods (up to 20) are used to efficiently integrate the equations from a mechatronical system. While the continuous part of the solution can be solved efficiently by the high order of the method, in the case of highly nonlinear or discontinuous effects the time step is chosen to be small. The implementation of the nonlinear system of equations for every implicit Runge–Kutta step is shown in detail, where special attention is paid to the system of mixed first and second order differential and algebraic equations. Especially, the mass matrix is not inverted within the solution procedure, as it has to be done for explicit methods. While the freely available time integration codes like DASSL, ODEPACK or RADAU5 are written in FORTRAN, the presented code HOTINT, is written in C++ and takes advantage of object oriented methods. A representative numerical example shows the performance of the method in the continuous and discontinuous case.
1
Introduction - Mechatronical System
The term mechatronics, introduced in the late 1960s by Japan´ s Yaskawa Electric Company, was derived from the observation of the synergy achieved through the integration of mechanical and electrical technologies, see [7]. Today, a mechatronical system includes a broad variety of mechanical systems operating under computer and electronic control. The main emphasis of this paper lies on the numerical simulation of mechatronical systems in form of a multibody system and control elements, hydraulics and electric or electronic devices. A multibody system (MBS) is understood as a mechanical system consisting of bodies, which have masses and inertias and can be rigid or flexible, see e.g. Jalon and Bayo [5]. The bodies are linked together by weightless interconnections which can be e.g. springs and dampers, or joints which reduce the total degrees of freedom. Typical joints constrain the relative displacement or rotation of the reference points of two bodies, e.g. spherical 1
or revolute joints, but joints may be as complicated as a sliding joint, where the reference point might be moving along the deformed surface of a body. General strategies for the treatment of discontinuities based on switching conditions are well known, see e.g.[1], however, the application to real multibody systems with several flexible bodies and many discontinuities is still not trivial. In the present paper, we treat the case where we do not wish to resolve the switching times exactly, but we only want to solve them within a specified tolerance. The derived simulation tool is applied to a representative numerical example.
2
HOTINT - High Order Time INTegration
The numerical time-integration tool HOTINT is designed to compute the numerical solution of mixed first and second order differential equations (ODE) and differentialalgebraic equations (DAEs) up to an index of 3. The numerical solution is obtained by using implicit Runge–Kutta (IRK) schemes like Gauss, Radau and Lobatto formulas, for a comprehensive discussion of this methods, see Hairer et al. [3, 4]. The code is developed for an arbitrary number of stages, so far 20 stages have been tested resulting in the conclusion that computing with as much as 10 stages can improve the speed of the numerical simulation before the machine precision is limiting the convergence of the underlying Newton method. Different IRK schemes are defined by tableaus of coefficients (A, b and c) which are defined by means of ASCII-Files. These files are automatically generated by means of built in functions of the code Mathematica 5.0. While it is known that multistep solvers can integrate DAEs of index 2 (e.g. BDF), it has been found out that the inability to restart the multistep method quickly after a discontinuous step makes it unattractive for discontinuous problems. Furthermore, the order of multistep methods which used in commercial MBS codes like ADAMS is limited by a comparatively low upper bound, while it is show in the present paper that an order of integration of up to 20 is possible and can even be most efficient. It shall be mentioned that in the special case, where a high accuracy of the solution of the DAE is needed, e.g. for sensitivity analysis or optimization methods, the very high order of IRK methods is extremely advantageous.
2.1
Equation structure of HOTINT
Starting point are the equations of motion for mixed 1st , 2nd order and algebraic equations given in semi-implicit form M(u, u, ˙ x, z)¨ u = F2 (u, u, ˙ x, z) x˙ = F1 (u, u, ˙ x, z) 0 = G(u, u, ˙ x, z)
(2.1)
where u denotes the vector of generalized coordinates for 2nd order ODEs (e.g. mechanics), x represents the vector of generalized coordinates for 1st order ODEs (e.g. hydraulics or control) and z the algebraic variables of the system. The possibly
2
nonlinear matrix M denotes the mass matrix and the vector F2 denotes the righthand side of the 2nd order equations which includes elastic and external forces as well as damping, gyroscopic terms and Lagrange multipliers. For completeness, the mass matrix may depend on the whole system state. F1 represents the right-hand side of the first order equations. The vector G represents all kinds of algebraic (constraint) equations. We transform the equations 2.1a into a first order system by introducing ˙ the new variable v = u, u˙ = v, ˙ x, z) v˙ = M−1 F2 (u,
(2.2)
We apply a specific n-stage IRK-scheme to Eqs. (2.1, 2.2) and get a system of nonlinear equations in g-form for every step with unknowns gi of every stage i, giu = u0 + τ giv = v0 + τ gix = x0 + τ
n X j=1 n X j=1 n X
Aij gjv , Aij M(tj , gjy )−1 F2 (tj , gjy ), Aij F1 (tj , gjy ),
j=1
giz = G(ti , giy )
(2.3)
The unknowns of the integration points (stages) are position and velocity coordinates in the second order system, giu and giv , first order variables, gix , and algebraic variables, giz . A is the matrix of Runge–Kutta (RK) coefficients for all stages, b is the vector of weights for the evaluation step and c the vector of relative time for every stage. The unknowns are summarized as giy = giu giv gix giz . The times ti of each stage are defined by ti = t0 + τ ci , where τ is the actual step size. The transformation from the g-form to the K-form is performed by means of Kiu = fu (ti , giy ) ,
Kiv = fv (ti , giy ) ,
Kix = fx (ti , giy )
(2.4)
We express giu , giv , and gix in terms of Ki’s giu = u0 + τ
n X j=1
Aij Kju ,
giv = v0 + τ
n X
Aij Kjv ,
gix = x0 + τ
j=1
n X
Aij Kjx (2.5)
j=1
Note, that for the specific case of a second order subsystem in u we can substitute Kiu for all equations by means of the linear relation Kiu = giv = v0 + τ
n X
Aij Kjv .
(2.6)
k=1
The equations for every stage i can be written as −M(ti , giy )Kiv + F2 (ti , giy ) + F1 (ti , giy ) = 0 Fi (y) = −Kix G(ti , giy ) 3
(2.7)
Note that this equations are seemingly decoupled for every stage i, which is because the arguments Ki and gi are mixed. The vector y collects all the unknowns for the K-form IRK-equations, y = [K1v . . . Knv K1x . . . Knx K1z . . . Knz ]
(2.8)
To see dependencies, we can write Eq. (2.7) in terms of Kiv , Kix and giz , 0 = −Mi Kiv+F2 (ti , gy0 + [τ 0 = −Kix+F1 (ti , gy0 + [τ 0 = G(ti , gy0 + [τ
n X j=1
n X
Aij Kju , τ
n X
Aij Kjv , τ
n X
j=1 n X
j=1 n X
j=1 n X
j=1
j=1
j=1
Aij Kju , τ
Aij Kju , τ
n X
Aij Kjv , τ
Aij Kjv , τ
j=1
n X
Aij Kjx , giz ]),
Aij Kjx , giz ]),
Aij Kjx , giz ])
(2.9)
j=1
P P P where Mi = M(ti , gy0 +[τ nj=1 Aij Kiu , τ nj=1 Aij Kjv , τ nj=1 Aij Kjx , giz ]) and Eq. (2.6) has to be taken into account. It shall be mentioned that the unknown Kiv are the accelerations of the underlying mechanical problem. The second order part (u and v) together with a LobattoIIIA 2-stage method (trapezoidal rule) are equivalent to the Newmark method with certain parameters β and γ. In the Newmark method it is also common, to solve for the accelerations and not for u and v, which would lead to higher dimensionality of the system to solve. The above equations can therefore be interpreted as the generalization of the Newmark method for any type or stage of IRK methods. The nonlinear system of equations (2.9) can be solved by using e.g. the modified Newton Method. The computation of the Jacobian for the Newton method is based on Eq. (2.7), where the chain rule of differentiation helps to build the Jacobian from many similar sub-matrices of the Jacobian. In the evaluation step, only Ki s are necessary to compute the next time step, uτ = u0 + τ
n X
bi Kiu ,
vτ = v0 + τ
i=1
n X
bi Kiv ,
i=1
xτ = x0 + τ
n X
bi Kix . (2.10)
i=1
The algebraic variables at the end of the time step can be either set zτ = gnz , especially if the condition cn = 1 holds for the IRK method. This is e.g. the case for RadauIIA methods, which are therefore suitable for DAEs, furthermore, they showed best results in many different mechanical systems tested with HOTINT. However, for the case that cn 6= 1 and that A is a regular matrix, the algebraic variables are extrapolated by means of the relations ! n n X X zτ = 1 − di z0 + di giz , (2.11) i=1
i=1
where we make use of the vector d = A−1 b.
4
3
Modified Newton method
The residual (2.7) needs to be computed at several steps of the underlying Newton method. As we only use the unknowns y, see Eq. (2.8), we first compute Kiu , see Eq. (2.6), then we compute giu , giv and gix from Eq. (2.5) which we can use to evaluate F2 , M, F1 and G in Eq. (2.7). The computational overhead by doing that is small compared to the effort of the residual computed of the equations written in the g-form (where the unknown gi could be directly used), where we can not extract the (inverse) mass matrix and therefore we would need to compute the residual by always taking into account the inverse mass matrix M−1 . This is one of the reasons, why much research in multibody dynamics has been done on simplifying the inversion (or factorization) of the mass matrix. The Jacobian (computed at some previous time step) of the Newton method is recomputed if the contractivity is “bad” or if the solution or the residual diverges (goes to infinity). We denote the ith iteration of the Newton method by (i), where i = 0 means initial values. The error of the current iteration is defined by q (3.1) (i) = ||F(y(i) )T F(y(i) )|| where y(i) is the solution of the ith iteration with the residual F(y(i) ). The (modified) Newton method runs until the actual error is smaller than the initial error (0) by a given factor, (i) ≤ tol (0) (3.2) It turned out that the contractivity c(i) =
(i) (i−1)
,
(3.3)
which is computed after every Newton step, might be bad, e.g. (i−1) > 1, for the first couple of iterations, even if the method converges fast after some initial iterations. From several numerical examples it therefore turned out to be efficient to recompute the Jacobian if c(i) > 0.7 and i > 3, (3.4) and to restart the modified Newton method with y(i) = y(0) . For some very particular configurations of dynamical systems (e.g. during contact) it might be necessary to operate with the full Newton method in order to gain convergence at all. Therefore, in the case that the method does not converge after a recalculation of the Jacobian (e.g. if the contractivity is bad after 3 iterations or if no convergence is reached after 25 iterations), we restart again (y(i) = y(0) ) and recompute the full Jacobian at every iteration of the Newton method. For the case of the full Newton method, we compute the more exact Jacobian, which takes into account the differences of each stage of the integration method, while in the modified Newton method, we compute an approximate Jacobian which evaluates the derivatives for all parts of the Jacobian at the beginning of the time step (as we anyway take the Jacobian for several time steps).
5
4
Jacobian
The most challenging part of the time integration with IRK methods is the efficient computation of the Jacobian. It turned out that for typical multibody systems with less than 200 degrees of freedom, the evaluation of the residual and the computation of the Jacobian dominates the computational time compared to the factorization of the Jacobian, even if we do not use sparse matrices. Based on the ideas of the RADAU5 code of Hairer and Wanner [3], we evaluate all elements of the Jacobian at t = t0 . For the K-form of the IRK equations we need to make use of partial derivatives, as mentioned above, however, this is much more . According to the problem definition we separate efficient than just computing ∂F ∂y our Jacobian J in the Kiv , Kix and giz according parts, (11) (1n) Jvv · · · Jvv Jvv Jvx Jvz .. , etc. .. J = Jxv Jxx Jxz , with Jvv = ... (4.1) . . (n1) (nn) Jzv Jzx Jzz Jvv · · · Jvv Each of the smaller matrices (Jvv , Jvx , . . .) is again devided into n × n parts due to n stages of the IRK method. Now we can compute the 9 matrices of Eq. (4.1) from Eq. (2.7) to J(ij) vv = − J(ij) vx = J(ij) vz = J(ij) xv = J(ij) xx = J(ij) zv = J(ij) zx =
∂Mi Kiv0 ∂giu ∂(−Mi Kiv+F2 (giy )) = −Mi δ ij − ∂Kjv ∂giu ∂Kjv ∂(Mi Kiv0 ) ∂giv ∂F2 (ti , giy ) ∂giu ∂F2 (ti , giy ) ∂giv + + , ∂giv ∂Kjv ∂giu ∂Kjv ∂giv ∂Kjv ∂(Mi Kiv0 ) ∂gix ∂F2 (ti , giy ) ∂gix − + , ∂gix ∂Kjx ∂gix ∂Kjx ∂(Mi Kiv0 ) ∂F2 (ti , giy ) − + , ∂giz ∂gjz ∂F(ti , giy ) ∂giu ∂F(ti , giy ) ∂giv + , ∂giu ∂Kjv ∂giv ∂Kjv ∂F(ti , giy ) ∂gix ∂F(ti , giy ) −δ ij + , J(ij) , xz = ∂gix ∂Kjx ∂gjz ∂G(ti , giy ) ∂giu ∂G(ti , giy ) ∂giv + , ∂giu ∂Kjv ∂giv ∂Kjv ∂G(ti , giy ) ∂gix ∂G(ti , giy ) , J(ij) . zz = ∂gix ∂Kjx ∂gjz
(4.2)
For brevity, the argument t0 is omitted, the abbreviations Mi = M(giy ), F2i = F2 (giy ), F1i = F1 (giy ) and Gi = G(giy ) are utilized, δ is the Kronecker δ, Kiv0 is equal to Kiv at t = t0 , and ∂Kiv0 /∂Kiv = 0. The partial derivatives of g with respect to K can be written in very short form as n n X X ∂giu 2 2 = Iτ Aik Akj = Iτ A2ij ∂Kjv k=1 k=1 ∂giv = Iτ Aij , ∂Kjv
∂gix = Iτ Aij ∂Kjx 6
(4.3)
In a typical multibody system, where the mass depends only on the position but not onto velocity, hydraulic or control parameters or Lagrange multipliers, we can set ∂(Mi Kiv0 ) ∂giv → 0, ∂giv ∂Kjv
∂(Mi Kiv0 ) ∂gix → 0, ∂gix ∂Kjx
∂(Mi Kiv0 ) → 0, ∂giz
(4.4)
and for the case of having only position and velocity constraints, we set ∂G(ti , giy ) ∂gix → 0, ∂gix ∂Kjx
∂G(ti , giy ) → 0. ∂gjz
(4.5)
In the case of absolute coordinates, such as in the absolute nodal coordinate formulation, the mass matrix is constant and we additionally set ∂Mi Kiv0 ∂giu → 0. ∂giu ∂Kjv
(4.6)
For a very efficient implementation of IRK methods with absolute coordinates, see Gerstmayr and Sch¨oberl [2]. For the special case of the floating frame of reference (relative coordinates), with elastic material, the stiffness matrix might be constant which means ∂F2 (ti , giy ) ∂giu → const. (4.7) ∂giu ∂Kjv Furthermore, it turned out that the dependence of the mass matrix with respect to the position coordinates is of minor importance for certain (flexible) multibody dynamic problems where one might use ∂Mi Kiv0 ∂giu → 0, ∂giu ∂Kjv
(4.8)
which additionally speeds up the computation of the Jacobian. It shall be mentioned that we can re-use the expensive parts of the Jacobians after a step-change (where the Jacobian changes significantly), however, it is not easily possible to update the factorized Jacobian by a cheap rank one update as it is possible for IRK methods based on first order methods. This is because in the specific K-form we have a mixed system of τ and τ 2 sub-matrices which are different from the implementation of the Radau5 code of Hairer and Wanner [3]. Nevertheless, the advantage of the method is due to the fact that the mass matrix needs not to be factorized (neither numerically nor symbolically) for the computation of the residual or the Jacobian. We should mention that we use numerical differentiation in the current implementation. While it is generally possible to solve an index 3 problems directly with RadauIIA methods with 2 stages or more, it results in bad convergence of the Newton method for very small step size (below 1e−6 . . . 1e−8) and even your achievable Newton accuracy will depend on the step size. Therefore, we suggest an index 2 reduction (differentiate constraints once with respect to time), and eventually use a GGL stabilization, which is not necessary a high order method is used, where the drift will be negligible small. The constraints are multiplied by 1/τ in order to scale the entries of the Jacobian. 7
5
Error control
Due to the possibility of very nonlinear behavior (like in hydraulics, nonlinear contact laws, etc.) and due to the possibility of discontinuities within a time step, a reliable error estimator is needed. While there are possibilities to estimate the error by means of a comparison with another Runge–Kutta formula, we just compare the computation of one time step with the results of two smaller half steps. That is actually what people mostly do by themselves when they want to check the convergence of their results. The computational costs for this error estimator is 50% overhead, as we use the result of the two half steps as initial values for the next time step, however, the reliability is excellent. For the error estimation, we compute the vector Vτ for comparable results of the whole step and Vτ /2 for comparable results of two half steps. We know that the according errors will approximately fulfill the relation τ = 2order τ /2 (5.1) in the case that the solution converges with the assumed order of the method (which is only true for sufficiently smooth solutions). Assuming to have the exact solution V∞ , the errors are τ = ||Vτ − V∞ || and τ /2 = ||Vτ /2 − V∞ ||.
(5.2)
We then can estimate the error by assuming that we have no oscillating convergence τ − τ /2 = τ /2 (2order − 1) = ||Vτ − V∞ || − ||Vτ /2 − V∞ || ≈ ||Vτ − Vτ /2 || (5.3) and therefore we get the estimated error for the two half steps τ /2 =
6
1 (2order
− 1)
||Vτ − Vτ /2 ||
(5.4)
Step size selection
The step size selection is done according to the ideas of Hairer and Wanner and based on the above error estimator. In order to avoid many changes of the step size (which currently results in a computation of the Jacobian), we introduce several parameters. The absolute error tolerance is tol , due to usually oscillatory solutions it turned out that relative errors are mostly less helpful in dynamic problems. The safety factor in order to prevent from assuming too small time steps is smin = 4, the minimum increase or decrease factor for the step size are smin inc = 2 and smin dec = 2 and the maximum increase is smax inc = 5. If the error is smaller than τ /smax then the step size will be recomputed, smax = s2min . Denoting the index (i) as the current step, the new step size at (i + 1) can be computed as !1/(order+1) tol (i+1) τ =γτ . (6.1) (i) smin τ /2 The value for γ is suggested by Hairer and Wanner to incorporate the fact that the convergence of the solution may not necessarily follow the assumed order. We 8
assume that the errors of two different steps with step sizes τ 1 and τ 2 follow the formula order τ 1 τ1 =γ (6.2) τ 2 τ2 While we set initially γ = 1, we then compute γ after every change of step size from the newly computed error (i−1)
γ=
τ
τ (i)
(i)
order (6.3)
τ (i−1)
τ
and restrict γ