GQCP
Loading...
Searching...
No Matches
OneElectronIntegralEngine.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
23
24
25namespace GQCP {
26
27
33template <typename _PrimitiveIntegralEngine>
35 public BaseOneElectronIntegralEngine<typename _PrimitiveIntegralEngine::Shell, _PrimitiveIntegralEngine::Components, typename _PrimitiveIntegralEngine::IntegralScalar> {
36public:
37 // The type of integral engine that is used for calculating integrals over primitives.
38 using PrimitiveIntegralEngine = _PrimitiveIntegralEngine;
39
40 // The type of shell that this engine can calculate integrals over.
41 using Shell = typename _PrimitiveIntegralEngine::Shell;
42
43 // The scalar representation of one of the integrals.
44 using IntegralScalar = typename _PrimitiveIntegralEngine::IntegralScalar;
45
46 // The number of components the operator has.
47 static constexpr auto N = _PrimitiveIntegralEngine::Components;
48
49
50private:
51 // The integral engine that is used for calculating integrals over primitives.
52 PrimitiveIntegralEngine primitive_engine;
53
54
55public:
56 /*
57 * MARK: Constructors
58 */
59
64 primitive_engine {primitive_engine} {}
65
66
67 /*
68 * MARK: Integral calculations.
69 */
70
81 std::shared_ptr<BaseOneElectronIntegralBuffer<IntegralScalar, N>> calculate(const Shell& shell1, const Shell& shell2) override {
82
83 // In this function, we loop over all basis functions that the shells contain.
84 const auto basis_functions1 = shell1.basisFunctions();
85 const auto basis_functions2 = shell2.basisFunctions();
86
87 std::array<std::vector<IntegralScalar>, N> integrals; // A "buffer" that stores the calculated integrals.
88
89 for (size_t i = 0; i < N; i++) { // Loop over all components of the operator.
90 this->primitive_engine.prepareStateForComponent(i);
91
92 for (const auto& bf1 : basis_functions1) {
93 const auto& coefficients1 = bf1.coefficients();
94 const auto& primitives1 = bf1.functions();
95
96 for (const auto& bf2 : basis_functions2) {
97 const auto& coefficients2 = bf2.coefficients();
98 const auto& primitives2 = bf2.functions();
99
100 IntegralScalar integral {};
101 for (size_t c1 = 0; c1 < bf1.length(); c1++) {
102 const auto& d1 = coefficients1[c1];
103 const auto& primitive1 = primitives1[c1];
104
105 for (size_t c2 = 0; c2 < bf2.length(); c2++) {
106 const auto& d2 = coefficients2[c2];
107 const auto& primitive2 = primitives2[c2];
108
109 const auto primitive_integral = this->primitive_engine.calculate(primitive1, primitive2);
110 integral += d1 * d2 * primitive_integral;
111 }
112 }
113 integrals[i].push_back(integral);
114 }
115 }
116 }
117
118 return std::make_shared<OneElectronIntegralBuffer<IntegralScalar, N>>(shell1.numberOfBasisFunctions(), shell2.numberOfBasisFunctions(), integrals);
119 }
120};
121
122
123} // namespace GQCP
Definition: BaseOneElectronIntegralEngine.hpp:37
Definition: OneElectronIntegralEngine.hpp:35
static constexpr auto N
Definition: OneElectronIntegralEngine.hpp:47
typename _PrimitiveIntegralEngine::IntegralScalar IntegralScalar
Definition: OneElectronIntegralEngine.hpp:44
std::shared_ptr< BaseOneElectronIntegralBuffer< IntegralScalar, N > > calculate(const Shell &shell1, const Shell &shell2) override
Definition: OneElectronIntegralEngine.hpp:81
_PrimitiveIntegralEngine PrimitiveIntegralEngine
Definition: OneElectronIntegralEngine.hpp:38
OneElectronIntegralEngine(const PrimitiveIntegralEngine &primitive_engine)
Definition: OneElectronIntegralEngine.hpp:63
typename _PrimitiveIntegralEngine::Shell Shell
Definition: OneElectronIntegralEngine.hpp:41
Definition: BaseOneElectronIntegralBuffer.hpp:25