Run Parallel Simulations for a Thermal Model of a House Usingparsim
This example shows how to use aSimulink.SimulationInput
object to change block and model parameters and run simulations in parallel with those changes.
The example modelsldemo_househeat
is a system that models the thermal characteristics of a house, its outdoor environment, and a house heating system. This model calculates heating costs for a generic house.
Set Point block, Thermostat subsystem, Heater subsystem, House subsystem, and Cost Calculator component are the main components. For a detailed explanation of the model, seeThermal Model of a House.
Run Multiple Parallel Simulations with Different Set Points
This model uses a Constant block to specify a temperature set point that must be maintained indoors. The default value of set point value is 70 degrees Fahrenheit. This example shows you how to simulate the model in parallel using different values ofSet Point
.
Open the example and the model
openExample('simulink_general/sldemo_househeatExample'); open_system('sldemo_househeat');
Define a set of values forSet Point
.
SetPointValues = 65:2:85; spv_length = length(SetPointValues);
Using the defined values, initialize an array ofSimulink.SimulationInput
objects. Use theseSimulink.SimulationInput
objects to specify theSet Point
values. In this step, to preallocate the array, the loop index is made to start from the largest value.
fori = spv_length:-1:1 in(i) = Simulink.SimulationInput('sldemo_househeat'); in(i) = in(i).setBlockParameter('sldemo_househeat/Set Point',...'Value',num2str(SetPointValues(i)));end
This example produces an array of 10Simulink.SimulationInput
objects, each corresponding to a different value ofSet Point
.
Now, run these multiple simulations in parallel using the commandparsim
. To monitor and analyze the runs, open the Simulation Manager by setting theShowSimulationManager
argument toon
. TheShowProgress
argument when set toon
shows the progress of the simulations.
out = parsim(in,'ShowSimulationManager','on','ShowProgress','on')
The output is generated as aSimulink.SimulationOutput
object. To see all of the different set point values, open the plot of the Temperatures (Indoor and Outdoor) and the Heat Cost component. The constant block Avg Outdoor Temp specifies the average air temperature outdoors. The Daily Temp Variation Sine Wave block generates daily temperature fluctuations of outdoor temperature. The indoor temperature is derived from the House subsystem. The temperature outdoor varies sinusoidally, whereas the temperature indoors is maintained within 5 degrees Fahrenheit of the set point.
In the absence of the Parallel Computing Toolbox™ licenses, theparsim
command behaves like thesim
command. The simulations run in serial.
View the Runs in the Simulation Manager
Setting theShowSimulationManager
argument toon
enables the Simulation Manager. For more information, seeSimulation Manager.
You can view the status of all the runs and detailed information about them.
The Simulation Manager enables you to view your results in the Simulation Data Inspector, which in turn allows you to analyze and compare your data. You can view the plot of the Temperatures (Indoor and Outdoor) and the Heat Cost in Simulation Data Inspector. Select the runs for which you want to view the plot and click图标。
You can now see the heat cost for three simulations.
Using the Simulation Manager, you can apply the parameters of any run to your model. Now, suppose that you want to apply the parameters of Run 3 to your model. Select Run 3 and click the图标。你的参数应用到模型。
See Also
Objects
Functions
applyToModel
|setExternalInput
|setInitialState
|setVariable
|setModelParameter
|setBlockParameter
|validate
|setPreSimFcn
|setPostSimFcn
|parsim