-
Notifications
You must be signed in to change notification settings - Fork 30
Example3:new model oscillating alphas
In this example we will show you how to introduce a new gravity model. In particular, we will introduce a model with oscillating alphas. The general overview can be found in Introducing new models.
The easiest path to success is just copying what already exists and modify it to your needs. This way, we will start looking for the lines where another gravity model, as propto_omega
, was defined.
From the hi_class root folder:
grep -n propto_omega */*[hc]
(the -n is to display line numbers and [hc] to only look into .c and .h files) which outputs:
include/background.h:14:enum gravity_model {propto_omega, propto_scale, eft_alphas_power_law, eft_gammas_power_law, eft_gammas_exponential}; //write here the different models
source/background.c:2190: case propto_omega:
source/background.c:2536: if (pba->gravity_model_smg == propto_omega) {
source/background.c:2672: case propto_omega:
source/background.c:2673: printf("Modified gravity: propto_omega with parameters: \n");
source/input.c:1031: if (strcmp(string1,"propto_omega") == 0) {
source/input.c:1032: pba->gravity_model_smg = propto_omega;
source/input.c:1079: "could not identify gravity_theory value, check that it is one of 'propto_omega', 'propto_scale', 'eft_alphas_power_law', 'eft_gammas_power_law', 'eft_gammas_exponential' ...");
source/input.c:2764: pba->gravity_model_smg = propto_omega; /* gravitational model */
Let's start from the first file: background.h
. Recall that this file has the declarations used in background. Using our fovourite editor, we go to line 14 and add the name of our new model: oscillating_omega
:
enum gravity_model {propto_omega, propto_scale, eft_alphas_power_law, eft_gammas_power_law, eft_gammas_exponential, oscillating_omega}; //write here the different models
Now, we move forward and open background.c
at line 2190, where we find:
switch (pba->gravity_model_smg) {
case propto_omega:
pvecback_integration[pba->index_bi_M_pl_smg] = pba->parameters_2_smg[4];
break;
case propto_scale:
pvecback_integration[pba->index_bi_M_pl_smg] = pba->parameters_2_smg[4];
break;
case eft_alphas_power_law:
pvecback_integration[pba->index_bi_M_pl_smg] = 1. + pba->parameters_2_smg[0]*pow(a, pba->parameters_2_smg[4]);
break;
case eft_gammas_power_law:
pvecback_integration[pba->index_bi_M_pl_smg] = 1. + pba->parameters_2_smg[0]*pow(a,pba->parameters_2_smg[4]) + pba->parameters_2_smg[3]*pow(a,pba->parameters_2_smg[7]);
break;
case eft_gammas_exponential:
pvecback_integration[pba->index_bi_M_pl_smg] = exp(pba->parameters_2_smg[0]*pow(a,pba->parameters_2_smg[4])) + exp(pba->parameters_2_smg[3]*pow(a,pba->parameters_2_smg[7])) -1.;
break;
}
This block of code set the initial condition for the Planck Mass. As we will only introduce oscillations in the alphas evolution, we copy the propto_omega
block and only modify the case item to adjust it to the new gravity model name:
switch (pba->gravity_model_smg) {
case propto_omega:
pvecback_integration[pba->index_bi_M_pl_smg] = pba->parameters_2_smg[4];
break;
case oscillating_omega:
pvecback_integration[pba->index_bi_M_pl_smg] = pba->parameters_2_smg[4];
break;
case propto_scale:
pvecback_integration[pba->index_bi_M_pl_smg] = pba->parameters_2_smg[4];
break;
case eft_alphas_power_law:
pvecback_integration[pba->index_bi_M_pl_smg] = 1. + pba->parameters_2_smg[0]*pow(a, pba->parameters_2_smg[4]);
break;
case eft_gammas_power_law:
pvecback_integration[pba->index_bi_M_pl_smg] = 1. + pba->parameters_2_smg[0]*pow(a,pba->parameters_2_smg[4]) + pba->parameters_2_smg[3]*pow(a,pba->parameters_2_smg[7]);
break;
case eft_gammas_exponential:
pvecback_integration[pba->index_bi_M_pl_smg] = exp(pba->parameters_2_smg[0]*pow(a,pba->parameters_2_smg[4])) + exp(pba->parameters_2_smg[3]*pow(a,pba->parameters_2_smg[7])) -1.;
break;
}
Note: We have written the new lines just after propto_omega to have all modifications at the same level since next steps would be messier if put the last one.
We move to the next ocurrence of propto_omega
in background.c
:
if (pba->gravity_model_smg == propto_omega) {
double c_k = pba->parameters_2_smg[0];
double c_b = pba->parameters_2_smg[1];
double c_m = pba->parameters_2_smg[2];
double c_t = pba->parameters_2_smg[3];
pvecback[pba->index_bg_kineticity_smg] = c_k*Omega_smg;
pvecback[pba->index_bg_braiding_smg] = c_b*Omega_smg;
pvecback[pba->index_bg_tensor_excess_smg] = c_t*Omega_smg;
pvecback[pba->index_bg_mpl_running_smg] = c_m*Omega_smg;
pvecback[pba->index_bg_M2_smg] = M_pl;
}
We will copy this block and modify it to our needs. We suggest pasting it just below for clarity since the last blocks are bigger and messier. The new block should look something like this:
else if (pba->gravity_model_smg == oscillating_omega) {
double c_k = pba->parameters_2_smg[0];
double c_b = pba->parameters_2_smg[1];
double c_m = pba->parameters_2_smg[2];
double c_t = pba->parameters_2_smg[3];
double freq = pba->parameters_2_smg[5]*pba->H0;
pvecback[pba->index_bg_kineticity_smg] = c_k*Omega_smg*cos(freq*tau);
pvecback[pba->index_bg_braiding_smg] = c_b*Omega_smg*cos(freq*tau);
pvecback[pba->index_bg_tensor_excess_smg] = c_t*Omega_smg*cos(freq*tau);
pvecback[pba->index_bg_mpl_running_smg] = c_m*Omega_smg*cos(freq*tau);
pvecback[pba->index_bg_M2_smg] = M_pl;
}
Note the change from if
to else if
. Since only a gravity_model_smg
will be activated, we only want to check what is the chosen one and, once found, skip the rest of checks.
At this point we realize we need to accept a new input parameter: the frequency of oscillation freq
. In addition, we need to use the conformal time tau
which is not defined in background_gravity_functions
. The first issue will be solved when we start with input.c
. The second one is going to be our next job.
We must go to the beginning of the function background_gravity_functions
(line 2474 after the above modifications) and locate the declaration of a
and M_pl
:
double a, M_pl;
Where we have to add our new variable tau
:
double a, M_pl, tau;
Then, copy the definition of a
:
a = pvecback_B[pba->index_bi_a];
and modify it to use the conformal time:
tau = pvecback_B[pba->index_bi_tau];
This should have lead to something like this:
double a, M_pl, tau;
double rho_tot, p_tot;
double Omega_smg;
a = pvecback_B[pba->index_bi_a];
tau = pvecback_B[pba->index_bi_tau];
M_pl = pvecback_B[pba->index_bi_M_pl_smg];
Now, we can move on. Next ocurrence is in line 2689:
int background_gravity_parameters(
struct background *pba
){
switch (pba->gravity_model_smg) {
case propto_omega:
printf("Modified gravity: propto_omega with parameters: \n");
printf("-> c_K = %g, c_B = %g, c_M = %g, c_T = %g, M_*^2_init = %g \n",
pba->parameters_2_smg[0],pba->parameters_2_smg[1],pba->parameters_2_smg[2],pba->parameters_2_smg[3],
pba->parameters_2_smg[4]);
break;
Again, we copy and modify the propto_omega
block:
case oscillating_omega:
printf("Modified gravity: oscillating_omega with parameters: \n");
printf("-> c_K = %g, c_B = %g, c_M = %g, c_T = %g, M_*^2_init = %g, freq (H0) = %g \n",
pba->parameters_2_smg[0],pba->parameters_2_smg[1],pba->parameters_2_smg[2],pba->parameters_2_smg[3],
pba->parameters_2_smg[4], pba->parameters_2_smg[5]);
break;
This time you can put it wherever you prefer but we have chosen to put it after the propto_omega
block to have all models to the same relative level, apart from the fact that this way we are able to display them together:
int background_gravity_parameters(
struct background *pba
){
switch (pba->gravity_model_smg) {
case propto_omega:
printf("Modified gravity: propto_omega with parameters: \n");
printf("-> c_K = %g, c_B = %g, c_M = %g, c_T = %g, M_*^2_init = %g \n",
pba->parameters_2_smg[0],pba->parameters_2_smg[1],pba->parameters_2_smg[2],pba->parameters_2_smg[3],
pba->parameters_2_smg[4]);
break;
case oscillating_omega:
printf("Modified gravity: oscillating_omega with parameters: \n");
printf("-> c_K = %g, c_B = %g, c_M = %g, c_T = %g, M_*^2_init = %g, freq (H0) = %g \n",
pba->parameters_2_smg[0],pba->parameters_2_smg[1],pba->parameters_2_smg[2],pba->parameters_2_smg[3],
pba->parameters_2_smg[4], pba->parameters_2_smg[5]);
break;
Finally, we just have to edit input.c
. The first line is 1026:
if (strcmp(string1,"propto_omega") == 0) {
pba->gravity_model_smg = propto_omega;
pba->field_evolution_smg = _FALSE_;
pba->M_pl_evolution_smg = _TRUE_;
flag2=_TRUE_;
pba->parameters_2_size_smg = 5;
class_read_list_of_doubles("parameters_smg",pba->parameters_2_smg,pba->parameters_2_size_smg);
As before, copy, paste below and modify. Recall this time we need an extra parameter to choose the frequency of oscillation:
if (strcmp(string1,"oscillating_omega") == 0) {
pba->gravity_model_smg = oscillating_omega;
pba->field_evolution_smg = _FALSE_;
pba->M_pl_evolution_smg = _TRUE_;
flag2=_TRUE_;
pba->parameters_2_size_smg = 6;
class_read_list_of_doubles("parameters_smg",pba->parameters_2_smg,pba->parameters_2_size_smg);
The next appearence of propto_omega
is in line 1081:
class_test(flag2==_FALSE_,
errmsg,
"could not identify gravity_theory value, check that it is one of 'propto_omega', 'propto_scale', 'eft_alphas_power_law', 'eft_gammas_power_law', 'eft_gammas_exponential' ...");
This may be changed to include our new theory, although it is not mandatory:
class_test(flag2==_FALSE_,
errmsg,
"could not identify gravity_theory value, check that it is one of 'propto_omega', 'propto_scale', 'eft_alphas_power_law', 'eft_gammas_power_law', 'eft_gammas_exponential', 'oscillating_omega' ...");
The last ocurrence is in input_default_params
:
pba->gravity_model_smg = propto_omega; /* gravitational model */
and, unless we want to make our model the new default, we should not change it.
The last optional step would be modifying hi_class.ini
to describe your new available model. As before, it is a matter of copying, pasting and modifying propto_omega
lines (lines 76 and 98). In this case, in the section of 'gravity parameters', we would add:
vi) "oscillating_omega": all the alphas are proportional to the fractional density of the Dark
Energy fluid at the background multiplied by a cos(freq*tau). Then, you have to provide a vector containg the
factor of proportionality of each alpha, the initial value of the Planck Mass and the frequency of oscillation in H0 units.
after the v) "eft_gammas_exponential"
items and in the next block:
vi) "oscillating_omega" -> x_k, x_b, x_m, x_t, M*^2_ini, freq (H0)
This would end your new gravity model addition.
Home
Installation
Basic usage
classy: the python wrapper
Introducing new models
The code:
- Code 1: Philosophy and structure
- Code 2: Indexing
- Code 3: Errors
- Code 4: input.c
- Code 5: background.c
- Code 6: thermodynamics.c
- Code 7: perturbations.c
- Code 8: primordial.c
- Code 10: output.c
- Other modules
- classy: classy.pyx and classy.pxd
Examples: