plug_flow_reactor2_nbi.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
45 #include <acado_gnuplot.hpp>
46 
47 
48 int main( ){
49 
51 
52  // INTRODUCE FIXED PARAMETERS:
53  // ---------------------------
54  #define v 0.1
55  #define L 1.0
56  #define Beta 0.2
57  #define Delta 0.25
58  #define E 11250.0
59  #define k0 1E+06
60  #define R 1.986
61  #define K3 30.0
62  #define Cin 0.02
63  #define Tin 340.0
64 
65 
66  // INTRODUCE THE VARIABLES:
67  // -------------------------
68  DifferentialState x1,x2,x3;
69  Control u ;
70  DifferentialEquation f( 0.0, L );
71 
72 
73  // DEFINE A DIFFERENTIAL EQUATION:
74  // -------------------------------
75  double Alpha, Gamma;
76  Alpha = k0*exp(-E/(R*Tin));
77  Gamma = E/(R*Tin);
78 
79  f << dot(x1) == Alpha /v * (1.0-x1) * exp((Gamma*x2)/(1.0+x2));
80  f << dot(x2) == (Alpha*Delta)/v * (1.0-x1) * exp((Gamma*x2)/(1.0+x2)) + Beta/v * (u-x2);
81  f << dot(x3) == 1.0/K3*Beta/L*(u-x2);
82 
83 
84  // DEFINE AN OPTIMAL CONTROL PROBLEM:
85  // ----------------------------------
86  OCP ocp( 0.0, L, 50 );
87  ocp.minimizeMayerTerm( 0, Cin*(1.0-x1) ); // Solve conversion optimal problem
88  ocp.minimizeMayerTerm( 1, x3 ); // Solve energy optimal problem
89 
90  ocp.subjectTo( f );
91 
92  ocp.subjectTo( AT_START, x1 == 0.0 );
93  ocp.subjectTo( AT_START, x2 == 0.0 );
94  ocp.subjectTo( AT_START, x3 == 0.0 );
95 
96  ocp.subjectTo( 0.0 <= x1 <= 1.0 );
97  ocp.subjectTo( (280.0-Tin)/Tin <= x2 <= (400.0-Tin)/Tin );
98  ocp.subjectTo( (280.0-Tin)/Tin <= u <= (400.0-Tin)/Tin );
99 
100 
101  // DEFINE A MULTI-OBJECTIVE ALGORITHM AND SOLVE THE OCP:
102  // -----------------------------------------------------
103  MultiObjectiveAlgorithm algorithm(ocp);
104 
105  algorithm.set( INTEGRATOR_TYPE, INT_BDF );
106  algorithm.set( KKT_TOLERANCE, 1e-8 );
107 
109  algorithm.set( PARETO_FRONT_DISCRETIZATION, 11 );
110 
111 
112  // Minimize individual objective function
113  algorithm.solveSingleObjective(0);
114 
115  algorithm.getDifferentialStates("pfr_nominal_states0.txt");
116  algorithm.getControls("pfr_nominal_controls0.txt");
117 
118 
119 
120  // Minimize individual objective function
121  algorithm.solveSingleObjective(1);
122 
123  // Generate Pareto set
124  algorithm.solve();
125 
126 // algorithm.getWeights("plug_flow_reactor2_nbi_weights.txt");
127 // algorithm.getAllDifferentialStates("plug_flow_reactor2_nbi_states.txt");
128 // algorithm.getAllControls("plug_flow_reactor2_nbi_controls.txt");
129 
130 
131 
132  // VISUALIZE THE RESULTS IN A GNUPLOT WINDOW:
133  // ------------------------------------------
134  VariablesGrid paretoFront;
135  algorithm.getParetoFront( paretoFront );
136 
137  GnuplotWindow window1;
138  window1.addSubplot( paretoFront, "Pareto Front (conversion versus energy)", "OUTLET CONCENTRATION","ENERGY", PM_POINTS );
139  window1.plot( );
140 
141 
142  // PRINT INFORMATION ABOUT THE ALGORITHM:
143  // --------------------------------------
144  algorithm.printInfo();
145 
146 
147  // SAVE INFORMATION:
148  // ----------------
149  paretoFront.print();
150 
151  return 0;
152 }
153 
154 
returnValue print(std::ostream &stream=std::cout, const char *const name=DEFAULT_LABEL, const char *const startString=DEFAULT_START_STRING, const char *const endString=DEFAULT_END_STRING, uint width=DEFAULT_WIDTH, uint precision=DEFAULT_PRECISION, const char *const colSeparator=DEFAULT_COL_SEPARATOR, const char *const rowSeparator=DEFAULT_ROW_SEPARATOR) const
int main()
virtual returnValue plot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
returnValue printInfo()
returnValue addSubplot(PlotWindowSubplot &_subplot)
#define Delta
#define Beta
#define k0
#define Cin
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
#define E
returnValue getParetoFront(VariablesGrid &paretoFront) const
Data class for defining optimal control problems.
Definition: ocp.hpp:89
#define v
Expression dot(const Expression &arg)
#define L
returnValue getControls(VariablesGrid &p_) const
virtual returnValue solveSingleObjective(const int &number)
IntermediateState exp(const Expression &arg)
User-interface to formulate and solve optimal control problems with multiple objectives.
Provides an interface to Gnuplot for plotting algorithmic outputs.
#define Tin
#define R
returnValue getDifferentialStates(VariablesGrid &xd_) const
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.
#define K3


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:59