fixed edge display for volume cells
[engrid-github.git] / src / libengrid / optimisation.h
blob7c2ace9d160cd305f8076ae90cb1c83eab55166e
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
11 // + +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
16 // + +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #ifndef optimisation_H
22 #define optimisation_H
24 class Optimisation;
25 class ErrorFunction;
27 #include "engrid.h"
29 class ErrorFunction
32 private: // attributes
34 double m_Err0;
35 double m_ErrS;
36 double m_XS;
37 double m_Exp;
38 double m_MaxErr;
39 double m_TotalError;
40 double m_AverageError;
41 bool m_Active;
42 QString m_Name;
43 int m_NumTotalCalls;
44 int m_NumCalls;
46 public: // methods
48 ErrorFunction();
49 void set(QString settings_txt);
50 void setName(QString name) { m_Name = name; }
51 QString name() { return m_Name; }
52 double operator()(double x);
53 double maxError() { return m_MaxErr; }
54 void reset(bool reset_average);
55 bool active() { return m_Active && (m_Err0 > 1e-10); }
56 double averageError();
57 double totalError();
58 void activate() { m_Active = true; }
59 void deactivate() { m_Active = false; }
64 class Optimisation
67 protected: // attributes
69 double ***F;
70 double Dx;
71 double Dy;
72 double Dz;
73 vec3_t grad_f;
74 mat3_t J;
75 QList<ErrorFunction*> m_ErrorFunctions;
77 protected: // methods
79 virtual double func(vec3_t x) = 0;
80 virtual double func(double x, double y, double z) { return func(vec3_t(x,y,z)); }
81 virtual void computeDerivatives(vec3_t x);
83 void getErrSet(QString group, QString key, double err0, double xs, ErrorFunction* err_func);
84 double angleX(const vec3_t &v1, const vec3_t &v2);
85 void resetErrorFunctions(bool reset_average = false);
86 double totalError();
88 public: // methods
90 Optimisation();
92 virtual vec3_t optimise(vec3_t x);
93 void setDeltas(double d) { Dx = d; Dy = d; Dz = d; }
94 void setDx(double d) { Dx = d; }
95 void setDy(double d) { Dy = d; }
96 void setDz(double d) { Dz = d; }
97 void printErrors();
101 #endif