18#ifdef DEAL_II_WITH_SLEPC
24# include <petscversion.h>
26# include <slepcversion.h>
37 , mpi_communicator(mpi_communicator)
38 , reason(EPS_CONVERGED_ITERATING)
46 ierr = EPSSetTolerances(
eps,
48 this->solver_control.max_steps());
67 const PetscErrorCode ierr = EPSDestroy(&
eps);
80 const PetscErrorCode ierr = EPSSetOperators(
eps, A,
nullptr);
91 const PetscErrorCode ierr = EPSSetOperators(
eps, A, B);
103 PetscErrorCode ierr = EPSSetST(
eps, transformation.
st);
106# if DEAL_II_SLEPC_VERSION_GTE(3, 8, 0)
117 ierr = EPSSetTarget(
eps, sinv->additional_data.shift_parameter);
131 const PetscErrorCode ierr = EPSSetTarget(
eps, this_target);
141 const PetscErrorCode ierr = EPSSetWhichEigenpairs(
eps, eps_which);
150 const PetscErrorCode ierr = EPSSetProblemType(
eps, eps_problem);
160 PetscErrorCode ierr =
161 EPSSetDimensions(
eps, n_eigenpairs, PETSC_DECIDE, PETSC_DECIDE);
165 ierr = EPSSetFromOptions(
eps);
174 ierr = EPSSetConvergenceTest(
eps, EPS_CONV_ABS);
184 ierr = EPSSolve(
eps);
192 PetscInt petsc_n_converged = *n_converged;
193 ierr = EPSGetConverged(
eps, &petsc_n_converged);
195 *n_converged = petsc_n_converged;
198 PetscInt n_iterations = 0;
199 PetscReal residual_norm = 0;
205 ierr = EPSGetIterationNumber(
eps, &n_iterations);
209 for (
unsigned int i = 0; i < *n_converged; ++i)
211 double residual_norm_i = 0.0;
230# if DEAL_II_SLEPC_VERSION_GTE(3, 6, 0)
231 ierr = EPSComputeError(
eps, i, EPS_ERROR_ABSOLUTE, &residual_norm_i);
233 ierr = EPSComputeResidualNorm(
eps, i, &residual_norm_i);
237 residual_norm =
std::max(residual_norm, residual_norm_i);
265 const PetscErrorCode ierr =
274 double & real_eigenvalues,
275 double & imag_eigenvalues,
279# ifndef PETSC_USE_COMPLEX
281 const PetscErrorCode ierr = EPSGetEigenpair(
eps,
292 "Your PETSc/SLEPc installation was configured with scalar-type complex "
293 "but this function is not defined for complex types."));
297 (void)real_eigenvalues;
298 (void)imag_eigenvalues;
299 (void)real_eigenvectors;
300 (void)imag_eigenvectors;
311 case ::SolverControl::iterate:
312 reason = EPS_CONVERGED_ITERATING;
315 case ::SolverControl::success:
316 reason =
static_cast<EPSConvergedReason
>(1);
319 case ::SolverControl::failure:
321 reason = EPS_DIVERGED_ITS;
323 reason = EPS_DIVERGED_BREAKDOWN;
366 , additional_data(data)
368 const PetscErrorCode ierr =
369 EPSSetType(
eps,
const_cast<char *
>(EPSKRYLOVSCHUR));
377 const bool delayed_reorthogonalization)
378 : delayed_reorthogonalization(delayed_reorthogonalization)
389 PetscErrorCode ierr = EPSSetType(
eps,
const_cast<char *
>(EPSARNOLDI));
396 ierr = EPSArnoldiSetDelayed(
eps, PETSC_TRUE);
416 PetscErrorCode ierr = EPSSetType(
eps,
const_cast<char *
>(EPSLANCZOS));
430 , additional_data(data)
432 PetscErrorCode ierr = EPSSetType(
eps,
const_cast<char *
>(EPSPOWER));
440 bool double_expansion)
441 : double_expansion(double_expansion)
453 PetscErrorCode ierr = EPSSetType(
eps,
const_cast<char *
>(EPSGD));
458 ierr = EPSGDSetDoubleExpansion(
eps, PETSC_TRUE);
470 , additional_data(data)
472 const PetscErrorCode ierr = EPSSetType(
eps,
const_cast<char *
>(EPSJD));
483 , additional_data(data)
487# if PETSC_HAVE_BLASLAPACK
488 const PetscErrorCode ierr = EPSSetType(
eps,
const_cast<char *
>(EPSLAPACK));
494 "Your PETSc/SLEPc installation was not configured with BLAS/LAPACK "
495 "but this is needed to use the LAPACK solver."));
SolverArnoldi(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
const AdditionalData additional_data
SolverControl & control() const
EPSConvergedReason reason
void set_target_eigenvalue(const PetscScalar &this_target)
const MPI_Comm mpi_communicator
void set_matrices(const PETScWrappers::MatrixBase &A)
void get_solver_state(const SolverControl::State state)
void set_problem_type(EPSProblemType set_problem)
SolverControl & solver_control
void solve(const PETScWrappers::MatrixBase &A, std::vector< PetscScalar > &eigenvalues, std::vector< OutputVector > &eigenvectors, const unsigned int n_eigenpairs=1)
void get_eigenpair(const unsigned int index, PetscScalar &eigenvalues, PETScWrappers::VectorBase &eigenvectors)
void set_transformation(SLEPcWrappers::TransformationBase &this_transformation)
SolverBase(SolverControl &cn, const MPI_Comm &mpi_communicator)
static int convergence_test(EPS eps, PetscScalar real_eigenvalue, PetscScalar imag_eigenvalue, PetscReal residual_norm, PetscReal *estimated_error, void *solver_control)
void set_which_eigenpairs(EPSWhich set_which)
SolverGeneralizedDavidson(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
const AdditionalData additional_data
SolverJacobiDavidson(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
SolverKrylovSchur(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
SolverLAPACK(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
const AdditionalData additional_data
SolverLanczos(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
SolverPower(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
unsigned int last_step() const
virtual State check(const unsigned int step, const double check_value)
unsigned int max_steps() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcSLEPcError(int arg1)
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertNothrow(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
bool delayed_reorthogonalization
AdditionalData(const bool delayed_reorthogonalization=false)
AdditionalData(bool double_expansion=false)
AdditionalData(const EPSLanczosReorthogType r=EPS_LANCZOS_REORTHOG_FULL)
EPSLanczosReorthogType reorthog
std::array< Number, 1 > eigenvalues(const SymmetricTensor< 2, 1, Number > &T)
std::array< std::pair< Number, Tensor< 1, dim, Number > >, std::integral_constant< int, dim >::value > eigenvectors(const SymmetricTensor< 2, dim, Number > &T, const SymmetricTensorEigenvectorMethod method=SymmetricTensorEigenvectorMethod::ql_implicit_shifts)