Poster of Linux kernelThe best gift for a Linux geek
DiffSolver

DiffSolver

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

DiffSolver -  

SYNOPSIS


#include <diff_solver.h>

Inherits ReferenceCountedObject< DiffSolver >.

Inherited by NewtonSolver, and PetscDiffSolver.  

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 DifferentiableSystem sys_type
 

Public Member Functions


DiffSolver (sys_type &s)

virtual ~DiffSolver ()

virtual void init ()

virtual void reinit ()

virtual unsigned int solve ()=0

virtual unsigned int adjoint_solve ()=0

unsigned int total_outer_iterations ()

unsigned int total_inner_iterations ()

unsigned int solve_result ()

const sys_type & system () const

sys_type & system ()
 

Static Public Member Functions


static AutoPtr< DiffSolver > build (sys_type &s)

static std::string get_info ()

static void print_info ()

static unsigned int n_objects ()
 

Public Attributes


unsigned int max_linear_iterations

unsigned int max_nonlinear_iterations

bool quiet

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
 

Detailed Description

This is a generic class that defines a solver to handle DifferentiableSystems 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

Definition at line 50 of file diff_solver.h.  

Member Typedef Documentation

 

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > ReferenceCounter::Counts [protected, inherited]Data structure to log the information. The log is identified by the class name.

Definition at line 105 of file reference_counter.h.  

typedef DifferentiableSystem DiffSolver::sys_typeThe type of system

Definition at line 56 of file diff_solver.h.  

Member Enumeration Documentation

 

enum DiffSolver::SolveResultEnumeration 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 200 of file diff_solver.h.

                   {
    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
  };
 

Constructor & Destructor Documentation

 

DiffSolver::DiffSolver (sys_type &s)Constructor. Requires a reference to the system to be solved.

Definition at line 26 of file diff_solver.C.

    : max_linear_iterations(1000),
      max_nonlinear_iterations(100),
      quiet(true),
      continue_after_max_iterations(true),
      continue_after_backtrack_failure(false),
      absolute_residual_tolerance(0.),
      relative_residual_tolerance(0.),
      absolute_step_tolerance(0.),
      relative_step_tolerance(0.),
      initial_linear_tolerance(1e-12),
      minimum_linear_tolerance(TOLERANCE*TOLERANCE),
      max_solution_norm(0.),
      max_residual_norm(0.),
      _system (s),
      _solve_result(INVALID_SOLVE_RESULT)
{
}
 

virtual DiffSolver::~DiffSolver () [inline, virtual]Destructor.

Definition at line 73 of file diff_solver.h.

{}
 

Member Function Documentation

 

virtual unsigned int DiffSolver::adjoint_solve () [pure virtual]This method performs a solve on the adjoint system. What occurs in this method will depend on the type of solver. See the subclasses for more details.

Implemented in NewtonSolver, and PetscDiffSolver.  

AutoPtr< DiffSolver > DiffSolver::build (sys_type &s) [static]Factory. Requires a reference to the system to be solved. Returns a NewtonSolver by default

Definition at line 47 of file diff_solver.C.

Referenced by PetscDiffSolver::adjoint_solve(), and TimeSolver::init().

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

std::string ReferenceCounter::get_info () [static, inherited]Gets a string containing the reference information.

Definition at line 45 of file reference_counter.C.

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

Referenced by ReferenceCounter::print_info().

{
#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)

  std::ostringstream out;
  
  out << '
      << ' ---------------------------------------------------------------------------- 
      << '| Reference count information                                                |
      << ' ---------------------------------------------------------------------------- ;
  
  for (Counts::iterator it = _counts.begin();
       it != _counts.end(); ++it)
    {
      const std::string name(it->first);
      const unsigned int creations    = it->second.first;
      const unsigned int destructions = it->second.second;

      out << '| ' << name << ' reference count information:
          << '|  Creations:    ' << creations    << '
          << '|  Destructions: ' << destructions << ';
    }
  
  out << ' ---------------------------------------------------------------------------- ;

  return out.str();

#else

  return '';
  
#endif
}
 

void 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 149 of file reference_counter.h.

References ReferenceCounter::_counts, Quality::name(), and Threads::spin_mtx.

Referenced by ReferenceCountedObject< Value >::ReferenceCountedObject().

{
  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
  std::pair<unsigned int, unsigned int>& p = _counts[name];

  p.first++;
}
 

void 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 167 of file reference_counter.h.

References ReferenceCounter::_counts, Quality::name(), and Threads::spin_mtx.

Referenced by ReferenceCountedObject< Value >::~ReferenceCountedObject().

{
  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
  std::pair<unsigned int, unsigned int>& p = _counts[name];

  p.second++;
}
 

void DiffSolver::init () [virtual]The initialization function. This method is used to initialize internal data structures before a simulation begins.

Reimplemented in PetscDiffSolver.

Definition at line 63 of file diff_solver.C.

References max_residual_norm, and max_solution_norm.

Referenced by PetscDiffSolver::init().

{
  // Reset the max_step_size and max_residual_norm for a new problem
  max_solution_norm = 0.;
  max_residual_norm = 0.;
}
 

static unsigned int ReferenceCounter::n_objects () [inline, static, inherited]Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 76 of file reference_counter.h.

References ReferenceCounter::_n_objects.

Referenced by System::read_serialized_blocked_dof_objects(), and System::write_serialized_blocked_dof_objects().

  { return _n_objects; }
 

void ReferenceCounter::print_info () [static, inherited]Prints the reference information to std::cout.

Definition at line 83 of file reference_counter.C.

References ReferenceCounter::get_info().

{
#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
  
  std::cout << ReferenceCounter::get_info();
  
#endif
}
 

void DiffSolver::reinit () [virtual]The reinitialization function. This method is used after changes in the mesh.

Reimplemented in NewtonSolver, and PetscDiffSolver.

Definition at line 54 of file diff_solver.C.

References max_residual_norm, and max_solution_norm.

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

{
  // Reset the max_step_size and max_residual_norm for a new mesh
  max_solution_norm = 0.;
  max_residual_norm = 0.;
}
 

virtual unsigned int 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 NewtonSolver, and PetscDiffSolver.  

unsigned int DiffSolver::solve_result () [inline]Returns:

the value of the SolveResult from the last solve.

Definition at line 116 of file diff_solver.h.

References _solve_result.

{ return _solve_result; }
 

sys_type& DiffSolver::system () [inline]Returns:

a writeable reference to the system we are solving.

Definition at line 126 of file diff_solver.h.

References _system.

{ return _system; }
 

const sys_type& DiffSolver::system () const [inline]Returns:

a constant reference to the system we are solving.

Definition at line 121 of file diff_solver.h.

References _system.

Referenced by __libmesh_petsc_diff_solver_jacobian(), and __libmesh_petsc_diff_solver_residual().

{ return _system; }
 

unsigned int DiffSolver::total_inner_iterations () [inline]Returns:

the number of 'inner' (e.g. Krylov) iterations required by the last solve.

Definition at line 111 of file diff_solver.h.

References _inner_iterations.

{ return _inner_iterations; }
 

unsigned int DiffSolver::total_outer_iterations () [inline]Returns:

the number of 'outer' (e.g. quasi-Newton) iterations required by the last solve.

Definition at line 105 of file diff_solver.h.

References _outer_iterations.

{ return _outer_iterations; }
 

Member Data Documentation

 

ReferenceCounter::Counts ReferenceCounter::_counts [static, protected, inherited]Actually holds the data.

Definition at line 110 of file reference_counter.h.

Referenced by ReferenceCounter::get_info(), ReferenceCounter::increment_constructor_count(), and ReferenceCounter::increment_destructor_count().  

unsigned int DiffSolver::_inner_iterations [protected]The number of inner iterations used by the last solve

Definition at line 280 of file diff_solver.h.

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

Threads::spin_mutex ReferenceCounter::_mutex [static, protected, inherited]Mutual exclusion object to enable thread-safe reference counting.

Definition at line 123 of file reference_counter.h.  

Threads::atomic< unsigned int > ReferenceCounter::_n_objects [static, protected, inherited]The number of objects. Print the reference count information when the number returns to 0.

Definition at line 118 of file reference_counter.h.

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

unsigned int DiffSolver::_outer_iterations [protected]The number of outer iterations used by the last solve

Definition at line 275 of file diff_solver.h.

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

unsigned int 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 293 of file diff_solver.h.

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

sys_type& DiffSolver::_system [protected]A reference to the system we are solving.

Definition at line 285 of file diff_solver.h.

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

Real DiffSolver::absolute_residual_toleranceThe 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 169 of file diff_solver.h.

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

Real DiffSolver::absolute_step_toleranceThe 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 181 of file diff_solver.h.

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

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

Definition at line 158 of file diff_solver.h.

Referenced by NewtonSolver::line_search().  

bool DiffSolver::continue_after_max_iterationsDefaults to true, telling the DiffSolver to continue rather than exit when a solve has reached its maximum number of nonlinear iterations.

Definition at line 152 of file diff_solver.h.

Referenced by NewtonSolver::solve().  

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

Definition at line 188 of file diff_solver.h.

Referenced by NewtonSolver::solve().  

unsigned int DiffSolver::max_linear_iterationsEach linear solver step should exit after max_linear_iterations is exceeded.

Definition at line 132 of file diff_solver.h.

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

unsigned int DiffSolver::max_nonlinear_iterationsThe 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 140 of file diff_solver.h.

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

Real DiffSolver::max_residual_norm [protected]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 270 of file diff_solver.h.

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

Real DiffSolver::max_solution_norm [protected]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 263 of file diff_solver.h.

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

Real DiffSolver::minimum_linear_toleranceThe tolerance for linear solves is kept above this minimum

Definition at line 193 of file diff_solver.h.

Referenced by NewtonSolver::solve().  

bool DiffSolver::quietThe DiffSolver should not print anything to std::cout unless quiet is set to false

Definition at line 146 of file diff_solver.h.

Referenced by NewtonSolver::adjoint_solve(), NewtonSolver::line_search(), NewtonSolver::print_convergence(), and NewtonSolver::solve().  

Real DiffSolver::relative_residual_tolerance

Definition at line 170 of file diff_solver.h.

Referenced by PetscDiffSolver::adjoint_solve(), NewtonSolver::adjoint_solve(), NewtonSolver::print_convergence(), and NewtonSolver::test_convergence().  

Real DiffSolver::relative_step_tolerance

Definition at line 182 of file diff_solver.h.

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

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Types
Public Member Functions
Static Public Member Functions
Public Attributes
Protected Types
Protected Member Functions
Protected Attributes
Static Protected Attributes
Detailed Description
Member Typedef Documentation
typedef std::map<std::string, std::pair<unsigned int, unsigned int> > ReferenceCounter::Counts [protected, inherited]Data structure to log the information. The log is identified by the class name.
typedef DifferentiableSystem DiffSolver::sys_typeThe type of system
Member Enumeration Documentation
enum DiffSolver::SolveResultEnumeration 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.
Constructor & Destructor Documentation
DiffSolver::DiffSolver (sys_type &s)Constructor. Requires a reference to the system to be solved.
virtual DiffSolver::~DiffSolver () [inline, virtual]Destructor.
Member Function Documentation
virtual unsigned int DiffSolver::adjoint_solve () [pure virtual]This method performs a solve on the adjoint system. What occurs in this method will depend on the type of solver. See the subclasses for more details.
AutoPtr< DiffSolver > DiffSolver::build (sys_type &s) [static]Factory. Requires a reference to the system to be solved. Returns a NewtonSolver by default
std::string ReferenceCounter::get_info () [static, inherited]Gets a string containing the reference information.
void 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.
void 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.
void DiffSolver::init () [virtual]The initialization function. This method is used to initialize internal data structures before a simulation begins.
static unsigned int ReferenceCounter::n_objects () [inline, static, inherited]Prints the number of outstanding (created, but not yet destroyed) objects.
void ReferenceCounter::print_info () [static, inherited]Prints the reference information to std::cout.
void DiffSolver::reinit () [virtual]The reinitialization function. This method is used after changes in the mesh.
virtual unsigned int 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.
unsigned int DiffSolver::solve_result () [inline]Returns:
sys_type& DiffSolver::system () [inline]Returns:
const sys_type& DiffSolver::system () const [inline]Returns:
unsigned int DiffSolver::total_inner_iterations () [inline]Returns:
unsigned int DiffSolver::total_outer_iterations () [inline]Returns:
Member Data Documentation
ReferenceCounter::Counts ReferenceCounter::_counts [static, protected, inherited]Actually holds the data.
unsigned int DiffSolver::_inner_iterations [protected]The number of inner iterations used by the last solve
Threads::spin_mutex ReferenceCounter::_mutex [static, protected, inherited]Mutual exclusion object to enable thread-safe reference counting.
Threads::atomic< unsigned int > ReferenceCounter::_n_objects [static, protected, inherited]The number of objects. Print the reference count information when the number returns to 0.
unsigned int DiffSolver::_outer_iterations [protected]The number of outer iterations used by the last solve
unsigned int 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.
sys_type& DiffSolver::_system [protected]A reference to the system we are solving.
Real DiffSolver::absolute_residual_toleranceThe 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.
Real DiffSolver::absolute_step_toleranceThe 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.
bool DiffSolver::continue_after_backtrack_failureDefaults to false, telling the DiffSolver to throw a libmesh_error() when the backtracking scheme fails to find a descent direction.
bool DiffSolver::continue_after_max_iterationsDefaults to true, telling the DiffSolver to continue rather than exit when a solve has reached its maximum number of nonlinear iterations.
Real DiffSolver::initial_linear_toleranceAny required linear solves will at first be done with this tolerance; the DiffSolver may tighten the tolerance for later solves.
unsigned int DiffSolver::max_linear_iterationsEach linear solver step should exit after max_linear_iterations is exceeded.
unsigned int DiffSolver::max_nonlinear_iterationsThe 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.
Real DiffSolver::max_residual_norm [protected]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
Real DiffSolver::max_solution_norm [protected]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
Real DiffSolver::minimum_linear_toleranceThe tolerance for linear solves is kept above this minimum
bool DiffSolver::quietThe DiffSolver should not print anything to std::cout unless quiet is set to false
Real DiffSolver::relative_residual_tolerance
Real DiffSolver::relative_step_tolerance
Author

This document was created by man2html, using the manual pages.
Time: 21:45:00 GMT, April 16, 2011