chemical_rate_equations.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 
27 
35 #include <acado_integrators.hpp>
36 
37 
52 int main( ){
53 
55 
56 
57  // DEFINE THE RIGHT-HAND-SIDE
58  // OF A DOUBLE PENDULUM:
59  // ---------------------------
60 
64 
68 
69  Parameter p1;
70  Parameter p2;
71  Parameter p3;
72 
73 
75 
76  f << dy1 + p1*y1 - p2*y2*y3 ;
77  f << dy2 - p1*y1 + p2*y2*y3 + p3*y2*y2 ;
78  f << dy3 - p3*y2*y2 ;
79 
80 
81  // DEFINE AN INTEGRATOR:
82  // ---------------------
83 
84  IntegratorBDF integrator(f);
85  integrator.set(INTEGRATOR_PRINTLEVEL, MEDIUM );
86 
87  integrator.set(INTEGRATOR_TOLERANCE, 1e-5 );
88  integrator.set(ABSOLUTE_TOLERANCE, 1e-6 );
89 
90  integrator.set(MAX_NUM_INTEGRATOR_STEPS, 2000 );
91  // integrator.set(MAX_INTEGRATOR_STEPSIZE, 1e-3 );
92 
93 // integrator.set( LINEAR_ALGEBRA_SOLVER , SPARSE_LU );
94 
95 
96  // DEFINE INITIAL VALUES:
97  // ----------------------
98 
99  double x0[3] = { 1.0, 0.0, 0.0 };
100  double pp[3] = { 0.04, 1e+4, 3e+7 };
101 
102  double t0 = 0.0 ;
103  double tend = 4e9;
104 
105 
106  // START THE INTEGRATION:
107  // ----------------------
108 
109 // double a = acadoGetTime();
110 
111  //integrator.freezeAll();
112  integrator.integrate( t0, tend, x0, 0, pp );
113 
114 // printf("%.16e \n", acadoGetTime() - a );
115 
116 
117  // GET THE RESULTS
118  // ---------------
119 
120  VariablesGrid differentialStates;
121  integrator.getX( differentialStates );
122 
123  differentialStates.print( "x" );
124 
125 
126  return 0;
127 }
128 
129 
130 
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
returnValue getX(DVector &xEnd) const
Implements the backward-differentiation formula for integrating DAEs.
returnValue set(OptionsName name, int value)
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
returnValue integrate(double t0, double tend, double *x0, double *xa=0, double *p=0, double *u=0, double *w=0)
Definition: integrator.cpp:207
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:29