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/petsc_matrix_base.h> 25 # include <deal.II/lac/slepc_spectral_transformation.h> 26 # include <deal.II/lac/solver_control.h> 28 # include <petscconf.h> 29 # include <petscksp.h> 31 # include <slepceps.h> 35 DEAL_II_NAMESPACE_OPEN
178 template <
typename OutputVector>
183 const unsigned int n_eigenpairs = 1);
190 template <
typename OutputVector>
196 const unsigned int n_eigenpairs = 1);
203 template <
typename OutputVector>
207 std::vector<double> & real_eigenvalues,
208 std::vector<double> & imag_eigenvalues,
209 std::vector<OutputVector> & real_eigenvectors,
210 std::vector<OutputVector> & imag_eigenvectors,
211 const unsigned int n_eigenpairs = 1);
226 template <
typename Vector>
281 <<
" An error with error number " << arg1
282 <<
" occurred while calling a SLEPc function");
290 <<
" The number of converged eigenvectors is " << arg1
291 <<
" but " << arg2 <<
" were requested. ");
318 solve(
const unsigned int n_eigenpairs,
unsigned int *n_converged);
337 double & real_eigenvalues,
338 double & imag_eigenvalues,
378 PetscScalar real_eigenvalue,
379 PetscScalar imag_eigenvalue,
380 PetscReal residual_norm,
381 PetscReal * estimated_error,
491 const EPSLanczosReorthogType r = EPS_LANCZOS_REORTHOG_FULL);
666 template <
typename OutputVector>
671 const unsigned int n_eigenpairs)
674 AssertThrow((n_eigenpairs > 0) && (n_eigenpairs <= A.
m()),
681 unsigned int n_converged = 0;
682 solve(n_eigenpairs, &n_converged);
684 if (n_converged > n_eigenpairs)
685 n_converged = n_eigenpairs;
694 for (
unsigned int index = 0; index < n_converged; ++index)
698 template <
typename OutputVector>
704 const unsigned int n_eigenpairs)
711 AssertThrow((n_eigenpairs > 0) && (n_eigenpairs <= A.
m()),
718 unsigned int n_converged = 0;
719 solve(n_eigenpairs, &n_converged);
721 if (n_converged >= n_eigenpairs)
722 n_converged = n_eigenpairs;
732 for (
unsigned int index = 0; index < n_converged; ++index)
736 template <
typename OutputVector>
740 std::vector<double> & real_eigenvalues,
741 std::vector<double> & imag_eigenvalues,
742 std::vector<OutputVector> & real_eigenvectors,
743 std::vector<OutputVector> & imag_eigenvectors,
744 const unsigned int n_eigenpairs)
751 AssertThrow(real_eigenvalues.size() == imag_eigenvalues.size(),
753 imag_eigenvalues.size()));
754 AssertThrow(real_eigenvectors.size() == imag_eigenvectors.size(),
756 imag_eigenvectors.size()));
759 AssertThrow((n_eigenpairs > 0) && (n_eigenpairs <= A.
m()),
766 unsigned int n_converged = 0;
767 solve(n_eigenpairs, &n_converged);
769 if (n_converged >= n_eigenpairs)
770 n_converged = n_eigenpairs;
776 (imag_eigenvectors.size() != 0),
779 real_eigenvectors.resize(n_converged, real_eigenvectors.front());
780 imag_eigenvectors.resize(n_converged, imag_eigenvectors.front());
781 real_eigenvalues.resize(n_converged);
782 imag_eigenvalues.resize(n_converged);
784 for (
unsigned int index = 0; index < n_converged; ++index)
786 real_eigenvalues[index],
787 imag_eigenvalues[index],
788 real_eigenvectors[index],
789 imag_eigenvectors[index]);
792 template <
typename Vector>
796 std::vector<Vec> vecs(this_initial_space.size());
798 for (
unsigned int i = 0; i < this_initial_space.size(); i++)
800 Assert(this_initial_space[i].l2_norm() > 0.0,
801 ExcMessage(
"Initial vectors should be nonzero."));
802 vecs[i] = this_initial_space[i];
811 const PetscErrorCode ierr =
812 EPSSetInitialSpace(
eps, vecs.size(), vecs.data());
818 DEAL_II_NAMESPACE_CLOSE
820 # endif // DEAL_II_WITH_SLEPC
static ::ExceptionBase & ExcSLEPcWrappersUsageError()
void set_problem_type(EPSProblemType set_problem)
#define DeclException2(Exception2, type1, type2, outsequence)
static int convergence_test(EPS eps, PetscScalar real_eigenvalue, PetscScalar imag_eigenvalue, PetscReal residual_norm, PetscReal *estimated_error, void *solver_control)
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())
std::array< Number, 1 > eigenvalues(const SymmetricTensor< 2, 1, Number > &T)
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)
#define DeclException1(Exception1, type1, outsequence)
void get_solver_state(const SolverControl::State state)
void set_matrices(const PETScWrappers::MatrixBase &A)
#define Assert(cond, exc)
void set_initial_space(const std::vector< Vector > &initial_space)
void set_initial_vector(const PETScWrappers::VectorBase &this_initial_vector)
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
SolverControl & control() const
const AdditionalData additional_data
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)
static ::ExceptionBase & ExcSLEPcEigenvectorConvergenceMismatchError(int arg1, int arg2)
SolverLAPACK(SolverControl &cn, const MPI_Comm &mpi_communicator=PETSC_COMM_SELF, const AdditionalData &data=AdditionalData())
SolverBase(SolverControl &cn, const MPI_Comm &mpi_communicator)
const AdditionalData additional_data
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())