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)
218 stars 291 forks source link

Unable to obtain Matter-Power specturm at a redhsift higher than the Recombination #543

Open Amlan1996 opened 10 months ago

Amlan1996 commented 10 months ago

Hi,

I was trying to generate the matter power spectra at different redshifts. In class, it is done by providing the value of z_pk in the '.ini' file. It gives perfect results only up to the recombination redshift, i.e. z ~ 1088. For any redshift higher than this, the class provides an error.

For example, if I want to obtain the matter power spectra around the matter-radiation equality, then by putting z_pk = 3300 and output = mPk,mTk in the '.ini' file, I get the following error after running the class,

Error in perturbations_init 
=>perturbations_init(L:888) :condition (ppt->has_source_delta_m == _TRUE_) is true; 
You requested a very high z_pk=3.300000e+03, higher than z_rec=1.088807e+03. This works very well 
when you ask only transfer functions, e.g. with 'output=mTk' or 'output=mTk,vTk'. But if you need the total 
matter (e.g. with 'mPk', 'dCl', etc.) there is an issue with the calculation of delta_m at very early times. 
By default, delta_m is a gauge-invariant variable (the density fluctuation in comoving gauge) and this quantity is 
hard to get accurately at very early times. The solution is to define delta_m as the density fluctuation in the
current gauge, synchronous or newtonian. For the moment this must be done manually by commenting the line 
'ppw->delta_m += 3. *ppw->pvecback[pba->index_bg_a]*ppw->pvecback[pba->index_bg_H] * ppw->theta_m/k2;' 
in perturbations_sources(). In the future there will be an option for doing it in an easier way.

After checking the error, I tried to get just the transfer function by putting output = mTk in the '.ini' file, which is also sufficient for my work, but I still got the same error as the above.

I also tried to comment out the line in perturbations_sources() from the perturbation.c file, but it still returned the same error as above.

I am still trying to figure out how to solve this problem. Could anyone help me out on this?

muralisaravanan commented 8 months ago

Also having this issue, did you ever find a solution?

brinckmann commented 8 months ago

Hi both,

I had a test ini file that worked as intended with CLASS 2.7, but it appears that in new versions of CLASS asking for mTk sets "ppt->has_density_transfers" to true in input.c line 1810, which sets "ppt->has_source_delta_m" to true in perturbations.c line 1395, which triggers the error in perturbations.c line 889. The change from CLASS 2.7 is that "ppt->has_density_transfers" did not result in "ppt->has_source_delta_m" being set to true in perturbations.c.

I'm not sure why this change was made or if it is necessary. You can try commenting line where "ppt->has_source_delta_m" is set to true (line 1395 in the current public CLASS, 1394 in the recent version I had compiled) and see if does anything wrong then. The ini file runs for me in this case, but I haven't checked or understood if the commented line is actually needed. Even if it doesn't cause problems, don't forget that you have made this change, in case you do something where it's needed.

It might be nice if we could get some sort of official word on or if someone wants to do some investigation into why this line was added, if it is necessary in this context, and what cases might break if it is commented.

Best, Thejs