MATLAB Answers

Rapid Accelerator Simulation

46 views (last 30 days)
I am running a simulation on bunch of differnt matfiles. My model can indvidually run in Rapid Accelerator mode but I can not figure out a way to run the whole sim in a for loop simulating each matfile....WITHOUT BUILDING RAPID ACCELETOR EACH TIME.
Here is how my code looks like
for i=1:100
filename = filelist(i)
load(filename) %This one loads, 11 (say V1 to V11) variables from the file into Matlab workspace
Process data, create time vector and initialize simulink variable
mdl = 'Mymodel.mdl'
sim(mdl,'SimulationMode', 'rapid')
end
so in this example, my code will build rapid accelerator target every single time for each loaded file (100 times). Which consumes lots of time.
I tried using,
if (i == 1)
load_system(mdl);
rtp = Simulink.BlockDiagram.buildRapidAcceleratorTarget(mdl);
sim(mdl,'SimulationMode', 'rapid');
else
sim(mdl,'SimulationMode', 'rapid','RapidAcceleratorUpToDateCheck','off');
end
Here it builds rapid accelerator target only for the first time, but for all subsequent runs, it uses the exact model that it built from (first loaded model + workspace) and my workspace variables dont get assigned to model every time Basically all my 100 runs produce same results.
My question is.... Is there any way to assign new variables from workspace to already built simulation target model and run the sim in for loop?
paramName = {'V1', 'V2', 'V3',...'V11'}
paramValue = {Cspeed, CTemp, Cflow,...,Cvar };
sim(mdl, paramName, paramValue,'SimulationMode', 'rapid','RapidAcceleratorUpToDateCheck','off')
(In my sim model, there is one input block where I assign all the 11 loaded workspace variable to 11 simulink blocks)

  0 Comments

Sign in to comment.

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 9 Apr 2012
You can only change tunable parameters after the rapid accelerator target has been built. You can figure out if a parameter is tunable or non-tunable by looking at the parameter attributes list that can be obtained using get_param(gcb, 'DialogParameters'). This command returns a structure with the block parameter names as fields. Each field further is a structure that has an "Attributes" field. The list of attributes will contain 'read-only-if-compiled' for non-tunable parameters.

  0 Comments

Sign in to comment.

More Answers (2)

Jayesh Kavathe
Jayesh Kavathe on 9 Apr 2012
Thank you for the response but I didnt get it completely.
I have a Input block in my model (Mymodel/Input). In this block I have 11 "from workspace" variables feeding into 11 Simulink DataStoreWrite blocks.
These are the 11 variables I load from each file and run simulation on them, after I feed them to Simulink DataStore blocks. Can you tell me if they are tunable or not, can I change them for every sim run?
I did get_param on Mymodel/Input block but I was unable to find these 11 "from workspace variables" or 11 DataStoreWrite blocks.
Thanks again in advance.

  2 Comments

Kaustubha Govind
Kaustubha Govind on 10 Apr 2012
Is your "Input" block a subsystem containing "From Workspace" blocks? You'll need to run the get_param command I suggested on the From Workspace blocks. In any case, I ran that command on the block, and the "VariableName" parameter is non-tunable, so you cannot modify them without rebuilding your rapid accelerator target. The reason that this parameter is non-tunable is because the type/size of this parameter value determines the output signal type/size, which will affect the types/sizes propagated throughout the model. I think the better approach for your case might be to replace the From Workspace blocks with Inport blocks, and use the model Data Import/Export pane to import the data from workspace. You will need to ensure that the type/size of the data does not change between simulations.
K E
K E on 16 Apr 2012
Very useful answer. Now I will be able to use Rapid Accelerator on my model.

Sign in to comment.


Jayesh Kavathe
Jayesh Kavathe on 16 Apr 2012
Thanks again. I used inports blocks and Data Import/Export method and now I am running Rapid Accl sim without rebuilding the model each time. I dont know how I did it but I am able to run Input data vector with different size and still its running just fine.
Now another question :(.
How do I make my Calibration Tunable? I could not find a way to change the calibration for each sim run while keeping the same input data vector.
Here is a sample about how I initiate all the calibrations : %% Exhaust_Flow
Exhaust_Flow.DataType='double';
Exhaust_Flow.Description='Exhaust Flow';
Exhaust_Flow.DocUnits='';
Exhaust_Flow.Max=500000;
Exhaust_Flow.Min=0;
Exhaust_Flow.RTWInfo.CustomAttributes.HeaderFile='dsm_scm_data.h';
Exhaust_Flow.RTWInfo.CustomStorageClass='ImportFromFile';
Exhaust_Flow.RTWInfo.StorageClass='Custom';
Exhaust_Flow.Value=0.995;
Exhaust_Flow=mpt.Parameter;
I need to change "Exhaust_Flow.Value=0.995" for each itiration while everything else remains the same.

  2 Comments

K E
K E on 16 Apr 2012
You might want to ask this as a separate question since it is separate from your original question.
Kaustubha Govind
Kaustubha Govind on 16 Apr 2012
I agree with KE. Also, I think just assigning Exhaust_Flow.Value to a different value before each simulation should work. When you create a new question please specify why that doesn't work.

Sign in to comment.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by