Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align fmi2DoStep() break condition with FMI 3.0 #210

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/cosimulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "model.h"

#define EPSILON (FIXED_SOLVER_STEP * 1e-6)

void doFixedStep(ModelInstance *comp, bool* stateEvent, bool* timeEvent);

#endif /* cosimulation_h */
1 change: 0 additions & 1 deletion include/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ void getEventIndicators(ModelInstance *comp, double z[], size_t nz);
void eventUpdate(ModelInstance *comp);
//void updateEventTime(ModelInstance *comp);

double epsilon(double value);
bool invalidNumber(ModelInstance *comp, const char *f, const char *arg, size_t actual, size_t expected);
bool invalidState(ModelInstance *comp, const char *f, int statesExpected);
bool nullPointer(ModelInstance* comp, const char *f, const char *arg, const void *p);
Expand Down
4 changes: 0 additions & 4 deletions src/cosimulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ void reset(ModelInstance* comp) {
comp->isDirtyValues = true;
}

double epsilon(double value) {
return (1.0 + fabs(value)) * DBL_EPSILON;
}

bool invalidNumber(ModelInstance *comp, const char *f, const char *arg, size_t actual, size_t expected) {

if (actual != expected) {
Expand Down
8 changes: 7 additions & 1 deletion src/fmi1Functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,13 @@ fmiStatus fmiDoStep(fmiComponent c, fmiReal currentCommunicationPoint, fmiReal c

ModelInstance* instance = (ModelInstance *)c;

while (instance->time + FIXED_SOLVER_STEP < currentCommunicationPoint + communicationStepSize + epsilon(instance->time)) {
const fmiReal nextCommunicationPoint = currentCommunicationPoint + communicationStepSize + EPSILON;

while (true) {

if (instance->time + FIXED_SOLVER_STEP > nextCommunicationPoint) {
break; // next communcation point reached
}

bool stateEvent, timeEvent;

Expand Down
8 changes: 7 additions & 1 deletion src/fmi2Functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,13 @@ fmi2Status fmi2DoStep(fmi2Component c, fmi2Real currentCommunicationPoint,
return fmi2Error;
}

while (S->time + FIXED_SOLVER_STEP < currentCommunicationPoint + communicationStepSize + epsilon(S->time)) {
const fmi2Real nextCommunicationPoint = currentCommunicationPoint + communicationStepSize + EPSILON;

while (true) {

if (S->time + FIXED_SOLVER_STEP > nextCommunicationPoint) {
break; // next communcation point reached
}

bool stateEvent, timeEvent;

Expand Down
2 changes: 1 addition & 1 deletion src/fmi3Functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ fmi3Status fmi3DoStep(fmi3Instance instance,
return fmi3Error;
}

const fmi3Float64 nextCommunicationPoint = currentCommunicationPoint + communicationStepSize + epsilon(S->time);
const fmi3Float64 nextCommunicationPoint = currentCommunicationPoint + communicationStepSize + EPSILON;

fmi3Boolean nextCommunicationPointReached;

Expand Down