Skip to content

Commit 5a70568

Browse files
committed
ode logic where needs_nbody
1 parent 606e6a7 commit 5a70568

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

rebound/tests/test_trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_trace_harmonic_with_nbody(self):
7272
self.assertLess(math.fabs(ode_ho.y[0]-1.),2e-10)
7373
self.assertLess(math.fabs(ode_ho.y[1]),2e-9)
7474

75-
def test_trace_harmonic_with_nbody_coupledy(self):
75+
def test_trace_harmonic_with_nbody_coupled(self):
7676
sim = rebound.Simulation()
7777
sim.add(m=1)
7878
sim.add(m=1e-3,a=1,e=0.123);

src/integrator_bs.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ static int tryStep(struct reb_simulation* r, const int Ns, const int k, const in
116116
const double subStep = step / n;
117117
double t = t0;
118118
int needs_nbody = ri_bs->user_ode_needs_nbody;
119-
if (r->integrator == REB_INTEGRATOR_TRACE){
120-
needs_nbody = 0; // TRACE does not allow for coupling of N-body and other ODEs
121-
}
122119

123120
// Modified Midpoint method
124121
// first substep
@@ -134,7 +131,9 @@ static int tryStep(struct reb_simulation* r, const int Ns, const int k, const in
134131
}
135132

136133
// other substeps
137-
if (needs_nbody){
134+
if (r->integrator == REB_INTEGRATOR_BS && needs_nbody){
135+
// Particle do not get updated during bs integration if integrator for N-body is not BS.
136+
// Also no need to update particles if user provided ode does not need particle data.
138137
reb_integrator_bs_update_particles(r, r->ri_bs.nbody_ode->y1);
139138
}
140139
for (int s=0; s < Ns; s++){
@@ -163,7 +162,7 @@ static int tryStep(struct reb_simulation* r, const int Ns, const int k, const in
163162
}
164163
}
165164

166-
if (needs_nbody){
165+
if (r->integrator == REB_INTEGRATOR_BS && needs_nbody){
167166
reb_integrator_bs_update_particles(r, r->ri_bs.nbody_ode->y1);
168167
}
169168
for (int s=0; s < Ns; s++){
@@ -313,6 +312,12 @@ int reb_integrator_bs_step_odes(struct reb_simulation* r, double dt){
313312
//
314313
struct reb_integrator_bs* ri_bs = &r->ri_bs;
315314

315+
for (size_t s=0; s < r->N_odes; s++){
316+
if (r->odes[s]->needs_nbody){
317+
ri_bs->user_ode_needs_nbody = 1;
318+
}
319+
}
320+
316321
if (ri_bs->sequence==NULL){
317322
allocate_sequence_arrays(ri_bs);
318323
}
@@ -699,12 +704,6 @@ void reb_integrator_bs_step(struct reb_simulation* r){
699704
ri_bs->first_or_last_step = 1;
700705
}
701706

702-
for (size_t s=0; s < r->N_odes; s++){
703-
if (r->odes[s]->needs_nbody){
704-
ri_bs->user_ode_needs_nbody = 1;
705-
}
706-
}
707-
708707
double* const y = ri_bs->nbody_ode->y;
709708
for (size_t i=0; i<r->N; i++){
710709
const struct reb_particle p = r->particles[i];
@@ -819,5 +818,6 @@ void reb_integrator_bs_reset(struct reb_simulation* r){
819818
ri_bs->first_or_last_step = 1;
820819
ri_bs->previous_rejected = 0;
821820
ri_bs->target_iter = 0;
821+
ri_bs->user_ode_needs_nbody = 0;
822822

823823
}

0 commit comments

Comments
 (0)