20 #ifndef _libint2_src_bin_libint_compderivgauss_h_ 21 #define _libint2_src_bin_libint_compderivgauss_h_ 23 #include <generic_rr.h> 37 std::set<std::pair<unsigned int, bool> > template_instances_;
41 void add(
unsigned int L,
bool vectorize);
47 template <
class IntType,
int part, FunctionPosition where>
49 typename IntType::BasisFunctionType,
54 typedef typename IntType::BasisFunctionType BasisFunctionType;
55 typedef IntType TargetType;
58 static const unsigned int max_nchildren = 2;
60 using ParentType::Instance;
66 using ParentType::RecurrenceRelation::expr_;
67 using ParentType::RecurrenceRelation::nflops_;
68 using ParentType::target_;
69 using ParentType::is_simple;
74 static std::string descr() {
return "CR_DerivGauss"; }
78 std::string generate_label()
const 80 typedef typename TargetType::AuxIndexType
mType;
81 static SafePtr<mType> aux0(
new mType(0u));
83 os << descr() <<
"P" << part <<
to_string(where)
84 << genintegralset_label(target_->bra(),target_->ket(),aux0,target_->oper());
88 #if LIBINT_ENABLE_GENERIC_CODE 89 bool has_generic(
const SafePtr<CompilationParameters>& cparams)
const;
92 std::string generic_header()
const;
94 std::string generic_instance(
const SafePtr<CodeContext>& context,
const SafePtr<CodeSymbols>& args)
const;
98 template <
class IntType,
int part, FunctionPosition where>
106 typedef BasisFunctionType F;
107 const F& _1 = unit<F>(is_simple() ? dir : 0);
109 const typename IntType::AuxQuantaType& aux = Tint->aux();
110 const typename IntType::OperType& oper = Tint->oper();
114 if (where == InBra && Tint->bra(part,0).contracted())
116 if (where == InKet && Tint->ket(part,0).contracted())
122 if (where == InBra && Tint->bra(part,0).deriv().d(dir) == 0)
124 if (where == InKet && Tint->ket(part,0).deriv().d(dir) == 0)
128 typedef typename IntType::BraType IBraType;
129 typedef typename IntType::KetType IKetType;
130 IBraType* bra =
new IBraType(Tint->bra());
131 IKetType* ket =
new IKetType(Tint->ket());
133 if (where == InBra) {
134 F a(bra->member(part,0));
137 F ap1(bra->member(part,0) + _1);
138 ap1.deriv().dec(dir);
139 bra->set_member(ap1,part,0);
140 auto int_ap1 = this->add_child(IntType::Instance(*bra,*ket,aux,oper));
141 bra->set_member(a,part,0);
143 std::ostringstream oss;
144 oss <<
"two_alpha" << part <<
"_bra";
145 expr_ = Scalar(oss.str()) * int_ap1; nflops_+=1;
149 F am1(bra->member(part,0) - _1);
151 am1.deriv().dec(dir);
152 bra->set_member(am1,part,0);
153 auto int_am1 = this->add_child(IntType::Instance(*bra,*ket,aux,oper));
154 bra->set_member(a,part,0);
156 expr_ -= Scalar(a[dir]) * int_am1; nflops_+=2;
162 if (where == InKet) {
163 F a(ket->member(part,0));
166 F ap1(ket->member(part,0) + _1);
167 ap1.deriv().dec(dir);
168 ket->set_member(ap1,part,0);
169 auto int_ap1 = this->add_child(IntType::Instance(*bra,*ket,aux,oper));
170 ket->set_member(a,part,0);
172 std::ostringstream oss;
173 oss <<
"two_alpha" << part <<
"_ket";
174 expr_ = Scalar(oss.str()) * int_ap1; nflops_+=1;
178 F am1(ket->member(part,0) - _1);
180 am1.deriv().dec(dir);
181 ket->set_member(am1,part,0);
182 auto int_am1 = this->add_child(IntType::Instance(*bra,*ket,aux,oper));
183 ket->set_member(a,part,0);
185 expr_ -= Scalar(a[dir]) * int_am1; nflops_+=2;
194 #if LIBINT_ENABLE_GENERIC_CODE 195 template <
class IntType,
int part, FunctionPosition where>
203 const unsigned int max_opt_am = cparams->max_am_opt();
204 unsigned int am_total = 0;
205 unsigned int nfunctions = 0;
206 const unsigned int np = IntType::OperType::Properties::np;
207 for(
unsigned int p=0; p<np; p++) {
208 unsigned int nbra = target_->bra().num_members(p);
209 for(
unsigned int i=0; i<nbra; i++) {
210 am_total += target_->bra(p,i).norm();
213 unsigned int nket = target_->ket().num_members(p);
214 for(
unsigned int i=0; i<nket; i++) {
215 am_total += target_->ket(p,i).norm();
219 if (am_total > max_opt_am*nfunctions)
226 template <
class IntType,
int part, FunctionPosition where>
230 return std::string(
"GenericGaussDeriv.h");
233 template <
class IntType,
int part, FunctionPosition where>
237 std::ostringstream oss;
239 oss <<
"using namespace libint2;" << endl;
241 BasisFunctionType sh(where == InBra ? target_->bra(part,0) : target_->ket(part,0));
243 const unsigned int L = sh.norm();
244 const bool vectorize = (context->cparams()->max_vector_length() == 1) ?
false :
true;
245 oss <<
"libint2::GenericGaussDeriv<" << L <<
"," 246 << (vectorize ?
"true" :
"false")
247 <<
">::compute(inteval";
249 oss <<
"," << args->symbol(0);
250 const unsigned int nargs = args->n();
251 for(
unsigned int a=1; a<nargs; a++) {
252 oss <<
"," << args->symbol(a);
259 unsigned int hsr = 1;
260 unsigned int lsr = 1;
261 const unsigned int np = IntType::OperType::Properties::np;
266 for(
int p=0; p<static_cast<int>(np); p++) {
267 unsigned int nbra = target_->bra().num_members(p);
269 for(
unsigned int i=0; i<nbra; i++) {
270 SubIterator* iter = target_->bra().member_subiter(p,i);
271 if (p < part || (p == part && where == InKet))
278 unsigned int nket = target_->ket().num_members(p);
280 for(
unsigned int i=0; i<nket; i++) {
281 SubIterator* iter = target_->ket().member_subiter(p,i);
285 if (p > part || (p == part && where == InBra))
290 oss <<
"," << hsr <<
"," << lsr;
293 oss <<
"," << this->dir();
296 oss <<
",inteval->two_alpha" << part <<
"_" << (where == InBra ?
"bra" :
"ket");
300 CR_DerivGauss_GenericInstantiator::instance().add(L, vectorize);
304 #endif // #if !LIBINT_ENABLE_GENERIC_CODE TrivialBFSet<T> defines static member result, which is true if T is a basis function set consisting o...
Definition: bfset.h:879
static bool directional()
always directional! Cartesian derivatives are applied in a particular direction
Definition: comp_deriv_gauss.h:63
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
Definition: stdarray.h:18
Definition: prefactors.h:159
RRImpl must inherit GenericRecurrenceRelation<RRImpl>
Definition: generic_rr.h:48
QuantumNumbersA<T,N> is a set of N quantum numbers of type T implemented in terms of a C-style array...
Definition: quanta.h:198
compute relation for derivative 2-e ERI.
Definition: comp_deriv_gauss.h:48
std::string to_string(const T &x)
Converts x to its string representation.
Definition: entity.h:71
these objects help to construct BraketPairs
Definition: braket.h:442
bool exists(const IncableBFSet &A)
Return true if A is valid.
Definition: bfset.h:91
Iterator provides a base class for all object iterator classes.
Definition: iter.h:44
virtual unsigned int num_iter() const =0
Returns a number of iterations (number of elements in a set over which to iterate).
Definition: comp_deriv_gauss.h:30