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.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 PetscErrorCode
ierr = PCApply(_pc, x_vec, y_vec);
59 libmesh_error_msg_if(!this->_matrix,
"ERROR: No matrix set for PetscPreconditioner, but init() called");
68 PetscErrorCode
ierr = PCCreate(this->comm().
get(), _pc.get());
71 auto pmatrix = cast_ptr<PetscMatrix<T> *>(this->_matrix);
72 _mat = pmatrix->mat();
75 PetscErrorCode
ierr = PCSetOperators(_pc, _mat, _mat);
85 set_petsc_preconditioner_type(this->_preconditioner_type, *_pc);
101 template <
typename T>
109 template <
typename T>
112 PetscErrorCode
ierr = 0;
115 Parallel::communicator comm;
116 PetscObjectGetComm((PetscObject)pc, & comm);
119 switch (preconditioner_type)
122 ierr = PCSetType (pc, const_cast<KSPType>(PCNONE));
123 CHKERRABORT(comm,
ierr);
127 ierr = PCSetType (pc, const_cast<KSPType>(PCCHOLESKY));
128 CHKERRABORT(comm,
ierr);
132 ierr = PCSetType (pc, const_cast<KSPType>(PCICC));
133 CHKERRABORT(comm,
ierr);
141 ierr = PCSetType (pc, const_cast<KSPType>(PCILU));
142 CHKERRABORT(comm,
ierr);
149 ierr = PCSetType (pc, const_cast<KSPType>(PCBJACOBI));
150 CHKERRABORT(comm,
ierr);
153 set_petsc_subpreconditioner_type(PCILU, pc);
163 ierr = PCSetType (pc, const_cast<KSPType>(PCLU));
164 CHKERRABORT(comm,
ierr);
171 ierr = PCSetType (pc, const_cast<KSPType>(PCBJACOBI));
172 CHKERRABORT(comm,
ierr);
175 set_petsc_subpreconditioner_type(PCLU, pc);
185 ierr = PCSetType (pc, const_cast<KSPType>(PCASM));
186 CHKERRABORT(comm,
ierr);
191 ierr = PCSetType (pc, const_cast<KSPType>(PCJACOBI));
192 CHKERRABORT(comm,
ierr);
196 ierr = PCSetType (pc, const_cast<KSPType>(PCBJACOBI));
197 CHKERRABORT(comm,
ierr);
201 ierr = PCSetType (pc, const_cast<KSPType>(PCSOR));
202 CHKERRABORT(comm,
ierr);
206 ierr = PCSetType (pc, const_cast<KSPType>(PCEISENSTAT));
207 CHKERRABORT(comm,
ierr);
211 ierr = PCSetType (pc, const_cast<KSPType>(PCHYPRE));
212 CHKERRABORT(comm,
ierr);
216 ierr = PCSetType (pc, const_cast<KSPType>(PCSVD));
217 CHKERRABORT(comm,
ierr);
221 ierr = PCSetType (pc, const_cast<KSPType>(PCMAT));
222 CHKERRABORT(comm,
ierr);
226 ierr = PCSetType (pc, const_cast<KSPType>(PCSHELL));
227 CHKERRABORT(comm,
ierr);
231 libMesh::err <<
"ERROR: Unsupported PETSC Preconditioner: " 232 << preconditioner_type << std::endl
233 <<
"Continuing with PETSC defaults" << std::endl;
238 #ifdef LIBMESH_HAVE_PETSC_HYPRE 241 ierr = PCHYPRESetType(pc,
"boomeramg");
242 CHKERRABORT(comm,
ierr);
247 ierr = PCSetFromOptions(pc);
248 CHKERRABORT(comm,
ierr);
252 template <
typename T>
256 PetscErrorCode
ierr = 0;
259 Parallel::communicator comm;
260 PetscObjectGetComm((PetscObject)pc, & comm);
271 CHKERRABORT(comm,
ierr);
284 ierr = PCBJacobiGetSubKSP(pc, &n_local, LIBMESH_PETSC_NULLPTR,
286 CHKERRABORT(comm,
ierr);
289 for (PetscInt i=0; i<n_local; ++i)
293 ierr = KSPGetPC(subksps[i], &subpc);
294 CHKERRABORT(comm,
ierr);
297 ierr = PCSetType(subpc, type);
298 CHKERRABORT(comm,
ierr);
311 #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...
static void set_petsc_subpreconditioner_type(const PCType type, PC &pc)
Some PETSc preconditioners (ILU, LU) don't work in parallel.
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.
DIE A HORRIBLE DEATH HERE typedef MPI_Comm communicator