|
FhSim
3.1.0
Marine systems simulation
|
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.
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:
SimObjectclass, and the header file should include <fhsim/simobject/SimObject.h>.CMakeLists.txt with the new file names.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.
DEVELOPING.md file with a step-by-step cheat sheet. See SimObject template tool.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) const 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 AcceptedStep(double T, const double* X) bool HasJacobians() const void OdeJacobian(double T, const double* X, double* J, int nStates) int GetJacobianSparsity(int nStates, int* rowPtr, int* colIdx) void RenderInit(Ogre::Root* ogreRoot, ISimObjectCreator* creator) void RenderUpdate(double T, const double* X)
The HasJacobians(), OdeJacobian(), and GetJacobianSparsity() methods are optional but enable analytical Jacobian support for implicit integration methods. See Implicit Integration with Analytical Jacobians for details.
Their calling sequence is given in the figure below.
Detailed information about these methods and their use is found in:
The header declares your class and its interface:
The constructor registers ports, states, and reads parameters:
The OdeFcn computes state derivatives:
Output port functions return pointers into the state vector:
To better understand the implementation of SimObjects, view the implementation of a linear spring and a mass object. The following files are disclosed:
C-prefixed class names (CLinearSpring, CMass) so their documentation and cross-references stay stable. The C prefix is a legacy FhSim 2.x convention and must not be used for new code — name new SimObjects without it (e.g. LinearSpring, Mass). The examples are illustrative of the SimObject structure, not of current naming style.