LALBurst 2.0.7.1-eeff03c
cs_lambda_cosmo.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Xavier Siemens
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20/*********************************************************************************/
21/* Cosmological functions for cosmic string burst computation */
22/* */
23/* Jolien Creighton, Irit Maor, Xavier Siemens */
24/* */
25/* UWM/Caltech - September 2006 */
26/*********************************************************************************/
27#include <math.h>
28#include <gsl/gsl_integration.h>
29#include <lal/cs_lambda_cosmo.h>
30
31#ifdef __GNUC__
32#define UNUSED __attribute__ ((unused))
33#else
34#define UNUSED
35#endif
36
37static double cs_lambda_hubble( double one_plus_z )
38{
39 const double Omega_m = LAMBDA_OMEGA_M;
40 const double Omega_r = LAMBDA_OMEGA_R;
41 const double Omega_L = 1.0 - LAMBDA_OMEGA_M - LAMBDA_OMEGA_R;
42 double one_plus_z_3 = one_plus_z * one_plus_z * one_plus_z;
43 double one_plus_z_4 = one_plus_z * one_plus_z_3;
44 double ans;
45 /* Eq. (A2) of [SCMRMCR] */
46 ans = sqrt( Omega_m * one_plus_z_3 + Omega_r * one_plus_z_4 + Omega_L );
47 return ans;
48}
49
50static double cs_lambda_phit_integrand( double y, void UNUSED * p )
51{
52 double one_plus_z;
53 double z;
54 double ans;
55
56 p = NULL;
57 z = 1.0 / y;
58 one_plus_z = 1.0 + z;
59 /* Integrand of Eq. (A4) of [SCMRMCR] */
60 ans = 1.0 / ( one_plus_z * cs_lambda_hubble( one_plus_z ) );
61 ans *= z * z; /* from change of variables */
62 return ans;
63}
64
65static double cs_lambda_phiA_integrand( double z, void UNUSED * p )
66{
67 double ans;
68
69 p = NULL;
70 /* Integrand of Eq. (A6) of [SCMRMCR] */
71 ans = 1.0 / cs_lambda_hubble( 1.0 + z );
72 return ans;
73}
74
75#define WORKSZ 100000
76#define EPS 1e-7
77cs_cosmo_functions_t XLALCSCosmoFunctionsAlloc( double zmin, double dlnz, size_t n )
78{
79 cs_cosmo_functions_t cosmofns;
80 gsl_integration_workspace * w = gsl_integration_workspace_alloc(WORKSZ);
81 gsl_function F1, F2;
82 size_t i;
83
84 cosmofns.zmin = zmin;
85 cosmofns.dlnz = dlnz;
86 cosmofns.n = n;
87 cosmofns.z = calloc( n, sizeof( *cosmofns.z ) );
88 cosmofns.phit = calloc( n, sizeof( *cosmofns.phit ) );
89 cosmofns.phiA = calloc( n, sizeof( *cosmofns.phiA ) );
90 cosmofns.phiV = calloc( n, sizeof( *cosmofns.phiV ) );
91
92 F1.params = F2.params = NULL;
93 F1.function = &cs_lambda_phiA_integrand;
94 F2.function = &cs_lambda_phit_integrand;
95
96 for ( i = 0; i < n; ++i )
97 {
98 double one_plus_z;
99 double one_plus_z_3;
100 double err;
101 double h;
102
103 cosmofns.z[i] = zmin * exp( i * dlnz );
104
105 gsl_integration_qag (&F1, 0, cosmofns.z[i], 0, EPS, WORKSZ, 1, w, cosmofns.phiA+i, &err );
106 gsl_integration_qag (&F2, 0, 1.0/cosmofns.z[i], 0, EPS, WORKSZ, 1, w, cosmofns.phit+i, &err );
107 /* Eq. (A8) of [SCMRMCR] */
108 one_plus_z = 1.0 + cosmofns.z[i];
109 one_plus_z_3 = one_plus_z * one_plus_z * one_plus_z;
110 h = cs_lambda_hubble( one_plus_z );
111 cosmofns.phiV[i] = 4.0 * M_PI * cosmofns.phiA[i] * cosmofns.phiA[i] / ( one_plus_z_3 * h );
112 }
113
114 gsl_integration_workspace_free( w );
115 return cosmofns;
116}
117
119{
120 cs_cosmo_functions_t cosmofns;
121 gsl_integration_workspace * w = gsl_integration_workspace_alloc(WORKSZ);
122 gsl_function F1, F2;
123 size_t i;
124
125 cosmofns.zmin = z[0];
126 cosmofns.dlnz = 0;
127 cosmofns.n = n;
128 cosmofns.z = calloc( n, sizeof( *cosmofns.z ) );
129 cosmofns.phit = calloc( n, sizeof( *cosmofns.phit ) );
130 cosmofns.phiA = calloc( n, sizeof( *cosmofns.phiA ) );
131 cosmofns.phiV = calloc( n, sizeof( *cosmofns.phiV ) );
132
133 F1.params = F2.params = NULL;
134 F1.function = &cs_lambda_phiA_integrand;
135 F2.function = &cs_lambda_phit_integrand;
136
137 for ( i = 0; i < n; ++i )
138 {
139 double one_plus_z;
140 double one_plus_z_3;
141 double err;
142 double h;
143
144 cosmofns.z[i] = z[i];
145
146 gsl_integration_qag (&F1, 0, cosmofns.z[i], 0, EPS, WORKSZ, 1, w, cosmofns.phiA+i, &err );
147 gsl_integration_qag (&F2, 0, 1.0/cosmofns.z[i], 0, EPS, WORKSZ, 1, w, cosmofns.phit+i, &err );
148 /* Eq. (A8) of [SCMRMCR] */
149 one_plus_z = 1.0 + cosmofns.z[i];
150 one_plus_z_3 = one_plus_z * one_plus_z * one_plus_z;
151 h = cs_lambda_hubble( one_plus_z );
152 cosmofns.phiV[i] = 4.0 * M_PI * cosmofns.phiA[i] * cosmofns.phiA[i] / ( one_plus_z_3 * h );
153 }
154
155 gsl_integration_workspace_free( w );
156 return cosmofns;
157}
158
160{
161 free(cosmofns.z);
162 free(cosmofns.phit);
163 free(cosmofns.phiA);
164 free(cosmofns.phiV);
165}
double i
static double cs_lambda_phit_integrand(double y, void UNUSED *p)
static double cs_lambda_hubble(double one_plus_z)
void XLALCSCosmoFunctionsFree(cs_cosmo_functions_t cosmofns)
#define WORKSZ
#define EPS
cs_cosmo_functions_t XLALCSCosmoFunctionsAlloc(double zmin, double dlnz, size_t n)
static double cs_lambda_phiA_integrand(double z, void UNUSED *p)
cs_cosmo_functions_t XLALCSCosmoFunctions(double *z, size_t n)
#define LAMBDA_OMEGA_R
#define LAMBDA_OMEGA_M
const double w
list y
p