LIBINT 2.9.0
integral_1_1.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_integral11_h_
22#define _libint2_src_bin_libint_integral11_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 DefaultOnePBraket<BFS>::Result,
36 typename DefaultOnePBraket<BFS>::Result, AuxQuanta> {
37 public:
38 typedef BFS BasisFunctionType;
39 typedef Oper OperType;
42 typedef AuxQuanta AuxIndexType;
46
48 typedef GenIntegralSet_1_1<typename BFS::iter_type, typename Oper::iter_type,
49 typename AuxQuanta::iter_type>
51 typedef typename parent_type::key_type key_type;
57
64 static const std::shared_ptr<this_type> Instance(
65 const BFS& bra0, const BFS& ket0,
66 const AuxIndexType& aux = AuxIndexType(),
67 const OperType& oper = OperType());
68
69#if 0
72 static const std::shared_ptr<this_type>
74 const AuxIndexType& aux = AuxIndexType(), const OperType& oper = OperType()) {
75 return Instance(braket_wedge.left[0],
76 braket_wedge.right[0],
77 aux,
78 oper);
79 }
82 static const std::shared_ptr<this_type>
84 const AuxIndexType& aux = AuxIndexType(), const OperType& oper = OperType()) {
85 return Instance(braket_wedge.left[0],
86 braket_wedge.left[1],
87 braket_wedge.right[0],
88 braket_wedge.right[1],
89 aux,
90 oper);
91 }
92#endif
93
99 static const std::shared_ptr<this_type> Instance(
100 const BraType& bra, const KetType& ket,
101 const AuxIndexType& aux = AuxIndexType(),
102 const OperType& oper = OperType());
103 virtual ~GenIntegralSet_1_1();
104
106 bool operator==(const this_type&) const;
107
109 void unregister() const;
110
112 bool auto_unroll() const;
113
114 private:
117 GenIntegralSet_1_1(const OperType& oper, const BraType& bra,
118 const KetType& ket, const AuxIndexType& aux);
119
120 // This is used to manage GenIntegralSet objects as singletons
121 static SingletonManagerType singl_manager_;
122
124 bool this_precomputed() const;
125};
126
127#if USE_INT_KEY_TO_HASH
128template <class BFS, class Oper, class AuxQuanta>
130 GenIntegralSet_1_1<BFS, Oper, AuxQuanta>::singl_manager_(&this_type::key);
131#else
132#error "USE_INT_KEY_TO_HASH must be set"
133#endif
134
135template <class BFS, class Oper, class AuxQuanta>
136GenIntegralSet_1_1<BFS, Oper, AuxQuanta>::GenIntegralSet_1_1(
137 const OperType& oper, const BraType& bra, const KetType& ket,
138 const AuxIndexType& aux)
139 : parent_type(oper, bra, ket, aux) {
140 if (bra.num_members(0) != 1)
141 throw std::runtime_error(
142 "GenIntegralSet_1_1::GenIntegralSet_1_1(bra,ket) -- number of BFSs in "
143 "bra for particle 0 must be 1");
144 if (ket.num_members(0) != 1)
145 throw std::runtime_error(
146 "GenIntegralSet_1_1::GenIntegralSet_1_1(bra,ket) -- number of BFSs in "
147 "ket for particle 0 must be 1");
148#if DEBUG
149 std::cout << "GenIntegralSet_1_1: constructed " << this->label() << std::endl;
150#endif
151}
152
153template <class BFS, class Oper, class AuxQuanta>
154GenIntegralSet_1_1<BFS, Oper, AuxQuanta>::~GenIntegralSet_1_1() {
155#if DEBUG
156 std::cout << "GenIntegralSet_1_1: destructed " << this->label() << std::endl;
157#endif
158}
159
160template <class BFS, class Oper, class AuxQuanta>
161const std::shared_ptr<GenIntegralSet_1_1<BFS, Oper, AuxQuanta> >
163 const KetType& ket,
164 const AuxIndexType& aux,
165 const OperType& oper) {
166 typedef typename SingletonManagerType::value_type map_value_type;
167 key_type key = parent_type::compute_key(oper, bra, ket, aux);
168 const map_value_type& val = singl_manager_.find(key);
169 if (!val.second) {
170 std::shared_ptr<this_type> this_int(new this_type(oper, bra, ket, aux));
171 // Use singl_manager_ to make sure this is a new object of this type
172 const typename SingletonManagerType::value_type& val =
173 singl_manager_.find(this_int);
174 val.second->instid_ = val.first;
175 return val.second;
176 }
177 return val.second;
178}
179
180template <class BFS, class Oper, class AuxQuanta>
181const std::shared_ptr<GenIntegralSet_1_1<BFS, Oper, AuxQuanta> >
183 const BFS& ket0,
184 const AuxIndexType& aux,
185 const OperType& oper) {
186#if USE_BRAKET_H
187 typedef BFS BFSRef;
188 BFSRef bra0_ref(bra0);
189 BFSRef ket0_ref(ket0);
190#else
191 typedef std::shared_ptr<BFS> BFSRef;
192 BFSRef bra0_ref(new BFS(bra0));
193 BFSRef ket0_ref(new BFS(ket0));
194#endif
195 std::vector<BFSRef> vbra0;
196 vbra0.push_back(bra0_ref);
197 std::vector<BFSRef> vket0;
198 vket0.push_back(ket0_ref);
199 std::vector<std::vector<BFSRef> > vvbra;
200 vvbra.push_back(vbra0);
201 std::vector<std::vector<BFSRef> > vvket;
202 vvket.push_back(vket0);
203 BraType bra(vvbra);
204 KetType ket(vvket);
205 return Instance(bra, ket, aux, oper);
206}
207
208template <class BFS, class Oper, class AuxQuanta>
210 const this_type& a) const {
211 return parent_type::PtrComp::equiv(static_cast<const parent_type*>(this), a);
212}
213
214template <class BFS, class Oper, class AuxQuanta>
216 std::shared_ptr<parent_type> this_parent_ptr =
217 std::const_pointer_cast<parent_type, const parent_type>(
218 std::enable_shared_from_this<parent_type>::shared_from_this());
219 std::shared_ptr<this_type> this_ptr =
220 std::static_pointer_cast<this_type>(this_parent_ptr);
221 singl_manager_.remove(this_ptr);
222}
223
224// this_precomputed() and auto_unroll() will be specialized, the nonspecialized
225// version is in integral_11_11.impl.h
226}; // namespace libint2
227
228#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 one-body operator with one bfs for each particle in bra and ket.
Definition integral_1_1.h:36
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_1_1.h:73
static const std::shared_ptr< this_type > Instance(const BFS &bra0, const BFS &ket0, const AuxIndexType &aux=AuxIndexType(), const OperType &oper=OperType())
This "constructor" takes basis function sets.
Definition integral_1_1.h:182
PtrEquiv< this_type > PtrComp
This class provides comparison operations on pointers.
Definition integral_1_1.h:56
GenIntegralSet_1_1< typename BFS::iter_type, typename Oper::iter_type, typename AuxQuanta::iter_type > iter_type
this is a set of these subobjects
Definition integral_1_1.h:50
bool auto_unroll() const
Implements GenIntegralSet::auto_unroll()
Definition integral_1_1.impl.h:32
void unregister() const
Reimplements DGVertex::unregister()
Definition integral_1_1.h:215
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_1_1.h:83
bool operator==(const this_type &) const
Comparison operator.
Definition integral_1_1.h:209
SingletonStack< this_type, key_type > SingletonManagerType
This the type of the object that manages objects of this type as Singletons.
Definition integral_1_1.h:54
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