21 #include "libmesh/libmesh_logging.h" 22 #include "libmesh/linear_solver.h" 23 #include "libmesh/laspack_linear_solver.h" 24 #include "libmesh/eigen_sparse_linear_solver.h" 25 #include "libmesh/petsc_linear_solver.h" 26 #include "libmesh/trilinos_aztec_linear_solver.h" 27 #include "libmesh/preconditioner.h" 28 #include "libmesh/sparse_matrix.h" 29 #include "libmesh/enum_to_string.h" 30 #include "libmesh/solver_configuration.h" 31 #include "libmesh/enum_solver_package.h" 32 #include "libmesh/enum_preconditioner_type.h" 33 #include "libmesh/enum_solver_type.h" 49 _preconditioner (nullptr),
50 same_preconditioner (false),
51 _solver_configuration(nullptr)
58 std::unique_ptr<LinearSolver<T>>
66 switch (solver_package)
68 #ifdef LIBMESH_HAVE_LASPACK 70 return std::make_unique<LaspackLinearSolver<T>>(comm);
74 #ifdef LIBMESH_HAVE_PETSC 76 return std::make_unique<PetscLinearSolver<T>>(comm);
80 #ifdef LIBMESH_TRILINOS_HAVE_AZTECOO 82 return std::make_unique<AztecLinearSolver<T>>(comm);
86 #ifdef LIBMESH_HAVE_EIGEN 88 return std::make_unique<EigenSparseLinearSolver<T>>(comm);
92 libmesh_error_msg(
"ERROR: Unrecognized solver package: " << solver_package);
95 return std::unique_ptr<LinearSolver<T>>();
103 return _preconditioner->type();
105 return _preconditioner_type;
108 template <
typename T>
113 _preconditioner->set_type(pct);
115 _preconditioner_type = pct;
118 template <
typename T>
123 "Preconditioner must be attached before the solver is initialized!");
126 _preconditioner = preconditioner;
129 template <
typename T>
133 same_preconditioner = reuse_flag;
136 template <
typename T>
142 libmesh_not_implemented();
146 template <
typename T>
150 const std::optional<double> tol,
151 const std::optional<unsigned int> n_its)
154 LOG_SCOPE(
"adjoint_solve()",
"LinearSolver");
162 const std::pair<unsigned int, Real> totalrval = this->solve (mat, sol, rhs, tol, n_its);
171 template <
typename T>
178 template <
typename T>
181 _solver_configuration = &solver_configuration;
184 template <
typename T>
186 const std::optional<double> & setting,
187 const std::optional<double> default_value)
189 if (setting.has_value())
190 return setting.value();
191 else if (_solver_configuration)
193 if (
const auto it = this->_solver_configuration->real_valued_data.find(setting_name);
194 it != this->_solver_configuration->real_valued_data.end())
195 return double(it->second);
197 else if (default_value.has_value())
198 return default_value.value();
200 libmesh_error_msg(
"Iteration configuration parameter to the linear solver should either be supplied through input arguments or a SolverConfiguration object!");
205 template <
typename T>
207 const std::optional<int> & setting,
208 const std::optional<int> default_value)
210 if (setting.has_value())
211 return setting.value();
212 else if (_solver_configuration)
214 if (
const auto it = this->_solver_configuration->int_valued_data.find(setting_name);
215 it != this->_solver_configuration->int_valued_data.end())
218 else if (default_value.has_value())
219 return default_value.value();
221 libmesh_error_msg(
"Iteration configuration parameter to the linear solver should either be supplied through input arguments or a SolverConfiguration object!");
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.
This base class can be inherited from to provide interfaces to linear solvers from different packages...
This class provides a uniform interface for preconditioners.
void libmesh_ignore(const Args &...)
LinearSolver(const libMesh::Parallel::Communicator &comm_in)
Constructor.
bool _is_initialized
Flag that tells if init() has been called.
This class stores solver configuration data, e.g.
An object whose state is distributed along a set of processors.
PreconditionerType
Defines an enum for preconditioner types.
std::string enum_to_string(const T e)
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
virtual void get_transpose(SparseMatrix< T > &dest) const =0
Copies the transpose of the matrix into dest, which may be *this.
SolverPackage
Defines an enum for various linear solver packages.
SubsetSolveMode
defines an enum for the question what happens to the dofs outside the given subset when a system is s...