ug4
newton.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3  * Author: Andreas Vogel
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG__LIB_DISC__OPERATOR__NON_LINEAR_OPERATOR__NEWTON_SOLVER__NEWTON__
34 #define __H__UG__LIB_DISC__OPERATOR__NON_LINEAR_OPERATOR__NEWTON_SOLVER__NEWTON__
35 
36 #include <cmath>
37 
41 
42 // modul intern headers
46 #include "../line_search.h"
49 
50 namespace ug {
51 
53 template <typename TAlgebra>
55  : public IOperatorInverse<typename TAlgebra::vector_type>,
56  public DebugWritingObject<TAlgebra>
57 {
58  public:
60  typedef TAlgebra algebra_type;
61 
63  typedef typename TAlgebra::vector_type vector_type;
64 
66  typedef typename TAlgebra::matrix_type matrix_type;
67 
68  public:
71 
74 
76  NewtonSolver();
77 
81  SmartPtr<ILineSearch<vector_type> > spLineSearch);
82 
85 
88 
90  void set_line_search(SmartPtr<ILineSearch<vector_type> > spLineSearch) {m_spLineSearch = spLineSearch;}
93 
95  virtual bool init(SmartPtr<IOperator<vector_type> > N);
96 
98  virtual bool prepare(vector_type& u);
99 
101  virtual bool apply(vector_type& u);
102 
104 
111  virtual std::string config_string() const;
112 
114  void print_average_convergence() const;
115 
118  size_t num_newton_steps() const;
119  int num_linsolver_calls(size_t call) const;
120  int num_linsolver_steps(size_t call) const;
121  double average_linear_steps(size_t call) const;
122  int total_linsolver_calls() const;
123  int total_linsolver_steps() const;
124  double total_average_linear_steps() const;
125  int last_num_newton_steps() const {return m_lastNumSteps;}
127 
130 
133  {m_innerStepUpdate.push_back(NU);}
134 
137  {m_innerStepUpdate.clear();}
138 
141  {m_stepUpdate.push_back(NU);}
142 
145  {m_stepUpdate.clear();}
146 
148  void set_reassemble_J_freq(int freq)
149  {m_reassembe_J_freq = freq;};
150 
151  private:
154  void write_debug(const vector_type& vec, std::string filename);
155  void write_debug(const matrix_type& mat, std::string filename);
157 
158  private:
161 
164 
167 
169  std::vector<SmartPtr<INewtonUpdate> > m_innerStepUpdate;
170  std::vector<SmartPtr<INewtonUpdate> > m_stepUpdate;
171 
180 
184 
187  std::vector<int> m_vTotalLinSolverSteps;
188  std::vector<int> m_vLinSolverCalls;
189  std::vector<number> m_vNonLinSolverRates;
190  std::vector<number> m_vLinSolverRates;
192 };
193 
194 }
195 
196 #include "newton_impl.h"
197 
198 #endif /* __H__UG__LIB_DISC__OPERATOR__NON_LINEAR_OPERATOR__NEWTON_SOLVER__NEWTON__ */
Definition: smart_pointer.h:108
Definition: debug_writer.h:354
Interface providing Jacobian and Defect of a discretization.
Definition: assemble_interface.h:110
Definition: convergence_check.h:72
Definition: line_search.h:60
describes an inverse linear mapping X->Y
Definition: linear_operator_inverse.h:80
describes a mapping X->Y
Definition: operator.h:86
describes an inverse mapping X->Y
Definition: operator_inverse.h:79
linear solver using abstract preconditioner interface
Definition: linear_solver.h:57
Newton solver for assembling based discretizations.
Definition: newton.h:57
std::vector< SmartPtr< INewtonUpdate > > m_innerStepUpdate
Update.
Definition: newton.h:169
int total_linsolver_calls() const
Definition: newton_impl.h:382
void add_step_update(SmartPtr< INewtonUpdate > NU)
add outer step update (applied before every Newton step)
Definition: newton.h:140
std::vector< SmartPtr< INewtonUpdate > > m_stepUpdate
Definition: newton.h:170
void clear_average_convergence()
resets average linear solver convergence
Definition: newton_impl.h:407
void clear_inner_step_update(SmartPtr< INewtonUpdate > NU)
clears inner step update
Definition: newton.h:136
virtual bool prepare(vector_type &u)
prepare Operator
Definition: newton_impl.h:142
SmartPtr< IConvergenceCheck< vector_type > > m_spConvCheck
Convergence Check.
Definition: newton.h:163
SmartPtr< ILineSearch< vector_type > > line_search()
Definition: newton.h:92
void disable_line_search()
Definition: newton.h:91
void set_reassemble_J_freq(int freq)
sets the frequency of reassembling of the Jacobian (0 == 1 == in every step, i.e. classically)
Definition: newton.h:148
virtual bool apply(vector_type &u)
apply Operator, i.e. N^{-1}(0) = u
Definition: newton_impl.h:149
NewtonSolver()
default constructor
Definition: newton_impl.h:74
virtual bool init(SmartPtr< IOperator< vector_type > > N)
This operator inverts the Operator N: Y -> X.
Definition: newton_impl.h:130
int num_linsolver_steps(size_t call) const
Definition: newton_impl.h:370
void write_debug(const vector_type &vec, std::string filename)
Definition: newton_impl.h:416
int m_dgbCall
call counter
Definition: newton.h:182
TAlgebra::matrix_type matrix_type
Matrix type.
Definition: newton.h:66
int m_lastNumSteps
Definition: newton.h:183
int last_num_newton_steps() const
Definition: newton.h:125
void clear_step_update(SmartPtr< INewtonUpdate > NU)
clears outer step update
Definition: newton.h:144
void set_line_search(SmartPtr< ILineSearch< vector_type > > spLineSearch)
sets the line search
Definition: newton.h:90
double total_average_linear_steps() const
Definition: newton_impl.h:400
std::vector< number > m_vLinSolverRates
Definition: newton.h:190
std::vector< number > m_vNonLinSolverRates
Definition: newton.h:189
virtual std::string config_string() const
returns information about configuration parameters
Definition: newton_impl.h:438
std::vector< int > m_vTotalLinSolverSteps
Definition: newton.h:187
SmartPtr< ILinearOperatorInverse< vector_type > > m_spLinearSolver
linear solver
Definition: newton.h:160
SmartPtr< ILineSearch< vector_type > > m_spLineSearch
LineSearch.
Definition: newton.h:166
double average_linear_steps(size_t call) const
Definition: newton_impl.h:376
int m_reassembe_J_freq
how often to reassemble the Jacobian (0 == 1 == in every step, i.e. classically)
Definition: newton.h:179
TAlgebra::vector_type vector_type
Vector type.
Definition: newton.h:63
SmartPtr< AssembledLinearOperator< algebra_type > > m_J
jacobi operator
Definition: newton.h:175
SmartPtr< AssembledOperator< algebra_type > > m_N
assembling routine
Definition: newton.h:173
TAlgebra algebra_type
Algebra type.
Definition: newton.h:60
void print_average_convergence() const
prints average linear solver convergence
Definition: newton_impl.h:328
size_t num_newton_steps() const
Definition: newton_impl.h:358
void set_convergence_check(SmartPtr< IConvergenceCheck< vector_type > > spConvCheck)
sets the convergence check
Definition: newton_impl.h:121
SmartPtr< IAssemble< TAlgebra > > m_spAss
assembling
Definition: newton.h:177
std::vector< int > m_vLinSolverCalls
Definition: newton.h:188
void set_linear_solver(SmartPtr< ILinearOperatorInverse< vector_type > > LinearSolver)
sets the linear solver
Definition: newton.h:84
int num_linsolver_calls(size_t call) const
Definition: newton_impl.h:364
void add_inner_step_update(SmartPtr< INewtonUpdate > NU)
add inner step update (applied before every linear solver step)
Definition: newton.h:132
int total_linsolver_steps() const
Definition: newton_impl.h:391
Wrapper for sequential matrices to handle them in parallel.
Definition: parallel_matrix.h:65
const NullSmartPtr SPNULL
The equivalent to NULL for smart pointers.
Definition: smart_pointer.h:90
CPUAlgebra::vector_type vector_type
the ug namespace