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
public class PlantSimulator
- Inheritance
-
PlantSimulator
- Inherited Members
Constructors
PlantSimulator(List<ISimulatableModel>, string, string)
Constructor
public PlantSimulator(List<ISimulatableModel> processModelList, string plantName = "", string plantDescription = "")
Parameters
processModelListList<ISimulatableModel>A list of process models, each implementing
ISimulatableModelplantNamestringoptional name of plant, used when serializing
plantDescriptionstringoptional description of plant
Fields
PlantFitScore
The fitScore of the plant the last time it was saved.
public double PlantFitScore
Field Value
comments
A list of comments that the user may have added to track changes made over time.
public List<Comment> comments
Field Value
connections
The connection parser object.
public ConnectionParser connections
Field Value
externalInputSignalIDs
List of all external signal IDs.
public List<string> externalInputSignalIDs
Field Value
modelDict
Dictionary of all unit models in the plant simulator (must implement ISimulatableModel).
public Dictionary<string, ISimulatableModel> modelDict
Field Value
Properties
date
The date of when the model was last saved.
public DateTime date { get; set; }
Property Value
plantDescription
A short user-friendly description of what the plant is and does.
public string plantDescription { get; set; }
Property Value
plantName
User-friendly name that may include white spaces.
public string plantName { get; set; }
Property Value
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
modelISimulatableModelsignalIDstringtypeSignalTypeindexint
Returns
- string
signalID or
nullif 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
modelISimulatableModeltypeSignalTypeindexintthe index of the signal, this is only needed if this is an input to a multi-input model
Returns
ConnectModelToOutput(ISimulatableModel, ISimulatableModel)
Add a disturbance model to the output a given model.
public bool ConnectModelToOutput(ISimulatableModel disturbanceModel, ISimulatableModel model)
Parameters
disturbanceModelISimulatableModelmodelISimulatableModel
Returns
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
upstreamModelISimulatableModelthe upstream model, meaning the model whose output will be connected
downstreamModelISimulatableModelthe downstream model, meaning the model whose input will be connected
inputIndexint?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
signalIDstringmodelISimulatableModelidxint
Returns
GetConnections()
Get ConnectionParser object.
public ConnectionParser GetConnections()
Returns
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
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
inputDataTimeSeriesDataSetpidModelPidModel
Returns
SelectMinimalInputData(TimeSeriesDataSet)
Choose only the input time series that are actually used by a given plant
public TimeSeriesDataSet SelectMinimalInputData(TimeSeriesDataSet rawInputData)
Parameters
rawInputDataTimeSeriesDataSet
Returns
Serialize(string, string)
Creates a JSON file representation of this object.
public bool Serialize(string newPlantName = null, string path = null)
Parameters
newPlantNamestringthe desired file name and plant name (can be null, in which case the filename should be given in the path argument)
pathstringcreate file in the given path
Returns
SerializeTxt()
Creates a JSON text string serialization of this object.
public string SerializeTxt()
Returns
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
inputDataTimeSeriesDataSetthe external signals for the simulation(also, determines the simulation time span and time-base)
doDetermineIndicesToIgnoreboolis set to true, the simulator tries to determine indices to ignore internally
simDataTimeSeriesDataSetthe simulated data set to be outputted(excluding the external signals)
enableSimulatorRestartingboolif set to true, the simulator will try to restart after long periods of flat data
doVariableTimeBaseboolif set to true, the simulator will vary the time base based on indicesToIgnore(jumping from one good value to the next)
Returns
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
inputDataTimeSeriesDataSetsimDataTimeSeriesDataSet
Returns
- bool
true if able to simulate, otherwise false