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 #include "quadrature.h"
9 #include "background.h"
10 #include "thermodynamics.h"
11 #include "perturbations.h"
12 #include "transfer.h"
13 #include "primordial.h"
14 #include "spectra.h"
15 #include "nonlinear.h"
16 #include "lensing.h"
17 #include "output.h"
18 
19 /* macro for reading parameter values with routines from the parser */
20 #define class_read_double(name,destination) \
21  do { \
22  class_call(parser_read_double(pfc,name,&param1,&flag1,errmsg), \
23  errmsg, \
24  errmsg); \
25  if (flag1 == _TRUE_) \
26  destination = param1; \
27  } while(0);
28 
29 
30 #define class_read_int(name,destination) \
31  do { \
32  class_call(parser_read_int(pfc,name,&int1,&flag1,errmsg), \
33  errmsg, \
34  errmsg); \
35  if (flag1 == _TRUE_) \
36  destination = int1; \
37  } while(0);
38 
39 #define class_read_string(name,destination) \
40  do { \
41  class_call(parser_read_string(pfc,name,&string1,&flag1,errmsg), \
42  errmsg, \
43  errmsg); \
44  if (flag1 == _TRUE_) \
45  strcpy(destination,string1); \
46  } while(0);
47 
48 #define class_read_double_one_of_two(name1,name2,destination) \
49  do { \
50  class_call(parser_read_double(pfc,name1,&param1,&flag1,errmsg), \
51  errmsg, \
52  errmsg); \
53  class_call(parser_read_double(pfc,name2,&param2,&flag2,errmsg), \
54  errmsg, \
55  errmsg); \
56  class_test((flag1 == _TRUE_) && (flag2 == _TRUE_), \
57  errmsg, \
58  "In input file, you can only enter one of %s, %s, choose one", \
59  name1,name2); \
60  if (flag1 == _TRUE_) \
61  destination = param1; \
62  if (flag2 == _TRUE_) \
63  destination = param2; \
64  } while(0);
65 
66 #define class_at_least_two_of_three(a,b,c) \
67  ((a == _TRUE_) && (b == _TRUE_)) || \
68  ((a == _TRUE_) && (c == _TRUE_)) || \
69  ((b == _TRUE_) && (c == _TRUE_))
70 
71 #define class_none_of_three(a,b,c) \
72  (a == _FALSE_) && (b == _FALSE_) && (c == _FALSE_)
73 
74 /* macro for reading parameter values with routines from the parser */
75 #define class_read_list_of_doubles_or_default(name,destination,default,siz) \
76  do { \
77  class_call(parser_read_list_of_doubles(pfc,name, \
78  &entries_read,&(destination),&flag1,errmsg), \
79  errmsg, \
80  errmsg); \
81  if (flag1 == _TRUE_){ \
82  class_test(entries_read != siz,errmsg, \
83  "Number of entries in %s, %d, does not match expected number, %d.", \
84  name,entries_read,siz); \
85  }else{ \
86  class_alloc(destination,siz*sizeof(double),errmsg); \
87  for(n=0; n<siz; n++) destination[n] = default; \
88  } \
89  } while(0);
90 
91 #define class_read_list_of_integers_or_default(name,destination,default,siz) \
92  do { \
93  class_call(parser_read_list_of_integers(pfc,name, \
94  &entries_read,&(destination),&flag1,errmsg), \
95  errmsg, \
96  errmsg); \
97  if (flag1 == _TRUE_){ \
98  class_test(entries_read != siz,errmsg, \
99  "Number of entries in %s, %d, does not match expected number, %d.", \
100  name,entries_read,siz); \
101  }else{ \
102  class_alloc(destination,siz*sizeof(int),errmsg); \
103  for(n=0; n<siz; n++) destination[n] = default; \
104  } \
105  } while(0);
106 
107 #define class_read_list_of_doubles(name,destination,siz) \
108  do { \
109  class_call(parser_read_list_of_doubles(pfc,name, \
110  &entries_read,&(destination),&flag1,errmsg), \
111  errmsg, \
112  errmsg); \
113  class_test(flag1 == _FALSE_,errmsg, \
114  "Entry %s is required but not found!",name) \
115  class_test(entries_read != siz,errmsg, \
116  "Number of entries in %s, %d, does not match expected number, %d.", \
117  name,entries_read,siz); \
118  } while(0);
119 
120 #define class_read_list_of_integers(name,destination,siz) \
121  do { \
122  class_call(parser_read_list_of_integers(pfc,name, \
123  &entries_read,&(destination),&flag1,errmsg), \
124  errmsg, \
125  errmsg); \
126  class_test(flag1 == _FALSE_,errmsg, \
127  "Entry %s is required but not found!",name) \
128  class_test(entries_read != siz,errmsg, \
129  "Number of entries in %s, %d, does not match expected number, %d.", \
130  name,entries_read,siz); \
131  } while(0);
132 
137 enum target_names {theta_s, Omega_dcdmdr, omega_dcdmdr, Omega_scf, Omega_ini_dcdm, omega_ini_dcdm};
138 enum computation_stage {cs_background, cs_thermodynamics, cs_perturbations,
139  cs_primordial, cs_nonlinear, cs_transfer, cs_spectra};
140 #define _NUM_TARGETS_ 6 //Keep this number as number of target_names
141 
142 struct input_pprpba {
143  struct precision * ppr;
144  struct background * pba;
145 };
146 
147 struct fzerofun_workspace {
148  int * unknown_parameters_index;
149  struct file_content fc;
150  enum target_names * target_name;
151  double * target_value;
152  int target_size;
153  enum computation_stage required_computation_stage;
154 };
155 
156 
157 /**************************************************************/
158 /* @cond INCLUDE_WITH_DOXYGEN */
159 /*
160  * Boilerplate for C++
161  */
162 #ifdef __cplusplus
163 extern "C" {
164 #endif
165 
167  int argc,
168  char **argv,
169  struct precision * ppr,
170  struct background *pba,
171  struct thermo *pth,
172  struct perturbs *ppt,
173  struct transfers *ptr,
174  struct primordial *ppm,
175  struct spectra *psp,
176  struct nonlinear *pnl,
177  struct lensing *ple,
178  struct output *pop,
179  ErrorMsg errmsg
180  );
181 
182  int input_init(
183  struct file_content * pfc,
184  struct precision * ppr,
185  struct background *pba,
186  struct thermo *pth,
187  struct perturbs *ppt,
188  struct transfers *ptr,
189  struct primordial *ppm,
190  struct spectra *psp,
191  struct nonlinear *pnl,
192  struct lensing *ple,
193  struct output *pop,
194  ErrorMsg errmsg
195  );
196 
198  struct file_content * pfc,
199  struct precision * ppr,
200  struct background *pba,
201  struct thermo *pth,
202  struct perturbs *ppt,
203  struct transfers *ptr,
204  struct primordial *ppm,
205  struct spectra *psp,
206  struct nonlinear *pnl,
207  struct lensing *ple,
208  struct output *pop,
209  ErrorMsg errmsg
210  );
211 
213  struct background *pba,
214  struct thermo *pth,
215  struct perturbs *ppt,
216  struct transfers *ptr,
217  struct primordial *ppm,
218  struct spectra *psp,
219  struct nonlinear *pnl,
220  struct lensing *ple,
221  struct output *pop
222  );
223 
225  struct precision * ppp
226  );
227 
228  int get_machine_precision(double * smallest_allowed_variation);
229 
230  int class_fzero_ridder(int (*func)(double x, void *param, double *y, ErrorMsg error_message),
231  double x1,
232  double x2,
233  double xtol,
234  void *param,
235  double *Fx1,
236  double *Fx2,
237  double *xzero,
238  int *fevals,
239  ErrorMsg error_message);
240 
241  int input_fzerofun_for_background(double Omega_ini_dcdm,
242  void* container,
243  double *valout,
244  ErrorMsg error_message);
245 
246  int input_try_unknown_parameters(double * unknown_parameter,
247  int unknown_parameters_size,
248  void * pfzw,
249  double * output,
250  ErrorMsg errmsg);
251 
252  int input_fzerofun_1d(double input,
253  void* fzerofun_workspace,
254  double *output,
255  ErrorMsg error_message);
256 
257  int input_get_guess(double *xguess,
258  double *dxdy,
259  struct fzerofun_workspace * pfzw,
260  ErrorMsg errmsg);
261 
262  int input_find_root(double *xzero,
263  int *fevals,
264  struct fzerofun_workspace *pfzw,
265  ErrorMsg errmsg);
266 
267  int file_exists(const char *fname);
268 
269  int input_auxillary_target_conditions(struct file_content * pfc,
270  enum target_names target_name,
271  double target_value,
272  int * aux_flag,
273  ErrorMsg error_message);
274 
275  int compare_integers (const void * elem1, const void * elem2);
276 
277  int compare_doubles(const void *a,const void *b);
278 
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 
284 /**************************************************************/
285 
286 #endif
287 /* @endcond */
Definition: background.h:25
int class_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:3394
Definition: lensing.h:17
Definition: spectra.h:17
Definition: nonlinear.h:20
Definition: perturbations.h:95
int input_init_from_arguments(int argc, char **argv, struct precision *ppr, struct background *pba, struct thermo *pth, struct perturbs *ppt, struct transfers *ptr, struct primordial *ppm, struct spectra *psp, struct nonlinear *pnl, struct lensing *ple, struct output *pop, ErrorMsg errmsg)
Definition: input.c:17
Definition: thermodynamics.h:57
int input_read_parameters(struct file_content *pfc, struct precision *ppr, struct background *pba, struct thermo *pth, struct perturbs *ppt, struct transfers *ptr, struct primordial *ppm, struct spectra *psp, struct nonlinear *pnl, struct lensing *ple, struct output *pop, ErrorMsg errmsg)
Definition: input.c:497
int input_default_params(struct background *pba, struct thermo *pth, struct perturbs *ppt, struct transfers *ptr, struct primordial *ppm, struct spectra *psp, struct nonlinear *pnl, struct lensing *ple, struct output *pop)
Definition: input.c:2765
target_names
Definition: input.h:137
int input_find_root(double *xzero, int *fevals, struct fzerofun_workspace *pfzw, ErrorMsg errmsg)
Definition: input.c:3802
int input_get_guess(double *xguess, double *dxdy, struct fzerofun_workspace *pfzw, ErrorMsg errmsg)
Definition: input.c:3660
Definition: output.h:22
int input_default_precision(struct precision *ppr)
Definition: input.c:3091
Definition: transfer.h:38
int get_machine_precision(double *smallest_allowed_variation)
Definition: input.c:3361
int input_try_unknown_parameters(double *unknown_parameter, int unknown_parameters_size, void *voidpfzw, double *output, ErrorMsg errmsg)
Definition: input.c:3479
Definition: common.h:345
Definition: primordial.h:79
int input_init(struct file_content *pfc, struct precision *ppr, struct background *pba, struct thermo *pth, struct perturbs *ppt, struct transfers *ptr, struct primordial *ppm, struct spectra *psp, struct nonlinear *pnl, struct lensing *ple, struct output *pop, ErrorMsg errmsg)
Definition: input.c:194