From 2c087a3e3ba221417c7b6f438fca184c1fcd361d Mon Sep 17 00:00:00 2001 From: Torsten Sommer Date: Fri, 2 Aug 2024 15:06:45 +0200 Subject: [PATCH] Add reinit=true to variable h in BouncingBall (#541) and check state in setFloat64() --- BouncingBall/FMI2.xml | 2 +- BouncingBall/FMI3.xml | 2 +- BouncingBall/model.c | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/BouncingBall/FMI2.xml b/BouncingBall/FMI2.xml index 01ef5691..e9c0f391 100644 --- a/BouncingBall/FMI2.xml +++ b/BouncingBall/FMI2.xml @@ -64,7 +64,7 @@ - + diff --git a/BouncingBall/FMI3.xml b/BouncingBall/FMI3.xml index 915db887..a462bdae 100644 --- a/BouncingBall/FMI3.xml +++ b/BouncingBall/FMI3.xml @@ -49,7 +49,7 @@ - + diff --git a/BouncingBall/model.c b/BouncingBall/model.c index 8f6a8558..518a1921 100644 --- a/BouncingBall/model.c +++ b/BouncingBall/model.c @@ -58,10 +58,26 @@ Status setFloat64(ModelInstance* comp, ValueReference vr, const double value[], switch (vr) { case vr_h: +#if FMI_VERSION > 1 + if (comp->state != Instantiated && + comp->state != InitializationMode && + comp->state != ContinuousTimeMode) { + logError(comp, "Variable \"h\" can only be set in Instantiated Mode, Initialization Mode, and Continuous Time Mode."); + return Error; + } +#endif M(h) = value[(*index)++]; return OK; case vr_v: +#if FMI_VERSION > 1 + if (comp->state != Instantiated && + comp->state != InitializationMode && + comp->state != ContinuousTimeMode) { + logError(comp, "Variable \"v\" can only be set in Instantiated Mode, Initialization Mode, and Continuous Time Mode."); + return Error; + } +#endif M(v) = value[(*index)++]; return OK;