/
FFT_potDot_linear.c
300 lines (223 loc) · 9.96 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
/****************************************************************************************************
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;
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)) );
GR_OmegaM = pow(OmegaM_ofa, 0.6);
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(void)
{
int m;
double norm, alpha, z, fn_app1, fn_app2, factor;
FILE *pf=NULL;
/*----- 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");
/*----- 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;
printf("Computing the linear approximations in Fourier space");
printf("----------------------------------------------------");
for( m=0; m<GV.NTOTK; m++ )
{
if( fabs(gp[m].k_module) > GV.ZERO )
{
alpha = factor / (gp[m].k_module * gp[m].k_module);
/*::::: Approximation proportional to 1/\Omega_{L0} :::::*/
gp[m].potDot_k_l_app1[0] = alpha * gp[m].DenCon_K[0] * fn_app1; //Re()
gp[m].potDot_k_l_app1[1] = alpha * gp[m].DenCon_K[1] * fn_app1; //Im()
/*::::: Aproximation proportional to \Omega_M(a) :::::*/
gp[m].potDot_k_l_app2[0] = alpha * gp[m].DenCon_K[0] * fn_app2; //Re()
gp[m].potDot_k_l_app2[1] = alpha * gp[m].DenCon_K[1] * fn_app2; //Im()
}//if
else
{
gp[m].potDot_k_l_app1[0] = 0.0;
gp[m].potDot_k_l_app1[1] = 0.0;
gp[m].potDot_k_l_app2[0] = 0.0;
gp[m].potDot_k_l_app2[1] = 0.0;
}//else
}//for m
printf("Time derivative of potential in k-space saved!\n");
printf("--------------------------------------------------\n");
/*+++++ OUT-OF-PLACE TRANSFORM +++++*/
#ifdef OUTOFPLACE
/*+++++ FFTW DEFINITIONS +++++*/
fftw_complex *in=NULL;
fftw_complex *in2=NULL;
double *out=NULL;
fftw_plan plan_k2r; // FFTW from k-space to r-space
fftw_plan plan_r2k; // FFTW from r-space to k-space
/**************************************************************************************/
/* 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.NTOTK);
out = ( double *) fftw_malloc( sizeof( double ) * GV.NTOTALCELLS );
for( m=0; m<GV.NTOTK; m++ )
{
in[m][0] = gp[m].potDot_k_l_app1[0]; //Re()
in[m][1] = gp[m].potDot_k_l_app1[1]; //Im()
}//for m
/*+++++ Making the FFT +++++*/
plan_k2r = fftw_plan_dft_c2r_3d( GV.NCELLS, GV.NCELLS, GV.NCELLS, in, out, FFTW_ESTIMATE );
fftw_execute(plan_k2r);
printf("FFT of potential derivative in r finished!\n");
printf("-----------------------------------------\n");
/*+++++ Saving data +++++*/
for( m=0; m<GV.NTOTALCELLS; m++ )
{
gp[m].potDot_r_l_app1 = out[m]/GV.NORM; //Re()
}//for m
/*+++++ Recreating input array +++++*/
/*
in2 = (fftw_complex *) malloc( sizeof( fftw_complex ) * GV.NTOTK );
plan_r2k = fftw_plan_dft_r2c_3d( GV.NCELLS, GV.NCELLS, GV.NCELLS, out, in2, FFTW_ESTIMATE );
fftw_execute( plan_r2k );
*/
fftw_free(in);
//fftw_free(in2);
fftw_free(out);
/**************************************************************************************/
/* 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.NTOTK );
out = ( double *) fftw_malloc( sizeof( double ) * GV.NTOTALCELLS );
for( m=0; m<GV.NTOTK; m++ )
{
in[m][0] = gp[m].potDot_k_l_app2[0];
in[m][1] = gp[m].potDot_k_l_app2[1];
}//for m
/*+++++ Making the FFT +++++*/
plan_k2r = fftw_plan_dft_c2r_3d( GV.NCELLS, GV.NCELLS, GV.NCELLS, in, out, FFTW_ESTIMATE );
fftw_execute(plan_k2r);
printf("FFT of potential derivative in r finished!\n");
printf("-----------------------------------------\n");
/*+++++ Saving data +++++*/
for( m=0; m<GV.NTOTALCELLS; m++ )
{
gp[m].potDot_r_l_app2 = out[m]/GV.NORM;
}//for m
/*+++++ Recreating input array +++++*/
/*
in2 = (double *) malloc( sizeof( double ) * GV.NTOTALCELLS );
plan_r2k = fftw_plan_dft_r2c_3d( GV.NCELLS, GV.NCELLS, GV.NCELLS, out, in2, FFTW_ESTIMATE );
fftw_execute( plan_r2k );
*/
fftw_free(in);
//fftw_free(in2);
fftw_free(out);
/*+++++ Finishing +++++*/
fftw_destroy_plan( plan_k2r );
//fftw_destroy_plan( plan_r2k );
#endif
/*+++++ IN-PLACE TRANSFORM +++++*/
#ifdef INPLACE
/*+++++ FFTW DEFINITIONS +++++*/
fftw_complex *in=NULL;
fftw_plan plan_k2r; // FFTW from k-space to r-space
fftw_plan plan_r2k; // FFTW from r-space to k-space
/**************************************************************************************/
/* 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.NTOTK);
for( m=0; m<GV.NTOTK; m++ )
{
in[m][0] = gp[m].potDot_k_l_app1[0]; //Re()
in[m][1] = gp[m].potDot_k_l_app1[1]; //Im()
}//for m
/*+++++ Making the FFT +++++*/
plan_k2r = fftw_plan_dft_c2r_3d( GV.NCELLS, GV.NCELLS, GV.NCELLS, in, (double*)in, FFTW_ESTIMATE );
fftw_execute(plan_k2r);
printf("FFT of potential derivative in r finished!\n");
printf("-----------------------------------------\n");
/*+++++ Saving data +++++*/
for( m=0; m<GV.NTOTALCELLS/2; m++ )
{
gp[2*m].potDot_r_l_app1 = in[m][0]/GV.NORM;
gp[2*m+1].potDot_r_l_app1 = in[m][1]/GV.NORM;
}//for m
/*+++++ Recreating input array +++++*/
/*
plan_r2k = fftw_plan_dft_r2c_3d( GV.NCELLS, GV.NCELLS, GV.NCELLS, (double*)in, in, FFTW_ESTIMATE );
fftw_execute( plan_r2k );
*/
fftw_free(in);
/**************************************************************************************/
/* 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 );
for( m=0; m<GV.NTOTK; m++ )
{
in[m][0] = gp[m].potDot_k_l_app2[0];
in[m][1] = gp[m].potDot_k_l_app2[1];
}//for m
/*+++++ Making the FFT +++++*/
plan_k2r = fftw_plan_dft_c2r_3d( GV.NCELLS, GV.NCELLS, GV.NCELLS, in, (double*) in, FFTW_ESTIMATE );
fftw_execute(plan_k2r);
printf("FFT of potential derivative in r finished!\n");
printf("-----------------------------------------\n");
/*+++++ Saving data +++++*/
for( m=0; m<GV.NTOTALCELLS/2; m++ )
{
gp[2*m].potDot_r_l_app2 = in[m][0]/GV.NORM;
gp[2*m+1].potDot_r_l_app2 = in[m][1]/GV.NORM;
}//for m
/*+++++ Recreating input array +++++*/
/*
plan_r2k = fftw_plan_dft_r2c_3d( GV.NCELLS, GV.NCELLS, GV.NCELLS, (double*)in, in, FFTW_ESTIMATE );
fftw_execute( plan_r2k );
*/
/*+++++ Finishing +++++*/
fftw_free(in);
fftw_destroy_plan( plan_k2r );
fftw_destroy_plan( plan_k2r );
#endif
printf("FFT_pot_dot lineal code finished!\n");
printf("--------------------------\n");
return 0;
}//potential_dot_linear