#include <trilinos_aztec_linear_solver.h>
AztecLinearSolver ()
~AztecLinearSolver ()
void clear ()
void init ()
std::pair< unsigned int, Real > solve (SparseMatrix< T > &matrix_in, NumericVector< T > &solution_in, NumericVector< T > &rhs_in, const double tol, const unsigned int m_its)
std::pair< unsigned int, Real > solve (SparseMatrix< T > &matrix, SparseMatrix< T > &preconditioner, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its)
std::pair< unsigned int, Real > solve (const ShellMatrix< T > &shell_matrix, NumericVector< T > &solution_in, NumericVector< T > &rhs_in, const double tol, const unsigned int m_its)
virtual std::pair< unsigned int, Real > solve (const ShellMatrix< T > &shell_matrix, const SparseMatrix< T > &precond_matrix, NumericVector< T > &solution_in, NumericVector< T > &rhs_in, const double tol, const unsigned int m_its)
void get_residual_history (std::vector< double > &hist)
Real get_initial_residual ()
virtual void print_converged_reason ()
bool initialized () const
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)
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 ()
typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
void increment_constructor_count (const std::string &name)
void increment_destructor_count (const std::string &name)
SolverType _solver_type
PreconditionerType _preconditioner_type
bool _is_initialized
Preconditioner< T > * _preconditioner
static Counts _counts
static Threads::atomic< unsigned int > _n_objects
static Threads::spin_mutex _mutex
Epetra_LinearProblem * _linear_problem
AztecOO * _linear_solver
Author:
Definition at line 50 of file trilinos_aztec_linear_solver.h.
Definition at line 105 of file reference_counter.h.
Definition at line 161 of file trilinos_aztec_linear_solver.h.
References libMeshEnums::BLOCK_JACOBI_PRECOND, libMeshEnums::ILU_PRECOND, and libMesh::n_processors().
{
if (libMesh::n_processors() == 1)
this->_preconditioner_type = ILU_PRECOND;
else
this->_preconditioner_type = BLOCK_JACOBI_PRECOND;
}
Definition at line 173 of file trilinos_aztec_linear_solver.h.
{
this->clear ();
}
Definition at line 103 of file linear_solver.C.
References libMesh::libMeshPrivateData::_is_initialized, and libMeshEnums::SHELL_PRECOND.
{
if(this->_is_initialized)
{
std::cerr<<'Preconditioner must be attached before the solver is initialized!'<<std::endl;
libmesh_error();
}
_preconditioner_type = SHELL_PRECOND;
_preconditioner = preconditioner;
}
Definition at line 37 of file linear_solver.C.
References LASPACK_SOLVERS, libMeshEnums::PETSC_SOLVERS, and TRILINOS_SOLVERS.
Referenced by LegacyXdrIO::read_mesh().
{
// Build the appropriate solver
switch (solver_package)
{
#ifdef LIBMESH_HAVE_LASPACK
case LASPACK_SOLVERS:
{
AutoPtr<LinearSolver<T> > ap(new LaspackLinearSolver<T>);
return ap;
}
#endif
#ifdef LIBMESH_HAVE_PETSC
case PETSC_SOLVERS:
{
AutoPtr<LinearSolver<T> > ap(new PetscLinearSolver<T>);
return ap;
}
#endif
#ifdef LIBMESH_HAVE_TRILINOS
case TRILINOS_SOLVERS:
{
AutoPtr<LinearSolver<T> > ap(new AztecLinearSolver<T>);
return ap;
}
#endif
default:
std::cerr << 'ERROR: Unrecognized solver package: '
<< solver_package
<< std::endl;
libmesh_error();
}
AutoPtr<LinearSolver<T> > ap(NULL);
return ap;
}
Reimplemented from LinearSolver< T >.
Definition at line 38 of file trilinos_aztec_linear_solver.C.
References libMesh::libMeshPrivateData::_is_initialized, libMeshEnums::BLOCK_JACOBI_PRECOND, libMeshEnums::GMRES, libMeshEnums::ILU_PRECOND, libMesh::initialized(), and libMesh::n_processors().
{
if (this->initialized())
{
this->_is_initialized = false;
// Mimic PETSc default solver and preconditioner
this->_solver_type = GMRES;
if (libMesh::n_processors() == 1)
this->_preconditioner_type = ILU_PRECOND;
else
this->_preconditioner_type = BLOCK_JACOBI_PRECOND;
}
}
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
}
Definition at line 199 of file trilinos_aztec_linear_solver.C.
{
return _linear_solver->TrueResidual();
}
Definition at line 164 of file trilinos_aztec_linear_solver.C.
{
libmesh_not_implemented();
// int ierr = 0;
// int its = 0;
// // Fill the residual history vector with the residual norms
// // Note that GetResidualHistory() does not copy any values, it
// // simply sets the pointer p. Note that for some Krylov subspace
// // methods, the number of residuals returned in the history
// // vector may be different from what you are expecting. For
// // example, TFQMR returns two residual values per iteration step.
// PetscReal* p;
// ierr = KSPGetResidualHistory(_ksp, &p, &its);
// CHKERRABORT(libMesh::COMM_WORLD,ierr);
// // Check for early return
// if (its == 0) return;
// // Create space to store the result
// hist.resize(its);
// // Copy history into the vector provided by the user.
// for (int i=0; i<its; ++i)
// {
// hist[i] = *p;
// p++;
// }
}
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++;
}
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++;
}
Implements LinearSolver< T >.
Definition at line 57 of file trilinos_aztec_linear_solver.C.
References libMesh::libMeshPrivateData::_is_initialized, libMeshEnums::BLOCK_JACOBI_PRECOND, libMeshEnums::ILU_PRECOND, and libMesh::initialized().
{
// Initialize the data structures if not done so already.
if (!this->initialized())
{
this->_is_initialized = true;
_linear_solver = new AztecOO();
switch(this->_preconditioner_type)
{
case ILU_PRECOND:
_linear_solver->SetAztecOption(AZ_precond,AZ_dom_decomp);
break;
case BLOCK_JACOBI_PRECOND:
_linear_solver->SetAztecOption(AZ_precond,AZ_Jacobi);
break;
default:
_linear_solver->SetAztecOption(AZ_precond,AZ_dom_decomp);
}
}
}
Definition at line 78 of file linear_solver.h.
{ return _is_initialized; }
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; }
Definition at line 83 of file linear_solver.C.
{
if(_preconditioner)
return _preconditioner->type();
return _preconditioner_type;
}
Implements LinearSolver< T >.
Definition at line 207 of file trilinos_aztec_linear_solver.C.
{
libmesh_not_implemented();
// #if PETSC_VERSION_LESS_THAN(2,3,1)
// std::cout << 'This method is currently not supported '
// << '(but may work!) for Petsc 2.3.0 and earlier.' << std::endl;
// #else
// KSPConvergedReason reason;
// KSPGetConvergedReason(_ksp, &reason);
// // KSP_CONVERGED_RTOL (residual 2-norm decreased by a factor of rtol, from 2-norm of right hand side)
// // KSP_CONVERGED_ATOL (residual 2-norm less than abstol)
// // KSP_CONVERGED_ITS (used by the preonly preconditioner that always uses ONE iteration)
// // KSP_CONVERGED_STEP_LENGTH
// // KSP_DIVERGED_ITS (required more than its to reach convergence)
// // KSP_DIVERGED_DTOL (residual norm increased by a factor of divtol)
// // KSP_DIVERGED_NAN (residual norm became Not-a-number likely do to 0/0)
// // KSP_DIVERGED_BREAKDOWN (generic breakdown in method)
// switch (reason)
// {
// case KSP_CONVERGED_RTOL:
// {
// std::cout << 'Linear solver converged, relative tolerance reached.' << std::endl;
// break;
// }
// case KSP_CONVERGED_ATOL:
// {
// std::cout << 'Linear solver converged, absolute tolerance reached.' << std::endl;
// break;
// }
// // Divergence
// case KSP_DIVERGED_ITS:
// {
// std::cout << 'Linear solver diverged, max no. of iterations reached.' << std::endl;
// break;
// }
// case KSP_DIVERGED_DTOL:
// {
// std::cout << 'Linear solver diverged, residual norm increase by dtol (default 1.e5).' << std::endl;
// break;
// }
// case KSP_DIVERGED_NAN:
// {
// std::cout << 'Linear solver diverged, residual norm is NaN.' << std::endl;
// break;
// }
// case KSP_DIVERGED_BREAKDOWN:
// {
// std::cout << 'Linear solver diverged, generic breakdown in the method.' << std::endl;
// break;
// }
// default:
// {
// std::cout << 'Unknown/unsupported con(di)vergence reason: ' << reason << std::endl;
// }
// }
// #endif
}
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
}
Definition at line 93 of file linear_solver.C.
{
if(_preconditioner)
_preconditioner->set_type(pct);
else
_preconditioner_type = pct;
}
Definition at line 98 of file linear_solver.h.
{ _solver_type = st; }
Implements LinearSolver< T >.
Definition at line 127 of file trilinos_aztec_linear_solver.C.
{
libmesh_not_implemented();
}
Implements LinearSolver< T >.
Definition at line 78 of file trilinos_aztec_linear_solver.h.
{
return this->solve(matrix_in, matrix_in, solution_in, rhs_in, tol, m_its);
}
Implements LinearSolver< T >.
Definition at line 145 of file trilinos_aztec_linear_solver.C.
{
libmesh_not_implemented();
}
Implements LinearSolver< T >.
Definition at line 85 of file trilinos_aztec_linear_solver.C.
References EpetraMatrix< T >::close(), libMesh::init(), and EpetraMatrix< T >::mat().
{
START_LOG('solve()', 'AztecLinearSolver');
// Make sure the data passed in are really of Epetra types
EpetraMatrix<T>* matrix = libmesh_cast_ptr<EpetraMatrix<T>*>(&matrix_in);
EpetraMatrix<T>* precond = libmesh_cast_ptr<EpetraMatrix<T>*>(&precond_in);
EpetraVector<T>* solution = libmesh_cast_ptr<EpetraVector<T>*>(&solution_in);
EpetraVector<T>* rhs = libmesh_cast_ptr<EpetraVector<T>*>(&rhs_in);
this->init();
// Close the matrices and vectors in case this wasn't already done.
matrix->close ();
precond->close ();
solution->close ();
rhs->close ();
_linear_solver->SetAztecOption(AZ_max_iter,m_its);
_linear_solver->SetAztecParam(AZ_tol,tol);
Epetra_FECrsMatrix * emat = matrix->mat();
Epetra_Vector * esol = solution->vec();
Epetra_Vector * erhs = rhs->vec();
_linear_solver->Iterate(emat, esol, erhs, m_its, tol);
STOP_LOG('solve()', 'AztecLinearSolver');
// return the # of its. and the final residual norm.
return std::make_pair(_linear_solver->NumIters(), _linear_solver->TrueResidual());
}
Definition at line 93 of file linear_solver.h.
{ return _solver_type; }
Definition at line 110 of file reference_counter.h.
Referenced by ReferenceCounter::get_info(), ReferenceCounter::increment_constructor_count(), and ReferenceCounter::increment_destructor_count().
Definition at line 200 of file linear_solver.h.
Referenced by LinearSolver< Number >::initialized().
Definition at line 149 of file trilinos_aztec_linear_solver.h.
Definition at line 154 of file trilinos_aztec_linear_solver.h.
Definition at line 123 of file reference_counter.h.
Definition at line 118 of file reference_counter.h.
Referenced by ReferenceCounter::n_objects(), ReferenceCounter::ReferenceCounter(), and ReferenceCounter::~ReferenceCounter().
Definition at line 205 of file linear_solver.h.
Definition at line 195 of file linear_solver.h.
Definition at line 190 of file linear_solver.h.
Referenced by LinearSolver< Number >::set_solver_type(), and LinearSolver< Number >::solver_type().
Definition at line 182 of file linear_solver.h.
Generated automatically by Doxygen for libMesh from the source code.