LIBINT  2.1.0-stable
integral_11_11.h
1 /*
2  * This file is a part of Libint.
3  * Copyright (C) 2004-2014 Edward F. Valeev
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see http://www.gnu.org/licenses/.
17  *
18  */
19 
20 #ifndef _libint2_src_bin_libint_integral1111_h_
21 #define _libint2_src_bin_libint_integral1111_h_
22 
23 #include <integral.h>
24 
25 using namespace std;
26 
27 namespace libint2 {
28 
32  template <class BFS, class Oper, class AuxQuanta = EmptySet> class GenIntegralSet_11_11 :
33  public GenIntegralSet< Oper, IncableBFSet, typename DefaultTwoPBraket<BFS>::Result, typename DefaultTwoPBraket<BFS>::Result, AuxQuanta >
34  {
35  public:
36  typedef BFS BasisFunctionType;
37  typedef Oper OperType;
38  typedef typename DefaultTwoPBraket<BFS>::Result BraType;
39  typedef typename DefaultTwoPBraket<BFS>::Result KetType;
40  typedef AuxQuanta AuxIndexType;
43 
46  typedef typename parent_type::key_type key_type;
51 
57  static const SafePtr<this_type> Instance(const BFS& bra0, const BFS& ket0, const BFS& bra1, const BFS& ket1, const AuxIndexType& aux = AuxIndexType(), const OperType& oper = OperType());
60  static const SafePtr<this_type>
62  const AuxIndexType& aux = AuxIndexType(), const OperType& oper = OperType()) {
63  return Instance(braket_wedge.left[0],
64  braket_wedge.right[0],
65  braket_wedge.left[1],
66  braket_wedge.right[1],
67  aux,
68  oper);
69  }
72  static const SafePtr<this_type>
74  const AuxIndexType& aux = AuxIndexType(), const OperType& oper = OperType()) {
75  return Instance(braket_wedge.left[0],
76  braket_wedge.left[1],
77  braket_wedge.right[0],
78  braket_wedge.right[1],
79  aux,
80  oper);
81  }
86  static const SafePtr<this_type> Instance(const BraType& bra, const KetType& ket, const AuxIndexType& aux = AuxIndexType(), const OperType& oper = OperType());
88 
90  bool operator==(const this_type&) const;
91 
93  void unregister() const;
94 
95  private:
97  GenIntegralSet_11_11(const OperType& oper, const BraType& bra, const KetType& ket, const AuxIndexType& aux);
98 
99  // This is used to manage GenIntegralSet objects as singletons
100  static SingletonManagerType singl_manager_;
101 
103  bool this_precomputed() const;
104 
105  };
106 
107 #if USE_INT_KEY_TO_HASH
108  template <class BFS, class Oper, class AuxQuanta>
111 #else
112 # error "USE_INT_KEY_TO_HASH must be set"
113 #endif
114 
115  template <class BFS, class Oper, class AuxQuanta>
116  GenIntegralSet_11_11<BFS,Oper,AuxQuanta>::GenIntegralSet_11_11(const OperType& oper, const BraType& bra, const KetType& ket, const AuxIndexType& aux) :
117  parent_type(oper, bra, ket, aux)
118  {
119  if (bra.num_members(0) != 1)
120  throw std::runtime_error("GenIntegralSet_11_11::GenIntegralSet_11_11(bra,ket) -- number of BFSs in bra for particle 0 must be 1");
121  if (bra.num_members(1) != 1)
122  throw std::runtime_error("GenIntegralSet_11_11::GenIntegralSet_11_11(bra,ket) -- number of BFSs in bra for particle 1 must be 1");
123  if (ket.num_members(0) != 1)
124  throw std::runtime_error("GenIntegralSet_11_11::GenIntegralSet_11_11(bra,ket) -- number of BFSs in ket for particle 0 must be 1");
125  if (ket.num_members(1) != 1)
126  throw std::runtime_error("GenIntegralSet_11_11::GenIntegralSet_11_11(bra,ket) -- number of BFSs in ket for particle 1 must be 1");
127 #if DEBUG
128  std::cout << "GenIntegralSet_11_11: constructed " << this->label() << std::endl;
129 #endif
130  }
131 
132  template <class BFS, class Oper, class AuxQuanta>
134  {
135 #if DEBUG
136  std::cout << "GenIntegralSet_11_11: destructed " << this->label() << std::endl;
137 #endif
138  }
139 
140  template <class BFS, class Oper, class AuxQuanta>
141  const SafePtr< GenIntegralSet_11_11<BFS,Oper,AuxQuanta> >
142  GenIntegralSet_11_11<BFS,Oper,AuxQuanta>::Instance(const BraType& bra, const KetType& ket,
143  const AuxIndexType& aux, const OperType& oper)
144  {
145  typedef typename SingletonManagerType::value_type map_value_type;
146  key_type key = parent_type::compute_key(oper,bra,ket,aux);
147  const map_value_type& val = singl_manager_.find(key);
148  if (!val.second) {
149  SafePtr<this_type> this_int(new this_type(oper,bra,ket,aux));
150  // Use singl_manager_ to make sure this is a new object of this type
151  const typename SingletonManagerType::value_type& val = singl_manager_.find(this_int);
152  val.second->instid_ = val.first;
153  return val.second;
154  }
155  return val.second;
156  }
157 
158  template <class BFS, class Oper, class AuxQuanta>
159  const SafePtr< GenIntegralSet_11_11<BFS,Oper,AuxQuanta> >
160  GenIntegralSet_11_11<BFS,Oper,AuxQuanta>::Instance(const BFS& bra0, const BFS& ket0, const BFS& bra1, const BFS& ket1,
161  const AuxIndexType& aux, const OperType& oper)
162  {
163 #if USE_BRAKET_H
164  typedef BFS BFSRef;
165  BFSRef bra0_ref(bra0);
166  BFSRef bra1_ref(bra1);
167  BFSRef ket0_ref(ket0);
168  BFSRef ket1_ref(ket1);
169 #else
170  typedef SafePtr<BFS> BFSRef;
171  BFSRef bra0_ref(new BFS(bra0));
172  BFSRef bra1_ref(new BFS(bra1));
173  BFSRef ket0_ref(new BFS(ket0));
174  BFSRef ket1_ref(new BFS(ket1));
175 #endif
176  vector<BFSRef> vbra0; vbra0.push_back(bra0_ref);
177  vector<BFSRef> vbra1; vbra1.push_back(bra1_ref);
178  vector<BFSRef> vket0; vket0.push_back(ket0_ref);
179  vector<BFSRef> vket1; vket1.push_back(ket1_ref);
180  vector< vector<BFSRef> > vvbra; vvbra.push_back(vbra0); vvbra.push_back(vbra1);
181  vector< vector<BFSRef> > vvket; vvket.push_back(vket0); vvket.push_back(vket1);
182  BraType bra(vvbra);
183  KetType ket(vvket);
184  return Instance(bra,ket,aux,oper);
185  }
186 
187  template <class BFS, class Oper, class AuxQuanta>
188  bool
190  {
191  return parent_type::PtrComp::equiv(static_cast<const parent_type*>(this),a);
192  }
193 
194  template <class BFS, class Oper, class AuxQuanta>
195  void
197  {
198  SafePtr<parent_type> this_parent_ptr = const_pointer_cast<parent_type,const parent_type>(EnableSafePtrFromThis<parent_type>::SafePtr_from_this());
199  SafePtr<this_type> this_ptr = static_pointer_cast<this_type>(this_parent_ptr);
200  singl_manager_.remove(this_ptr);
201  }
202 
203  template <class BFS, class Oper, class AuxQuanta>
204  bool
206  {
207  return false;
208  }
209 
210 };
211 
212 #endif
213 
SingletonStack<T,KeyType> helps to implement Singleton-like objects of type T.
Definition: singl_stack.h:42
unsigned int num_members(unsigned int p) const
Returns the number of BFS for particle p.
Definition: braket.h:247
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
Wedge is a typeholder for the result of a wedge product.
Definition: algebra.h:245
Generic integral over a two-body operator with one bfs for each particle in bra and ket...
Definition: integral_11_11.h:32
static const SafePtr< 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:61
PtrEquiv<T> provides a set of comparison functions named &#39;equiv&#39; which take as arguments a mix of ref...
Definition: equiv.h:35
Oper is OperSet characterized by properties Props.
Definition: oper.h:82
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:45
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:48
BraketPair is a trimmed down version of ArrayBraket specialized for same-particle or different-partic...
Definition: braket.h:416
ArrayBraket is a lightweight implementation of Braket concept.
Definition: braket.h:214
static const SafePtr< 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:73
PtrEquiv< this_type > PtrComp
This class provides comparison operations on pointers.
Definition: integral_11_11.h:50