pyblocksim Package

core Module

Module for block based modeling and simulation of dynamic systems

class pyblocksim.core.AbstractBlock(name)

Bases: object

connect_new_input(insig_new)

Allows to reconfigure the network, e.g. to study the consequences of different topology. Use with care.

class pyblocksim.core.Blockfnc(expr, name=None)

Bases: AbstractBlock

used to realize linear and nonlinear static functions

class pyblocksim.core.DelayBlock(T, insig, ivalue=None, name=None)

Bases: AbstractBlock

read()
write_input_and_step(input_value)
class pyblocksim.core.HyperBlock(name)

Bases: AbstractBlock

Class for blocks that consist of other blocks

class pyblocksim.core.IBlock(expr, insig, name=None)

Bases: AbstractBlock

Integrating block

requestDeriv(n)
class pyblocksim.core.NILBlock(expr, insig, name=None)

Bases: AbstractBlock

Non-Integrating Linear Block (we call it NIL-Block)

class pyblocksim.core.RHSBlock(f_expr, h_expr, local_state, insig, name=None)

Bases: AbstractBlock

Block that models a (nonlinear) system described via rhs vector field (expression)

x_dot = f(x, u) # x: state, u: input

and an output function

y = h(x)

class pyblocksim.core.RingBuffer(length)

Bases: object

data structure for saving the internal state of a delay block

read()
write_and_step(value)
class pyblocksim.core.StateAdmin

Bases: object

Omniscient object for data bookkeeping

get_nil_eq(nilblock)

computes the eqn for a Non Integrating Linear block (i. e. collects the derivatives of the input and combines them linearly (as the polynomial says)

register_block(block)

Method for central bookkeeping of all blocks

register_inputs(namestr)
register_loop(output, input_to_be_replaced)
resolve_blockfnc(bf, subsdict)

go down the algebraic chain to substitute for all other algebraic interim results

subsdict is supposed to contain the mapping from the block outputs of IBlocks and NILBlocks to the state variables

setup_DelayBlocks(dt)
class pyblocksim.core.TFBlock(expr, insig, name=None)

Bases: AbstractBlock

Metablock for representing rational transfer functions will be decomposed to numerator (NILBlock) and denom. (IBlock)

get_output_deriv(order)

Creates an additional numerator (-> NILBlock) for the TF which serves to calculate derivatives of the actual output

Parameters:

order – derivative order; must be smaller than relative degree

Returns:

output variable of the new NILBlock

class pyblocksim.core.Trajectory(expr, smoothness_degree)

Bases: object

combined_trajectories(expr)

expects expr to be a polynomial in s which determines how to linearly combine the trajectory and its derivatives to a new function of time

Example : expr = s**2 -3*s + 5 means

return a function consisting of y_ddot - 3*y_dot + 5*y

get_trajectory(diff_idx=0)
pyblocksim.core.blocksimulation(tend, inputs=None, xx0=None, dt=0.005)
Parameters:
  • xx0 – state for t = 0

  • inputs – a dict (like {u1 : calc_u1, u2 : calc_u2} where calc_u1, etc. are callables (in the case of just one specified input (u1, calc_u1) is allowed.

Returns:

tuple (tt, xxuu) tt: array of simulation time instants xxuu: array of states and inputs

pyblocksim.core.compute_block_outputs(simresults)
pyblocksim.core.degree(expr)
pyblocksim.core.exceptionwrapper(fnc)

prevent the integration algorithm to get stuck if a exception occurs in rhs

pyblocksim.core.expr2coeffs(expr, lead_test=True)

returns a list of the coeffs (highest last)

pyblocksim.core.gen_rhs(stateadmin)

resolves dependencies in the eqns and creates a function (called rhs) which can be passed to the integration algorithm

pyblocksim.core.get_linear_ct_model(stateadmin, system_output)

Return Matrices A, B, C, D

Parameters:

stateadmin

Returns:

pyblocksim.core.inputs(namestr)
pyblocksim.core.loop(output, input_to_be_replaced)
pyblocksim.core.main()
pyblocksim.core.mainprint(*args, **kwargs)

This function wraps pythons print function such that it is only executed if the calling module is the main module.

This is relevant to the examples which are imported as modules in the unittest script where we don’t want all the output which is generated, by the actual example

pyblocksim.core.numbered_symbols(prefix='x', function=<class 'sympy.core.symbol.Symbol'>, start=0, *args, **assumptions)

Generate an infinite stream of Symbols consisting of a prefix and increasing subscripts.

This implementation is copied from sympy.numbered_symbols and adapted for leading zeros

pyblocksim.core.restart()

Forget about all blocks and states. This is useful for unittests

pyblocksim.core.stepfnc(tup, amp1=1, tdown=inf, amp0=0)

returns a callable of 1 arg which is a step function