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 <Eigen/Core>
11 
12 #include "GenEigsBase.h"
13 #include "Util/SelectionRule.h"
14 #include "MatOp/DenseGenRealShiftSolve.h"
15 
16 namespace Spectra {
17 
18 
39 template <typename Scalar = double,
40  int SelectionRule = LARGEST_MAGN,
41  typename OpType = DenseGenRealShiftSolve<double> >
42 class GenEigsRealShiftSolver: public GenEigsBase<Scalar, SelectionRule, OpType, IdentityBOp>
43 {
44 private:
45  typedef std::complex<Scalar> Complex;
46  typedef Eigen::Array<Complex, Eigen::Dynamic, 1> ComplexArray;
47 
48  const Scalar m_sigma;
49 
50  // First transform back the Ritz values, and then sort
51  void sort_ritzpair(int sort_rule)
52  {
53  // The eigenvalues we get from the iteration is nu = 1 / (lambda - sigma)
54  // So the eigenvalues of the original problem is lambda = 1 / nu + sigma
55  ComplexArray ritz_val_org = Scalar(1.0) / this->m_ritz_val.head(this->m_nev).array() + m_sigma;
56  this->m_ritz_val.head(this->m_nev) = ritz_val_org;
58  }
59 public:
78  GenEigsRealShiftSolver(OpType* op, int nev, int ncv, Scalar sigma) :
79  GenEigsBase<Scalar, SelectionRule, OpType, IdentityBOp>(op, NULL, nev, ncv),
80  m_sigma(sigma)
81  {
82  this->m_op->set_shift(m_sigma);
83  }
84 };
85 
86 
87 } // namespace Spectra
88 
89 #endif // GEN_EIGS_REAL_SHIFT_SOLVER_H
GenEigsRealShiftSolver(OpType *op, int nev, int ncv, Scalar sigma)