LIBINT  2.6.0
comp_11_g12tig12_11.h
1 /*
2  * Copyright (C) 2004-2019 Edward F. Valeev
3  *
4  * This file is part of Libint.
5  *
6  * Libint is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Libint is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Libint. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef _libint2_src_bin_libint_cr11g12tig1211_h_
22 #define _libint2_src_bin_libint_cr11g12tig1211_h_
23 
24 #include <generic_rr.h>
25 #include <gaussoper.h>
26 
27 using namespace std;
28 
29 namespace libint2 {
30 
33  template <class BFSet>
34  class CR_11_G12TiG12_11 : public GenericRecurrenceRelation< CR_11_G12TiG12_11<BFSet>,
35  BFSet,
36  GenIntegralSet_11_11<BFSet,G12TiG12,mType> >
37  {
38  public:
40  typedef BFSet BasisFunctionType;
44  static const unsigned int max_nchildren = 1;
45 
46  using ParentType::Instance;
47 
49  static bool directional() { return false; }
50 
51  private:
52  using ParentType::RecurrenceRelation::expr_;
53  using ParentType::RecurrenceRelation::nflops_;
54  using ParentType::target_;
55  using ParentType::is_simple;
56 
58  CR_11_G12TiG12_11(const SafePtr<TargetType>&, unsigned int dir);
59  static std::string descr() { return "CR"; }
60 
61 #if LIBINT_ENABLE_GENERIC_CODE
62  bool has_generic(const SafePtr<CompilationParameters>& cparams) const;
65  std::string generic_header() const { return "GenericScale.h"; }
67  std::string generic_instance(const SafePtr<CodeContext>& context, const SafePtr<CodeSymbols>& args) const;
68 #endif
69  };
70 
71  template <class F>
72  CR_11_G12TiG12_11<F>::CR_11_G12TiG12_11(const SafePtr<TargetType>& Tint,
73  unsigned int dir) :
74  ParentType(Tint,dir)
75  {
76  if (dir != 0)
77  return;
78  using namespace libint2::algebra;
79  using namespace libint2::prefactor;
80  using namespace libint2::braket;
81  // kinetic energy of which electron?
82  //const int i = target_->oper()->descr().K();
83  const R12kG12 G2(2);
84 
85  F a(Tint->bra(0,0));
86  F b(Tint->ket(0,0));
87  F c(Tint->bra(1,0));
88  F d(Tint->ket(1,0));
89 
90  if (target_->oper()->descr().contracted())
91  return;
92 
93  // [G12,[T1,G12]] = [G12,[T2,G12]]
94  {
95  typedef GenIntegralSet_11_11<BasisFunctionType,R12kG12,mType> ChildType;
96  ChildFactory<ThisType,ChildType> factory(this);
97  auto ab_G2_cd = factory.make_child(a,b,c,d,0u,G2);
98  if (is_simple()) {
99  expr_ = Scalar("R12_2_G12_scale_to_G12T1G12") * ab_G2_cd;
100  nflops_ += 1;
101  }
102  }
103 
104  }
105 
106 #if LIBINT_ENABLE_GENERIC_CODE
107  template <class F>
108  bool
109  CR_11_G12TiG12_11<F>::has_generic(const SafePtr<CompilationParameters>& cparams) const
110  {
111  F sh_a(target_->bra(0,0));
112  F sh_b(target_->ket(0,0));
113  F sh_c(target_->bra(1,0));
114  F sh_d(target_->ket(1,0));
115  const unsigned int max_opt_am = cparams->max_am_opt();
116  // to generate optimized code for xxxx integral need to generate specialized code for up to (x+x)0(x+x)0 integrals
117  if (!TrivialBFSet<F>::result &&
118  (sh_a.norm() > max_opt_am ||
119  sh_b.norm() > max_opt_am ||
120  sh_c.norm() > max_opt_am ||
121  sh_d.norm() > max_opt_am
122  )
123  )
124  return true;
125  return false;
126  }
127 
128  template <class F>
129  std::string
130  CR_11_G12TiG12_11<F>::generic_instance(const SafePtr<CodeContext>& context, const SafePtr<CodeSymbols>& args) const {
131  std::ostringstream oss;
132 
133  const bool vec = (context->cparams()->max_vector_length() != 1);
134  if (vec)
135  oss << "_libint2_static_api_scale_vec_short_(";
136  else
137  oss << "_libint2_static_api_scale_short_(";
138 
139  const unsigned int nargs = args->n();
140  for(unsigned int a=0; a<nargs; a++) {
141  oss << args->symbol(a) << ",";
142  }
143 
144  oss << target_->size() << "*" << (vec ? "inteval->veclen" : "1")
145  << ",inteval->R12_2_G12_scale_to_G12T1G12" << (vec ? ",inteval->veclen" : "[0]") << ");";
146 
147  // HACK alert ... unfortunately it's not completely possible to figure out all "precomputed" symbols from the DAG alone
148  // force R12_2_G12_scale_to_G12T1G12 on the list of symbols
149  {
150  LibraryTaskManager& taskmgr = LibraryTaskManager::Instance();
151  std::list<std::string> forced_symbol;
152  forced_symbol.push_back(std::string("R12_2_G12_scale_to_G12T1G12"));
153  taskmgr.current().symbols()->add(forced_symbol);
154  }
155 
156  return oss.str();
157  }
158 #endif
159 
160 };
161 
162 #endif
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
bool is_simple() const
Implementation of RecurrenceRelation::is_simple()
Definition: generic_rr.h:81
Generic integral over a two-body operator with one bfs for each particle in bra and ket.
Definition: integral_11_11.h:33
RRImpl must inherit GenericRecurrenceRelation<RRImpl>
Definition: generic_rr.h:49
these objects help to construct BraketPairs
Definition: braket.h:270
Compute relation for 2-e integrals of the G12_Ti_G12 operators.
Definition: comp_11_g12tig12_11.h:34
static bool directional()
This relation is not directional.
Definition: comp_11_g12tig12_11.h:49
Set of basis functions.
Definition: bfset.h:42
static LibraryTaskManager & Instance()
LibraryTaskManager is a Singleton.
Definition: task.cc:34