21#ifndef _libint2_src_bin_libint_genericrr_h_
22#define _libint2_src_bin_libint_genericrr_h_
30#include <boost/type_traits/is_same.hpp>
37#include <prefactors.h>
39#include <default_params.h>
46 template <
typename RRImpl,
typename F,
typename Target>
49 typedef F BasisFunctionType;
50 typedef Target TargetType;
55 static SafePtr<RRImpl>
Instance(
const SafePtr<TargetType>& Tint,
unsigned int dir) {
57 if (!RRImpl::directional() && dir != 0)
58 return SafePtr<RRImpl>();
60 SafePtr<RRImpl> this_ptr(
new RRImpl(Tint,dir));
62 if (this_ptr->num_children() != 0) {
63 this_ptr->template register_with_rrstack<RRImpl>();
67 return SafePtr<RRImpl>();
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);
86 std::ostringstream os;
87 os << RRImpl::descr() <<
" " << target_->label();
93 target_(Tint), dir_(dir) {
94 children_.reserve(RRImpl::max_nchildren);
100 if (boost::is_same<BasisFunctionType,CGF>::value)
105 unsigned int dir()
const {
return dir_; }
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());
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));
137 SafePtr<TargetType> target_;
141 std::vector< SafePtr<DGVertex> > children_;
146 template <
class GenRR,
class ChildType>
149 typedef typename ChildType::BasisFunctionType F;
150 typedef typename ChildType::AuxIndexType AuxIndexType;
151 typedef typename ChildType::OperType OperType;
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);
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);
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);
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);
192 const AuxIndexType& aux = AuxIndexType(),
193 const OperType& oper = OperType()) {
194 using namespace libint2::algebra;
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()) {
207 rr_->expr_ += term.first * child;
209 rr_->expr_ = term.first * child;
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);
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);
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