GQCP
Loading...
Searching...
No Matches
T1Amplitudes.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
26
27
28namespace GQCP {
29
30
38template <typename _Scalar>
40 public VectorSpaceArithmetic<T1Amplitudes<_Scalar>, _Scalar> {
41
42public:
43 // The scalar type that represents one of the amplitudes.
44 using Scalar = _Scalar;
45
46 // The type of 'this'.
48
49
50private:
51 // The orbital space which encapsulates the occupied-virtual separation.
52 OrbitalSpace orbital_space;
53
54 // The T1-amplitudes as an implicit matrix, implementing intuitive operator(i,a) calls.
56
57
58public:
59 /*
60 * MARK: Constructors
61 */
62
69 T1Amplitudes(const ImplicitMatrixSlice<Scalar>& t, const OrbitalSpace& orbital_space) :
70 orbital_space {orbital_space},
71 t {t} {}
72
73
81 T1Amplitudes(const ImplicitMatrixSlice<Scalar>& t, const size_t N, const size_t M) :
83
84
85 /*
86 * MARK: Named constructors
87 */
88
97 static T1Amplitudes<Scalar> Perturbative(const SquareMatrix<Scalar>& f, const OrbitalSpace& orbital_space) {
98
99 // Zero-initialize a matrix representation for the (occupied-virtual) T1-amplitudes t_i^a.
101
102 // Provide the perturbative T1-amplitudes, by setting the RHS amplitudes in Stanton1991, equation (1) to zero.
103 for (const auto& i : orbital_space.indices(OccupationType::k_occupied)) {
104 for (const auto& a : orbital_space.indices(OccupationType::k_virtual)) {
105 const auto denominator = f(i, i) - f(a, a);
106
107 t1(i, a) = f(i, a) / denominator;
108 }
109 }
110
111 return T1Amplitudes<Scalar>(t1, orbital_space);
112 }
113
114
115 /*
116 * MARK: Access.
117 */
118
127 Scalar operator()(const size_t i, const size_t a) const { return this->t(i, a); }
128
137 Scalar& operator()(const size_t i, const size_t a) { return this->t(i, a); }
138
142 const ImplicitMatrixSlice<Scalar>& asImplicitMatrixSlice() const { return this->t; }
143
147 const OrbitalSpace& orbitalSpace() const { return this->orbital_space; }
148
149
150 /*
151 * MARK: Linear algebra
152 */
153
157 Scalar norm() const { return this->asImplicitMatrixSlice().asMatrix().norm(); }
158
159
160 /*
161 * MARK: Vector space arithmetic
162 */
163
167 Self& operator+=(const Self& rhs) override {
168
169 // Prepare some variables.
170 const auto& row_map = this->asImplicitMatrixSlice().rowIndexMap();
171 const auto& col_map = this->asImplicitMatrixSlice().columnIndexMap();
172
173 // Sum the matrix representations.
174 const MatrixX<Scalar> t_sum_dense = this->asImplicitMatrixSlice().asMatrix() + rhs.asImplicitMatrixSlice().asMatrix();
175 const ImplicitMatrixSlice<Scalar> t_sum_slice {row_map, col_map, t_sum_dense};
176
177 this->t = t_sum_slice;
178
179 return *this;
180 }
181
182
186 Self& operator*=(const Scalar& a) override {
187
188 // Prepare some variables.
189 const auto& row_map = this->asImplicitMatrixSlice().rowIndexMap();
190 const auto& col_map = this->asImplicitMatrixSlice().columnIndexMap();
191
192 // Multiply the matrix representation.
193 const MatrixX<Scalar> t_multiplied_dense = a * this->asImplicitMatrixSlice().asMatrix();
194 const ImplicitMatrixSlice<Scalar> t_multiplied_slice {row_map, col_map, t_multiplied_dense};
195
196 this->t = t_multiplied_slice;
197
198 return *this;
199 }
200};
201
202} // namespace GQCP
Definition: ImplicitMatrixSlice.hpp:38
const MatrixX< Scalar > & asMatrix() const
Definition: ImplicitMatrixSlice.hpp:243
const std::map< size_t, size_t > & columnIndexMap() const
Definition: ImplicitMatrixSlice.hpp:253
const std::map< size_t, size_t > & rowIndexMap() const
Definition: ImplicitMatrixSlice.hpp:276
Definition: Matrix.hpp:47
Definition: OrbitalSpace.hpp:40
const std::vector< size_t > & indices() const
Definition: OrbitalSpace.hpp:150
ImplicitMatrixSlice< Scalar > initializeRepresentableObjectFor(const OccupationType row_type, const OccupationType column_type) const
Definition: OrbitalSpace.hpp:173
Definition: SquareMatrix.hpp:39
Definition: T1Amplitudes.hpp:40
T1Amplitudes(const ImplicitMatrixSlice< Scalar > &t, const OrbitalSpace &orbital_space)
Definition: T1Amplitudes.hpp:69
Scalar operator()(const size_t i, const size_t a) const
Definition: T1Amplitudes.hpp:127
const OrbitalSpace & orbitalSpace() const
Definition: T1Amplitudes.hpp:147
Self & operator*=(const Scalar &a) override
Definition: T1Amplitudes.hpp:186
const ImplicitMatrixSlice< Scalar > & asImplicitMatrixSlice() const
Definition: T1Amplitudes.hpp:142
Scalar & operator()(const size_t i, const size_t a)
Definition: T1Amplitudes.hpp:137
Self & operator+=(const Self &rhs) override
Definition: T1Amplitudes.hpp:167
static T1Amplitudes< Scalar > Perturbative(const SquareMatrix< Scalar > &f, const OrbitalSpace &orbital_space)
Definition: T1Amplitudes.hpp:97
T1Amplitudes(const ImplicitMatrixSlice< Scalar > &t, const size_t N, const size_t M)
Definition: T1Amplitudes.hpp:81
Scalar norm() const
Definition: T1Amplitudes.hpp:157
_Scalar Scalar
Definition: T1Amplitudes.hpp:44
Definition: VectorSpaceArithmetic.hpp:35
Definition: BaseOneElectronIntegralBuffer.hpp:25