lesgourg / class_public

Public repository of the Cosmic Linear Anisotropy Solving System (master for the most recent version of the standard code; GW_CLASS to include Cosmic Gravitational Wave Background anisotropies; classnet branch for acceleration with neutral networks; ExoCLASS branch for exotic energy injection; class_matter branch for FFTlog)
223 stars 292 forks source link

minor bug when asking for nonlinear spectra #466

Closed emiliobellini closed 2 years ago

emiliobellini commented 2 years ago

Hi all, in the latest version of Class (after 2.9) there is a minor bug with the value of "k_max_for_pk" when you ask for nonlinear spectra.

Basically, whenever the user specify P_k_max_1/Mpc or P_k_max_h/Mpc, this value overwrites the "nonlinear_min_k_max" value.

This is beacuse k_max is first inferred in the input_read_parameters_nonlinear function, and only after that the parameters P_k_max_1/Mpc and P_k_max_h/Mpc are read in input_read_parameters_spectra.

A clean and quick workaround is to replace if (flag1 == TRUE){ ppt->k_max_for_pk=param1*pba->h; } if (flag2 == TRUE){ ppt->k_max_for_pk=param2; }

with if (flag1 == TRUE){ ppt->k_max_for_pk=MAX(ppt->k_max_for_pk,param1*pba->h); } if (flag2 == TRUE){ ppt->k_max_for_pk=MAX(ppt->k_max_for_pk,param2); }

Unless you want to read P_k_max_h/Mpc in input_read_parameters_nonlinear or even in input_read_parameters_general (it could make sense to have there the initial scale factor, together with k_min and k_max, but this depends on you)

Cheers, Emilio

lesgourg commented 2 years ago

Indeed, this was annoying! We also saw it recently, and this will be fixed in the minor release 3.1.2 due this afternoon. Thanks for noticing! Now, the values of ppt->k_max_for_pk and ppr->nonlinear_min_k_max will be kept separate in the code. This allows another change: the function .get_pk_and_k_and_z() will return the P(k) only up to ppt->k_max_for_pk, and not up to the MAX(,) of the previous two numbers. It makes more sense this way. Thanks for noticing!

emiliobellini commented 2 years ago

Fantastic!