Marine systems simulation
Create a new SimObject

SimObjects are time domain simulation models which are loaded by FhSim at runtime. Herein, a sketch of the procedure for creating a new SimObject is presented. It is practical to use existing implementations as starting point for new developments.

Steps for creating a new SimObject

Suppose you have an existing SimObject library and want to add a new SimObject. To create new SimObject, simply inherit from the SimObject class and implement necessary functions:

  • Create new source and header files, usually by taking an existing SimObject implementation as starting point. The new class should inherit the SimObjectclass, and the header file should include <SimObject.h>.
  • Extend appropriate variables in CMakeLists.txt with the new file names.
  • Add an include directive for your new header file to the SimObject library's module header file and add ADD_SIMOBJECT_REF(<Class name>, <Object reference name>); or ADD_SIMOBJECT_REF3(<Namespace>, <Class name>, <Object reference name>); in the getSimObject function of the corresponding cpp file.
  • Compile and load its configuration using your newly defined object reference name. Build with either cmake --build . --config Release, conan build ., or via your IDE.

    Note
    If your SimObject library is created from the SimObject template tool, there is a DEVELOPING.md file on the project root that contains a step-by-step cheat sheet.

Central methods to implement for a new SimObject

A SimObject can implement a range of methods, some optional and some required:

 SimObject(const string& simObjectName)
 void OdeFcn(double T, const double* X, double* XDot, bool IsMajorTimeStep)
 void InitialConditionSetup(const double T, const double* const currentIC, double* const updatedIC, ISimObjectCreator* const creator)
 void FinalSetup(double T, const double* X, ISimObjectCreator* creator)
 void PreOdeFcn(double T, const double* X, IStateUpdater* updater)
 void RenderInit(Ogre::Root* ogreRoot, ISimObjectCreator* creator)
 void RenderUpdate(double T, const double* X)

Their calling sequence is given in the figure below.

The FhSim call sequence.

Detailed information about these methods and their use is found in:

Example SimObjects

To better understand the implementation of SimObjects, view the implementation of a linear spring and a mass object. The following files are disclosed: