plug_flow_reactor_nnc.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 K1 250000.0
62  #define Cin 0.02
63  #define Tin 340.0
64 
65 
66  // INTRODUCE THE VARIABLES:
67  // -------------------------
68  DifferentialState x1,x2;
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 
82 
83  // DEFINE AN OPTIMAL CONTROL PROBLEM:
84  // ----------------------------------
85  OCP ocp( 0.0, L, 50 );
86  ocp.minimizeMayerTerm( 0, Cin*(1.0-x1) ); // Solve conversion optimal problem
87  ocp.minimizeMayerTerm( 1, (pow((Tin*x2),2.0)/K1) + 0.005*Cin*(1.0-x1) ); // Solve energy optimal problem (perturbed by small conversion cost;
88  // otherwise the problem is ill-defined.)
89 
90  ocp.subjectTo( f );
91 
92  ocp.subjectTo( AT_START, x1 == 0.0 );
93  ocp.subjectTo( AT_START, x2 == 0.0 );
94 
95  ocp.subjectTo( 0.0 <= x1 <= 1.0 );
96  ocp.subjectTo( (280.0-Tin)/Tin <= x2 <= (400.0-Tin)/Tin );
97  ocp.subjectTo( (280.0-Tin)/Tin <= u <= (400.0-Tin)/Tin );
98 
99 
100  // DEFINE A MULTI-OBJECTIVE ALGORITHM AND SOLVE THE OCP:
101  // -----------------------------------------------------
102  MultiObjectiveAlgorithm algorithm(ocp);
103 
104  algorithm.set( INTEGRATOR_TYPE, INT_BDF );
105  algorithm.set( KKT_TOLERANCE, 1e-7 );
106 
108  algorithm.set( PARETO_FRONT_DISCRETIZATION, 11 );
109 
110  // Minimize individual objective function
111  algorithm.solveSingleObjective(0);
112 
113  // Minimize individual objective function
114  algorithm.solveSingleObjective(1);
115 
116  // Generate Pareto set
117  algorithm.solve();
118 
119  algorithm.getWeights("plug_flow_reactor_nnc_weights.txt");
120  algorithm.getAllDifferentialStates("plug_flow_reactor_nnc_states.txt");
121  algorithm.getAllControls("plug_flow_reactor_nnc_controls.txt");
122 
123 
124  // VISUALIZE THE RESULTS IN A GNUPLOT WINDOW:
125  // ------------------------------------------
126  VariablesGrid paretoFront;
127  algorithm.getParetoFront( paretoFront );
128 
129  GnuplotWindow window1;
130  window1.addSubplot( paretoFront, "Pareto Front (conversion versus energy)", "OUTLET CONCENTRATION", "ENERGY", PM_POINTS );
131  window1.plot( );
132 
133 
134  // PRINT INFORMATION ABOUT THE ALGORITHM:
135  // --------------------------------------
136  algorithm.printInfo();
137 
138 
139  // SAVE INFORMATION:
140  // ----------------
141  paretoFront.print();
142 
143  return 0;
144 }
145 
146 
147 
#define K1
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
#define Beta
DMatrix getWeights() const
#define Cin
virtual returnValue plot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
int main()
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
#define Delta
returnValue printInfo()
IntermediateState pow(const Expression &arg1, const Expression &arg2)
#define v
returnValue addSubplot(PlotWindowSubplot &_subplot)
#define E
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
returnValue getAllControls(const char *fileName) const
returnValue getParetoFront(VariablesGrid &paretoFront) const
#define R
Data class for defining optimal control problems.
Definition: ocp.hpp:89
Expression dot(const Expression &arg)
#define Tin
virtual returnValue solveSingleObjective(const int &number)
IntermediateState exp(const Expression &arg)
#define k0
User-interface to formulate and solve optimal control problems with multiple objectives.
returnValue getAllDifferentialStates(const char *fileName) const
Provides an interface to Gnuplot for plotting algorithmic outputs.
#define L
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.


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