Skip to content
This repository was archived by the owner on Feb 12, 2020. It is now read-only.

Commit 93110f2

Browse files
committed
Merge branch 'release/v0.0.2'
2 parents d6a7910 + 810f369 commit 93110f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2720
-2928
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ fmi1_cs/
55
fmi1_me/
66
fmi2/
77
fmi3/
8+
fmus/
9+
*.fmu
10+
*.zip

BouncingBall/FMI1CS.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<?xml version="1.0" encoding="ISO-8859-1"?>
2-
<fmiModelDescription fmiVersion="1.0" modelName="BouncingBall" modelIdentifier="BouncingBall" guid="{8c4e810f-3df3-4a00-8276-176fa3c9f003}" numberOfContinuousStates="2" numberOfEventIndicators="1">
2+
<fmiModelDescription
3+
fmiVersion="1.0"
4+
modelName="BouncingBall"
5+
modelIdentifier="BouncingBall"
6+
description="This model calculates the trajectory, over time, of a ball dropped from a height of 1 m."
7+
guid="{8c4e810f-3df3-4a00-8276-176fa3c9f003}"
8+
numberOfContinuousStates="2"
9+
numberOfEventIndicators="1">
310

411
<DefaultExperiment startTime="0" stopTime="3"/>
512

BouncingBall/FMI1ME.xml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
<?xml version="1.0" encoding="ISO-8859-1"?>
2-
<fmiModelDescription fmiVersion="1.0" modelName="BouncingBall" modelIdentifier="BouncingBall" guid="{8c4e810f-3df3-4a00-8276-176fa3c9f003}" numberOfContinuousStates="2" numberOfEventIndicators="1">
2+
<fmiModelDescription
3+
fmiVersion="1.0"
4+
modelName="BouncingBall"
5+
modelIdentifier="BouncingBall"
6+
description="This model calculates the trajectory, over time, of a ball dropped from a height of 1 m."
7+
guid="{8c4e810f-3df3-4a00-8276-176fa3c9f003}"
8+
numberOfContinuousStates="2"
9+
numberOfEventIndicators="1">
310

411
<DefaultExperiment startTime="0" stopTime="3"/>
512

613
<ModelVariables>
714
<ScalarVariable name="h" valueReference="0" causality="output" description="Height">
8-
<Real start="1" fixed="true"/>
15+
<Real start="1"/>
916
</ScalarVariable>
1017
<ScalarVariable name="v" valueReference="1" causality="output" description="Velocity">
11-
<Real/>
18+
<Real start="0"/>
1219
</ScalarVariable>
13-
<ScalarVariable name="g" valueReference="2" description="Gravity" variability="parameter">
20+
<ScalarVariable name="g" valueReference="2" variability="parameter" description="Gravity">
1421
<Real start="-9.81" fixed="true"/>
1522
</ScalarVariable>
16-
<ScalarVariable name="e" valueReference="3" description="Rebound factor" variability="parameter">
23+
<ScalarVariable name="e" valueReference="3" variability="parameter" description="Coefficient of restitution">
1724
<Real start="0.7"/>
1825
</ScalarVariable>
1926
</ModelVariables>

BouncingBall/FMI2.xml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
<?xml version="1.0" encoding="ISO-8859-1"?>
2-
<fmiModelDescription fmiVersion="2.0" modelName="BouncingBall" guid="{8c4e810f-3df3-4a00-8276-176fa3c9f003}" numberOfEventIndicators="1">
2+
<fmiModelDescription
3+
fmiVersion="2.0"
4+
modelName="BouncingBall"
5+
description="This model calculates the trajectory, over time, of a ball dropped from a height of 1 m."
6+
guid="{8c4e810f-3df3-4a00-8276-176fa3c9f003}"
7+
numberOfEventIndicators="1">
38

49
<ModelExchange modelIdentifier="BouncingBall">
510
<SourceFiles>
6-
<File name="fmi2.c"/>
7-
<File name="euler.c"/>
8-
<File name="model.c"/>
9-
<File name="slave.c"/>
11+
<File name="all.c"/>
1012
</SourceFiles>
1113
</ModelExchange>
1214

1315
<CoSimulation modelIdentifier="BouncingBall" canHandleVariableCommunicationStepSize="true">
1416
<SourceFiles>
15-
<File name="fmi2.c"/>
16-
<File name="euler.c"/>
17-
<File name="model.c"/>
18-
<File name="slave.c"/>
17+
<File name="all.c"/>
1918
</SourceFiles>
2019
</CoSimulation>
2120

22-
<!-- <LogCategories> <Category name="logAll"/> <Category name="logError"/> <Category name="logFmiCall"/> <Category name="logEvent"/> </LogCategories> -->
23-
2421
<UnitDefinitions>
2522
<Unit name="m">
2623
<BaseUnit m="1"/>
@@ -45,22 +42,27 @@
4542
</SimpleType>
4643
</TypeDefinitions>
4744

48-
<DefaultExperiment startTime="0" stopTime="3"/>
45+
<LogCategories>
46+
<Category name="logEvents" description="Log events"/>
47+
<Category name="logStatusError" description="Log error messages"/>
48+
</LogCategories>
49+
50+
<DefaultExperiment startTime="0" stopTime="3" stepSize="1e-3"/>
4951

5052
<ModelVariables>
51-
<ScalarVariable name="h" valueReference="0" description="Position of the ball" causality="output" variability="continuous" initial="exact">
53+
<ScalarVariable name="h" valueReference="0" causality="output" variability="continuous" initial="exact" description="Position of the ball">
5254
<Real start="1" declaredType="Position"/>
5355
</ScalarVariable>
54-
<ScalarVariable name="v" valueReference="1" description="Velocity of the ball" causality="output" variability="continuous" initial="exact">
56+
<ScalarVariable name="v" valueReference="1" causality="output" variability="continuous" initial="exact" description="Velocity of the ball">
5557
<Real start="0" derivative="1" reinit="true" declaredType="Velocity"/>
5658
</ScalarVariable>
57-
<ScalarVariable name="g" valueReference="2" description="Gravity acting on the ball" causality="parameter" variability="fixed" initial="exact">
59+
<ScalarVariable name="g" valueReference="2" causality="parameter" variability="fixed" initial="exact" description="Gravity acting on the ball">
5860
<Real start="-9.81" derivative="2" declaredType="Acceleration"/>
5961
</ScalarVariable>
60-
<ScalarVariable name="e" valueReference="3" description="Rebound factor" causality="parameter" variability="tunable" initial="exact">
62+
<ScalarVariable name="e" valueReference="3" causality="parameter" variability="tunable" initial="exact" description="Coefficient of restitution">
6163
<Real start="0.7" min="0.5" max="1"/>
6264
</ScalarVariable>
63-
<ScalarVariable name="v_min" valueReference="4" description="Velocity below which the ball stops bouncing" causality="parameter" variability="constant">
65+
<ScalarVariable name="v_min" valueReference="4" variability="constant" description="Velocity below which the ball stops bouncing">
6466
<Real start="0.1" declaredType="Velocity"/>
6567
</ScalarVariable>
6668
</ModelVariables>

BouncingBall/FMI3.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,22 @@
33

44
<ModelExchange modelIdentifier="BouncingBall">
55
<SourceFiles>
6-
<File name="BouncingBall.c"/>
6+
<File name="all.c"/>
77
</SourceFiles>
88
</ModelExchange>
99

1010
<CoSimulation modelIdentifier="BouncingBall" canHandleVariableCommunicationStepSize="true">
1111
<SourceFiles>
12-
<File name="BouncingBall.c"/>
12+
<File name="all.c"/>
1313
</SourceFiles>
1414
</CoSimulation>
1515

1616
<LogCategories>
17-
<Category name="logAll"/>
18-
<Category name="logError"/>
19-
<Category name="logFmiCall"/>
20-
<Category name="logEvent"/>
17+
<Category name="logEvents" description="Log events"/>
18+
<Category name="logStatusError" description="Log error messages"/>
2119
</LogCategories>
2220

23-
<DefaultExperiment startTime="0" stopTime="3"/>
21+
<DefaultExperiment startTime="0" stopTime="3" stepSize="1e-3"/>
2422

2523
<ModelVariables>
2624
<Float64 name="h" valueReference="0" description="height, used as state" causality="output" variability="continuous" initial="exact" start="1"/>

BouncingBall/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#define SET_FLOAT64
1414
#define EVENT_UPDATE
1515

16+
#define FIXED_SOLVER_STEP 1e-3
17+
1618
typedef enum {
1719
vr_h, vr_v, vr_g, vr_e, vr_v_min
1820
} ValueReference;

BouncingBall/model.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ Status getFloat64(ModelInstance* comp, ValueReference vr, double *value, size_t
4242

4343
Status setFloat64(ModelInstance* comp, ValueReference vr, const double *value, size_t *index) {
4444
switch (vr) {
45-
45+
4646
case vr_h:
4747
M(h) = value[(*index)++];
4848
return OK;
49-
49+
5050
case vr_v:
5151
M(v) = value[(*index)++];
5252
return OK;
53-
53+
5454
case vr_g:
5555
#if FMI_VERSION > 1
5656
if (comp->type == ModelExchange &&
@@ -62,7 +62,7 @@ Status setFloat64(ModelInstance* comp, ValueReference vr, const double *value, s
6262
#endif
6363
M(g) = value[(*index)++];
6464
return OK;
65-
65+
6666
case vr_e:
6767
#if FMI_VERSION > 1
6868
if (comp->type == ModelExchange &&
@@ -75,8 +75,13 @@ Status setFloat64(ModelInstance* comp, ValueReference vr, const double *value, s
7575
#endif
7676
M(e) = value[(*index)++];
7777
return OK;
78-
78+
79+
case vr_v_min:
80+
logError(comp, "Variable v_min (value reference %d) is constant and cannot be set.", vr_v_min);
81+
return Error;
82+
7983
default:
84+
logError(comp, "Unexpected value reference: %.", vr);
8085
return Error;
8186
}
8287
}

CMakeLists.txt

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (${FMI_VERSION} GREATER 1)
1717
set(FMI_TYPE "")
1818
endif ()
1919

20-
if (WIN32)
20+
if (MSVC)
2121
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
2222
string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
2323
endif ()
@@ -58,6 +58,13 @@ endif ()
5858

5959
MESSAGE("FMI_PLATFORM: " ${FMI_PLATFORM})
6060

61+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/all.c" "#define FMI_VERSION ${FMI_VERSION}
62+
63+
#include \"fmi${FMI_VERSION}Functions.c\"
64+
#include \"model.c\"
65+
#include \"slave.c\"
66+
")
67+
6168
set (MODEL_NAMES BouncingBall Dahlquist Stair Feedthrough VanDerPol)
6269

6370
if (${FMI_VERSION} GREATER 1 OR "${FMI_TYPE}" STREQUAL "CS")
@@ -75,13 +82,11 @@ set(TARGET_NAME ${MODEL_NAME})
7582
SET(HEADERS
7683
${MODEL_NAME}/config.h
7784
include/model.h
78-
include/solver.h
7985
)
8086

8187
SET(SOURCES
8288
${MODEL_NAME}/model.c
83-
src/fmi${FMI_VERSION}.c
84-
src/euler.c
89+
src/fmi${FMI_VERSION}Functions.c
8590
src/slave.c
8691
)
8792

@@ -93,7 +98,11 @@ add_library(${TARGET_NAME} SHARED
9398

9499
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist)
95100

96-
target_compile_definitions(${TARGET_NAME} PRIVATE DISABLE_PREFIX FMI_VERSION=${FMI_VERSION})
101+
target_compile_definitions(${TARGET_NAME} PRIVATE
102+
_CRT_SECURE_NO_WARNINGS
103+
DISABLE_PREFIX
104+
FMI_VERSION=${FMI_VERSION}
105+
)
97106

98107
if (${FMI_VERSION} EQUAL 1 AND "${FMI_TYPE}" STREQUAL CS)
99108
target_compile_definitions(${TARGET_NAME} PRIVATE FMI_COSIMULATION)
@@ -163,21 +172,27 @@ add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E
163172
)
164173

165174
# common headers
166-
foreach (SOURCE_FILE model.h slave.h solver.h)
175+
foreach (SOURCE_FILE model.h slave.h)
167176
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
168177
"${CMAKE_CURRENT_SOURCE_DIR}/include/${SOURCE_FILE}"
169178
"${FMU_BUILD_DIR}/sources/${SOURCE_FILE}"
170179
)
171180
endforeach(SOURCE_FILE)
172181

173182
# common sources
174-
foreach (SOURCE_FILE fmi${FMI_VERSION}.c euler.c slave.c)
183+
foreach (SOURCE_FILE fmi${FMI_VERSION}Functions.c slave.c)
175184
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
176185
"${CMAKE_CURRENT_SOURCE_DIR}/src/${SOURCE_FILE}"
177186
"${FMU_BUILD_DIR}/sources/${SOURCE_FILE}"
178187
)
179188
endforeach(SOURCE_FILE)
180189

190+
# all.c
191+
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
192+
"${CMAKE_CURRENT_BINARY_DIR}/all.c"
193+
"${FMU_BUILD_DIR}/sources/all.c"
194+
)
195+
181196
set(ARCHIVE_FILES "modelDescription.xml" "binaries" "documentation" "sources")
182197

183198
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${MODEL_NAME}/resources")

Dahlquist/FMI1CS.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<?xml version="1.0" encoding="ISO-8859-1"?>
2-
<fmiModelDescription fmiVersion="1.0" modelName="Dahlquist" modelIdentifier="Dahlquist" guid="{8c4e810f-3df3-4a00-8276-176fa3c9f000}" numberOfContinuousStates="1" numberOfEventIndicators="0">
2+
<fmiModelDescription
3+
fmiVersion="1.0"
4+
modelName="Dahlquist"
5+
modelIdentifier="Dahlquist"
6+
description="This model implements the Dahlquist test equation."
7+
guid="{8c4e810f-3df3-4a00-8276-176fa3c9f000}"
8+
numberOfContinuousStates="1"
9+
numberOfEventIndicators="0">
310

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

Dahlquist/FMI1ME.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<?xml version="1.0" encoding="ISO-8859-1"?>
2-
<fmiModelDescription fmiVersion="1.0" modelName="Dahlquist" modelIdentifier="Dahlquist" guid="{8c4e810f-3df3-4a00-8276-176fa3c9f000}" numberOfContinuousStates="1" numberOfEventIndicators="0">
2+
<fmiModelDescription
3+
fmiVersion="1.0"
4+
modelName="Dahlquist"
5+
modelIdentifier="Dahlquist"
6+
description="This model implements the Dahlquist test equation."
7+
guid="{8c4e810f-3df3-4a00-8276-176fa3c9f000}"
8+
numberOfContinuousStates="1"
9+
numberOfEventIndicators="0">
310

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

0 commit comments

Comments
 (0)