{"id":1249,"date":"2012-08-31T17:00:08","date_gmt":"2012-08-31T22:00:08","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=1249"},"modified":"2012-08-31T16:52:26","modified_gmt":"2012-08-31T21:52:26","slug":"simulink-debugger-monitoring-variable-step-solver-performance","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2012\/08\/31\/simulink-debugger-monitoring-variable-step-solver-performance\/","title":{"rendered":"Simulink Debugger: Monitoring Variable Step Solver Performance"},"content":{"rendered":"<p>A few months ago I introduced <a href=\"https:\/\/blogs.mathworks.com\/seth\/2012\/06\/04\/the-most-useful-command-for-debugging-variable-step-solver-performance\/\">my favorite command to analyze the performance of a variable-step solver<\/a>.<\/p>\r\n\r\n<p>This week, I will introduce how the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/ug\/f5-6104.html\">Simulink Debugger<\/a> can be used for a deeper analysis of variable-step solvers performance. For this, we will use the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/ug\/f5-23291.html\">debugger command-line interface<\/a>.<\/p>\r\n\r\n<p><strong>Launching the debugger<\/strong><\/p>\r\n\r\n<p>For this example, let's use the demo model <tt>vdp.mdl<\/tt>. I start the debugger using <tt>sldebug<\/tt> and enable tracing of the solver information using <tt>strace 1<\/tt>. For this example, I want to run just a small part of the simulation, so I will set a breakpoint after 5 seconds using <tt>tbreak 5<\/tt>.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/launchingTheDebugger.png\" alt=\"Launching the Simulink Debugger from command line\" \/><\/p>\r\n\r\n<p>After using the <tt>continue<\/tt> command (or the one-character shortcut <tt>c<\/tt>), a lot of information is displayed. <\/p>\r\n\r\n<p><strong>Solver Information<\/strong><\/p>\r\n\r\n<p>Let's look at a successful step where we moved from 0.284s to 0.54s.<\/p>\r\n\r\n<p><a href=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/debuggerSuccessfulStep.png\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/debuggerSuccessfulStep_small.png\" alt=\"Example successful step\" \/><\/a> <em>(click to view full size)<\/em><\/p>\r\n\r\n\r\n<p>In the above screen capture, you can identify:<\/p>\r\n\r\n<ul>\r\n\t<li><strong>TM: <\/strong>We take a major step at 0.284s<\/li>\r\n<br>\r\n\t<li><strong>Tm - Hm: <\/strong>We start a minor step at 0.284s. Based on the evolution of the states during the previous step, the solver thinks this minor step should advance by 0.256 seconds.<\/li>\r\n<br>\r\n\t<li><strong>Tm - H: <\/strong>Nothing is blocking us from trying this step, we begin the integration from 0.284s and advance by 0.256s<\/li>\r\n<br>\r\n\t<li><strong>Ts - Hs: <\/strong>The minor step was successful, we move forward by 0.256s without exceeding solver tolerance<\/li>\r\n<br>\r\n\t<li><strong>Err - Ix: <\/strong> Among all the states in the model, the one closest to the maximum tolerance was state 1 and it's normalized error was 8.2045e-2. The normalization is made relative to the maximum tolerance. An error above 1 exceeds the tolerance and below one passes.<\/li>\r\n<br>\r\n<\/ul>\r\n\r\n<p>For more details on how to interpret the solver trace information, you can look at the documentation for <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/slref\/strace.html\">strace<\/a>.<\/p>\r\n\r\n<p>To determine which state had the maximum error, use the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/slref\/states.html\">states<\/a> command:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/debuggerStates.png\" alt=\"continuous states as shown by the Simulink debugger\" \/><\/p>\r\n\r\n<p>For this step, the state closest to the maximum tolerance (<tt>Ix=1<\/tt>) is from the Integrator block <tt>x2<\/tt>.<\/p>\r\n\r\n<p><strong>Step limited by maximum step size<\/strong><\/p>\r\n\r\n<p>Now let's look at a different type of output. If we move forward to 4.651s, we notice a step where the step size is limited by the solver <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/gui\/bq7cmsp-1.html#bq9bzfv-1\">maximum step size<\/a>:<\/p>\r\n\r\n<p><a href=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/debuggerLimitedStep.png\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/debuggerLimitedStep_small.png\" alt=\"Example limited step\" \/><\/a> <em>(click to view full size)<\/em><\/p>\r\n\r\n<p>If you see many of those in your model, this probably means you could increase the maximum step size in the solver configuration.<\/p>\r\n\r\n<p><strong>Failed step<\/strong><\/p>\r\n\r\nOf course, not all steps move forward smoothly. Sometimes the solver needs to take steps back to respect tolerances. If we continue to step forward, at t=13.21s we notice that it took 2 attempts before respecting the tolerance.\r\n\r\n<p><a href=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/debuggerFailedStep.png\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q3\/debuggerFailedStep_small.png\" alt=\"Example failed step\" \/><\/a> <em>(click to view full size)<\/em><\/p>\r\n\r\n<p>If this happens often in your model, you might want to try other solvers, like stiff solvers. If this does not help, you might want to look at your equations and the block with the maximum error.<\/p>\r\n\r\n<p><strong>Conclusion<\/strong><\/p>\r\n\r\n<p>The examples I have given show how the Simulink debugger can be useful to understand why a variable-step solver takes steps of a certain size. Those examples are mainly focused on states, but you can follow the same principle for zero-crossings by using functions like <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/slref\/zcbreak.html\">zcbreak<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/slref\/zclist.html\">zclist<\/a>.<\/p>\r\n\r\n<p>I need to stop here because this post is already long enough, but I want to mention that those examples are only the tip of the iceberg. With the Simulink debugger, it is possible to see finer details of the integration done during minor steps and display data for any signal or block.<\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>Take the time to go through the list of <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/slref\/bqbsiz6.html\">Simulink debugger Commands<\/a> and let us know if you find something you will use by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=1249&#comment\">comment here<\/a><\/p>\r\n\r\n","protected":false},"excerpt":{"rendered":"<p>A few months ago I introduced my favorite command to analyze the performance of a variable-step solver.\r\n\r\nThis week, I will introduce how the Simulink Debugger can be used for a deeper analysis of... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2012\/08\/31\/simulink-debugger-monitoring-variable-step-solver-performance\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[43,76,29],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1249"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=1249"}],"version-history":[{"count":40,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1249\/revisions"}],"predecessor-version":[{"id":1297,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1249\/revisions\/1297"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=1249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=1249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=1249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}