forked from modelica/Reference-FMUs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.c
43 lines (34 loc) · 1.11 KB
/
model.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <float.h> // for DBL_EPSILON
#include <math.h> // for fabs()
#include "config.h"
#include "model.h"
void setStartValues(ModelInstance *comp) {
M(counter) = 1;
// TODO: move this to initialize()?
comp->nextEventTime = 1;
comp->nextEventTimeDefined = true;
}
void calculateValues(ModelInstance *comp) {
// do nothing
UNUSED(comp)
}
Status getInt32(ModelInstance* comp, ValueReference vr, int *value, size_t *index) {
switch (vr) {
case vr_counter:
value[(*index)++] = M(counter);
return OK;
default:
return Error;
}
}
void eventUpdate(ModelInstance *comp) {
double epsilon = (1.0 + fabs(comp->time)) * DBL_EPSILON;
if (comp->nextEventTimeDefined && comp->time + epsilon >= comp->nextEventTime) {
M(counter)++;
comp->nextEventTime += 1;
}
comp->valuesOfContinuousStatesChanged = false;
comp->nominalsOfContinuousStatesChanged = false;
comp->terminateSimulation = false;
comp->nextEventTimeDefined = true;
}