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

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

#include <petsc_linear_solver.h>

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

Public Member Functions

 PetscLinearSolver (const libMesh::Parallel::Communicator &comm_in)
 Constructor. More...
 
 ~PetscLinearSolver ()
 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...
 
void init (PetscMatrix< T > *matrix, const char *name=nullptr)
 Initialize data structures if not done so already plus much more. More...
 
virtual void init_names (const System &) override
 Apply names to the system to be solved. More...
 
virtual void restrict_solve_to (const std::vector< unsigned int > *const dofs, const SubsetSolveMode subset_solve_mode=SUBSET_ZERO) override
 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...
 
virtual std::pair< unsigned int, Realsolve (SparseMatrix< T > &matrix_in, NumericVector< T > &solution_in, NumericVector< T > &rhs_in, const double tol, const unsigned int m_its) override
 Call the Petsc solver. More...
 
virtual std::pair< unsigned int, Realadjoint_solve (SparseMatrix< T > &matrix_in, NumericVector< T > &solution_in, NumericVector< T > &rhs_in, const double tol, const unsigned int m_its) override
 Call the Petsc solver. More...
 
virtual std::pair< unsigned int, Realsolve (SparseMatrix< T > &matrix, SparseMatrix< T > &preconditioner, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its) override
 This method allows you to call a linear solver while specifying the matrix to use as the (left) preconditioning matrix. 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...
 
PC pc ()
 
KSP ksp ()
 
void get_residual_history (std::vector< double > &hist)
 Fills the input vector with the sequence of residual norms from the latest iterative solve. More...
 
Real get_initial_residual ()
 
virtual LinearConvergenceReason get_converged_reason () const override
 
bool initialized () const
 
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 ()
 
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...
 
virtual void print_converged_reason () const
 Prints a useful message about why the latest linear solve con(di)verged. 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_petsc_solver_type ()
 Tells PETSC to use the user-specified solver stored in _solver_type. More...
 
PetscInt _restrict_solve_to_is_local_size () const
 
void _create_complement_is (const NumericVector< T > &vec_in)
 Creates _restrict_solve_to_is_complement to contain all indices that are local in vec_in, except those that are contained in _restrict_solve_to_is. More...
 

Static Private Member Functions

static PetscErrorCode _petsc_shell_matrix_mult (Mat mat, Vec arg, Vec dest)
 Internal function if shell matrix mode is used. More...
 
static PetscErrorCode _petsc_shell_matrix_mult_add (Mat mat, Vec arg, Vec add, Vec dest)
 Internal function if shell matrix mode is used. More...
 
static PetscErrorCode _petsc_shell_matrix_get_diagonal (Mat mat, Vec dest)
 Internal function if shell matrix mode is used. More...
 

Private Attributes

PC _pc
 Preconditioner context. More...
 
KSP _ksp
 Krylov subspace context. More...
 
IS _restrict_solve_to_is
 PETSc index set containing the dofs on which to solve (nullptr means solve on all dofs). More...
 
IS _restrict_solve_to_is_complement
 PETSc index set, complement to _restrict_solve_to_is. More...
 
SubsetSolveMode _subset_solve_mode
 If restrict-solve-to-subset mode is active, this member decides what happens with the dofs outside the subset. More...
 

Detailed Description

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

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

Author
Benjamin Kirk
Date
2002-2007

Definition at line 101 of file petsc_linear_solver.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

◆ PetscLinearSolver()

template<typename T >
libMesh::PetscLinearSolver< T >::PetscLinearSolver ( const libMesh::Parallel::Communicator comm_in)

Constructor.

Initializes Petsc data structures

◆ ~PetscLinearSolver()

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

Destructor.

Definition at line 331 of file petsc_linear_solver.h.

332 {
333  this->clear ();
334 }
virtual void clear() override
Release all memory and clear data structures.

Member Function Documentation

◆ _create_complement_is()

template<typename T >
void libMesh::PetscLinearSolver< T >::_create_complement_is ( const NumericVector< T > &  vec_in)
private

Creates _restrict_solve_to_is_complement to contain all indices that are local in vec_in, except those that are contained in _restrict_solve_to_is.

Definition at line 355 of file petsc_linear_solver.h.

362 {
363  libmesh_assert(_restrict_solve_to_is);
364 #if PETSC_VERSION_LESS_THAN(3,0,0)
365  // No ISComplement in PETSc 2.3.3
366  libmesh_not_implemented();
367 #else
369  {
370  int ierr = ISComplement(_restrict_solve_to_is,
371  vec_in.first_local_index(),
372  vec_in.last_local_index(),
374  LIBMESH_CHKERR(ierr);
375  }
376 #endif
377 }
IS _restrict_solve_to_is
PETSc index set containing the dofs on which to solve (nullptr means solve on all dofs)...
IS _restrict_solve_to_is_complement
PETSc index set, complement to _restrict_solve_to_is.

◆ _petsc_shell_matrix_get_diagonal()

template<typename T >
static PetscErrorCode libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal ( Mat  mat,
Vec  dest 
)
staticprivate

Internal function if shell matrix mode is used.

◆ _petsc_shell_matrix_mult()

template<typename T >
static PetscErrorCode libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult ( Mat  mat,
Vec  arg,
Vec  dest 
)
staticprivate

Internal function if shell matrix mode is used.

◆ _petsc_shell_matrix_mult_add()

template<typename T >
static PetscErrorCode libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add ( Mat  mat,
Vec  arg,
Vec  add,
Vec  dest 
)
staticprivate

Internal function if shell matrix mode is used.

◆ _restrict_solve_to_is_local_size()

template<typename T >
PetscInt libMesh::PetscLinearSolver< T >::_restrict_solve_to_is_local_size ( ) const
private
Returns
The local size of _restrict_solve_to_is.

Definition at line 340 of file petsc_linear_solver.h.

341 {
342  libmesh_assert(_restrict_solve_to_is);
343 
344  PetscInt s;
345  int ierr = ISGetLocalSize(_restrict_solve_to_is, &s);
346  LIBMESH_CHKERR(ierr);
347 
348  return s;
349 }
IS _restrict_solve_to_is
PETSc index set containing the dofs on which to solve (nullptr means solve on all dofs)...

◆ adjoint_solve()

template<typename T >
virtual std::pair<unsigned int, Real> libMesh::PetscLinearSolver< T >::adjoint_solve ( SparseMatrix< T > &  matrix_in,
NumericVector< T > &  solution_in,
NumericVector< T > &  rhs_in,
const double  tol,
const unsigned int  m_its 
)
overridevirtual

Call the Petsc solver.

It calls the method below, using the same matrix for the system and preconditioner matrices.

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::PetscLinearSolver< 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::PetscLinearSolver< 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_initial_residual()

template<typename T >
Real libMesh::PetscLinearSolver< T >::get_initial_residual ( )
Returns
Just the initial residual for the solve just completed with this interface.

Use this method instead of the one above if you just want the starting residual and not the entire history.

◆ get_residual_history()

template<typename T >
void libMesh::PetscLinearSolver< T >::get_residual_history ( std::vector< double > &  hist)

Fills the input vector with the sequence of residual norms from the latest iterative solve.

◆ 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() [1/2]

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

Initialize data structures if not done so already.

Assigns a name, which is turned into an underscore-separated prefix for the underlying KSP object.

Implements libMesh::LinearSolver< T >.

Referenced by libMesh::PetscLinearSolver< T >::ksp(), and libMesh::PetscLinearSolver< T >::pc().

◆ init() [2/2]

template<typename T >
void libMesh::PetscLinearSolver< T >::init ( PetscMatrix< T > *  matrix,
const char *  name = nullptr 
)

Initialize data structures if not done so already plus much more.

◆ init_names()

template<typename T >
virtual void libMesh::PetscLinearSolver< T >::init_names ( const System )
overridevirtual

Apply names to the system to be solved.

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 from libMesh::LinearSolver< T >.

◆ 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.

◆ ksp()

template<typename T >
KSP libMesh::PetscLinearSolver< T >::ksp ( )
Returns
The raw PETSc ksp context pointer.

This is useful if you are for example setting a custom convergence test with KSPSetConvergenceTest().

Definition at line 240 of file petsc_linear_solver.h.

References libMesh::PetscLinearSolver< T >::_ksp, and libMesh::PetscLinearSolver< T >::init().

240 { this->init(); return _ksp; }
KSP _ksp
Krylov subspace context.
virtual void init(const char *name=nullptr) override
Initialize data structures if not done so already.

◆ 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

◆ pc()

template<typename T >
PC libMesh::PetscLinearSolver< T >::pc ( )
Returns
The raw PETSc preconditioner context pointer.

This allows you to specify the PCShellSetApply() and PCShellSetSetUp() functions if you desire. Just don't do anything crazy like calling libMeshPCDestroy() on the pointer!

Definition at line 232 of file petsc_linear_solver.h.

References libMesh::PetscLinearSolver< T >::_pc, and libMesh::PetscLinearSolver< T >::init().

232 { this->init(); return _pc; }
PC _pc
Preconditioner context.
virtual void init(const char *name=nullptr) override
Initialize data structures if not done so already.

◆ 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::LinearSolver< T >::print_converged_reason ( ) const
virtualinherited

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

Reimplemented in libMesh::AztecLinearSolver< T >, and libMesh::LaspackLinearSolver< 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::PetscLinearSolver< T >::restrict_solve_to ( const std::vector< unsigned int > *const  dofs,
const SubsetSolveMode  subset_solve_mode = SUBSET_ZERO 
)
overridevirtual

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 from libMesh::LinearSolver< 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_petsc_solver_type()

template<typename T >
void libMesh::PetscLinearSolver< T >::set_petsc_solver_type ( )
private

Tells PETSC to use the user-specified solver stored in _solver_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::PetscLinearSolver< T >::solve ( SparseMatrix< T > &  matrix_in,
NumericVector< T > &  solution_in,
NumericVector< T > &  rhs_in,
const double  tol,
const unsigned int  m_its 
)
overridevirtual

Call the Petsc solver.

It calls the method below, using the same matrix for the system and preconditioner matrices.

Implements libMesh::LinearSolver< T >.

Definition at line 157 of file petsc_linear_solver.h.

162  {
163  return this->solve(matrix_in, matrix_in, solution_in, rhs_in, tol, m_its);
164  }
virtual 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) override
Call the Petsc solver.

◆ solve() [2/6]

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

This method allows you to call a linear solver while specifying the matrix to use as the (left) preconditioning matrix.

Note
The linear solver will not compute a preconditioner in this case, and will instead premultiply by the matrix you provide. In PETSc, this is accomplished by calling
PCSetType(_pc, PCMAT);
before invoking KSPSolve().
This functionality is not implemented in the LinearSolver class since there is not a built-in analog to this method for LASPACK. You could probably implement it by hand if you wanted.

Implements libMesh::LinearSolver< T >.

◆ solve() [3/6]

template<typename T >
virtual std::pair<unsigned int, Real> libMesh::PetscLinearSolver< 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>
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() [5/6]

template<typename T >
virtual std::pair<unsigned int, Real> libMesh::PetscLinearSolver< 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() [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().

◆ _ksp

template<typename T >
KSP libMesh::PetscLinearSolver< T >::_ksp
private

Krylov subspace context.

Definition at line 293 of file petsc_linear_solver.h.

Referenced by libMesh::PetscLinearSolver< T >::ksp().

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

◆ _pc

template<typename T >
PC libMesh::PetscLinearSolver< T >::_pc
private

Preconditioner context.

Definition at line 288 of file petsc_linear_solver.h.

Referenced by libMesh::PetscLinearSolver< T >::pc().

◆ _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.

◆ _restrict_solve_to_is

template<typename T >
IS libMesh::PetscLinearSolver< T >::_restrict_solve_to_is
private

PETSc index set containing the dofs on which to solve (nullptr means solve on all dofs).

Definition at line 299 of file petsc_linear_solver.h.

◆ _restrict_solve_to_is_complement

template<typename T >
IS libMesh::PetscLinearSolver< T >::_restrict_solve_to_is_complement
private

PETSc index set, complement to _restrict_solve_to_is.

This will be created on demand by the method _create_complement_is().

Definition at line 306 of file petsc_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().

◆ _subset_solve_mode

template<typename T >
SubsetSolveMode libMesh::PetscLinearSolver< T >::_subset_solve_mode
private

If restrict-solve-to-subset mode is active, this member decides what happens with the dofs outside the subset.

Definition at line 324 of file petsc_linear_solver.h.

◆ 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 file: