Systems

There are different systems that can be used in a simulation. The standard building block is a c++ system, but there are also cython and python systems that fill the same role, but are much slower. All of these systems are based on something called a commonsystem.

CommonSystem

Systems used for simulation.

Base classes for systems. They are inherited by CppSystems and CythonSystems.

class pysim.commonsystem.CommonSystem

Common base class for systems that are editable from Python.

pars

The parameters, can be set before the simulation starts.

Type

Parameters

inputs

The inputs to the system, can be set and connected to outputs

Type

PysimVars

outputs

the outputs of the system, can be connected to inputs of other systems

Type

PysimVars

states

The states of the system

Type

PysimVars

ders

The derivatives of the system

Type

PysimVars

connections

The connections from this system to other systems

Type

pysim.connections.Connections

res

The stored values from the simulation.

Type

Results

add_break_greater()

Add a break that will be activated if the value of the variable or state is larger than the value supplied as argument.

Parameters
  • name (str) – Name of the variable to watch.

  • value (float) – If the variable is below this value then break

add_break_smaller()

Add a break that will be activated if the value of the variable or state is smaller than the value supplied as argument.

Parameters
  • name (str) – Name of the variable to watch

  • value (double) – If the variable is below this value then break

set_store_interval()

Set the store interval of this system.

By default the store interval for all systems in a simulation is set by the simulation, typically for the step length for fixed step algorithms. By calling this function the store interval for this system is set differently.

Parameters

interval (float) – The time between stores, in seconds.

store()

Store a input, output or state in the system.

Parameters

name (str) – Name of the variable to store.

store_all()

Store all inputs, outputs, states and ders in the system.

class pysim.commonsystem.Parameters

Contains all the parameters for the system.

class pysim.commonsystem.PysimVars

Contains all the variables for the system.

Each attribute of this class correspond to a variable of the system.

class pysim.commonsystem.Results

Class containing the results of a simulation.

The results are stored as attributes and returned as numpy arrays. They can be scalars, vectors or matrices.

CppSystem

class pysim.cppsystem.Sys

Represents a System, to be added to an Simulation for evaluation. Each System consists of parameters, inputs set prior to the simulation, States and State derivatives, and Variables, that may be stored during a simulation

CythonSystem

This module contains functionality for creating a cython or python system for pysim. Both cython and python systems can inherit from the Sys class in this module and then be added to a simulation.

class pysim.cythonsystem.Sys

This class is meant to be inherited by python and cython systems. They can then be set up and after that used in a simulation together with other systems, both c++, python and cython systems.

Connections

Connections between systems

class pysim.connections.Connections

The connections of the system. The connections are either from an output or a state of a system. To add a new connection use the function add_connection.

add_connection()

Connect the outputs from this system to the inputs of another.

The systems that are to be connected must be derived from a CommonSystem, e.g. CppSystems and CythonSystems, or be a CompositeSystem.

Parameters
  • outputname (str) – The name of the output of this system

  • inputsys (CommonSystem) – The system that is to be connected, that will receive the signals.

  • inputname (str) – The name of the input that will receive the signal

  • (optional) (output_index) – The index of a vector to use if connecting to a scalar

Raises

ValueError – If inputname or outputname are not inputs, outputs members of the system.