mbsim 4.0.0 MBSim Kernel

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 "fmatvec/fmatvec.h"
24 #include "mbsim/functions/function.h"
25
26 namespace MBSim {
27
33 class RegulaFalsi {
34 public:
35 /*
36 * \brief constructor
37 * \param root function
38 */
39 RegulaFalsi(Function<double(double)> *f);
40
41 /* GETTER / SETTER */
42 int getNumberOfIterations() const { return it; };
43 int getInfo() const { return info; };
44 void setMaximumNumberOfIterations(int itmax_) { itmax = itmax_; }
45 void setTolerance(double tol_) { tol = tol_; }
46 /***************************************************/
47
53 double solve(double a, double b);
54
55 private:
59 Function<double(double)> *func;
60
64 int itmax, it, info;
65
69 double tol;
70 };
71
77 class MultiDimFixPointIteration {
78 public:
79 /*
80 * \brief constructor
81 * \param fct pointer to used fix-point-function
82 */
83 MultiDimFixPointIteration(Function<fmatvec::Vec(fmatvec::Vec)> *function_);
84
85 /* GETTER / SETTER */
86 /*
87 * \brief returns info of iteration progress
88 * info == 0 : a solution has been found
89 * info == -1: no converge
90 * info == 1: process (seems to) converge but hasn't finished
91 */
92 int getInfo() {
93 return info;
94 }
95 std::vector<double> getNorms() {
96 return norms;
97 }
98 double getNumberOfIterations() {
99 return iter;
100 }
101 double getNumberOfMaximalIterations() {
102 return itermax;
103 }
104 void setNumberOfMaximalIterations(int itermax_) {
105 itermax = itermax_;
106 }
107 double getTolerance() {
108 return tol;
109 }
110 void setTolerance(double tol_) {
111 tol = tol_;
112 }
113 /*******************/
114
115 fmatvec::Vec solve(const fmatvec::Vec &initialGuess);
116
117 private:
121 Function<fmatvec::Vec(fmatvec::Vec)> *function;
122
126 double tol;
127
131 int iter;
132
136 double itermax;
137
141 std::vector<double> norms;
142
146 int info;
147 };
148
154 class NewtonMethod {
155 public:
156 /*
157 * \brief constructor
158 * \param root function
159 * \param Jacobian matrix
160 */
161 NewtonMethod(Function<double(double)> *fct_, Function<double(double)> *jac_=nullptr);
162
163 /* GETTER / SETTER */
164 int getNumberOfIterations() const { return iter; }
165 int getInfo() const { return info; }
166 void setMaximumNumberOfIterations(int itmax_) { itmax = itmax_; }
167 void setMaximumDampingSteps(int kmax_) { kmax = kmax_; }
168 void setTolerance(double tol_) { tol = tol_; }
169 /***************************************************/
170
175 double solve(const double &x);
176
177 private:
181 Function<double(double)> *fct;
182
186 Function<double(double)> *jac;
187
191 int itmax, iter, kmax, info;
192
196 double tol;
197 };
198
204 class MultiDimNewtonMethod {
205 public:
206 /*
207 * \brief constructor
208 * \param root function
209 * \param Jacobian matrix
210 */
211 MultiDimNewtonMethod(Function<fmatvec::Vec(fmatvec::Vec)> *fct_, Function<fmatvec::SqrMat(fmatvec::Vec)> *jac_=nullptr);
212
213 /* GETTER / SETTER */
214 int getNumberOfIterations() const { return iter; }
215 int getNumberOfMaximalIterations() const { return itmax; }
216 int getInfo() const { return info; }
217 std::vector<double> getNorms() { return norms; }
218 void setMaximumNumberOfIterations(int itmax_) { itmax = itmax_; }
219 void setMaximumDampingSteps(int kmax_) { kmax = kmax_; }
220 void setTolerance(double tol_) { tol = tol_; }
221 void setLinearAlgebra(int linAlg_) { linAlg = linAlg_; }
222 /***************************************************/
223
228 fmatvec::Vec solve(const fmatvec::Vec &x);
229
230 private:
234 Function<fmatvec::Vec(fmatvec::Vec)> *fct;
235
239 Function<fmatvec::SqrMat(fmatvec::Vec)> *jac;
240
244 int itmax, iter, kmax, info;
245
249 std::vector<double> norms;
250
254 double tol;
255
256 int linAlg;
257 };
258
259 }
260
261 #endif /* NONLINEAR_ALGEBRA_H_ */
262
MBSim::MultiDimFixPointIteration::iter
int iter
number of iterations
Definition: nonlinear_algebra.h:131
MBSim::NewtonMethod
Newton method for one-dimensional root-finding.
Definition: nonlinear_algebra.h:154
MBSim::MultiDimNewtonMethod::jac
Function< fmatvec::SqrMat(fmatvec::Vec)> * jac
Jacobian matrix.
Definition: nonlinear_algebra.h:239
MBSim::MultiDimFixPointIteration::norms
std::vector< double > norms
vector of norms
Definition: nonlinear_algebra.h:141
MBSim::NewtonMethod::solve
double solve(const double &x)
solve nonlinear root function
Definition: nonlinear_algebra.cc:115
MBSim::RegulaFalsi::itmax
int itmax
maximum number of iterations, actual number of iterations, information about success (0 = ok,...
Definition: nonlinear_algebra.h:64
MBSim::RegulaFalsi::func
Function< double(double)> * func
root function
Definition: nonlinear_algebra.h:59
MBSim::MultiDimNewtonMethod::itmax
int itmax
maximum number of iterations, actual number of iterations, maximum number of damping steps,...
Definition: nonlinear_algebra.h:244
MBSim::NewtonMethod::itmax
int itmax
maximum number of iterations, actual number of iterations, maximum number of damping steps,...
Definition: nonlinear_algebra.h:191
MBSim::MultiDimFixPointIteration::info
int info
information variable about success of iteration
Definition: nonlinear_algebra.h:146
MBSim::MultiDimNewtonMethod::tol
double tol
tolerance
Definition: nonlinear_algebra.h:254
MBSim::RegulaFalsi::solve
double solve(double a, double b)
solve nonlinear root function
Definition: nonlinear_algebra.cc:34
MBSim::NewtonMethod::tol
double tol
tolerance
Definition: nonlinear_algebra.h:196
MBSim::MultiDimFixPointIteration::itermax
double itermax
maximal iterations
Definition: nonlinear_algebra.h:136
MBSim::RegulaFalsi
Regular Falsi for one-dimensional root-finding.
Definition: nonlinear_algebra.h:33
MBSim::MultiDimNewtonMethod
Newton method for multi-dimensional root-finding.
Definition: nonlinear_algebra.h:204
MBSim::MultiDimNewtonMethod::solve
fmatvec::Vec solve(const fmatvec::Vec &x)
solve nonlinear root function
Definition: nonlinear_algebra.cc:180
MBSim::Function
Definition: contact_kinematics.h:32
MBSim::MultiDimFixPointIteration
FixpointIteration for multi-dimensional fixpoint-finding.
Definition: nonlinear_algebra.h:77
MBSim::MultiDimNewtonMethod::norms
std::vector< double > norms
vector of norms for each iteration step
Definition: nonlinear_algebra.h:249
MBSim::MultiDimNewtonMethod::fct
Function< fmatvec::Vec(fmatvec::Vec)> * fct
root function
Definition: nonlinear_algebra.h:234
MBSim::NewtonMethod::fct
Function< double(double)> * fct
root function
Definition: nonlinear_algebra.h:181
MBSim::MultiDimFixPointIteration::tol
double tol
tolerance
Definition: nonlinear_algebra.h:126
MBSim::RegulaFalsi::tol
double tol
tolerance
Definition: nonlinear_algebra.h:69
MBSim::NewtonMethod::jac
Function< double(double)> * jac
Jacobian matrix.
Definition: nonlinear_algebra.h:186
MBSim
namespace MBSim
Definition: bilateral_constraint.cc:30