mbsim  4.0.0
MBSim Kernel
criteria_functions.h
1/* Copyright (C) 2004-2012 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 NUMERICSCRITERIAFUNCTIONS_H_
21#define NUMERICSCRITERIAFUNCTIONS_H_
22
23#include <fmatvec/fmatvec.h>
24#include <mbsim/functions/function.h>
25
26#include <map>
27
28namespace MBSim {
29
33 class CriteriaFunction : public Function<int(fmatvec::Vec)> {
34
35 public:
40
45
46 /* GETTER / SETTER*/
47 void setFunction(Function<fmatvec::Vec(fmatvec::Vec)> *function_) {
48 function = function_;
49 }
50 /*****************/
51
61 int operator ()(const fmatvec::Vec & vector) override = 0;
62
66 virtual void clear() = 0;
67
71 virtual bool isBetter(const fmatvec::Vec & vector, const fmatvec::Vec & fVal = fmatvec::Vec(0,fmatvec::NONINIT)) = 0;
72
73 protected:
77 Function<fmatvec::Vec(fmatvec::Vec)> *function{nullptr};
78
79 };
80
85
86 public:
90 GlobalCriteriaFunction(const double & tolerance_ = 1e-10);
91
96
97 /* INHERITED INTERFACE */
98 int operator ()(const fmatvec::Vec & vector) override;
99 bool isBetter(const fmatvec::Vec & vector, const fmatvec::Vec & fVal = fmatvec::Vec(0,fmatvec::NONINIT)) override;
100 void clear() override;
101 /*END - INHERITED INTERFACE*/
102
103 const std::vector<double> & getResults() {
104 return criteriaResults;
105 }
106
107 void setTolerance(double tol) {
108 tolerance = tol;
109 }
110
111 protected:
112 /*INHERITED INTERFACE*/
113 virtual double computeResults(const fmatvec::Vec & x, const fmatvec::Vec & fVal = fmatvec::Vec(0,fmatvec::NONINIT)) = 0;
114 /********************/
115
119 double tolerance;
120
124 std::vector<double> criteriaResults;
125 };
126
131
132 public:
136 LocalCriteriaFunction(std::map<fmatvec::RangeV, double> tolerances_);
137
142
143 /* INHERITED INTERFACE */
144 int operator ()(const fmatvec::Vec & vector) override;
145 bool isBetter(const fmatvec::Vec & vector, const fmatvec::Vec & fVal = fmatvec::Vec(0,fmatvec::NONINIT)) override;
146 void clear() override;
147 /*END - INHERITED INTERFACE*/
148
149 virtual void setTolerances(const std::map<fmatvec::RangeV, double> & tolerances_) {
150 tolerances = tolerances_;
151 }
152
153 protected:
154 virtual std::vector<double> computeResults(const fmatvec::Vec & x, const fmatvec::Vec & fVal = fmatvec::Vec(0,fmatvec::NONINIT)) = 0;
155
156 /*
157 * \brief saves the tolerance for a specified index sets
158 */
159 std::map<fmatvec::RangeV, double> tolerances;
160
164 std::vector<std::vector<double>> criteriaResults;
165 };
166
171
172 public:
176 GlobalResidualCriteriaFunction(const double & tolerance_ = 1e-10);
177
182
183 protected:
184 /* INHERITED INTERFACE */
185 double computeResults(const fmatvec::Vec & x, const fmatvec::Vec & fVal = fmatvec::Vec(0,fmatvec::NONINIT)) override;
186 /*END - INHERITED INTERFACE*/
187 };
188
193
194 public:
198 LocalResidualCriteriaFunction(const std::map<fmatvec::RangeV, double> & tolerances_);
199
204
205 protected:
206
207 std::vector<double> computeResults(const fmatvec::Vec & x, const fmatvec::Vec & fVal = fmatvec::Vec(0,fmatvec::NONINIT)) override;
208 };
209
214 public:
218 GlobalShiftCriteriaFunction(const double & tolerance_ = 1e-10);
219
224
225 virtual fmatvec::Vec getLastPoint() {
226 return lastPoint;
227 }
228
229 protected:
230 /* INHERITED INTERFACE */
231 double computeResults(const fmatvec::Vec & x, const fmatvec::Vec & fVal = fmatvec::Vec(0,fmatvec::NONINIT)) override;
232 /*END - INHERITED INTERFACE*/
233
237 fmatvec::Vec lastPoint;
238
239 };
240
245
246 public:
250 LocalShiftCriteriaFunction(const std::map<fmatvec::RangeV, double> & tolerances_);
251
256
257 virtual fmatvec::Vec getLastPoint() {
258 return lastPoint;
259 }
260
261 protected:
262 std::vector<double> computeResults(const fmatvec::Vec & x, const fmatvec::Vec & fVal = fmatvec::Vec(0,fmatvec::NONINIT)) override;
263
267 fmatvec::Vec lastPoint;
268 };
269
270 inline CriteriaFunction::~CriteriaFunction()= default;
277}
278#endif //NUMERICSCRITERIAFUNCTIONS_H_
Mother class for different criterias that are fulfilled or not.
Definition: criteria_functions.h:33
virtual bool isBetter(const fmatvec::Vec &vector, const fmatvec::Vec &fVal=fmatvec::Vec(0, fmatvec::NONINIT))=0
compares the result of given vector with the last result and returns if it got better (for damping)
CriteriaFunction()
Constructor.
Definition: criteria_functions.cc:31
int operator()(const fmatvec::Vec &vector) override=0
computes the criteria
~CriteriaFunction() override
Destructor.
virtual void clear()=0
deletes the list of criteria results
Function< fmatvec::Vec(fmatvec::Vec)> * function
function that computes the values
Definition: criteria_functions.h:77
Definition: function.h:53
This criteria function class applies the infinity norm globally for complete vectors thus it has one ...
Definition: criteria_functions.h:84
~GlobalCriteriaFunction() override
Destructor.
void clear() override
deletes the list of criteria results
Definition: criteria_functions.cc:63
int operator()(const fmatvec::Vec &vector) override
computes the criteria
Definition: criteria_functions.cc:39
double tolerance
tolerance value for the criteria results
Definition: criteria_functions.h:119
GlobalCriteriaFunction(const double &tolerance_=1e-10)
Constructor.
Definition: criteria_functions.cc:35
bool isBetter(const fmatvec::Vec &vector, const fmatvec::Vec &fVal=fmatvec::Vec(0, fmatvec::NONINIT)) override
compares the result of given vector with the last result and returns if it got better (for damping)
Definition: criteria_functions.cc:52
std::vector< double > criteriaResults
saves the results of the criteria
Definition: criteria_functions.h:124
This criteria function class applies the infinity norm globally on the complete vector and compares i...
Definition: criteria_functions.h:170
GlobalResidualCriteriaFunction(const double &tolerance_=1e-10)
Constructor.
Definition: criteria_functions.cc:106
~GlobalResidualCriteriaFunction() override
Destructor.
This criteria function class applies the infinity norm globally on the difference between the complet...
Definition: criteria_functions.h:213
~GlobalShiftCriteriaFunction() override
Destructor.
fmatvec::Vec lastPoint
save the point of the last step for comparison
Definition: criteria_functions.h:237
GlobalShiftCriteriaFunction(const double &tolerance_=1e-10)
Constructor.
Definition: criteria_functions.cc:133
This criteria function class applies the infinity norm locally for arbitrary combinations of sub-vect...
Definition: criteria_functions.h:130
LocalCriteriaFunction(std::map< fmatvec::RangeV, double > tolerances_)
Constructor.
Definition: criteria_functions.cc:67
bool isBetter(const fmatvec::Vec &vector, const fmatvec::Vec &fVal=fmatvec::Vec(0, fmatvec::NONINIT)) override
compares the result of given vector with the last result and returns if it got better (for damping)
Definition: criteria_functions.cc:88
int operator()(const fmatvec::Vec &vector) override
computes the criteria
Definition: criteria_functions.cc:71
~LocalCriteriaFunction() override
Destructor.
std::vector< std::vector< double > > criteriaResults
saves the results of the criteria for each index set and each operator step
Definition: criteria_functions.h:164
void clear() override
deletes the list of criteria results
Definition: criteria_functions.cc:102
This criteria function class applies the infinity norm on single indices sets (each with another tole...
Definition: criteria_functions.h:192
LocalResidualCriteriaFunction(const std::map< fmatvec::RangeV, double > &tolerances_)
Constructor.
Definition: criteria_functions.cc:117
~LocalResidualCriteriaFunction() override
Destructor.
This criteria function class applies the infinity norm on single indices sets (each with another tole...
Definition: criteria_functions.h:244
fmatvec::Vec lastPoint
save the point of the last step for comparison
Definition: criteria_functions.h:267
LocalShiftCriteriaFunction(const std::map< fmatvec::RangeV, double > &tolerances_)
Constructor.
Definition: criteria_functions.cc:152
~LocalShiftCriteriaFunction() override
Destructor.
namespace MBSim
Definition: bilateral_constraint.cc:30