LIBINT 2.9.0
integral_11_11.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_integral1111_h_
22#define _libint2_src_bin_libint_integral1111_h_
23
24#include <integral.h>
25
26namespace libint2 {
27
32template <class BFS, class Oper, class AuxQuanta = EmptySet>
34 : public GenIntegralSet<
35 Oper, IncableBFSet, typename DefaultTwoPBraket<BFS>::Result,
36 typename DefaultTwoPBraket<BFS>::Result, AuxQuanta> {
37 public:
38 typedef BFS BasisFunctionType;
39 typedef Oper OperType;
42 typedef AuxQuanta AuxIndexType;
46
48 typedef GenIntegralSet_11_11<typename BFS::iter_type,
49 typename Oper::iter_type,
50 typename AuxQuanta::iter_type>
52 typedef typename parent_type::key_type key_type;
58
65 static const std::shared_ptr<this_type> Instance(
66 const BFS& bra0, const BFS& ket0, const BFS& bra1, const BFS& ket1,
67 const AuxIndexType& aux = AuxIndexType(),
68 const OperType& oper = OperType());
71 static const std::shared_ptr<this_type> Instance(
73 braket_wedge,
74 const AuxIndexType& aux = AuxIndexType(),
75 const OperType& oper = OperType()) {
76 return Instance(braket_wedge.left[0], braket_wedge.right[0],
77 braket_wedge.left[1], braket_wedge.right[1], aux, oper);
78 }
81 static const std::shared_ptr<this_type> Instance(
83 braket_wedge,
84 const AuxIndexType& aux = AuxIndexType(),
85 const OperType& oper = OperType()) {
86 return Instance(braket_wedge.left[0], braket_wedge.left[1],
87 braket_wedge.right[0], braket_wedge.right[1], aux, oper);
88 }
94 static const std::shared_ptr<this_type> Instance(
95 const BraType& bra, const KetType& ket,
96 const AuxIndexType& aux = AuxIndexType(),
97 const OperType& oper = OperType());
99
101 bool operator==(const this_type&) const;
102
104 void unregister() const;
105
107 bool auto_unroll() const;
108
109 private:
112 GenIntegralSet_11_11(const OperType& oper, const BraType& bra,
113 const KetType& ket, const AuxIndexType& aux);
114
115 // This is used to manage GenIntegralSet objects as singletons
116 static SingletonManagerType singl_manager_;
117
119 bool this_precomputed() const;
120};
121
122#if USE_INT_KEY_TO_HASH
123template <class BFS, class Oper, class AuxQuanta>
125 GenIntegralSet_11_11<BFS, Oper, AuxQuanta>::singl_manager_(&this_type::key);
126#else
127#error "USE_INT_KEY_TO_HASH must be set"
128#endif
129
130template <class BFS, class Oper, class AuxQuanta>
131GenIntegralSet_11_11<BFS, Oper, AuxQuanta>::GenIntegralSet_11_11(
132 const OperType& oper, const BraType& bra, const KetType& ket,
133 const AuxIndexType& aux)
134 : parent_type(oper, bra, ket, aux) {
135 if (bra.num_members(0) != 1)
136 throw std::runtime_error(
137 "GenIntegralSet_11_11::GenIntegralSet_11_11(bra,ket) -- number of BFSs "
138 "in bra for particle 0 must be 1");
139 if (bra.num_members(1) != 1)
140 throw std::runtime_error(
141 "GenIntegralSet_11_11::GenIntegralSet_11_11(bra,ket) -- number of BFSs "
142 "in bra for particle 1 must be 1");
143 if (ket.num_members(0) != 1)
144 throw std::runtime_error(
145 "GenIntegralSet_11_11::GenIntegralSet_11_11(bra,ket) -- number of BFSs "
146 "in ket for particle 0 must be 1");
147 if (ket.num_members(1) != 1)
148 throw std::runtime_error(
149 "GenIntegralSet_11_11::GenIntegralSet_11_11(bra,ket) -- number of BFSs "
150 "in ket for particle 1 must be 1");
151#if DEBUG
152 std::cout << "GenIntegralSet_11_11: constructed " << this->label()
153 << std::endl;
154#endif
155}
156
157template <class BFS, class Oper, class AuxQuanta>
158GenIntegralSet_11_11<BFS, Oper, AuxQuanta>::~GenIntegralSet_11_11() {
159#if DEBUG
160 std::cout << "GenIntegralSet_11_11: destructed " << this->label()
161 << std::endl;
162#endif
163}
164
165template <class BFS, class Oper, class AuxQuanta>
166const std::shared_ptr<GenIntegralSet_11_11<BFS, Oper, AuxQuanta> >
168 const KetType& ket,
169 const AuxIndexType& aux,
170 const OperType& oper) {
171 typedef typename SingletonManagerType::value_type map_value_type;
172 key_type key = parent_type::compute_key(oper, bra, ket, aux);
173 const map_value_type& val = singl_manager_.find(key);
174 if (!val.second) {
175 std::shared_ptr<this_type> this_int(new this_type(oper, bra, ket, aux));
176 // Use singl_manager_ to make sure this is a new object of this type
177 const typename SingletonManagerType::value_type& val =
178 singl_manager_.find(this_int);
179 val.second->instid_ = val.first;
180 return val.second;
181 }
182 return val.second;
183}
184
185template <class BFS, class Oper, class AuxQuanta>
186const std::shared_ptr<GenIntegralSet_11_11<BFS, Oper, AuxQuanta> >
188 const BFS& bra0, const BFS& ket0, const BFS& bra1, const BFS& ket1,
189 const AuxIndexType& aux, const OperType& oper) {
190#if USE_BRAKET_H
191 typedef BFS BFSRef;
192 BFSRef bra0_ref(bra0);
193 BFSRef bra1_ref(bra1);
194 BFSRef ket0_ref(ket0);
195 BFSRef ket1_ref(ket1);
196#else
197 typedef std::shared_ptr<BFS> BFSRef;
198 BFSRef bra0_ref(new BFS(bra0));
199 BFSRef bra1_ref(new BFS(bra1));
200 BFSRef ket0_ref(new BFS(ket0));
201 BFSRef ket1_ref(new BFS(ket1));
202#endif
203 std::vector<BFSRef> vbra0;
204 vbra0.push_back(bra0_ref);
205 std::vector<BFSRef> vbra1;
206 vbra1.push_back(bra1_ref);
207 std::vector<BFSRef> vket0;
208 vket0.push_back(ket0_ref);
209 std::vector<BFSRef> vket1;
210 vket1.push_back(ket1_ref);
211 std::vector<std::vector<BFSRef> > vvbra;
212 vvbra.push_back(vbra0);
213 vvbra.push_back(vbra1);
214 std::vector<std::vector<BFSRef> > vvket;
215 vvket.push_back(vket0);
216 vvket.push_back(vket1);
217 BraType bra(vvbra);
218 KetType ket(vvket);
219 return Instance(bra, ket, aux, oper);
220}
221
222template <class BFS, class Oper, class AuxQuanta>
224 const this_type& a) const {
225 return parent_type::PtrComp::equiv(static_cast<const parent_type*>(this), a);
226}
227
228template <class BFS, class Oper, class AuxQuanta>
230 std::shared_ptr<parent_type> this_parent_ptr =
231 std::const_pointer_cast<parent_type, const parent_type>(
232 std::enable_shared_from_this<parent_type>::shared_from_this());
233 std::shared_ptr<this_type> this_ptr =
234 std::static_pointer_cast<this_type>(this_parent_ptr);
235 singl_manager_.remove(this_ptr);
236}
237
238// this_precomputed() and auto_unroll() will be specialized, the nonspecialized
239// version is in integral_11_11.impl.h
240}; // namespace libint2
241
242#endif
ArrayBraket is a lightweight implementation of Braket concept.
Definition src/bin/libint/braket.h:39
unsigned int num_members(unsigned int p) const
Returns the number of BFS for particle p.
Definition src/bin/libint/braket.h:79
BraketPair is a trimmed down version of ArrayBraket specialized for same-particle or different-partic...
Definition src/bin/libint/braket.h:247
Generic integral over a two-body operator with one bfs for each particle in bra and ket.
Definition integral_11_11.h:36
void unregister() const
Reimplements DGVertex::unregister()
Definition integral_11_11.h:229
static const std::shared_ptr< this_type > Instance(const algebra::Wedge< BraketPair< BFS, CBra >, BraketPair< BFS, CKet > > &braket_wedge, const AuxIndexType &aux=AuxIndexType(), const OperType &oper=OperType())
This "constructor" uses a wedge of 2 chemists brakets.
Definition integral_11_11.h:81
GenIntegralSet_11_11< typename BFS::iter_type, typename Oper::iter_type, typename AuxQuanta::iter_type > iter_type
this is a set of these subobjects
Definition integral_11_11.h:51
static const std::shared_ptr< this_type > Instance(const algebra::Wedge< BraketPair< BFS, PBra >, BraketPair< BFS, PKet > > &braket_wedge, const AuxIndexType &aux=AuxIndexType(), const OperType &oper=OperType())
This "constructor" uses a wedge of 2 physicists brakets.
Definition integral_11_11.h:71
static const std::shared_ptr< this_type > Instance(const BFS &bra0, const BFS &ket0, const BFS &bra1, const BFS &ket1, const AuxIndexType &aux=AuxIndexType(), const OperType &oper=OperType())
This "constructor" takes basis function sets, in Mulliken ordering.
Definition integral_11_11.h:187
PtrEquiv< this_type > PtrComp
This class provides comparison operations on pointers.
Definition integral_11_11.h:57
bool operator==(const this_type &) const
Comparison operator.
Definition integral_11_11.h:223
SingletonStack< this_type, key_type > SingletonManagerType
This the type of the object that manages objects of this type as Singletons.
Definition integral_11_11.h:55
bool auto_unroll() const
Implements GenIntegralSet::auto_unroll()
Definition integral_11_11.impl.h:32
GenIntegralSet is a set of integrals over functions derived from BFS.
Definition integral.h:99
const std::string & label() const override
Specialization of DGVertex::label()
Definition integral.h:525
const BraType & bra() const
Obtain const ref to bra.
Definition integral.h:406
const KetType & ket() const
Obtain const ref to bra.
Definition integral.h:414
const std::shared_ptr< Oper > oper() const
Obtain the operator.
Definition integral.h:421
const std::shared_ptr< AuxQuanta > aux() const
Obtain the auxiliary quanta.
Definition integral.h:428
Oper is OperSet characterized by properties Props.
Definition oper.h:91
PtrEquiv<T> provides a set of comparison functions named 'equiv' which take as arguments a mix of ref...
Definition equiv.h:36
SingletonStack<T,KeyType> helps to implement Singleton-like objects of type T.
Definition singl_stack.h:45
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24
Wedge is a typeholder for the result of a wedge product.
Definition algebra.h:248