block_diagram module

class simupy.block_diagram.BlockDiagram(*systems)[source]

A block diagram of dynamical systems with their connections which can be numerically simulated.

Initialize a BlockDiagram, with an optional list of systems to start the diagram.

add_system(system)[source]

Add a system to the block diagram

Parameters:system (dynamical system) – System to add to BlockDiagram
computation_step(t, state, output=None, selector=True, do_events=False)[source]

callable to compute system outputs and state derivatives

connect(from_system_output, to_system_input, outputs=[], inputs=[])[source]

Connect systems in the block diagram.

Parameters:
  • from_system_output (dynamical system) – The system (already added to BlockDiagram) from which outputs will be connected. Note that the outputs of a system can be connected to multiple inputs.
  • to_system_input (dynamical system) – The system (already added to BlockDiagram) to which inputs will be connected. Note that any previous input connections will be over-written.
  • outputs (list-like, optional) – Selector index of the outputs to connect. If not specified or of length 0, will connect all of the outputs.
  • inputs (list-like, optional) – Selector index of the inputs to connect. If not specified or of length 0, will connect all of the inputs.
create_input(to_system_input, channels=[], inputs=[])[source]

Create or use input channels to use block diagram as a subsystem.

Parameters:
  • channels (list-like) – Selector index of the input channels to connect.
  • to_system_input (dynamical system) – The system (already added to BlockDiagram) to which inputs will be connected. Note that any previous input connections will be over-written.
  • inputs (list-like, optional) – Selector index of the inputs to connect. If not specified or of length 0, will connect all of the inputs.
dim_output
dim_state
dt
event_equation_function_implementation(t, state, output=None)[source]
initial_condition
output_equation_function(t, state, input_=None, update_memoryless_event=False)[source]
prepare_to_integrate()[source]
simulate(tspan, integrator_class=<class 'scipy.integrate._ode.ode'>, integrator_options={'atol': 1e-12, 'max_step': 0.0, 'name': 'dopri5', 'nsteps': 500, 'rtol': 1e-06}, event_finder=<function brentq>, event_find_options={'maxiter': 100, 'rtol': 8.881784197001252e-16, 'xtol': 2e-12})[source]

Simulate the block diagram

Parameters:
  • tspan (list-like or float) –

    Argument to specify integration time-steps.

    If a single time is specified, it is treated as the final time. If two times are specified, they are treated as initial and final times. In either of these conditions, it is assumed that that every time step from a variable time-step integrator will be stored in the result.

    If more than two times are specified, these are the only times where the trajectories will be stored.

  • integrator_class (class, optional) –

    Class of integrator to use. Defaults to scipy.integrate.ode. Must provide the following subset of the scipy.integrate.ode API:

    • __init__(derivative_callable(time, state))
    • set_integrator(**kwargs)
    • set_initial_value(state, time)
    • set_solout(successful_step_callable(time, state))
    • integrate(time)
    • successful()
    • y, t properties
  • integrator_options (dict, optional) – Dictionary of keyword arguments to pass to integrator_class.set_integrator.
  • event_finder (callable, optional) – Interval root-finder function. Defaults to scipy.optimize.brentq, and must take the equivalent positional arguments, f, a, and b, and return x0, where a <= x0 <= b and f(x0) is the zero.
  • event_find_options (dict, optional) – Dictionary of keyword arguments to pass to event_finder. It must provide a key 'xtol', and it is expected that the exact zero lies within x0 +/- xtol/2, as brentq provides.
state_equation_function(t, state, input_=None, output=None)[source]
systems_event_equation_functions(t, state, output)[source]
update_equation_function_implementation(t, state, input_=None, output=None)[source]
class simupy.block_diagram.SimulationResult(dim_states, dim_outputs, tspan, n_sys, initial_size=0)[source]

A simple class to collect simulation result trajectories.

t
Type:array of times
x
Type:array of states
y
Type:array of outputs
e
Type:array of events
allocate_space(t)[source]
last_result(n=1, copy=False)[source]
max_allocation = 128
new_result(t, x, y, e=None)[source]