MATLAB: Can I put assertions in the Parameters section of the .SSC file

Simscape

I have been using the setup section in Simscape to handle error checking for parameters/inputs upon initialization, but now it appears as though the setup section is no longer recommended. MathWorks suggests using assertions to handle errors (which I already use for dynamic variables/inputs), but it seems like extra/wasted computation cost to run assertions over and over for static parameters/inputs. Is it possible to use assertions in the parameters section of my .SSC file, or could this be added in a future release?

Best Answer

  • To validate Simscape parameter values we do recommend using 'assert' commands placed in an equations section of the .SSC file. The 'assert' command is not supported in the parameters section at this time.
    Although 'assert' is written inside an equations section, if the assert expression references just parameters and constants, it is only checked during model compilation and there is no impact on simulation performance. Even if a Simscape parameter is set to be a run-time parameter, the assert is only checked once at the beginning of simulation.
    As Simscape supports multiple equations sections, for code readability it may be helpful to place parameter checking asserts in a separate equations section just below the parameters section. To see an example you can type the following command at the MATLAB Command Window:
    >> edit foundation.thermal_liquid.elements.flow_resistance