14 #include <gsl/gsl_matrix.h> 15 #include <gsl/gsl_linalg.h> 16 #include <gsl/gsl_spline.h> 17 #include <gsl/gsl_errno.h> 25 static int m[2] = {111, 36},
neta=2808,
peta[2]={7, 28},
rs=8,
p=8;
32 static double beta[2][28][8];
33 static double w[2][28][111];
61 for(j=0; j<111; j++) {
62 w[0][i][j] =
w1[i][j];
68 w[1][i][j] =
w2[i][j];
85 for(ee=0; ee<2; ee++) {
88 SigmaSim = gsl_matrix_alloc(
m[ee],
m[ee]);
89 b = gsl_vector_alloc(
m[ee]);
92 for(i=0; i<
peta[ee]; i++) {
95 for(j=0; j<
m[ee]; j++) {
98 gsl_matrix_set(SigmaSim, j, j, (1.0/
lamz[ee][i]) + (1.0/
lamws[ee][i]));
106 cov -=
beta[ee][i][
l]*
pow(
x[j][l] -
x[k][l], 2.0);
108 cov = exp(cov) /
lamz[ee][i];
111 gsl_matrix_set(SigmaSim, j, k, cov);
112 gsl_matrix_set(SigmaSim, k, j, cov);
117 gsl_vector_set(b, j,
w[ee][i][j]);
122 gsl_linalg_cholesky_decomp(SigmaSim);
123 gsl_linalg_cholesky_svx(SigmaSim, b);
126 for(j=0; j<m[ee]; j++) {
127 KrigBasis[ee][i][j] = gsl_vector_get(b, j);
133 gsl_matrix_free(SigmaSim);
143 static double inited=0;
146 double Sigmastar[2][peta[1]][
m[0]];
147 double ystaremu[
neta];
148 *ystar=(
double *)malloc(
sizeof(
double)*
NK_EMU);
153 gsl_spline *zinterp = gsl_spline_alloc(gsl_interp_cspline,
rs);
154 gsl_interp_accel *accel = gsl_interp_accel_alloc();
164 xstar[6] =
pow(-xstar[5]-xstar[6], 0.25);
167 if((xstar[i] <
xmin[i]) || (xstar[i] >
xmax[i])) {
171 "ccl_pkemu(): omega_m must be between %f and %f.\n",
176 "ccl_pkemu(): omega_b must be between %f and %f.\n",
181 "ccl_pkemu(): sigma8 must be between %f and %f.\n",
186 "ccl_pkemu(): h must be between %f and %f.\n",
191 "ccl_pkemu(): n_s must be between %f and %f.\n",
196 "ccl_pkemu(): w_0 must be between %f and %f.\n",
201 "ccl_pkemu(): (-w_0-w_a)^(1/4) must be between %f and %f.\n",
206 "ccl_pkemu(): omega_nu must be between %f and %f.\n",
212 gsl_spline_free(zinterp);
213 gsl_interp_accel_free(accel);
217 if((xstar[p] <
z[0]) || (xstar[p] >
z[
rs-1])) {
219 "ccl_pkemu(): z must be between %f and %f.\n",
223 gsl_spline_free(zinterp);
224 gsl_interp_accel_free(accel);
230 xstarstd[i] = (xstar[i] -
xmin[i]) /
xrange[i];
234 for(ee=0; ee<2; ee++) {
235 for(i=0; i<peta[ee]; i++) {
236 for(j=0; j<m[ee]; j++) {
239 logc -=
beta[ee][i][k]*
pow(
x[j][k] - xstarstd[k], 2.0);
241 Sigmastar[ee][i][j] = exp(logc) /
lamz[ee][i];
247 for(i=0; i<peta[0]; i++) {
249 for(j=0; j<m[0]; j++) {
250 wstar[i] += Sigmastar[0][i][j] *
KrigBasis[0][i][j];
254 for(i=0; i<peta[1]; i++) {
255 wstar[peta[0]+i]=0.0;
256 for(j=0; j<m[1]; j++) {
257 wstar[peta[0]+i] += Sigmastar[1][i][j] *
KrigBasis[1][i][j];
268 for(i=0; i<
neta; i++) {
270 for(j=0; j<peta[0]+peta[1]; j++) {
271 ystaremu[i] +=
K[i][j]*wstar[j];
273 ystaremu[i] = ystaremu[i]*
sd +
mean[i];
287 for(i=0; i<
rs; i++) {
288 if(xstar[p] ==
z[i]) {
296 for(j=0; j<
rs; j++) {
297 ybyz[rs-j-1] = ystaremu[j*NK_EMU+i];
299 gsl_spline_init(zinterp,
z, ybyz, rs);
300 (*ystar)[i] = gsl_spline_eval(zinterp, xstar[p], accel);
301 gsl_interp_accel_reset(accel);
306 (*ystar)[i] = ystaremu[zmatch*NK_EMU + i];
310 gsl_spline_free(zinterp);
311 gsl_interp_accel_free(accel);
315 (*ystar)[i] = (*ystar)[i] - 1.5*log10(
mode[i]) + log10(2) + 2*log10(
M_PI);
316 (*ystar)[i] =
pow(10, (*ystar)[i]);
static double KrigBasis[2][28][111]
static double lamz[2][28]
static double beta2[28][8]
static double beta1[7][8]
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
static double lamws[2][28]
static double beta[2][28][8]
static CCL_BEGIN_DECLS double x[111][8]
void ccl_pkemu(double *xstar, double **ystar, int *status, ccl_cosmology *cosmo)
#define CCL_ERROR_EMULATOR_BOUND
float pow(float base, unsigned long int exp)
void ccl_raise_exception(int err, const char *msg,...)
static double K[2808][35]
static double w[2][28][111]