diff --git a/CMakeLists.txt b/CMakeLists.txt index 0711f963..f351b4b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,7 +88,7 @@ if (${FMI_VERSION} GREATER 1 OR "${FMI_TYPE}" STREQUAL "CS") endif () if (${FMI_VERSION} GREATER 2) - set (MODEL_NAMES ${MODEL_NAMES} LinearTransform StateSpace Clocks) + set (MODEL_NAMES ${MODEL_NAMES} StateSpace Clocks) endif () foreach (MODEL_NAME ${MODEL_NAMES}) diff --git a/LinearTransform/FMI3.xml b/LinearTransform/FMI3.xml deleted file mode 100644 index 1c11cab3..00000000 --- a/LinearTransform/FMI3.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/LinearTransform/buildDescription.xml b/LinearTransform/buildDescription.xml deleted file mode 100644 index 9eb477c7..00000000 --- a/LinearTransform/buildDescription.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/LinearTransform/config.h b/LinearTransform/config.h deleted file mode 100644 index d2867414..00000000 --- a/LinearTransform/config.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef config_h -#define config_h - -#include - -// define class name and unique id -#define MODEL_IDENTIFIER LinearTransform -#define INSTANTIATION_TOKEN "{D773325B-AB94-4630-BF85-643EB24FCB78}" - -#define CO_SIMULATION -#define MODEL_EXCHANGE - -#define SET_FLOAT64 -#define GET_UINT64 -#define SET_UINT64 -#define EVENT_UPDATE - -#define FIXED_SOLVER_STEP 1 -#define DEFAULT_STOP_TIME 10 - -#define M_MAX 5 -#define N_MAX 5 - -typedef enum { - vr_time, - vr_m, - vr_n, - vr_u, - vr_A, - vr_y -} ValueReference; - -typedef struct { - uint64_t m; - uint64_t n; - double u[N_MAX]; - double A[M_MAX][N_MAX]; - double y[M_MAX]; -} ModelData; - -#endif /* config_h */ diff --git a/LinearTransform/model.c b/LinearTransform/model.c deleted file mode 100644 index 43e15f74..00000000 --- a/LinearTransform/model.c +++ /dev/null @@ -1,146 +0,0 @@ -#include "config.h" -#include "model.h" - - -void setStartValues(ModelInstance *comp) { - - M(m) = 2; - M(n) = 2; - - // identity matrix - for (int i = 0; i < M_MAX; i++) { - for (int j = 0; j < N_MAX; j++) { - M(A)[i][j] = i == j ? 1 : 0; - }} - - for (int i = 0; i < M_MAX; i++) { - M(u)[i] = i + 1; - } - - for (int i = 0; i < N_MAX; i++) { - M(y)[i] = 0; - } - -} - -Status calculateValues(ModelInstance *comp) { - - // y = A * u - for (size_t i = 0; i < M(m); i++) { - M(y)[i] = 0; - for (size_t j = 0; j < M(n); j++) { - M(y)[i] += M(A)[i][j] * M(u)[j]; - } - } - - return OK; -} - -Status getFloat64(ModelInstance* comp, ValueReference vr, double values[], size_t nValues, size_t* index) { - - calculateValues(comp); - - switch (vr) { - case vr_time: - ASSERT_NVALUES(1); - values[(*index)++] = comp->time; - return OK; - case vr_u: - ASSERT_NVALUES(M(n)); - for (size_t i = 0; i < M(n); i++) { - values[(*index)++] = M(u)[i]; - } - return OK; - case vr_A: - ASSERT_NVALUES(M(m) * M(n)); - for (size_t i = 0; i < M(m); i++) - for (size_t j = 0; j < M(n); j++) { - values[(*index)++] = M(A)[i][j]; - } - return OK; - case vr_y: - ASSERT_NVALUES(1); - for (size_t i = 0; i < M(m); i++) { - values[(*index)++] = M(y)[i]; - } - return OK; - default: - logError(comp, "Get Float64 is not allowed for value reference %u.", vr); - return Error; - } -} - -Status setFloat64(ModelInstance* comp, ValueReference vr, const double values[], size_t nValues, size_t* index) { - - switch (vr) { - case vr_u: - ASSERT_NVALUES(M(n)); - for (size_t i = 0; i < M(n); i++) { - M(u)[i] = values[(*index)++]; - } - calculateValues(comp); - return OK; - case vr_A: - ASSERT_NVALUES(M(m) * M(n)); - for (size_t i = 0; i < M(m); i++) - for (size_t j = 0; j < M(n); j++) { - M(A)[i][j] = values[(*index)++]; - } - return OK; - default: - logError(comp, "Set Float64 is not allowed for value reference %u.", vr); - return Error; - } -} - -Status getUInt64(ModelInstance* comp, ValueReference vr, uint64_t values[], size_t nValues, size_t* index) { - - ASSERT_NVALUES(1); - - calculateValues(comp); - - switch (vr) { - case vr_m: - values[(*index)++] = M(m); - return OK; - case vr_n: - values[(*index)++] = M(n); - return OK; - default: - logError(comp, "Get UInt64 is not allowed for value reference %u.", vr); - return Error; - } -} - -Status setUInt64(ModelInstance* comp, ValueReference vr, const uint64_t values[], size_t nValues, size_t* index) { - - ASSERT_NVALUES(1); - - if (comp->state != ConfigurationMode && comp->state != ReconfigurationMode) { - logError(comp, "Structural variables can only be set in Configuration Mode or Reconfiguration Mode."); - return Error; - } - - const uint64_t v = values[(*index)++]; - - switch (vr) { - case vr_m: - if (v < 1 || v > M_MAX) return Error; - M(m) = v; - return OK; - case vr_n: - if (v < 1 || v > N_MAX) return Error; - M(n) = v; - return OK; - default: - logError(comp, "Set UInt64 is not allowed for value reference %u.", vr); - return Error; - } -} - -void eventUpdate(ModelInstance *comp) { - comp->valuesOfContinuousStatesChanged = false; - comp->nominalsOfContinuousStatesChanged = false; - comp->terminateSimulation = false; - comp->nextEventTimeDefined = false; -} diff --git a/LinearTransform/readme.md b/LinearTransform/readme.md deleted file mode 100644 index c90517e0..00000000 --- a/LinearTransform/readme.md +++ /dev/null @@ -1,7 +0,0 @@ -# LinearTransform - -Implements the equation - -``` -y' = u * A -``` diff --git a/examples/Examples.cmake b/examples/Examples.cmake index fdfe6a6f..9c3fcf0e 100644 --- a/examples/Examples.cmake +++ b/examples/Examples.cmake @@ -184,7 +184,7 @@ elseif(${FMI_VERSION} EQUAL 2) set(MODEL_NAMES ${MODEL_NAMES} Resource) set(INTERFACE_TYPES cs me) else() - set(MODEL_NAMES ${MODEL_NAMES} LinearTransform Resource) + set(MODEL_NAMES ${MODEL_NAMES} Resource StateSpace) set(INTERFACE_TYPES cs me) endif() diff --git a/examples/LinearTransform.c b/examples/StateSpace.c similarity index 66% rename from examples/LinearTransform.c rename to examples/StateSpace.c index 76df365c..34c80962 100644 --- a/examples/LinearTransform.c +++ b/examples/StateSpace.c @@ -8,7 +8,7 @@ FILE *createOutputFile(const char *filename) { FILE *file = fopen(filename, "w"); if (file) { - fputs("time,y[1],y[2]\n", file); + fputs("time,y\n", file); } return file; @@ -18,11 +18,11 @@ FMIStatus recordVariables(FMIInstance *S, FILE *outputFile) { const fmi3ValueReference valueReferences[1] = { vr_y }; - fmi3Float64 values[2] = { 0 }; + fmi3Float64 values[3] = { 0 }; - FMIStatus status = FMI3GetFloat64((FMIInstance *)S, valueReferences, 1, values, 2); + FMIStatus status = FMI3GetFloat64((FMIInstance *)S, valueReferences, 1, values, 3); - fprintf(outputFile, "%g,%g,%g\n", ((FMIInstance *)S)->time, values[0], values[1]); + fprintf(outputFile, "%g,%g %g %g\n", ((FMIInstance *)S)->time, values[0], values[1], values[2]); return status; }