libMesh::DiffSolver Class Reference

#include <diff_solver.h>

Inheritance diagram for libMesh::DiffSolver:

List of all members.

Public Types

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
}
typedef ImplicitSystem sys_type

Public Member Functions

 DiffSolver (sys_type &s)
virtual ~DiffSolver ()
virtual void init ()
virtual void reinit ()
virtual unsigned int solve ()=0
unsigned int total_outer_iterations ()
unsigned int total_inner_iterations ()
unsigned int solve_result ()
const sys_typesystem () const
sys_typesystem ()

Static Public Member Functions

static AutoPtr< DiffSolverbuild (sys_type &s)
static std::string get_info ()
static void print_info (std::ostream &out=libMesh::out)
static unsigned int n_objects ()
static void enable_print_counter_info ()
static void disable_print_counter_info ()

Public Attributes

unsigned int max_linear_iterations
unsigned int max_nonlinear_iterations
bool quiet
bool verbose
bool continue_after_max_iterations
bool continue_after_backtrack_failure
Real absolute_residual_tolerance
Real relative_residual_tolerance
Real absolute_step_tolerance
Real relative_step_tolerance
Real initial_linear_tolerance
Real minimum_linear_tolerance

Protected Types

typedef std::map< std::string,
std::pair< unsigned int,
unsigned int > > 
Counts

Protected Member Functions

void increment_constructor_count (const std::string &name)
void increment_destructor_count (const std::string &name)

Protected Attributes

Real max_solution_norm
Real max_residual_norm
unsigned int _outer_iterations
unsigned int _inner_iterations
sys_type_system
unsigned int _solve_result

Static Protected Attributes

static Counts _counts
static Threads::atomic
< unsigned int > 
_n_objects
static Threads::spin_mutex _mutex
static bool _enable_print_counter = true

Detailed Description

This is a generic class that defines a solver to handle ImplicitSystem classes, including NonlinearImplicitSystem and DifferentiableSystem A user can define a solver by deriving from this class and implementing certain functions.

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.

Author:
Roy H. Stogner 2006-2010

Definition at line 54 of file diff_solver.h.


Member Typedef Documentation

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts [protected, inherited]

Data structure to log the information. The log is identified by the class name.

Definition at line 113 of file reference_counter.h.

The type of system

Definition at line 60 of file diff_solver.h.


Member Enumeration Documentation

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)

Definition at line 203 of file diff_solver.h.

00203                    {
00208     INVALID_SOLVE_RESULT = 0,
00209 
00214     CONVERGED_NO_REASON = 1,
00215 
00220     CONVERGED_ABSOLUTE_RESIDUAL = 2,
00221 
00226     CONVERGED_RELATIVE_RESIDUAL = 4,
00227 
00232     CONVERGED_ABSOLUTE_STEP = 8,
00233 
00238     CONVERGED_RELATIVE_STEP = 16,
00239 
00244     DIVERGED_NO_REASON = 32,
00245 
00251     DIVERGED_MAX_NONLINEAR_ITERATIONS = 64,
00252 
00257     DIVERGED_BACKTRACKING_FAILURE = 128
00258   };


Constructor & Destructor Documentation

libMesh::DiffSolver::DiffSolver ( sys_type s  ) 

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

Definition at line 27 of file diff_solver.C.

virtual libMesh::DiffSolver::~DiffSolver (  )  [inline, virtual]

Destructor.

Definition at line 77 of file diff_solver.h.

00077 {}


Member Function Documentation

AutoPtr< DiffSolver > libMesh::DiffSolver::build ( sys_type s  )  [static]

Factory. Requires a reference to the system to be solved. Returns a NewtonSolver by default

Definition at line 49 of file diff_solver.C.

Referenced by libMesh::TimeSolver::init().

00050 {
00051   return AutoPtr<DiffSolver>(new NewtonSolver(s));
00052 }

void libMesh::ReferenceCounter::disable_print_counter_info (  )  [static, inherited]

Definition at line 106 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

00107 {
00108   _enable_print_counter = false;
00109   return;
00110 }

void libMesh::ReferenceCounter::enable_print_counter_info (  )  [static, inherited]

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

Definition at line 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

00101 {
00102   _enable_print_counter = true;
00103   return;
00104 }

std::string libMesh::ReferenceCounter::get_info (  )  [static, inherited]

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

References libMesh::ReferenceCounter::_counts, and libMesh::Quality::name().

Referenced by libMesh::ReferenceCounter::print_info().

00048 {
00049 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
00050 
00051   std::ostringstream oss;
00052 
00053   oss << '\n'
00054       << " ---------------------------------------------------------------------------- \n"
00055       << "| Reference count information                                                |\n"
00056       << " ---------------------------------------------------------------------------- \n";
00057 
00058   for (Counts::iterator it = _counts.begin();
00059        it != _counts.end(); ++it)
00060     {
00061       const std::string name(it->first);
00062       const unsigned int creations    = it->second.first;
00063       const unsigned int destructions = it->second.second;
00064 
00065       oss << "| " << name << " reference count information:\n"
00066           << "|  Creations:    " << creations    << '\n'
00067           << "|  Destructions: " << destructions << '\n';
00068     }
00069 
00070   oss << " ---------------------------------------------------------------------------- \n";
00071 
00072   return oss.str();
00073 
00074 #else
00075 
00076   return "";
00077 
00078 #endif
00079 }

void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name  )  [inline, protected, inherited]

Increments the construction counter. Should be called in the constructor of any derived class that will be reference counted.

Definition at line 163 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

00164 {
00165   Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
00166   std::pair<unsigned int, unsigned int>& p = _counts[name];
00167 
00168   p.first++;
00169 }

void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name  )  [inline, protected, inherited]

Increments the destruction counter. Should be called in the destructor of any derived class that will be reference counted.

Definition at line 176 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

00177 {
00178   Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
00179   std::pair<unsigned int, unsigned int>& p = _counts[name];
00180 
00181   p.second++;
00182 }

void libMesh::DiffSolver::init (  )  [virtual]

The initialization function. This method is used to initialize internal data structures before a simulation begins.

Reimplemented in libMesh::PetscDiffSolver.

Definition at line 65 of file diff_solver.C.

References max_residual_norm, and max_solution_norm.

Referenced by libMesh::PetscDiffSolver::init().

00066 {
00067   // Reset the max_step_size and max_residual_norm for a new problem
00068   max_solution_norm = 0.;
00069   max_residual_norm = 0.;
00070 }

static unsigned int libMesh::ReferenceCounter::n_objects (  )  [inline, static, inherited]

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 79 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

00080   { return _n_objects; }

void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out  )  [static, inherited]

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

Definition at line 88 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter, and libMesh::ReferenceCounter::get_info().

00089 {
00090   if( _enable_print_counter ) out_stream << ReferenceCounter::get_info();
00091 }

void libMesh::DiffSolver::reinit (  )  [virtual]

The reinitialization function. This method is used after changes in the mesh.

Reimplemented in libMesh::NewtonSolver, and libMesh::PetscDiffSolver.

Definition at line 56 of file diff_solver.C.

References max_residual_norm, and max_solution_norm.

Referenced by libMesh::PetscDiffSolver::reinit(), and libMesh::NewtonSolver::reinit().

00057 {
00058   // Reset the max_step_size and max_residual_norm for a new mesh
00059   max_solution_norm = 0.;
00060   max_residual_norm = 0.;
00061 }

virtual unsigned int libMesh::DiffSolver::solve (  )  [pure virtual]

This method performs a solve. What occurs in this method will depend on the type of solver. See the subclasses for more details.

Implemented in libMesh::NewtonSolver, and libMesh::PetscDiffSolver.

unsigned int libMesh::DiffSolver::solve_result (  )  [inline]
Returns:
the value of the SolveResult from the last solve.

Definition at line 113 of file diff_solver.h.

References _solve_result.

00113 { return _solve_result; }

sys_type& libMesh::DiffSolver::system (  )  [inline]
Returns:
a writeable reference to the system we are solving.

Definition at line 123 of file diff_solver.h.

References _system.

00123 { return _system; }

const sys_type& libMesh::DiffSolver::system (  )  const [inline]
Returns:
a constant reference to the system we are solving.

Definition at line 118 of file diff_solver.h.

References _system.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), and libMesh::__libmesh_petsc_diff_solver_residual().

00118 { return _system; }

unsigned int libMesh::DiffSolver::total_inner_iterations (  )  [inline]
Returns:
the number of "inner" (e.g. Krylov) iterations required by the last solve.

Definition at line 108 of file diff_solver.h.

References _inner_iterations.

00108 { return _inner_iterations; }

unsigned int libMesh::DiffSolver::total_outer_iterations (  )  [inline]
Returns:
the number of "outer" (e.g. quasi-Newton) iterations required by the last solve.

Definition at line 102 of file diff_solver.h.

References _outer_iterations.

00102 { return _outer_iterations; }


Member Data Documentation

bool libMesh::ReferenceCounter::_enable_print_counter = true [static, protected, inherited]

Flag to control whether reference count information is printed when print_info is called.

Definition at line 137 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info(), and libMesh::ReferenceCounter::print_info().

unsigned int libMesh::DiffSolver::_inner_iterations [protected]

The number of inner iterations used by the last solve

Definition at line 283 of file diff_solver.h.

Referenced by libMesh::NewtonSolver::solve(), and total_inner_iterations().

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 131 of file reference_counter.h.

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects [static, protected, inherited]

The number of objects. Print the reference count information when the number returns to 0.

Definition at line 126 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter(), and libMesh::ReferenceCounter::~ReferenceCounter().

unsigned int libMesh::DiffSolver::_outer_iterations [protected]

The number of outer iterations used by the last solve

Definition at line 278 of file diff_solver.h.

Referenced by libMesh::NewtonSolver::line_search(), libMesh::PetscDiffSolver::solve(), libMesh::NewtonSolver::solve(), and total_outer_iterations().

unsigned int libMesh::DiffSolver::_solve_result [protected]

Initialized to zero. solve_result is typically set internally in the solve() function before it returns. When non-zero, solve_result tells the result of the latest solve. See enum definition for description.

Definition at line 296 of file diff_solver.h.

Referenced by libMesh::NewtonSolver::line_search(), libMesh::NewtonSolver::solve(), solve_result(), and libMesh::NewtonSolver::test_convergence().

A reference to the system we are solving.

Definition at line 288 of file diff_solver.h.

Referenced by libMesh::NewtonSolver::line_search(), libMesh::PetscDiffSolver::solve(), libMesh::NewtonSolver::solve(), and system().

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 172 of file diff_solver.h.

Referenced by libMesh::NewtonSolver::print_convergence(), and libMesh::NewtonSolver::test_convergence().

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 184 of file diff_solver.h.

Referenced by libMesh::NewtonSolver::print_convergence(), and libMesh::NewtonSolver::test_convergence().

Defaults to false, telling the DiffSolver to throw a libmesh_error() when the backtracking scheme fails to find a descent direction.

Definition at line 161 of file diff_solver.h.

Referenced by libMesh::NewtonSolver::line_search().

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 155 of file diff_solver.h.

Referenced by libMesh::NewtonSolver::solve().

Any required linear solves will at first be done with this tolerance; the DiffSolver may tighten the tolerance for later solves.

Definition at line 191 of file diff_solver.h.

Referenced by libMesh::NewtonSolver::solve().

Each linear solver step should exit after max_linear_iterations is exceeded.

Definition at line 129 of file diff_solver.h.

Referenced by libMesh::ContinuationSystem::continuation_solve(), libMesh::NewtonSolver::solve(), and libMesh::ContinuationSystem::solve_tangent().

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 137 of file diff_solver.h.

Referenced by libMesh::ContinuationSystem::continuation_solve(), libMesh::NewtonSolver::solve(), and libMesh::ContinuationSystem::update_solution().

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 273 of file diff_solver.h.

Referenced by init(), libMesh::NewtonSolver::print_convergence(), reinit(), libMesh::NewtonSolver::solve(), and libMesh::NewtonSolver::test_convergence().

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 266 of file diff_solver.h.

Referenced by init(), libMesh::NewtonSolver::print_convergence(), reinit(), libMesh::NewtonSolver::solve(), and libMesh::NewtonSolver::test_convergence().

The tolerance for linear solves is kept above this minimum

Definition at line 196 of file diff_solver.h.

Referenced by libMesh::NewtonSolver::solve().

The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is true.

Definition at line 143 of file diff_solver.h.

Referenced by libMesh::NewtonSolver::line_search(), and libMesh::NewtonSolver::solve().


The documentation for this class was generated from the following files:

Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:14 UTC

Hosted By:
SourceForge.net Logo