pathsim.blocks.generic module
- class pathsim.blocks.generic.Generic(func_dyn=None, func_alg=<function Generic.<lambda>>, initial_value=0.0, jac_dyn=None)[source]
Bases:
BlockThis is a generic mixed dynamic-algebraic block where the dynamical component is implemented as an ODE and the algebraic component as a function of the states and the inputs
- d/dt x = func_dyn(x, u, t)
y = func_alg(x, u, t)
with inhomogenity (input) ‘u’ and state vector ‘x’. The functions can be nonlinear and the ODE can be of arbitrary order. The block utilizes the integration engine to solve the ODE by integrating the dynamic component ‘func_dyn’.
Essentially this is a generic nonlinear statespace block.
- INPUTS :
func_dyn : (callable object) dynamic component (rhs function of ODE) func_alg : (callable object) algebraic component initial_value : (array of floats) initial state / initial condition jac_dyn : (callable or None) jacobian of ‘func_dyn’ or ‘None’
- 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.
- 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.