Class PlantSimulator
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, intalization handled by ProcessSimulatorInitializer
(this requires no user interaction).
The building blocks of plant models are UnitModel
, PidModel
and Select
Inherited Members
Namespace: TimeSeriesAnalysis.Dynamic
Assembly: TimeSeriesAnalysis.dll
Syntax
public class PlantSimulator
Constructors
| Edit this page View SourcePlantSimulator(List<ISimulatableModel>, string, string)
Constructor
Declaration
public PlantSimulator(List<ISimulatableModel> processModelList, string plantName = "", string plantDescription = "")
Parameters
Type | Name | Description |
---|---|---|
List<ISimulatableModel> | processModelList | A list of process models, each implementing |
string | plantName | optional name of plant, used when serializing |
string | plantDescription | optional description of plant |
Fields
| Edit this page View SourcePlantFitScore
The fitScore of the plant the last time it was saved.
Declaration
public double PlantFitScore
Field Value
Type | Description |
---|---|
double |
comments
A list of comments that the user may have added to track changes made over time.
Declaration
public List<Comment> comments
Field Value
Type | Description |
---|---|
List<Comment> |
connections
The connection parser object.
Declaration
public ConnectionParser connections
Field Value
Type | Description |
---|---|
ConnectionParser |
externalInputSignalIDs
List of all external signal IDs.
Declaration
public List<string> externalInputSignalIDs
Field Value
Type | Description |
---|---|
List<string> |
modelDict
Dictionary of all unit models in the plant simulator (must implement ISimulatableModel).
Declaration
public Dictionary<string, ISimulatableModel> modelDict
Field Value
Type | Description |
---|---|
Dictionary<string, ISimulatableModel> |
Properties
| Edit this page View Sourcedate
The date of when the model was last saved.
Declaration
public DateTime date { get; set; }
Property Value
Type | Description |
---|---|
DateTime |
plantDescription
A short user-friendly description of what the plant is and does.
Declaration
public string plantDescription { get; set; }
Property Value
Type | Description |
---|---|
string |
plantName
User-friendly name that may include white spaces.
Declaration
public string plantName { get; set; }
Property Value
Type | Description |
---|---|
string |
Methods
| Edit this page View SourceAddAndConnectExternalSignal(ISimulatableModel, string, SignalType, int)
Add an external signal. Preferred implementation, as the signal can have any ID without naming convention.
Declaration
public string AddAndConnectExternalSignal(ISimulatableModel model, string signalID, SignalType type, int index = 0)
Parameters
Type | Name | Description |
---|---|---|
ISimulatableModel | model | |
string | signalID | |
SignalType | type | |
int | index |
Returns
Type | Description |
---|---|
string | signalID or |
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).
Declaration
public string AddExternalSignal(ISimulatableModel model, SignalType type, int index = 0)
Parameters
Type | Name | Description |
---|---|---|
ISimulatableModel | model | |
SignalType | type | |
int | index | the index of the signal, this is only needed if this is an input to a multi-input model |
Returns
Type | Description |
---|---|
string |
ConnectModelToOutput(ISimulatableModel, ISimulatableModel)
Add a disturbance model to the output a given model
.
Declaration
public bool ConnectModelToOutput(ISimulatableModel disturbanceModel, ISimulatableModel model)
Parameters
Type | Name | Description |
---|---|---|
ISimulatableModel | disturbanceModel | |
ISimulatableModel | model |
Returns
Type | Description |
---|---|
bool |
ConnectModels(ISimulatableModel, ISimulatableModel, int?)
Connect the output of the upstream model to the input of the downstream model.
Declaration
public string ConnectModels(ISimulatableModel upstreamModel, ISimulatableModel downstreamModel, int? inputIndex = null)
Parameters
Type | Name | Description |
---|---|---|
ISimulatableModel | upstreamModel | the upstream model, meaning the model whose output will be connected |
ISimulatableModel | downstreamModel | the downstream model, meaning the model whose input will be connected |
int? | inputIndex | input index of the downstream model to connect to (default is first input) |
Returns
Type | Description |
---|---|
string | returns the signal id if all is ok, otherwise |
ConnectSignalToInput(string, ISimulatableModel, int)
Connect an existing signal with a given signalID to a new model.
Declaration
public bool ConnectSignalToInput(string signalID, ISimulatableModel model, int idx)
Parameters
Type | Name | Description |
---|---|---|
string | signalID | |
ISimulatableModel | model | |
int | idx |
Returns
Type | Description |
---|---|
bool |
CreateFeedbackLoop(UnitDataSet, PidModel, UnitModel, int)
Create a PlantSimulator and TimeSeriesDataSet from a UnitDataSet, PidModel and UnitModel to do closed-loop simulations
The feedback loop has no disturbance signal added, but this can be added to the returned PlantSimualtor as needed.
Declaration
public static (PlantSimulator, TimeSeriesDataSet) CreateFeedbackLoop(UnitDataSet unitDataSet, PidModel pidModel, UnitModel unitModel, int pidInputIdx = 0)
Parameters
Type | Name | Description |
---|---|---|
UnitDataSet | unitDataSet | |
PidModel | pidModel | |
UnitModel | unitModel | |
int | pidInputIdx |
Returns
Type | Description |
---|---|
(PlantSimulator, TimeSeriesDataSet) |
GetConnections()
Get ConnenectionParser object.
Declaration
public ConnectionParser GetConnections()
Returns
Type | Description |
---|---|
ConnectionParser |
GetExternalSignalIDs()
Get a TimeSeriesDataSet of all external signals of model.
Declaration
public string[] GetExternalSignalIDs()
Returns
Type | Description |
---|---|
string[] |
GetModels()
Get a dictionary of all models.
Declaration
public Dictionary<string, ISimulatableModel> GetModels()
Returns
Type | Description |
---|---|
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.
Declaration
public UnitDataSet GetUnitDataSetForPID(TimeSeriesDataSet inputData, PidModel pidModel)
Parameters
Type | Name | Description |
---|---|---|
TimeSeriesDataSet | inputData | |
PidModel | pidModel |
Returns
Type | Description |
---|---|
UnitDataSet |
GetUnitDataSetForProcess(TimeSeriesDataSet, UnitModel)
Returns a unit data set for a given UnitModel.
Declaration
public UnitDataSet GetUnitDataSetForProcess(TimeSeriesDataSet inputData, UnitModel unitModel)
Parameters
Type | Name | Description |
---|---|---|
TimeSeriesDataSet | inputData | |
UnitModel | unitModel |
Returns
Type | Description |
---|---|
UnitDataSet |
Serialize(string, string)
Creates a JSON file representation of this object.
Declaration
public bool Serialize(string newPlantName = null, string path = null)
Parameters
Type | Name | Description |
---|---|---|
string | newPlantName | the desired file name and plant name (can be null, in which case the filename should be given in the path argument) |
string | path | create file in the given path |
Returns
Type | Description |
---|---|
bool |
SerializeTxt()
Creates a JSON text string serialization of this object.
Declaration
public string SerializeTxt()
Returns
Type | Description |
---|---|
string |
Simulate(TimeSeriesDataSet, out TimeSeriesDataSet)
Perform a dynamic simulation of the model provided, given the specified connections and external signals.
Declaration
public bool Simulate(TimeSeriesDataSet inputData, out TimeSeriesDataSet simData)
Parameters
Type | Name | Description |
---|---|---|
TimeSeriesDataSet | inputData | the external signals for the simulation(also, determines the simulation time span and timebase) |
TimeSeriesDataSet | simData | the simulated data set to be outputted(excluding the external signals) |
Returns
Type | Description |
---|---|
bool |
SimulateSingle(UnitDataSet, ISimulatableModel, bool)
Simulates a single model given a unit data set, optionally writing the simulation to unitData.Y_sim
Declaration
public static (bool, double[]) SimulateSingle(UnitDataSet unitData, ISimulatableModel model, bool addSimToUnitData)
Parameters
Type | Name | Description |
---|---|---|
UnitDataSet | unitData | |
ISimulatableModel | model | |
bool | addSimToUnitData |
Returns
Type | Description |
---|---|
(bool, double[]) |
SimulateSingle(TimeSeriesDataSet, string, bool, out TimeSeriesDataSet)
Simulate a single model(any ISimulatable model), using inputData as inputs,
If the model is a unitModel and the inputData inludes both the measured y and measured u, the simData will include an estimate of the additive disturbance.
Declaration
public bool SimulateSingle(TimeSeriesDataSet inputData, string singleModelName, bool doCalcYwithoutAdditiveTerms, out TimeSeriesDataSet simData)
Parameters
Type | Name | Description |
---|---|---|
TimeSeriesDataSet | inputData | |
string | singleModelName | |
bool | doCalcYwithoutAdditiveTerms | |
TimeSeriesDataSet | simData |
Returns
Type | Description |
---|---|
bool |
SimulateSingle(TimeSeriesDataSet, string, out TimeSeriesDataSet)
Simulate a single model to get the output including any additive inputs.
Declaration
public bool SimulateSingle(TimeSeriesDataSet inputData, string singleModelName, out TimeSeriesDataSet simData)
Parameters
Type | Name | Description |
---|---|---|
TimeSeriesDataSet | inputData | |
string | singleModelName | |
TimeSeriesDataSet | simData |
Returns
Type | Description |
---|---|
bool |
SimulateSingleInternal(TimeSeriesDataSet, string, out TimeSeriesDataSet)
Simulate a single model to get the internal "x" unmeasured output that excludes any additive outputs (like disturbances).
Declaration
public bool SimulateSingleInternal(TimeSeriesDataSet inputData, string singleModelName, out TimeSeriesDataSet simData)
Parameters
Type | Name | Description |
---|---|---|
TimeSeriesDataSet | inputData | |
string | singleModelName | |
TimeSeriesDataSet | simData |
Returns
Type | Description |
---|---|
bool |
SimulateSingleToYmeas(UnitDataSet, ISimulatableModel, double, int)
Simulates a single model for a unit dataset and adds the output to unitData.Y_meas of the unitData, optionally with noise
Declaration
public static (bool, double[]) SimulateSingleToYmeas(UnitDataSet unitData, ISimulatableModel model, double noiseAmplitude = 0, int noiseSeed = 123)
Parameters
Type | Name | Description |
---|---|---|
UnitDataSet | unitData | the dataset to be simualted over, and where the Y_meas is updated with result |
ISimulatableModel | model | the model to be simulated |
double | noiseAmplitude | the amplitude of noise to be added to Y_meas |
int | noiseSeed | a seed value of the randm noise(specify so that tests are repeatable) |
Returns
Type | Description |
---|---|
(bool, double[]) |