LIBINT  2.6.0
prefactors.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_prefactors_h_
22 #define _libint2_src_bin_libint_prefactors_h_
23 
24 #include <cstring>
25 #include <smart_ptr.h>
26 #include <entity.h>
27 #include <bfset.h>
28 #include <singl_stack.h>
29 
30 #define CTIMEENTITIES_SINGLETONS 1
31 
32 namespace libint2 {
33 
40  class Prefactors {
41  public:
42  Prefactors();
43  ~Prefactors();
44 
47 
48  static const unsigned int NMAX = 200;
49  static const unsigned int np = 2;
50  static const unsigned int nfunc_per_part = 1;
51 
56  SafePtr<rdouble> vX_Y[np];
58  SafePtr<rdouble> X_Y[np][3];
59 
64  SafePtr<rdouble> vY_X[np];
66  SafePtr<rdouble> Y_X[np][3];
67 
75  SafePtr<rdouble> vXY_X[np][2];
77  SafePtr<rdouble> XY_X[np][2][3];
82  SafePtr<rdouble> vW_XY[np];
84  SafePtr<rdouble> W_XY[np][3];
85 
89  SafePtr<rdouble> zeta[np][2];
93  SafePtr<rdouble> zeta2[np][2];
94 
100  SafePtr<rdouble> alpha12[np];
102  SafePtr<rdouble> rho;
104  SafePtr<rdouble> one_o_2alpha12[np];
106  SafePtr<rdouble> rho_o_alpha12[np];
108  SafePtr<rdouble> one_o_2alphasum;
109 
113  SafePtr<rdouble> TwoPRepITR_vpfac0[np];
116  SafePtr<rdouble> TwoPRepITR_pfac0[np][3];
118  SafePtr<rdouble> TwoPRepITR_pfac1[np];
121 
125  SafePtr<rdouble> R12kG12VRR_vpfac0[np];
128  SafePtr<rdouble> R12kG12VRR_pfac0[np][3];
130  SafePtr<rdouble> R12kG12VRR_pfac1[np];
132  SafePtr<rdouble> R12kG12VRR_pfac2;
134  SafePtr<rdouble> R12kG12VRR_pfac3[np];
136  SafePtr<rdouble> R12kG12VRR_vpfac4[np];
138  SafePtr<rdouble> R12kG12VRR_pfac4[np][3];
139 
143  SafePtr<rdouble> Overlap00_1d[3];
145 
146 
147 #if CTIMEENTITIES_SINGLETONS
148  SafePtr<cdouble> N_i[NMAX];
150 
151  SafePtr<cdouble> Cdouble(double a);
152 #endif
153 
154  private:
155 
156  };
157 
158  extern Prefactors prefactors;
159 
160  namespace prefactor {
161 
162  template <typename T> struct RTimeSingletons {
163  typedef SingletonStack<RTimeEntity<T>,typename RTimeEntity<T>::key_type> ManagerType;
164  static SafePtr<ManagerType>& Manager() {
165  if (manager_ == 0) {
166  manager_ = SafePtr<ManagerType>(new ManagerType(&RTimeEntity<T>::key));
167  }
168  return manager_;
169  }
170  static SafePtr<ManagerType> manager_;
171  };
172  template <typename T> SafePtr<typename RTimeSingletons<T>::ManagerType> RTimeSingletons<T>::manager_;
173 
174 #if CTIMEENTITIES_SINGLETONS
175  template <typename T> struct CTimeSingletons {
177  static SafePtr<ManagerType>& Manager() {
178  if (manager_ == 0) {
179  manager_ = SafePtr<ManagerType>(new ManagerType(&CTimeEntity<T>::value));
180  }
181  return manager_;
182  }
183  static SafePtr<ManagerType> manager_;
184  };
185  template <typename T> SafePtr<typename CTimeSingletons<T>::ManagerType> CTimeSingletons<T>::manager_;
186 #endif
187 
189  template <typename T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
190  SafePtr< CTimeEntity<double> > Scalar(T a) {
191  typedef CTimeEntity<double> return_type;
192  SafePtr<return_type> tmp(new return_type(a));
193 #if CTIMEENTITIES_SINGLETONS
194  typedef CTimeSingletons<double> singletons_type;
195  typedef typename singletons_type::ManagerType ManagerType;
196  const typename ManagerType::value_type& result = singletons_type::Manager()->find(tmp);
197  return result.second;
198 #else
199  return tmp;
200 #endif
201  }
203  inline SafePtr< CTimeEntity<double> > Scalar(double a) {
204  typedef CTimeEntity<double> return_type;
205  SafePtr<return_type> tmp(new return_type(a));
206 #if CTIMEENTITIES_SINGLETONS
207  typedef CTimeSingletons<double> singletons_type;
208  typedef typename singletons_type::ManagerType ManagerType;
209  const typename ManagerType::value_type& result = singletons_type::Manager()->find(tmp);
210  return result.second;
211 #else
212  return tmp;
213 #endif
214  }
216 // inline SafePtr< RTimeEntity<double> > Scalar(const char* id) {
217 // typedef double T;
218 // typedef RTimeEntity<T> return_type;
219 // typedef RTimeSingletons<T> singletons_type;
220 // typedef singletons_type::ManagerType ManagerType;
221 // SafePtr<return_type> tmp(new return_type(id));
222 // const ManagerType::value_type& result = singletons_type::Manager()->find(tmp);
223 // return result.second;
224 // }
226  inline SafePtr< RTimeEntity<double> > Scalar(const std::string& id) {
227  typedef double T;
228  typedef RTimeEntity<T> return_type;
229  typedef RTimeSingletons<T> singletons_type;
230  typedef singletons_type::ManagerType ManagerType;
231  SafePtr<return_type> tmp(new return_type(id));
232  const ManagerType::value_type& result = singletons_type::Manager()->find(tmp);
233  return result.second;
234  }
235 
237  template <class T> class RTimeVector3 {
238  public:
239  RTimeVector3(const char* id) : id_(id) { }
240  RTimeVector3(const std::string& id) : id_(id) { }
241  SafePtr< RTimeEntity<T> > operator[](unsigned int xyz) {
242  return Scalar(id_ + "_" + dirchar[xyz]);
243  }
244  private:
245  static const char* dirchar;
246  std::string id_;
247  };
248  template <class T> const char* RTimeVector3<T>::dirchar(strdup("xyz"));
249 
251  template <class T> class CTimeVector3 {
252  public:
253  CTimeVector3(const T* val) {
254  for(int xyz=0; xyz<3; ++xyz) val_[xyz] = val[xyz];
255  }
256  SafePtr< CTimeEntity<T> > operator[](unsigned int xyz) {
257  return Scalar(val_[xyz]);
258  }
259  private:
260  T val_[3];
261  };
262 
264 #if 0 // these do not get resolved correctly by icpc 12 on OS X
265  template <class T = double> RTimeVector3<T> Vector(const char* id)
266  {
267  return RTimeVector3<T>(id);
268  }
270  template <class T = double> RTimeVector3<T> Vector(const std::string& id)
271  {
272  return RTimeVector3<T>(id);
273  }
275  template <class T = double> CTimeVector3<T> Vector(const T* a)
276  {
277  return CTimeVector3<T>(a);
278  }
279 #endif
280  inline RTimeVector3<double> Vector(const char* id)
281  {
282  return RTimeVector3<double>(id);
283  }
285  inline CTimeVector3<double> Vector(const CGF& bf)
286  {
287  double qn[3]; for(unsigned int xyz=0; xyz<3; ++xyz) qn[xyz] = bf.qn(xyz);
288  return CTimeVector3<double>(qn);
289  }
291  inline CTimeVector3<double> Vector(const OriginDerivative<3u>& dd)
292  {
293  double d[3]; for(unsigned int xyz=0; xyz<3; ++xyz) d[xyz] = dd.d(xyz);
294  return CTimeVector3<double>(d);
295  }
296 
297  }
298 };
299 
300 #endif
301 
Definition: prefactors.h:162
SafePtr< rdouble > TwoPRepITR_vpfac0[np]
Prefactors for the ITR relation for TwoPRep integrals (a+1 0|c0):
Definition: prefactors.h:114
SingletonStack<T,KeyType> helps to implement Singleton-like objects of type T.
Definition: singl_stack.h:43
SafePtr< rdouble > R12kG12VRR_pfac2
prefactor in front of (a0|c-1 0)
Definition: prefactors.h:132
SafePtr< cdouble > N_i[NMAX]
integers represented as doubles
Definition: prefactors.h:149
auxiliary class that write expressions with runtime cartesian vectors
Definition: prefactors.h:237
SafePtr< rdouble > vX_Y[np]
X-Y vectors, where X and Y are for the same particle: X_Y[0] = AB, X_Y[1] = CD, etc.
Definition: prefactors.h:56
CTimeEntity is an Entity of type T that exists at compile-time of the generated code (hence has a val...
Definition: entity.h:186
SafePtr< rdouble > Y_X[np][3]
Cartesian components of Y_X vectors.
Definition: prefactors.h:66
SafePtr< rdouble > zeta2[np][2]
squared orbital exponents
Definition: prefactors.h:93
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
SafePtr< rdouble > XY_X[np][2][3]
cartesian components of vXY_X vector
Definition: prefactors.h:77
Prefactors is a collection of common quantities which appear as prefactors in recurrence relations fo...
Definition: prefactors.h:40
SafePtr< rdouble > R12kG12VRR_pfac4[np][3]
cartesian components of pfac4 vector
Definition: prefactors.h:138
SafePtr< rdouble > one_o_2alpha12[np]
1/(2*alpha12)
Definition: prefactors.h:104
SafePtr< rdouble > R12kG12VRR_vpfac0[np]
prefactor in front of (a-1 0|c0) is one_o_2alpha12[0] prefactor in front of (a0|c-1 0) is one_o_2alph...
Definition: prefactors.h:126
SafePtr< rdouble > W_XY[np][3]
cartesian components of W_XY vector
Definition: prefactors.h:84
SafePtr< rdouble > vXY_X[np][2]
XY-X vectors: XY is either P or Q, X is either (A or B) or (C or D).
Definition: prefactors.h:75
SafePtr< rdouble > zeta[np][2]
orbital exponents
Definition: prefactors.h:89
RTimeEntity is an Entity of type T that exists at runtime of the generated code (hence has no value k...
Definition: entity.h:102
SafePtr< rdouble > vW_XY[np]
W-XY vectors: vW_XY[0] = W-P, vW_XY[1] = W-Q.
Definition: prefactors.h:82
SafePtr< rdouble > rho_o_alpha12[np]
rho/alpha12
Definition: prefactors.h:106
SafePtr< rdouble > one_o_2alphasum
1/(2*(zeta+eta))
Definition: prefactors.h:108
SafePtr< rdouble > R12kG12VRR_vpfac4[np]
prefactor in front of (a0|k-2|c0)
Definition: prefactors.h:136
SafePtr< rdouble > R12kG12VRR_pfac0[np][3]
cartesian components of pfac0 vector
Definition: prefactors.h:128
auxiliary class that write expressions with compile-time cartesian vectors
Definition: prefactors.h:251
SafePtr< rdouble > R12kG12VRR_pfac1[np]
prefactor in front of (a-1 0|c0)
Definition: prefactors.h:130
SafePtr< rdouble > alpha12[np]
alpha12[p] is the sum of exponents for particle p: alpha12[0] = zeta, alpha12[1] = eta.
Definition: prefactors.h:100
Definition: prefactors.h:175
SafePtr< rdouble > Overlap00_1d[3]
Precomputed 1-d integrals.
Definition: prefactors.h:144
SafePtr< rdouble > X_Y[np][3]
Cartesian components of X-Y vectors.
Definition: prefactors.h:58
SafePtr< rdouble > TwoPRepITR_pfac0[np][3]
cartesian components of pfac0 vector
Definition: prefactors.h:116
SafePtr< rdouble > TwoPRepITR_pfac1[np]
prefactor in front of (a0|c+1 0) = -alpha12[1]/alpha12[0]
Definition: prefactors.h:118
SafePtr< rdouble > R12kG12VRR_pfac3[np]
prefactor in front of (|k-2|)
Definition: prefactors.h:134
SafePtr< rdouble > rho
rho = zeta*eta/(zeta+eta)
Definition: prefactors.h:102
SafePtr< rdouble > vY_X[np]
Y-X vectors, where X and Y are for the same particle: Y_X[0] = BA, Y_X[1] = DC, etc.
Definition: prefactors.h:64