Using accelerator modes and fast restart for faster model execution | Simscape Electrical Modeling Practices for Fast Simulation - MATLAB & Simulink
Video Player is loading.
Current Time 0:00
Duration 7:24
Loaded: 0%
Stream Type LIVE
Remaining Time 7:24
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 7:24

    Using accelerator modes and fast restart for faster model execution | Simscape Electrical Modeling Practices for Fast Simulation

    From the series: Simscape Electrical Modeling Practices for Fast Simulation

    This video shows the impact the various simulation modes have on the execution speed of electrical system models. These modes are Normal, Accelerator and Rapid Accelerator Mode.

    Published: 7 May 2024

    Hello, my name is Gernot Schraberger. I'm application engineer at The MathWorks and I want to show you today how you can use simulation modes and fast restart to accelerate the execution of the model.

    What you see here is a live script that can be used for better repeatability. But I will show things interactively because it's also possible like that.

    Well, what are simulation modes? We have got normal mode, as you might have seen here already several times in the model. There is also an accelerator mode and rapid accelerator mode. And normal mode means that the model is executed in an interpreted way without code generation. In accelerator mode or rapid accelerator mode, the model is first compiled before it's executing.

    Typically that's because it runs faster then, but you will need additional time for compilation. So if we have a closer look what happens during the simulation, at time step zero, before you execute the model, it has to be checked if any model structures have changed. That means if anything has changed, then it has to be recompiled in case of accelerator or rapid accelerator mode.

    The variables have to be initialized and then the real execution starts. And depending on the number of execution steps, you will see that the elapsed time will increase and that's depending on the different modes.

    Additionally, I can say that the second run typically takes much shorter compared to the first run and that's especially the case if you use fast restart option that you can see here.

    In case of fast restart, the intensive model checking can be skipped because you were not allowed to change the structure of the model. You're only allowed to change certain parameters. In that case, you have to use so-called runtime parameters instead of compile time parameters.

    If you use Simscape, you can see that here, for example, in the battery module, if I open the mask, you can see, for example here the cell capacity is a runtime parameter and not a compile time parameter. That's the precondition here for fast restart because typically, of course, you want to change parameters from one run to the next run.

    But then of course it's important to measure the execution time to be able to compare the different runs. Therefore, we go to Model Properties and we select the StartFcn function callback and enter the comment tick here so that the timer is started whenever the execution, not the initialization, but the execution starts.

    I use the tock comment here for the StopFcn function callback. That means it will deliver me the time that has been used for model execution.

    And then we start in normal mode without fast reset to get the reference values. How long does the model execute? What you can see here, first up, is model checking compilation and so on that takes a certain time. Now the model's initialized and it's running now and you see the progress of time.

    So now the execution has finished, we can view the model diagnostics where we'll find the elapsed time. So now, in the next step, I switch over to accelerator mode. And I also activate the fast reset option.

    Now, once again, you see the compilation of the model. Additionally, C code has to be generated then we could see initialization and running now you can see the model execution was a little bit faster 57 seconds compared to 109 seconds before and you see also that the model stopped in a mode ready fast restart.

    Before we start the model again, I want to change a parameter now and that I can do by entering the parameter here, like charging CV and by assigning a new value to that parameter. I press run once again and you see we have an immediate restart.

    So time is now 60 seconds, which is about the same time as for the run before. These are quite normal tolerances we have on a non-real time system. I've shown you now how you can use accelerator mode to accelerate the execution itself and fast restart to reduce the time at timestep zero for preparation of the model and its initialization.

    And we've seen that we still can change parameters here. But what if you have different structures in the model, different variants, for example, that you want to switch? Is that also supported with fast restart. Well, I've prepared another model here where I can show you how you have to set it up so that you can also use fast restart in that context. We've got a controller here modeled in the variant subsystem.

    And you see the two different variants here, linear control and a nonlinear controller. And this variant subsystem is a so-called start up variant subsystem. If we look to the block parameters here, you can see that the variant activation time is start up. If you use that kind of variant for a system that has got inputs and outputs, it can be pre-compiled in all the different variants and it does also support fast restart. So I think now you're prepared to try out those things with the own models.

    I've done it interactively in that video, but we can also deliver you this script here where all the single steps are explained and where all the actions are scripted for better reproducibility. So we have here the opening of the model adding tick tock for time measurement, choosing simulation mode, fast restart, and also to execution of the model here with different options. You might see here also the rapid accelerator mode. This one has the biggest benefit if you use pure Simulink models. I hope you found this video interesting and you can apply those things that I've shown to your model successfully.

    Up Next:

    View full series (15 Videos)

    View more related videos