LIBINT  2.1.0-stable
policy_spec.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 #include <vector>
21 #include <smart_ptr.h>
22 #include <iter.h>
23 #include <policy.h>
24 #include <integral_decl.h>
25 
26 #ifndef _libint2_src_bin_libint_policyspec_h_
27 #define _libint2_src_bin_libint_policyspec_h_
28 
29 namespace libint2 {
30 
31  /*
32  Definition of a generic StdLibintTDPolicy is provided in policy.h
33  */
34 
52  template <>
53  void
54  StdLibintTDPolicy<CGShell>::init_subobj(const StdLibintTDPolicy<CGShell>::obj_stype& cgshell,
55  std::vector<StdLibintTDPolicy<CGShell>::subobj_stype>& cgfs);
56 
57  template <>
58  void
59  StdLibintTDPolicy<CGShell>::dealloc_subobj(std::vector<StdLibintTDPolicy<CGShell>::subobj_stype>& subobj);
60  /* source is in policy_spec.cc */
61 
66  template <CartesianAxis Axis>
67  struct StdLibintTDPolicy< CGShell1d<Axis> > {
68  typedef CGShell1d<Axis> obj_type;
69  typedef typename obj_type::iter_type subobj_type;
74 
76  static void init_subobj(const obj_stype& cgshell, std::vector<subobj_stype>& cgfs)
77  {
78  if (cgshell.is_unit()) {
79  cgfs.push_back(CGF1d<Axis>::unit());
80  }
81  else {
82  unsigned int am = TypeTraits<CGShell1d<Axis>>::const_ref(cgshell).qn();
83  for(unsigned int q=0; q<=am; ++q) {
84  subobj_stype cgf(q);
85  cgf.deriv() = cgshell.deriv();
86  if (cgshell.contracted()) cgf.contract();
87  cgfs.push_back(cgf);
88  }
89  }
90  }
91  static void dealloc_subobj(vector<subobj_stype>& subobj)
92  {
93  }
94  };
95 
106  template <class Oper, class BFS, class BraSetType, class KetSetType, class AuxQuanta>
107  struct StdLibintTDPolicy< GenIntegralSet<Oper,BFS,BraSetType,KetSetType,AuxQuanta> >
108  {
110  typedef typename obj_type::iter_type subobj_type;
111  static const unsigned int np = Oper::Properties::np;
116 
117  static void init_subobj(const SafePtr<obj_type>& obj, std::vector< SafePtr<subobj_type> >& subobj) {
118 
119  std::vector< SubIterator* > siters_inord; // subiterators used to iterate over each set (in the above order)
120  typedef std::vector< std::vector< SubIterator* > > bra_siters_type;
121  typedef std::vector< std::vector< SubIterator* > > ket_siters_type;
122  bra_siters_type bra_siters; // subiterators for bra basis function sets (outer vector runs over particle index)
123  ket_siters_type ket_siters; // subiterators for ket basis function sets (outer vector runs over particle index)
124  bra_siters.resize(np);
125  ket_siters.resize(np);
126 
127  // Obtain subiterators in order
128  SubIteratorBase< Oper > oper_siter(obj->oper());
129  siters_inord.push_back(&oper_siter);
130 
131  SubIteratorBase< AuxQuanta > aux_siter(obj->aux());
132  siters_inord.push_back(&aux_siter);
133 
134  for(unsigned int p=0; p<np; p++) {
135  const unsigned int nbra = obj->bra().num_members(p);
136  bra_siters[p].resize(nbra);
137  for(unsigned int i=0; i<nbra; i++) {
138  SubIterator* iter = obj->bra().member_subiter(p,i);
139  siters_inord.push_back(iter);
140  bra_siters[p][i] = iter;
141  }
142 
143  const unsigned int nket = obj->ket().num_members(p);
144  ket_siters[p].resize(nket);
145  for(unsigned int i=0; i<nket; i++) {
146  SubIterator* iter = obj->ket().member_subiter(p,i);
147  siters_inord.push_back(iter);
148  ket_siters[p][i] = iter;
149  }
150  }
151 
152  const unsigned int niters = siters_inord.size();
153  for(unsigned int it=0; it<niters; it++)
154  siters_inord[it]->init();
155 
156  // Now iterate over contents of each subiterator
157  bool can_iterate = true;
158  while (can_iterate) {
159 
160  typename Oper::iter_type oper(oper_siter.elem());
161  typename AuxQuanta::iter_type aux(aux_siter.elem());
162 
163  // Construct and initialize bra
164  typename BraSetType::iter_type bra;
165  for(unsigned int p=0; p<np; p++) {
166  const unsigned int nbra = bra_siters[p].size();
167  for(unsigned int i=0; i<nbra; i++)
168  bra.set_member(bra_siters[p][i]->pelem(), p, i);
169  }
170 
171  // Construct and initialize ket
172  typename KetSetType::iter_type ket;
173  for(unsigned int p=0; p<np; p++) {
174  const unsigned int nket = ket_siters[p].size();
175  for(unsigned int i=0; i<nket; i++)
176  ket.set_member(ket_siters[p][i]->pelem(), p, i);
177  }
178 
179  // construct this subobj
180  SafePtr<subobj_type> curr_subobj_sptr = subobj_type::Instance(bra,ket,aux,oper);
181  subobj.push_back(curr_subobj_sptr);
182 
183  // update subiterators to refer to the next element
184  for(int it=niters-1; it>=0; it--) {
185  SubIterator& siter = *siters_inord[it];
186  ++siter;
187  // If next element exists -> break out, else -> rewind it and try next subiterator
188  if (siter) {
189  break;
190  }
191  else {
192  siter.init();
193  // If all subiterators have been exhausted then we are done iterating
194  if (it == 0)
195  can_iterate = false;
196  }
197  }
198 
199  }
200 
201  // Deallocate bra and ket subiterators
202  {
203  typedef bra_siters_type::iterator bra_iter;
204  typedef ket_siters_type::iterator ket_iter;
205  typedef bra_siters_type::value_type::iterator bra_elem_iter;
206  typedef bra_siters_type::value_type::iterator ket_elem_iter;
207 
208  const bra_iter bi_end = bra_siters.end();
209  for(bra_iter bi=bra_siters.begin(); bi != bi_end; ++bi) {
210  const bra_elem_iter bij_end = bi->end();
211  for(bra_elem_iter bij=bi->begin(); bij != bij_end; ++bij) {
212  delete *bij;
213  }
214  }
215  bra_siters.clear();
216 
217  const ket_iter ki_end = ket_siters.end();
218  for(ket_iter ki=ket_siters.begin(); ki != ki_end; ++ki) {
219  const ket_elem_iter kij_end = ki->end();
220  for(ket_elem_iter kij=ki->begin(); kij != kij_end; ++kij) {
221  delete *kij;
222  }
223  }
224  ket_siters.clear();
225  }
226 
227  }
228 
229  // Nothing is done here because GenIntegralSet objects are Singleton-like and don't need to be destroyed
230  static void dealloc_subobj(std::vector< SafePtr<subobj_type> >& subobj) {
231  }
232  };
233 
234 #if LIBINT_SUPPORT_ONEBODYINTS
235  template <typename BFS, typename Oper, typename AuxQuanta>
236  struct StdLibintTDPolicy< GenIntegralSet_1_1<BFS,Oper,AuxQuanta> >
237  {
239  typedef typename obj_type::iter_type subobj_type;
245 
246  static void init_subobj(const SafePtr<obj_type>& obj, std::vector< SafePtr<subobj_type> >& subobj) {
247 
248  // Iterate over all SubIteratorBase<GenIntegralSet::iter_type>
249  parent_siter gis_siter(obj);
250  for(gis_siter.init(); gis_siter; ++gis_siter) {
251  const SafePtr<typename obj_type::parent_type::iter_type> curr_gis_ptr = gis_siter.elem();
252  const SafePtr<subobj_type> curr_subobj =
253  subobj_type::Instance(curr_gis_ptr->bra(), curr_gis_ptr->ket(), *curr_gis_ptr->aux().get(), *curr_gis_ptr->oper().get());
254  subobj.push_back(curr_subobj);
255  }
256  }
257 
258  // Nothing is done here because GenIntegralSet_1_1 objects are Singleton-like and don't need to be destroyed
259  static void dealloc_subobj(std::vector< SafePtr< subobj_type > >& subobj) {
260  }
261  };
262 #endif // LIBINT_SUPPORT_ONEBODYINTS
263 
264  template <typename BFS, typename Oper, typename AuxQuanta>
265  struct StdLibintTDPolicy< GenIntegralSet_11_11<BFS,Oper,AuxQuanta> >
266  {
268  typedef typename obj_type::iter_type subobj_type;
274 
275  static void init_subobj(const SafePtr<obj_type>& obj, std::vector< SafePtr<subobj_type> >& subobj) {
276 
277  // Iterate over all SubIteratorBase<GenIntegralSet::iter_type>
278  parent_siter gis_siter(obj);
279  for(gis_siter.init(); gis_siter; ++gis_siter) {
280  const SafePtr<typename obj_type::parent_type::iter_type> curr_gis_ptr = gis_siter.elem();
281  const SafePtr<subobj_type> curr_subobj =
282  subobj_type::Instance(curr_gis_ptr->bra(), curr_gis_ptr->ket(), *curr_gis_ptr->aux().get(), *curr_gis_ptr->oper().get());
283  subobj.push_back(curr_subobj);
284  }
285  }
286 
287  // Nothing is done here because GenIntegralSet_11_11 objects are Singleton-like and don't need to be destroyed
288  static void dealloc_subobj(std::vector< SafePtr< subobj_type > >& subobj) {
289  }
290  };
291 
292 #if 0
293 
296  template <class BFS>
297  struct StdLibintTDPolicy< TwoPRep_11_11<BFS> >
298  {
300  typedef typename obj_type::iter_type subobj_type;
306 
307  static void init_subobj(const SafePtr<obj_type>& obj, std::vector< SafePtr<subobj_type> >& subobj) {
308 
309  // Iterate over all SubIteratorBase<GenIntegralSet::iter_type>
310  parent_siter gis_siter(obj);
311  for(gis_siter.init(); gis_siter; ++gis_siter) {
312  const SafePtr<typename TwoPRep_11_11<BFS>::parent_type::iter_type> curr_gis_ptr = gis_siter.elem();
313  const SafePtr<subobj_type> curr_subobj =
314  subobj_type::Instance(curr_gis_ptr->bra(), curr_gis_ptr->ket(), *curr_gis_ptr->aux().get());
315  subobj.push_back(curr_subobj);
316  }
317  }
318 
319  // Nothing is done here because TwoPRep_11_11 objects are Singleton-like and don't need to be destroyed
320  static void dealloc_subobj(std::vector< SafePtr< TwoPRep_11_11<typename BFS::iter_type> > >& subobj) {
321  }
322  };
323 #endif
324 
328  template <class BFS, int K>
329  struct StdLibintTDPolicy< R12kG12_11_11<BFS,K> >
330  {
332  typedef typename obj_type::iter_type subobj_type;
338 
339  static void init_subobj(const SafePtr<obj_type>& obj, std::vector< SafePtr<subobj_type> >& subobj) {
340 
341  // Iterate over all SubIteratorBase<GenIntegralSet::iter_type>
342  parent_siter gis_siter(obj);
343  for(gis_siter.init(); gis_siter; ++gis_siter) {
344  const SafePtr<typename obj_type::parent_type::iter_type> curr_gis_ptr = gis_siter.elem();
345  const SafePtr<subobj_type> curr_subobj =
346  subobj_type::Instance(curr_gis_ptr->bra(), curr_gis_ptr->ket(), *curr_gis_ptr->aux().get());
347  subobj.push_back(curr_subobj);
348  }
349  }
350 
351  // Nothing is done here because R12kG12_11_11 objects are Singleton-like and don't need to be destroyed
352  static void dealloc_subobj(std::vector< SafePtr< R12kG12_11_11<typename BFS::iter_type,K> > >& subobj) {
353  }
354  };
355 
356 
360  template <class BFS, int K>
361  struct StdLibintTDPolicy< TiG12_11_11<BFS,K> >
362  {
364  typedef typename obj_type::iter_type subobj_type;
370 
371  static void init_subobj(const SafePtr<obj_type>& obj, std::vector< SafePtr<subobj_type> >& subobj) {
372 
373  // Iterate over all SubIteratorBase<GenIntegralSet::iter_type>
374  parent_siter gis_siter(obj);
375  for(gis_siter.init(); gis_siter; ++gis_siter) {
376  const SafePtr<typename obj_type::parent_type::iter_type> curr_gis_ptr = gis_siter.elem();
377  const SafePtr<subobj_type> curr_subobj =
378  subobj_type::Instance(curr_gis_ptr->bra(), curr_gis_ptr->ket(), *curr_gis_ptr->aux().get());
379  subobj.push_back(curr_subobj);
380  }
381  }
382 
383  // Nothing is done here because TiG12_11_11 objects are Singleton-like and don't need to be destroyed
384  static void dealloc_subobj(std::vector< SafePtr< TiG12_11_11<typename BFS::iter_type,K> > >& subobj) {
385  }
386  };
387 
388 
392  template <class BFS>
393  struct StdLibintTDPolicy< R1dotR1G12_11_11<BFS> >
394  {
396  typedef typename obj_type::iter_type subobj_type;
402 
403  static void init_subobj(const SafePtr<obj_type>& obj, std::vector< SafePtr<subobj_type> >& subobj) {
404 
405  // Iterate over all SubIteratorBase<GenIntegralSet::iter_type>
406  parent_siter gis_siter(obj);
407  for(gis_siter.init(); gis_siter; ++gis_siter) {
408  const SafePtr<typename obj_type::parent_type::iter_type> curr_gis_ptr = gis_siter.elem();
409  const SafePtr<subobj_type> curr_subobj =
410  subobj_type::Instance(curr_gis_ptr->bra(), curr_gis_ptr->ket(), *curr_gis_ptr->aux().get());
411  subobj.push_back(curr_subobj);
412  }
413  }
414 
415  // Nothing is done here because R1dotR1G12_11_11 objects are Singleton-like and don't need to be destroyed
416  static void dealloc_subobj(std::vector< SafePtr< R1dotR1G12_11_11<typename BFS::iter_type> > >& subobj) {
417  }
418  };
419 
423  template <class BFS>
424  struct StdLibintTDPolicy< R2dotR2G12_11_11<BFS> >
425  {
427  typedef typename obj_type::iter_type subobj_type;
433 
434  static void init_subobj(const SafePtr<obj_type>& obj, std::vector< SafePtr<subobj_type> >& subobj) {
435 
436  // Iterate over all SubIteratorBase<GenIntegralSet::iter_type>
437  parent_siter gis_siter(obj);
438  for(gis_siter.init(); gis_siter; ++gis_siter) {
439  const SafePtr<typename obj_type::parent_type::iter_type> curr_gis_ptr = gis_siter.elem();
440  const SafePtr<subobj_type> curr_subobj =
441  subobj_type::Instance(curr_gis_ptr->bra(), curr_gis_ptr->ket(), *curr_gis_ptr->aux().get());
442  subobj.push_back(curr_subobj);
443  }
444  }
445 
446  // Nothing is done here because R2dotR2G12_11_11 objects are Singleton-like and don't need to be destroyed
447  static void dealloc_subobj(std::vector< SafePtr< R2dotR2G12_11_11<typename BFS::iter_type> > >& subobj) {
448  }
449  };
450 
454  template <class BFS>
455  struct StdLibintTDPolicy< R1dotR2G12_11_11<BFS> >
456  {
458  typedef typename obj_type::iter_type subobj_type;
464 
465  static void init_subobj(const SafePtr<obj_type>& obj, std::vector< SafePtr<subobj_type> >& subobj) {
466 
467  // Iterate over all SubIteratorBase<GenIntegralSet::iter_type>
468  parent_siter gis_siter(obj);
469  for(gis_siter.init(); gis_siter; ++gis_siter) {
470  const SafePtr<typename obj_type::parent_type::iter_type> curr_gis_ptr = gis_siter.elem();
471  const SafePtr<subobj_type> curr_subobj =
472  subobj_type::Instance(curr_gis_ptr->bra(), curr_gis_ptr->ket(), *curr_gis_ptr->aux().get());
473  subobj.push_back(curr_subobj);
474  }
475  }
476 
477  // Nothing is done here because R1dotR2G12_11_11 objects are Singleton-like and don't need to be destroyed
478  static void dealloc_subobj(std::vector< SafePtr< R1dotR2G12_11_11<typename BFS::iter_type> > >& subobj) {
479  }
480  };
481 
482 };
483 
484 #endif
485 
static void init_subobj(const obj_stype &cgshell, std::vector< subobj_stype > &cgfs)
This function allocates subobj of obj (e.g. basis functions contained in a shell) ...
Definition: policy_spec.h:76
TypeTraits< obj_type >::StorageType obj_stype
how these objects are stored
Definition: policy_spec.h:303
StorageTraits< T >::StorageType StorageType
By default, use SafePtr to manage these objects.
Definition: traits.h:83
TypeTraits< obj_type >::StorageType obj_stype
how these objects are stored
Definition: policy_spec.h:461
Cartesian components of 3D CGF = 1D CGF.
Definition: bfset.h:425
TypeTraits< obj_type >::StorageType obj_stype
how these objects are stored
Definition: policy_spec.h:367
const iref & elem() const
Returns current element.
Definition: iter.h:164
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
a "shell" of 1D CGFs with quantum number L is a set of 1D CGFs with quantum numbers 0 ...
Definition: bfset.h:614
TypeTraits< obj_type >::StorageType obj_stype
how these objects are stored
Definition: policy_spec.h:430
Generic integral over a two-body operator with one bfs for each particle in bra and ket...
Definition: integral_11_11.h:32
TypeTraits< subobj_type >::StorageType subobj_stype
how these subobjects are stored
Definition: policy_spec.h:337
void init()
Initializes the iterator.
Definition: iter.h:187
Definition: integral_decl.h:38
SubIteratorBase<T> provides a base class for a sub-iterator class for T.
Definition: iter.h:72
TypeTraits< subobj_type >::StorageType subobj_stype
how these subobjects are stored
Definition: policy_spec.h:115
virtual void init()=0
Initializes the iterator.
TypeTraits< obj_type >::StorageType obj_stype
how these objects are stored
Definition: policy_spec.h:113
TypeTraits< obj_type >::StorageType obj_stype
how these objects are stored
Definition: policy_spec.h:242
TypeTraits< subobj_type >::StorageType subobj_stype
how these subobjects are stored
Definition: policy_spec.h:463
TypeTraits< obj_type >::StorageType obj_stype
how these objects are stored
Definition: policy_spec.h:335
TypeTraits< subobj_type >::StorageType subobj_stype
how these subobjects are stored
Definition: policy_spec.h:244
Definition: integral_decl.h:35
Oper is OperSet characterized by properties Props.
Definition: oper.h:82
Generic integral over a one-body operator with one bfs for each particle in bra and ket...
Definition: integral_1_1.h:32
TypeTraits< subobj_type >::StorageType subobj_stype
how these subobjects are stored
Definition: policy_spec.h:432
TypeTraits< subobj_type >::StorageType subobj_stype
how these subobjects are stored
Definition: policy_spec.h:73
Definition: integral_decl.h:41
Definition: traits.h:81
Iterator provides a base class for all object iterator classes.
Definition: iter.h:44
TypeTraits< subobj_type >::StorageType subobj_stype
how these subobjects are stored
Definition: policy_spec.h:369
TypeTraits< subobj_type >::StorageType subobj_stype
how these subobjects are stored
Definition: policy_spec.h:273
TypeTraits< subobj_type >::StorageType subobj_stype
how these subobjects are stored
Definition: policy_spec.h:305
R2dotR2G12_11_11 – integral over R2dotR2_G12 operator with one bfs for each particle in bra and ket...
Definition: integral_decl.h:40
TypeTraits< obj_type >::StorageType obj_stype
how these objects are stored
Definition: policy_spec.h:399
TypeTraits< subobj_type >::StorageType subobj_stype
how these subobjects are stored
Definition: policy_spec.h:401
TypeTraits< obj_type >::StorageType obj_stype
how these objects are stored
Definition: policy_spec.h:271
Definition: integral_decl.h:37
TypeTraits< obj_type >::StorageType obj_stype
how these objects are stored
Definition: policy_spec.h:71