LinearSolver< T > Class Template Reference
#include <linear_solver.h>

Public Member Functions | |
| LinearSolver () | |
| virtual | ~LinearSolver () |
| bool | initialized () const |
| virtual void | clear () |
| virtual void | init ()=0 |
| SolverType | solver_type () const |
| void | set_solver_type (const SolverType st) |
| PreconditionerType | preconditioner_type () const |
| void | set_preconditioner_type (const PreconditionerType pct) |
| void | attach_preconditioner (Preconditioner< T > *preconditioner) |
| virtual std::pair< unsigned int, Real > | solve (SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0 |
| virtual std::pair< unsigned int, Real > | solve (SparseMatrix< T > &, SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0 |
| std::pair< unsigned int, Real > | solve (SparseMatrix< T > &matrix, SparseMatrix< T > *precond_matrix, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int) |
| virtual std::pair< unsigned int, Real > | solve (const ShellMatrix< T > &shell_matrix, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0 |
| virtual std::pair< unsigned int, Real > | solve (const ShellMatrix< T > &shell_matrix, const SparseMatrix< T > &precond_matrix, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0 |
| std::pair< unsigned int, Real > | solve (const ShellMatrix< T > &matrix, const SparseMatrix< T > *precond_matrix, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int) |
| virtual void | print_converged_reason ()=0 |
Static Public Member Functions | |
| static AutoPtr< LinearSolver< T > > | build (const SolverPackage solver_package=libMesh::default_solver_package()) |
| static std::string | get_info () |
| static void | print_info () |
| static unsigned int | n_objects () |
Public Attributes | |
| bool | same_preconditioner |
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 | |
| SolverType | _solver_type |
| PreconditionerType | _preconditioner_type |
| bool | _is_initialized |
| Preconditioner< T > * | _preconditioner |
Static Protected Attributes | |
| static Counts | _counts |
| static Threads::atomic < unsigned int > | _n_objects |
| static Threads::spin_mutex | _mutex |
Detailed Description
template<typename T>
class LinearSolver< T >
This class provides a uniform interface for linear solvers. This base class is overloaded to provide linear solvers from different packages like PETSC or LASPACK.
Definition at line 53 of file linear_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.
Constructor & Destructor Documentation
| LinearSolver< T >::LinearSolver | ( | ) | [inline] |
Constructor. Initializes Solver data structures
Definition at line 237 of file linear_solver.h.
00237 : 00238 00239 same_preconditioner (false), 00240 _solver_type (GMRES), 00241 _preconditioner_type (ILU_PRECOND), 00242 _is_initialized (false), 00243 _preconditioner (NULL) 00244 { 00245 }
| LinearSolver< T >::~LinearSolver | ( | ) | [inline, virtual] |
Destructor.
Definition at line 251 of file linear_solver.h.
References LinearSolver< T >::clear().
00252 { 00253 this->clear (); 00254 }
Member Function Documentation
| void LinearSolver< T >::attach_preconditioner | ( | Preconditioner< T > * | preconditioner | ) | [inline] |
Attaches a Preconditioner object to be used
Definition at line 103 of file linear_solver.C.
References LinearSolver< T >::_is_initialized, LinearSolver< T >::_preconditioner, LinearSolver< T >::_preconditioner_type, and libMeshEnums::SHELL_PRECOND.
00104 { 00105 if(this->_is_initialized) 00106 { 00107 std::cerr<<"Preconditioner must be attached before the solver is initialized!"<<std::endl; 00108 libmesh_error(); 00109 } 00110 00111 _preconditioner_type = SHELL_PRECOND; 00112 _preconditioner = preconditioner; 00113 }
| AutoPtr< LinearSolver< T > > LinearSolver< T >::build | ( | const SolverPackage | solver_package = libMesh::default_solver_package() |
) | [inline, static] |
Builds a LinearSolver using the linear solver package specified by solver_package
Definition at line 37 of file linear_solver.C.
References LASPACK_SOLVERS, libMeshEnums::PETSC_SOLVERS, and TRILINOS_SOLVERS.
Referenced by LegacyXdrIO::read_mesh().
00038 { 00039 // Build the appropriate solver 00040 switch (solver_package) 00041 { 00042 00043 00044 #ifdef LIBMESH_HAVE_LASPACK 00045 case LASPACK_SOLVERS: 00046 { 00047 AutoPtr<LinearSolver<T> > ap(new LaspackLinearSolver<T>); 00048 return ap; 00049 } 00050 #endif 00051 00052 00053 #ifdef LIBMESH_HAVE_PETSC 00054 case PETSC_SOLVERS: 00055 { 00056 AutoPtr<LinearSolver<T> > ap(new PetscLinearSolver<T>); 00057 return ap; 00058 } 00059 #endif 00060 00061 00062 #ifdef LIBMESH_HAVE_TRILINOS 00063 case TRILINOS_SOLVERS: 00064 { 00065 AutoPtr<LinearSolver<T> > ap(new AztecLinearSolver<T>); 00066 return ap; 00067 } 00068 #endif 00069 00070 default: 00071 std::cerr << "ERROR: Unrecognized solver package: " 00072 << solver_package 00073 << std::endl; 00074 libmesh_error(); 00075 } 00076 00077 AutoPtr<LinearSolver<T> > ap(NULL); 00078 return ap; 00079 }
| virtual void LinearSolver< T >::clear | ( | ) | [inline, virtual] |
Release all memory and clear data structures.
Reimplemented in LaspackLinearSolver< T >, PetscLinearSolver< T >, and AztecLinearSolver< T >.
Definition at line 83 of file linear_solver.h.
Referenced by LinearSolver< T >::~LinearSolver().
| 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 }
| virtual void LinearSolver< T >::init | ( | ) | [pure virtual] |
Initialize data structures if not done so already.
Implemented in LaspackLinearSolver< T >, PetscLinearSolver< T >, and AztecLinearSolver< T >.
| bool LinearSolver< T >::initialized | ( | ) | const [inline] |
- Returns:
- true if the data structures are initialized, false otherwise.
Definition at line 78 of file linear_solver.h.
References LinearSolver< T >::_is_initialized.
Referenced by AztecLinearSolver< T >::clear(), PetscLinearSolver< T >::clear(), LaspackLinearSolver< T >::clear(), AztecLinearSolver< T >::init(), PetscLinearSolver< T >::init(), and LaspackLinearSolver< T >::init().
00078 { return _is_initialized; }
| 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; }
| PreconditionerType LinearSolver< T >::preconditioner_type | ( | ) | const [inline] |
Returns the type of preconditioner to use.
Definition at line 83 of file linear_solver.C.
References LinearSolver< T >::_preconditioner, and LinearSolver< T >::_preconditioner_type.
00084 { 00085 if(_preconditioner) 00086 return _preconditioner->type(); 00087 00088 return _preconditioner_type; 00089 }
| virtual void LinearSolver< T >::print_converged_reason | ( | ) | [pure virtual] |
Prints a useful message about why the latest linear solve con(di)verged.
Implemented in LaspackLinearSolver< T >, PetscLinearSolver< T >, and AztecLinearSolver< T >.
| 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 LinearSolver< T >::set_preconditioner_type | ( | const PreconditionerType | pct | ) | [inline] |
Sets the type of preconditioner to use.
Definition at line 93 of file linear_solver.C.
References LinearSolver< T >::_preconditioner, and LinearSolver< T >::_preconditioner_type.
00094 { 00095 if(_preconditioner) 00096 _preconditioner->set_type(pct); 00097 else 00098 _preconditioner_type = pct; 00099 }
| void LinearSolver< T >::set_solver_type | ( | const SolverType | st | ) | [inline] |
Sets the type of solver to use.
Definition at line 98 of file linear_solver.h.
References LinearSolver< T >::_solver_type.
00099 { _solver_type = st; }
| std::pair< unsigned int, Real > LinearSolver< T >::solve | ( | const ShellMatrix< T > & | matrix, | |
| const SparseMatrix< T > * | precond_matrix, | |||
| NumericVector< T > & | sol, | |||
| NumericVector< T > & | rhs, | |||
| const double | tol, | |||
| const unsigned int | n_iter | |||
| ) | [inline] |
This function solves a system whose matrix is a shell matrix, but an optional sparse matrix may be used as preconditioning matrix.
Definition at line 278 of file linear_solver.h.
References LinearSolver< T >::solve().
00284 { 00285 if (pc_mat) 00286 return this->solve(mat, *pc_mat, sol, rhs, tol, n_iter); 00287 else 00288 return this->solve(mat, sol, rhs, tol, n_iter); 00289 }
| virtual std::pair<unsigned int, Real> LinearSolver< T >::solve | ( | const ShellMatrix< T > & | shell_matrix, | |
| const SparseMatrix< T > & | precond_matrix, | |||
| NumericVector< T > & | , | |||
| NumericVector< T > & | , | |||
| const | double, | |||
| const unsigned | int | |||
| ) | [pure virtual] |
This function solves a system whose matrix is a shell matrix, but a sparse matrix is used as preconditioning matrix, this allowing other preconditioners than JACOBI.
Implemented in LaspackLinearSolver< T >, PetscLinearSolver< T >, and AztecLinearSolver< T >.
| virtual std::pair<unsigned int, Real> LinearSolver< T >::solve | ( | const ShellMatrix< T > & | shell_matrix, | |
| NumericVector< T > & | , | |||
| NumericVector< T > & | , | |||
| const | double, | |||
| const unsigned | int | |||
| ) | [pure virtual] |
This function solves a system whose matrix is a shell matrix.
Implemented in LaspackLinearSolver< T >, PetscLinearSolver< T >, and AztecLinearSolver< T >.
| std::pair< unsigned int, Real > LinearSolver< T >::solve | ( | SparseMatrix< T > & | matrix, | |
| SparseMatrix< T > * | precond_matrix, | |||
| NumericVector< T > & | sol, | |||
| NumericVector< T > & | rhs, | |||
| const double | tol, | |||
| const unsigned int | n_iter | |||
| ) | [inline] |
This function calls the solver "_solver_type" preconditioned with the "_preconditioner_type" preconditioner. The preconditioning matrix is used if it is provided, or the system matrix is used if precond_matrix is null
Definition at line 261 of file linear_solver.h.
References LinearSolver< T >::solve().
00267 { 00268 if (pc_mat) 00269 return this->solve(mat, *pc_mat, sol, rhs, tol, n_iter); 00270 else 00271 return this->solve(mat, sol, rhs, tol, n_iter); 00272 }
| virtual std::pair<unsigned int, Real> LinearSolver< T >::solve | ( | SparseMatrix< T > & | , | |
| SparseMatrix< T > & | , | |||
| NumericVector< T > & | , | |||
| NumericVector< T > & | , | |||
| const | double, | |||
| const unsigned | int | |||
| ) | [pure virtual] |
This function calls the solver "_solver_type" preconditioned with the "_preconditioner_type" preconditioner.
Implemented in LaspackLinearSolver< T >, PetscLinearSolver< T >, and AztecLinearSolver< T >.
| virtual std::pair<unsigned int, Real> LinearSolver< T >::solve | ( | SparseMatrix< T > & | , | |
| NumericVector< T > & | , | |||
| NumericVector< T > & | , | |||
| const | double, | |||
| const unsigned | int | |||
| ) | [pure virtual] |
This function calls the solver "_solver_type" preconditioned with the "_preconditioner_type" preconditioner. Note that this method will compute the preconditioner from the system matrix.
Implemented in LaspackLinearSolver< T >, PetscLinearSolver< T >, and AztecLinearSolver< T >.
Referenced by ImplicitSystem::adjoint_solve(), ImplicitSystem::sensitivity_solve(), LinearSolver< T >::solve(), ImplicitSystem::weighted_sensitivity_adjoint_solve(), and ImplicitSystem::weighted_sensitivity_solve().
| SolverType LinearSolver< T >::solver_type | ( | ) | const [inline] |
Returns the type of solver to use.
Definition at line 93 of file linear_solver.h.
References LinearSolver< T >::_solver_type.
00093 { return _solver_type; }
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().
bool LinearSolver< T >::_is_initialized [protected] |
Flag indicating if the data structures have been initialized.
Definition at line 223 of file linear_solver.h.
Referenced by LinearSolver< T >::attach_preconditioner(), AztecLinearSolver< T >::clear(), PetscLinearSolver< T >::clear(), LaspackLinearSolver< T >::clear(), AztecLinearSolver< T >::init(), PetscLinearSolver< T >::init(), LaspackLinearSolver< T >::init(), and LinearSolver< T >::initialized().
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().
Preconditioner<T>* LinearSolver< T >::_preconditioner [protected] |
Holds the Preconditioner object to be used for the linear solves.
Definition at line 228 of file linear_solver.h.
Referenced by LinearSolver< T >::attach_preconditioner(), PetscLinearSolver< T >::clear(), PetscLinearSolver< T >::init(), LinearSolver< T >::preconditioner_type(), LinearSolver< T >::set_preconditioner_type(), and PetscLinearSolver< T >::solve().
PreconditionerType LinearSolver< T >::_preconditioner_type [protected] |
Enum statitng with type of preconditioner to use.
Definition at line 218 of file linear_solver.h.
Referenced by LinearSolver< T >::attach_preconditioner(), AztecLinearSolver< T >::AztecLinearSolver(), AztecLinearSolver< T >::clear(), PetscLinearSolver< T >::clear(), LaspackLinearSolver< T >::clear(), AztecLinearSolver< T >::init(), PetscLinearSolver< T >::init(), PetscLinearSolver< T >::PetscLinearSolver(), LinearSolver< T >::preconditioner_type(), LaspackLinearSolver< T >::set_laspack_preconditioner_type(), and LinearSolver< T >::set_preconditioner_type().
SolverType LinearSolver< T >::_solver_type [protected] |
Enum stating which type of iterative solver to use.
Definition at line 213 of file linear_solver.h.
Referenced by AztecLinearSolver< T >::clear(), PetscLinearSolver< T >::clear(), LaspackLinearSolver< T >::clear(), PetscLinearSolver< T >::set_petsc_solver_type(), LinearSolver< T >::set_solver_type(), LaspackLinearSolver< T >::solve(), and LinearSolver< T >::solver_type().
| bool LinearSolver< T >::same_preconditioner |
Boolean flag to indicate whether we want to use an identical preconditioner to the previous solve. This can save substantial work in the cases where the system matrix is the same for successive solves.
Definition at line 205 of file linear_solver.h.
Referenced by PetscLinearSolver< T >::solve().
The documentation for this class was generated from the following files: