From d4c40484f3770ec9763d393d5250d3fba66eeb08 Mon Sep 17 00:00:00 2001 From: Torsten Sommer Date: Tue, 15 Oct 2024 11:47:45 +0200 Subject: [PATCH] Respect canHandleVariableCommunicationStepSize in FMI{2|3}CSSimulation.c (#615) --- fmusim/FMI2CSSimulation.c | 10 ++++++++-- fmusim/FMI3CSSimulation.c | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/fmusim/FMI2CSSimulation.c b/fmusim/FMI2CSSimulation.c index c9319f54..1224c691 100644 --- a/fmusim/FMI2CSSimulation.c +++ b/fmusim/FMI2CSSimulation.c @@ -16,6 +16,8 @@ FMIStatus FMI2CSSimulate(const FMISimulationSettings* s) { fmi2Real nextCommunicationPoint = 0.0; fmi2Real nextInputEventTime = 0.0; fmi2Real stepSize = 0.0; + + const bool canHandleVariableCommunicationStepSize = s->modelDescription->coSimulation->canHandleVariableCommunicationStepSize; char resourcePath[FMI_PATH_MAX] = ""; char resourceURI[FMI_PATH_MAX] = ""; @@ -68,12 +70,16 @@ FMIStatus FMI2CSSimulate(const FMISimulationSettings* s) { nextInputEventTime = FMINextInputEvent(s->input, time); - if (nextCommunicationPoint > nextInputEventTime && !FMIIsClose(nextCommunicationPoint, nextInputEventTime)) { + if (canHandleVariableCommunicationStepSize && + nextCommunicationPoint > nextInputEventTime && + !FMIIsClose(nextCommunicationPoint, nextInputEventTime)) { + nextCommunicationPoint = nextInputEventTime; } if (nextCommunicationPoint > s->stopTime && !FMIIsClose(nextCommunicationPoint, s->stopTime)) { - if (s->modelDescription->coSimulation->canHandleVariableCommunicationStepSize) { + + if (canHandleVariableCommunicationStepSize) { nextCommunicationPoint = s->stopTime; } else { break; diff --git a/fmusim/FMI3CSSimulation.c b/fmusim/FMI3CSSimulation.c index 572e6666..049531b6 100644 --- a/fmusim/FMI3CSSimulation.c +++ b/fmusim/FMI3CSSimulation.c @@ -37,6 +37,7 @@ FMIStatus FMI3CSSimulate(const FMISimulationSettings* s) { FMIStatus status = FMIOK; FMIInstance* S = s->S; + const bool canHandleVariableCommunicationStepSize = s->modelDescription->coSimulation->canHandleVariableCommunicationStepSize; fmi3Boolean inputEvent = fmi3False; fmi3Boolean eventEncountered = fmi3False; @@ -141,12 +142,16 @@ FMIStatus FMI3CSSimulate(const FMISimulationSettings* s) { nextInputEventTime = FMINextInputEvent(s->input, time); - if (nextCommunicationPoint > nextInputEventTime && !FMIIsClose(nextCommunicationPoint, nextInputEventTime)) { + if (canHandleVariableCommunicationStepSize && + nextCommunicationPoint > nextInputEventTime && + !FMIIsClose(nextCommunicationPoint, nextInputEventTime)) { + nextCommunicationPoint = nextInputEventTime; } if (nextCommunicationPoint > s->stopTime && !FMIIsClose(nextCommunicationPoint, s->stopTime)) { - if (s->modelDescription->coSimulation->canHandleVariableCommunicationStepSize) { + + if (canHandleVariableCommunicationStepSize) { nextCommunicationPoint = s->stopTime; } else { break;