GQCP
Loading...
Searching...
No Matches
CorrectionVectorCalculation.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
23
24
25namespace GQCP {
26
27
32 public Step<EigenproblemEnvironment<double>> {
33
34private:
35 size_t number_of_requested_eigenpairs;
36 double correction_threshold;
37
38
39public:
40 /*
41 * CONSTRUCTORS
42 */
43
48 CorrectionVectorCalculation(const size_t number_of_requested_eigenpairs = 1, const double correction_threshold = 1.0e-12) :
49 number_of_requested_eigenpairs {number_of_requested_eigenpairs},
50 correction_threshold {correction_threshold} {}
51
52
53 /*
54 * PUBLIC OVERRIDDEN METHODS
55 */
56
60 std::string description() const override {
61 return "Calculate the correction vectors by solving the residual equations.";
62 }
63
64
70 void execute(EigenproblemEnvironment<double>& environment) override {
71
72 const auto dim = environment.dimension;
73
74 const auto& diagonal = environment.diagonal; // the diagonal of the matrix
75 const auto& Lambda = environment.Lambda; // the (requested number of) eigenvalues of the subspace matrix S
76
77 const auto& VA = environment.VA; // VA = A * V (implicitly calculated through the matrix-vector product)
78 const auto& Z = environment.Z; // the (requested number of) eigenvectors of the subspace matrix S
79 const auto& X = environment.X; // contains the new guesses for the eigenvectors (as a linear combination of the current subspace V)
80 const auto& R = environment.R; // the residual vectors
81
82 // Solve the residual equations to find the correction vectors.
83 // The implementation of these equations is adapted from Klaas Gunst's DOCI code (https://github.com/klgunst/doci)
84 environment.Delta = MatrixX<double>::Zero(dim, this->number_of_requested_eigenpairs);
85 for (size_t column_index = 0; column_index < this->number_of_requested_eigenpairs; column_index++) {
86
87 VectorX<double> denominator = diagonal - VectorX<double>::Constant(dim, Lambda(column_index));
88
89 // If the denominator is large enough, the correction vector is the residual vector dividided by the denominator.
90 // If it isn't, the correction vector is the residual vector divided by the threshold.
91 // clang-format off
92 environment.Delta.col(column_index) = (denominator.array().abs() > this->correction_threshold).select(
93 R.col(column_index).array() / denominator.array().abs(),
94 R.col(column_index) / this->correction_threshold
95 );
96 // clang-format on
97 environment.Delta.col(column_index).normalize();
98 }
99 }
100};
101
102
103} // namespace GQCP
Definition: CorrectionVectorCalculation.hpp:32
std::string description() const override
Definition: CorrectionVectorCalculation.hpp:60
CorrectionVectorCalculation(const size_t number_of_requested_eigenpairs=1, const double correction_threshold=1.0e-12)
Definition: CorrectionVectorCalculation.hpp:48
void execute(EigenproblemEnvironment< double > &environment) override
Definition: CorrectionVectorCalculation.hpp:70
Definition: EigenproblemEnvironment.hpp:35
MatrixX< Scalar > X
Definition: EigenproblemEnvironment.hpp:79
VectorX< Scalar > diagonal
Definition: EigenproblemEnvironment.hpp:50
MatrixX< Scalar > Delta
Definition: EigenproblemEnvironment.hpp:86
size_t dimension
Definition: EigenproblemEnvironment.hpp:53
MatrixX< Scalar > Z
Definition: EigenproblemEnvironment.hpp:69
VectorX< double > Lambda
Definition: EigenproblemEnvironment.hpp:66
MatrixX< Scalar > VA
Definition: EigenproblemEnvironment.hpp:76
MatrixX< Scalar > R
Definition: EigenproblemEnvironment.hpp:83
Definition: Matrix.hpp:47
Definition: Step.hpp:37
Definition: BaseOneElectronIntegralBuffer.hpp:25