libMesh

This class defines a solver which uses the default libMesh linear solver in a quasiNewton method to handle a DifferentiableSystem. More...
#include <newton_solver.h>
Public Types  
typedef DiffSolver  Parent 
enum  SolveResult { INVALID_SOLVE_RESULT = 0, CONVERGED_NO_REASON = 1, CONVERGED_ABSOLUTE_RESIDUAL = 2, CONVERGED_RELATIVE_RESIDUAL = 4, CONVERGED_ABSOLUTE_STEP = 8, CONVERGED_RELATIVE_STEP = 16, DIVERGED_NO_REASON = 32, DIVERGED_MAX_NONLINEAR_ITERATIONS = 64, DIVERGED_BACKTRACKING_FAILURE = 128, DIVERGED_LINEAR_SOLVER_FAILURE = 256 } 
Enumeration return type for the solve() function. More...  
typedef ImplicitSystem  sys_type 
The type of system. More...  
Public Member Functions  
NewtonSolver (sys_type &system)  
Constructor. More...  
virtual  ~NewtonSolver () 
Destructor. More...  
virtual void  init () override 
The initialization function. More...  
virtual void  reinit () override 
The reinitialization function. More...  
virtual unsigned int  solve () override 
This method performs a solve, using an inexact NewtonKrylov method with line search. More...  
LinearSolver< Number > &  get_linear_solver () 
const LinearSolver< Number > &  get_linear_solver () const 
unsigned int  total_outer_iterations () 
unsigned int  total_inner_iterations () 
unsigned int  solve_result () 
const sys_type &  system () const 
sys_type &  system () 
const Parallel::Communicator &  comm () const 
processor_id_type  n_processors () const 
processor_id_type  processor_id () const 
Static Public Member Functions  
static std::unique_ptr< DiffSolver >  build (sys_type &s) 
Factory method. More...  
static std::string  get_info () 
Gets a string containing the reference information. More...  
static void  print_info (std::ostream &out=libMesh::out) 
Prints the reference information, by default to libMesh::out . More...  
static unsigned int  n_objects () 
Prints the number of outstanding (created, but not yet destroyed) objects. More...  
static void  enable_print_counter_info () 
Methods to enable/disable the reference counter output from print_info() More...  
static void  disable_print_counter_info () 
Public Attributes  
bool  require_residual_reduction 
If this is set to true, the solver is forced to test the residual after each Newton step, and to reduce the length of its steps whenever necessary to avoid a residual increase. More...  
bool  require_finite_residual 
If this is set to true, the solver is forced to test the residual after each Newton step, and to reduce the length of its steps whenever necessary to avoid an infinite or NaN residual. More...  
bool  brent_line_search 
If require_residual_reduction is true, the solver may reduce step lengths when required. More...  
bool  track_linear_convergence 
If set to true, check for convergence of the linear solve. More...  
Real  minsteplength 
If the quasiNewton step length must be reduced to below this factor to give a residual reduction, then the Newton solver dies with an error message. More...  
Real  linear_tolerance_multiplier 
The tolerance for linear solves is kept below this multiplier (which defaults to 1e3) times the norm of the current nonlinear residual. More...  
unsigned int  max_linear_iterations 
Each linear solver step should exit after max_linear_iterations is exceeded. More...  
unsigned int  max_nonlinear_iterations 
The DiffSolver should exit in failure if max_nonlinear_iterations is exceeded and continue_after_max_iterations is false, or should end the nonlinear solve if max_nonlinear_iterations is exceeded and continue_after_max_iterations is true. More...  
bool  quiet 
The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is true. More...  
bool  verbose 
The DiffSolver may print a lot more to libMesh::out if verbose is set to true; default is false. More...  
bool  continue_after_max_iterations 
Defaults to true, telling the DiffSolver to continue rather than exit when a solve has reached its maximum number of nonlinear iterations. More...  
bool  continue_after_backtrack_failure 
Defaults to false, telling the DiffSolver to throw an error when the backtracking scheme fails to find a descent direction. More...  
Real  absolute_residual_tolerance 
The DiffSolver should exit after the residual is reduced to either less than absolute_residual_tolerance or less than relative_residual_tolerance times the initial residual. More...  
Real  relative_residual_tolerance 
Real  absolute_step_tolerance 
The DiffSolver should exit after the full nonlinear step norm is reduced to either less than absolute_step_tolerance or less than relative_step_tolerance times the largest nonlinear solution which has been seen so far. More...  
Real  relative_step_tolerance 
Real  initial_linear_tolerance 
Any required linear solves will at first be done with this tolerance; the DiffSolver may tighten the tolerance for later solves. More...  
Real  minimum_linear_tolerance 
The tolerance for linear solves is kept above this minimum. More...  
std::unique_ptr< LinearSolutionMonitor >  linear_solution_monitor 
Pointer to functor which is called right after each linear solve. More...  
Protected Types  
typedef std::map< std::string, std::pair< unsigned int, unsigned int > >  Counts 
Data structure to log the information. More...  
Protected Member Functions  
Real  line_search (Real tol, Real last_residual, Real ¤t_residual, NumericVector< Number > &newton_iterate, const NumericVector< Number > &linear_solution) 
This does a line search in the direction opposite linear_solution to try and minimize the residual of newton_iterate . More...  
void  print_convergence (unsigned int step_num, Real current_residual, Real step_norm, bool linear_solve_finished) 
This prints output for the convergence criteria based on by the given residual and step size. More...  
bool  test_convergence (Real current_residual, Real step_norm, bool linear_solve_finished) 
void  increment_constructor_count (const std::string &name) 
Increments the construction counter. More...  
void  increment_destructor_count (const std::string &name) 
Increments the destruction counter. More...  
Protected Attributes  
std::unique_ptr< LinearSolver< Number > >  _linear_solver 
The LinearSolver defines the interface used to solve the linear_implicit system. More...  
Real  max_solution_norm 
The largest solution norm which the DiffSolver has yet seen will be stored here, to be used for stopping criteria based on relative_step_tolerance. More...  
Real  max_residual_norm 
The largest nonlinear residual which the DiffSolver has yet seen will be stored here, to be used for stopping criteria based on relative_residual_tolerance. More...  
unsigned int  _outer_iterations 
The number of outer iterations used by the last solve. More...  
unsigned int  _inner_iterations 
The number of inner iterations used by the last solve. More...  
sys_type &  _system 
A reference to the system we are solving. More...  
unsigned int  _solve_result 
Initialized to zero. More...  
const Parallel::Communicator &  _communicator 
Static Protected Attributes  
static Counts  _counts 
Actually holds the data. More...  
static Threads::atomic< unsigned int >  _n_objects 
The number of objects. More...  
static Threads::spin_mutex  _mutex 
Mutual exclusion object to enable threadsafe reference counting. More...  
static bool  _enable_print_counter 
Flag to control whether reference count information is printed when print_info is called. More...  
This class defines a solver which uses the default libMesh linear solver in a quasiNewton method to handle a DifferentiableSystem.
This class is part of the new DifferentiableSystem framework, which is still experimental. Users of this framework should beware of bugs and future API changes.
Definition at line 46 of file newton_solver.h.

protectedinherited 
Data structure to log the information.
The log is identified by the class name.
Definition at line 117 of file reference_counter.h.
Definition at line 61 of file newton_solver.h.

inherited 
The type of system.
Definition at line 78 of file diff_solver.h.

inherited 
Enumeration return type for the solve() function.
Multiple SolveResults may be combined (OR'd) in the single return. To test which ones are present, just AND the return value with any of the SolveResult flags defined below.
Enumerator  

INVALID_SOLVE_RESULT  A default or invalid solve result. This usually means no solve has occurred yet. 
CONVERGED_NO_REASON  The solver converged but no particular reason is specified. 
CONVERGED_ABSOLUTE_RESIDUAL  The DiffSolver achieved the desired absolute residual tolerance. 
CONVERGED_RELATIVE_RESIDUAL  The DiffSolver achieved the desired relative residual tolerance. 
CONVERGED_ABSOLUTE_STEP  The DiffSolver achieved the desired absolute step size tolerance. 
CONVERGED_RELATIVE_STEP  The DiffSolver achieved the desired relative step size tolerance. 
DIVERGED_NO_REASON  The DiffSolver diverged but no particular reason is specified. 
DIVERGED_MAX_NONLINEAR_ITERATIONS  The DiffSolver reached the maximum allowed number of nonlinear iterations before satisfying any convergence tests. 
DIVERGED_BACKTRACKING_FAILURE  The DiffSolver failed to find a descent direction by backtracking (See newton_solver.C) 
DIVERGED_LINEAR_SOLVER_FAILURE  The linear solver used by the DiffSolver failed to find a solution. 
Definition at line 223 of file diff_solver.h.

explicit 
Constructor.
Requires a reference to the system to be solved.

virtual 
Destructor.

staticinherited 

inherited 
Parallel::Communicator
object used by this mesh. Definition at line 87 of file parallel_object.h.
References libMesh::ParallelObject::_communicator.
Referenced by libMesh::EpetraVector< T >::EpetraVector(), libMesh::Parallel::sync_element_data_by_parent_id(), libMesh::Parallel::sync_node_data_by_element_id(), and libMesh::Parallel::sync_node_data_by_element_id_once().

staticinherited 

staticinherited 
Methods to enable/disable the reference counter output from print_info()

staticinherited 
Gets a string containing the reference information.
LinearSolver<Number>& libMesh::NewtonSolver::get_linear_solver  (  ) 
Definition at line 81 of file newton_solver.h.
References _linear_solver.
const LinearSolver<Number>& libMesh::NewtonSolver::get_linear_solver  (  )  const 
Definition at line 86 of file newton_solver.h.
References _linear_solver.

protectedinherited 
Increments the construction counter.
Should be called in the constructor of any derived class that will be reference counted.
Definition at line 181 of file reference_counter.h.
References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.
Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

protectedinherited 
Increments the destruction counter.
Should be called in the destructor of any derived class that will be reference counted.
Definition at line 194 of file reference_counter.h.
References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.
Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

overridevirtual 
The initialization function.
This method is used to initialize internal data structures before a simulation begins.
Reimplemented from libMesh::DiffSolver.

protected 
This does a line search in the direction opposite linear_solution
to try and minimize the residual of newton_iterate
.
newton_iterate
is moved to the end of the quasiNewton step.

staticinherited 
Prints the number of outstanding (created, but not yet destroyed) objects.
Definition at line 83 of file reference_counter.h.
References libMesh::ReferenceCounter::_n_objects.

inherited 
Definition at line 93 of file parallel_object.h.
References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::size().
Referenced by libMesh::MeshBase::partition().

protected 
This prints output for the convergence criteria based on by the given residual and step size.

staticinherited 
Prints the reference information, by default to libMesh::out
.

inherited 
Definition at line 99 of file parallel_object.h.
References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::rank().
Referenced by libMesh::DofMap::end_dof(), libMesh::DofMap::end_old_dof(), libMesh::DofMap::first_dof(), libMesh::DofMap::first_old_dof(), libMesh::DofMap::last_dof(), libMesh::MeshBase::n_active_local_elem(), libMesh::DofMap::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), and libMesh::MeshTools::weight().

overridevirtual 
The reinitialization function.
This method is used after changes in the mesh.
Reimplemented from libMesh::DiffSolver.

overridevirtual 
This method performs a solve, using an inexact NewtonKrylov method with line search.
Implements libMesh::DiffSolver.

inherited 
Definition at line 133 of file diff_solver.h.
References libMesh::DiffSolver::_solve_result.

inherited 
Definition at line 138 of file diff_solver.h.
References libMesh::DiffSolver::_system.

inherited 
Definition at line 143 of file diff_solver.h.
References libMesh::DiffSolver::_system.

protected 
true
if a convergence criterion has been passed by the given residual and step size; false otherwise.

inherited 
Definition at line 128 of file diff_solver.h.
References libMesh::DiffSolver::_inner_iterations.

inherited 
Definition at line 122 of file diff_solver.h.
References libMesh::DiffSolver::_outer_iterations.

protectedinherited 
Definition at line 105 of file parallel_object.h.
Referenced by libMesh::ParallelObject::comm(), libMesh::ParallelObject::n_processors(), libMesh::ParallelObject::operator=(), and libMesh::ParallelObject::processor_id().

staticprotectedinherited 
Actually holds the data.
Definition at line 122 of file reference_counter.h.
Referenced by libMesh::ReferenceCounter::increment_constructor_count(), and libMesh::ReferenceCounter::increment_destructor_count().

staticprotectedinherited 
Flag to control whether reference count information is printed when print_info is called.
Definition at line 141 of file reference_counter.h.

protectedinherited 
The number of inner iterations used by the last solve.
Definition at line 314 of file diff_solver.h.
Referenced by libMesh::DiffSolver::total_inner_iterations().

protected 
The LinearSolver
defines the interface used to solve the linear_implicit system.
This class handles all the details of interfacing with various linear algebra packages like PETSc or LASPACK.
Definition at line 153 of file newton_solver.h.
Referenced by get_linear_solver().

staticprotectedinherited 
Mutual exclusion object to enable threadsafe reference counting.
Definition at line 135 of file reference_counter.h.

staticprotectedinherited 
The number of objects.
Print the reference count information when the number returns to 0.
Definition at line 130 of file reference_counter.h.
Referenced by libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter(), and libMesh::ReferenceCounter::~ReferenceCounter().

protectedinherited 
The number of outer iterations used by the last solve.
Definition at line 309 of file diff_solver.h.
Referenced by libMesh::DiffSolver::total_outer_iterations().

protectedinherited 
Initialized to zero.
solve_result is typically set internally in the solve() function before it returns. When nonzero, solve_result tells the result of the latest solve. See enum definition for description.
Definition at line 327 of file diff_solver.h.
Referenced by libMesh::DiffSolver::solve_result().

protectedinherited 
A reference to the system we are solving.
Definition at line 319 of file diff_solver.h.
Referenced by libMesh::DiffSolver::system().

inherited 
The DiffSolver should exit after the residual is reduced to either less than absolute_residual_tolerance or less than relative_residual_tolerance times the initial residual.
Users should increase any of these tolerances that they want to use for a stopping condition.
Definition at line 192 of file diff_solver.h.
Referenced by TimeSolverTestImplementation< TimeSolverType >::run_test_with_exact_soln().

inherited 
The DiffSolver should exit after the full nonlinear step norm is reduced to either less than absolute_step_tolerance or less than relative_step_tolerance times the largest nonlinear solution which has been seen so far.
Users should increase any of these tolerances that they want to use for a stopping condition.
Definition at line 204 of file diff_solver.h.
bool libMesh::NewtonSolver::brent_line_search 
If require_residual_reduction is true, the solver may reduce step lengths when required.
If so, brent_line_search is an option. If brent_line_search is set to false, the solver reduces the length of its steps by 1/2 iteratively until it finds residual reduction. If true, step lengths are first reduced by 1/2 or more to find some residual reduction, then Brent's method is used to find as much residual reduction as possible.
brent_line_search is currently set to true by default.
Definition at line 120 of file newton_solver.h.

inherited 
Defaults to false, telling the DiffSolver to throw an error when the backtracking scheme fails to find a descent direction.
Definition at line 181 of file diff_solver.h.

inherited 
Defaults to true, telling the DiffSolver to continue rather than exit when a solve has reached its maximum number of nonlinear iterations.
Definition at line 175 of file diff_solver.h.

inherited 
Any required linear solves will at first be done with this tolerance; the DiffSolver may tighten the tolerance for later solves.
Definition at line 211 of file diff_solver.h.

inherited 
Pointer to functor which is called right after each linear solve.
Definition at line 289 of file diff_solver.h.
Real libMesh::NewtonSolver::linear_tolerance_multiplier 
The tolerance for linear solves is kept below this multiplier (which defaults to 1e3) times the norm of the current nonlinear residual.
Definition at line 143 of file newton_solver.h.

inherited 
Each linear solver step should exit after max_linear_iterations
is exceeded.
Definition at line 149 of file diff_solver.h.

inherited 
The DiffSolver should exit in failure if max_nonlinear_iterations
is exceeded and continue_after_max_iterations
is false, or should end the nonlinear solve if max_nonlinear_iterations
is exceeded and continue_after_max_iterations
is true.
Definition at line 157 of file diff_solver.h.

protectedinherited 
The largest nonlinear residual which the DiffSolver has yet seen will be stored here, to be used for stopping criteria based on relative_residual_tolerance.
Definition at line 304 of file diff_solver.h.

protectedinherited 
The largest solution norm which the DiffSolver has yet seen will be stored here, to be used for stopping criteria based on relative_step_tolerance.
Definition at line 297 of file diff_solver.h.

inherited 
The tolerance for linear solves is kept above this minimum.
Definition at line 216 of file diff_solver.h.
Real libMesh::NewtonSolver::minsteplength 
If the quasiNewton step length must be reduced to below this factor to give a residual reduction, then the Newton solver dies with an error message.
It is currently set to 1e5 by default.
Definition at line 137 of file newton_solver.h.

inherited 
The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is true.
Definition at line 163 of file diff_solver.h.

inherited 
Definition at line 193 of file diff_solver.h.
Referenced by TimeSolverTestImplementation< TimeSolverType >::run_test_with_exact_soln().

inherited 
Definition at line 205 of file diff_solver.h.
Referenced by TimeSolverTestImplementation< TimeSolverType >::run_test_with_exact_soln().
bool libMesh::NewtonSolver::require_finite_residual 
If this is set to true, the solver is forced to test the residual after each Newton step, and to reduce the length of its steps whenever necessary to avoid an infinite or NaN residual.
It is currently set to true by default; set it to false to avoid unnecessary residual assembly on wellbehaved systems.
Definition at line 107 of file newton_solver.h.
bool libMesh::NewtonSolver::require_residual_reduction 
If this is set to true, the solver is forced to test the residual after each Newton step, and to reduce the length of its steps whenever necessary to avoid a residual increase.
It is currently set to true by default; set it to false to avoid unnecessary residual assembly on wellbehaved systems.
Definition at line 98 of file newton_solver.h.
bool libMesh::NewtonSolver::track_linear_convergence 
If set to true, check for convergence of the linear solve.
If no convergence is acquired during the linear solve, the nonlinear solve fails with DiffSolver::DIVERGED_LINEAR_SOLVER_FAILURE. Enabled by default as nonlinear convergence is very difficult, if the linear solver is not converged.
Definition at line 129 of file newton_solver.h.

inherited 
The DiffSolver may print a lot more to libMesh::out if verbose is set to true; default is false.
Definition at line 169 of file diff_solver.h.