Marine systems simulation
SimObject modeling concept

The most fundamental elements for developing new models in FhSim are the SimObject interface, its building blocks, common computations and initial conditions.

A simulation is usually comprised of multiple sub-models which are connected through input and output ports. These sub-models are a fundamental part of FhSim and is referred to as SimObjects. A SimObject has the following properties:

  • Input ports: Each input port is defined by a name and a width (number of elements). The data type is always double. All input ports must be connected.
  • Output ports: Each output port is defined by a name and a width. The data type is always double. It is allowed to have output ports which are not connected. The values of output ports are calculated for every time step if any other SimObject is requesting it, and if it is not cached.
  • Parameters: Parameters are static values which are set before the simulation starts. They are defined by a name and a width.
  • States: Each state is defined by a name and a width.

Shared objects

In some cases, it is beneficial to have access to perform identical calculations, coordinated tasks across SimObjects or calculations not fitting within the usual time integration paradigm. A typical example would be when one wants to calculate the environmental forces on multiple structures operating in the same sea, and especially if these interact. In FhSim, this is typically solved by defining an environment object, and giving all relevant SimObjects access to this. FhSim includes a mechanism to share any kind of C++ object between simObjects. Typically, in the simObject constructor one sets the shared resource using the supplied instance of the creator. Considering a resource of type resource_class one wants to associate with the name resource_name and that resource_pointer is a permanent pointer to the resource. Registering this resource can be done like this (creator points to an object of type ISimObjectCreator):

creator->SetSharedResource(resource_name, resource_pointer);

When another simObject wants to use the shared resource, it must know the name and type of the object. It can then retrieve it like this:

my_pointer_to_resource = (resource_class*) creator->GetSharedResource(resource_name);

To ensure that all shared resources are registered before they are retrieved, it is advisable to register them in the simObject constructor and retrieve them in the simObject function FinalSetup. Both takes creator as one of their arguments.

CommonComputation

Computations that are shared between different functions (OdeFcn, PortFunctions, different SimObjects) may be registered as a CommonComputation. The system will ensure it is called only once per time step. The typical use case is if several output ports depends on the same calculation. Imagine a spring which outputs force in each end in two separate output ports. Each port function could then start by calling the same CommonComputation, calculating the tension and orientation of the spring only once per time step.

Initial condition

The time integration must have a starting point in the form of an initial state vector. This starting point can be defined in multiple ways:

  • A full state vector read from a file (typically written from a previous simulation).
  • Defined for the individual SimObjects in the input file.
  • Calculated by the function InitialConditionSetup of the individual SimObjects.

The latter allows for example SimObjects to calculate their initial state based on parameters and input ports. In some cases multiple SimObjects use input ports for determining their states, and output ports depend on input ports and/or states. This can lead to mutual dependencies. FhSim tries to solve this by iteration. If this doesn't succeed within a predefined number of iterations, the simulation will be aborted with an error message.