Loading...
Searching...
No Matches
on_grid_function_mixin.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * On-grid function mixin.
5 *
6 * Mixin for functions whose values are stored at discrete grid points
7 * rather than evaluated analytically. The grid is a PointsGrid
8 * (or subclass like GVectorGrid).
9 *
10 * Templated on the grid type and value type to allow both
11 * real-space grids with Real values and reciprocal-space grids
12 * with Complex coefficients.
13 */
14
15#include <vector>
16
19
20namespace q3 {
21
22/// Mixin for functions defined on a discrete grid of points.
23template <typename GridType, typename ValueType> class OnGridFunctionMixin {
24 public:
25 /// Access the grid this function is defined on.
26 [[nodiscard]] const GridType& grid() const {
27 return grid_;
28 }
29
30 /// Access all values on the grid.
31 [[nodiscard]] const std::vector<ValueType>& values() const {
32 return values_;
33 }
34
35 /// Access a single value by grid point index.
36 [[nodiscard]] const ValueType& value_at_index(int index) const {
37 return values_[index];
38 }
39
40 ValueType& value_at_index(int index) {
41 return values_[index];
42 }
43
44 /// Number of grid points.
45 [[nodiscard]] int number_of_grid_points() const {
46 return static_cast<int>(values_.size());
47 }
48
49 protected:
50 GridType grid_;
51 std::vector<ValueType> values_;
52};
53
54} // namespace q3
Mixin for functions defined on a discrete grid of points.
const GridType & grid() const
Access the grid this function is defined on.
const ValueType & value_at_index(int index) const
Access a single value by grid point index.
int number_of_grid_points() const
Number of grid points.
std::vector< ValueType > values_
ValueType & value_at_index(int index)
const std::vector< ValueType > & values() const
Access all values on the grid.