21#ifndef _libint2_src_bin_libint_compderivgauss_h_
22#define _libint2_src_bin_libint_compderivgauss_h_
24#include <generic_rr.h>
36 std::set<std::pair<unsigned int, bool> > template_instances_;
40 void add(
unsigned int L,
bool vectorize);
59 template <
class IntType,
61 FunctionPosition where,
62 int trans_inv_part = -1,
63 FunctionPosition trans_inv_where = InBra>
65 typename IntType::BasisFunctionType,
69 static constexpr auto trans_inv_oper = not IntType::OperType::Properties::odep;
71 static constexpr auto using_trans_inv = trans_inv_oper &&
72 (part == trans_inv_part) &&
73 (where == trans_inv_where);
77 typedef typename IntType::BasisFunctionType BasisFunctionType;
78 typedef IntType TargetType;
84 static constexpr auto max_nchildren = using_trans_inv ? (IntType::num_bf - 1) : 2u;
92 using ParentType::RecurrenceRelation::expr_;
93 using ParentType::RecurrenceRelation::nflops_;
94 using ParentType::target_;
100 static std::string descr() {
return "CR_DerivGauss"; }
104 std::string generate_label()
const override
106 typedef typename TargetType::AuxIndexType
mType;
107 static SafePtr<mType> aux0(
new mType(0u));
108 std::ostringstream os;
109 os << descr() <<
"P" << part <<
to_string(where)
110 << genintegralset_label(target_->bra(),target_->ket(),aux0,target_->oper());
114#if LIBINT_ENABLE_GENERIC_CODE
116 bool has_generic(
const SafePtr<CompilationParameters>& cparams)
const override;
118 std::string generic_header()
const override;
120 std::string generic_instance(
const SafePtr<CodeContext>& context,
const SafePtr<CodeSymbols>& args)
const override;
124 template <
class IntType,
int part, FunctionPosition where,
125 int trans_inv_part, FunctionPosition trans_inv_where>
126 CR_DerivGauss<IntType,part,where,trans_inv_part,trans_inv_where>::CR_DerivGauss(
127 const SafePtr< TargetType >& Tint,
131 using namespace libint2::algebra;
132 using namespace libint2::prefactor;
134 typedef BasisFunctionType F;
135 const F& _1 = unit<F>(is_simple() ? dir : 0);
137 const typename IntType::AuxQuantaType& aux = Tint->aux();
138 const typename IntType::OperType& oper = Tint->oper();
144 if (where == InBra && Tint->bra(part,0).deriv().d(dir) == 0)
146 if (where == InKet && Tint->ket(part,0).deriv().d(dir) == 0)
152 if (not using_trans_inv) {
153 if (where == InBra && Tint->bra(part,0).contracted())
155 if (where == InKet && Tint->ket(part,0).contracted())
159 typedef typename IntType::BraType IBraType;
160 typedef typename IntType::KetType IKetType;
161 IBraType* bra =
new IBraType(Tint->bra());
162 IKetType* ket =
new IKetType(Tint->ket());
164 if (not using_trans_inv) {
166 if (where == InBra) {
167 F a(bra->member(part,0));
170 F ap1(bra->member(part,0) + _1);
171 ap1.deriv().dec(dir);
172 bra->set_member(ap1,part,0);
173 auto int_ap1 = this->
add_child(IntType::Instance(*bra,*ket,aux,oper));
174 bra->set_member(a,part,0);
176 std::ostringstream oss;
177 oss <<
"two_alpha" << part <<
"_bra";
178 expr_ = Scalar(oss.str()) * int_ap1; nflops_+=1;
182 F am1(bra->member(part,0) - _1);
184 am1.deriv().dec(dir);
185 bra->set_member(am1,part,0);
186 auto int_am1 = this->
add_child(IntType::Instance(*bra,*ket,aux,oper));
187 bra->set_member(a,part,0);
189 expr_ -= Scalar(a[dir]) * int_am1; nflops_+=2;
195 if (where == InKet) {
196 F a(ket->member(part,0));
199 F ap1(ket->member(part,0) + _1);
200 ap1.deriv().dec(dir);
201 ket->set_member(ap1,part,0);
202 auto int_ap1 = this->
add_child(IntType::Instance(*bra,*ket,aux,oper));
203 ket->set_member(a,part,0);
205 std::ostringstream oss;
206 oss <<
"two_alpha" << part <<
"_ket";
207 expr_ = Scalar(oss.str()) * int_ap1; nflops_+=1;
211 F am1(ket->member(part,0) - _1);
213 am1.deriv().dec(dir);
214 ket->set_member(am1,part,0);
215 auto int_am1 = this->
add_child(IntType::Instance(*bra,*ket,aux,oper));
216 ket->set_member(a,part,0);
218 expr_ -= Scalar(a[dir]) * int_am1; nflops_+=2;
226 if (where == InBra) bra->member(part,0).deriv().dec(dir);
227 if (where == InKet) ket->member(part,0).deriv().dec(dir);
230 for (
int p = 0; p != IntType::num_particles; ++p) {
231 if (p != trans_inv_part || trans_inv_where != InBra) {
232 F a(bra->member(p, 0));
233 if (not a.is_unit()) {
236 bra->set_member(da, p, 0);
238 this->
add_child(IntType::Instance(*bra, *ket, aux, oper));
239 bra->set_member(a, p, 0);
241 std::ostringstream oss;
243 expr_ = Scalar(-1) * int_da;
251 if (p != trans_inv_part || trans_inv_where != InKet) {
252 F a(ket->member(p, 0));
253 if (not a.is_unit()) {
256 ket->set_member(da, p, 0);
258 this->
add_child(IntType::Instance(*bra, *ket, aux, oper));
259 ket->set_member(a, p, 0);
261 std::ostringstream oss;
263 expr_ = Scalar(-1) * int_da;
277#if LIBINT_ENABLE_GENERIC_CODE
278 template <
class IntType,
int part, FunctionPosition where,
279 int trans_inv_part, FunctionPosition trans_inv_where>
281 CR_DerivGauss<IntType,part,where,trans_inv_part,trans_inv_where>::has_generic(
282 const SafePtr<CompilationParameters>& cparams
286 if (using_trans_inv)
return false;
288 if (TrivialBFSet<BasisFunctionType>::result)
292 const unsigned int max_opt_am = cparams->max_am_opt();
293 unsigned int am_total = 0;
294 unsigned int nfunctions = 0;
295 const unsigned int np = IntType::OperType::Properties::np;
296 for(
unsigned int p=0; p<np; p++) {
297 unsigned int nbra = target_->bra().num_members(p);
298 for(
unsigned int i=0; i<nbra; i++) {
299 am_total += target_->bra(p,i).norm();
302 unsigned int nket = target_->ket().num_members(p);
303 for(
unsigned int i=0; i<nket; i++) {
304 am_total += target_->ket(p,i).norm();
308 if (am_total > max_opt_am*nfunctions)
315 template <
class IntType,
int part, FunctionPosition where,
316 int trans_inv_part, FunctionPosition trans_inv_where>
318 CR_DerivGauss<IntType,part,where,trans_inv_part,trans_inv_where>::generic_header()
const
320 return std::string(
"GenericGaussDeriv.h");
323 template <
class IntType,
int part, FunctionPosition where,
324 int trans_inv_part, FunctionPosition trans_inv_where>
326 CR_DerivGauss<IntType,part,where,trans_inv_part,trans_inv_where>::generic_instance(
327 const SafePtr<CodeContext>& context,
const SafePtr<CodeSymbols>& args
330 std::ostringstream oss;
332 oss <<
"using namespace libint2;" << std::endl;
334 BasisFunctionType sh(where == InBra ? target_->bra(part,0) : target_->ket(part,0));
336 const unsigned int L = sh.norm();
337 const bool vectorize = (context->cparams()->max_vector_length() == 1) ?
false :
true;
338 oss <<
"libint2::GenericGaussDeriv<" << L <<
","
339 << (vectorize ?
"true" :
"false")
340 <<
">::compute(inteval";
342 oss <<
"," << args->symbol(0);
343 const unsigned int nargs = args->n();
344 for(
unsigned int a=1; a<nargs; a++) {
345 oss <<
"," << args->symbol(a);
352 unsigned int hsr = 1;
353 unsigned int lsr = 1;
354 const unsigned int np = IntType::OperType::Properties::np;
359 for(
int p=0; p<static_cast<int>(np); p++) {
360 unsigned int nbra = target_->bra().num_members(p);
362 for(
unsigned int i=0; i<nbra; i++) {
363 SubIterator* iter = target_->bra().member_subiter(p,i);
364 if (p < part || (p == part && where == InKet))
365 hsr *= iter->num_iter();
368 lsr *= iter->num_iter();
371 unsigned int nket = target_->ket().num_members(p);
373 for(
unsigned int i=0; i<nket; i++) {
374 SubIterator* iter = target_->ket().member_subiter(p,i);
376 hsr *= iter->num_iter();
378 if (p > part || (p == part && where == InBra))
379 lsr *= iter->num_iter();
383 oss <<
"," << hsr <<
"," << lsr;
386 oss <<
"," << this->dir();
389 oss <<
",inteval->two_alpha" << part <<
"_" << (where == InBra ?
"bra" :
"ket");
393 CR_DerivGauss_GenericInstantiator::instance().add(L, vectorize);
Definition: comp_deriv_gauss.h:29
Compute relation for (geometric) derivative Gaussian ints of generic type IntType .
Definition: comp_deriv_gauss.h:67
static bool directional()
always directional! Cartesian derivatives are applied in a particular direction
Definition: comp_deriv_gauss.h:89
RRImpl must inherit GenericRecurrenceRelation<RRImpl>
Definition: generic_rr.h:47
bool is_simple() const override
Implementation of RecurrenceRelation::is_simple()
Definition: generic_rr.h:79
const SafePtr< DGVertex > & add_child(const SafePtr< DGVertex > &child)
add child
Definition: generic_rr.h:108
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:55
these objects help to construct BraketPairs
Definition: src/bin/libint/braket.h:270
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
bool exists(const IncableBFSet &A)
Return true if A is valid.
Definition: bfset.h:92
DefaultQuantumNumbers< unsignedint, 1 >::Result mType
mType is the type that describes the auxiliary index of standard 2-body repulsion integrals
Definition: quanta.h:408
std::string to_string(const T &x)
Converts x to its string representation.
Definition: entity.h:74