45const double box = 100.0;
64 return 1e-4 / std::pow(k,
Ndim);
73 std::function<double(
double)> Powspec;
79 const double volume = std::pow(
box,
Ndim);
80 Powspec = [&](
double kBox) ->
double {
return power_spectrum(kBox /
box) / volume; };
95 const int Nmesh = 128;
127 std::array<FFTWGrid<Ndim>,
Ndim> Psi_1LPT_vector;
131 std::array<FFTWGrid<Ndim>,
Ndim> Psi_2LPT_vector;
150 std::array<std::vector<FML::GRID::FloatType>,
Ndim> displacements_1LPT;
156 for (
int idim = 0; idim <
Ndim; idim++) {
157 Psi_1LPT_vector[idim].free();
163 std::array<std::vector<FML::GRID::FloatType>,
Ndim> displacements_2LPT;
169 for (
int idim = 0; idim <
Ndim; idim++) {
170 Psi_2LPT_vector[idim].free();
179 const double a_ini = 1.0 / (1.0 + 50.0);
180 const double OmegaM = 1.0;
182 const double growth_rate1 = 1.0;
183 const double growth_rate2 = 2.0;
184 const double vfac_1LPT = a_ini * a_ini *
HoverH0 * growth_rate1;
185 const double vfac_2LPT = a_ini * a_ini *
HoverH0 * growth_rate2;
192 double max_disp_1LPT = 0.0;
193 double max_disp_2LPT = 0.0;
194 double max_vel_1LPT = 0.0;
195 double max_vel_2LPT = 0.0;
199#pragma omp parallel for reduction(max : max_disp_1LPT, max_disp_2LPT, max_vel_1LPT, max_vel_2LPT)
201 for (
size_t ind = 0; ind < part.
get_npart(); ind++) {
202 auto * pos = part_ptr[ind].get_pos();
203 auto * vel = part_ptr[ind].get_vel();
204 for (
int idim =
Ndim - 1; idim >= 0; idim--) {
205 const double dpos_1LPT = displacements_1LPT[idim][ind];
206 const double dpos_2LPT = displacements_2LPT[idim][ind];
207 pos[idim] += dpos_1LPT + dpos_2LPT;
208 vel[idim] = vfac_1LPT * dpos_1LPT + vfac_2LPT * dpos_2LPT;
209 if (std::fabs(dpos_1LPT) > max_disp_1LPT)
210 max_disp_1LPT = std::fabs(dpos_1LPT);
211 if (std::fabs(dpos_2LPT) > max_disp_2LPT)
212 max_disp_2LPT = std::fabs(dpos_2LPT);
213 if (std::fabs(vfac_1LPT * dpos_1LPT) > max_vel_1LPT)
214 max_vel_1LPT = std::fabs(vfac_1LPT * dpos_1LPT);
215 if (std::fabs(vfac_2LPT * dpos_2LPT) > max_vel_2LPT)
216 max_vel_2LPT = std::fabs(vfac_2LPT * dpos_2LPT);
217 if (pos[idim] >= 1.0)
227 for (
int idim = 0; idim <
Ndim; idim++) {
228 displacements_1LPT[idim].clear();
229 displacements_1LPT[idim].shrink_to_fit();
230 displacements_2LPT[idim].clear();
231 displacements_2LPT[idim].shrink_to_fit();
242 std::cout <<
"Maximum displacements: " << max_disp_1LPT *
Nmesh <<
" grid cells\n";
244 std::cout <<
"Maximum displacements: " << max_disp_2LPT *
Nmesh <<
" grid cells\n";
246 std::cout <<
"Maximum velocity: " << max_vel_1LPT * 100.0 *
box / a_ini <<
" km/s peculiar\n";
248 std::cout <<
"Maximum velocity: " << max_vel_2LPT * 100.0 *
box / a_ini <<
" km/s peculiar\n";
263 const bool interlacing =
true;
264 const std::string density_assignment_method =
"PQS";
274 density_assignment_method,
293 std::cout <<
"\n# k (h/Mpc) CorrelationCoeff P_part / P P / P_analytic\n";
294 for (
int i = 0; i < pofk_ini.
n; i++) {
295 double k = pofk_ini.
kbin[i];
296 double cross_corr_coeff = pofk_cross.
pofk[i] / std::sqrt(pofk_part.
pofk[i] * pofk_ini.
pofk[i]);
297 std::cout << k <<
" " << cross_corr_coeff <<
" " << pofk_part.
pofk[i] / pofk_ini.
pofk[i] <<
" "
void generate_delta(FFTWGrid< Ndim > &delta)
double power_spectrum(double k)
const double buffer_factor
const std::string interpolation_method
Class for holding the results after binning up a power-spectrum.
std::vector< double > kbin
The mean k-value in the bin.
void scale(const double boxsize)
Scale to physical units: k *= 1/Box and pofk *= Box^N.
std::vector< double > pofk
The power-spectrum in the bin.
Class for holding grids and performing real-to-complex and complex-to-real FFTs using FFTW with MPI.
void free()
The fftw_complex cast of get_fourier_gride.
static MemoryLog * get()
The (only) instance.
A container class for holding particles that are distributed across many CPUs and to easily deal with...
void create_particle_grid(int Npart_1D, double buffer_factor, double xmin_local, double xmax_local)
Create particles in a rectangular grid spread across all tasks buffer_factor is how much extra to al...
size_t get_npart_total() const
Total number of active particles across all tasks.
T * get_particles_ptr()
Get a pointer to the first particle.
void info()
Show some info about the class.
void communicate_particles(size_t max_message_bytes=std::numeric_limits< int >::max(), bool force_general=false)
Communicate particles across CPU boundaries.
size_t get_npart() const
Number of active particles on the local task.
void free()
Free all memory of the stored particles.
This is a class for having a unified interface for random numbers in the library.
void bin_up_power_spectrum(const FFTWGrid< N > &fourier_grid, PowerSpectrumBinning< N > &pofk)
Compute the power-spectrum of a fourier grid.
void bin_up_cross_power_spectrum(const FFTWGrid< N > &fourier_grid_1, const FFTWGrid< N > &fourier_grid_2, PowerSpectrumBinning< N > &pofk)
Compute the cross power-spectrum of two fourier grids.
void compute_1LPT_potential_fourier(const FFTWGrid< N > &delta_fourier, FFTWGrid< N > &phi_1LPT_fourier)
Generate the 1LPT potential defined as and .
void compute_2LPT_potential_fourier(const FFTWGrid< N > &delta_fourier, FFTWGrid< N > &phi_2LPT_fourier, Dealiasing dealiasing=Dealiasing::None)
Optional Padding uses a >=3N/2 work mesh for the quadratic source.
void from_LPT_potential_to_displacement_vector(const FFTWGrid< N > &phi_fourier, std::array< FFTWGrid< N >, N > &psi_real, double DoverDini=1.0)
Generate the displaceement field from the LPT potential .
void particles_to_fourier_grid(const 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.
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.
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 assignment / interpolation ...
void deconvolve_window_function_fourier(FFTWGrid< N > &fourier_grid, std::string density_assignment_method)
Deconvolves the density assignment kernel in Fourier space.
void generate_gaussian_random_field_fourier(FFTWGrid< N > &grid, RandomGenerator *rng, std::function< double(double)> Pofk_of_kBox_over_volume, bool fix_amplitude)
double xmax_domain
The local extent of the domain (global domain goes from 0 to 1)
void MaxOverTasks(T *value)
Inplace max over tasks of a single value.
int ThisTask
The MPI task number.
double xmin_domain
The local extent of the domain (global domain goes from 0 to 1)
Example of a simple particle with all the methods needed to be used with MPIParticles Some algorithms...
std::mt19937_64 rng(1234)