21#ifdef DEAL_II_WITH_PETSC
29# include <petscversion.h>
90 const Mat B = preconditioner;
92 ExcMessage(
"PETSc preconditioner should have an "
93 "associated matrix set to be used in solver."));
97# if DEAL_II_PETSC_VERSION_LT(3, 5, 0)
103 SAME_PRECONDITIONER);
105 ierr = KSPSetOperators(
solver_data->ksp, A, preconditioner);
122 PetscErrorCode ierr =
176 const PetscInt iteration,
177 const PetscReal residual_norm,
178 KSPConvergedReason *reason,
179 void * solver_control_x)
189 case ::SolverControl::iterate:
190 *reason = KSP_CONVERGED_ITERATING;
193 case ::SolverControl::success:
194 *reason =
static_cast<KSPConvergedReason
>(1);
197 case ::SolverControl::failure:
199 *reason = KSP_DIVERGED_ITS;
201 *reason = KSP_DIVERGED_DTOL;
269 PetscErrorCode ierr = KSPSetType(ksp, KSPRICHARDSON);
279 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
295 ierr = KSPSetTolerances(ksp,
299 this->solver_control.max_steps() + 1);
310 , additional_data(data)
317 PetscErrorCode ierr = KSPSetType(ksp, KSPCHEBYSHEV);
323 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
334 , additional_data(data)
341 PetscErrorCode ierr = KSPSetType(ksp, KSPCG);
347 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
358 , additional_data(data)
365 PetscErrorCode ierr = KSPSetType(ksp, KSPBICG);
371 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
379 const unsigned int restart_parameter,
380 const bool right_preconditioning)
381 : restart_parameter(restart_parameter)
382 , right_preconditioning(right_preconditioning)
398 PetscErrorCode ierr = KSPSetType(ksp, KSPGMRES);
422 ierr = PetscObjectQueryFunction(
reinterpret_cast<PetscObject
>(ksp),
423 "KSPGMRESSetRestart_C",
424 reinterpret_cast<void (**)()
>(&fun_ptr));
434 ierr = KSPSetPCSide(ksp, PC_RIGHT);
441 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
452 , additional_data(data)
459 PetscErrorCode ierr = KSPSetType(ksp, KSPBCGS);
465 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
476 , additional_data(data)
483 PetscErrorCode ierr = KSPSetType(ksp, KSPCGS);
489 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
500 , additional_data(data)
507 PetscErrorCode ierr = KSPSetType(ksp, KSPTFQMR);
513 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
524 , additional_data(data)
531 PetscErrorCode ierr = KSPSetType(ksp, KSPTCQMR);
537 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
548 , additional_data(data)
555 PetscErrorCode ierr = KSPSetType(ksp, KSPCR);
561 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
572 , additional_data(data)
579 PetscErrorCode ierr = KSPSetType(ksp, KSPLSQR);
585 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
596 , additional_data(data)
603 PetscErrorCode ierr = KSPSetType(ksp, KSPPREONLY);
619 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_FALSE);
651 PetscErrorCode ierr = KSPSetType(ksp, KSPPREONLY);
666 ierr = KSPSetInitialGuessNonzero(ksp, PETSC_FALSE);
675# ifdef DEAL_II_PETSC_WITH_MUMPS
686 PetscInt ival = 2, icntl = 7;
714# if DEAL_II_PETSC_VERSION_LT(3, 5, 0)
716 KSPSetOperators(
solver_data->ksp, A, A, DIFFERENT_NONZERO_PATTERN);
758# if DEAL_II_PETSC_VERSION_LT(3, 9, 0)
759 ierr = PCFactorSetMatSolverPackage(
solver_data->pc, MATSOLVERMUMPS);
761 ierr = PCFactorSetMatSolverType(
solver_data->pc, MATSOLVERMUMPS);
768# if DEAL_II_PETSC_VERSION_LT(3, 9, 0)
769 ierr = PCFactorSetUpMatSolverPackage(
solver_data->pc);
771 ierr = PCFactorSetUpMatSolverType(
solver_data->pc);
786 ierr = MatMumpsSetIcntl(F, icntl, ival);
806 PetscErrorCode ierr = KSPSolve(
solver_data->ksp, b, x);
824 ierr = KSPGetIterationNumber(
solver_data->ksp, &its);
826 ierr = KSPGetResidualNorm(
solver_data->ksp, &rnorm);
834 "Your PETSc installation does not include a copy of "
835 "the MUMPS package necessary for this solver. You will need to configure "
836 "PETSc so that it includes MUMPS, recompile it, and then re-configure "
837 "and recompile deal.II as well."));
848 const PetscInt iteration,
849 const PetscReal residual_norm,
850 KSPConvergedReason *reason,
851 void * solver_control_x)
861 case ::SolverControl::iterate:
862 *reason = KSP_CONVERGED_ITERATING;
865 case ::SolverControl::success:
866 *reason =
static_cast<KSPConvergedReason
>(1);
869 case ::SolverControl::failure:
871 *reason = KSP_DIVERGED_ITS;
873 *reason = KSP_DIVERGED_DTOL;
const PC & get_pc() const
virtual void set_solver_type(KSP &ksp) const =0
SolverControl & control() const
SolverControl & solver_control
void initialize(const PreconditionBase &preconditioner)
static PetscErrorCode convergence_test(KSP ksp, const PetscInt iteration, const PetscReal residual_norm, KSPConvergedReason *reason, void *solver_control)
const MPI_Comm mpi_communicator
void set_prefix(const std::string &prefix)
void solve(const MatrixBase &A, VectorBase &x, const VectorBase &b, const PreconditionBase &preconditioner)
std::unique_ptr< SolverData > solver_data
SolverBase(SolverControl &cn, const MPI_Comm &mpi_communicator)
SolverBiCG(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
virtual void set_solver_type(KSP &ksp) const override
SolverBicgstab(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
virtual void set_solver_type(KSP &ksp) const override
SolverCGS(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
virtual void set_solver_type(KSP &ksp) const override
SolverCG(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
virtual void set_solver_type(KSP &ksp) const override
virtual void set_solver_type(KSP &ksp) const override
SolverCR(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
virtual void set_solver_type(KSP &ksp) const override
SolverChebychev(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
const AdditionalData additional_data
SolverGMRES(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
virtual void set_solver_type(KSP &ksp) const override
virtual void set_solver_type(KSP &ksp) const override
SolverLSQR(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
SolverPreOnly(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
virtual void set_solver_type(KSP &ksp) const override
SolverRichardson(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
virtual void set_solver_type(KSP &ksp) const override
const AdditionalData additional_data
virtual void set_solver_type(KSP &ksp) const override
SolverTCQMR(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
SolverTFQMR(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
virtual void set_solver_type(KSP &ksp) const override
void solve(const MatrixBase &A, VectorBase &x, const VectorBase &b)
virtual void set_solver_type(KSP &ksp) const override
const AdditionalData additional_data
void set_symmetric_mode(const bool flag)
static PetscErrorCode convergence_test(KSP ksp, const PetscInt iteration, const PetscReal residual_norm, KSPConvergedReason *reason, void *solver_control)
SparseDirectMUMPS(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
std::unique_ptr< SolverDataMUMPS > solver_data
unsigned int last_step() const
double last_value() const
virtual State check(const unsigned int step, const double check_value)
unsigned int max_steps() const
@ success
Stop iteration, goal reached.
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
PetscErrorCode destroy_krylov_solver(KSP &krylov_solver)
AdditionalData(const unsigned int restart_parameter=30, const bool right_preconditioning=false)
bool right_preconditioning
unsigned int restart_parameter
AdditionalData(const double omega=1)