Line data Source code
1 : /*
2 : * newtonUpdaterGeneric.h
3 : *
4 : * Created on: 28.07.2021
5 : * Author: Markus Knodel
6 : */
7 :
8 : #ifndef UGCORE_UGBASE_LIB_DISC_OPERATOR_NON_LINEAR_OPERATOR_NEWTON_SOLVER_NEWTONUPDATERGENERIC_H_
9 : #define UGCORE_UGBASE_LIB_DISC_OPERATOR_NON_LINEAR_OPERATOR_NEWTON_SOLVER_NEWTONUPDATERGENERIC_H_
10 :
11 : #include <ostream>
12 : #include <string>
13 : #include <vector>
14 : #include <cmath>
15 : #include <sstream>
16 : #include <type_traits>
17 :
18 : #include "common/common.h"
19 :
20 : namespace ug
21 : {
22 :
23 : template <typename TVector>
24 0 : class NewtonUpdaterGeneric
25 : {
26 :
27 : public:
28 :
29 0 : virtual ~NewtonUpdaterGeneric() {};
30 :
31 :
32 : using vector_type = TVector;
33 :
34 0 : virtual bool updateSolution( vector_type & sol, vector_type const & corr, bool signNegative = true )
35 : {
36 0 : if( signNegative )
37 0 : sol -= corr;
38 : else
39 0 : sol += corr;
40 :
41 0 : return true;
42 : // return (*this)(sol, 1, sol, - 1, corr );
43 : }
44 :
45 :
46 0 : virtual bool updateSolution( vector_type & solNew, number scaleOldSol, vector_type const & solOld,
47 : number scaleCorr, vector_type const & corr )
48 : {
49 0 : VecScaleAdd(solNew, scaleOldSol, solOld, scaleCorr, corr);
50 :
51 0 : return true;
52 :
53 : }
54 :
55 0 : virtual bool resetSolution( vector_type & resettedSol, vector_type const & oldSol )
56 : {
57 0 : resettedSol = oldSol;
58 :
59 : // reset not only u, but also internal variables if available!!!!!
60 :
61 0 : return true;
62 : }
63 :
64 0 : virtual bool tellAndFixUpdateEvents( vector_type const & sol )
65 : {
66 0 : return true;
67 : }
68 :
69 : };
70 :
71 : }
72 :
73 :
74 : #endif /* UGCORE_UGBASE_LIB_DISC_OPERATOR_NON_LINEAR_OPERATOR_NEWTON_SOLVER_NEWTONUPDATERGENERIC_H_ */
75 :
76 :
77 : // muss noch im Newton und line search irgendwie automatisch so initialisiert werden, aber auf User-Wunsch ueberschrieben
78 : // mit Hilfe von gettern und settern, damit entweder der line search oder der Newton selber sich das vom anderen holen koennen
79 : // und dann muss es soweit registriert werden, wie es noetig ist, damit man von aussen zu greifen kann
80 : // und die abgeleiteten Klassen brauchen ggf einen Konstruktor und so weiter
81 : /// Vector type
82 : //typedef typename TAlgebra::vector_type vector_type;
83 :
84 : // using vector_type = TVector; // typename TAlgebra::vector_type;
85 : // using vec_typ_val_typ = typename vector_type::value_type;
86 :
87 : //typedef TVector vector_type; // typename TAlgebra::vector_type;
88 : //typedef typename vector_type::value_type vec_typ_val_typ;
89 : //typedef typename vector_type::value_type value_type;
90 :
91 : // template <typename VecTyp> //, typename ScalTyp >
92 : // template <typename ScalTyp> //, typename ScalTyp >
93 : // bool updateNewton( vector_type & solNew, value_type scaleOldSol, vector_type const & solOld,
94 : // value_type scaleCorr, vector_type const & corr )
95 : // bool updateNewton( VecTyp & solNew, ScalTyp scaleOldSol, VecTyp const & solOld,
96 : // ScalTyp scaleCorr, VecTyp const & corr )
97 : // bool updateNewton( VecTyp & solNew, typename VecTyp::value_type scaleOldSol, VecTyp const & solOld,
98 : // typename VecTyp::value_type scaleCorr, VecTyp const & corr )
99 : // bool updateNewton( vector_type & solNew, ScalTyp scaleOldSol, vector_type const & solOld,
100 : // ScalTyp scaleCorr, vector_type const & corr )
101 : // static_assert( std::is_same<ScalTyp, double>::value, "is ScalType double" );
102 : //
103 : // static_assert( !std::is_same<ScalTyp, number>::value, "! is ScalType number" );
104 : //
105 : // static_assert( std::is_same<ScalTyp, value_type>::value, "is it value_type" );
106 : //
107 : // static_assert( std::is_same<double, value_type>::value, "is value_type double" );
108 : //
109 : // static_assert( std::is_same<number, value_type>::value, "is value_type number" );
110 :
111 : // Standard: try on line u := u - lambda*p
112 : // VecScaleAdd(u, 1.0, u, (-1)*lambda, p);
113 :
114 : // typedef typename vector_type::size_type size_type;
115 : //// using size_type = typename vector_type::size_type;
116 : //
117 : // for(size_type i = 0; i < solNew.size(); ++i)
118 : // {
119 : // solNew[i] = scaleOldSol * solOld[i] + scaleCorr * corr[i];
120 : // }
|