Hermes2D  2.0
newton_solver.h
1 // This file is part of Hermes2D
2 //
3 // Copyright (c) 2009 hp-FEM group at the University of Nevada, Reno (UNR).
4 // Email: hpfem-group@unr.edu, home page: http://hpfem.org/.
5 //
6 // Hermes2D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published
8 // by the Free Software Foundation; either version 2 of the License,
9 // or (at your option) any later version.
10 //
11 // Hermes2D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with Hermes2D; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef __H2D_SOLVER_NEWTON_H_
23 #define __H2D_SOLVER_NEWTON_H_
24 
25 #include "global.h"
26 #include "discrete_problem.h"
27 #include "exceptions.h"
28 
29 namespace Hermes
30 {
31  namespace Hermes2D
32  {
70  template<typename Scalar>
71  class HERMES_API NewtonSolver : public NonlinearSolver<Scalar>, public Hermes::Hermes2D::Mixins::SettableSpaces<Scalar>, public Hermes::Mixins::OutputAttachable, public Hermes::Hermes2D::Mixins::MatrixRhsOutput<Scalar>, public Hermes::Hermes2D::Mixins::StateQueryable
72  {
73  public:
74  NewtonSolver();
76  NewtonSolver(const WeakForm<Scalar>* wf, const Space<Scalar>* space);
77  NewtonSolver(const WeakForm<Scalar>* wf, Hermes::vector<const Space<Scalar>*> spaces);
78  void init_linear_solver();
79 
80  ~NewtonSolver();
81 
83  virtual bool isOkay() const;
84  inline std::string getClassName() const { return "NewtonSolver"; }
85 
88  void solve(Scalar* coeff_vec = NULL);
89 
92  void solve(Solution<Scalar>* initial_guess);
93 
96  void solve(Hermes::vector<Solution<Scalar>*> initial_guess);
97 
100  void solve_keep_jacobian(Scalar* coeff_vec = NULL);
101 
104  void solve_keep_jacobian(Solution<Scalar>* initial_guess);
105 
108  void solve_keep_jacobian(Hermes::vector<Solution<Scalar>*> initial_guess);
109 
112  void set_max_allowed_residual_norm(double max_allowed_residual_norm_to_set);
113 
116  void set_min_allowed_damping_coeff(double min_allowed_damping_coeff_to_set);
117 
119  virtual void set_iterative_method(const char* iterative_method_name);
120 
122  virtual void set_preconditioner(const char* preconditioner_name);
123 
131  void set_residual_as_function();
132 
135  void set_newton_tol(double newton_tol);
136 
139  void set_newton_max_iter(int newton_max_iter);
140 
143  virtual void set_time(double time);
144  virtual void set_time_step(double time_step);
145 
147  virtual void set_spaces(Hermes::vector<const Space<Scalar>*> spaces);
148  virtual void set_space(const Space<Scalar>* space);
149  virtual Hermes::vector<const Space<Scalar>*> get_spaces() const;
150 
155  void set_manual_damping_coeff(bool onOff, double coeff = 1.0);
156 
161  void set_initial_auto_damping_coeff(double coeff);
162 
169  void set_auto_damping_ratio(double ratio);
170 
176  void set_sufficient_improvement_factor(double ratio);
177 
183  void set_necessary_successful_steps_to_increase(unsigned int steps);
184 
186  void set_weak_formulation(const WeakForm<Scalar>* wf);
187 
188  protected:
190  const bool own_dp;
191 
193  SparseMatrix<Scalar>* kept_jacobian;
194 
196  void init_attributes();
197 
199  SparseMatrix<Scalar>* jacobian;
200 
202  Vector<Scalar>* residual;
203 
205  LinearMatrixSolver<Scalar>* linear_solver;
206 
207  double newton_tol;
208  int newton_max_iter;
209  bool residual_as_function;
210 
215  double min_allowed_damping_coeff;
216 
217  double currentDampingCofficient;
218 
229  };
230  }
231 }
232 #endif