GQCP
Loading...
Searching...
No Matches
CubicGrid.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
24#include "Molecule/Molecule.hpp"
25
26#include <array>
27#include <functional>
28#include <numeric>
29#include <type_traits>
30
31
32namespace GQCP {
33
34
38class CubicGrid {
39private:
40 Vector<double, 3> m_origin; // the origin of the grid
41 std::array<size_t, 3> numbers_of_steps; // the number of steps in the x, y, z-directions
42 std::array<double, 3> step_sizes; // the step sizes in the x, y, z-directions
43
44
45public:
46 // CONSTRUCTORS
47
53 CubicGrid(const Vector<double, 3>& origin, const std::array<size_t, 3>& numbers_of_steps, const std::array<double, 3>& step_sizes);
54
55
56 // NAMED CONSTRUCTORS
57
65 static CubicGrid Centered(const Vector<double, 3>& point, const size_t number_of_steps, const double step_size);
66
74 static CubicGrid ReadCubeFile(const std::string& filename);
75
88 static CubicGrid ReadRegularGridFile(const std::string& filename);
89
90
91 // PUBLIC METHODS
92
100 template <typename OutputType>
101 Field<OutputType> evaluate(const Function<OutputType, Vector<double, 3>>& function) const {
102
103 std::vector<OutputType> values;
104 values.reserve(this->numberOfPoints());
105
106 this->forEach([&values, &function](const Vector<double, 3>& r) {
107 values.push_back(function(r));
108 });
109
110 return Field<OutputType>(values);
111 }
112
113
121 template <typename T>
122 T integrate(const Field<T>& field) const {
123
124 // Using field.value(0) as the initial value makes sure that the initialization is already correct: e.g. when a Vector is initialized, it doesn't automatically have the required size due to the default constructor
125 auto result = std::accumulate(field.values().begin(), field.values().end(), field.value(0));
126 result -= field.value(0); // subtract the initial value of result
127
128 // For cubic grids, the weight of each point is the voxel volume, so we'll have to multiply the final result by this.
129 return result * this->voxelVolume();
130 }
131
132
138 void forEach(const std::function<void(const size_t, const size_t, const size_t)>& callback) const;
139
145 void forEach(const std::function<void(const Vector<double, 3>&)>& callback) const;
146
150 size_t numberOfPoints() const;
151
155 const Vector<double, 3>& origin() const { return this->m_origin; }
156
164 Vector<double, 3> position(const size_t i, const size_t j, const size_t k) const;
165
169 std::vector<Vector<double, 3>> points() const;
170
176 size_t numbersOfSteps(const size_t axis) const { return this->numbers_of_steps[axis]; }
177
181 const std::array<size_t, 3>& numbersOfSteps() const { return this->numbers_of_steps; }
182
188 double stepSize(const size_t axis) const { return this->step_sizes[axis]; }
189
193 const std::array<double, 3>& stepSizes() const { return this->step_sizes; }
194
198 double totalVolume() const { return this->voxelVolume() * this->numberOfPoints(); }
199
207 void writeToCubeFile(const Field<double>& scalar_field, const std::string& filename, const Molecule& molecule) const;
208
212 double voxelVolume() const;
213};
214
215
216} // namespace GQCP
Definition: CubicGrid.hpp:38
size_t numberOfPoints() const
Definition: CubicGrid.cpp:291
double totalVolume() const
Definition: CubicGrid.hpp:198
const std::array< double, 3 > & stepSizes() const
Definition: CubicGrid.hpp:193
const std::array< size_t, 3 > & numbersOfSteps() const
Definition: CubicGrid.hpp:181
static CubicGrid ReadRegularGridFile(const std::string &filename)
Definition: CubicGrid.cpp:144
Vector< double, 3 > position(const size_t i, const size_t j, const size_t k) const
Definition: CubicGrid.cpp:304
size_t numbersOfSteps(const size_t axis) const
Definition: CubicGrid.hpp:176
double stepSize(const size_t axis) const
Definition: CubicGrid.hpp:188
static CubicGrid ReadCubeFile(const std::string &filename)
Definition: CubicGrid.cpp:76
T integrate(const Field< T > &field) const
Definition: CubicGrid.hpp:122
static CubicGrid Centered(const Vector< double, 3 > &point, const size_t number_of_steps, const double step_size)
Definition: CubicGrid.cpp:54
Field< OutputType > evaluate(const Function< OutputType, Vector< double, 3 > > &function) const
Definition: CubicGrid.hpp:101
double voxelVolume() const
Definition: CubicGrid.cpp:391
void writeToCubeFile(const Field< double > &scalar_field, const std::string &filename, const Molecule &molecule) const
Definition: CubicGrid.cpp:338
std::vector< Vector< double, 3 > > points() const
Definition: CubicGrid.cpp:317
void forEach(const std::function< void(const size_t, const size_t, const size_t)> &callback) const
Definition: CubicGrid.cpp:261
const Vector< double, 3 > & origin() const
Definition: CubicGrid.hpp:155
Definition: Field.hpp:39
const T & value(const size_t index) const
Definition: Field.hpp:363
const std::vector< T > & values() const
Definition: Field.hpp:377
Definition: Function.hpp:153
Definition: Matrix.hpp:47
Definition: Molecule.hpp:34
Definition: BaseOneElectronIntegralBuffer.hpp:25