FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
StateFrame Class Reference

#include <JacobianStates.h>

Public Member Functions

 StateFrame (const double *localStates, int firstStateIndex)
 
 StateFrame (int firstStateIndex)
 
int Local (int globalIndex) const
 Index within the slice of the state with global index globalIndex.
 
const double * State (int globalIndex) const
 The state with global index globalIndex, in the slice.
 
const double * Global () const
 The global state vector, as OdeFcn is handed it.
 

Detailed Description

A Jacobian callback's view of the global state vector.

AddState returns indices into the global state vector, the one OdeFcn is handed. FhSim hands SimObject::OdeJacobian, OutputPortJacobian and InputPortJacobian only the pointer state + offset, where offset is the object's first state, the value its first AddState returned (fhsim/src/engine/model/JacobianAssembler.cpp, SimObjectJacobianBlock.cpp, PortCouplingEvaluator.cpp), and a block sized to its own states. The callback indexes that slice with local indices.

A StateFrame pairs the slice with the object's first global state index so a callback never mixes the two up:

  • Local(i) turns a global state index into an index within the slice, for writing the Jacobian blocks;
  • State(i) points at the state with global index i in the slice, for reading its value;
  • Global() is the global state vector. Anything that expects what OdeFcn is handed must be given this: ISignalPort::GetPortValue, ICommonComputation::ComputeFunction and the object's own functions that index with AddState values. A port or common computation evaluates its source with the vector it is given whenever its cache is empty, so a local slice would make it read the wrong states (BASE-0042).

A frame is built per callback; it holds the two values and nothing else.

Constructor & Destructor Documentation

◆ StateFrame() [1/2]

StateFrame::StateFrame ( const double *  localStates,
int  firstStateIndex 
)
inline
Parameters
localStatesThe slice the callback was handed.
firstStateIndexThe object's first global state index, as its first AddState returned it.

◆ StateFrame() [2/2]

StateFrame::StateFrame ( int  firstStateIndex)
inlineexplicit

A frame for a callback that is handed no slice, such as GetJacobianSparsity. Only Local may be used on it.


The documentation for this class was generated from the following file: