design optimization with uncertain variables (code) -凯发k8网页登录
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 the simulink model.
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 concentration, , and feed temperature, . 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 2] m^2.
p(1).minimum = 1; p(1).maximum = 2;
limit the height to a range of [1 3] m.
p(2).minimum = 1; p(2).maximum = 3;
specify uncertain variables
select the feed concentration and feed temperature as uncertain variables. you evaluate the design using different values of feed temperature and concentration.
punc = sdo.getparameterfrommodel('sdocstr',{'feedcon0','feedtemp0'});
create a parameter space for the uncertain variables. use normal distributions for both variables. specify the mean as the current parameter value. specify a variance of 5% of the mean for the feed concentration and 1% of the mean for the temperature.
uspace = sdo.parameterspace(punc); uspace = setdistribution(uspace,'feedcon0',makedist('normal',punc(1).value,0.05*punc(1).value)); uspace = setdistribution(uspace,'feedtemp0',makedist('normal',punc(2).value,0.01*punc(2).value));
the feed concentration is inversely correlated with the feed temperature. add this information to the parameter space.
%uspace.rankcorrelation = [1 -0.6; -0.6 1];
the rank correlation matrix has a row and column for each parameter with the (i,j) entry specifying the correlation between the i and j parameters.
sample the parameter space. the scatter plot shows the correlation between concentration and temperature.
rng('default'); %for reproducibility usmpl = sdo.sample(uspace,60); sdo.scatterplot(usmpl)
ideally you want to evaluate the design for every combination of points in the design and uncertain spaces, which implies 30*60 = 1800 simulations. each simulation takes around 0.5 sec. you can use parallel computing to speed up the evaluation. for this example you instead only use the samples that have maximum & minimum concentration and temperature values, reducing the evaluation time to around 1 min.
[~,iminc] = min(usmpl.feedcon0); [~,imaxc] = max(usmpl.feedcon0); [~,imint] = min(usmpl.feedtemp0); [~,imaxt] = max(usmpl.feedtemp0); usmpl = usmpl(unique([iminc,imaxc,imint,imaxt]) ,:);
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,punc,usmpl);
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, feed concentration, and feed temperature 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 = struct with fields: f: 11.3356 costconc: 6.4390 costcoolant: 4.8965
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,punc,usmpl);
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 2023-mar-03, 09:12:51 max first-order iter f-count f(x) constraint step-size optimality 0 4 5.17535 0 1 8 3.81522 0 2.01 7.83 2 12 2.63963 0 0.57 3.03 3 16 2.52991 0 0.159 0.27 4 20 2.51352 0 0.0156 0.453 5 24 2.50978 0 0.131 1.64 6 28 2.50087 0 0.102 0.314 7 32 2.48124 0 0.0164 0.179 8 39 2.47744 0 0.00748 0.316 9 48 2.46313 0 0.0323 0.468 10 57 2.46313 0 0.000778 0.468 local minimum possible. constraints satisfied. fmincon stopped because the size of the current step is less than the value of the step size tolerance and constraints are satisfied to within the 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.2037 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 = struct with fields: f: 2.4631 costconc: 1.4415 costcoolant: 1.0217
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,punc,usmpl);
related examples
to learn how to use sensitivity analysis to explore the cstr design space and select an initial design for optimization, see .
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')
see also
| |