libMesh
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes | List of all members
libMesh::LaspackLinearSolver< T > Class Template Reference

This class provides an interface to Laspack iterative solvers that is compatible with the libMesh LinearSolver<> More...

#include <laspack_matrix.h>

Inheritance diagram for libMesh::LaspackLinearSolver< T >:
[legend]

Public Member Functions

 LaspackLinearSolver (const libMesh::Parallel::Communicator &comm)
 Constructor. More...
 
 ~LaspackLinearSolver ()
 Destructor. More...
 
virtual void clear () override
 Release all memory and clear data structures. More...
 
virtual void init (const char *name=nullptr) override
 Initialize data structures if not done so already. More...
 
virtual std::pair< unsigned int, Realsolve (SparseMatrix< T > &matrix, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its) override
 Call the Laspack solver. More...
 
virtual std::pair< unsigned int, Realadjoint_solve (SparseMatrix< T > &matrix, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its) override
 Call the Laspack solver to solve A^T x = b. More...
 
virtual std::pair< unsigned int, Realsolve (SparseMatrix< T > &matrix, SparseMatrix< T > &pc, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its) override
 Call the Laspack solver. More...
 
virtual std::pair< unsigned int, Realsolve (const ShellMatrix< T > &shell_matrix, NumericVector< T > &solution_in, NumericVector< T > &rhs_in, const double tol, const unsigned int m_its) override
 This function solves a system whose matrix is a shell matrix. More...
 
virtual std::pair< unsigned int, Realsolve (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) override
 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. More...
 
virtual void print_converged_reason () const override
 Prints a useful message about why the latest linear solve con(di)verged. More...
 
virtual LinearConvergenceReason get_converged_reason () const override
 
bool initialized () const
 
virtual void init_names (const System &)
 Apply names to the system to be solved. More...
 
SolverType solver_type () const
 
void set_solver_type (const SolverType st)
 Sets the type of solver to use. More...
 
PreconditionerType preconditioner_type () const
 
void set_preconditioner_type (const PreconditionerType pct)
 Sets the type of preconditioner to use. More...
 
void attach_preconditioner (Preconditioner< T > *preconditioner)
 Attaches a Preconditioner object to be used. More...
 
virtual void reuse_preconditioner (bool)
 Set the same_preconditioner flag, which indicates if we reuse the same preconditioner for subsequent solves. More...
 
bool get_same_preconditioner ()
 
virtual void restrict_solve_to (const std::vector< unsigned int > *const dofs, const SubsetSolveMode subset_solve_mode=SUBSET_ZERO)
 After calling this method, all successive solves will be restricted to the given set of dofs, which must contain local dofs on each processor only and not contain any duplicates. More...
 
std::pair< unsigned int, Realsolve (SparseMatrix< T > &matrix, SparseMatrix< T > *precond_matrix, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)
 This function calls the solver "_solver_type" preconditioned with the "_preconditioner_type" preconditioner. More...
 
std::pair< unsigned int, Realsolve (const ShellMatrix< T > &matrix, const SparseMatrix< T > *precond_matrix, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)
 This function solves a system whose matrix is a shell matrix, but an optional sparse matrix may be used as preconditioning matrix. More...
 
void set_solver_configuration (SolverConfiguration &solver_configuration)
 Set the solver configuration object. More...
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static std::unique_ptr< LinearSolver< T > > build (const libMesh::Parallel::Communicator &comm_in, const SolverPackage solver_package=libMesh::default_solver_package())
 Builds a LinearSolver using the linear solver package specified by solver_package. More...
 
static std::string get_info ()
 Gets a string containing the reference information. More...
 
static void print_info (std::ostream &out=libMesh::out)
 Prints the reference information, by default to libMesh::out. More...
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects. More...
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info() More...
 
static void disable_print_counter_info ()
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 Data structure to log the information. More...
 

Protected Member Functions

void increment_constructor_count (const std::string &name)
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name)
 Increments the destruction counter. More...
 

Protected Attributes

SolverType _solver_type
 Enum stating which type of iterative solver to use. More...
 
PreconditionerType _preconditioner_type
 Enum stating with type of preconditioner to use. More...
 
bool _is_initialized
 Flag indicating if the data structures have been initialized. More...
 
Preconditioner< T > * _preconditioner
 Holds the Preconditioner object to be used for the linear solves. More...
 
bool same_preconditioner
 Boolean flag to indicate whether we want to use an identical preconditioner to the previous solve. More...
 
SolverConfiguration_solver_configuration
 Optionally store a SolverOptions object that can be used to set parameters like solver type, tolerances and iteration limits. More...
 
const Parallel::Communicator_communicator
 

Static Protected Attributes

static Counts _counts
 Actually holds the data. More...
 
static Threads::atomic< unsigned int > _n_objects
 The number of objects. More...
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting. More...
 
static bool _enable_print_counter
 Flag to control whether reference count information is printed when print_info is called. More...
 

Private Member Functions

void set_laspack_preconditioner_type ()
 Tells LASPACK to use the user-specified preconditioner stored in _preconditioner_type. More...
 

Private Attributes

PrecondProcType _precond_type
 Preconditioner type. More...
 

Detailed Description

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

This class provides an interface to Laspack iterative solvers that is compatible with the libMesh LinearSolver<>

Author
Benjamin Kirk
Date
2002-2007

Definition at line 43 of file laspack_matrix.h.

Member Typedef Documentation

◆ Counts

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information.

The log is identified by the class name.

Definition at line 117 of file reference_counter.h.

Constructor & Destructor Documentation

◆ LaspackLinearSolver()

Constructor.

Initializes Laspack data structures

Definition at line 156 of file laspack_linear_solver.h.

156  :
157  LinearSolver<T>(comm),
158  _precond_type (ILUPrecond)
159 {
160 }
const Parallel::Communicator & comm() const
PrecondProcType _precond_type
Preconditioner type.

◆ ~LaspackLinearSolver()

template<typename T >
libMesh::LaspackLinearSolver< T >::~LaspackLinearSolver ( )

Destructor.

Definition at line 166 of file laspack_linear_solver.h.

167 {
168  this->clear ();
169 }
virtual void clear() override
Release all memory and clear data structures.

Member Function Documentation

◆ adjoint_solve()

template<typename T >
virtual std::pair<unsigned int, Real> libMesh::LaspackLinearSolver< T >::adjoint_solve ( SparseMatrix< T > &  matrix,
NumericVector< T > &  solution,
NumericVector< T > &  rhs,
const double  tol,
const unsigned int  m_its 
)
overridevirtual

Call the Laspack solver to solve A^T x = b.

Reimplemented from libMesh::LinearSolver< T >.

◆ attach_preconditioner()

template<typename T>
void libMesh::LinearSolver< T >::attach_preconditioner ( Preconditioner< T > *  preconditioner)
inherited

Attaches a Preconditioner object to be used.

◆ build()

template<typename T>
static std::unique_ptr<LinearSolver<T> > libMesh::LinearSolver< T >::build ( const libMesh::Parallel::Communicator comm_in,
const SolverPackage  solver_package = libMesh::default_solver_package() 
)
staticinherited

Builds a LinearSolver using the linear solver package specified by solver_package.

◆ clear()

template<typename T >
virtual void libMesh::LaspackLinearSolver< T >::clear ( )
overridevirtual

Release all memory and clear data structures.

Reimplemented from libMesh::LinearSolver< T >.

◆ comm()

const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inherited

◆ disable_print_counter_info()

static void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

◆ enable_print_counter_info()

static void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

◆ get_converged_reason()

template<typename T >
virtual LinearConvergenceReason libMesh::LaspackLinearSolver< T >::get_converged_reason ( ) const
overridevirtual
Returns
The solver's convergence flag.

Implements libMesh::LinearSolver< T >.

◆ get_info()

static std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

◆ get_same_preconditioner()

template<typename T >
bool libMesh::LinearSolver< T >::get_same_preconditioner ( )
inherited
Returns
same_preconditioner, which indicates if we reuse the same preconditioner for subsequent solves.

Definition at line 322 of file linear_solver.h.

323 {
324  return same_preconditioner;
325 }
bool same_preconditioner
Boolean flag to indicate whether we want to use an identical preconditioner to the previous solve...

◆ increment_constructor_count()

void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
protectedinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

Definition at line 181 of file reference_counter.h.

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

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

182 {
183  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
184  std::pair<unsigned int, unsigned int> & p = _counts[name];
185 
186  p.first++;
187 }
std::string name(const ElemQuality q)
static Counts _counts
Actually holds the data.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.

◆ increment_destructor_count()

void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
protectedinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

Definition at line 194 of file reference_counter.h.

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

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

195 {
196  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
197  std::pair<unsigned int, unsigned int> & p = _counts[name];
198 
199  p.second++;
200 }
std::string name(const ElemQuality q)
static Counts _counts
Actually holds the data.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.

◆ init()

template<typename T >
virtual void libMesh::LaspackLinearSolver< T >::init ( const char *  name = nullptr)
overridevirtual

Initialize data structures if not done so already.

Implements libMesh::LinearSolver< T >.

◆ init_names()

template<typename T>
virtual void libMesh::LinearSolver< T >::init_names ( const System )
virtualinherited

Apply names to the system to be solved.

For most packages this is a no-op; for PETSc this sets an option prefix from the system name and sets field names from the system's variable names.

Since field names are applied to DoF numberings, this method must be called again after any System reinit.

Reimplemented in libMesh::PetscLinearSolver< T >.

Definition at line 117 of file linear_solver.h.

117 {}

◆ initialized()

template<typename T>
bool libMesh::LinearSolver< T >::initialized ( ) const
inherited
Returns
true if the data structures are initialized, false otherwise.

Definition at line 96 of file linear_solver.h.

96 { return _is_initialized; }
bool _is_initialized
Flag indicating if the data structures have been initialized.

◆ n_objects()

static unsigned int libMesh::ReferenceCounter::n_objects ( )
staticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 83 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

84  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.

◆ n_processors()

processor_id_type libMesh::ParallelObject::n_processors ( ) const
inherited
Returns
The number of processors in the group.

Definition at line 93 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::size().

Referenced by libMesh::MeshBase::partition().

94  { return cast_int<processor_id_type>(_communicator.size()); }
processor_id_type size() const
Definition: communicator.h:175
const Parallel::Communicator & _communicator

◆ preconditioner_type()

template<typename T>
PreconditionerType libMesh::LinearSolver< T >::preconditioner_type ( ) const
inherited
Returns
The type of preconditioner to use.

◆ print_converged_reason()

template<typename T >
virtual void libMesh::LaspackLinearSolver< T >::print_converged_reason ( ) const
overridevirtual

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

Reimplemented from libMesh::LinearSolver< T >.

◆ print_info()

static void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

◆ processor_id()

processor_id_type libMesh::ParallelObject::processor_id ( ) const
inherited

◆ restrict_solve_to()

template<typename T>
virtual void libMesh::LinearSolver< T >::restrict_solve_to ( const std::vector< unsigned int > *const  dofs,
const SubsetSolveMode  subset_solve_mode = SUBSET_ZERO 
)
virtualinherited

After calling this method, all successive solves will be restricted to the given set of dofs, which must contain local dofs on each processor only and not contain any duplicates.

This mode can be disabled by calling this method with dofs being a nullptr.

Reimplemented in libMesh::PetscLinearSolver< T >.

◆ reuse_preconditioner()

template<typename T>
virtual void libMesh::LinearSolver< T >::reuse_preconditioner ( bool  )
virtualinherited

Set the same_preconditioner flag, which indicates if we reuse the same preconditioner for subsequent solves.

◆ set_laspack_preconditioner_type()

template<typename T >
void libMesh::LaspackLinearSolver< T >::set_laspack_preconditioner_type ( )
private

Tells LASPACK to use the user-specified preconditioner stored in _preconditioner_type.

◆ set_preconditioner_type()

template<typename T>
void libMesh::LinearSolver< T >::set_preconditioner_type ( const PreconditionerType  pct)
inherited

Sets the type of preconditioner to use.

◆ set_solver_configuration()

template<typename T>
void libMesh::LinearSolver< T >::set_solver_configuration ( SolverConfiguration solver_configuration)
inherited

Set the solver configuration object.

◆ set_solver_type()

template<typename T>
void libMesh::LinearSolver< T >::set_solver_type ( const SolverType  st)
inherited

Sets the type of solver to use.

Definition at line 127 of file linear_solver.h.

128  { _solver_type = st; }
SolverType _solver_type
Enum stating which type of iterative solver to use.

◆ solve() [1/6]

template<typename T >
virtual std::pair<unsigned int, Real> libMesh::LaspackLinearSolver< T >::solve ( SparseMatrix< T > &  matrix,
NumericVector< T > &  solution,
NumericVector< T > &  rhs,
const double  tol,
const unsigned int  m_its 
)
overridevirtual

Call the Laspack solver.

Implements libMesh::LinearSolver< T >.

◆ solve() [2/6]

template<typename T >
std::pair< unsigned int, Real > libMesh::LaspackLinearSolver< T >::solve ( SparseMatrix< T > &  matrix,
SparseMatrix< T > &  pc,
NumericVector< T > &  solution,
NumericVector< T > &  rhs,
const double  tol,
const unsigned int  m_its 
)
overridevirtual

Call the Laspack solver.

Implements libMesh::LinearSolver< T >.

Definition at line 176 of file laspack_linear_solver.h.

182 {
183  libmesh_error_msg("ERROR: LASPACK does not support a user-supplied preconditioner!");
184 
185  std::pair<unsigned int, Real> p;
186  return p;
187 }

◆ solve() [3/6]

template<typename T >
virtual std::pair<unsigned int, Real> libMesh::LaspackLinearSolver< T >::solve ( const ShellMatrix< T > &  shell_matrix,
NumericVector< T > &  solution_in,
NumericVector< T > &  rhs_in,
const double  tol,
const unsigned int  m_its 
)
overridevirtual

This function solves a system whose matrix is a shell matrix.

Implements libMesh::LinearSolver< T >.

◆ solve() [4/6]

template<typename T >
virtual std::pair<unsigned int, Real> libMesh::LaspackLinearSolver< T >::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 
)
overridevirtual

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.

Implements libMesh::LinearSolver< T >.

◆ solve() [5/6]

template<typename T>
std::pair< unsigned int, Real > libMesh::LinearSolver< T >::solve ( SparseMatrix< T > &  matrix,
SparseMatrix< T > *  precond_matrix,
NumericVector< T > &  sol,
NumericVector< T > &  rhs,
const double  tol,
const unsigned int  n_iter 
)
inherited

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 330 of file linear_solver.h.

336 {
337  if (pc_mat)
338  return this->solve(mat, *pc_mat, sol, rhs, tol, n_iter);
339  else
340  return this->solve(mat, sol, rhs, tol, n_iter);
341 }
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0
This function calls the solver _solver_type preconditioned with the _preconditioner_type precondition...

◆ solve() [6/6]

template<typename T>
std::pair< unsigned int, Real > libMesh::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 
)
inherited

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 347 of file linear_solver.h.

353 {
354  if (pc_mat)
355  return this->solve(mat, *pc_mat, sol, rhs, tol, n_iter);
356  else
357  return this->solve(mat, sol, rhs, tol, n_iter);
358 }
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0
This function calls the solver _solver_type preconditioned with the _preconditioner_type precondition...

◆ solver_type()

template<typename T>
SolverType libMesh::LinearSolver< T >::solver_type ( ) const
inherited
Returns
The type of solver to use.

Definition at line 122 of file linear_solver.h.

122 { return _solver_type; }
SolverType _solver_type
Enum stating which type of iterative solver to use.

Member Data Documentation

◆ _communicator

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited

◆ _counts

Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

◆ _enable_print_counter

bool libMesh::ReferenceCounter::_enable_print_counter
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

Definition at line 141 of file reference_counter.h.

◆ _is_initialized

template<typename T>
bool libMesh::LinearSolver< T >::_is_initialized
protectedinherited

Flag indicating if the data structures have been initialized.

Definition at line 287 of file linear_solver.h.

Referenced by libMesh::LinearSolver< Number >::initialized().

◆ _mutex

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 135 of file reference_counter.h.

◆ _n_objects

Threads::atomic<unsigned int> libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects.

Print the reference count information when the number returns to 0.

Definition at line 130 of file reference_counter.h.

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

◆ _precond_type

template<typename T >
PrecondProcType libMesh::LaspackLinearSolver< T >::_precond_type
private

Preconditioner type.

Definition at line 149 of file laspack_linear_solver.h.

◆ _preconditioner

template<typename T>
Preconditioner<T>* libMesh::LinearSolver< T >::_preconditioner
protectedinherited

Holds the Preconditioner object to be used for the linear solves.

Definition at line 292 of file linear_solver.h.

◆ _preconditioner_type

template<typename T>
PreconditionerType libMesh::LinearSolver< T >::_preconditioner_type
protectedinherited

Enum stating with type of preconditioner to use.

Definition at line 282 of file linear_solver.h.

◆ _solver_configuration

template<typename T>
SolverConfiguration* libMesh::LinearSolver< T >::_solver_configuration
protectedinherited

Optionally store a SolverOptions object that can be used to set parameters like solver type, tolerances and iteration limits.

Definition at line 306 of file linear_solver.h.

◆ _solver_type

template<typename T>
SolverType libMesh::LinearSolver< T >::_solver_type
protectedinherited

Enum stating which type of iterative solver to use.

Definition at line 277 of file linear_solver.h.

Referenced by libMesh::LinearSolver< Number >::set_solver_type(), and libMesh::LinearSolver< Number >::solver_type().

◆ same_preconditioner

template<typename T>
bool libMesh::LinearSolver< T >::same_preconditioner
protectedinherited

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 300 of file linear_solver.h.


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