Skip to main content

pyBondGraph

pyBondGraph is a Python library for modeling and analyzing linear bond graph systems using symbolic computation.

The library allows users to construct bond graph models programmatically, automatically derive the governing equations, and analyze the resulting dynamic systems using tools from control theory.

Bond graphs provide a domain-independent modeling framework for physical systems. Using a unified representation of power exchange, the same modeling approach can be used for electrical, mechanical, hydraulic, and multi-domain systems.


Features

  • Programmatic construction of bond graph models
  • Automatic symbolic equation derivation using SymPy
  • Conversion of models to state-space systems
  • Example models for electrical and mechanical systems

Installation

Install from PyPI or Github

The easiest way to install the library is via your preferred package manager (e.g. pip) directly from PyPI:

pip install pyBondGraph

Alternatively one can install the latest development version directly from the GitHub repository:

pip install git+https://github.com/MrP123/pyBondGraph.git

Development installation

To work with the source code:

git clone https://github.com/MrP123/pyBondGraph.git
cd pyBondGraph
pip install -e .

Dependencies

The main dependencies are:

  • sympy
  • numpy
  • networkx
  • matplotlib
  • control only needed for the examples

Optional dependencies are used for experimental visualization tools.


Basic Usage

A bond graph model is constructed by creating elements and connecting them via bonds.

Simple RC-Filter circuit:

from pyBondGraph import BondGraph, SourceEffort, Resistor, Capacitor, OneJunction, Bond, Causality

bg = BondGraph()

# create elements
voltage_source = SourceEffort("U", "u_in")
resistor = Resistor("R", "R")
capacitor = Capacitor("C", "C")
series_junction = OneJunction("J1")

# connect elements
# causalities need to be assigned manually 
bg.add_bond(Bond(voltage_source, series_junction, Causality.EFFORT_OUT))
bg.add_bond(Bond(series_junction, resistor, Causality.EFFORT_OUT))
bg.add_bond(Bond(series_junction, capacitor, Causality.FLOW_OUT))

# plot the resulting BondGraph
bg.plot()

# derive system equations in linear state space form
A, B, C, D, x, n_states, n_inputs, n_outputs = bond_graph.get_state_space()

The library automatically derives the symbolic system equations describing the dynamics of the model.


Core Concepts

Bond graphs represent power exchange between system components, where power is the product of effort and flow associated with the following components:

Elements

Element Meaning
R Dissipation
C Energy storage (compliance, capacitance)
I Energy storage (inertia, inductance)
Se Effort source
Sf Flow source

Junctions

Junction Meaning
0 Common effort
1 Common flow

Sensors

Sensor Meaning
IntegratedEffortSensor Measures integral of the effort at its bond
IntegratedFlowSensor Measures integral of the flow at its bond

In mechanical bond graph models:

  • flow corresponds to velocity
  • effort corresponds to force

An integrated flow sensor can therefore be used to compute position:


Example Systems

The repository contains example models illustrating typical applications of bond graphs.

RLC Circuit

Demonstrates modeling of an electrical circuit using bond graph elements.

DC Motor

A multi-domain electromechanical system coupling electrical and mechanical dynamics.

Transformer

Example of energy transformation between two ports.

Two DOF Mass–Spring–Damper System

Classical mass-spring-damper system with two degrees of freedom.


Typical Applications

Bond graph modeling is particularly useful for:

  • electromechanical systems
  • robotics and mechatronics
  • multi-domain energy systems
  • control system modeling
  • teaching system dynamics

Metadata

Release files for pyBondGraph 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyBondGraph 0.2.0
File Size Uploaded
pybondgraph-0.2.0.tar.gz 18.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyBondGraph 0.2.0
File Interpreter ABI Platform
pybondgraph-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.0 kB

Release files / pybondgraph-0.2.0.tar.gz

Download URL pybondgraph-0.2.0.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0ca8f23130e614063dbf52160ba6367c64634114c7b1a84f38da351d762a665d
BLAKE2b-256 checksum
How to use checksums
53ace1ba7bc1bf2e67b04efdfd4afd13edac4bd3e3799bbcc55dd1dc4183a10e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / pybondgraph-0.2.0-py3-none-any.whl

Download URL pybondgraph-0.2.0-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bbee3ad0c02c5a6420112ce4f8e1507113d7d283e37c0ad8d833189e7ef7665
BLAKE2b-256 checksum
How to use checksums
afc4794a46dea630a4819f36dadbe62bd210f563bcd8f8780d81e022692d0766
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page