Skip to content

Commit

Permalink
Issue #3682 Added IntegratorMemory::t_step, t_next_out
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeandersson committed May 13, 2024
1 parent 393e6bb commit fc34b95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
21 changes: 11 additions & 10 deletions casadi/core/integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,16 @@ int Integrator::eval(const double** arg, double** res,
// Integrate forward
for (m->k = 0; m->k < nt(); ++m->k) {
// Next output time
m->t_next = tout_[m->k];
m->t_next_out = tout_[m->k];
// By default, integrate until the next output time
m->t_next = m->t_next_out;
// Handle changes in control input
if (m->k > k_stop) {
// Pass new controls
set_u(m, u);
// Detect next stopping time
k_stop = next_stop(m->k, u);
m->t_stop = tout_[k_stop];
m->t_stop = m->t_step = tout_[k_stop];
// Need to reset solver
m->reset_solver = true;
}
Expand Down Expand Up @@ -432,9 +434,9 @@ 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->step if modified by event
m->t_next = tout_[m->k];
m->t_stop = tout_[k_stop];
// 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 @@ -2520,15 +2522,14 @@ int Integrator::check_event(IntegratorMemory* m) const {
casadi_copy(m->e, ne_, m->old_e);
// Recalculate m->e and m->edot
if (calc_edot(m)) return 1;
// Earliest event time allowed
// double t_first = tout_[m->k];
// By default, continue integrating to the next output time
m->t_next = m->t_next_out;
// Detect events
for (casadi_int i = 0; i < ne_; ++i) {
// Make sure that event was not already triggered
if (m->old_e[i] >= 0) continue;
// Check if event was triggered or is still projected to be triggered before t_next
double dt = tout_[m->k] - m->t;
if (m->e[i] > 0 || (m->edot[i] > 0 && m->old_e[i] + dt * m->edot[i] > 0)) {
// 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];
// Just print the results for now
Expand Down
6 changes: 5 additions & 1 deletion casadi/core/integrator_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ struct CASADI_EXPORT IntegratorMemory : public OracleMemory {
double t;
// Next time to be visited by the integrator
double t_next;
// Next stop time due to step change in input
// Time not to be exceeded by during integrator integration
double t_stop;
// Next output time
double t_next_out;
// Next stop time due to step change in input
double t_step;
// Projected or actual event time and corresponding index
double t_event;
casadi_int event_index;
Expand Down

0 comments on commit fc34b95

Please sign in to comment.