MBSim

Project Page
nonlinear_algebra.h
1 /* Copyright (C) 2004-2009 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: martin.o.foerg@googlemail.com
18  */
19 
20 #ifndef NONLINEAR_ALGEBRA_H_
21 #define NONLINEAR_ALGEBRA_H_
22 
23 #include "mbsim/utils/function.h"
24 #include "fmatvec.h"
25 
26 namespace MBSim {
27 
28  enum SolverType {
29  RegulaFalsiSolver, FixPointIterationSolver, NewtonMethodSolver
30  };
31 
37  class RegulaFalsi {
38  public:
39  /*
40  * \brief constructor
41  * \param root function
42  */
44 
45  /* GETTER / SETTER */
46  int getNumberOfIterations() const { return it; };
47  int getInfo() const { return info; };
48  void setMaximumNumberOfIterations(int itmax_) { itmax = itmax_; }
49  void setTolerance(double tol_) { tol = tol_; }
50  /***************************************************/
51 
57  double solve(double a, double b);
58 
59  private:
64 
68  int itmax, it, info;
69 
73  double tol;
74  };
75 
82  public:
83  /*
84  * \brief constructor
85  * \param fct pointer to used fix-point-function
86  */
88 
89  /* GETTER / SETTER */
90  /*
91  * \brief returns info of iteration progress
92  * info == 0 : a solution has been found
93  * info == -1: no converge
94  * info == 1: process (seems to) converge but hasn't finished
95  */
96  int getInfo() {
97  return info;
98  }
99  std::vector<double> getNorms() {
100  return norms;
101  }
102  double getNumberOfIterations() {
103  return iter;
104  }
105  double getNumberOfMaximalIterations() {
106  return itermax;
107  }
108  void setNumberOfMaximalIterations(int itermax_) {
109  itermax = itermax_;
110  }
111  double getTolerance() {
112  return tol;
113  }
114  void setTolerance(double tol_) {
115  tol = tol_;
116  }
117  /*******************/
118 
119  fmatvec::Vec solve(const fmatvec::Vec &initialGuess);
120 
121  private:
126 
130  double tol;
131 
135  int iter;
136 
140  double itermax;
141 
145  std::vector<double> norms;
146 
150  int info;
151  };
152 
158  class NewtonMethod {
159  public:
160  /*
161  * \brief constructor
162  * \param root function
163  * \param Jacobian matrix
164  */
166 
167  /* GETTER / SETTER */
168  int getNumberOfIterations() const { return iter; }
169  int getInfo() const { return info; }
170  void setMaximumNumberOfIterations(int itmax_) { itmax = itmax_; }
171  void setMaximumDampingSteps(int kmax_) { kmax = kmax_; }
172  void setTolerance(double tol_) { tol = tol_; }
173  /***************************************************/
174 
179  double solve(const double &x);
180 
181  private:
186 
191 
195  int itmax, iter, kmax, info;
196 
200  double tol;
201  };
202 
209  public:
210  /*
211  * \brief constructor
212  * \param root function
213  * \param Jacobian matrix
214  */
216 
217  /* GETTER / SETTER */
218  int getNumberOfIterations() const { return iter; }
219  int getNumberOfMaximalIterations() const { return itmax; }
220  int getInfo() const { return info; }
221  std::vector<double> getNorms() { return norms; }
222  void setMaximumNumberOfIterations(int itmax_) { itmax = itmax_; }
223  void setMaximumDampingSteps(int kmax_) { kmax = kmax_; }
224  void setTolerance(double tol_) { tol = tol_; }
225  /***************************************************/
226 
231  fmatvec::Vec solve(const fmatvec::Vec &x);
232 
233  private:
238 
243 
247  int itmax, iter, kmax, info;
248 
252  std::vector<double> norms;
253 
257  double tol;
258  };
259 
260 }
261 
262 #endif /* NONLINEAR_ALGEBRA_H_ */
263