diff --git a/fmusim/FMIModelDescription.c b/fmusim/FMIModelDescription.c index 302afaed..d627b14e 100644 --- a/fmusim/FMIModelDescription.c +++ b/fmusim/FMIModelDescription.c @@ -467,13 +467,15 @@ static FMIModelDescription* readModelDescriptionFMI3(xmlNodePtr root) { xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression((xmlChar*)"/fmiModelDescription/CoSimulation", xpathCtx); if (xpathObj->nodesetval->nodeNr == 1) { CALL(FMICalloc((void**)&modelDescription->coSimulation, 1, sizeof(FMICoSimulationInterface))); - modelDescription->coSimulation->modelIdentifier = (char*)xmlGetProp(xpathObj->nodesetval->nodeTab[0], (xmlChar*)"modelIdentifier"); + const xmlNodePtr node = xpathObj->nodesetval->nodeTab[0]; + modelDescription->coSimulation->modelIdentifier = (char*)xmlGetProp(node, (xmlChar*)"modelIdentifier"); + modelDescription->coSimulation->hasEventMode = getBooleanAttribute(node, "hasEventMode"); } xmlXPathFreeObject(xpathObj); xpathObj = xmlXPathEvalExpression((xmlChar*)"/fmiModelDescription/ModelExchange", xpathCtx); if (xpathObj->nodesetval->nodeNr == 1) { - xmlNodePtr node = xpathObj->nodesetval->nodeTab[0]; + const xmlNodePtr node = xpathObj->nodesetval->nodeTab[0]; CALL(FMICalloc((void**)&modelDescription->modelExchange, 1, sizeof(FMIModelExchangeInterface))); modelDescription->modelExchange->modelIdentifier = (char*)xmlGetProp(node, (xmlChar*)"modelIdentifier"); modelDescription->modelExchange->providesDirectionalDerivatives = getBooleanAttribute(node, "providesDirectionalDerivatives"); diff --git a/fmusim/FMIModelDescription.h b/fmusim/FMIModelDescription.h index b02ce694..44df89a9 100644 --- a/fmusim/FMIModelDescription.h +++ b/fmusim/FMIModelDescription.h @@ -82,6 +82,7 @@ typedef struct { typedef struct { const char* modelIdentifier; + bool hasEventMode; } FMICoSimulationInterface; diff --git a/fmusim/fmusim.c b/fmusim/fmusim.c index 8132d4f8..631f2b4a 100644 --- a/fmusim/fmusim.c +++ b/fmusim/fmusim.c @@ -303,7 +303,6 @@ int main(int argc, const char* argv[]) { } else if (!strcmp(v, "--early-return-allowed")) { earlyReturnAllowed = true; } else if (!strcmp(v, "--event-mode-used")) { - earlyReturnAllowed = true; eventModeUsed = true; } else if (!strcmp(v, "--record-intermediate-values")) { recordIntermediateValues = true; diff --git a/fmusim/fmusim_fmi3_cs.c b/fmusim/fmusim_fmi3_cs.c index 95381fdd..5051cd21 100644 --- a/fmusim/fmusim_fmi3_cs.c +++ b/fmusim/fmusim_fmi3_cs.c @@ -142,7 +142,7 @@ FMIStatus simulateFMI3CS(FMIInstance* S, nextInputEventTime = FMINextInputEvent(input, time); - inputEvent = nextCommunicationPoint > nextInputEventTime; + inputEvent = nextCommunicationPoint >= nextInputEventTime; if (inputEvent) { nextCommunicationPoint = nextInputEventTime; @@ -150,11 +150,11 @@ FMIStatus simulateFMI3CS(FMIInstance* S, stepSize = nextCommunicationPoint - time; - if (settings->eventModeUsed) { - CALL(FMIApplyInput(S, input, time, false, true, false)); - } else { - CALL(FMIApplyInput(S, input, time, true, true, true)); - } + CALL(FMIApplyInput(S, input, time, + !settings->eventModeUsed, // discrete + true, // continuous + !settings->eventModeUsed // afterEvent + )); CALL(FMI3DoStep(S, time, // currentCommunicationPoint @@ -167,6 +167,7 @@ FMIStatus simulateFMI3CS(FMIInstance* S, )); if (earlyReturn && !settings->earlyReturnAllowed) { + FMILogError("The FMU returned early from fmi3DoStep() but early return is not allowed."); status = FMIError; goto TERMINATE; } diff --git a/tests/test_fmusim.py b/tests/test_fmusim.py index 90127588..bea96862 100644 --- a/tests/test_fmusim.py +++ b/tests/test_fmusim.py @@ -371,10 +371,10 @@ def test_event_mode_time_events(platform): interface_type='cs', test_name='test_event_mode_input_events', args=[ - '--event-mode-used', '--stop-time', '5', '--output-interval', '2.5', - '--event-mode-used' + '--event-mode-used', + '--early-return-allowed' ], model='Stair.fmu' )