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