flags

A flag describes a particular phase of a simulation. In models, a block can be called with flags to perform different operations.

For example a block can be called to update its output with flag= VssFlag_OutputUpdate (= 1) or can be called to provide the state derivatives with flag= VssFlag_Derivatives (= 0).

Flags are defined as follows:

Flag Number Issued Flag Name Result When a Block Is Called with this Flag
Flag 0 VssFlag_Derivatives The simulator requests the block to provide the continuous-time state time derivatives.
Flag 1 VssFlag_OutputUpdate The simulator requests the output(s) of the block.
Flag 2 VssFlag_StateUpdate An event has activated the block to update its discrete-time and continuous-time states.
Flag 3 VssFlag_EventScheduling The block can program a new event at one or more of its output activation ports.
Flag 4 VssFlag_Initialize The block is called for the first time at the beginning of the simulation where initialization issues can be resolved.
Flag 5 VssFlag_Terminate The simulator calls the blocks once at final time when a simulation is finished or stopped due to an error or user-request.
Flag 6 VssFlag_Reinitialize The block can reset its continuous-time state as a function of its input values.
Flag 7 VssFlag_ReinitializeImplicit In an implicit model after an event restarts the solver, the implicit block updates its states and state derivatives.
Flag 8 VssFlag_Projection If a block’s dynamics is represented by an ODE with algebraic constraints, the simulator calls the block to either compute the projection update or the residual of constraints.
Flag 9 VssFlag_ZeroCrossings The simulator requests the block to provide its zero-crossing surfaces.
Flag 10 VssFlag_Jacobians The simulator requests the block to provide the analytical Jacobian matrix of the model.
Flag 11 VssFlag_GotoPause The block pauses to perform any required jobs before the simulation stops.
Flag 12 VssFlag_ReturnFromPause After the pause in a simulation is finished, the blocks resume the simulation.

The following is an example skeleton showing how flags are used to define the simulation function of a C Custom block.

VSS_EXPORT void
        CBlockFunction(vss_block *block,int flag)
{
SCSREAL_COP *u1=GetRealInPortPtrs(block,1);
     int mu1=GetInPortSize(block,1,1);
     int nu1=GetInPortSize(block,1,2);
SCSREAL_COP *y1=GetRealOutPortPtrs(block,1);
     int my1=GetOutPortSize(block,1,1);
     int ny1=GetOutPortSize(block,1,2);
     int nevprt=GetEventCode(block);
     switch (flag){
     case VssFlag_Initialize:

       break;
     case VssFlag_Reinitialize:

       break;
     case VssFlag_Terminate:

       break;
     case VssFlag_OutputUpdate:

       break;
     }
}