-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathic_curvature.hpp
More file actions
619 lines (473 loc) · 21.6 KB
/
ic_curvature.hpp
File metadata and controls
619 lines (473 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
//////////////////////////
// ic_curvature.hpp
//////////////////////////
//
// initial condition generator for gevolution for LTB models
//
// Author: Julian Adamek (Université de Genève & Observatoire de Paris & Queen Mary University of London & Universität Zürich)
//
// Last modified: March 2025
//
//////////////////////////
#ifndef IC_CURVATURE_HEADER
#define IC_CURVATURE_HEADER
using namespace LATfield2;
void generateIC_curvature(metadata & sim, icsettings & ic, cosmology & cosmo, const double fourpiG, Particles<part_simple,part_simple_info,part_simple_dataType> * pcls_cdm, Particles<part_simple,part_simple_info,part_simple_dataType> * pcls_b, Particles<part_simple,part_simple_info,part_simple_dataType> * pcls_ncdm, double * maxvel, Field<Real> * phi, Field<Real> * chi, Field<Real> * Bi, Field<Real> * source, Field<Real> * Sij, Field<Cplx> * zetaFT, Field<Cplx> * scalarFT, Field<Cplx> * BiFT, Field<Cplx> * SijFT, PlanFFT<Cplx> * plan_phi, PlanFFT<Cplx> * plan_chi, PlanFFT<Cplx> * plan_Bi, PlanFFT<Cplx> * plan_source, PlanFFT<Cplx> * plan_Sij, parameter * params, int & numparam)
{
double a = 1. / (1. + sim.z_in);
float * pcldata = NULL;
double * sinc = NULL;
Site x(phi->lattice());
rKSite kFT(scalarFT->lattice());
double max_displacement;
double r2, d1, i2, inner_radius, H2, dlnm;
part_simple_info pcls_cdm_info;
part_simple_dataType pcls_cdm_dataType;
part_simple_info pcls_b_info;
part_simple_dataType pcls_b_dataType;
Real boxSize[3] = {1.,1.,1.};
Real vertex[3];
Real origin[3] = {Real(0.5 * sim.numpts), Real(0.5 * sim.numpts), Real(0.5 * sim.numpts)};
Field<Real> * ic_fields[2];
char filename[2*PARAM_MAX_LENGTH+64];
int reduce = MAX;
ic_fields[0] = chi;
ic_fields[1] = chi;
H2 = Hconf(a, fourpiG, cosmo) * Hconf(a, fourpiG, cosmo);
d1 = -0.6 * ic.LTB_Omega_k * (1. + 11. * ic.LTB_Omega_k / 35.);
inner_radius = sim.LTB_radius / pow(1. + d1, 1./3.);
i2 = inner_radius * inner_radius;
dlnm = 0.5 * d1 * H2 * sim.LTB_radius * sim.LTB_radius;
COUT << " mass correction: dm/m = " << dlnm << " (first order), dm/m = ";
// second-order correction
dlnm += dlnm * ((113 * dlnm - 73 * d1) / 70.) - d1 * d1 / 1.5;
COUT << dlnm << " (second order)" << endl;
if (parallel.isRoot())
{
FILE * outfile = nullptr;
sprintf(filename, "%s%s_flat_cosmology.ini", sim.output_path, sim.basename_generic);
outfile = fopen(filename, "w");
if (outfile != nullptr)
{
fprintf(outfile, "# Flat cosmology parameters\n");
fprintf(outfile, "Omega_Lambda = %.12g\n", cosmo.Omega_Lambda);
fprintf(outfile, "Omega_b = %.12g\n", cosmo.Omega_b);
fprintf(outfile, "Omega_cdm = %.12g\n", cosmo.Omega_cdm);
fprintf(outfile, "Omega_g = %.12g\n", cosmo.Omega_g);
fprintf(outfile, "Omega_ur = %.12g\n", cosmo.Omega_ur);
fprintf(outfile, "h = %.12g\n", cosmo.h);
fprintf(outfile, "z_in = %.12g\n", sim.z_in);
fclose(outfile);
}
else
{
COUT << COLORTEXT_YELLOW << " /!\\ warning" << COLORTEXT_RESET << ": could not write flat cosmology parameters to file " << filename << endl;
}
}
COUT << " computed gravitational potential at the center of the LTB model: phi(r=0) = " << -0.25 * d1 * H2 * (sim.LTB_radius * sim.LTB_radius * (1.0 - d1 / 3.)) << endl; //<< -0.5 * dlnm << endl;
dlnm *= 4. * M_PI * sim.LTB_radius * sim.LTB_radius * sim.LTB_radius / 3.;
// generate the kernel for the 1st order displacement field
loadHomogeneousTemplate(ic.pclfile[0], sim.numpcl[0], pcldata);
if (pcldata == NULL)
{
COUT << " error: particle data was empty!" << endl;
parallel.abortForce();
}
if (ic.flags & ICFLAG_CORRECT_DISPLACEMENT)
generateCICKernel(*source, sim.numpcl[0], pcldata, ic.numtile[0]);
else
generateCICKernel(*source);
plan_source->execute(FFT_FORWARD);
// use BiFT as temporary storage for the kernel
for (kFT.first(); kFT.test(); kFT.next())
(*BiFT)(kFT, 0) = (*scalarFT)(kFT);
// precompute sinc function
sinc = (double *) malloc(sim.numpts * sizeof(double));
sinc[0] = 1.;
for (int i = 1; i <= sim.numpts/2; i++)
sinc[i] = sin(M_PI * i / sim.numpts) / (M_PI * i / sim.numpts);
for (int i = 1; i < sim.numpts/2; i++)
sinc[sim.numpts-i] = sinc[i];
for (x.first(); x.test(); x.next())
{
r2 = 0.;
for (int i = 0; i < 3; i++)
{
r2 += (x.coord(i) - sim.numpts / 2) * (x.coord(i) - sim.numpts / 2);
vertex[i] = (Real) x.coord(i);
}
r2 /= sim.numpts * sim.numpts;
Real w1 = Real(1) - computeTruncatedCellVolume(vertex, origin, inner_radius * sim.numpts);
Real w2 = Real(1) - computeTruncatedCellVolume(vertex, origin, sim.LTB_radius * sim.numpts);
/*if (w1 > 1 || w1 < -1.0e-5)
cout << "error in position [" << x.coord(0) << "," << x.coord(1) << "," << x.coord(2) << "]: w1 = " << w1 << endl;
if (w2 > 1 || w2 < -1.0e-5)
cout << "error in position [" << x.coord(0) << "," << x.coord(1) << "," << x.coord(2) << "]: w2 = " << w2 << endl;*/
w2 -= w1;
(*source)(x) = w1 * d1 * (1. + 0.5 * sim.gr_flag * H2 * (sim.LTB_radius * sim.LTB_radius * (1. + 10. * d1 / 21.) - r2 * (1. + 16. * d1 / 63.) + d1 * H2 * (17. * r2 * r2 + sim.LTB_radius * sim.LTB_radius * (27. * sim.LTB_radius * sim.LTB_radius - 44. * r2)) / 24.)) - w2;
if (r2 < i2)
{
(*phi)(x) = -0.25 * d1 * H2 * (sim.LTB_radius * sim.LTB_radius * (1.0 - d1 / 3.) - r2 - 5. * d1 * H2 * r2 * (2. * r2 + sim.LTB_radius * sim.LTB_radius - 3. * sim.LTB_radius * sqrt(r2)) / 6.);
}
else if (r2 < sim.LTB_radius * sim.LTB_radius)
{
r2 = sqrt(r2);
(*phi)(x) = -0.25 * H2 * (1. + 2. * sim.LTB_radius / r2) * (sim.LTB_radius - r2) * (sim.LTB_radius - r2);
}
else
{
(*phi)(x) = Real(0);
}
}
plan_phi->execute(FFT_FORWARD);
for (kFT.first(); kFT.test(); kFT.next())
{
double W = sinc[kFT.coord(0)] * sinc[kFT.coord(1)] * sinc[kFT.coord(2)];
(*scalarFT)(kFT) *= W*W/sim.numpts/sim.numpts/sim.numpts;
}
plan_phi->execute(FFT_BACKWARD);
phi->updateHalo();
sprintf(filename, "%s%s_IC_phi.h5", sim.output_path, sim.basename_generic);
phi->saveHDF5(string(filename));
source->updateHalo();
sprintf(filename, "%s%s_IC_delta.h5", sim.output_path, sim.basename_generic);
source->saveHDF5(string(filename));
COUT << " computing 1st order displacement..." << endl;
if (sim.gr_flag == 1)
{
for (x.first(); x.test(); x.next())
(*chi)(x) = (*source)(x) - 3. * (*phi)(x);
}
else
{
for (x.first(); x.test(); x.next())
(*chi)(x) = (*source)(x);
}
plan_chi->execute(FFT_FORWARD);
for (kFT.first(); kFT.test(); kFT.next())
{
if ((*BiFT)(kFT, 0).norm() > 1.0e-16)
(*scalarFT)(kFT) = (*scalarFT)(kFT) / (*BiFT)(kFT, 0);
}
plan_chi->execute(FFT_BACKWARD);
chi->updateHalo();
//filename.assign("1st_order_displacement.h5");
sprintf(filename, "%s%s_IC_1st_order_displacement.h5", sim.output_path, sim.basename_generic);
chi->saveHDF5(string(filename));
strcpy(pcls_cdm_info.type_name, "part_simple");
if (sim.baryon_flag == 1)
pcls_cdm_info.mass = (1. + dlnm) * cosmo.Omega_cdm / (Real) (sim.numpcl[0]*(long)ic.numtile[0]*(long)ic.numtile[0]*(long)ic.numtile[0]);
else
pcls_cdm_info.mass = (1. + dlnm) * (cosmo.Omega_cdm + cosmo.Omega_b) / (Real) (sim.numpcl[0]*(long)ic.numtile[0]*(long)ic.numtile[0]*(long)ic.numtile[0]);
pcls_cdm_info.relativistic = false;
pcls_cdm->initialize(pcls_cdm_info, pcls_cdm_dataType, &(phi->lattice()), boxSize);
initializeParticlePositions(sim.numpcl[0], pcldata, ic.numtile[0], *pcls_cdm);
free(pcldata);
if (sim.baryon_flag == 3) // baryon treatment = hybrid; displace particles using both displacement fields
pcls_cdm->moveParticles(displace_pcls_ic_basic, 1./sim.numpts/sim.numpts/sim.numpts, ic_fields, 2, NULL, &max_displacement, &reduce, 1);
else
pcls_cdm->moveParticles(displace_pcls_ic_basic, 1./sim.numpts/sim.numpts/sim.numpts, &chi, 1, NULL, &max_displacement, &reduce, 1); // displace CDM particles
sim.numpcl[0] *= (long) ic.numtile[0] * (long) ic.numtile[0] * (long) ic.numtile[0];
COUT << " " << sim.numpcl[0] << " cdm particles initialized: maximum displacement (1st order) = " << max_displacement * sim.numpts << " lattice units." << endl;
maxvel[0] = pcls_cdm->updateVel(initialize_q_ic_basic, a/(1.5 * Hconf(a, fourpiG, cosmo)), &phi, 1) / a;
parallel.max<double>(maxvel, 1);
COUT << " maximum velocity (1st order) = " << maxvel[0] << endl;
COUT << " computing 1st order density..." << endl;
projection_init(chi);
projection_T00_project(pcls_cdm, chi, a, sim.gr_flag ? phi : NULL); // gr_flag=1 -> GR, else Newton
scalarProjectionCIC_comm(chi);
for (x.first(); x.test(); x.next())
(*chi)(x) = (*chi)(x) / (cosmo.Omega_cdm + cosmo.Omega_b) - 1.;
//filename.assign("1st_order_density.h5");
sprintf(filename, "%s%s_IC_1st_order_density.h5", sim.output_path, sim.basename_generic);
chi->saveHDF5(string(filename));
for (x.first(); x.test(); x.next())
(*chi)(x) = (*source)(x) - (*chi)(x);
plan_chi->execute(FFT_FORWARD);
for (kFT.first(); kFT.test(); kFT.next())
{
if ((*BiFT)(kFT, 0).norm() > 1.0e-16)
(*scalarFT)(kFT) = (*scalarFT)(kFT) / (*BiFT)(kFT, 0);
}
plan_chi->execute(FFT_BACKWARD);
chi->updateHalo();
//filename.assign("2nd_order_displacement.h5");
//chi->saveHDF5(filename);
pcls_cdm->moveParticles(displace_pcls_ic_basic, 1./sim.numpts/sim.numpts/sim.numpts, &chi, 1, NULL, &max_displacement, &reduce, 1);
COUT << " " << sim.numpcl[0] << " cdm particles initialized: maximum displacement (2nd order) = " << max_displacement * sim.numpts << " lattice units." << endl;
// compute velocity potential at second order
for (x.first(); x.test(); x.next())
{
r2 = 0.;
for (int i = 0; i < 3; i++)
r2 += (x.coord(i) - sim.numpts / 2) * (x.coord(i) - sim.numpts / 2);
r2 /= sim.numpts * sim.numpts;
(*chi)(x) = (*phi)(x) * (Real(1) + Real(2) * (*phi)(x));
if (r2 < sim.LTB_radius * sim.LTB_radius)
(*chi)(x) -= d1 * d1 * H2 * (r2 - sim.LTB_radius * sim.LTB_radius) * (16 + 35 * H2 * (r2 - sim.LTB_radius * sim.LTB_radius)) / 336.;
}
chi->updateHalo();
maxvel[0] = pcls_cdm->updateVel(initialize_q_ic_basic, a/(1.5 * Hconf(a, fourpiG, cosmo)), &chi, 1) / a;
parallel.max<double>(maxvel, 1);
COUT << " maximum velocity (2nd order) = " << maxvel[0] << endl;
COUT << " computing 2nd order density..." << endl;
projection_init(chi);
projection_T00_project(pcls_cdm, chi, a, sim.gr_flag ? phi : NULL); // toma
scalarProjectionCIC_comm(chi);
for (x.first(); x.test(); x.next())
(*chi)(x) = (*source)(x) - ((*chi)(x) / (cosmo.Omega_cdm + cosmo.Omega_b) - 1.);
plan_chi->execute(FFT_FORWARD);
for (kFT.first(); kFT.test(); kFT.next())
{
if ((*BiFT)(kFT, 0).norm() > 1.0e-16)
(*scalarFT)(kFT) = (*scalarFT)(kFT) / (*BiFT)(kFT, 0);
}
plan_chi->execute(FFT_BACKWARD);
chi->updateHalo();
//filename.assign("3rd_order_displacement.h5");
//chi->saveHDF5(filename);
pcls_cdm->moveParticles(displace_pcls_ic_basic, 1./sim.numpts/sim.numpts/sim.numpts, &chi, 1, NULL, &max_displacement, &reduce, 1);
COUT << " " << sim.numpcl[0] << " cdm particles initialized: maximum displacement (3rd order) = " << max_displacement * sim.numpts << " lattice units." << endl;
if (ic.tkfile[0] != '\0')
{
gsl_spline * pkspline = NULL;
gsl_spline * dgaugespline = NULL;
gsl_spline * vgaugespline = NULL;
gsl_spline * tk_d1 = NULL;
gsl_spline * tk_d2 = NULL;
gsl_spline * tk_t1 = NULL;
gsl_spline * tk_t2 = NULL;
double * temp1 = NULL;
double * temp2 = NULL;
loadTransferFunctions(ic.tkfile, tk_d1, tk_t1, NULL, sim.boxsize, cosmo.h);
if (tk_d1 == NULL || tk_t1 == NULL)
{
COUT << " error: total transfer function was empty!" << endl;
parallel.abortForce();
}
temp1 = (double *) malloc(tk_d1->size * sizeof(double));
temp2 = (double *) malloc(tk_d1->size * sizeof(double));
for (int i = 0; i < tk_d1->size; i++) // construct phi
{
temp1[i] = tk_d1->x[i] * ic.LTB_h_rescale * (ic.z_ic + 1.) / (sim.z_in + 1.);
temp2[i] = -M_PI * tk_d1->y[i] * sqrt(Pk_primordial(tk_d1->x[i] * cosmo.h * ic.LTB_h_rescale / sim.boxsize, ic) / temp1[i]) * temp1[i];
}
pkspline = gsl_spline_alloc(gsl_interp_cspline, tk_d1->size);
gsl_spline_init(pkspline, temp1, temp2, tk_d1->size);
loadTransferFunctions(ic.tkfile, tk_d2, tk_t2, "eta", sim.boxsize, cosmo.h);
if (tk_d2 == NULL || tk_t2 == NULL)
{
COUT << " error: transfer functions were empty!" << endl;
parallel.abortForce();
}
if (sim.gr_flag == 0)
{
double rescale = (Hconf(a, fourpiG, cosmo) - 100. * (Hconf(1.005 * a, fourpiG, cosmo) - Hconf(0.995 * a, fourpiG, cosmo))); // FIXME
for (int i = 0; i < tk_t2->size; i++) // construct gauge correction for N-body gauge (3 Hconf theta_tot / k^2 = 3 Hconf eta' / (Hconf^2 - Hconf'))
temp2[i] = 3. * tk_t2->y[i] / rescale;
}
else
{
for (int i = 0; i < tk_t2->size; i++) // construct gauge correction for Poisson gauge (3 phi - 3 eta)
temp2[i] = 3. * tk_d1->y[i] - 3. * tk_d2->y[i];
}
dgaugespline = gsl_spline_alloc(gsl_interp_cspline, tk_t2->size);
gsl_spline_init(dgaugespline, temp1, temp2, tk_t2->size);
gsl_spline_free(tk_d1);
gsl_spline_free(tk_t1);
if (sim.gr_flag > 0)
{
for (int i = 0; i < tk_t2->size; i++)
temp2[i] = 3. * tk_t2->y[i];
}
else
{
COUT << COLORTEXT_YELLOW << " /!\\ warning" << COLORTEXT_RESET << ": gauge correction for N-body gauge velocities cannot be computed accurately from the transfer functions at a single redshift!" << endl;
for (int i = 0; i < tk_t2->size; i++)
temp2[i] = 0.;
}
loadTransferFunctions(ic.tkfile, tk_d1, tk_t1, "h", sim.boxsize, cosmo.h);
if (tk_d1 == NULL || tk_t1 == NULL)
{
COUT << " error: transfer functions were empty!" << endl;
parallel.abortForce();
}
for (int i = 0; i < tk_t1->size; i++)
temp2[i] += tk_t1->y[i] * 0.5;
gsl_spline_free(tk_d1);
gsl_spline_free(tk_t1);
vgaugespline = gsl_spline_alloc(gsl_interp_cspline, tk_t2->size);
gsl_spline_init(vgaugespline, temp1, temp2, tk_t2->size);
gsl_spline_free(tk_d2);
gsl_spline_free(tk_t2);
loadTransferFunctions(ic.tkfile, tk_d1, tk_t1, "d_m", sim.boxsize, cosmo.h); // get transfer functions for matter
if (tk_d1 == NULL || tk_t1 == NULL)
{
COUT << " error: matter transfer function was empty!" << endl;
parallel.abortForce();
}
if (sim.baryon_flag == 2) // baryon treatment = blend; compute displacement & velocity from weighted average
{
loadTransferFunctions(ic.tkfile, tk_d2, tk_t2, "b", sim.boxsize, cosmo.h); // get transfer functions for baryons
if (tk_d2 == NULL || tk_t2 == NULL)
{
COUT << " error: baryon transfer function was empty!" << endl;
parallel.abortForce();
}
if (tk_d2->size != tk_d1->size)
{
COUT << " error: baryon transfer function line number mismatch!" << endl;
parallel.abortForce();
}
for (int i = 0; i < tk_d1->size; i++)
{
temp1[i] = (sim.gr_flag > 0 ? -3. * pkspline->y[i] / pkspline->x[i] / pkspline->x[i] : 0.) - ((cosmo.Omega_cdm * tk_d1->y[i] + cosmo.Omega_b * tk_d2->y[i]) / (cosmo.Omega_cdm + cosmo.Omega_b) + dgaugespline->y[i]) * M_PI * sqrt(Pk_primordial(tk_d1->x[i] * cosmo.h * ic.LTB_h_rescale / sim.boxsize, ic) / pkspline->x[i]) / pkspline->x[i];
temp2[i] = -a * ((cosmo.Omega_b * tk_t2->y[i]) / (cosmo.Omega_cdm + cosmo.Omega_b) + vgaugespline->y[i]) * M_PI * sqrt(Pk_primordial(tk_d1->x[i] * cosmo.h * ic.LTB_h_rescale / sim.boxsize, ic) / pkspline->x[i]) / pkspline->x[i];
}
gsl_spline_free(tk_d1);
gsl_spline_free(tk_t1);
tk_d1 = gsl_spline_alloc(gsl_interp_cspline, tk_d2->size);
tk_t1 = gsl_spline_alloc(gsl_interp_cspline, tk_d2->size);
gsl_spline_init(tk_d1, dgaugespline->x, temp1, tk_d2->size);
gsl_spline_init(tk_t1, dgaugespline->x, temp2, tk_d2->size);
gsl_spline_free(tk_d2);
gsl_spline_free(tk_t2);
}
else
{
for (int i = 0; i < tk_d1->size; i++)
{
temp1[i] = (sim.gr_flag > 0 ? -3. * pkspline->y[i] / tk_d1->x[i] / tk_d1->x[i] : 0.) - (tk_d1->y[i] + dgaugespline->y[i]) * M_PI * sqrt(Pk_primordial(tk_d1->x[i] * cosmo.h * ic.LTB_h_rescale / sim.boxsize, ic) / pkspline->x[i]) / pkspline->x[i];
temp2[i] = -a * vgaugespline->y[i] * M_PI * sqrt(Pk_primordial(tk_d1->x[i] * cosmo.h * ic.LTB_h_rescale / sim.boxsize, ic) / pkspline->x[i]) / pkspline->x[i];
}
gsl_spline_free(tk_d1);
gsl_spline_free(tk_t1);
tk_d1 = gsl_spline_alloc(gsl_interp_cspline, pkspline->size);
tk_t1 = gsl_spline_alloc(gsl_interp_cspline, pkspline->size);
gsl_spline_init(tk_d1, pkspline->x, temp1, pkspline->size);
gsl_spline_init(tk_t1, pkspline->x, temp2, pkspline->size);
}
free(temp1);
free(temp2);
for (kFT.first(); kFT.test(); kFT.next()) // get the CIC kernel
(*scalarFT)(kFT) = (*BiFT)(kFT, 0);
generateDisplacementField(*scalarFT, 0., tk_d1, (unsigned int) ic.seed, ic.flags & ICFLAG_KSPHERE);
gsl_spline_free(tk_d1);
plan_chi->execute(FFT_BACKWARD);
// apodize
for (x.first(); x.test(); x.next())
{
r2 = 0.;
for (int i = 0; i < 3; i++)
r2 += (x.coord(i) - sim.numpts / 2) * (x.coord(i) - sim.numpts / 2);
r2 /= sim.numpts * sim.numpts;
if (r2 > i2)
{
(*chi)(x) = Real(0);
}
else if ((r2 = sqrt(r2) / inner_radius) > 0.9)
{
(*chi)(x) *= 0.5 + 0.5 * cos(10. * M_PI * (r2 - 0.9));
}
}
chi->updateHalo(); // chi now contains the CDM displacement
pcls_cdm->moveParticles(displace_pcls_ic_basic, 1.0 /*pow((sim.z_in + 1.) / (ic.z_ic + 1.) / ic.LTB_h_rescale, 5)*/, &chi, 1, NULL, &max_displacement, &reduce, 1); // displace CDM particles
for (kFT.first(); kFT.test(); kFT.next()) // get the CIC kernel
(*scalarFT)(kFT) = (*BiFT)(kFT, 0);
generateDisplacementField(*scalarFT, 0., tk_t1, (unsigned int) ic.seed, ic.flags & ICFLAG_KSPHERE, 0);
gsl_spline_free(tk_t1);
plan_chi->execute(FFT_BACKWARD);
for (kFT.first(); kFT.test(); kFT.next()) // get the CIC kernel
(*scalarFT)(kFT) = (*BiFT)(kFT, 0);
generateDisplacementField(*scalarFT, 0., pkspline, (unsigned int) ic.seed, ic.flags & ICFLAG_KSPHERE, 0);
plan_source->execute(FFT_BACKWARD);
// apodize
for (x.first(); x.test(); x.next())
{
r2 = 0.;
for (int i = 0; i < 3; i++)
r2 += (x.coord(i) - sim.numpts / 2) * (x.coord(i) - sim.numpts / 2);
r2 /= sim.numpts * sim.numpts;
if (r2 > i2)
{
(*chi)(x) = Real(0);
}
else if ((r2 = sqrt(r2) / inner_radius) > 0.9)
{
(*chi)(x) *= 0.5 + 0.5 * cos(10. * M_PI * (r2 - 0.9));
(*phi)(x) += (0.5 + 0.5 * cos(10. * M_PI * (r2 - 0.9))) * (*source)(x) / pow((sim.z_in + 1.) / (ic.z_ic + 1.) / ic.LTB_h_rescale, 2);
}
else
{
(*phi)(x) += (*source)(x) * pow((sim.z_in + 1.) / (ic.z_ic + 1.) / ic.LTB_h_rescale, 3);
}
}
chi->updateHalo(); // chi now contains the CDM velocity potential
phi->updateHalo(); // phi has been updated with the matter perturbations
sprintf(filename, "%s%s_IC_phi_pert.h5", sim.output_path, sim.basename_generic);
phi->saveHDF5(string(filename));
r2 = 1.;
maxvel[0] = pcls_cdm->updateVel(update_q_Newton, 1.0 /*pow((sim.z_in + 1.) / (ic.z_ic + 1.) / ic.LTB_h_rescale, 5)*/, &chi, 1, &r2) / a;
parallel.max<double>(maxvel, 1);
COUT << " adding matter perturbations: maximum displacement = " << max_displacement * sim.numpts << " lattice units; maximum velocity = " << maxvel[0] << endl;
gsl_spline_free(pkspline);
if (dgaugespline != NULL)
gsl_spline_free(dgaugespline);
if (vgaugespline != NULL)
gsl_spline_free(vgaugespline);
}
/*if (sim.baryon_flag == 1)
{
loadHomogeneousTemplate(ic.pclfile[1], sim.numpcl[1], pcldata);
if (pcldata == NULL)
{
COUT << " error: particle data was empty!" << endl;
parallel.abortForce();
}
strcpy(pcls_b_info.type_name, "part_simple");
pcls_b_info.mass = cosmo.Omega_b / (Real) (sim.numpcl[1]*(long)ic.numtile[1]*(long)ic.numtile[1]*(long)ic.numtile[1]);
pcls_b_info.relativistic = false;
pcls_b->initialize(pcls_b_info, pcls_b_dataType, &(phi->lattice()), boxSize);
initializeParticlePositions(sim.numpcl[1], pcldata, ic.numtile[1], *pcls_b);
pcls_b->moveParticles(displace_pcls_ic_basic, 1./sim.boxsize/sim.boxsize, &phi, 1, NULL, &max_displacement, &reduce, 1); // displace baryon particles
sim.numpcl[1] *= (long) ic.numtile[1] * (long) ic.numtile[1] * (long) ic.numtile[1];
COUT << " " << sim.numpcl[1] << " baryon particles initialized: maximum displacement = " << max_displacement * sim.numpts << " lattice units." << endl;
free(pcldata);
}
if (ic.pkfile[0] == '\0') // set velocities using transfer functions
{
filename.assign(ic.velocityfile[1]);
chi->loadHDF5(filename);
chi->updateHalo();
if (sim.baryon_flag == 3) // baryon treatment = hybrid; set velocities using both velocity potentials
maxvel[0] = pcls_cdm->updateVel(initialize_q_ic_basic, -a/sim.boxsize, ic_fields, 2) / a;
else
maxvel[0] = pcls_cdm->updateVel(initialize_q_ic_basic, -a/sim.boxsize, &chi, 1) / a; // set CDM velocities
if (sim.baryon_flag == 1)
maxvel[1] = pcls_b->updateVel(initialize_q_ic_basic, -a/sim.boxsize, &phi, 1) / a; // set baryon velocities
}*/
if (sim.baryon_flag > 1) sim.baryon_flag = 0;
projection_init(Bi);
projection_T0i_project(pcls_cdm, Bi, phi);
if (sim.baryon_flag)
projection_T0i_project(pcls_b, Bi, phi);
projection_T0i_comm(Bi);
prepareFTsource(*Bi, *phi, 3. * a * a * Hconf(a, fourpiG, cosmo) * (double) sim.numpts / fourpiG);
plan_Bi->execute(FFT_FORWARD);
projectFTvector(*BiFT, *BiFT, fourpiG / (double) sim.numpts / (double) sim.numpts);
plan_Bi->execute(FFT_BACKWARD);
Bi->updateHalo(); // B initialized
ic_fields[1] = Bi;
projection_init(Sij);
projection_Tij_project(pcls_cdm, Sij, a, phi);
if (sim.baryon_flag)
projection_Tij_project(pcls_b, Sij, a, phi);
projection_Tij_comm(Sij);
prepareFTsource<Real>(*phi, *Sij, *Sij, 2. * fourpiG / a / (double) sim.numpts / (double) sim.numpts);
plan_Sij->execute(FFT_FORWARD);
projectFTscalar(*SijFT, *scalarFT);
plan_chi->execute(FFT_BACKWARD);
chi->updateHalo(); // chi now finally contains chi
free(sinc);
}
#endif