16 #include <deal.II/lac/slepc_solver.h> 18 #ifdef DEAL_II_WITH_SLEPC 20 # include <deal.II/lac/petsc_matrix_base.h> 21 # include <deal.II/lac/petsc_vector_base.h> 22 # include <deal.II/lac/slepc_spectral_transformation.h> 24 # include <petscversion.h> 26 # include <slepcversion.h> 31 DEAL_II_NAMESPACE_OPEN
37 , mpi_communicator(mpi_communicator)
38 , reason(EPS_CONVERGED_ITERATING)
46 ierr = EPSSetTolerances(
eps,
65 const PetscErrorCode ierr = EPSDestroy(&
eps);
76 const PetscErrorCode ierr = EPSSetOperators(
eps, A,
nullptr);
85 const PetscErrorCode ierr = EPSSetOperators(
eps, A, B);
95 PetscErrorCode ierr = EPSSetST(
eps, transformation.
st);
98 # if DEAL_II_SLEPC_VERSION_GTE(3, 8, 0) 106 dynamic_cast<SLEPcWrappers::TransformationShiftInvert *>(
109 ierr = EPSSetTarget(
eps, sinv->additional_data.shift_parameter);
120 ExcMessage(
"Initial vector should be nonzero."));
122 Vec vec = this_initial_vector;
123 const PetscErrorCode ierr = EPSSetInitialSpace(
eps, 1, &vec);
134 const PetscErrorCode ierr = EPSSetTarget(
eps, this_target);
142 const PetscErrorCode ierr = EPSSetWhichEigenpairs(
eps, eps_which);
149 const PetscErrorCode ierr = EPSSetProblemType(
eps, eps_problem);
157 PetscErrorCode ierr =
158 EPSSetDimensions(
eps, n_eigenpairs, PETSC_DECIDE, PETSC_DECIDE);
162 ierr = EPSSetFromOptions(
eps);
171 ierr = EPSSetConvergenceTest(
eps, EPS_CONV_ABS);
181 ierr = EPSSolve(
eps);
185 ierr = EPSGetConverged(
eps, reinterpret_cast<PetscInt *>(n_converged));
188 PetscInt n_iterations = 0;
189 PetscReal residual_norm = 0;
195 ierr = EPSGetIterationNumber(
eps, &n_iterations);
199 for (
unsigned int i = 0; i < *n_converged; i++)
201 double residual_norm_i = 0.0;
220 # if DEAL_II_SLEPC_VERSION_GTE(3, 6, 0) 221 ierr = EPSComputeError(
eps, i, EPS_ERROR_ABSOLUTE, &residual_norm_i);
223 ierr = EPSComputeResidualNorm(
eps, i, &residual_norm_i);
227 residual_norm = std::max(residual_norm, residual_norm_i);
253 const PetscErrorCode ierr =
261 double & real_eigenvalues,
262 double & imag_eigenvalues,
266 # ifndef PETSC_USE_COMPLEX 268 const PetscErrorCode ierr = EPSGetEigenpair(
eps,
279 "Your PETSc/SLEPc installation was configured with scalar-type complex " 280 "but this function is not defined for complex types."));
284 (void)real_eigenvalues;
285 (void)imag_eigenvalues;
286 (void)real_eigenvectors;
287 (void)imag_eigenvectors;
296 case ::SolverControl::iterate:
297 reason = EPS_CONVERGED_ITERATING;
300 case ::SolverControl::success:
301 reason =
static_cast<EPSConvergedReason
>(1);
304 case ::SolverControl::failure:
306 reason = EPS_DIVERGED_ITS;
308 reason = EPS_DIVERGED_BREAKDOWN;
342 const MPI_Comm & mpi_communicator,
345 , additional_data(data)
347 const PetscErrorCode ierr =
348 EPSSetType(
eps, const_cast<char *>(EPSKRYLOVSCHUR));
354 const bool delayed_reorthogonalization)
355 : delayed_reorthogonalization(delayed_reorthogonalization)
364 PetscErrorCode ierr = EPSSetType(
eps, const_cast<char *>(EPSARNOLDI));
371 ierr = EPSArnoldiSetDelayed(
eps, PETSC_TRUE);
388 PetscErrorCode ierr = EPSSetType(
eps, const_cast<char *>(EPSLANCZOS));
397 const MPI_Comm & mpi_communicator,
400 , additional_data(data)
402 PetscErrorCode ierr = EPSSetType(
eps, const_cast<char *>(EPSPOWER));
408 bool double_expansion)
409 : double_expansion(double_expansion)
419 PetscErrorCode ierr = EPSSetType(
eps, const_cast<char *>(EPSGD));
424 ierr = EPSGDSetDoubleExpansion(
eps, PETSC_TRUE);
431 const MPI_Comm &mpi_communicator,
434 , additional_data(data)
436 const PetscErrorCode ierr = EPSSetType(
eps, const_cast<char *>(EPSJD));
442 const MPI_Comm & mpi_communicator,
445 , additional_data(data)
449 # if PETSC_HAVE_BLASLAPACK 450 const PetscErrorCode ierr = EPSSetType(
eps, const_cast<char *>(EPSLAPACK));
456 "Your PETSc/SLEPc installation was not configured with BLAS/LAPACK " 457 "but this is needed to use the LAPACK solver."));
462 DEAL_II_NAMESPACE_CLOSE
464 #endif // DEAL_II_WITH_SLEPC
void set_problem_type(EPSProblemType set_problem)
#define AssertNothrow(cond, exc)
static int convergence_test(EPS eps, PetscScalar real_eigenvalue, PetscScalar imag_eigenvalue, PetscReal residual_norm, PetscReal *estimated_error, void *solver_control)
bool delayed_reorthogonalization
virtual State check(const unsigned int step, const double check_value)
AdditionalData(bool double_expansion=false)
SolverJacobiDavidson(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
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)
SolverPower(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
std::array< Number, 1 > eigenvalues(const SymmetricTensor< 2, 1, Number > &T)
real_type l2_norm() const
void set_which_eigenpairs(EPSWhich set_which)
void set_target_eigenvalue(const PetscScalar &this_target)
#define AssertThrow(cond, exc)
const MPI_Comm mpi_communicator
void get_eigenpair(const unsigned int index, PetscScalar &eigenvalues, PETScWrappers::VectorBase &eigenvectors)
const AdditionalData additional_data
SolverKrylovSchur(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
EPSLanczosReorthogType reorthog
AdditionalData(const bool delayed_reorthogonalization=false)
static ::ExceptionBase & ExcMessage(std::string arg1)
void get_solver_state(const SolverControl::State state)
void set_matrices(const PETScWrappers::MatrixBase &A)
#define Assert(cond, exc)
void set_initial_vector(const PETScWrappers::VectorBase &this_initial_vector)
SolverGeneralizedDavidson(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
EPSConvergedReason reason
SolverControl & control() const
const AdditionalData additional_data
SolverLanczos(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
void set_transformation(SLEPcWrappers::TransformationBase &this_transformation)
unsigned int last_step() const
unsigned int max_steps() const
SolverLAPACK(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
SolverBase(SolverControl &cn, const MPI_Comm &mpi_communicator)
static ::ExceptionBase & ExcNotImplemented()
AdditionalData(const EPSLanczosReorthogType r=EPS_LANCZOS_REORTHOG_FULL)
const AdditionalData additional_data
static ::ExceptionBase & ExcSLEPcError(int arg1)
void solve(const PETScWrappers::MatrixBase &A, std::vector< PetscScalar > &eigenvalues, std::vector< OutputVector > &eigenvectors, const unsigned int n_eigenpairs=1)
SolverControl & solver_control
SolverArnoldi(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())