Skip to content

Commit

Permalink
Remove FMIDiscreteFloat{32|64}Type enums
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sommer committed Aug 20, 2024
1 parent 3596ae9 commit 1b863b3
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 184 deletions.
6 changes: 2 additions & 4 deletions fmusim-gui/AbstractModelVariablesModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,8 @@ QVariant AbstractModelVariablesModel::columnData(const FMIModelVariable *variabl
return variable->name;
case TypeColumn:
switch (variable->type) {
case FMIFloat32Type:
case FMIDiscreteFloat32Type: return "Float32";
case FMIFloat64Type:
case FMIDiscreteFloat64Type: return "Float64";
case FMIFloat32Type: return "Float32";
case FMIFloat64Type: return "Float64";
case FMIInt8Type: return "Int8";
case FMIUInt8Type: return "UInt8";
case FMIInt16Type: return "Int16";
Expand Down
2 changes: 0 additions & 2 deletions fmusim-gui/PlotUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ static QString getData(const FMIRecorder* recorder, const FMIModelVariable* vari

switch (type) {
case FMIFloat32Type:
case FMIDiscreteFloat32Type:
{
const float* values = (float*)row->values[type];
y += QString::number(values[index]);
}
break;
case FMIFloat64Type:
case FMIDiscreteFloat64Type:
{
const double* values = (double*)row->values[type];
y += QString::number(values[index]);
Expand Down
34 changes: 6 additions & 28 deletions fmusim/FMIModelDescription.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,7 @@ static FMIModelDescription* readModelDescriptionFMI1(xmlNodePtr root) {
xmlFree((void*)variability);

if (!strcmp(typeName, "Real")) {
const char* variability = (char*)xmlGetProp(variableNode, (xmlChar*)"variability");
if (variability && !strcmp(variability, "discrete")) {
variable->type = FMIDiscreteRealType;
} else {
variable->type = FMIRealType;
}
xmlFree((void*)variability);
variable->type = FMIRealType;
} else if (!strcmp(typeName, "Integer") || !strcmp(typeName, "Enumeration")) {
variable->type = FMIIntegerType;
} else if (!strcmp(typeName, "Boolean")) {
Expand All @@ -224,7 +218,7 @@ static FMIModelDescription* readModelDescriptionFMI1(xmlNodePtr root) {
// check variabilities
for (size_t i = 0; i < modelDescription->nModelVariables; i++) {
const FMIModelVariable* variable = modelDescription->modelVariables[i];
if (variable->type != FMIRealType && variable->type != FMIDiscreteRealType && variable->variability == FMIContinuous) {
if (variable->type != FMIRealType && variable->variability == FMIContinuous) {
FMILogError("Variable \"%s\" is not of type Real but has variability = continuous.\n", variable->name);
nProblems++;
}
Expand Down Expand Up @@ -592,7 +586,7 @@ static FMIModelDescription* readModelDescriptionFMI2(xmlNodePtr root) {
xmlFree((void*)variability);

if (!strcmp(typeName, "Real")) {
variable->type = variable->variability == FMIDiscrete ? FMIDiscreteRealType : FMIRealType;
variable->type = FMIRealType;
} else if (!strcmp(typeName, "Integer") || !strcmp(typeName, "Enumeration")) {
variable->type = FMIIntegerType;
} else if (!strcmp(typeName, "Boolean")) {
Expand Down Expand Up @@ -653,7 +647,7 @@ static FMIModelDescription* readModelDescriptionFMI2(xmlNodePtr root) {
// check variabilities
for (size_t i = 0; i < modelDescription->nModelVariables; i++) {
FMIModelVariable* variable = modelDescription->modelVariables[i];
if (variable->type != FMIRealType && variable->type != FMIDiscreteRealType && variable->variability == FMIContinuous) {
if (variable->type != FMIRealType && variable->variability == FMIContinuous) {
FMILogError("Variable \"%s\" is not of type Real but has variability = continuous.\n", variable->name);
nProblems++;
}
Expand Down Expand Up @@ -939,25 +933,9 @@ static FMIModelDescription* readModelDescriptionFMI3(xmlNodePtr root) {
xmlFree((void*)variability);

if (!strcmp(name, "Float32")) {
switch (variable->variability) {
case -1:
case FMIContinuous:
type = FMIFloat32Type;
break;
default:
type = FMIDiscreteFloat32Type;
break;
}
type = FMIFloat32Type;
} else if (!strcmp(name, "Float64")) {
switch (variable->variability) {
case -1:
case FMIContinuous:
type = FMIFloat64Type;
break;
default:
type = FMIDiscreteFloat64Type;
break;
}
type = FMIFloat64Type;
} else if (!strcmp(name, "Int8")) {
type = FMIInt8Type;
} else if (!strcmp(name, "UInt8")) {
Expand Down
71 changes: 2 additions & 69 deletions fmusim/FMIRecorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,71 +145,6 @@ FMIStatus FMIRecorderUpdateSizes(FMIRecorder* recorder) {
return status;
}

static size_t FMISizeOfVariableType(FMIMajorVersion majorVersion, FMIVariableType type) {

switch (type) {
case FMIFloat32Type:
case FMIDiscreteFloat32Type:
return sizeof(fmi3Float32);

case FMIFloat64Type:
case FMIDiscreteFloat64Type:
return sizeof(fmi3Float64);

case FMIInt8Type:
return sizeof(fmi3Int8);

case FMIUInt8Type:
return sizeof(fmi3UInt8);

case FMIInt16Type:
return sizeof(fmi3Int16);

case FMIUInt16Type:
return sizeof(fmi3UInt16);

case FMIInt32Type:
return sizeof(fmi3Int32);

case FMIUInt32Type:
return sizeof(fmi3UInt32);

case FMIInt64Type:
return sizeof(fmi3Int64);

case FMIUInt64Type:
return sizeof(fmi3UInt64);

case FMIBooleanType:
switch (majorVersion) {
case FMIMajorVersion1:
return sizeof(fmi1Boolean);
case FMIMajorVersion2:
return sizeof(fmi2Boolean);
case FMIMajorVersion3:
return sizeof(fmi3Boolean);
}

case FMIStringType:
return sizeof(fmi3String);

case FMIBinaryType:
return sizeof(fmi3Binary);

case FMIClockType:
return sizeof(fmi3Clock);

case FMIValueReferenceType:
return sizeof(FMIValueReference);

case FMISizeTType:
return sizeof(size_t);

default:
return 0;
}
}

FMIStatus FMISample(FMIInstance* instance, double time, FMIRecorder* recorder) {

FMIStatus status = FMIOK;
Expand Down Expand Up @@ -244,7 +179,7 @@ FMIStatus FMISample(FMIInstance* instance, double time, FMIRecorder* recorder) {

void* values = NULL;

CALL(FMICalloc(&values, info->nValues, FMISizeOfVariableType(recorder->instance->fmiMajorVersion, type)));
CALL(FMICalloc(&values, info->nValues, FMISizeOfVariableType(type, recorder->instance->fmiMajorVersion)));

CALL(FMIGetValues(recorder->instance, type, info->valueReferences, info->nVariables, row->sizes, values, info->nValues));

Expand Down Expand Up @@ -282,11 +217,9 @@ static void print_value(FILE* file, FMIVariableType type, void* value) {

switch (type) {
case FMIFloat32Type:
case FMIDiscreteFloat32Type:
fprintf(file, "%.7g", *((fmi3Float32*)value));
break;
case FMIFloat64Type:
case FMIDiscreteFloat64Type:
fprintf(file, "%.16g", *((fmi3Float64*)value));
break;
case FMIInt8Type:
Expand Down Expand Up @@ -383,7 +316,7 @@ FMIStatus FMIRecorderWriteCSV(FMIRecorder* recorder, FILE* file) {
}

const FMIVariableType type = (FMIVariableType)j;
const size_t size = FMISizeOfVariableType(FMIMajorVersion3, type);
const size_t size = FMISizeOfVariableType(type, FMIMajorVersion3);
char* value = (char*)row->values[j];

for (size_t k = 0; k < info->nVariables; k++) {
Expand Down
65 changes: 2 additions & 63 deletions fmusim/FMIStaticInput.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,67 +115,6 @@ void FMIFreeInput(FMIStaticInput* input) {
FMIFree((void**)&input);
}

static size_t FMISizeOf(FMIVariableType type, FMIMajorVersion fmiMajorVersion) {

switch (type) {

case FMIFloat32Type:
case FMIDiscreteFloat32Type:
return sizeof(fmi3Float32);

case FMIFloat64Type:
case FMIDiscreteFloat64Type:
return sizeof(fmi3Float64);

case FMIInt8Type:
return sizeof(fmi3Int8);

case FMIUInt8Type:
return sizeof(fmi3UInt8);

case FMIInt16Type:
return sizeof(fmi3Int16);

case FMIUInt16Type:
return sizeof(fmi3UInt16);

case FMIInt32Type:
return sizeof(fmi3Int32);

case FMIUInt32Type:
return sizeof(fmi3UInt32);

case FMIInt64Type:
return sizeof(fmi3Int64);

case FMIUInt64Type:
return sizeof(fmi3UInt64);

case FMIBooleanType:
switch (fmiMajorVersion) {
case FMIMajorVersion1:
return sizeof(fmi1Boolean);
case FMIMajorVersion2:
return sizeof(fmi2Boolean);
case FMIMajorVersion3:
return sizeof(fmi3Boolean);
}

case FMIClockType:
return sizeof(fmi3Clock);

case FMIValueReferenceType:
return sizeof(FMIValueReference);

case FMISizeTType:
return sizeof(size_t);

default:
return 0;
}

}

double FMINextInputEvent(const FMIStaticInput* input, double time) {

if (!input) {
Expand All @@ -201,13 +140,13 @@ double FMINextInputEvent(const FMIStaticInput* input, double time) {
const FMIVariableType type = variable->type;
const size_t nValues = input->nValues[j];

if (type == FMIFloat32Type || type == FMIFloat64Type) {
if (variable->variability == FMIContinuous) {
continue; // skip continuous variables
}

const void* values0 = input->values[i * input->nVariables + j];
const void* values1 = input->values[(i + 1) * input->nVariables + j];
const size_t size = FMISizeOf(type, input->fmiMajorVersion) * nValues;
const size_t size = FMISizeOfVariableType(type, input->fmiMajorVersion) * nValues;

if (memcmp(values0, values1, size)) {
return t1;
Expand Down
Loading

0 comments on commit 1b863b3

Please sign in to comment.