newton.hh

Go to the documentation of this file.
1 
8 #ifndef newton_hh
9 #define newton_hh
10 
11 #include <type_traits>
12 #include "basics/debug.hh"
13 
14 #define NEWTON_CONST_D 0
15 
16 
17 #if defined(__clang__)
18 #include <functional>
19 #endif
20 
21 #if defined(__GNUC__)
22 #if __GNUC__ >= 7
23 #include <functional>
24 #endif
25 #endif
26 
27 namespace concepts
28 {
29  // ****************************************************** Newton **
30 
34  template<class F>
35  class Newton: public VecOperator<typename F::d_type >
36  {
37  public:
38 
39  typename F::d_type type;
40 
41 #include "basics/warnings/push.h"
52  Real tol = 1e-8, Real iterMax = 1000) :
53  VecOperator<typename F::d_type>(dimY, dimX), A_(A), JacA_(nullptr), definedJacA_(false), dx_(dx), dimY_(dimY), dimX_(dimX),
54  tol_(tol), iterMax_(iterMax), verbose_(false), linearSolver_(nullptr) {
55  DEBUGL(NEWTON_CONST_D, "Newton solver with implicit computation of the Jacobian built");
56  };
57 
68  uint dimX, Real tol = 1e-8, Real iterMax = 50) :
69  VecOperator<typename F::d_type>(dimY, dimX), A_(A), JacA_(&JacA), definedJacA_(true), dx_(0.), dimY_(dimY), dimX_(dimX),
70  tol_(tol), iterMax_(iterMax), verbose_(false), linearSolver_(nullptr) {
71  DEBUGL(NEWTON_CONST_D, "Newton solver with explicit Jacobian built");
72  };
73 #include "basics/warnings/pop.h"
74 
75  virtual ~Newton() {};
76 
77  virtual void show_messages();
78 
79  virtual void hide_messages();
80 
81  virtual void apply_(const Vector<typename F::d_type>& fncY,
83 
84  virtual void apply_();
85 
86  protected:
87 
88 #include "basics/warnings/push.h"
90 
92  std::function<Vector<typename F::d_type>(Vector<typename F::d_type>)>& A_;
93 
95  std::function<F(Vector<typename F::d_type>)>* JacA_;
96 
97 #include "basics/warnings/pop.h"
98 
101 
104 
106  uint dimY_;
107 
109  uint dimX_;
110 
113 
115  uint iterMax_;
116 
118  bool verbose_;
119 
121  std::unique_ptr<concepts::Operator<typename F::d_type> > linearSolver_;
122 
124  virtual void setLinearSolver_(F* Jacobian);
125 
126  };
127 }
128 
129 #endif
virtual void apply_()
Intrinsic application method without argument.
virtual ~Newton()
Definition: newton.hh:75
std::unique_ptr< concepts::Operator< typename F::d_type > > linearSolver_
Internal linear solver.
Definition: newton.hh:121
bool definedJacA_
Flag that states if the Jacobian matrix has been set.
Definition: newton.hh:100
uint dimX_
Size of the unknown.
Definition: newton.hh:109
virtual void setLinearSolver_(F *Jacobian)
Set linear solver.
virtual const uint dimX() const
Returns the size of the image space of the operator (number of rows of the corresponding matrix)
Definition: compositions.hh:93
#define DEBUGL(doit, msg)
uint dimY_
Size of the data.
Definition: newton.hh:106
virtual void show_messages()
std::function< F(Vector< typename F::d_type >)> * JacA_
Function that evaluates the Jacobian of matrix A applied to vector X.
Definition: newton.hh:95
std::function< Vector< typename F::d_type >Vector< typename F::d_type >)> & A_
Function that evaluates the matrix A applied to vector X.
Definition: newton.hh:92
Real tol_
Tolerance for the functional.
Definition: newton.hh:112
Newton(std::function< Vector< typename F::d_type >(Vector< typename F::d_type >)> A, Real dx, uint dimY, uint dimX, Real tol=1e-8, Real iterMax=1000)
Constructor.
Definition: newton.hh:51
virtual void hide_messages()
uint iterMax_
Maximum number of iterations.
Definition: newton.hh:115
#define NEWTON_CONST_D
Definition: newton.hh:14
F::d_type type
Definition: newton.hh:39
Abstract class for an operator acting on vectors only, not arbitrary functions.
virtual void apply_(const Vector< typename F::d_type > &fncY, Vector< typename F::d_type > &fncX)
virtual const uint dimY() const
Returns the size of the source space of the operator (number of columns of the corresponding matrix)
Definition: compositions.hh:98
Real dx_
Step for the computation of the pseudo-Jacobian.
Definition: newton.hh:103
bool verbose_
Internal flag for verbosity.
Definition: newton.hh:118
Solves a non-linear system of the form A(X)=Y.
Definition: newton.hh:36
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
Newton(std::function< Vector< typename F::d_type >(Vector< typename F::d_type >)> A, std::function< F(Vector< typename F::d_type >)> JacA, uint dimY, uint dimX, Real tol=1e-8, Real iterMax=50)
Constructor.
Definition: newton.hh:67
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich