20 #ifndef _libint2_src_bin_libint_integral_h_ 21 #define _libint2_src_bin_libint_integral_h_ 23 #include <smart_ptr.h> 27 #include <policy_spec.h> 30 #include <singl_stack.h> 31 #include <class_registry.h> 32 #include <global_macros.h> 40 extern long living_count;
54 virtual unsigned int num_part()
const =0;
57 virtual unsigned int num_func_bra(
unsigned int p)
const =0;
59 virtual unsigned int num_func_ket(
unsigned int p)
const =0;
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;
69 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;
123 static const SafePtr<GenIntegralSet> Instance(
const BraSetType& bra,
const KetSetType& ket,
const AuxQuanta& aux,
const Oper& oper=
Oper());
128 bool equiv(
const SafePtr<DGVertex>& v)
const 130 return PtrComp::equiv(
this,v);
133 virtual unsigned int size()
const;
135 virtual const std::string& label()
const;
137 virtual const std::string& id()
const;
139 virtual std::string description()
const;
142 unsigned int num_part()
const {
return OperType::Properties::np; }
144 virtual unsigned int num_func_bra(
unsigned int p)
const {
return bra_.num_members(p); }
146 virtual unsigned int num_func_ket(
unsigned int p)
const {
return ket_.num_members(p); }
148 typename BraSetType::bfs_cref bra(
unsigned int p,
unsigned int i)
const;
150 typename KetSetType::bfs_cref ket(
unsigned int p,
unsigned int i)
const;
152 typename BraSetType::bfs_ref bra(
unsigned int p,
unsigned int i);
154 typename KetSetType::bfs_ref ket(
unsigned int p,
unsigned int i);
158 typedef Oper OperatorType;
162 const SafePtr<Oper> oper()
const;
164 const BraType& bra()
const;
166 const KetType& ket()
const;
168 const SafePtr<AuxQuanta> aux()
const;
171 DGVertex::KeyReturnType
key()
const {
172 if (key_ == 0) compute_key();
177 void unregister()
const;
181 GenIntegralSet(
const Oper& oper,
const BraSetType& bra,
const KetSetType& ket,
const AuxQuanta& aux);
183 static key_type
compute_key(
const Oper& O,
const BraType& bra,
const KetType& ket,
const AuxQuanta& aux) {
184 #define TEST_KEYTYPE_SAFETY 0 185 #if TEST_KEYTYPE_SAFETY 186 key_type remainder = UINT64_MAX;
187 remainder /= (key_type)aux.max_key(); assert(remainder != 0);
188 remainder /= (key_type)ket.
max_key(); assert(remainder != 0);
189 remainder /= (key_type)bra.
max_key(); assert(remainder != 0);
190 remainder /= (key_type)O.max_key; assert(remainder != 0);
195 key = ( (key_type(O.key()) * KeyTypes::cast(bra.
max_key()) + KeyTypes::cast(bra.
key()) ) * KeyTypes::cast(ket.
max_key()) +
196 KeyTypes::cast(ket.
key()) ) * KeyTypes::cast(aux.max_key()) + KeyTypes::cast(aux.key());
206 void set_size(
unsigned int sz);
224 static SingletonManagerType singl_manager_;
229 SafePtr<AuxQuanta> aux_;
232 mutable unsigned int size_;
235 mutable std::string label_;
237 std::string generate_label()
const;
239 mutable key_type key_;
242 void compute_key()
const {
243 key_ = compute_key(*(O_.get()),bra_,ket_,*(aux_.get()));
248 #if USE_INT_KEY_TO_HASH 250 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
255 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
260 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
265 if (Op::Properties::np != bra.num_part())
266 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");
267 if (Op::Properties::np != ket.num_part())
268 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");
271 std::cout <<
"GenIntegralSet: constructed " << label() << std::endl;
272 std::cout <<
"GenIntegralSet: living_count = " << ++living_count << std::endl;
276 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
280 std::cout <<
"GenIntegralSet: destructed " << 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>
286 const SafePtr< GenIntegralSet<Op,BFS,BraSetType,KetSetType,AuxQuanta> >
289 typedef typename SingletonManagerType::value_type map_value_type;
290 key_type key = compute_key(oper,bra,ket,aux);
291 const map_value_type& val = singl_manager_.find(key);
293 SafePtr<this_type> this_int(
new this_type(oper,bra,ket,aux));
295 const map_value_type& val = singl_manager_.find(this_int);
296 val.second->instid_ = val.first;
303 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
304 typename BraSetType::bfs_cref
307 return bra_.member(p,i);
310 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
311 typename KetSetType::bfs_cref
314 return ket_.member(p,i);
317 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
318 typename BraSetType::bfs_ref
322 return bra_.member(p,i);
325 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
326 typename KetSetType::bfs_ref
330 return ket_.member(p,i);
333 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
334 const typename GenIntegralSet<Op,BFS,BraSetType,KetSetType,AuxQuanta>::BraType&
340 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
341 const typename GenIntegralSet<Op,BFS,BraSetType,KetSetType,AuxQuanta>::KetType&
347 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
354 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
355 const SafePtr<AuxQuanta>
361 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
365 #if USE_INT_KEY_TO_COMPARE 366 return key() == a.
key();
369 if (!aux_equiv)
return false;
372 if (!bra_equiv)
return false;
374 if (!ket_equiv)
return false;
379 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
383 singl_manager_.remove(const_pointer_cast<this_type,const this_type>(EnableSafePtrFromThis<this_type>::SafePtr_from_this()));
386 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
393 #if COMPUTE_SIZE_DIRECTLY 396 size_ = bra_.
size() * ket_.size() * O_->num_oper();
399 SafePtr<this_type> this_ptr = const_pointer_cast<this_type,
const this_type>(EnableSafePtrFromThis<GenIntegralSet>::SafePtr_from_this());
401 size_ = siter->num_iter();
403 throw std::runtime_error(
"GenIntegralSet<Op,BFS,BraSetType,KetSetType,AuxQuanta>::size() -- size is 0");
409 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
416 template <
class BraSetType,
class KetSetType,
class AuxQuanta,
class Op>
418 genintegralset_label(
const BraSetType& bra,
const KetSetType& ket,
const SafePtr<AuxQuanta>& aux,
const SafePtr<Op>& O)
422 for(
unsigned int p=0; p<Op::Properties::np; p++) {
423 unsigned int nbra = bra.num_members(p);
424 for(
unsigned int i=0; i<nbra; i++)
426 os << bra.member(p,i).label() <<
"(" << p <<
") ";
428 os << bra.member(p,i)->label() <<
"(" << p <<
") ";
431 os <<
"| " << O->label() <<
" | ";
432 for(
unsigned int p=0; p<Op::Properties::np; p++) {
433 unsigned int nket = ket.num_members(p);
434 for(
unsigned int i=0; i<nket; i++)
436 os << ket.member(p,i).label() <<
"(" << p <<
") ";
438 os << ket.member(p,i)->label() <<
"(" << p <<
") ";
441 os <<
"> ^ { " << aux->label() <<
" }";
445 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
450 label_ = generate_label();
454 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
458 return genintegralset_label(bra_,ket_,aux_,O_);
461 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
468 template <
class Op,
class BFS,
class BraSetType,
class KetSetType,
class AuxQuanta>
473 os <<
" GenIntegralSet: " << label();
474 const std::string descr = os.str();
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
IntegralSet< BFS > parent_type
GenIntegralSet is derived from IntegralSet.
Definition: integral.h:98
SingletonStack<T,KeyType> helps to implement Singleton-like objects of type T.
Definition: singl_stack.h:42
LIBINT2_UINT_LEAST64 max_key() const
key lies in range [0,max_key())
Definition: braket.h:362
unsigned int num_part() const
Implementation of IntegralSet::num_part.
Definition: integral.h:142
virtual unsigned int num_func_bra(unsigned int p) const
Implementation of IntegralSet::num_func_bra.
Definition: integral.h:144
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
GenIntegralSet is a set of integrals over functions derived from BFS.
Definition: integral.h:89
Definition: stdarray.h:18
This is a vertex of a Directed Graph (DG)
Definition: dgvertex.h:42
virtual bool this_precomputed() const
Specialization of DGVertex::this_precomputed()
Definition: integral.h:208
bool equiv(const SafePtr< DGVertex > &v) const
Specialization of DGVertex::equiv()
Definition: integral.h:128
SubIteratorBase<T> provides a base class for a sub-iterator class for T.
Definition: iter.h:72
LIBINT2_UINT_LEAST64 key() const
Implements Hashable::key()
Definition: braket.h:349
QuantumNumbersA<T,N> is a set of N quantum numbers of type T implemented in terms of a C-style array...
Definition: quanta.h:198
PtrEquiv<T> provides a set of comparison functions named 'equiv' which take as arguments a mix of ref...
Definition: equiv.h:35
Oper is OperSet characterized by properties Props.
Definition: oper.h:82
BraSetType::bfs_type BasisFunctionType
This is the real type of basis functions.
Definition: integral.h:111
PtrEquiv< GenIntegralSet > PtrComp
This type provides comparison operations on pointers to GenIntegralSet.
Definition: integral.h:100
virtual unsigned int num_func_ket(unsigned int p) const
Implementation of IntegralSet::num_func_ket.
Definition: integral.h:146
virtual unsigned int size() const
Specialization of DGVertex::size()
Definition: integral.h:388
This is an abstract base for sets of all types of integrals.
Definition: integral.h:48
Objects of this type provide limited information about the class at runtime.
Definition: class_registry.h:43
DGVertex::KeyReturnType key() const
Implements Hashable::key()
Definition: integral.h:171
void reset_cache()
Resets all cached values.
Definition: integral.h:210
ArrayBraket is a lightweight implementation of Braket concept.
Definition: braket.h:214
Oper OperType
This is the type of the operator.
Definition: integral.h:109
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:183