DiffSolver Class Reference
#include <diff_solver.h>

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.
Definition at line 53 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.
The type of system
Definition at line 59 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 196 of file diff_solver.h.
00196 { 00201 INVALID_SOLVE_RESULT = 0, 00202 00207 CONVERGED_NO_REASON = 1, 00208 00213 CONVERGED_ABSOLUTE_RESIDUAL = 2, 00214 00219 CONVERGED_RELATIVE_RESIDUAL = 4, 00220 00225 CONVERGED_ABSOLUTE_STEP = 8, 00226 00231 CONVERGED_RELATIVE_STEP = 16, 00232 00237 DIVERGED_NO_REASON = 32, 00238 00244 DIVERGED_MAX_NONLINEAR_ITERATIONS = 64, 00245 00250 DIVERGED_BACKTRACKING_FAILURE = 128 00251 };
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.
00027 : max_linear_iterations(1000), 00028 max_nonlinear_iterations(100), 00029 quiet(true), 00030 continue_after_max_iterations(true), 00031 continue_after_backtrack_failure(false), 00032 absolute_residual_tolerance(0.), 00033 relative_residual_tolerance(0.), 00034 absolute_step_tolerance(0.), 00035 relative_step_tolerance(0.), 00036 initial_linear_tolerance(1e-12), 00037 minimum_linear_tolerance(TOLERANCE*TOLERANCE), 00038 max_solution_norm(0.), 00039 max_residual_norm(0.), 00040 _system (s), 00041 _solve_result(INVALID_SOLVE_RESULT) 00042 { 00043 }
| virtual DiffSolver::~DiffSolver | ( | ) | [inline, virtual] |
Member Function Documentation
| 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 TimeSolver::init().
00048 { 00049 return AutoPtr<DiffSolver>(new NewtonSolver(s)); 00050 }
| 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 QuadratureRules::name().
Referenced by ReferenceCounter::print_info().
00046 { 00047 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG) 00048 00049 std::ostringstream out; 00050 00051 out << '\n' 00052 << " ---------------------------------------------------------------------------- \n" 00053 << "| Reference count information |\n" 00054 << " ---------------------------------------------------------------------------- \n"; 00055 00056 for (Counts::iterator it = _counts.begin(); 00057 it != _counts.end(); ++it) 00058 { 00059 const std::string name(it->first); 00060 const unsigned int creations = it->second.first; 00061 const unsigned int destructions = it->second.second; 00062 00063 out << "| " << name << " reference count information:\n" 00064 << "| Creations: " << creations << '\n' 00065 << "| Destructions: " << destructions << '\n'; 00066 } 00067 00068 out << " ---------------------------------------------------------------------------- \n"; 00069 00070 return out.str(); 00071 00072 #else 00073 00074 return ""; 00075 00076 #endif 00077 }
| 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, and Threads::spin_mtx.
Referenced by ReferenceCountedObject< SparseMatrix< T > >::ReferenceCountedObject().
00150 { 00151 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 00152 std::pair<unsigned int, unsigned int>& p = _counts[name]; 00153 00154 p.first++; 00155 }
| 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, and Threads::spin_mtx.
Referenced by ReferenceCountedObject< SparseMatrix< T > >::~ReferenceCountedObject().
00168 { 00169 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 00170 std::pair<unsigned int, unsigned int>& p = _counts[name]; 00171 00172 p.second++; 00173 }
| 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().
00064 { 00065 // Reset the max_step_size and max_residual_norm for a new problem 00066 max_solution_norm = 0.; 00067 max_residual_norm = 0.; 00068 }
| 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.
00077 { 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().
00084 { 00085 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG) 00086 00087 std::cout << ReferenceCounter::get_info(); 00088 00089 #endif 00090 }
| 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().
00055 { 00056 // Reset the max_step_size and max_residual_norm for a new mesh 00057 max_solution_norm = 0.; 00058 max_residual_norm = 0.; 00059 }
| 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 112 of file diff_solver.h.
References _solve_result.
00112 { return _solve_result; }
| sys_type& DiffSolver::system | ( | ) | [inline] |
- Returns:
- a writeable reference to the system we are solving.
Definition at line 122 of file diff_solver.h.
References _system.
00122 { return _system; }
| const sys_type& DiffSolver::system | ( | ) | const [inline] |
- Returns:
- a constant reference to the system we are solving.
Definition at line 117 of file diff_solver.h.
References _system.
Referenced by __libmesh_petsc_diff_solver_jacobian(), and __libmesh_petsc_diff_solver_residual().
00117 { 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 107 of file diff_solver.h.
References _inner_iterations.
00107 { 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 101 of file diff_solver.h.
References _outer_iterations.
00101 { 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 276 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 271 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 289 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 281 of file diff_solver.h.
Referenced by NewtonSolver::line_search(), PetscDiffSolver::solve(), 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 165 of file diff_solver.h.
Referenced by NewtonSolver::print_convergence(), and 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 177 of file diff_solver.h.
Referenced by NewtonSolver::print_convergence(), and 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 154 of file diff_solver.h.
Referenced by 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 148 of file diff_solver.h.
Referenced by 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 184 of file diff_solver.h.
Referenced by NewtonSolver::solve().
| unsigned int DiffSolver::max_linear_iterations |
Each linear solver step should exit after max_linear_iterations is exceeded.
Definition at line 128 of file diff_solver.h.
Referenced by ContinuationSystem::continuation_solve(), NewtonSolver::solve(), and ContinuationSystem::solve_tangent().
| unsigned int DiffSolver::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.
Definition at line 136 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 266 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 259 of file diff_solver.h.
Referenced by init(), NewtonSolver::print_convergence(), reinit(), NewtonSolver::solve(), and NewtonSolver::test_convergence().
The tolerance for linear solves is kept above this minimum
Definition at line 189 of file diff_solver.h.
Referenced by NewtonSolver::solve().
| bool DiffSolver::quiet |
The DiffSolver should not print anything to std::cout unless quiet is set to false
Definition at line 142 of file diff_solver.h.
Referenced by NewtonSolver::line_search(), NewtonSolver::print_convergence(), and NewtonSolver::solve().
Definition at line 166 of file diff_solver.h.
Referenced by NewtonSolver::print_convergence(), and NewtonSolver::test_convergence().
Definition at line 178 of file diff_solver.h.
Referenced by NewtonSolver::print_convergence(), and NewtonSolver::test_convergence().
The documentation for this class was generated from the following files: