Go to the documentation of this file.
20 #ifndef LIBMESH_LINEAR_SOLVER_H
21 #define LIBMESH_LINEAR_SOLVER_H
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/enum_subset_solve_mode.h"
26 #include "libmesh/reference_counted_object.h"
27 #include "libmesh/libmesh.h"
28 #include "libmesh/parallel_object.h"
30 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
39 #include "libmesh/enum_solver_package.h"
40 #include "libmesh/enum_preconditioner_type.h"
41 #include "libmesh/enum_solver_type.h"
42 #include "libmesh/enum_convergence_flags.h"
54 template <
typename T>
class SparseMatrix;
55 template <
typename T>
class NumericVector;
56 template <
typename T>
class ShellMatrix;
57 template <
typename T>
class Preconditioner;
59 class SolverConfiguration;
77 LinearSolver (
const libMesh::Parallel::Communicator & comm_in);
88 static std::unique_ptr<LinearSolver<T>>
build(
const libMesh::Parallel::Communicator & comm_in,
106 virtual void init (
const char *
name =
nullptr) = 0;
177 const unsigned int) = 0;
202 const unsigned int) = 0;
226 const unsigned int) = 0;
239 const unsigned int) = 0;
312 template <
typename T>
319 template <
typename T>
323 return same_preconditioner;
326 template <
typename T>
328 std::pair<unsigned int, Real>
334 const unsigned int n_iter)
337 return this->solve(mat, *pc_mat, sol, rhs, tol, n_iter);
339 return this->solve(mat, sol, rhs, tol, n_iter);
343 template <
typename T>
345 std::pair<unsigned int, Real>
351 const unsigned int n_iter)
354 return this->solve(mat, *pc_mat, sol, rhs, tol, n_iter);
356 return this->solve(mat, sol, rhs, tol, n_iter);
362 #endif // LIBMESH_LINEAR_SOLVER_H
virtual void reuse_preconditioner(bool)
Set the same_preconditioner flag, which indicates if we reuse the same preconditioner for subsequent ...
Generic shell matrix, i.e.
Manages consistently variables, degrees of freedom, and coefficient vectors.
SolverPackage
Defines an enum for various linear solver packages.
virtual LinearConvergenceReason get_converged_reason() const =0
void set_solver_configuration(SolverConfiguration &solver_configuration)
Set the solver configuration object.
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,...
LinearSolver(const libMesh::Parallel::Communicator &comm_in)
Constructor.
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...
This class implements reference counting.
The libMesh namespace provides an interface to certain functionality in the library.
SolverType _solver_type
Enum stating which type of iterative solver to use.
SolverPackage default_solver_package()
virtual void init_names(const System &)
Apply names to the system to be solved.
virtual void init(const char *name=nullptr)=0
Initialize data structures if not done so already.
PreconditionerType _preconditioner_type
Enum stating with type of preconditioner to use.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
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.
LinearConvergenceReason
Linear solver convergence flags (taken from the PETSc flags).
void set_solver_type(const SolverType st)
Sets the type of solver to use.
virtual void clear()
Release all memory and clear data structures.
Preconditioner< T > * _preconditioner
Holds the Preconditioner object to be used for the linear solves.
This class provides a uniform interface for preconditioners.
virtual ~LinearSolver()
Destructor.
SolverType solver_type() const
PreconditionerType
Defines an enum for preconditioner types.
virtual void print_converged_reason() const
Prints a useful message about why the latest linear solve con(di)verged.
bool _is_initialized
Flag indicating if the data structures have been initialized.
virtual std::pair< unsigned int, Real > adjoint_solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)
Function to solve the adjoint system.
bool same_preconditioner
Boolean flag to indicate whether we want to use an identical preconditioner to the previous solve.
bool get_same_preconditioner()
This base class can be inherited from to provide interfaces to linear solvers from different packages...
SolverConfiguration * _solver_configuration
Optionally store a SolverOptions object that can be used to set parameters like solver type,...
void set_preconditioner_type(const PreconditionerType pct)
Sets the type of preconditioner to use.
This class stores solver configuration data, e.g.
PreconditionerType preconditioner_type() const
SolverType
Defines an enum for iterative solver types.
An object whose state is distributed along a set of processors.
void ErrorVector unsigned int
void attach_preconditioner(Preconditioner< T > *preconditioner)
Attaches a Preconditioner object to be used.
std::string name(const ElemQuality q)
This function returns a string containing some name for q.