20 #ifdef LIBMESH_HAVE_PETSC 33 #if PETSC_VERSION_LESS_THAN(3,1,0) 34 # include "petscksp.h" 46 Vec x_vec = x_pvec.
vec();
47 Vec y_vec = y_pvec.
vec();
49 int ierr = PCApply(_pc,x_vec,y_vec);
60 libmesh_error_msg(
"ERROR: No matrix set for PetscPreconditioner, but init() called");
68 int ierr = LibMeshPCDestroy(&_pc);
72 int ierr = PCCreate(this->comm().
get(),&_pc);
77 _mat = pmatrix->
mat();
80 #if PETSC_RELEASE_LESS_THAN(3,5,0) 81 int ierr = PCSetOperators(_pc,_mat,_mat,SAME_NONZERO_PATTERN);
83 int ierr = PCSetOperators(_pc,_mat,_mat);
94 set_petsc_preconditioner_type(this->_preconditioner_type, _pc);
101 template <
typename T>
106 int ierr = LibMeshPCDestroy(&_pc);
107 LIBMESH_CHKERR(
ierr);
114 template <
typename T>
121 PetscObjectGetComm((PetscObject)pc, & comm);
124 switch (preconditioner_type)
127 ierr = PCSetType (pc, const_cast<KSPType>(PCNONE));
128 CHKERRABORT(comm,
ierr);
132 ierr = PCSetType (pc, const_cast<KSPType>(PCCHOLESKY));
133 CHKERRABORT(comm,
ierr);
137 ierr = PCSetType (pc, const_cast<KSPType>(PCICC));
138 CHKERRABORT(comm,
ierr);
146 ierr = PCSetType (pc, const_cast<KSPType>(PCILU));
147 CHKERRABORT(comm,
ierr);
154 ierr = PCSetType (pc, const_cast<KSPType>(PCBJACOBI));
155 CHKERRABORT(comm,
ierr);
158 set_petsc_subpreconditioner_type(PCILU, pc);
168 ierr = PCSetType (pc, const_cast<KSPType>(PCLU));
169 CHKERRABORT(comm,
ierr);
176 ierr = PCSetType (pc, const_cast<KSPType>(PCBJACOBI));
177 CHKERRABORT(comm,
ierr);
180 set_petsc_subpreconditioner_type(PCLU, pc);
190 ierr = PCSetType (pc, const_cast<KSPType>(PCASM));
191 CHKERRABORT(comm,
ierr);
196 ierr = PCSetType (pc, const_cast<KSPType>(PCJACOBI));
197 CHKERRABORT(comm,
ierr);
201 ierr = PCSetType (pc, const_cast<KSPType>(PCBJACOBI));
202 CHKERRABORT(comm,
ierr);
206 ierr = PCSetType (pc, const_cast<KSPType>(PCSOR));
207 CHKERRABORT(comm,
ierr);
211 ierr = PCSetType (pc, const_cast<KSPType>(PCEISENSTAT));
212 CHKERRABORT(comm,
ierr);
216 ierr = PCSetType (pc, const_cast<KSPType>(PCHYPRE));
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 #if PETSC_VERSION_LESS_THAN(3,0,0) 253 #define PCTYPE_CV_QUALIFIER 255 #define PCTYPE_CV_QUALIFIER const 258 template <
typename T>
266 PetscObjectGetComm((PetscObject)pc, & comm);
277 CHKERRABORT(comm,
ierr);
290 ierr = PCBJacobiGetSubKSP(pc, &n_local, PETSC_NULL, &subksps);
291 CHKERRABORT(comm,
ierr);
294 for (PetscInt i=0; i<n_local; ++i)
298 ierr = KSPGetPC(subksps[i], &subpc);
299 CHKERRABORT(comm,
ierr);
302 ierr = PCSetType(subpc, type);
303 CHKERRABORT(comm,
ierr);
313 template class PetscPreconditioner<Number>;
317 #endif // #ifdef LIBMESH_HAVE_PETSC
NumericVector interface to PETSc Vec.
virtual void init() override
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y) override
static void set_petsc_subpreconditioner_type(PCType type, PC &pc)
OStreamProxy err(std::cerr)
virtual void clear() override
static void set_petsc_preconditioner_type(const PreconditionerType &preconditioner_type, PC &pc)
SparseMatrix interface to PETSc Mat.