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;