Marine systems simulation
SimObject construction methods

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.

Reading of parameters from the input file

The following is a list of methods which are used for getting information from the input file.

GetParamSize

int GetParamSize(string parameter) override;
Parameters
[in]parameterThe name of the parameter.

Finds the number of elements in a parameter.

GetBoolParamArray

bool GetBoolParamArray(string parameter, bool* result, int num, const bool* aDefaultValue = nullptr) override;
Parameters
parameterThe name of the parameter.
resultThe read array.
numThe size of the parameter to read.
aDefaultValueThe deafult value to use if the parameter is not found.
Returns
Returns true if the parameter was found.

Finds a bool array parameter of size 'num'. If aDefaultValue is defined, it will be used if the parameter is not found.

GetBoolParam

bool GetBoolParam(string parameter, bool* result, bool defaultValue) override;
bool GetBoolParam(string parameter, bool* result) override;
Parameters
parameterThe name of the parameter.
resultThe read value.
aDefaultValueThe deafult value to use if the parameter is not found.
Returns
Returns true if the parameter was found.

Finds a bool parameter. DefaultValue will be used if the parameter is not found.

GetIntParamArray

bool GetIntParamArray(string parameter, int* result, int num, const int* aDefaultValue = nullptr) override;
Parameters
parameterThe name of the parameter.
resultThe read array.
numThe size of the parameter to read.
aDefaultValueThe deafult value to use if the parameter is not found.
Returns
Returns true if the parameter was found.

Finds an integer array parameter of size 'num'. If aDefaultValue is defined, it will be used if the parameter is not found.

GetIntParam

bool GetIntParam(string parameter, int* result, int defaultValue) override;
bool GetIntParam(string parameter, int* result) override;
Parameters
parameterThe name of the parameter.
resultThe read value.
aDefaultValueThe deafult value to use if the parameter is not found.
Returns
Returns true if the parameter was found.

Finds an integer parameter. DefaultValue will be used if the parameter is not found.

GetDoubleParamArray

bool GetDoubleParamArray(string parameter, double* result, int num, const double* aDefaultValue = nullptr) override;
Parameters
parameterThe name of the parameter.
resultThe read array.
numThe size of the parameter to read.
aDefaultValueThe deafult value to use if the parameter is not found.
Returns
Returns true if the parameter was found.

Finds a float array parameter of size 'num'. If aDefaultValue is defined, it will be used if the parameter is not found.

GetDoubleParam

bool GetDoubleParam(string parameter, double* result, double defaultValue) override;
bool GetDoubleParam(string parameter, double* result) override;
Parameters
parameterThe name of the parameter.
resultThe read value.
aDefaultValueThe deafult value to use if the parameter is not found.
Returns
Returns true if the parameter was found.

Finds a float parameter. DefaultValue will be used if the parameter is not found.

GetStringParamVector

bool GetStringParamVector(string parameter, std::vector<string>& VsResult) override;
Parameters
parameterThe name of the parameter.
resultThe read array.
Returns
Returns true if the parameter was found.

Finds a string array parameter.

GetStringParam

bool GetStringParam(string parameter, string& result, const string& defaultValue) override;
bool GetStringParam(string parameter, string& result) override;
Parameters
parameterThe name of the parameter.
resultThe read value.
aDefaultValueThe deafult value to use if the parameter is not found.
Returns
Returns true if the parameter was found.

Finds a string parameter. DefaultValue will be used if the parameter is not found.

Writing to log file and reporting errors

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.

SimObject ports and states

Registering output ports

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;

Shared resources

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.