LIBINT  2.1.0-stable
comp_11_g12tig12_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_cr11g12tig1211_h_
21 #define _libint2_src_bin_libint_cr11g12tig1211_h_
22 
23 #include <generic_rr.h>
24 #include <gaussoper.h>
25 
26 using namespace std;
27 
28 namespace libint2 {
29 
32  template <class BFSet>
33  class CR_11_G12TiG12_11 : public GenericRecurrenceRelation< CR_11_G12TiG12_11<BFSet>,
34  BFSet,
35  GenIntegralSet_11_11<BFSet,G12TiG12,mType> >
36  {
37  public:
39  typedef BFSet BasisFunctionType;
42  friend class GenericRecurrenceRelation<ThisType,BFSet,TargetType>;
43  static const unsigned int max_nchildren = 1;
44 
45  using ParentType::Instance;
46 
48  static bool directional() { return false; }
49 
50  private:
51  using ParentType::RecurrenceRelation::expr_;
52  using ParentType::RecurrenceRelation::nflops_;
53  using ParentType::target_;
54  using ParentType::is_simple;
55 
57  CR_11_G12TiG12_11(const SafePtr<TargetType>&, unsigned int dir);
58  static std::string descr() { return "CR"; }
59 
60 #if LIBINT_ENABLE_GENERIC_CODE
61  bool has_generic(const SafePtr<CompilationParameters>& cparams) const;
64  std::string generic_header() const { return "GenericScale.h"; }
66  std::string generic_instance(const SafePtr<CodeContext>& context, const SafePtr<CodeSymbols>& args) const;
67 #endif
68  };
69 
70  template <class F>
71  CR_11_G12TiG12_11<F>::CR_11_G12TiG12_11(const SafePtr<TargetType>& Tint,
72  unsigned int dir) :
73  ParentType(Tint,dir)
74  {
75  if (dir != 0)
76  return;
77  using namespace libint2::algebra;
78  using namespace libint2::prefactor;
79  using namespace libint2::braket;
80  // kinetic energy of which electron?
81  //const int i = target_->oper()->descr().K();
82  const R12kG12 G2(2);
83 
84  F a(Tint->bra(0,0));
85  F b(Tint->ket(0,0));
86  F c(Tint->bra(1,0));
87  F d(Tint->ket(1,0));
88 
89  if (target_->oper()->descr().contracted())
90  return;
91 
92  // [G12,[T1,G12]] = [G12,[T2,G12]]
93  {
96  auto ab_G2_cd = factory.make_child(a,b,c,d,0u,G2);
97  if (is_simple()) {
98  expr_ = Scalar("R12_2_G12_scale_to_G12T1G12") * ab_G2_cd;
99  nflops_ += 1;
100  }
101  }
102 
103  }
104 
105 #if LIBINT_ENABLE_GENERIC_CODE
106  template <class F>
107  bool
108  CR_11_G12TiG12_11<F>::has_generic(const SafePtr<CompilationParameters>& cparams) const
109  {
110  F sh_a(target_->bra(0,0));
111  F sh_b(target_->ket(0,0));
112  F sh_c(target_->bra(1,0));
113  F sh_d(target_->ket(1,0));
114  const unsigned int max_opt_am = cparams->max_am_opt();
115  // to generate optimized code for xxxx integral need to generate specialized code for up to (x+x)0(x+x)0 integrals
117  (sh_a.norm() > max_opt_am ||
118  sh_b.norm() > max_opt_am ||
119  sh_c.norm() > max_opt_am ||
120  sh_d.norm() > max_opt_am
121  )
122  )
123  return true;
124  return false;
125  }
126 
127  template <class F>
128  std::string
129  CR_11_G12TiG12_11<F>::generic_instance(const SafePtr<CodeContext>& context, const SafePtr<CodeSymbols>& args) const {
130  std::ostringstream oss;
131 
132  const bool vec = (context->cparams()->max_vector_length() != 1);
133  if (vec)
134  oss << "_libint2_static_api_scale_vec_short_(";
135  else
136  oss << "_libint2_static_api_scale_short_(";
137 
138  const unsigned int nargs = args->n();
139  for(unsigned int a=0; a<nargs; a++) {
140  oss << args->symbol(a) << ",";
141  }
142 
143  oss << target_->size() << "*" << (vec ? "inteval->veclen" : "1")
144  << ",inteval->R12_2_G12_scale_to_G12T1G12" << (vec ? ",inteval->veclen" : "[0]") << ");";
145 
146  // HACK alert ... unfortunately it's not completely possible to figure out all "precomputed" symbols from the DAG alone
147  // force R12_2_G12_scale_to_G12T1G12 on the list of symbols
148  {
149  LibraryTaskManager& taskmgr = LibraryTaskManager::Instance();
150  std::list<std::string> forced_symbol;
151  forced_symbol.push_back(std::string("R12_2_G12_scale_to_G12T1G12"));
152  taskmgr.current().symbols()->add(forced_symbol);
153  }
154 
155  return oss.str();
156  }
157 #endif
158 
159 };
160 
161 #endif
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
Manages tasks. This is a Singleton.
Definition: task.h:62
TrivialBFSet<T> defines static member result, which is true if T is a basis function set consisting o...
Definition: bfset.h:879
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
Definition: stdarray.h:18
Definition: prefactors.h:159
GenOper is a single operator described by descriptor Descr.
Definition: oper.h:152
Generic integral over a two-body operator with one bfs for each particle in bra and ket...
Definition: integral_11_11.h:32
void current(const std::string &task_label)
Makes this task current (must have been added already)
Definition: task.cc:64
RRImpl must inherit GenericRecurrenceRelation<RRImpl>
Definition: generic_rr.h:48
Definition: algebra.h:32
these objects help to construct BraketPairs
Definition: braket.h:442
Compute relation for 2-e integrals of the G12_Ti_G12 operators.
Definition: comp_11_g12tig12_11.h:33
static bool directional()
This relation is not directional.
Definition: comp_11_g12tig12_11.h:48
Set of basis functions.
Definition: bfset.h:41
Helps GenericRecurrenceRelation to work around the compiler problem with make_child.
Definition: generic_rr.h:148