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, Omega_dcdmdr, omega_dcdmdr, Omega_scf, Omega_ini_dcdm, omega_ini_dcdm, sigma8};
207 /* Important: Keep this number equal to the number of target_names (except sigma8), and keep sigma8 at the very end */
208 #define _NUM_TARGETS_ 6
209 /* Important: add one for each new target_names */
210 enum computation_stage {cs_background, cs_thermodynamics, cs_perturbations, cs_primordial, cs_nonlinear, cs_transfer, cs_spectra};
211 
217  int * unknown_parameters_index;
218  struct file_content fc;
219  enum target_names * target_name;
220  double * target_value;
221  int target_size;
222  enum computation_stage required_computation_stage;
223 };
224 
225 /**************************************************************/
226 /* @cond INCLUDE_WITH_DOXYGEN */
227 /*
228  * Boilerplate for C++
229  */
230 #ifdef __cplusplus
231 extern "C" {
232 #endif
233 
234  /* Main functions */
235 
236  int input_init(int argc,
237  char **argv,
238  struct precision * ppr,
239  struct background * pba,
240  struct thermodynamics * pth,
241  struct perturbations * ppt,
242  struct transfer * ptr,
243  struct primordial * ppm,
244  struct harmonic * phr,
245  struct fourier * pfo,
246  struct lensing *ple,
247  struct distortions *psd,
248  struct output *pop,
249  ErrorMsg errmsg);
250 
251  /* Note that the input module does not require an input_free() */
252 
253  int input_find_file(int argc,
254  char ** argv,
255  struct file_content * fc,
256  ErrorMsg errmsg);
257 
258  int input_set_root(char* input_file,
259  struct file_content** ppfc_input,
260  struct file_content* pfc_setroot,
261  ErrorMsg errmsg);
262 
263  int input_read_from_file(struct file_content * pfc,
264  struct precision * ppr,
265  struct background *pba,
266  struct thermodynamics *pth,
267  struct perturbations *ppt,
268  struct transfer *ptr,
269  struct primordial *ppm,
270  struct harmonic *phr,
271  struct fourier *pfo,
272  struct lensing *ple,
273  struct distortions *psd,
274  struct output *pop,
275  ErrorMsg errmsg);
276 
277  /* Functions related to shooting */
278 
279  int input_shooting(struct file_content * pfc,
280  struct precision * ppr,
281  struct background * pba,
282  struct thermodynamics * pth,
283  struct perturbations * ppt,
284  struct transfer * ptr,
285  struct primordial * ppm,
286  struct harmonic * phr,
287  struct fourier * pfo,
288  struct lensing *ple,
289  struct distortions *psd,
290  struct output *pop,
291  int input_verbose,
292  int * has_shooting,
293  ErrorMsg errmsg);
294 
295  int input_needs_shooting_for_target(struct file_content * pfc,
296  enum target_names target_name,
297  double target_value,
298  int * aux_flag,
299  ErrorMsg errmsg);
300 
301  int input_find_root(double * xzero,
302  int * fevals,
303  double tol_x_rel,
304  struct fzerofun_workspace * pfzw,
305  ErrorMsg errmsg);
306 
307  int input_fzerofun_1d(double input,
308  void * fzerofun_workspace,
309  double * output,
310  ErrorMsg error_message);
311 
312  int input_fzero_ridder(int (*func)(double x,
313  void * param,
314  double * y,
315  ErrorMsg error_message),
316  double x1,
317  double x2,
318  double xtol,
319  void * param,
320  double * Fx1,
321  double * Fx2,
322  double * xzero,
323  int * fevals,
324  ErrorMsg error_message);
325 
326  int input_get_guess(double * xguess,
327  double * dxdy,
328  struct fzerofun_workspace * pfzw,
329  ErrorMsg errmsg);
330 
331  int input_try_unknown_parameters(double * unknown_parameter,
332  int unknown_parameters_size,
333  void * pfzw,
334  double * output,
335  ErrorMsg errmsg);
336 
337  /* Read from precision.h */
338 
339  int input_read_precisions(struct file_content * pfc,
340  struct precision * ppr,
341  struct background * pba,
342  struct thermodynamics * pth,
343  struct perturbations * ppt,
344  struct transfer * ptr,
345  struct primordial * ppm,
346  struct harmonic * phr,
347  struct fourier * pfo,
348  struct lensing * ple,
349  struct distortions *psd,
350  struct output * pop,
351  ErrorMsg errmsg);
352 
353  /* Read from .ini file */
354 
355  int input_read_parameters(struct file_content * pfc,
356  struct precision * ppr,
357  struct background * pba,
358  struct thermodynamics * pth,
359  struct perturbations * ppt,
360  struct transfer * ptr,
361  struct primordial * ppm,
362  struct harmonic * phr,
363  struct fourier * pfo,
364  struct lensing * ple,
365  struct distortions *psd,
366  struct output * pop,
367  ErrorMsg errmsg);
368 
369  int input_read_parameters_general(struct file_content * pfc,
370  struct background * pba,
371  struct thermodynamics * pth,
372  struct perturbations * ppt,
373  struct distortions * psd,
374  ErrorMsg errmsg);
375 
376  int input_read_parameters_species(struct file_content * pfc,
377  struct precision * ppr,
378  struct background * pba,
379  struct thermodynamics * pth,
380  struct perturbations * ppt,
381  int input_verbose,
382  ErrorMsg errmsg);
383 
384  int input_read_parameters_injection(struct file_content * pfc,
385  struct precision * ppr,
386  struct thermodynamics * pth,
387  ErrorMsg errmsg);
388 
389  int input_read_parameters_nonlinear(struct file_content * pfc,
390  struct precision * ppr,
391  struct background * pba,
392  struct thermodynamics * pth,
393  struct perturbations * ppt,
394  struct fourier * pfo,
395  int input_verbose,
396  ErrorMsg errmsg);
397 
398  int input_prepare_pk_eq(struct precision * ppr,
399  struct background * pba,
400  struct thermodynamics * pth,
401  struct fourier * pfo,
402  int input_verbose,
403  ErrorMsg errmsg);
404 
405  int input_read_parameters_primordial(struct file_content * pfc,
406  struct perturbations * ppt,
407  struct primordial * ppm,
408  ErrorMsg errmsg);
409 
410  int input_read_parameters_spectra(struct file_content * pfc,
411  struct precision * ppr,
412  struct background * pba,
413  struct primordial * ppm,
414  struct perturbations * ppt,
415  struct transfer * ptr,
416  struct harmonic * phr,
417  struct output * pop,
418  ErrorMsg errmsg);
419 
420  int input_read_parameters_lensing(struct file_content * pfc,
421  struct precision * ppr,
422  struct perturbations * ppt,
423  struct transfer * ptr,
424  struct lensing * ple,
425  ErrorMsg errmsg);
426 
427  int input_read_parameters_distortions(struct file_content * pfc,
428  struct precision * ppr,
429  struct distortions * psd,
430  ErrorMsg errmsg);
431 
432  int input_read_parameters_additional(struct file_content * pfc,
433  struct precision * ppr,
434  struct background * pba,
435  struct thermodynamics * pth,
436  ErrorMsg errmsg);
437 
438  int input_read_parameters_output(struct file_content * pfc,
439  struct background * pba,
440  struct thermodynamics * pth,
441  struct perturbations * ppt,
442  struct transfer * ptr,
443  struct primordial * ppm,
444  struct harmonic * phr,
445  struct fourier * pfo,
446  struct lensing *ple,
447  struct distortions *psd,
448  struct output *pop,
449  ErrorMsg errmsg);
450 
451  int input_write_info(struct file_content * pfc,
452  struct output * pop,
453  ErrorMsg errmsg);
454 
455  /* Set default parameters */
456 
457  int input_default_params(struct background *pba,
458  struct thermodynamics *pth,
459  struct perturbations *ppt,
460  struct transfer *ptr,
461  struct primordial *ppm,
462  struct harmonic *phr,
463  struct fourier *pfo,
464  struct lensing *ple,
465  struct distortions *psd,
466  struct output *pop);
467 
468  /* get version number */
469 
470  int class_version( char * version);
471 
472 #ifdef __cplusplus
473 }
474 #endif
475 
476 /**************************************************************/
477 
478 #endif
479 /* @endcond */
Definition: background.h:48
Definition: common.h:378
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:492
int input_read_parameters_additional(struct file_content *pfc, struct precision *ppr, struct background *pba, struct thermodynamics *pth, ErrorMsg errmsg)
Definition: input.c:5204
int input_read_parameters_primordial(struct file_content *pfc, struct perturbations *ppt, struct primordial *ppm, ErrorMsg errmsg)
Definition: input.c:3984
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:4926
int input_write_info(struct file_content *pfc, struct output *pop, ErrorMsg errmsg)
Definition: input.c:5457
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:2289
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:4590
int input_read_parameters_injection(struct file_content *pfc, struct precision *ppr, struct thermodynamics *pth, ErrorMsg errmsg)
Definition: input.c:3331
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:3616
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:3785
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:1590
int input_read_parameters_general(struct file_content *pfc, struct background *pba, struct thermodynamics *pth, struct perturbations *ppt, struct distortions *psd, ErrorMsg errmsg)
Definition: input.c:1705
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:1524
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:1285
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:5538
int input_read_parameters_distortions(struct file_content *pfc, struct precision *ppr, struct distortions *psd, ErrorMsg errmsg)
Definition: input.c:4999
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:5327
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:216
Definition: lensing.h:17
Definition: output.h:23
Definition: perturbations.h:98
Definition: primordial.h:79
Definition: thermodynamics.h:59
Definition: transfer.h:76