GQCP
Loading...
Searching...
No Matches
SubspaceMatrixDiagonalization.hpp
Go to the documentation of this file.
1// This file is part of GQCG-GQCP.
2//
3// Copyright (C) 2017-2020 the GQCG developers
4//
5// GQCG-GQCP is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// GQCG-GQCP is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with GQCG-GQCP. If not, see <http://www.gnu.org/licenses/>.
17
18#pragma once
19
20
24
25#include <type_traits>
26
27
28namespace GQCP {
29
30
35 public Step<EigenproblemEnvironment<double>> {
36
37private:
38 size_t number_of_requested_eigenpairs;
39
40
41public:
42 /*
43 * CONSTRUCTORS
44 */
45
49 SubspaceMatrixDiagonalization(const size_t number_of_requested_eigenpairs = 1) :
50 number_of_requested_eigenpairs {number_of_requested_eigenpairs} {}
51
52
53 /*
54 * PUBLIC OVERRIDDEN METHODS
55 */
56
60 std::string description() const override {
61 return "Diagonalize the subspace matrix, i.e. the projection of the matrix A onto the subspace spanned by the vectors in V, and write its eigenvalues and eigenvectors to the environment.";
62 }
63
64
70 void execute(EigenproblemEnvironment<double>& environment) override {
71
72 // Diagonalize the subspace matrix and find the r (this->number_of_requested_eigenpairs) lowest eigenpairs
73 // Lambda contains the requested number of eigenvalues, Z contains the corresponding eigenvectors
74 // Z is a (subspace_dimension x number_of_requested_eigenpairs)- matrix
75
76 // Use our own dense diagonalization algorithm to find the number of requested eigenpairs
77 const auto& S = environment.S;
78 auto dense_environment = EigenproblemEnvironment<double>::Dense(S);
79 auto dense_diagonalizer = EigenproblemSolver::Dense<double>();
80 dense_diagonalizer.perform(dense_environment);
81
82
83 environment.Lambda = dense_environment.eigenvalues.head(this->number_of_requested_eigenpairs); // the (requested number of) eigenvalues of the subspace matrix S
84 environment.eigenvalues = environment.Lambda;
85
86 environment.Z = dense_environment.eigenvectors.topLeftCorner(S.cols(), this->number_of_requested_eigenpairs); // the (requested number of) eigenvectors of the subspace matrix S
87 }
88};
89
90
91} // namespace GQCP
Definition: EigenproblemEnvironment.hpp:35
VectorX< double > eigenvalues
Definition: EigenproblemEnvironment.hpp:57
MatrixX< Scalar > Z
Definition: EigenproblemEnvironment.hpp:69
VectorX< double > Lambda
Definition: EigenproblemEnvironment.hpp:66
SquareMatrix< Scalar > S
Definition: EigenproblemEnvironment.hpp:63
static EigenproblemEnvironment Dense(const SquareMatrix< Scalar > &A)
Definition: EigenproblemEnvironment.hpp:121
Definition: Step.hpp:37
Definition: SubspaceMatrixDiagonalization.hpp:35
void execute(EigenproblemEnvironment< double > &environment) override
Definition: SubspaceMatrixDiagonalization.hpp:70
std::string description() const override
Definition: SubspaceMatrixDiagonalization.hpp:60
SubspaceMatrixDiagonalization(const size_t number_of_requested_eigenpairs=1)
Definition: SubspaceMatrixDiagonalization.hpp:49
Definition: BaseOneElectronIntegralBuffer.hpp:25