Simulator

(class from pyomo.dae.simulator)

class pyomo.dae.simulator.Simulator(m, package='scipy')[source]

Bases: object

Simulator objects allow a user to simulate a dynamic model formulated using pyomo.dae.

Parameters:
  • m (Pyomo Model) – The Pyomo model to be simulated should be passed as the first argument

  • package (string) – The Python simulator package to use. Currently ‘scipy’ and ‘casadi’ are the only supported packages

__init__(m, package='scipy')[source]

Methods

__init__(m[, package])

get_variable_order([vartype])

This function returns the ordered list of differential variable names.

initialize_model()

This function will initialize the model using the profile obtained from simulating the dynamic model.

simulate([numpoints, tstep, integrator, ...])

Simulate the model.

Member Documentation

get_variable_order(vartype=None)[source]

This function returns the ordered list of differential variable names. The order corresponds to the order being sent to the integrator function. Knowing the order allows users to provide initial conditions for the differential equations using a list or map the profiles returned by the simulate function to the Pyomo variables.

Parameters:

vartype (string or None) – Optional argument for specifying the type of variables to return the order for. The default behavior is to return the order of the differential variables. ‘time-varying’ will return the order of all the time-dependent algebraic variables identified in the model. ‘algebraic’ will return the order of algebraic variables used in the most recent call to the simulate function. ‘input’ will return the order of the time-dependent algebraic variables that were treated as inputs in the most recent call to the simulate function.

Return type:

list

initialize_model()[source]

This function will initialize the model using the profile obtained from simulating the dynamic model.

simulate(numpoints=None, tstep=None, integrator=None, varying_inputs=None, initcon=None, integrator_options=None)[source]

Simulate the model. Integrator-specific options may be specified as keyword arguments and will be passed on to the integrator.

Parameters:
  • numpoints (int) – The number of points for the profiles returned by the simulator. Default is 100

  • tstep (int or float) – The time step to use in the profiles returned by the simulator. This is not the time step used internally by the integrators. This is an optional parameter that may be specified in place of ‘numpoints’.

  • integrator (string) – The string name of the integrator to use for simulation. The default is ‘lsoda’ when using Scipy and ‘idas’ when using CasADi

  • varying_inputs (pyomo.environ.Suffix) – A Suffix object containing the piecewise constant profiles to be used for certain time-varying algebraic variables.

  • initcon (list of floats) – The initial conditions for the the differential variables. This is an optional argument. If not specified then the simulator will use the current value of the differential variables at the lower bound of the ContinuousSet for the initial condition.

  • integrator_options (dict) – Dictionary containing options that should be passed to the integrator. See the documentation for a specific integrator for a list of valid options.

Returns:

The first return value is a 1D array of time points corresponding to the second return value which is a 2D array of the profiles for the simulated differential and algebraic variables.

Return type:

numpy array, numpy array