SimMechanics    

Choosing an ODE Solver

SimMechanics uses an ODE solver to solve a system's equations of motion, typically in tandem with a constraint solver (see Choosing a Constraint Solver). Simulink provides an extensive set of ODE solvers that represent the most advanced numerical techniques available for solving differential equations in general and equations of motion in particular. The Solver pane of a model's Simulation Parameters dialog box allows you to select any of these solvers for use by Simulink in solving the model's dynamics (see "The Solver Pane" in the Simulink User's Guide more information).

The Dormand-Prince solver (ode45) that Simulink uses by default works well for many mechanical systems, but might require too much time to solve systems that are stiff, that is, have bodies that move at widely varying speeds or that have many discontinuities in their motion. An example of a stiff system is a pair of coupled oscillators in which one oscillator is much lighter than the other and hence oscillates much more rapidly. Any of the following solvers might require significantly less time than the default solver to solve a stiff system:

Try each of these solvers in turn and then use the solver that gives the best results.

Setting ODE Solver Tolerances

By default Simulink automatically determines the absolute tolerance used by ODE solvers. The resulting tolerance might not be small enough for a mechanical system, particularly a nonlinear or chaotic system. Try running a simulation with the relative tolerance set to 1e-3 (the default) and the absolute tolerance set to 1e-4. Then increase the tolerances if the simulation takes too long or decrease them if the solution is not sufficiently accurate.

If your model contains one or more Joint Stiction Actuator blocks, you must also take into account the velocity thresholds of these blocks when setting the absolute tolerance of the ODE solver. If the absolute tolerance of the solver is greater than a joint's velocity threshold, the simulation might never detect the unlocking of a joint. To prevent this from happening, set the absolute tolerance to be no more than 10% of the size of the smallest stiction velocity threshold in your model.

Handling Singularities

Singularities in a system's equations of motions can dramatically slow down a standard Simulink ODE solver or even prevent it from finding a solution to a system's equations of motions. Because singularities are frequent in mechanical equations of motion, SimMechanics provides an optional feature, called Robust Singularity Handling, that works in tandem with the currently selected ODE solver to solve singular equations of motions efficiently. This feature can enable Simulink to simulate models that otherwise cannot be simulated or cannot be solved in a reasonable amount of time because of the singularities.

To enable this feature, select Use robust singularity handling on the Constraints pane of the Mechanical Environment Settings dialog (see Use Robust Singularity Handling). Because this option requires extra computation whether or not singularities exist, you should select this option only as a last resort, i.e., select this option only if you cannot find a standard Simulink solver that solves your model in a reasonable amount of time without it.

Setting Assembly Tolerances

A model's Mechanical Environment Settings dialog allows you to specify a linear and an angular assembly tolerance (see Parameters Pane). These tolerances specify the precision with which:

Simulink checks the locations and angles of a model's assembled joints during the model initialization phase of a simulation. If any of the joint locations or angles fail to meet the corresponding assembly tolerances, Simulink halts the simulation and displays an error message. If this happens, you should check your model to ensure that it specifies the locations and angles of its assembled joints to the precision specified on the Parameters pane of the Mechanical Environment Settings dialog. If not, either change the locations and angles that fail to meet the assembly tolerances or increase the tolerances themselves.

Choosing a Constraint Solver

If your model contains implicit or explicit constraints on a system's motion, SimMechanics uses a constraint solver to find a solution to its equations of motion that meet the constraints. The Constraints pane of the Mechanical Environment Settings dialog (see Constraints Pane) allows you to select one of the following solvers to solve the constraints specified by your model:

The following sections describe these solvers.

Stabilizing Constraint Solver

Adds a self-correcting term to the state equations to be solved that stabilizes the numerical solution, i.e., causes it to gravitate toward, rather than drift away from, the actual solution. SimMechanics uses this solver by default. It is typically faster than the other solvers, but can stop at a solution that exceeds the model's assembly tolerances. If assembly tolerance errors occur during the simulation, use one of the following solvers instead.

Tolerancing Constraint Solver

Solves the constraints on the system's states to the tolerance that you specify. Specifically the solver stops refining the numerical solution of the state equation when the difference between two successive solutions satisfies the equation

where error is the difference between successive solutions, rtol is the relative constraint tolerance (see Constraint Relative Tolerance), x is the state to be solved, and atol is the absolute constraint tolerance (see Constraint Absolute Tolerance).

Use this solver if you plan to run the simulation in Kinematics mode and you want to trade off simulation accuracy for simulation time. Relaxing the constraint solver tolerances generally reduces the time required to simulate the model. Decreasing the tolerances increases the accuracy of the simulation but also increases the time required to simulate the model.

Machine-Precision Constraint Solver

Solves the constraints to the numerical precision of the computer on which the simulation is running. Select this solver if you want to obtain the most accurate simulation permitted by the computer, regardless of simulation time.


  Choosing Simulation Options Mechanical Environment Settings Dialog Box