MPQC  3.0.0-alpha
integrals.hpp
1 //
2 // integrals.hpp
3 //
4 // Copyright (C) 2013 Drew Lewis and Andrey Asadchev
5 //
6 // Authors: Drew Lewis
7 // Maintainer: Drew Lewis and Edward Valeev
8 //
9 // This file is part of the MPQC Toolkit.
10 //
11 // The MPQC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The MPQC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the MPQC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef MPQC_INTEGRALS_INTEGRALS_HPP
29 #define MPQC_INTEGRALS_INTEGRALS_HPP
30 
31 #include <vector>
32 
33 #include <mpqc/math/tensor.hpp>
34 #include <boost/foreach.hpp>
35 
36 #include <chemistry/molecule/molecule.h>
37 #include <chemistry/qc/basis/integral.h>
38 
39 #include "shell.hpp"
40 
41 namespace mpqc {
42 namespace lcao {
43 
46 
49  template<class RefEngine>
50  class Integrals {
51  public:
55 
60  explicit Integrals(RefEngine engineptr)
61  : engine_(engineptr) {}
62 
63  RefEngine& engine() {
64  return engine_;
65  }
66 
72  size_t dims[] = {size_t(p.size()), size_t(q.size()) };
73  engine_->compute_shell(p.index(), q.index());
74  return Tensor2(engine_->buffer(), dims);
75  }
76 
77  Tensor3 operator()(Shell p, Shell q, Shell r) {
78  size_t dims[] = {size_t( p.size()), size_t(q.size()),
79  size_t(r.size()) };
80  engine_->compute_shell(p.index(), q.index(), r.index());
81  return Tensor3(engine_->buffer(), dims);
82  }
83 
84  Tensor4 operator()(Shell p, Shell q, Shell r, Shell s) {
85  size_t dims[] = { size_t(p.size()), size_t(q.size()),
86  size_t(r.size()), size_t(s.size()) };
87  engine_->compute_shell(p.index(), q.index(),
88  r.index(), s.index());
89  return Tensor4(engine_->buffer(), dims);
90  }
91 
92  private:
93  RefEngine engine_;
94  };
95 
97 
98  namespace detail {
99 
102  inline std::vector<Shell> pack(sc::Ref<sc::GaussianBasisSet> basis,
103  const std::vector<int> &S) {
104  int f = 0;
105  std::vector<Shell> shells;
106  BOOST_FOREACH(int s, S){
107  int n = basis->shell(s).nfunction();
108  shells.push_back(Shell(s,range(f,f+n)));
109  f += n;
110  }
111  return shells;
112  }
113 
114 
115  //inline size_t extent(const std::vector<Shell> &S) {
116  // size_t extent = 0;
117  // BOOST_FOREACH(Shell s, S){
118  // extent = std::max(extent, *s.end());
119  // }
120  // return extent;
121  //}
122 
123 
124 
126  template<class Engine>
127  void evaluate(Integrals<Engine> integral,
128  const std::vector<int> &P,
129  const std::vector<int> &Q,
130  TensorRef<double,2, TensorRowMajor > &ints) {
131  std::vector<Shell> shells[] = {
132  pack(integral.engine()->basis1(), P),
133  pack(integral.engine()->basis2(), Q)
134  };
135 
136  BOOST_FOREACH(Shell p, shells[0]){
137  BOOST_FOREACH(Shell q, shells[1]){
138  ints(p,q) = integral(p,q);
139  }
140  }
141 
142  }
143 
144  template<class Engine>
145  void evaluate(Integrals<Engine> integral,
146  const std::vector<int> &P,
147  const std::vector<int> &Q,
148  const std::vector<int> &R,
149  TensorRef<double,3, TensorRowMajor > &ints) {
150  std::vector<Shell> shells[] = {
151  pack(integral.engine()->basis1(), P),
152  pack(integral.engine()->basis2(), Q),
153  pack(integral.engine()->basis3(), R)
154  };
155  BOOST_FOREACH(Shell p, shells[0]){
156  BOOST_FOREACH(Shell q, shells[1]){
157  BOOST_FOREACH(Shell r, shells[2]){
158  ints(p,q,r) = integral(p,q,r);
159  }
160  }
161  }
162  }
163 
164  template<class Engine>
165  void evaluate(Integrals<Engine> integral,
166  const std::vector<int> &P,
167  const std::vector<int> &Q,
168  const std::vector<int> &R,
169  const std::vector<int> &S,
170  TensorRef<double,4, TensorRowMajor > &ints) {
171  std::vector<Shell> shells[] = {
172  pack(integral.engine()->basis1(), P),
173  pack(integral.engine()->basis2(), Q),
174  pack(integral.engine()->basis3(), R),
175  pack(integral.engine()->basis4(), S),
176  };
177  BOOST_FOREACH(Shell p, shells[0]){
178  BOOST_FOREACH(Shell q, shells[1]){
179  BOOST_FOREACH(Shell r, shells[2]){
180  BOOST_FOREACH(Shell s, shells[3]){
181  ints(p,q,r,s) = integral(p,q,r,s);
182  }
183  }
184  }
185  }
186  }
187 
188 } // namespace detail
189 } // namespace integrals
190 } // namespace mpqc
191 
192 
193 namespace mpqc {
194 namespace lcao {
195 
198 
206  inline void evaluate(sc::Ref<sc::OneBodyInt> &engine,
207  const std::vector<int> &P,
208  const std::vector<int> &Q,
210  detail::evaluate(Integrals<sc::Ref<sc::OneBodyInt> >(engine), P, Q,
211  ints);
212  }
213 
214  inline void evaluate(sc::Ref<sc::TwoBodyTwoCenterInt> &engine,
215  const std::vector<int> &P,
216  const std::vector<int> &Q,
218  detail::evaluate(Integrals<sc::Ref<sc::TwoBodyTwoCenterInt> >(engine),
219  P, Q, ints);
220  }
221 
222  inline void evaluate(sc::Ref<sc::TwoBodyThreeCenterInt> &engine,
223  const std::vector<int> &P,
224  const std::vector<int> &Q,
225  const std::vector<int> &R,
226  TensorRef<double,3, TensorRowMajor > &ints) {
227  detail::evaluate(Integrals<sc::Ref<sc::TwoBodyThreeCenterInt> >(engine),
228  P, Q, R, ints);
229  }
230 
231  inline void evaluate(sc::Ref<sc::TwoBodyInt> engine,
232  const std::vector<int> &P,
233  const std::vector<int> &Q,
234  const std::vector<int> &R,
235  const std::vector<int> &S,
236  TensorRef<double,4, TensorRowMajor > &ints) {
237  detail::evaluate(Integrals<sc::Ref<sc::TwoBodyInt> >(engine),
238  P, Q, R, S, ints);
239  }
240 
241 
243 } // namespace integrals
244 } // namespace mpqc
245 
246 
247 #endif /* MPQC_INTEGRALS_INTEGRALS_HPP */
mpqc
Contains new MPQC code since version 3.
Definition: integralenginepool.hpp:37
sc::Ref< sc::GaussianBasisSet >
mpqc::lcao::Integrals::operator()
Tensor2 operator()(Shell p, Shell q)
Calls the MPQC integral object on shells p and q and returns a TensorRef holding the integral buffer.
Definition: integrals.hpp:71
mpqc::TensorRef
Tensor reference class.
Definition: ref.hpp:15
mpqc::lcao::Integrals
Wraps an MPQC integral engine (e.g.
Definition: integrals.hpp:50
sc::GaussianShell::nfunction
unsigned int nfunction() const
The number of basis functions.
Definition: gaussshell.h:191
mpqc::lcao::Shell
Definition: shell.hpp:38
mpqc::lcao::Integrals::Integrals
Integrals(RefEngine engineptr)
Constructor for Integrals.
Definition: integrals.hpp:60
sc::GaussianBasisSet::shell
const Shell & shell(int i) const
Return a reference to Shell number i.
Definition: gaussbas.h:558

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.