libMesh::NonlinearSolver< T > Class Template Reference

#include <nonlinear_solver.h>

Inheritance diagram for libMesh::NonlinearSolver< T >:

List of all members.

Public Types

typedef NonlinearImplicitSystem sys_type

Public Member Functions

 NonlinearSolver (sys_type &s)
virtual ~NonlinearSolver ()
bool initialized () const
virtual void clear ()
virtual void init ()=0
virtual std::pair< unsigned
int, Real
solve (SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0
virtual void print_converged_reason ()
virtual int get_total_linear_iterations ()=0
virtual unsigned get_current_nonlinear_iteration_number () const =0
const sys_typesystem () const
sys_typesystem ()
void attach_preconditioner (Preconditioner< T > *preconditioner)

Static Public Member Functions

static AutoPtr
< NonlinearSolver< T > > 
build (sys_type &s, const SolverPackage solver_package=libMesh::default_solver_package())
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

void(* residual )(const NumericVector< Number > &X, NumericVector< Number > &R, sys_type &S)
NonlinearImplicitSystem::ComputeResidualresidual_object
void(* jacobian )(const NumericVector< Number > &X, SparseMatrix< Number > &J, sys_type &S)
NonlinearImplicitSystem::ComputeJacobianjacobian_object
void(* matvec )(const NumericVector< Number > &X, NumericVector< Number > *R, SparseMatrix< Number > *J, sys_type &S)
NonlinearImplicitSystem::ComputeResidualandJacobianresidual_and_jacobian_object
void(* bounds )(NumericVector< Number > &XL, NumericVector< Number > &XU, sys_type &S)
NonlinearImplicitSystem::ComputeBoundsbounds_object
void(* nullspace )(std::vector< NumericVector< Number > * > &sp, sys_type &S)
NonlinearImplicitSystem::ComputeVectorSubspacenullspace_object
void(* nearnullspace )(std::vector< NumericVector< Number > * > &sp, sys_type &S)
NonlinearImplicitSystem::ComputeVectorSubspacenearnullspace_object
void(* user_presolve )(sys_type &S)
unsigned int max_nonlinear_iterations
unsigned int max_function_evaluations
Real absolute_residual_tolerance
Real relative_residual_tolerance
Real absolute_step_tolerance
Real relative_step_tolerance
unsigned int max_linear_iterations
Real initial_linear_tolerance
Real minimum_linear_tolerance
bool converged

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

sys_type_system
bool _is_initialized
Preconditioner< T > * _preconditioner

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

template<typename T>
class libMesh::NonlinearSolver< T >

This class provides a uniform interface for nonlinear solvers. This base class is overloaded to provide nonlinear solvers from different packages like PETSC.

Author:
Benjamin Kirk, 2005

Definition at line 54 of file nonlinear_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.


Constructor & Destructor Documentation

template<typename T >
libMesh::NonlinearSolver< T >::NonlinearSolver ( sys_type s  )  [inline, explicit]

Constructor. Initializes Solver data structures

Definition at line 312 of file nonlinear_solver.h.

00312                                                 :
00313   residual                     (NULL),
00314   residual_object              (NULL),
00315   jacobian                     (NULL),
00316   jacobian_object              (NULL),
00317   matvec                       (NULL),
00318   residual_and_jacobian_object (NULL),
00319   bounds                       (NULL),
00320   bounds_object                (NULL),
00321   nullspace                    (NULL),
00322   nullspace_object             (NULL),
00323   nearnullspace                (NULL),
00324   nearnullspace_object         (NULL),
00325   user_presolve                (NULL),
00326   max_nonlinear_iterations(0),
00327   max_function_evaluations(0),
00328   absolute_residual_tolerance(0),
00329   relative_residual_tolerance(0),
00330   absolute_step_tolerance(0),
00331   relative_step_tolerance(0),
00332   max_linear_iterations(0),
00333   initial_linear_tolerance(0),
00334   minimum_linear_tolerance(0),
00335   _system(s),
00336   _is_initialized (false),
00337   _preconditioner (NULL)
00338 {
00339 }

template<typename T >
libMesh::NonlinearSolver< T >::~NonlinearSolver (  )  [inline, virtual]

Destructor.

Definition at line 345 of file nonlinear_solver.h.

References libMesh::NonlinearSolver< T >::clear().

00346 {
00347   this->clear ();
00348 }


Member Function Documentation

template<typename T>
void libMesh::NonlinearSolver< T >::attach_preconditioner ( Preconditioner< T > *  preconditioner  )  [inline]

Attaches a Preconditioner object to be used during the linear solves.

Definition at line 91 of file nonlinear_solver.C.

References libMesh::NonlinearSolver< T >::_is_initialized, libMesh::NonlinearSolver< T >::_preconditioner, and libMesh::err.

00092 {
00093   if(this->_is_initialized)
00094   {
00095     libMesh::err << "Preconditioner must be attached before the solver is initialized!"<<std::endl;
00096     libmesh_error();
00097   }
00098 
00099   _preconditioner = preconditioner;
00100 }

template<typename T >
AutoPtr< NonlinearSolver< T > > libMesh::NonlinearSolver< T >::build ( sys_type s,
const SolverPackage  solver_package = libMesh::default_solver_package() 
) [inline, static]

Builds a NonlinearSolver using the nonlinear solver package specified by solver_package

Definition at line 38 of file nonlinear_solver.C.

References libMesh::err, libMesh::on_command_line(), libMeshEnums::PETSC_SOLVERS, libMesh::AutoPtr< Tp >::reset(), and libMesh::TRILINOS_SOLVERS.

00039 {
00040   AutoPtr<NonlinearSolver<T> > ap;
00041 
00042   // Build the appropriate solver
00043   switch (solver_package)
00044     {
00045 
00046 #ifdef LIBMESH_HAVE_PETSC
00047     case PETSC_SOLVERS:
00048 #if PETSC_VERSION_LESS_THAN(3,3,0)
00049       ap.reset(new PetscNonlinearSolver<T>(s));
00050       break;
00051 #else
00052       if (libMesh::on_command_line ("--use-petsc-dm")){
00053         ap.reset(new PetscDMNonlinearSolver<T>(s));
00054       }
00055       else {
00056         ap.reset(new PetscNonlinearSolver<T>(s));
00057       }
00058       break;
00059 #endif
00060 #endif // LIBMESH_HAVE_PETSC
00061 
00062 #ifdef LIBMESH_HAVE_NOX
00063     case TRILINOS_SOLVERS:
00064       ap.reset(new NoxNonlinearSolver<T>(s));
00065       break;
00066 #endif
00067 
00068     default:
00069       libMesh::err << "ERROR:  Unrecognized solver package: "
00070                     << solver_package
00071                     << std::endl;
00072       libmesh_error();
00073     }
00074 
00075   return ap;
00076 }

template<typename T>
virtual void libMesh::NonlinearSolver< T >::clear (  )  [inline, virtual]

Release all memory and clear data structures.

Reimplemented in libMesh::PetscNonlinearSolver< T >, libMesh::NoxNonlinearSolver< T >, and libMesh::NoxNonlinearSolver< Number >.

Definition at line 89 of file nonlinear_solver.h.

Referenced by libMesh::NonlinearSolver< T >::~NonlinearSolver().

00089 {}

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 }

template<typename T>
virtual unsigned libMesh::NonlinearSolver< T >::get_current_nonlinear_iteration_number (  )  const [pure virtual]

If called *during* the solve(), for example by the user-specified residual or Jacobian function, returns the current nonlinear iteration number. Must be redefined in derived classes.

Implemented in libMesh::PetscNonlinearSolver< T >, libMesh::NoxNonlinearSolver< T >, and libMesh::NoxNonlinearSolver< Number >.

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 }

template<typename T>
virtual int libMesh::NonlinearSolver< T >::get_total_linear_iterations (  )  [pure virtual]

Get the total number of linear iterations done in the last solve

Implemented in libMesh::PetscNonlinearSolver< T >, libMesh::NoxNonlinearSolver< T >, and libMesh::NoxNonlinearSolver< Number >.

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 }

template<typename T>
virtual void libMesh::NonlinearSolver< T >::init (  )  [pure virtual]
template<typename T>
bool libMesh::NonlinearSolver< T >::initialized (  )  const [inline]
Returns:
true if the data structures are initialized, false otherwise.

Definition at line 84 of file nonlinear_solver.h.

Referenced by libMesh::PetscNonlinearSolver< T >::clear(), libMesh::PetscNonlinearSolver< T >::get_converged_reason(), libMesh::NoxNonlinearSolver< T >::init(), and libMesh::PetscNonlinearSolver< T >::init().

00084 { return _is_initialized; }

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

template<typename T>
virtual void libMesh::NonlinearSolver< T >::print_converged_reason (  )  [inline, virtual]

Prints a useful message about why the latest nonlinear solve con(di)verged.

Reimplemented in libMesh::PetscNonlinearSolver< T >.

Definition at line 109 of file nonlinear_solver.h.

00109 { libmesh_not_implemented(); }

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 }

template<typename T>
virtual std::pair<unsigned int, Real> libMesh::NonlinearSolver< T >::solve ( SparseMatrix< T > &  ,
NumericVector< T > &  ,
NumericVector< T > &  ,
const   double,
const unsigned  int 
) [pure virtual]
template<typename T>
sys_type& libMesh::NonlinearSolver< T >::system (  )  [inline]
Returns:
a writeable reference to the system we are solving.

Definition at line 222 of file nonlinear_solver.h.

00222 { return _system; }


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().

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().

template<typename T>
sys_type& libMesh::NonlinearSolver< T >::_system [protected]

A reference to the system we are solving.

Definition at line 293 of file nonlinear_solver.h.

Referenced by libMesh::NonlinearSolver< Number >::system().

The NonlinearSolver 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 249 of file nonlinear_solver.h.

Referenced by libMesh::PetscDMNonlinearSolver< T >::init(), libMesh::NoxNonlinearSolver< T >::solve(), and libMesh::PetscNonlinearSolver< T >::solve().

The NonlinearSolver 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.

Note that not all NonlinearSolvers support relative_step_tolerance!

Definition at line 263 of file nonlinear_solver.h.

Referenced by libMesh::PetscDMNonlinearSolver< T >::init(), and libMesh::NoxNonlinearSolver< T >::solve().

template<typename T>
void(* libMesh::NonlinearSolver< T >::bounds)(NumericVector< Number > &XL, NumericVector< Number > &XU, sys_type &S)

Function that computes the lower and upper bounds XL and XU on the solution of the nonlinear system.

Object that computes the bounds vectors $ XL $ and $ XU $.

Definition at line 179 of file nonlinear_solver.h.

template<typename T>
bool libMesh::NonlinearSolver< T >::converged

After a call to solve this will reflect whether or not the nonlinear solve was successful.

Definition at line 287 of file nonlinear_solver.h.

Referenced by libMesh::NoxNonlinearSolver< T >::solve(), libMesh::PetscNonlinearSolver< T >::solve(), and libMesh::PetscDMNonlinearSolver< T >::solve().

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

Definition at line 276 of file nonlinear_solver.h.

Referenced by libMesh::PetscDMNonlinearSolver< T >::init(), libMesh::NoxNonlinearSolver< T >::solve(), and libMesh::PetscNonlinearSolver< T >::solve().

template<typename T>
void(* libMesh::NonlinearSolver< T >::jacobian)(const NumericVector< Number > &X, SparseMatrix< Number > &J, sys_type &S)
template<typename T>
void(* libMesh::NonlinearSolver< T >::matvec)(const NumericVector< Number > &X, NumericVector< Number > *R, SparseMatrix< Number > *J, sys_type &S)

Function that computes either the residual $ R(X) $ or the Jacobian $ J(X) $ of the nonlinear system at the input iterate $ X $. Note that either R or J could be XSNULL.

Referenced by libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), and libMesh::Problem_Interface::computePreconditioner().

template<typename T>
unsigned int libMesh::NonlinearSolver< T >::max_function_evaluations

Maximum number of function evaluations.

Definition at line 237 of file nonlinear_solver.h.

Referenced by libMesh::PetscDMNonlinearSolver< T >::init(), and libMesh::PetscNonlinearSolver< T >::solve().

template<typename T>
unsigned int libMesh::NonlinearSolver< T >::max_linear_iterations

Each linear solver step should exit after max_linear_iterations is exceeded.

Definition at line 270 of file nonlinear_solver.h.

Referenced by libMesh::PetscDMNonlinearSolver< T >::init(), libMesh::NoxNonlinearSolver< T >::solve(), and libMesh::PetscNonlinearSolver< T >::solve().

template<typename T>
unsigned int libMesh::NonlinearSolver< T >::max_nonlinear_iterations

The tolerance for linear solves is kept above this minimum

Definition at line 281 of file nonlinear_solver.h.

template<typename T>
void(* libMesh::NonlinearSolver< T >::nearnullspace)(std::vector< NumericVector< Number > * > &sp, sys_type &S)

Function that computes a basis for the Jacobian's near nullspace -- the set of "low energy modes" -- that can be used for AMG coarsening, if the solver supports it (e.g., ML, PETSc's GAMG).

Referenced by libMesh::PetscNonlinearSolver< T >::solve().

A callable object that computes a basis for the Jacobian's near nullspace -- the set of "low energy modes" -- that can be used for AMG coarsening, if the solver supports it (e.g., ML, PETSc's GAMG).

Definition at line 209 of file nonlinear_solver.h.

Referenced by libMesh::PetscNonlinearSolver< T >::solve().

template<typename T>
void(* libMesh::NonlinearSolver< T >::nullspace)(std::vector< NumericVector< Number > * > &sp, sys_type &S)

Function that computes a basis for the Jacobian's nullspace -- the kernel or the "zero energy modes" -- that can be used in solving a degenerate problem iteratively, if the solver supports it (e.g., PETSc's KSP).

Referenced by libMesh::PetscNonlinearSolver< T >::solve().

A callable object that computes a basis for the Jacobian's nullspace -- the kernel or the "zero energy modes" -- that can be used in solving a degenerate problem iteratively, if the solver supports it (e.g., PETSc's KSP).

Definition at line 195 of file nonlinear_solver.h.

Referenced by libMesh::PetscNonlinearSolver< T >::solve().

Definition at line 264 of file nonlinear_solver.h.

Referenced by libMesh::PetscNonlinearSolver< T >::solve().

template<typename T>
void(* libMesh::NonlinearSolver< T >::residual)(const NumericVector< Number > &X, NumericVector< Number > &R, sys_type &S)

Function that computes the residual R(X) of the nonlinear system at the input iterate X.

Referenced by libMesh::Problem_Interface::computeF().

Object that computes either the residual $ R(X) $ or the Jacobian $ J(X) $ of the nonlinear system at the input iterate $ X $. Note that either R or J could be XSNULL.

Definition at line 168 of file nonlinear_solver.h.

Referenced by libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::NoxNonlinearSolver< T >::solve(), and libMesh::PetscNonlinearSolver< T >::solve().

Object that computes the residual R(X) of the nonlinear system at the input iterate X.

Definition at line 135 of file nonlinear_solver.h.

Referenced by libMesh::Problem_Interface::computeF().


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

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

Hosted By:
SourceForge.net Logo