18#ifdef DEAL_II_WITH_PETSC
28# include <petscconf.h>
61 PetscErrorCode ierr = PCDestroy(&
pc);
71 PetscErrorCode ierr = PCApply(
pc, src, dst);
80 PetscErrorCode ierr = PCApplyTranspose(
pc, src, dst);
89 PetscErrorCode ierr = PCSetUp(
pc);
96 return PetscObjectComm(
reinterpret_cast<PetscObject
>(
pc));
107 PetscErrorCode ierr = PetscObjectGetComm(
108 reinterpret_cast<PetscObject
>(
static_cast<const Mat &
>(matrix)), &
comm);
113 ierr = PCSetOperators(
pc, matrix, matrix);
121 PetscErrorCode ierr = PCCreate(
comm, &
pc);
146 PetscErrorCode ierr = PCCreate(
comm, &
pc);
168 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCJACOBI));
171 ierr = PCSetFromOptions(
pc);
203 PetscErrorCode ierr = PCCreate(
comm, &
pc);
224 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCBJACOBI));
227 ierr = PCSetFromOptions(
pc);
278 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCSOR));
285 ierr = PCSetFromOptions(
pc);
322 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCSOR));
330 ierr = PCSORSetSymmetric(
pc, SOR_SYMMETRIC_SWEEP);
333 ierr = PCSetFromOptions(
pc);
370 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCICC));
377 ierr = PCSetFromOptions(
pc);
414 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCILU));
421 ierr = PCSetFromOptions(
pc);
429 const bool symmetric_operator,
430 const double strong_threshold,
431 const double max_row_sum,
432 const unsigned int aggressive_coarsening_num_levels,
433 const bool output_details,
437 const unsigned int n_sweeps_coarse,
439 const unsigned int max_iter,
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)
446 , relaxation_type_up(relaxation_type_up)
447 , relaxation_type_down(relaxation_type_down)
448 , relaxation_type_coarse(relaxation_type_coarse)
449 , n_sweeps_coarse(n_sweeps_coarse)
457# ifdef DEAL_II_PETSC_WITH_HYPRE
468 std::string string_type;
470 switch (relaxation_type)
473 string_type =
"Jacobi";
477 string_type =
"sequential-Gauss-Seidel";
481 string_type =
"seqboundary-Gauss-Seidel";
484 string_type =
"SOR/Jacobi";
488 string_type =
"backward-SOR/Jacobi";
492 string_type =
"symmetric-SOR/Jacobi";
496 string_type =
" l1scaled-SOR/Jacobi";
500 string_type =
"Gaussian-elimination";
504 string_type =
"l1-Gauss-Seidel";
508 string_type =
"backward-l1-Gauss-Seidel";
514 string_type =
"Chebyshev";
517 string_type =
"FCF-Jacobi";
521 string_type =
"l1scaled-Jacobi";
524 string_type =
"None";
549 PetscErrorCode ierr = PCCreate(
comm, &
pc);
552# ifdef DEAL_II_PETSC_WITH_HYPRE
557 ExcMessage(
"Your PETSc installation does not include a copy of "
558 "the hypre package necessary for this preconditioner."));
577# ifdef DEAL_II_PETSC_WITH_HYPRE
578 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCHYPRE));
581 ierr = PCHYPRESetType(
pc,
"boomeramg");
625 auto relaxation_type_is_symmetric =
642 ExcMessage(
"Use a symmetric smoother for relaxation_type_up"));
647 ExcMessage(
"Use a symmetric smoother for relaxation_type_down"));
652 ExcMessage(
"Use a symmetric smoother for relaxation_type_coarse"));
673 ierr = PCSetFromOptions(
pc);
677 ExcMessage(
"Your PETSc installation does not include a copy of "
678 "the hypre package necessary for this preconditioner."));
688# ifdef DEAL_II_PETSC_WITH_HYPRE
698 (void)additional_data_;
700 ExcMessage(
"Your PETSc installation does not include a copy of "
701 "the hypre package necessary for this preconditioner."));
709 const unsigned int symmetric,
710 const unsigned int n_levels,
711 const double threshold,
713 const bool output_details)
714 : symmetric(symmetric)
716 , threshold(threshold)
718 , output_details(output_details)
746# ifdef DEAL_II_PETSC_WITH_HYPRE
749 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCHYPRE));
752 ierr = PCHYPRESetType(
pc,
"parasails");
763 "ParaSails parameter symmetric can only be equal to 0, 1, 2!"));
765 std::stringstream ssStream;
771 ssStream <<
"nonsymmetric";
783 ssStream <<
"nonsymmetric,SPD";
791 "ParaSails parameter symmetric can only be equal to 0, 1, 2!"));
807 ierr = PCSetFromOptions(
pc);
813 ExcMessage(
"Your PETSc installation does not include a copy of "
814 "the hypre package necessary for this preconditioner."));
845 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCNONE));
848 ierr = PCSetFromOptions(
pc);
856 const double zero_pivot,
857 const double damping)
859 , zero_pivot(zero_pivot)
889 PetscErrorCode ierr = PCSetType(
pc,
const_cast<char *
>(PCLU));
902 ierr = PCSetFromOptions(
pc);
910 const bool use_vertices,
911 const bool use_edges,
912 const bool use_faces,
913 const bool symmetric,
915 : use_vertices(use_vertices)
916 , use_edges(use_edges)
917 , use_faces(use_faces)
918 , symmetric(symmetric)
939 PetscErrorCode ierr = PCCreate(
comm, &
pc);
961# if DEAL_II_PETSC_VERSION_GTE(3, 10, 0)
962 PetscErrorCode ierr = PCSetType(pc,
const_cast<char *
>(PCBDDC));
968 MatType current_type;
972 ierr = PCGetOperators(pc, &A, &P);
974 ierr = PCGetUseAmat(pc, &flg);
977 ierr = MatGetType(flg ? A : P, ¤t_type);
980 strcmp(current_type, MATIS) == 0,
982 "Matrix must be of IS type. For this, the variant of reinit that includes the active dofs must be used."));
986 std::stringstream ssStream;
988 if (additional_data.use_vertices)
992 if (additional_data.use_edges)
996 if (additional_data.use_faces)
1000 if (additional_data.symmetric)
1004 if (additional_data.coords.size() > 0)
1008 std::vector<PetscReal> coords_petsc(additional_data.coords.size() *
1010 for (
unsigned int i = 0, j = 0; i < additional_data.coords.size(); ++i)
1012 for (j = 0; j < dim; ++j)
1013 coords_petsc[dim * i + j] = additional_data.coords[i][j];
1016 ierr = PCSetCoordinates(pc,
1018 additional_data.coords.size(),
1019 coords_petsc.data());
1025 ierr = PCSetCoordinates(pc, 0, 0,
nullptr);
1030 ierr = PCSetFromOptions(pc);
1034 false,
ExcMessage(
"BDDC preconditioner requires PETSc 3.10.0 or newer"));
1047 additional_data = additional_data_;
1049 create_pc_with_mat(matrix_);
1068 PetscErrorCode ierr;
1071 ierr = PCDestroy(&
pc);
1076 ierr = PCSetType(
pc, PCSHELL);
1078 ierr = PCShellSetContext(
pc,
static_cast<void *
>(
this));
1086 ierr = PCShellSetName(
pc,
"deal.II user solve");
1094 PetscErrorCode ierr;
1095 ierr = PCSetOperators(
pc, matrix, matrix);
1100# define PetscCall(code) \
1103 PetscErrorCode ierr = (code); \
1112 PetscFunctionBeginUser;
1117 PetscFunctionReturn(0);
1125 PetscFunctionBeginUser;
1126 PetscCall(PCShellGetContext(ppc, &ctx));
1131 PetscObjectComm((PetscObject)ppc),
1133 "Failure in ::PETScWrappers::PreconditionShell::pcapply. Missing std::function vmult");
1137 const int lineno = __LINE__;
1140 user->vmult(dst, src);
1149 PetscObjectComm((PetscObject)ppc),
1154 PETSC_ERROR_INITIAL,
1155 "Failure in pcapply from ::PETScWrappers::NonlinearSolver");
1158 PetscFunctionReturn(0);
1166 PetscFunctionBeginUser;
1167 PetscCall(PCShellGetContext(ppc, &ctx));
1172 PetscObjectComm((PetscObject)ppc),
1174 "Failure in ::PETScWrappers::PreconditionShell::pcapply_transpose. Missing std::function vmultT");
1178 const int lineno = __LINE__;
1181 user->vmultT(dst, src);
1190 PetscObjectComm((PetscObject)ppc),
1195 PETSC_ERROR_INITIAL,
1196 "Failure in pcapply_transpose from ::PETScWrappers::NonlinearSolver");
1199 PetscFunctionReturn(0);
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
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcInvalidState()
static ::ExceptionBase & RecoverableUserCallbackError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
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)