Skip to main content

A framework for modelling and simulation of dynamical systems

Project description

dynode

codecov docs

A framework for modelling and simulation of dynamical systems in the form of ordinary differential equations.

--> Documentation <--

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:

Van der Pol 2nd order differential equation

Rewriting it to a system of ordinary differential equations yields:

Van der Pol ODE1

Van der Pol ODE2

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')
sys.add_store('states', '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 to 0.1*sin(0.1*t)
  • The damping parmeter (mu) of oscillator 2 is forced to follow the the state y 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


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

dynode-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file dynode-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dynode-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for dynode-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 537973aeeaf96ba07d26ad55b444d793d6c4ff979e250ff7193200d5b4a20679
MD5 6f8f287196bd0f07f3da6fb40ec970b4
BLAKE2b-256 4753c0bd411910cfdfb18bcadb5eea4e45affba71f5bf57794504c47d54a3a11

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