Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

## Design Optimization with Uncertain Variables (Code)

This example shows how to optimize a design when there are uncertain variables. You optimize the dimensions of a Continuously Stirred Tank Reactor (CSTR) to minimize product concentration variation and production cost in case of varying, or uncertain, feed stock.

Continuously Stirred Tank Reactor (CSTR) Model

Continuously Stirred Tank Reactors (CSTRs) are common in the process industry. The Simulink model, sdoCSTR, models a jacketed diabatic (i.e., non-adiabatic) tank reactor described in [1]. The CSTR is assumed to be perfectly mixed, with a single first-order exothermic and irreversible reaction, . , the reactant, is converted to , the product.

In this example, you use the following two-state CSTR model, which uses basic accounting and energy conservation principles:

• , and - Concentrations of A in the CSTR and in the feed [kgmol/m^3]

• , , and - CSTR, feed, and coolant temperatures [K]

• and - Volumetric flow rate [m^3/h] and the density of the material in the CSTR [1/m^3]

• and - Height [m] and heated cross-sectional area [m^2] of the CSTR.

• - Pre-exponential non-thermal factor for reaction [1/h]

• and - Activation energy and heat of reaction for [kcal/kgmol]

• - Boltzmann's gas constant [kcal/(kgmol * K)]

• and - Heat capacity [kcal/K] and heat transfer coefficients [kcal/(m^2 * K * h)]

open_system('sdoCSTR');


The model includes a cascaded PID controller in the Controller subsystem. The controller regulates the reactor temperature, , and reactor residual concentration, .

CSTR Design Problem

Assume that the CSTR is cylindrical, with the coolant applied to the base of the cylinder. Tune the CSTR cross-sectional area, , and CSTR height, , to meet the following design goals:

• Minimize the variation in residual concentration, . Variations in the residual concentration negatively affect the quality of the CSTR product. Minimizing the variations also improves CSTR profit.

• Minimize the mean coolant temperature . Heating or cooling the jacket coolant temperature is expensive. Minimizing the mean coolant temperature improves CSTR profit.

The design must allow for variations in the quality of supply feed, . The CSTR is fed with feed from different suppliers. The quality of the feed differs from supplier to supplier and also varies within each supply batch.

Specify Design Variables

Select the following model parameters as design variables for optimization:

• Cylinder cross-sectional area

• Cylinder height

p = sdo.getParameterFromModel('sdoCSTR',{'A','h'});


Limit the cross-sectional area to a range of 1 to 2 square meters.

p(1).Minimum = 1;
p(1).Maximum = 2;


Limit the height to a range of 1 to 3 meters.

p(2).Minimum = 1;
p(2).Maximum = 3;


Specify Uncertain Variables

Create a parameter object for the model feed concentration, . Use this parameter to vary the feed concentration during optimization.

FeedConc = sdo.getParameterFromModel('sdoCSTR','FeedCon0');


Specify a plus-or-minus 10% range of values for the feed concentration.

FeedConcValues = FeedConc.Value*[1 0.9 1.1];


Specify Design Requirements

The design requirements require logging model signals. During optimization, the model is simulated using the current value of the design variables. Logged signals are used to evaluate the design requirements.

Log the following signals:

• CSTR concentration, available at the second output port of the sdoCSTR/CSTR block

Conc = Simulink.SimulationData.SignalLoggingInfo;
Conc.BlockPath               = 'sdoCSTR/CSTR';
Conc.OutputPortIndex         = 2;
Conc.LoggingInfo.NameMode    = 1;
Conc.LoggingInfo.LoggingName = 'Concentration';

• Coolant temperature, available at the first output of the sdoCSTR/Controller block

Coolant = Simulink.SimulationData.SignalLoggingInfo;
Coolant.BlockPath               = 'sdoCSTR/Controller';
Coolant.OutputPortIndex         = 1;
Coolant.LoggingInfo.NameMode    = 1;
Coolant.LoggingInfo.LoggingName = 'Coolant';


Create and configure a simulation test object to log the required signals.

simulator = sdo.SimulationTest('sdoCSTR');
simulator.LoggingInfo.Signals = [Conc,Coolant];


Create Objective/Constraint Function

Create a function to evaluate the CSTR design. This function is called at each optimization iteration.

Use an anonymous function with one argument that calls the sdoCSTR_design function.

evalDesign = @(p) sdoCSTR_design(p,simulator,FeedConc,FeedConcValues);


The evalDesign function:

• Has one input argument that specifies the CSTR dimensions

• Returns the optimization objective value

The sdoCSTR_design function uses a for loop that iterates through the sample values specified for the feed concentration. Within the loop, the function:

• Simulates the model using the current iterate and feed concentration values

• Calculates the residual concentration variation and coolant temperature costs

To view the objective function, type edit sdoCSTR_design.

Evaluate Initial Design

Call the evalDesign function with the initial CSTR dimensions.

dInit = evalDesign(p)

dInit =

F: 6.7369
costConc: 4.0265
costCoolant: 2.7103



Plot the model response for the initial design. Simulate the model using the sample feed concentration values. The plot shows the variation in the residual concentration and coolant temperature.

sdoCSTR_plotModelResponse(p,simulator,FeedConc,FeedConcValues);


The sdoCSTR_plotModelResponse function plots the model response. To view this function, type edit sdoCSTR_plotModelResponse.

Optimize Design

Pass the objective function and initial CSTR dimensions to sdo.optimize.

pOpt = sdo.optimize(evalDesign,p)

 Optimization started 09-Aug-2013 03:42:35

max        Step-size    First-order
Iter F-count        f(x)   constraint                 optimality
0      4      3.26706            0
1      8      2.30302            0         1.96         4.95
2     14      1.67935            0        0.485        0.983
3     18      1.54086            0        0.156        0.354
4     22      1.52587            0       0.0353        0.176
5     26      1.52181            0       0.0117       0.0946
6     31      1.51509            0      0.00287       0.0414
7     35      1.51354            0     0.000699      0.00898
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.

pOpt(1,1) =

Name: 'A'
Value: 2
Minimum: 1
Maximum: 2
Free: 1
Scale: 0.5000
Info: [1x1 struct]

pOpt(2,1) =

Name: 'h'
Value: 2.3980
Minimum: 1
Maximum: 3
Free: 1
Scale: 2
Info: [1x1 struct]

2x1 param.Continuous



Evaluate Optimized Design

Call the evalDesign function with the optimized CSTR dimensions.

dFinal = evalDesign(pOpt)

dFinal =

F: 1.5135
costConc: 1.1178
costCoolant: 0.3958



Plot the model response for the optimized design. Simulate the model using the sample feed concentration values. The optimized design reduces the residual concentration variation and average coolant temperature for different feed stocks.

sdoCSTR_plotModelResponse(pOpt,simulator,FeedConc,FeedConcValues);


References

[1] Bequette, B.W. Process Dynamics: Modeling, Analysis and Simulation. 1st ed. Upper Saddle River, NJ: Prentice Hall, 1998.

% Close the model
bdclose('sdoCSTR')