LIBINT  2.1.0-stable
comp_11_r2dotr2g12_11.h
1 /*
2  * This file is a part of Libint.
3  * Copyright (C) 2004-2014 Edward F. Valeev
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see http://www.gnu.org/licenses/.
17  *
18  */
19 
20 #ifndef _libint2_src_bin_libint_cr11r2dotr2g1211_h_
21 #define _libint2_src_bin_libint_cr11r2dotr2g1211_h_
22 
23 #include <iostream>
24 #include <sstream>
25 #include <string>
26 #include <vector>
27 #include <stdexcept>
28 #include <assert.h>
29 #include <dgvertex.h>
30 #include <rr.h>
31 #include <rr.templ.h>
32 #include <integral.h>
33 #include <r2dotr2g12_11_11.h>
34 #include <algebra.h>
35 #include <flop.h>
36 #include <prefactors.h>
37 #include <context.h>
38 #include <default_params.h>
39 
40 using namespace std;
41 
42 
43 namespace libint2 {
44 
49  template <template <class> class I, class BFSet>
51  {
52 
53  public:
55  typedef BFSet BasisFunctionType;
57  typedef I<BFSet> TargetType;
61 
65  static SafePtr<ThisType> Instance(const SafePtr<TargetType>&);
66  virtual ~CR_11_R2dotR2G12_11() {}
67 
69  unsigned int num_children() const { return nchildren_; };
71  SafePtr<TargetType> target() const { return target_; };
73  SafePtr<ChildType> child(unsigned int i) const;
75  SafePtr<DGVertex> rr_target() const { return static_pointer_cast<DGVertex,TargetType>(target()); }
77  SafePtr<DGVertex> rr_child(unsigned int i) const { return dynamic_pointer_cast<DGVertex,ChildType>(child(i)); }
79  bool is_simple() const {
81  }
82 
83  private:
89  CR_11_R2dotR2G12_11(const SafePtr<TargetType>&);
90 
91 #if 0
92  bool register_with_rrstack() const;
94 #endif
95 
96  static const unsigned int max_nchildren_ = 3;
97  SafePtr<TargetType> target_;
98  SafePtr<ChildType> children_[max_nchildren_];
99  unsigned int nchildren_;
100 
101  std::string generate_label() const
102  {
103  ostringstream os;
104  os << "RR ( " << rr_target()->label() << " )";
105  return os.str();
106  }
107 
108 
109  };
110 
111  template <template <class> class I, class F>
112  SafePtr< CR_11_R2dotR2G12_11<I,F> >
113  CR_11_R2dotR2G12_11<I,F>::Instance(const SafePtr<TargetType>& Tint)
114  {
115  SafePtr<ThisType> this_ptr(new ThisType(Tint));
116  // Do post-construction duties
117  if (this_ptr->num_children() != 0) {
118  this_ptr->register_with_rrstack<ThisType>();
119  return this_ptr;
120  }
121  return SafePtr<ThisType>();
122  }
123 
124  template <template <class> class I, class F>
125  CR_11_R2dotR2G12_11<I,F>::CR_11_R2dotR2G12_11(const SafePtr<I<F> >& Tint) :
126  ParentType(), target_(Tint), nchildren_(0)
127  {
128  F sh_a(Tint->bra(0,0));
129  F sh_b(Tint->ket(0,0));
130  F sh_c(Tint->bra(1,0));
131  F sh_d(Tint->ket(1,0));
132 
133  vector<F> bra;
134  vector<F> ket;
135  bra.push_back(sh_a);
136  bra.push_back(sh_c);
137  ket.push_back(sh_b);
138  ket.push_back(sh_d);
139 
140  vector<F>* bra_ref = &bra;
141  vector<F>* ket_ref = &ket;
142 
143  const unsigned int ndirs = is_simple() ? 3 : 1;
144  for(int xyz=0; xyz<ndirs; xyz++) {
145 
146  // c+1_i d+1_i
147  bra_ref->operator[](1).inc(xyz);
148  ket_ref->operator[](1).inc(xyz);
149  int next_child = nchildren_;
150  children_[next_child] = ChildType::Instance(bra[0],ket[0],bra[1],ket[1],0);
151  ++nchildren_;
152 
153  if (is_simple()) {
154  SafePtr<ExprType> expr0_ptr(new ExprType(ExprType::OperatorTypes::Times,Scalar(1.0),rr_child(next_child)));
155  add_expr(expr0_ptr);
156  nflops_ += 1;
157  }
158  bra_ref->operator[](1).dec(xyz);
159  ket_ref->operator[](1).dec(xyz);
160  }
161  }
162 
163  template <template <class> class I, class F>
164  SafePtr< typename CR_11_R2dotR2G12_11<I,F>::ChildType >
165  CR_11_R2dotR2G12_11<I,F>::child(unsigned int i) const
166  {
167  assert(i>=0 && i<nchildren_);
168  unsigned int nc=0;
169  for(int c=0; c<max_nchildren_; c++) {
170  if (children_[c] != 0) {
171  if (nc == i)
172  return children_[c];
173  nc++;
174  }
175  }
176  };
177 
181 
182 };
183 
184 #endif
RecurrenceRelation::ExprType ExprType
The type of expressions in which RecurrenceRelations result.
Definition: comp_11_r2dotr2g12_11.h:60
TrivialBFSet<T> defines static member result, which is true if T is a basis function set consisting o...
Definition: bfset.h:879
bool is_simple() const
Implementation of RecurrenceRelation::is_simple()
Definition: comp_11_r2dotr2g12_11.h:79
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
SafePtr< DGVertex > rr_child(unsigned int i) const
Implementation of RecurrenceRelation::rr_child()
Definition: comp_11_r2dotr2g12_11.h:77
Definition: stdarray.h:18
This is a vertex of a Directed Graph (DG)
Definition: dgvertex.h:42
AlgebraicOperator is an algebraic operator that acts on objects of type T.
Definition: algebra.h:47
SafePtr< TargetType > target() const
target() returns pointer to the i-th child
Definition: comp_11_r2dotr2g12_11.h:71
unsigned int num_children() const
Implementation of RecurrenceRelation::num_children()
Definition: comp_11_r2dotr2g12_11.h:69
RecurrenceRelation describes all recurrence relations.
Definition: rr.h:100
Set of basis functions.
Definition: bfset.h:41
SafePtr< DGVertex > rr_target() const
Implementation of RecurrenceRelation::rr_target()
Definition: comp_11_r2dotr2g12_11.h:75
Definition: integral_decl.h:37
Compute relation for 2-e integrals of the r2.r2 x G12 operators.
Definition: comp_11_r2dotr2g12_11.h:50