Marine systems simulation
3 Software overview

The FhSim core codebase consists of several components and tools which support different ways of use. These components and tools are specified in the main code base for FhSim and include the following:

  • The FhSim executables can run simulations with and without visualisation and with or without real-time requirements. Corresponding executables are FhRtVis, FhRtSim, FhSim, FhVis.
  • BatchSim facilitates running parameter sweeps using FhSim and visualising the results as 3D plots.
  • FMU tools makes it possible to export a FhSim model as a stand-alone FMU.
  • FhSim Light API can be used for running simulations from your own software, utilizing a shared library.
  • The FhSim API can be used for creating new simulation models and seamlessly integrate FhSim with your own software.
  • Plugable model libraries, based on the SimObject interface.

Software components

Overview of the FhSim API if compiled with visualization

Components

Referring to the figure above, the following are the key components of the FhSim API:

CFhSim

CFhSim wraps a system to integrate, the integrator, and the integrator settings. The system is specified through input files. The results are returned either as a text file or as the answer to a function call.

CModelStructure

CModelStructure is responsible for representing a collection of SimObjects as one larger model for the CFhIntegrator. It maintains an overview of the SimObjects, their ports and their states, and applies the interconnections as defined in the construct input file. It acts as a single model which the integrator calls, and it implements all the necessary methods for the class CModel.

CFhIntegrator

The integrator is responsible for keeping track of the states of the total model, and to advance these states by getting the calculations of the derivatives from the CModelStructure. It also handles aspects such as reading and writing initial conditions from/to file and gets its parameters from the input file parser, CParse.

CSimObject

In the source code, submodels translates to classes derived from the CSimObject class. This class contains all functionality common to all SimObjects, while functionality specific for each submodel is implemented in classes inheriting this CSimObject. Typically this includes defining its interface, in terms of input ports, output ports and parameters, as well as its state variables. A SimObject should also provide methods for calculating the derivatives of its states and for setting its output ports. Each SimObject needs to know nothing about other SimObjects, as all input are provided for by CModelStructure.

File I/O

FhSim handles different file types in different ways. The main input file is in XML format, and is read by CParse, which uses the library TinyXML for this purpose. CParse contains functions to read the input file and write its content to the appropriate structures. These structures are then provided where they are needed. While FhSim is running, the writing of log messages to screen and file is performed by CPrintDuringExec. This is done according to separate loglevels for screen and logfile. CPrintDuringExec is also able to write the results of the simulation to file. This method writes states and/or output from the specified SimObjects at the specified times to the specified file. The points in time for which this is to be done is found based on the settings in the main input file, specifically by the property TOutput.