GQCP
Loading...
Searching...
No Matches
WeightedGrid.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
34private:
35 ArrayX<double> m_weights; // a 1-D array containing the weights for each of the grid points
36
37 std::vector<Vector<double, 3>> m_points; // the grid points
38
39
40public:
41 // CONSTRUCTORS
42
49 WeightedGrid(const std::vector<Vector<double, 3>>& points, const ArrayX<double>& weights);
50
51
52 // NAMED CONSTRUCTORS
53
59 static WeightedGrid FromCubicGrid(const CubicGrid& cubic_grid);
60
74 static WeightedGrid ReadIntegrationGridFile(const std::string& filename);
75
76
77 // PUBLIC METHODS
78
86 template <typename T>
87 T integrate(const Field<T>& field) const {
88
89 // A KISS-implementation of integration: multiplying every field value by the weight of the associated grid point.
90 auto result = field.value(0) * this->weight(0); // this makes sure that 'result' is already initialized to the correct type, e.g. when a Vector is initialized, it doesn't automatically have the required size
91 for (size_t i = 1; i < this->size(); i++) {
92 result += field.value(i) * this->weight(i);
93 }
94
95 return result;
96 }
97
98
102 size_t numberOfPoints() const { return this->m_points.size(); }
103
111 const Vector<double, 3>& point(const size_t index) const { return this->m_points[index]; }
112
116 const std::vector<Vector<double, 3>>& points() const { return this->m_points; }
117
121 size_t size() const { return this->numberOfPoints(); }
122
130 double weight(const size_t index) const { return this->m_weights(index); }
131
135 const ArrayX<double>& weights() const { return this->m_weights; };
136};
137
138
139} // namespace GQCP
Definition: Array.hpp:36
Definition: CubicGrid.hpp:38
Definition: Field.hpp:39
const T & value(const size_t index) const
Definition: Field.hpp:363
Definition: Matrix.hpp:47
Definition: WeightedGrid.hpp:33
T integrate(const Field< T > &field) const
Definition: WeightedGrid.hpp:87
const ArrayX< double > & weights() const
Definition: WeightedGrid.hpp:135
const std::vector< Vector< double, 3 > > & points() const
Definition: WeightedGrid.hpp:116
static WeightedGrid FromCubicGrid(const CubicGrid &cubic_grid)
Definition: WeightedGrid.cpp:57
const Vector< double, 3 > & point(const size_t index) const
Definition: WeightedGrid.hpp:111
double weight(const size_t index) const
Definition: WeightedGrid.hpp:130
static WeightedGrid ReadIntegrationGridFile(const std::string &filename)
Definition: WeightedGrid.cpp:80
size_t size() const
Definition: WeightedGrid.hpp:121
size_t numberOfPoints() const
Definition: WeightedGrid.hpp:102
Definition: BaseOneElectronIntegralBuffer.hpp:25