Spectra
GenEigsRealShiftSolver.h
1 // Copyright (C) 2016-2018 Yixuan Qiu <yixuan.qiu@cos.name>
2 //
3 // This Source Code Form is subject to the terms of the Mozilla
4 // Public License v. 2.0. If a copy of the MPL was not distributed
5 // with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
6 
7 #ifndef GEN_EIGS_REAL_SHIFT_SOLVER_H
8 #define GEN_EIGS_REAL_SHIFT_SOLVER_H
9 
10 #include "GenEigsSolver.h"
11 #include "MatOp/DenseGenRealShiftSolve.h"
12 
13 namespace Spectra {
14 
15 
36 template <typename Scalar = double,
37  int SelectionRule = LARGEST_MAGN,
38  typename OpType = DenseGenRealShiftSolve<double> >
39 class GenEigsRealShiftSolver: public GenEigsSolver<Scalar, SelectionRule, OpType>
40 {
41 private:
42  typedef std::complex<Scalar> Complex;
43  typedef Eigen::Array<Complex, Eigen::Dynamic, 1> ComplexArray;
44 
45  const Scalar m_sigma;
46 
47  // First transform back the ritz values, and then sort
48  void sort_ritzpair(int sort_rule)
49  {
50  // The eigenvalus we get from the iteration is nu = 1 / (lambda - sigma)
51  // So the eigenvalues of the original problem is lambda = 1 / nu + sigma
52  ComplexArray ritz_val_org = Scalar(1.0) / this->m_ritz_val.head(this->m_nev).array() + m_sigma;
53  this->m_ritz_val.head(this->m_nev) = ritz_val_org;
55  }
56 public:
75  GenEigsRealShiftSolver(OpType* op, int nev, int ncv, Scalar sigma) :
76  GenEigsSolver<Scalar, SelectionRule, OpType>(op, nev, ncv),
77  m_sigma(sigma)
78  {
79  this->m_op->set_shift(m_sigma);
80  }
81 };
82 
83 
84 } // namespace Spectra
85 
86 #endif // GEN_EIGS_REAL_SHIFT_SOLVER_H
GenEigsRealShiftSolver(OpType *op, int nev, int ncv, Scalar sigma)