GQCP
Loading...
Searching...
No Matches
SpinResolvedBase.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
22
23#include <stdexcept>
24
25#include <array>
26#include <vector>
27
28
29namespace GQCP {
30
31
38template <typename _Of, typename _Derived>
40public:
41 // The type of the alpha- and beta-objects. The name 'Of' is chosen for a natural reading `SpinResolvedBase<_Of, _Derived>`.
42 using Of = _Of;
43
44 // The type that derives from this type, given as a template argument, enabling CRTP and compile-time polymorphism.
45 using Derived = _Derived;
46
47 // The type of 'this'.
49
50
51private:
52 // The alpha-object.
53 Of m_alpha;
54
55 // The beta-object.
56 Of m_beta;
57
58
59public:
60 /*
61 * MARK: Constructors
62 */
63
70 SpinResolvedBase(const Of& alpha, const Of& beta) :
71 m_alpha {alpha},
72 m_beta {beta} {}
73
74
80 SpinResolvedBase(const std::vector<Of>& both) :
81 SpinResolvedBase(both[0], both[1]) {
82
83 if (both.size() != 2) {
84 throw std::invalid_argument("SpinResolvedBase(const std::vector<Of>&): The given vector does not have exactly two elements.");
85 }
86 }
87
88
94 SpinResolvedBase(const std::array<Of, 2>& both) :
95 SpinResolvedBase(both[0], both[1]) {}
96
97
103 SpinResolvedBase(const std::initializer_list<Of>& both) :
104 SpinResolvedBase(std::vector<Of>(both)) {}
105
106
107 /*
108 * MARK: Named constructors
109 */
110
118 static Derived FromEqual(const Of& equal) {
119 return Derived {equal, equal};
120 }
121
122
123 /*
124 * MARK: Accessing spin components
125 */
126
130 const Of& alpha() const { return this->m_alpha; }
131
135 Of& alpha() { return this->m_alpha; }
136
140 const Of& beta() const { return this->m_beta; }
141
145 Of& beta() { return this->m_beta; }
146
154 const Of& component(const Spin sigma) const {
155
156 switch (sigma) {
157 case Spin::alpha: {
158 return this->alpha();
159 break;
160 }
161
162 case Spin::beta: {
163 return this->beta();
164 break;
165 }
166 }
167 }
168
176 Of& component(const Spin sigma) { return const_cast<Of&>(const_cast<const Self*>(this)->component(sigma)); }
177};
178
179
180} // namespace GQCP
Definition: OrbitalSpace.hpp:40
Definition: SpinResolvedBase.hpp:39
const Of & beta() const
Definition: SpinResolvedBase.hpp:140
Of & component(const Spin sigma)
Definition: SpinResolvedBase.hpp:176
Of & alpha()
Definition: SpinResolvedBase.hpp:135
SpinResolvedBase(const std::vector< Of > &both)
Definition: SpinResolvedBase.hpp:80
_Derived Derived
Definition: SpinResolvedBase.hpp:45
SpinResolvedBase(const std::array< Of, 2 > &both)
Definition: SpinResolvedBase.hpp:94
Of & beta()
Definition: SpinResolvedBase.hpp:145
SpinResolvedBase(const std::initializer_list< Of > &both)
Definition: SpinResolvedBase.hpp:103
const Of & component(const Spin sigma) const
Definition: SpinResolvedBase.hpp:154
SpinResolvedBase(const Of &alpha, const Of &beta)
Definition: SpinResolvedBase.hpp:70
const Of & alpha() const
Definition: SpinResolvedBase.hpp:130
static Derived FromEqual(const Of &equal)
Definition: SpinResolvedBase.hpp:118
Definition: BaseOneElectronIntegralBuffer.hpp:25
Spin
Definition: Spin.hpp:27
@ beta
Definition: Spin.hpp:29
@ alpha
Definition: Spin.hpp:28