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/petsc_vector.h> 23 # include <deal.II/lac/slepc_spectral_transformation.h> 28 # include <petscversion.h> 29 # include <slepcversion.h> 31 DEAL_II_NAMESPACE_OPEN
37 const MPI_Comm &mpi_communicator)
40 mpi_communicator (mpi_communicator)
65 #if DEAL_II_PETSC_VERSION_LT(3,2,0) 66 const PetscErrorCode ierr = EPSDestroy (
eps);
68 const PetscErrorCode ierr = EPSDestroy (&
eps);
78 const PetscErrorCode ierr = EPSSetOperators (
eps, A, PETSC_NULL);
87 const PetscErrorCode ierr = EPSSetOperators (
eps, A, B);
96 const PetscErrorCode ierr = EPSSetST(
eps,transformation.
st);
104 ExcMessage(
"Initial vector should be nonzero."));
106 Vec vec = this_initial_vector;
107 #if DEAL_II_PETSC_VERSION_LT(3,1,0) 108 const PetscErrorCode ierr = EPSSetInitialVector (
eps, &vec);
110 const PetscErrorCode ierr = EPSSetInitialSpace (
eps, 1, &vec);
121 const PetscErrorCode ierr = EPSSetTarget (
eps, this_target );
129 const PetscErrorCode ierr = EPSSetWhichEigenpairs (
eps, eps_which);
136 const PetscErrorCode ierr = EPSSetProblemType (
eps, eps_problem);
142 unsigned int *n_converged)
145 PetscErrorCode ierr = EPSSetDimensions (
eps, n_eigenpairs,
146 PETSC_DECIDE, PETSC_DECIDE);
150 ierr = EPSSetFromOptions (
eps);
159 ierr = EPSSetConvergenceTest (
eps, EPS_CONV_ABS);
168 ierr = EPSSolve (
eps);
172 ierr = EPSGetConverged (
eps,
173 reinterpret_cast<PetscInt *>(n_converged));
176 PetscInt n_iterations = 0;
177 PetscReal residual_norm = 0;
183 ierr = EPSGetIterationNumber (
eps, &n_iterations);
187 for (
unsigned int i = 0; i < *n_converged; i++)
189 double residual_norm_i = 0.0;
194 ierr = EPSComputeResidualNorm (
eps, i, &residual_norm_i);
208 residual_norm = std::max (residual_norm, residual_norm_i);
229 PetscScalar &eigenvalues,
233 const PetscErrorCode ierr = EPSGetEigenpair (
eps, index,
234 &eigenvalues, PETSC_NULL,
235 eigenvectors, PETSC_NULL);
242 double &real_eigenvalues,
243 double &imag_eigenvalues,
247 #ifndef PETSC_USE_COMPLEX 249 const PetscErrorCode ierr = EPSGetEigenpair (
eps, index,
257 ExcMessage (
"Your PETSc/SLEPc installation was configured with scalar-type complex " 258 "but this function is not defined for complex types."));
262 (void) real_eigenvalues;
263 (void) imag_eigenvalues;
264 (void) real_eigenvectors;
265 (void) imag_eigenvectors;
274 case ::SolverControl::iterate:
275 reason = EPS_CONVERGED_ITERATING;
278 case ::SolverControl::success:
279 reason =
static_cast<EPSConvergedReason
>(1);
282 case ::SolverControl::failure:
284 reason = EPS_DIVERGED_ITS;
286 reason = EPS_DIVERGED_BREAKDOWN;
319 const MPI_Comm &mpi_communicator,
323 additional_data (data)
325 const PetscErrorCode ierr = EPSSetType (
eps,
326 const_cast<char *>(EPSKRYLOVSCHUR));
334 delayed_reorthogonalization (delayed_reorthogonalization)
344 PetscErrorCode ierr = EPSSetType (
eps, const_cast<char *>(EPSARNOLDI));
351 ierr = EPSArnoldiSetDelayed (
eps, PETSC_TRUE);
370 PetscErrorCode ierr = EPSSetType (
eps, const_cast<char *>(EPSLANCZOS));
379 const MPI_Comm &mpi_communicator,
383 additional_data (data)
385 PetscErrorCode ierr = EPSSetType (
eps, const_cast<char *>(EPSPOWER));
392 : double_expansion(double_expansion)
402 #if DEAL_II_PETSC_VERSION_GTE(3,1,0) 403 PetscErrorCode ierr = EPSSetType (
eps, const_cast<char *>(EPSGD));
408 ierr = EPSGDSetDoubleExpansion (
eps, PETSC_TRUE);
414 ExcMessage (
"Your SLEPc installation does not include a copy of the " 415 "Generalized Davidson solver. A SLEPc version > 3.1.0 is required."));
421 const MPI_Comm &mpi_communicator,
425 additional_data (data)
427 #if DEAL_II_PETSC_VERSION_GTE(3,1,0) 428 const PetscErrorCode ierr = EPSSetType (
eps, const_cast<char *>(EPSJD));
433 ExcMessage (
"Your SLEPc installation does not include a copy of the " 434 "Jacobi-Davidson solver. A SLEPc version > 3.1.0 is required."));
440 const MPI_Comm &mpi_communicator,
444 additional_data (data)
448 #if PETSC_HAVE_BLASLAPACK 449 const PetscErrorCode ierr = EPSSetType (
eps, const_cast<char *>(EPSLAPACK));
453 ExcMessage (
"Your PETSc/SLEPc installation was not configured with BLAS/LAPACK " 454 "but this is needed to use the LAPACK solver."));
459 DEAL_II_NAMESPACE_CLOSE
461 #endif // DEAL_II_WITH_SLEPC
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())
SolverPower(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
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()
void set_initial_vector(const PETScWrappers::VectorBase &this_initial_vector) 1
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)