diff --git a/fmusim-gui/AbstractModelVariablesModel.cpp b/fmusim-gui/AbstractModelVariablesModel.cpp index 614c3169..89a69703 100644 --- a/fmusim-gui/AbstractModelVariablesModel.cpp +++ b/fmusim-gui/AbstractModelVariablesModel.cpp @@ -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"; diff --git a/fmusim-gui/PlotUtil.cpp b/fmusim-gui/PlotUtil.cpp index 6832d6ee..213183e4 100644 --- a/fmusim-gui/PlotUtil.cpp +++ b/fmusim-gui/PlotUtil.cpp @@ -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]); diff --git a/fmusim/FMIModelDescription.c b/fmusim/FMIModelDescription.c index c0c7379b..025679f4 100644 --- a/fmusim/FMIModelDescription.c +++ b/fmusim/FMIModelDescription.c @@ -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")) { @@ -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++; } @@ -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")) { @@ -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++; } @@ -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")) { diff --git a/fmusim/FMIRecorder.c b/fmusim/FMIRecorder.c index 98af2ad1..19bb770c 100644 --- a/fmusim/FMIRecorder.c +++ b/fmusim/FMIRecorder.c @@ -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; @@ -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)); @@ -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: @@ -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++) { diff --git a/fmusim/FMIStaticInput.c b/fmusim/FMIStaticInput.c index 8081306f..d0b3e5a7 100644 --- a/fmusim/FMIStaticInput.c +++ b/fmusim/FMIStaticInput.c @@ -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) { @@ -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; diff --git a/fmusim/FMIUtil.c b/fmusim/FMIUtil.c index d9fe4f14..41991346 100644 --- a/fmusim/FMIUtil.c +++ b/fmusim/FMIUtil.c @@ -25,7 +25,6 @@ FMIStatus FMIGetValues( switch (type) { case FMIRealType: - case FMIDiscreteRealType: return FMI1GetReal(instance, valueReferences, nValueReferences, (fmi1Real*)values); case FMIIntegerType: return FMI1GetInteger(instance, valueReferences, nValueReferences, (fmi1Integer*)values); @@ -43,7 +42,6 @@ FMIStatus FMIGetValues( switch (type) { case FMIRealType: - case FMIDiscreteRealType: return FMI2GetReal(instance, valueReferences, nValueReferences, (fmi2Real*)values); case FMIIntegerType: return FMI2GetInteger(instance, valueReferences, nValueReferences, (fmi2Integer*)values); @@ -61,10 +59,8 @@ FMIStatus FMIGetValues( switch (type) { case FMIFloat32Type: - case FMIDiscreteFloat32Type: return FMI3GetFloat32(instance, valueReferences, nValueReferences, (fmi3Float32*)values, nValues); case FMIFloat64Type: - case FMIDiscreteFloat64Type: return FMI3GetFloat64(instance, valueReferences, nValueReferences, (fmi3Float64*)values, nValues); case FMIInt8Type: return FMI3GetInt8(instance, valueReferences, nValueReferences, (fmi3Int8*)values, nValues); @@ -176,7 +172,6 @@ FMIStatus FMISetValues( switch (type) { case FMIRealType: - case FMIDiscreteRealType: return FMI1SetReal(instance, valueReferences, nValueReferences, (fmi1Real*)values); case FMIIntegerType: return FMI1SetInteger(instance, valueReferences, nValueReferences, (fmi1Integer*)values); @@ -194,7 +189,6 @@ FMIStatus FMISetValues( switch (type) { case FMIRealType: - case FMIDiscreteRealType: return FMI2SetReal(instance, valueReferences, nValueReferences, (fmi2Real*)values); case FMIIntegerType: return FMI2SetInteger(instance, valueReferences, nValueReferences, (fmi2Integer*)values); @@ -212,10 +206,8 @@ FMIStatus FMISetValues( switch (type) { case FMIFloat32Type: - case FMIDiscreteFloat32Type: return FMI3SetFloat32(instance, valueReferences, nValueReferences, (fmi3Float32*)values, nValues); case FMIFloat64Type: - case FMIDiscreteFloat64Type: return FMI3SetFloat64(instance, valueReferences, nValueReferences, (fmi3Float64*)values, nValues); case FMIInt8Type: return FMI3SetInt8(instance, valueReferences, nValueReferences, (fmi3Int8*)values, nValues); @@ -265,6 +257,34 @@ FMIStatus FMISetValues( (*nValues)++; \ } +size_t FMISizeOfVariableType(FMIVariableType type, FMIMajorVersion majorVersion) { + + switch (type) { + case FMIFloat32Type: return sizeof(fmi3Float32); + case FMIFloat64Type: 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 FMIParseValues(FMIMajorVersion fmiMajorVersion, FMIVariableType type, const char* literal, size_t* nValues, void** values) { FMIStatus status = FMIOK; @@ -281,11 +301,9 @@ FMIStatus FMIParseValues(FMIMajorVersion fmiMajorVersion, FMIVariableType type, switch (type) { case FMIFloat32Type: - case FMIDiscreteFloat32Type: PARSE_VALUES(fmi3Float32, strtof); break; case FMIFloat64Type: - case FMIDiscreteFloat64Type: PARSE_VALUES(fmi3Float64, strtod); break; case FMIInt8Type: @@ -397,7 +415,7 @@ FMIStatus FMIParseValues(FMIMajorVersion fmiMajorVersion, FMIVariableType type, char* next = (char*)literal; - if (type == FMIFloat32Type || type == FMIDiscreteFloat32Type) { + if (type == FMIFloat32Type) { fmi3Float32* v = (fmi3Float32*)values; @@ -405,7 +423,7 @@ FMIStatus FMIParseValues(FMIMajorVersion fmiMajorVersion, FMIVariableType type, v[i] = strtof(next, &next); } - } else if (type == FMIFloat64Type || type == FMIDiscreteFloat64Type) { + } else if (type == FMIFloat64Type) { fmi3Float64* v = (fmi3Float64*)values; diff --git a/fmusim/FMIUtil.h b/fmusim/FMIUtil.h index bedde332..21855963 100644 --- a/fmusim/FMIUtil.h +++ b/fmusim/FMIUtil.h @@ -33,6 +33,8 @@ FMIStatus FMIGetNumberOfUnkownValues( const FMIUnknown* unknowns[], size_t* nValues); +size_t FMISizeOfVariableType(FMIVariableType type, FMIMajorVersion majorVersion); + FMIStatus FMIParseValues(FMIMajorVersion fmiMajorVersion, FMIVariableType type, const char* literal, size_t* nValues, void** values); FMIStatus FMIParseStartValues(FMIVariableType type, const char* literal, size_t nValues, void* values); diff --git a/include/FMI.h b/include/FMI.h index 35759e53..9c083ba9 100644 --- a/include/FMI.h +++ b/include/FMI.h @@ -72,9 +72,9 @@ typedef enum { // FMI 3.0 variable types FMIFloat32Type, - FMIDiscreteFloat32Type, + //FMIDiscreteFloat32Type, FMIFloat64Type, - FMIDiscreteFloat64Type, + //FMIDiscreteFloat64Type, FMIInt8Type, FMIUInt8Type, FMIInt16Type, @@ -94,7 +94,7 @@ typedef enum { // aliases for FMI 1.0 and 2.0 variable types FMIRealType = FMIFloat64Type, - FMIDiscreteRealType = FMIDiscreteFloat64Type, + //FMIDiscreteRealType = FMIDiscreteFloat64Type, FMIIntegerType = FMIInt32Type, } FMIVariableType; diff --git a/src/FMI.c b/src/FMI.c index 66cf37da..17865c93 100644 --- a/src/FMI.c +++ b/src/FMI.c @@ -235,11 +235,9 @@ void FMIAppendArrayToLogMessageBuffer(FMIInstance* instance, const void* values, switch (variableType) { case FMIFloat32Type: - case FMIDiscreteFloat32Type: length = snprintf(s, n, "%.7g", ((float*)values)[i]); break; case FMIFloat64Type: - case FMIDiscreteFloat64Type: length = snprintf(s, n, "%.16g", ((double*)values)[i]); break; case FMIInt8Type: diff --git a/tests/test_fmusim.py b/tests/test_fmusim.py index b1be1aa9..6872b86e 100644 --- a/tests/test_fmusim.py +++ b/tests/test_fmusim.py @@ -351,7 +351,6 @@ def test_event_mode_input_events(platform): '--stop-time', '5', '--output-interval', '2.5', '--input-file', input_file, - '--event-mode-used' ], model='Feedthrough.fmu' )