Skip to content

Commit

Permalink
Consolidate nominalsChanged and statesChanged variables
Browse files Browse the repository at this point in the history
to resetSolver
  • Loading branch information
t-sommer committed Nov 18, 2023
1 parent d3b2f6b commit 22f2273
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 31 deletions.
10 changes: 6 additions & 4 deletions fmusim/fmusim_fmi1_me.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FMIStatus simulateFMI1ME(
fmi1Boolean timeEvent = fmi1False;
fmi1Boolean stepEvent = fmi1False;

fmi1Boolean statesChanged = fmi1False;
fmi1Boolean resetSolver;

Solver* solver = NULL;

Expand Down Expand Up @@ -125,7 +125,7 @@ FMIStatus simulateFMI1ME(
));
}

statesChanged = fmi1False;
resetSolver = fmi1False;

// event iteration
do {
Expand All @@ -135,15 +135,17 @@ FMIStatus simulateFMI1ME(
goto TERMINATE;
}

statesChanged |= eventInfo.stateValuesChanged;
resetSolver |= eventInfo.stateValuesChanged;

} while (!eventInfo.iterationConverged);

if (!eventInfo.upcomingTimeEvent) {
eventInfo.nextEventTime = INFINITY;
}

settings->solverReset(solver, time);
if (resetSolver) {
settings->solverReset(solver, time);
}
}

}
Expand Down
20 changes: 6 additions & 14 deletions fmusim/fmusim_fmi2_me.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ FMIStatus simulateFMI2ME(
fmi2Boolean timeEvent = fmi2False;
fmi2Boolean stepEvent = fmi2False;

fmi2Boolean nominalsChanged = fmi2False;
fmi2Boolean statesChanged = fmi2False;
fmi2Boolean resetSolver;

Solver* solver = NULL;

Expand Down Expand Up @@ -74,10 +73,6 @@ FMIStatus simulateFMI2ME(
CALL(FMI2EnterInitializationMode(S));
CALL(FMI2ExitInitializationMode(S));

// intial event iteration
nominalsChanged = fmi2False;
statesChanged = fmi2False;

do {

CALL(FMI2NewDiscreteStates(S, &eventInfo));
Expand All @@ -86,9 +81,6 @@ FMIStatus simulateFMI2ME(
goto TERMINATE;
}

nominalsChanged |= eventInfo.nominalsOfContinuousStatesChanged;
statesChanged |= eventInfo.valuesOfContinuousStatesChanged;

} while (eventInfo.newDiscreteStatesNeeded);

if (!eventInfo.nextEventTimeDefined) {
Expand Down Expand Up @@ -164,8 +156,7 @@ FMIStatus simulateFMI2ME(
));
}

nominalsChanged = fmi2False;
statesChanged = fmi2False;
resetSolver = fmi2False;

// event iteration
do {
Expand All @@ -175,8 +166,7 @@ FMIStatus simulateFMI2ME(
goto TERMINATE;
}

nominalsChanged |= eventInfo.nominalsOfContinuousStatesChanged;
statesChanged |= eventInfo.valuesOfContinuousStatesChanged;
resetSolver |= eventInfo.nominalsOfContinuousStatesChanged || eventInfo.valuesOfContinuousStatesChanged;

} while (eventInfo.newDiscreteStatesNeeded);

Expand All @@ -187,7 +177,9 @@ FMIStatus simulateFMI2ME(
// enter Continuous-Time Mode
CALL(FMI2EnterContinuousTimeMode(S));

settings->solverReset(solver, time);
if (resetSolver) {
settings->solverReset(solver, time);
}
}

}
Expand Down
19 changes: 6 additions & 13 deletions fmusim/fmusim_fmi3_me.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ FMIStatus simulateFMI3ME(
fmi3Float64 nextCommunicationPoint;
fmi3Float64 nextInputEventTime;

fmi3Boolean nominalsChanged = fmi3False;
fmi3Boolean statesChanged = fmi3False;
fmi3Boolean resetSolver;

Solver* solver = NULL;

Expand Down Expand Up @@ -72,9 +71,6 @@ FMIStatus simulateFMI3ME(
CALL(FMI3ExitInitializationMode(S));

// intial event iteration
nominalsChanged = fmi3False;
statesChanged = fmi3False;

do {

CALL(FMI3UpdateDiscreteStates(S,
Expand All @@ -89,9 +85,6 @@ FMIStatus simulateFMI3ME(
goto TERMINATE;
}

nominalsChanged |= nominalsOfContinuousStatesChanged;
statesChanged |= valuesOfContinuousStatesChanged;

} while (discreteStatesNeedUpdate);

if (!nextEventTimeDefined) {
Expand Down Expand Up @@ -166,8 +159,7 @@ FMIStatus simulateFMI3ME(
));
}

nominalsChanged = fmi3False;
statesChanged = fmi3False;
resetSolver = fmi3False;

do {

Expand All @@ -183,8 +175,7 @@ FMIStatus simulateFMI3ME(
goto TERMINATE;
}

nominalsChanged |= nominalsOfContinuousStatesChanged;
statesChanged |= valuesOfContinuousStatesChanged;
resetSolver |= nominalsOfContinuousStatesChanged || valuesOfContinuousStatesChanged;

} while (discreteStatesNeedUpdate);

Expand All @@ -194,7 +185,9 @@ FMIStatus simulateFMI3ME(

CALL(FMI3EnterContinuousTimeMode(S));

settings->solverReset(solver, time);
if (resetSolver) {
settings->solverReset(solver, time);
}
}

}
Expand Down

0 comments on commit 22f2273

Please sign in to comment.