LIBINT 2.9.0
generic_rr.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#ifndef _libint2_src_bin_libint_genericrr_h_
22#define _libint2_src_bin_libint_genericrr_h_
23
24#include <algebra.h>
25#include <context.h>
26#include <default_params.h>
27#include <dgvertex.h>
28#include <flop.h>
29#include <integral.h>
30#include <prefactors.h>
31#include <rr.h>
32#include <util.h>
33
34#include <boost/type_traits/is_same.hpp>
35#include <cassert>
36#include <iostream>
37#include <sstream>
38#include <stdexcept>
39#include <string>
40#include <vector>
41
42namespace libint2 {
43
46template <typename RRImpl, typename F, typename Target>
48 public:
49 typedef F BasisFunctionType;
50 typedef Target TargetType;
53
55 static std::shared_ptr<RRImpl> Instance(
56 const std::shared_ptr<TargetType>& Tint, unsigned int dir) {
57 // screen out calls with nondefault extra parameters
58 if (!RRImpl::directional() && dir != 0) return std::shared_ptr<RRImpl>();
59 // attempt to construct
60 std::shared_ptr<RRImpl> this_ptr(new RRImpl(Tint, dir));
61 // if succeeded (nchildren > 0) do post-construction
62 if (this_ptr->num_children() != 0) {
63 this_ptr->template register_with_rrstack<RRImpl>();
64 return this_ptr;
65 }
66 // else return null pointer
67 return std::shared_ptr<RRImpl>();
68 }
69
71 unsigned int num_children() const override { return children_.size(); }
73 std::shared_ptr<DGVertex> rr_target() const override {
74 return std::static_pointer_cast<DGVertex, TargetType>(target_);
75 }
77 std::shared_ptr<DGVertex> rr_child(unsigned int i) const override {
78 return children_.at(i);
79 }
81 bool is_simple() const override {
83 }
84
86 std::string generate_label() const override {
87 std::ostringstream os;
88 os << RRImpl::descr() << " " << target_->label();
89 return os.str();
90 }
91
92 protected:
93 GenericRecurrenceRelation(const std::shared_ptr<TargetType>& Tint,
94 unsigned int dir)
95 : target_(Tint), dir_(dir) {
96 children_.reserve(RRImpl::max_nchildren);
97 }
101 static bool default_directional() {
102 if (boost::is_same<BasisFunctionType, CGF>::value) return true;
103 return false;
104 }
105
106 unsigned int dir() const { return dir_; }
107
109 const std::shared_ptr<DGVertex>& add_child(
110 const std::shared_ptr<DGVertex>& child) {
111 typedef std::vector<std::shared_ptr<DGVertex> > cvector;
112 typedef typename cvector::const_iterator citer;
113 const citer pos = std::find(children_.begin(), children_.end(), child);
114 if (pos == children_.end()) {
115 children_.push_back(child);
116 return *(children_.rbegin());
117 } else
118 return *pos;
119 }
120
122 template <class RR, class C>
123 friend class ChildFactory;
127#if 0
128 template <class RealChildType>
129 const std::shared_ptr<DGVertex>& make_child(const typename RealChildType::BasisFunctionType& A,
130 const typename RealChildType::BasisFunctionType& B,
131 const typename RealChildType::BasisFunctionType& C,
132 const typename RealChildType::BasisFunctionType& D,
133 const typename RealChildType::AuxIndexType& aux = typename RealChildType::AuxIndexType(),
134 const typename RealChildType::OperType& oper = typename RealChildType::OperType()) {
135 const std::shared_ptr<DGVertex>& i = std::static_pointer_cast<DGVertex,RealChildType>(ChildType::Instance(A,B,C,D,aux,oper));
136 return add_child(i);
137 }
138#endif
139
140 std::shared_ptr<TargetType> target_;
141
142 private:
143 unsigned int dir_;
144 std::vector<std::shared_ptr<DGVertex> > children_;
145};
146
149template <class GenRR, class ChildType>
151 public:
152 typedef typename ChildType::BasisFunctionType F;
153 typedef typename ChildType::AuxIndexType AuxIndexType;
154 typedef typename ChildType::OperType OperType;
155
156 ChildFactory(GenRR* rr) : rr_(rr) {}
157
159 const std::shared_ptr<DGVertex>& make_child(
160 const F& A, const F& B, const F& C, const F& D,
161 const AuxIndexType& aux = AuxIndexType(),
162 const OperType& oper = OperType()) {
163 auto i = std::static_pointer_cast<DGVertex, ChildType>(
164 ChildType::Instance(A, B, C, D, aux, oper));
165 return rr_->add_child(i);
166 }
168 const std::shared_ptr<DGVertex>& make_child(
169 const F& A, const F& B, const AuxIndexType& aux = AuxIndexType(),
170 const OperType& oper = OperType()) {
171 auto i = std::static_pointer_cast<DGVertex, ChildType>(
172 ChildType::Instance(A, B, aux, oper));
173 return rr_->add_child(i);
174 }
176 const std::shared_ptr<DGVertex>& make_child(
178 braket_wedge,
179 const AuxIndexType& aux = AuxIndexType(),
180 const OperType& oper = OperType()) {
181 auto i = std::static_pointer_cast<DGVertex, ChildType>(
182 ChildType::Instance(braket_wedge, aux, oper));
183 return rr_->add_child(i);
184 }
186 const std::shared_ptr<DGVertex>& make_child(
188 braket_wedge,
189 const AuxIndexType& aux = AuxIndexType(),
190 const OperType& oper = OperType()) {
191 auto i = std::static_pointer_cast<DGVertex, ChildType>(
192 ChildType::Instance(braket_wedge, aux, oper));
193 return rr_->add_child(i);
194 }
196 void wedge(const LinearCombination<std::shared_ptr<DGVertex>,
197 BraketPair<F, PBra> >& bra_lc,
198 const LinearCombination<std::shared_ptr<DGVertex>,
199 BraketPair<F, PKet> >& ket_lc,
200 const AuxIndexType& aux = AuxIndexType(),
201 const OperType& oper = OperType()) {
202 using namespace libint2::algebra;
205 ProductLC;
206 const ProductLC& product_lc = bra_lc ^ ket_lc;
207 const size_t nprod = product_lc.size();
208 for (unsigned int t = 0; t < nprod; ++t) {
209 const typename ProductLC::term_t& term = product_lc[t];
210 auto child = make_child(term.second, aux, oper);
211 if (rr_->is_simple()) {
212 if (rr_->expr_)
213 rr_->expr_ += term.first * child;
214 else
215 rr_->expr_ = term.first * child;
216 }
217 }
218 }
219 void wedge(const BraketPair<F, PBra>& bra,
220 const LinearCombination<std::shared_ptr<DGVertex>,
221 BraketPair<F, PKet> >& ket_lc,
222 const AuxIndexType& aux = AuxIndexType(),
223 const OperType& oper = OperType()) {
224 using namespace libint2::prefactor;
226 bra_lc += make_pair(Scalar(1.0), bra);
227 wedge(bra_lc, ket_lc, aux, oper);
228 }
229 void wedge(const LinearCombination<std::shared_ptr<DGVertex>,
230 BraketPair<F, PBra> >& bra_lc,
231 const BraketPair<F, PKet>& ket,
232 const AuxIndexType& aux = AuxIndexType(),
233 const OperType& oper = OperType()) {
234 using namespace libint2::prefactor;
236 ket_lc += make_pair(Scalar(1.0), ket);
237 wedge(bra_lc, ket_lc, aux, oper);
238 }
239
240 private:
241 GenRR* rr_;
242};
243
244}; // namespace libint2
245
246#endif
AlgebraicOperator is an algebraic operator that acts on objects of type T.
Definition algebra.h:47
BraketPair is a trimmed down version of ArrayBraket specialized for same-particle or different-partic...
Definition src/bin/libint/braket.h:247
Helps GenericRecurrenceRelation to work around the compiler problem with make_child.
Definition generic_rr.h:150
const std::shared_ptr< DGVertex > & make_child(const algebra::Wedge< BraketPair< F, CBra >, BraketPair< F, CKet > > &braket_wedge, const AuxIndexType &aux=AuxIndexType(), const OperType &oper=OperType())
make a child from a wedge of chemists' brackets
Definition generic_rr.h:186
const std::shared_ptr< DGVertex > & make_child(const algebra::Wedge< BraketPair< F, PBra >, BraketPair< F, PKet > > &braket_wedge, const AuxIndexType &aux=AuxIndexType(), const OperType &oper=OperType())
make a child from a wedge of physicists' brackets
Definition generic_rr.h:176
const std::shared_ptr< DGVertex > & make_child(const F &A, const F &B, const F &C, const F &D, const AuxIndexType &aux=AuxIndexType(), const OperType &oper=OperType())
make_child
Definition generic_rr.h:159
void wedge(const LinearCombination< std::shared_ptr< DGVertex >, BraketPair< F, PBra > > &bra_lc, const LinearCombination< std::shared_ptr< DGVertex >, BraketPair< F, PKet > > &ket_lc, const AuxIndexType &aux=AuxIndexType(), const OperType &oper=OperType())
take a wedge product of various (linear combinations of) brakets
Definition generic_rr.h:196
const std::shared_ptr< DGVertex > & make_child(const F &A, const F &B, const AuxIndexType &aux=AuxIndexType(), const OperType &oper=OperType())
make_child
Definition generic_rr.h:168
RRImpl must inherit GenericRecurrenceRelation<RRImpl>
Definition generic_rr.h:47
const std::shared_ptr< DGVertex > & make_child(const typename RealChildType::BasisFunctionType &A, const typename RealChildType::BasisFunctionType &B, const typename RealChildType::BasisFunctionType &C, const typename RealChildType::BasisFunctionType &D, const typename RealChildType::AuxIndexType &aux=typename RealChildType::AuxIndexType(), const typename RealChildType::OperType &oper=typename RealChildType::OperType())
make_child should really looks something like this, but gcc 4.3.0 craps out TODO test is this works
Definition generic_rr.h:129
bool is_simple() const override
Implementation of RecurrenceRelation::is_simple()
Definition generic_rr.h:81
std::shared_ptr< DGVertex > rr_target() const override
Implementation of RecurrenceRelation::rr_target()
Definition generic_rr.h:73
std::string generate_label() const override
Implementation of RecurrenceRelation::generate_label()
Definition generic_rr.h:86
unsigned int num_children() const override
Implementation of RecurrenceRelation::num_children()
Definition generic_rr.h:71
const std::shared_ptr< DGVertex > & add_child(const std::shared_ptr< DGVertex > &child)
add child
Definition generic_rr.h:109
std::shared_ptr< DGVertex > rr_child(unsigned int i) const override
Implementation of RecurrenceRelation::rr_child()
Definition generic_rr.h:77
static bool default_directional()
is this recurrence relation parameterized by a direction (x, y, or z).
Definition generic_rr.h:101
static std::shared_ptr< RRImpl > Instance(const std::shared_ptr< TargetType > &Tint, unsigned int dir)
Return an instance if applicable, or a null pointer otherwise.
Definition generic_rr.h:55
represents linear combination of objects of type T with coefficients of type C
Definition algebra.h:222
RecurrenceRelation describes all recurrence relations.
Definition rr.h:97
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24
TrivialBFSet<T> defines static member result, which is true if T is a basis function set consisting o...
Definition bfset.h:906
Wedge is a typeholder for the result of a wedge product.
Definition algebra.h:248