GQCP
Loading...
Searching...
No Matches
LibcintTwoElectronIntegralEngine.hpp
Go to the documentation of this file.
1// This file is part of GQCG-GQCP.
2//
3// Copyright (C) 2017-2020 the GQCG developers
4//
5// GQCG-GQCP is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// GQCG-GQCP is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with GQCG-GQCP. If not, see <http://www.gnu.org/licenses/>.
17
18#pragma once
19
20
25
26
27namespace GQCP {
28
29
41template <typename _Shell, size_t _N, typename _IntegralScalar>
42class LibcintTwoElectronIntegralEngine: public BaseTwoElectronIntegralEngine<_Shell, _N, _IntegralScalar> {
43public:
44 using Shell = _Shell; // the type of shell the integral engine is able to handle
45 using IntegralScalar = _IntegralScalar; // the scalar representation of an integral
46 static constexpr auto N = _N; // the number of components the operator has
47
48
49private:
50 Libcint2eFunction libcint_function; // the libcint two-electron integral function
51 Libcint2eOptimizerFunction libcint_optimizer_function; // the libcint two-electron optimizer integral function
52
53 // Data that has to be kept as a member (see the class note)
54 libcint::RawContainer libcint_raw_container; // the raw libcint data
55 ShellSet<Shell> shell_set; // the corresponding shell set
56
57
58public:
59 /*
60 * CONSTRUCTORS
61 */
62
68 libcint_function {LibcintInterfacer().twoElectronFunction(op)},
69 libcint_optimizer_function {LibcintInterfacer().twoElectronOptimizerFunction(op)},
70 libcint_raw_container {LibcintInterfacer().convert(shell_set)},
71 shell_set {shell_set} {}
72
73
74 /*
75 * PUBLIC OVERRIDDEN METHODS
76 */
77
86 std::shared_ptr<BaseTwoElectronIntegralBuffer<IntegralScalar, N>> calculate(const Shell& shell1, const Shell& shell2, const Shell& shell3, const Shell& shell4) override {
87
88 // Find to which indices in the RawContainer the given shells correspond
89 int shell_indices[4];
90 shell_indices[0] = static_cast<int>(findElementIndex(this->shell_set.asVector(), shell1));
91 shell_indices[1] = static_cast<int>(findElementIndex(this->shell_set.asVector(), shell2));
92 shell_indices[2] = static_cast<int>(findElementIndex(this->shell_set.asVector(), shell3));
93 shell_indices[3] = static_cast<int>(findElementIndex(this->shell_set.asVector(), shell4));
94
95
96 // Pre-allocate a raw buffer, because libcint functions expect a data pointer
97 const size_t nbf1 = shell1.numberOfBasisFunctions();
98 const size_t nbf2 = shell2.numberOfBasisFunctions();
99 const size_t nbf3 = shell3.numberOfBasisFunctions();
100 const size_t nbf4 = shell4.numberOfBasisFunctions();
101 double libcint_buffer[N * nbf1 * nbf2 * nbf3 * nbf4];
102
103
104 // Let libcint compute the integrals and return the corresponding buffer
105 const auto result = this->libcint_function(libcint_buffer, shell_indices, this->libcint_raw_container.atmData(), this->libcint_raw_container.numberOfAtoms(), this->libcint_raw_container.basData(), this->libcint_raw_container.numberOfBasisFunctions(), this->libcint_raw_container.envData(), nullptr); // no optimizer struct
106
107
108 std::vector<double> buffer_converted {libcint_buffer, libcint_buffer + N * nbf1 * nbf2 * nbf3 * nbf4}; // std::vector constructor from .begin() and .end()
109 return std::make_shared<LibcintTwoElectronIntegralBuffer<IntegralScalar, N>>(buffer_converted, nbf1, nbf2, nbf3, nbf4, result);
110 }
111};
112
113
114} // namespace GQCP
Definition: BaseTwoElectronIntegralEngine.hpp:37
Definition: CoulombRepulsionOperator.hpp:31
Definition: LibcintInterfacer.hpp:86
Definition: LibcintTwoElectronIntegralEngine.hpp:42
_Shell Shell
Definition: LibcintTwoElectronIntegralEngine.hpp:44
LibcintTwoElectronIntegralEngine(const CoulombRepulsionOperator &op, const ShellSet< Shell > &shell_set)
Definition: LibcintTwoElectronIntegralEngine.hpp:67
std::shared_ptr< BaseTwoElectronIntegralBuffer< IntegralScalar, N > > calculate(const Shell &shell1, const Shell &shell2, const Shell &shell3, const Shell &shell4) override
Definition: LibcintTwoElectronIntegralEngine.hpp:86
_IntegralScalar IntegralScalar
Definition: LibcintTwoElectronIntegralEngine.hpp:45
static constexpr auto N
Definition: LibcintTwoElectronIntegralEngine.hpp:46
Definition: ShellSet.hpp:41
const std::vector< Shell > & asVector() const
Definition: ShellSet.hpp:180
Definition: LibcintInterfacer.hpp:180
const int * atmData() const
Definition: LibcintInterfacer.hpp:233
Definition: BaseOneElectronIntegralBuffer.hpp:25
size_t findElementIndex(const std::vector< T > &vector, const T &value)
Definition: miscellaneous.hpp:44
std::function< int(double *, const int *, const int *, int, const int *, int, const double *, const CINTOpt *)> Libcint2eFunction
Definition: LibcintInterfacer.hpp:66
std::function< void(CINTOpt **, const int *, int, const int *, int, const double *)> Libcint2eOptimizerFunction
Definition: LibcintInterfacer.hpp:67