pathsim.blocks._block module
- class pathsim.blocks._block.Block[source]
Bases:
SerializableBase ‘Block’ object that defines the inputs, outputs and the connect method.
Block interconnections are handeled via the io interface of the blocks. It is realized by dicts for the ‘inputs’ and for the ‘outputs’, where the key of the dict is the input/output channel and the corresponding value is the input/output value.
The block can spawn discrete events that are handled by the main simulation for triggers, discrete time blocks, etc.
Notes
This block is not intended to be used directly and serves as a base class definition for other blocks to be inherited.
- inputs
input value register of block
- Type:
dict{int: float}
- outputs
output value register of block
- Type:
dict{int: float}
- plot(*args, **kwargs)[source]
Block specific visualization, enables plotting access from the simulation level.
This gets primarily used by the visualization blocks such as the ‘Scope’ and ‘Spectrum’.
- on()[source]
Activate the block and all internal events, sets the boolean evaluation flag to ‘True’.
- off()[source]
Deactivate the block and all internal events, sets the boolean evaluation flag to ‘False’. Also resets the block.
- reset()[source]
Reset the blocks inputs and outputs and also its internal solver, if the block has a solver instance.
- get_events()[source]
Return internal events of the block, for discrete time blocks such as triggers / comparators, clocks, etc.
- set_solver(Solver, **solver_args)[source]
Initialize the numerical integration engine with local truncation error tolerance if required.
If the block already has an integration engine, it is changed, if it does not require an integration engine, this method just passes.
- revert()[source]
Revert the block to the state of the previous timestep, if the block has a solver instance indicated by the ‘has_engine’ flag.
This is required for adaptive solvers to revert the state to the previous timestep.
- buffer(dt)[source]
Buffer current internal state of the block and the current timestep if the block has a solver instance (is stateful).
This is required for multistage, multistep and adaptive integrators.
- Parameters:
dt (float) – integration timestep
- sample(t)[source]
Samples the data of the blocks inputs or internal state when called.
This can record block parameters after a succesful timestep such as for the ‘Scope’ and ‘Delay’ blocks but also for sampling from a random distribution in the ‘RNG’ and the noise blocks.
- Parameters:
t (float) – evaluation time for sampling
- get(port)[source]
Get the value of an output port of the block.
Uses the ‘get’ method of ‘outputs’ dict with default value ‘0.0’.
- update(t)[source]
The ‘update’ method is called iteratively for all blocks BEFORE the timestep to resolve algebraic loops (fixed-point iteraion).
It is meant for instant time blocks (blocks that dont have a delay due to the timestep, such as Amplifier, etc.) and updates the ‘outputs’ of the block directly based on the ‘inputs’ and possibly internal states.
It computes and returns the relative difference between the new output and the previous output (before the step) to track convergence of the fixed-point iteration.
- solve(t, dt)[source]
The ‘solve’ method performes one iterative solution step that is required to solve the implicit update equation of the solver if an implicit solver (numerical integrator) is used.
It returns the relative difference between the new updated solution and the previous iteration of the solution to track convergence within an outer loop.
This only has to be implemented by blocks that have an internal integration engine with an implicit solver.
- step(t, dt)[source]
The ‘step’ method is used in transient simulations and performs an action (numeric integration timestep, recording data, etc.) based on the current inputs and the current internal state.
It performes one timestep for the internal states. For instant time blocks, the ‘step’ method does not has to be implemented specifically.
The method handles timestepping for dynamic blocks with internal states such as ‘Integrator’, ‘StateSpace’, etc.