Spectra  1.0.1 Header-only C++ Library for Large Scale Eigenvalue Problems
GenEigsRealShiftSolver.h
1 // Copyright (C) 2016-2022 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 SPECTRA_GEN_EIGS_REAL_SHIFT_SOLVER_H
8 #define SPECTRA_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
32 template <typename OpType = DenseGenRealShiftSolve<double>>
33 class GenEigsRealShiftSolver : public GenEigsBase<OpType, IdentityBOp>
34 {
35 private:
36  using Scalar = typename OpType::Scalar;
37  using Index = Eigen::Index;
38  using Complex = std::complex<Scalar>;
39  using ComplexArray = Eigen::Array<Complex, Eigen::Dynamic, 1>;
40
42  using Base::m_nev;
43  using Base::m_ritz_val;
44
45  const Scalar m_sigma;
46
47  // First transform back the Ritz values, and then sort
48  void sort_ritzpair(SortRule sort_rule) override
49  {
50  // The eigenvalues we get from the iteration is nu = 1 / (lambda - sigma)
51  // So the eigenvalues of the original problem is lambda = 1 / nu + sigma
53  Base::sort_ritzpair(sort_rule);
54  }
55
56 public:
75  GenEigsRealShiftSolver(OpType& op, Index nev, Index ncv, const Scalar& sigma) :
76  Base(op, IdentityBOp(), nev, ncv),
77  m_sigma(sigma)
78  {
79  op.set_shift(m_sigma);
80  }
81 };
82
83 } // namespace Spectra
84
85 #endif // SPECTRA_GEN_EIGS_REAL_SHIFT_SOLVER_H
GenEigsRealShiftSolver(OpType &op, Index nev, Index ncv, const Scalar &sigma)