GQCP
Loading...
Searching...
No Matches
Simple1DM.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
27
28
29namespace GQCP {
30
31
32/*
33 * MARK: `Simple1DM` implementation
34 */
35
44template <typename _Scalar, typename _DerivedDM>
46 public BasisTransformable<_DerivedDM>,
47 public JacobiRotatable<_DerivedDM>,
48 public VectorSpaceArithmetic<_DerivedDM, _Scalar> {
49public:
50 // The scalar type used for a density matrix element: real or complex.
51 using Scalar = _Scalar;
52
53 // The type of the density matrix that derives from this class, enabling CRTP and compile-time polymorphism.
54 using DerivedDM = _DerivedDM;
55
56 // The type of 'this'.
58
59 // The type of transformation that is naturally related to the `DerivedDM`.
61
62
63private:
64 // The matrix representation of this one-electron density matrix.
66
67
68public:
69 /*
70 * MARK: Constructors
71 */
72
79 D {D} {}
80
81
86 Simple1DM(SquareMatrix<Scalar>::Zero(0)) {}
87
88
89 /*
90 * MARK: Access
91 */
92
96 const SquareMatrix<Scalar>& matrix() const { return this->D; }
97
101 SquareMatrix<Scalar>& matrix() { return this->D; }
102
103
104 /*
105 * MARK: General information
106 */
107
111 size_t numberOfOrbitals() const { return this->matrix().dimension(); }
112
113
119 double norm() const { return this->matrix().norm(); }
120
121
122 /*
123 * MARK: Conforming to `VectorSpaceArithmetic`
124 */
125
129 DerivedDM& operator+=(const DerivedDM& rhs) override {
130 this->matrix() += rhs.matrix();
131 return static_cast<DerivedDM&>(*this);
132 }
133
137 DerivedDM& operator*=(const Scalar& a) override {
138 this->matrix() *= a;
139 return static_cast<DerivedDM&>(*this);
140 }
141
142
143 /*
144 * MARK: Conforming to `BasisTransformable`
145 */
146
154 DerivedDM transformed(const Transformation& T) const override {
155
156 // The transformation formulas for one-electron operators and 1-DMs are similar, but not quite the same. Instead of using T, the transformation formula for the 1-DM uses T_inverse_transpose. See also (https://gqcg-res.github.io/knowdes/spinor-transformations.html).
157 const auto T_related = T.matrix().transpose().inverse();
158 return DerivedDM {T_related.adjoint() * this->matrix() * T_related};
159 }
160
161 // Allow the `rotate` method from `BasisTransformable`, since there's also a `rotate` from `JacobiRotatable`.
163
164 // Allow the `rotated` method from `BasisTransformable`, since there's also a `rotated` from `JacobiRotatable`.
166
167
168 /*
169 * MARK: Conforming to `JacobiRotatable`
170 */
171
179 DerivedDM rotated(const JacobiRotation& jacobi_rotation) const override {
180
181 // We implement this rotation by constructing a Jacobi rotation matrix and then simply doing a rotation with it.
182 const auto J = Transformation::FromJacobi(jacobi_rotation, this->numberOfOrbitals());
183 return this->rotated(J);
184 }
185
186 // Allow the `rotate` method from `JacobiRotatable`, since there's also a `rotate` from `BasisTransformable`.
188};
189
190
191} // namespace GQCP
Definition: BasisTransformable.hpp:50
void rotate(const Transformation &U)
Definition: BasisTransformable.hpp:107
Definition: JacobiRotatable.hpp:50
Definition: JacobiRotation.hpp:33
Definition: Simple1DM.hpp:48
_Scalar Scalar
Definition: Simple1DM.hpp:51
size_t numberOfOrbitals() const
Definition: Simple1DM.hpp:111
DerivedDM rotated(const JacobiRotation &jacobi_rotation) const override
Definition: Simple1DM.hpp:179
DerivedDM transformed(const Transformation &T) const override
Definition: Simple1DM.hpp:154
_DerivedDM DerivedDM
Definition: Simple1DM.hpp:54
SquareMatrix< Scalar > & matrix()
Definition: Simple1DM.hpp:101
double norm() const
Definition: Simple1DM.hpp:119
const SquareMatrix< Scalar > & matrix() const
Definition: Simple1DM.hpp:96
typename DensityMatrixTraits< DerivedDM >::Transformation Transformation
Definition: Simple1DM.hpp:60
DerivedDM & operator*=(const Scalar &a) override
Definition: Simple1DM.hpp:137
Simple1DM()
Definition: Simple1DM.hpp:85
Simple1DM(const SquareMatrix< Scalar > &D)
Definition: Simple1DM.hpp:78
DerivedDM & operator+=(const DerivedDM &rhs) override
Definition: Simple1DM.hpp:129
Definition: SquareMatrix.hpp:39
size_t dimension() const
Definition: SquareMatrix.hpp:299
Definition: VectorSpaceArithmetic.hpp:35
Definition: BaseOneElectronIntegralBuffer.hpp:25
Definition: DensityMatrixTraits.hpp:28