How to speed up the simulation?

I developed a model using SimEvents. It contains several constant blocks and Embedded Matlab functions that collect parameter values from Matlab workspace. Parameters vary with time.
During the simulation, some calculations based on the output has to be done and depending on results, it chooses rather to continue or stop the simulation.
I managed it using Assertion block to pause the simulation. After that, parameters values are being changed from Matlab and updated using:
set_param(bdroot,'SimulationCommand','update')
And continued using:
set_param(bdroot,'SimulationCommand','continue')
The model works just fine in this way. But the problem is because it is such a big time consumer. Since it represents a part of an optimization algorithm it has to be run numerous number of times, so running time is unacceptable. I understand that updating parameters takes the most of the time, but that was the only way i knew.
Is there some other way how to manage this thing working? How could I speed up running time of the simulation?
It should be noted that pausing times are defined before running the simulation. Constant blocks are scalars and values for Embedded Matlab functions are matrices (constant size).
The second issue is can I run the model without having it opened? I assume, in that case i should use something different than bdroot. Any ideas?
I would highly appreciate any suggestions.

 采纳的回答

Kaustubha Govind
Kaustubha Govind 2011-7-25

0 个投票

Regarding the second question, you only need to load your model using load_system - this will load it into memory, but not open it.

更多回答(2 个)

Fangjun Jiang
Fangjun Jiang 2011-7-24

1 个投票

Can you also implement the matrices through Constant block? While a simulation is running, you can double click the Constant block, the simulation will pause, you can then change the value of the constant block. Once you click Okay, the simulation will resume using the new value. Of course, you can do this through setting the 'SimulationCommand' like you did. All I am trying to say is that you may not need to run set_param(bdroot,'SimulationCommand','update') which will save you time.
Refer to this link

6 个评论

Thank you for your reply. Yes, I understand and believe it should work, but the point is that it has to be done automatically, not by manual opening the every single Constant block.
I don't mean to manually change it. After your Assertion block pauses the simulation, you can use set_param() to change the Constant value or many other block parameters. What I am trying to say, you MAY NOT need to run set_param(bdroot,'SimulationCommand','update'). You can run set_param(bdroot,'SimulationCommand','continue') right away. Try a simple example to see if it works out.
Thank you for the answer. It works fine. But, i have other problem. I thought that I coded the main thing from the question right, but i found out that i made a mistake. Model has been run within FOR loop. Code is organised as follows :
for i = 1: number_of_pause_times
calculation of the parameters
if i == 1
set_param(bdroot,'SimulationCommand','start')
else
set_param(bdroot,'SimulationCommand','continue')
end
end
The problem is cause the FOR loop, doesn't "recognize" that model is still running. So the parameters are being updated before the simulation even started. Do you have any idea how to pause the FOR loop until the model pauses, and after that to continue it?
Thank you a lot for your time, Nikola.
Thank you both for your time. I thought that I could accept both answers. Sorry if that something matters. I'll know for the next time. Nikola.
You can use get_param('sys', 'SimulationStatus') to query the status of your simulation. See http://www.mathworks.com/help/toolbox/simulink/ug/f11-61851.html for more information. You could use a while loop to wait until the status becomes 'paused'.
I tried that and it didn't work. I added an infinite while loop for checking the simulation status, but the simulation couldn't even start and Matlab became unresponsive.

请先登录,再进行评论。

Kushagra
Kushagra 2013-9-16

0 个投票

For speeding up simulation, you can use accelerator and rapid accelerator mode. For details, refer to below webinar: https://www.mathworks.in/company/events/webinars/webinarconf.html?id=54186&language=en&confirmation_page&wfsid=4859788

类别

帮助中心File Exchange 中查找有关 Messages 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by