LIBINT  2.1.0-stable
r1dotr1g12_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_r1dotr1g121111_h_
21 #define _libint2_src_bin_libint_r1dotr1g121111_h_
22 
23 #include <integral.h>
24 
25 using namespace std;
26 
27 namespace libint2 {
28 
29 #if 0
30 
34  template <class BFS> class R1dotR1G12_11_11 :
35  public GenIntegralSet< R1dotR1_G12, IncableBFSet, typename DefaultTwoPBraket<BFS>::Result, typename DefaultTwoPBraket<BFS>::Result, EmptySet >
36  {
37  public:
38  typedef BFS BasisFunctionType;
39  typedef R1dotR1_G12 OperType;
40  typedef typename DefaultTwoPBraket<BFS>::Result BraType;
41  typedef typename DefaultTwoPBraket<BFS>::Result KetType;
42  typedef EmptySet AuxIndexType;
43  typedef R1dotR1G12_11_11<BFS> this_type;
44 
51 
52  typedef typename parent_type::key_type key_type;
55 
56  /* This "constructor" takes basis function sets, in Mulliken ordering.
57  Returns a pointer to a unique instance, a la Singleton
58  */
59  static const SafePtr<R1dotR1G12_11_11> Instance(const BFS& bra0, const BFS& ket0, const BFS& bra1, const BFS& ket1);
61  static const SafePtr<R1dotR1G12_11_11> Instance(const BraType& bra, const KetType& ket, const AuxIndexType& aux);
63 
65  bool operator==(const this_type&) const;
66 #if OVERLOAD_GENINTEGRALSET_LABEL
67  const std::string& label() const;
69 #endif
70 
71  private:
72  // This constructor is also private and not implemented since all Integral's are Singletons. Use Instance instead.
73  R1dotR1G12_11_11(const BraType& bra, const KetType& ket, const AuxIndexType& aux);
74 
75  // This is used to manage GenIntegralSet objects as singletons
76  static SingletonManagerType singl_manager_;
77 
79  bool this_precomputed() const;
80 #if OVERLOAD_GENINTEGRALSET_LABEL
81  mutable std::string label_;
82 #endif
83 
84  };
85 
86 #if USE_INT_KEY_TO_HASH
87  template <class BFS>
90 #else
91 # error "USE_INT_KEY_TO_HASH must be set"
92 #endif
93 
94  template <class BFS>
95  R1dotR1G12_11_11<BFS>::R1dotR1G12_11_11(const BraType& bra, const KetType& ket, const AuxIndexType& aux) :
96  parent_type(R1dotR1_G12(),bra, ket, aux)
97  {
98  if (bra.num_members(0) != 1)
99  throw std::runtime_error("R1dotR1G12_11_11<BFS>::R1dotR1G12_11_11(bra,ket) -- number of BFSs in bra for particle 0 must be 1");
100  if (bra.num_members(1) != 1)
101  throw std::runtime_error("R1dotR1G12_11_11<BFS>::R1dotR1G12_11_11(bra,ket) -- number of BFSs in bra for particle 1 must be 1");
102  if (ket.num_members(0) != 1)
103  throw std::runtime_error("R1dotR1G12_11_11<BFS>::R1dotR1G12_11_11(bra,ket) -- number of BFSs in ket for particle 0 must be 1");
104  if (ket.num_members(1) != 1)
105  throw std::runtime_error("R1dotR1G12_11_11<BFS>::R1dotR1G12_11_11(bra,ket) -- number of BFSs in ket for particle 1 must be 1");
106 #if DEBUG
107  std::cout << "R1dotR1G12_11_11: constructed " << this->label() << std::endl;
108 #endif
109  }
110 
111  template <class BFS>
113  {
114 #if DEBUG
115  std::cout << "R1dotR1G12_11_11: destructed " << this->label() << std::endl;
116 #endif
117  }
118 
119  template <class BFS>
120  const SafePtr< R1dotR1G12_11_11<BFS> >
121  R1dotR1G12_11_11<BFS>::Instance(const BraType& bra, const KetType& ket, const AuxIndexType& aux)
122  {
123  typedef typename SingletonManagerType::value_type map_value_type;
124  key_type key = compute_key(OperType(),bra,ket,aux);
125  const map_value_type& val = singl_manager_.find(key);
126  if (!val.second) {
127  SafePtr<R1dotR1G12_11_11> this_int(new R1dotR1G12_11_11<BFS>(bra,ket,aux));
128  // Use singl_manager_ to make sure this is a new object of this type
129  const typename SingletonManagerType::value_type& val = singl_manager_.find(this_int);
130  val.second->instid_ = val.first;
131  return val.second;
132  }
133  return val.second;
134  }
135 
136  template <class BFS>
137  const SafePtr< R1dotR1G12_11_11<BFS> >
138  R1dotR1G12_11_11<BFS>::Instance(const BFS& bra0, const BFS& ket0, const BFS& bra1, const BFS& ket1)
139  {
140 #if USE_BRAKET_H
141  typedef BFS BFSRef;
142  BFSRef bra0_ref(bra0);
143  BFSRef bra1_ref(bra1);
144  BFSRef ket0_ref(ket0);
145  BFSRef ket1_ref(ket1);
146 #else
147  typedef SafePtr<BFS> BFSRef;
148  BFSRef bra0_ref(new BFS(bra0));
149  BFSRef bra1_ref(new BFS(bra1));
150  BFSRef ket0_ref(new BFS(ket0));
151  BFSRef ket1_ref(new BFS(ket1));
152 #endif
153  vector<BFSRef> vbra0; vbra0.push_back(bra0_ref);
154  vector<BFSRef> vbra1; vbra1.push_back(bra1_ref);
155  vector<BFSRef> vket0; vket0.push_back(ket0_ref);
156  vector<BFSRef> vket1; vket1.push_back(ket1_ref);
157  vector< vector<BFSRef> > vvbra; vvbra.push_back(vbra0); vvbra.push_back(vbra1);
158  vector< vector<BFSRef> > vvket; vvket.push_back(vket0); vvket.push_back(vket1);
159  BraType bra(vvbra);
160  KetType ket(vvket);
161  AuxIndexType aux(vector<int>(0));
162  return Instance(bra,ket,aux);
163  }
164 
165  template <class BFS>
166  bool
168  {
169  return parent_type::PtrComp::equiv(static_cast<const parent_type*>(this),a);
170  }
171 
172 #if OVERLOAD_GENINTEGRALSET_LABEL
173  template <class BFS>
174  const std::string&
176  {
177  if (label_.empty()) {
178  ostringstream os;
179  os << "(" << parent_type::bra_.member(0,0)->label() << " "
180  << parent_type::ket_.member(0,0)->label()
181  << " | r_1^2 * G12 | "
182  << parent_type::bra_.member(1,0)->label() << " "
183  << parent_type::ket_.member(1,0)->label() << ")";
184  label_ = os.str();
185  }
186  return label_;
187  };
188 #endif
189 
190  template <class BFS>
191  bool
193  {
194  return false;
195  }
196 
200 #endif
201 };
202 
203 #endif
204 
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
R1dotR1G12_11_11 – integral over R1dotR1_G12 operator with one bfs for each particle in bra and ket...
Definition: integral_decl.h:39
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
PtrEquiv< this_type > PtrComp
This class provides comparison operations on pointers.
Definition: r1dotr1g12_11_11.h:50
Definition: stdarray.h:18
bool operator==(const this_type &) const
Comparison operator.
Definition: r1dotr1g12_11_11.h:167
const std::string & label() const
Specialization of GenIntegralSet::label()
Definition: r1dotr1g12_11_11.h:175
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
const value_type & find(const SafePtr< T > &obj)
Returns the pointer to the unique instance of object obj.
Definition: singl_stack.h:79
SingletonStack< R1dotR1G12_11_11, key_type > SingletonManagerType
This the type of the object that manages GenIntegralSet&#39;s as Singletons.
Definition: r1dotr1g12_11_11.h:54
PtrEquiv<T> provides a set of comparison functions named &#39;equiv&#39; which take as arguments a mix of ref...
Definition: equiv.h:35
GenIntegralSet< OperType, IncableBFSet, BraType, KetType, AuxIndexType > parent_type
This is the immediate parent.
Definition: r1dotr1g12_11_11.h:48
R1dotR1G12_11_11< CGShell > R1dotR1G12_11_11_sq
the following typedefs are useful
Definition: r1dotr1g12_11_11.h:198
ArrayBraket is a lightweight implementation of Braket concept.
Definition: braket.h:214
static key_type compute_key(const R1dotR1_G12 &O, const BraType &bra, const KetType &ket, const EmptySet &aux)
computes a key. it&#39;s protected so that derived classes can use it to implement smart caching in const...
Definition: integral.h:183
R1dotR1G12_11_11< typename BFS::iter_type > iter_type
R1dotR1G12_11_11 is a set of these subobjects.
Definition: r1dotr1g12_11_11.h:46
DefaultQuantumNumbers< int, 0 >::Result EmptySet
EmptySet is the type that describes null set of auxiliary indices.
Definition: quanta.h:405