pydykit - A Python-based Dynamics toolKIT
Repository | https://github.com/pydykit/pydykit |
Copyright | Copyright © 2024 - 2025 The authors of pydykit |
Table of Contents
Welcome to¶
What is pydykit
?¶
pydykit
is a Python-based dynamics simulation toolkit for dynamical systems. The package is based on time stepping methods, which are discrete versions of the corresponding dynamics equations - either ordinary differential equations (ODEs) or differential-algebraic equations (DAEs).
How to install?¶
Directly install from the Python Package Index (PyPI) with
pip install pydykit
or clone the repository and install the package locally, following these steps:
- Create a new virtual environment and activate it.
We recommend using
venv
:python3.12 -m venv .venv source .venv/bin/activate
- Clone the repository
- Install in editable- / development-mode:
pip install --editable .
- Run your first script, e.g.
python scripts/s*.py
How to use?¶
Check out the
getting started to familiarize yourself with pydykit
and
examples for more details.
Who are we?¶
- Julian K. Bauer - Code architect - @JulianKarlBauer
- Philipp L. Kinon - Core developer - @plkinon
Getting Started¶
A pydykit
-simulation contains several building blocks,
which are at least a system
, integrator
, simulator
and a time_stepper
.
These building blocks are defined within a config file.
Config File¶
A pydykit
-config file configures a simulation devided into several building blocks.
Each building blocks consists of parameters and methods.
Example config files can be found in pydykit/example_files
and some of them are discussed in more detail in the section examples.
System¶
The system
defines the system of ordinary differential equations (ODEs)
or differential algebraic equations (DAEs), to be solved.
Pydykit
covers three system families,
which are:
- Multibody systems
- Port-Hamiltonian systems
- Quasilinear DAEs
Lets briefly introduce them one by one.
1. Multibody system (MBS) dynamics ¶
This family covers DAEs belonging to mechanical systems composed of multiple rigid bodies, governed by
where \(q\) and \(p\) are generalized coordinates and momenta, respectively, \(M\) is the mass matrix, \(V\) is the potential energy, \(D\) is the Rayleigh dissipation matrix and \(g\) are independent, holonomic constraint functions enforced by Lagrange multipliers \(\lambda\). One example can be studied in more detail, the 3D pendulum.
2. Port-Hamiltonian systems (PHS)¶
Port-Hamiltonian systems are an extension of classical Hamiltonian dyamics with respect to dissipative effects and interconnection terms from the environment. This energy-based approach combines dynamics from various physical disciplines in one formalism and emerges from control systems theory. The dynamics follow
with state \(x\), co-state function \(z\), possibly singular descriptor matrix \(E\), structure matrix \(J=-J^{\mathrm{T}}\), positive semi-definite dissipatrix matrix \(R=R^{\mathrm{T}}\), input matrix \(B\), control input \(u\) with collocated output \(y\) and Hamiltonian \(H\).
3. Quasilinear DAEs¶
This last framework is an even more general one. It comprises all DAEs of the general form
where \(E\) is a possibly singular descriptor matrix, \(x\) are the unknowns/states and \(f\) denotes an arbitrary right-hand side function. Examples that can be studied in more detail, are the Lorenz attractor and the chemical reactor.
Integrator¶
The integrator
defines the numerical integration scheme
to be used for the system at hand.
As the integration scheme defines whether a numerical procedure preserves the underlying structure of the problem,
pydykit
places particular emphasis on integrator classed.
Although a system may fit into even two or three of the abovementioned framework,
the user might want to introduce specialized integrators to capture as much of the underlying structure as possible,
e.g. exactly preserve the constraint functions of the MBS or the skew-symmetry of the structure matrix of a PHS.
Simulator¶
The simulator
defines the solution procedure to be used.
This includes the equation solver to be used,
e.g. Newton's method and its characeteristics such as accuracy.
Time Stepper¶
The time_stepper
defines the discrete temporal grid,
where approximative solutions are computed.
Currently, pydykit
supports one-step methods only,
i.e. for a known solution at one time-instance pydykit
computes the solution at the next time instance on the specified grid.
Examples ↵
Pendulum 3D¶
Let's use the system class pydykit.systems_multi_body.ParticleSystem
to simulate a single particle with concentrated mass within a three-dimensional space.
The particle's initial position is
(1.0, 0.0, 0.0)
and its initial velocity points into the y
-direction.
The particle's distance to a fixed support at (0.0, 0.0, 0.0)
is constraint to be of length 1.0
and there is a gravitational field into negative z
-direction.
In consequence, the particle is called a 3D pendulum
and its motion is visualized in belows Result
tab.
The source code of leading to this viosualization is given within the Source
tab.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
Config File¶
Let's have a closer look at the configuration file of this simulation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
System¶
The system
-section in the above configuration file
defines the scene, aka. system, to be simulated.
This includes definition of the particle, the fixed support, the constraint and the gravitation.
The system
-sections variable class_name
tells pydykit
that the
scene shall be based on the system class
ParticleSystem
,
which belongs to the family of MBS.
This class is known to pydykit
as it has been
registered
within the
SystemFactory
.
Integrator¶
The integrator
-section in the above configuration file
defines the integration scheme to be used.
Here, the implicit midpoint rule will be applied
to the system which is formulated as a MBS.
Similar to the registration pattern of the system
,
the variable class_name
within section integrator
tells pydykit
to use the class
MidpointMultibody
.
This class is known to pydykit
as it has been
registered
within the
IntegratorFactory
.
The pattern of referencing a registered Python class in terms of class_name
also applies to the sections simulator
and time_stepper
.
Simulator¶
The simulator
-section
defines the solution procedure, aka. simulator, to be used.
The simulator uses a Newton method with
a specific accuracy for the norm of the residual newton_epsilon
and a maximum number of iterations per time step before the simulation procedure is stopped.
Time Stepper¶
The time_stepper
-section defines the time stepping algorithm based on settings for
start time, end time and step size.
Lorenz System¶
Let's use the system class pydykit.systems_dae.Lorenz
to simulate the famous Lorenz attractor,
which is modelled in terms a quasilinear differential algebraic equations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
Config File¶
The configuration file of this simulation reads as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
For details on the usage of class_name
-variable, see the example Pendulum 3D
.
Chemical Reactor¶
Let's use the system class pydykit.systems_dae.ChemicalReactor
to represent a chemical reactor in terms of a differential-algebraic system and solve it's behavior in time.
This system is modelled as quasilinear differential-algebraic equations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
Config File¶
The configuration file of this simulation reads as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
For details on the usage of class_name
-variable, see the example Pendulum 3D
.
List Examples¶
Examples shipped with pydykit
can accessed with
pydykit.examples.ExampleManager
.
This is demonstrated by the list of available examples within the tab Result
shown below.
The source code generating this list, is shown in tab Source
.
- four_particle_system_discrete_gradient_dissipative config file
- four_particle_system_midpoint config file
- four_particle_system_ph_discrete_gradient_dissipative config file
- four_particle_system_ph_midpoint config file
- lorenz config file
- pendulum_2d config file
- pendulum_3d config file
- reactor config file
- rigid_body_rotating_quaternion config file
- two_particle_system config file
- visco_pendulum config file
1 2 3 4 5 6 7 8 9 10 11 12 |
|