-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new example FMU for Linear Equation.
Signed-off-by: Timothy Rule (VM/EMT3) <[email protected]>
- Loading branch information
1 parent
ca65860
commit a14dc2f
Showing
7 changed files
with
358 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_subdirectory(fmu/counter) | ||
add_subdirectory(fmu/linear) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
# Copyright 2024 Robert Bosch GmbH | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.21) | ||
|
||
# set(CMAKE_VERBOSE_MAKEFILE ON) | ||
|
||
|
||
################################################# | ||
## Configure FMU here: | ||
## ------------------ | ||
set(VERSION "$ENV{PACKAGE_VERSION}") | ||
set(MODULE "Linear") | ||
set(MODULE_LC "linear") | ||
set(FMU_FILES | ||
linear.c | ||
) | ||
## | ||
################################################# | ||
|
||
|
||
project(Fmu VERSION ${VERSION}) | ||
|
||
include(FetchContent) | ||
|
||
# set(CMAKE_VERBOSE_MAKEFILE ON) | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
set(CMAKE_C_STANDARD 99) | ||
set(CMAKE_C_STANDARD_REQUIRED TRUE) | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
set(CMAKE_BUILD_TYPE Debug) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -ggdb -DLIBXML_STATIC") | ||
list(APPEND C_CXX_WARNING_FLAGS | ||
-Wall | ||
-W | ||
-Wwrite-strings | ||
-Wno-missing-field-initializers | ||
-Wno-misleading-indentation | ||
) | ||
add_compile_options(${C_CXX_WARNING_FLAGS}) | ||
|
||
|
||
# External Project - DSE C Lib | ||
# ---------------------------- | ||
FetchContent_Declare(dse_clib | ||
URL https://github.com/boschglobal/dse.clib/archive/refs/tags/v$ENV{DSE_CLIB_VERSION}.zip | ||
) | ||
FetchContent_MakeAvailable(dse_clib) | ||
set(DSE_CLIB_SOURCE_DIR ${dse_clib_SOURCE_DIR}/dse) | ||
set(DSE_CLIB_INCLUDE_DIR "${DSE_CLIB_SOURCE_DIR}/..") | ||
set(DSE_CLIB_SOURCE_FILES | ||
${DSE_CLIB_SOURCE_DIR}/clib/util/strings.c | ||
${DSE_CLIB_SOURCE_DIR}/clib/util/binary.c | ||
${DSE_CLIB_SOURCE_DIR}/clib/collections/hashmap.c | ||
) | ||
set(FMI2_INCLUDE_DIR "${DSE_CLIB_SOURCE_DIR}/clib/fmi/fmi2/headers") | ||
set(FMI3_INCLUDE_DIR "${DSE_CLIB_SOURCE_DIR}/clib/fmi/fmi3/headers") | ||
|
||
|
||
set(FMU_SOURCE_DIR "../../../fmu") | ||
set(FMU_INCLUDE_DIR "../../../..") | ||
set(FMI_2_COMMON_FILES | ||
${FMU_SOURCE_DIR}/ascii85.c | ||
${FMU_SOURCE_DIR}/fmi2fmu.c | ||
${FMU_SOURCE_DIR}/signal.c | ||
) | ||
set(FMI_3_COMMON_FILES | ||
${FMU_SOURCE_DIR}/ascii85.c | ||
${FMU_SOURCE_DIR}/fmi3fmu.c | ||
${FMU_SOURCE_DIR}/signal.c | ||
) | ||
|
||
|
||
# Targets | ||
# ======= | ||
|
||
# FMI2 FMU | ||
# -------- | ||
set(FMU_FMI2_PATH examples/fmu/${MODULE_LC}/fmi2) | ||
add_library(fmu2${MODULE_LC} SHARED | ||
${DSE_CLIB_SOURCE_FILES} | ||
${FMI_2_COMMON_FILES} | ||
${FMU_FILES} | ||
) | ||
target_include_directories(fmu2${MODULE_LC} | ||
PRIVATE | ||
${FMI2_INCLUDE_DIR} | ||
${DSE_CLIB_INCLUDE_DIR} | ||
${FMU_INCLUDE_DIR} | ||
) | ||
target_link_libraries(fmu2${MODULE_LC} | ||
PRIVATE | ||
xml | ||
$<$<BOOL:${WIN32}>:bcrypt> | ||
$<$<BOOL:${WIN32}>:dl> | ||
) | ||
set_target_properties(fmu2${MODULE_LC} | ||
PROPERTIES | ||
OUTPUT_NAME ${MODULE_LC} | ||
) | ||
install( | ||
TARGETS | ||
fmu2${MODULE_LC} | ||
LIBRARY DESTINATION | ||
${FMU_FMI2_PATH}/binaries/linux64 | ||
) | ||
install( | ||
FILES | ||
fmi2/modelDescription.xml | ||
DESTINATION | ||
${FMU_FMI2_PATH} | ||
) | ||
|
||
|
||
# FMI3 FMU | ||
# -------- | ||
set(FMU_FMI3_PATH examples/fmu/${MODULE_LC}/fmi3) | ||
add_library(fmu3${MODULE_LC} SHARED | ||
${DSE_CLIB_SOURCE_FILES} | ||
${FMI_3_COMMON_FILES} | ||
${FMU_FILES} | ||
) | ||
target_include_directories(fmu3${MODULE_LC} | ||
PRIVATE | ||
${FMI3_INCLUDE_DIR} | ||
${DSE_CLIB_INCLUDE_DIR} | ||
${FMU_INCLUDE_DIR} | ||
) | ||
target_link_libraries(fmu3${MODULE_LC} | ||
PRIVATE | ||
xml | ||
$<$<BOOL:${WIN32}>:bcrypt> | ||
$<$<BOOL:${WIN32}>:dl> | ||
) | ||
set_target_properties(fmu3${MODULE_LC} | ||
PROPERTIES | ||
OUTPUT_NAME ${MODULE_LC} | ||
) | ||
install( | ||
TARGETS | ||
fmu3${MODULE_LC} | ||
LIBRARY DESTINATION | ||
${FMU_FMI3_PATH}/binaries/x86_64-linux | ||
) | ||
install( | ||
FILES | ||
fmi3/modelDescription.xml | ||
DESTINATION | ||
${FMU_FMI3_PATH} | ||
) | ||
|
||
# Package FMU | ||
# ----------- | ||
install(CODE " | ||
execute_process( | ||
COMMAND sh -c \" | ||
zip -r ${MODULE_LC}.zip ./ | ||
exit 0 | ||
\" | ||
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${FMU_FMI2_PATH} | ||
)" | ||
) | ||
install(CODE " | ||
execute_process( | ||
COMMAND sh -c \" | ||
zip -r ${MODULE_LC}.zip ./ | ||
exit 0 | ||
\" | ||
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${FMU_FMI3_PATH} | ||
)" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<fmiModelDescription | ||
fmiVersion="2.0" | ||
modelName="linear" | ||
description="Linear Equation FMU." | ||
generationTool="Reference FMUs (development build)" | ||
guid="{71da084a-0998-4418-a29d-01af36a32568}" | ||
numberOfEventIndicators="0"> | ||
|
||
<CoSimulation | ||
modelIdentifier="linear" | ||
canHandleVariableCommunicationStepSize="false" | ||
canNotUseMemoryManagementFunctions="false" | ||
canGetAndSetFMUstate="false" | ||
canSerializeFMUstate="false"> | ||
<SourceFiles> | ||
<File name="linear.c" /> | ||
</SourceFiles> | ||
</CoSimulation> | ||
|
||
<DefaultExperiment startTime="0" stopTime="0.0040" stepSize="0.0005" /> | ||
|
||
<ModelVariables> | ||
<ScalarVariable name="input" valueReference="1" causality="input"> | ||
<Real start="0" reinit="" derivative=""></Real> | ||
</ScalarVariable> | ||
<ScalarVariable name="factor" valueReference="2" causality="input"> | ||
<Real start="1" reinit="" derivative=""></Real> | ||
</ScalarVariable> | ||
<ScalarVariable name="offset" valueReference="3" causality="input"> | ||
<Real start="0" reinit="" derivative=""></Real> | ||
</ScalarVariable> | ||
<ScalarVariable name="output" valueReference="4" causality="output"> | ||
<Real start="0" reinit="" derivative=""></Real> | ||
</ScalarVariable> | ||
</ModelVariables> | ||
|
||
</fmiModelDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<fmiModelDescription | ||
fmiVersion="3.0" | ||
modelName="linear" | ||
description="Linear Example FMU." | ||
generationTool="Reference FMUs (development build)" | ||
instantiationToken="{71da084a-0998-4418-a29d-01af36a32568}" | ||
numberOfEventIndicators="0" | ||
version="1.0"> | ||
|
||
<CoSimulation | ||
modelIdentifier="linear" | ||
canHandleVariableCommunicationStepSize="false" | ||
canNotUseMemoryManagementFunctions="false" | ||
canGetAndSetFMUstate="false" | ||
canSerializeFMUstate="false"> | ||
<SourceFiles> | ||
<File name="linear.c" /> | ||
</SourceFiles> | ||
</CoSimulation> | ||
|
||
<ModelVariables> | ||
<Float64 name="input" valueReference="1" causality="input" start="0" /> | ||
<Float64 name="factor" valueReference="2" causality="input" start="0" /> | ||
<Float64 name="offset" valueReference="3" causality="input" start="0" /> | ||
<Float64 name="output" valueReference="4" causality="output" start="0" /> | ||
</ModelVariables> | ||
<ModelStructure> | ||
<Input valueReference="1"/> | ||
<Input valueReference="2"/> | ||
<Input valueReference="3"/> | ||
<Output valueReference="4"/> | ||
</ModelStructure> | ||
</fmiModelDescription> |
Oops, something went wrong.