Python Runge-Kutta ODE Solver

Acronyms

ODE = ordinary differential equation

SDOF = single-degree-of-freedom

MDOF = multi-degree-of-freedom

* * *

Supporting Functions

The scripts on this page require the utility modules:

tompy.py

ode_plots.py

generalized_eigen.py

* * *

Runge-Kutta

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.

* * *

odeint

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 script for the response of a single-degree-of-freedom (SDOF) system subjected to initial condition excitation is given at: sdof_initial.py. An example is given in: sdof_initial_py.pdf.

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

Python Newmark-beta ODE Solver

Acronyms

ODE = ordinary differential equation

SDOF = single-degree-of-freedom

MDOF = multi-degree-of-freedom

* * *

Supporting Functions

The scripts on this page require the utility modules:

tompy.py

ode_plots.py

generalized_eigen.py

Newmark.py

Some of the scripts use the generalized eigenvalue function to calculate the natural frequencies. This step is not part of the Newmark calculation except for the modal transient implementations. Rather the natural frequencies are given for reference only for the direct implementation.

* * *

Newmark-beta Function

The Newmark-beta method is used for direct integration of a system of structural dynamics equations.

The system equations are second-order ordinary differential equations. The system may be excited by initial conditions or an external forcing function.

* * *

Free Vibration

The following examples use the Newmark function.

The response of a single-degree-of-freedom system to initial excitation is given at: sdof_initial_nm.py

The response of a multi-degree-of-freedom system to initial excitation is given at: mdof_initial_nm.py

* * *

Response to Applied Force, Direct Integration

The response of a multi-degree-of-freedom system to an applied force or forces is given at: mdof_arbit_force_nm.py. It is intended for the case where damping is applied via a damping coefficient matrix.

* * *

Response to Applied Force, Modal Transient

The response of a multi-degree-of-freedom system to an applied force or forces is given at: mdof_modal_arbit_force_nm.py. It is intended for the case where damping is applied via a modal damping ratio. The system is decoupled via the normal modes as an intermediate step.

* * *

Response to Base Excitation, Modal Transient

The response of a multi-degree-of-freedom system to base acceleration or enforced acceleration is given at: mdof_modal_enforced_acceleration_nm.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 Newmark method as a modal transient solution. A partition tutorial is given at: modal_enforced_motion.pdf

* * *

– Tom Irvine

Python Digital Recursive Filtering Relationship ODE Solver

Acronyms

ODE = ordinary differential equation

SDOF = single-degree-of-freedom

MDOF = multi-degree-of-freedom

* * *

Utilities

The scripts on this page require the utility modules

tompy.py

ode_plots.py

generalized_eigen.py

* * *

Filter Implementation

The digital recursive filtering relationship can be implemented in Python by importing the lfilter function from scipy.

from scipy.signal import lfilter

* * *

Arbitrary Base Input – Time Domain Response for a given SDOF System

Digital recursive filtering relationship method: arbit.py

* * *

Arbitrary Applied Force – Time Domain Response for a given SDOF System

A script for the SDOF response to an applied force is given at: arbit_force.py

* * *

Arbitrary Applied Force – Time Domain Response for a given MDOF System

A script for the MDOF response to applied forces is given at: mdof_modal_arbit_force_ri.py

* * *

External References

Smallwood

Irvine Force Ramp Invariant

Irvine General Coordinate

Irvine Impulse Response Function 1

Irvine Impulse Response Function 2

Irvine Ramp Invariant Base

Irvine Enforced Motion

Vibrationdata SRS Page