Marine systems simulation
|
The following describes som methods which are often used in the creation of SimObjects. They are all part of the interface ISimObjectCreator and available only in the SimObject constructor. Example usage can be found in e.g.
The following is a list of methods which are used for getting information from the input file.
int GetParamSize(string parameter) override;
[in] | parameter | The name of the parameter. |
Finds the number of elements in a parameter.
bool GetBoolParamArray(string parameter, bool* result, int num, const bool* aDefaultValue = nullptr) override;
parameter | The name of the parameter. |
result | The read array. |
num | The size of the parameter to read. |
aDefaultValue | The deafult value to use if the parameter is not found. |
Finds a bool array parameter of size 'num'. If aDefaultValue is defined, it will be used if the parameter is not found.
bool GetBoolParam(string parameter, bool* result, bool defaultValue) override; bool GetBoolParam(string parameter, bool* result) override;
parameter | The name of the parameter. |
result | The read value. |
aDefaultValue | The deafult value to use if the parameter is not found. |
Finds a bool parameter. DefaultValue will be used if the parameter is not found.
bool GetIntParamArray(string parameter, int* result, int num, const int* aDefaultValue = nullptr) override;
parameter | The name of the parameter. |
result | The read array. |
num | The size of the parameter to read. |
aDefaultValue | The deafult value to use if the parameter is not found. |
Finds an integer array parameter of size 'num'. If aDefaultValue is defined, it will be used if the parameter is not found.
bool GetIntParam(string parameter, int* result, int defaultValue) override; bool GetIntParam(string parameter, int* result) override;
parameter | The name of the parameter. |
result | The read value. |
aDefaultValue | The deafult value to use if the parameter is not found. |
Finds an integer parameter. DefaultValue will be used if the parameter is not found.
bool GetDoubleParamArray(string parameter, double* result, int num, const double* aDefaultValue = nullptr) override;
parameter | The name of the parameter. |
result | The read array. |
num | The size of the parameter to read. |
aDefaultValue | The deafult value to use if the parameter is not found. |
Finds a float array parameter of size 'num'. If aDefaultValue is defined, it will be used if the parameter is not found.
bool GetDoubleParam(string parameter, double* result, double defaultValue) override; bool GetDoubleParam(string parameter, double* result) override;
parameter | The name of the parameter. |
result | The read value. |
aDefaultValue | The deafult value to use if the parameter is not found. |
Finds a float parameter. DefaultValue will be used if the parameter is not found.
bool GetStringParamVector(string parameter, std::vector<string>& VsResult) override;
parameter | The name of the parameter. |
result | The read array. |
Finds a string array parameter.
bool GetStringParam(string parameter, string& result, const string& defaultValue) override; bool GetStringParam(string parameter, string& result) override;
parameter | The name of the parameter. |
result | The read value. |
aDefaultValue | The deafult value to use if the parameter is not found. |
Finds a string parameter. DefaultValue will be used if the parameter is not found.
void ReportError(string errorMessage) override;
Informs the system that an error occured. If the error is regarding a spesific parameter value, the method ReportParameterError should be used instead.
void ReportParameterError(string parameterName, string errorMessage) override;
Informs the system of an error related to a spesific parameter.
void LogInfo(string infoMessage) override;
Sends log information to the system. If the info is regarding a spesific parameter value, the method LogParameterInfo should be used instead.
void LogParameterInfo(string parameterName, string infoMessage) override;
Sends log information conserning a spesific parameter to the system. Excessive logging is discouraged.
void LogDebug(string debugMessage) override;
Sends debug-log information to the system. If the debug-log is regarding a spesific parameter value, the methog LogParameterDebug should be used instead.
void LogParameterDebug(string parameterName, string debugMessage) override;
Sends debug-log information conserning a spesific parameter to the system.
Each output port is implemented as a method responsible for returning a pointer to the data structure containing the value of the output port. If more than one output port depends on running the same code for updating some data, it is recommended to put these calculations in a common method, which is called from all port functions, and to start the method by a test to check if the method have already been run in this time step.
void AddOutport(string portName, int portSize, PortFunction outputFunction) override; void AddOutportIndexed(string portName, int portSize, IndexedPortFunction outputFunction, int index) override; void AddInport(string portName, int portSize, ISignalPort** portAddress) override; int AddState(string stateName, int numStates, double* initialConditions = nullptr) override; void RegisterCommonCalculation(CommonComputation computationFunction, ICommonComputation** computationAddress) override; void OutputPortNotReady(string outputPort) override;
The use of shared resources is a powerful mechanism which supports efficient and flexible communication and calculations independent of the port system. Its most dominant use is for having a shared environment on which the SimObjects can run queries at will. Its only requirement is that the user knows
void SetSharedResource(string resourceName, void* resourcePointer) override;
Informs the system of a resource the simobject wishes to share. Note that the resource will not be accessible to other simobjects until FinalSetup.
void* GetSharedResource(string resourceName) override;
Retrieves a shared resource. Note that resources registered by other simobjects will not be accessible until FinalSetup.