3 ms·
Is the code in gravity_calculate_acceleration correct? I think 'j' will always be 0 in the inner-loop, which seems to defeat the purpose of having a j variable.
by dottrap 10y ago
Is the code in gravity_calculate_acceleration correct?
I think 'j' will always be 0 in the inner-loop, which seems to defeat the purpose of having a j variable.
void gravity_calculate_acceleration(int n_particles, double m[], double x[][3], double a[][3]) {
double G = 6.6742367e-11; // m^3.kg^-1.s^-2
for (int i=0; i<n_particles; i++){
a[i][0] = 0;
a[i][1] = 0;
a[i][2] = 0;
for (int j=0; i<n_particles; i++){
if (j == i) {
continue;
}
double dx = x[i][0] - x[j][0];
double dy = x[i][0] - x[j][0];
double dz = x[i][0] - x[j][0];
double r = sqrt(dx*dx + dy*dy + dz*dz);
double prefact = -G/(r*r*r) * m[j];
a[i][0] += prefact * dx;
a[i][1] += prefact * dy;
a[i][2] += prefact * dz;
}
}
}
- michaf 10y agoThis seems to have been fixed 3 hours ago: https://github.com/marblestation/benchmark-leapfrog/commit/c51d95dad0a83d6c3cb5f2868896da3bfa46e158 https://github.com/marblestation/benchmark-leapfrog/commit/c...