A framework for modelling and simulation of dynamical systems
Project description
dynode
A framework for modelling and simulation of dynamical systems in the form of ordinary differential equations.
Requires python >= 3.6
General
Dynode solves equations of the form y' = f(t, y)
using SciPy's ode solver but allows f
to be modelled in a modular, object-oriented fashion using the notions of separate Systems
that expose states
and their corresponding derivatives, ders
. f
may then be composed of an arbitraily complex collection of, connected or unconnected, Systems
.
Example: Single Van der Pol oscillator
A well-known dynamical system is the Van der Pol oscillator, which is described by a second-order differential equation:
Rewriting it to a system of ordinary differential equations yields:
In dynode, a Van der Pol system
may be modelled as:
from dynode import SystemInterface
class VanDerPol(SystemInterface):
def __init__(self):
super().__init__()
self.inputs.mu = 1.0
self.states.x = 0.0
self.ders.dx = 0.0
self.states.y = 0.0
self.ders.dy = 0.0
def do_step(self, time):
mu = self.inputs.mu
x = self.states.x
y = self.states.y
self.ders.dx = y
self.ders.dy = mu*(1-x**2)*y - x
And may be simulated like this:
from dynode.simulation import Simulation
sys = VanDerPol()
sys.add_store('states.x', alias='x')
sys.add_store('states.y', alias='y')
sim = Simulation()
sim.add_system(sys)
sys.states.x = 1
sim.simulate(100, 0.1)
import matplotlib.pyplot as plt
plt.plot(sys.res.time, sys.res['x'])
plt.plot(sys.res.time, sys.res['y'])
plt.show()
Connected systems
Dynode systems accepts connections
as callbacks registered to a system. The callback signature looks like:
def connection_callback(system, time):
pass
where system
is a reference to the system this callback is registered to and time
is the current time in the simulation.
Connections can be either pre_step_connections
or post_step_connections
depending on if the callback should be called prior to or after the do_step
-method of the system
Example: Two connected Van der Pol oscillators
Imagine the situation where you have two oscillators interacting as follows:
- The damping paramater (
mu
) of oscillator 1 is forced by a sinus wave according to0.1*sin(0.1*t)
- The damping parmeter (
mu
) of oscillator 2 is forced to follow the the statey
of oscillator 1
In dynode, the above scenario can be described and simulated as:
from dynode import connect_signals
sys1 = VanDerPol()
sys1.states.x = 1
sys2 = VanDerPol()
# Connecting state y of sys1 to input mu of sys2
sys1.add_post_connection(connect_signals(sys1.states, 'y', sys2.inputs, 'mu'))
# Forcing input mu of sys1 to follow a sinus function
def sinus_forcer(sys, t):
sys.inputs.mu = 0.1*np.sin(0.1*t)
sys1.add_pre_connection(sinus_forcer)
sim = Sim()
sim.add_system(sys1)
sim.add_system(sys2)
sim.simulate(100, 0.1)
License
Distributed under the terms of the MIT license, dynode
is free and open source software
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file dynode-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: dynode-0.3.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b0dc16d1c5534761bd17382c135832c00fe8ed5d603b993fcbe93885d765b92 |
|
MD5 | 919bd0ca2e67283095a098cb6728ddbd |
|
BLAKE2b-256 | 99822e27980139f93d2610f6ca13a75f54589d69460fbf4513f5e4518c199073 |