18 #include "libmesh/libmesh_common.h" 20 #ifdef LIBMESH_HAVE_PETSC 23 #include "libmesh/petsc_preconditioner.h" 24 #include "libmesh/petsc_macro.h" 25 #include "libmesh/petsc_matrix_base.h" 26 #include "libmesh/petsc_vector.h" 27 #include "libmesh/libmesh_common.h" 28 #include "libmesh/enum_preconditioner_type.h" 46 Vec x_vec = x_pvec.
vec();
47 Vec y_vec = y_pvec.
vec();
49 LibmeshPetscCall(PCApply(_pc, x_vec, y_vec));
58 libmesh_error_msg_if(!this->_matrix,
"ERROR: No matrix set for PetscPreconditioner, but init() called");
67 LibmeshPetscCall(PCCreate(this->comm().
get(), _pc.get()));
69 auto pmatrix = cast_ptr<PetscMatrixBase<T> *>(this->_matrix);
70 _mat = pmatrix->mat();
73 LibmeshPetscCall(PCSetOperators(_pc, _mat, _mat));
82 set_petsc_preconditioner_type(this->_preconditioner_type, *_pc);
106 template <
typename T>
110 Parallel::communicator comm;
111 PetscErrorCode ierr = PetscObjectGetComm((PetscObject)pc, & comm);
112 if (ierr != LIBMESH_PETSC_SUCCESS)
113 libmesh_error_msg(
"Error retrieving communicator");
115 #define CasePCSetType(PreconditionerType, PCType) \ 116 case PreconditionerType: \ 117 LibmeshPetscCallA(comm, PCSetType (pc, const_cast<KSPType>(PCType))); \ 120 switch (preconditioner_type)
138 libMesh::err <<
"ERROR: Unsupported PETSC Preconditioner: " 140 <<
"Continuing with PETSC defaults" << std::endl;
145 #ifdef LIBMESH_HAVE_PETSC_HYPRE 147 LibmeshPetscCallA(comm, PCHYPRESetType(pc,
"boomeramg"));
151 LibmeshPetscCallA(comm, PCSetFromOptions(pc));
162 #endif // #ifdef LIBMESH_HAVE_PETSC
This class provides a nice interface to PETSc's Vec object.
This class provides an interface to the suite of preconditioners available from PETSc.
virtual void init() override
Initialize data structures if not done so already.
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.
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y) override
Computes the preconditioned vector y based on input vector x.
This class provides a uniform interface for preconditioners.
bool _is_initialized
Flag that tells if init() has been called.
PetscPreconditioner(const libMesh::Parallel::Communicator &comm_in)
Constructor.
virtual void clear() override
Release all memory and clear data structures.
static void set_petsc_preconditioner_type(const PreconditionerType &preconditioner_type, PC &pc)
Tells PETSc to use the user-specified preconditioner.
PreconditionerType
Defines an enum for preconditioner types.
std::string enum_to_string(const T e)