20 #ifndef _libint2_src_bin_libint_genericrr_h_ 21 #define _libint2_src_bin_libint_genericrr_h_ 29 #include <boost/type_traits/is_same.hpp> 36 #include <prefactors.h> 38 #include <default_params.h> 47 template <
typename RRImpl,
typename F,
typename Target>
50 typedef F BasisFunctionType;
51 typedef Target TargetType;
56 static SafePtr<RRImpl>
Instance(
const SafePtr<TargetType>& Tint,
unsigned int dir) {
58 if (!RRImpl::directional() && dir != 0)
59 return SafePtr<RRImpl>();
61 SafePtr<RRImpl> this_ptr(
new RRImpl(Tint,dir));
63 if (this_ptr->num_children() != 0) {
64 this_ptr->template register_with_rrstack<RRImpl>();
68 return SafePtr<RRImpl>();
74 SafePtr<DGVertex>
rr_target()
const {
return static_pointer_cast<
DGVertex,TargetType>(target_); }
76 SafePtr<DGVertex>
rr_child(
unsigned int i)
const {
77 return children_.at(i);
88 os << RRImpl::descr() <<
" " << target_->label();
94 target_(Tint), dir_(dir) {
95 children_.reserve(RRImpl::max_nchildren);
101 if (boost::is_same<BasisFunctionType,CGF>::value)
106 unsigned int dir()
const {
return dir_; }
109 const SafePtr<DGVertex>&
add_child(
const SafePtr<DGVertex>& child) {
110 typedef std::vector< SafePtr<DGVertex> > cvector;
111 typedef typename cvector::const_iterator citer;
112 const citer pos = std::find(children_.begin(),children_.end(),child);
113 if (pos == children_.end()) {
114 children_.push_back(child);
115 return *(children_.rbegin());
126 template <
class RealChildType>
127 const SafePtr<DGVertex>&
make_child(
const typename RealChildType::BasisFunctionType& A,
128 const typename RealChildType::BasisFunctionType& B,
129 const typename RealChildType::BasisFunctionType& C,
130 const typename RealChildType::BasisFunctionType& D,
131 const typename RealChildType::AuxIndexType& aux =
typename RealChildType::AuxIndexType(),
132 const typename RealChildType::OperType& oper =
typename RealChildType::OperType()) {
133 const SafePtr<DGVertex>& i = static_pointer_cast<
DGVertex,RealChildType>(ChildType::Instance(A,B,C,D,aux,oper));
138 SafePtr<TargetType> target_;
142 std::vector< SafePtr<DGVertex> > children_;
147 template <
class GenRR,
class ChildType>
150 typedef typename ChildType::BasisFunctionType F;
151 typedef typename ChildType::AuxIndexType AuxIndexType;
152 typedef typename ChildType::OperType OperType;
161 const AuxIndexType& aux = AuxIndexType(),
162 const OperType& oper = OperType()) {
163 auto i = static_pointer_cast<
DGVertex,ChildType>(ChildType::Instance(A,B,C,D,aux,oper));
164 return rr_->add_child(i);
169 const AuxIndexType& aux = AuxIndexType(),
170 const OperType& oper = OperType()) {
171 auto i = static_pointer_cast<
DGVertex,ChildType>(ChildType::Instance(A,B,aux,oper));
172 return rr_->add_child(i);
175 const SafePtr<DGVertex>&
177 const AuxIndexType& aux = AuxIndexType(),
178 const OperType& oper = OperType()) {
179 auto i = static_pointer_cast<
DGVertex,ChildType>(ChildType::Instance(braket_wedge,aux,oper));
180 return rr_->add_child(i);
183 const SafePtr<DGVertex>&
185 const AuxIndexType& aux = AuxIndexType(),
186 const OperType& oper = OperType()) {
187 auto i = static_pointer_cast<
DGVertex,ChildType>(ChildType::Instance(braket_wedge,aux,oper));
188 return rr_->add_child(i);
193 const AuxIndexType& aux = AuxIndexType(),
194 const OperType& oper = OperType()) {
201 const ProductLC& product_lc = bra_lc ^ ket_lc;
202 const size_t nprod = product_lc.size();
203 for(
unsigned int t=0; t<nprod; ++t) {
204 const typename ProductLC::term_t& term = product_lc[t];
205 auto child = make_child(term.second,aux,oper);
206 if (rr_->is_simple()) {
208 rr_->expr_ += term.first * child;
210 rr_->expr_ = term.first * child;
216 const AuxIndexType& aux = AuxIndexType(),
217 const OperType& oper = OperType()) {
220 bra_lc += make_pair(Scalar(1.0),bra);
221 wedge(bra_lc,ket_lc,aux,oper);
225 const AuxIndexType& aux = AuxIndexType(),
226 const OperType& oper = OperType()) {
229 ket_lc += make_pair(Scalar(1.0),ket);
230 wedge(bra_lc,ket_lc,aux,oper);
static bool default_directional()
is this recurrence relation parameterized by a direction (x, y, or z).
Definition: generic_rr.h:100
SafePtr< DGVertex > rr_target() const
Implementation of RecurrenceRelation::rr_target()
Definition: generic_rr.h:74
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:157
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:56
TrivialBFSet<T> defines static member result, which is true if T is a basis function set consisting o...
Definition: bfset.h:879
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:184
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
Definition: stdarray.h:18
Wedge is a typeholder for the result of a wedge product.
Definition: algebra.h:245
Definition: prefactors.h:159
This is a vertex of a Directed Graph (DG)
Definition: dgvertex.h:42
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:191
RRImpl must inherit GenericRecurrenceRelation<RRImpl>
Definition: generic_rr.h:48
represents linear combination of objects of type T with coefficients of type C
Definition: algebra.h:222
AlgebraicOperator is an algebraic operator that acts on objects of type T.
Definition: algebra.h:47
bool is_simple() const
Implementation of RecurrenceRelation::is_simple()
Definition: generic_rr.h:80
std::string generate_label() const
Implementation of RecurrenceRelation::generate_label()
Definition: generic_rr.h:85
unsigned int num_children() const
Implementation of RecurrenceRelation::num_children()
Definition: generic_rr.h:72
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:176
RecurrenceRelation describes all recurrence relations.
Definition: rr.h:100
const SafePtr< DGVertex > & add_child(const SafePtr< DGVertex > &child)
add child
Definition: generic_rr.h:109
BraketPair is a trimmed down version of ArrayBraket specialized for same-particle or different-partic...
Definition: braket.h:416
Helps GenericRecurrenceRelation to work around the compiler problem with make_child.
Definition: generic_rr.h:148
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:127
SafePtr< DGVertex > rr_child(unsigned int i) const
Implementation of RecurrenceRelation::rr_child()
Definition: generic_rr.h:76
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:167