MATLAB Examples

Adaptive MPC Control of Nonlinear Chemical Reactor Using Linear Parameter Varying System

This example shows how to use an Adaptive MPC controller to control a nonlinear continuous stirred tank reactor (CSTR) as it transitions from low conversion rate to high conversion rate.

A linear parameter varying (LPV) system consisting of three linear plant models is constructed offline to describe the local plant dynamics across the operating range. The adaptive MPC controller then uses the LPV system to update the internal predictive model at each control interval and achieves nonlinear control successfully.

Contents

About the Continuous Stirred Tank Reactor

A Continuously Stirred Tank Reactor (CSTR) is a common chemical system in the process industry. A schematic of the CSTR system is:

This is a jacketed non-adiabatic tank reactor described extensively in Seborg's book, "Process Dynamics and Control", published by Wiley, 2004. The vessel is assumed to be perfectly mixed, and a single first-order exothermic and irreversible reaction, A --> B, takes place. The inlet stream of reagent A is fed to the tank at a constant volumetric rate. The product stream exits continuously at the same volumetric rate and liquid density is constant. Thus the volume of reacting liquid is constant.

The inputs of the CSTR model are:

$$ \begin{array} {ll}
u_1 = CA_i \; & \textnormal{Concentration of A in inlet feed
stream} [kgmol/m^3] \\
u_2 = T_i \; & \textnormal{Inlet feed stream temperature} [K] \\
u_3 = T_c \; & \textnormal{Jacket coolant temperature} [K] \\
\end{array} $$

and the outputs (y(t)), which are also the states of the model (x(t)), are:

$$ \begin{array} {ll}
y_1 = x_1 = CA \; & \textnormal{Concentration of A in reactor tank} [kgmol/m^3] \\
y_2 = x_2 = T \; & \textnormal{Reactor temperature} [K] \\
\end{array} $$

The control objective is to maintain the concentration of reagent A, $CA$ at its desired setpoint, which changes over time when reactor transitions from low conversion rate to high conversion rate. The coolant temperature $T_c$ is the manipulated variable used by the MPC controller to track the reference as well as reject the measured disturbance arising from the inlet feed stream temperature $T_i$. The inlet feed stream concentration, $CA_i$, is assumed to be constant. The Simulink model mpc_cstr_plant implements the nonlinear CSTR plant.

About Adaptive Model Predictive Control

It is well known that the CSTR dynamics are strongly nonlinear with respect to reactor temperature variations and can be open-loop unstable during the transition from one operating condition to another. A single MPC controller designed at a particular operating condition cannot give satisfactory control performance over a wide operating range.

To control the nonlinear CSTR plant with linear MPC control technique, you have a few options:

  • If a linear plant model cannot be obtained at run time, first you need to obtain several linear plant models offline at different operating conditions that cover the typical operating range. Next you can choose one of the two approaches to implement MPC control strategy:

(1) Design several MPC controllers offline, one for each plant model. At run time, use Multiple MPC Controller block that switches MPC controllers from one to another based on a desired scheduling strategy. See docid:mpc_examples.example-ex20937898 for more details. Use this approach when the plant models have different orders or time delays.

(2) Design one MPC controller offline at the initial operating point. At run time, use Adaptive MPC Controller block (updating predictive model at each control interval) together with Linear Parameter Varying (LPV) System block (supplying linear plant model with a scheduling strategy) as shown in this example. Use this approach when all the plant models have the same order and time delay.

  • If a linear plant model can be obtained at run time, you should use Adaptive MPC Controller block to achieve nonlinear control. There are two typical ways to obtain a linear plant model online:

(1) Use successive linearization. See docid:mpc_examples.example-ex07272954 for more details. Use this approach when a nonlinear plant model is available and can be linearized at run time.

(2) Use online estimation to identify a linear model when loop is closed. See docid:mpc_examples.example-ex24638454 for more details. Use this approach when linear plant model cannot be obtained from either an LPV system or successive linearization.

Obtain Linear Plant Model at Initial Operating Condition

To linearize the plant, Simulink® and Simulink Control Design® are required.

if ~mpcchecktoolboxinstalled('simulink')
    disp('Simulink(R) is required to run this example.')
    return
end
if ~mpcchecktoolboxinstalled('slcontrol')
    disp('Simulink Control Design(R) is required to run this example.')
    return
end

First, a linear plant model is obtained at the initial operating condition, CAi is 10 kgmol/m^3, Ti and Tc are 298.15 K. Functions from Simulink Control Design such as "operspec", "findop", "linearize", are used to generate the linear state space system from the Simulink model.

Specify sample time used by plant models and MPC controller

Ts = 0.5;
% Create operating point specification.
plant_mdl = 'mpc_cstr_plant';
op = operspec(plant_mdl);

Feed concentration is known at the initial condition.

op.Inputs(1).u = 10;
op.Inputs(1).Known = true;

Feed temperature is known at the initial condition.

op.Inputs(2).u = 298.15;
op.Inputs(2).Known = true;

Coolant temperature is known at the initial condition.

op.Inputs(3).u = 298.15;
op.Inputs(3).Known = true;

Compute initial condition.

[op_point,op_report] = findop(plant_mdl,op);
% Obtain nominal values of x, y and u.
x0_initial = [op_report.States(1).x; op_report.States(2).x];
y0_initial = [op_report.Outputs(1).y; op_report.Outputs(2).y];
u0_initial = [op_report.Inputs(1).u; op_report.Inputs(2).u; op_report.Inputs(3).u];
 Operating point search report:
---------------------------------

 Operating point search report for the Model mpc_cstr_plant.
 (Time-Varying Components Evaluated at time t=0)

Operating point specifications were successfully met.
States: 
----------
(1.) mpc_cstr_plant/CSTR/Integrator
      x:           311      dx:      8.12e-11 (0)
(2.) mpc_cstr_plant/CSTR/Integrator1
      x:          8.57      dx:     -6.87e-12 (0)

Inputs: 
----------
(1.) mpc_cstr_plant/CAi
      u:            10
(2.) mpc_cstr_plant/Ti
      u:           298
(3.) mpc_cstr_plant/Tc
      u:           298

Outputs: 
----------
(1.) mpc_cstr_plant/T
      y:           311    [-Inf Inf]
(2.) mpc_cstr_plant/CA
      y:          8.57    [-Inf Inf]

Obtain linear model at the initial condition.

plant_initial = linearize(plant_mdl,op_point);
% Discretize the plant model
plant_initial = c2d(plant_initial,Ts);

Specify signal types and names used in MPC.

plant_initial.InputGroup.UnmeasuredDisturbances = [1 2];
plant_initial.InputGroup.ManipulatedVariables = 3;
plant_initial.OutputGroup.Measured = [1 2];
plant_initial.InputName = {'CAi','Ti','Tc'};
plant_initial.OutputName = {'T','CA'};

Obtain Linear Plant Model at Intermediate Operating Condition

Create operating point specification.

op = operspec(plant_mdl);

Feed concentration is known.

op.Inputs(1).u = 10;
op.Inputs(1).Known = true;

Feed temperature is known.

op.Inputs(2).u = 298.15;
op.Inputs(2).Known = true;

Reactor concentration is known

op.Outputs(2).y = 5.5;
op.Outputs(2).Known = true;

Find steady state operating condition.

[op_point,op_report] = findop(plant_mdl,op);
% Obtain nominal values of x, y and u.
x0_intermediate = [op_report.States(1).x; op_report.States(2).x];
y0_intermediate = [op_report.Outputs(1).y; op_report.Outputs(2).y];
u0_intermediate = [op_report.Inputs(1).u; op_report.Inputs(2).u; op_report.Inputs(3).u];
 Operating point search report:
---------------------------------

 Operating point search report for the Model mpc_cstr_plant.
 (Time-Varying Components Evaluated at time t=0)

Operating point specifications were successfully met.
States: 
----------
(1.) mpc_cstr_plant/CSTR/Integrator
      x:           339      dx:      3.42e-08 (0)
(2.) mpc_cstr_plant/CSTR/Integrator1
      x:           5.5      dx:     -2.87e-09 (0)

Inputs: 
----------
(1.) mpc_cstr_plant/CAi
      u:            10
(2.) mpc_cstr_plant/Ti
      u:           298
(3.) mpc_cstr_plant/Tc
      u:           298    [-Inf Inf]

Outputs: 
----------
(1.) mpc_cstr_plant/T
      y:           339    [-Inf Inf]
(2.) mpc_cstr_plant/CA
      y:           5.5    (5.5)

Obtain linear model at the initial condition.

plant_intermediate = linearize(plant_mdl,op_point);
% Discretize the plant model
plant_intermediate = c2d(plant_intermediate,Ts);

Specify signal types and names used in MPC.

plant_intermediate.InputGroup.UnmeasuredDisturbances = [1 2];
plant_intermediate.InputGroup.ManipulatedVariables = 3;
plant_intermediate.OutputGroup.Measured = [1 2];
plant_intermediate.InputName = {'CAi','Ti','Tc'};
plant_intermediate.OutputName = {'T','CA'};

Obtain Linear Plant Model at Final Operating Condition

Create operating point specification.

op = operspec(plant_mdl);

Feed concentration is known.

op.Inputs(1).u = 10;
op.Inputs(1).Known = true;

Feed temperature is known.

op.Inputs(2).u = 298.15;
op.Inputs(2).Known = true;

Reactor concentration is known

op.Outputs(2).y = 2;
op.Outputs(2).Known = true;

Find steady state operating condition.

[op_point,op_report] = findop(plant_mdl,op);
% Obtain nominal values of x, y and u.
x0_final = [op_report.States(1).x; op_report.States(2).x];
y0_final = [op_report.Outputs(1).y; op_report.Outputs(2).y];
u0_final = [op_report.Inputs(1).u; op_report.Inputs(2).u; op_report.Inputs(3).u];
 Operating point search report:
---------------------------------

 Operating point search report for the Model mpc_cstr_plant.
 (Time-Varying Components Evaluated at time t=0)

Operating point specifications were successfully met.
States: 
----------
(1.) mpc_cstr_plant/CSTR/Integrator
      x:           373      dx:      5.57e-11 (0)
(2.) mpc_cstr_plant/CSTR/Integrator1
      x:             2      dx:      -4.6e-12 (0)

Inputs: 
----------
(1.) mpc_cstr_plant/CAi
      u:            10
(2.) mpc_cstr_plant/Ti
      u:           298
(3.) mpc_cstr_plant/Tc
      u:           305    [-Inf Inf]

Outputs: 
----------
(1.) mpc_cstr_plant/T
      y:           373    [-Inf Inf]
(2.) mpc_cstr_plant/CA
      y:             2    (2)

Obtain linear model at the initial condition.

plant_final = linearize(plant_mdl,op_point);
% Discretize the plant model
plant_final = c2d(plant_final,Ts);

Specify signal types and names used in MPC.

plant_final.InputGroup.UnmeasuredDisturbances = [1 2];
plant_final.InputGroup.ManipulatedVariables = 3;
plant_final.OutputGroup.Measured = [1 2];
plant_final.InputName = {'CAi','Ti','Tc'};
plant_final.OutputName = {'T','CA'};

Construct Linear Parameter Varying System

You can use an LTI array to store the three linear plant models obtained in previous sections.

lpv(:,:,1) = plant_initial;
lpv(:,:,2) = plant_intermediate;
lpv(:,:,3) = plant_final;

Specify reactor temperature T as the scheduling parameter.

lpv.SamplingGrid = struct('T',[y0_initial(1); y0_intermediate(1); y0_final(1)]);

Specify nominal values of plant inputs, outputs and states at each steady state operating point.

lpv_u0(:,:,1) = u0_initial;
lpv_u0(:,:,2) = u0_intermediate;
lpv_u0(:,:,3) = u0_final;
lpv_y0(:,:,1) = y0_initial;
lpv_y0(:,:,2) = y0_intermediate;
lpv_y0(:,:,3) = y0_final;
lpv_x0(:,:,1) = x0_initial;
lpv_x0(:,:,2) = x0_intermediate;
lpv_x0(:,:,3) = x0_final;

You don't need to provide input signal "u" to the LPV System block because plant output signal "y" is not used in this example.

Design MPC Controller at Initial Operating Condition

You design a MPC controller at the initial operating condition but the controller settings such as horizons and tuning weights should be chosen such that they apply to the whole operating range.

Create MPC controller with default prediction and control horizons

mpcobj = mpc(plant_initial,Ts);
-->The "PredictionHorizon" property of "mpc" object is empty. Trying PredictionHorizon = 10.
-->The "ControlHorizon" property of the "mpc" object is empty. Assuming 2.
-->The "Weights.ManipulatedVariables" property of "mpc" object is empty. Assuming default 0.00000.
-->The "Weights.ManipulatedVariablesRate" property of "mpc" object is empty. Assuming default 0.10000.
-->The "Weights.OutputVariables" property of "mpc" object is empty. Assuming default 1.00000.
   for output(s) y1 and zero weight for output(s) y2 

Set nominal values in the controller. Note that nominal values for unmeasured disturbance must be zero.

mpcobj.Model.Nominal = struct('X',x0_initial,'U',[0;0;u0_initial(3)],'Y',y0_initial,'DX',[0 0]);

Set scale factors because plant input and output signals have different orders of magnitude

Uscale = [10;30;50];
Yscale = [50;10];
mpcobj.DV(1).ScaleFactor = Uscale(1);
mpcobj.DV(2).ScaleFactor = Uscale(2);
mpcobj.MV.ScaleFactor = Uscale(3);
mpcobj.OV(1).ScaleFactor = Yscale(1);
mpcobj.OV(2).ScaleFactor = Yscale(2);

The goal will be to track a specified transition in the reactor concentration. The reactor temperature will be measured and used in state estimation but the controller will not attempt to regulate it directly. It will vary as needed to regulate the concentration. Thus, set its MPC weight to zero.

mpcobj.Weights.OV = [0 1];

Plant inputs 1 and 2 are unmeasured disturbances. By default, the controller assumes integrated white noise with unit magnitude at these inputs when configuring the state estimator. Increase the state estimator signal-to-noise by a factor of 10 to improve disturbance rejection performance.

Dist = ss(getindist(mpcobj));
Dist.B = eye(2)*10;
setindist(mpcobj,'model',Dist);
-->The "Model.Disturbance" property of "mpc" object is empty:
   Assuming unmeasured input disturbance #1 is integrated white noise.
   Assuming unmeasured input disturbance #2 is integrated white noise.
   Assuming no disturbance added to measured output channel #2.
   Assuming no disturbance added to measured output channel #1.
-->The "Model.Noise" property of the "mpc" object is empty. Assuming white noise on each measured output channel.

All other MPC parameters are at their default values.

Implement Adaptive MPC Control of CSTR Plant in Simulink (R)

Open the Simulink model.

mdl = 'ampc_cstr_lpv';
open_system(mdl);

The model includes three parts:

  1. The "CSTR" block implements the nonlinear plant model.
  2. The "Adaptive MPC Controller" block runs the designed MPC controller in the adaptive mode.
  3. The "LPV System" block provides local state space plant model and its nominal values via interpolation at each control interval. The plant model is then fed to the "Adaptive MPC Controller" block and updates the predictive model used by MPC controller. In this example, the initial plant model is used to initialize the LPV System block.

The "LPV System" is provided by Control System Toolbox. You can use the Simulink model as a template to develop your own LPV based adaptive MPC applications.

Validate Adaptive MPC Control Performance

Controller performance is validated against both setpoint tracking and disturbance rejection.

  • Tracking: reactor temperature T setpoint transitions from original 311 K (low conversion rate) to 377 K (high conversion rate) kgmol/m^3. During the transition, the plant first becomes unstable then stable again (see the poles plot).
  • Regulating: feed temperature Ti has slow fluctuation represented by a sine wave with amplitude of 5 degrees, which is a measured disturbance fed to MPC controller.

Simulate the closed-loop performance.

open_system([mdl '/Concentration'])
open_system([mdl '/Temperature'])
sim(mdl);
   Assuming no disturbance added to measured output channel #2.
   Assuming no disturbance added to measured output channel #1.
-->The "Model.Noise" property of the "mpc" object is empty. Assuming white noise on each measured output channel.

The tracking and regulating performance is very satisfactory.

bdclose(mdl)