From 22f2273f12ec4f0d69ba7a559482520324230726 Mon Sep 17 00:00:00 2001 From: Torsten Sommer Date: Sat, 18 Nov 2023 11:34:57 +0100 Subject: [PATCH] Consolidate nominalsChanged and statesChanged variables to resetSolver --- fmusim/fmusim_fmi1_me.c | 10 ++++++---- fmusim/fmusim_fmi2_me.c | 20 ++++++-------------- fmusim/fmusim_fmi3_me.c | 19 ++++++------------- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/fmusim/fmusim_fmi1_me.c b/fmusim/fmusim_fmi1_me.c index 1608522d..d8df16de 100644 --- a/fmusim/fmusim_fmi1_me.c +++ b/fmusim/fmusim_fmi1_me.c @@ -23,7 +23,7 @@ FMIStatus simulateFMI1ME( fmi1Boolean timeEvent = fmi1False; fmi1Boolean stepEvent = fmi1False; - fmi1Boolean statesChanged = fmi1False; + fmi1Boolean resetSolver; Solver* solver = NULL; @@ -125,7 +125,7 @@ FMIStatus simulateFMI1ME( )); } - statesChanged = fmi1False; + resetSolver = fmi1False; // event iteration do { @@ -135,7 +135,7 @@ FMIStatus simulateFMI1ME( goto TERMINATE; } - statesChanged |= eventInfo.stateValuesChanged; + resetSolver |= eventInfo.stateValuesChanged; } while (!eventInfo.iterationConverged); @@ -143,7 +143,9 @@ FMIStatus simulateFMI1ME( eventInfo.nextEventTime = INFINITY; } - settings->solverReset(solver, time); + if (resetSolver) { + settings->solverReset(solver, time); + } } } diff --git a/fmusim/fmusim_fmi2_me.c b/fmusim/fmusim_fmi2_me.c index ca9af3a5..40aa7eec 100644 --- a/fmusim/fmusim_fmi2_me.c +++ b/fmusim/fmusim_fmi2_me.c @@ -26,8 +26,7 @@ FMIStatus simulateFMI2ME( fmi2Boolean timeEvent = fmi2False; fmi2Boolean stepEvent = fmi2False; - fmi2Boolean nominalsChanged = fmi2False; - fmi2Boolean statesChanged = fmi2False; + fmi2Boolean resetSolver; Solver* solver = NULL; @@ -74,10 +73,6 @@ FMIStatus simulateFMI2ME( CALL(FMI2EnterInitializationMode(S)); CALL(FMI2ExitInitializationMode(S)); - // intial event iteration - nominalsChanged = fmi2False; - statesChanged = fmi2False; - do { CALL(FMI2NewDiscreteStates(S, &eventInfo)); @@ -86,9 +81,6 @@ FMIStatus simulateFMI2ME( goto TERMINATE; } - nominalsChanged |= eventInfo.nominalsOfContinuousStatesChanged; - statesChanged |= eventInfo.valuesOfContinuousStatesChanged; - } while (eventInfo.newDiscreteStatesNeeded); if (!eventInfo.nextEventTimeDefined) { @@ -164,8 +156,7 @@ FMIStatus simulateFMI2ME( )); } - nominalsChanged = fmi2False; - statesChanged = fmi2False; + resetSolver = fmi2False; // event iteration do { @@ -175,8 +166,7 @@ FMIStatus simulateFMI2ME( goto TERMINATE; } - nominalsChanged |= eventInfo.nominalsOfContinuousStatesChanged; - statesChanged |= eventInfo.valuesOfContinuousStatesChanged; + resetSolver |= eventInfo.nominalsOfContinuousStatesChanged || eventInfo.valuesOfContinuousStatesChanged; } while (eventInfo.newDiscreteStatesNeeded); @@ -187,7 +177,9 @@ FMIStatus simulateFMI2ME( // enter Continuous-Time Mode CALL(FMI2EnterContinuousTimeMode(S)); - settings->solverReset(solver, time); + if (resetSolver) { + settings->solverReset(solver, time); + } } } diff --git a/fmusim/fmusim_fmi3_me.c b/fmusim/fmusim_fmi3_me.c index 8b16e971..2f789dd4 100644 --- a/fmusim/fmusim_fmi3_me.c +++ b/fmusim/fmusim_fmi3_me.c @@ -39,8 +39,7 @@ FMIStatus simulateFMI3ME( fmi3Float64 nextCommunicationPoint; fmi3Float64 nextInputEventTime; - fmi3Boolean nominalsChanged = fmi3False; - fmi3Boolean statesChanged = fmi3False; + fmi3Boolean resetSolver; Solver* solver = NULL; @@ -72,9 +71,6 @@ FMIStatus simulateFMI3ME( CALL(FMI3ExitInitializationMode(S)); // intial event iteration - nominalsChanged = fmi3False; - statesChanged = fmi3False; - do { CALL(FMI3UpdateDiscreteStates(S, @@ -89,9 +85,6 @@ FMIStatus simulateFMI3ME( goto TERMINATE; } - nominalsChanged |= nominalsOfContinuousStatesChanged; - statesChanged |= valuesOfContinuousStatesChanged; - } while (discreteStatesNeedUpdate); if (!nextEventTimeDefined) { @@ -166,8 +159,7 @@ FMIStatus simulateFMI3ME( )); } - nominalsChanged = fmi3False; - statesChanged = fmi3False; + resetSolver = fmi3False; do { @@ -183,8 +175,7 @@ FMIStatus simulateFMI3ME( goto TERMINATE; } - nominalsChanged |= nominalsOfContinuousStatesChanged; - statesChanged |= valuesOfContinuousStatesChanged; + resetSolver |= nominalsOfContinuousStatesChanged || valuesOfContinuousStatesChanged; } while (discreteStatesNeedUpdate); @@ -194,7 +185,9 @@ FMIStatus simulateFMI3ME( CALL(FMI3EnterContinuousTimeMode(S)); - settings->solverReset(solver, time); + if (resetSolver) { + settings->solverReset(solver, time); + } } }