CLASS MANUAL
input.h
Go to the documentation of this file.
1 
3 #ifndef __INPUT__
4 #define __INPUT__
5 
6 #include "common.h"
7 #include "parser.h"
8 
9 #define _N_FILEROOT_ 100 /* Number of files that will be not overwritten for a given root */
10 
11 /* macro for reading parameter values with routines from the parser */
12 
13 #define class_read_double(name,destination) \
14  do { \
15  double param_temp; int flag_temp; \
16  class_call(parser_read_double(pfc,name,&param_temp,&flag_temp,errmsg), \
17  errmsg, \
18  errmsg); \
19  if (flag_temp == _TRUE_){ \
20  destination = param_temp; \
21  } \
22  } while(0);
23 
24 
25 #define class_read_int(name,destination) \
26  do { \
27  int int_temp,flag_temp; \
28  class_call(parser_read_int(pfc,name,&int_temp,&flag_temp,errmsg), \
29  errmsg, \
30  errmsg); \
31  if (flag_temp == _TRUE_){ \
32  destination = int_temp; \
33  } \
34  } while(0);
35 
36 #define class_read_string(name,destination) \
37  do { \
38  char string_temp[_ARGUMENT_LENGTH_MAX_]; int flag_temp; \
39  class_call(parser_read_string(pfc,name,&string_temp,&flag_temp,errmsg), \
40  errmsg, \
41  errmsg); \
42  if (flag_temp == _TRUE_){ \
43  strcpy(destination,string_temp); \
44  } \
45  } while(0);
46 
47 #define class_read_flag(name,destination) \
48  do { \
49  char string_temp[_ARGUMENT_LENGTH_MAX_]; int flag_temp; \
50  class_call(parser_read_string(pfc,name,&string_temp,&flag_temp,errmsg), \
51  errmsg, \
52  errmsg); \
53  if (flag_temp == _TRUE_){ \
54  if (string_begins_with(string_temp,'y') \
55  || string_begins_with(string_temp,'Y') ){ \
56  destination = _TRUE_; \
57  } \
58  else if (string_begins_with(string_temp,'n') \
59  || string_begins_with(string_temp,'N') ){ \
60  destination = _FALSE_; \
61  } \
62  else { \
63  class_stop(errmsg,"incomprehensible input '%s' for the field '%s'.", \
64  string_temp, name); \
65  } \
66  } \
67  } while(0);
68 
69 #define class_read_flag_or_deprecated(name,oldname,destination) \
70  do { \
71  char string_temp[_ARGUMENT_LENGTH_MAX_]; int flag_temp; \
72  class_call(parser_read_string(pfc,name,&string_temp,&flag_temp,errmsg), \
73  errmsg, \
74  errmsg); \
75  /* Compatibility code BEGIN */ \
76  if (flag_temp == _FALSE_){ \
77  class_call(parser_read_string(pfc,oldname,&string_temp,&flag_temp,errmsg),\
78  errmsg, \
79  errmsg); \
80  } \
81  /* Compatibility code END */ \
82  if (flag_temp == _TRUE_){ \
83  if (string_begins_with(string_temp,'y') \
84  || string_begins_with(string_temp,'Y') ){ \
85  destination = _TRUE_; \
86  } \
87  else if (string_begins_with(string_temp,'n') \
88  || string_begins_with(string_temp,'N') ){ \
89  destination = _FALSE_; \
90  } \
91  else { \
92  class_stop(errmsg,"incomprehensible input '%s' for the field '%s'.", \
93  string_temp, name); \
94  } \
95  } \
96  } while(0);
97 
98 #define class_read_double_one_of_two(name1,name2,destination) \
99  do { \
100  int flag_temp1,flag_temp2; \
101  double param_temp1,param_temp2; \
102  class_call(parser_read_double(pfc,name1,&param_temp1,&flag_temp1,errmsg), \
103  errmsg, \
104  errmsg); \
105  class_call(parser_read_double(pfc,name2,&param_temp2,&flag_temp2,errmsg), \
106  errmsg, \
107  errmsg); \
108  class_test((flag_temp1 == _TRUE_) && (flag_temp2 == _TRUE_), \
109  errmsg, \
110  "You can only enter one of '%s' or '%s'.", \
111  name1,name2); \
112  if (flag_temp1 == _TRUE_){ \
113  destination = param_temp1; \
114  } \
115  if (flag_temp2 == _TRUE_){ \
116  destination = param_temp2; \
117  } \
118  } while(0);
119 
120 #define class_at_least_two_of_three(a,b,c) \
121  (((a) == _TRUE_) && ((b) == _TRUE_)) || \
122  (((a) == _TRUE_) && ((c) == _TRUE_)) || \
123  (((b) == _TRUE_) && ((c) == _TRUE_))
124 
125 #define class_none_of_three(a,b,c) \
126  ((a) == _FALSE_) && ((b) == _FALSE_) && ((c) == _FALSE_)
127 
128 #define class_read_list_of_doubles_or_default(name,destination,val_default,siz) \
129  do { \
130  int flag_temp,entries_read_temp; \
131  class_call(parser_read_list_of_doubles(pfc,name, \
132  &entries_read_temp, \
133  &(destination), \
134  &flag_temp, \
135  errmsg), \
136  errmsg, \
137  errmsg); \
138  if (flag_temp == _TRUE_){ \
139  class_test(entries_read_temp != siz, errmsg, \
140  "Number of entries of '%s' (%d) does not match expected number (%d).", \
141  name, entries_read_temp, siz); \
142  }else{ \
143  class_alloc(destination,siz*sizeof(double),errmsg); \
144  for (n=0; n<siz; n++){destination[n] = val_default;} \
145  } \
146  } while(0);
147 
148 #define class_read_list_of_integers_or_default(name,destination,val_default,siz)\
149  do { \
150  int flag_temp,entries_read_temp; \
151  class_call(parser_read_list_of_integers(pfc,name, \
152  &entries_read_temp, \
153  &(destination), \
154  &flag_temp, \
155  errmsg), \
156  errmsg, \
157  errmsg); \
158  if (flag_temp == _TRUE_){ \
159  class_test(entries_read_temp != siz, errmsg, \
160  "Number of entries of '%s' (%d) does not match expected number (%d).", \
161  name, entries_read_temp, siz); \
162  }else{ \
163  class_alloc(destination,siz*sizeof(int),errmsg); \
164  for (n=0; n<siz; n++){destination[n] = val_default;} \
165  } \
166  } while(0);
167 
168 #define class_read_list_of_doubles(name,destination,siz) \
169  do { \
170  int flag_temp,entries_read_temp; \
171  class_call(parser_read_list_of_doubles(pfc,name, \
172  &entries_read_temp, \
173  &(destination), \
174  &flag_temp, \
175  errmsg), \
176  errmsg, \
177  errmsg); \
178  class_test(flag_temp == _FALSE_, errmsg, \
179  "Entry '%s' is required but not found!", name) \
180  class_test(entries_read_temp != siz, errmsg, \
181  "Number of entries of '%s' (%d) does not match expected number (%d).", \
182  name,entries_read_temp, siz); \
183  } while(0);
184 
185 #define class_read_list_of_integers(name,destination,siz) \
186  do { \
187  int flag_temp,entries_read_temp; \
188  class_call(parser_read_list_of_integers(pfc,name, \
189  &entries_read_temp, \
190  &(destination), \
191  &flag_temp, \
192  errmsg), \
193  errmsg, \
194  errmsg); \
195  class_test(flag_temp == _FALSE_, errmsg, \
196  "Entry '%s' is required but not found!", name) \
197  class_test(entries_read_temp != siz, errmsg, \
198  "Number of entries of '%s' (%d) does not match expected number (%d).", \
199  name,entries_read_temp, siz); \
200  } while(0);
201 
206 enum target_names {theta_s, theta_s_100, Neff, Omega_dcdmdr, omega_dcdmdr, Omega_scf, Omega_ini_dcdm, omega_ini_dcdm, sigma8, S8};
207 /* Important: Keep this number equal to the number of target_names (except sigma8, S8), and keep sigma8, S8 at the very end */
208 #define _NUM_TARGETS_ 8
209 
210 /* Until which class stage is being computed? Pretty much fixed list, don't change. */
211 enum computation_stage {cs_background, cs_thermodynamics, cs_perturbations, cs_primordial, cs_nonlinear, cs_transfer, cs_spectra};
212 
218  int * unknown_parameters_index;
219  struct file_content fc;
220  enum target_names * target_name;
221  double * target_value;
222  int target_size;
223  enum computation_stage required_computation_stage;
224 };
225 
226 /**************************************************************/
227 /* @cond INCLUDE_WITH_DOXYGEN */
228 /*
229  * Boilerplate for C++
230  */
231 #ifdef __cplusplus
232 extern "C" {
233 #endif
234 
235  /* Main functions */
236 
237  int input_init(int argc,
238  char **argv,
239  struct precision * ppr,
240  struct background * pba,
241  struct thermodynamics * pth,
242  struct perturbations * ppt,
243  struct transfer * ptr,
244  struct primordial * ppm,
245  struct harmonic * phr,
246  struct fourier * pfo,
247  struct lensing *ple,
248  struct distortions *psd,
249  struct output *pop,
250  ErrorMsg errmsg);
251 
252  /* Note that the input module does not require an input_free() */
253 
254  int input_find_file(int argc,
255  char ** argv,
256  struct file_content * fc,
257  ErrorMsg errmsg);
258 
259  int input_set_root(char* input_file,
260  struct file_content** ppfc_input,
261  struct file_content* pfc_setroot,
262  ErrorMsg errmsg);
263 
264  int input_read_from_file(struct file_content * pfc,
265  struct precision * ppr,
266  struct background *pba,
267  struct thermodynamics *pth,
268  struct perturbations *ppt,
269  struct transfer *ptr,
270  struct primordial *ppm,
271  struct harmonic *phr,
272  struct fourier *pfo,
273  struct lensing *ple,
274  struct distortions *psd,
275  struct output *pop,
276  ErrorMsg errmsg);
277 
278  /* Functions related to shooting */
279 
280  int input_shooting(struct file_content * pfc,
281  struct precision * ppr,
282  struct background * pba,
283  struct thermodynamics * pth,
284  struct perturbations * ppt,
285  struct transfer * ptr,
286  struct primordial * ppm,
287  struct harmonic * phr,
288  struct fourier * pfo,
289  struct lensing *ple,
290  struct distortions *psd,
291  struct output *pop,
292  int input_verbose,
293  int * has_shooting,
294  ErrorMsg errmsg);
295 
296  int input_needs_shooting_for_target(struct file_content * pfc,
297  enum target_names target_name,
298  double target_value,
299  int * aux_flag,
300  ErrorMsg errmsg);
301 
302  int input_find_root(double * xzero,
303  int * fevals,
304  double tol_x_rel,
305  struct fzerofun_workspace * pfzw,
306  ErrorMsg errmsg);
307 
308  int input_fzerofun_1d(double input,
309  void * fzerofun_workspace,
310  double * output,
311  ErrorMsg error_message);
312 
313  int input_fzero_ridder(int (*func)(double x,
314  void * param,
315  double * y,
316  ErrorMsg error_message),
317  double x1,
318  double x2,
319  double xtol,
320  void * param,
321  double * Fx1,
322  double * Fx2,
323  double * xzero,
324  int * fevals,
325  ErrorMsg error_message);
326 
327  int input_get_guess(double * xguess,
328  double * dxdy,
329  struct fzerofun_workspace * pfzw,
330  ErrorMsg errmsg);
331 
332  int input_try_unknown_parameters(double * unknown_parameter,
333  int unknown_parameters_size,
334  void * pfzw,
335  double * output,
336  ErrorMsg errmsg);
337 
338  /* Read from precision.h */
339 
340  int input_read_precisions(struct file_content * pfc,
341  struct precision * ppr,
342  struct background * pba,
343  struct thermodynamics * pth,
344  struct perturbations * ppt,
345  struct transfer * ptr,
346  struct primordial * ppm,
347  struct harmonic * phr,
348  struct fourier * pfo,
349  struct lensing * ple,
350  struct distortions *psd,
351  struct output * pop,
352  ErrorMsg errmsg);
353 
354  /* Read from .ini file */
355 
356  int input_read_parameters(struct file_content * pfc,
357  struct precision * ppr,
358  struct background * pba,
359  struct thermodynamics * pth,
360  struct perturbations * ppt,
361  struct transfer * ptr,
362  struct primordial * ppm,
363  struct harmonic * phr,
364  struct fourier * pfo,
365  struct lensing * ple,
366  struct distortions *psd,
367  struct output * pop,
368  ErrorMsg errmsg);
369 
370  int input_read_parameters_general(struct file_content * pfc,
371  struct background * pba,
372  struct thermodynamics * pth,
373  struct perturbations * ppt,
374  struct fourier * pfo,
375  struct distortions * psd,
376  ErrorMsg errmsg);
377 
378  int input_read_parameters_species(struct file_content * pfc,
379  struct precision * ppr,
380  struct background * pba,
381  struct thermodynamics * pth,
382  struct perturbations * ppt,
383  int input_verbose,
384  ErrorMsg errmsg);
385 
386  int input_read_parameters_injection(struct file_content * pfc,
387  struct precision * ppr,
388  struct thermodynamics * pth,
389  ErrorMsg errmsg);
390 
391  int input_read_parameters_nonlinear(struct file_content * pfc,
392  struct precision * ppr,
393  struct background * pba,
394  struct thermodynamics * pth,
395  struct perturbations * ppt,
396  struct fourier * pfo,
397  int input_verbose,
398  ErrorMsg errmsg);
399 
400  int input_prepare_pk_eq(struct precision * ppr,
401  struct background * pba,
402  struct thermodynamics * pth,
403  struct fourier * pfo,
404  int input_verbose,
405  ErrorMsg errmsg);
406 
407  int input_read_parameters_primordial(struct file_content * pfc,
408  struct perturbations * ppt,
409  struct primordial * ppm,
410  ErrorMsg errmsg);
411 
412  int input_read_parameters_spectra(struct file_content * pfc,
413  struct precision * ppr,
414  struct background * pba,
415  struct primordial * ppm,
416  struct perturbations * ppt,
417  struct transfer * ptr,
418  struct harmonic * phr,
419  struct output * pop,
420  ErrorMsg errmsg);
421 
422  int input_read_parameters_lensing(struct file_content * pfc,
423  struct precision * ppr,
424  struct perturbations * ppt,
425  struct transfer * ptr,
426  struct lensing * ple,
427  ErrorMsg errmsg);
428 
429  int input_read_parameters_distortions(struct file_content * pfc,
430  struct precision * ppr,
431  struct distortions * psd,
432  ErrorMsg errmsg);
433 
434  int input_read_parameters_additional(struct file_content * pfc,
435  struct precision * ppr,
436  struct background * pba,
437  struct thermodynamics * pth,
438  ErrorMsg errmsg);
439 
440  int input_read_parameters_output(struct file_content * pfc,
441  struct background * pba,
442  struct thermodynamics * pth,
443  struct perturbations * ppt,
444  struct transfer * ptr,
445  struct primordial * ppm,
446  struct harmonic * phr,
447  struct fourier * pfo,
448  struct lensing *ple,
449  struct distortions *psd,
450  struct output *pop,
451  ErrorMsg errmsg);
452 
453  int input_write_info(struct file_content * pfc,
454  struct output * pop,
455  ErrorMsg errmsg);
456 
457  /* Set default parameters */
458 
459  int input_default_params(struct background *pba,
460  struct thermodynamics *pth,
461  struct perturbations *ppt,
462  struct transfer *ptr,
463  struct primordial *ppm,
464  struct harmonic *phr,
465  struct fourier *pfo,
466  struct lensing *ple,
467  struct distortions *psd,
468  struct output *pop);
469 
470  /* get version number */
471 
472  int class_version( char * version);
473 
474 #ifdef __cplusplus
475 }
476 #endif
477 
478 /**************************************************************/
479 
480 #endif
481 /* @endcond */
Definition: common.h:406
Definition: distortions.h:35
Definition: fourier.h:33
Definition: harmonic.h:17
int input_init(int argc, char **argv, struct precision *ppr, struct background *pba, struct thermodynamics *pth, struct perturbations *ppt, struct transfer *ptr, struct primordial *ppm, struct harmonic *phr, struct fourier *pfo, struct lensing *ple, struct distortions *psd, struct output *pop, ErrorMsg errmsg)
Definition: input.c:48
int input_needs_shooting_for_target(struct file_content *pfc, enum target_names target_name, double target_value, int *needs_shooting, ErrorMsg errmsg)
Definition: input.c:869
int input_shooting(struct file_content *pfc, struct precision *ppr, struct background *pba, struct thermodynamics *pth, struct perturbations *ppt, struct transfer *ptr, struct primordial *ppm, struct harmonic *phr, struct fourier *pfo, struct lensing *ple, struct distortions *psd, struct output *pop, int input_verbose, int *has_shooting, ErrorMsg errmsg)
Definition: input.c:499
int input_read_parameters_additional(struct file_content *pfc, struct precision *ppr, struct background *pba, struct thermodynamics *pth, ErrorMsg errmsg)
Definition: input.c:5311
int input_read_parameters_primordial(struct file_content *pfc, struct perturbations *ppt, struct primordial *ppm, ErrorMsg errmsg)
Definition: input.c:4080
int input_set_root(char *input_file, struct file_content **ppfc_input, struct file_content *pfc_setroot, ErrorMsg errmsg)
Definition: input.c:218
int input_fzero_ridder(int(*func)(double x, void *param, double *y, ErrorMsg error_message), double x1, double x2, double xtol, void *param, double *Fx1, double *Fx2, double *xzero, int *fevals, ErrorMsg error_message)
Definition: input.c:1029
int input_read_parameters_lensing(struct file_content *pfc, struct precision *ppr, struct perturbations *ppt, struct transfer *ptr, struct lensing *ple, ErrorMsg errmsg)
Definition: input.c:5029
int input_write_info(struct file_content *pfc, struct output *pop, ErrorMsg errmsg)
Definition: input.c:5564
int input_read_parameters_species(struct file_content *pfc, struct precision *ppr, struct background *pba, struct thermodynamics *pth, struct perturbations *ppt, int input_verbose, ErrorMsg errmsg)
Definition: input.c:2333
int input_read_parameters_spectra(struct file_content *pfc, struct precision *ppr, struct background *pba, struct primordial *ppm, struct perturbations *ppt, struct transfer *ptr, struct harmonic *phr, struct output *pop, ErrorMsg errmsg)
Definition: input.c:4692
int input_read_parameters_injection(struct file_content *pfc, struct precision *ppr, struct thermodynamics *pth, ErrorMsg errmsg)
Definition: input.c:3376
int input_read_parameters_general(struct file_content *pfc, struct background *pba, struct thermodynamics *pth, struct perturbations *ppt, struct fourier *pfo, struct distortions *psd, ErrorMsg errmsg)
Definition: input.c:1742
int input_get_guess(double *xguess, double *dxdy, struct fzerofun_workspace *pfzw, ErrorMsg errmsg)
Definition: input.c:1138
int input_read_parameters_nonlinear(struct file_content *pfc, struct precision *ppr, struct background *pba, struct thermodynamics *pth, struct perturbations *ppt, struct fourier *pfo, int input_verbose, ErrorMsg errmsg)
Definition: input.c:3661
int input_prepare_pk_eq(struct precision *ppr, struct background *pba, struct thermodynamics *pth, struct fourier *pfo, int input_verbose, ErrorMsg errmsg)
Definition: input.c:3881
int input_read_parameters(struct file_content *pfc, struct precision *ppr, struct background *pba, struct thermodynamics *pth, struct perturbations *ppt, struct transfer *ptr, struct primordial *ppm, struct harmonic *phr, struct fourier *pfo, struct lensing *ple, struct distortions *psd, struct output *pop, ErrorMsg errmsg)
Definition: input.c:1626
int input_find_file(int argc, char **argv, struct file_content *fc, ErrorMsg errmsg)
Definition: input.c:104
int input_read_precisions(struct file_content *pfc, struct precision *ppr, struct background *pba, struct thermodynamics *pth, struct perturbations *ppt, struct transfer *ptr, struct primordial *ppm, struct harmonic *phr, struct fourier *pfo, struct lensing *ple, struct distortions *psd, struct output *pop, ErrorMsg errmsg)
Definition: input.c:1560
int input_read_from_file(struct file_content *pfc, struct precision *ppr, struct background *pba, struct thermodynamics *pth, struct perturbations *ppt, struct transfer *ptr, struct primordial *ppm, struct harmonic *phr, struct fourier *pfo, struct lensing *ple, struct distortions *psd, struct output *pop, ErrorMsg errmsg)
Definition: input.c:382
int input_try_unknown_parameters(double *unknown_parameter, int unknown_parameters_size, void *voidpfzw, double *output, ErrorMsg errmsg)
Definition: input.c:1305
int input_default_params(struct background *pba, struct thermodynamics *pth, struct perturbations *ppt, struct transfer *ptr, struct primordial *ppm, struct harmonic *phr, struct fourier *pfo, struct lensing *ple, struct distortions *psd, struct output *pop)
Definition: input.c:5645
int input_read_parameters_distortions(struct file_content *pfc, struct precision *ppr, struct distortions *psd, ErrorMsg errmsg)
Definition: input.c:5106
int input_find_root(double *xzero, int *fevals, double tol_x_rel, struct fzerofun_workspace *pfzw, ErrorMsg errmsg)
Definition: input.c:910
int input_read_parameters_output(struct file_content *pfc, struct background *pba, struct thermodynamics *pth, struct perturbations *ppt, struct transfer *ptr, struct primordial *ppm, struct harmonic *phr, struct fourier *pfo, struct lensing *ple, struct distortions *psd, struct output *pop, ErrorMsg errmsg)
Definition: input.c:5434
int input_fzerofun_1d(double input, void *pfzw, double *output, ErrorMsg error_message)
Definition: input.c:992
target_names
Definition: input.h:206
Definition: input.h:217
Definition: lensing.h:17
Definition: output.h:23
Definition: perturbations.h:98
Definition: primordial.h:79
Definition: background.h:44
Definition: thermodynamics.h:59
Definition: transfer.h:74