Analyze the magnitude of Simscape Variables for defining good scaling values | Simscape Electrical Modeling Practices for Fast Simulation - MATLAB & Simulink
Video length is 4:19

Analyze the magnitude of Simscape Variables for defining good scaling values | Simscape Electrical Modeling Practices for Fast Simulation

From the series: Simscape Electrical Modeling Practices for Fast Simulation

This video shows how the Variable Scaling Analyzer can be used for scaling Simscape variables to increase simulation robustness and performance.

Published: 7 May 2024

Hello, my name is Eva and I'm an application engineer at MathWorks. In this video I would like to demonstrate the Variable Scaling Analyzer. You can use this tool to analyze the magnitude of different Simscape variables to support you with the process of scaling those states, which can improve solver performance.

The model used in this example was taken from the Simscape electrical examples library. Using this example model, I will walk through the variable scaling analyzer. To start, when working with Simscape, it is good practice to have variable scaling enabled. Confirm the setting in the model settings under Simscape.

In Simscape, you can enable scaling and then specify corresponding nominal values. The nominal values dialog is where those scaling values can be provided as value unit pairs.

When the solver is carrying out the simulation and assessing the results with respect to the tolerance settings, it uses variables without units. And the nominal value is a way of converting Simscape variables to unitless values. And poorly scaled units can magnify or reduce the influence of the corresponding variable. The scale can be either too high compared to other variables or it can be too small, meaning too close to the actual absolute tolerance value. So for more robust performance, it is beneficial to have all scaled Simscape variables be of a similar magnitude.

The nominal values dialog provides a Simscape network-wide setting. And some Simscape components have the option of defining nominal values that will only be valid for the block variables. In case it is not defined elsewhere, a nominal value can also be derived, for example, from other fundamental dimensions.

Another setting that will be important when using the Variable Scaling Analyzer will be that of the absolute tolerance value. This can be defined in model settings, solver, and then solver details. Note that the autoscale absolute tolerance setting is disabled here, which is recommended for Simscape networks.

To now analyze the effect of the variable scaling using the simulation results, open the Variable Scaling Analyzer. If needed, attach the tool to the current model and run the simulation from here.

Using the results, the app will display an analysis of the simulation states with respect to each other and the absolute tolerance value. The results in the raw data pane display a table with an index number representing a retained state, the state name, and the nominal value unit pair associated with it.

The percent of time below absolute tolerance column refers to the percentage of the simulation time that this variable has a value below that of the absolute tolerance parameter. This applies when the autoscale absolute tolerance setting is disabled.

The min data and max data are minimal and maximal values during the simulation run for the given variable. And the remaining columns give additional information on variable statistics such as their time-weighted statistical mean.

The yellow highlighting and the result points to potentially problematic observations. In this case, this is highlighting where the state values have been below its absolute tolerance for the majority of the simulation time as well as a value where the mean absolute value is of much higher magnitude than all other variables.

The messages pane in the lower right will make some more suggestions on actions I could take based on those results. Use the plot option to create visualization of states with respect to their absolute tolerance value. This will plot the state value and display it together with a gray band, indicating the tolerance limits. This could help you to decide if this is representing noise or scaling could be helpful to lower the percentage time the value spends within the tolerance band.