Skip to content

Commit

Permalink
Add reinit=true to variable h in BouncingBall (#541)
Browse files Browse the repository at this point in the history
and check state in setFloat64()
  • Loading branch information
t-sommer authored Aug 2, 2024
1 parent 0f6a4ac commit 2c087a3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion BouncingBall/FMI2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<Real/>
</ScalarVariable>
<ScalarVariable name="h" valueReference="1" causality="output" variability="continuous" initial="exact" description="Position of the ball">
<Real start="1" declaredType="Position"/>
<Real start="1" reinit="true" declaredType="Position"/>
</ScalarVariable>
<ScalarVariable name="der(h)" valueReference="2" causality="local" variability="continuous" initial="calculated" description="Derivative of h">
<Real derivative="2" declaredType="Velocity"/>
Expand Down
2 changes: 1 addition & 1 deletion BouncingBall/FMI3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<ModelVariables>
<Float64 name="time" valueReference="0" causality="independent" variability="continuous" description="Simulation time"/>
<Float64 name="h" valueReference="1" causality="output" variability="continuous" initial="exact" declaredType="Position" start="1" description="Position of the ball" intermediateUpdate="true"/>
<Float64 name="h" valueReference="1" causality="output" variability="continuous" initial="exact" declaredType="Position" start="1" reinit="true" description="Position of the ball" intermediateUpdate="true"/>
<Float64 name="der(h)" valueReference="2" causality="local" variability="continuous" initial="calculated" declaredType="Velocity" derivative="1" description="Derivative of h"/>
<Float64 name="v" valueReference="3" causality="output" variability="continuous" initial="exact" declaredType="Velocity" start="0" reinit="true" description="Velocity of the ball" intermediateUpdate="true"/>
<Float64 name="der(v)" valueReference="4" causality="local" variability="continuous" initial="calculated" declaredType="Acceleration" derivative="3" description="Derivative of v"/>
Expand Down
16 changes: 16 additions & 0 deletions BouncingBall/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 2c087a3

Please sign in to comment.