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