Table of Contents

Class PlantSimulator

Namespace
TimeSeriesAnalysis.Dynamic
Assembly
TimeSeriesAnalysis.dll

Simulates larger "plant-models" that is built up of connected sub-models that each implement ISimulatableModel.

To set up a simulation, first connect models, and then add external input signals. This class handles information about which model is connected to which, and handles calling sub-models in the correct order with the correct input signals.

By default, the model attempts to start in steady-state, initialization handled by ProcessSimulatorInitializer (this requires no user interaction).

The building blocks of plant models are UnitModel, PidModel and Select

UnitModel PidModel PlantSimulatorInitializer Select
public class PlantSimulator
Inheritance
PlantSimulator
Inherited Members

Constructors

PlantSimulator(List<ISimulatableModel>, string, string)

Constructor

public PlantSimulator(List<ISimulatableModel> processModelList, string plantName = "", string plantDescription = "")

Parameters

processModelList List<ISimulatableModel>

A list of process models, each implementing ISimulatableModel

plantName string

optional name of plant, used when serializing

plantDescription string

optional description of plant

Fields

PlantFitScore

The fitScore of the plant the last time it was saved.

public double PlantFitScore

Field Value

double

comments

A list of comments that the user may have added to track changes made over time.

public List<Comment> comments

Field Value

List<Comment>

connections

The connection parser object.

public ConnectionParser connections

Field Value

ConnectionParser

externalInputSignalIDs

List of all external signal IDs.

public List<string> externalInputSignalIDs

Field Value

List<string>

modelDict

Dictionary of all unit models in the plant simulator (must implement ISimulatableModel).

public Dictionary<string, ISimulatableModel> modelDict

Field Value

Dictionary<string, ISimulatableModel>

Properties

date

The date of when the model was last saved.

public DateTime date { get; set; }

Property Value

DateTime

plantDescription

A short user-friendly description of what the plant is and does.

public string plantDescription { get; set; }

Property Value

string

plantName

User-friendly name that may include white spaces.

public string plantName { get; set; }

Property Value

string

Methods

AddAndConnectExternalSignal(ISimulatableModel, string, SignalType, int)

Add an external signal. Preferred implementation, as the signal can have any ID without naming convention.

public string AddAndConnectExternalSignal(ISimulatableModel model, string signalID, SignalType type, int index = 0)

Parameters

model ISimulatableModel
signalID string
type SignalType
index int

Returns

string

signalID or null if something went wrong

AddExternalSignal(ISimulatableModel, SignalType, int)

Informs the PlantSimulator that a specific sub-model has a specific signal at its input (use for unit testing only, using a naming convention to name signal).

public string AddExternalSignal(ISimulatableModel model, SignalType type, int index = 0)

Parameters

model ISimulatableModel
type SignalType
index int

the index of the signal, this is only needed if this is an input to a multi-input model

Returns

string

ConnectModelToOutput(ISimulatableModel, ISimulatableModel)

Add a disturbance model to the output a given model.

public bool ConnectModelToOutput(ISimulatableModel disturbanceModel, ISimulatableModel model)

Parameters

disturbanceModel ISimulatableModel
model ISimulatableModel

Returns

bool

ConnectModels(ISimulatableModel, ISimulatableModel, int?)

Connect the output of the upstream model to the input of the downstream model.

public string ConnectModels(ISimulatableModel upstreamModel, ISimulatableModel downstreamModel, int? inputIndex = null)

Parameters

upstreamModel ISimulatableModel

the upstream model, meaning the model whose output will be connected

downstreamModel ISimulatableModel

the downstream model, meaning the model whose input will be connected

inputIndex int?

input index of the downstream model to connect to (default is first input)

Returns

string

returns the signal id if all is ok, otherwise null.

ConnectSignalToInput(string, ISimulatableModel, int)

Connect an existing signal with a given signalID to a new model.

public bool ConnectSignalToInput(string signalID, ISimulatableModel model, int idx)

Parameters

signalID string
model ISimulatableModel
idx int

Returns

bool

GetConnections()

Get ConnectionParser object.

public ConnectionParser GetConnections()

Returns

ConnectionParser

GetExternalSignalIDs()

Get a TimeSeriesDataSet of all external signals of model.

public string[] GetExternalSignalIDs()

Returns

string[]

GetModels()

Get a dictionary of all models.

public Dictionary<string, ISimulatableModel> GetModels()

Returns

Dictionary<string, ISimulatableModel>

GetUnitDataSetForPID(TimeSeriesDataSet, PidModel)

Returns a "unitDataSet" for the given pidModel in the plant. This function only works when the unit model connected to the pidModel only has a single input.

public UnitDataSet GetUnitDataSetForPID(TimeSeriesDataSet inputData, PidModel pidModel)

Parameters

inputData TimeSeriesDataSet
pidModel PidModel

Returns

UnitDataSet

SelectMinimalInputData(TimeSeriesDataSet)

Choose only the input time series that are actually used by a given plant

public TimeSeriesDataSet SelectMinimalInputData(TimeSeriesDataSet rawInputData)

Parameters

rawInputData TimeSeriesDataSet

Returns

TimeSeriesDataSet

Serialize(string, string)

Creates a JSON file representation of this object.

public bool Serialize(string newPlantName = null, string path = null)

Parameters

newPlantName string

the desired file name and plant name (can be null, in which case the filename should be given in the path argument)

path string

create file in the given path

Returns

bool

SerializeTxt()

Creates a JSON text string serialization of this object.

public string SerializeTxt()

Returns

string

Simulate(TimeSeriesDataSet, bool, out TimeSeriesDataSet, bool, bool)

Perform a "plant-wide" full dynamic simulation of the entire plant,i.e. all models in the plant, given the specified connections and external signals.

The dynamic simulation will also return estimated disturbances in simData, if the plant contains feedback loops where there is an additive disturbance with a signal named according to SignalNamer.EstDisturbance() convention

The simulation will also set the PlantFitScore which can be used to evaluate the fit of the simulation to the plant data. For this score to be calculated, the measured time-series corresponding to simData need to be provided in inputData

If doDetermineIndicesToIgnore is set to false, then the the simulation will consider the .IndicesToIgnore member of the inputData, and ignore these data indices, re-starting dynamic models once periods of bad data pass.(this indices will be padded internally do not need to be padded when supplied) If instead set to true, the simulator will parse the input data to determine bad indices, but it will not be able to determine periods of "frozen" datasets (as outputs y are generally not required to be given in the input data.)

public bool Simulate(TimeSeriesDataSet inputData, bool doDetermineIndicesToIgnore, out TimeSeriesDataSet simData, bool enableSimulatorRestarting = true, bool doVariableTimeBase = false)

Parameters

inputData TimeSeriesDataSet

the external signals for the simulation(also, determines the simulation time span and time-base)

doDetermineIndicesToIgnore bool

is set to true, the simulator tries to determine indices to ignore internally

simData TimeSeriesDataSet

the simulated data set to be outputted(excluding the external signals)

enableSimulatorRestarting bool

if set to true, the simulator will try to restart after long periods of flat data

doVariableTimeBase bool

if set to true, the simulator will vary the time base based on indicesToIgnore(jumping from one good value to the next)

Returns

bool

Simulate(TimeSeriesDataSet, out TimeSeriesDataSet)

Simulate plant. This version of simulate does not internally determine any indices to ignore, but it will consider indicesToIgnore of inputData

public bool Simulate(TimeSeriesDataSet inputData, out TimeSeriesDataSet simData)

Parameters

inputData TimeSeriesDataSet
simData TimeSeriesDataSet

Returns

bool

true if able to simulate, otherwise false