Main Content

Fixed-Cost Simulation Process

When you determine that your model is ready to test on a fixed-step, fixed-cost solver, use the fixed-cost simulation process to complete your preparation for real time simulation. The flowchart demonstrates an example fixed-cost simulation process. Use a fixed-cost solver to simulate the model and check whether the results and execution time are acceptable. Like the model preparation process, the fixed-cost process may require several iterations of adjusting step size and number of iterations, and you may need to return to the model preparation process if you are unable to produce acceptable results. If your model produces acceptable results with acceptable execution time, proceed to the Real-Time Code Generation and Deployment Process.

Your model is real-time capable if it meets both of these criteria when you simulate it on your real-time computer:

  • The results match your expectations, based on empirical data or theoretical models.

  • The model simulates without incurring an overrun.

Fixed-step, fixed-cost simulation sets an upper boundary on computational cost by limiting both the step size and the number of iterations that the solver uses.

Make Your Model Real-Time Viable

Perform Fixed-Step, Fixed-Cost Simulation

Run your model on a desktop computer using fixed-step, fixed-cost configurations for the global solver and local solvers. For more information on specifying fixed-step, fixed-cost solver configurations for real-time simulation, see Choose Step Size and Number of Iterations and Fixed-Cost Simulation for Real-Time Viability.

Evaluate Model Accuracy

Compare the results from the simulation on the target computer to your reference results. Are the reference and modified model results the same? If not, are they similar enough that the empirical or theoretical data also supports the results from the simulation of the modified model? Is the modified model representing the phenomena that you want it to measure? Is it representing those phenomena correctly? If you plan on using your model to test your controller design, is the model accurate enough to produce results that you can rely on for system qualification? The answers to these questions help you to decide if your real-time results are accurate enough.

Improve Accuracy by Adjusting Solver Settings

If your fixed-step, fixed-cost simulation results do not match your reference results, try to improve accuracy by adjusting solver configurations. Increasing the number of iterations or decreasing the step size can improve accuracy.

For an implicit global solver (ode14x, ode1be), increase the number of Newton’s iterations. For a Backward Euler or Trapezoidal Rule local solver, increase the number of nonlinear iterations.

For the global solver, and for any local solvers, decrease the step size. Configure the step size for each local solver as an integer multiple of the step size you specify for the global solver.

Return to the Real-Time Model Preparation Workflow

If changing solver configurations does not improve or speed enough, try to make your model real-time capable by returning to the real-time model preparation workflow.

Adjust the fidelity or scope of your model, and then step through the other processes and decisions in the real-time model preparation workflow. Iterate on adjusting, simulating, and analyzing your model until it is fast and accurate enough for you to attempt the real-time simulation workflow again. For information, see Model Preparation Process.

Evaluate Overrun Risk

In terms of speed, the only method for definitively determining that your model is real-time capable is to test for overruns during simulation on your target hardware. You can, however, use fixed-step, fixed-cost simulation to estimate the likelihood that your solver executes quickly enough for real-time simulation. For information on estimating simulation time, see Estimate Computation Costs.

Improve Simulation Speed by Adjusting Solver Settings

If your computational cost estimate indicates that your model executes too slowly to avoid an overrun on a real-time target machine, try to increase simulation speed by adjusting solver configurations. Decreasing the number of iterations or increasing the step size can improve accuracy.

For an implicit global solver (ode14x, ode1be), decrease the number of Newton’s iterations. For either a Backward Euler or Trapezoidal Rule local solver, decrease the number of nonlinear iterations.

For the global solver, and for any local solvers, increase the step size. Configure the step size for each local solver as an integer multiple of the step size you specify for the global solver.

Model Is Real-Time Viable

When fixed-step, fixed-cost simulation results indicate that your model is likely real-time capable, you can attempt real-time simulation on the target hardware. For information on how you can use real-time simulation to test your controller hardware, see Basics of Hardware-in-the-Loop Simulation.

Return to the Real-Time Simulation Workflow

The connector is an entry point for returning to the real-time simulation workflow from another workflow (for example, the hardware-in-the-loop simulation workflow).

Insufficient Computational Capability for Real-Time Viability

It is possible that your real-time target machine lacks the computational capability for running your model in real time. If, after multiple iterations of the workflow, there is no combination of model complexity and solver settings that makes your model real-time viable, consider simulating parts of the system in parallel to increase processing power. To learn more, see Simulating Parts of the System in Parallel.

Related Examples

More About