Skip to content

Code4:input.c

ardok-m edited this page Jun 28, 2017 · 4 revisions

Code 3: input.c

based on https://lesgourg.github.io/class-tour/Tokyo2014/lecture6_input_module.pdf

The input.c module is incharged of reading the ini and precision files and of setting to its default those not present in them. The functions that store the default values are:

  • input_default_params

  • input_default_precision

To understand how input.c works let's follow the execution path.

1. input_init_from_arguments(argc, argv, ...)

  1. Read the arguments passed to ./class.

  2. Check they are one (and only one) ini-file and at most one precision file.

  3. And, in case root = was not set in the ini-file, choose a defualt one.

  4. It stores the file contents in a single structure file_content, fc. In particular, for a number n, fc.name[n] = "variable_name" and fc.value[n] = the_value_of_the_variable.

  5. Finally, call input_init(&fc, ...)

2. input_init(pfc, ...)

  1. Create three arrays with the name of the parameter to be searched for in the file_content structure, its corresponding associated parameter used by CLASS and the computation stage needed.

  2. Look for them in file_content. If there is none of them, call input_read_parameters; if there is one, run a shooting algorithm:

    1. Call input_get_guess(&x1, &dxdy, pfzw, errmsg) to find our guess for the unknown parameter value.

    2. Call input_fzerofun_1d(x1,pfzw,&f1,errmsg); to evaluate f1 = desired_value - computed_value. In the particular case of using Omega_smg as shooting parameter f = Omega0_smg_desired - Omega0_smg_computed.

    3. Change guessing param so that x2= f*x1*dxdy, with dxdy = dx/dy.

    4. Call input_fzerofun_1d(x2,pfzw,&f2,errmsg);.

    5. If f1*f2'<0 the root has been bracketed and we exit loop. Elsewise, repeat previous two steps untill it fails more than a certain number of times when it will just exit the loop.

    6. Run a bisection method. If the root was not bracketed it will finish the hi_class execution with an error.

    and, if more than one unknown parameters are present, try a Newton method to find the value of the CLASS associated variables.

  3. If shooting worked, call input_read_parameters; else, turn on pba->shooting_failed and wait until background.c to exit hi_class to play nicely with MontePython.

  4. Set pba->parameters_tuned_smg = _TRUE_;.

3. input_read_parameters(pfc, ...)

  1. Initialize all paramters with their default values, calling input_default_params and input_default_precision.

  2. Overwrite the value of the parameters present in the file_content structure, fc, with their stored value.