MBSim

Project Page
nonlinear_algebra.h
00001 /* Copyright (C) 2004-2009 MBSim Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or 
00004  * modify it under the terms of the GNU Lesser General Public 
00005  * License as published by the Free Software Foundation; either 
00006  * version 2.1 of the License, or (at your option) any later version. 
00007  *  
00008  * This library is distributed in the hope that it will be useful, 
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00011  * Lesser General Public License for more details. 
00012  *  
00013  * You should have received a copy of the GNU Lesser General Public 
00014  * License along with this library; if not, write to the Free Software 
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact: martin.o.foerg@googlemail.com
00018  */
00019 
00020 #ifndef NONLINEAR_ALGEBRA_H_
00021 #define NONLINEAR_ALGEBRA_H_
00022 
00023 #include "fmatvec/fmatvec.h"
00024 #include "mbsim/functions/function.h"
00025 
00026 namespace MBSim {
00027 
00033   class RegulaFalsi {
00034     public:
00035       /*
00036        * \brief constructor
00037        * \param root function
00038        */
00039       RegulaFalsi(Function<double(double)> *f);
00040 
00041       /* GETTER / SETTER */
00042       int getNumberOfIterations() const { return it; };
00043       int getInfo() const { return info; };
00044       void setMaximumNumberOfIterations(int itmax_) { itmax = itmax_; }
00045       void setTolerance(double tol_) { tol = tol_; }
00046       /***************************************************/
00047 
00053       double solve(double a, double b);
00054 
00055     private:
00059       Function<double(double)> *func;
00060 
00064       int itmax, it, info;
00065 
00069       double tol;
00070   };
00071 
00077   class MultiDimFixPointIteration {
00078     public:
00079       /*
00080        * \brief constructor
00081        * \param fct pointer to used fix-point-function
00082        */
00083       MultiDimFixPointIteration(Function<fmatvec::Vec(fmatvec::Vec)> *function_);
00084 
00085       /* GETTER / SETTER */
00086       /*
00087        * \brief returns info of iteration progress
00088        * info == 0 :  a solution has been found
00089        * info == -1:  no converge
00090        * info == 1:   process (seems to) converge but hasn't finished
00091        */
00092       int getInfo() {
00093         return info;
00094       }
00095       std::vector<double> getNorms() {
00096         return norms;
00097       }
00098       double getNumberOfIterations() {
00099         return iter;
00100       }
00101       double getNumberOfMaximalIterations() {
00102         return itermax;
00103       }
00104       void setNumberOfMaximalIterations(int itermax_) {
00105         itermax = itermax_;
00106       }
00107       double getTolerance() {
00108         return tol;
00109       }
00110       void setTolerance(double tol_) {
00111         tol = tol_;
00112       }
00113       /*******************/
00114 
00115       fmatvec::Vec solve(const fmatvec::Vec &initialGuess);
00116 
00117     private:
00121       Function<fmatvec::Vec(fmatvec::Vec)> *function;
00122 
00126       double tol;
00127 
00131       int iter;
00132 
00136       double itermax;
00137 
00141       std::vector<double> norms;
00142 
00146       int info;
00147   };
00148 
00154   class NewtonMethod {
00155     public:
00156       /*
00157        * \brief constructor
00158        * \param root function
00159        * \param Jacobian matrix
00160        */
00161       NewtonMethod(Function<double(double)> *fct_, Function<double(double)> *jac_=0);
00162 
00163       /* GETTER / SETTER */
00164       int getNumberOfIterations() const { return iter; }
00165       int getInfo() const { return info; }
00166       void setMaximumNumberOfIterations(int itmax_) { itmax = itmax_; }
00167       void setMaximumDampingSteps(int kmax_) { kmax = kmax_; }
00168       void setTolerance(double tol_) { tol = tol_; }
00169       /***************************************************/
00170 
00175       double solve(const double &x);
00176 
00177     private:
00181       Function<double(double)> *fct;
00182 
00186       Function<double(double)> *jac;
00187 
00191       int itmax, iter, kmax, info;
00192 
00196       double tol;
00197   };
00198 
00204   class MultiDimNewtonMethod {
00205     public:
00206       /*
00207        * \brief constructor
00208        * \param root function
00209        * \param Jacobian matrix
00210        */
00211       MultiDimNewtonMethod(Function<fmatvec::Vec(fmatvec::Vec)> *fct_, Function<fmatvec::SqrMat(fmatvec::Vec)> *jac_=0);
00212 
00213       /* GETTER / SETTER */
00214       int getNumberOfIterations() const { return iter; }
00215       int getNumberOfMaximalIterations() const { return itmax; }
00216       int getInfo() const { return info; }
00217       std::vector<double> getNorms() { return norms; }
00218       void setMaximumNumberOfIterations(int itmax_) { itmax = itmax_; }
00219       void setMaximumDampingSteps(int kmax_) { kmax = kmax_; }
00220       void setTolerance(double tol_) { tol = tol_; }
00221       void setLinearAlgebra(int linAlg_) { linAlg = linAlg_; }
00222       /***************************************************/
00223 
00228       fmatvec::Vec solve(const fmatvec::Vec &x);
00229 
00230     private:
00234       Function<fmatvec::Vec(fmatvec::Vec)> *fct;
00235 
00239       Function<fmatvec::SqrMat(fmatvec::Vec)> *jac;
00240 
00244       int itmax, iter, kmax, info;
00245 
00249       std::vector<double> norms;
00250 
00254       double tol;
00255 
00256       int linAlg;
00257   };
00258   
00259 }
00260 
00261 #endif /* NONLINEAR_ALGEBRA_H_ */
00262