GQCP
Loading...
Searching...
No Matches
SubspaceUpdate.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
34
35private:
36 size_t maximum_subspace_dimension;
37 double threshold; // the threshold on the norm used for determining if a new projected correction vector should be added to the subspace
38
39
40public:
41 /*
42 * CONSTRUCTORS
43 */
44
49 SubspaceUpdate(const size_t maximum_subspace_dimension = 15, const double threshold = 1.0e-03) :
50 maximum_subspace_dimension {maximum_subspace_dimension},
51 threshold {threshold} {}
52
53
54 /*
55 * PUBLIC OVERRIDDEN METHODS
56 */
57
61 std::string description() const override {
62 return "Add projected correction vectors to the subspace (if their norm is large enough) and collapse the subspace becomes too large. The new subspace vectors (after a collapse) are linear combinations of current subspace vectors, with coefficients found in the lowest eigenvectors of the subspace matrix.";
63 }
64
65
71 void execute(EigenproblemEnvironment<double>& environment) override {
72
73 auto& V = environment.V;
74 const auto& Delta = environment.Delta;
75
76 // If the subspace will potentially become too large, collapse it in advance.
77 const auto current_subspace_dimension = V.cols();
78 if (current_subspace_dimension + Delta.cols() > this->maximum_subspace_dimension) {
79 V = environment.X;
80 }
81
82 // Update the current subspace V with new vectors: add the normalized orthogonal projection of the correction vectors if their norm is large enough.
83 // Note that we can't add more than one vector simultaneously, as the inclusion of one vector changes the subspace, which in turn changes its orthogonal complement.
84 for (size_t column_index = 0; column_index < Delta.cols(); column_index++) {
85 VectorX<double> v = Delta.col(column_index) - V * (V.transpose() * Delta.col(column_index)); // project the correction vector on the orthogonal complement of V
86 const double norm = v.norm();
87 v.normalize();
88
89 if (norm > this->threshold) {
90 V.conservativeResize(Eigen::NoChange, V.cols() + 1); // the number of rows doesn't change
91 V.col(V.cols() - 1) = v; // add the new vector to the last column
92 }
93 }
94 }
95};
96
97
98} // namespace GQCP
Definition: EigenproblemEnvironment.hpp:35
MatrixX< Scalar > X
Definition: EigenproblemEnvironment.hpp:79
MatrixX< Scalar > V
Definition: EigenproblemEnvironment.hpp:73
MatrixX< Scalar > Delta
Definition: EigenproblemEnvironment.hpp:86
Definition: Matrix.hpp:47
Definition: Step.hpp:37
Definition: SubspaceUpdate.hpp:32
std::string description() const override
Definition: SubspaceUpdate.hpp:61
void execute(EigenproblemEnvironment< double > &environment) override
Definition: SubspaceUpdate.hpp:71
SubspaceUpdate(const size_t maximum_subspace_dimension=15, const double threshold=1.0e-03)
Definition: SubspaceUpdate.hpp:49
Definition: BaseOneElectronIntegralBuffer.hpp:25