22 #ifdef DEAL_II_WITH_PETSC
30 # 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;
217 solver_data = std_cxx14::make_unique<SolverData>();
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;
701 solver_data = std_cxx14::make_unique<SolverDataMUMPS>();
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);
824 ierr = KSPGetIterationNumber(
solver_data->ksp, &its);
826 ierr = KSPGetResidualNorm(
solver_data->ksp, &rnorm);
830 # else // DEAL_II_PETSC_WITH_MUMPS
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;
893 #endif // DEAL_II_WITH_PETSC