Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_emu17.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define A_MIN_EMU   1./3.
 
#define K_MAX_EMU   5.0
 
#define K_MIN_EMU   1.0000000474974513E-003
 
#define NK_EMU   351
 

Functions

CCL_BEGIN_DECLS void ccl_pkemu (double *xstarin, double **Pkemu, int *status, ccl_cosmology *cosmo)
 

Macro Definition Documentation

#define A_MIN_EMU   1./3.
#define K_MAX_EMU   5.0

Definition at line 5 of file ccl_emu17.h.

Referenced by ccl_cosmology_compute_power_emu().

#define K_MIN_EMU   1.0000000474974513E-003

Definition at line 6 of file ccl_emu17.h.

Referenced by ccl_cosmology_compute_power_emu().

#define NK_EMU   351

Definition at line 7 of file ccl_emu17.h.

Referenced by ccl_cosmology_compute_power_emu(), and ccl_pkemu().

Function Documentation

CCL_BEGIN_DECLS void ccl_pkemu ( double xstarin,
double **  Pkemu,
int *  status,
ccl_cosmology cosmo 
)

Emulator power spectrum Obtain P(k,z) [Mpc^3] for a given set of input parameters.

Parameters
xstarinvector of input parameters for the emulator, including redshift.
Pkemuoutput P(k,z) power spectrum
statusStatus flag. 0 if there are no errors, nonzero otherwise.
cosmoCosmology parameters and configurations (only relevant for storing status)

Definition at line 141 of file ccl_emu17.c.

References beta, ccl_cosmology_set_status_message(), CCL_ERROR_EMULATOR_BOUND, ccl_raise_exception(), emuInit(), K, KrigBasis, lamz, m, M_PI, mean, mode, neta, NK_EMU, p, peta, pow(), rs, sd, ccl_cosmology::status_message, x, xmax, xmin, xrange, and z.

Referenced by ccl_cosmology_compute_power_emu().

141  {
142 
143  static double inited=0;
144  int ee, i, j, k;
145  double wstar[peta[0]+peta[1]];
146  double Sigmastar[2][peta[1]][m[0]];
147  double ystaremu[neta];
148  *ystar=(double *)malloc(sizeof(double)*NK_EMU);
149  double ybyz[rs];
150  double logc;
151  double xstarstd[p];
152  int zmatch;
153  gsl_spline *zinterp = gsl_spline_alloc(gsl_interp_cspline, rs);
154  gsl_interp_accel *accel = gsl_interp_accel_alloc();
155 
156 
157  // Initialize if necessary
158  if(inited==0) {
159  emuInit();
160  inited = 1;
161  }
162 
163  // Transform w_a into (-w_0-w_a)^(1/4)
164  xstar[6] = pow(-xstar[5]-xstar[6], 0.25);
165  // Check the inputs to make sure we're interpolating.
166  for(i=0; i<p; i++) {
167  if((xstar[i] < xmin[i]) || (xstar[i] > xmax[i])) {
168  switch(i) {
169  case 0:
171  "ccl_pkemu(): omega_m must be between %f and %f.\n",
172  xmin[i], xmax[i]);
173  break;
174  case 1:
176  "ccl_pkemu(): omega_b must be between %f and %f.\n",
177  xmin[i], xmax[i]);
178  break;
179  case 2:
181  "ccl_pkemu(): sigma8 must be between %f and %f.\n",
182  xmin[i], xmax[i]);
183  break;
184  case 3:
186  "ccl_pkemu(): h must be between %f and %f.\n",
187  xmin[i], xmax[i]);
188  break;
189  case 4:
191  "ccl_pkemu(): n_s must be between %f and %f.\n",
192  xmin[i], xmax[i]);
193  break;
194  case 5:
196  "ccl_pkemu(): w_0 must be between %f and %f.\n",
197  xmin[i], xmax[i]);
198  break;
199  case 6:
201  "ccl_pkemu(): (-w_0-w_a)^(1/4) must be between %f and %f.\n",
202  xmin[i], xmax[i]);
203  break;
204  case 7:
206  "ccl_pkemu(): omega_nu must be between %f and %f.\n",
207  xmin[i], xmax[i]);
208  break;
209  }
210  *status = CCL_ERROR_EMULATOR_BOUND;
211  ccl_raise_exception(*status, cosmo->status_message);
212  gsl_spline_free(zinterp);
213  gsl_interp_accel_free(accel);
214  return;
215  }
216  } // for(i=0; i<p; i++)
217  if((xstar[p] < z[0]) || (xstar[p] > z[rs-1])) {
219  "ccl_pkemu(): z must be between %f and %f.\n",
220  z[0], z[rs-1]);
221  *status = CCL_ERROR_EMULATOR_BOUND;
222  ccl_raise_exception(*status, cosmo->status_message);
223  gsl_spline_free(zinterp);
224  gsl_interp_accel_free(accel);
225  return;
226  }
227 
228  // Standardize the inputs
229  for(i=0; i<p; i++) {
230  xstarstd[i] = (xstar[i] - xmin[i]) / xrange[i];
231  }
232 
233  // compute the covariances between the new input and sims for all the PCs.
234  for(ee=0; ee<2; ee++) {
235  for(i=0; i<peta[ee]; i++) {
236  for(j=0; j<m[ee]; j++) {
237  logc = 0.0;
238  for(k=0; k<p; k++) {
239  logc -= beta[ee][i][k]*pow(x[j][k] - xstarstd[k], 2.0);
240  }
241  Sigmastar[ee][i][j] = exp(logc) / lamz[ee][i];
242  }
243  }
244  }
245 
246  // Compute wstar for the first chunk.
247  for(i=0; i<peta[0]; i++) {
248  wstar[i]=0.0;
249  for(j=0; j<m[0]; j++) {
250  wstar[i] += Sigmastar[0][i][j] * KrigBasis[0][i][j];
251  }
252  }
253  // Compute wstar for the second chunk.
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];
258  }
259  }
260 
261  /*
262  for(i=0; i<peta[0]+peta[1]; i++) {
263  printf("%f\n", wstar[i]);
264  }
265  */
266 
267  // Compute ystar, the new output
268  for(i=0; i<neta; i++) {
269  ystaremu[i] = 0.0;
270  for(j=0; j<peta[0]+peta[1]; j++) {
271  ystaremu[i] += K[i][j]*wstar[j];
272  }
273  ystaremu[i] = ystaremu[i]*sd + mean[i];
274 
275  // Convert to P(k)
276  //ystaremu[i] = ystaremu[i] - 1.5*log10(mode[i % NK_EMU]);
277  //ystaremu[i] = 2*M_PI*M_PI*pow(10, ystaremu[i]);
278  }
279 
280 
281 
282  // Interpolate to the desired redshift
283  // Natural cubic spline interpolation over z.
284 
285  // First check to see if the requested z is one of the training z.
286  zmatch = -1;
287  for(i=0; i<rs; i++) {
288  if(xstar[p] == z[i]) {
289  zmatch = rs-i-1;
290  }
291  }
292 
293  // z doesn't match a training z, interpolate
294  if(zmatch == -1) {
295  for(i=0; i<NK_EMU; i++) {
296  for(j=0; j<rs; j++) {
297  ybyz[rs-j-1] = ystaremu[j*NK_EMU+i];
298  }
299  gsl_spline_init(zinterp, z, ybyz, rs);
300  (*ystar)[i] = gsl_spline_eval(zinterp, xstar[p], accel);
301  gsl_interp_accel_reset(accel);
302  }
303 
304  } else { //otherwise, copy in the emulated z without interpolating
305  for(i=0; i<NK_EMU; i++) {
306  (*ystar)[i] = ystaremu[zmatch*NK_EMU + i];
307  }
308  }
309 
310  gsl_spline_free(zinterp);
311  gsl_interp_accel_free(accel);
312 
313  // Convert to P(k)
314  for(i=0; i<NK_EMU; i++) {
315  (*ystar)[i] = (*ystar)[i] - 1.5*log10(mode[i]) + log10(2) + 2*log10(M_PI);
316  (*ystar)[i] = pow(10, (*ystar)[i]);
317  }
318 }
static double sd
static int rs
Definition: ccl_emu17.c:25
#define NK_EMU
Definition: ccl_emu17.h:7
static double KrigBasis[2][28][111]
Definition: ccl_emu17.c:29
static double lamz[2][28]
Definition: ccl_emu17.c:35
#define M_PI
Definition: ccl_constants.h:22
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
static double beta[2][28][8]
Definition: ccl_emu17.c:32
static CCL_BEGIN_DECLS double x[111][8]
static int peta[2]
Definition: ccl_emu17.c:25
#define CCL_ERROR_EMULATOR_BOUND
Definition: ccl_error.h:23
static int neta
Definition: ccl_emu17.c:25
static double z[8]
static void emuInit()
Definition: ccl_emu17.c:38
static int p
Definition: ccl_emu17.c:25
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
static int m[2]
Definition: ccl_emu17.c:25
static double mode[351]
void ccl_raise_exception(int err, const char *msg,...)
Definition: ccl_error.c:35
static double K[2808][35]
static double mean[2808]
static double xrange[8]
static double xmax[8]
char status_message[500]
Definition: ccl_core.h:136
static double xmin[8]