### Author Topic: Common mistakes  (Read 62 times)

#### winther

• Global Moderator
• Member
• Posts: 73
##### Common mistakes
« on: 21. April 2021, 14:53:15 »
This is just a summary (for future years) of common mistakes that are very easy to make (and hard to see) that have popped up during the work on milestone 3.

Using Theta[2] in tight coupling:
Code: [Select]
q = ... + Theta[2] + ... ;In tight coupling we only evolve Theta[0] and Theta[1]. If you try to access Theta[2] then you will access the solution vector out of bounds (or accessing Nu[0] if you have neutrinos) which leads to bugs. How to solve this? Compute Theta2 and store it in a different variable:

Code: [Select]
double Theta2 = -8.0/15.0 * ckoverHpdtaudx * Theta[1];q = ... + Theta2 + ...;
Using variables before they have been computed:
Code: [Select]
double q =  ... + dThetadx[0] + ...;dThetadx[0] = -cqoverHp * Theta[1];Here we want to use dThetadx[0]  in the first equation, but its not been computed yet. We must do it the other way around (or just store it in a variable and use that):
Code: [Select]
dThetadx[0] = -cqoverHp * Theta[1];double q =  ... + dThetadx[0] + ...;Allocating the theta spline (if you use this - its fine to just spline Theta0,1,2):
Code: [Select]
Theta_spline = std::vector<Spline2D>(n_ell_theta); // We need to allocate space for the splines before using itfor (int ell = 0; ell < n_ell_theta; ell++) {    std::string name = "theta" + std::to_string(ell) + "_x_k";    Theta_spline[ell].create(x_array, k_array, results[ell], name); // ...otherwise we access memory addresses that don't exist}
« Last Edit: 21. April 2021, 17:14:20 by winther »