Skip to content

Commit

Permalink
Issue #3682 Added tolerance for terminating the zero crossing iteration
Browse files Browse the repository at this point in the history
Ensures that e.g. zero crossing functions that are linear in t will converge in first iteration
  • Loading branch information
jaeandersson committed May 13, 2024
1 parent c3fca60 commit 393e6bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions casadi/core/integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ Integrator::Integrator(const std::string& name, const Function& oracle,
nadj_ = 0;
print_stats_ = false;
max_event_iter_ = 1;
event_tol_ = 1e-6;
}

Integrator::~Integrator() {
Expand Down Expand Up @@ -550,6 +551,9 @@ const Options Integrator::options_
{"max_event_iter",
{OT_INT,
"Maximum number of iterations to zero in on an event."}},
{"event_tol",
{OT_DOUBLE,
"Termination tolerance for the event iteration."}},
{"output_t0",
{OT_BOOL,
"[DEPRECATED] Output the state at the initial time"}}
Expand Down Expand Up @@ -586,6 +590,8 @@ void Integrator::init(const Dict& opts) {
event_transition_ = op.second;
} else if (op.first=="max_event_iter") {
max_event_iter_ = op.second;
} else if (op.first=="event_tol") {
event_tol_ = op.second;
} else if (op.first=="t0") {
t0 = op.second;
uses_legacy_options = true;
Expand Down Expand Up @@ -2302,6 +2308,7 @@ void Integrator::serialize_body(SerializingStream &s) const {

s.pack("Integrator::event_transition", event_transition_);
s.pack("Integrator::max_event_iter", max_event_iter_);
s.pack("Integrator::event_tol", event_tol_);
}

void Integrator::serialize_type(SerializingStream &s) const {
Expand Down Expand Up @@ -2357,6 +2364,7 @@ Integrator::Integrator(DeserializingStream & s) : OracleFunction(s) {

s.unpack("Integrator::event_transition", event_transition_);
s.unpack("Integrator::max_event_iter", max_event_iter_);
s.unpack("Integrator::event_tol", event_tol_);
}

void FixedStepIntegrator::serialize_body(SerializingStream &s) const {
Expand Down
3 changes: 3 additions & 0 deletions casadi/core/integrator_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ Integrator : public OracleFunction, public PluginInterface<Integrator> {
/// Maximum number of event iterations
casadi_int max_event_iter_;

/// Acceptance tolerance for the event iteration
double event_tol_;

// Creator function for internal class
typedef Integrator* (*Creator)(const std::string& name, const Function& oracle,
double t0, const std::vector<double>& tout);
Expand Down

0 comments on commit 393e6bb

Please sign in to comment.