Emulator

class mpcpy.Emulator(input_keys, parameters=None, initial_conditions=None)[source]

Base class for defining an emulator object

Initializes the emulator object self.inputs and self.res attributes must be defined

Parameters:

input_keys : list of strings

list of strings of inputs. This is done so that not all data from the boundary conditions and control signals have to be transferred to the simulation. Only the boundary conditions and control signals in the inputs attribute are interpolated and passed to the __call__ method.

parameters : dict

A dictionary of parameters used by the emulator.

initial_conditions : dict

A dictionary of initial conditions of the system under consideration.

__call__(time, input)[source]

Simulates the system and updated the results dictionary, calls the :code:`simulate`method.

Parameters:

time : numpy array

Times at which the results are requested.

input : dict

Dictionary with values for the inputs of the model, time must be a part of it.

Returns:

dict

Dictionary with the complete simulation results.

Examples

>>> em = Emulator(['u1'])
>>> t  = np.arange(0.,3600.1,600.)
>>> u1 = 5.*np.ones_like(t)
>>> em(t,['time':t,'u1':u1])
initialize()[source]

Redefine in a child class

This method is called once before the start of the MPC and by default clears the results dictionary and then add the initial conditions to it at time 0.

simulate(starttime, stoptime, input)[source]

Redefine in a child class

This method runs the simulation and should return a dictionary with results for times between the starttime and stoptime given the inputs.

Parameters:

starttime : number

time to start the simulation

stoptime : number

time to stop the simulation

input : dict

dictionary with values for the inputs for the simulation, ‘time’ and all values in self.inputs must be keys

Returns:

dict

dictionary with the simulation results

class mpcpy.DympyEmulator(dymola, inputs, initializationtime=1, **kwargs)[source]

A class defining an emulator object using dympy for the simulation

Initialize a dympy object for use as an MPC emulation

Parameters:

dymola : dympy.Dymola

a dympy object with an opened and compiled dymola model

inputs : list of strings

a list of strings of the variable names of the inputs

initializationtime : number

time to run the initialization simulation

**kwargs :

arguments which can be passed on to dympy

initialize()[source]

initializes the dympy model, by simulating it for self.initializationtime. Afterwards the res attribute is populated

Also, the keys in parameters and initialconditions are checked. If they do not appear in the dympy results, they are removed and the model is reinitialized.

simulate(starttime, stoptime, input)[source]