parsim: Create SimulinkInput Object from currently open model with initial values
3 次查看(过去 30 天)
显示 更早的评论
Good morning everyone,
I am trying to parallelize a large number of Simulink simulations for a Monte Carlo study on a multicore Machine using parsim.
The Help on parsim details, that one has to create a "SimulinkInput object" for each simulation that will run in parsim.
I have my model set up for calculation, initial values and other external values loaded into the model.
What I do not understand is: How can I generate the SimulinkInput Object from my currently open Simulink model? Especially: Without looping over all Input values that are loaded in "from Workspace" blocks? (they are also initial values for my ode)
Currently I run my simulations in nested for loops over all the parameters that change during the study but I think of running the loop for all possible combinations, create the SimulinkInput object for each set of data and afterwards run everything in parallel using parsim, avoiding the nested loops. Is this even possible?
0 个评论
采纳的回答
Reid Spence
2021-6-23
Hi Sebastian,
If I understand correctly you have a lot of variables and inputs in the base workspace, some of these variables change from run to run while others remain constant. Currently you have nested for loops to iterate over all possible combinations and Im guessing you are calling sim() in the deepest nested for loop?
Based on that understanding, I think the best way to transition your code to use parsim is to keep your nested for loops but instead of calling sim() instead use setVariable() on the SimulationInput object for only the variables that are changing from run to run. For all variables in the base workspace that are the same from run-to-run, you can leave those in the base workspace (no need to attach them directly to the SimuationInput object) and then transfer the base workspace to the workers with the "TransferBaseWorkspaceVariables" option on parsim.
Hope that helps
2 个评论
Reid Spence
2021-6-24
Exactly, yes use setVariable for the values you want to vary between runs. The Simulink.SimulationInput object does not affect the model file. The point of the input object is to store run specific information in a contained "box" so that you do not have to dirty the model or the workspace to sweep through the iterations. So by that philosophy, no changes to the mode should be required and you can still run a single simulation with sim() afterwards.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Run Multiple Simulations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!