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" 40 template <
typename T>
class SparseMatrix;
41 template <
typename T>
class NumericVector;
42 template <
typename T>
class ShellMatrix;
43 template <
typename T>
class Preconditioner;
45 class SolverConfiguration;
59 class LinearSolver :
public ReferenceCountedObject<LinearSolver<T>>,
96 virtual void init (
const char *
name =
nullptr) = 0;
166 const std::optional<double> tol = std::nullopt,
167 const std::optional<unsigned int> m_its = std::nullopt) = 0;
179 const std::optional<double> tol = std::nullopt,
180 const std::optional<unsigned int> m_its = std::nullopt);
191 const std::optional<double> tol = std::nullopt,
192 const std::optional<unsigned int> m_its = std::nullopt) = 0;
204 const std::optional<double> tol = std::nullopt,
205 const std::optional<unsigned int> m_its = std::nullopt);
215 const std::optional<double> tol = std::nullopt,
216 const std::optional<unsigned int> m_its = std::nullopt) = 0;
228 const std::optional<double> tol = std::nullopt,
229 const std::optional<unsigned int> m_its = std::nullopt) = 0;
240 const std::optional<double> tol = std::nullopt,
241 const std::optional<unsigned int> m_its = std::nullopt);
300 const std::optional<double> & setting,
301 const std::optional<double> default_value = std::nullopt);
308 const std::optional<int> & setting,
309 const std::optional<int> default_value = std::nullopt);
316 template <
typename T>
323 template <
typename T>
327 return same_preconditioner;
330 template <
typename T>
332 std::pair<unsigned int, Real>
337 const std::optional<double> tol,
338 const std::optional<unsigned int> n_iter)
341 return this->solve(mat, *pc_mat, sol, rhs, tol, n_iter);
343 return this->solve(mat, sol, rhs, tol, n_iter);
347 template <
typename T>
349 std::pair<unsigned int, Real>
354 const std::optional<double> tol,
355 const std::optional<unsigned int> n_iter)
358 return this->solve(mat, *pc_mat, sol, rhs, tol, n_iter);
360 return this->solve(mat, sol, rhs, tol, n_iter);
367 #endif // LIBMESH_LINEAR_SOLVER_H std::string name(const ElemQuality q)
This function returns a string containing some name for q.
virtual void clear()
Release all memory and clear data structures.
SolverType _solver_type
Enum stating which type of iterative solver to use.
virtual ~LinearSolver()
Destructor.
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.
Preconditioner< T > * _preconditioner
Holds the Preconditioner object to be used for the linear solves.
virtual void print_converged_reason() const
Prints a useful message about why the latest linear solve con(di)verged.
LinearConvergenceReason
Linear solver convergence flags (taken from the PETSc flags).
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
The libMesh namespace provides an interface to certain functionality in the library.
SolverPackage default_solver_package()
double get_real_solver_setting(const std::string &setting_name, const std::optional< double > &setting, const std::optional< double > default_value=std::nullopt)
Get solver settings based on optional parameters and the solver configuration object.
This class provides a uniform interface for preconditioners.
LinearSolver(const libMesh::Parallel::Communicator &comm_in)
Constructor.
virtual void init(const char *name=nullptr)=0
Initialize data structures if not done so already.
Manages consistently variables, degrees of freedom, and coefficient vectors.
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.
void set_solver_type(const SolverType st)
Sets the type of solver to use.
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const std::optional< double > tol=std::nullopt, const std::optional< unsigned int > m_its=std::nullopt)=0
This function calls the solver _solver_type preconditioned with the _preconditioner_type precondition...
void attach_preconditioner(Preconditioner< T > *preconditioner)
Attaches a Preconditioner object to be used.
void set_solver_configuration(SolverConfiguration &solver_configuration)
Set the solver configuration object.
PreconditionerType
Defines an enum for preconditioner types.
PreconditionerType preconditioner_type() const
SolverType
Defines an enum for iterative solver types.
virtual LinearConvergenceReason get_converged_reason() const =0
int get_int_solver_setting(const std::string &setting_name, const std::optional< int > &setting, const std::optional< int > default_value=std::nullopt)
Get solver settings based on optional parameters and the solver configuration object.
virtual void reuse_preconditioner(bool)
Set the same_preconditioner flag, which indicates if we reuse the same preconditioner for subsequent ...
PreconditionerType _preconditioner_type
Enum stating with type of preconditioner to use.
bool same_preconditioner
Boolean flag to indicate whether we want to use an identical preconditioner to the previous solve...
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...
SolverPackage
Defines an enum for various linear solver packages.
Generic shell matrix, i.e.
virtual std::pair< unsigned int, Real > adjoint_solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const std::optional< double > tol=std::nullopt, const std::optional< unsigned int > m_its=std::nullopt)
Function to solve the adjoint system.
SubsetSolveMode
defines an enum for the question what happens to the dofs outside the given subset when a system is s...
void ErrorVector unsigned int
SolverType solver_type() const
virtual void init_names(const System &)
Apply names to the system to be solved.
bool _is_initialized
Flag indicating if the data structures have been initialized.
bool get_same_preconditioner()