FML
|
This namespace deals with interpolation and density assignment. More...
Namespaces | |
namespace | SPLINE |
This namespace deals with creating and using splines. | |
Typedefs | |
using | FloatType = FML::GRID::FloatType |
template<int N> | |
using | FFTWGrid = FML::GRID::FFTWGrid< N > |
Functions | |
template<int N, int ORDER, class T > | |
void | interpolate_grid_to_particle_positions (const FFTWGrid< N > &grid, const T *part, size_t NumPart, std::vector< FloatType > &interpolated_values) |
Interpolate a grid to a set of positions given by the positions of particles. More... | |
template<int N, int ORDER, class T > | |
void | interpolate_grid_vector_to_particle_positions (const std::array< FFTWGrid< N >, N > &grid_vec, const T *part, size_t NumPart, std::array< std::vector< FloatType >, N > &interpolated_values_vec) |
Interpolate a vector of grids (e.g. More... | |
template<int N, class T > | |
void | interpolate_grid_to_particle_positions (const FFTWGrid< N > &grid, const T *part, size_t NumPart, std::vector< FloatType > &interpolated_values, std::string interpolation_method) |
Interpolate a grid to a set of positions given by the positions of particles. More... | |
template<int N, class T > | |
void | interpolate_grid_vector_to_particle_positions (const std::array< FFTWGrid< N >, N > &grid_vec, const T *part, size_t NumPart, std::array< std::vector< FloatType >, N > &interpolated_values_vec, std::string interpolation_method) |
Interpolate a vector of grids to a set of positions given by the positions of particles. More... | |
template<int N, class T > | |
void | particles_to_grid (const T *part, size_t NumPart, size_t NumPartTot, FFTWGrid< N > &density, std::string density_assignment_method) |
Assign particles to a grid to compute the over density field delta. More... | |
template<int N, int ORDER, class T > | |
void | particles_to_grid (const T *part, size_t NumPart, size_t NumPartTot, FFTWGrid< N > &density) |
Assign particles to a grid to compute the over density field delta. More... | |
template<int N, class T > | |
void | particles_to_fourier_grid_interlacing (T *part, size_t NumPart, size_t NumPartTot, FFTWGrid< N > &density_grid_fourier, std::string density_assignment_method) |
Internal method. More... | |
template<int N, class T > | |
void | particles_to_fourier_grid (T *part, size_t NumPart, size_t NumPartTot, FFTWGrid< N > &density_grid_fourier, std::string density_assignment_method, bool interlacing) |
Assign particles to grid to compute the over density. More... | |
template<int N, int ORDER> | |
void | convolve_grid_with_kernel (const FFTWGrid< N > &grid_in, FFTWGrid< N > &grid_out, std::function< FloatType(std::array< double, N > &)> &convolution_kernel) |
Convolve a grid with a kernel. More... | |
int | interpolation_order_from_name (std::string density_assignment_method) |
Get the interpolation order from a string holding the density_assignment_method (NGP, CIC, ...). More... | |
std::pair< int, int > | get_extra_slices_needed_for_density_assignment (std::string density_assignment_method) |
Compute how many extra slices we need in the FFTWGrid for a given density assignement / interpolation method. More... | |
template<int ORDER> | |
std::pair< int, int > | get_extra_slices_needed_by_order () |
Compute how many extra slices we need in the FFTWGrid for a given density assignment order. More... | |
template<int ORDER> | |
double | kernel (double x) |
Internal method. More... | |
template<> | |
double | kernel< 1 > (double x) |
The NGP kernel. More... | |
template<> | |
double | kernel< 2 > (double x) |
The CIC kernel. More... | |
template<> | |
double | kernel< 3 > (double x) |
The TSC kernel. More... | |
template<> | |
double | kernel< 4 > (double x) |
The PCS kernel. More... | |
template<> | |
double | kernel< 5 > (double x) |
The PQS kernel. More... | |
template<int N> | |
void | add_contribution_from_extra_slices (FFTWGrid< N > &density) |
Internal method. For communication between tasks needed when adding particles to grid. More... | |
template<int N> | |
std::function< double(std::array< double, N > &)> | get_window_function (std::string density_assignment_method, int Ngrid) |
This returns the a function giving the window function for a given density assignement method as function of the wave-vector in dimensionless units. More... | |
template<int N> | |
void | deconvolve_window_function_fourier (FFTWGrid< N > &fourier_grid, std::string density_assignment_method) |
Deconvolves the density assignement kernel in Fourier space. More... | |
This namespace deals with interpolation and density assignment.
We give methods to assign particles to a grid to compute the density contrast and to interpolate a grid to any given position using the same B spline kernels (this is basically a convolution of the kernels with the grid). This kind of interpolation is useful for computing forces from a density field of particles. Using the interpolation method corresponding to the density assignment help prevent unphysical self-forces.
If the particle class has a get_mass method then we will use this mass (divided by the mean mass of all particles so the absolute size of the masses does not matter) when assigning the particles to the grid. Otherwise we will assume all particles have the same mass. The resulting density-field delta will always have mean 0.
The assignment function is a B spline kernel of any order, i.e. H*H*...*H with H being a tophat and * convolution. The fourier space window functions of these are just sinc(pi/2 * k / kny)^ORDER Order 1=NGP, 2=CIC, 3=TSC, 4=PCS, 5=PQS and higher orders are easily added if you for some strange reason needs this (just add the kernel function).
Also contains a method for doing a convolution of a grid with a general kernel.
Compile time defines:
DEBUG_INTERPOL : Check that the interpolation weights sum to unity for density assignment
CELLCENTERSHIFTED : Shift the position of the cell (located at center of cell vs at the corners). Use with care. Not using this option saves a slice for even order interpoation and using it saves a slice for odd ordered interpolation (TSC+). Only relevant if memory is really tight and you need to use TSC or PQS
using FML::INTERPOLATION::FFTWGrid = typedef FML::GRID::FFTWGrid<N> |
Definition at line 58 of file ParticleGridInterpolation.h.
using FML::INTERPOLATION::FloatType = typedef FML::GRID::FloatType |
Definition at line 55 of file ParticleGridInterpolation.h.
void FML::INTERPOLATION::add_contribution_from_extra_slices | ( | FFTWGrid< N > & | density | ) |
Internal method. For communication between tasks needed when adding particles to grid.
Definition at line 911 of file ParticleGridInterpolation.h.
void FML::INTERPOLATION::convolve_grid_with_kernel | ( | const FFTWGrid< N > & | grid_in, |
FFTWGrid< N > & | grid_out, | ||
std::function< FloatType(std::array< double, N > &)> & | convolution_kernel | ||
) |
Convolve a grid with a kernel.
N | The dimension of the grid |
ORDER | The width of the kernel in units of the cell-size. We consider the \( {\rm ORDER}^{\rm N} \) closest grid-cells, so ORDER/2 cells to the left and right in each dimension. |
[in] | grid_in | The grid we want to convolve. |
[out] | grid_out | The in grid convolved with the kernel. |
[in] | convolution_kernel | A function taking in the distance to a given cell (in units of the cell size) and returns the kernel. For example the NGP kernel would be the function Prod_i ( |dx[i]| < 0.5 ), i.e. 1 if all positions are within half a grid cell of the cell center. |
Definition at line 1005 of file ParticleGridInterpolation.h.
void FML::INTERPOLATION::deconvolve_window_function_fourier | ( | FFTWGrid< N > & | fourier_grid, |
std::string | density_assignment_method | ||
) |
Deconvolves the density assignement kernel in Fourier space.
We divide the fourier grid by the FFT of the density assignment kernels \( FFT[ H*H*H*...*H ] = FT[H]^p\).
N | The dimension of the grid |
[out] | fourier_grid | The Fourier grid of the density contrast that we will deconvolve. |
[in] | density_assignment_method | The density assignment method (NGP, CIC, ...) we used when making the density contrast. |
Definition at line 425 of file ParticleGridInterpolation.h.
|
inline |
Compute how many extra slices we need in the FFTWGrid for a given density assignment order.
ORDER | The order of the B-spline assignment kernel (NGP=1, CIC=2, TSC=3, PCS=4, PQS=5, ...) |
Definition at line 322 of file ParticleGridInterpolation.h.
|
inline |
Compute how many extra slices we need in the FFTWGrid for a given density assignement / interpolation method.
[in] | density_assignment_method | The density assignement method (NGP, CIC, TSC, PCS or PQS). |
Example usage:
auto nleftright = get_extra_slices_needed_for_density_assignment("CIC");
FFTWGrid<N> grid (Nmesh, nleftright.first, nleftright.second);
Definition at line 288 of file ParticleGridInterpolation.h.
std::function< double(std::array< double, N > &)> FML::INTERPOLATION::get_window_function | ( | std::string | density_assignment_method, |
int | Ngrid | ||
) |
This returns the a function giving the window function for a given density assignement method as function of the wave-vector in dimensionless units.
N | The dimension of the grid |
[in] | density_assignment_method | The density assignment method (NGP, CIC, ...) we used when making the density contrast. |
[in] | Ngrid | The grid size (used to set the nyquist frequency) |
Definition at line 391 of file ParticleGridInterpolation.h.
void FML::INTERPOLATION::interpolate_grid_to_particle_positions | ( | const FFTWGrid< N > & | grid, |
const T * | part, | ||
size_t | NumPart, | ||
std::vector< FloatType > & | interpolated_values | ||
) |
Interpolate a grid to a set of positions given by the positions of particles.
N | The dimension of the grid |
T | The particle class. Must have a get_pos() method. |
ORDER | The order of the B-spline interpolation (1=NGP, 2=CIC, 3=TSC, 4=PCS, 5=PQS, ...) |
[in] | grid | A grid. |
[in] | part | A pointer the first particle. |
[in] | NumPart | How many particles/positions we have that we want to interpolate the grid to. |
[out] | interpolated_values | A vector with the interpolated values, one per particle. Allocated in the method. |
Definition at line 777 of file ParticleGridInterpolation.h.
void FML::INTERPOLATION::interpolate_grid_to_particle_positions | ( | const FFTWGrid< N > & | grid, |
const T * | part, | ||
size_t | NumPart, | ||
std::vector< FloatType > & | interpolated_values, | ||
std::string | interpolation_method | ||
) |
Interpolate a grid to a set of positions given by the positions of particles.
N | The dimension of the grid |
T | The particle class. Must have a get_pos() method. |
[in] | grid | A grid. |
[in] | part | A pointer the first particle. |
[in] | NumPart | How many particles/positions we have that we want to interpolate the grid to. |
[out] | interpolated_values | A vector with the interpolated values, one per particle. Allocated in the method. |
[in] | interpolation_method | The interpolation method: NGP, CIC, TSC, PCS or PQS. |
Definition at line 242 of file ParticleGridInterpolation.h.
void FML::INTERPOLATION::interpolate_grid_vector_to_particle_positions | ( | const std::array< FFTWGrid< N >, N > & | grid_vec, |
const T * | part, | ||
size_t | NumPart, | ||
std::array< std::vector< FloatType >, N > & | interpolated_values_vec | ||
) |
Interpolate a vector of grids (e.g.
force vector) to a set of positions given by the positions of particles.
N | The dimension of the grid |
T | The particle class. Must have a get_pos() method. |
ORDER | The order of the B-spline interpolation (1=NGP, 2=CIC, 3=TSC, 4=PCS, 5=PQS, ...) |
[in] | grid_vec | A N-dimensional array of grids |
[in] | part | A pointer the first particle. |
[in] | NumPart | How many particles/positions we have that we want to interpolate the grid to. |
[out] | interpolated_values_vec | The interpolated values, one per grid per particle. Allocated in the method. |
Definition at line 620 of file ParticleGridInterpolation.h.
void FML::INTERPOLATION::interpolate_grid_vector_to_particle_positions | ( | const std::array< FFTWGrid< N >, N > & | grid_vec, |
const T * | part, | ||
size_t | NumPart, | ||
std::array< std::vector< FloatType >, N > & | interpolated_values_vec, | ||
std::string | interpolation_method | ||
) |
Interpolate a vector of grids to a set of positions given by the positions of particles.
N | The dimension of the grid |
T | The particle class. Must have a get_pos() method. |
[in] | grid_vec | A vector of grids |
[in] | part | A pointer the first particle. |
[in] | NumPart | How many particles/positions we have that we want to interpolate the grid to. |
[out] | interpolated_values_vec | The interpolated values, one per grid per particle. Allocated in the method. |
[in] | interpolation_method | The interpolation method: NGP, CIC, TSC, PCS or PQS. |
Definition at line 759 of file ParticleGridInterpolation.h.
|
inline |
Get the interpolation order from a string holding the density_assignment_method (NGP, CIC, ...).
Needed for the Fourier-space window function
Definition at line 261 of file ParticleGridInterpolation.h.
|
inline |
Internal method.
The B-spline interpolation kernels for a given order \( H^{(p)} = H * H * \ldots * H \) where H is the tophat \( H = [ |dx| < 0.5 ? 1 : 0 ] \) and * is a convolution (easily computed with Mathematica)
Definition at line 344 of file ParticleGridInterpolation.h.
|
inline |
The NGP kernel.
Definition at line 350 of file ParticleGridInterpolation.h.
|
inline |
The CIC kernel.
Definition at line 355 of file ParticleGridInterpolation.h.
|
inline |
|
inline |
|
inline |
The PQS kernel.
Definition at line 371 of file ParticleGridInterpolation.h.
void FML::INTERPOLATION::particles_to_fourier_grid | ( | T * | part, |
size_t | NumPart, | ||
size_t | NumPartTot, | ||
FFTWGrid< N > & | density_grid_fourier, | ||
std::string | density_assignment_method, | ||
bool | interlacing | ||
) |
Assign particles to grid to compute the over density.
Do this for a normal grid and an interlaced grid and return the alias-corrected fourier transform of the density field in fourier space. This method does not deconvolve the window function
T | The particle class. Must have a get_pos() method. If the particle has a get_mass method then this is used to weight the particle (we assign the particle with weight mass / mean_mass). |
[in] | part | A pointer the first particle. |
[in] | NumPart | How many particles/positions we have that we want to interpolate the grid to. |
[in] | NumPartTot | How many particles/positions we have in total over all tasks. |
[out] | density_grid_fourier | The output density grid in fourier space (must be initialized) |
[in] | density_assignment_method | The density assignement method (NGP, CIC, TSC, PCS or PQS). |
[in] | interlacing | If true use interlacing to reduce aliasing |
Definition at line 1174 of file ParticleGridInterpolation.h.
void FML::INTERPOLATION::particles_to_fourier_grid_interlacing | ( | T * | part, |
size_t | NumPart, | ||
size_t | NumPartTot, | ||
FFTWGrid< N > & | density_grid_fourier, | ||
std::string | density_assignment_method | ||
) |
Internal method.
Definition at line 1088 of file ParticleGridInterpolation.h.
void FML::INTERPOLATION::particles_to_grid | ( | const T * | part, |
size_t | NumPart, | ||
size_t | NumPartTot, | ||
FFTWGrid< N > & | density | ||
) |
Assign particles to a grid to compute the over density field delta.
N | The dimension of the grid |
T | The particle class. Must have a get_pos() method. If the particle has a get_mass method then this is used to weight the particle (we assign the particle with weight mass / mean_mass). |
ORDER | The order of the B-spline interpolation (1=NGP, 2=CIC, 3=TSC, 4=PCS, 5=PQS, ...). If larger than 5 then you must implement kernel<ORDER> yourself (a simple Mathematica calculation), see the source. |
[in] | part | A pointer the first particle. |
[in] | NumPart | How many particles/positions we have that we want to interpolate the grid to. |
[in] | NumPartTot | How many particles/positions we have in total over all tasks. |
[out] | density | The overdensity field. |
Definition at line 477 of file ParticleGridInterpolation.h.
void FML::INTERPOLATION::particles_to_grid | ( | const T * | part, |
size_t | NumPart, | ||
size_t | NumPartTot, | ||
FFTWGrid< N > & | density, | ||
std::string | density_assignment_method | ||
) |
Assign particles to a grid to compute the over density field delta.
N | The dimension of the grid |
T | The particle class. Must have a get_pos() method. If the particle has a get_mass method then this is used to weight the particle (we assign the particle with weight mass / mean_mass). |
[in] | part | A pointer the first particle. |
[in] | NumPart | How many particles/positions we have that we want to interpolate the grid to. |
[in] | NumPartTot | How many particles/positions we have in total over all tasks. |
[out] | density | The overdensity field. |
[in] | density_assignment_method | The assignment method: NGP, CIC, TSC, PCS or PQS. |
Definition at line 224 of file ParticleGridInterpolation.h.