Go to the documentation of this file.
20 #ifndef LIBMESH_PETSC_LINEAR_SOLVER_H
21 #define LIBMESH_PETSC_LINEAR_SOLVER_H
23 #include "libmesh/libmesh_config.h"
25 #ifdef LIBMESH_HAVE_PETSC
27 #include "libmesh/petsc_macro.h"
28 #include "libmesh/petsc_solver_exception.h"
32 # define LIBMESH_SAW_I
36 # undef I // Avoid complex.h contamination
40 #include "libmesh/linear_solver.h"
54 #if PETSC_RELEASE_LESS_THAN(3,0,1)
71 #if LIBMESH_ENABLE_DEPRECATED
72 #if PETSC_RELEASE_LESS_THAN(3,0,1)
96 template <
typename T>
class PetscMatrix;
106 template <
typename T>
123 virtual void clear ()
override;
130 virtual void init (
const char *
name =
nullptr)
override;
136 const char *
name =
nullptr);
162 virtual std::pair<unsigned int, Real>
167 const unsigned int m_its)
override
169 return this->
solve(matrix_in, matrix_in, solution_in, rhs_in, tol, m_its);
177 virtual std::pair<unsigned int, Real>
182 const unsigned int m_its)
override;
200 virtual std::pair<unsigned int, Real>
206 const unsigned int m_its)
override;
211 virtual std::pair<unsigned int, Real>
216 const unsigned int m_its)
override;
223 virtual std::pair<unsigned int, Real>
229 const unsigned int m_its)
override;
335 template <
typename T>
344 template <
typename T>
351 int ierr = ISGetLocalSize(_restrict_solve_to_is, &s);
352 LIBMESH_CHKERR(
ierr);
359 template <
typename T>
362 #
if PETSC_VERSION_LESS_THAN(3,0,0)
370 #if PETSC_VERSION_LESS_THAN(3,0,0)
372 libmesh_not_implemented();
374 if (_restrict_solve_to_is_complement==
nullptr)
376 int ierr = ISComplement(_restrict_solve_to_is,
377 vec_in.first_local_index(),
378 vec_in.last_local_index(),
379 &_restrict_solve_to_is_complement);
380 LIBMESH_CHKERR(
ierr);
390 #endif // #ifdef LIBMESH_HAVE_PETSC
391 #endif // LIBMESH_PETSC_LINEAR_SOLVER_H
Generic shell matrix, i.e.
Manages consistently variables, degrees of freedom, and coefficient vectors.
PetscInt _restrict_solve_to_is_local_size() const
Real get_initial_residual()
static PetscErrorCode _petsc_shell_matrix_get_diagonal(Mat mat, Vec dest)
Internal function if shell matrix mode is used.
~PetscLinearSolver()
Destructor.
static PetscErrorCode _petsc_shell_matrix_mult_add(Mat mat, Vec arg, Vec add, Vec dest)
Internal function if shell matrix mode is used.
The libMesh namespace provides an interface to certain functionality in the library.
void get_residual_history(std::vector< double > &hist)
Fills the input vector with the sequence of residual norms from the latest iterative solve.
PetscErrorCode libmesh_petsc_preconditioner_setup(void *ctx)
This function is called by PETSc to initialize the preconditioner.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
KSP _ksp
Krylov subspace context.
IS _restrict_solve_to_is
PETSc index set containing the dofs on which to solve (nullptr means solve on all dofs).
static PetscErrorCode _petsc_shell_matrix_mult(Mat mat, Vec arg, Vec dest)
Internal function if shell matrix mode is used.
LinearConvergenceReason
Linear solver convergence flags (taken from the PETSc flags).
void set_petsc_solver_type()
Tells PETSC to use the user-specified solver stored in _solver_type.
virtual void clear() override
Release all memory and clear data structures.
PetscErrorCode __libmesh_petsc_preconditioner_apply(void *ctx, Vec x, Vec y)
This function is called by PETSc to actually apply the preconditioner.
This class provides an interface to PETSc iterative solvers that is compatible with the libMesh Linea...
PetscLinearSolver(const libMesh::Parallel::Communicator &comm_in)
Constructor.
SubsetSolveMode _subset_solve_mode
If restrict-solve-to-subset mode is active, this member decides what happens with the dofs outside th...
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.
PetscErrorCode libmesh_petsc_preconditioner_apply(void *ctx, Vec x, Vec y)
This function is called by PETSc to actually apply the preconditioner.
virtual void init(const char *name=nullptr) override
Initialize data structures if not done so already.
virtual LinearConvergenceReason get_converged_reason() const override
This class provides a nice interface to the PETSc C-based data structures for parallel,...
This base class can be inherited from to provide interfaces to linear solvers from different packages...
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,...
PC _pc
Preconditioner context.
PetscErrorCode __libmesh_petsc_preconditioner_setup(void *ctx)
This function is called by PETSc to initialize the preconditioner.
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,...
IS _restrict_solve_to_is_complement
PETSc index set, complement to _restrict_solve_to_is.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void init_names(const System &) override
Apply names to the system to be solved.
virtual std::pair< unsigned int, Real > adjoint_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.
std::string name(const ElemQuality q)
This function returns a string containing some name for q.