1 #ifndef SELDON_FILE_VIRTUAL_EIGENVALUE_SOLVER_HXX
3 #ifdef SELDON_WITH_SLEPC
6 #if defined(PETSC_USE_COMPLEX)
7 #define Petsc_Scalar complex<double>
9 #define Petsc_Scalar double
12 #define Petsc_Error_Code int
30 enum {SOLVER_LOBPCG, SOLVER_BKS, SOLVER_BD};
33 enum {ORTHO_DGKS, ORTHO_SVQB};
73 int nstep_inner, nstep_outer;
75 int moment_size, block_max_size, npart;
76 double delta_rank, delta_spur;
80 int krylov_restart, restart_number, restart_add;
81 int nb_conv_vector, nb_conv_vector_proj;
82 bool non_locking_variant;
88 enum {SHIFT_CONSTANT, SHIFT_RAYLEIGH, SHIFT_WILKINSON};
90 enum {QUADRULE_TRAPEZE, QUADRULE_CHEBY};
92 enum {EXTRACT_RITZ, EXTRACT_HANKEL};
94 enum {POWER, SUBSPACE, ARNOLDI, LANCZOS, KRYLOVSCHUR, GD, JD,
95 RQCG, LOBPCG, CISS, LAPACK, ARPACK, BLZPACK, TRLAN, BLOPEX, PRIMME, FEAST};
99 const char* GetEigensolverChar()
const;
100 int GetEigensolverType()
const;
101 void SetEigensolverType(
int type);
103 void SetBlockSize(
int n);
104 int GetBlockSize()
const;
105 void SetMaximumBlockSize(
int n);
106 int GetMaximumBlockSize()
const;
108 void SetNumberOfSteps(
int n);
109 int GetNumberOfSteps()
const;
111 void SetExtractionType(
int);
112 int GetExtractionType()
const;
114 void SetQuadratureRuleType(
int);
115 int GetQuadratureRuleType()
const;
117 void SetInnerSteps(
int);
118 void SetOuterSteps(
int);
119 int GetInnerSteps()
const;
120 int GetOuterSteps()
const;
122 int GetNumberIntegrationPoints()
const;
123 void SetNumberIntegrationPoints(
int);
124 int GetMomentSize()
const;
125 void SetMomentSize(
int);
126 int GetNumberPartitions()
const;
127 void SetNumberPartitions(
int);
129 void SetThresholdRank(
double);
130 double GetThresholdRank()
const;
131 void SetThresholdSpurious(
double);
132 double GetThresholdSpurious()
const;
134 int GetBorthogonalization()
const;
135 void SetBorthogonalization(
int);
136 int GetDoubleExpansion()
const;
137 void SetDoubleExpansion(
int);
138 int GetInitialSize()
const;
139 void SetInitialSize(
int);
140 int GetKrylovRestart()
const;
141 void SetKrylovRestart(
int);
142 int GetRestartNumber()
const;
143 void SetRestartNumber(
int);
144 int GetRestartNumberAdd()
const;
145 void SetRestartNumberAdd(
int);
147 int GetNumberConvergedVectors()
const;
148 void SetNumberConvergedVectors(
int);
149 int GetNumberConvergedVectorsProjected()
const;
150 void SetNumberConvergedVectorsProjected(
int);
152 bool UseNonLockingVariant()
const;
153 void SetNonLockingVariant(
bool n);
154 double GetRestartRatio()
const;
155 void SetRestartRatio(
double d);
156 string GetMethod()
const;
157 void SetMethod(
string s);
158 int GetShiftType()
const;
159 void SetShiftType(
int n);
189 void EnableEstimateNumberEigenval(
bool p =
true);
190 bool EstimateNumberEigenval()
const;
192 int GetNumOfQuadraturePoints()
const;
193 void SetNumOfQuadraturePoints(
int);
195 int GetTypeIntegration()
const;
196 void SetTypeIntegration(
int);
198 double GetCircleRadiusSpectrum()
const;
199 complex<double> GetCircleCenterSpectrum()
const;
200 double GetRatioEllipseSpectrum()
const;
201 double GetAngleEllipseSpectrum()
const;
209 double ratio,
double teta);
213 template<
class T0,
class T1>
214 void to_complex_eigen(
const T0& x, T1& y);
216 template<
class T0,
class T1>
217 void to_complex_eigen(
const complex<T0>& x, T1& y);
219 template<
class T0,
class T1>
220 void to_complex_eigen(
const T0& x, complex<T1>& y);
222 template<
class T0,
class T1>
223 void to_complex_eigen(
const complex<T0>& x, complex<T1>& y);
231 virtual int CompareEigenvalue(
const T& Lr,
const T& Li,
const T& Lr2,
const T& Li2) = 0;
245 enum {SMALL_EIGENVALUES, LARGE_EIGENVALUES, CENTERED_EIGENVALUES};
248 enum {SORTED_REAL, SORTED_IMAG, SORTED_MODULUS, SORTED_USER};
282 #ifdef SELDON_WITH_MPI
291 MPI_Comm comm_global;
292 bool global_comm_set;
299 #ifdef SELDON_WITH_MPI
300 void SetCommunicator(
const MPI_Comm& comm_);
301 MPI_Comm& GetCommunicator();
302 MPI_Comm& GetRciCommunicator();
304 void SetGlobalCommunicator(
const MPI_Comm& comm_);
305 MPI_Comm& GetGlobalCommunicator();
341 virtual bool IsSymmetricProblem()
const;
342 virtual bool IsHermitianProblem()
const;
359 typedef typename ClassComplexType<T>::Tcplx Tcplx;
360 typedef typename ClassComplexType<T>::Treal Treal;
372 int type_sort = SORTED_MODULUS);
375 int type_sort = SORTED_MODULUS);
379 #ifdef SELDON_WITH_SLEPC
381 static Petsc_Error_Code
382 GetComparisonEigenvalueSlepcGen(Petsc_Scalar, Petsc_Scalar, Petsc_Scalar, Petsc_Scalar, T0,
385 static Petsc_Error_Code
386 GetComparisonEigenvalueSlepcGen(Petsc_Scalar, Petsc_Scalar, Petsc_Scalar, Petsc_Scalar, Petsc_Scalar,
389 static Petsc_Error_Code
390 GetComparisonEigenvalueSlepc(Petsc_Scalar, Petsc_Scalar, Petsc_Scalar, Petsc_Scalar,
394 void FillComplexEigenvectors(
int m,
const Tcplx& Emid, Treal eps,
403 #ifdef SELDON_WITH_MPI
441 enum {REGULAR_MODE, SHIFTED_MODE, IMAG_SHIFTED_MODE, INVERT_MODE,
442 BUCKLING_MODE, CAYLEY_MODE};
445 enum { REAL_PART, IMAG_PART, COMPLEX_PART};
448 typedef typename ClassComplexType<T>::Tcplx Tcplx;
449 typedef typename ClassComplexType<T>::Treal Treal;
513 virtual void GetSqrtDiagonal(
Vector<T>&) = 0;
547 int real_p = COMPLEX_PART);
550 int real_p = COMPLEX_PART);
569 virtual void Clear();
574 template<
class T0,
class Prop,
class Storage>
579 const T0& shiftr,
const T0& shifti);
581 template<
class T0,
class Prop,
class Storage>
583 Vector<complex<T0> >& eigen_values,
584 Vector<complex<T0> >& lambda_imag,
585 Matrix<complex<T0>, Prop, Storage>& eigen_vectors,
586 const complex<T0>& shiftr,
587 const complex<T0>& shifti);
593 template<
class T,
class StiffValue = T,
594 class MassValue =
typename ClassComplexType<T>::Treal>
607 typedef typename ClassComplexType<T>::Tcplx Tcplx;
608 typedef typename ClassComplexType<T>::Treal Treal;
645 void MltStiffness(
const T& coef_mass,
const T& coef_stiff,
648 void MltStiffness(
const T& coef_mass,
const T& coef_stiff,
660 template<
class T,
class Storage1,
class Storage2>
664 int type_spectrum,
int type_sort,
665 const T& shift_r,
const T& shift_i);
668 template<
class T,
class Storage1,
class Storage2>
670 Vector<complex<T> >& lambda_i,
673 int type_spectrum,
int type_sort,
674 const complex<T>& shift_r,
const complex<T>& shift_i);
678 template<
class T,
class Tstiff,
class Prop,
class Storage,
679 class Tmass =
typename ClassComplexType<T>::Treal,
684 typedef typename ClassComplexType<T>::Tcplx Tcplx;
685 typedef typename ClassComplexType<T>::Treal Treal;
731 void MltStiffness(
const T& coef_mass,
const T& coef_stiff,
734 void MltStiffness(
const T& coef_mass,
const T& coef_stiff,
741 const Treal& b,
int which);
744 const Treal& b,
int which);
769 template<
class T,
class MatStiff,
774 typename MatMass::entry_type>
777 typedef typename ClassComplexType<T>::Tcplx Tcplx;
778 typedef typename ClassComplexType<T>::Treal Treal;
780 #ifdef SELDON_WITH_MPI
806 bool distributed;
int nloc;
810 int nodl_scalar_, nb_unknowns_scal_;
812 int RetrieveLocalNumbers(MatStiff& K);
820 void InitMatrix(MatStiff&);
821 void InitMatrix(MatStiff&, MatMass&);
826 template<
class Storage>
829 template<
class T0,
class Prop,
class Storage>
832 #ifdef SELDON_WITH_MPI
833 template<
class Storage>
836 template<
class T0,
class Prop,
class Storage>
853 void MltStiffness(
const T& coef_mass,
const T& coef_stiff,
856 void MltStiffness(
const T& coef_mass,
const T& coef_stiff,
863 const Treal& b,
int which);
866 const Treal& b,
int which);
896 enum {DEFAULT, ARPACK, ANASAZI, FEAST, SLEPC};
904 template<
class T,
class Prop,
class Storage>
905 void GetEigenvaluesEigenvectors(EigenProblem_Base<T>& var_eig,
906 Vector<T>& lambda, Vector<T>& lambda_imag,
907 Matrix<T, Prop, Storage>& eigen_vec,
908 int type_solver = TypeEigenvalueSolver::DEFAULT);
912 #define SELDON_FILE_VIRTUAL_EIGENVALUE_SOLVER_HXX
int GetM() const
returns number of rows
int GetNbArnoldiVectors() const
returns the number of Arnoldi vectors to use
void PrintErrorInit() const
prints error of initialization and aborts program
void SetTypeSpectrum(int type, const T &val, int type_sort=EigenProblem_Base< T >::SORTED_MODULUS)
sets which eigenvalues are searched
int nb_blocks
number of blocks for blocked solvers
computation of a few eigenvalues for dense matrices
Matrix< Treal, Prop, Storage > mat_lu_real
LU factorisation of a real matrix.
void SetEigensolverType(int type)
sets the solver used in Anasazi
SparseDirectSolver< Treal > mat_lu_real
LU factorisation of sparse matrix.
void MltInvSqrtDiagonalMass(Vector< Treal > &X)
multiplication of X by D^-1/2
void MltStiffness(const Vector< Treal > &X, Vector< Treal > &Y)
multiplication by stiffness matrix
void MltCholeskyMass(const TransStatus &transA, Vector< T0 > &X)
computation of L X or L^T X
Vector< MassValue > sqrt_diagonal_mass
diagonal D^1/2 if the mass matrix is diagonal positive
GeneralEigenProblem_Base()
default constructor
list of availables eigenvalue solvers
SparseCholeskySolver< Treal > chol_facto_mass_matrix
Cholesky factorisation of mass matrix if required.
SparseCholeskySolver< double > chol_facto_mass_matrix
Cholesky factorisation of mass matrix if required.
int type_solver
which solver ?
T shift
shift sigma (if type_spectrum = centered_eigenvalues)
computation of a few eigenvalues for sparse matrices
double ratio_ellipse
parameters for an ellipse
EigenProblem_Base()
default constructor
void SetUserComparisonClass(EigenvalueComparisonClass< T > *ev)
sets the class where two eigenvalues can be compared
SparseDirectSolver< Complexe > mat_lu_cplx
factorisation of complex system
void MltStiffness(const Vector< Treal > &X, Vector< Treal > &Y)
matrix vector product with stifness matrix Y = K X
void GetComplexShift(const Treal &, const Treal &, Tcplx &) const
forms the complex shift from real and imaginary part
int eigenvalue_computation_mode
mode used to find eigenvalues (regular, shifted, Cayley, etc)
bool IsHermitianProblem() const
returns true if the matrix is hermitian
int restart_number
restart parameter for blocked solvers
void MltMass(const Vector< Treal > &X, Vector< Treal > &Y)
matrix-vector product Y = M X where M is the mass matrix
void FactorizeCholeskyMass()
computes Cholesky factorisation of M from matrix M
int type_sort_eigenvalues
large eigenvalues because of their real part, imaginary part or magnitude ?
void ComputeSolution(const Vector< T0 > &X, Vector< T0 > &Y)
solution of (a M + b K) Y = X
Parameters for Slepc package.
void SetCircleSpectrum(const complex< double > &z, double r)
sets a circle where eigenvalues are searched
int GetTypeSpectrum() const
returns the spectrum desired (large, small eigenvalues, etc)
Vector< Treal > Xchol_real
temporary vectors for Cholesky
void ComputeAndFactorizeStiffnessMatrix(const T &a, const T &b)
computation of matrix a M + b K and factorisation of this matrix
general class for direct solver
int GetNbLinearSolves() const
returns the number of linear solves
Matrix< Treal, PropM, StorageM > mat_chol
Cholesky factorisation of mass matrix.
void Clear()
clears memory used by the object
int GetComputationalMode() const
returns the spectral transformation used for evaluation of eigenvalues
EigenvalueComparisonClass< T > * compar_eigenval
class for comparing eigenvalues
void SortEigenvalues(Vector< T > &lambda_r, Vector< T > &lambda_i, Matrix< T, General, Storage1, Alloc1 > &eigen_old, Matrix< T, General, Storage2, Alloc2 > &eigen_new, int type_spectrum, int type_sort, const T &shift_r, const T &shift_i)
sorting eigenvalues
void Clear()
clearing variables used for eigenvalue resolution
VirtualMatrix< MassValue > * Mh
mass matrix
void MltStiffness(const Vector< T > &X, Vector< T > &Y)
matrix vector product with stifness matrix Y = K X
void ComputeStiffnessMatrix()
computation of stiffness matrix K
int nb_points_quadrature
number of points in the contour
int GetNbMaximumRestarts() const
returns the restart parameter used in blocked solvers
void ComputeDiagonalMass()
computation of diagonal of mass matrix
void ComputeMassMatrix()
computation of mass matrix M
int nb_prod
number of matrix-vector products
bool diagonal_mass
if true, the generalized problem is reduced to a standard problem
SparseEigenProblem()
default constructor
int nb_linear_solves
number of linear solves
int GetNbMaximumIterations() const
returns the maximal number of iterations allowed for the iterative algorithm
void MltCholeskyMass(const TransStatus &transA, Vector< T0 > &X)
computes L X or L^T x if M = L L^T
Matrix< Tmass, PropM, StorageM > * Mh
mass matrix
void SetImagShiftValue(const T &)
Sets the imaginary part of shift value.
void SetPrintLevel(int lvl)
sets the level of verbosity
void ComputeSolution(const Vector< T0 > &X, Vector< T0 > &Y)
solves (a M + b K) Y = X with stored factorization
Matrix< Tstiff, Prop, Storage > * Kh
stiffness matrix
SlepcParam & GetSlepcParameters()
returns parameters specific to Slepc
bool evaluate_number_eigenval
if true, we want to estimate the number of eigenvalues
T GetShiftValue() const
returns the shift value used
void SetTypeSpectrum(int type, const T &val, int type_sort=SORTED_MODULUS)
sets which eigenvalues are searched
double GetLowerBoundInterval() const
returns lower bound of the interval where eigenvalues are searched
void GetSqrtDiagonal(Vector< T > &)
fills D^1/2
static int GetDefaultSolver()
returns the default eigenvalue solver (linear eigenproblem)
void MltInvSqrtDiagonalMass(Vector< T0 > &X)
multiplication of X by D^-1/2
Vector< Treal > Xchol_real
temporary vectors for Cholesky
void ComputeSolution(const Vector< T0 > &X, Vector< T0 > &Y)
solving the linear system (a M + b K) Y = X
void SetNbAdditionalEigenvalues(int n)
sets the number of additional eigenvalues
int GetNbBlocks() const
returns the number of blocks used in blocked solvers
SparseDirectSolver< Tcplx > mat_lu_cplx
factorisation of complex system
void SolveCholeskyMass(const TransStatus &transA, Vector< T > &X)
computation of L^-1 X or L^-T x if M = L L^T
FeastParam feast_param
additional parameters for Feast
int GetEigensolverType() const
returns the solver used in Anasazi
int GetRankCommunicator() const
returns rank for the solver communicator
Base class to solve a general eigenvalue problem (linear or not)
void Clear()
memory release
bool use_cholesky
if true, the generalized problem is reduced to a standard problem
Matrix< Tcplx, Prop, Storage > mat_lu_cplx
LU factorisation of a complex matrix.
void FactorizeDiagonalMass()
computation of D^1/2 from D
double emin_interval
interval where eigenvalues are searched (real symmetric or hermitian)
void ComputeAndFactorizeStiffnessMatrix(const T &a, const T &b)
computes and factorizes a M + b K where M is the mass matrix and K the stiffness matrix
void IncrementProdMatVect()
increment of the number of matrix vector products
AnasaziParam & GetAnasaziParameters()
returns parameters specific to Anasazi
void MltMass(const Vector< Treal > &X, Vector< Treal > &Y)
multiplication by mass matrix
complex< double > center_spectrum
disk where eigenvalues are searched (non-symmetric)
void Clear()
memory release
base class for setting comparison between eigenvalues
int GetOrthoManager() const
returns orthogonalization manager set in Anasazi
void MltMass(const Vector< T > &X, Vector< T > &Y)
matrix vector product with mass matrix Y = M X
Parameters for Anasazi package.
int type_solver
which solver ?
void SetCholeskyFactoForMass(bool chol=true)
indicates the use of Cholesky factorisation in order to solve a standard eigenvalue problem instead o...
void ComputeDiagonalMass()
computation of diagonal of mass matrix
void IncrementLinearSolves()
increments the number of linear solves
FeastParam()
default constructor
bool DiagonalMass() const
returns true if the mass matrix is diagonal
bool IsSymmetricProblem() const
returns true if the matrix is symmetric
AnasaziParam anasazi_param
additional parameters for Anasazi
static int GetDefaultPolynomialSolver()
returns the default eigenvalue solver (polynomial eigenproblem)
virtual ~GeneralEigenProblem_Base()
destructor
void InitMatrix(Matrix< Tstiff, Prop, Storage > &)
Sets stiffness matrix, eigenproblem is K x = lambda x.
int GetPrintLevel() const
returns level of verbosity
int GetNbAskedEigenvalues() const
returns the number of eigenvalues asked by the user
void MltMass(const Vector< Treal > &X, Vector< Treal > &Y)
matrix vector product with mass matrix Y = M X
void SetIntervalSpectrum(double, double)
sets the interval where eigenvalues are searched
VirtualEigenProblem()
default constructor
DenseEigenProblem()
default constructor
Base class to solve an eigenvalue problem.
void ComputeAndFactoRealMatrix(const Treal &, const Treal &a, const Treal &b, int which)
computes and factorizes a M + b K where M is the mass matrix and K the stiffness matrix
int nb_add_eigenvalues
additional number of eigenvalues
VirtualMatrix< StiffValue > * Kh
stiffness matrix
int type_integration
Method of integration.
void MltSqrtDiagonalMass(Vector< Treal > &X)
multiplication of X by D^1/2
void FactorizeCholeskyMass()
Cholesky factorisation of mass matrix.
GeneralEigenProblem()
default constructor
static int GetDefaultNonLinearSolver()
returns the default eigenvalue solver (non-linear eigenproblem)
matrix distributed over all the processors
int n_
size of the problem
int GetN() const
returns number of columns
void SetNbBlocks(int)
returns the number of blocks used in blocked solvers
int GetNbAdditionalEigenvalues() const
returns the additional number of eigenvalues
bool UseCholeskyFactoForMass() const
returns true if Cholesky factorisation has to be used for mass matrix
SlepcParam slepc_param
additional parameters for Slepc
Vector< int > pivot
pivot used by the LU factorisation
void SetEllipseSpectrum(const complex< double > &z, double r, double ratio, double teta)
sets an ellipse where eigenvalues are searched
void FactorizeDiagonalMass()
computation of D^1/2 from D
void DistributeEigenvectors(Matrix< T, General, ColMajor > &eigen_vec)
changes final eigenvectors if needed
bool automatic_selection_arnoldi_vectors
if true nb_arnoldi_vectors is automatically computed
void MltStiffness(const Vector< Treal > &X, Vector< Treal > &Y)
matrix-vector product Y = K X where K is the stiffness matrix
void SetDiagonalMass(bool diag=true)
indicates that the mass matrix is diagonal
void SetShiftValue(const T &)
Sets the real part of shift value.
void SetNbMaximumIterations(int n)
sets the maximal number of iterations allowed for the iterative algorithm
int nb_maximum_iterations
Maximal number of iterations.
double GetStoppingCriterion() const
returns the stopping criterion
void ComputeDiagonalMass()
computation of diagonal of mass matrix
base class for eigenvalue problems
friend void ApplyScalingEigenvec(EigenPb &var, Vector1 &eigen_values, Vector1 &lambda_imag, Matrix1 &eigen_vectors, const T0 &shiftr, const T0 &shifti)
modification of eigenvectors to take into account scaling by mass matrix
void SolveCholeskyMass(const TransStatus &transA, Vector< T0 > &X)
computes L^-1 X or L^-T x if M = L L^T
void ComputeAndFactoRealMatrix(const Treal &, const Treal &a, const Treal &b, int which)
computation and factorisation of a M + b K
void SolveCholeskyMass(const TransStatus &transA, Vector< T0 > &X)
computation of L^-1 X or L^-T X
void SetMatrix(VirtualMatrix< StiffValue > &K, VirtualMatrix< MassValue > &M)
sets pointers to the stiffness and mass matrix
AnasaziParam()
default constructor
int nb_eigenvalues_wanted
number of eigenvalues to be computed
SlepcParam()
Default constructor.
void MltCholeskyMass(const TransStatus &transA, Vector< T > &X)
computation of L X or L^T x if M = L L^T
FeastParam & GetFeastParameters()
returns parameters specific to Feast
bool complex_system
if true consider Real( (a M + bK)^-1) or Imag( (a M + b K)^-1 ) or the whole system,...
void Init(int n)
initialisation of the size of the eigenvalue problem
int GetGlobalM() const
returns global number of rows
T GetImagShiftValue() const
returns the imaginary part of shift value used
void ComputeMassForCholesky()
computation of mass matrix
void ComputeAndFactorizeStiffnessMatrix(const T &a, const T &b)
computation and factorisation of a M + b K
int GetNbMatrixVectorProducts() const
returns the number of matrix-vector products performed since last call to Init
int ortho_manager
orthogonalization manager
int nb_arnoldi_vectors
number of Arnoldi vectors
int GetGlobalRankCommunicator() const
returns rank for the global communicator
class for solving a general eigenproblem with parameter T (double or complex)
parameters for Feast package
int type_spectrum_wanted
which spectrum ? Near from Zero ? Near from Infinity ? or near from a value ?
virtual void DistributeEigenvectors(Matrix< T, General, ColMajor > &eigen_vec)
changes final eigenvectors if needed
double GetUpperBoundInterval() const
returns upper bound of the interval where eigenvalues are searched
void SetComputationalMode(int mode)
sets the spectral transformation used for evaluation of eigenvalues
void SetNbAskedEigenvalues(int n)
sets the number of eigenvalues to compute
void SetNbMaximumRestarts(int)
sets the restart parameter used in blocked solvers
void SelectCholeskySolver(int type)
sets Cholesky solver to use
void SetStoppingCriterion(double eps)
modifies the stopping critertion
Abstract base class for all matrices.
void SetNbArnoldiVectors(int n)
sets the number of Arnoldi vectors to use
void MltSqrtDiagonalMass(Vector< T0 > &X)
multiplication of X by D^1/2
void ComputeDiagonalMass()
computation of diagonal of mass matrix
int GetTypeSorting() const
returns how eigenvalues are sorted (real, imaginary part or modulus)
void InitMatrix(VirtualMatrix< StiffValue > &K, int n=-1)
initialization of a standard eigenvalue problem
void FactorizeCholeskyMass()
computation of Cholesky factorisation of M from matrix M
double stopping_criterion
threshold for Arpack's iterative process