21#ifndef _libint2_src_bin_libint_integral_h_
22#define _libint2_src_bin_libint_integral_h_
29#include <policy_spec.h>
32#include <singl_stack.h>
33#include <class_registry.h>
34#include <global_macros.h>
40extern long living_count;
61 virtual const BasisFunctionSet&
bra(
unsigned int p,
unsigned int i)
const =0;
63 virtual const BasisFunctionSet&
ket(
unsigned int p,
unsigned int i)
const =0;
65 virtual BasisFunctionSet&
bra(
unsigned int p,
unsigned int i) =0;
67 virtual BasisFunctionSet&
ket(
unsigned int p,
unsigned int i) =0;
70 virtual unsigned int np()
const =0;
72 virtual const SafePtr<BasisFunctionSet>
bra(
unsigned int p,
unsigned int i)
const =0;
74 virtual const SafePtr<BasisFunctionSet>
ket(
unsigned int p,
unsigned int i)
const =0;
88 template <
class Oper,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta = EmptySet>
91 public EnableSafePtrFromThis< GenIntegralSet<Oper,BFS,BraSetType,KetSetType,AuxQuanta> >
101#if USE_INT_KEY_TO_HASH
102 typedef mpz_class key_type;
104 typedef std::string key_type;
114 static_assert(BraSetType::num_particles == KetSetType::num_particles,
115 "number of particles in bra and ket must be same");
117 static constexpr auto num_bf = BraSetType::num_bf + KetSetType::num_bf;
134 bool equiv(
const SafePtr<DGVertex>& v)
const override
136 return PtrComp::equiv(
this,v);
139 unsigned int size()
const override;
141 const std::string&
label()
const override;
143 const std::string&
id()
const override;
148 unsigned int num_part()
const override {
return OperType::Properties::np; }
150 unsigned int num_func_bra(
unsigned int p)
const override {
return bra_.num_members(p); }
152 unsigned int num_func_ket(
unsigned int p)
const override {
return ket_.num_members(p); }
154 typename BraSetType::bfs_cref
bra(
unsigned int p,
unsigned int i)
const override;
156 typename KetSetType::bfs_cref
ket(
unsigned int p,
unsigned int i)
const override;
158 typename BraSetType::bfs_ref
bra(
unsigned int p,
unsigned int i)
override;
160 typename KetSetType::bfs_ref
ket(
unsigned int p,
unsigned int i)
override;
168 const SafePtr<Oper>
oper()
const;
174 const SafePtr<AuxQuanta>
aux()
const;
177 DGVertex::KeyReturnType
key()
const override {
193#define TEST_KEYTYPE_SAFETY 0
194#if TEST_KEYTYPE_SAFETY
195 key_type remainder = UINT64_MAX;
196 remainder /= (key_type)
aux.max_key(); assert(remainder != 0);
197 remainder /= (key_type)
ket.max_key(); assert(remainder != 0);
198 remainder /= (key_type)
bra.max_key(); assert(remainder != 0);
199 remainder /= (key_type)O.max_key; assert(remainder != 0);
204 key = ( (key_type(O.key()) * KeyTypes::cast(
bra.max_key()) + KeyTypes::cast(
bra.key()) ) * KeyTypes::cast(
ket.max_key()) +
205 KeyTypes::cast(
ket.key()) ) * KeyTypes::cast(
aux.max_key()) + KeyTypes::cast(
aux.key());
238 SafePtr<AuxQuanta> aux_;
241 mutable unsigned int size_;
244 mutable std::string label_;
246 std::string generate_label() const ;
248 mutable key_type key_;
251 void compute_key()
const {
252 key_ = compute_key(*(O_.get()),bra_,ket_,*(aux_.get()));
257#if USE_INT_KEY_TO_HASH
259 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
264 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
269 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
270 GenIntegralSet<Op,BFS,BraSetType,KetSetType,AuxQuanta>::GenIntegralSet(
const Op& oper,
const BraSetType& bra,
const KetSetType& ket,
const AuxQuanta& aux) :
271 DGVertex(ClassInfo<GenIntegralSet>::Instance().id()), bra_(bra), ket_(ket), O_(SafePtr<Op>(new Op(oper))), aux_(SafePtr<AuxQuanta>(new AuxQuanta(aux))),
274 if (Op::Properties::np !=
bra.num_part())
275 throw std::runtime_error(
"GenIntegralSet<Op,BFS,BraSetType,KetSetType,AuxQuanta>::GenIntegralSet(bra,ket) -- number of particles in bra doesn't match that in the operator");
276 if (Op::Properties::np !=
ket.num_part())
277 throw std::runtime_error(
"GenIntegralSet<Op,BFS,BraSetType,KetSetType,AuxQuanta>::GenIntegralSet(bra,ket) -- number of particles in ket doesn't match that in the operator");
280 std::cout <<
"GenIntegralSet: constructed " <<
label() << std::endl;
281 std::cout <<
"GenIntegralSet: living_count = " << ++living_count << std::endl;
285 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
289 std::cout <<
"GenIntegralSet: destructed " << label() << std::endl;
290 std::cout <<
"GenIntegralSet: living_count = " << --living_count << std::endl;
294 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
295 const SafePtr< GenIntegralSet<Op,BFS,BraSetType,KetSetType,AuxQuanta> >
298 typedef typename SingletonManagerType::value_type map_value_type;
299 key_type key = compute_key(oper,bra,ket,aux);
300 const map_value_type& val = singl_manager_.find(key);
302 SafePtr<this_type> this_int(
new this_type(oper,bra,ket,aux));
304 const map_value_type& val = singl_manager_.find(this_int);
305 val.second->instid_ = val.first;
312 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
313 typename BraSetType::bfs_cref
316 return bra_.member(p,i);
319 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
320 typename KetSetType::bfs_cref
323 return ket_.member(p,i);
326 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
327 typename BraSetType::bfs_ref
331 return bra_.member(p,i);
334 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
335 typename KetSetType::bfs_ref
339 return ket_.member(p,i);
342 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
343 const typename GenIntegralSet<Op,BFS,BraSetType,KetSetType,AuxQuanta>::BraType&
349 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
350 const typename GenIntegralSet<Op,BFS,BraSetType,KetSetType,AuxQuanta>::KetType&
356 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
363 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
364 const SafePtr<AuxQuanta>
370 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
374#if USE_INT_KEY_TO_COMPARE
375 return key() == a.
key();
378 if (!aux_equiv)
return false;
381 if (!bra_equiv)
return false;
383 if (!ket_equiv)
return false;
388 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
392 singl_manager_.remove(const_pointer_cast<this_type,const this_type>(EnableSafePtrFromThis<this_type>::SafePtr_from_this()));
395 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
402#if COMPUTE_SIZE_DIRECTLY
405 size_ = bra_.size() * ket_.size() * O_->num_oper();
408 SafePtr<this_type> this_ptr = const_pointer_cast<this_type,const this_type>(EnableSafePtrFromThis<GenIntegralSet>::SafePtr_from_this());
410 size_ = siter->num_iter();
412 throw std::runtime_error(
"GenIntegralSet<Op,BFS,BraSetType,KetSetType,AuxQuanta>::size() -- size is 0");
418 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
425 template <
class BraSetType,
class KetSetType,
class AuxQuanta,
class Op>
427 genintegralset_label(
const BraSetType& bra,
const KetSetType& ket,
const SafePtr<AuxQuanta>& aux,
const SafePtr<Op>& O)
429 std::ostringstream os;
431 for(
unsigned int p=0; p<Op::Properties::np; p++) {
432 unsigned int nbra = bra.num_members(p);
433 for(
unsigned int i=0; i<nbra; i++)
435 os << bra.member(p,i).label() <<
"(" << p <<
") ";
437 os << bra.member(p,i)->label() <<
"(" << p <<
") ";
440 os <<
"| " << O->label() <<
" | ";
441 for(
unsigned int p=0; p<Op::Properties::np; p++) {
442 unsigned int nket = ket.num_members(p);
443 for(
unsigned int i=0; i<nket; i++)
445 os << ket.member(p,i).label() <<
"(" << p <<
") ";
447 os << ket.member(p,i)->label() <<
"(" << p <<
") ";
450 os <<
"> ^ { " << aux->label() <<
" }";
454 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
459 label_ = generate_label();
463 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
467 return genintegralset_label(bra_,ket_,aux_,O_);
470 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
477 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
481 std::ostringstream os;
482 os <<
" GenIntegralSet: " << label();
483 const std::string descr = os.str();
ArrayBraket is a lightweight implementation of Braket concept.
Definition: src/bin/libint/braket.h:38
This is a vertex of a Directed Graph (DG)
Definition: dgvertex.h:43
GenIntegralSet is a set of integrals over functions derived from BFS.
Definition: integral.h:92
const std::string & label() const override
Specialization of DGVertex::label()
Definition: integral.h:456
GenIntegralSet< typename Oper::iter_type, BFS, typename BraSetType::iter_type, typename KetSetType::iter_type, typename AuxQuanta::iter_type > iter_type
GenIntegralSet is a set of these subobjects.
Definition: integral.h:96
virtual bool operator==(const GenIntegralSet &) const
Comparison operator.
Definition: integral.h:372
BraSetType::bfs_cref bra(unsigned int p, unsigned int i) const override
Implementation of IntegralSet::bra() const.
Definition: integral.h:314
const BraType & bra() const
Obtain const ref to bra.
Definition: integral.h:344
unsigned int num_func_bra(unsigned int p) const override
Implementation of IntegralSet::num_func_bra.
Definition: integral.h:150
virtual ~GenIntegralSet()
No constructors are public since this is a singleton-like quantity.
Definition: integral.h:286
virtual bool auto_unroll() const
If consists of precomputed elements, override this to return true.
Definition: integral.h:186
std::string description() const override
Specialization of DGVertex::description()
Definition: integral.h:479
static constexpr auto num_particles
The number of particles.
Definition: integral.h:113
IntegralSet< BFS > parent_type
GenIntegralSet is derived from IntegralSet.
Definition: integral.h:98
Oper OperType
This is the type of the operator.
Definition: integral.h:109
DGVertex::KeyReturnType key() const override
Implements Hashable::key()
Definition: integral.h:177
bool equiv(const SafePtr< DGVertex > &v) const override
Specialization of DGVertex::equiv()
Definition: integral.h:134
BraSetType::bfs_ref bra(unsigned int p, unsigned int i) override
Implementation of IntegralSet::bra()
Definition: integral.h:328
bool this_precomputed() const override
Specialization of DGVertex::this_precomputed()
Definition: integral.h:217
const KetType & ket() const
Obtain const ref to bra.
Definition: integral.h:351
BraSetType::bfs_type BasisFunctionType
This is the real type of basis functions.
Definition: integral.h:111
static key_type compute_key(const Oper &O, const BraType &bra, const KetType &ket, const AuxQuanta &aux)
computes a key. it's protected so that derived classes can use it to implement smart caching in const...
Definition: integral.h:192
const SafePtr< AuxQuanta > aux() const
Obtain the auxiliary quanta.
Definition: integral.h:365
unsigned int num_func_ket(unsigned int p) const override
Implementation of IntegralSet::num_func_ket.
Definition: integral.h:152
KetSetType::bfs_cref ket(unsigned int p, unsigned int i) const override
Implementation of IntegralSet::ket() const.
Definition: integral.h:321
unsigned int num_part() const override
Implementation of IntegralSet::num_part.
Definition: integral.h:148
void unregister() const override
Reimplements DGVertex::unregister()
Definition: integral.h:390
const std::string & id() const override
Specialization of DGVertex::id()
Definition: integral.h:472
static constexpr auto num_bf
The total number of basis functions.
Definition: integral.h:117
void set_size(unsigned int sz)
set size to sz
Definition: integral.h:420
SingletonStack< GenIntegralSet, key_type > SingletonManagerType
This the type of the object that manages GenIntegralSet's as Singletons.
Definition: integral.h:107
PtrEquiv< GenIntegralSet > PtrComp
This type provides comparison operations on pointers to GenIntegralSet.
Definition: integral.h:100
unsigned int size() const override
Specialization of DGVertex::size()
Definition: integral.h:397
KetSetType::bfs_ref ket(unsigned int p, unsigned int i) override
Implementation of IntegralSet::ket()
Definition: integral.h:336
static const SafePtr< GenIntegralSet > Instance(const BraSetType &bra, const KetSetType &ket, const AuxQuanta &aux, const Oper &oper=Oper())
Returns a pointer to a unique instance, a la Singleton.
Definition: integral.h:296
void reset_cache()
Resets all cached values.
Definition: integral.h:219
const SafePtr< Oper > oper() const
Obtain the operator.
Definition: integral.h:358
This is an abstract base for sets of all types of integrals.
Definition: integral.h:48
virtual unsigned int num_func_ket(unsigned int p) const =0
Return the number of functions for particle p.
virtual unsigned int num_part() const =0
Return the number of particles.
virtual BasisFunctionSet & ket(unsigned int p, unsigned int i)=0
Obtain pointers to ith BasisFunctionSet for particle p in ket.
virtual const BasisFunctionSet & bra(unsigned int p, unsigned int i) const =0
Obtain pointers to ith BasisFunctionSet for particle p in bra.
virtual const BasisFunctionSet & ket(unsigned int p, unsigned int i) const =0
Obtain pointers to ith BasisFunctionSet for particle p in ket.
virtual unsigned int np() const =0
Return the number of particles.
virtual unsigned int num_func_bra(unsigned int p) const =0
Return the number of functions for particle p.
virtual const SafePtr< BasisFunctionSet > bra(unsigned int p, unsigned int i) const =0
Obtain pointers to ith BasisFunctionSet for particle p in bra.
virtual BasisFunctionSet & bra(unsigned int p, unsigned int i)=0
Obtain pointers to ith BasisFunctionSet for particle p in bra.
virtual const SafePtr< BasisFunctionSet > ket(unsigned int p, unsigned int i) const =0
Obtain pointers to ith BasisFunctionSet for particle p in ket.
Oper is OperSet characterized by properties Props.
Definition: oper.h:90
PtrEquiv<T> provides a set of comparison functions named 'equiv' which take as arguments a mix of ref...
Definition: equiv.h:36
QuantumNumbersA<T,N> is a set of N quantum numbers of type T implemented in terms of a C-style array.
Definition: quanta.h:197
SingletonStack<T,KeyType> helps to implement Singleton-like objects of type T.
Definition: singl_stack.h:44
SubIteratorBase<T> provides a base class for a sub-iterator class for T.
Definition: iter.h:70
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24