21 #ifndef _libint2_src_bin_libint_compderivgauss_h_ 22 #define _libint2_src_bin_libint_compderivgauss_h_ 24 #include <generic_rr.h> 38 std::set<std::pair<unsigned int, bool> > template_instances_;
42 void add(
unsigned int L,
bool vectorize);
61 template <
class IntType,
63 FunctionPosition where,
64 int trans_inv_part = -1,
65 FunctionPosition trans_inv_where = InBra>
67 typename IntType::BasisFunctionType,
71 static constexpr
auto trans_inv_oper = not IntType::OperType::Properties::odep;
73 static constexpr
auto using_trans_inv = trans_inv_oper &&
74 (part == trans_inv_part) &&
75 (where == trans_inv_where);
79 typedef typename IntType::BasisFunctionType BasisFunctionType;
80 typedef IntType TargetType;
86 static constexpr
auto max_nchildren = using_trans_inv ? (IntType::num_bf - 1) : 2u;
88 using ParentType::Instance;
94 using ParentType::RecurrenceRelation::expr_;
95 using ParentType::RecurrenceRelation::nflops_;
96 using ParentType::target_;
97 using ParentType::is_simple;
102 static std::string descr() {
return "CR_DerivGauss"; }
106 std::string generate_label()
const 108 typedef typename TargetType::AuxIndexType mType;
109 static SafePtr<mType> aux0(
new mType(0u));
111 os << descr() <<
"P" << part << to_string(where)
112 << genintegralset_label(target_->bra(),target_->ket(),aux0,target_->oper());
116 #if LIBINT_ENABLE_GENERIC_CODE 117 bool has_generic(
const SafePtr<CompilationParameters>& cparams)
const;
120 std::string generic_header()
const;
122 std::string generic_instance(
const SafePtr<CodeContext>& context,
const SafePtr<CodeSymbols>& args)
const;
126 template <
class IntType,
int part, FunctionPosition where,
127 int trans_inv_part, FunctionPosition trans_inv_where>
128 CR_DerivGauss<IntType,part,where,trans_inv_part,trans_inv_where>::CR_DerivGauss(
129 const SafePtr< TargetType >& Tint,
133 using namespace libint2::algebra;
134 using namespace libint2::prefactor;
136 typedef BasisFunctionType F;
137 const F& _1 = unit<F>(
is_simple() ? dir : 0);
139 const typename IntType::AuxQuantaType& aux = Tint->aux();
140 const typename IntType::OperType& oper = Tint->oper();
146 if (where == InBra && Tint->bra(part,0).deriv().d(dir) == 0)
148 if (where == InKet && Tint->ket(part,0).deriv().d(dir) == 0)
154 if (not using_trans_inv) {
155 if (where == InBra && Tint->bra(part,0).contracted())
157 if (where == InKet && Tint->ket(part,0).contracted())
161 typedef typename IntType::BraType IBraType;
162 typedef typename IntType::KetType IKetType;
163 IBraType* bra =
new IBraType(Tint->bra());
164 IKetType* ket =
new IKetType(Tint->ket());
166 if (not using_trans_inv) {
168 if (where == InBra) {
169 F a(bra->member(part,0));
172 F ap1(bra->member(part,0) + _1);
173 ap1.deriv().dec(dir);
174 bra->set_member(ap1,part,0);
175 auto int_ap1 = this->
add_child(IntType::Instance(*bra,*ket,aux,oper));
176 bra->set_member(a,part,0);
178 std::ostringstream oss;
179 oss <<
"two_alpha" << part <<
"_bra";
180 expr_ = Scalar(oss.str()) * int_ap1; nflops_+=1;
184 F am1(bra->member(part,0) - _1);
186 am1.deriv().dec(dir);
187 bra->set_member(am1,part,0);
188 auto int_am1 = this->
add_child(IntType::Instance(*bra,*ket,aux,oper));
189 bra->set_member(a,part,0);
191 expr_ -= Scalar(a[dir]) * int_am1; nflops_+=2;
197 if (where == InKet) {
198 F a(ket->member(part,0));
201 F ap1(ket->member(part,0) + _1);
202 ap1.deriv().dec(dir);
203 ket->set_member(ap1,part,0);
204 auto int_ap1 = this->
add_child(IntType::Instance(*bra,*ket,aux,oper));
205 ket->set_member(a,part,0);
207 std::ostringstream oss;
208 oss <<
"two_alpha" << part <<
"_ket";
209 expr_ = Scalar(oss.str()) * int_ap1; nflops_+=1;
213 F am1(ket->member(part,0) - _1);
215 am1.deriv().dec(dir);
216 ket->set_member(am1,part,0);
217 auto int_am1 = this->
add_child(IntType::Instance(*bra,*ket,aux,oper));
218 ket->set_member(a,part,0);
220 expr_ -= Scalar(a[dir]) * int_am1; nflops_+=2;
228 if (where == InBra) bra->member(part,0).deriv().dec(dir);
229 if (where == InKet) ket->member(part,0).deriv().dec(dir);
232 for (
int p = 0; p != IntType::num_particles; ++p) {
233 if (p != trans_inv_part || trans_inv_where != InBra) {
234 F a(bra->member(p, 0));
235 if (not a.is_unit()) {
238 bra->set_member(da, p, 0);
240 this->
add_child(IntType::Instance(*bra, *ket, aux, oper));
241 bra->set_member(a, p, 0);
243 std::ostringstream oss;
245 expr_ = Scalar(-1) * int_da;
253 if (p != trans_inv_part || trans_inv_where != InKet) {
254 F a(ket->member(p, 0));
255 if (not a.is_unit()) {
258 ket->set_member(da, p, 0);
260 this->
add_child(IntType::Instance(*bra, *ket, aux, oper));
261 ket->set_member(a, p, 0);
263 std::ostringstream oss;
265 expr_ = Scalar(-1) * int_da;
279 #if LIBINT_ENABLE_GENERIC_CODE 280 template <
class IntType,
int part, FunctionPosition where,
281 int trans_inv_part, FunctionPosition trans_inv_where>
283 CR_DerivGauss<IntType,part,where,trans_inv_part,trans_inv_where>::has_generic(
284 const SafePtr<CompilationParameters>& cparams
288 if (using_trans_inv)
return false;
290 if (TrivialBFSet<BasisFunctionType>::result)
294 const unsigned int max_opt_am = cparams->max_am_opt();
295 unsigned int am_total = 0;
296 unsigned int nfunctions = 0;
297 const unsigned int np = IntType::OperType::Properties::np;
298 for(
unsigned int p=0; p<np; p++) {
299 unsigned int nbra = target_->bra().num_members(p);
300 for(
unsigned int i=0; i<nbra; i++) {
301 am_total += target_->bra(p,i).norm();
304 unsigned int nket = target_->ket().num_members(p);
305 for(
unsigned int i=0; i<nket; i++) {
306 am_total += target_->ket(p,i).norm();
310 if (am_total > max_opt_am*nfunctions)
317 template <
class IntType,
int part, FunctionPosition where,
318 int trans_inv_part, FunctionPosition trans_inv_where>
320 CR_DerivGauss<IntType,part,where,trans_inv_part,trans_inv_where>::generic_header()
const 322 return std::string(
"GenericGaussDeriv.h");
325 template <
class IntType,
int part, FunctionPosition where,
326 int trans_inv_part, FunctionPosition trans_inv_where>
328 CR_DerivGauss<IntType,part,where,trans_inv_part,trans_inv_where>::generic_instance(
329 const SafePtr<CodeContext>& context,
const SafePtr<CodeSymbols>& args
332 std::ostringstream oss;
334 oss <<
"using namespace libint2;" << endl;
336 BasisFunctionType sh(where == InBra ? target_->bra(part,0) : target_->ket(part,0));
338 const unsigned int L = sh.norm();
339 const bool vectorize = (context->cparams()->max_vector_length() == 1) ?
false :
true;
340 oss <<
"libint2::GenericGaussDeriv<" << L <<
"," 341 << (vectorize ?
"true" :
"false")
342 <<
">::compute(inteval";
344 oss <<
"," << args->symbol(0);
345 const unsigned int nargs = args->n();
346 for(
unsigned int a=1; a<nargs; a++) {
347 oss <<
"," << args->symbol(a);
354 unsigned int hsr = 1;
355 unsigned int lsr = 1;
356 const unsigned int np = IntType::OperType::Properties::np;
361 for(
int p=0; p<static_cast<int>(np); p++) {
362 unsigned int nbra = target_->bra().num_members(p);
364 for(
unsigned int i=0; i<nbra; i++) {
365 SubIterator* iter = target_->bra().member_subiter(p,i);
366 if (p < part || (p == part && where == InKet))
367 hsr *= iter->num_iter();
370 lsr *= iter->num_iter();
373 unsigned int nket = target_->ket().num_members(p);
375 for(
unsigned int i=0; i<nket; i++) {
376 SubIterator* iter = target_->ket().member_subiter(p,i);
378 hsr *= iter->num_iter();
380 if (p > part || (p == part && where == InBra))
381 lsr *= iter->num_iter();
385 oss <<
"," << hsr <<
"," << lsr;
388 oss <<
"," << this->dir();
391 oss <<
",inteval->two_alpha" << part <<
"_" << (where == InBra ?
"bra" :
"ket");
395 CR_DerivGauss_GenericInstantiator::instance().add(L, vectorize);
399 #endif // #if !LIBINT_ENABLE_GENERIC_CODE 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
RRImpl must inherit GenericRecurrenceRelation<RRImpl>
Definition: generic_rr.h:49
Compute relation for (geometric) derivative Gaussian ints of generic type IntType .
Definition: comp_deriv_gauss.h:66
these objects help to construct BraketPairs
Definition: braket.h:270
bool exists(const IncableBFSet &A)
Return true if A is valid.
Definition: bfset.h:92
const SafePtr< DGVertex > & add_child(const SafePtr< DGVertex > &child)
add child
Definition: generic_rr.h:110
static bool directional()
always directional! Cartesian derivatives are applied in a particular direction
Definition: comp_deriv_gauss.h:91
Definition: comp_deriv_gauss.h:31