13#ifndef dealii_parpack_solver_h
14#define dealii_parpack_solver_h
31#ifdef DEAL_II_ARPACK_WITH_PARPACK
207template <
typename VectorType>
312 const std::vector<IndexSet> &partitioning);
318 reinit(
const VectorType &distributed_vector);
335 set_shift(
const std::complex<double> sigma);
346 template <
typename MatrixType1,
typename MatrixType2,
typename INVERSE>
348 solve(
const MatrixType1 &A,
349 const MatrixType2 &B,
350 const INVERSE &inverse,
353 const unsigned int n_eigenvalues);
358 template <
typename MatrixType1,
typename MatrixType2,
typename INVERSE>
360 solve(
const MatrixType1 &A,
361 const MatrixType2 &B,
362 const INVERSE &inverse,
365 const unsigned int n_eigenvalues);
434 std::vector<double>
v;
457 std::vector<double>
z;
510 << arg1 <<
" eigenpairs were requested, but only " << arg2
516 <<
"Number of wanted eigenvalues " << arg1
517 <<
" is larger that the size of the matrix " << arg2);
522 <<
"Number of wanted eigenvalues " << arg1
523 <<
" is larger that the size of eigenvectors " << arg2);
529 <<
"To store the real and complex parts of " << arg1
530 <<
" eigenvectors in real-valued vectors, their size (currently set to "
531 << arg2 <<
") should be greater than or equal to " << arg1 + 1);
536 <<
"Number of wanted eigenvalues " << arg1
537 <<
" is larger that the size of eigenvalues " << arg2);
542 <<
"Number of Arnoldi vectors " << arg1
543 <<
" is larger that the size of the matrix " << arg2);
548 <<
"Number of Arnoldi vectors " << arg1
549 <<
" is too small to obtain " << arg2 <<
" eigenvalues");
553 <<
"This ido " << arg1
554 <<
" is not supported. Check documentation of ARPACK");
558 <<
"This mode " << arg1
559 <<
" is not supported. Check documentation of ARPACK");
563 <<
"Error with Pdnaupd, info " << arg1
564 <<
". Check documentation of ARPACK");
568 <<
"Error with Pdneupd, info " << arg1
569 <<
". Check documentation of ARPACK");
573 <<
"Maximum number " << arg1 <<
" of iterations reached.");
577 <<
"No shifts could be applied during implicit"
578 <<
" Arnoldi update, try increasing the number of"
579 <<
" Arnoldi vectors.");
584template <
typename VectorType>
589 (workl.size() + workd.size() + v.size() + resid.size() + z.size() +
591 src.memory_consumption() + dst.memory_consumption() +
592 tmp.memory_consumption() +
594 local_indices.size();
599template <
typename VectorType>
601 const unsigned int number_of_arnoldi_vectors,
603 const bool symmetric,
605 : number_of_arnoldi_vectors(number_of_arnoldi_vectors)
606 , eigenvalue_of_interest(eigenvalue_of_interest)
607 , symmetric(symmetric)
616 "'largest real part' can only be used for non-symmetric problems!"));
620 "'smallest real part' can only be used for non-symmetric problems!"));
624 "'largest imaginary part' can only be used for non-symmetric problems!"));
628 "'smallest imaginary part' can only be used for non-symmetric problems!"));
631 ExcMessage(
"Currently, only modes 1, 2 and 3 are supported."));
636template <
typename VectorType>
657template <
typename VectorType>
661 sigmar = sigma.real();
662 sigmai = sigma.imag();
667template <
typename VectorType>
671 initial_vector_provided =
true;
672 Assert(resid.size() == local_indices.size(),
674 vec.extract_subvector_to(local_indices.begin(),
681template <
typename VectorType>
690 ncv = additional_data.number_of_arnoldi_vectors;
696 v.resize(ldv * ncv, 0.0);
698 resid.resize(nloc, 1.0);
701 workd.resize(3 * nloc, 0.0);
704 additional_data.symmetric ? ncv * ncv + 8 * ncv : 3 * ncv * ncv + 6 * ncv;
705 workl.resize(lworkl, 0.);
708 z.resize(ldz * ncv, 0.);
711 lworkev = additional_data.symmetric ? 0
714 workev.resize(lworkev, 0.);
716 select.resize(ncv, 0);
721template <
typename VectorType>
725 internal_reinit(locally_owned_dofs);
728 src.reinit(locally_owned_dofs, mpi_communicator);
729 dst.reinit(locally_owned_dofs, mpi_communicator);
730 tmp.reinit(locally_owned_dofs, mpi_communicator);
735template <
typename VectorType>
739 internal_reinit(distributed_vector.locally_owned_elements());
742 src.reinit(distributed_vector);
743 dst.reinit(distributed_vector);
744 tmp.reinit(distributed_vector);
749template <
typename VectorType>
752 const std::vector<IndexSet> &partitioning)
754 internal_reinit(locally_owned_dofs);
757 src.reinit(partitioning, mpi_communicator);
758 dst.reinit(partitioning, mpi_communicator);
759 tmp.reinit(partitioning, mpi_communicator);
764template <
typename VectorType>
765template <
typename MatrixType1,
typename MatrixType2,
typename INVERSE>
768 const MatrixType2 &B,
769 const INVERSE &inverse,
772 const unsigned int n_eigenvalues)
774 std::vector<VectorType *> eigenvectors_ptr(
eigenvectors.size());
777 solve(A, B, inverse,
eigenvalues, eigenvectors_ptr, n_eigenvalues);
782template <
typename VectorType>
783template <
typename MatrixType1,
typename MatrixType2,
typename INVERSE>
786 const MatrixType2 &mass_matrix,
787 const INVERSE &inverse,
790 const unsigned int n_eigenvalues)
792 if (additional_data.symmetric)
795 PArpackExcInvalidEigenvectorSize(n_eigenvalues,
800 PArpackExcInvalidEigenvectorSizeNonsymmetric(n_eigenvalues,
804 PArpackExcInvalidEigenvalueSize(n_eigenvalues,
eigenvalues.size()));
810 PArpackExcInvalidNumberofEigenvalues(n_eigenvalues,
814 PArpackExcInvalidNumberofArnoldiVectors(
815 additional_data.number_of_arnoldi_vectors,
eigenvectors[0]->size()));
817 Assert(additional_data.number_of_arnoldi_vectors > 2 * n_eigenvalues + 1,
818 PArpackExcSmallNumberofArnoldiVectors(
819 additional_data.number_of_arnoldi_vectors, n_eigenvalues));
821 int mode = additional_data.mode;
830 bmat[0] = (mode == 1) ?
'I' :
'G';
844 switch (additional_data.eigenvalue_of_interest)
846 case algebraically_largest:
847 std::strcpy(which,
"LA");
849 case algebraically_smallest:
850 std::strcpy(which,
"SA");
852 case largest_magnitude:
853 std::strcpy(which,
"LM");
855 case smallest_magnitude:
856 std::strcpy(which,
"SM");
858 case largest_real_part:
859 std::strcpy(which,
"LR");
861 case smallest_real_part:
862 std::strcpy(which,
"SR");
864 case largest_imaginary_part:
865 std::strcpy(which,
"LI");
867 case smallest_imaginary_part:
868 std::strcpy(which,
"SI");
871 std::strcpy(which,
"BE");
876 double tol = control().tolerance();
879 std::vector<int> iparam(11, 0);
886 iparam[2] = control().max_steps();
899 std::vector<int> ipntr(14, 0);
907 int info = initial_vector_provided ? 1 : 0;
910 int nev = n_eigenvalues;
911 int n_inside_arpack = nloc;
917 if (additional_data.symmetric)
954 AssertThrow(info == 0, PArpackExcInfoPdnaupd(info));
962 const int shift_x = ipntr[0] - 1;
963 const int shift_y = ipntr[1] - 1;
965 Assert(shift_x + nloc <=
static_cast<int>(workd.size()),
968 Assert(shift_y + nloc <=
static_cast<int>(workd.size()),
974 if ((ido == -1) || (ido == 1 && mode < 3))
977 src.add(nloc, local_indices.data(), workd.data() + shift_x);
983 mass_matrix.vmult(tmp, src);
984 inverse.vmult(dst, tmp);
989 system_matrix.vmult(tmp, src);
991 tmp.extract_subvector_to(local_indices.begin(),
993 workd.data() + shift_x);
994 inverse.vmult(dst, tmp);
998 system_matrix.vmult(dst, src);
1003 else if (ido == 1 && mode >= 3)
1007 const int shift_b_x = ipntr[2] - 1;
1009 Assert(shift_b_x + nloc <=
static_cast<int>(workd.size()),
1013 src.add(nloc, local_indices.data(), workd.data() + shift_b_x);
1018 inverse.vmult(dst, src);
1023 src.add(nloc, local_indices.data(), workd.data() + shift_x);
1034 mass_matrix.vmult(dst, src);
1043 dst.extract_subvector_to(local_indices.begin(),
1044 local_indices.end(),
1045 workd.data() + shift_y);
1053 char howmany[4] =
"All";
1055 std::vector<double> eigenvalues_real(n_eigenvalues + 1, 0.);
1056 std::vector<double> eigenvalues_im(n_eigenvalues + 1, 0.);
1059 if (additional_data.symmetric)
1060 pdseupd_(&mpi_communicator_fortran,
1064 eigenvalues_real.data(),
1084 pdneupd_(&mpi_communicator_fortran,
1088 eigenvalues_real.data(),
1089 eigenvalues_im.data(),
1113 AssertThrow(
false, PArpackExcInfoMaxIt(control().max_steps()));
1124 for (
int i = 0; i < nev; ++i)
1129 eigenvectors[i]->add(nloc, local_indices.data(), &v[i * nloc]);
1133 for (
size_type i = 0; i < n_eigenvalues; ++i)
1135 std::complex<double>(eigenvalues_real[i], eigenvalues_im[i]);
1138 AssertThrow(iparam[4] >=
static_cast<int>(n_eigenvalues),
1139 PArpackExcConvergedEigenvectors(n_eigenvalues, iparam[4]));
1147 tmp.add(nloc, local_indices.data(), resid.data());
1149 solver_control.check(iparam[2], tmp.l2_norm());
1155template <
typename VectorType>
1159 return solver_control;
size_type n_elements() const
std::vector< size_type > get_index_vector() const
void set_initial_vector(const VectorType &vec)
SolverControl & solver_control
MPI_Comm mpi_communicator
SolverControl & control() const
@ smallest_imaginary_part
void solve(const MatrixType1 &A, const MatrixType2 &B, const INVERSE &inverse, std::vector< std::complex< double > > &eigenvalues, std::vector< VectorType > &eigenvectors, const unsigned int n_eigenvalues)
PArpackSolver(SolverControl &control, const MPI_Comm mpi_communicator, const AdditionalData &data=AdditionalData())
std::vector< types::global_dof_index > local_indices
std::vector< double > workl
std::vector< int > select
std::size_t memory_consumption() const
MPI_Fint mpi_communicator_fortran
void set_shift(const std::complex< double > sigma)
void reinit(const IndexSet &locally_owned_dofs)
std::vector< double > workd
const AdditionalData additional_data
bool initial_vector_provided
void internal_reinit(const IndexSet &locally_owned_dofs)
std::vector< double > resid
std::vector< double > workev
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & PArpackExcInvalidNumberofEigenvalues(int arg1, int arg2)
static ::ExceptionBase & PArpackExcInvalidEigenvalueSize(int arg1, int arg2)
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & PArpackExcNoShifts(int arg1)
static ::ExceptionBase & PArpackExcInvalidEigenvectorSize(int arg1, int arg2)
static ::ExceptionBase & PArpackExcSmallNumberofArnoldiVectors(int arg1, int arg2)
#define Assert(cond, exc)
#define DeclException2(Exception2, type1, type2, outsequence)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & PArpackExcInfoPdneupd(int arg1)
#define AssertIndexRange(index, range)
static ::ExceptionBase & PArpackExcIdo(int arg1)
static ::ExceptionBase & PArpackExcConvergedEigenvectors(int arg1, int arg2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & PArpackExcInfoMaxIt(int arg1)
static ::ExceptionBase & PArpackExcMode(int arg1)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & PArpackExcInfoPdnaupd(int arg1)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & PArpackExcInvalidEigenvectorSizeNonsymmetric(int arg1, int arg2)
static ::ExceptionBase & PArpackExcInvalidNumberofArnoldiVectors(int arg1, int arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
std::vector< index_type > data
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
unsigned int global_dof_index
void pdneupd_(MPI_Fint *comm, int *rvec, char *howmany, int *select, double *d, double *di, double *z, int *ldz, double *sigmar, double *sigmai, double *workev, char *bmat, int *n, char *which, int *nev, double *tol, double *resid, int *ncv, double *v, int *nloc, int *iparam, int *ipntr, double *workd, double *workl, int *lworkl, int *info)
void pdsaupd_(MPI_Fint *comm, int *ido, char *bmat, int *n, char *which, int *nev, double *tol, double *resid, int *ncv, double *v, int *nloc, int *iparam, int *ipntr, double *workd, double *workl, int *lworkl, int *info)
void pdnaupd_(MPI_Fint *comm, int *ido, char *bmat, int *n, char *which, int *nev, double *tol, double *resid, int *ncv, double *v, int *nloc, int *iparam, int *ipntr, double *workd, double *workl, int *lworkl, int *info)
void pdseupd_(MPI_Fint *comm, int *rvec, char *howmany, int *select, double *d, double *z, int *ldz, double *sigmar, char *bmat, int *n, char *which, int *nev, double *tol, double *resid, int *ncv, double *v, int *nloc, int *iparam, int *ipntr, double *workd, double *workl, int *lworkl, int *info)
AdditionalData(const unsigned int number_of_arnoldi_vectors=15, const WhichEigenvalues eigenvalue_of_interest=largest_magnitude, const bool symmetric=false, const int mode=3)
const unsigned int number_of_arnoldi_vectors
const WhichEigenvalues eigenvalue_of_interest
std::array< Number, 1 > eigenvalues(const SymmetricTensor< 2, 1, Number > &T)
std::array< std::pair< Number, Tensor< 1, dim, Number > >, dim > eigenvectors(const SymmetricTensor< 2, dim, Number > &T, const SymmetricTensorEigenvectorMethod method=SymmetricTensorEigenvectorMethod::ql_implicit_shifts)