chemical_rate_equations.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00027 
00035 #include <acado_integrators.hpp>
00036 
00037 
00052 int main( ){
00053 
00054     USING_NAMESPACE_ACADO
00055 
00056 
00057     // DEFINE THE RIGHT-HAND-SIDE
00058     // OF A DOUBLE PENDULUM:
00059     // ---------------------------
00060 
00061     DifferentialState             y1;
00062     DifferentialState             y2;
00063     DifferentialState             y3;
00064 
00065     DifferentialStateDerivative  dy1;
00066     DifferentialStateDerivative  dy2;
00067     DifferentialStateDerivative  dy3;
00068 
00069     Parameter                     p1;
00070     Parameter                     p2;
00071     Parameter                     p3;
00072 
00073 
00074     DifferentialEquation f;
00075 
00076     f << dy1 + p1*y1 - p2*y2*y3                 ;
00077     f << dy2 - p1*y1 + p2*y2*y3 + p3*y2*y2      ;
00078     f << dy3 - p3*y2*y2  ;
00079 
00080 
00081     // DEFINE AN INTEGRATOR:
00082     // ---------------------
00083 
00084     IntegratorBDF integrator(f);
00085         integrator.set(INTEGRATOR_PRINTLEVEL, MEDIUM );
00086 
00087     integrator.set(INTEGRATOR_TOLERANCE, 1e-5 );
00088     integrator.set(ABSOLUTE_TOLERANCE, 1e-6 );
00089 
00090     integrator.set(MAX_NUM_INTEGRATOR_STEPS, 2000  );
00091    // integrator.set(MAX_INTEGRATOR_STEPSIZE, 1e-3  );
00092 
00093 //    integrator.set( LINEAR_ALGEBRA_SOLVER , SPARSE_LU );
00094 
00095 
00096     // DEFINE INITIAL VALUES:
00097     // ----------------------
00098 
00099     double x0[3] = { 1.0, 0.0, 0.0 };
00100     double pp[3] = { 0.04, 1e+4, 3e+7 };
00101 
00102     double t0   = 0.0 ;
00103     double tend = 4e9;
00104 
00105 
00106     // START THE INTEGRATION:
00107     // ----------------------
00108 
00109 //     double a = acadoGetTime();
00110 
00111     //integrator.freezeAll();
00112         integrator.integrate( t0, tend, x0, 0, pp );
00113 
00114 //     printf("%.16e \n",  acadoGetTime() - a );
00115 
00116 
00117     // GET THE RESULTS
00118     // ---------------
00119 
00120         VariablesGrid differentialStates;
00121         integrator.getX( differentialStates );
00122         
00123         differentialStates.print( "x" );
00124 
00125 
00126     return 0;
00127 }
00128 
00129 
00130 


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:57:54