Spectra  1.0.1
Header-only C++ Library for Large Scale Eigenvalue Problems
SymGEigsSolver.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_SYM_GEIGS_SOLVER_H
8 #define SPECTRA_SYM_GEIGS_SOLVER_H
9 
10 #include "SymEigsBase.h"
11 #include "Util/GEigsMode.h"
12 #include "MatOp/internal/SymGEigsCholeskyOp.h"
13 #include "MatOp/internal/SymGEigsRegInvOp.h"
14 
15 namespace Spectra {
16 
22 
42 
43 // Empty class template
44 template <typename OpType, typename BOpType, GEigsMode Mode>
46 {};
47 
146 
147 // Partial specialization for mode = GEigsMode::Cholesky
148 template <typename OpType, typename BOpType>
149 class SymGEigsSolver<OpType, BOpType, GEigsMode::Cholesky> :
150  public SymEigsBase<SymGEigsCholeskyOp<OpType, BOpType>, IdentityBOp>
151 {
152 private:
153  using Scalar = typename OpType::Scalar;
154  using Index = Eigen::Index;
155  using Matrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
156  using Vector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
157 
158  using ModeMatOp = SymGEigsCholeskyOp<OpType, BOpType>;
160 
161  const BOpType& m_Bop;
162 
163 public:
188  SymGEigsSolver(OpType& op, BOpType& Bop, Index nev, Index ncv) :
189  Base(ModeMatOp(op, Bop), IdentityBOp(), nev, ncv),
190  m_Bop(Bop)
191  {}
192 
194 
195  Matrix eigenvectors(Index nvec) const override
196  {
197  Matrix res = Base::eigenvectors(nvec);
198  Vector tmp(res.rows());
199  const Index nconv = res.cols();
200  for (Index i = 0; i < nconv; i++)
201  {
202  m_Bop.upper_triangular_solve(&res(0, i), tmp.data());
203  res.col(i).noalias() = tmp;
204  }
205 
206  return res;
207  }
208 
209  Matrix eigenvectors() const override
210  {
212  }
213 
215 };
216 
248 
249 // Partial specialization for mode = GEigsMode::RegularInverse
250 template <typename OpType, typename BOpType>
251 class SymGEigsSolver<OpType, BOpType, GEigsMode::RegularInverse> :
252  public SymEigsBase<SymGEigsRegInvOp<OpType, BOpType>, BOpType>
253 {
254 private:
255  using Index = Eigen::Index;
256 
257  using ModeMatOp = SymGEigsRegInvOp<OpType, BOpType>;
259 
260 public:
283  SymGEigsSolver(OpType& op, BOpType& Bop, Index nev, Index ncv) :
284  Base(ModeMatOp(op, Bop), Bop, nev, ncv)
285  {}
286 };
287 
288 } // namespace Spectra
289 
290 #endif // SPECTRA_SYM_GEIGS_SOLVER_H
SymGEigsSolver(OpType &op, BOpType &Bop, Index nev, Index ncv)
SymGEigsSolver(OpType &op, BOpType &Bop, Index nev, Index ncv)
@ RegularInverse
Regular inverse mode for generalized eigenvalue solver.
@ Cholesky
Using Cholesky decomposition to solve generalized eigenvalues.