Let us return to Alice, Bob, and Carol, who are about to implement the Hermite scheme. Since Bob was most eager to test out this new algorithm, he got his turn behind the computer.
for (int k = 0; k < 3; k++){ a[i][k] += m * rji[k] / r3; a[j][k] -= m * rji[k] / r3; }
by:
for (int k = 0; k < 3; k++){ a[i][k] += m * rji[k] / r3; a[j][k] -= m * rji[k] / r3; jk[i][k] += m * (vji[k] - 3 * rv * rji[k]) / r3; jk[j][k] -= m * (vji[k] - 3 * rv * rji[k]) / r3; }
in addition to some extra changes, such as introducing and calculating
the variable vji[] for the relative velocities for particles
and
. All of this is fine, as far as I can see. The statements are
correctly written and reflect the Hermite, but there is one problem.
In the last two lines above you use the relative velocities
,
but at this point in the program they have not been assigned yet.
|gravity> g++ -o hermite1b hermite1b.C |gravity> hermite1b > /dev/null Please provide a value for the time step 0.01 and for the duration of the run 100 Initial total energy E_in = -0.866025 Final total energy E_out = -0.975389 absolute energy error: E_out - E_in = -0.109364 relative energy error: (E_out - E_in) / E_in = 0.126282 |gravity> !! hermite1b > /dev/null Please provide a value for the time step 0.001 and for the duration of the run 100 Initial total energy E_in = -0.866025 Final total energy E_out = -0.866586 absolute energy error: E_out - E_in = -0.000560173 relative energy error: (E_out - E_in) / E_in = 0.000646832 |gravity> !! hermite1b > /dev/null Please provide a value for the time step 0.0001 and for the duration of the run 100 Initial total energy E_in = -0.866025 Final total energy E_out = -0.866026 absolute energy error: E_out - E_in = -5.52839e-07 relative energy error: (E_out - E_in) / E_in = 6.38364e-07 |gravity> !! hermite1b > /dev/null Please provide a value for the time step 0.00001 and for the duration of the run 100 Initial total energy E_in = -0.866025 Final total energy E_out = -0.866025 absolute energy error: E_out - E_in = -5.53711e-10 relative energy error: (E_out - E_in) / E_in = 6.39371e-10 |gravity>
for (int i = 0; i < n; i++){ for (int k = 0; k < 3; k++){ r[i][k] = old_r[i][k] + (old_v[i][k] + v[i][k])*dt/2 + (old_a[i][k] - a[i][k])*dt*dt/12; v[i][k] = old_v[i][k] + (old_a[i][k] + a[i][k])*dt/2 + (old_j[i][k] - jk[i][k])*dt*dt/12; } }
for (int i = 0; i < n; i++){ for (int k = 0; k < 3; k++){ v[i][k] = old_v[i][k] + (old_a[i][k] + a[i][k])*dt/2 + (old_j[i][k] - jk[i][k])*dt*dt/12; r[i][k] = old_r[i][k] + (old_v[i][k] + v[i][k])*dt/2 + (old_a[i][k] - a[i][k])*dt*dt/12; } }