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

Commit

Permalink
Merge branch 'release/v0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sommer committed Jun 24, 2019
2 parents d6a7910 + 810f369 commit 93110f2
Show file tree
Hide file tree
Showing 49 changed files with 2,720 additions and 2,928 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ fmi1_cs/
fmi1_me/
fmi2/
fmi3/
fmus/
*.fmu
*.zip
9 changes: 8 additions & 1 deletion BouncingBall/FMI1CS.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiModelDescription fmiVersion="1.0" modelName="BouncingBall" modelIdentifier="BouncingBall" guid="{8c4e810f-3df3-4a00-8276-176fa3c9f003}" numberOfContinuousStates="2" numberOfEventIndicators="1">
<fmiModelDescription
fmiVersion="1.0"
modelName="BouncingBall"
modelIdentifier="BouncingBall"
description="This model calculates the trajectory, over time, of a ball dropped from a height of 1 m."
guid="{8c4e810f-3df3-4a00-8276-176fa3c9f003}"
numberOfContinuousStates="2"
numberOfEventIndicators="1">

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

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

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

<ModelVariables>
<ScalarVariable name="h" valueReference="0" causality="output" description="Height">
<Real start="1" fixed="true"/>
<Real start="1"/>
</ScalarVariable>
<ScalarVariable name="v" valueReference="1" causality="output" description="Velocity">
<Real/>
<Real start="0"/>
</ScalarVariable>
<ScalarVariable name="g" valueReference="2" description="Gravity" variability="parameter">
<ScalarVariable name="g" valueReference="2" variability="parameter" description="Gravity">
<Real start="-9.81" fixed="true"/>
</ScalarVariable>
<ScalarVariable name="e" valueReference="3" description="Rebound factor" variability="parameter">
<ScalarVariable name="e" valueReference="3" variability="parameter" description="Coefficient of restitution">
<Real start="0.7"/>
</ScalarVariable>
</ModelVariables>
Expand Down
36 changes: 19 additions & 17 deletions BouncingBall/FMI2.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiModelDescription fmiVersion="2.0" modelName="BouncingBall" guid="{8c4e810f-3df3-4a00-8276-176fa3c9f003}" numberOfEventIndicators="1">
<fmiModelDescription
fmiVersion="2.0"
modelName="BouncingBall"
description="This model calculates the trajectory, over time, of a ball dropped from a height of 1 m."
guid="{8c4e810f-3df3-4a00-8276-176fa3c9f003}"
numberOfEventIndicators="1">

<ModelExchange modelIdentifier="BouncingBall">
<SourceFiles>
<File name="fmi2.c"/>
<File name="euler.c"/>
<File name="model.c"/>
<File name="slave.c"/>
<File name="all.c"/>
</SourceFiles>
</ModelExchange>

<CoSimulation modelIdentifier="BouncingBall" canHandleVariableCommunicationStepSize="true">
<SourceFiles>
<File name="fmi2.c"/>
<File name="euler.c"/>
<File name="model.c"/>
<File name="slave.c"/>
<File name="all.c"/>
</SourceFiles>
</CoSimulation>

<!-- <LogCategories> <Category name="logAll"/> <Category name="logError"/> <Category name="logFmiCall"/> <Category name="logEvent"/> </LogCategories> -->

<UnitDefinitions>
<Unit name="m">
<BaseUnit m="1"/>
Expand All @@ -45,22 +42,27 @@
</SimpleType>
</TypeDefinitions>

<DefaultExperiment startTime="0" stopTime="3"/>
<LogCategories>
<Category name="logEvents" description="Log events"/>
<Category name="logStatusError" description="Log error messages"/>
</LogCategories>

<DefaultExperiment startTime="0" stopTime="3" stepSize="1e-3"/>

<ModelVariables>
<ScalarVariable name="h" valueReference="0" description="Position of the ball" causality="output" variability="continuous" initial="exact">
<ScalarVariable name="h" valueReference="0" causality="output" variability="continuous" initial="exact" description="Position of the ball">
<Real start="1" declaredType="Position"/>
</ScalarVariable>
<ScalarVariable name="v" valueReference="1" description="Velocity of the ball" causality="output" variability="continuous" initial="exact">
<ScalarVariable name="v" valueReference="1" causality="output" variability="continuous" initial="exact" description="Velocity of the ball">
<Real start="0" derivative="1" reinit="true" declaredType="Velocity"/>
</ScalarVariable>
<ScalarVariable name="g" valueReference="2" description="Gravity acting on the ball" causality="parameter" variability="fixed" initial="exact">
<ScalarVariable name="g" valueReference="2" causality="parameter" variability="fixed" initial="exact" description="Gravity acting on the ball">
<Real start="-9.81" derivative="2" declaredType="Acceleration"/>
</ScalarVariable>
<ScalarVariable name="e" valueReference="3" description="Rebound factor" causality="parameter" variability="tunable" initial="exact">
<ScalarVariable name="e" valueReference="3" causality="parameter" variability="tunable" initial="exact" description="Coefficient of restitution">
<Real start="0.7" min="0.5" max="1"/>
</ScalarVariable>
<ScalarVariable name="v_min" valueReference="4" description="Velocity below which the ball stops bouncing" causality="parameter" variability="constant">
<ScalarVariable name="v_min" valueReference="4" variability="constant" description="Velocity below which the ball stops bouncing">
<Real start="0.1" declaredType="Velocity"/>
</ScalarVariable>
</ModelVariables>
Expand Down
12 changes: 5 additions & 7 deletions BouncingBall/FMI3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@

<ModelExchange modelIdentifier="BouncingBall">
<SourceFiles>
<File name="BouncingBall.c"/>
<File name="all.c"/>
</SourceFiles>
</ModelExchange>

<CoSimulation modelIdentifier="BouncingBall" canHandleVariableCommunicationStepSize="true">
<SourceFiles>
<File name="BouncingBall.c"/>
<File name="all.c"/>
</SourceFiles>
</CoSimulation>

<LogCategories>
<Category name="logAll"/>
<Category name="logError"/>
<Category name="logFmiCall"/>
<Category name="logEvent"/>
<Category name="logEvents" description="Log events"/>
<Category name="logStatusError" description="Log error messages"/>
</LogCategories>

<DefaultExperiment startTime="0" stopTime="3"/>
<DefaultExperiment startTime="0" stopTime="3" stepSize="1e-3"/>

<ModelVariables>
<Float64 name="h" valueReference="0" description="height, used as state" causality="output" variability="continuous" initial="exact" start="1"/>
Expand Down
2 changes: 2 additions & 0 deletions BouncingBall/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#define SET_FLOAT64
#define EVENT_UPDATE

#define FIXED_SOLVER_STEP 1e-3

typedef enum {
vr_h, vr_v, vr_g, vr_e, vr_v_min
} ValueReference;
Expand Down
15 changes: 10 additions & 5 deletions BouncingBall/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ Status getFloat64(ModelInstance* comp, ValueReference vr, double *value, size_t

Status setFloat64(ModelInstance* comp, ValueReference vr, const double *value, size_t *index) {
switch (vr) {

case vr_h:
M(h) = value[(*index)++];
return OK;

case vr_v:
M(v) = value[(*index)++];
return OK;

case vr_g:
#if FMI_VERSION > 1
if (comp->type == ModelExchange &&
Expand All @@ -62,7 +62,7 @@ Status setFloat64(ModelInstance* comp, ValueReference vr, const double *value, s
#endif
M(g) = value[(*index)++];
return OK;

case vr_e:
#if FMI_VERSION > 1
if (comp->type == ModelExchange &&
Expand All @@ -75,8 +75,13 @@ Status setFloat64(ModelInstance* comp, ValueReference vr, const double *value, s
#endif
M(e) = value[(*index)++];
return OK;


case vr_v_min:
logError(comp, "Variable v_min (value reference %d) is constant and cannot be set.", vr_v_min);
return Error;

default:
logError(comp, "Unexpected value reference: %.", vr);
return Error;
}
}
Expand Down
29 changes: 22 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (${FMI_VERSION} GREATER 1)
set(FMI_TYPE "")
endif ()

if (WIN32)
if (MSVC)
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
endif ()
Expand Down Expand Up @@ -58,6 +58,13 @@ endif ()

MESSAGE("FMI_PLATFORM: " ${FMI_PLATFORM})

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/all.c" "#define FMI_VERSION ${FMI_VERSION}
#include \"fmi${FMI_VERSION}Functions.c\"
#include \"model.c\"
#include \"slave.c\"
")

set (MODEL_NAMES BouncingBall Dahlquist Stair Feedthrough VanDerPol)

if (${FMI_VERSION} GREATER 1 OR "${FMI_TYPE}" STREQUAL "CS")
Expand All @@ -75,13 +82,11 @@ set(TARGET_NAME ${MODEL_NAME})
SET(HEADERS
${MODEL_NAME}/config.h
include/model.h
include/solver.h
)

SET(SOURCES
${MODEL_NAME}/model.c
src/fmi${FMI_VERSION}.c
src/euler.c
src/fmi${FMI_VERSION}Functions.c
src/slave.c
)

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

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist)

target_compile_definitions(${TARGET_NAME} PRIVATE DISABLE_PREFIX FMI_VERSION=${FMI_VERSION})
target_compile_definitions(${TARGET_NAME} PRIVATE
_CRT_SECURE_NO_WARNINGS
DISABLE_PREFIX
FMI_VERSION=${FMI_VERSION}
)

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

# common headers
foreach (SOURCE_FILE model.h slave.h solver.h)
foreach (SOURCE_FILE model.h slave.h)
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/include/${SOURCE_FILE}"
"${FMU_BUILD_DIR}/sources/${SOURCE_FILE}"
)
endforeach(SOURCE_FILE)

# common sources
foreach (SOURCE_FILE fmi${FMI_VERSION}.c euler.c slave.c)
foreach (SOURCE_FILE fmi${FMI_VERSION}Functions.c slave.c)
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/src/${SOURCE_FILE}"
"${FMU_BUILD_DIR}/sources/${SOURCE_FILE}"
)
endforeach(SOURCE_FILE)

# all.c
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_BINARY_DIR}/all.c"
"${FMU_BUILD_DIR}/sources/all.c"
)

set(ARCHIVE_FILES "modelDescription.xml" "binaries" "documentation" "sources")

if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${MODEL_NAME}/resources")
Expand Down
9 changes: 8 additions & 1 deletion Dahlquist/FMI1CS.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiModelDescription fmiVersion="1.0" modelName="Dahlquist" modelIdentifier="Dahlquist" guid="{8c4e810f-3df3-4a00-8276-176fa3c9f000}" numberOfContinuousStates="1" numberOfEventIndicators="0">
<fmiModelDescription
fmiVersion="1.0"
modelName="Dahlquist"
modelIdentifier="Dahlquist"
description="This model implements the Dahlquist test equation."
guid="{8c4e810f-3df3-4a00-8276-176fa3c9f000}"
numberOfContinuousStates="1"
numberOfEventIndicators="0">

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

Expand Down
9 changes: 8 additions & 1 deletion Dahlquist/FMI1ME.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiModelDescription fmiVersion="1.0" modelName="Dahlquist" modelIdentifier="Dahlquist" guid="{8c4e810f-3df3-4a00-8276-176fa3c9f000}" numberOfContinuousStates="1" numberOfEventIndicators="0">
<fmiModelDescription
fmiVersion="1.0"
modelName="Dahlquist"
modelIdentifier="Dahlquist"
description="This model implements the Dahlquist test equation."
guid="{8c4e810f-3df3-4a00-8276-176fa3c9f000}"
numberOfContinuousStates="1"
numberOfEventIndicators="0">

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

Expand Down
25 changes: 11 additions & 14 deletions Dahlquist/FMI2.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiModelDescription fmiVersion="2.0" modelName="Dahlquist" guid="{8c4e810f-3df3-4a00-8276-176fa3c9f000}" numberOfEventIndicators="0">
<fmiModelDescription
fmiVersion="2.0"
modelName="Dahlquist"
description="This model implements the Dahlquist test equation."
guid="{8c4e810f-3df3-4a00-8276-176fa3c9f000}"
numberOfEventIndicators="0">

<ModelExchange modelIdentifier="Dahlquist">
<SourceFiles>
<File name="fmi2.c"/>
<File name="euler.c"/>
<File name="model.c"/>
<File name="slave.c"/>
<File name="all.c"/>
</SourceFiles>
</ModelExchange>

<CoSimulation modelIdentifier="Dahlquist" canHandleVariableCommunicationStepSize="true">
<SourceFiles>
<File name="fmi2.c"/>
<File name="euler.c"/>
<File name="model.c"/>
<File name="slave.c"/>
<File name="all.c"/>
</SourceFiles>
</CoSimulation>

<LogCategories>
<Category name="logAll"/>
<Category name="logError"/>
<Category name="logFmiCall"/>
<Category name="logEvent"/>
<Category name="logEvents" description="Log events"/>
<Category name="logStatusError" description="Log error messages"/>
</LogCategories>

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

<ModelVariables>
<ScalarVariable name="x" valueReference="0" description="the only state" causality="output" variability="continuous" initial="exact">
Expand Down
18 changes: 5 additions & 13 deletions Dahlquist/FMI3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,22 @@

<ModelExchange modelIdentifier="Dahlquist">
<SourceFiles>
<File name="fmi2.c"/>
<File name="euler.c"/>
<File name="model.c"/>
<File name="slave.c"/>
<File name="all.c"/>
</SourceFiles>
</ModelExchange>

<CoSimulation modelIdentifier="Dahlquist" canHandleVariableCommunicationStepSize="true">
<SourceFiles>
<File name="fmi2.c"/>
<File name="euler.c"/>
<File name="model.c"/>
<File name="slave.c"/>
<File name="all.c"/>
</SourceFiles>
</CoSimulation>

<LogCategories>
<Category name="logAll"/>
<Category name="logError"/>
<Category name="logFmiCall"/>
<Category name="logEvent"/>
<Category name="logEvents" description="Log events"/>
<Category name="logStatusError" description="Log error messages"/>
</LogCategories>

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

<ModelVariables>
<Float64 name="x" valueReference="0" description="the only state" causality="output" variability="continuous" initial="exact" start="1"/>
Expand Down
Loading

0 comments on commit 93110f2

Please sign in to comment.