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 00034 #include <acado/code_generation/integrators/rk_export.hpp> 00035 00036 00037 00038 BEGIN_NAMESPACE_ACADO 00039 00040 00041 // 00042 // PUBLIC MEMBER FUNCTIONS: 00043 // 00044 00045 RungeKuttaExport::RungeKuttaExport( UserInteraction* _userInteraction, 00046 const std::string& _commonHeaderName 00047 ) : IntegratorExport( _userInteraction,_commonHeaderName ) 00048 { 00049 } 00050 00051 00052 RungeKuttaExport::RungeKuttaExport( const RungeKuttaExport& arg 00053 ) : IntegratorExport( arg ) 00054 { 00055 copy( arg ); 00056 } 00057 00058 00059 RungeKuttaExport::~RungeKuttaExport( ) 00060 { 00061 clear( ); 00062 } 00063 00064 00065 RungeKuttaExport& RungeKuttaExport::operator=( const RungeKuttaExport& arg 00066 ) 00067 { 00068 if( this != &arg ) 00069 { 00070 clear( ); 00071 IntegratorExport::operator=( arg ); 00072 copy( arg ); 00073 } 00074 return *this; 00075 } 00076 00077 00078 returnValue RungeKuttaExport::initializeButcherTableau( const DMatrix& _AA, const DVector& _bb, const DVector& _cc ) { 00079 00080 if( _cc.isEmpty() || !_AA.isSquare() || _AA.getNumRows() != _bb.getDim() || _bb.getDim() != _cc.getDim() ) return RET_INVALID_OPTION; 00081 00082 numStages = _cc.getDim(); 00083 is_symmetric = checkSymmetry( _cc ); 00084 // std::cout << "Symmetry of the chosen method: " << is_symmetric << "\n"; 00085 AA = _AA; 00086 bb = _bb; 00087 cc = _cc; 00088 00089 return SUCCESSFUL_RETURN; 00090 } 00091 00092 00093 BooleanType RungeKuttaExport::checkSymmetry( const DVector& _cc ) { 00094 00095 if( _cc.getDim() <= 1 ) return BT_FALSE; 00096 BooleanType symmetry = BT_TRUE; 00097 uint i; 00098 for( i = 0; i < _cc.getDim(); i++ ) { 00099 int tmp = acadoRoundAway(1.0 - _cc(i) - _cc(_cc.getDim()-1-i)); 00100 if( symmetry ) symmetry = (tmp == 0); 00101 } 00102 return symmetry; 00103 } 00104 00105 00106 uint RungeKuttaExport::getNumStages() { 00107 00108 return numStages; 00109 } 00110 00111 00112 returnValue RungeKuttaExport::setNARXmodel( const uint delay, const DMatrix& parms ) { 00113 00114 return RET_INVALID_OPTION; 00115 } 00116 00117 00118 00119 // PROTECTED: 00120 00121 00122 returnValue RungeKuttaExport::copy( const RungeKuttaExport& arg 00123 ) 00124 { 00125 numStages = arg.numStages; 00126 AA = arg.AA; 00127 bb = arg.bb; 00128 cc = arg.cc; 00129 00130 rhs = arg.rhs; 00131 diffs_rhs = arg.diffs_rhs; 00132 grid = arg.grid; 00133 00134 // ExportVariables 00135 rk_ttt = arg.rk_ttt; 00136 rk_xxx = arg.rk_xxx; 00137 rk_kkk = arg.rk_kkk; 00138 00139 // ExportFunctions 00140 integrate = arg.integrate; 00141 00142 return SUCCESSFUL_RETURN; 00143 } 00144 00145 00146 00147 CLOSE_NAMESPACE_ACADO 00148 00149 // end of file.