From d8e140c490e6f4b1890976af831d1a495f19dd9a Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Tue, 5 Dec 2023 09:16:14 +0100 Subject: [PATCH] Fix sign --- include/amici/forwardproblem.h | 3 ++- src/forwardproblem.cpp | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/amici/forwardproblem.h b/include/amici/forwardproblem.h index 3d3742b794..2871ab28f8 100644 --- a/include/amici/forwardproblem.h +++ b/include/amici/forwardproblem.h @@ -370,7 +370,8 @@ class ForwardProblem { * @brief Array of flags indicating which root has been found. * * Array of length nr (ne) with the indices of the user functions gi found - * to have a root. For i = 0, . . . ,nr 1 if gi has a root, and = 0 if not. + * to have a root. For i = 0, . . . ,nr 1 or -1 if gi has a root, and = 0 + * if not. See CVodeGetRootInfo for details. */ std::vector roots_found_; diff --git a/src/forwardproblem.cpp b/src/forwardproblem.cpp index 9a02d31403..e3dcecd1a9 100644 --- a/src/forwardproblem.cpp +++ b/src/forwardproblem.cpp @@ -21,7 +21,6 @@ namespace amici { * @return True if too close, false otherwise. */ bool is_next_t_too_close(realtype cur_t, realtype t_next) { - // Based on cvHin auto tdiff = t_next - cur_t; if(tdiff == 0.0) return true; @@ -181,7 +180,9 @@ void ForwardProblem::workForwardProblem() { // if so, set the root-found flag if (t_ == next_t_event) { for (auto ie : model->state_independent_events_[t_]) { - roots_found_[ie] = 1; + // determine direction of root crossing from + // root function value at the previous event + roots_found_[ie] = std::copysign(1, -rootvals_[ie]); } ++it_trigger_timepoints; }