## Documentation |

This example shows how to use parallel computing to optimize the time-domain response of a Simulink® model. You use Simulink® Design Optimization™ and Parallel Computing Toolbox™ to tune the gains of a discrete PI controller of a boiler to meet the design requirements. The example also shows how the software automatically handles model path dependencies.

This example requires Parallel Computing Toolbox™.

On this page… |
---|

Configuring and Running the Optimization in the GUI Using Parallel Computing Configuring and Running the Optimization at the Command Line |

The Simulink model consists of a boiler model and a discrete PI controller. When using parallel computing, Simulink Design Optimization performs an automatic path dependency check, which recognizes the boiler model library as an installed library.

In order to illustrate how model path dependencies are handled when using parallel computing, we copy the boiler model and library block to a temporary folder before opening the model.

pathToLib = boilerpressure_setup; %Copies boiler model and library to a temporary folder addpath(pathToLib); open_system('boilerpressure_demo')

Starting parpool using the 'local' profile ... connected to 4 workers.

The boiler pressure is regulated by a discrete PI controller. The design requirement for the controller is to limit the pressure variation of the boiler within +-%5 of the nominal pressure.

The initial controller has fairly good regulation characteristics but in the presence of additional heat disturbances, modeled by the Heat Disturbance block, we want to tune the controller performance to provide tighter pressure regulation.

Double-click the 'Response Optimization GUI with preloaded data' block in the Simulink model to open a pre-configured SDOTOOL. The SDOTOOL is configured with:

**1.** Upper and lower bounds representing a +-5% allowable range on the drum pressure

**2.** A reference tracking objective to minimize the deviation of the drum pressure from nominal

**3.** The PI controller gains, Kp and Ki, are selected for tuning

Click **Plot Current Response** to display the drum pressure variations with the initial controller.

**Configuring and Running the Optimization in the GUI Using Parallel Computing**

When computing the model response with the initial controller, this complex model took a long time to simulate. Using parallel computing can reduce the optimization time by simulating the model in parallel. For more information on parallel computing and optimization performance see the tutorial "Improving Optimization Performance Using Parallel Computing".

To configure the optimization problem to use parallel computing click **Options** in the SDOTOOL and select the **Parallel Options** tab. Select the "Use the parallel pool during optimization" option. This triggers an automated search for any model path dependencies. In this example, the folder that contains the Boiler Library block is found as a model path dependency, and is displayed in the Model path dependencies list box.

Note that the model path dependencies must be accessible by all the workers in the MATLAB pool. In this example, we opened a local MATLAB pool, and all the workers have access to the folder containing the Boiler Model library. You can also manually edit the path dependency list, add paths using the folder browser, or rerun the automatic dependency checker.

Clicking OK configures the optimization to use parallel computing.

To run the optimization click the **Optimize** button. A progress window opens displaying optimization progress.

The final response shows that the optimized regulator tracks the reference pressure much more closely.

**Configuring and Running the Optimization at the Command Line**

You can also use the command line functions to configure the optimization to use parallel computing and run the optimization.

Select the model variables for optimization and set lower limits

p = sdo.getParameterFromModel('boilerpressure_demo',{'Kp','Ki'}); p(1).Minimum = 0.001; p(2).Minimum = 0.001;

Select the model signal to bound and create a simulator to simulate the model.

nPressure = Simulink.SimulationData.SignalLoggingInfo; nPressure.BlockPath = 'boilerpressure_demo/1//y0'; nPressure.OutputPortIndex = 1; nPressure.LoggingInfo.NameMode = 1; nPressure.LoggingInfo.LoggingName = 'nPressure'; simulator = sdo.SimulationTest('boilerpressure_demo'); simulator.LoggingInfo.Signals = nPressure;

Get the optimization requirements defined by the check blocks in the model so that we can use them in the optimization problem.

bnds = getbounds('boilerpressure_demo/Drum pressure constraint'); PressureLimits = [bnds{:}]; bnds = getbounds('boilerpressure_demo/Drum pressure constraint(Reference Tracking)'); PressureRegulation = [bnds{:}]; requirements = struct(... 'PressureLimits', PressureLimits, ... 'PressureRegulation', PressureRegulation);

Define the function called during optimization. Notice that the function uses the simulator and requirements defined earlier to evaluate the design.

```
evalDesign = @(p) boilerpressure_design(p,simulator,requirements);
type boilerpressure_design
```

function design = boilerpressure_design(p,simulator,requirements) %BOILERPRESSURE_DESIGN % % The boilerpressure_design function is used to evaluate a boiler % controller design design. % % The |p| input argument is the vector of controller parameters. % % The |simulator| input argument is a sdo.SimulinkTest object used to % simulate the |boilerpressure_demo| model and log simulation signals. % % The |requirements| input argument contains the design requirements used % to evaluate the boiler controller design. % % The |design| return argument contains information about the design % evaluation that can be used by the |sdo.optimize| function to optimize % the design. % % see also sdo.optimize, sdoExampleCostFunction % Copyright 2011 The MathWorks, Inc. %% Simulate the model % % Use the simulator input argument to simulate the model and log model % signals. % % First ensure that we simulate the model with the parameter values chosen % by the optimizer. % simulator.Parameters = p; %% % Simulate the model and log signals. % simulator = sim(simulator); %% % Get the simulation signal log, the simulation log name is defined by the % model |SignalLoggingName| property % logName = get_param('boilerpressure_demo','SignalLoggingName'); simLog = get(simulator.LoggedData,logName); %% Evaluate the design requirements % % Use the requirements input argument to evaluate the design requirements % % Check the Pressure signal against the |PressureLimits| requirements. % nPressure = get(simLog,'nPressure'); c = [... evalRequirement(requirements.PressureLimits(1),nPressure.Values); ... evalRequirement(requirements.PressureLimits(2),nPressure.Values)]; %% % Use the PressureLimits requirements as non-linear constraints for % optimization. design.Cleq = c(:); %% % Check the pressure signal against the |PressureRegulation| requirement. % f = evalRequirement(requirements.PressureRegulation,nPressure.Values); %% % Use the PressureRegulation requirement as an objective for optimization. design.F = f; end

Setup optimization options to use the parallel pool and specify the model and model dependencies used during optimization.

opt = sdo.OptimizeOptions; opt.UseParallel = 'always'; opt.OptimizedModel = 'boilerpressure_demo'; opt.ParallelPathDependencies = sdo.getModelDependencies('boilerpressure_demo');

Warning: the following problems were found during MATLAB code analysis: <a href="matlab:dependencies.openref('BlockCallback,OpenFcn','boilerpressure_demo/Click on the Optimize button in the GUI to optimize the Kp, Ki gains of the PI Pressure regulator block.')">BlockCallback,OpenFcn: boilerpressure_demo/Click on the Optimize button in the GUI to optimize the Kp, Ki gains of the PI Pressure regulator block. (line 1)</a> First argument to "evalin" is not a literal string

Run the optimization

[pOpt,info] = sdo.optimize(evalDesign,p,opt);

Configuring parallel workers for optimization... Parallel workers configured for optimization. Optimization started 31-May-2013 11:13:52 max Step-size First-order Iter F-count f(x) constraint optimality 0 1 17.5068 0 1 2 11.6563 0 1.25 32.2 2 3 8.32632 0 1.27 17.4 3 4 0.694611 0 70.1 0.0391 4 5 0.562489 0 4.3 0.0355 5 7 0.543708 0 2.79 0.0316 6 12 0.543708 0 0.0515 0.0316 Local minimum possible. Constraints satisfied. fmincon stopped because the size of the current step is less than the selected value of the step size tolerance and constraints are satisfied to within the selected value of the constraint tolerance. Removing data from parallel workers... Data removed from parallel workers.

After the model is optimized, we remove the boiler model and library file from the temporary folder.

```
rmpath(pathToLib)
boilerpressure_cleanup(pathToLib)
bdclose('boilerpressure_demo')
```

Sending a stop signal to all the workers ... stopped.

Was this topic helpful?