LIBINT 2.9.0
src/bin/libint/braket.h
1/*
2 * Copyright (C) 2004-2024 Edward F. Valeev
3 *
4 * This file is part of Libint compiler.
5 *
6 * Libint compiler is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Libint compiler is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Libint compiler. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_bin_libint_braket_h_
22#define _libint2_src_bin_libint_braket_h_
23
24#include <algebra.h>
25#include <bfset.h>
26#include <global_macros.h>
27#include <libint2/util/intrinsic_types.h>
28#include <polyconstr.h>
29
30namespace libint2 {
31
33
38template <class BFS, unsigned int NP>
40 public:
44 typedef struct {
49 static constexpr auto num_particles = NP;
51 static constexpr auto num_bf = NP;
52
53 typedef BFS bfs_type;
54 typedef bfs_type& bfs_ref;
55 typedef const BFS& bfs_cref;
56
61 ArrayBraket(const BFS* braket);
62 ArrayBraket(const std::vector<std::vector<BFS> >& braket);
64
66 bool operator==(const this_type&) const;
68 bfs_cref member(unsigned int p, unsigned int i = 0) const;
70 bfs_ref member(unsigned int p, unsigned int i = 0);
72 SubIterator* member_subiter(unsigned int p, unsigned int i = 0) const;
74 void set_member(const BFS&, unsigned int p, unsigned int i = 0);
76 void set_member(const ConstructablePolymorphically&, unsigned int p,
77 unsigned int i = 0);
79 unsigned int num_members(unsigned int p) const {
80 assert(p < NP);
81 return 1;
82 }
84 unsigned int num_part() const { return NP; }
86 inline LIBINT2_UINT_LEAST64 key() const;
88 LIBINT2_UINT_LEAST64 max_key() const;
89#if COMPUTE_SIZE_DIRECTLY
90 unsigned int size() const;
91#endif
92
93 private:
94 BFS bfs_[NP];
95
96 // this function resets all cached values
97 void reset_cache();
98#if COMPUTE_SIZE_DIRECTLY
99 mutable unsigned int size_;
100#endif
101};
102
103template <class BFS, unsigned int NP>
105#if COMPUTE_SIZE_DIRECTLY
106 size_ = 0;
107#endif
108}
109
110template <class BFS, unsigned int NP>
111ArrayBraket<BFS, NP>::ArrayBraket(const BFS* braket) {
112 for (int i = 0; i < NP; i++) bfs_[i] = braket[i];
113#if COMPUTE_SIZE_DIRECTLY
114 size_ = 0;
115#endif
116}
117
118template <class BFS, unsigned int NP>
120 const std::vector<std::vector<BFS> >& braket) {
121 assert(braket.size() == NP);
122 for (unsigned int i = 0; i < NP; i++) {
123 assert(braket[i].size() == 1);
124 bfs_[i] = braket[i][0];
125 }
126#if COMPUTE_SIZE_DIRECTLY
127 size_ = 0;
128#endif
129}
130
131template <class BFS, unsigned int NP>
132ArrayBraket<BFS, NP>::~ArrayBraket() {}
133
134template <class BFS, unsigned int NP>
136 for (int i = 0; i < NP; i++)
137 if (bfs_[i] != a[i]) return false;
138 return true;
139}
140
141template <class BFS, unsigned int NP>
142typename ArrayBraket<BFS, NP>::bfs_cref ArrayBraket<BFS, NP>::member(
143 unsigned int p, unsigned int i) const {
144 assert(i == 0 && p < NP);
145 return bfs_[p];
146}
147
148template <class BFS, unsigned int NP>
149typename ArrayBraket<BFS, NP>::bfs_ref ArrayBraket<BFS, NP>::member(
150 unsigned int p, unsigned int i) {
151 assert(i == 0 && p < NP);
152 reset_cache();
153 return bfs_[p];
154}
155
156template <class BFS, unsigned int NP>
158 unsigned int i) const {
159 assert(i == 0 && p < NP);
160 return static_cast<SubIterator*>(new SubIteratorBase<BFS>(member(p, i)));
161}
162
163template <class BFS, unsigned int NP>
164void ArrayBraket<BFS, NP>::set_member(const BFS& f, unsigned int p,
165 unsigned int i) {
166 assert(i == 0 && p < NP);
167 reset_cache();
168 bfs_[p] = f;
169}
170
171template <class BFS, unsigned int NP>
173 unsigned int p, unsigned int i) {
174 assert(i == 0 && p < NP);
175 reset_cache();
176 bfs_[p] = BFS(f);
177}
178
179template <class BFS, unsigned int NP>
180LIBINT2_UINT_LEAST64 ArrayBraket<BFS, NP>::key() const {
181 LIBINT2_UINT_LEAST64 pfac = 1;
182 LIBINT2_UINT_LEAST64 key = 0;
183 for (int p = NP - 1; p >= 0; p--) {
184 key += pfac * bfs_[p].key();
185 pfac *= BFS::max_key;
186 }
187 assert(key < this->max_key());
188 return key;
189}
190
191template <class BFS, unsigned int NP>
192LIBINT2_UINT_LEAST64 ArrayBraket<BFS, NP>::max_key() const {
193 LIBINT2_UINT_LEAST64 max_key = 1;
194 for (int p = NP - 1; p >= 0; p--) {
195 max_key *= BFS::max_key;
196 }
197 return max_key;
198}
199
200#if COMPUTE_SIZE_DIRECTLY
201template <class BFS, unsigned int NP>
202unsigned int ArrayBraket<BFS, NP>::size() const {
203 if (size_ > 0) return size_;
204 size_ = 1;
206 for (int p = NP - 1; p >= 0; p--) {
207 size_ *= bfs_[p].num_bf();
208 }
209 }
210 return size_;
211}
212#endif
213
214template <class BFS, unsigned int NP>
215void ArrayBraket<BFS, NP>::reset_cache() {
216 size_ = 0;
217}
218
220// really need to have typedef template!
221template <typename BFS>
226
229// really need to have typedef template!
230template <typename BFS>
235
237
241enum BraketType { CBra, CKet, PBra, PKet };
246template <class BFS, BraketType BKType>
248 public:
251 typedef BFS bfs_type;
252
256 BraketPair(const BFS& f1, const BFS& f2) : bfs_(f1, f2) {}
257 BraketPair(const BraketPair& source) : bfs_(source.bfs_) {}
258 BraketPair& operator=(const BraketPair& rhs) {
259 bfs_ = rhs.bfs_;
260 return *this;
261 }
262 const BFS& operator[](unsigned int i) const {
263 if (i == 0) return bfs_.first;
264 if (i == 1) return bfs_.second;
265 throw std::logic_error("BraketPair::operator[] -- argument out of range");
266 }
268 bool operator==(const this_type& rhs) const { return rhs.bfs_ == bfs_; }
269
270 private:
271 std::pair<BFS, BFS> bfs_;
272};
273
275namespace braket {
277template <class F>
278BraketPair<F, PBra> _pbra(const F& f1, const F& f2) {
279 return BraketPair<F, PBra>(f1, f2);
280}
282template <class F>
283BraketPair<F, PKet> _pket(const F& f1, const F& f2) {
284 return BraketPair<F, PKet>(f1, f2);
285}
287template <class F>
288BraketPair<F, CBra> _cbra(const F& f1, const F& f2) {
289 return BraketPair<F, CBra>(f1, f2);
290}
292template <class F>
293BraketPair<F, CKet> _cket(const F& f1, const F& f2) {
294 return BraketPair<F, CKet>(f1, f2);
295}
296}; // namespace braket
297
298template <class BFS, BraketType BKTypeL, BraketType BKTypeR>
299algebra::Wedge<BraketPair<BFS, BKTypeL>, BraketPair<BFS, BKTypeR> > operator^(
300 const BraketPair<BFS, BKTypeL>& L, const BraketPair<BFS, BKTypeR>& R) {
301 return algebra::make_wedge(L, R);
302}
303
304}; // namespace libint2
305
306#endif
ArrayBraket is a lightweight implementation of Braket concept.
Definition src/bin/libint/braket.h:39
bool operator==(const this_type &) const
Comparison function.
Definition src/bin/libint/braket.h:135
LIBINT2_UINT_LEAST64 max_key() const
key lies in range [0,max_key())
Definition src/bin/libint/braket.h:192
static constexpr auto num_particles
The total # of particles.
Definition src/bin/libint/braket.h:49
static constexpr auto num_bf
The total # of basis functions = # of particles (since 1 bf / particle)
Definition src/bin/libint/braket.h:51
unsigned int num_members(unsigned int p) const
Returns the number of BFS for particle p.
Definition src/bin/libint/braket.h:79
LIBINT2_UINT_LEAST64 key() const
Implements Hashable::key()
Definition src/bin/libint/braket.h:180
ArrayBraket()
This one is a very dangerous constructor – do not to use it if at all possible.
Definition src/bin/libint/braket.h:104
void set_member(const BFS &, unsigned int p, unsigned int i=0)
Sets i-th function for particle p.
Definition src/bin/libint/braket.h:164
ArrayBraket< BFS, NP > this_type
This type.
Definition src/bin/libint/braket.h:42
SubIterator * member_subiter(unsigned int p, unsigned int i=0) const
Returns pointer to the SubIterator for i-th BFS of particle p.
Definition src/bin/libint/braket.h:157
unsigned int num_part() const
Returns the number of particles.
Definition src/bin/libint/braket.h:84
bfs_cref member(unsigned int p, unsigned int i=0) const
Returns cref to the i-th function for particle p.
Definition src/bin/libint/braket.h:142
ArrayBraket< typename BFS::iter_type, NP > iter_type
The iterator through ArrayBraket.
Definition src/bin/libint/braket.h:47
BraketPair is a trimmed down version of ArrayBraket specialized for same-particle or different-partic...
Definition src/bin/libint/braket.h:247
bool operator==(const this_type &rhs) const
Comparison function.
Definition src/bin/libint/braket.h:268
BraketPair(const BFS &f1, const BFS &f2)
This one is a very dangerous constructor – do not to use it if at all possible.
Definition src/bin/libint/braket.h:256
BraketPair< BFS, BKType > this_type
This type.
Definition src/bin/libint/braket.h:250
ConstructablePolymorphically is a base for all objects which can be constructed using a std::shared_p...
Definition polyconstr.h:30
SubIteratorBase<T> provides a base class for a sub-iterator class for T.
Definition iter.h:73
Iterator provides a base class for all object iterator classes.
Definition iter.h:43
BraketPair< F, PKet > _pket(const F &f1, const F &f2)
Physicists ket.
Definition src/bin/libint/braket.h:283
BraketPair< F, PBra > _pbra(const F &f1, const F &f2)
Physicists bra.
Definition src/bin/libint/braket.h:278
BraketPair< F, CBra > _cbra(const F &f1, const F &f2)
Chemists bra.
Definition src/bin/libint/braket.h:288
BraketPair< F, CKet > _cket(const F &f1, const F &f2)
Chemists ket.
Definition src/bin/libint/braket.h:293
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24
BraketType
enumerates types of brakets used for describing two-electron integrals: CBra and CKet are bra and ket...
Definition src/bin/libint/braket.h:241
There's no parent.
Definition src/bin/libint/braket.h:44
This is the implementation of the Braket concept used by GenIntegralSet_1_1.
Definition src/bin/libint/braket.h:222
ArrayBraket< BFS, 1 > Result
This defines which Braket implementation to use.
Definition src/bin/libint/braket.h:224
This is the implementation of the Braket concept used by GenIntegralSet_11_11.
Definition src/bin/libint/braket.h:231
ArrayBraket< BFS, 2 > Result
This defines which Braket implementation to use.
Definition src/bin/libint/braket.h:233
TrivialBFSet<T> defines static member result, which is true if T is a basis function set consisting o...
Definition bfset.h:906