Main Content

Run Parallel Simulations for a Thermal Model of a House Usingparsim

This example shows how to use aSimulink.SimulationInputobject to change block and model parameters and run simulations in parallel with those changes.

The example modelsldemo_househeatis 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.SimulationInputobjects. Use theseSimulink.SimulationInputobjects to specify theSet Pointvalues. 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.SimulationInputobjects, 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 theShowSimulationManagerargument toon. TheShowProgressargument when set toonshows the progress of the simulations.

out = parsim(in,'ShowSimulationManager','on','ShowProgress','on')

The output is generated as aSimulink.SimulationOutputobject. 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, theparsimcommand behaves like thesimcommand. The simulations run in serial.

View the Runs in the Simulation Manager

Setting theShowSimulationManagerargument toonenables 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

Tools

Related Topics