86 {
87#ifdef MEMORY_LOGGING
89#endif
90
91
92
93
94
95 const int Nmesh = 128;
98
99
100
101
102
103
104
109
110
111
112
115
116
117
118
119
122
123
124
125
126
127 std::array<FFTWGrid<Ndim>,
Ndim> Psi_1LPT_vector;
130
131 std::array<FFTWGrid<Ndim>,
Ndim> Psi_2LPT_vector;
134
135
136
137
138
142
143
144
145
146
147
148
149
150 std::array<std::vector<FML::GRID::FloatType>,
Ndim> displacements_1LPT;
154 displacements_1LPT,
156 for (
int idim = 0; idim <
Ndim; idim++) {
157 Psi_1LPT_vector[idim].free();
158 }
159
160
161
162
163 std::array<std::vector<FML::GRID::FloatType>,
Ndim> displacements_2LPT;
167 displacements_2LPT,
169 for (
int idim = 0; idim <
Ndim; idim++) {
170 Psi_2LPT_vector[idim].free();
171 }
172
173
174
175
176
177
178
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;
186
187
188
189
190
191
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;
196
198#ifdef USE_OMP
199#pragma omp parallel for reduction(max : max_disp_1LPT, max_disp_2LPT, max_vel_1LPT, max_vel_2LPT)
200#endif
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)
219 if (pos[idim] < 0.0)
221 }
222 }
223
224
225
226
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();
232 }
233
234
235
236
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";
249
250
251
252
253
255
256
257
258
259
260
261
262
263 const bool interlacing = true;
264 const std::string density_assignment_method = "PQS";
273 delta_from_part,
274 density_assignment_method,
275 interlacing);
280
281
282
283
284
285 pofk_part.scale(
box);
287 pofk_cross.scale(
box);
288
289
290
291
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] <<
" "
299 }
300 }
301
302
303
304
305
307
308#ifdef MEMORY_LOGGING
309
310 mem->print();
311#endif
312}
void generate_delta(FFTWGrid< Ndim > &delta)
const double buffer_factor
const std::string interpolation_method
Class for holding the results after binning up a power-spectrum.
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.
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.
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)