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> 27 # include <petscversion.h> 28 # include <slepcversion.h> 30 DEAL_II_NAMESPACE_OPEN
36 const MPI_Comm &mpi_communicator)
39 mpi_communicator (mpi_communicator),
40 reason (EPS_CONVERGED_ITERATING)
65 const PetscErrorCode ierr = EPSDestroy (&
eps);
76 const PetscErrorCode ierr = EPSSetOperators (
eps, A,
nullptr);
85 const PetscErrorCode ierr = EPSSetOperators (
eps, A, B);
94 PetscErrorCode ierr = EPSSetST(
eps,transformation.
st);
97 #if DEAL_II_SLEPC_VERSION_GTE(3, 8, 0) 104 ierr = EPSSetTarget (
eps, sinv->additional_data.shift_parameter);
115 ExcMessage(
"Initial vector should be nonzero."));
117 Vec vec = this_initial_vector;
118 const PetscErrorCode ierr = EPSSetInitialSpace (
eps, 1, &vec);
129 const PetscErrorCode ierr = EPSSetTarget (
eps, this_target );
137 const PetscErrorCode ierr = EPSSetWhichEigenpairs (
eps, eps_which);
144 const PetscErrorCode ierr = EPSSetProblemType (
eps, eps_problem);
150 unsigned int *n_converged)
153 PetscErrorCode ierr = EPSSetDimensions (
eps, n_eigenpairs,
154 PETSC_DECIDE, PETSC_DECIDE);
158 ierr = EPSSetFromOptions (
eps);
167 ierr = EPSSetConvergenceTest (
eps, EPS_CONV_ABS);
176 ierr = EPSSolve (
eps);
180 ierr = EPSGetConverged (
eps,
181 reinterpret_cast<PetscInt *>(n_converged));
184 PetscInt n_iterations = 0;
185 PetscReal residual_norm = 0;
191 ierr = EPSGetIterationNumber (
eps, &n_iterations);
195 for (
unsigned int i = 0; i < *n_converged; i++)
197 double residual_norm_i = 0.0;
216 #if DEAL_II_SLEPC_VERSION_GTE(3, 6, 0) 217 ierr = EPSComputeError(
eps, i, EPS_ERROR_ABSOLUTE, &residual_norm_i);
219 ierr = EPSComputeResidualNorm(
eps, i, &residual_norm_i);
223 residual_norm = std::max (residual_norm, residual_norm_i);
248 const PetscErrorCode ierr = EPSGetEigenpair (
eps, index,
257 double &real_eigenvalues,
258 double &imag_eigenvalues,
262 #ifndef PETSC_USE_COMPLEX 264 const PetscErrorCode ierr = EPSGetEigenpair (
eps, index,
272 ExcMessage (
"Your PETSc/SLEPc installation was configured with scalar-type complex " 273 "but this function is not defined for complex types."));
277 (void) real_eigenvalues;
278 (void) imag_eigenvalues;
279 (void) real_eigenvectors;
280 (void) imag_eigenvectors;
289 case ::SolverControl::iterate:
290 reason = EPS_CONVERGED_ITERATING;
293 case ::SolverControl::success:
294 reason =
static_cast<EPSConvergedReason
>(1);
297 case ::SolverControl::failure:
299 reason = EPS_DIVERGED_ITS;
301 reason = EPS_DIVERGED_BREAKDOWN;
334 const MPI_Comm &mpi_communicator,
338 additional_data (data)
340 const PetscErrorCode ierr = EPSSetType (
eps,
341 const_cast<char *>(EPSKRYLOVSCHUR));
349 delayed_reorthogonalization (delayed_reorthogonalization)
359 PetscErrorCode ierr = EPSSetType (
eps, const_cast<char *>(EPSARNOLDI));
366 ierr = EPSArnoldiSetDelayed (
eps, PETSC_TRUE);
385 PetscErrorCode ierr = EPSSetType (
eps, const_cast<char *>(EPSLANCZOS));
394 const MPI_Comm &mpi_communicator,
398 additional_data (data)
400 PetscErrorCode ierr = EPSSetType (
eps, const_cast<char *>(EPSPOWER));
407 : double_expansion(double_expansion)
417 PetscErrorCode ierr = EPSSetType (
eps, const_cast<char *>(EPSGD));
422 ierr = EPSGDSetDoubleExpansion (
eps, PETSC_TRUE);
429 const MPI_Comm &mpi_communicator,
433 additional_data (data)
435 const PetscErrorCode ierr = EPSSetType (
eps, const_cast<char *>(EPSJD));
441 const MPI_Comm &mpi_communicator,
445 additional_data (data)
449 #if PETSC_HAVE_BLASLAPACK 450 const PetscErrorCode ierr = EPSSetType (
eps, const_cast<char *>(EPSLAPACK));
454 ExcMessage (
"Your PETSc/SLEPc installation was not configured with BLAS/LAPACK " 455 "but this is needed to use the LAPACK solver."));
460 DEAL_II_NAMESPACE_CLOSE
462 #endif // DEAL_II_WITH_SLEPC
#define AssertNothrow(cond, exc)
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())
void set_initial_vector(const PETScWrappers::VectorBase &this_initial_vector)
std::array< Number, 1 > eigenvalues(const SymmetricTensor< 2, 1, Number > &T)
real_type l2_norm() const
#define AssertThrow(cond, exc)
void solve(const PETScWrappers::MatrixBase &A, std::vector< PetscScalar > &eigenvalues, std::vector< OutputVector > &eigenvectors, const unsigned int n_eigenpairs=1)
const MPI_Comm mpi_communicator
const AdditionalData additional_data
SolverKrylovSchur(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
EPSLanczosReorthogType reorthog
SolverBase(SolverControl &cn, const MPI_Comm &mpi_communicator)
AdditionalData(const bool delayed_reorthogonalization=false)
void set_problem_type(EPSProblemType set_problem)
static ::ExceptionBase & ExcMessage(std::string arg1)
void set_target_eigenvalue(const PetscScalar &this_target)
void set_matrices(const PETScWrappers::MatrixBase &A)
void set_which_eigenpairs(EPSWhich set_which)
#define Assert(cond, exc)
SolverGeneralizedDavidson(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
EPSConvergedReason reason
const AdditionalData additional_data
void get_eigenpair(const unsigned int index, PetscScalar &eigenvalues, PETScWrappers::VectorBase &eigenvectors)
static int convergence_test(EPS eps, PetscScalar real_eigenvalue, PetscScalar imag_eigenvalue, PetscReal residual_norm, PetscReal *estimated_error, void *solver_control)
SolverLanczos(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
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())
static ::ExceptionBase & ExcNotImplemented()
AdditionalData(const EPSLanczosReorthogType r=EPS_LANCZOS_REORTHOG_FULL)
const AdditionalData additional_data
static ::ExceptionBase & ExcSLEPcError(int arg1)
void set_transformation(SLEPcWrappers::TransformationBase &this_transformation)
SolverControl & solver_control
SolverArnoldi(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
SolverControl & control() const
void get_solver_state(const SolverControl::State state)