17 #ifndef dealii_slepc_solver_h 18 #define dealii_slepc_solver_h 20 #include <deal.II/base/config.h> 22 #ifdef DEAL_II_WITH_SLEPC 24 # include <deal.II/lac/solver_control.h> 25 # include <deal.II/lac/petsc_matrix_base.h> 26 # include <deal.II/lac/slepc_spectral_transformation.h> 28 # include <petscconf.h> 29 # include <petscksp.h> 30 # include <slepceps.h> 34 DEAL_II_NAMESPACE_OPEN
173 template <
typename OutputVector>
178 const unsigned int n_eigenpairs = 1);
185 template <
typename OutputVector>
191 const unsigned int n_eigenpairs = 1);
198 template <
typename OutputVector>
202 std::vector<double> &real_eigenvalues,
203 std::vector<double> &imag_eigenvalues,
204 std::vector<OutputVector> &real_eigenvectors,
205 std::vector<OutputVector> &imag_eigenvectors,
206 const unsigned int n_eigenpairs = 1);
222 template <
typename Vector>
225 (
const std::vector<Vector> &initial_space);
278 <<
" An error with error number " << arg1
279 <<
" occurred while calling a SLEPc function");
286 <<
" The number of converged eigenvectors is " << arg1
287 <<
" but " << arg2 <<
" were requested. ");
314 solve (
const unsigned int n_eigenpairs,
315 unsigned int *n_converged);
334 double &real_eigenvalues,
335 double &imag_eigenvalues,
377 PetscScalar real_eigenvalue,
378 PetscScalar imag_eigenvalue,
379 PetscReal residual_norm,
380 PetscReal *estimated_error,
492 AdditionalData(
const EPSLanczosReorthogType r = EPS_LANCZOS_REORTHOG_FULL);
671 template <
typename OutputVector>
676 const unsigned int n_eigenpairs)
679 AssertThrow ((n_eigenpairs > 0) && (n_eigenpairs <= A.
m ()),
686 unsigned int n_converged = 0;
687 solve (n_eigenpairs, &n_converged);
689 if (n_converged > n_eigenpairs)
690 n_converged = n_eigenpairs;
698 for (
unsigned int index=0; index<n_converged; ++index)
702 template <
typename OutputVector>
708 const unsigned int n_eigenpairs)
715 AssertThrow ((n_eigenpairs>0) && (n_eigenpairs<=A.
m ()),
722 unsigned int n_converged = 0;
723 solve (n_eigenpairs, &n_converged);
725 if (n_converged>=n_eigenpairs)
726 n_converged = n_eigenpairs;
735 for (
unsigned int index=0; index<n_converged; ++index)
739 template <
typename OutputVector>
743 std::vector<double> &real_eigenvalues,
744 std::vector<double> &imag_eigenvalues,
745 std::vector<OutputVector> &real_eigenvectors,
746 std::vector<OutputVector> &imag_eigenvectors,
747 const unsigned int n_eigenpairs)
754 AssertThrow (real_eigenvalues.size() == imag_eigenvalues.size(),
756 AssertThrow (real_eigenvectors.size() == imag_eigenvectors.size (),
760 AssertThrow ((n_eigenpairs>0) && (n_eigenpairs<=A.
m ()),
767 unsigned int n_converged = 0;
768 solve (n_eigenpairs, &n_converged);
770 if (n_converged>=n_eigenpairs)
771 n_converged = n_eigenpairs;
775 AssertThrow ((real_eigenvectors.size()!=0) && (imag_eigenvectors.size()!=0),
778 real_eigenvectors.resize (n_converged, real_eigenvectors.front());
779 imag_eigenvectors.resize (n_converged, imag_eigenvectors.front());
780 real_eigenvalues.resize (n_converged);
781 imag_eigenvalues.resize (n_converged);
783 for (
unsigned int index=0; index<n_converged; ++index)
785 real_eigenvalues[index], imag_eigenvalues[index],
786 real_eigenvectors[index], imag_eigenvectors[index]);
789 template <
typename Vector>
793 std::vector<Vec> vecs(this_initial_space.size());
795 for (
unsigned int i = 0; i < this_initial_space.size(); i++)
797 Assert(this_initial_space[i].l2_norm()>0.0,
798 ExcMessage(
"Initial vectors should be nonzero."));
799 vecs[i] = this_initial_space[i];
807 const PetscErrorCode ierr = EPSSetInitialSpace (
eps, vecs.size(), vecs.data());
813 DEAL_II_NAMESPACE_CLOSE
815 #endif // DEAL_II_WITH_SLEPC
static ::ExceptionBase & ExcSLEPcWrappersUsageError()
void set_initial_space(const std::vector< Vector > &initial_space)
#define DeclException2(Exception2, type1, type2, outsequence)
bool delayed_reorthogonalization
const AdditionalData additional_data
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)
#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)
#define DeclException1(Exception1, type1, outsequence)
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)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
SolverGeneralizedDavidson(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
const AdditionalData additional_data
#define DeclException0(Exception0)
EPSConvergedReason reason
const AdditionalData additional_data
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())
static ::ExceptionBase & ExcSLEPcEigenvectorConvergenceMismatchError(int arg1, int arg2)
SolverLAPACK(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
const AdditionalData additional_data
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)