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
28 namespace MBSim {
29
33 class CriteriaFunction : public Function<int(fmatvec::Vec)> {
34
35 public:
39 CriteriaFunction();
40
44 ~CriteriaFunction() override;
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
84 class GlobalCriteriaFunction : public CriteriaFunction {
85
86 public:
90 GlobalCriteriaFunction(const double & tolerance_ = 1e-10);
91
95 ~GlobalCriteriaFunction() override;
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
130 class LocalCriteriaFunction : public CriteriaFunction {
131
132 public:
136 LocalCriteriaFunction(std::map<fmatvec::RangeV, double> tolerances_);
137
141 ~LocalCriteriaFunction() override;
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
170 class GlobalResidualCriteriaFunction : public GlobalCriteriaFunction {
171
172 public:
176 GlobalResidualCriteriaFunction(const double & tolerance_ = 1e-10);
177
181 ~GlobalResidualCriteriaFunction() override;
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
192 class LocalResidualCriteriaFunction : public LocalCriteriaFunction {
193
194 public:
198 LocalResidualCriteriaFunction(const std::map<fmatvec::RangeV, double> & tolerances_);
199
203 ~LocalResidualCriteriaFunction() override;
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
213 class GlobalShiftCriteriaFunction : public GlobalCriteriaFunction {
214 public:
218 GlobalShiftCriteriaFunction(const double & tolerance_ = 1e-10);
219
223 ~GlobalShiftCriteriaFunction() override;
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
244 class LocalShiftCriteriaFunction : public LocalCriteriaFunction {
245
246 public:
250 LocalShiftCriteriaFunction(const std::map<fmatvec::RangeV, double> & tolerances_);
251
255 ~LocalShiftCriteriaFunction() override;
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;
271 inline GlobalCriteriaFunction::~GlobalCriteriaFunction()= default;
272 inline LocalCriteriaFunction::~LocalCriteriaFunction()= default;
273 inline GlobalResidualCriteriaFunction::~GlobalResidualCriteriaFunction() = default;
274 inline GlobalShiftCriteriaFunction::~GlobalShiftCriteriaFunction() = default;
275 inline LocalResidualCriteriaFunction::~LocalResidualCriteriaFunction() = default;
276 inline LocalShiftCriteriaFunction::~LocalShiftCriteriaFunction() = default;
277 }
278 #endif //NUMERICSCRITERIAFUNCTIONS_H_
MBSim::LocalCriteriaFunction::operator()
int operator()(const fmatvec::Vec &vector) override
computes the criteria
Definition: criteria_functions.cc:71
MBSim::GlobalResidualCriteriaFunction
This criteria function class applies the infinity norm globally on the complete vector and compares i...
Definition: criteria_functions.h:170
MBSim::CriteriaFunction::CriteriaFunction
CriteriaFunction()
Constructor.
Definition: criteria_functions.cc:31
MBSim::GlobalShiftCriteriaFunction::lastPoint
fmatvec::Vec lastPoint
save the point of the last step for comparison
Definition: criteria_functions.h:237
MBSim::LocalResidualCriteriaFunction::~LocalResidualCriteriaFunction
~LocalResidualCriteriaFunction() override
Destructor.
MBSim::GlobalShiftCriteriaFunction
This criteria function class applies the infinity norm globally on the difference between the complet...
Definition: criteria_functions.h:213
MBSim::GlobalCriteriaFunction::criteriaResults
std::vector< double > criteriaResults
saves the results of the criteria
Definition: criteria_functions.h:124
MBSim::CriteriaFunction::clear
virtual void clear()=0
deletes the list of criteria results
MBSim::GlobalCriteriaFunction
This criteria function class applies the infinity norm globally for complete vectors thus it has one ...
Definition: criteria_functions.h:84
MBSim::LocalShiftCriteriaFunction::lastPoint
fmatvec::Vec lastPoint
save the point of the last step for comparison
Definition: criteria_functions.h:267
MBSim::GlobalCriteriaFunction::~GlobalCriteriaFunction
~GlobalCriteriaFunction() override
Destructor.
MBSim::GlobalShiftCriteriaFunction::GlobalShiftCriteriaFunction
GlobalShiftCriteriaFunction(const double &tolerance_=1e-10)
Constructor.
Definition: criteria_functions.cc:133
MBSim::GlobalResidualCriteriaFunction::GlobalResidualCriteriaFunction
GlobalResidualCriteriaFunction(const double &tolerance_=1e-10)
Constructor.
Definition: criteria_functions.cc:106
MBSim::CriteriaFunction::operator()
int operator()(const fmatvec::Vec &vector) override=0
computes the criteria
MBSim::LocalResidualCriteriaFunction
This criteria function class applies the infinity norm on single indices sets (each with another tole...
Definition: criteria_functions.h:192
MBSim::GlobalCriteriaFunction::tolerance
double tolerance
tolerance value for the criteria results
Definition: criteria_functions.h:119
MBSim::CriteriaFunction
Mother class for different criterias that are fulfilled or not.
Definition: criteria_functions.h:33
MBSim::LocalShiftCriteriaFunction
This criteria function class applies the infinity norm on single indices sets (each with another tole...
Definition: criteria_functions.h:244
MBSim::Function
Definition: contact_kinematics.h:32
MBSim::CriteriaFunction::~CriteriaFunction
~CriteriaFunction() override
Destructor.
MBSim::LocalCriteriaFunction
This criteria function class applies the infinity norm locally for arbitrary combinations of sub-vect...
Definition: criteria_functions.h:130
MBSim::GlobalCriteriaFunction::clear
void clear() override
deletes the list of criteria results
Definition: criteria_functions.cc:63
MBSim::LocalResidualCriteriaFunction::LocalResidualCriteriaFunction
LocalResidualCriteriaFunction(const std::map< fmatvec::RangeV, double > &tolerances_)
Constructor.
Definition: criteria_functions.cc:117
MBSim::GlobalCriteriaFunction::isBetter
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
MBSim::CriteriaFunction::isBetter
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)
MBSim::LocalCriteriaFunction::clear
void clear() override
deletes the list of criteria results
Definition: criteria_functions.cc:102
MBSim::GlobalCriteriaFunction::operator()
int operator()(const fmatvec::Vec &vector) override
computes the criteria
Definition: criteria_functions.cc:39
MBSim::GlobalResidualCriteriaFunction::~GlobalResidualCriteriaFunction
~GlobalResidualCriteriaFunction() override
Destructor.
MBSim::GlobalCriteriaFunction::GlobalCriteriaFunction
GlobalCriteriaFunction(const double &tolerance_=1e-10)
Constructor.
Definition: criteria_functions.cc:35
MBSim::LocalShiftCriteriaFunction::~LocalShiftCriteriaFunction
~LocalShiftCriteriaFunction() override
Destructor.
MBSim::LocalCriteriaFunction::~LocalCriteriaFunction
~LocalCriteriaFunction() override
Destructor.
MBSim::LocalCriteriaFunction::criteriaResults
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
MBSim::LocalShiftCriteriaFunction::LocalShiftCriteriaFunction
LocalShiftCriteriaFunction(const std::map< fmatvec::RangeV, double > &tolerances_)
Constructor.
Definition: criteria_functions.cc:152
MBSim::LocalCriteriaFunction::isBetter
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
MBSim::GlobalShiftCriteriaFunction::~GlobalShiftCriteriaFunction
~GlobalShiftCriteriaFunction() override
Destructor.
MBSim::LocalCriteriaFunction::LocalCriteriaFunction
LocalCriteriaFunction(std::map< fmatvec::RangeV, double > tolerances_)
Constructor.
Definition: criteria_functions.cc:67
MBSim
namespace MBSim
Definition: bilateral_constraint.cc:30