29#ifndef __FFT3D_GRID_HPP__
30#define __FFT3D_GRID_HPP__
37class Grid :
public std::array<int, 3>
48 for (
int k = 2; k <= 5; k++) {
64 for (
int i = 0; i < 3; i++) {
71 for (
int x = 0; x < (*this)[0]; x++) {
72 if (coord_by_freq<0>(freq_by_coord<0>(x)) != x) {
73 throw std::runtime_error(
"fft::Grid::find_grid_size(): wrong mapping of x-coordinates");
76 for (
int x = 0; x < (*this)[1]; x++) {
77 if (coord_by_freq<1>(freq_by_coord<1>(x)) != x) {
78 throw std::runtime_error(
"fft::Grid::find_grid_size(): wrong mapping of y-coordinates");
81 for (
int x = 0; x < (*this)[2]; x++) {
82 if (coord_by_freq<2>(freq_by_coord<2>(x)) != x) {
83 throw std::runtime_error(
"ffr::Grid::find_grid_size(): wrong mapping of z-coordinates");
96 Grid(std::array<int, 3> initial_dims__)
102 inline const std::pair<int, int>&
limits(
int idim__)
const
104 assert(idim__ >= 0 && idim__ < 3);
111 return (*
this)[0] * (*this)[1] * (*this)[2];
127 return {coord_by_freq<0>(i0__), coord_by_freq<1>(i1__), coord_by_freq<2>(i2__)};
143 return {freq_by_coord<0>(x__), freq_by_coord<1>(y__), freq_by_coord<2>(z__)};
149 return (x__ + (*
this)[0] * (y__ + z__ * (*
this)[1]));
Helper class to create FFT grids of given sizes and compute indices in space- and frequency domains.
std::array< int, 3 > freq_by_coord(int x__, int y__, int z__) const
Return 3d vector of frequencies corresponding to {x, y, z} position in the FFT buffer.
int coord_by_freq(int i__) const
Get coordinate in range [0, N_d) by the frequency index.
int index_by_coord(int x__, int y__, int z__) const
Linear index inside FFT buffer by grid coordinates.
std::array< int, 3 > coord_by_freq(int i0__, int i1__, int i2__) const
Return {x, y, z} coordinates by frequency indices.
void find_grid_size(std::array< int, 3 > initial_dims__)
Find grid sizes and limits for all three dimensions.
int num_points() const
Total size of the FFT grid.
const std::pair< int, int > & limits(int idim__) const
Limits of a given dimension.
std::array< std::pair< int, int >, 3 > grid_limits_
Reciprocal space range.
int freq_by_coord(int x__) const
Get frequency by coordinate.
int index_by_freq(int i0__, int i1__, int i2__) const
Return linear index of a plane-wave harmonic with fractional coordinates (i0, i1, i2) inside FFT buff...
Grid(std::array< int, 3 > initial_dims__)
Create FFT grid with initial dimensions.
Grid()
Default constructor.
int find_grid_size(int n)
Find smallest optimal grid size starting from n.
Simple implementation of 3d vector.
auto get_min_grid(double cutoff__, r3::matrix< double > M__)
Get the minimum grid that circumscribes the cutoff sphere.
auto find_translations(double radius__, matrix< double > const &lattice_vectors__)
Find supercell that circumscribes the sphere with a given radius.
Namespace of the SIRIUS library.
Simple classes and functions to work with vectors and matrices of the R^3 space.