GQCP
Loading...
Searching...
No Matches
GSQTwoElectronOperator.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
30
31
32namespace GQCP {
33
34
41template <typename _Scalar, typename _Vectorizer>
43 public SimpleSQTwoElectronOperator<_Scalar, _Vectorizer, GSQTwoElectronOperator<_Scalar, _Vectorizer>> {
44public:
45 // The scalar type used for a single parameter/matrix element: real or complex.
46 using Scalar = _Scalar;
47
48 // The type of the vectorizer that relates a one-dimensional storage of tensors to the tensor structure of two-electron operators. This distinction is carried over from SimpleSQOneElectronOperator.
49 using Vectorizer = _Vectorizer;
50
51 // The spinor tag corresponding to a `GSQTwoElectronOperator`.
53
54
55public:
56 /*
57 * MARK: Constructors
58 */
59
60 // Inherit `SimpleSQOneElectronOperator`'s constructors.
61 using SimpleSQTwoElectronOperator<_Scalar, _Vectorizer, GSQTwoElectronOperator<_Scalar, _Vectorizer>>::SimpleSQTwoElectronOperator;
62
63
64 /*
65 * MARK: Named constructors
66 */
67
74
75 // We can just wrap the one-electron integrals into the correct class.
78 }
79};
80
81
82/*
83 * MARK: Convenience aliases
84 */
85
86// A scalar-like GSQTwoElectronOperator, i.e. with scalar-like access.
87template <typename Scalar>
89
90// A vector-like GSQTwoElectronOperator, i.e. with vector-like access.
91template <typename Scalar>
93
94// A matrix-like GSQTwoElectronOperator, i.e. with matrix-like access.
95template <typename Scalar>
97
98// A tensor-like GSQTwoElectronOperator, i.e. with tensor-like access.
99template <typename Scalar, size_t N>
101
102
103/*
104 * MARK: Operator traits
105 */
106
113template <typename Scalar, typename Vectorizer>
114struct OperatorTraits<GSQTwoElectronOperator<Scalar, Vectorizer>> {
115
116 // A type that corresponds to the scalar version of the associated general(ized) two-electron operator type.
118
119 // The type of one-electron operator that is naturally related to a `GSQTwoElectronOperator`.
121
122 // The type of transformation that is naturally associated to a `GSQTwoElectronOperator`.
124
125 // The type of density matrix that is naturally associated to a `GSQTwoElectronOperator`.
127
128 // The type of density matrix that is naturally associated to a `GSQTwoElectronOperator`.
130};
131
132
133/*
134 * MARK: BasisTransformableTraits
135 */
136
143template <typename Scalar, typename Vectorizer>
145
146 // The type of transformation matrix that is naturally associated to a `GSQTwoElectronOperator`.
148};
149
150
151/*
152 * MARK: JacobiRotatableTraits
153 */
154
158template <typename Scalar, typename Vectorizer>
160
161 // The type of Jacobi rotation for which the Jacobi rotation should be defined.
163};
164
165
166/*
167 * MARK: One-electron operator products
168 */
169
175template <typename _Scalar>
177 public VectorSpaceArithmetic<ScalarGSQOneElectronOperatorProduct<_Scalar>, _Scalar>,
178 public BasisTransformable<ScalarGSQOneElectronOperatorProduct<_Scalar>>,
179 public JacobiRotatable<ScalarGSQOneElectronOperatorProduct<_Scalar>> {
180public:
181 // The scalar type of one of the matrix elements: real or complex.
182 using Scalar = _Scalar;
183
184 // The type of 'this'.
186
187
188private:
189 // The one-electron part of the product.
191
192 // The two-electron part of the product. Since it is expressed as a `SQTwoElectronOperator`, it implicitly assumes the incorporation of a factor 2.
194
195
196public:
197 /*
198 * MARK: Constructors
199 */
200
208 o {o},
209 t {t} {}
210
211
212 /*
213 * MARK: Access
214 */
215
219 const ScalarGSQOneElectronOperator<Scalar>& oneElectron() const { return this->o; }
220
224 const ScalarGSQTwoElectronOperator<Scalar>& twoElectron() const { return this->t; }
225
230
235
236
237 /*
238 * MARK: Conforming to `VectorSpaceArithmetic`
239 */
240
245
246 // Add the one- and two-electron operator parts.
247 this->oneElectron() += rhs.oneElectron();
248 this->twoElectron() += rhs.twoElectron();
249
250 return *this;
251 }
252
253
258
259 // Multiply the one- and two-electron operator parts with the scalar.
260 this->oneElectron() *= a;
261 this->twoElectron() *= a;
262
263 return *this;
264 }
265
266
267 /*
268 * MARK: Conforming to BasisTransformable
269 */
270
278 Self transformed(const GTransformation<Scalar>& T) const override {
279
280 auto result = *this;
281
282 // Transform the one- and two-electron contributions.
283 result.oneElectron().transform(T);
284 result.twoElectron().transform(T);
285
286 return result;
287 }
288
289
290 // Allow the `rotate` method from `BasisTransformable`, since there's also a `rotate` from `JacobiRotatable`.
292
293 // Allow the `rotated` method from `BasisTransformable`, since there's also a `rotated` from `JacobiRotatable`.
295
296
297 /*
298 * MARK: Conforming to JacobiRotatable
299 */
300
308 Self rotated(const JacobiRotation& jacobi_rotation) const override {
309
310 auto result = *this;
311
312 // Transform the total one- and two-electron contributions.
313 result.oneElectron().rotate(jacobi_rotation);
314 result.twoElectron().rotate(jacobi_rotation);
315
316 return result;
317 }
318
319 // Allow the `rotate` method from `JacobiRotatable`, since there's also a `rotate` from `BasisTransformable`.
321
322
323 /*
324 * MARK: Expectation value
325 */
326
336
337 // We can access the expectation value of a scalar operator using an empty call.
338 return this->oneElectron().calculateExpectationValue(D)() + this->twoElectron().calculateExpectationValue(d)();
339 }
340};
341
342
343/*
344 * MARK: `BasisTransformableTraits` for `ScalarGSQOneElectronOperatorProduct`.
345 */
346
352template <typename Scalar>
354
355 // The type of transformation matrix that is naturally associated to a `ScalarGSQOneElectronOperatorProduct`.
357};
358
359
360/*
361 * MARK: `JacobiRotatableTraits` for `ScalarGSQOneElectronOperatorProduct`.
362 */
363
369template <typename Scalar>
371
372 // The type of Jacobi rotation for which the Jacobi rotation should be defined.
374};
375
376
384template <typename Scalar>
386
387 // Prepare some variables.
388 const auto& L = lhs.parameters();
389 const auto& R = rhs.parameters();
390
391 // Determine the matrix elements of the one-electron part of the product.
392 SquareMatrix<Scalar> O = L * R;
394
395
396 // Determine the matrix elements of the two-electron part of the product.
397 const auto dim = lhs.parameters().dimension();
399 for (size_t p = 0; p < dim; p++) {
400 for (size_t q = 0; q < dim; q++) {
401 for (size_t r = 0; r < dim; r++) {
402 for (size_t s = 0; s < dim; s++) {
403 T(p, q, r, s) = 2.0 * L(p, q) * R(r, s); // Include the prefactor '2' because we're going to encapsulate these matrix elements with a `ScalarGSQTwoElectronOperator`, whose matrix elements should not embet the prefactor 0.5 for two-electron operators.
404 }
405 }
406 }
407 }
409
410
412}
413
414
415} // namespace GQCP
Definition: BasisTransformable.hpp:50
void rotate(const Transformation &U)
Definition: BasisTransformable.hpp:107
Definition: G1DM.hpp:41
Definition: G2DM.hpp:42
Definition: GSQOneElectronOperator.hpp:42
Definition: GSQTwoElectronOperator.hpp:43
_Scalar Scalar
Definition: GSQTwoElectronOperator.hpp:46
_Vectorizer Vectorizer
Definition: GSQTwoElectronOperator.hpp:49
static GSQTwoElectronOperator< Scalar, Vectorizer > FromUnrestrictedComponent(const PureUSQTwoElectronOperatorComponent< Scalar, Vectorizer > &g_component)
Definition: GSQTwoElectronOperator.hpp:73
Definition: spinor_tags.hpp:47
Definition: JacobiRotatable.hpp:50
Definition: JacobiRotation.hpp:33
Definition: PureUSQTwoElectronOperatorComponent.hpp:39
const MatrixRepresentation & parameters(const Indices &... indices) const
Definition: SQOperatorStorageBase.hpp:236
const std::vector< MatrixRepresentation > & allParameters() const
Definition: SQOperatorStorageBase.hpp:221
const Vectorizer & vectorizer() const
Definition: SQOperatorStorageBase.hpp:282
StorageArray< MatrixRepresentation, Vectorizer > array
Definition: SQOperatorStorageBase.hpp:68
Definition: GSQTwoElectronOperator.hpp:179
ScalarGSQOneElectronOperatorProduct & operator*=(const Scalar &a) override
Definition: GSQTwoElectronOperator.hpp:257
const ScalarGSQOneElectronOperator< Scalar > & oneElectron() const
Definition: GSQTwoElectronOperator.hpp:219
Self transformed(const GTransformation< Scalar > &T) const override
Definition: GSQTwoElectronOperator.hpp:278
Scalar calculateExpectationValue(const G1DM< Scalar > &D, const G2DM< Scalar > &d) const
Definition: GSQTwoElectronOperator.hpp:335
ScalarGSQOneElectronOperatorProduct & operator+=(const ScalarGSQOneElectronOperatorProduct &rhs) override
Definition: GSQTwoElectronOperator.hpp:244
_Scalar Scalar
Definition: GSQTwoElectronOperator.hpp:182
Self rotated(const JacobiRotation &jacobi_rotation) const override
Definition: GSQTwoElectronOperator.hpp:308
ScalarGSQTwoElectronOperator< Scalar > & twoElectron()
Definition: GSQTwoElectronOperator.hpp:234
ScalarGSQOneElectronOperator< Scalar > & oneElectron()
Definition: GSQTwoElectronOperator.hpp:229
ScalarGSQOneElectronOperatorProduct< Scalar > Self
Definition: GSQTwoElectronOperator.hpp:185
const ScalarGSQTwoElectronOperator< Scalar > & twoElectron() const
Definition: GSQTwoElectronOperator.hpp:224
ScalarGSQOneElectronOperatorProduct(const ScalarGSQOneElectronOperator< Scalar > &o, const ScalarGSQTwoElectronOperator< Scalar > &t)
Definition: GSQTwoElectronOperator.hpp:207
Definition: SimpleSQTwoElectronOperator.hpp:46
Definition: SquareMatrix.hpp:39
Definition: SquareRankFourTensor.hpp:36
static Self Zero(const size_t dim)
Definition: SquareRankFourTensor.hpp:147
Definition: StorageArray.hpp:38
Definition: VectorSpaceArithmetic.hpp:35
Definition: BaseOneElectronIntegralBuffer.hpp:25
FunctionProduct< F1, F2 > operator*(const F1 &lhs, const F2 &rhs)
Definition: Function.hpp:208
Definition: BasisTransformable.hpp:37
Definition: JacobiRotatable.hpp:37
Definition: OperatorTraits.hpp:28