我做了一个简单的s函数,可以通过检查输入端口是否为NaN类型来抛出异常:
s-function块用于具有固定步长ODE4求解器的Simulink模型。但是,在运行此模型时,我收到以下警告:The model 'testError' does not have continuous states, hence Simulink is using the solver 'FixedStepDiscrete' instead of solver 'ode4'.
。我应该在mdlInitializeSizes
或mdlInitializeSampleTimes
函数中更改什么才能确保s函数与OD4求解器一起运行?
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 0);
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
return; /* Parameter mismatch will be reported by Simulink */
}
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 1);
ssSetInputPortDataType(S, 0, SS_DOUBLE);
ssSetInputPortDirectFeedThrough(S, 0, 1);
/* specify the sim state compliance to be same as a built-in block */
//ssSetSimStateCompliance(S, HAS_NO_SIM_STATE);
ssSetOptions(S,
SS_OPTION_DISALLOW_CONSTANT_SAMPLE_TIME |
SS_OPTION_WORKS_WITH_CODE_REUSE |
SS_OPTION_USE_TLC_WITH_ACCELERATOR);
}
static void mdlInitializeSampleTimes(SimStruct *S)
{
/*
* the first sample time, continuous
*/
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0);
ssSetModelReferenceSampleTimeDefaultInheritance(S);
}