Why is my model made of Simscape and Simscape Multibody simulating very slowly?

32 次查看(过去 30 天)
I have a model made of Simscape and Simscape Multibody that simulates significantly slower than I would expect.
I ran the simulation through the
. The time step looks like the following picture. The step size remains small and chatters a lot. Also, in the Solver Profiler statistics, we see a large amount of newton iteration failures and Jacobian recalculation compared to the total number of steps.
When looking at the states contributing the most to newton iterations, they do not seem to change significantly fast, so capturing their behavior should not require such small step size.

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2021-3-9
Here are steps to help investigating the performance of Simscape and Simscape Mlutibody simulations.

1. Solver Tolerances

The default tolerances for Simscape are sometimes not ideal for large Simscape models. Based on experience, we find the following usually works well for Simscape models:
  • For Relative tolerance, the default 1e-3 is usually a good first guess.
  • For Absolute Tolerance, specify a value one or two orders of magnitude smaller than the Relative Tolerance. The default "auto" is often too small for Simscape models
  • Disable the option "Auto scale absolute tolerance". 

2. Solver Profiler

Simulate the model using the Solver Profiler. enable logging of States and Zero Crossing, and Simscape Logging. In the Statistics pane, look for large number of events, relative to the total number of steps. Depending on which statistic shows high number, try the following:
  • Zero-crossing: Use the Zero-Crossing Explorer to understand the reason for the zero-crossing sources triggered a large amount of time. Zero-crossing detection is necessary for simulation accuracy, to detect sudden changes accurately. To reduce the amount of zero-crossing events, consider making the algorithm continuous, or look into modifying the dynamic of the system being modeled. See this article for an example where stiffness and damping used for contact modeling can be adjusted to compromize between performance and accuracy.
  • Solver Resets: One common source of solver resets is when a block running at a discrete rate drives a block is continuous states. When the value of the discrete signal changes, the solver needs to be reset to handle the discontinuity. In R2019b, a new First Order Hold block has been introduced in the continuous section of the Simulink Library. This block does first order interpolation of the discrete signal, making the signal to be integrated continous, removing the need for solver reset.
  • Solver Exceptions: If you see large number of solver exceptions, instead the states with the largest numbers using the States Explorer. In the States Explorer, sort by solver exceptions. Verify if the signals are as expected, or if they contain unexpected numerical noise. If that's the case, see next items.

3. States Scaling using Simscape nominal values

In the States Explorer, rank the states by State Value. If the first states have very large values, try scaling the system using nominal values. In the model configuration, it is possible to scale all the states with a specific unit, and using the Property Inspector, it is possible to scale individual states of a specific block.
In general, solvers behave better when states are scaled within the -1 to 1 range.

4. Jacobian Perturbation

We have found that for some models, limiting the level of perturbation used to compute the solver Jacobian 
can improve performance. Using the attached function "limitJacobianPerturbations", it is possible to limit the amplitude of this perturbation. Use it the following ways.
limitJacobianPerturbations('recommended')
This will limit the numerical perturbation to a minimum of "sqrt(eps)" (1.4901e-08). We found that this value works well with a majority of impacted models.
limitJacobianPerturbations('reset')
This will restore factory settings.
limitJacobianPerturbations('custom',[lowerLimit upperLimit])
Allows you to specify custom limits. In some cases, the recommended setting ends up being still too small and increasing the lower limit to values like 1e-6 or 1e-5 helps. Setting the lower limit too large can lead to less accurate results. Changing the upper limit typically does not have significant impact, we recommend settign it to "inf" or a large number.

5. Modeling Issues

If none of the above works, use the Solver Profiler and associated tools like the States Explorer and Zero-Crossing Explorer to try identifying modeling issues. Start with the states ranked highest in the different tables, and then use the Simscape Explorer to observe surrounding states in the model to confirm that the results are what you expect.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulation Setup 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by