21#ifndef _libint2_src_bin_libint_genericrr_h_
22#define _libint2_src_bin_libint_genericrr_h_
26#include <default_params.h>
30#include <prefactors.h>
34#include <boost/type_traits/is_same.hpp>
46template <
typename RRImpl,
typename F,
typename Target>
49 typedef F BasisFunctionType;
50 typedef Target TargetType;
56 const std::shared_ptr<TargetType>& Tint,
unsigned int dir) {
58 if (!RRImpl::directional() && dir != 0)
return std::shared_ptr<RRImpl>();
60 std::shared_ptr<RRImpl> this_ptr(
new RRImpl(Tint, dir));
62 if (this_ptr->num_children() != 0) {
63 this_ptr->template register_with_rrstack<RRImpl>();
67 return std::shared_ptr<RRImpl>();
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_);
77 std::shared_ptr<DGVertex>
rr_child(
unsigned int i)
const override {
78 return children_.at(i);
87 std::ostringstream os;
88 os << RRImpl::descr() <<
" " << target_->label();
95 : target_(Tint), dir_(dir) {
96 children_.reserve(RRImpl::max_nchildren);
102 if (boost::is_same<BasisFunctionType, CGF>::value)
return true;
106 unsigned int dir()
const {
return dir_; }
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());
122 template <
class RR,
class C>
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));
140 std::shared_ptr<TargetType> target_;
144 std::vector<std::shared_ptr<DGVertex> > children_;
149template <
class GenRR,
class ChildType>
152 typedef typename ChildType::BasisFunctionType F;
153 typedef typename ChildType::AuxIndexType AuxIndexType;
154 typedef typename ChildType::OperType OperType;
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);
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);
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);
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);
200 const AuxIndexType& aux = AuxIndexType(),
201 const OperType& oper = OperType()) {
202 using namespace libint2::algebra;
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()) {
213 rr_->expr_ += term.first * child;
215 rr_->expr_ = term.first * child;
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);
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);
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