Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Improving Performance

Optimizing Mechanical and Mathematical Settings

SimMechanics™ software is a general-purpose mechanical simulator. With it, you can model and simulate many types of machines with very different behaviors. In some cases, the settings you use for "well-behaved" machines are not optimal for more-difficult-to-simulate systems. Simulink® and SimMechanics software give you great freedom to change the mechanical and mathematical settings used in your simulations. Use this flexibility to avoid simulation errors and optimize performance, subject to the fundamental tradeoff between speed and accuracy. This section explains techniques for achieving these goals.

In this chapter, consult also

Simplifying the Degrees of Freedom

In general, the more degrees of freedom (DoFs) you add to your model, the slower the simulation.

Eliminating Unnecessary Degrees of Freedom

Under certain circumstances, a model can contain DoFs not practically necessary to predict system behavior. For example, a subsystem might contain very light masses whose motion is almost completely determined by the heavier masses in the system and that have almost no inverse influence on the larger system.

Consider freezing or eliminating such degrees of freedom from your model in order to speed up the simulation.

Freezing "Fast" and "Slow" Degrees of Freedom

A related distinction can be made between DoFs that change rapidly and those that change slowly. Such systems are "stiff" (literally, in the case of a stiff spring that oscillates at a very high frequency) and often hard to simulate accurately in a reasonable time.

One approach to improving the speed is to selectively freeze certain DoFs.

  1. Freeze or eliminate the "fast" DoFs and simulate only the "slow" DoFs.

  2. Freeze the "slow" DoFs in some representative configuration and simulate the motion of only the "fast" DoFs.

Such a split simulation between "fast" and "slow" DoFs can isolate important features of the system behavior, while ignoring unimportant features.

    Caution   Splitting DoFs between "fast" and "slow" sets and simulating the two sets separately neglects coupling between the two sets of DoFs. Only a full simulation can capture such coupling.

See Solving Stiff Systems in this section for a different approach to handling speed mismatches among DoFs.

Removing Stiction Actuators

Stiction requires computationally expensive algebraic loops. If possible, remove Joint Stiction Actuator blocks from your model to speed it up.

Simulating in Two Dimensions

If your machine moves in only two dimensions, not three, it qualifies for the SimMechanics two-dimensional simulation option. By reducing the linear and rotational directions from three to two and three to one, respectively, this option can noticeably improve simulation performance.

See Choosing Your Machine's Dimensionality in this chapter.

Adjusting Constraint Tolerances

Maintaining constraints on a system's DoFs is a major and computationally expensive part of a simulation. If your simulation seems to run slowly or stops with constraint errors, especially when the mechanism passes through certain configurations, consider relaxing the constraint tolerances and/or solver. This step generally speeds up the simulation, although it also makes the simulation less accurate. Decreasing the tolerances increases the accuracy of the simulation but can increase the time required to simulate the model.

To view and change these settings in your machine, see Maintaining Constraints in this chapter and the Machine Environment block reference.

Smoothing Motion Singularities

Singularities in a system's equations of motion can dramatically slow down a standard Simulink solver or even prevent it from finding a solution to a system's equations of motion. Because mechanical motion can become singular, you have the option of robust singularity handling, which works together with your selected solver to solve singular equations of motions efficiently. This feature allows Simulink in many cases to simulate models that otherwise cannot run or cannot be solved in a reasonable time. To enable robust singularity handling, see Avoiding Simulation Failures in this chapter.

Exact singularities are recoverable if they form isolated configurations that can be avoided by perturbing the initial state or "stepping over" them during simulation. In that case, the neighborhood of the exact singularity is quasi-singular and appropriate for robust singularity handling. If the machine has a whole neighborhood of continuously related singular configurations, motion in that neighborhood cannot be simulated. For examples of typical singularities, see Motion Inconsistency and Singularity Errors in this chapter.

Avoiding Singular Initial Configurations

Avoid starting a machine in a singular configuration. Its subsequent motion violates assembly tolerances, as the simulation incorrectly removes one or more necessary constraints. Common singular configurations include these:

  • The machine can move in two or three dimensions, but starts in exactly one or two dimensions, respectively.

  • Two or more identical bodies spatially coincide in position and orientation.

Work around an initial singularity by slightly misaligning the singular joint axes or slightly displacing the coincident bodies, within assembly tolerances, before starting the simulation.

The SimMechanics node of the Configuration Parameters dialog allows you to enable simulation warnings for possible singular initial configurations. See Avoiding Simulation Failures in this chapter.

Changing the Simulink Solver and Tolerances

The Dormand-Prince solver (ode45) that Simulink uses by default works well for many mechanical systems. But if your simulation seems to be slow and/or inaccurate you should consider changing the solver and/or adjusting the solver's relative and absolute tolerances. Chaotic and highly nonlinear systems especially require experimentation with different solvers and tolerances to obtain optimal results.

Consult the Simulink documentation for more about choosing Simulink solvers and tolerances.

Solving Stiff Systems

The default Simulink solver typically requires too much time to solve systems that are stiff, that is, have bodies moving at widely differing speeds or have many discontinuities in their motions. An example of a stiff system is a pair of coupled oscillators in which one body is much lighter than the other and hence oscillates much more rapidly. Any of the Simulink stiff solvers might require significantly less time to solve a stiff system.

See the Simulink documentation on choosing a solver for more about stiff solvers.

Real-Time Simulation and Ignoring Motion Details with Fixed-Step Solvers

For most mechanical systems, variable time-step solvers are preferable. Fixed time-step solvers, depending on the size of the time step, often fail to resolve certain motion details.

Using a fixed-step solver can be advantageous in some cases, however:

  • If you want to ignore unimportant motion details. Ignoring them can speed up your simulation, especially for a larger time step.

  • If you are simulating in real time with generated code. Fixed-step solvers are typically, but not exclusively, the norm for real-time simulation.

For such cases, choose one of Simulink's fixed-step solvers and select the largest time step that produces reasonable simulation results.

Most of Simulink's fixed-step solvers are explicit. For stiff systems and larger time steps, an implicit solver such as the ode14x fixed-step solver can be superior to an explicit solver in speed and accuracy.

Adjusting the Time Step in Real-Time Simulation

A real-time simulation using code generated and compiled from your model must keep up with the actual mechanical motion. To this end, you must ensure that the solver time step is greater than the computation time needed by your compiled model.

To meet this condition, you might have to increase the time step or decrease the computation time. Increasing the time step often requires removing the model's "fast" DoFs. Decreasing the computation time requires simplifying your model. You can do this most easily by removing DoFs and/or constraints. See Simplifying the Degrees of Freedom preceding.

Was this topic helpful?