Skip to content

Commit

Permalink
Issue #3682 Cleanup Integrator::check_event
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeandersson committed May 13, 2024
1 parent fc34b95 commit c1a29c8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions casadi/core/integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ int Integrator::eval(const double** arg, double** res,
bool event_detection = ne_ > 0 && m->t_next > m->t;
// Number of root-finding iterations
m->event_iter = 0;
// Keep integrating until we reached the next output time
// Keep integrating until we reach the next output time
while (true) {
// Reset the solver
if (m->reset_solver) {
Expand All @@ -434,9 +434,6 @@ int Integrator::eval(const double** arg, double** res,
// Check if event occured
if (event_detection) {
if (check_event(m)) return 1;
// Restore m->t_next, m->t_stop if modified by event
m->t_next = m->t_next_out;
m->t_stop = m->t_step;
}
// If output time reached, stop
if (m->t == m->t_next) break;
Expand Down Expand Up @@ -2531,10 +2528,10 @@ int Integrator::check_event(IntegratorMemory* m) const {
// Check if event was triggered or is still projected to be triggered before next output time
if (m->e[i] > 0 || (m->edot[i] > 0 && m->old_e[i] + (m->t_next_out - m->t) * m->edot[i] > 0)) {
// Projected zero-crossing time
double t_next = m->t - m->e[i] / m->edot[i];
double t_zero = m->t - m->e[i] / m->edot[i];
// Just print the results for now
if (verbose_) casadi_message("Zero crossing for index " + str(i) + " at t = " + str(m->t)
+ ". t_next = " + str(t_next));
+ ". t_zero = " + str(t_zero));
// Call event transition function, if any
if (has_function("event_transition")) {
// Evaluate to tmp1
Expand All @@ -2553,8 +2550,12 @@ int Integrator::check_event(IntegratorMemory* m) const {
}
// Solver needs to be reset
m->reset_solver = true;
// Restore stopping time after event
m->t_stop = m->t_step;
}
}
// Restore m->t_next, m->t_stop if modified by event
m->t_next = m->t_next_out;
return 0;
}

Expand Down

0 comments on commit c1a29c8

Please sign in to comment.