LIBINT  2.6.0
integral_11_11.h
1 /*
2  * Copyright (C) 2004-2019 Edward F. Valeev
3  *
4  * This file is part of Libint.
5  *
6  * Libint 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 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. 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 
26 using namespace std;
27 
28 namespace libint2 {
29 
33  template <class BFS, class Oper, class AuxQuanta = EmptySet> class GenIntegralSet_11_11 :
34  public GenIntegralSet< Oper, IncableBFSet, typename DefaultTwoPBraket<BFS>::Result, typename DefaultTwoPBraket<BFS>::Result, AuxQuanta >
35  {
36  public:
37  typedef BFS BasisFunctionType;
38  typedef Oper OperType;
39  typedef typename DefaultTwoPBraket<BFS>::Result BraType;
40  typedef typename DefaultTwoPBraket<BFS>::Result KetType;
41  typedef AuxQuanta AuxIndexType;
44 
47  typedef typename parent_type::key_type key_type;
52 
58  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());
61  static const SafePtr<this_type>
63  const AuxIndexType& aux = AuxIndexType(), const OperType& oper = OperType()) {
64  return Instance(braket_wedge.left[0],
65  braket_wedge.right[0],
66  braket_wedge.left[1],
67  braket_wedge.right[1],
68  aux,
69  oper);
70  }
73  static const SafePtr<this_type>
75  const AuxIndexType& aux = AuxIndexType(), const OperType& oper = OperType()) {
76  return Instance(braket_wedge.left[0],
77  braket_wedge.left[1],
78  braket_wedge.right[0],
79  braket_wedge.right[1],
80  aux,
81  oper);
82  }
87  static const SafePtr<this_type> Instance(const BraType& bra, const KetType& ket, const AuxIndexType& aux = AuxIndexType(), const OperType& oper = OperType());
89 
91  bool operator==(const this_type&) const;
92 
94  void unregister() const;
95 
97  bool auto_unroll() const;
98 
99  private:
101  GenIntegralSet_11_11(const OperType& oper, const BraType& bra, const KetType& ket, const AuxIndexType& aux);
102 
103  // This is used to manage GenIntegralSet objects as singletons
104  static SingletonManagerType singl_manager_;
105 
107  bool this_precomputed() const;
108 
109  };
110 
111 #if USE_INT_KEY_TO_HASH
112  template <class BFS, class Oper, class AuxQuanta>
113  typename GenIntegralSet_11_11<BFS,Oper,AuxQuanta>::SingletonManagerType
114  GenIntegralSet_11_11<BFS,Oper,AuxQuanta>::singl_manager_(&this_type::key);
115 #else
116 # error "USE_INT_KEY_TO_HASH must be set"
117 #endif
118 
119  template <class BFS, class Oper, class AuxQuanta>
120  GenIntegralSet_11_11<BFS,Oper,AuxQuanta>::GenIntegralSet_11_11(const OperType& oper, const BraType& bra, const KetType& ket, const AuxIndexType& aux) :
121  parent_type(oper, bra, ket, aux)
122  {
123  if (bra.num_members(0) != 1)
124  throw std::runtime_error("GenIntegralSet_11_11::GenIntegralSet_11_11(bra,ket) -- number of BFSs in bra for particle 0 must be 1");
125  if (bra.num_members(1) != 1)
126  throw std::runtime_error("GenIntegralSet_11_11::GenIntegralSet_11_11(bra,ket) -- number of BFSs in bra for particle 1 must be 1");
127  if (ket.num_members(0) != 1)
128  throw std::runtime_error("GenIntegralSet_11_11::GenIntegralSet_11_11(bra,ket) -- number of BFSs in ket for particle 0 must be 1");
129  if (ket.num_members(1) != 1)
130  throw std::runtime_error("GenIntegralSet_11_11::GenIntegralSet_11_11(bra,ket) -- number of BFSs in ket for particle 1 must be 1");
131 #if DEBUG
132  std::cout << "GenIntegralSet_11_11: constructed " << this->label() << std::endl;
133 #endif
134  }
135 
136  template <class BFS, class Oper, class AuxQuanta>
137  GenIntegralSet_11_11<BFS,Oper,AuxQuanta>::~GenIntegralSet_11_11()
138  {
139 #if DEBUG
140  std::cout << "GenIntegralSet_11_11: destructed " << this->label() << std::endl;
141 #endif
142  }
143 
144  template <class BFS, class Oper, class AuxQuanta>
145  const SafePtr< GenIntegralSet_11_11<BFS,Oper,AuxQuanta> >
147  const AuxIndexType& aux, const OperType& oper)
148  {
149  typedef typename SingletonManagerType::value_type map_value_type;
150  key_type key = parent_type::compute_key(oper,bra,ket,aux);
151  const map_value_type& val = singl_manager_.find(key);
152  if (!val.second) {
153  SafePtr<this_type> this_int(new this_type(oper,bra,ket,aux));
154  // Use singl_manager_ to make sure this is a new object of this type
155  const typename SingletonManagerType::value_type& val = singl_manager_.find(this_int);
156  val.second->instid_ = val.first;
157  return val.second;
158  }
159  return val.second;
160  }
161 
162  template <class BFS, class Oper, class AuxQuanta>
163  const SafePtr< GenIntegralSet_11_11<BFS,Oper,AuxQuanta> >
164  GenIntegralSet_11_11<BFS,Oper,AuxQuanta>::Instance(const BFS& bra0, const BFS& ket0, const BFS& bra1, const BFS& ket1,
165  const AuxIndexType& aux, const OperType& oper)
166  {
167 #if USE_BRAKET_H
168  typedef BFS BFSRef;
169  BFSRef bra0_ref(bra0);
170  BFSRef bra1_ref(bra1);
171  BFSRef ket0_ref(ket0);
172  BFSRef ket1_ref(ket1);
173 #else
174  typedef SafePtr<BFS> BFSRef;
175  BFSRef bra0_ref(new BFS(bra0));
176  BFSRef bra1_ref(new BFS(bra1));
177  BFSRef ket0_ref(new BFS(ket0));
178  BFSRef ket1_ref(new BFS(ket1));
179 #endif
180  vector<BFSRef> vbra0; vbra0.push_back(bra0_ref);
181  vector<BFSRef> vbra1; vbra1.push_back(bra1_ref);
182  vector<BFSRef> vket0; vket0.push_back(ket0_ref);
183  vector<BFSRef> vket1; vket1.push_back(ket1_ref);
184  vector< vector<BFSRef> > vvbra; vvbra.push_back(vbra0); vvbra.push_back(vbra1);
185  vector< vector<BFSRef> > vvket; vvket.push_back(vket0); vvket.push_back(vket1);
186  BraType bra(vvbra);
187  KetType ket(vvket);
188  return Instance(bra,ket,aux,oper);
189  }
190 
191  template <class BFS, class Oper, class AuxQuanta>
192  bool
194  {
195  return parent_type::PtrComp::equiv(static_cast<const parent_type*>(this),a);
196  }
197 
198  template <class BFS, class Oper, class AuxQuanta>
199  void
201  {
202  SafePtr<parent_type> this_parent_ptr = const_pointer_cast<parent_type,const parent_type>(EnableSafePtrFromThis<parent_type>::SafePtr_from_this());
203  SafePtr<this_type> this_ptr = static_pointer_cast<this_type>(this_parent_ptr);
204  singl_manager_.remove(this_ptr);
205  }
206 
207  // this_precomputed() and auto_unroll() will be specialized, the nonspecialized version is in integral_11_11.impl.h
208 };
209 
210 #endif
211 
bool operator==(const this_type &) const
Comparison operator.
Definition: integral_11_11.h:193
SingletonStack<T,KeyType> helps to implement Singleton-like objects of type T.
Definition: singl_stack.h:43
unsigned int num_members(unsigned int p) const
Returns the number of BFS for particle p.
Definition: braket.h:75
virtual const std::string & label() const
Specialization of DGVertex::label()
Definition: integral.h:458
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
GenIntegralSet is a set of integrals over functions derived from BFS.
Definition: integral.h:91
void unregister() const
Reimplements DGVertex::unregister()
Definition: integral_11_11.h:200
Wedge is a typeholder for the result of a wedge product.
Definition: algebra.h:246
Generic integral over a two-body operator with one bfs for each particle in bra and ket.
Definition: integral_11_11.h:33
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:62
PtrEquiv<T> provides a set of comparison functions named 'equiv' which take as arguments a mix of ref...
Definition: equiv.h:36
Oper is OperSet characterized by properties Props.
Definition: oper.h:90
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:46
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:49
BraketPair is a trimmed down version of ArrayBraket specialized for same-particle or different-partic...
Definition: braket.h:244
ArrayBraket is a lightweight implementation of Braket concept.
Definition: braket.h:38
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:74
PtrEquiv< this_type > PtrComp
This class provides comparison operations on pointers.
Definition: integral_11_11.h:51
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())
This "constructor" takes basis function sets, in Mulliken ordering.
Definition: integral_11_11.h:164