HermesCommon  3.0
newton_matrix_solver.cpp
1 // This file is part of HermesCommon
2 //
3 // Copyright (c) 2009 hp-FEM group at the University of Nevada, Reno (UNR).
4 // Email: hpfem-group@unr.edu, home page: http://www.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.
19 
20 #include "newton_matrix_solver.h"
21 
22 using namespace Hermes::Algebra;
23 
24 namespace Hermes
25 {
26  namespace Solvers
27  {
28  template<typename Scalar>
30  {
31  init_newton();
32  }
33 
34  template<typename Scalar>
36  {
37  this->min_allowed_damping_coeff = 1E-4;
38  this->manual_damping = false;
39  this->auto_damping_ratio = 2.0;
40  this->initial_auto_damping_factor = 1.0;
41  this->sufficient_improvement_factor = 0.95;
42  this->necessary_successful_steps_to_increase = 3;
43 
44  this->sufficient_improvement_factor_jacobian = 1e-1;
45  this->max_steps_with_reused_jacobian = 3;
46 
47  this->set_tolerance(1e-8, ResidualNormAbsolute);
48  }
49 
50  template<typename Scalar>
52  {
53  double residual_norm = this->get_parameter_value(this->p_residual_norms).back();
54 
55  if (residual_norm > this->max_allowed_residual_norm)
56  return AboveMaxAllowedResidualNorm;
57  else
59  }
60 
61  template<typename Scalar>
63  {
64  double current_damping_factor = this->get_parameter_value(this->p_damping_factors).back();
65 
66  double solution_change_norm = 0.;
67  for (int i = 0; i < this->problem_size; i++)
68  {
69  solution_change_norm += std::pow(std::abs(linear_system_solution[i]), 2.);
70  this->sln_vector[i] += current_damping_factor * linear_system_solution[i];
71  }
72  return std::sqrt(solution_change_norm) * current_damping_factor;
73  }
74 
75  template class HERMES_API NewtonMatrixSolver < double > ;
76  template class HERMES_API NewtonMatrixSolver < std::complex<double> > ;
77  }
78 }
General namespace for the Hermes library.
Newton's method for algebraic equations.
Namespace containing classes for vector / matrix operations.
Base class for defining interface for nonlinear solvers.
NonlinearConvergenceState
Nonlinear Convergence state.
virtual NonlinearConvergenceState get_convergence_state()
Find out the convergence state.
virtual NonlinearConvergenceState get_convergence_state()
Find out the convergence state.
virtual double update_solution_return_change_norm(Scalar *linear_system_solution)