FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
Exercise: Creating simple SimObjects

This exercise extends fhsim_tutorial with two custom SimObjects.

Goal

Create and run:

  1. A damped spring SimObject in 3D.
  2. A mass SimObject that supports multiple force inputs.

Prerequisites

Workflow overview

For each new SimObject, you will:

  1. Create .h / .cpp files.
  2. Add files to CMakeLists.txt.
  3. Add includes/registration in the library entry file (for example fhsim_tutorial.cpp) using ADD_SIMOBJECT_REF.
  4. Build the project.
  5. Update/create an XML input file.
  6. Run and verify behavior.

Part A: Damped spring in 3D

  1. Copy CLinearSpring.h/.cpp to CDampedSpring.h/.cpp.
  2. Rename class identifiers from CLinearSpring to CDampedSpring.
  3. Add damping parameters and force terms in the implementation.
  4. Register the new SimObject in the project.

Part B: Multi-input mass object

  1. Copy CMass.h/.cpp to CMultiPortMass.h/.cpp.
  2. Rename class identifiers from CMass to CMultiPortMass.
  3. Add configurable number of input ports and sum the force contributions.
  4. Register the new SimObject in the project.

Build and run

Build

conan build .

Run

See Running a compiled SimObject.

XML checklist

When creating your scenario XML:

  • Connect every required input port.
  • Initialize all state variables that must start from non-zero values.
  • Verify input/output vector sizes match.
  • Set SimObject="..." exactly to the registered type name.
Note
If you base XML on older tutorials using <INTEGRATION>, migrate to <SIMULATION> + <Integrator Method="..."> as documented in Running simulations.