{"id":18898,"date":"2026-10-21T13:01:16","date_gmt":"2026-10-21T17:01:16","guid":{"rendered":"https:\/\/blogs.mathworks.com\/simulink\/?p=18898"},"modified":"2026-10-21T13:01:16","modified_gmt":"2026-10-21T17:01:16","slug":"best-practices-for-large-simscape-models","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2026\/10\/21\/best-practices-for-large-simscape-models\/","title":{"rendered":"Best Practices for Large Simscape Models"},"content":{"rendered":"<div class = rtcContent><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><a href = \"https:\/\/matlab.mathworks.com\/open\/github\/v1?repo=simulink\/blog&amp;project=SimscapeBestPractices\/SimscapeBestPractices.prj\"><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_1.png\" width = \"136\" height = \"21\" alt = \"\" style = \"vertical-align: baseline; width: 136px; height: 21px;\"><\/img><\/a><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">I have been supporting users of Simulink and Simscape for many years. During this time, I built up in my head a list of best practices that I systematically go through when I receive new Simscape models from colleagues and customers.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">In this post, I will share that checklist, with examples.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Before getting started, a few disclaimers:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">It's not a must to follow all those practices 100% of the time. Many small and medium scale Simscape networks can simulate successfully and efficiently even if you do not follow my recommended best practices. Based on my experience, following those best practices is especially important for large Simscape simulations where, at scale, any small issue gets amplified.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">Most of my experience with Simscape is with the mechanical and isothermal liquid domains, so what I am describing has been learned with those domains.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">Many of those best practices are targeted at Simulink variable step solvers, to avoid unnecessarily small time steps that can slow the simulation unnecessarily.<\/span><\/li><\/ul><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Let's get started.<\/span><\/div><h2  style = 'margin: 10px 10px 5px 26px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span class=\"_richTextNode\" style=' font-weight: bold;'>Initialization<\/span><\/h2><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">When configured properly, Simscape networks usually initialize quickly. When variables do not converge on the first attempt, the Simscape initialization falls back to more advanced modes that require more computation and can take time. When that happens, you will see this warning:<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\" style=' font-family: monospace;'>Warning: First solve for initial conditions failed to converge. Trying again with all high priorities relaxed to low.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">You really want to avoid this warning.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">The tool I like to use to investigate this issue is the <\/span><a href = \"https:\/\/www.mathworks.com\/help\/simscape\/ug\/variable-viewer.html\"><span class=\"_richTextNode\">Simscape Variable Viewer<\/span><\/a><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_2.png\" width = \"621\" height = \"303\" alt = \"\" style = \"vertical-align: baseline; width: 621px; height: 303px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">What I recommend is to enable the <\/span><span class=\"_richTextNode\" style=' font-weight: bold;'>Advanced<\/span><span class=\"_richTextNode\"> configuration so you can see the column titled <\/span><span class=\"_richTextNode\" style=' font-weight: bold;'>Differential<\/span><span class=\"_richTextNode\">.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_3.png\" width = \"971\" height = \"434\" alt = \"\" style = \"vertical-align: baseline; width: 971px; height: 434px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Differential variables are the actual degrees of freedom in the system, the variables that will be integrated by the Simulink solver. Because of that, the general advice I typically give is:<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\" style=' font-style: italic;'>Set the priority of<\/span><span class=\"_richTextNode\"> <\/span><span class=\"_richTextNode\" style=' font-weight: bold; font-style: italic;'>all<\/span><span class=\"_richTextNode\"> <\/span><span class=\"_richTextNode\" style=' font-style: italic;'>differential variables and<\/span><span class=\"_richTextNode\"> <\/span><span class=\"_richTextNode\" style=' font-weight: bold; font-style: italic;'>only<\/span><span class=\"_richTextNode\"> <\/span><span class=\"_richTextNode\" style=' font-style: italic;'>the differential variables to<\/span><span class=\"_richTextNode\"> <\/span><span class=\"_richTextNode\" style=' font-weight: bold; font-style: italic;'>High<\/span><span class=\"_richTextNode\">, set all other priorities to <\/span><span class=\"_richTextNode\" style=' font-weight: bold; font-style: italic;'>none<\/span><span class=\"_richTextNode\">. Never use Low priority.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">This comes with three exceptions:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">Simscape Multibody: Low priority should be used only with Simscape Multibody joints. For example, a low priority can be used to guide a closed loop mechanism that has two valid configurations of type \"elbow-up vs elbow-down\", like this <\/span><a href = \"https:\/\/www.mathworks.com\/help\/sm\/ug\/assembling-parts-into-a-four-bar-mechanism.html\"><span class=\"_richTextNode\">four bar mechanism<\/span><\/a><span class=\"_richTextNode\">.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">Some shipping Simscape components have variables that will end up being differential for which the user does not have control. Those typically have a priority of None and are fine like that, no worries.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">When you can manually swap a differential variable for an equivalent algebraic variable.<\/span><\/li><\/ul><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Let's look at an example.<\/span><\/div><h3  style = 'margin: 10px 10px 5px 26px; padding: 0px; line-height: 20.4px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 17px; font-weight: 700; text-align: left; '><span class=\"_richTextNode\">Conflicting Initial Conditions<\/span><\/h3><div style=\"background-color: #F5F5F5; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 0px none rgb(33, 33, 33); border-right: 0px none rgb(33, 33, 33); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 21px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; text-indent: 0px; '><span style=\"white-space: pre\"><span >mdl = <\/span><span style=\"color: rgb(167, 9, 245);\">'GasChargedAccumulatorTestRig'<\/span><span >;<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 0px none rgb(33, 33, 33); border-right: 0px none rgb(33, 33, 33); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 21px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; text-indent: 0px; '><span style=\"white-space: pre\"><span >open_system(mdl);<\/span><\/span><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_4.png\" width = \"397\" height = \"149\" alt = \"\" style = \"vertical-align: baseline; width: 397px; height: 149px;\"><\/img><\/div><div style=\"background-color: #F5F5F5; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 0px none rgb(33, 33, 33); border-right: 0px none rgb(33, 33, 33); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 21px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; text-indent: 0px; '><span style=\"white-space: pre\"><span >out = sim(mdl);<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(217, 217, 217) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsWarningElement\" uid=\"011334A1\" prevent-scroll=\"true\" data-testid=\"output_0\" style=\"width: 1178px; white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\" tabindex=\"-1\"><div class=\"diagnosticMessage-wrapper diagnosticMessage-warningType eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1141\" data-previous-scroll-height=\"19\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"warning output \" style=\"max-height: 261px; white-space: normal; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\"><div class=\"diagnosticMessage-messagePart\" style=\"white-space: pre-wrap; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\">Warning: First solve for initial conditions failed to converge. Trying again with all high priorities relaxed to low.<\/div><div class=\"diagnosticMessage-stackPart\" style=\"white-space: pre; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\"><\/div><\/div><\/div><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsWarningElement\" uid=\"CBAD524F\" prevent-scroll=\"true\" data-testid=\"output_1\" style=\"width: 1178px; white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\" tabindex=\"-1\"><div class=\"diagnosticMessage-wrapper diagnosticMessage-warningType eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1141\" data-previous-scroll-height=\"93\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"warning output \" style=\"max-height: 261px; white-space: normal; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\"><div class=\"diagnosticMessage-messagePart\" style=\"white-space: pre-wrap; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\">Warning: Unable to satisfy all initial conditions. The variables involved are listed below.<br style=\"white-space: pre-wrap; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\"><br style=\"white-space: pre-wrap; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\">The following variables' targets could not be honored:<br style=\"white-space: pre-wrap; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\"><br style=\"white-space: pre-wrap; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\">'Gas_Charged_Accumulator.p_I' (Pressure of liquid volume)<br style=\"white-space: pre-wrap; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\">'Gas_Charged_Accumulator.liquid_volume' (Volume of liquid)<br style=\"white-space: pre-wrap; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\"><\/div><div class=\"diagnosticMessage-stackPart\" style=\"white-space: pre; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\"><\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">In this case, the <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2025b\/hydro\/ref\/gaschargedaccumulatoril.html\"><span class=\"_richTextNode\">Gas Charged Accumulator<\/span><\/a><span class=\"_richTextNode\"> specifies both an initial pressure and initial volume. Those two variables are not independent and only one should be specified with High Priority.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_5.png\" width = \"553\" height = \"260\" alt = \"\" style = \"vertical-align: baseline; width: 553px; height: 260px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">The Simscape Variable Viewer shows that the Pressure is the differential variable, so I would set the Volume of Liquid priority to None to make the warning go away.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_6.png\" width = \"957\" height = \"242\" alt = \"\" style = \"vertical-align: baseline; width: 957px; height: 242px;\"><\/img><\/div><h2  style = 'margin: 10px 10px 5px 26px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span class=\"_richTextNode\">Algebraic Loops<\/span><\/h2><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">The <\/span><a href = \"https:\/\/www.mathworks.com\/help\/simscape\/ug\/limitations.html#bqqjdvg-4\"><span class=\"_richTextNode\">Simscape documentation<\/span><\/a><span class=\"_richTextNode\"> states it clearly: <\/span><span class=\"_richTextNode\" style=' font-weight: bold; font-style: italic;'>A Simscape physical network should not exist within a Simulink algebraic loop<\/span><span class=\"_richTextNode\">*.*<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">However this is not enforced, because it can work in some cases. Based on my experience, even if it works for your model today, fix it, this will likely cause you trouble as your model grows.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">To avoid algebraic loops, I can recommend two approaches:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">If the algorithm is relatively simple, instead of going out to Simulink and back into Simscape, stay in Simscape and use the blocks from the Physical Signals section of the library. For example, see these posts where I described how to create custom valves for Simscape (<\/span><a href = \"https:\/\/blogs.mathworks.com\/simulink\/2015\/05\/26\/creating-custom-valve-in-simscape\"><span class=\"_richTextNode\">Custom hydraulic valve<\/span><\/a><span class=\"_richTextNode\">, <\/span><a href = \"https:\/\/blogs.mathworks.com\/simulink\/2017\/08\/17\/creating-your-own-check-valve-for-the-simscape-gas-domain\"><span class=\"_richTextNode\">Custom Gas valve<\/span><\/a><span class=\"_richTextNode\">)<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">If the algorithm is too complex to be implemented using the Simscape Physical Signals blocks, use a <\/span><a href = \"https:\/\/www.mathworks.com\/help\/simulink\/slref\/transferfcn.html\"><span class=\"_richTextNode\">Transfer Function<\/span><\/a><span class=\"_richTextNode\"> to break the algebraic loop. See this post for more details:  <\/span><a href = \"https:\/\/blogs.mathworks.com\/simulink\/2015\/07\/18\/why-you-should-never-break-an-algebraic-loop-with-with-a-memory-block\/\"><span class=\"_richTextNode\">Why you should never break a continuous algebraic loop with a Memory block<\/span><\/a><\/li><\/ul><h2  style = 'margin: 10px 10px 5px 26px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span class=\"_richTextNode\">DAE Failures<\/span><\/h2><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">DAE stands for <\/span><a href = \"https:\/\/www.mathworks.com\/help\/simscape\/ug\/how-simscape-models-represent-physical-systems.html#bsjpdmk\"><span class=\"_richTextNode\">Differential Algebraic Equations<\/span><\/a><span class=\"_richTextNode\"> and is key to how Simscape solve equations.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">You really want to avoid this warning:<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\" style=' font-family: monospace;'>Warning:Solver is encountering difficulty in simulating model 'modelname' at time 1.0000000000000036. Simulink will continue to simulate with warnings. Please check the model for errors.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\" style=' font-family: monospace;'>Caused by:<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\"> <\/span><span class=\"_richTextNode\" style=' font-family: monospace;'>Solver was unable to reduce the step size without violating the minimum step size value of 3.55271E-15 for 1 consecutive times at time 1. This usually may be caused by violating algebraic constraints in the differential-algebraic system or by the high stiffness of the system. Try tightening the error tolerances, and\/or the tolerances for computing consistent conditions. If the problem persists, please check the system or increase the solver Number of consecutive min steps violation parameter.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\"> <\/span><span class=\"_richTextNode\" style=' font-family: monospace;'>Suggested Actions:<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\"> <\/span><span class=\"_richTextNode\" style=' font-family: monospace;'>Open Solver Profiler to explore such issues<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">I wrote about this topic a long time ago here: <\/span><a href = \"https:\/\/blogs.mathworks.com\/simulink\/2015\/07\/06\/identifying-the-root-cause-of-an-algebraic-constraint-violation\/\"><span class=\"_richTextNode\">Identifying the root cause of an algebraic constraint violation<\/span><\/a><span class=\"_richTextNode\" style=' text-decoration: underline;'>.<\/span><span class=\"_richTextNode\"> While the core issue is the same, the tools to investigate those have improved a lot.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">If you have only one or two instances of this warning and the simulation completes successfully, you can probably ignore it, but it's a sign of bad numerical robustness. Typically, this kind of warning is related to the fact that the system is modeled too ideally.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">To illustrate this situation, I made this simple model using the Isothermal Liquid domain. On the right of the diagram, I used two <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2025b\/simscape\/ref\/capil.html\"><span class=\"_richTextNode\">Cap (IL)<\/span><\/a><span class=\"_richTextNode\"> blocks. This block is an ideal component that allows zero flow.<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 0px none rgb(33, 33, 33); border-right: 0px none rgb(33, 33, 33); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 21px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; text-indent: 0px; '><span style=\"white-space: pre\"><span >mdl = <\/span><span style=\"color: rgb(167, 9, 245);\">'dae_example'<\/span><span >;<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 0px none rgb(33, 33, 33); border-right: 0px none rgb(33, 33, 33); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 21px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; text-indent: 0px; '><span style=\"white-space: pre\"><span >open_system(mdl);<\/span><\/span><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_7.png\" width = \"504\" height = \"244\" alt = \"\" style = \"vertical-align: baseline; width: 504px; height: 244px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">If I try simulating this model, it will hang with an infinite number of the above warnings, so I will run it with the <\/span><span class=\"_richTextNode\" style=' font-family: monospace;'>TimeOut<\/span><span class=\"_richTextNode\"> option.<\/span><\/div><div class = 'preformatted-matlab' style = 'margin: 10px 3px 10px 55px; padding: 10px 10px 10px 5px; '><div  style = 'border-left: 0px none rgb(33, 33, 33); border-right: 0px none rgb(33, 33, 33); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px; line-height: 15.6px; min-height: 16px; white-space: pre; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 12px; text-indent: 0px; '><span style=\"white-space: pre\"><span >out = sim(mdl,<\/span><span style=\"color: rgb(167, 9, 245);\">'TimeOut'<\/span><span >,2);<\/span><\/span><\/div><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_8.png\" width = \"879\" height = \"306\" alt = \"\" style = \"vertical-align: baseline; width: 879px; height: 306px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">As mentioned in the Suggested Action, let's run the model through the Solver Profiler.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_9.png\" width = \"467\" height = \"332\" alt = \"\" style = \"vertical-align: baseline; width: 467px; height: 332px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">In the configure section, I always enable logging for these three options:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">Continuous States<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">Simscape States<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">Zero Crossing<\/span><\/li><\/ul><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_10.png\" width = \"541\" height = \"196\" alt = \"\" style = \"vertical-align: baseline; width: 541px; height: 196px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">I click run, wait for a few seconds that many instances of the diagnostic are triggered, and stop it. What we can see here is that the solver step size \"stalls\", taking very small step of only 1e-15sec. <\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_11.png\" width = \"867\" height = \"536\" alt = \"\" style = \"vertical-align: baseline; width: 867px; height: 536px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">In the Solver Profiler Solver Exceptions table, we try sorting the states such that the most likely culprits are at the top of the list. Any non-zero value in the DAE column should be addressed.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">In the Solver Profiler, try opening the State Explorer and\/or the Simscape Results Explorer. <\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_12.png\" width = \"284\" height = \"94\" alt = \"\" style = \"vertical-align: baseline; width: 284px; height: 94px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">These two tools present similar results in different ways:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\" style=' font-weight: bold;'>State Explorer:<\/span><span class=\"_richTextNode\"> Visualize the states integrated by the Simulink solver. States are listed in a table and sorted based on different criteria. I like to start here, sort the states by Newton\/DAE Exception and look for anything unexpected or nonphysical, like sudden jumps. This helps me identify which blocks in the model are the most likely culprits.<\/span><\/li><\/ul><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_13.png\" width = \"795\" height = \"405\" alt = \"\" style = \"vertical-align: baseline; width: 795px; height: 405px;\"><\/img><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\" style=' font-weight: bold;'>Simscape Results Explorer:<\/span><span class=\"_richTextNode\"> Displays all Simscape variables (a subset of these become states and are shown in the State Explorer). This allows me to \"zoom in\" the culprit area identified in the previous step and see all variables and get a better understanding of the problem.<\/span><\/li><\/ul><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_14.png\" width = \"593\" height = \"396\" alt = \"\" style = \"vertical-align: baseline; width: 593px; height: 396px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">For the example we are looking into today, the first block listed in the solver profiler is the pressure at port B of the upper Check Valve. The problem is that this node is \"dry\", or too ideal. The Check Valve is trying to open, but the fluid has nowhere to go. In the real system, there is most likely a volume of fluid between the check valve and the 4-way valve.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">To avoid the problem, the simplest trick is usually to insert a <\/span><a href = \"https:\/\/www.mathworks.com\/help\/simscape\/ref\/constantvolumechamberil.html\"><span class=\"_richTextNode\">Constant Volume Chamber<\/span><\/a><span class=\"_richTextNode\"> on the node to allow the fluid to go somewhere.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_15.png\" width = \"507\" height = \"280\" alt = \"\" style = \"vertical-align: baseline; width: 507px; height: 280px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">In terms of equations, this happens when many variables are linked together by complex algebraic constraints. Adding a volume of fluid on that node breaks the algebraic constraint and the variables involved become independent degrees of freedom.<\/span><\/div><h2  style = 'margin: 10px 10px 5px 26px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span class=\"_richTextNode\">Solver Resets<\/span><\/h2><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">I covered this concept in this post: <\/span><a href = \"https:\/\/blogs.mathworks.com\/simulink\/2020\/01\/17\/a-new-first-order-hold\/\"><span class=\"_richTextNode\">A New First Order Hold! \u00bb Guy on Simulink - MATLAB &amp; Simulink<\/span><\/a><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">When a block with continuous states (Integrator, State-Space, a Simscape network, etc) is driven by a signal with a discrete sample time, the Simulink solver needs to reset. When the model contains Simscape blocks and uses an implicit solver (ode15s, ode23t, daessc), a solver reset systematically triggers a recomputation of the solver Jacobian. This is an expensive operation that scales exponentially with the size of the model, so you want to avoid that as much as possible.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Here are my tips to avoid that:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">When looping out to Simulink and back into Simscape, avoid introducing Fixed-In-Minor sample times. See this post for more details: <\/span><a href = \"https:\/\/blogs.mathworks.com\/simulink\/2015\/07\/18\/why-you-should-never-break-an-algebraic-loop-with-with-a-memory-block\/\"><span class=\"_richTextNode\">Why you should never break a continuous algebraic loop with a Memory block<\/span><\/a><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">When the Simscape network is connected in a loop with a fixed-step discrete controller, insert First Order Hold blocks on the discrete signal. See this <\/span><a href = \"https:\/\/blogs.mathworks.com\/simulink\/2020\/01\/17\/a-new-first-order-hold\/\"><span class=\"_richTextNode\">blog post<\/span><\/a><span class=\"_richTextNode\"> for more details on how to use this block properly.<\/span><\/li><\/ul><h2  style = 'margin: 10px 10px 5px 26px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span class=\"_richTextNode\">Zero-Crossing Events<\/span><\/h2><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">The other type of events that forces the Simulink solver to recompute its Jacobian is zero-crossing. If you are not familiar with the concept of zero-crossing detection, I recommend starting with the Simulink documentation: <\/span><a href = \"https:\/\/www.mathworks.com\/help\/simulink\/ug\/zero-crossing-detection.html\"><span class=\"_richTextNode\">Zero-Crossing Detection - MATLAB &amp; Simulink<\/span><\/a><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Once you are familiar with zero-crossing detection in Simulink, see this Simscape-specifics guidance:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2025b\/simscape\/ug\/how-simscape-models-represent-physical-systems.html#bviqsqd-1\"><span class=\"_richTextNode\">Managing Zero Crossings in Simscape Models<\/span><\/a><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2025b\/simscape\/ug\/reduce-zero-crossings.html\"><span class=\"_richTextNode\">Reduce Zero Crossings<\/span><\/a><\/li><\/ul><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Here is my take on that.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">With Simulink variable-step solvers, zero-crossing detection is necessary to accurately capture discontinuities. However, you don't want to capture more than needed.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">The first thing to do to determine if zero-crossing is a problem for a simulation is to run it through the Solver Profiler. Look at the zero-crossing tab and use your knowledge of the model to determine if the blocks listed and the number of events seem appropriate. If you see more events than you expect, open the <\/span><a href = \"https:\/\/www.mathworks.com\/help\/simulink\/slref\/zerocrossingexplorer.html\"><span class=\"_richTextNode\">Zero-Crossing Explorer<\/span><\/a><span class=\"_richTextNode\">, and look for the following patterns:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">If a variable is chattering around one event, try adding damping to damp out the oscillations faster, or see if you could steer the system to operate slightly on one side or the other of the zero-crossing threshold<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">If a variable crosses its zero level often, but seems continuous and this is a component for which you have control over the Simscape language source code, try disabling zero-crossing. <\/span><\/li><\/ul><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">In a similar way as I do with the State Explorer and the Simscape Results Explorer, when investigating zero-crossing events I alternate between the Zero-Crossing Explorer and the Simscape Results Explorer.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Let's illustrate that with a classic: The bouncing ball, which I implemented using a <\/span><a href = \"https:\/\/www.mathworks.com\/help\/simscape\/ref\/translationalhardstop.html\"><span class=\"_richTextNode\">Translational Hard Stop<\/span><\/a><span class=\"_richTextNode\">:<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_16.png\" width = \"350\" height = \"171\" alt = \"\" style = \"vertical-align: baseline; width: 350px; height: 171px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">The Solver Profiler tells me that the zero-crossing events are coming from the Hard Stop block, but not exactly which equation within the Hard Stop block.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_17.png\" width = \"523\" height = \"516\" alt = \"\" style = \"vertical-align: baseline; width: 523px; height: 516px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">If you open the Simscape Results Explorer, you can see that the Hard Stop block has two zero-crossing equations registered. If you select \"zc_2\", the Node Statistics panel contains a hyperlink to the location.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_18.png\" width = \"777\" height = \"662\" alt = \"\" style = \"vertical-align: baseline; width: 777px; height: 662px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Clicking the location hyperlink opens the source code for the block and puts the cursor on the line generating the zero-crossing event.<\/span><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_19.png\" width = \"587\" height = \"187\" alt = \"\" style = \"vertical-align: baseline; width: 587px; height: 187px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Knowing exactly which equation triggers the zero-crossing events should help you determine if it is really needed for your application and make appropriate engineering decisions.<\/span><\/div><h2  style = 'margin: 10px 10px 5px 26px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span class=\"_richTextNode\">Now it's your turn<\/span><\/h2><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">In this post, I listed a set of things to look for to keep your Simscape simulations healthy. This includes:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">Initial conditions<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">Algebraic loops<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">DAE failures and dry nodes<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">Solver Resets<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span class=\"_richTextNode\">Zero-Crossing events<\/span><\/li><\/ul><div  style = 'margin: 2px 10px 9px 26px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Let us know in the comments below if there are other items you typically look for to assess if your Simscape simulations run efficiently.<\/span><\/div>\r\n<br>\r\n<\/div><script type=\"text\/javascript\">\r\n{ let css = '._richTextNode {white-space: break-spaces;} \/* Copyright 2014-2025 The MathWorks, Inc. *\/\/* Styling that is common to warnings and errors is in diagnosticOutput.css *\/.embeddedOutputsErrorElement {    min-height: 18px;    max-height: 550px;} .embeddedOutputsErrorElement .diagnosticMessage-errorType {    overflow: auto;} .embeddedOutputsErrorElement.inlineElement {} .embeddedOutputsErrorElement.rightPaneElement {} \/* Copyright 2014-2025 The MathWorks, Inc. *\/\/* Styling that is common to warnings and errors is in diagnosticOutput.css *\/.embeddedOutputsWarningElement {    min-height: 18px;    max-height: 550px;} .embeddedOutputsWarningElement .diagnosticMessage-warningType {    overflow: auto;} .embeddedOutputsWarningElement.inlineElement {} .embeddedOutputsWarningElement.rightPaneElement {} \/* Copyright 2015-2025 The MathWorks, Inc. *\/\/* In this file, styles are not scoped to rtcContainer since they could be in the Dojo Tooltip *\/.diagnosticMessage-wrapper {    \/* Since this selector may be used outside RTC Container without RTC semantic variables, a    default value is used. An example here is the App Designers alert tooltip. *\/    font-family: var(--rtc-output-font-family, Menlo, Monaco, Consolas, \"Courier New\", monospace);    font-size: var(--rtc-output-font-size, 12px);} .diagnosticMessage-wrapper.diagnosticMessage-warningType {    \/*This fallback value will be used for appdesigner warnings*\/    color: var(--rtc-warning-output-color, var(--mw-color-matlabWarning));} .diagnosticMessage-wrapper.diagnosticMessage-warningType a {    \/*This fallback value will be used for appdesigner warnings*\/    color: var(--rtc-warning-output-color, var(--mw-color-matlabWarning));    text-decoration: underline;} .rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-warningType,.rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-warningType a {    color: var(--mw-color-matlabWarning) !important;} .diagnosticMessage-wrapper.diagnosticMessage-errorType {    \/*This fallback value will be used in appdesigner error tooltip text*\/    color: var(--rtc-error-output-color, var(--mw-color-matlabErrors));} .diagnosticMessage-wrapper.diagnosticMessage-errorType a {    \/*This fallback value will be used in appdesigner error tooltip text*\/    color: var(--rtc-error-output-color, var(--mw-color-matlabErrors));    text-decoration: underline;} .rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-errorType,.rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-errorType a {    color: var(--mw-color-matlabErrors) !important;} .diagnosticMessage-wrapper .diagnosticMessage-messagePart,.diagnosticMessage-wrapper .diagnosticMessage-causePart {    white-space: pre-wrap;} .diagnosticMessage-wrapper .diagnosticMessage-stackPart {    white-space: pre;} \/* Copyright 2014-2025 The MathWorks, Inc. *\/.embeddedOutputsTextElement,.embeddedOutputsVariableStringElement {    white-space: pre;    word-wrap:  initial;    min-height: 18px;    max-height: 550px;} .embeddedOutputsTextElement .textElement,.embeddedOutputsVariableStringElement .textElement {    overflow: auto;} .textElement,.rtcDataTipElement .textElement {    padding-top: 2px;} .embeddedOutputsTextElement.inlineElement,.embeddedOutputsVariableStringElement.inlineElement {} .inlineElement .textElement {} .embeddedOutputsTextElement.rightPaneElement,.embeddedOutputsVariableStringElement.rightPaneElement {    min-height: 16px;} .rightPaneElement .textElement {    padding-top: 2px;    padding-left: 9px;} .embeddedOutputsVariableStringElement { width: initial !important; }';\r\nlet head = document.head || document.getElementsByTagName('head')[0];\r\nlet style = document.createElement('style');\r\nhead.appendChild(style);\r\nstyle.type = 'text\/css';\r\nif (style.styleSheet) {\r\n    style.styleSheet.cssText = css;\r\n} else {\r\n    style.appendChild(document.createTextNode(css));\r\n}\r\n\r\n\r\n}<\/script>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/simulink\/files\/SimscapeBestPractices.m-10-21-26_15.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>I have been supporting users of Simulink and Simscape for many years. During this time, I built up in my head a list of best practices that I systematically go through when I receive new Simscape... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2026\/10\/21\/best-practices-for-large-simscape-models\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":18885,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43,39,33],"tags":[105],"class_list":["post-18898","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debugging","category-physical-modeling","category-simulink-tips","tag-simscape"],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/18898","targetHints":{"allow":["GET"]}}],"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=18898"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/18898\/revisions"}],"predecessor-version":[{"id":18902,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/18898\/revisions\/18902"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media\/18885"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=18898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=18898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=18898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}