Vous êtes sur la page 1sur 17

Numerical Integration in Structural Dynamics

CEE 541. Structural Dynamics


Department of Civil & Environmental Engineering
Duke University
Henri P. Gavin
Fall 2016

Introduction
A damped structural system subjected to dynamic forces and possibly experiencing
nonlinear material behavior is modeled by
M x(t) + C x(t)
+ Kx(t) + R(x(t), x(t))
= f ext (t), (1)
where x is a vector of displacements of structural coordinates, M is a positive definite mass
matrix, C is a non-negative definite damping matrix, and K is a non-negative definite stiffness
and f ext (t) is a vector of external
matrix. The nonlinear restoring forces are given in R(x, x)
dynamic loads. At any point in time, t = ti+1 = (i + 1)h, we may solve for the accelerations
in terms of the displacements, velocities, and the applied forces.
x(ti+1 ) = M 1 [C x(t i+1 )) f ext (ti+1 )].
i+1 ) + Kx(ti+1 ) + R(x(ti+1 ), x(t (2)
Given values for accelerations, velocities, displacements, and applied forces at time ti , if we
can extrapolate the velocities and displacements forward in time by a time step h to time
ti+1 = ti + h, then we may compute the acceleration x(ti+1 ) using equation 2. The various
numerical integration algorithms described in this document1 2 differ primarily in the manner
in which x(ti+1 ) and x(t i ), x(ti ), f ext (ti ), and f ext (ti+1 ). Note
i+1 ) are computed from x(ti ), x(t
that since differentiation amplifies high frequencies, changes in x and x from ti to ti+1 will
be much smoother than the corresponding changes in x.
There are two general classifications of numerical integration methods: explicit and
implicit. In explicit methods, displacements and velocities at ti+1 can be determined in
closed form from displacements, velocities, accelerations, at ti , and from external forcing at
ti and, potentially, ti+1 . For structural systems with linear elastic stiffness and linear viscous
damping, such discrete-time systems may be written
" # " #
x(ti+1 ) x(ti )
=A + B f ext (ti ) (3)
i+1 )
x(t i)
x(t
where A is a 2n 2n discrete time dynamics matrix which depends upon M , C, K, the time
step, h, and some algorithmic parameters. Implicit methods involve the solution of a set of
nonlinear algebraic equations at each time step. For example, the displacements and velocities
at time ti+1 , [x(ti+1 ), x(t
i+1 )], are determined from the roots of a nonlinear equation in terms
of [x(ti+1 ), x(t
i+1 )]. Explicit numerical methods are typically more computationally-efficient
than implicit methods.
1
Clough, R. and Penzien, J., Dynamics of Structures, 2nd ed., McGraw-Hill, 1993.
2
Hanson, R.D., CE 611: Structural Dynamics, class notes, The University of Michigan, 1988
2 CEE 541. Structural Dynamics Duke University Fall 2016 H.P. Gavin

Accuracy and Stability


Numerical methods for integrating equations of motion are compared in terms of their
accuracy and stability. In general, accuracy and stability depend upon the ratio of the
time step, h, to the shortest natural period of the structural system. For a system with
many coordinates (n > 103 ), the shortest natural period can be much shorter than the
fundamental natural period, Tn /T1 > 104 . Typically, responses of the highest several modes
of a numerical model are physically meaningless, should be insignificantly small, but are
potentially lightly-damped. Nonetheless, the shortest natural period governs the stability
of numerical integration methods. The explicit numerical methods described in these notes
can artificially add numerical damping to suppress instabilities of the higher mode responses.
Implicit numerical integration methods are unconditionally stable.

The Central Difference Method


The central difference approximations for the first and second derivatives are
1
x(t (xi+1 xi1 ) ,
i ) = x i (4)
2h
1
x(ti ) = xi 2 (xi+1 2xi + xi1 ) . (5)
h
Substituting approximations (4) and (5) into equation (1), and re-arranging terms,
1 1 2 1 1
     
2
M + C xi+1 = 2 M K xi + 2 M + C xi1 + fiext , (6)
h 2h h h 2h
which may be written A0 xi+1 = A1 xi + A2 xi1 + fiext . The matrix A0 is positive definite and
may be factorized prior to the iterative solution for xi at each time step.
The numerical stability of the central difference method depends on the choice of the
time step interval, h. To obtain a stable solution, h < Ti /, where Ti is the shortest natural
period of the structural system. If the central difference method is used with a time step
larger than Ti / the solution will increase exponentially.
A step-by-step procedure for the central difference method may be written as3 :

1. Input the mass, M , damping, C, stiffness, K, matrices and the time step interval h.
h2
2. Initialize x0 , x 0 , x0 and compute x1 = x0 hx 0 + 2 0
x .
3. Form the matrices A0 , A1 and A2 , and triangularize A0 using LDLT factorization.
4. for i = 1 to N
solve A0 xi+1 = A1 xi + A2 xi1 + fiext for xi+1 using LDLT back-substitution.
calculate x i and xi using equations (4) and (5), if required.
write results (ti , xi , x i , xi ) to a data file.
3
K.J. Bathe, Finite Element Procedures in Engineering Analysis, Prentice-Hall, 1982, pp. 439449, 499
506.

CC BY-NC-ND H.P. Gavin


Numerical Integration for Structural Dynamics 3

The Implicit Linear Acceleration Method


Consider the Taylor series expansions for displacement, velocity, and acceleration:

h2 h3 ... h4 ....
x(ti+1 ) = xi+1 = xi + hx i + xi + xi + x i + (7)
2! 3! 4!
h2 ... h3 ....
i+1 ) = x i+1
x(t = x i + h
xi + x i+ x i + (8)
2! 3!
... h2 ....
x(ti+1 ) = xi+1 = xi + h x i + x i + (9)
2!
Rearranging equation (9),

... h2 ....
h x i = xi+1 xi x i , (10)
2!
and substituting equation (10) into equations (7) and (8) results in
!
h2 h2 h2 .... h4 ....
xi+1 = xi + hx i + xi + xi+1 xi x i + x i + , (11)
2 6 2! 4!
!
h h2 .... h3 ....
x i+1 = x i + h
xi + xi+1 xi x i + x i + (12)
2 2! 3!

Truncating the fourth time-derivative and higher from these expansions, the resulting finite
difference approximations are

h2
xi+1 xi + hx i + (
xi+1 + 2
xi ), (13)
6
and
h
x i+1 x i + (
xi+1 + xi ). (14)
2
These relationships are implicit because xi+1 needs to be determined in order to find xi+1 and
x i+1 , but xi+1 can not be found without knowing xi+1 and x i+1 . Note that the substitutions
above, have eliminated the third time-derivative of x, and that the method is accurate to
....
within h4 x .
This is called the linear acceleration method because the third time derivative of x has
been eliminated. If the rate of change of acceleration is constant, then the approximation
of truncating the Taylor series at the fourth-order term does not affect the accuracy of the
solution.

CC BY-NC-ND H.P. Gavin


4 CEE 541. Structural Dynamics Duke University Fall 2016 H.P. Gavin

The Implicit Linear Acceleration Method,


Made Explicit for Linear Structural Dynamics
Recall that at time ti+1 we can satisfy the equations of motion, by calculating the
acceleration with equation (2). Substituting equations (13) and (14) for the displacements
and velocities at time ti+1 into equation (2),

xi + xi+1 )} + K{xi + hx i + (h2 /6)(


M xi+1 + C{x i + (h/2)( xi+1 + 2 ext
xi )} = fi+1 , (15)

where the nonlinearities, R(x, x),


are negligible. Collecting similar derivatives of x,
" # " #
h h2 ext h h2
M + C + K xi+1 = fi+1 Kxi [C + hK]x i C + K xi . (16)
2 6 2 3

and re-arranging,
" # " #
h h2 h h2 ext
M + C + K xi+1 = C K xi Kxi C x i hK x i + fi+1 . (17)
2 6 2 3

Recall from the equations of motion, that

M xi fiext = Kxi C x i . (18)

Substituting equation (18) into (17), we obtain the closed-form linear acceleration recurrence
relations for structural dynamics simulation.
" # " #
h h2 h h2 ext
M + C + K xi+1 = M C K xi hK x i + fi+1 fiext . (19)
2 6 2 3

h
x i+1 = x i + [
xi+1 + xi ] . (20)
2
and
h2
xi+1 = xi + hx i +
[
xi+1 + 2
xi ] . (21)
6
These relationships are now explicit because xi+1 can be determined from the current response
values (xi and x i ), the current dynamic load fiext , and the next dynamic load fi+1
ext
. Note that
within each time step, the dynamic equations of equilibrium are satisfied both at time ti and
at time ti+1 .
The explicit linear acceleration method is a good technique to correct for acceleromter
sensor dynamics. Accelerometers are themselves simple oscillators, with an input f ext (t) =
m z (t), and a voltage output proportional to the relative displacement, v(t) = x(t), where
is related to the accelerometer sensitivity (in volts/m/s2 ). Given the sensor senstivity,
natural frequency and damping ratio, accelerometer dynamics can be corrected by solving
for z(t) from measurements of v(t)/. Equations (19) and (20) can be inverted to correct
acceleration measurements for sensor dynamics.

CC BY-NC-ND H.P. Gavin


Numerical Integration for Structural Dynamics 5

The Newmark- method incremental formulation


The finite difference approximations for the Newmark- method are
1
  
xi+1 xi + hx i + h2 xi + xi+1 , (22)
2
and
x i+1 x i + h [(1 )
xi + xi+1 ] . (23)
If = 1/4 and = 1/2 the Newmark- method is implicit and unconditionally stable. In
this case the acceleration within the time interval t [ti ti+1 ) is presumed to be constant. If
= 1/6 and = 1/2 the Newmark- method is identical to the linear acceleration method.
If = 0 and = 1/2 the Newmark- method is identical to the central difference method.
For linear structural dynamics, if 2 1/2, then the Newmark- method is stable
regardless of the size of the time-step, h. The Newmark- method is conditionally stable if
< 1/2. For = 1/2 the Newmark- method is at least second-order accurate; it is first
order accurate for all other values of .
Formulating the finite difference relationships in terms of the increments of displacement
(xi = xi+1 xi ), velocity ( x i = x i+1 x i ), acceleration ( xi = xi+1 xi ), and nonlinear
restoring force (Ri = R(xi+1 , x i+1 ) R(xi , x i ))
1 1 1
xi =
2
xi x i xi , (24)
h h 2
and !

x i = xi x i + h 1 xi . (25)
h 2
Now, satisfying incremental equilibrium over the time step, h,
ext
xi + C x i + Kxi + Ri = fi+1
M fiext = fiext , (26)
re-grouping terms, and solving for the increment in displacements,
" #
6 3 h 6
   
2
M + C + K xi = fiext Ri + 3M + C xi + M + 3C x i , (27)
h h 2 h
where = 1/6 and = 1/2. Solving this linear system of equations4 for xi , the displace-
ments are updated with,
xi+1 = xi + xi , (28)
the velocities are updated with
h 3
x i+1 = 2x i xi + xi , (29)
2 h
and the accelerations satisfy the equations of motion,
xi+1 = M 1 [C x i+1 + Kxi+1 + R(xi+1 , x i+1 ) fi+1
ext
]. (30)
Similar relations may be found for other values of and . Note that in this incremental
formulation one needs to obtain the inverse of the mass matrix, M , and the inverse of the
matrix [6M/h2 + 3C/h + K].
4
If the incremental nonlinear restoring forces Ri are not negligible, equation (27) is solved using the
Newton-Raphson method, equation (48).

CC BY-NC-ND H.P. Gavin


6 CEE 541. Structural Dynamics Duke University Fall 2016 H.P. Gavin

The HHT- method


The HHT- method5 is a generalization of the Newmark- method and reduces to the
Newmark- method for = 0. The HHT- method adopts the finite difference equations of
the Newmark- method, (equations (22) and (23)). The equations of motion are modified,
however, using a parameter , which represents a numerical lag in the damping, stiffness,
nonlinear, and external forces.
ext
M xi+1 + (1 )C x i+1 + C x i + (1 )Kxi+1 + Kxi = (1 )fi+1 + fiext . (31)

Equation (31) is analogous to equation (26) with the added condition that the acceleration
is constant within the interval t [ti ti+1 ). If

0 1/3 (32)
= (1 + )2 /4 , and (33)
= 1/2 + , (34)

the HHT- method is at least second-order accurate and unconditionally stable. The HHT-
method is useful in structural dynamics simulations incorporating many degrees of freedom,
and in which it is desirable to numerically attenuate (or dampen-out) the response at high
frequencies. Increasing decreases the response at frequencies above 1/(2h), provided that
and are defined as above.
Substituting the Newmark- finite difference relationships into equation (31),

M xi+1 + (1 )C{x i + h[(1 )xi + xi+1 ]} + C x i


2
+ (1 )K{xi + hx i + h [(1/2 ) xi + xi+1 ]} + Kxi
ext ext
= (1 )fi+1 + fi , (35)

and grouping terms, we obtain

[M + h(1 )C + h2 (1 )K]
xi+1 + [h(1 )(1 )C + h2 (1 )(1/2 )K]
xi
+ [C + h(1 )K]x i
+ Kxi
ext
= (1 )fi+1 + fiext . (36)

These are a set of linear equations for xi+1 in terms of xi , x i , xi , the external dynamic load,
and the structures mass, damping, and stiffness. Equations (22), (23), and (36) provide the
recurrence relationship for the HHT- method.

5
Hughes, T.J.R., Analysis of Transient Algorithms with Particular Reference to Stability Behavior. in
Computational Methods for Transient Analysis, North-Holland, 1983, pp. 67155.

CC BY-NC-ND H.P. Gavin


Numerical Integration for Structural Dynamics 7

The HHT- method incremental formulation


The HHT- method may be formulated in an incremental form, as was done with
the Newmark- method in the previous section. Again, formulating the finite difference
relationships in terms of the increments of displacement (xi = xi+1 xi ), velocity ( x i =
x i+1 x i ), acceleration (
xi = xi+1 xi ), and nonlinear restoring force, and difference between
equation (31) (evaluated at time ti+1 ) and the same expression evaluated at time ti , results
in

i +(1)C x i +C x i1 +(1)Kxi +Kxi1 +(1)Ri +Ri1 = (1)fiext +fi1


M x ext
.
(37)
Now, substituting in expressions for x and
x at times ti and ti1 , and grouping terms
results in
" # " #
1 1
2
M + (1 ) C + (1 )K xi = M + (1 ) C x i
h h h
" ! #
1
+ M (1 )h 1 C xi
2 2
" #

C + K xi1
h
!

+ C x i1 h 1 C xi1
2
(1 )Ri Ri1
+ (1 )fi + fi1 . (38)

If R(x, x) = 0, these are a set of linear equations for xi in terms of x i , xi , xi1 , x i1 ,


xi1 , xi1 , the external dynamic load, and the structures mass, damping, and stiffness.
Equations (22), (23), and (38) provide the recurrence relationship for the HHT- method
in incremental form. Solving this linear system of equations6 for xi , the displacements are
updated with,
xi+1 = xi + xi , (39)
the velocities are updated with
! !

x i+1 = 1 x i + xi + h 1 xi . (40)
h 2

and the accelerations satisfy the HHT- form of the equations of motion,
h i
xi+1 = M 1 (1 )C x i+1 + C x i + (1 )Kxi+1 + Kxi (1 )fi+1
ext
fiext . (41)

This algorithm is explicit regardless of the values of , , or .

6
If the incremental nonlinear restoring forces Ri are not negligible, equation (38) is solved using the
Newton-Raphson method, equation (48).

CC BY-NC-ND H.P. Gavin


8 CEE 541. Structural Dynamics Duke University Fall 2016 H.P. Gavin

Numerical Example
The simple linear structural model shown below
111
000
000
111
1 2 3 111
000
000
111
000 200 kN/mm
111
000
111 200 kN/mm 200 kN/mm 000
111
000
111
000
111 000
111
000
111
000
111 000
111
000
111
000
111 000
111
000
111
000
111 000
111
000
111
000
111 1 Mt 1 Mt 1 Mt 000
111
000
111
000
111 000
111
000
111
000
111 000
111
000
111 000
111
000
111
000
111 000
111
000
111
000
111 000
111
000
111 0.15 kN/mm/s 111
000
000 0.35 kN/mm/s
111 0.20 kN/mm/s 0.20 kN/mm/s 000
111

is described by the following stiffness, damping, and mass matrices (units kN,mm,s):

400 200 0 0.55 0.20 0 1 0 0
K = 200 400 200 C = 0.20 0.55 0.20 M = 0 1 0 (42)


0 200 200 0 0.20 0.35 0 0 1

This system has natural periods of 1.00 s, 0.36 s, and 0.25 s, with about 1.5% critical damp-
ing in each mode. Free acceleration responses to initial conditions of x(0) = [0, 0, 0]T and

x(0) = [1, 1, 1]T using the HHT- method with time steps of 0.001 s (black solid) and 0.1 s
(blue dash-dot), and values of of 0.0 (left) and 0.1 (right) are shown below.
10 10

= 0.00 = 0.10

5 5
accel #1, mm/s2

accel #1, mm/s2

0 0

-5 -5

-10 -10
0 2 4 6 8 10 0 2 4 6 8 10
time, s time, s

For the = 0 cases, the response computed with h = 0.1 s has a magnified short-period
response as compared to the h = 0.001 s case. For = 0.1 and h = 0.1 s, the response
is more heavily damped especially the response at the shorter periods. Also, the responses
simulated with = 0.1 and h = 0.1 s has a longer period than the systems true fundamental
period of 1.0 s. Note that the linear acceleration method ( = 0, = 1/6, = 1/2) would be
numerically unstable for this system with a time step of 0.1 s.
A more formal analysis of numerical damping, stability, and period lengthening effects
in explicit numerical integration methods can be carried out by examining the eigenvalues of
the discrete time dynamics matrix, A, in equation (3).

CC BY-NC-ND H.P. Gavin


Numerical Integration for Structural Dynamics 9

Simulation of SDOF Bilinear Hysteretic Behavior


Bilinear hysteretic behavior may be simulated using linear dynamic models. The basic
idea is that each branch of the hysteresis may be described by an equation of the form
R = K(x d), where the restoring force is zero when x = d and K will take the value of the
pre-yield stiffness or the strain hardening stiffness. The procedure is as follows:

1. Initialize K using the pre-yield stiffness Khi . Initialize x0 , x 0 , x0 , f0ext , and d to be zero
at time t0 = 0. The value d is the equilibrium displacement of the bilinear hysteretic
system.
ext
2. At time t = ti+1 , read the value of the external forcing fi+1 , solve equation (27) for xi ,
and calculate xi+1 and x i+1 using equations (28) and (29).
3. Compute the next acceleration xi+1 from equilibrium
xi+1 = M 1 [C x i+1 + K(xi+1 d) fi+1
ext
]. (43)

4. Compute the yielding force level from


f yield (xi+1 , x i+1 ) = Klo xi+1 + (Khi Klo ) xy sgn(x i+1 ) (44)

5. Check for yielding:


(a) If K = Khi and x i+1 > 0 and K(xi+1 d) > f yield ,
then the system has just exceeded its positive yield force level.
Set K = Klo and d = (1 Khi /Klo )xy .
(b) If K = Khi and x i+1 < 0 and K(xi+1 d) < f yield ,
then the system has just exceeded its negative yield force level.
Set K = Klo and d = (Khi /Klo 1)xy .
6. Check for load reversal:

If K = Klo and x i+1 x i < 0,


Set K = Khi and d = xi+1 (Klo /Khi )(xi+1 d)
7. If any of the checks in steps 5 or 6 were true, then correct the velocity and acceleration
(x i+1 , xi+1 ) using equations (27), (29), and (43) with a very small time step (h/104 ),
over which the external forcing is assumed to be constant (fiext = 0).
8. Record xi+1 , x i+1 , xi+1 , and fi+1 M xi+1 . Increment the time step. i := i + 1.
9. Go back to step 2 and repeat until the end of the time history.
.
R(x(t),x(t)) yield .
f(x, x > 0)
K hi
K lo xy x y (K hi / K lo 1)
d d
x y (1 Khi / Klo) x(t)
yield .
f(x, x < 0)

CC BY-NC-ND H.P. Gavin


10 CEE 541. Structural Dynamics Duke University Fall 2016 H.P. Gavin

Newton-Raphson Iterative Solution for Nonlinear Behavior


Equations (27) or (38) may be written K xi = fi . If the nonlinear restoring force

increment Ri is not negligible, then f depends on x and x. For the case of the linear
acceleration method ( = 0, = 1/6, = 1/2),
6 3
 
=
K M + C +K , (45)
h2 h
and
" #
h 6
 
fi (xi ) = fiext R(xi + xi , x i + x i ) + R(xi , x i ) + 3M + C xi + M + 3C x i . (46)
2 h
The Newton-Raphson algorithm7 is an efficient method to solve the nonlinear equations
K xi = fi (xi ) for the incremental displacement xi . The algorithm is iterative and proceeds
as follows:
(0)
1. The initial value for xi is denoted xi and is arbitrarily set to zero. The corresponding
value for fi is
" #
h 6
 
(0)
fi (xi ) = fiext + 3M + C xi + M + 3C x i (47)
2 h

2. The Newton-Raphson recurrence relation is simply


(n+1) 1 fi (xi(n) )
xi =K (48)
where
(n) (0) (n) (n)
fi (xi ) = fi (xi ) R(xi + xi , x i + x i ) + R(xi , x i ), (49)
and
(n) 3 (n) h
x i = xi 3x i xi . (50)
h 2
3. Equation (48) is iterated upon until the incremental displacement xi converges, i.e.,
(n+1) (n)
||xi xi || < .

The convergence of this form of the Newton-Raphson method depends on the local
smoothness of R(x, x).
Convergence can be improved, for a particular time step, by making
h smaller.
Note that K is strongly positive definite; it does not depend on xi ; and it is inverted
or factorized only once at the beginning of the simulation. If convergence is problematic,
matrices may be formed, some with small time steps, and factorized prior to
then a set of K
the simulation.
As an alternative to Newton-Raphson iterations, the approximation Ri Ri1 results
in an explicit formulation for the simulation of the response of nonlinear systems, and can
significantly reduce computational time, but with some loss of accuracy.
7
Press, W.H., et al., Numerical Recipes, Cambridge Univ. Press, 1993. http://www.nr.com/

CC BY-NC-ND H.P. Gavin


Numerical Integration for Structural Dynamics 11

State Variable Formulations


The second order ordinary differential equations of motion for a structural system are

M r(t) + C r(t)
+ Kr(t) + R(r(t), r(t))
= f ext (t), (51)

where we have re-named the displacement vector x(t) of equation (1) with r(t). This set
of n second order differential equations may be written as a set of 2n first order differential
equations, as follows:
" # " #" # " # " #
d r 0N N IN N r 0N 1 0N N
= + + f ext (t). (52)
dt r M 1 K M 1 C r M 1 R(r, r)
M 1

The vector [rT r T ]T is called the state vector; along with the external forces, it can completely
describe the state of the system at any point in time. State-space models are conventionally
written as
x = Ax + g(x) + Bu, (53)
where x is the state vector, A is the dynamics matrix, g(x) contains any nonlinear terms in
the equations of state, B is the input matrix, and u is the input to the system. For a linear
structure, g(x) = 0 and the eigenvalues of A contain the complex poles of the system. For
under-damped dynamic systems the poles are complex-valued. The imaginary part of the
pole is the damped natural frequency, and the real part of the pole is the negative of the
natural frequency times the damping ratio.
A convenient feature of state-variable formulations is that first order systems can be eas-
ily combined. If components of the structural system have first-order dynamics (for example,
visco-elasticity or Bouc-Wen hysteresis), then the first order dynamics of those components
can be appended to the state vector, and the simulation of the second order structural system
coupled with the first order structural components can proceed in parallel.
The state variable formulation is the most general description of a dynamic system, and
many methods exist for the simulation of state-variable models. A set of these methods has
been implemented in Matlab. See, for example, the Matlab command ode45 .
For large second-order systems (n > 1000), however, the HHT- method is typically
more efficient in terms of memory and speed.

A Fixed-Step Fourth-Order Runge-Kutta Solver


In the computation of transient response analyses of linear or nonlinear systems, it
is common for the external forcing to be sampled at uniformly-spaced increments in time,
and to desire the response to be computed at these same points in time. If the sample
interval h = t is less than one-tenth of the shortest natural period involved in the system
(over the course of the simulation) then a fixed time-step Runge-Kutta solver can compute a
solution quickly, and with reasonable accuracy.8 The most famous of these solvers is fourth-
order accurate. The goal of the solver is to advance the solution, x, of a general system of
8
Press, W.H., et al., Numerical Recipes, Cambridge Univ. Press, 1993. Section 16.1 http://www.nr.com/

CC BY-NC-ND H.P. Gavin


12 CEE 541. Structural Dynamics Duke University Fall 2016 H.P. Gavin

non-homogeneous first-order ordinary differential equations


x(t) = f (t, x(t), u(t)) , x(0) = xo , (54)

from time t to time t+t. Given the state vector x(t), we endeavor to find the state x(t+t).
The solution scheme is illustrated in Figure 1. Within each time-step, the algorithm evaluates

. .
x2 = f ( t+dt/2, x(t)+x1 (dt/2) , u(t+dt/2) )

. . . .
x(t+dt) = x(t) + ( x1 + 2(x2+x3) + x4) (dt/6)
x(t+dt)

. .
x3 = f ( t+dt/2, x(t)+x2 (dt/2) , u(t+dt/2) )

x(t)
. . .
x1 = f ( t, x(t) , u(t) ) x4 = f (t+dt, x(t)+x3 dt , u(t+dt) )

t t + dt/2 t+dt

Figure 1. Solution Scheme of the Fourth Order Runge-Kutta Method.

x four times.

x 1 = f ( t , x(t) , u(t)) (55)


!!
t t t
x 2 = f t + , x(t) + x 1 , u t + (56)
2 2 2
!!
t t t
x 3 = f t + , x(t) + x 2 , u t + (57)
2 2 2
x 4 = f ( t + t , x(t) + x 3 t , u(t + t)) (58)

The desired solution, x(t + t), is computed from the four state derivatives

t
x(t + t) = x(t) + (x 1 + 2(x 2 + x 3 ) + x 4 ) , (59)
6
time is incremented, t = t + t, and the solution marches on. The solution scheme is
implemented in the Matlab function ode4u.m9 . As long as t is shorter than 0.45Tn where
Tn is the shortest natural period in the system, this constant time-step Runge-Kutta method
is stable.

9
http://www.duke.edu/hpgavin/ode4u.m

CC BY-NC-ND H.P. Gavin


Numerical Integration for Structural Dynamics 13

1 function [ time , x_sol , x_drv , y_sol ] = ode4u ( dxdt , time , x0 , u , params )


2 % [ time , x s o l , x d r v , y s o l ] = ode4u ( d x d t , time , x0 , u , params )
3 %
4 % S o l v e a sy s te m o f nonhomogeneous o r d i n a r y d i f f e r e n t i a l e q u a t i o n s u s i n g t h e
5 % 4 t h o r d e r RungeKutta method .
6 %
7 % Input Variable Description
8 %
9 % dxdt : a f u n c t i o n o f t h e form [ x d o t , y ] = d x d t ( t , x , u , params )
10 % which p r o v i d e s t h e s t a t e d e r i v a t i v e g i v e n t h e time , t ,
11 % t h e s t a t e , x , e x t e r n a l f o r c i n g , u , and p a r a m e t e r s ;
12 % a v e c t o r sy s te m o u t p u t s , y , may a l s o be r e t u r n e d .
13 % time : 1byp v e c t o r o f time v a l u e s , u n i f o r m l y i n c r e a s i n g
14 % ( or d e c r e a s i n g ) , a t which t h e s o l u t i o n i s computed .
15 % x0 : nby1 v e c t o r o f i n i t i a l s t a t e v a l u e s , a t time ( 1 ) .
16 % u : mbyp m a t r i x o f s y st e m f o r c i n g d a t a f o r t h e ode ,
17 % sampled a t p o i n t s i n t h e 1byp v e c t o r time .
18 % params : o p t i o n a l parameters f o r the f u n c t i o n dxdt .
19 %
20 % Output V a r i a b l e Description
21 %
22 % time : i s r e t u r n e d , unchanged .
23 % x sol : the solution to the d i f f e r e n t i a l equation at
24 % t i m e s g i v e n i n t h e 1byp v e c t o r time .
25 % x drv : the d e r i v i t i v e of the solution
26 % y sol : a d d i t i o n a l s y st e m o u t p u t s
27 %
28 % Henri Gavin , C i v i l and Environmental E n g i n e e r i n g , Duke U n i v s e r s i t y , Jun . 2014
29 % WH Press , e t a l , Numerical R e c i p e s i n C, 1992 , S e c t i o n 1 6 . 1
30
31 points = length ( time );
32 i f nargin < 5 , params = 0; end
33 i f nargin < 4 , u = zeros (1 , points ); end
34
35 [ dxdt0 , y0 ] = f e v a l ( dxdt , time (1) , x0 , u (: ,1) , params ); % compute i n i t i a l o u t p u t
36
37 n = length ( x0 (:));
38 m = length ( y0 (:)); % number o f o u t p u t s
39
40 x_sol = nan (n , points ); % memory a l l o c a t i o n f o r s t a t e h i s t o r y
41 x_drv = nan (n , points ); % memory a l l o c a t i o n f o r s t a t e d e r i v a t i v e h i s t o r y
42 y_sol = nan (m , points ); % memory a l l o c a t i o n f o r o u t p u t h i s t o r y
43 x_sol (: ,1) = x0 (:); % the i n i t i a l conditions for the s t a t e s
44 y_sol (: ,1) = y0 (:); % the i n i t i a l output
45
46 [ ru , cu ] = s i z e ( u );
47 % pad u w i t h z e r o s i f i t i s n o t l o n g enough
48 i f ( cu < points ) , u (: , cu +1: points ) = 0; end
49
50 f o r p = 1: points -1 % advance t h e s o l u t i o n from p t o p+1
51 t = time ( p );
52 dt = time ( p +1) - t ; % t h e time s t e p f o r t h i s i n t e r v a l
53 dt2 = dt /2; % h a l f o f t h e time s t e p
54 [ dxdt1 , y1 ] = f e v a l ( dxdt , t , x0 , u (: , p ) , params );
55 [ dxdt2 , y2 ] = f e v a l ( dxdt , t + dt2 , x0 + dxdt1 * dt2 , ( u (: , p )+ u (: , p +1))/2.0 , params );
56 [ dxdt3 , y3 ] = f e v a l ( dxdt , t + dt2 , x0 + dxdt2 * dt2 , ( u (: , p )+ u (: , p +1))/2.0 , params );
57 [ dxdt4 , y4 ] = f e v a l ( dxdt , t + dt , x0 + dxdt3 * dt , u (: , p +1) , params );
58 x0 = x0 + ( dxdt1 + 2*( dxdt2 + dxdt3 ) + dxdt4 ) * dt /6.0;
59 x_sol (: , p +1) = x0 (:); % next s t a t e
60 x_drv (: , p ) = dxdt1 (:); % current rate
61 y_sol (: , p ) = y1 (:); % current output
62 i f a l l ( isfinite ( x0 )) , break; end % f l o a t i n g point error
63 end
64 [ dxdt1 , y1 ] = f e v a l ( dxdt , time ( p ) , x0 , u (: , p ) , params ); % f i n a l r a t e & o u t p u t
65 x_drv (: , p +1) = dxdt1 (:); % f i n a l rate
66 y_sol (: , p +1) = y1 (:); % f i n a l output
67 % ODE4U

CC BY-NC-ND H.P. Gavin


14 CEE 541. Structural Dynamics Duke University Fall 2016 H.P. Gavin

A Variable-Step Fourth-Fifth-Order Runge-Kutta Solver


For problems in which the time increments are not much shorter than the shortest
natural periods involved in the system, and for problems involving hard nonlinearities, such
as problems involving impact or friction, fixed-step Runge-Kutta solvers may be numerically
unstable. In such cases one may attempt a re-analysis using a shorter time step for every
time step, or one may use a solver in which the large fixed time-steps are automatically sub-
divided only when necessary. A feature of such variable time-step solvers is that a desired
level of accuracy may be enforced throughout the simulation, by comparing a fourth-order
accurate solution with a fifth-order accurate solution.
The implementation of the fourth-fifth order solver discussed here was proposed by
Cash and Karp in 1990.10 To advance the solution from a time t to a time t + t, six state
derivatives are computed

x 1 = f (t + a1 t, x(t), u(t + a1 t)) (60)


x 2 = f (t + a2 t, x(t) + x 1 b21 t, u(t + a2 t)) (61)
x 3 = f (t + a3 t, x(t) + (x 1 b31 + x 2 b32 )t, u(t + a3 t)) (62)
x 4 = f (t + a4 t, x(t) + (x 1 b41 + x 2 b42 + x 3 b43 )t, u(t + a4 t)) (63)
x 5 = f (t + a5 t, x(t) + (x 1 b51 + x 2 b52 + x 3 b53 + x 4 b54 )t, u(t + a5 t)) (64)
x 6 = f (t + a6 t, x(t) + (x 1 b61 + x 2 b62 + x 3 b63 + x 4 b64 + x 5 b65 )t, u(t + a6 t)) (65)

The fourth order predictor at time t + t, is x4 (t + t), and the fifth order predictor at time
t + t, is x5 (t + t).

x4 (t + t) = x(t) + (x 1 c41 + x 3 c43 + x 4 c44 + x 5 c45 + x 6 c46 )t (66)


x5 (t + t) = x(t) + (x 1 c51 + x 3 c53 + x 4 c54 + x 6 c56 )t (67)

The coefficients ai , bij , and cij are provided in Cash and Karps paper. If every term of the
truncation error vector,  = |x4 x5 |/|x5 | is less than the required tolerance, tol , then the
solution x5 is considered sufficiently accurate. In this case, x(t + t) is assigned to x5 , t is
assigned to t + t, and the solution marches on. Otherwise, the time step is divided into Nss
sub-steps,11 where l h   im
Nss = Nss max max (/tol )1/4 , 1.1 , (68)
and Nss is initialized to 1, and de is the round-up operator.
These concepts are implemented in the Matlab function ode45u.m12

10
Cash, J.R. and Karp, A.H., A Variable Order Runge-Kutta Method for Initial Value Problems with
Rapidly Varying Right-Hand Sides, ACM Transactions on Mathematical Software, vol 16, no 3, pp 201-222
(1990). http://www.duke.edu/hpgavin/cee541/Cash-90.pdf
11
Press, W.H., et al., Numerical Recipes, Cambridge Univ. Press, 1993. Section 16.2 http://www.nr.com/
12
http://www.duke.edu/hpgavin/ode45u.m

CC BY-NC-ND H.P. Gavin


Numerical Integration for Structural Dynamics 15

The usage of ode45u.m is very similar to the usage of ode4u.m

ode45u.m
1 % [ time , x , x d o t , y ] = ode45u ( d x d t , time , x0 , u , params , t o l e r a n c e , d i s p l a y )
2 %
3 % S o l v e a sy s te m o f nonhomogeneous o r d i n a r y d i f f e r e n t i a l e q u a t i o n s
4 % u s i n g t h e embedded RungeKutta f o r m u l a s o f J .R. Cash and A.H. Karp , and
5 % u s i n g l i n e a r i n t e r p o l a t i o n o f e x t e r n a l f o r c i n g w i t h i n times t e p s .
6 %
7 % Input Variable Description
8 %
9 % dxdt : a f u n c t i o n o f t h e form [ x d o t , y ] = d x d t ( t , x , u , params )
10 % which p r o v i d e s t h e s t a t e d e r i v a t i v e g i v e n t h e time , t ,
11 % t h e s t a t e , x , e x t e r n a l f o r c i n g , u , and p a r a m e t e r s
12 % a v e c t o r s y st e m o u t p u t s , y , may a l s o be r e t u r n e d .
13 % time : 1byp v e c t o r o f time v a l u e s , u n i f o r m l y i n c r e a s i n g
14 % ( or d e c r e a s i n g ) , a t which t h e s o l u t i o n i s computed .
15 % x0 : nby1 v e c t o r o f i n i t i a l s t a t e v a l u e s , a t time ( 1 ) .
16 % u : mbyp m a t r i x o f s y st e m f o r c i n g d a t a f o r t h e ode ,
17 % sampled a t p o i n t s i n t h e 1byp v e c t o r time .
18 % params : o p t i o n a l p a r a m e t e r s used i n t h e f u n c t i o n d x d t
19 % tolerance : the desired tolerance constant ( d e f a u l t 0.001)
20 % may be a v e c t o r o f t h e l e n g t h o f x0 , or a s c a l a r
21 % display : 3= d i s p l a y l o t s o f r e s u l t s ; 2= d i s p l a y l e s s ; 1= even l e s s
22 %
23 % Output V a r i a b l e Description
24 %
25 % time : i s r e t u r n e d , unchanged
26 % x : the s o l u t i o n to the d i f f e r e n t i a l equation at times
27 % x dot : the d e r i v a t i v e to the d i f f e r e n t i a l equation at times
28 % y : the output of the d i f f e r e n t i a l equation at times
29 %

Numerical Example
In this example ode4u.m is used to solve the transient response of an inelastic system
described by the equations:

+ z(t) = w(t)
r(t) + 2n r(t) (69)
 

z(t) = 1 z 3 sgn(r(t))

r(t)/dy. (70)

with initial conditions r(0) = 0, r(0)


= 0, z(0) = 0. The paramter is a plastic force level
divided by the mass ( = fp /m), and the paramter dy is a yield displacement. The external
forcing is ground acceleration, w(t),
given by
(
Ao sin(2t/Tp ) 0 t Tp
=
w(t) (71)
0 otherwise

In state space, these equations may be expressed as x = f (t, x, u, p)



r(t)
r(t)
d

r(t) = 2n r(t)
z(t) w(t)
(72)

dt

3
z(t) (1 z sgn(r(t)))

r(t)/dy.

These ordinary differential equations are computed in the short m-file inelasSys.m

CC BY-NC-ND H.P. Gavin


16 CEE 541. Structural Dynamics Duke University Fall 2016 H.P. Gavin

1 function [ dxdt , fi ] = inelasSys (t ,x , a_g , p )


2 % [ dxdt , f i ] = i n e l a s S y s ( t , x , a g , p )
3 % dynamics o f an SDOF i n e l a s t i c s ys t e m
4
5 % state vector ...
6 r = x (1); % displacement response , m
7 r_dot = x (2); % v e l o c i t y r e s p o n s e , m/ s
8 z = x (3); % hysteretic variable
9
10 % parameters . . .
11 wn = p (1); % n a t u r a l f r e q u e n c y , rad / s
12 zeta = p (2); % v i s c o u s damping r a t i o
13 mu = p (3); % y i e l d f o r c e d i v i d e d by mass , m/ s 2
14 dy = p (4); % y i e l d displacement , m
15
16 fi = mu * z ; % inelastic force
17
18 % state equations
19 dxdt = [ r_dot ; % v e l o c i t y response
20 -2* zeta * wn * r_dot - fi - a_g ; % acceleration response
21 (1 - z 3 * sign ( r_dot )) * r_dot / dy ]; % inelastic force derivitive

And the simulation may be executed using the m-file inelasSim.m


1 % i n e l a s S i m .m s i m u l a t e t h e r e s p o n s e o f a SDOF i n e l a s t i c s y st e m u s i n g ode4u .m
2
3 % parameters . . .
4 g = 9.81; % g r a v i t a t i o n a l a c c e l e r a t i o n , m/ s 2
5 k = 5000; % s t i f f n e s s , N/m
6 m = 100; % mass , kg
7 zeta = 0.02; % v i s c o u s damping r a t i o
8 fp = 95.0; % plastic force level , N
9 Tp = 1.0; % pulse period , s
10 Ao = 1.0; % p u l s e a m p l i t u d e , m/ s 2
11
12 mu = fp / m ; % y i e l d f o r c e d i v i d e d by mass , m/ s 2
13 wn = sqrt ( k / m ); % n a t u r a l f r e q u e n c y , rad / s
14 dy = fp / k ; % y i e l d displacement
15
16 p = [ wn , zeta , mu , dy ]; % v e c t o r o f s y st e m p a r a m e t e r s
17
18 % time a x i s d a t a . . .
19 T = 5; % duration of simulation , sec
20 dt = 0.005; % time s t e p , s
21 N = f l o o r ( T / dt ); % number o f d a t a p o i n t s
22 t = [1: N ]* dt ; % time , s
23
24 % ground a c c e l e r a t i o n i n p u t d i s t u r b a n c e , m/ s 2 . . .
25 a_g = Ao * s i n (2* pi * t / Tp ); a_g ( f l o o r ( Tp / dt ):end ) = 0;
26
27 x0 = [ 0; 0; 0]; % i n i t i a l states : [ displ ; veloc ; inelastic force ]
28 [t ,x , dxdt , fi ] = ode4u ( inelasSys , t , x0 , a_g , p ); % s i m u l a t e r e s p o n s e u s i n g ode4u
29
30 % P l o t s
31 %e p s P l o t s = 0 ; i f e p s P l o t s , f o r m a t P l o t ( 1 4 , 7 , 4 ) ; e l s e f o r m a t P l o t ( 0 ) ; end
32 f i g u r e (1)
33 plot ( t , x (1 ,:) , t , x (2 ,:) );
34 ylabel ( response )
35 xlabel ( time , s )
36 legend ( displacement response , m , velocity response , m / s )
37 %i f e p s P l o t s , p r i n t ( i n e l a s S i m 1 . eps , c o l o r , s o l i d , F H e l v e t i c a : 1 4 ) ; end
38 f i g u r e (2)
39 plot ( x (1 ,:) , fi );
40 xlabel ( displacement , m )
41 ylabel ( inelastic force / mass , m / s 2 )
42 %i f e p s P l o t s , p r i n t ( i n e l a s S i m 2 . eps , c o l o r , s o l i d , F H e l v e t i c a : 1 4 ) ; end

CC BY-NC-ND H.P. Gavin


Numerical Integration for Structural Dynamics 17

0.4
displacement response, m
velocity response, m/s

0.3

0.2
response

0.1

-0.1

-0.2
0 1 2 3 4 5
time, s

0.5
inelastic force/mass, m/s2

-0.5

-1
-0.06 -0.04 -0.02 0 0.02 0.04 0.06
displacement, m

CC BY-NC-ND H.P. Gavin