# Astro-forum - don't use UiO password

## AST 5220 / AST9420 => Milestone III => Topic started by: winther on 21. April 2021, 14:53:15

Title: Common mistakes
Post by: winther 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 in tight coupling:
Code: [Select]
q = ... + Theta + ... ;In tight coupling we only evolve Theta and Theta. If you try to access Theta then you will access the solution vector out of bounds (or accessing Nu 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;q = ... + Theta2 + ...;
Using variables before they have been computed:
Code: [Select]
double q =  ... + dThetadx + ...;dThetadx = -cqoverHp * Theta;Here we want to use dThetadx  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 = -cqoverHp * Theta;double q =  ... + dThetadx + ...;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}