17#ifdef DEAL_II_WITH_PETSC
27# include <petscconf.h>
60 PetscErrorCode ierr = PCDestroy(&
pc);
70 PetscErrorCode ierr = PCApply(
pc, src, dst);
79 PetscErrorCode ierr = PCApplyTranspose(
pc, src, dst);
88 PetscErrorCode ierr = PCSetUp(
pc);
95 return PetscObjectComm(
reinterpret_cast<PetscObject
>(
pc));
106 PetscErrorCode ierr = PetscObjectGetComm(
107 reinterpret_cast<PetscObject
>(
static_cast<const Mat &
>(matrix)), &
comm);
112 ierr = PCSetOperators(
pc, matrix, matrix);
120 PetscErrorCode ierr = PCCreate(
comm, &
pc);
145 PetscErrorCode ierr = PCCreate(
comm, &
pc);
167 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCJACOBI));
170 ierr = PCSetFromOptions(
pc);
202 PetscErrorCode ierr = PCCreate(
comm, &
pc);
223 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCBJACOBI));
226 ierr = PCSetFromOptions(
pc);
277 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCSOR));
284 ierr = PCSetFromOptions(
pc);
321 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCSOR));
329 ierr = PCSORSetSymmetric(
pc, SOR_SYMMETRIC_SWEEP);
332 ierr = PCSetFromOptions(
pc);
369 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCICC));
376 ierr = PCSetFromOptions(
pc);
413 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCILU));
420 ierr = PCSetFromOptions(
pc);
428 const bool symmetric_operator,
429 const double strong_threshold,
430 const double max_row_sum,
431 const unsigned int aggressive_coarsening_num_levels,
432 const bool output_details,
436 const unsigned int n_sweeps_coarse,
438 const unsigned int max_iter,
440 : symmetric_operator(symmetric_operator)
441 , strong_threshold(strong_threshold)
442 , max_row_sum(max_row_sum)
443 , aggressive_coarsening_num_levels(aggressive_coarsening_num_levels)
444 , output_details(output_details)
445 , relaxation_type_up(relaxation_type_up)
446 , relaxation_type_down(relaxation_type_down)
447 , relaxation_type_coarse(relaxation_type_coarse)
448 , n_sweeps_coarse(n_sweeps_coarse)
456# ifdef DEAL_II_PETSC_WITH_HYPRE
467 std::string string_type;
469 switch (relaxation_type)
472 string_type =
"Jacobi";
476 string_type =
"sequential-Gauss-Seidel";
480 string_type =
"seqboundary-Gauss-Seidel";
483 string_type =
"SOR/Jacobi";
487 string_type =
"backward-SOR/Jacobi";
491 string_type =
"symmetric-SOR/Jacobi";
495 string_type =
" l1scaled-SOR/Jacobi";
499 string_type =
"Gaussian-elimination";
503 string_type =
"l1-Gauss-Seidel";
507 string_type =
"backward-l1-Gauss-Seidel";
513 string_type =
"Chebyshev";
516 string_type =
"FCF-Jacobi";
520 string_type =
"l1scaled-Jacobi";
523 string_type =
"None";
548 PetscErrorCode ierr = PCCreate(
comm, &
pc);
551# ifdef DEAL_II_PETSC_WITH_HYPRE
556 ExcMessage(
"Your PETSc installation does not include a copy of "
557 "the hypre package necessary for this preconditioner."));
576# ifdef DEAL_II_PETSC_WITH_HYPRE
577 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCHYPRE));
580 ierr = PCHYPRESetType(
pc,
"boomeramg");
624 auto relaxation_type_is_symmetric =
641 ExcMessage(
"Use a symmetric smoother for relaxation_type_up"));
646 ExcMessage(
"Use a symmetric smoother for relaxation_type_down"));
651 ExcMessage(
"Use a symmetric smoother for relaxation_type_coarse"));
672 ierr = PCSetFromOptions(
pc);
676 ExcMessage(
"Your PETSc installation does not include a copy of "
677 "the hypre package necessary for this preconditioner."));
687# ifdef DEAL_II_PETSC_WITH_HYPRE
697 (void)additional_data_;
699 ExcMessage(
"Your PETSc installation does not include a copy of "
700 "the hypre package necessary for this preconditioner."));
708 const unsigned int symmetric,
709 const unsigned int n_levels,
710 const double threshold,
712 const bool output_details)
713 : symmetric(symmetric)
715 , threshold(threshold)
717 , output_details(output_details)
745# ifdef DEAL_II_PETSC_WITH_HYPRE
748 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCHYPRE));
751 ierr = PCHYPRESetType(
pc,
"parasails");
762 "ParaSails parameter symmetric can only be equal to 0, 1, 2!"));
764 std::stringstream ssStream;
770 ssStream <<
"nonsymmetric";
782 ssStream <<
"nonsymmetric,SPD";
790 "ParaSails parameter symmetric can only be equal to 0, 1, 2!"));
806 ierr = PCSetFromOptions(
pc);
812 ExcMessage(
"Your PETSc installation does not include a copy of "
813 "the hypre package necessary for this preconditioner."));
844 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCNONE));
847 ierr = PCSetFromOptions(
pc);
855 const double zero_pivot,
856 const double damping)
858 , zero_pivot(zero_pivot)
888 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCLU));
901 ierr = PCSetFromOptions(
pc);
909 const bool use_vertices,
910 const bool use_edges,
911 const bool use_faces,
912 const bool symmetric,
914 : use_vertices(use_vertices)
915 , use_edges(use_edges)
916 , use_faces(use_faces)
917 , symmetric(symmetric)
938 PetscErrorCode ierr = PCCreate(
comm, &
pc);
960# if DEAL_II_PETSC_VERSION_GTE(3, 10, 0)
961 PetscErrorCode ierr = PCSetType(pc,
const_cast<char *
>(PCBDDC));
967 MatType current_type;
971 ierr = PCGetOperators(pc, &A, &P);
973 ierr = PCGetUseAmat(pc, &flg);
976 ierr = MatGetType(flg ? A : P, ¤t_type);
979 strcmp(current_type, MATIS) == 0,
981 "Matrix must be of IS type. For this, the variant of reinit that includes the active dofs must be used."));
985 std::stringstream ssStream;
987 if (additional_data.use_vertices)
991 if (additional_data.use_edges)
995 if (additional_data.use_faces)
999 if (additional_data.symmetric)
1003 if (additional_data.coords.size() > 0)
1007 std::vector<PetscReal> coords_petsc(additional_data.coords.size() *
1009 for (
unsigned int i = 0, j = 0; i < additional_data.coords.size(); ++i)
1011 for (j = 0; j < dim; ++j)
1012 coords_petsc[dim * i + j] = additional_data.coords[i][j];
1015 ierr = PCSetCoordinates(pc,
1017 additional_data.coords.size(),
1018 coords_petsc.data());
1024 ierr = PCSetCoordinates(pc, 0, 0,
nullptr);
1029 ierr = PCSetFromOptions(pc);
1033 false,
ExcMessage(
"BDDC preconditioner requires PETSc 3.10.0 or newer"));
1046 additional_data = additional_data_;
1048 create_pc_with_mat(matrix_);
1067 PetscErrorCode ierr;
1070 ierr = PCDestroy(&
pc);
1075 ierr = PCSetType(
pc, PCSHELL);
1077 ierr = PCShellSetContext(
pc,
static_cast<void *
>(
this));
1085 ierr = PCShellSetName(
pc,
"deal.II user solve");
1093 PetscErrorCode ierr;
1094 ierr = PCSetOperators(
pc, matrix, matrix);
1099# define PetscCall(code) \
1102 PetscErrorCode ierr = (code); \
1111 PetscFunctionBeginUser;
1116 PetscFunctionReturn(PETSC_SUCCESS);
1124 PetscFunctionBeginUser;
1125 PetscCall(PCShellGetContext(ppc, &ctx));
1130 PetscObjectComm((PetscObject)ppc),
1132 "Failure in ::PETScWrappers::PreconditionShell::pcapply. Missing std::function vmult");
1136 const int lineno = __LINE__;
1139 user->vmult(dst, src);
1148 PetscObjectComm((PetscObject)ppc),
1153 PETSC_ERROR_INITIAL,
1154 "Failure in pcapply from ::PETScWrappers::NonlinearSolver");
1157 PetscFunctionReturn(PETSC_SUCCESS);
1165 PetscFunctionBeginUser;
1166 PetscCall(PCShellGetContext(ppc, &ctx));
1171 PetscObjectComm((PetscObject)ppc),
1173 "Failure in ::PETScWrappers::PreconditionShell::pcapply_transpose. Missing std::function vmultT");
1177 const int lineno = __LINE__;
1180 user->vmultT(dst, src);
1189 PetscObjectComm((PetscObject)ppc),
1194 PETSC_ERROR_INITIAL,
1195 "Failure in pcapply_transpose from ::PETScWrappers::NonlinearSolver");
1198 PetscFunctionReturn(PETSC_SUCCESS);
AdditionalData additional_data
void Tvmult(VectorBase &dst, const VectorBase &src) const
MPI_Comm get_mpi_communicator() const
const PC & get_pc() const
void create_pc_with_comm(const MPI_Comm)
virtual ~PreconditionBase()
void vmult(VectorBase &dst, const VectorBase &src) const
void create_pc_with_mat(const MatrixBase &)
PreconditionBlockJacobi()
AdditionalData additional_data
AdditionalData additional_data
AdditionalData additional_data
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
AdditionalData additional_data
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
AdditionalData additional_data
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
AdditionalData additional_data
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
AdditionalData additional_data
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
AdditionalData additional_data
AdditionalData additional_data
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
AdditionalData additional_data
void initialize(const MatrixBase &matrix, const AdditionalData &additional_data=AdditionalData())
static PetscErrorCode pcapply_transpose(PC pc, Vec src, Vec dst)
static PetscErrorCode pcsetup(PC pc)
void initialize(const MPI_Comm comm)
PreconditionShell()=default
static PetscErrorCode pcapply(PC pc, Vec src, Vec dst)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcInvalidState()
static ::ExceptionBase & RecoverableUserCallbackError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
#define DEAL_II_NOT_IMPLEMENTED()
void set_option_value(const std::string &name, const std::string &value)
PetscErrorCode pc_set_failed_reason(PC pc, PCFailedReason reason)
void petsc_increment_state_counter(Vec v)
AdditionalData(const bool use_vertices=true, const bool use_edges=false, const bool use_faces=false, const bool symmetric=false, const std::vector< Point< dim > > coords={})
RelaxationType relaxation_type_up
unsigned int n_sweeps_coarse
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, const RelaxationType relaxation_type_up=RelaxationType::SORJacobi, const RelaxationType relaxation_type_down=RelaxationType::SORJacobi, const RelaxationType relaxation_type_coarse=RelaxationType::GaussianElimination, const unsigned int n_sweeps_coarse=1, const double tol=0.0, const unsigned int max_iter=1, const bool w_cycle=false)
unsigned int aggressive_coarsening_num_levels
RelaxationType relaxation_type_down
RelaxationType relaxation_type_coarse
AdditionalData(const unsigned int levels=0)
AdditionalData(const unsigned int levels=0)
AdditionalData(const double pivoting=1.e-6, const double zero_pivot=1.e-12, const double damping=0.0)
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)
AdditionalData(const double omega=1)
AdditionalData(const double omega=1)