Marine systems simulation
|
SimObjects are compiled into a shared library – a dll
/so
file – which are loaded by FhSim at runtime. Herein, a sketch of the procedure for creating a new SimObject is presented, and we outline how to create a new SimObject library with a set of SimObjects. It is practical to use existing implementations as starting point for new developments. We have written a SimObject template tool to make it easier to create a new SimObject library that follow good coding practices, see SimObject template tool.
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:
#include <SimObject.h>
in your header file.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.cmake --build . --config Release
, conan build ..
, or via your IDE.DEVELOPING.md
file on the project root that contains a step-by-step cheat sheet.SimObject libraries are loadable modules (dll
or so
files) that contain one or more classes inheriting from the SimObject interface. Each implemented SimObject must be referenced using ADD_SIMOBJECT_REF
or ADD_SIMOBJECT_REF3
macros in a CMake MODULE
target. The MODULE
target must link to the target FhSim::fhsim
, which contains the SimObject
base implementation. Suppose fhsim_example.cpp
contains a class my::deep::space::VanDerPol
and Pendulum
, both implementing the SimObject interface. To create a SimObject library with these models, we add to fhsim_example.cpp
:
An excerpt of the CMakeLists.txt
is:
The resulting dll
/so
is now a SimObject library with two SimObjects: Oscillator/VanDerPol
and Oscillator/Pendulum
.
The simobject template
tool is a command line interface that help create a minimal SimObject library, with ready-made scripts for CMake, conan and documentation. If you are lucky, you are almost completely relieved the burden of writing build system scripts.
Install it from the following URL:
If you have access to the git repository, install the development version from there:
Run simobject --help
to get available commands. A user scenario is typically
simobject new config_dir
config_dir/simobject.cfg
in a text editor. A simobject.cfg file will be on the format:simobject create config_dir --output-folder generated_dir
cd generated_dir && git init
mkdir build && cd build
conan install .. && conan build ..
DEVELOPING.md
and README.md
in the generated directory.To better understand the implementation of SimObjects, view the implementation of a linear spring and a mass object. The following files are disclosed: