7.3 Numerical Example
7.3.2 Using Fully Converged Solutions
Figure 7.4 shows states and control inputs of the simulated CSTR start-up controlled using online optimisation with fully converged solutions. We compare the tracking NMPC formulation and the time-optimal NMPC formulation with
α = 1 and α = 0.5. As expected, the time-optimal NMPC formulation is able to
regulate the CSTR faster to the desired steady-states. This comes at the expense of a larger overshoot at the beginning. We see that decreasing the tuning parameter
α, i.e. reducing the influence of the tracking component in the objective function,
leads to a more aggressive behaviour such that the desired steady-state is reached even faster.
As mentioned in Subsection 7.2.3, we need to choose a lower bound Tmin on the
horizon length T when employing the time-optimal NMPC formulation. For our simulations, we use a constant value of Tmin = 150 s which does not constrain
T in the first samples but ensures a smooth tracking NMPC behaviour once the
steady-state can be reached within 150 s.
Figure 7.5 compares the computational load of different algorithmic variants by illustrating the total runtime per sampling instant required to solve the respective optimal control problem. The tracking NMPC formulation is solved once employing the Gauss-Newton algorithm described in Subsection 7.2.1 and once using an exact Hessian computation. Solution of the time-optimal NMPC formulation is always based on an exact Hessian computation.
We can observe that runtimes vary greatly depending on the number of Newton- type iterations needed to solve the problem, which becomes smaller when we approach the steady-state. In case of the tracking NMPC formulation, calculation
NUMERICAL EXAMPLE 133
Listing 7.2: Symbolic formulation in ACADO syntax of an optimal control problem comprising the CSTR model and a least-squares objective function.
i n t main ( ) { // . . . // DEFINE CSTR MODEL: // −−−−−−−−−−−−−−−−−− D i f f e r e n t i a l E q u a t i o n f ; D i f f e r e n t i a l S t a t e cA , cB , t h e t a , thetaK ; C o n t r o l u ( 2 ) ; I n t e r m e d i a t e S t a t e k1 , k2 , k3 ; k1 = k10 ∗ exp ( E1 / ( 2 7 3 . 1 5 + t h e t a ) ) ; k2 = k20 ∗ exp ( E2 / ( 2 7 3 . 1 5 + t h e t a ) ) ; k3 = k30 ∗ exp ( E3 / ( 2 7 3 . 1 5 + t h e t a ) ) ;
f << d o t ( cA ) == u ( 0 ) ∗ ( cA0−cA ) − k1 ∗cA − k3 ∗cA∗cA ; f << d o t ( cB ) == − u ( 0 ) ∗ cB + k1 ∗cA − k2 ∗cB ; f << d o t ( t h e t a ) == u ( 0 ) ∗ ( t h e t a 0 −t h e t a )
−(1/( r h o ∗Cp ) ) ∗ ( k1 ∗cA∗H1 + k2 ∗cB∗H2 + k3 ∗cA∗cA∗H3 ) +(kw∗AR/ ( r h o ∗Cp∗VR) ) ∗ ( thetaK −t h e t a ) ;
f << d o t ( thetaK ) == ( 1 / (mK∗CPK) ) ∗ ( u ( 1 ) + kw∗AR∗ ( t h e t a −thetaK ) ) ;
// DEFINE LEAST−SQUARE FUNCTION: // −−−−−−−−−−−−−−−−−−−−−−−−−−−−− F u n c t i o n h ; h << cA ; h << cB ; h << t h e t a ; h << thetaK ; h << u ( 0 ) ; h << u ( 1 ) ; M a t r i x S = e y e ( 6 ) ; V e c t o r r = z e r o s ( 6 ) ; // . . .
// DEFINE AN OPTIMAL CONTROL PROBLEM: // −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
const double t S t a r t = 0 . 0 ;
const double tEnd = 1 5 0 0 . 0 ; OCP ocp ( t S t a r t , tEnd , 20 ) ;
ocp . minimizeLSQ ( S , h , r ) ; ocp . s u b j e c t T o ( f ) ;
ocp . s u b j e c t T o ( AT START, cA == 0 . 0 ) ; ocp . s u b j e c t T o ( AT START, cB == 0 . 0 ) ; ocp . s u b j e c t T o ( AT START, t h e t a == 8 5 . 0 ) ; ocp . s u b j e c t T o ( AT START, thetaK == 8 5 . 0 ) ; ocp . s u b j e c t T o ( 3 . 0 <= u ( 0 ) <= 3 5 . 0 ) ; ocp . s u b j e c t T o ( −9000.0 <= u ( 1 ) <= 0 . 0 ) ;
// DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP: // −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
O p t i m i z a t i o n A l g o r i t h m a l g o r i t h m ( ocp ) ;
a l g o r i t h m . s e t ( HESSIAN APPROXIMATION, GAUSS NEWTON ) ; a l g o r i t h m . s e t ( KKT TOLERANCE, 1 e−5 ) ;
a l g o r i t h m . s o l v e ( ) ;
return 0 ; }
of the exact Hessian does not seem to speed-up convergence while making each iteration more expensive. Changing α moderately in the time-optimal NMPC formulation does not seem to affect the overall runtime significantly.
Note that the computational performance of the ACADO Toolkit on this example is competitive with other existing software packages: For example, solving the
0 500 1000 1500 0 0.5 1 1.5 2 2.5 3 3.5 time [s]
(a) Concentration of substance A in mol/l.
0 500 1000 1500 0 0.2 0.4 0.6 0.8 1 1.2 1.4 time [s]
(b) Concentration of substance B in mol/l.
0 500 1000 1500 85 90 95 100 105 110 115 time [s]
(c) Temperature in the reactor in◦C.
0 500 1000 1500 85 90 95 100 105 110 115 time [s]
(d) Temperature of the jacket in◦C.
0 500 1000 1500 5 10 15 20 25 30 35 time [s]
(e) Scaled feed flow u1in 1/s.
0 500 1000 1500 −2000 −1500 −1000 −500 0 500 time [s]
(f) Heat removal rate u2 in kJ/s.
Figure 7.4: CSTR start-up controlled using online optimisation with fully converged solutions: tracking NMPC (solid), time-optimal NMPC with α = 1 (dashed), time-optimal NMPC with α = 0.5 (dash-dotted). Also the respective
NUMERICAL EXAMPLE 135
optimal control problem at the first sampling instant with the nonlinear optimal control package dsoa takes about 0.86 seconds to obtain the same solution accuracy. dsoa implements a single-shooting approach and solves the resulting small-scale NLP by means of an inexact SQP algorithm [73] based on BFGS updates (6.19). 0 2 4 6 8 10 12 14 16 18 20 22 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 No. MPC loop
Figure 7.5: Runtimes in seconds for the CSTR start-up controlled using online optimisation with fully converged solutions: tracking NMPC (solid), tracking NMPC using exact Hessians (dotted), time-optimal NMPC with α = 1 (dashed), time-optimal NMPC with α = 0.5 (dash-dotted).