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> 48 template <
typename RRImpl,
typename F,
typename Target>
51 typedef F BasisFunctionType;
52 typedef Target TargetType;
57 static SafePtr<RRImpl>
Instance(
const SafePtr<TargetType>& Tint,
unsigned int dir) {
59 if (!RRImpl::directional() && dir != 0)
60 return SafePtr<RRImpl>();
62 SafePtr<RRImpl> this_ptr(
new RRImpl(Tint,dir));
64 if (this_ptr->num_children() != 0) {
65 this_ptr->template register_with_rrstack<RRImpl>();
69 return SafePtr<RRImpl>();
75 SafePtr<DGVertex>
rr_target()
const {
return static_pointer_cast<DGVertex,TargetType>(target_); }
77 SafePtr<DGVertex>
rr_child(
unsigned int i)
const {
78 return children_.at(i);
89 os << RRImpl::descr() <<
" " << target_->label();
95 target_(Tint), dir_(dir) {
96 children_.reserve(RRImpl::max_nchildren);
102 if (boost::is_same<BasisFunctionType,CGF>::value)
107 unsigned int dir()
const {
return dir_; }
110 const SafePtr<DGVertex>&
add_child(
const SafePtr<DGVertex>& child) {
111 typedef std::vector< SafePtr<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());
127 template <
class RealChildType>
128 const SafePtr<DGVertex>&
make_child(
const typename RealChildType::BasisFunctionType& A,
129 const typename RealChildType::BasisFunctionType& B,
130 const typename RealChildType::BasisFunctionType& C,
131 const typename RealChildType::BasisFunctionType& D,
132 const typename RealChildType::AuxIndexType& aux =
typename RealChildType::AuxIndexType(),
133 const typename RealChildType::OperType& oper =
typename RealChildType::OperType()) {
134 const SafePtr<DGVertex>& i = static_pointer_cast<DGVertex,RealChildType>(ChildType::Instance(A,B,C,D,aux,oper));
139 SafePtr<TargetType> target_;
143 std::vector< SafePtr<DGVertex> > children_;
148 template <
class GenRR,
class ChildType>
151 typedef typename ChildType::BasisFunctionType F;
152 typedef typename ChildType::AuxIndexType AuxIndexType;
153 typedef typename ChildType::OperType OperType;
162 const AuxIndexType& aux = AuxIndexType(),
163 const OperType& oper = OperType()) {
164 auto i = static_pointer_cast<DGVertex,ChildType>(ChildType::Instance(A,B,C,D,aux,oper));
165 return rr_->add_child(i);
170 const AuxIndexType& aux = AuxIndexType(),
171 const OperType& oper = OperType()) {
172 auto i = static_pointer_cast<DGVertex,ChildType>(ChildType::Instance(A,B,aux,oper));
173 return rr_->add_child(i);
176 const SafePtr<DGVertex>&
178 const AuxIndexType& aux = AuxIndexType(),
179 const OperType& oper = OperType()) {
180 auto i = static_pointer_cast<DGVertex,ChildType>(ChildType::Instance(braket_wedge,aux,oper));
181 return rr_->add_child(i);
184 const SafePtr<DGVertex>&
186 const AuxIndexType& aux = AuxIndexType(),
187 const OperType& oper = OperType()) {
188 auto i = static_pointer_cast<DGVertex,ChildType>(ChildType::Instance(braket_wedge,aux,oper));
189 return rr_->add_child(i);
194 const AuxIndexType& aux = AuxIndexType(),
195 const OperType& oper = OperType()) {
196 using namespace libint2::algebra;
202 const ProductLC& product_lc = bra_lc ^ ket_lc;
203 const size_t nprod = product_lc.size();
204 for(
unsigned int t=0; t<nprod; ++t) {
205 const typename ProductLC::term_t& term = product_lc[t];
206 auto child = make_child(term.second,aux,oper);
207 if (rr_->is_simple()) {
209 rr_->expr_ += term.first * child;
211 rr_->expr_ = term.first * child;
217 const AuxIndexType& aux = AuxIndexType(),
218 const OperType& oper = OperType()) {
219 using namespace libint2::prefactor;
221 bra_lc += make_pair(Scalar(1.0),bra);
222 wedge(bra_lc,ket_lc,aux,oper);
224 void wedge(
const LinearCombination< SafePtr<DGVertex>, BraketPair<F,PBra> >& bra_lc,
225 const BraketPair<F,PKet>& ket,
226 const AuxIndexType& aux = AuxIndexType(),
227 const OperType& oper = OperType()) {
228 using namespace libint2::prefactor;
229 LinearCombination< SafePtr<DGVertex>, BraketPair<F,PKet> > ket_lc;
230 ket_lc += make_pair(Scalar(1.0),ket);
231 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:101
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:158
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:57
TrivialBFSet<T> defines static member result, which is true if T is a basis function set consisting o...
Definition: bfset.h:892
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:185
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
Wedge is a typeholder for the result of a wedge product.
Definition: algebra.h:246
bool is_simple() const
Implementation of RecurrenceRelation::is_simple()
Definition: generic_rr.h:81
SafePtr< DGVertex > rr_child(unsigned int i) const
Implementation of RecurrenceRelation::rr_child()
Definition: generic_rr.h:77
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:192
RRImpl must inherit GenericRecurrenceRelation<RRImpl>
Definition: generic_rr.h:49
represents linear combination of objects of type T with coefficients of type C
Definition: algebra.h:223
unsigned int num_children() const
Implementation of RecurrenceRelation::num_children()
Definition: generic_rr.h:73
AlgebraicOperator is an algebraic operator that acts on objects of type T.
Definition: algebra.h:48
SafePtr< DGVertex > rr_target() const
Implementation of RecurrenceRelation::rr_target()
Definition: generic_rr.h:75
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:177
RecurrenceRelation describes all recurrence relations.
Definition: rr.h:101
const SafePtr< DGVertex > & add_child(const SafePtr< DGVertex > &child)
add child
Definition: generic_rr.h:110
BraketPair is a trimmed down version of ArrayBraket specialized for same-particle or different-partic...
Definition: braket.h:244
std::string generate_label() const
Implementation of RecurrenceRelation::generate_label()
Definition: generic_rr.h:86
Helps GenericRecurrenceRelation to work around the compiler problem with make_child.
Definition: generic_rr.h:149
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:128
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:168