Dynamic system Tutorial

The DynamicSystem Class is a python class defined by BMS core. It allows to define a complete model containing all the data for simulation.

Defining a model

First, we need to import bms:

import bms

Defining signals

Inputs are special variable in the model which are not computed. See the Signals list in reference

Here we define a ramp named which name is e

from bms.signals.functions import Ramp
e=Ramp('e',1.)

See also

class bms.signals.functions.Ramp(name='Ramp', amplitude=1, delay=0, initial_value=0)[source]

Create a ramp such as : f(t)=(t-delay)*amplitude+initial_value

Defining Variables

Let’s define a variable s which will be the output of a first order block

s=bms.Variable('s')

See also

class bms.Variable(names='variable', initial_values=[0], hidden=False)[source]

Defines a variable

Parameters:names – Defines full name and short name.

If names is a string the two names will be identical otherwise names should be a tuple of strings (full_name,short_name) :param hidden: inner variable to hide in plots if true

Defining Blocks

See the list of available Blocks

For this example, let’s define a first order block:

from bms.blocks.continuous import ODE
block=ODE(e,s,[1],[1,3])

See also

class bms.blocks.continuous.ODE(input_variable, output_variable, a, b)[source]

a,b are vectors of coefficients such as H, the transfert function of the block, may be written as: H(p)=(a[i]p**i)/(b[j]p**j) (Einstein sum on i,j) p is Laplace’s variable

Defining the model

te=10# time of end in seconds
ns=2000 # number of time steps
model=bms.DynamicSystem(te,ns,[block])

See also

class bms.DynamicSystem(te, ns, blocks=[])[source]

Defines a dynamic system that can simulate itself

Parameters:
  • te – time of simulation’s end
  • ns – number of steps
  • blocks – (optional) list of blocks defining the model

The blocks are given in a list as third argument.

Model methods

Simulating

model.Simulate()

See also

class bms.DynamicSystem(te, ns, blocks=[])[source]

Defines a dynamic system that can simulate itself

Parameters:
  • te – time of simulation’s end
  • ns – number of steps
  • blocks – (optional) list of blocks defining the model

Plotting variables

model.PlotVariables()

See also

class bms.DynamicSystem(te, ns, blocks=[])[source]

Defines a dynamic system that can simulate itself

Parameters:
  • te – time of simulation’s end
  • ns – number of steps
  • blocks – (optional) list of blocks defining the model

Accessing values

Values of variables at a given time t is accessible by:

model.VariablesValues(t)

See also

class bms.DynamicSystem(te, ns, blocks=[])[source]

Defines a dynamic system that can simulate itself

Parameters:
  • te – time of simulation’s end
  • ns – number of steps
  • blocks – (optional) list of blocks defining the model
VariablesValues(variables, t)[source]

Returns the value of given variables at time t. Linear interpolation is performed between two time steps.

Parameters:
  • variables – one variable or a list of variables
  • t – time of evaluation

The time values vector of a variable is accessible via the values attribute:

import matplotlib.pyplot as plt
plt.plot(model.t,e.values)
plt.plot(model.t,s.values)

Physical Modelling Tutorial

BMS offers to model physical system by generating automaticaly the block model (DynamicSystem object of BMS) from an intuitive, physical model.

The physical model consists in Physical nodes which have a potential variable and are connected by blocks which connection give a flux to the node. Example of physical nodes:

  • an electric node has a voltage variable and receive fluxes (electric currents) from each block connected
  • an hydraulic node has a pressure variable and receive flows

Other Examples

See the project examples folder on github: https://github.com/masfaraud/BMSpy/tree/master/bms/examples