16 #include <deal.II/lac/petsc_precondition.h> 18 #ifdef DEAL_II_WITH_PETSC 20 # include <deal.II/base/utilities.h> 21 # include <deal.II/lac/exceptions.h> 22 # include <deal.II/lac/petsc_compatibility.h> 23 # include <deal.II/lac/petsc_matrix_base.h> 24 # include <deal.II/lac/petsc_vector_base.h> 25 # include <deal.II/lac/petsc_solver.h> 26 # include <petscconf.h> 29 DEAL_II_NAMESPACE_OPEN
35 pc(nullptr), matrix(nullptr)
55 PetscErrorCode ierr = PCDestroy(&
pc);
68 const PetscErrorCode ierr = PCApply(
pc, src, dst);
84 PetscErrorCode ierr = PetscObjectGetComm(reinterpret_cast<PetscObject>(
matrix),
88 ierr = PCCreate(comm, &
pc);
91 #if DEAL_II_PETSC_VERSION_LT(3, 5, 0) 107 PreconditionerBase::operator Mat ()
const 119 PetscErrorCode ierr = PCCreate(comm, &
pc);
138 PetscErrorCode ierr = PCSetType (
pc, const_cast<char *>(PCJACOBI));
141 ierr = PCSetFromOptions (
pc);
151 matrix =
static_cast<Mat
>(matrix_);
157 PetscErrorCode ierr = PCSetUp (
pc);
168 PetscErrorCode ierr = PCCreate(comm, &
pc);
186 PetscErrorCode ierr = PCSetType (
pc, const_cast<char *>(PCBJACOBI));
189 ierr = PCSetFromOptions (
pc);
200 matrix =
static_cast<Mat
>(matrix_);
206 PetscErrorCode ierr = PCSetUp (
pc);
234 matrix =
static_cast<Mat
>(matrix_);
239 PetscErrorCode ierr = PCSetType (
pc, const_cast<char *>(PCSOR));
246 ierr = PCSetFromOptions (
pc);
277 matrix =
static_cast<Mat
>(matrix_);
282 PetscErrorCode ierr = PCSetType (
pc, const_cast<char *>(PCSOR));
290 ierr = PCSORSetSymmetric (
pc, SOR_SYMMETRIC_SWEEP);
293 ierr = PCSetFromOptions (
pc);
324 matrix =
static_cast<Mat
>(matrix_);
329 PetscErrorCode ierr = PCSetType (
pc, const_cast<char *>(PCEISENSTAT));
336 ierr = PCSetFromOptions (
pc);
368 matrix =
static_cast<Mat
>(matrix_);
373 PetscErrorCode ierr = PCSetType (
pc, const_cast<char *>(PCICC));
380 ierr = PCSetFromOptions (
pc);
411 matrix =
static_cast<Mat
>(matrix_);
416 PetscErrorCode ierr = PCSetType (
pc, const_cast<char *>(PCILU));
423 ierr = PCSetFromOptions (
pc);
435 const double strong_threshold,
436 const double max_row_sum,
437 const unsigned int aggressive_coarsening_num_levels,
438 const bool output_details
441 symmetric_operator(symmetric_operator),
442 strong_threshold(strong_threshold),
443 max_row_sum(max_row_sum),
444 aggressive_coarsening_num_levels(aggressive_coarsening_num_levels),
445 output_details(output_details)
455 PetscErrorCode ierr = PCCreate(comm, &
pc);
458 #ifdef DEAL_II_PETSC_WITH_HYPRE 460 #else // DEAL_II_PETSC_WITH_HYPRE 463 ExcMessage (
"Your PETSc installation does not include a copy of " 464 "the hypre package necessary for this preconditioner."));
478 #ifdef DEAL_II_PETSC_WITH_HYPRE 479 PetscErrorCode ierr = PCSetType (
pc, const_cast<char *>(PCHYPRE));
482 ierr = PCHYPRESetType(
pc,
"boomeramg");
493 std::stringstream ssStream;
503 set_option_value(
"-pc_hypre_boomeramg_relax_type_up",
"symmetric-SOR/Jacobi");
504 set_option_value(
"-pc_hypre_boomeramg_relax_type_down",
"symmetric-SOR/Jacobi");
505 set_option_value(
"-pc_hypre_boomeramg_relax_type_coarse",
"Gaussian-elimination");
511 set_option_value(
"-pc_hypre_boomeramg_relax_type_coarse",
"Gaussian-elimination");
514 ierr = PCSetFromOptions (
pc);
518 ExcMessage (
"Your PETSc installation does not include a copy of " 519 "the hypre package necessary for this preconditioner."));
527 #ifdef DEAL_II_PETSC_WITH_HYPRE 530 matrix =
static_cast<Mat
>(matrix_);
536 PetscErrorCode ierr = PCSetUp (
pc);
539 #else // DEAL_II_PETSC_WITH_HYPRE 541 (void)additional_data_;
543 ExcMessage (
"Your PETSc installation does not include a copy of " 544 "the hypre package necessary for this preconditioner."));
553 const unsigned int n_levels,
554 const double threshold,
556 const bool output_details)
558 symmetric(symmetric),
560 threshold(threshold),
562 output_details(output_details)
580 matrix =
static_cast<Mat
>(matrix_);
583 #ifdef DEAL_II_PETSC_WITH_HYPRE 586 PetscErrorCode ierr = PCSetType (
pc, const_cast<char *>(PCHYPRE));
589 ierr = PCHYPRESetType(
pc,
"parasails");
600 ExcMessage(
"ParaSails parameter symmetric can only be equal to 0, 1, 2!"));
602 std::stringstream ssStream;
608 ssStream <<
"nonsymmetric";
620 ssStream <<
"nonsymmetric,SPD";
626 ExcMessage(
"ParaSails parameter symmetric can only be equal to 0, 1, 2!"));
642 ierr = PCSetFromOptions (
pc);
648 #else // DEAL_II_PETSC_WITH_HYPRE 651 ExcMessage (
"Your PETSc installation does not include a copy of " 652 "the hypre package necessary for this preconditioner."));
672 matrix =
static_cast<Mat
>(matrix_);
677 PetscErrorCode ierr = PCSetType (
pc, const_cast<char *>(PCNONE));
680 ierr = PCSetFromOptions (
pc);
692 const double zero_pivot,
693 const double damping)
696 zero_pivot (zero_pivot),
715 matrix =
static_cast<Mat
>(matrix_);
720 PetscErrorCode ierr = PCSetType (
pc, const_cast<char *>(PCLU));
733 ierr = PCSetFromOptions (
pc);
742 DEAL_II_NAMESPACE_CLOSE
744 #endif // DEAL_II_WITH_PETSC PreconditionILU()=default
void vmult(VectorBase &dst, const VectorBase &src) const
AdditionalData(const double pivoting=1.e-6, const double zero_pivot=1.e-12, const double damping=0.0)
AdditionalData additional_data
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
AdditionalData(const double omega=1)
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
PreconditionSOR()=default
AdditionalData(const unsigned int levels=0)
PreconditionICC()=default
PreconditionParaSails()=default
#define AssertThrow(cond, exc)
std::string to_string(const number value, const unsigned int digits=numbers::invalid_unsigned_int)
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
void set_option_value(const std::string &name, const std::string &value)
AdditionalData additional_data
PreconditionEisenstat()=default
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
PreconditionSSOR()=default
AdditionalData additional_data
AdditionalData additional_data
PreconditionJacobi()=default
static ::ExceptionBase & ExcInvalidState()
static ::ExceptionBase & ExcMessage(std::string arg1)
AdditionalData(const unsigned int levels=0)
AdditionalData additional_data
#define Assert(cond, exc)
AdditionalData additional_data
PreconditionNone()=default
PreconditionBlockJacobi()=default
AdditionalData additional_data
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
AdditionalData additional_data
unsigned int aggressive_coarsening_num_levels
AdditionalData(const double omega=1)
AdditionalData additional_data
AdditionalData(const unsigned int symmetric=1, const unsigned int n_levels=1, const double threshold=0.1, const double filter=0.05, const bool output_details=false)
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
const PC & get_pc() const
AdditionalData(const double omega=1)
virtual ~PreconditionerBase()
AdditionalData(const bool symmetric_operator=false, const double strong_threshold=0.25, const double max_row_sum=0.9, const unsigned int aggressive_coarsening_num_levels=0, const bool output_details=false)
AdditionalData additional_data
PreconditionBoomerAMG()=default