The issue you encounter may be related to the solver type or tolerance settings. In particular, check the "Consistency Tolerance" in the Solver Configuration block, as well as the "Relative tolerance" and "Absolute tolerance" in the Simulink Solver settings.
If the solver tolerance is too loose (i.e., the tolerance value is too large), the simulation may overlook small discrepancies, allowing the system to extend beyond physical limits. This can result in larger cumulative errors and ultimately cause a constraint violation.
On the other hand, if the solver tolerance is too tight (i.e., the tolerance value is too small), the solver may need to take extremely small time steps to maintain accuracy. This can also lead to a constraint violation due to the solver being unable to progress effectively.
To troubleshoot the issue, follow these steps:
Use the Solver Profiler to determine what the solver is doing just before the error occurs during simulation
- In the Step Size tab, investigate the graph showing the simulation step size with respect to overall simulation time.
- When running the Solver Profiler, there may be large downward spikes in the step size, especially at the moment the "singularity" (time of error message) is reached. The downward spike in step size shows the solver attempting to keep the simulation accuracy within the specified tolerance.
- Zoom in on the spike for more information, such as indication that there is a zero crossing.
- For more information on the Solver Profiler, refer to the documentation page Examine Solver Behavior Using Solver Profiler.
Adjust the solver tolerances
- For example, decrease the "Relative tolerance" parameter from 1e-3 to 1e-4.
- Alternatively, increase the "Relative tolerance" parameter from 1e-4 to 1e-3 while keeping in mind the overall target simulation accuracy.
- For more information on solver parameters refer to the documentation page Solver Pane.
Switch your solver
- For example, changing the solver from 'Variable Step Auto', to 'ode23t'.
- Refer to the documentation page Choose a Solver for more information.
I hope this helps