GQCP
Loading...
Searching...
No Matches
SpinResolvedOrbitalSpace.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 SpinResolvedBase<OrbitalSpace, SpinResolvedOrbitalSpace> {
33public:
34 // The type component this spin resolved object is made of.
36
37public:
38 /*
39 * MARK: Constructors
40 */
41
42 // Inherit `SpinResolvedBase`'s constructors.
44
45
46 /*
47 * MARK: Public methods
48 */
49
64 template <typename Scalar>
66 const OccupationType column_type, const Spin column_spin, const MatrixX<Scalar>& M) const {
67
68 // Prepare the necessary members for ImplicitMatrixSlice.
69 // The spin component of each axis determines from which of the two internal OrbitalSpace members the orbitals of the chosen occupation type are used.
70 // Determine the spin component and dimension of the rows.
71 std::vector<size_t> row_indices;
72 if (row_spin == Spin::alpha) {
73 row_indices = this->alpha().indices(row_type);
74 } else {
75 row_indices = this->beta().indices(row_type);
76 }
77
78 // Determine the spin component and dimension of the columns.
79 std::vector<size_t> column_indices;
80 if (column_spin == Spin::alpha) {
81 column_indices = this->alpha().indices(column_type);
82 } else {
83 column_indices = this->beta().indices(column_type);
84 }
85
86 return ImplicitMatrixSlice<Scalar>::FromIndices(row_indices, column_indices, M);
87 }
88
89
108 template <typename Scalar>
109 ImplicitRankFourTensorSlice<Scalar> createMixedRepresentableObjectFor(const OccupationType axis1_type, const Spin axis1_spin, const OccupationType axis2_type, const Spin axis2_spin,
110 const OccupationType axis3_type, const Spin axis3_spin, const OccupationType axis4_type, const Spin axis4_spin, const Tensor<Scalar, 4>& T) const {
111
112 // Prepare the necessary members for ImplicitRankFourTensor.
113 // The spin component of each axis determines from which of the two internal OrbitalSpace members the orbitals of the chosen occupation type are used.
114 // Determine the spin component and dimension of the first axis.
115 std::vector<size_t> axis1_indices;
116 if (axis1_spin == Spin::alpha) {
117 axis1_indices = this->alpha().indices(axis1_type);
118 } else {
119 axis1_indices = this->beta().indices(axis1_type);
120 }
121
122 // Determine the spin component and dimension of the second axis.
123 std::vector<size_t> axis2_indices;
124 if (axis2_spin == Spin::alpha) {
125 axis2_indices = this->alpha().indices(axis2_type);
126 } else {
127 axis2_indices = this->beta().indices(axis2_type);
128 }
129
130 // Determine the spin component and dimension of the third axis.
131 std::vector<size_t> axis3_indices;
132 if (axis3_spin == Spin::alpha) {
133 axis3_indices = this->alpha().indices(axis3_type);
134 } else {
135 axis3_indices = this->beta().indices(axis3_type);
136 }
137
138 // Determine the spin component and dimension of the fourth axis.
139 std::vector<size_t> axis4_indices;
140 if (axis4_spin == Spin::alpha) {
141 axis4_indices = this->alpha().indices(axis4_type);
142 } else {
143 axis4_indices = this->beta().indices(axis4_type);
144 }
145
146 return ImplicitRankFourTensorSlice<Scalar>::FromIndices(axis1_indices, axis2_indices, axis3_indices, axis4_indices, T);
147 }
148
149
163 template <typename Scalar>
165 const OccupationType column_type, const Spin column_spin) const {
166
167 // Prepare the necessary members for the other method.
168 // Determine the dimension of the matrix rows.
169 size_t rows {};
170 if (row_spin == Spin::alpha) {
171 rows = this->alpha().numberOfOrbitals(row_type);
172 } else {
173 rows = this->beta().numberOfOrbitals(row_type);
174 }
175
176 // Determine the dimension of the matrix columns.
177 size_t columns {};
178 if (column_spin == Spin::alpha) {
179 columns = this->alpha().numberOfOrbitals(column_type);
180 } else {
181 columns = this->beta().numberOfOrbitals(column_type);
182 }
183
184 // Zero-initialize a matrix of the specified dimensions.
185 const MatrixX<Scalar> M = MatrixX<Scalar>::Zero(rows, columns);
186
187 return this->createMixedRepresentableObjectFor<Scalar>(row_type, row_spin, column_type, column_spin, M);
188 }
189
190
208 template <typename Scalar>
209 ImplicitRankFourTensorSlice<Scalar> initializeMixedRepresentableObjectFor(const OccupationType axis1_type, const Spin axis1_spin, const OccupationType axis2_type, const Spin axis2_spin,
210 const OccupationType axis3_type, const Spin axis3_spin, const OccupationType axis4_type, const Spin axis4_spin) const {
211
212 // Prepare the necessary members for the other method.
213 // The spin component of each axis determines from which of the two internal OrbitalSpace members the orbitals of the chosen occupation type are used.
214
215 // Determine the spin component and dimension of the first axis.
216 int axis1_dimension; // Need an `int` because a `Tensor` requires it.
217 if (axis1_spin == Spin::alpha) {
218 axis1_dimension = this->alpha().numberOfOrbitals(axis1_type);
219 } else {
220 axis1_dimension = this->beta().numberOfOrbitals(axis1_type);
221 }
222
223 // Determine the spin component and dimension of the second axis.
224 int axis2_dimension;
225 if (axis2_spin == Spin::alpha) {
226 axis2_dimension = this->alpha().numberOfOrbitals(axis2_type);
227 } else {
228 axis2_dimension = this->beta().numberOfOrbitals(axis2_type);
229 }
230
231 // Determine the spin component and dimension of the second axis.
232 int axis3_dimension;
233 if (axis3_spin == Spin::alpha) {
234 axis3_dimension = this->alpha().numberOfOrbitals(axis3_type);
235 } else {
236 axis3_dimension = this->beta().numberOfOrbitals(axis3_type);
237 }
238
239 // Determine the spin component and dimension of the second axis.
240 int axis4_dimension;
241 if (axis4_spin == Spin::alpha) {
242 axis4_dimension = this->alpha().numberOfOrbitals(axis4_type);
243 } else {
244 axis4_dimension = this->beta().numberOfOrbitals(axis4_type);
245 }
246
247 // Zero-initialize the tensor of the specified dimensions.
248 Tensor<Scalar, 4> T {axis1_dimension, axis2_dimension, axis3_dimension, axis4_dimension};
249 T.setZero();
250
251 return this->createMixedRepresentableObjectFor(axis1_type, axis1_spin, axis2_type, axis2_spin, axis3_type, axis3_spin, axis4_type, axis4_spin, T);
252 }
253};
254
255} // namespace GQCP
Definition: ImplicitMatrixSlice.hpp:38
static ImplicitMatrixSlice< Scalar > FromIndices(const std::vector< size_t > &row_indices, const std::vector< size_t > &col_indices, const MatrixX< Scalar > &M)
Definition: ImplicitMatrixSlice.hpp:134
Definition: ImplicitRankFourTensorSlice.hpp:38
static ImplicitRankFourTensorSlice< Scalar > FromIndices(const std::vector< std::vector< size_t > > &axes_indices, const Tensor< Scalar, 4 > &T)
Definition: ImplicitRankFourTensorSlice.hpp:128
Definition: Matrix.hpp:47
Definition: OrbitalSpace.hpp:40
const std::vector< size_t > & indices() const
Definition: OrbitalSpace.hpp:150
size_t numberOfOrbitals() const
Definition: OrbitalSpace.hpp:235
Definition: SpinResolvedBase.hpp:39
const Of & beta() const
Definition: SpinResolvedBase.hpp:140
const Of & alpha() const
Definition: SpinResolvedBase.hpp:130
Definition: SpinResolvedOrbitalSpace.hpp:32
ImplicitMatrixSlice< Scalar > initializeMixedRepresentableObjectFor(const OccupationType row_type, const Spin row_spin, const OccupationType column_type, const Spin column_spin) const
Definition: SpinResolvedOrbitalSpace.hpp:164
ImplicitRankFourTensorSlice< Scalar > initializeMixedRepresentableObjectFor(const OccupationType axis1_type, const Spin axis1_spin, const OccupationType axis2_type, const Spin axis2_spin, const OccupationType axis3_type, const Spin axis3_spin, const OccupationType axis4_type, const Spin axis4_spin) const
Definition: SpinResolvedOrbitalSpace.hpp:209
typename SpinResolvedBase< OrbitalSpace, SpinResolvedOrbitalSpace >::Of ComponentType
Definition: SpinResolvedOrbitalSpace.hpp:35
ImplicitRankFourTensorSlice< Scalar > createMixedRepresentableObjectFor(const OccupationType axis1_type, const Spin axis1_spin, const OccupationType axis2_type, const Spin axis2_spin, const OccupationType axis3_type, const Spin axis3_spin, const OccupationType axis4_type, const Spin axis4_spin, const Tensor< Scalar, 4 > &T) const
Definition: SpinResolvedOrbitalSpace.hpp:109
ImplicitMatrixSlice< Scalar > createMixedRepresentableObjectFor(const OccupationType row_type, const Spin row_spin, const OccupationType column_type, const Spin column_spin, const MatrixX< Scalar > &M) const
Definition: SpinResolvedOrbitalSpace.hpp:65
Definition: Tensor.hpp:46
Definition: BaseOneElectronIntegralBuffer.hpp:25
OccupationType
Definition: OccupationType.hpp:29
Spin
Definition: Spin.hpp:27
@ alpha
Definition: Spin.hpp:28