Parametric Sweep for a Simscape Thermal Model
This example shows how to test a physical system, and how to optimize a parameter using a test harness, test sequence, and the test manager. The example uses a system-level thermal model of a projector which includes Simscape® thermal blocks.
Set Up Variables
Set the required variables for the example.
Model = 'sltestProjectorFanSpeedExample'; Harness = 'FanSpeedTestHarness'; TestSuite = 'sltestProjectorFanSpeedTestSuite.mldatx'; open_system(Model);
Test Plan and System Requirements
This test demonstrates sweeping through several fan speeds to determine the optimal value. In short, the optimal fan speed results in the fastest response without damaging the system. In detail, the optimal fan speed:
Prevents the system from exceeding the specified maximum temperature.
Minimizes the time for the system to reach the temperature at which the lamp emits visible light.
sltestProjectorFanSpeedExampleRequirements.slreqx captures these detailed requirements and the test procedure.
Test-specific model items reside in the test harness, keeping main models free of unnecessary blocks, suitable for code generation, and suitable for integration with other models.
Open the Test File
Open the Test Manager to view the test suite controlling the parameter sweep. From the model, open the
Simulink Test app and click on
Simulink Test Manager. Open the file referenced by
TestSuite. You can also enter
Description of the Test
The test investigates the transient and steady-state thermal characteristics of the system. The test sequence initializes the system to ambient temperature, then powers the projector lamp. When the system reaches a steady-state condition, the lamp switches off. This test is modeled in a test harness using a Test Sequence block. Run the following to open the test harness:
The test suite contains links to the requirements document. You can view the requirements link by opening the test suite in the Test Browser, and clicking the links in the Requirements section.
The Test Sequence
Double-click the Test Sequence block to open the test sequence editor.
T0in signals store the initial projector temperature at each test step.
PowerOnTime stores simulation time when the lamp signal activates. This facilitates subsequent data analysis.
The transition condition detects the steady-state condition. At steady-state, the system temperature change is a small fraction
(Threshold) of the difference between the current projector temperature and the initial projector temperature at each step. This condition must hold for a minimum time
DurationLimit, in this case 10 seconds.
You may link the steps in the test sequence blocks against prepopulated requirements in the requirements document
Description of the Parameter Sweep
The pre-load callbacks contain the command to set the fan speed for each test case under the
Fan Speed Parametric Study test suite. The parameter overrides contain the command to recalculate fan airflow from fan speed, and then override the test harness parameter. You can view these commands in the Callbacks and Parameter Overrides section of each test case.
Run the Test
In the Test Browser, highlight Fan Speed Parametric Study and click Run. When the test suite simulation completes, open the results for each test case and select
ProjectorTemp. View the results in the Test Manager.
Export the Data
With the Test Manager you can export data for post-processing. In the Results and Artifacts pane of the Test Manager, right-click Sim Output for each test case and select Export.
This example includes the exported data in four MAT files, located in the example folder:
ProjectorTempFanSpeed800.mat ProjectorTempFanSpeed1300.mat ProjectorTempFanSpeed1800.mat ProjectorTempFanSpeed2300.mat
Investigate Response Time and Maximum Projector Temperature
Since the test sequence transitions execute when the system reaches steady-state, and the fan speed changes the system response, the lamp activates at different simulation times for each of the four test cases. Simplify the graphical results analysis by plotting each response with the lamp activation at the same time.
Extract the lamp activation response data, and plot the system response for the four fan speeds. Evaluate the results against these criteria:
The temperature shall not exceed 65 deg C.
The lamp emits visible light above 45 deg C. Minimize the time to reach this temperature.
Load the results. At the command line, enter
DataAt800 = load('ProjectorTempFanSpeed800.mat'); DataAt1300 = load('ProjectorTempFanSpeed1300.mat'); DataAt1800 = load('ProjectorTempFanSpeed1800.mat'); DataAt2300 = load('ProjectorTempFanSpeed2300.mat');
ArrangeProjectorData.m arranges the temperature and power on data from the output for each run.
PlotProjectorThermalResponse.m plots the thermal response of the projector after the lamp activates, for each of the fan speeds.
The results show that while the highest fan speed results in the lowest maximum temperature, it also takes the longest time to reach the lamp activation temperature. The lowest fan speed results in the fastest lamp activation, but the system exceeds the maximum specified temperature by a significant margin.
Fan speed = 1300 keeps the system under the maximum temperature spec, and the system also reaches lamp activation temperature approximately 3 seconds faster than with the highest fan speed.
clear Model; clear Harness; clear TestSuite; close(figure(1));