run parallel simulations for a thermal model of a house using
parsim
this example shows how to use a simulink.simulationinput
object to change block and model parameters and run simulations in parallel with those
changes.
the example model sldemo_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, see thermal 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 of set
point
.
open the example and the model
openexample('simulink_general/sldemo_househeatexample'); open_system('sldemo_househeat');
define a set of values for set point
.
setpointvalues = 65:2:85; spv_length = length(setpointvalues);
using the defined values, initialize an array of simulink.simulationinput
objects. use these simulink.simulationinput
objects to specify the set point
values.
in this step, to preallocate the array, the loop index is made to start from the largest
value.
for i = 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 11 simulink.simulationinput
objects, each corresponding to a different value of
set point
.
now, run these multiple simulations in parallel using the command
parsim
. to monitor and analyze the runs, open the simulation manager by
setting the showsimulationmanager
argument to on
. the
showprogress
argument when set to on
shows the progress
of the simulations.
out = parsim(in,'showsimulationmanager','on','showprogress','on')
the output is generated as a simulink.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, the parsim
command behaves like the
sim
command. the simulations run in serial.
view the runs in the simulation manager
setting the showsimulationmanager
argument to on
enables the simulation manager. for more information, see simulation
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 icon.
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 icon. your parameters are applied to the model.
see also
objects
functions
- | | | | | | | | |
parsim