Runge-Kutta ODE Solver
From Python Wiki
ODE = ordinary differential equation
SDOF = single-degree-of-freedom
MDOF = multi-degree-of-freedom
The scripts on this page require the utility modules:
The Runge-Kutta family of numerical methods may be used to solve ordinary differential equations with initial conditions.
The solution is given in the time domain. Thus, the Runge-Kutta method may be used for modal transient analysis.
Note that the Runge-Kutta method may give unstable results for certain "stiff" systems.
The Newmark-beta ODE Solver is thus preferred in most structural dynamics texts.
Another robust method is the Digital Recursive Filtering Relationship ODE Solver.
The odeint function in the scipy.integrate package is a wrapper around lsoda, an ODE integrator developed at Lawrence Livermore National Lab, as part of the odepack package. lsoda/odeint automatically switches between stiff and non-stiff integration routines, depending on the characteristics of the solution, and does adaptive time-stepping to achieve a desired level of solution accuracy.
The function may be accessed via
from scipy.integrate import odeint
Free Vibration Example
A similar multi-degree-of-freedom (MDOF) system script is given at: mdof_initial.py
The MDOF script shows how odeint can be applied to simultaneous second-order ODEs.
Response to Sinusoidal Base Excitation
A script for the response of an SDOF system subjected to sinusoidal base excitation is given at: sdof_base_sine.py
An example is given in: sdof_base_py.pdf.
Response to Arbitrary Base Input
The odeint solver is intended for initial condition excitation and for external excitation where the forcing function is a continuous analytical function.
The odeint function can be used for a random or arbitrary excitation as follows. First, take a Fourier transform of the forcing function. Second, pass the Fourier coefficients and frequencies to the ode function. Third, represent the excitation time history via a series of analytical sine and cosine terms inside the ode function. This method requires careful bookkeeping. It is also numerically inefficient. Thus, it is only recommended in academic settings.
A faster approach is to simply use the Runge-Kutta Fourth-order method, as shown in the following script.
A script for the response of an SDOF system subjected to arbitrary base excitation is given at: arbit_rk4.py
SDOF Response to Arbitrary Applied Force
The script is given at: arbit_force_rk4.py
MDOF Response to Arbitrary Applied Force via Direct Integration
This approach is intended for the case where the damping is specified in terms of a viscous damping coefficient matrix.
The script is given at: mdof_arbit_force_rk4.py.
MDOF Response to Arbitrary Applied Force via Modal Transient Solution
This approach is intended for the case where the damping is specified in terms of modal damping ratios. The system is decoupled via the eigenvectors as an intermediate step.
The script is given at: mdof_modal_arbit_force_rk4.py.
MDOF Response to Base Excitation, Modal Transient
The response to base acceleration or enforced acceleration is given at: mdof_modal_enforced_acceleration_rk4.py. It is intended for the case where damping is applied via a modal damping ratio. The system is first partitioned via a transformation matrix. Next it is decoupled using normal modes. Then the response is calculated using the RK4 method as a modal transient solution. A partition tutorial is given at: modal_enforced_motion.pdf.