Skip to content

Commit

Permalink
Fixes backwards integrations in MERCURIUS. Fixes #753.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannorein committed Feb 26, 2024
1 parent a952fdc commit 7a6f596
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/integrator_mercurius.c
Expand Up @@ -327,14 +327,15 @@ static void reb_mercurius_encounter_step(struct reb_simulation* const r, const d

// run
const double old_dt = r->dt;
const double dtsign = old_dt>=0.?1.:-1.;
const double old_t = r->t;
double t_needed = r->t + _dt;

reb_integrator_ias15_reset(r);

r->dt = 0.0001*_dt; // start with a small timestep.

while(r->t < t_needed && fabs(r->dt/old_dt)>1e-14 ){
while(dtsign*r->t < dtsign*t_needed && fabs(r->dt/old_dt)>1e-14 ){
struct reb_particle star = r->particles[0]; // backup velocity
r->particles[0].vx = 0; // star does not move in dh
r->particles[0].vy = 0;
Expand All @@ -345,7 +346,7 @@ static void reb_mercurius_encounter_step(struct reb_simulation* const r, const d
r->particles[0].vy = star.vy;
r->particles[0].vz = star.vz;

if (r->t+r->dt > t_needed){
if (dtsign*(r->t+r->dt) > dtsign*t_needed){
r->dt = t_needed-r->t;
}

Expand Down

0 comments on commit 7a6f596

Please sign in to comment.