replaced abort() with EG_BUG
[engrid.git] / src / optimisation.h
blob7586580ce8a6adfd29d73b62e0b980263c88d078
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008,2009 Oliver Gloth +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #ifndef optimisation_H
24 #define optimisation_H
26 class Optimisation;
27 class ErrorFunction;
29 #include "engrid.h"
31 class ErrorFunction
34 private: // attributes
36 double m_Weighting1;
37 double m_Weighting2;
38 double m_XSwitch;
39 double m_Exponent;
40 double m_MaxErr;
42 public: // methods
44 ErrorFunction();
45 void set(QString settings_txt);
46 double operator()(double x);
47 double maxError() { return m_MaxErr; }
48 void reset() { m_MaxErr = 0; }
49 bool active() { return (m_Weighting1 > 1e-10) || (m_Weighting2 > 1e-10); }
54 class Optimisation
57 protected: // attributes
59 double ***F;
60 double Dx;
61 double Dy;
62 double Dz;
63 vec3_t grad_f;
64 mat3_t J;
66 protected: // methods
68 virtual double func(vec3_t x) = 0;
69 virtual double func(double x, double y, double z) { return func(vec3_t(x,y,z)); };
70 virtual void computeDerivatives(vec3_t x);
72 void getErrSet(QString group, QString key, double w1, double w2, double e, double s, ErrorFunction &err_func);
73 double angleX(const vec3_t &v1, const vec3_t &v2);
75 public: // methods
77 Optimisation();
79 vec3_t optimise(vec3_t x);
80 void setDeltas(double d) { Dx = d; Dy = d; Dz = d; };
81 void setDx(double d) { Dx = d; };
82 void setDy(double d) { Dy = d; };
83 void setDz(double d) { Dz = d; };
87 #endif