Skip to main content

Dynamic System Simulators

Project description

DynaSim

GitHub repo size GitHub contributors

The dynasim package simulates dynamic systems in the form:

\mathbf{M}\ddot{\mathbf{x}} + \mathbf{C}\dot{\mathbf{x}} + \mathbf{K}\mathbf{x} + \mathbf{C}_n g_c(\mathbf{x}, \dot{\mathbf{x}}) + \mathbf{K}_n g_k(\mathbf{x}, \dot{\mathbf{x}}) = \mathbf{f}

where $\mathbf{\Xi}n g{\bullet}(\mathbf{x},\dot{\mathbf{x}}) = \mathbf{C}_n g_c(\mathbf{x}, \dot{\mathbf{x}}) + \mathbf{K}_n g_k(\mathbf{x}, \dot{\mathbf{x}})$ represents the nonlinear system forces. For example, a 3DOF Duffing oscillator, connected at one end, would have representative nonlinear forces,

\mathbf{K}_n g_n(\mathbf{x}) = \begin{bmatrix}
    k_{n,1} & - k_{n,2} & 0 \\
    0 & k_{n,2} & -k_{n,3} \\
    0 & 0 & k_{n,3}
\end{bmatrix}
\begin{bmatrix}
    x_1^3 \\
    (x_2-x_1)^3 \\
    (x_3 - x_2)^3
\end{bmatrix}

Installing DynaSim

To install DynaSim, follow these steps:

Linux and macOS:

python3 -m pip install dynasim

Windows:

py -m pip install dynasim

Using DynaSim

Quickstart Guide

To use DynaSim, here is a quick start guide to generate a 5-DOF oscillating system with some cubic stiffness nonlinearities:

import numpy as np
import dynasim

# create required variables
n_dof = 5

# create a time vector of 2048 time points up to 120 seconds
nt = 2048
time_span = np.linspace(0, 120, nt)

# create vectors of system parameters for sequential MDOF
m_vec = 10.0 * np.ones(n_dof)
c_vec = 1.0 * np.ones(n_dof)
k_vec = 15.0 * np.ones(n_dof)
# imposes every other connection as having an additional cubic stiffness
kn_vec = np.array([25.0 * (i%2) for i in range(n_dof)])

# create nonlinearities
system_nonlin = dynasim.nonlinearities.exponent_stiffness(kn_vec, exponent=3, dofs=n_dof)
# instantiate system and embed nonlinearity
system = dynasim.systems.mdof_cantilever(m_vec, c_vec, k_vec, dofs=n_dof, nonlinearity=system_nonlin)

# create excitations and embed to system
system.excitations = [None] * n_dof
system.excitations[-1] = dynasim.actuators.sine_sweep(w_l = 0.5, w_u = 2.0, F0 = 1.0)

# simulate system
data = system.simulate(time_span, z0=None)

Nonlinearities

Three nonlinearities are available, exponent stiffness, exponent damping, and Van der Pol damping

dynasim.nonlinearities.exponent_stiffness(kn_vec, exponent=3, dofs=n_dof)
dynasim.nonlinearities.exponent_damping(cn_vec, exponent=0.5, dofs=n_dof)
dynasim.nonlinearities.vanDerPol(cn_vec, dofs=n_dof)

These classes contain the $g_k(\mathbf{x}, \dot{\mathbf{x}})$ function.

Common system classes

There are a currently two system types available for MDOF systems, which are instantiated from vectors of system parameter values:

dynasim.systems.mdof_symmetric(m_, c_, k_, dofs, nonlinearity)
dynasim.systems.mdof_cantilever(m_, c_, k_, dofs, nonlinearity)
dynasim.systems.bid_mdof_walled(m_vec, ch_mat, cv_mat, kh_mat, kv_mat)

Actuator classes

The forcing for the system should be a list of actuations, equal in length to the number of DOFs of the system, there many actuation types,

dynasim.actuators.sinusoid(...)
dynasim.actuators.white_gaussian(...)
dynasim.actuators.sine_sweep(...)
dynasim.actuators.rand_phase_ms(...)
dynasim.actuators.banded_noise(...)

Totally custom system

One can generate a custom system by instantiating an MDOF system with corresponding modal matrices, but the nonlinearity must also be instantiated and

dynasim.base.mdof_system(M, C, K, Cn, Kn)

Continuous Beams

These work much like the MDOF systems but with a few tweaks. Where beam_kwargs_cmb is a dictionary of combined properties of the beam.

beam_kwargs_cmb = {
    "EI" : EI,  # Young's Modulus multiplied by second moment of intertia
    "pA" : pA,  # density multiplied by cross sectional area
    "c" : c,  # damping
    "l" : l  # length of beam
}
ss_beam = dynasim.systems.cont_beam("cmb_vars", **beam_kwargs_cmb)

One can then generate and retrieve the mode shapes of the beam via

xx, phis = ss_beam.gen_modes(support, n_modes, nx)

Where support is a string representing different support types for the beam, options available are:

Code Description
ss-ss Simply supported at both ends
fx-fx Fixed at both ends
fr-fr Free at both ends
fx-ss Fixed at one end and simply supported at the other
fx-fr Fixed at one end and free at the other

Then, excitations are added as a list of dictionaries containing the location (in m) and excitation (prescribed as with mdof systems)

ss_beam.excitations = [
    {
        "excitation" : dynasim.actuators.sinusoid(1.2, 1.0),
        "loc" : 0.25
    }
]

Then simulate just as with the MDOF system, however, the returned data here is the modal coordinates, and so to retrieve displacement, simply multiply by, and sum through, the mode shapes.

data = ss_beam.simulate(tt, z0 = tau0)

ww = np.sum(np.matmul(data['x'][:,:,np.newaxis], phis.T[:,np.newaxis,:]), axis=0)
wwd = np.sum(np.matmul(data['xdot'][:,:,np.newaxis], phis.T[:,np.newaxis,:]), axis=0)

Contact

If you want to contact me you can reach me at mhaywood@ethz.ch.

License

This project uses the following license: MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynasim-0.1.7.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

dynasim-0.1.7-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file dynasim-0.1.7.tar.gz.

File metadata

  • Download URL: dynasim-0.1.7.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for dynasim-0.1.7.tar.gz
Algorithm Hash digest
SHA256 b2e077dbe9094103080cb1ff5460181e93818b3ab1c13bc3869231604601ca6f
MD5 aea111fa48872c473f53876492d6c79a
BLAKE2b-256 f30fabf2c90fdce9c8b886e8c57a944083abeb70924ff6ba52ab91a3599340c7

See more details on using hashes here.

File details

Details for the file dynasim-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: dynasim-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for dynasim-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fdb64a785ad08b2297c7f0fd423e83b3b62505addd8dcddc1b238684884a99c3
MD5 e21f832bf8dc7bec96906c73fc40d046
BLAKE2b-256 fe6ef0824d2c1df5da0d9ce87528ace0c4e2dc8c34b5a63d7b372999bcb42ce2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page