Dynamic system Tutorial¶
Access to example scripts on github: https://github.com/masfaraud/BMSpy/tree/master/scripts
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.)
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])
Defining the model¶
te=10# time of end in seconds
ns=2000 # number of time steps
model=bms.DynamicSystem(te,ns,[block])
See also
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
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)