LIBINT 2.7.2
generic_rr.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#ifndef _libint2_src_bin_libint_genericrr_h_
22#define _libint2_src_bin_libint_genericrr_h_
23
24#include <iostream>
25#include <sstream>
26#include <string>
27#include <vector>
28#include <stdexcept>
29#include <cassert>
30#include <boost/type_traits/is_same.hpp>
31
32#include <dgvertex.h>
33#include <rr.h>
34#include <integral.h>
35#include <algebra.h>
36#include <flop.h>
37#include <prefactors.h>
38#include <context.h>
39#include <default_params.h>
40#include <util.h>
41
42namespace libint2 {
43
46 template <typename RRImpl, typename F, typename Target>
48 public:
49 typedef F BasisFunctionType;
50 typedef Target TargetType;
53
55 static SafePtr<RRImpl> Instance(const SafePtr<TargetType>& Tint, unsigned int dir) {
56 // screen out calls with nondefault extra parameters
57 if (!RRImpl::directional() && dir != 0)
58 return SafePtr<RRImpl>();
59 // attempt to construct
60 SafePtr<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 SafePtr<RRImpl>();
68 }
69
71 unsigned int num_children() const override { return children_.size(); }
73 SafePtr<DGVertex> rr_target() const override { return static_pointer_cast<DGVertex,TargetType>(target_); }
75 SafePtr<DGVertex> rr_child(unsigned int i) const override {
76 return children_.at(i);
77 }
79 bool is_simple() const override {
81 }
82
84 std::string generate_label() const override
85 {
86 std::ostringstream os;
87 os << RRImpl::descr() << " " << target_->label();
88 return os.str();
89 }
90
91 protected:
92 GenericRecurrenceRelation(const SafePtr<TargetType>& Tint, unsigned int dir) :
93 target_(Tint), dir_(dir) {
94 children_.reserve(RRImpl::max_nchildren);
95 }
99 static bool default_directional() {
100 if (boost::is_same<BasisFunctionType,CGF>::value)
101 return true;
102 return false;
103 }
104
105 unsigned int dir() const { return dir_; }
106
108 const SafePtr<DGVertex>& add_child(const SafePtr<DGVertex>& child) {
109 typedef std::vector< SafePtr<DGVertex> > cvector;
110 typedef typename cvector::const_iterator citer;
111 const citer pos = std::find(children_.begin(),children_.end(),child);
112 if (pos == children_.end()) {
113 children_.push_back(child);
114 return *(children_.rbegin());
115 }
116 else
117 return *pos;
118 }
119
121 template<class RR, class C> friend class ChildFactory;
124#if 0
125 template <class RealChildType>
126 const SafePtr<DGVertex>& make_child(const typename RealChildType::BasisFunctionType& A,
127 const typename RealChildType::BasisFunctionType& B,
128 const typename RealChildType::BasisFunctionType& C,
129 const typename RealChildType::BasisFunctionType& D,
130 const typename RealChildType::AuxIndexType& aux = typename RealChildType::AuxIndexType(),
131 const typename RealChildType::OperType& oper = typename RealChildType::OperType()) {
132 const SafePtr<DGVertex>& i = static_pointer_cast<DGVertex,RealChildType>(ChildType::Instance(A,B,C,D,aux,oper));
133 return add_child(i);
134 }
135#endif
136
137 SafePtr<TargetType> target_;
138
139 private:
140 unsigned int dir_;
141 std::vector< SafePtr<DGVertex> > children_;
142
143 };
144
146 template <class GenRR, class ChildType>
148 public:
149 typedef typename ChildType::BasisFunctionType F;
150 typedef typename ChildType::AuxIndexType AuxIndexType;
151 typedef typename ChildType::OperType OperType;
152
153 ChildFactory(GenRR* rr) : rr_(rr) {}
154
156 const SafePtr<DGVertex>& make_child(const F& A,
157 const F& B,
158 const F& C,
159 const F& D,
160 const AuxIndexType& aux = AuxIndexType(),
161 const OperType& oper = OperType()) {
162 auto i = static_pointer_cast<DGVertex,ChildType>(ChildType::Instance(A,B,C,D,aux,oper));
163 return rr_->add_child(i);
164 }
166 const SafePtr<DGVertex>& make_child(const F& A,
167 const F& B,
168 const AuxIndexType& aux = AuxIndexType(),
169 const OperType& oper = OperType()) {
170 auto i = static_pointer_cast<DGVertex,ChildType>(ChildType::Instance(A,B,aux,oper));
171 return rr_->add_child(i);
172 }
174 const SafePtr<DGVertex>&
176 const AuxIndexType& aux = AuxIndexType(),
177 const OperType& oper = OperType()) {
178 auto i = static_pointer_cast<DGVertex,ChildType>(ChildType::Instance(braket_wedge,aux,oper));
179 return rr_->add_child(i);
180 }
182 const SafePtr<DGVertex>&
184 const AuxIndexType& aux = AuxIndexType(),
185 const OperType& oper = OperType()) {
186 auto i = static_pointer_cast<DGVertex,ChildType>(ChildType::Instance(braket_wedge,aux,oper));
187 return rr_->add_child(i);
188 }
190 void wedge(const LinearCombination< SafePtr<DGVertex>, BraketPair<F,PBra> >& bra_lc,
191 const LinearCombination< SafePtr<DGVertex>, BraketPair<F,PKet> >& ket_lc,
192 const AuxIndexType& aux = AuxIndexType(),
193 const OperType& oper = OperType()) {
194 using namespace libint2::algebra;
198 >
199 > ProductLC;
200 const ProductLC& product_lc = bra_lc ^ ket_lc;
201 const size_t nprod = product_lc.size();
202 for(unsigned int t=0; t<nprod; ++t) {
203 const typename ProductLC::term_t& term = product_lc[t];
204 auto child = make_child(term.second,aux,oper);
205 if (rr_->is_simple()) {
206 if (rr_->expr_)
207 rr_->expr_ += term.first * child;
208 else
209 rr_->expr_ = term.first * child;
210 }
211 }
212 }
213 void wedge(const BraketPair<F,PBra>& bra,
214 const LinearCombination< SafePtr<DGVertex>, BraketPair<F,PKet> >& ket_lc,
215 const AuxIndexType& aux = AuxIndexType(),
216 const OperType& oper = OperType()) {
217 using namespace libint2::prefactor;
219 bra_lc += make_pair(Scalar(1.0),bra);
220 wedge(bra_lc,ket_lc,aux,oper);
221 }
222 void wedge(const LinearCombination< SafePtr<DGVertex>, BraketPair<F,PBra> >& bra_lc,
223 const BraketPair<F,PKet>& ket,
224 const AuxIndexType& aux = AuxIndexType(),
225 const OperType& oper = OperType()) {
226 using namespace libint2::prefactor;
227 LinearCombination< SafePtr<DGVertex>, BraketPair<F,PKet> > ket_lc;
228 ket_lc += make_pair(Scalar(1.0),ket);
229 wedge(bra_lc,ket_lc,aux,oper);
230 }
231
232 private:
233 GenRR* rr_;
234 };
235
236};
237
238#endif
AlgebraicOperator is an algebraic operator that acts on objects of type T.
Definition: algebra.h:50
BraketPair is a trimmed down version of ArrayBraket specialized for same-particle or different-partic...
Definition: src/bin/libint/braket.h:244
Helps GenericRecurrenceRelation to work around the compiler problem with make_child.
Definition: generic_rr.h:147
const SafePtr< 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:183
const SafePtr< 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:175
const SafePtr< 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:156
void wedge(const LinearCombination< SafePtr< DGVertex >, BraketPair< F, PBra > > &bra_lc, const LinearCombination< SafePtr< 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:190
const SafePtr< DGVertex > & make_child(const F &A, const F &B, const AuxIndexType &aux=AuxIndexType(), const OperType &oper=OperType())
make_child
Definition: generic_rr.h:166
RRImpl must inherit GenericRecurrenceRelation<RRImpl>
Definition: generic_rr.h:47
const SafePtr< 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:126
SafePtr< DGVertex > rr_target() const override
Implementation of RecurrenceRelation::rr_target()
Definition: generic_rr.h:73
bool is_simple() const override
Implementation of RecurrenceRelation::is_simple()
Definition: generic_rr.h:79
std::string generate_label() const override
Implementation of RecurrenceRelation::generate_label()
Definition: generic_rr.h:84
const SafePtr< DGVertex > & add_child(const SafePtr< DGVertex > &child)
add child
Definition: generic_rr.h:108
unsigned int num_children() const override
Implementation of RecurrenceRelation::num_children()
Definition: generic_rr.h:71
static SafePtr< RRImpl > Instance(const SafePtr< TargetType > &Tint, unsigned int dir)
Return an instance if applicable, or a null pointer otherwise.
Definition: generic_rr.h:55
SafePtr< DGVertex > rr_child(unsigned int i) const override
Implementation of RecurrenceRelation::rr_child()
Definition: generic_rr.h:75
static bool default_directional()
is this recurrence relation parameterized by a direction (x, y, or z).
Definition: generic_rr.h:99
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:99
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:892
Wedge is a typeholder for the result of a wedge product.
Definition: algebra.h:245