Ask Simulink engine to reset solver


void ssSetSolverNeedsReset(SimStruct *S)



SimStruct representing an S-Function block or a Simulink® model.


Use the ssSetSolverNeedsReset macro when a change occurs in the dynamics of the S-function that can affect the ODE solver. An example change is a discontinuity in S-function continuous state or a discontinuity in its output that is driving other continuous blocks. An S-function should only change its continuous state vector in a major time step. Do not change continuous state values in minor time steps.

A discontinuity in a state or output of a continuous S-function can invalidate the cached state and derivative information in the ODE solver. Use the ssSetSolverNeedsReset macro to have the ODE solver reinitialize the cached information in the next integration step. Continuous state changes without solver resets are unsafe. Changing continuous states without also using the ssSetSolverNeedsReset macro can lead to incorrect results because the ODE solver may ignore these changes to protect internal consistency of its data and integration results. Only reinitialize states at major time steps. Integration algorithms do not expect state vectors to change during minor time steps.


When using this macro, for performance issues, consider also using ssSetSkipContStatesConsistencyCheck(S,1) in the mdlInitializeSizes method. ssSetSkipContStatesConsistencyCheck disables the monitoring of S-function continuous states by Simulink, improving simulation performance.


C, C++


The following example uses this macro to ask the Simulink engine to reset the solver.

static void mdlOutputs(SimStruct *S, int_T tid) 
	: <snip> 
	if ( ssIsMajorTimeStep(S) && YourConditionsForStateChange ) {
		double *x = ssGetContStates(S);
		/* reset the states */ 
		for (i=0; i<nContStates; i++) { 
			x[i] = 0.0; 
		/* Ask the Simulink engine to reset the solver. */ 

Also see the source code for the Time-Varying Continuous Transfer Function (stvctf.c) for an example of where and how to use this macro.

Introduced before R2006a

Was this topic helpful?