Skip to content

Commit

Permalink
Respect canHandleVariableCommunicationStepSize in FMI{2|3}CSSimulatio…
Browse files Browse the repository at this point in the history
…n.c (#615)
  • Loading branch information
t-sommer authored Oct 15, 2024
1 parent f7f44fa commit d4c4048
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 8 additions & 2 deletions fmusim/FMI2CSSimulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ FMIStatus FMI2CSSimulate(const FMISimulationSettings* s) {
fmi2Real nextCommunicationPoint = 0.0;
fmi2Real nextInputEventTime = 0.0;
fmi2Real stepSize = 0.0;

const bool canHandleVariableCommunicationStepSize = s->modelDescription->coSimulation->canHandleVariableCommunicationStepSize;

char resourcePath[FMI_PATH_MAX] = "";
char resourceURI[FMI_PATH_MAX] = "";
Expand Down Expand Up @@ -68,12 +70,16 @@ FMIStatus FMI2CSSimulate(const FMISimulationSettings* s) {

nextInputEventTime = FMINextInputEvent(s->input, time);

if (nextCommunicationPoint > nextInputEventTime && !FMIIsClose(nextCommunicationPoint, nextInputEventTime)) {
if (canHandleVariableCommunicationStepSize &&
nextCommunicationPoint > nextInputEventTime &&
!FMIIsClose(nextCommunicationPoint, nextInputEventTime)) {

nextCommunicationPoint = nextInputEventTime;
}

if (nextCommunicationPoint > s->stopTime && !FMIIsClose(nextCommunicationPoint, s->stopTime)) {
if (s->modelDescription->coSimulation->canHandleVariableCommunicationStepSize) {

if (canHandleVariableCommunicationStepSize) {
nextCommunicationPoint = s->stopTime;
} else {
break;
Expand Down
9 changes: 7 additions & 2 deletions fmusim/FMI3CSSimulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ FMIStatus FMI3CSSimulate(const FMISimulationSettings* s) {
FMIStatus status = FMIOK;

FMIInstance* S = s->S;
const bool canHandleVariableCommunicationStepSize = s->modelDescription->coSimulation->canHandleVariableCommunicationStepSize;

fmi3Boolean inputEvent = fmi3False;
fmi3Boolean eventEncountered = fmi3False;
Expand Down Expand Up @@ -141,12 +142,16 @@ FMIStatus FMI3CSSimulate(const FMISimulationSettings* s) {

nextInputEventTime = FMINextInputEvent(s->input, time);

if (nextCommunicationPoint > nextInputEventTime && !FMIIsClose(nextCommunicationPoint, nextInputEventTime)) {
if (canHandleVariableCommunicationStepSize &&
nextCommunicationPoint > nextInputEventTime &&
!FMIIsClose(nextCommunicationPoint, nextInputEventTime)) {

nextCommunicationPoint = nextInputEventTime;
}

if (nextCommunicationPoint > s->stopTime && !FMIIsClose(nextCommunicationPoint, s->stopTime)) {
if (s->modelDescription->coSimulation->canHandleVariableCommunicationStepSize) {

if (canHandleVariableCommunicationStepSize) {
nextCommunicationPoint = s->stopTime;
} else {
break;
Expand Down

0 comments on commit d4c4048

Please sign in to comment.