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

Extend LinearTransform to StateSpace #433

Merged
merged 5 commits into from
Dec 6, 2023
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: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ if (${FMI_VERSION} GREATER 1 OR "${FMI_TYPE}" STREQUAL "CS")
endif ()

if (${FMI_VERSION} GREATER 2)
set (MODEL_NAMES ${MODEL_NAMES} LinearTransform Clocks)
set (MODEL_NAMES ${MODEL_NAMES} StateSpace Clocks)
endif ()

foreach (MODEL_NAME ${MODEL_NAMES})
Expand Down
51 changes: 0 additions & 51 deletions LinearTransform/FMI3.xml

This file was deleted.

149 changes: 0 additions & 149 deletions LinearTransform/model.c

This file was deleted.

7 changes: 0 additions & 7 deletions LinearTransform/readme.md

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ A set of hand-coded FMUs for development, testing and debugging of the [Function
- [BouncingBall](BouncingBall) - a bouncing ball model with state events
- [Dahlquist](Dahlquist) - Dahlquist test equation
- [Feedthrough](Feedthrough) - all variable types
- [LinearTransform](LinearTransform) - arrays and structural parameters
- [Resource](Resource) - load data from a file
- [Stair](Stair) - a counter with time events
- [StateSpace](StateSpace) - arrays and structural parameters
- [VanDerPol](VanDerPol) - Van der Pol test equation

Use the [fmusim](fmusim) executable to simulate an FMU:
Expand Down Expand Up @@ -96,7 +96,7 @@ To build the `fmusim` executable, run the `ThirdParty/build_*.py` Python scripts

## License and attribution

Copyright © 2022, Modelica Association Project "FMI".
Copyright © 2023, Modelica Association Project "FMI".
All rights reserved.
The code is released under the [2-Clause BSD License](LICENSE.txt).

Expand Down
76 changes: 76 additions & 0 deletions StateSpace/FMI3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<fmiModelDescription
fmiVersion="3.0"
modelName="StateSpace"
generationTool="Reference FMUs (development build)"
instantiationToken="{D773325B-AB94-4630-BF85-643EB24FCB78}">

<ModelExchange
modelIdentifier="StateSpace"
canGetAndSetFMUState="true"
canSerializeFMUState="true"/>

<CoSimulation
modelIdentifier="StateSpace"
canGetAndSetFMUState="true"
canSerializeFMUState="true"
canHandleVariableCommunicationStepSize="true"
providesIntermediateUpdate="true"
canReturnEarlyAfterIntermediateUpdate="true"
fixedInternalStepSize="1"
hasEventMode="true"/>

<LogCategories>
<Category name="logEvents" description="Log events"/>
<Category name="logStatusError" description="Log error messages"/>
</LogCategories>

<DefaultExperiment startTime="0" stopTime="10"/>

<ModelVariables>
<Float64 name="time" valueReference="0" causality="independent" variability="continuous" description="Simulation time"/>
<UInt64 name="m" valueReference="1" description="Number of inputs" causality="structuralParameter" variability="tunable" start="3" min="0" max="5"/>
<UInt64 name="n" valueReference="2" description="Number of states" causality="structuralParameter" variability="tunable" start="3" min="0" max="5"/>
<UInt64 name="r" valueReference="3" description="Number of outputs" causality="structuralParameter" variability="tunable" start="3" min="0" max="5"/>
<Float64 name="A" valueReference="4" description="Matrix coefficient A" causality="parameter" variability="tunable" start="1 0 0 0 1 0 0 0 1">
<Dimension valueReference="2"/>
<Dimension valueReference="2"/>
</Float64>
<Float64 name="B" valueReference="5" description="Matrix coefficient B" causality="parameter" variability="tunable" start="1 0 0 0 1 0 0 0 1">
<Dimension valueReference="2"/>
<Dimension valueReference="1"/>
</Float64>
<Float64 name="C" valueReference="6" description="Matrix coefficient C" causality="parameter" variability="tunable" start="1 0 0 0 1 0 0 0 1">
<Dimension valueReference="3"/>
<Dimension valueReference="2"/>
</Float64>
<Float64 name="D" valueReference="7" description="Matrix coefficient D" causality="parameter" variability="tunable" start="1 0 0 0 1 0 0 0 1">
<Dimension valueReference="3"/>
<Dimension valueReference="1"/>
</Float64>
<Float64 name="x0" valueReference="8" description="Initial state vector" causality="parameter" variability="tunable" start="0 0 0">
<Dimension valueReference="2"/>
</Float64>
<Float64 name="u" valueReference="9" description="Input vector" causality="input" start="1 2 3">
<Dimension valueReference="1"/>
</Float64>
<Float64 name="y" valueReference="10" description="Output vector" causality="output">
<Dimension valueReference="3"/>
</Float64>
<Float64 name="x" valueReference="11" description="State vector" causality="local">
<Dimension valueReference="2"/>
</Float64>
<Float64 name="der(x)" valueReference="12" description="Derivative of the state vector" causality="local" derivative="11">
<Dimension valueReference="2"/>
</Float64>
</ModelVariables>

<ModelStructure>
<Output valueReference="10"/>
<ContinuousStateDerivative valueReference="12"/>
<InitialUnknown valueReference="10"/>
<InitialUnknown valueReference="11"/>
<InitialUnknown valueReference="12"/>
</ModelStructure>

</fmiModelDescription>
File renamed without changes.
29 changes: 23 additions & 6 deletions LinearTransform/config.h → StateSpace/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#include <stdint.h>

// define class name and unique id
#define MODEL_IDENTIFIER LinearTransform
#define MODEL_IDENTIFIER StateSpace
#define INSTANTIATION_TOKEN "{D773325B-AB94-4630-BF85-643EB24FCB78}"

#define HAS_CONTINUOUS_STATES

#define CO_SIMULATION
#define MODEL_EXCHANGE

Expand All @@ -15,27 +17,42 @@
#define SET_UINT64
#define EVENT_UPDATE

#define FIXED_SOLVER_STEP 1
#define FIXED_SOLVER_STEP 1e-3
#define DEFAULT_STOP_TIME 10

#define M_MAX 5
#define N_MAX 5
#define R_MAX 5

typedef enum {
vr_time,
vr_m,
vr_n,
vr_u,
vr_r,
vr_A,
vr_y
vr_B,
vr_C,
vr_D,
vr_x0,
vr_u,
vr_y,
vr_x,
vr_der_x
} ValueReference;

typedef struct {
uint64_t m;
uint64_t n;
double u[N_MAX];
uint64_t r;
double A[M_MAX][N_MAX];
double y[M_MAX];
double B[M_MAX][N_MAX];
double C[M_MAX][N_MAX];
double D[M_MAX][N_MAX];
double x0[N_MAX];
double u[N_MAX];
double y[N_MAX];
double x[N_MAX];
double der_x[N_MAX];
} ModelData;

#endif /* config_h */
Loading