From 5a4f95744af4125cbbcd3b14511d1920a44677f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20T=C3=A4uber?= <92858933+PTaeuberDS@users.noreply.github.com> Date: Fri, 12 Jan 2024 16:10:17 +0100 Subject: [PATCH] Fix event handling w/o early return (#424) fixes #421 fixes #425 fixes #236 --- src/fmi3Functions.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/fmi3Functions.c b/src/fmi3Functions.c index 1734f51e..480e687d 100644 --- a/src/fmi3Functions.c +++ b/src/fmi3Functions.c @@ -1341,12 +1341,20 @@ fmi3Status fmi3DoStep(fmi3Instance instance, while (true) { - nextCommunicationPointReached = S->time + FIXED_SOLVER_STEP > nextCommunicationPoint; + const fmi3Float64 nextSolverStepTime = S->time + FIXED_SOLVER_STEP; + nextCommunicationPointReached = nextSolverStepTime > nextCommunicationPoint; - if (nextCommunicationPointReached) { + if (nextCommunicationPointReached || (*eventHandlingNeeded && S->earlyReturnAllowed)) { break; } +#ifdef EVENT_UPDATE + if (*eventHandlingNeeded) { + eventUpdate(S); + *eventHandlingNeeded = fmi3False; + } +#endif + bool stateEvent, timeEvent; CALL(doFixedStep(S, &stateEvent, &timeEvent));