-
Notifications
You must be signed in to change notification settings - Fork 0
/
FFT_potDot_linear.c
364 lines (288 loc) · 12 KB
/
FFT_potDot_linear.c
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
/****************************************************************************************************
NAME: growth_rate_OmegaL0
FUNCTION: Computes the growth rate f(t) for first linear approx. proportional to Omega_Lambda0
INPUT: Scale factor
RETURN: Growth rate f(t) for first approx. proportional to Omega_Lambda0
****************************************************************************************************/
/*
double growth_rate_OmegaL0(double a_SF)
{
double GR_OmegaL0, a_cube;
a_cube = pow(a_SF, 3.0);
GR_OmegaL0 = 1.0/( pow( (1.0+GV.Omega_L0*a_cube), 0.6) );
printf("-----------------------------------------------------------------\n");
printf("First approximation to f(t)\n");
printf("OmegaL0=%lf, growth rate f(t)=%lf\n",
GV.Omega_L0, GR_OmegaL0);
printf("-----------------------------------------------------------------\n");
return GR_OmegaL0;
}//growth_rate_app1
*/
/****************************************************************************************************
NAME: growth_rate_OmegaM
FUNCTION: Computes the growth rate f(t) for second linear approx. proportional to Omega_M(a)
INPUT: Scale factor
RETURN: Growth rate f(t) for second linear approx. proportional to Omega_M(a)
****************************************************************************************************/
double growth_rate_OmegaM(double a_SF)
{
double OmegaM_ofa, mu, GR_OmegaM, z, a_cube;
a_cube = POW3(a_SF);
//mu = a_SF * pow((GV.Omega_L0/GV.Omega_M0), 1.0/3.0);
//OmegaM_ofa = GV.Omega_M0 / ( (double) (1 + pow(mu, 3.0)) );
OmegaM_ofa = GV.Omega_M0 / ( (GV.Omega_M0 + GV.Omega_L0*a_cube) );
GR_OmegaM = pow(OmegaM_ofa, 5.0/9.0);
printf("-----------------------------------------------------------------\n");
printf("Second approximation to f(t)\n");
printf("mu=%lf, OmegaM(a)=%lf, growth rate f(t)=%lf\n",
mu, OmegaM_ofa, GR_OmegaM);
printf("-----------------------------------------------------------------\n");
return GR_OmegaM;
}//growth_rate_app2
/****************************************************************************************************
NAME: potential_dot_linear
FUNCTION: Calculates the time derivative of the gravitational potential the k-space, and then with
an IFFT calculates the time derivative of potential in the position's space. This is performed in
the linear approximations computed before.
INPUT: None
RETURN: none
****************************************************************************************************/
/****** COMPUTING LINEAR POTDOT ******/
//int potential_dot_linear( double **potDot_r_l_app1, double **potDot_r_l_app2 )
int potential_dot_linear( void )
{
int m, i, j, k;
double pos_aux[3];
double alpha, fn_app1, fn_app2, factor;
double Green_factor;
FILE *pf=NULL;
/*+++++ FFTW DEFINITIONS +++++*/
fftw_complex *in=NULL;
fftw_complex *in2=NULL;
fftw_complex *out=NULL;
fftw_plan plan_k2r; // FFTW from k-space to r-space
fftw_plan plan_r2k; // FFTW from r-space to k-space
/*----- Computing the approximations to the linear growth rate f -----*/
//fn_app1 = 1.0 - ( growth_rate_OmegaL0( GV.a_SF ) );
fn_app2 = 1.0 - ( growth_rate_OmegaM( GV.a_SF ) );
/*
printf("GR_OmegaL0=%lf GR_OmegaM=%lf a_SF=%lf\n",
growth_rate_OmegaL0(GV.a_SF), growth_rate_OmegaM(GV.a_SF), GV.a_SF);
printf("---------------------------------------\n");
*/
printf("GR_OmegaM=%lf a_SF=%lf\n",
growth_rate_OmegaM(GV.a_SF), GV.a_SF);
printf("---------------------------------------\n");
/**************************************************************************************/
/* Linear PotDot with the first approximation to the linear growth rate f */
/**************************************************************************************/
/*+++++ Creating input/output arrays +++++*/
/*
in = ( fftw_complex *) fftw_malloc( sizeof( fftw_complex ) * GV.NTOTALCELLS);
out = ( fftw_complex *) fftw_malloc( sizeof( fftw_complex ) * GV.NTOTALCELLS );
plan_k2r = fftw_plan_dft_3d( GV.NCELLS, GV.NCELLS, GV.NCELLS, in, out, FFTW_BACKWARD, FFTW_ESTIMATE );
*/
/*----- Computing the time derivative of potential in k-space -----*/
/*
factor = (-3.0/2.0) * GV.H0 * GV.H0 * (GV.Hz / GV.a_SF) * GV.Omega_M0;
for(m=0; m<GV.NTOTALCELLS; m++)
{
if(gp[m].k_mod_HE > GV.ZERO)
{
Green_factor = -1.0 / gp[m].k_mod_HE;
alpha = factor * Green_factor;
//::::: Approximation proportional to 1/\Omega_{L0} :::::
in[m][0] = alpha * gp[m].DenCon_K[0] * fn_app1; //Re()
in[m][1] = alpha * gp[m].DenCon_K[1] * fn_app1; //Im()
}//if
else
{
in[m][0] = 0.0;
in[m][1] = 0.0;
}//else
Green_factor = 0.0;
}//for m
//+++++ Making the FFT +++++
fftw_execute(plan_k2r);
printf("FFT of PotDot App1 in r finished!\n");
printf("-----------------------------------------\n");
//+++++ Freeing up memory +++++
fftw_free(in);
//+++++ Saving data +++++
for( m=0; m<GV.NTOTALCELLS; m++ )
{
//potDot_r_l_app1[m][0] = GV.fftw_norm * GV.conv_norm * out[m][0] / GV.r2k_norm; //Re()
//potDot_r_l_app1[m][1] = GV.k2r_norm * out[m][1]; //Im()
out[m][0] = GV.fftw_norm * out[m][0] / GV.r2k_norm; //Re()
}//for m
printf("Saving data in binary file for the first approximation\n");
printf("--------------------------\n");
pf = fopen("./../../Processed_data/PotDot_app1.bin", "w");
#ifdef SUPERCIC
//..... File app1 .....
fwrite(&GV.BoxSize, sizeof(double), 1, pf); // Box Size
fwrite(&GV.Omega_M0, sizeof(double), 1, pf); // Matter density parameter
fwrite(&GV.Omega_L0, sizeof(double), 1, pf); // Cosmological constant density parameter
fwrite(&GV.z_RS, sizeof(double), 1, pf); // Redshift
fwrite(&GV.H0, sizeof(double), 1, pf); // Hubble parameter
fwrite(&GV.NCELLS, sizeof(int), 1, pf); // Number of cells
for(m=0; m<GV.NTOTALCELLS; m++)
{
//..... File app1 .....
//fwrite(&potDot_r_l_app1[m][0], sizeof(double), 1, pf);
fwrite(&out[m][0], sizeof(double), 1, pf);
}//for m
#endif
#if defined(CIC_400) || defined(CIC_MDR)
//+++++ Saving Simulation parameters +++++
fwrite(&GV.BoxSize, sizeof(double), 1, pf); // Box Size
fwrite(&GV.Omega_M0, sizeof(double), 1, pf); // Matter density parameter
fwrite(&GV.Omega_L0, sizeof(double), 1, pf); // Cosmological constant density parameter
fwrite(&GV.z_RS, sizeof(double), 1, pf); // Redshift
fwrite(&GV.H0, sizeof(double), 1, pf); // Hubble parameter
fwrite(&GV.NCELLS, sizeof(int), 1, pf); // Hubble parameter
for(i=0; i<GV.NCELLS; i++)
{
for(j=0; j<GV.NCELLS; j++)
{
for(k=0; k<GV.NCELLS; k++)
{
m = INDEX_C_ORDER(i,j,k);
pos_aux[X] = i * GV.CellSize;
pos_aux[Y] = j * GV.CellSize;
pos_aux[Z] = k * GV.CellSize;
fwrite(&pos_aux[0], sizeof(double), 3, pf);
fwrite(&out[m][0], sizeof(double), 1, pf);
}//for k
}//for j
}//for i
#endif
fclose(pf);
fftw_free(out);
//free(potDot_r_l_app1);
*/
/**************************************************************************************/
/* Linear PotDot with the second approximation to the linear growth rate f */
/**************************************************************************************/
/*+++++ Creating input/output arrays +++++*/
in = ( fftw_complex *) fftw_malloc( sizeof( fftw_complex ) * GV.NTOTALCELLS);
out = ( fftw_complex *) fftw_malloc( sizeof( fftw_complex ) * GV.NTOTALCELLS );
plan_k2r = fftw_plan_dft_3d( GV.NCELLS, GV.NCELLS, GV.NCELLS, in, out, FFTW_BACKWARD, FFTW_ESTIMATE );
factor = (-3.0/2.0) * GV.H0 * GV.H0 * (GV.Hz / GV.a_SF) * GV.Omega_M0;
for(m=0; m<GV.NTOTALCELLS; m++)
{
if(gp[m].k_mod_HE > GV.ZERO)
{
Green_factor = -1.0 / gp[m].k_mod_HE;
alpha = factor * Green_factor;
/*::::: Approximation proportional to 1/\Omega_{M}(a) :::::*/
in[m][0] = alpha * gp[m].DenCon_K[0] * fn_app2; //Re()
in[m][1] = alpha * gp[m].DenCon_K[1] * fn_app2; //Im()
}//if
else
{
in[m][0] = 0.0;
in[m][1] = 0.0;
}//else
Green_factor = 0.0;
}//for m
#ifdef FOURIERFIELDS
pf = fopen("./../../Processed_data/PotDot_app2_k.bin", "w");
fwrite(&GV.BoxSize, sizeof(double), 1, pf); // Box Size
fwrite(&GV.Omega_M0, sizeof(double), 1, pf); // Matter density parameter
fwrite(&GV.Omega_L0, sizeof(double), 1, pf); // Cosmological constant density parameter
fwrite(&GV.z_RS, sizeof(double), 1, pf); // Redshift
fwrite(&GV.H0, sizeof(double), 1, pf); // Hubble parameter
fwrite(&GV.NCELLS, sizeof(int), 1, pf); // Hubble parameter
for(m=0; m< GV.NTOTALCELLS; m++)
{
fwrite(&(gp[m].DenCon_K[0]), sizeof(double), 2, pf);
}//for m
fclose(pf);
#endif
/*+++++ Making the FFT +++++*/
fftw_execute(plan_k2r);
printf("FFT of potential derivative in r finished!\n");
printf("-----------------------------------------\n");
/*+++++ Freeing up memory +++++*/
fftw_free(in);
/*+++++ Saving data +++++*/
for( m=0; m<GV.NTOTALCELLS; m++ )
{
out[m][0] = GV.fftw_norm * out[m][0] / GV.r2k_norm; //Re()
}//for m
printf("Saving data in binary file for the second approximation\n");
printf("--------------------------\n");
pf = fopen("./../../Processed_data/PotDot_app2.bin", "w");
#ifdef SUPERCIC
/*..... File app2 .....*/
fwrite(&GV.BoxSize, sizeof(double), 1, pf); // Box Size
fwrite(&GV.Omega_M0, sizeof(double), 1, pf); // Matter density parameter
fwrite(&GV.Omega_L0, sizeof(double), 1, pf); // Cosmological constant density parameter
fwrite(&GV.z_RS, sizeof(double), 1, pf); // Redshift
fwrite(&GV.H0, sizeof(double), 1, pf); // Hubble parameter
fwrite(&GV.NCELLS, sizeof(int), 1, pf); // Number of cells
for(m=0; m<GV.NTOTALCELLS; m++)
{
/*..... File app2 .....*/
fwrite(&out[m][0], sizeof(double), 1, pf);
}//for m
#endif
#ifdef CIC_400
/*+++++ Saving Simulation parameters +++++*/
fwrite(&GV.BoxSize, sizeof(double), 1, pf); // Box Size
fwrite(&GV.Omega_M0, sizeof(double), 1, pf); // Matter density parameter
fwrite(&GV.Omega_L0, sizeof(double), 1, pf); // Cosmological constant density parameter
fwrite(&GV.z_RS, sizeof(double), 1, pf); // Redshift
fwrite(&GV.H0, sizeof(double), 1, pf); // Hubble parameter
fwrite(&GV.NCELLS, sizeof(int), 1, pf); // Hubble parameter
for(i=0; i<GV.NCELLS; i++)
{
for(j=0; j<GV.NCELLS; j++)
{
for(k=0; k<GV.NCELLS; k++)
{
m = INDEX_C_ORDER(i,j,k);
pos_aux[X] = i * GV.CellSize;
pos_aux[Y] = j * GV.CellSize;
pos_aux[Z] = k * GV.CellSize;
fwrite(&pos_aux[0], sizeof(double), 3, pf);
fwrite(&out[m][0], sizeof(double), 1, pf);
}//for k
}//for j
}//for i
#endif
#ifdef CIC_MDR
/*+++++ Saving Simulation parameters +++++*/
fwrite(&GV.BoxSize, sizeof(double), 1, pf); // Box Size
fwrite(&GV.Omega_M0, sizeof(double), 1, pf); // Matter density parameter
fwrite(&GV.Omega_L0, sizeof(double), 1, pf); // Cosmological constant density parameter
fwrite(&GV.z_RS, sizeof(double), 1, pf); // Redshift
fwrite(&GV.H0, sizeof(double), 1, pf); // Hubble parameter
fwrite(&GV.NCELLS, sizeof(int), 1, pf); // Hubble parameter
for(i=0; i<GV.NCELLS; i++)
{
for(j=0; j<GV.NCELLS; j++)
{
for(k=0; k<GV.NCELLS; k++)
{
m = INDEX_C_ORDER(i,j,k);
//pos_aux[X] = i * GV.CellSize;
//pos_aux[Y] = j * GV.CellSize;
//pos_aux[Z] = k * GV.CellSize;
//fwrite(&pos_aux[0], sizeof(double), 3, pf);
fwrite(&out[m][0], sizeof(double), 1, pf);
}//for k
}//for j
}//for i
#endif
fclose(pf);
fftw_free(out);
//free(potDot_r_l_app2);
/*+++++ Finishing +++++*/
fftw_destroy_plan( plan_k2r );
//fftw_destroy_plan( plan_r2k );
printf("FFT_pot_dot lineal code finished!\n");
printf("--------------------------\n");
return 0;
}//potential_dot_linear