on how to modify equations.f90 in CAMB (in general)

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Jiwon Park
Posts: 9
Joined: July 09 2019
Affiliation: Soongsil University

on how to modify equations.f90 in CAMB (in general)

Post by Jiwon Park » May 24 2021

Dear all,

I'd like to ask how one should modify equations.f90 file in CAMB to add new features and species in general cases.

when I modify CAMB and add new species, I follow this recipe but it seems that there's a case that I can't get the result that I want.
But I'm not sure these steps are right as I'm using CAMB after a too long time.
So I'd like to check them just in case.
Could you please let me know if there is anything wrong with the steps?

- This is how I modify 'equation.f90' file

1. add new indexes for additional equations in module 'GaugeInterface,' line 43,44 like the following:
(note that all the line number here is based on the original file, not the modified one)

Code: Select all

    integer, parameter :: basic_num_eqns = 6 ! originally 4 ! line 43
    integer, parameter :: ix_etak=1, ix_clxc=2, ix_clxb=3, ix_vb=4, ix_new_one=5, ix_new_two=6 !Scalar array indices for each quantity
    ! ix_new_one and ix_new_two are the new species
2. add initial conditions in 'subroutine initial(EV,y, tau),' like the following;

i) after the line 1769,

Code: Select all

    integer, parameter :: i_clxg=1,i_clxr=2,i_clxc=3, i_clxb=4, &
        i_qg=5,i_qr=6,i_vb=7,i_pir=8, i_eta=9, i_aj3r=10,i_clxde=11,i_vde=12, & ! line 1769
        i_new_one=13, i_new_two=14
ii) and for example, in the adiabatic initial condition, after the line 1856,

Code: Select all

    initv(1,i_eta)=-chi*2*EV%Kf(1)*(1 - x2/12*(-10._dl/Rp15 + EV%Kf(1))) ! line 1856
    initv(1,i_new_one)=(###corresponding IC###)
    initv(1,i_new_two)=(###corresponding IC###)
iii) and after the line 1927,

Code: Select all

    !  Baryons
    y(ix_clxb)=InitVec(i_clxb)
    y(ix_vb)=InitVec(i_vb) !line 1927
    
    ! new species
    y(ix_new_one)=InitVec(i_new_one)
    y(ix_new_two)=InitVec(i_new_two)
3. add corresponding new equations in 'subroutine derivs(EV,n,tau,ay,ayprime),' like the following:

i) first, after the line 2176, add the variables

Code: Select all

    real(dl) dgrho_de, dgq_de, cs2_de ! line 2176
    
    real(dl) new_one, new_two ! new species
    real(dl) new_var ! new variable
    
    new_var=CP%new_var ! read input from inifile
ii) define the variables after the line 2196

Code: Select all

    !  Baryon variables
    clxb=ay(ix_clxb)
    vb=ay(ix_vb) ! line 2196
    
    ! new species
    new_one=ay(ix_new_one)
    new_two=ay(ix_new_two)
    ! first CDM, baryon, and then add new species following the order defined in line 44
iii) add equations after the line after the line 2311

Code: Select all

    !  Baryon equation of motion.
    clxbdot=-k*(z+vb)
    ayprime(ix_clxb)=clxbdot ! line 2311

    ! new species equation
    new_one = (###new equation###)
    new_two = (###new equation###)
    ! first CDM, baryon, and then add new species following the order defined in line 44
(I want to know this equation order is right or not, as different order gives sometimes different things and maybe errors too.
Plus, is this order mandatory in CAMB code?)

iv) add other features you want to add in:
for example,

Code: Select all

    !  8*pi*a*a*SUM[rho_i*clx_i] - radiation terms
    dgrho=dgrho + grhog_t*clxg+grhor_t*clxr + new_one/a ! line 2272

Code: Select all

    !  CDM equation of motion
    clxcdot=-k*z
    ayprime(ix_clxc)=clxcdot - k*new_one/new_two ! line 2307
4. For a final stage, modify other fortran files(like model.f90, camb.f90), python interface, etc. to read new inputs and to conduct other features you want.

(p.s. I note that this question is originally a subquestion of this question(viewtopic.php?f=11&t=3495).
I wrote my post too briefly and I thought I should explain more in detail to provide information to others so that someone may answer my post.
However, it seems to me that this question is worth treating another independent question so that others may refer to this post when modifying CAMB, and hence I write the question as a general one.)

Antony Lewis
Posts: 1936
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: on how to modify equations.f90 in CAMB (in general)

Post by Antony Lewis » May 25 2021

This looks basically OK at a quick look.
If you are using fixed indices in derivs(), they do need to be part of the basic_num_eqns equations at the start of the arrays. Your output derivatives for the new variables are assigned as

Code: Select all

ayprime(ix_new_one) = [xxx]
etc.

Post Reply