LIBINT 2.9.0
comp_11_r2dotr2g12_11.h
1/*
2 * Copyright (C) 2004-2024 Edward F. Valeev
3 *
4 * This file is part of Libint compiler.
5 *
6 * Libint compiler 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 compiler 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 compiler. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_bin_libint_cr11r2dotr2g1211_h_
22#define _libint2_src_bin_libint_cr11r2dotr2g1211_h_
23
24#include <algebra.h>
25#include <context.h>
26#include <default_params.h>
27#include <dgvertex.h>
28#include <flop.h>
29#include <integral.h>
30#include <prefactors.h>
31#include <r2dotr2g12_11_11.h>
32#include <rr.h>
33#include <rr.templ.h>
34
35#include <cassert>
36#include <iostream>
37#include <sstream>
38#include <stdexcept>
39#include <string>
40#include <vector>
41
42namespace libint2 {
43
48template <template <class> class I, class BFSet>
50 public:
54 typedef I<BFSet> TargetType;
58
63 static std::shared_ptr<ThisType> Instance(const std::shared_ptr<TargetType>&);
64 virtual ~CR_11_R2dotR2G12_11() {}
65
67 unsigned int num_children() const override { return nchildren_; }
69 std::shared_ptr<TargetType> target() const { return target_; };
71 std::shared_ptr<ChildType> child(unsigned int i) const;
73 std::shared_ptr<DGVertex> rr_target() const override {
74 return std::static_pointer_cast<DGVertex, TargetType>(target());
75 }
77 std::shared_ptr<DGVertex> rr_child(unsigned int i) const override {
78 return std::dynamic_pointer_cast<DGVertex, ChildType>(child(i));
79 }
81 bool is_simple() const override { return TrivialBFSet<BFSet>::result; }
82
83 private:
89 CR_11_R2dotR2G12_11(const std::shared_ptr<TargetType>&);
90
91#if 0
93 bool register_with_rrstack() const;
94#endif
95
96 static const unsigned int max_nchildren_ = 3;
97 std::shared_ptr<TargetType> target_;
98 std::shared_ptr<ChildType> children_[max_nchildren_];
99 unsigned int nchildren_;
100
101 std::string generate_label() const override {
102 std::ostringstream os;
103 os << "RR ( " << rr_target()->label() << " )";
104 return os.str();
105 }
106};
107
108template <template <class> class I, class F>
109std::shared_ptr<CR_11_R2dotR2G12_11<I, F> > CR_11_R2dotR2G12_11<I, F>::Instance(
110 const std::shared_ptr<TargetType>& Tint) {
111 std::shared_ptr<ThisType> this_ptr(new ThisType(Tint));
112 // Do post-construction duties
113 if (this_ptr->num_children() != 0) {
114 this_ptr->register_with_rrstack<ThisType>();
115 return this_ptr;
116 }
117 return std::shared_ptr<ThisType>();
118}
119
120template <template <class> class I, class F>
122 const std::shared_ptr<I<F> >& Tint)
123 : ParentType(), target_(Tint), nchildren_(0) {
124 F sh_a(Tint->bra(0, 0));
125 F sh_b(Tint->ket(0, 0));
126 F sh_c(Tint->bra(1, 0));
127 F sh_d(Tint->ket(1, 0));
128
129 std::vector<F> bra;
130 std::vector<F> ket;
131 bra.push_back(sh_a);
132 bra.push_back(sh_c);
133 ket.push_back(sh_b);
134 ket.push_back(sh_d);
135
136 auto* bra_ref = &bra;
137 auto* ket_ref = &ket;
138
139 const unsigned int ndirs = is_simple() ? 3 : 1;
140 for (int xyz = 0; xyz < ndirs; xyz++) {
141 // c+1_i d+1_i
142 bra_ref->operator[](1).inc(xyz);
143 ket_ref->operator[](1).inc(xyz);
144 int next_child = nchildren_;
145 children_[next_child] =
146 ChildType::Instance(bra[0], ket[0], bra[1], ket[1], 0);
147 ++nchildren_;
148
149 if (is_simple()) {
150 std::shared_ptr<ExprType> expr0_ptr(new ExprType(
151 ExprType::OperatorTypes::Times, Scalar(1.0), rr_child(next_child)));
152 add_expr(expr0_ptr);
153 nflops_ += 1;
154 }
155 bra_ref->operator[](1).dec(xyz);
156 ket_ref->operator[](1).dec(xyz);
157 }
158}
159
160template <template <class> class I, class F>
161std::shared_ptr<typename CR_11_R2dotR2G12_11<I, F>::ChildType>
162CR_11_R2dotR2G12_11<I, F>::child(unsigned int i) const {
163 assert(i >= 0 && i < nchildren_);
164 unsigned int nc = 0;
165 for (int c = 0; c < max_nchildren_; c++) {
166 if (children_[c] != 0) {
167 if (nc == i) return children_[c];
168 nc++;
169 }
170 }
171};
172
176
177}; // namespace libint2
178
179#endif
AlgebraicOperator is an algebraic operator that acts on objects of type T.
Definition algebra.h:47
Set of basis functions.
Definition bfset.h:43
Compute relation for 2-e integrals of the r2.r2 x G12 operators.
Definition comp_11_r2dotr2g12_11.h:49
std::shared_ptr< ChildType > child(unsigned int i) const
child(i) returns pointer to the i-th child
Definition comp_11_r2dotr2g12_11.h:162
std::shared_ptr< DGVertex > rr_child(unsigned int i) const override
Implementation of RecurrenceRelation::rr_child()
Definition comp_11_r2dotr2g12_11.h:77
static std::shared_ptr< ThisType > Instance(const std::shared_ptr< TargetType > &)
Use Instance() to obtain an instance of RR.
Definition comp_11_r2dotr2g12_11.h:109
bool is_simple() const override
Implementation of RecurrenceRelation::is_simple()
Definition comp_11_r2dotr2g12_11.h:81
std::shared_ptr< DGVertex > rr_target() const override
Implementation of RecurrenceRelation::rr_target()
Definition comp_11_r2dotr2g12_11.h:73
unsigned int num_children() const override
Implementation of RecurrenceRelation::num_children()
Definition comp_11_r2dotr2g12_11.h:67
RecurrenceRelation::ExprType ExprType
The type of expressions in which RecurrenceRelations result.
Definition comp_11_r2dotr2g12_11.h:57
std::shared_ptr< TargetType > target() const
target() returns pointer to the i-th child
Definition comp_11_r2dotr2g12_11.h:69
Definition integral_decl.h:40
RecurrenceRelation describes all recurrence relations.
Definition rr.h:97
void add_expr(const std::shared_ptr< ExprType > &a, int minus=1)
Adds a (or -a, if minus = -1) to expr_.
Definition rr.cc:305
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24
CR_11_R2dotR2G12_11< R2dotR2G12_11_11, CGShell > CR_11_R2dotR2G12_11_sq
Useful typedefs.
Definition comp_11_r2dotr2g12_11.h:174
TrivialBFSet<T> defines static member result, which is true if T is a basis function set consisting o...
Definition bfset.h:906