17#ifdef DEAL_II_WITH_SLEPC
23# include <petscversion.h>
25# include <slepcversion.h>
36 , mpi_communicator(mpi_communicator)
37 , reason(EPS_CONVERGED_ITERATING)
45 ierr = EPSSetTolerances(
eps,
47 this->solver_control.max_steps());
66 const PetscErrorCode ierr = EPSDestroy(&
eps);
79 const PetscErrorCode ierr = EPSSetOperators(
eps, A,
nullptr);
90 const PetscErrorCode ierr = EPSSetOperators(
eps, A, B);
102 PetscErrorCode ierr = EPSSetST(
eps, transformation.
st);
105# if DEAL_II_SLEPC_VERSION_GTE(3, 8, 0)
116 ierr = EPSSetTarget(
eps, sinv->additional_data.shift_parameter);
130 const PetscErrorCode ierr = EPSSetTarget(
eps, this_target);
140 const PetscErrorCode ierr = EPSSetWhichEigenpairs(
eps, eps_which);
149 const PetscErrorCode ierr = EPSSetProblemType(
eps, eps_problem);
159 PetscErrorCode ierr =
160 EPSSetDimensions(
eps, n_eigenpairs, PETSC_DECIDE, PETSC_DECIDE);
164 ierr = EPSSetFromOptions(
eps);
173 ierr = EPSSetConvergenceTest(
eps, EPS_CONV_ABS);
183 ierr = EPSSolve(
eps);
191 PetscInt petsc_n_converged = *n_converged;
192 ierr = EPSGetConverged(
eps, &petsc_n_converged);
194 *n_converged = petsc_n_converged;
197 PetscInt n_iterations = 0;
198 PetscReal residual_norm = 0;
204 ierr = EPSGetIterationNumber(
eps, &n_iterations);
208 for (
unsigned int i = 0; i < *n_converged; ++i)
210 double residual_norm_i = 0.0;
229# if DEAL_II_SLEPC_VERSION_GTE(3, 6, 0)
230 ierr = EPSComputeError(
eps, i, EPS_ERROR_ABSOLUTE, &residual_norm_i);
232 ierr = EPSComputeResidualNorm(
eps, i, &residual_norm_i);
236 residual_norm =
std::max(residual_norm, residual_norm_i);
264 const PetscErrorCode ierr =
273 double &real_eigenvalues,
274 double &imag_eigenvalues,
278# ifndef PETSC_USE_COMPLEX
280 const PetscErrorCode ierr = EPSGetEigenpair(
eps,
291 "Your PETSc/SLEPc installation was configured with scalar-type complex "
292 "but this function is not defined for complex types."));
296 (void)real_eigenvalues;
297 (void)imag_eigenvalues;
298 (void)real_eigenvectors;
299 (void)imag_eigenvectors;
310 case ::SolverControl::iterate:
311 reason = EPS_CONVERGED_ITERATING;
314 case ::SolverControl::success:
315 reason =
static_cast<EPSConvergedReason
>(1);
318 case ::SolverControl::failure:
320 reason = EPS_DIVERGED_ITS;
322 reason = EPS_DIVERGED_BREAKDOWN;
365 , additional_data(
data)
367 const PetscErrorCode ierr =
368 EPSSetType(
eps,
const_cast<char *
>(EPSKRYLOVSCHUR));
376 const bool delayed_reorthogonalization)
377 : delayed_reorthogonalization(delayed_reorthogonalization)
388 PetscErrorCode ierr = EPSSetType(
eps,
const_cast<char *
>(EPSARNOLDI));
395 ierr = EPSArnoldiSetDelayed(
eps, PETSC_TRUE);
415 PetscErrorCode ierr = EPSSetType(
eps,
const_cast<char *
>(EPSLANCZOS));
429 , additional_data(
data)
431 PetscErrorCode ierr = EPSSetType(
eps,
const_cast<char *
>(EPSPOWER));
439 bool double_expansion)
440 : double_expansion(double_expansion)
452 PetscErrorCode ierr = EPSSetType(
eps,
const_cast<char *
>(EPSGD));
457 ierr = EPSGDSetDoubleExpansion(
eps, PETSC_TRUE);
469 , additional_data(
data)
471 const PetscErrorCode ierr = EPSSetType(
eps,
const_cast<char *
>(EPSJD));
482 , additional_data(
data)
486# if PETSC_HAVE_BLASLAPACK
487 const PetscErrorCode ierr = EPSSetType(
eps,
const_cast<char *
>(EPSLAPACK));
493 "Your PETSc/SLEPc installation was not configured with BLAS/LAPACK "
494 "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)
SolverBase(SolverControl &cn, const MPI_Comm mpi_communicator)
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)
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)
const AdditionalData additional_data
SolverGeneralizedDavidson(SolverControl &cn, const MPI_Comm mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
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)
#define Assert(cond, exc)
#define AssertNothrow(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
#define DEAL_II_NOT_IMPLEMENTED()
std::vector< index_type > data
::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 > >, dim > eigenvectors(const SymmetricTensor< 2, dim, Number > &T, const SymmetricTensorEigenvectorMethod method=SymmetricTensorEigenvectorMethod::ql_implicit_shifts)