CAMB: adding a new fluid

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Arian Esmaieli
Posts: 2
Joined: August 18 2024
Affiliation: Shahid Beheshti University

CAMB: adding a new fluid

Post by Arian Esmaieli »

Hi everyone,

I'm trying to modify CAMB 1.5.6 and add a new fluid to the code, which has a specific equation of state and Omega. I think I handled the Fortran part correctly (but I could be wrong). My problem is with the Python interface. I'm not exactly sure where to make the changes. I've made some modifications to camb.py (line 245) and model.py (lines 197, 430, 502), but when I try to run the code, I have to include my new Omega (I also can't give it a zero value or anything below 0.001) in the .set_cosmology(), or it gives me this error:

Code: Select all

CAMBError                                 Traceback (most recent call last)
Cell In[1], line 12
      9 pars.InitPower.set_params(As=2e-9, ns=0.965)
     11 # Calculate results
---> 12 results = camb.get_results(pars)
     14 # Get the power spectra
     15 powers = results.get_cmb_power_spectra(pars)

File ~/anaconda3/lib/python3.10/site-packages/camb-1.5.6-py3.10-linux-x86_64.egg/camb/camb.py:37, in get_results(params)
     35 if _debug_params:
     36     print(params)
---> 37 res.calc_power_spectra(params)
     38 return res

File ~/anaconda3/lib/python3.10/site-packages/camb-1.5.6-py3.10-linux-x86_64.egg/camb/results.py:336, in CAMBdata.calc_power_spectra(self, params)
    329 """
    330 Calculates transfer functions and power spectra.
    331 
    332 :param params: optional :class:`~.model.CAMBparams` instance with parameters to use
    333 
    334 """
    335 if params is not None:
--> 336     self.calc_transfers(params, only_transfers=False)
    337 else:
    338     self._check_powers()

File ~/anaconda3/lib/python3.10/site-packages/camb-1.5.6-py3.10-linux-x86_64.egg/camb/results.py:318, in CAMBdata.calc_transfers(self, params, only_transfers, only_time_sources)
    315     self._check_powers(params)
    316 if CAMBdata_gettransfers(byref(self), byref(params), byref(c_int(1 if only_transfers else 0)),
    317                          byref(c_int(1 if only_time_sources else 0))):
--> 318     config.check_global_error('calc_transfer')

File ~/anaconda3/lib/python3.10/site-packages/camb-1.5.6-py3.10-linux-x86_64.egg/camb/_config.py:51, in _config.check_global_error(self, reference)
     49     reference = ''
     50 if err:
---> 51     raise CAMBError(reference + '%s' % err)
     52 else:
     53     raise CAMBError(reference + 'Error code: %s' % code)

CAMBError: Error in Fortran called from calc_transfer:
ThemoData Init: failed to find end of recombination
Additionally, the plots I'm getting do not match the plots I got from the Fortran code. Am I missing something here?

Thank you.
Antony Lewis
Posts: 1983
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: CAMB: adding a new fluid

Post by Antony Lewis »

Depends what you changed/how you implemented it in fortran (e.g. whether making new DarkEnergy subclass, or main equation editing etc). Might help to point to a github code diff.
Arian Esmaieli
Posts: 2
Joined: August 18 2024
Affiliation: Shahid Beheshti University

Re: CAMB: adding a new fluid

Post by Arian Esmaieli »

Thank you for your quick response.

I simply modified the Friedmann equation and other necessary physical equations in equation.f90, and changed one or two lines in camb.f90 and results.f90 so that it would recognize the new fluid's omega and print it out when I run CAMB. The changes were minimal.
Post Reply