├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── data ├── .gitignore ├── FMI_template │ ├── CMakeLists.txt │ ├── FMI_template.pro │ ├── bin │ │ ├── debug │ │ │ └── .gitignore │ │ ├── release │ │ │ ├── .gitignore │ │ │ └── readme.md │ │ └── release_x64 │ │ │ ├── .gitignore │ │ │ └── readme.md │ ├── build │ │ ├── .gitignore │ │ ├── build.sh │ │ ├── build_VC_x64.bat │ │ ├── build_VC_x64_vc2015.bat │ │ ├── build_VC_x64_vc2019.bat │ │ ├── build_VC_x64_vc2022.bat │ │ ├── deploy.bat │ │ ├── deploy.sh │ │ ├── deployMac.sh │ │ └── readme.md │ ├── data │ │ └── modelDescription.xml │ └── src │ │ ├── FMI_template.cpp │ │ ├── FMI_template.h │ │ └── fmi2common │ │ ├── InstanceData.cpp │ │ ├── InstanceData.h │ │ ├── fmi2FunctionTypes.h │ │ ├── fmi2Functions.cpp │ │ ├── fmi2Functions.h │ │ ├── fmi2Functions_complete.h │ │ └── fmi2TypesPlatform.h └── check │ ├── .gitignore │ ├── RealInputTest.input │ ├── RealInputTest │ ├── bin │ │ ├── debug │ │ │ └── .gitignore │ │ ├── release │ │ │ ├── .gitignore │ │ │ └── readme.md │ │ └── release_x64 │ │ │ ├── .gitignore │ │ │ └── readme.md │ ├── build │ │ ├── .gitignore │ │ ├── build.sh │ │ ├── build_VC_x64.bat │ │ ├── deploy.bat │ │ └── deploy.sh │ ├── data │ │ └── modelDescription.xml │ ├── projects │ │ ├── .gitignore │ │ ├── Qt │ │ │ └── RealInputTest.pro │ │ └── cmake │ │ │ └── CMakeLists.txt │ └── src │ │ ├── RealInputTest.cpp │ │ ├── RealInputTest.h │ │ └── fmi2common │ │ ├── InstanceData.cpp │ │ ├── InstanceData.h │ │ ├── fmi2FunctionTypes.h │ │ ├── fmi2Functions.cpp │ │ ├── fmi2Functions.h │ │ ├── fmi2Functions_complete.h │ │ └── fmi2TypesPlatform.h │ ├── input.tsv │ └── readme.md ├── doc ├── .gitignore ├── FMI_specs │ ├── FMI_for_CoSimulation_v1.0.pdf │ ├── FMI_for_ModelExchange_and_CoSimulation_v2.0.pdf │ └── FMI_for_ModelExchange_v1.0.pdf ├── Tutorial │ └── readme.md └── readme.md ├── examples ├── P_Control.fmu ├── P_Control.input ├── P_Control │ ├── bin │ │ ├── debug │ │ │ └── .gitignore │ │ ├── release │ │ │ ├── .gitignore │ │ │ └── readme.md │ │ └── release_x64 │ │ │ ├── .gitignore │ │ │ └── readme.md │ ├── build │ │ ├── .gitignore │ │ ├── build.sh │ │ ├── build_VC_x64.bat │ │ ├── deploy.bat │ │ ├── deploy.sh │ │ └── deployMac.sh │ ├── data │ │ └── modelDescription.xml │ ├── projects │ │ ├── .gitignore │ │ ├── Qt │ │ │ └── P_Control.pro │ │ └── cmake │ │ │ └── CMakeLists.txt │ └── src │ │ ├── P_Control.cpp │ │ ├── P_Control.h │ │ └── fmi2common │ │ ├── InstanceData.cpp │ │ ├── InstanceData.h │ │ ├── fmi2FunctionTypes.h │ │ ├── fmi2Functions.cpp │ │ ├── fmi2Functions.h │ │ ├── fmi2Functions_complete.h │ │ └── fmi2TypesPlatform.h ├── P_Control_2inputs.input ├── Test5.fmu ├── Test5 │ ├── bin │ │ ├── debug │ │ │ └── .gitignore │ │ ├── release │ │ │ ├── .gitignore │ │ │ └── readme.md │ │ └── release_x64 │ │ │ ├── .gitignore │ │ │ └── readme.md │ ├── build │ │ ├── .gitignore │ │ ├── Test5 │ │ │ ├── binaries │ │ │ │ └── linux64 │ │ │ │ │ └── .gitignore │ │ │ └── modelDescription.xml │ │ ├── build.sh │ │ ├── build_VC_x64.bat │ │ ├── deploy.bat │ │ └── deploy.sh │ ├── data │ │ └── modelDescription.xml │ ├── projects │ │ ├── .gitignore │ │ ├── Qt │ │ │ └── Test5.pro │ │ └── cmake │ │ │ └── CMakeLists.txt │ └── src │ │ ├── Test5.cpp │ │ ├── Test5.h │ │ └── fmi2common │ │ ├── InstanceData.cpp │ │ ├── InstanceData.h │ │ ├── fmi2FunctionTypes.h │ │ ├── fmi2Functions.cpp │ │ ├── fmi2Functions.h │ │ ├── fmi2Functions_complete.h │ │ └── fmi2TypesPlatform.h ├── TestWithOutputs.input ├── TestWithoutOutputs.input └── readme.md ├── readme.md ├── scripts ├── .gitignore ├── FMIGenerator.py ├── FMIGenerator.wpr ├── FMIGeneratorWizard.py ├── FMIGenerator_rc.py ├── FMIGenerator_wing6.wpr ├── Ui_WizardPageBasicProperties.py ├── Ui_WizardPageGenerate.py ├── Ui_WizardPageVariables.py ├── WizardPageBasicProperties.py ├── WizardPageGenerate.py ├── WizardPageVariables.py ├── commandLineGenerator.py ├── main.py ├── third_party │ ├── __init__.py │ └── send2trash_master │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── CHANGES.rst │ │ ├── LICENSE │ │ ├── MANIFEST.in │ │ ├── README.rst │ │ ├── __init__.py │ │ ├── send2trash │ │ ├── __init__.py │ │ ├── compat.py │ │ ├── exceptions.py │ │ ├── plat_gio.py │ │ ├── plat_osx.py │ │ ├── plat_other.py │ │ └── plat_win.py │ │ ├── setup.py │ │ ├── tests │ │ ├── __init__.py │ │ ├── test_plat_other.py │ │ └── test_plat_win.py │ │ └── tox.ini └── ui │ ├── .gitignore │ ├── FMIGenerator.qrc │ ├── WizardPageBasicProperties.ui │ ├── WizardPageGenerate.ui │ ├── WizardPageVariables.ui │ ├── gfx │ ├── minus.png │ └── plus.png │ ├── readme.md │ └── update.sh └── third_party ├── .gitignore ├── FMUChecker-2.0.4-linux64.zip └── FMUChecker-2.0.4-win64.zip /.gitignore: -------------------------------------------------------------------------------- 1 | *.pro.user 2 | 3 | /.DS_Store 4 | .DS_Store 5 | /scripts/__pycache__/ 6 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to FMICodeGenerator 2 | 3 | :+1::tada: First off, thanks for taking the time to contribute! :tada::+1: 4 | 5 | The following is a set of guidelines for contributing to FMICodeGenerator, its scripts and template code. I try to keep it brief, so here's the idea in a nutshell. 6 | 7 | ## License 8 | 9 | The FMICodeGenerator is provided under a *BSD 3-Clause License*. By contributing code/wiki/documentation content, you agree to place your contribution unter the same license. This will ensure, that the entire FMICodeGeneator project remains a free and open-source project. 10 | 11 | ## Coding Style 12 | 13 | The FMICodeGenerator project used Python code (with PyQt for GUI components) and, as a code generator, produces C/C++ code based on various template files. Instead of writing a fixed style guide here, I'd be happy if you would simply try to write your contribution in a similar manner as the existing code. I hope you don't mind if it happends that I adjust the coding style of contributed code a litte. 14 | 15 | That's all :-) 16 | 17 | Happy coding! 18 | 19 | *Ghorwin aka Andreas* 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2018, Andreas Nicolai 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /data/.gitignore: -------------------------------------------------------------------------------- 1 | /Test01/ 2 | -------------------------------------------------------------------------------- /data/FMI_template/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMake project file for generated FMI code 2 | # 3 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 4 | # 5 | # BSD 3-Clause License 6 | # 7 | # Copyright (c) 2018, Andreas Nicolai 8 | # All rights reserved. 9 | # 10 | # see https://github.com/ghorwin/FMICodeGenerator/blob/master/LICENSE for details. 11 | 12 | project( FMI_template ) 13 | 14 | cmake_minimum_required(VERSION 3.5) 15 | 16 | # add include directories 17 | include_directories( 18 | ${PROJECT_SOURCE_DIR}/src 19 | ) 20 | 21 | add_library( ${PROJECT_NAME} SHARED 22 | ${PROJECT_SOURCE_DIR}/src/${PROJECT_NAME}.cpp 23 | ${PROJECT_SOURCE_DIR}/src/fmi2common/fmi2Functions.cpp 24 | ${PROJECT_SOURCE_DIR}/src/fmi2common/InstanceData.cpp 25 | ) 26 | 27 | # link against the dependent libraries 28 | target_link_libraries( ${PROJECT_NAME} 29 | ${APPLE_FRAMEWORKS} 30 | ) 31 | 32 | # Library version strings set by code generator 33 | set( SO_VERSION_MAJOR 1) 34 | set( SO_VERSION_MINOR 0) 35 | set( SO_VERSION_PATCH 0) 36 | set( SO_VERSION_STRING 37 | ${SO_VERSION_MAJOR}.${SO_VERSION_MINOR}.${SO_VERSION_PATCH} 38 | ) 39 | 40 | set_target_properties( ${PROJECT_NAME} PROPERTIES 41 | VERSION ${SO_VERSION_STRING} 42 | SOVERSION ${SO_VERSION_MAJOR} 43 | ) 44 | -------------------------------------------------------------------------------- /data/FMI_template/FMI_template.pro: -------------------------------------------------------------------------------- 1 | # ---------------------------------- 2 | # Qt Project for building FMU 3 | # ---------------------------------- 4 | # 5 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 6 | # 7 | # BSD 3-Clause License 8 | # 9 | # Copyright (c) 2018, Andreas Nicolai 10 | # All rights reserved. 11 | # 12 | # see https://github.com/ghorwin/FMICodeGenerator/blob/master/LICENSE for details. 13 | 14 | 15 | TARGET = FMI_template 16 | TEMPLATE = lib 17 | 18 | # no GUI 19 | QT -= core gui 20 | 21 | CONFIG(debug, debug|release) { 22 | windows { 23 | DLLDESTDIR = bin/debug$${DIR_PREFIX} 24 | } 25 | else { 26 | DESTDIR = bin/debug$${DIR_PREFIX} 27 | } 28 | } 29 | else { 30 | windows { 31 | DLLDESTDIR = bin/release$${DIR_PREFIX} 32 | } 33 | else { 34 | DESTDIR = bin/release$${DIR_PREFIX} 35 | } 36 | } 37 | 38 | #DEFINES += FMI2_FUNCTION_PREFIX=FMI_template_ 39 | 40 | unix|mac { 41 | VER_MAJ = 1 42 | VER_MIN = 0 43 | VER_PAT = 0 44 | VERSION = $${VER_MAJ}.$${VER_MIN}.$${VER_PAT} 45 | } 46 | 47 | unix { 48 | # move actual lib to TARGET.so 49 | QMAKE_POST_LINK += $$quote(mv $${DESTDIR}/lib$${TARGET}.so.$${VER_MAJ}.$${VER_MIN}.$${VER_PAT} $${DESTDIR}/$${TARGET}.so) && 50 | # remove symlinks 51 | QMAKE_POST_LINK += $$quote(rm $${DESTDIR}/lib$${TARGET}.so.$${VER_MAJ}.$${VER_MIN}) && 52 | QMAKE_POST_LINK += $$quote(rm $${DESTDIR}/lib$${TARGET}.so.$${VER_MAJ}) && 53 | QMAKE_POST_LINK += $$quote(rm $${DESTDIR}/lib$${TARGET}.so) 54 | } 55 | 56 | 57 | INCLUDEPATH = src 58 | 59 | SOURCES += \ 60 | src/fmi2common/fmi2Functions.cpp \ 61 | src/fmi2common/InstanceData.cpp \ 62 | src/FMI_template.cpp 63 | 64 | HEADERS += \ 65 | src/fmi2common/fmi2Functions.h \ 66 | src/fmi2common/fmi2Functions_complete.h \ 67 | src/fmi2common/fmi2FunctionTypes.h \ 68 | src/fmi2common/fmi2TypesPlatform.h \ 69 | src/fmi2common/InstanceData.h \ 70 | src/FMI_template.h 71 | 72 | 73 | -------------------------------------------------------------------------------- /data/FMI_template/bin/debug/.gitignore: -------------------------------------------------------------------------------- 1 | /libFMI_template.so 2 | /libFMI_template.so.1 3 | /libFMI_template.so.1.0 4 | /libFMI_template.so.1.0.0 5 | -------------------------------------------------------------------------------- /data/FMI_template/bin/release/.gitignore: -------------------------------------------------------------------------------- 1 | *.so1.0.0 2 | *.dylib 3 | /libFMI_template.so.1.0.0 4 | -------------------------------------------------------------------------------- /data/FMI_template/bin/release/readme.md: -------------------------------------------------------------------------------- 1 | Target directory for generated shared library file. 2 | 3 | -------------------------------------------------------------------------------- /data/FMI_template/bin/release_x64/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /data/FMI_template/bin/release_x64/readme.md: -------------------------------------------------------------------------------- 1 | This directory is for x64 windows binaries. -------------------------------------------------------------------------------- /data/FMI_template/build/.gitignore: -------------------------------------------------------------------------------- 1 | /bb-gcc/ 2 | -------------------------------------------------------------------------------- /data/FMI_template/build/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Build script for building FMU. 4 | # 5 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 6 | # 7 | # BSD 3-Clause License 8 | # 9 | # Copyright (c) 2018, Andreas Nicolai 10 | # All rights reserved. 11 | # 12 | # Redistribution and use in source and binary forms, with or without 13 | # modification, are permitted provided that the following conditions are met: 14 | # 15 | # * Redistributions of source code must retain the above copyright notice, this 16 | # list of conditions and the following disclaimer. 17 | # 18 | # * Redistributions in binary form must reproduce the above copyright notice, 19 | # this list of conditions and the following disclaimer in the documentation 20 | # and/or other materials provided with the distribution. 21 | # 22 | # * Neither the name of the copyright holder nor the names of its 23 | # contributors may be used to endorse or promote products derived from 24 | # this software without specific prior written permission. 25 | # 26 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | # 37 | # 38 | # Command line options: 39 | # [reldeb|release|debug] build type 40 | # [2 [1..n]] cpu count 41 | # [gcc|icc] compiler 42 | # [off|gprof] gprof (includes gcc) 43 | # [off|threadChecker] threadchecker (includes icc) 44 | # [off|omp] openmp (gcc and icc) 45 | # [verbose] enable cmake to call verbose makefiles 46 | # 47 | # 48 | # FMU-specific variables - set by code generator 49 | FMU_SHARED_LIB_NAME=libFMI_template 50 | FMU_SHARED_LIB_TARGET_NAME=FMI_template 51 | FMU_SHARED_LIB_VERSION=1.0.0 52 | 53 | BUILD_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 54 | CMAKELISTSDIR=$(pwd)/.. 55 | BUILDDIR="bb" 56 | 57 | # set defaults 58 | CMAKE_BUILD_TYPE=" -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo" 59 | MAKE_CPUCOUNT="2" 60 | BUILD_DIR_SUFFIX="gcc" 61 | COMPILER="" 62 | SKIP_TESTS="false" 63 | 64 | # parse parameters, except gprof and threadchecker 65 | for var in "$@" 66 | do 67 | 68 | if [[ $var = "--help" ]]; 69 | then 70 | echo "Command line options:" 71 | echo " [reldeb|release|debug] build type" 72 | echo " [2 [1..n]] cpu count" 73 | echo " [gcc|icc] compiler" 74 | echo " [off|gprof] gprof (includes gcc)" 75 | echo " [off|threadChecker] threadchecker (includes icc)" 76 | echo " [off|omp] openmp (gcc and icc)" 77 | echo " [verbose] enable cmake to call verbose makefiles" 78 | 79 | exit 80 | fi 81 | 82 | if [[ $var = *[[:digit:]]* ]]; 83 | then 84 | MAKE_CPUCOUNT=$var 85 | echo "Using $MAKE_CPUCOUNT CPUs for compilation" 86 | fi 87 | 88 | if [[ $var = "omp" ]]; 89 | then 90 | CMAKE_OPTIONS="$CMAKE_OPTIONS -DUSE_OMP:BOOL=ON" 91 | echo "Using Open MP compile flags" 92 | fi 93 | 94 | if [[ $var = "debug" ]]; 95 | then 96 | CMAKE_BUILD_TYPE=" -DCMAKE_BUILD_TYPE:STRING=Debug" 97 | echo "Debug build..." 98 | fi 99 | 100 | if [[ $var = "release" ]]; 101 | then 102 | CMAKE_BUILD_TYPE=" -DCMAKE_BUILD_TYPE:STRING=Release" 103 | echo "Release build..." 104 | fi 105 | 106 | if [[ $var = "reldeb" ]]; 107 | then 108 | CMAKE_BUILD_TYPE=" -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo" 109 | echo "RelWithDebInfo build..." 110 | fi 111 | 112 | if [[ $var = "icc" && $COMPILER = "" ]]; 113 | then 114 | COMPILER="icc" 115 | BUILD_DIR_SUFFIX="icc" 116 | echo "Intel compiler build..." 117 | # export intel compiler path 118 | CMAKE_COMPILER_OPTIONS="-DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icc" 119 | fi 120 | 121 | if [[ $var = "gcc" && $COMPILER = "" ]]; 122 | then 123 | COMPILER="gcc" 124 | BUILD_DIR_SUFFIX="gcc" 125 | echo "GCC compiler build..." 126 | CMAKE_COMPILER_OPTIONS="" 127 | fi 128 | 129 | if [[ $var = "verbose" ]]; 130 | then 131 | CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" 132 | fi 133 | 134 | done 135 | 136 | 137 | # override compiler options 138 | for var in "$@" 139 | do 140 | 141 | if [[ $var = "gprof" ]]; 142 | then 143 | COMPILER="gcc" 144 | BUILD_DIR_SUFFIX="gcc" 145 | CMAKE_COMPILER_OPTIONS="-DCMAKE_CXX_FLAGS="'-pg'" -DCMAKE_EXE_LINKER_FLAGS="'-pg'"" 146 | echo "Gprof build, forcing GCC build..." 147 | fi 148 | 149 | if [[ $var = "threadChecker" ]]; 150 | then 151 | COMPILER="icc" 152 | BUILD_DIR_SUFFIX="icc" 153 | echo "Using Threadchecker, forcing Intel compiler build..." 154 | # export intel compiler path 155 | CMAKE_COMPILER_OPTIONS="-DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icc -DUSE_THREAD_CHECKER:BOOL=ON" 156 | fi 157 | 158 | done 159 | 160 | 161 | # create build dir if not exists 162 | BUILDDIR=$BUILDDIR-$BUILD_DIR_SUFFIX 163 | if [ ! -d $BUILDDIR ]; then 164 | mkdir -p $BUILDDIR 165 | fi 166 | 167 | cd $BUILDDIR && cmake $CMAKE_OPTIONS $CMAKE_BUILD_TYPE $CMAKE_COMPILER_OPTIONS $CMAKELISTSDIR && make -j$MAKE_CPUCOUNT && 168 | cd $BUILD_SCRIPT_DIR && 169 | mkdir -p ../bin/release && 170 | # copy for Linux/Unix builds 171 | if [ -e $BUILDDIR/$FMU_SHARED_LIB_NAME.so ]; then 172 | cp -f $BUILDDIR/$FMU_SHARED_LIB_NAME.so.$FMU_SHARED_LIB_VERSION ../bin/release/$FMU_SHARED_LIB_TARGET_NAME.so && 173 | echo "Created ../bin/release/$FMU_SHARED_LIB_TARGET_NAME.so ***" 174 | fi && 175 | # copy for Mac builds 176 | if [ -e $BUILDDIR/$FMU_SHARED_LIB_NAME.dylib ]; then 177 | cp -f $BUILDDIR/$FMU_SHARED_LIB_NAME.$FMU_SHARED_LIB_VERSION.dylib ../bin/release/$FMU_SHARED_LIB_TARGET_NAME.dylib && 178 | echo "Created ../bin/release/$FMU_SHARED_LIB_TARGET_NAME.dylib ***" 179 | fi 180 | 181 | -------------------------------------------------------------------------------- /data/FMI_template/build/build_VC_x64.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: setup VC environment variables 4 | call "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" 5 | 6 | :: FMU-specific variables - set by code generator 7 | set FMU_SHARED_LIB_NAME=FMI_template.dll 8 | 9 | set CMAKELISTSDIR=%CD%\.. 10 | 11 | :: create and change into build subdir 12 | mkdir bb_VC_x64 13 | pushd bb_VC_x64 14 | 15 | :: configure makefiles and build 16 | cmake -G "NMake Makefiles" %CMAKELISTSDIR% -DCMAKE_BUILD_TYPE:String="Release" 17 | nmake 18 | if ERRORLEVEL 1 GOTO fail 19 | 20 | popd 21 | 22 | :: copy executable to bin/release dir 23 | xcopy /Y .\bb_VC_x64\%FMU_SHARED_LIB_NAME% ..\bin\release_x64 24 | 25 | exit /b 0 26 | 27 | :fail 28 | echo ** Build Failed ** 29 | exit /b 1 30 | -------------------------------------------------------------------------------- /data/FMI_template/build/build_VC_x64_vc2015.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: setup VC environment variables 4 | set VCVARSALL_PATH="c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 5 | call %VCVARSALL_PATH% 6 | 7 | :: FMU-specific variables - set by code generator 8 | set FMU_SHARED_LIB_NAME=FMI_template.dll 9 | 10 | set CMAKELISTSDIR=%CD%\.. 11 | 12 | :: create and change into build subdir 13 | mkdir bb_VC_x64 14 | pushd bb_VC_x64 15 | 16 | :: configure makefiles and build 17 | cmake -G "NMake Makefiles" %CMAKELISTSDIR% -DCMAKE_BUILD_TYPE:String="Release" 18 | nmake 19 | if ERRORLEVEL 1 GOTO fail 20 | 21 | popd 22 | 23 | :: copy executable to bin/release dir 24 | xcopy /Y .\bb_VC_x64\%FMU_SHARED_LIB_NAME% ..\bin\release_x64 25 | 26 | exit /b 0 27 | 28 | :fail 29 | echo ** Build Failed ** 30 | exit /b 1 31 | -------------------------------------------------------------------------------- /data/FMI_template/build/build_VC_x64_vc2019.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: setup VC environment variables 4 | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat" 5 | 6 | :: FMU-specific variables - set by code generator 7 | set FMU_SHARED_LIB_NAME=FMI_template.dll 8 | 9 | set CMAKELISTSDIR=%CD%\.. 10 | 11 | :: create and change into build subdir 12 | mkdir bb_VC_x64 13 | pushd bb_VC_x64 14 | 15 | :: configure makefiles and build 16 | cmake -G "NMake Makefiles" %CMAKELISTSDIR% -DCMAKE_BUILD_TYPE:String="Release" 17 | nmake 18 | if ERRORLEVEL 1 GOTO fail 19 | 20 | popd 21 | 22 | :: copy executable to bin/release dir 23 | xcopy /Y .\bb_VC_x64\%FMU_SHARED_LIB_NAME% ..\bin\release_x64 24 | 25 | exit /b 0 26 | 27 | :fail 28 | echo ** Build Failed ** 29 | exit /b 1 30 | -------------------------------------------------------------------------------- /data/FMI_template/build/build_VC_x64_vc2022.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: setup VC environment variables 4 | call "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" 5 | 6 | :: FMU-specific variables - set by code generator 7 | set FMU_SHARED_LIB_NAME=FMI_template.dll 8 | 9 | set CMAKELISTSDIR=%CD%\.. 10 | 11 | :: create and change into build subdir 12 | mkdir bb_VC_x64 13 | pushd bb_VC_x64 14 | 15 | :: configure makefiles and build 16 | cmake -G "NMake Makefiles" %CMAKELISTSDIR% -DCMAKE_BUILD_TYPE:String="Release" 17 | nmake 18 | if ERRORLEVEL 1 GOTO fail 19 | 20 | popd 21 | 22 | :: copy executable to bin/release dir 23 | xcopy /Y .\bb_VC_x64\%FMU_SHARED_LIB_NAME% ..\bin\release_x64 24 | 25 | exit /b 0 26 | 27 | :fail 28 | echo ** Build Failed ** 29 | exit /b 1 30 | -------------------------------------------------------------------------------- /data/FMI_template/build/deploy.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: script is supposed to be executed in /build directory 3 | 4 | if exist ..\bin\release_x64\FMI_template.dll goto DLL_EXISTS 5 | echo "ERROR: File FMI_template.dll expected in directory ..\bin\release_x64\FMI_template.dll, but does not exist. 6 | exit /b 1 7 | :DLL_EXISTS 8 | 9 | :: remove target directory if it exists 10 | if not exist FMI_template goto DIRECTORY_CLEAN 11 | echo Removing existing directory 'FMI_template' 12 | rd /S /Q "FMI_template" 13 | :DIRECTORY_CLEAN 14 | 15 | :: remove target FMU if it exists 16 | if not exist FMI_template.fmu goto FMU_REMOVED 17 | echo Removing existing FMU file 'FMI_template.fmu' 18 | del /F /S /Q "FMI_template.fmu" 19 | :FMU_REMOVED 20 | 21 | ::create subdir and change into it 22 | mkdir FMI_template 23 | 24 | cd FMI_template 25 | 26 | :: create binary dir for Windows 27 | mkdir binaries\win64 28 | 29 | :: copy shared library, we expect it to be already renamed correctly 30 | xcopy ..\..\bin\release_x64\FMI_template.dll binaries\win64\ 31 | xcopy ..\..\data\modelDescription.xml . 32 | echo Created FMU directory structure 33 | 34 | ::change working directory back to original dir 35 | cd .. 36 | 37 | ::create zip archive 38 | echo Creating archive 'FMI_template.zip' 39 | cd FMI_template 40 | 7za a ../FMI_template.zip . 41 | cd .. 42 | 43 | echo Renaming archive to 'FMI_template.fmu' 44 | rename FMI_template.zip FMI_template.fmu 45 | 46 | :: all ok 47 | exit /b 0 48 | -------------------------------------------------------------------------------- /data/FMI_template/build/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # script is supposed to be executed in /build directory 4 | 5 | # remove target directory if it exists 6 | if [ -d FMI_template ]; then 7 | rm -rf FMI_template 8 | fi && 9 | 10 | # remove target FMU if it exists 11 | if [ -f FMI_template.fmu ]; then 12 | rm FMI_template.fmu 13 | fi && 14 | 15 | # create subdir and change into it 16 | mkdir -p FMI_template && 17 | cd FMI_template && 18 | 19 | # create binary dir for Linux 20 | mkdir -p binaries/linux64 && 21 | 22 | # copy shared library, we expect it to be already renamed correctly 23 | cp ../../bin/release/FMI_template.so binaries/linux64/FMI_template.so && 24 | cp ../../data/modelDescription.xml . && 25 | 26 | # create zip archive 27 | 7za a ../FMI_template.zip . | cat > /dev/null && 28 | cd .. && 29 | mv FMI_template.zip FMI_template.fmu && 30 | echo "Created FMI_template.fmu" && 31 | 32 | # change working directory back to original dir 33 | cd - 34 | 35 | -------------------------------------------------------------------------------- /data/FMI_template/build/deployMac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # script is supposed to be executed in /build directory 4 | 5 | # remove target directory if it exists 6 | if [ -d FMI_template ]; then 7 | rm -rf FMI_template 8 | fi && 9 | 10 | # remove target FMU if it exists 11 | if [ -f FMI_template.fmu ]; then 12 | rm FMI_template.fmu 13 | fi && 14 | 15 | # create subdir and change into it 16 | mkdir -p FMI_template && 17 | cd FMI_template && 18 | 19 | # create binary dir for Linux 20 | mkdir -p binaries/darwin64 && 21 | 22 | # copy shared library, we expect it to be already renamed correctly 23 | cp ../../bin/release/FMI_template.dylib binaries/darwin64/FMI_template.dylib && 24 | cp ../../data/modelDescription.xml . && 25 | 26 | # create zip archive 27 | zip -r ../FMI_template.zip . | cat > /dev/null && 28 | cd .. && 29 | mv FMI_template.zip FMI_template.fmu && 30 | echo "Created FMI_template.fmu" && 31 | 32 | # change working directory back to original dir 33 | cd - 34 | 35 | -------------------------------------------------------------------------------- /data/FMI_template/build/readme.md: -------------------------------------------------------------------------------- 1 | When using different Visual Studio variants on Windows, 2 | copy the respective build_VC_x64_vcxxxx.bat to build_VC_x64.bat in the template directory 3 | before creating an FMU. 4 | 5 | Or, alternatively, adjust the path to the vcvarsall.bat in build_VC_x64.bat. 6 | -------------------------------------------------------------------------------- /data/FMI_template/data/modelDescription.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 25 | 26 | 33 | 34 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | $$scalarVariables$$ 58 | 59 | 60 | 61 | $$outputDependencies$$ 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /data/FMI_template/src/FMI_template.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | FMI Interface for FMU generated by FMICodeGenerator. 4 | 5 | This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 6 | 7 | BSD 3-Clause License 8 | 9 | Copyright (c) 2018, Andreas Nicolai 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, 19 | this list of conditions and the following disclaimer in the documentation 20 | and/or other materials provided with the distribution. 21 | 22 | * Neither the name of the copyright holder nor the names of its 23 | contributors may be used to endorse or promote products derived from 24 | this software without specific prior written permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | */ 38 | 39 | #ifndef FMI_templateH 40 | #define FMI_templateH 41 | 42 | #include "fmi2common/InstanceData.h" 43 | 44 | /*! This class wraps all data needed for a single instance of the FMU. */ 45 | class FMI_template : public InstanceData { 46 | public: 47 | /*! Initializes empty instance. */ 48 | FMI_template(); 49 | 50 | /*! Destructor, writes out cached results from Therakles. */ 51 | ~FMI_template(); 52 | 53 | /*! Initializes model */ 54 | void init(); 55 | 56 | /*! This function triggers a state-update of the embedded model whenever our cached input 57 | data differs from the input data in the model. 58 | */ 59 | void updateIfModified(); 60 | 61 | /*! Called from fmi2DoStep(). */ 62 | virtual void integrateTo(double tCommunicationIntervalEnd); 63 | 64 | // Functions for getting/setting the state 65 | 66 | /*! This function computes the size needed for full serizalization of 67 | the FMU and stores the size in m_fmuStateSize. 68 | \note The size includes the leading 8byte for the 64bit integer size 69 | of the memory array (for testing purposes). 70 | */ 71 | virtual void computeFMUStateSize(); 72 | 73 | /*! Copies the internal state of the FMU to the memory array pointed to by FMUstate. 74 | Memory array always has size m_fmuStateSize. 75 | */ 76 | virtual void serializeFMUstate(void * FMUstate); 77 | 78 | /*! Copies the content of the memory array pointed to by FMUstate to the internal state of the FMU. 79 | Memory array always has size m_fmuStateSize. 80 | */ 81 | virtual bool deserializeFMUstate(void * FMUstate); 82 | 83 | /*! Cached current time point of the FMU, defines starting point for time integration in co-simulation mode. */ 84 | double m_currentTimePoint; 85 | }; // class FMI_template 86 | 87 | #endif // FMI_templateH 88 | 89 | -------------------------------------------------------------------------------- /data/FMI_template/src/fmi2common/InstanceData.cpp: -------------------------------------------------------------------------------- 1 | /* Generic FMI Interface Implementation 2 | 3 | This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 4 | 5 | BSD 3-Clause License 6 | 7 | Copyright (c) 2018, Andreas Nicolai 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "InstanceData.h" 38 | 39 | #include 40 | #include 41 | 42 | #include "fmi2Functions.h" 43 | #include "fmi2FunctionTypes.h" 44 | 45 | InstanceData::InstanceData() : 46 | m_callbackFunctions(0), 47 | m_initializationMode(false), 48 | m_modelExchange(true), 49 | m_tInput(0), 50 | m_externalInputVarsModified(false), 51 | m_fmuStateSize(0) 52 | { 53 | } 54 | 55 | 56 | InstanceData::~InstanceData() { 57 | for (std::set::iterator it = m_fmuStates.begin(); it != m_fmuStates.end(); ++it) { 58 | free(*it); 59 | } 60 | } 61 | 62 | 63 | void InstanceData::logger(fmi2Status state, fmi2String category, fmi2String message) { 64 | if (m_loggingOn) { 65 | m_callbackFunctions->logger(m_callbackFunctions->componentEnvironment, 66 | m_instanceName.c_str(), state, category, 67 | message); 68 | } 69 | } 70 | 71 | 72 | template 73 | void checkIfIDExists(const T & m, int varID) { 74 | if (m.find(varID) == m.end() ) { 75 | std::stringstream strm; 76 | strm << "Invalid or unknown value reference " << varID; 77 | throw std::runtime_error(strm.str()); 78 | } 79 | } 80 | 81 | void InstanceData::setReal(int varID, double value) { 82 | checkIfIDExists(m_realVar, varID); 83 | m_realVar[varID] = value; 84 | m_externalInputVarsModified = true; 85 | } 86 | 87 | 88 | void InstanceData::setInt(int varID, int value) { 89 | checkIfIDExists(m_integerVar, varID); 90 | m_integerVar[varID] = value; 91 | m_externalInputVarsModified = true; 92 | } 93 | 94 | 95 | void InstanceData::setString(int varID, fmi2String value) { 96 | checkIfIDExists(m_stringVar, varID); 97 | m_stringVar[varID] = value; 98 | m_externalInputVarsModified = true; 99 | } 100 | 101 | 102 | void InstanceData::setBool(int varID, bool value) { 103 | checkIfIDExists(m_boolVar, varID); 104 | m_boolVar[varID] = value; 105 | m_externalInputVarsModified = true; 106 | } 107 | 108 | 109 | void InstanceData::getReal(int varID, double & value) { 110 | // update procedure for model exchange 111 | if (m_modelExchange) 112 | updateIfModified(); 113 | checkIfIDExists(m_realVar, varID); 114 | value = m_realVar[varID]; 115 | } 116 | 117 | 118 | void InstanceData::getInt(int varID, int & value) { 119 | // update procedure for model exchange 120 | if(m_modelExchange) 121 | updateIfModified(); 122 | checkIfIDExists(m_integerVar, varID); 123 | value = m_integerVar[varID]; 124 | } 125 | 126 | 127 | void InstanceData::getString(int varID, fmi2String & value) { 128 | // update procedure for model exchange 129 | if(m_modelExchange) 130 | updateIfModified(); 131 | checkIfIDExists(m_stringVar, varID); 132 | value = m_stringVar[varID].c_str(); 133 | } 134 | 135 | 136 | void InstanceData::getBool(int varID, bool & value) { 137 | // update procedure for model exchange 138 | if(m_modelExchange) 139 | updateIfModified(); 140 | checkIfIDExists(m_boolVar, varID); 141 | value = m_boolVar[varID]; 142 | } 143 | 144 | 145 | void InstanceData::completedIntegratorStep() { 146 | // this function must only be called in ModelExchange mode!!! 147 | if (!m_modelExchange) 148 | throw std::runtime_error("Invalid function call; only permitted in ModelExchange mode."); 149 | updateIfModified(); 150 | completedIntegratorStep(m_tInput, &m_yInput[0]); 151 | } 152 | 153 | -------------------------------------------------------------------------------- /data/FMI_template/src/fmi2common/fmi2Functions_complete.h: -------------------------------------------------------------------------------- 1 | /* Inquire version numbers of header files */ 2 | 1 FMI2_Export const char* fmi2GetTypesPlatform(void); 3 | 2 FMI2_Export const char* fmi2GetVersion(void); 4 | 7 FMI2_Export fmi2Status fmi2SetDebugLogging(void* c, int loggingOn, size_t nCategories, const (const char* categories)[]); 5 | 6 | /* Creation and destruction of FMU instances */ 7 | 3 FMI2_Export void* fmi2Instantiate(const char* instanceName, fmi2Type fmuType, const char* fmuGUID, 8 | const char* fmuResourceLocation, const fmi2CallbackFunctions* functions, int visible, int loggingOn); 9 | 6 FMI2_Export void fmi2FreeInstance(void* c); 10 | 11 | /* Enter and exit initialization mode, terminate and reset */ 12 | 32 FMI2_Export fmi2Status fmi2SetupExperiment(void* c, int toleranceDefined, double tolerance, double startTime, int stopTimeDefined, double stopTime); 13 | 4 FMI2_Export fmi2Status fmi2EnterInitializationMode(void* c); 14 | 5 FMI2_Export fmi2Status fmi2ExitInitializationMode(void* c); 15 | 22 FMI2_Export fmi2Status fmi2Terminate(void* c); 16 | 23 FMI2_Export fmi2Status fmi2Reset(void* c); 17 | 18 | /* Getting and setting variables values */ 19 | 14 FMI2_Export fmi2Status fmi2GetReal(void* c, const unsigned int vr[], size_t nvr, double value[]); 20 | 18 FMI2_Export fmi2Status fmi2GetInteger(void* c, const unsigned int vr[], size_t nvr, int value[]); 21 | 19 FMI2_Export fmi2Status fmi2GetBoolean(void* c, const unsigned int vr[], size_t nvr, int value[]); 22 | 20 FMI2_Export fmi2Status fmi2GetString (void* c, const unsigned int vr[], size_t nvr, (const char* value)[]); 23 | 24 | 13 FMI2_Export fmi2Status fmi2SetReal(void* c, const unsigned int vr[], size_t nvr, const double value[]); 25 | 15 FMI2_Export fmi2Status fmi2SetInteger(void* c, const unsigned int vr[], size_t nvr, const int value[]); 26 | 16 FMI2_Export fmi2Status fmi2SetBoolean(void* c, const unsigned int vr[], size_t nvr, const int value[]); 27 | 17 FMI2_Export fmi2Status fmi2SetString(void* c, const unsigned int vr[], size_t nvr, const (const char* value[])); 28 | 29 | /* Getting and setting the internal FMU state */ 30 | 26 FMI2_Export fmi2Status fmi2GetFMUstate(void* c, fmi2FMUstate* FMUstate); 31 | 27 FMI2_Export fmi2Status fmi2SetFMUstate(void* c, fmi2FMUstate FMUstate); 32 | 28 FMI2_Export fmi2Status fmi2FreeFMUstate(void* c, fmi2FMUstate* FMUstate); 33 | 29 FMI2_Export fmi2Status fmi2SerializedFMUstateSize(void* c, fmi2FMUstate FMUstate, size_t* size); 34 | 30 FMI2_Export fmi2Status fmi2SerializeFMUstate(void* c, fmi2FMUstate FMUstate, char serializedState[], size_t size); 35 | 31 FMI2_Export fmi2Status fmi2DeSerializeFMUstate(void* c, const char serializedState[], size_t size, fmi2FMUstate* FMUstate); 36 | 37 | /* Getting partial derivatives */ 38 | 33 FMI2_Export fmi2Status fmi2GetDirectionalDerivative(void* c, const unsigned int vUnknown_ref[], size_t nUnknown, 39 | const unsigned int vKnown_ref[], size_t nKnown, 40 | const double vKnown[], double dvUnknown[]); 41 | 42 | /*************************************************** 43 | Functions for FMI2 for Model Exchange 44 | ****************************************************/ 45 | 46 | /* Enter and exit the different modes */ 47 | 21 FMI2_Export fmi2Status fmi2EnterEventMode(void* c); 48 | 34 FMI2_Export fmi2Status fmi2NewDiscreteStates(void* c, fmi2EventInfo* fmi2eventInfo); 49 | 35 FMI2_Export fmi2Status fmi2EnterContinuousTimeMode(void* c); 50 | 24 FMI2_Export fmi2Status fmi2CompletedIntegratorStep(void* c, int noSetFMUStatePriorToCurrentPoint, int* enterEventMode, int* terminateSimulation); 51 | 52 | /* Providing independent variables and re-initialization of caching */ 53 | 8 FMI2_Export fmi2Status fmi2SetTime(void* c, double time); 54 | 9 FMI2_Export fmi2Status fmi2SetContinuousStates(void* c, const double x[], size_t nx); 55 | 56 | /* Evaluation of the model equations */ 57 | 12 FMI2_Export fmi2Status fmi2GetDerivatives(void* c, double derivatives[], size_t nx); 58 | 25 FMI2_Export fmi2Status fmi2GetEventIndicators(void* c, double eventIndicators[], size_t ni); 59 | 10 FMI2_Export fmi2Status fmi2GetContinuousStates(void* c, double x[], size_t nx); 60 | 11 FMI2_Export fmi2Status fmi2GetNominalsOfContinuousStates(void* c, double x_nominal[], size_t nx); 61 | 62 | 63 | /*************************************************** 64 | Functions for FMI2 for Co-Simulation 65 | ****************************************************/ 66 | 67 | /* Simulating the slave */ 68 | FMI2_Export fmi2Status fmi2SetRealInputDerivatives(void* c, const unsigned int vr[], size_t nvr, const int order[], const double value[]); 69 | FMI2_Export fmi2Status fmi2GetRealOutputDerivatives(void* c, const unsigned int vr[], size_t nvr, const int order[], double value[]); 70 | 71 | FMI2_Export fmi2Status fmi2DoStep(void* c, double currentCommunicationPoint, double communicationStepSize, int noSetFMUStatePriorToCurrentPoint); 72 | FMI2_Export fmi2Status fmi2CancelStep (void* c); 73 | 74 | /* Inquire slave status */ 75 | FMI2_Export fmi2Status fmi2GetStatus(void* c, const fmi2StatusKind s, fmi2Status* value); 76 | FMI2_Export fmi2Status fmi2GetRealStatus(void* c, const fmi2StatusKind s, double* value); 77 | FMI2_Export fmi2Status fmi2GetIntegerStatus(void* c, const fmi2StatusKind s, int* value); 78 | FMI2_Export fmi2Status fmi2GetBooleanStatus(void* c, const fmi2StatusKind s, int* value); 79 | FMI2_Export fmi2Status fmi2GetStringStatus(void* c, const fmi2StatusKind s, const char** value); 80 | -------------------------------------------------------------------------------- /data/FMI_template/src/fmi2common/fmi2TypesPlatform.h: -------------------------------------------------------------------------------- 1 | #ifndef fmi2TypesPlatform_h 2 | #define fmi2TypesPlatform_h 3 | 4 | /* Standard header file to define the argument types of the 5 | functions of the Functional Mock-up Interface 2.0. 6 | This header file must be utilized both by the model and 7 | by the simulation engine. 8 | 9 | Revisions: 10 | - Apr. 9, 2014: all prefixes "fmi" renamed to "fmi2" (decision from April 8) 11 | - Mar 31, 2014: New datatype fmiChar introduced. 12 | - Feb. 17, 2013: Changed fmiTypesPlatform from "standard32" to "default". 13 | Removed fmiUndefinedValueReference since no longer needed 14 | (because every state is defined in ScalarVariables). 15 | - March 20, 2012: Renamed from fmiPlatformTypes.h to fmiTypesPlatform.h 16 | - Nov. 14, 2011: Use the header file "fmiPlatformTypes.h" for FMI 2.0 17 | both for "FMI for model exchange" and for "FMI for co-simulation" 18 | New types "fmiComponentEnvironment", "fmiState", and "fmiByte". 19 | The implementation of "fmiBoolean" is change from "char" to "int". 20 | The #define "fmiPlatform" changed to "fmiTypesPlatform" 21 | (in order that #define and function call are consistent) 22 | - Oct. 4, 2010: Renamed header file from "fmiModelTypes.h" to fmiPlatformTypes.h" 23 | for the co-simulation interface 24 | - Jan. 4, 2010: Renamed meModelTypes_h to fmiModelTypes_h (by Mauss, QTronic) 25 | - Dec. 21, 2009: Changed "me" to "fmi" and "meModel" to "fmiComponent" 26 | according to meeting on Dec. 18 (by Martin Otter, DLR) 27 | - Dec. 6, 2009: Added meUndefinedValueReference (by Martin Otter, DLR) 28 | - Sept. 9, 2009: Changes according to FMI-meeting on July 21: 29 | Changed "version" to "platform", "standard" to "standard32", 30 | Added a precise definition of "standard32" as comment 31 | (by Martin Otter, DLR) 32 | - July 19, 2009: Added "me" as prefix to file names, added meTrue/meFalse, 33 | and changed meValueReferenced from int to unsigned int 34 | (by Martin Otter, DLR). 35 | - March 2, 2009: Moved enums and function pointer definitions to 36 | ModelFunctions.h (by Martin Otter, DLR). 37 | - Dec. 3, 2008 : First version by Martin Otter (DLR) and 38 | Hans Olsson (Dynasim). 39 | 40 | 41 | Copyright © 2008-2011 MODELISAR consortium, 42 | 2012-2013 Modelica Association Project "FMI" 43 | All rights reserved. 44 | This file is licensed by the copyright holders under the BSD 2-Clause License 45 | (http://www.opensource.org/licenses/bsd-license.html): 46 | 47 | ---------------------------------------------------------------------------- 48 | Redistribution and use in source and binary forms, with or without 49 | modification, are permitted provided that the following conditions are met: 50 | 51 | - Redistributions of source code must retain the above copyright notice, 52 | this list of conditions and the following disclaimer. 53 | - Redistributions in binary form must reproduce the above copyright notice, 54 | this list of conditions and the following disclaimer in the documentation 55 | and/or other materials provided with the distribution. 56 | - Neither the name of the copyright holders nor the names of its 57 | contributors may be used to endorse or promote products derived 58 | from this software without specific prior written permission. 59 | 60 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 61 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 62 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 63 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 64 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 65 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 66 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 67 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 68 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 69 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 70 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 71 | ---------------------------------------------------------------------------- 72 | 73 | with the extension: 74 | 75 | You may distribute or publicly perform any modification only under the 76 | terms of this license. 77 | (Note, this means that if you distribute a modified file, 78 | the modified file must also be provided under this license). 79 | */ 80 | 81 | /* Platform (unique identification of this header file) */ 82 | #define fmi2TypesPlatform "default" 83 | 84 | /* Type definitions of variables passed as arguments 85 | Version "default" means: 86 | 87 | fmi2Component : an opaque object pointer 88 | fmi2ComponentEnvironment: an opaque object pointer 89 | fmi2FMUstate : an opaque object pointer 90 | fmi2ValueReference : handle to the value of a variable 91 | fmi2Real : double precision floating-point data type 92 | fmi2Integer : basic signed integer data type 93 | fmi2Boolean : basic signed integer data type 94 | fmi2Char : character data type 95 | fmi2String : a pointer to a vector of fmi2Char characters 96 | ('\0' terminated, UTF8 encoded) 97 | fmi2Byte : smallest addressable unit of the machine, typically one byte. 98 | */ 99 | typedef void* fmi2Component; /* Pointer to FMU instance */ 100 | typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ 101 | typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ 102 | typedef unsigned int fmi2ValueReference; 103 | typedef double fmi2Real ; 104 | typedef int fmi2Integer; 105 | typedef int fmi2Boolean; 106 | typedef char fmi2Char; 107 | typedef const fmi2Char* fmi2String; 108 | typedef char fmi2Byte; 109 | 110 | /* Values for fmi2Boolean */ 111 | #define fmi2True 1 112 | #define fmi2False 0 113 | 114 | 115 | #endif /* fmi2TypesPlatform_h */ 116 | -------------------------------------------------------------------------------- /data/check/.gitignore: -------------------------------------------------------------------------------- 1 | /P_control/ 2 | -------------------------------------------------------------------------------- /data/check/RealInputTest.input: -------------------------------------------------------------------------------- 1 | { 2 | "variables": [ 3 | { 4 | "variability": "continuous", 5 | "causality": "input", 6 | "name": "A", 7 | "typeID": "Real", 8 | "valueRef": -1, 9 | "initial": "approx", 10 | "startValue": "", 11 | "unit": "", 12 | "description": "" 13 | }, 14 | { 15 | "variability": "continuous", 16 | "causality": "input", 17 | "name": "B", 18 | "typeID": "Real", 19 | "valueRef": -1, 20 | "initial": "approx", 21 | "startValue": "", 22 | "unit": "", 23 | "description": "" 24 | }, 25 | { 26 | "variability": "continuous", 27 | "causality": "input", 28 | "name": "C", 29 | "typeID": "Real", 30 | "valueRef": -1, 31 | "initial": "approx", 32 | "startValue": "", 33 | "unit": "", 34 | "description": "" 35 | } 36 | ], 37 | "modelName": "RealInputTest", 38 | "description": "A test whether real inputs are handled correctly." 39 | } -------------------------------------------------------------------------------- /data/check/RealInputTest/bin/debug/.gitignore: -------------------------------------------------------------------------------- 1 | /libRealInputTest.so 2 | /libRealInputTest.so.1 3 | /libRealInputTest.so.1.0 4 | /libRealInputTest.so.1.0.0 5 | -------------------------------------------------------------------------------- /data/check/RealInputTest/bin/release/.gitignore: -------------------------------------------------------------------------------- 1 | *.so1.0.0 2 | *.dylib 3 | /libRealInputTest.so.1.0.0 4 | -------------------------------------------------------------------------------- /data/check/RealInputTest/bin/release/readme.md: -------------------------------------------------------------------------------- 1 | Target directory for generated shared library file. 2 | 3 | -------------------------------------------------------------------------------- /data/check/RealInputTest/bin/release_x64/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /data/check/RealInputTest/bin/release_x64/readme.md: -------------------------------------------------------------------------------- 1 | This directory is for x64 windows binaries. -------------------------------------------------------------------------------- /data/check/RealInputTest/build/.gitignore: -------------------------------------------------------------------------------- 1 | /bb-gcc/ 2 | -------------------------------------------------------------------------------- /data/check/RealInputTest/build/build_VC_x64.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: setup VC environment variables 4 | set VCVARSALL_PATH="c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 5 | call %VCVARSALL_PATH% 6 | 7 | :: FMU-specific variables - set by code generator 8 | set FMU_SHARED_LIB_NAME=RealInputTest.dll 9 | 10 | set CMAKELISTSDIR=%CD%\..\projects\cmake 11 | 12 | :: create and change into build subdir 13 | mkdir bb_VC_x64 14 | pushd bb_VC_x64 15 | 16 | :: configure makefiles and build 17 | cmake -G "NMake Makefiles" %CMAKELISTSDIR% -DCMAKE_BUILD_TYPE:String="Release" 18 | nmake 19 | if ERRORLEVEL 1 GOTO fail 20 | 21 | popd 22 | 23 | :: copy executable to bin/release dir 24 | xcopy /Y .\bb_VC_x64\%FMU_SHARED_LIB_NAME% ..\bin\release_x64 25 | 26 | exit /b 0 27 | 28 | :fail 29 | echo ** Build Failed ** 30 | exit /b 1 31 | -------------------------------------------------------------------------------- /data/check/RealInputTest/build/deploy.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: script is supposed to be executed in /build directory 3 | 4 | if exist ..\bin\release_x64\RealInputTest.dll goto DLL_EXISTS 5 | echo "ERROR: File RealInputTest.dll expected in directory ..\bin\release_x64\RealInputTest.dll, but does not exist. 6 | exit /b 1 7 | :DLL_EXISTS 8 | 9 | :: remove target directory if it exists 10 | if not exist RealInputTest goto DIRECTORY_CLEAN 11 | echo Removing existing directory 'RealInputTest' 12 | rd /S /Q "RealInputTest" 13 | :DIRECTORY_CLEAN 14 | 15 | :: remove target FMU if it exists 16 | if not exist RealInputTest.fmu goto FMU_REMOVED 17 | echo Removing existing FMU file 'RealInputTest.fmu' 18 | del /F /S /Q "RealInputTest.fmu" 19 | :FMU_REMOVED 20 | 21 | ::create subdir and change into it 22 | mkdir RealInputTest 23 | 24 | cd RealInputTest 25 | 26 | :: create binary dir for Windows 27 | mkdir binaries\win64 28 | 29 | :: copy shared library, we expect it to be already renamed correctly 30 | xcopy ..\..\bin\release_x64\RealInputTest.dll binaries\win64\ 31 | xcopy ..\..\data\modelDescription.xml . 32 | echo Created FMU directory structure 33 | 34 | ::change working directory back to original dir 35 | cd .. 36 | 37 | ::create zip archive 38 | echo Creating archive 'RealInputTest.zip' 39 | cd RealInputTest 40 | 7za a ../RealInputTest.zip . 41 | cd .. 42 | 43 | echo Renaming archive to 'RealInputTest.fmu' 44 | rename RealInputTest.zip RealInputTest.fmu 45 | 46 | :: all ok 47 | exit /b 0 48 | -------------------------------------------------------------------------------- /data/check/RealInputTest/build/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # script is supposed to be executed in /build directory 4 | 5 | # remove target directory if it exists 6 | if [ -d RealInputTest ]; then 7 | rm -rf RealInputTest 8 | fi && 9 | 10 | # remove target FMU if it exists 11 | if [ -f RealInputTest.fmu ]; then 12 | rm RealInputTest.fmu 13 | fi && 14 | 15 | # create subdir and change into it 16 | mkdir -p RealInputTest && 17 | cd RealInputTest && 18 | 19 | # create binary dir for Linux 20 | mkdir -p binaries/linux64 && 21 | 22 | # copy shared library, we expect it to be already renamed correctly 23 | cp ../../bin/release/RealInputTest.so binaries/linux64/RealInputTest.so && 24 | cp ../../data/modelDescription.xml . && 25 | 26 | # create zip archive 27 | 7za a ../RealInputTest.zip . | cat > /dev/null && 28 | cd .. && 29 | mv RealInputTest.zip RealInputTest.fmu && 30 | echo "Created RealInputTest.fmu" && 31 | 32 | # change working directory back to original dir 33 | cd - 34 | 35 | -------------------------------------------------------------------------------- /data/check/RealInputTest/data/modelDescription.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 25 | 26 | 33 | 34 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 66 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /data/check/RealInputTest/projects/.gitignore: -------------------------------------------------------------------------------- 1 | /build-* 2 | -------------------------------------------------------------------------------- /data/check/RealInputTest/projects/Qt/RealInputTest.pro: -------------------------------------------------------------------------------- 1 | # ---------------------------------- 2 | # Qt Project for building FMU 3 | # ---------------------------------- 4 | # 5 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 6 | # 7 | # BSD 3-Clause License 8 | # 9 | # Copyright (c) 2018, Andreas Nicolai 10 | # All rights reserved. 11 | # 12 | # see https://github.com/ghorwin/FMICodeGenerator/blob/master/LICENSE for details. 13 | 14 | 15 | TARGET = RealInputTest 16 | TEMPLATE = lib 17 | 18 | # no GUI 19 | QT -= core gui 20 | 21 | CONFIG(debug, debug|release) { 22 | windows { 23 | DLLDESTDIR = ../../bin/debug$${DIR_PREFIX} 24 | } 25 | else { 26 | DESTDIR = ../../bin/debug$${DIR_PREFIX} 27 | } 28 | } 29 | else { 30 | windows { 31 | DLLDESTDIR = ../../bin/release$${DIR_PREFIX} 32 | } 33 | else { 34 | DESTDIR = ../../bin/release$${DIR_PREFIX} 35 | } 36 | } 37 | 38 | #DEFINES += FMI2_FUNCTION_PREFIX=RealInputTest_ 39 | 40 | unix|mac { 41 | VER_MAJ = 1 42 | VER_MIN = 0 43 | VER_PAT = 0 44 | VERSION = $${VER_MAJ}.$${VER_MIN}.$${VER_PAT} 45 | } 46 | 47 | unix { 48 | QMAKE_POST_LINK += $$quote(mv $${DESTDIR}/lib$${TARGET}.so $${DESTDIR}/$${TARGET}.so) 49 | } 50 | 51 | INCLUDEPATH = ../../src 52 | 53 | SOURCES += \ 54 | ../../src/fmi2common/fmi2Functions.cpp \ 55 | ../../src/fmi2common/InstanceData.cpp \ 56 | ../../src/RealInputTest.cpp 57 | 58 | HEADERS += \ 59 | ../../src/fmi2common/fmi2Functions.h \ 60 | ../../src/fmi2common/fmi2Functions_complete.h \ 61 | ../../src/fmi2common/fmi2FunctionTypes.h \ 62 | ../../src/fmi2common/fmi2TypesPlatform.h \ 63 | ../../src/fmi2common/InstanceData.h \ 64 | ../../src/RealInputTest.h 65 | 66 | 67 | -------------------------------------------------------------------------------- /data/check/RealInputTest/projects/cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMake project file for generated FMI code 2 | # 3 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 4 | # 5 | # BSD 3-Clause License 6 | # 7 | # Copyright (c) 2018, Andreas Nicolai 8 | # All rights reserved. 9 | # 10 | # see https://github.com/ghorwin/FMICodeGenerator/blob/master/LICENSE for details. 11 | 12 | project( RealInputTest ) 13 | 14 | cmake_minimum_required(VERSION 3.5) 15 | 16 | # add include directories 17 | include_directories( 18 | ${PROJECT_SOURCE_DIR}/../../src 19 | ) 20 | 21 | add_library( ${PROJECT_NAME} SHARED 22 | ${PROJECT_SOURCE_DIR}/../../src/${PROJECT_NAME}.cpp 23 | ${PROJECT_SOURCE_DIR}/../../src/fmi2common/fmi2Functions.cpp 24 | ${PROJECT_SOURCE_DIR}/../../src/fmi2common/InstanceData.cpp 25 | ) 26 | 27 | # link against the dependent libraries 28 | target_link_libraries( ${PROJECT_NAME} 29 | ${APPLE_FRAMEWORKS} 30 | ) 31 | 32 | # Library version strings set by code generator 33 | set( SO_VERSION_MAJOR 1) 34 | set( SO_VERSION_MINOR 0) 35 | set( SO_VERSION_PATCH 0) 36 | set( SO_VERSION_STRING 37 | ${SO_VERSION_MAJOR}.${SO_VERSION_MINOR}.${SO_VERSION_PATCH} 38 | ) 39 | 40 | set_target_properties( ${PROJECT_NAME} PROPERTIES 41 | VERSION ${SO_VERSION_STRING} 42 | SOVERSION ${SO_VERSION_MAJOR} 43 | ) 44 | -------------------------------------------------------------------------------- /data/check/RealInputTest/src/RealInputTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | FMI Interface for FMU generated by FMICodeGenerator. 4 | 5 | This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 6 | 7 | BSD 3-Clause License 8 | 9 | Copyright (c) 2018, Andreas Nicolai 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, 19 | this list of conditions and the following disclaimer in the documentation 20 | and/or other materials provided with the distribution. 21 | 22 | * Neither the name of the copyright holder nor the names of its 23 | contributors may be used to endorse or promote products derived from 24 | this software without specific prior written permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | */ 38 | 39 | #ifndef RealInputTestH 40 | #define RealInputTestH 41 | 42 | #include "fmi2common/InstanceData.h" 43 | 44 | /*! This class wraps all data needed for a single instance of the FMU. */ 45 | class RealInputTest : public InstanceData { 46 | public: 47 | /*! Initializes empty instance. */ 48 | RealInputTest(); 49 | 50 | /*! Destructor, writes out cached results from Therakles. */ 51 | ~RealInputTest(); 52 | 53 | /*! Initializes model */ 54 | void init(); 55 | 56 | /*! This function triggers a state-update of the embedded model whenever our cached input 57 | data differs from the input data in the model. 58 | */ 59 | void updateIfModified(); 60 | 61 | /*! Called from fmi2DoStep(). */ 62 | virtual void integrateTo(double tCommunicationIntervalEnd); 63 | 64 | // Functions for getting/setting the state 65 | 66 | /*! This function computes the size needed for full serizalization of 67 | the FMU and stores the size in m_fmuStateSize. 68 | \note The size includes the leading 8byte for the 64bit integer size 69 | of the memory array (for testing purposes). 70 | */ 71 | virtual void computeFMUStateSize(); 72 | 73 | /*! Copies the internal state of the FMU to the memory array pointed to by FMUstate. 74 | Memory array always has size m_fmuStateSize. 75 | */ 76 | virtual void serializeFMUstate(void * FMUstate); 77 | 78 | /*! Copies the content of the memory array pointed to by FMUstate to the internal state of the FMU. 79 | Memory array always has size m_fmuStateSize. 80 | */ 81 | virtual bool deserializeFMUstate(void * FMUstate); 82 | 83 | /*! Cached current time point of the FMU, defines starting point for time integration in co-simulation mode. */ 84 | double m_currentTimePoint; 85 | }; // class RealInputTest 86 | 87 | #endif // RealInputTestH 88 | 89 | -------------------------------------------------------------------------------- /data/check/RealInputTest/src/fmi2common/InstanceData.cpp: -------------------------------------------------------------------------------- 1 | /* Generic FMI Interface Implementation 2 | 3 | This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 4 | 5 | BSD 3-Clause License 6 | 7 | Copyright (c) 2018, Andreas Nicolai 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "InstanceData.h" 38 | 39 | #include 40 | #include 41 | 42 | #include "fmi2Functions.h" 43 | #include "fmi2FunctionTypes.h" 44 | 45 | InstanceData::InstanceData() : 46 | m_callbackFunctions(0), 47 | m_initializationMode(false), 48 | m_modelExchange(true), 49 | m_tInput(0), 50 | m_externalInputVarsModified(false), 51 | m_fmuStateSize(0) 52 | { 53 | } 54 | 55 | 56 | InstanceData::~InstanceData() { 57 | for (std::set::iterator it = m_fmuStates.begin(); it != m_fmuStates.end(); ++it) { 58 | free(*it); 59 | } 60 | } 61 | 62 | 63 | void InstanceData::logger(fmi2Status state, fmi2String category, fmi2String message) { 64 | if (m_loggingOn) { 65 | m_callbackFunctions->logger(m_callbackFunctions->componentEnvironment, 66 | m_instanceName.c_str(), state, category, 67 | message); 68 | } 69 | } 70 | 71 | 72 | template 73 | void checkIfIDExists(const T & m, int varID) { 74 | if (m.find(varID) == m.end() ) { 75 | std::stringstream strm; 76 | strm << "Invalid or unknown value reference " << varID; 77 | throw std::runtime_error(strm.str()); 78 | } 79 | } 80 | 81 | void InstanceData::setReal(int varID, double value) { 82 | checkIfIDExists(m_realVar, varID); 83 | m_realVar[varID] = value; 84 | m_externalInputVarsModified = true; 85 | } 86 | 87 | 88 | void InstanceData::setInt(int varID, int value) { 89 | checkIfIDExists(m_integerVar, varID); 90 | m_integerVar[varID] = value; 91 | m_externalInputVarsModified = true; 92 | } 93 | 94 | 95 | void InstanceData::setString(int varID, fmi2String value) { 96 | checkIfIDExists(m_stringVar, varID); 97 | m_stringVar[varID] = value; 98 | m_externalInputVarsModified = true; 99 | } 100 | 101 | 102 | void InstanceData::setBool(int varID, bool value) { 103 | checkIfIDExists(m_boolVar, varID); 104 | m_boolVar[varID] = value; 105 | m_externalInputVarsModified = true; 106 | } 107 | 108 | 109 | void InstanceData::getReal(int varID, double & value) { 110 | // update procedure for model exchange 111 | if (m_modelExchange) 112 | updateIfModified(); 113 | checkIfIDExists(m_realVar, varID); 114 | value = m_realVar[varID]; 115 | } 116 | 117 | 118 | void InstanceData::getInt(int varID, int & value) { 119 | // update procedure for model exchange 120 | if(m_modelExchange) 121 | updateIfModified(); 122 | checkIfIDExists(m_integerVar, varID); 123 | value = m_integerVar[varID]; 124 | } 125 | 126 | 127 | void InstanceData::getString(int varID, fmi2String & value) { 128 | // update procedure for model exchange 129 | if(m_modelExchange) 130 | updateIfModified(); 131 | checkIfIDExists(m_stringVar, varID); 132 | value = m_stringVar[varID].c_str(); 133 | } 134 | 135 | 136 | void InstanceData::getBool(int varID, bool & value) { 137 | // update procedure for model exchange 138 | if(m_modelExchange) 139 | updateIfModified(); 140 | checkIfIDExists(m_boolVar, varID); 141 | value = m_boolVar[varID]; 142 | } 143 | 144 | 145 | void InstanceData::completedIntegratorStep() { 146 | // this function must only be called in ModelExchange mode!!! 147 | if (!m_modelExchange) 148 | throw std::runtime_error("Invalid function call; only permitted in ModelExchange mode."); 149 | updateIfModified(); 150 | completedIntegratorStep(m_tInput, &m_yInput[0]); 151 | } 152 | 153 | -------------------------------------------------------------------------------- /data/check/RealInputTest/src/fmi2common/fmi2Functions_complete.h: -------------------------------------------------------------------------------- 1 | /* Inquire version numbers of header files */ 2 | 1 FMI2_Export const char* fmi2GetTypesPlatform(void); 3 | 2 FMI2_Export const char* fmi2GetVersion(void); 4 | 7 FMI2_Export fmi2Status fmi2SetDebugLogging(void* c, int loggingOn, size_t nCategories, const (const char* categories)[]); 5 | 6 | /* Creation and destruction of FMU instances */ 7 | 3 FMI2_Export void* fmi2Instantiate(const char* instanceName, fmi2Type fmuType, const char* fmuGUID, 8 | const char* fmuResourceLocation, const fmi2CallbackFunctions* functions, int visible, int loggingOn); 9 | 6 FMI2_Export void fmi2FreeInstance(void* c); 10 | 11 | /* Enter and exit initialization mode, terminate and reset */ 12 | 32 FMI2_Export fmi2Status fmi2SetupExperiment(void* c, int toleranceDefined, double tolerance, double startTime, int stopTimeDefined, double stopTime); 13 | 4 FMI2_Export fmi2Status fmi2EnterInitializationMode(void* c); 14 | 5 FMI2_Export fmi2Status fmi2ExitInitializationMode(void* c); 15 | 22 FMI2_Export fmi2Status fmi2Terminate(void* c); 16 | 23 FMI2_Export fmi2Status fmi2Reset(void* c); 17 | 18 | /* Getting and setting variables values */ 19 | 14 FMI2_Export fmi2Status fmi2GetReal(void* c, const unsigned int vr[], size_t nvr, double value[]); 20 | 18 FMI2_Export fmi2Status fmi2GetInteger(void* c, const unsigned int vr[], size_t nvr, int value[]); 21 | 19 FMI2_Export fmi2Status fmi2GetBoolean(void* c, const unsigned int vr[], size_t nvr, int value[]); 22 | 20 FMI2_Export fmi2Status fmi2GetString (void* c, const unsigned int vr[], size_t nvr, (const char* value)[]); 23 | 24 | 13 FMI2_Export fmi2Status fmi2SetReal(void* c, const unsigned int vr[], size_t nvr, const double value[]); 25 | 15 FMI2_Export fmi2Status fmi2SetInteger(void* c, const unsigned int vr[], size_t nvr, const int value[]); 26 | 16 FMI2_Export fmi2Status fmi2SetBoolean(void* c, const unsigned int vr[], size_t nvr, const int value[]); 27 | 17 FMI2_Export fmi2Status fmi2SetString(void* c, const unsigned int vr[], size_t nvr, const (const char* value[])); 28 | 29 | /* Getting and setting the internal FMU state */ 30 | 26 FMI2_Export fmi2Status fmi2GetFMUstate(void* c, fmi2FMUstate* FMUstate); 31 | 27 FMI2_Export fmi2Status fmi2SetFMUstate(void* c, fmi2FMUstate FMUstate); 32 | 28 FMI2_Export fmi2Status fmi2FreeFMUstate(void* c, fmi2FMUstate* FMUstate); 33 | 29 FMI2_Export fmi2Status fmi2SerializedFMUstateSize(void* c, fmi2FMUstate FMUstate, size_t* size); 34 | 30 FMI2_Export fmi2Status fmi2SerializeFMUstate(void* c, fmi2FMUstate FMUstate, char serializedState[], size_t size); 35 | 31 FMI2_Export fmi2Status fmi2DeSerializeFMUstate(void* c, const char serializedState[], size_t size, fmi2FMUstate* FMUstate); 36 | 37 | /* Getting partial derivatives */ 38 | 33 FMI2_Export fmi2Status fmi2GetDirectionalDerivative(void* c, const unsigned int vUnknown_ref[], size_t nUnknown, 39 | const unsigned int vKnown_ref[], size_t nKnown, 40 | const double vKnown[], double dvUnknown[]); 41 | 42 | /*************************************************** 43 | Functions for FMI2 for Model Exchange 44 | ****************************************************/ 45 | 46 | /* Enter and exit the different modes */ 47 | 21 FMI2_Export fmi2Status fmi2EnterEventMode(void* c); 48 | 34 FMI2_Export fmi2Status fmi2NewDiscreteStates(void* c, fmi2EventInfo* fmi2eventInfo); 49 | 35 FMI2_Export fmi2Status fmi2EnterContinuousTimeMode(void* c); 50 | 24 FMI2_Export fmi2Status fmi2CompletedIntegratorStep(void* c, int noSetFMUStatePriorToCurrentPoint, int* enterEventMode, int* terminateSimulation); 51 | 52 | /* Providing independent variables and re-initialization of caching */ 53 | 8 FMI2_Export fmi2Status fmi2SetTime(void* c, double time); 54 | 9 FMI2_Export fmi2Status fmi2SetContinuousStates(void* c, const double x[], size_t nx); 55 | 56 | /* Evaluation of the model equations */ 57 | 12 FMI2_Export fmi2Status fmi2GetDerivatives(void* c, double derivatives[], size_t nx); 58 | 25 FMI2_Export fmi2Status fmi2GetEventIndicators(void* c, double eventIndicators[], size_t ni); 59 | 10 FMI2_Export fmi2Status fmi2GetContinuousStates(void* c, double x[], size_t nx); 60 | 11 FMI2_Export fmi2Status fmi2GetNominalsOfContinuousStates(void* c, double x_nominal[], size_t nx); 61 | 62 | 63 | /*************************************************** 64 | Functions for FMI2 for Co-Simulation 65 | ****************************************************/ 66 | 67 | /* Simulating the slave */ 68 | FMI2_Export fmi2Status fmi2SetRealInputDerivatives(void* c, const unsigned int vr[], size_t nvr, const int order[], const double value[]); 69 | FMI2_Export fmi2Status fmi2GetRealOutputDerivatives(void* c, const unsigned int vr[], size_t nvr, const int order[], double value[]); 70 | 71 | FMI2_Export fmi2Status fmi2DoStep(void* c, double currentCommunicationPoint, double communicationStepSize, int noSetFMUStatePriorToCurrentPoint); 72 | FMI2_Export fmi2Status fmi2CancelStep (void* c); 73 | 74 | /* Inquire slave status */ 75 | FMI2_Export fmi2Status fmi2GetStatus(void* c, const fmi2StatusKind s, fmi2Status* value); 76 | FMI2_Export fmi2Status fmi2GetRealStatus(void* c, const fmi2StatusKind s, double* value); 77 | FMI2_Export fmi2Status fmi2GetIntegerStatus(void* c, const fmi2StatusKind s, int* value); 78 | FMI2_Export fmi2Status fmi2GetBooleanStatus(void* c, const fmi2StatusKind s, int* value); 79 | FMI2_Export fmi2Status fmi2GetStringStatus(void* c, const fmi2StatusKind s, const char** value); 80 | -------------------------------------------------------------------------------- /data/check/RealInputTest/src/fmi2common/fmi2TypesPlatform.h: -------------------------------------------------------------------------------- 1 | #ifndef fmi2TypesPlatform_h 2 | #define fmi2TypesPlatform_h 3 | 4 | /* Standard header file to define the argument types of the 5 | functions of the Functional Mock-up Interface 2.0. 6 | This header file must be utilized both by the model and 7 | by the simulation engine. 8 | 9 | Revisions: 10 | - Apr. 9, 2014: all prefixes "fmi" renamed to "fmi2" (decision from April 8) 11 | - Mar 31, 2014: New datatype fmiChar introduced. 12 | - Feb. 17, 2013: Changed fmiTypesPlatform from "standard32" to "default". 13 | Removed fmiUndefinedValueReference since no longer needed 14 | (because every state is defined in ScalarVariables). 15 | - March 20, 2012: Renamed from fmiPlatformTypes.h to fmiTypesPlatform.h 16 | - Nov. 14, 2011: Use the header file "fmiPlatformTypes.h" for FMI 2.0 17 | both for "FMI for model exchange" and for "FMI for co-simulation" 18 | New types "fmiComponentEnvironment", "fmiState", and "fmiByte". 19 | The implementation of "fmiBoolean" is change from "char" to "int". 20 | The #define "fmiPlatform" changed to "fmiTypesPlatform" 21 | (in order that #define and function call are consistent) 22 | - Oct. 4, 2010: Renamed header file from "fmiModelTypes.h" to fmiPlatformTypes.h" 23 | for the co-simulation interface 24 | - Jan. 4, 2010: Renamed meModelTypes_h to fmiModelTypes_h (by Mauss, QTronic) 25 | - Dec. 21, 2009: Changed "me" to "fmi" and "meModel" to "fmiComponent" 26 | according to meeting on Dec. 18 (by Martin Otter, DLR) 27 | - Dec. 6, 2009: Added meUndefinedValueReference (by Martin Otter, DLR) 28 | - Sept. 9, 2009: Changes according to FMI-meeting on July 21: 29 | Changed "version" to "platform", "standard" to "standard32", 30 | Added a precise definition of "standard32" as comment 31 | (by Martin Otter, DLR) 32 | - July 19, 2009: Added "me" as prefix to file names, added meTrue/meFalse, 33 | and changed meValueReferenced from int to unsigned int 34 | (by Martin Otter, DLR). 35 | - March 2, 2009: Moved enums and function pointer definitions to 36 | ModelFunctions.h (by Martin Otter, DLR). 37 | - Dec. 3, 2008 : First version by Martin Otter (DLR) and 38 | Hans Olsson (Dynasim). 39 | 40 | 41 | Copyright © 2008-2011 MODELISAR consortium, 42 | 2012-2013 Modelica Association Project "FMI" 43 | All rights reserved. 44 | This file is licensed by the copyright holders under the BSD 2-Clause License 45 | (http://www.opensource.org/licenses/bsd-license.html): 46 | 47 | ---------------------------------------------------------------------------- 48 | Redistribution and use in source and binary forms, with or without 49 | modification, are permitted provided that the following conditions are met: 50 | 51 | - Redistributions of source code must retain the above copyright notice, 52 | this list of conditions and the following disclaimer. 53 | - Redistributions in binary form must reproduce the above copyright notice, 54 | this list of conditions and the following disclaimer in the documentation 55 | and/or other materials provided with the distribution. 56 | - Neither the name of the copyright holders nor the names of its 57 | contributors may be used to endorse or promote products derived 58 | from this software without specific prior written permission. 59 | 60 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 61 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 62 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 63 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 64 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 65 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 66 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 67 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 68 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 69 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 70 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 71 | ---------------------------------------------------------------------------- 72 | 73 | with the extension: 74 | 75 | You may distribute or publicly perform any modification only under the 76 | terms of this license. 77 | (Note, this means that if you distribute a modified file, 78 | the modified file must also be provided under this license). 79 | */ 80 | 81 | /* Platform (unique identification of this header file) */ 82 | #define fmi2TypesPlatform "default" 83 | 84 | /* Type definitions of variables passed as arguments 85 | Version "default" means: 86 | 87 | fmi2Component : an opaque object pointer 88 | fmi2ComponentEnvironment: an opaque object pointer 89 | fmi2FMUstate : an opaque object pointer 90 | fmi2ValueReference : handle to the value of a variable 91 | fmi2Real : double precision floating-point data type 92 | fmi2Integer : basic signed integer data type 93 | fmi2Boolean : basic signed integer data type 94 | fmi2Char : character data type 95 | fmi2String : a pointer to a vector of fmi2Char characters 96 | ('\0' terminated, UTF8 encoded) 97 | fmi2Byte : smallest addressable unit of the machine, typically one byte. 98 | */ 99 | typedef void* fmi2Component; /* Pointer to FMU instance */ 100 | typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ 101 | typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ 102 | typedef unsigned int fmi2ValueReference; 103 | typedef double fmi2Real ; 104 | typedef int fmi2Integer; 105 | typedef int fmi2Boolean; 106 | typedef char fmi2Char; 107 | typedef const fmi2Char* fmi2String; 108 | typedef char fmi2Byte; 109 | 110 | /* Values for fmi2Boolean */ 111 | #define fmi2True 1 112 | #define fmi2False 0 113 | 114 | 115 | #endif /* fmi2TypesPlatform_h */ 116 | -------------------------------------------------------------------------------- /data/check/input.tsv: -------------------------------------------------------------------------------- 1 | "time","A","B","C" 2 | 0,1.0,2.0,3.0 3 | -------------------------------------------------------------------------------- /data/check/readme.md: -------------------------------------------------------------------------------- 1 | # Real input test with input file support 2 | 3 | Command line to test: 4 | 5 | ./fmuCheck.linux64 -f -i input.tsv -o output.tsv ../RealInputTest/build/RealInputTest.fmu 6 | 7 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | /.DS_Store 2 | -------------------------------------------------------------------------------- /doc/FMI_specs/FMI_for_CoSimulation_v1.0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/doc/FMI_specs/FMI_for_CoSimulation_v1.0.pdf -------------------------------------------------------------------------------- /doc/FMI_specs/FMI_for_ModelExchange_and_CoSimulation_v2.0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/doc/FMI_specs/FMI_for_ModelExchange_and_CoSimulation_v2.0.pdf -------------------------------------------------------------------------------- /doc/FMI_specs/FMI_for_ModelExchange_v1.0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/doc/FMI_specs/FMI_for_ModelExchange_v1.0.pdf -------------------------------------------------------------------------------- /doc/Tutorial/readme.md: -------------------------------------------------------------------------------- 1 | # Concept: FMI Beginners Tutorial for Modelica Conference 2025 2 | 3 | - **Title:** FMI Beginners Tutorial - Writing an FMU in C/C++ 4 | - **Suggested duration of the tutorial:** 2 hours 5 | - **Presenter(s) name(s) and affiliation(s)**: Dr. Andreas Nicolai, Umwelt- und Ingenieurtechnik GmbH Dresden 6 | 7 | ## Abstract 8 | 9 | Purpose of the tutorial is to show the creation of a ModelExchange and a Co-Simulation FMU for a simple 10 | physical soil collector model to be used in domestic low energy district network. 11 | The model will be shortly explained and a brief overview of the coupled simulation scenario will be given. 12 | We'll start by designing a ModelExchange-FMU, defining interface variables (inputs and outputs, and parameters) and 13 | writing the `modelDescription.xml` file. 14 | Next is a short recap on shared library programming on Windows, Mac and Linux. A CMake build system is presented with a test 15 | shared library and program, for each participant to test their tool chain. We then start writing the C-code for the 16 | ModelExchange FMU v2.0 with only the mandatory functions. The FMU library will be build and we compose the FMU by 17 | assembling the files into the directory structure and zipping the FMU together. Finally, the FMU will be tested in OpenModelica with a prepared test model. We then move to FMI for Co-Simulation, where we just introduce the alternative functions and a simple time integration routine. 18 | The FMI is generated again and tested with a prepared co-simulation scenario using MasterSim or any other FMI master. Finally, the automation of generating barebone c-code and build system/deployment files with the FMICodeGenerator tool is demonstrated. 19 | 20 | ## Expected experience of participants 21 | 22 | Participants should have a basic understanding of FMI-concepts and ME/CS modes. Also, they should know C/C++ programming at beginners level and should know their development environment. 23 | 24 | ## Software requirements 25 | 26 | - C/C++ compiler: on Windows MinGW or Visual Studio is recommended (I use MinGW32-8.1 x64); on Linux gcc/clang; on Mac default compiler 27 | - CMake 28 | - MasterSim (OpenSource) or any other FMI Co-Simulation-Master 29 | - OpenModelica (OpenSource) or any other FMI ModelExchange-Master 30 | - (optional) FMICodeGenerator (OpenSource) 31 | 32 | -------------------------------------------------------------------------------- /doc/readme.md: -------------------------------------------------------------------------------- 1 | # Third-party Documentation and Articles 2 | 3 | This directory holds reference articles and publications about the FMICodeGenerator. 4 | -------------------------------------------------------------------------------- /examples/P_Control.fmu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/examples/P_Control.fmu -------------------------------------------------------------------------------- /examples/P_Control.input: -------------------------------------------------------------------------------- 1 | { 2 | "modelName": "P_Control", 3 | "description": "A stateless P-Controller", 4 | "variables": [ 5 | { 6 | "initial": "approx", 7 | "name": "T", 8 | "startValue": "293.15", 9 | "causality": "input", 10 | "variability": "continuous", 11 | "valueRef": -1, 12 | "typeID": "Real" 13 | }, 14 | { 15 | "initial": "calculated", 16 | "name": "P", 17 | "startValue": "0", 18 | "causality": "output", 19 | "variability": "continuous", 20 | "valueRef": -1, 21 | "typeID": "Real" 22 | }, 23 | { 24 | "initial": "exact", 25 | "name": "T_limit", 26 | "startValue": "276.15", 27 | "causality": "parameter", 28 | "variability": "fixed", 29 | "valueRef": -1, 30 | "typeID": "Real" 31 | }, 32 | { 33 | "initial": "exact", 34 | "name": "k_P", 35 | "startValue": "20000", 36 | "causality": "parameter", 37 | "variability": "fixed", 38 | "valueRef": -1, 39 | "typeID": "Real" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /examples/P_Control/bin/debug/.gitignore: -------------------------------------------------------------------------------- 1 | /libP_Control.so 2 | /libP_Control.so.1 3 | /libP_Control.so.1.0 4 | /libP_Control.so.1.0.0 5 | -------------------------------------------------------------------------------- /examples/P_Control/bin/release/.gitignore: -------------------------------------------------------------------------------- 1 | *.so1.0.0 2 | *.dylib 3 | /libP_Control.so.1.0.0 4 | *.so 5 | -------------------------------------------------------------------------------- /examples/P_Control/bin/release/readme.md: -------------------------------------------------------------------------------- 1 | Target directory for generated shared library file. 2 | 3 | -------------------------------------------------------------------------------- /examples/P_Control/bin/release_x64/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/P_Control/bin/release_x64/readme.md: -------------------------------------------------------------------------------- 1 | This directory is for x64 windows binaries. -------------------------------------------------------------------------------- /examples/P_Control/build/.gitignore: -------------------------------------------------------------------------------- 1 | /bb-gcc/ 2 | /P_Control/ 3 | *.fmu 4 | -------------------------------------------------------------------------------- /examples/P_Control/build/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Build script for building FMU. 4 | # 5 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 6 | # 7 | # BSD 3-Clause License 8 | # 9 | # Copyright (c) 2018, Andreas Nicolai 10 | # All rights reserved. 11 | # 12 | # Redistribution and use in source and binary forms, with or without 13 | # modification, are permitted provided that the following conditions are met: 14 | # 15 | # * Redistributions of source code must retain the above copyright notice, this 16 | # list of conditions and the following disclaimer. 17 | # 18 | # * Redistributions in binary form must reproduce the above copyright notice, 19 | # this list of conditions and the following disclaimer in the documentation 20 | # and/or other materials provided with the distribution. 21 | # 22 | # * Neither the name of the copyright holder nor the names of its 23 | # contributors may be used to endorse or promote products derived from 24 | # this software without specific prior written permission. 25 | # 26 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | # 37 | # 38 | # Command line options: 39 | # [reldeb|release|debug] build type 40 | # [2 [1..n]] cpu count 41 | # [gcc|icc] compiler 42 | # [off|gprof] gprof (includes gcc) 43 | # [off|threadChecker] threadchecker (includes icc) 44 | # [off|omp] openmp (gcc and icc) 45 | # [verbose] enable cmake to call verbose makefiles 46 | # 47 | # 48 | # FMU-specific variables - set by code generator 49 | FMU_SHARED_LIB_NAME=libP_Control 50 | FMU_SHARED_LIB_TARGET_NAME=P_Control 51 | FMU_SHARED_LIB_VERSION=1.0.0 52 | 53 | BUILD_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 54 | CMAKELISTSDIR=$(pwd)/../projects/cmake 55 | BUILDDIR="bb" 56 | 57 | # set defaults 58 | CMAKE_BUILD_TYPE=" -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo" 59 | MAKE_CPUCOUNT="2" 60 | BUILD_DIR_SUFFIX="gcc" 61 | COMPILER="" 62 | SKIP_TESTS="false" 63 | 64 | # parse parameters, except gprof and threadchecker 65 | for var in "$@" 66 | do 67 | 68 | if [[ $var = "--help" ]]; 69 | then 70 | echo "Command line options:" 71 | echo " [reldeb|release|debug] build type" 72 | echo " [2 [1..n]] cpu count" 73 | echo " [gcc|icc] compiler" 74 | echo " [off|gprof] gprof (includes gcc)" 75 | echo " [off|threadChecker] threadchecker (includes icc)" 76 | echo " [off|omp] openmp (gcc and icc)" 77 | echo " [verbose] enable cmake to call verbose makefiles" 78 | 79 | exit 80 | fi 81 | 82 | if [[ $var = *[[:digit:]]* ]]; 83 | then 84 | MAKE_CPUCOUNT=$var 85 | echo "Using $MAKE_CPUCOUNT CPUs for compilation" 86 | fi 87 | 88 | if [[ $var = "omp" ]]; 89 | then 90 | CMAKE_OPTIONS="$CMAKE_OPTIONS -DUSE_OMP:BOOL=ON" 91 | echo "Using Open MP compile flags" 92 | fi 93 | 94 | if [[ $var = "debug" ]]; 95 | then 96 | CMAKE_BUILD_TYPE=" -DCMAKE_BUILD_TYPE:STRING=Debug" 97 | echo "Debug build..." 98 | fi 99 | 100 | if [[ $var = "release" ]]; 101 | then 102 | CMAKE_BUILD_TYPE=" -DCMAKE_BUILD_TYPE:STRING=Release" 103 | echo "Release build..." 104 | fi 105 | 106 | if [[ $var = "reldeb" ]]; 107 | then 108 | CMAKE_BUILD_TYPE=" -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo" 109 | echo "RelWithDebInfo build..." 110 | fi 111 | 112 | if [[ $var = "icc" && $COMPILER = "" ]]; 113 | then 114 | COMPILER="icc" 115 | BUILD_DIR_SUFFIX="icc" 116 | echo "Intel compiler build..." 117 | # export intel compiler path 118 | CMAKE_COMPILER_OPTIONS="-DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icc" 119 | fi 120 | 121 | if [[ $var = "gcc" && $COMPILER = "" ]]; 122 | then 123 | COMPILER="gcc" 124 | BUILD_DIR_SUFFIX="gcc" 125 | echo "GCC compiler build..." 126 | CMAKE_COMPILER_OPTIONS="" 127 | fi 128 | 129 | if [[ $var = "verbose" ]]; 130 | then 131 | CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" 132 | fi 133 | 134 | done 135 | 136 | 137 | # override compiler options 138 | for var in "$@" 139 | do 140 | 141 | if [[ $var = "gprof" ]]; 142 | then 143 | COMPILER="gcc" 144 | BUILD_DIR_SUFFIX="gcc" 145 | CMAKE_COMPILER_OPTIONS="-DCMAKE_CXX_FLAGS="'-pg'" -DCMAKE_EXE_LINKER_FLAGS="'-pg'"" 146 | echo "Gprof build, forcing GCC build..." 147 | fi 148 | 149 | if [[ $var = "threadChecker" ]]; 150 | then 151 | COMPILER="icc" 152 | BUILD_DIR_SUFFIX="icc" 153 | echo "Using Threadchecker, forcing Intel compiler build..." 154 | # export intel compiler path 155 | CMAKE_COMPILER_OPTIONS="-DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icc -DUSE_THREAD_CHECKER:BOOL=ON" 156 | fi 157 | 158 | done 159 | 160 | 161 | # create build dir if not exists 162 | BUILDDIR=$BUILDDIR-$BUILD_DIR_SUFFIX 163 | if [ ! -d $BUILDDIR ]; then 164 | mkdir -p $BUILDDIR 165 | fi 166 | 167 | cd $BUILDDIR && cmake $CMAKE_OPTIONS $CMAKE_BUILD_TYPE $CMAKE_COMPILER_OPTIONS $CMAKELISTSDIR && make -j$MAKE_CPUCOUNT && 168 | cd $BUILD_SCRIPT_DIR && 169 | mkdir -p ../bin/release && 170 | # copy for Linux/Unix builds 171 | if [ -e $BUILDDIR/$FMU_SHARED_LIB_NAME.so ]; then 172 | cp -f $BUILDDIR/$FMU_SHARED_LIB_NAME.so.$FMU_SHARED_LIB_VERSION ../bin/release/$FMU_SHARED_LIB_NAME.so.$FMU_SHARED_LIB_VERSION && 173 | echo "Copied $FMU_SHARED_LIB_NAME.so.$FMU_SHARED_LIB_VERSION to bin/release ***" 174 | cp -f $BUILDDIR/$FMU_SHARED_LIB_NAME.so.$FMU_SHARED_LIB_VERSION ../bin/release/$FMU_SHARED_LIB_TARGET_NAME.so && 175 | echo "Created ../bin/release/$FMU_SHARED_LIB_TARGET_NAME.so ***" 176 | fi && 177 | # copy for Mac builds 178 | if [ -e $BUILDDIR/$FMU_SHARED_LIB_NAME.dylib ]; then 179 | cp -f $BUILDDIR/$FMU_SHARED_LIB_NAME.$FMU_SHARED_LIB_VERSION.dylib ../bin/release/$FMU_SHARED_LIB_NAME.$FMU_SHARED_LIB_VERSION.dylib && 180 | echo "Copied $FMU_SHARED_LIB_NAME.$FMU_SHARED_LIB_VERSION.dylib to bin/release ***" 181 | cp -f $BUILDDIR/$FMU_SHARED_LIB_NAME.$FMU_SHARED_LIB_VERSION.dylib ../bin/release/$FMU_SHARED_LIB_TARGET_NAME.dylib && 182 | echo "Created ../bin/release/$FMU_SHARED_LIB_TARGET_NAME.dylib ***" 183 | fi 184 | 185 | -------------------------------------------------------------------------------- /examples/P_Control/build/build_VC_x64.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: setup VC environment variables 4 | set VCVARSALL_PATH="c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 5 | call %VCVARSALL_PATH% 6 | 7 | :: FMU-specific variables - set by code generator 8 | set FMU_SHARED_LIB_NAME=P_Control.dll 9 | 10 | set CMAKELISTSDIR=%CD%\..\projects\cmake 11 | 12 | :: create and change into build subdir 13 | mkdir bb_VC_x64 14 | pushd bb_VC_x64 15 | 16 | :: configure makefiles and build 17 | cmake -G "NMake Makefiles" %CMAKELISTSDIR% -DCMAKE_BUILD_TYPE:String="Release" 18 | nmake 19 | if ERRORLEVEL 1 GOTO fail 20 | 21 | popd 22 | 23 | :: copy executable to bin/release dir 24 | xcopy /Y .\bb_VC_x64\%FMU_SHARED_LIB_NAME% ..\bin\release_x64 25 | 26 | exit /b 0 27 | 28 | :fail 29 | echo ** Build Failed ** 30 | exit /b 1 31 | -------------------------------------------------------------------------------- /examples/P_Control/build/deploy.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: script is supposed to be executed in /build directory 3 | 4 | if exist ..\bin\release_x64\P_Control.dll goto DLL_EXISTS 5 | echo "ERROR: File P_Control.dll expected in directory ..\bin\release_x64\P_Control.dll, but does not exist. 6 | exit /b 1 7 | :DLL_EXISTS 8 | 9 | :: remove target directory if it exists 10 | if not exist P_Control goto DIRECTORY_CLEAN 11 | echo Removing existing directory 'P_Control' 12 | rd /S /Q "P_Control" 13 | :DIRECTORY_CLEAN 14 | 15 | :: remove target FMU if it exists 16 | if not exist P_Control.fmu goto FMU_REMOVED 17 | echo Removing existing FMU file 'P_Control.fmu' 18 | del /F /S /Q "P_Control.fmu" 19 | :FMU_REMOVED 20 | 21 | ::create subdir and change into it 22 | mkdir P_Control 23 | 24 | cd P_Control 25 | 26 | :: create binary dir for Windows 27 | mkdir binaries\win64 28 | 29 | :: copy shared library, we expect it to be already renamed correctly 30 | xcopy ..\..\bin\release_x64\P_Control.dll binaries\win64\ 31 | xcopy ..\..\data\modelDescription.xml . 32 | echo Created FMU directory structure 33 | 34 | ::change working directory back to original dir 35 | cd .. 36 | 37 | ::create zip archive 38 | echo Creating archive 'P_Control.zip' 39 | cd P_Control 40 | 7za a ../P_Control.zip . 41 | cd .. 42 | 43 | echo Renaming archive to 'P_Control.fmu' 44 | rename P_Control.zip P_Control.fmu 45 | 46 | :: all ok 47 | exit /b 0 48 | -------------------------------------------------------------------------------- /examples/P_Control/build/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # script is supposed to be executed in /build directory 4 | 5 | # remove target directory if it exists 6 | if [ -d P_Control ]; then 7 | rm -rf P_Control 8 | fi && 9 | 10 | # remove target FMU if it exists 11 | if [ -f P_Control.fmu ]; then 12 | rm P_Control.fmu 13 | fi && 14 | 15 | # create subdir and change into it 16 | mkdir -p P_Control && 17 | cd P_Control && 18 | 19 | # create binary dir for Linux 20 | mkdir -p binaries/linux64 && 21 | 22 | # copy shared library, we expect it to be already renamed correctly 23 | cp ../../bin/release/P_Control.so binaries/linux64/P_Control.so && 24 | cp ../../data/modelDescription.xml . && 25 | 26 | # create zip archive 27 | 7za a ../P_Control.zip . | cat > /dev/null && 28 | cd .. && 29 | mv P_Control.zip P_Control.fmu && 30 | echo "Created P_Control.fmu" && 31 | 32 | # change working directory back to original dir 33 | cd - 34 | 35 | -------------------------------------------------------------------------------- /examples/P_Control/build/deployMac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # script is supposed to be executed in /build directory 4 | 5 | # remove target directory if it exists 6 | if [ -d P_Control ]; then 7 | rm -rf P_Control 8 | fi && 9 | 10 | # remove target FMU if it exists 11 | if [ -f P_Control.fmu ]; then 12 | rm P_Control.fmu 13 | fi && 14 | 15 | # create subdir and change into it 16 | mkdir -p P_Control && 17 | cd P_Control && 18 | 19 | # create binary dir for Linux 20 | mkdir -p binaries/darwin64 && 21 | 22 | # copy shared library, we expect it to be already renamed correctly 23 | cp ../../bin/release/P_Control.dylib binaries/darwin64/P_Control.dylib && 24 | cp ../../data/modelDescription.xml . && 25 | 26 | # create zip archive 27 | zip -r ../P_Control.zip . | cat > /dev/null && 28 | cd .. && 29 | mv P_Control.zip P_Control.fmu && 30 | echo "Created P_Control.fmu" && 31 | 32 | # change working directory back to original dir 33 | cd - 34 | 35 | -------------------------------------------------------------------------------- /examples/P_Control/data/modelDescription.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 25 | 26 | 33 | 34 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 66 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 88 | 89 | 90 | 91 | 92 | 93 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /examples/P_Control/projects/.gitignore: -------------------------------------------------------------------------------- 1 | /build-* 2 | -------------------------------------------------------------------------------- /examples/P_Control/projects/Qt/P_Control.pro: -------------------------------------------------------------------------------- 1 | # ---------------------------------- 2 | # Qt Project for building FMU 3 | # ---------------------------------- 4 | # 5 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 6 | # 7 | # BSD 3-Clause License 8 | # 9 | # Copyright (c) 2018, Andreas Nicolai 10 | # All rights reserved. 11 | # 12 | # see https://github.com/ghorwin/FMICodeGenerator/blob/master/LICENSE for details. 13 | 14 | 15 | TARGET = P_Control 16 | TEMPLATE = lib 17 | 18 | # no GUI 19 | QT -= core gui 20 | 21 | CONFIG(debug, debug|release) { 22 | windows { 23 | DLLDESTDIR = ../../bin/debug$${DIR_PREFIX} 24 | } 25 | else { 26 | DESTDIR = ../../bin/debug$${DIR_PREFIX} 27 | } 28 | } 29 | else { 30 | windows { 31 | DLLDESTDIR = ../../bin/release$${DIR_PREFIX} 32 | } 33 | else { 34 | DESTDIR = ../../bin/release$${DIR_PREFIX} 35 | } 36 | } 37 | 38 | #DEFINES += FMI2_FUNCTION_PREFIX=P_Control_ 39 | 40 | unix|mac { 41 | VER_MAJ = 1 42 | VER_MIN = 0 43 | VER_PAT = 0 44 | VERSION = $${VER_MAJ}.$${VER_MIN}.$${VER_PAT} 45 | } 46 | 47 | INCLUDEPATH = ../../src 48 | 49 | SOURCES += \ 50 | ../../src/fmi2common/fmi2Functions.cpp \ 51 | ../../src/fmi2common/InstanceData.cpp \ 52 | ../../src/P_Control.cpp 53 | 54 | HEADERS += \ 55 | ../../src/fmi2common/fmi2Functions.h \ 56 | ../../src/fmi2common/fmi2Functions_complete.h \ 57 | ../../src/fmi2common/fmi2FunctionTypes.h \ 58 | ../../src/fmi2common/fmi2TypesPlatform.h \ 59 | ../../src/fmi2common/InstanceData.h \ 60 | ../../src/P_Control.h 61 | 62 | 63 | -------------------------------------------------------------------------------- /examples/P_Control/projects/cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMake project file for generated FMI code 2 | # 3 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 4 | # 5 | # BSD 3-Clause License 6 | # 7 | # Copyright (c) 2018, Andreas Nicolai 8 | # All rights reserved. 9 | # 10 | # see https://github.com/ghorwin/FMICodeGenerator/blob/master/LICENSE for details. 11 | 12 | project( P_Control ) 13 | 14 | cmake_minimum_required(VERSION 3.5) 15 | 16 | # add include directories 17 | include_directories( 18 | ${PROJECT_SOURCE_DIR}/../../src 19 | ) 20 | 21 | add_library( ${PROJECT_NAME} SHARED 22 | ${PROJECT_SOURCE_DIR}/../../src/${PROJECT_NAME}.cpp 23 | ${PROJECT_SOURCE_DIR}/../../src/fmi2common/fmi2Functions.cpp 24 | ${PROJECT_SOURCE_DIR}/../../src/fmi2common/InstanceData.cpp 25 | ) 26 | 27 | # link against the dependent libraries 28 | target_link_libraries( ${PROJECT_NAME} 29 | ${APPLE_FRAMEWORKS} 30 | ) 31 | 32 | # Library version strings set by code generator 33 | set( SO_VERSION_MAJOR 1) 34 | set( SO_VERSION_MINOR 0) 35 | set( SO_VERSION_PATCH 0) 36 | set( SO_VERSION_STRING 37 | ${SO_VERSION_MAJOR}.${SO_VERSION_MINOR}.${SO_VERSION_PATCH} 38 | ) 39 | 40 | set_target_properties( ${PROJECT_NAME} PROPERTIES 41 | VERSION ${SO_VERSION_STRING} 42 | SOVERSION ${SO_VERSION_MAJOR} 43 | ) 44 | -------------------------------------------------------------------------------- /examples/P_Control/src/P_Control.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | FMI Interface for FMU generated by FMICodeGenerator. 4 | 5 | This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 6 | 7 | BSD 3-Clause License 8 | 9 | Copyright (c) 2018, Andreas Nicolai 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, 19 | this list of conditions and the following disclaimer in the documentation 20 | and/or other materials provided with the distribution. 21 | 22 | * Neither the name of the copyright holder nor the names of its 23 | contributors may be used to endorse or promote products derived from 24 | this software without specific prior written permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | */ 38 | 39 | #ifndef P_ControlH 40 | #define P_ControlH 41 | 42 | #include "fmi2common/InstanceData.h" 43 | 44 | /*! This class wraps all data needed for a single instance of the FMU. */ 45 | class P_Control : public InstanceData { 46 | public: 47 | /*! Initializes empty instance. */ 48 | P_Control(); 49 | 50 | /*! Destructor, writes out cached results from Therakles. */ 51 | ~P_Control(); 52 | 53 | /*! Initializes model */ 54 | void init(); 55 | 56 | /*! This function triggers a state-update of the embedded model whenever our cached input 57 | data differs from the input data in the model. 58 | */ 59 | void updateIfModified(); 60 | 61 | /*! Called from fmi2DoStep(). */ 62 | virtual void integrateTo(double tCommunicationIntervalEnd); 63 | 64 | // Functions for getting/setting the state 65 | 66 | /*! This function computes the size needed for full serizalization of 67 | the FMU and stores the size in m_fmuStateSize. 68 | \note The size includes the leading 8byte for the 64bit integer size 69 | of the memory array (for testing purposes). 70 | */ 71 | virtual void computeFMUStateSize(); 72 | 73 | /*! Copies the internal state of the FMU to the memory array pointed to by FMUstate. 74 | Memory array always has size m_fmuStateSize. 75 | */ 76 | virtual void serializeFMUstate(void * FMUstate); 77 | 78 | /*! Copies the content of the memory array pointed to by FMUstate to the internal state of the FMU. 79 | Memory array always has size m_fmuStateSize. 80 | */ 81 | virtual bool deserializeFMUstate(void * FMUstate); 82 | 83 | /*! Cached current time point of the FMU, defines starting point for time integration in co-simulation mode. */ 84 | double m_currentTimePoint; 85 | }; // class P_Control 86 | 87 | #endif // P_ControlH 88 | 89 | -------------------------------------------------------------------------------- /examples/P_Control/src/fmi2common/InstanceData.cpp: -------------------------------------------------------------------------------- 1 | /* Generic FMI Interface Implementation 2 | 3 | This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 4 | 5 | BSD 3-Clause License 6 | 7 | Copyright (c) 2018, Andreas Nicolai 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "InstanceData.h" 38 | 39 | #include 40 | #include 41 | 42 | #include "fmi2Functions.h" 43 | #include "fmi2FunctionTypes.h" 44 | 45 | InstanceData::InstanceData() : 46 | m_callbackFunctions(0), 47 | m_initializationMode(false), 48 | m_modelExchange(true), 49 | m_tInput(0), 50 | m_externalInputVarsModified(false), 51 | m_fmuStateSize(0) 52 | { 53 | } 54 | 55 | 56 | InstanceData::~InstanceData() { 57 | for (std::set::iterator it = m_fmuStates.begin(); it != m_fmuStates.end(); ++it) { 58 | free(*it); 59 | } 60 | } 61 | 62 | 63 | void InstanceData::logger(fmi2Status state, fmi2String category, fmi2String message) { 64 | if (m_loggingOn) { 65 | m_callbackFunctions->logger(m_callbackFunctions->componentEnvironment, 66 | m_instanceName.c_str(), state, category, 67 | message); 68 | } 69 | } 70 | 71 | 72 | template 73 | void checkIfIDExists(const T & m, int varID) { 74 | if (m.find(varID) == m.end() ) { 75 | std::stringstream strm; 76 | strm << "Invalid or unknown value reference " << varID; 77 | throw std::runtime_error(strm.str()); 78 | } 79 | } 80 | 81 | void InstanceData::setReal(int varID, double value) { 82 | checkIfIDExists(m_realVar, varID); 83 | m_realVar[varID] = value; 84 | m_externalInputVarsModified = true; 85 | } 86 | 87 | 88 | void InstanceData::setInt(int varID, int value) { 89 | checkIfIDExists(m_integerVar, varID); 90 | m_integerVar[varID] = value; 91 | m_externalInputVarsModified = true; 92 | } 93 | 94 | 95 | void InstanceData::setString(int varID, fmi2String value) { 96 | checkIfIDExists(m_stringVar, varID); 97 | m_stringVar[varID] = value; 98 | m_externalInputVarsModified = true; 99 | } 100 | 101 | 102 | void InstanceData::setBool(int varID, bool value) { 103 | checkIfIDExists(m_boolVar, varID); 104 | m_boolVar[varID] = value; 105 | m_externalInputVarsModified = true; 106 | } 107 | 108 | 109 | void InstanceData::getReal(int varID, double & value) { 110 | // update procedure for model exchange 111 | if (m_modelExchange) 112 | updateIfModified(); 113 | checkIfIDExists(m_realVar, varID); 114 | value = m_realVar[varID]; 115 | } 116 | 117 | 118 | void InstanceData::getInt(int varID, int & value) { 119 | // update procedure for model exchange 120 | if(m_modelExchange) 121 | updateIfModified(); 122 | checkIfIDExists(m_integerVar, varID); 123 | value = m_integerVar[varID]; 124 | } 125 | 126 | 127 | void InstanceData::getString(int varID, fmi2String & value) { 128 | // update procedure for model exchange 129 | if(m_modelExchange) 130 | updateIfModified(); 131 | checkIfIDExists(m_stringVar, varID); 132 | value = m_stringVar[varID].c_str(); 133 | } 134 | 135 | 136 | void InstanceData::getBool(int varID, bool & value) { 137 | // update procedure for model exchange 138 | if(m_modelExchange) 139 | updateIfModified(); 140 | checkIfIDExists(m_boolVar, varID); 141 | value = m_boolVar[varID]; 142 | } 143 | 144 | 145 | void InstanceData::completedIntegratorStep() { 146 | // this function must only be called in ModelExchange mode!!! 147 | if (!m_modelExchange) 148 | throw std::runtime_error("Invalid function call; only permitted in ModelExchange mode."); 149 | updateIfModified(); 150 | completedIntegratorStep(m_tInput, &m_yInput[0]); 151 | } 152 | 153 | -------------------------------------------------------------------------------- /examples/P_Control/src/fmi2common/fmi2Functions_complete.h: -------------------------------------------------------------------------------- 1 | /* Inquire version numbers of header files */ 2 | 1 FMI2_Export const char* fmi2GetTypesPlatform(void); 3 | 2 FMI2_Export const char* fmi2GetVersion(void); 4 | 7 FMI2_Export fmi2Status fmi2SetDebugLogging(void* c, int loggingOn, size_t nCategories, const (const char* categories)[]); 5 | 6 | /* Creation and destruction of FMU instances */ 7 | 3 FMI2_Export void* fmi2Instantiate(const char* instanceName, fmi2Type fmuType, const char* fmuGUID, 8 | const char* fmuResourceLocation, const fmi2CallbackFunctions* functions, int visible, int loggingOn); 9 | 6 FMI2_Export void fmi2FreeInstance(void* c); 10 | 11 | /* Enter and exit initialization mode, terminate and reset */ 12 | 32 FMI2_Export fmi2Status fmi2SetupExperiment(void* c, int toleranceDefined, double tolerance, double startTime, int stopTimeDefined, double stopTime); 13 | 4 FMI2_Export fmi2Status fmi2EnterInitializationMode(void* c); 14 | 5 FMI2_Export fmi2Status fmi2ExitInitializationMode(void* c); 15 | 22 FMI2_Export fmi2Status fmi2Terminate(void* c); 16 | 23 FMI2_Export fmi2Status fmi2Reset(void* c); 17 | 18 | /* Getting and setting variables values */ 19 | 14 FMI2_Export fmi2Status fmi2GetReal(void* c, const unsigned int vr[], size_t nvr, double value[]); 20 | 18 FMI2_Export fmi2Status fmi2GetInteger(void* c, const unsigned int vr[], size_t nvr, int value[]); 21 | 19 FMI2_Export fmi2Status fmi2GetBoolean(void* c, const unsigned int vr[], size_t nvr, int value[]); 22 | 20 FMI2_Export fmi2Status fmi2GetString (void* c, const unsigned int vr[], size_t nvr, (const char* value)[]); 23 | 24 | 13 FMI2_Export fmi2Status fmi2SetReal(void* c, const unsigned int vr[], size_t nvr, const double value[]); 25 | 15 FMI2_Export fmi2Status fmi2SetInteger(void* c, const unsigned int vr[], size_t nvr, const int value[]); 26 | 16 FMI2_Export fmi2Status fmi2SetBoolean(void* c, const unsigned int vr[], size_t nvr, const int value[]); 27 | 17 FMI2_Export fmi2Status fmi2SetString(void* c, const unsigned int vr[], size_t nvr, const (const char* value[])); 28 | 29 | /* Getting and setting the internal FMU state */ 30 | 26 FMI2_Export fmi2Status fmi2GetFMUstate(void* c, fmi2FMUstate* FMUstate); 31 | 27 FMI2_Export fmi2Status fmi2SetFMUstate(void* c, fmi2FMUstate FMUstate); 32 | 28 FMI2_Export fmi2Status fmi2FreeFMUstate(void* c, fmi2FMUstate* FMUstate); 33 | 29 FMI2_Export fmi2Status fmi2SerializedFMUstateSize(void* c, fmi2FMUstate FMUstate, size_t* size); 34 | 30 FMI2_Export fmi2Status fmi2SerializeFMUstate(void* c, fmi2FMUstate FMUstate, char serializedState[], size_t size); 35 | 31 FMI2_Export fmi2Status fmi2DeSerializeFMUstate(void* c, const char serializedState[], size_t size, fmi2FMUstate* FMUstate); 36 | 37 | /* Getting partial derivatives */ 38 | 33 FMI2_Export fmi2Status fmi2GetDirectionalDerivative(void* c, const unsigned int vUnknown_ref[], size_t nUnknown, 39 | const unsigned int vKnown_ref[], size_t nKnown, 40 | const double vKnown[], double dvUnknown[]); 41 | 42 | /*************************************************** 43 | Functions for FMI2 for Model Exchange 44 | ****************************************************/ 45 | 46 | /* Enter and exit the different modes */ 47 | 21 FMI2_Export fmi2Status fmi2EnterEventMode(void* c); 48 | 34 FMI2_Export fmi2Status fmi2NewDiscreteStates(void* c, fmi2EventInfo* fmi2eventInfo); 49 | 35 FMI2_Export fmi2Status fmi2EnterContinuousTimeMode(void* c); 50 | 24 FMI2_Export fmi2Status fmi2CompletedIntegratorStep(void* c, int noSetFMUStatePriorToCurrentPoint, int* enterEventMode, int* terminateSimulation); 51 | 52 | /* Providing independent variables and re-initialization of caching */ 53 | 8 FMI2_Export fmi2Status fmi2SetTime(void* c, double time); 54 | 9 FMI2_Export fmi2Status fmi2SetContinuousStates(void* c, const double x[], size_t nx); 55 | 56 | /* Evaluation of the model equations */ 57 | 12 FMI2_Export fmi2Status fmi2GetDerivatives(void* c, double derivatives[], size_t nx); 58 | 25 FMI2_Export fmi2Status fmi2GetEventIndicators(void* c, double eventIndicators[], size_t ni); 59 | 10 FMI2_Export fmi2Status fmi2GetContinuousStates(void* c, double x[], size_t nx); 60 | 11 FMI2_Export fmi2Status fmi2GetNominalsOfContinuousStates(void* c, double x_nominal[], size_t nx); 61 | 62 | 63 | /*************************************************** 64 | Functions for FMI2 for Co-Simulation 65 | ****************************************************/ 66 | 67 | /* Simulating the slave */ 68 | FMI2_Export fmi2Status fmi2SetRealInputDerivatives(void* c, const unsigned int vr[], size_t nvr, const int order[], const double value[]); 69 | FMI2_Export fmi2Status fmi2GetRealOutputDerivatives(void* c, const unsigned int vr[], size_t nvr, const int order[], double value[]); 70 | 71 | FMI2_Export fmi2Status fmi2DoStep(void* c, double currentCommunicationPoint, double communicationStepSize, int noSetFMUStatePriorToCurrentPoint); 72 | FMI2_Export fmi2Status fmi2CancelStep (void* c); 73 | 74 | /* Inquire slave status */ 75 | FMI2_Export fmi2Status fmi2GetStatus(void* c, const fmi2StatusKind s, fmi2Status* value); 76 | FMI2_Export fmi2Status fmi2GetRealStatus(void* c, const fmi2StatusKind s, double* value); 77 | FMI2_Export fmi2Status fmi2GetIntegerStatus(void* c, const fmi2StatusKind s, int* value); 78 | FMI2_Export fmi2Status fmi2GetBooleanStatus(void* c, const fmi2StatusKind s, int* value); 79 | FMI2_Export fmi2Status fmi2GetStringStatus(void* c, const fmi2StatusKind s, const char** value); 80 | -------------------------------------------------------------------------------- /examples/P_Control/src/fmi2common/fmi2TypesPlatform.h: -------------------------------------------------------------------------------- 1 | #ifndef fmi2TypesPlatform_h 2 | #define fmi2TypesPlatform_h 3 | 4 | /* Standard header file to define the argument types of the 5 | functions of the Functional Mock-up Interface 2.0. 6 | This header file must be utilized both by the model and 7 | by the simulation engine. 8 | 9 | Revisions: 10 | - Apr. 9, 2014: all prefixes "fmi" renamed to "fmi2" (decision from April 8) 11 | - Mar 31, 2014: New datatype fmiChar introduced. 12 | - Feb. 17, 2013: Changed fmiTypesPlatform from "standard32" to "default". 13 | Removed fmiUndefinedValueReference since no longer needed 14 | (because every state is defined in ScalarVariables). 15 | - March 20, 2012: Renamed from fmiPlatformTypes.h to fmiTypesPlatform.h 16 | - Nov. 14, 2011: Use the header file "fmiPlatformTypes.h" for FMI 2.0 17 | both for "FMI for model exchange" and for "FMI for co-simulation" 18 | New types "fmiComponentEnvironment", "fmiState", and "fmiByte". 19 | The implementation of "fmiBoolean" is change from "char" to "int". 20 | The #define "fmiPlatform" changed to "fmiTypesPlatform" 21 | (in order that #define and function call are consistent) 22 | - Oct. 4, 2010: Renamed header file from "fmiModelTypes.h" to fmiPlatformTypes.h" 23 | for the co-simulation interface 24 | - Jan. 4, 2010: Renamed meModelTypes_h to fmiModelTypes_h (by Mauss, QTronic) 25 | - Dec. 21, 2009: Changed "me" to "fmi" and "meModel" to "fmiComponent" 26 | according to meeting on Dec. 18 (by Martin Otter, DLR) 27 | - Dec. 6, 2009: Added meUndefinedValueReference (by Martin Otter, DLR) 28 | - Sept. 9, 2009: Changes according to FMI-meeting on July 21: 29 | Changed "version" to "platform", "standard" to "standard32", 30 | Added a precise definition of "standard32" as comment 31 | (by Martin Otter, DLR) 32 | - July 19, 2009: Added "me" as prefix to file names, added meTrue/meFalse, 33 | and changed meValueReferenced from int to unsigned int 34 | (by Martin Otter, DLR). 35 | - March 2, 2009: Moved enums and function pointer definitions to 36 | ModelFunctions.h (by Martin Otter, DLR). 37 | - Dec. 3, 2008 : First version by Martin Otter (DLR) and 38 | Hans Olsson (Dynasim). 39 | 40 | 41 | Copyright © 2008-2011 MODELISAR consortium, 42 | 2012-2013 Modelica Association Project "FMI" 43 | All rights reserved. 44 | This file is licensed by the copyright holders under the BSD 2-Clause License 45 | (http://www.opensource.org/licenses/bsd-license.html): 46 | 47 | ---------------------------------------------------------------------------- 48 | Redistribution and use in source and binary forms, with or without 49 | modification, are permitted provided that the following conditions are met: 50 | 51 | - Redistributions of source code must retain the above copyright notice, 52 | this list of conditions and the following disclaimer. 53 | - Redistributions in binary form must reproduce the above copyright notice, 54 | this list of conditions and the following disclaimer in the documentation 55 | and/or other materials provided with the distribution. 56 | - Neither the name of the copyright holders nor the names of its 57 | contributors may be used to endorse or promote products derived 58 | from this software without specific prior written permission. 59 | 60 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 61 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 62 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 63 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 64 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 65 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 66 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 67 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 68 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 69 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 70 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 71 | ---------------------------------------------------------------------------- 72 | 73 | with the extension: 74 | 75 | You may distribute or publicly perform any modification only under the 76 | terms of this license. 77 | (Note, this means that if you distribute a modified file, 78 | the modified file must also be provided under this license). 79 | */ 80 | 81 | /* Platform (unique identification of this header file) */ 82 | #define fmi2TypesPlatform "default" 83 | 84 | /* Type definitions of variables passed as arguments 85 | Version "default" means: 86 | 87 | fmi2Component : an opaque object pointer 88 | fmi2ComponentEnvironment: an opaque object pointer 89 | fmi2FMUstate : an opaque object pointer 90 | fmi2ValueReference : handle to the value of a variable 91 | fmi2Real : double precision floating-point data type 92 | fmi2Integer : basic signed integer data type 93 | fmi2Boolean : basic signed integer data type 94 | fmi2Char : character data type 95 | fmi2String : a pointer to a vector of fmi2Char characters 96 | ('\0' terminated, UTF8 encoded) 97 | fmi2Byte : smallest addressable unit of the machine, typically one byte. 98 | */ 99 | typedef void* fmi2Component; /* Pointer to FMU instance */ 100 | typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ 101 | typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ 102 | typedef unsigned int fmi2ValueReference; 103 | typedef double fmi2Real ; 104 | typedef int fmi2Integer; 105 | typedef int fmi2Boolean; 106 | typedef char fmi2Char; 107 | typedef const fmi2Char* fmi2String; 108 | typedef char fmi2Byte; 109 | 110 | /* Values for fmi2Boolean */ 111 | #define fmi2True 1 112 | #define fmi2False 0 113 | 114 | 115 | #endif /* fmi2TypesPlatform_h */ 116 | -------------------------------------------------------------------------------- /examples/P_Control_2inputs.input: -------------------------------------------------------------------------------- 1 | { 2 | "modelName": "P_Control", 3 | "description": "A stateless P-Controller", 4 | "variables": [ 5 | { 6 | "name": "T", 7 | "valueRef": -1, 8 | "variability": "continuous", 9 | "causality": "input", 10 | "initial": "approx", 11 | "typeID": "Real", 12 | "startValue": "293.15", 13 | "description": "", 14 | "unit": "" 15 | }, 16 | { 17 | "name": "P", 18 | "valueRef": -1, 19 | "variability": "continuous", 20 | "causality": "output", 21 | "initial": "calculated", 22 | "typeID": "Real", 23 | "startValue": "0", 24 | "description": "", 25 | "unit": "" 26 | }, 27 | { 28 | "name": "T_limit", 29 | "valueRef": -1, 30 | "variability": "fixed", 31 | "causality": "parameter", 32 | "initial": "exact", 33 | "typeID": "Real", 34 | "startValue": "276.15", 35 | "description": "", 36 | "unit": "" 37 | }, 38 | { 39 | "name": "k_P", 40 | "valueRef": -1, 41 | "variability": "fixed", 42 | "causality": "parameter", 43 | "initial": "exact", 44 | "typeID": "Real", 45 | "startValue": "20000", 46 | "description": "", 47 | "unit": "" 48 | }, 49 | { 50 | "name": "T2", 51 | "valueRef": -1, 52 | "variability": "continuous", 53 | "causality": "input", 54 | "initial": "approx", 55 | "typeID": "Real", 56 | "startValue": "293.15", 57 | "description": "Second temperature", 58 | "unit": "" 59 | }, 60 | { 61 | "name": "P2", 62 | "valueRef": -1, 63 | "variability": "continuous", 64 | "causality": "output", 65 | "initial": "calculated", 66 | "typeID": "Real", 67 | "startValue": "0", 68 | "description": "Second pressure", 69 | "unit": "" 70 | } 71 | ] 72 | } -------------------------------------------------------------------------------- /examples/Test5.fmu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/examples/Test5.fmu -------------------------------------------------------------------------------- /examples/Test5/bin/debug/.gitignore: -------------------------------------------------------------------------------- 1 | /libTest5.so 2 | /libTest5.so.1 3 | /libTest5.so.1.0 4 | /libTest5.so.1.0.0 5 | -------------------------------------------------------------------------------- /examples/Test5/bin/release/.gitignore: -------------------------------------------------------------------------------- 1 | *.so1.0.0 2 | *.dylib 3 | /libTest5.so.1.0.0 4 | -------------------------------------------------------------------------------- /examples/Test5/bin/release/readme.md: -------------------------------------------------------------------------------- 1 | Target directory for generated shared library file. 2 | 3 | -------------------------------------------------------------------------------- /examples/Test5/bin/release_x64/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/Test5/bin/release_x64/readme.md: -------------------------------------------------------------------------------- 1 | This directory is for x64 windows binaries. -------------------------------------------------------------------------------- /examples/Test5/build/.gitignore: -------------------------------------------------------------------------------- 1 | /bb-gcc/ 2 | *.fmu 3 | -------------------------------------------------------------------------------- /examples/Test5/build/Test5/binaries/linux64/.gitignore: -------------------------------------------------------------------------------- 1 | *.so 2 | -------------------------------------------------------------------------------- /examples/Test5/build/Test5/modelDescription.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 25 | 26 | 33 | 34 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 67 | 68 | 69 | 70 | 71 | 72 | 79 | 80 | 81 | 82 | 83 | 84 | 91 | 92 | 93 | 94 | 95 | 96 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /examples/Test5/build/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Build script for building FMU. 4 | # 5 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 6 | # 7 | # BSD 3-Clause License 8 | # 9 | # Copyright (c) 2018, Andreas Nicolai 10 | # All rights reserved. 11 | # 12 | # Redistribution and use in source and binary forms, with or without 13 | # modification, are permitted provided that the following conditions are met: 14 | # 15 | # * Redistributions of source code must retain the above copyright notice, this 16 | # list of conditions and the following disclaimer. 17 | # 18 | # * Redistributions in binary form must reproduce the above copyright notice, 19 | # this list of conditions and the following disclaimer in the documentation 20 | # and/or other materials provided with the distribution. 21 | # 22 | # * Neither the name of the copyright holder nor the names of its 23 | # contributors may be used to endorse or promote products derived from 24 | # this software without specific prior written permission. 25 | # 26 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | # 37 | # 38 | # Command line options: 39 | # [reldeb|release|debug] build type 40 | # [2 [1..n]] cpu count 41 | # [gcc|icc] compiler 42 | # [off|gprof] gprof (includes gcc) 43 | # [off|threadChecker] threadchecker (includes icc) 44 | # [off|omp] openmp (gcc and icc) 45 | # [verbose] enable cmake to call verbose makefiles 46 | # 47 | # 48 | # FMU-specific variables - set by code generator 49 | FMU_SHARED_LIB_NAME=libTest5 50 | FMU_SHARED_LIB_TARGET_NAME=Test5 51 | FMU_SHARED_LIB_VERSION=1.0.0 52 | 53 | BUILD_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 54 | CMAKELISTSDIR=$(pwd)/../projects/cmake 55 | BUILDDIR="bb" 56 | 57 | # set defaults 58 | CMAKE_BUILD_TYPE=" -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo" 59 | MAKE_CPUCOUNT="2" 60 | BUILD_DIR_SUFFIX="gcc" 61 | COMPILER="" 62 | SKIP_TESTS="false" 63 | 64 | # parse parameters, except gprof and threadchecker 65 | for var in "$@" 66 | do 67 | 68 | if [[ $var = "--help" ]]; 69 | then 70 | echo "Command line options:" 71 | echo " [reldeb|release|debug] build type" 72 | echo " [2 [1..n]] cpu count" 73 | echo " [gcc|icc] compiler" 74 | echo " [off|gprof] gprof (includes gcc)" 75 | echo " [off|threadChecker] threadchecker (includes icc)" 76 | echo " [off|omp] openmp (gcc and icc)" 77 | echo " [verbose] enable cmake to call verbose makefiles" 78 | 79 | exit 80 | fi 81 | 82 | if [[ $var = *[[:digit:]]* ]]; 83 | then 84 | MAKE_CPUCOUNT=$var 85 | echo "Using $MAKE_CPUCOUNT CPUs for compilation" 86 | fi 87 | 88 | if [[ $var = "omp" ]]; 89 | then 90 | CMAKE_OPTIONS="$CMAKE_OPTIONS -DUSE_OMP:BOOL=ON" 91 | echo "Using Open MP compile flags" 92 | fi 93 | 94 | if [[ $var = "debug" ]]; 95 | then 96 | CMAKE_BUILD_TYPE=" -DCMAKE_BUILD_TYPE:STRING=Debug" 97 | echo "Debug build..." 98 | fi 99 | 100 | if [[ $var = "release" ]]; 101 | then 102 | CMAKE_BUILD_TYPE=" -DCMAKE_BUILD_TYPE:STRING=Release" 103 | echo "Release build..." 104 | fi 105 | 106 | if [[ $var = "reldeb" ]]; 107 | then 108 | CMAKE_BUILD_TYPE=" -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo" 109 | echo "RelWithDebInfo build..." 110 | fi 111 | 112 | if [[ $var = "icc" && $COMPILER = "" ]]; 113 | then 114 | COMPILER="icc" 115 | BUILD_DIR_SUFFIX="icc" 116 | echo "Intel compiler build..." 117 | # export intel compiler path 118 | CMAKE_COMPILER_OPTIONS="-DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icc" 119 | fi 120 | 121 | if [[ $var = "gcc" && $COMPILER = "" ]]; 122 | then 123 | COMPILER="gcc" 124 | BUILD_DIR_SUFFIX="gcc" 125 | echo "GCC compiler build..." 126 | CMAKE_COMPILER_OPTIONS="" 127 | fi 128 | 129 | if [[ $var = "verbose" ]]; 130 | then 131 | CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" 132 | fi 133 | 134 | done 135 | 136 | 137 | # override compiler options 138 | for var in "$@" 139 | do 140 | 141 | if [[ $var = "gprof" ]]; 142 | then 143 | COMPILER="gcc" 144 | BUILD_DIR_SUFFIX="gcc" 145 | CMAKE_COMPILER_OPTIONS="-DCMAKE_CXX_FLAGS="'-pg'" -DCMAKE_EXE_LINKER_FLAGS="'-pg'"" 146 | echo "Gprof build, forcing GCC build..." 147 | fi 148 | 149 | if [[ $var = "threadChecker" ]]; 150 | then 151 | COMPILER="icc" 152 | BUILD_DIR_SUFFIX="icc" 153 | echo "Using Threadchecker, forcing Intel compiler build..." 154 | # export intel compiler path 155 | CMAKE_COMPILER_OPTIONS="-DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icc -DUSE_THREAD_CHECKER:BOOL=ON" 156 | fi 157 | 158 | done 159 | 160 | 161 | # create build dir if not exists 162 | BUILDDIR=$BUILDDIR-$BUILD_DIR_SUFFIX 163 | if [ ! -d $BUILDDIR ]; then 164 | mkdir -p $BUILDDIR 165 | fi 166 | 167 | cd $BUILDDIR && cmake $CMAKE_OPTIONS $CMAKE_BUILD_TYPE $CMAKE_COMPILER_OPTIONS $CMAKELISTSDIR && make -j$MAKE_CPUCOUNT && 168 | cd $BUILD_SCRIPT_DIR && 169 | mkdir -p ../bin/release && 170 | # copy for Linux/Unix builds 171 | if [ -e $BUILDDIR/$FMU_SHARED_LIB_NAME.so ]; then 172 | cp -f $BUILDDIR/$FMU_SHARED_LIB_NAME.so.$FMU_SHARED_LIB_VERSION ../bin/release/$FMU_SHARED_LIB_NAME.so.$FMU_SHARED_LIB_VERSION && 173 | echo "Copied $FMU_SHARED_LIB_NAME.so.$FMU_SHARED_LIB_VERSION to bin/release ***" 174 | cp -f $BUILDDIR/$FMU_SHARED_LIB_NAME.so.$FMU_SHARED_LIB_VERSION ../bin/release/$FMU_SHARED_LIB_TARGET_NAME.so && 175 | echo "Created ../bin/release/$FMU_SHARED_LIB_TARGET_NAME.so ***" 176 | fi && 177 | # copy for Mac builds 178 | if [ -e $BUILDDIR/$FMU_SHARED_LIB_NAME.dylib ]; then 179 | cp -f $BUILDDIR/$FMU_SHARED_LIB_NAME.$FMU_SHARED_LIB_VERSION.dylib ../bin/release/$FMU_SHARED_LIB_NAME.$FMU_SHARED_LIB_VERSION.dylib && 180 | echo "Copied $FMU_SHARED_LIB_NAME.$FMU_SHARED_LIB_VERSION.dylib to bin/release ***" 181 | cp -f $BUILDDIR/$FMU_SHARED_LIB_NAME.$FMU_SHARED_LIB_VERSION.dylib ../bin/release/$FMU_SHARED_LIB_TARGET_NAME.dylib && 182 | echo "Created ../bin/release/$FMU_SHARED_LIB_TARGET_NAME.dylib ***" 183 | fi 184 | 185 | -------------------------------------------------------------------------------- /examples/Test5/build/build_VC_x64.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: setup VC environment variables 4 | set VCVARSALL_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 5 | call %VCVARSALL_PATH% 6 | 7 | :: FMU-specific variables - set by code generator 8 | set FMU_SHARED_LIB_NAME=Test5.dll 9 | 10 | set CMAKELISTSDIR=%CD%\..\projects\cmake 11 | 12 | :: create and change into build subdir 13 | mkdir bb_VC_x64 14 | pushd bb_VC_x64 15 | 16 | :: configure makefiles and build 17 | cmake -G "NMake Makefiles" %CMAKELISTSDIR% -DCMAKE_BUILD_TYPE:String="Release" 18 | nmake 19 | if ERRORLEVEL 1 GOTO fail 20 | 21 | popd 22 | 23 | :: copy executable to bin/release dir 24 | xcopy /Y .\bb_VC_x64\%FMU_SHARED_LIB_NAME% ..\bin\release_x64 25 | 26 | exit /b 0 27 | 28 | :fail 29 | echo ** Build Failed ** 30 | exit /b 1 31 | -------------------------------------------------------------------------------- /examples/Test5/build/deploy.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: script is supposed to be executed in /build directory 3 | 4 | if exist ..\bin\release_x64\Test5.dll goto DLL_EXISTS 5 | echo "ERROR: File Test5.dll expected in directory ..\bin\release_x64\Test5.dll, but does not exist. 6 | exit /b 1 7 | :DLL_EXISTS 8 | 9 | :: remove target directory if it exists 10 | if not exist Test5 goto DIRECTORY_CLEAN 11 | echo Removing existing directory 'Test5' 12 | rd /S /Q "Test5" 13 | :DIRECTORY_CLEAN 14 | 15 | :: remove target FMU if it exists 16 | if not exist Test5.fmu goto FMU_REMOVED 17 | echo Removing existing FMU file 'Test5.fmu' 18 | del /F /S /Q "Test5.fmu" 19 | :FMU_REMOVED 20 | 21 | ::create subdir and change into it 22 | mkdir Test5 23 | 24 | cd Test5 25 | 26 | :: create binary dir for Windows 27 | mkdir binaries\win64 28 | 29 | :: copy shared library, we expect it to be already renamed correctly 30 | xcopy ..\..\bin\release_x64\Test5.dll binaries\win64\ 31 | xcopy ..\..\data\modelDescription.xml . 32 | echo Created FMU directory structure 33 | 34 | ::change working directory back to original dir 35 | cd .. 36 | 37 | ::create zip archive 38 | echo Creating archive 'Test5.zip' 39 | cd Test5 40 | 7za a ../Test5.zip . 41 | cd .. 42 | 43 | echo Renaming archive to 'Test5.fmu' 44 | rename Test5.zip Test5.fmu 45 | 46 | :: all ok 47 | exit /b 0 48 | -------------------------------------------------------------------------------- /examples/Test5/build/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # script is supposed to be executed in /build directory 4 | 5 | # remove target directory if it exists 6 | if [ -d Test5 ]; then 7 | rm -rf Test5 8 | fi && 9 | 10 | # remove target FMU if it exists 11 | if [ -f Test5.fmu ]; then 12 | rm Test5.fmu 13 | fi && 14 | 15 | # create subdir and change into it 16 | mkdir -p Test5 && 17 | cd Test5 && 18 | 19 | # create binary dir for Linux 20 | mkdir -p binaries/linux64 && 21 | 22 | # copy shared library, we expect it to be already renamed correctly 23 | cp ../../bin/release/Test5.so binaries/linux64/Test5.so && 24 | cp ../../data/modelDescription.xml . && 25 | 26 | # create zip archive 27 | 7za a ../Test5.zip . | cat > /dev/null && 28 | cd .. && 29 | mv Test5.zip Test5.fmu && 30 | echo "Created Test5.fmu" && 31 | 32 | # change working directory back to original dir 33 | cd - 34 | 35 | -------------------------------------------------------------------------------- /examples/Test5/data/modelDescription.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 25 | 26 | 33 | 34 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 67 | 68 | 69 | 70 | 71 | 72 | 79 | 80 | 81 | 82 | 83 | 84 | 91 | 92 | 93 | 94 | 95 | 96 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /examples/Test5/projects/.gitignore: -------------------------------------------------------------------------------- 1 | /build-* 2 | -------------------------------------------------------------------------------- /examples/Test5/projects/Qt/Test5.pro: -------------------------------------------------------------------------------- 1 | # ---------------------------------- 2 | # Qt Project for building FMU 3 | # ---------------------------------- 4 | # 5 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 6 | # 7 | # BSD 3-Clause License 8 | # 9 | # Copyright (c) 2018, Andreas Nicolai 10 | # All rights reserved. 11 | # 12 | # see https://github.com/ghorwin/FMICodeGenerator/blob/master/LICENSE for details. 13 | 14 | 15 | TARGET = Test5 16 | TEMPLATE = lib 17 | 18 | # no GUI 19 | QT -= core gui 20 | 21 | CONFIG(debug, debug|release) { 22 | windows { 23 | DLLDESTDIR = ../../bin/debug$${DIR_PREFIX} 24 | } 25 | else { 26 | DESTDIR = ../../bin/debug$${DIR_PREFIX} 27 | } 28 | } 29 | else { 30 | windows { 31 | DLLDESTDIR = ../../bin/release$${DIR_PREFIX} 32 | } 33 | else { 34 | DESTDIR = ../../bin/release$${DIR_PREFIX} 35 | } 36 | } 37 | 38 | #DEFINES += FMI2_FUNCTION_PREFIX=Test5_ 39 | 40 | unix|mac { 41 | VER_MAJ = 1 42 | VER_MIN = 0 43 | VER_PAT = 0 44 | VERSION = $${VER_MAJ}.$${VER_MIN}.$${VER_PAT} 45 | } 46 | 47 | unix { 48 | QMAKE_POST_LINK += $$quote(mv $${DESTDIR}/lib$${TARGET}.so $${DESTDIR}/$${TARGET}.so) 49 | } 50 | 51 | INCLUDEPATH = ../../src 52 | 53 | SOURCES += \ 54 | ../../src/fmi2common/fmi2Functions.cpp \ 55 | ../../src/fmi2common/InstanceData.cpp \ 56 | ../../src/Test5.cpp 57 | 58 | HEADERS += \ 59 | ../../src/fmi2common/fmi2Functions.h \ 60 | ../../src/fmi2common/fmi2Functions_complete.h \ 61 | ../../src/fmi2common/fmi2FunctionTypes.h \ 62 | ../../src/fmi2common/fmi2TypesPlatform.h \ 63 | ../../src/fmi2common/InstanceData.h \ 64 | ../../src/Test5.h 65 | 66 | 67 | -------------------------------------------------------------------------------- /examples/Test5/projects/cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMake project file for generated FMI code 2 | # 3 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 4 | # 5 | # BSD 3-Clause License 6 | # 7 | # Copyright (c) 2018, Andreas Nicolai 8 | # All rights reserved. 9 | # 10 | # see https://github.com/ghorwin/FMICodeGenerator/blob/master/LICENSE for details. 11 | 12 | project( Test5 ) 13 | 14 | cmake_minimum_required(VERSION 3.5) 15 | 16 | # add include directories 17 | include_directories( 18 | ${PROJECT_SOURCE_DIR}/../../src 19 | ) 20 | 21 | add_library( ${PROJECT_NAME} SHARED 22 | ${PROJECT_SOURCE_DIR}/../../src/${PROJECT_NAME}.cpp 23 | ${PROJECT_SOURCE_DIR}/../../src/fmi2common/fmi2Functions.cpp 24 | ${PROJECT_SOURCE_DIR}/../../src/fmi2common/InstanceData.cpp 25 | ) 26 | 27 | # link against the dependent libraries 28 | target_link_libraries( ${PROJECT_NAME} 29 | ${APPLE_FRAMEWORKS} 30 | ) 31 | 32 | # Library version strings set by code generator 33 | set( SO_VERSION_MAJOR 1) 34 | set( SO_VERSION_MINOR 0) 35 | set( SO_VERSION_PATCH 0) 36 | set( SO_VERSION_STRING 37 | ${SO_VERSION_MAJOR}.${SO_VERSION_MINOR}.${SO_VERSION_PATCH} 38 | ) 39 | 40 | set_target_properties( ${PROJECT_NAME} PROPERTIES 41 | VERSION ${SO_VERSION_STRING} 42 | SOVERSION ${SO_VERSION_MAJOR} 43 | ) 44 | -------------------------------------------------------------------------------- /examples/Test5/src/Test5.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | FMI Interface for FMU generated by FMICodeGenerator. 4 | 5 | This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 6 | 7 | BSD 3-Clause License 8 | 9 | Copyright (c) 2018, Andreas Nicolai 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, 19 | this list of conditions and the following disclaimer in the documentation 20 | and/or other materials provided with the distribution. 21 | 22 | * Neither the name of the copyright holder nor the names of its 23 | contributors may be used to endorse or promote products derived from 24 | this software without specific prior written permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | */ 38 | 39 | #ifndef Test5H 40 | #define Test5H 41 | 42 | #include "fmi2common/InstanceData.h" 43 | 44 | /*! This class wraps all data needed for a single instance of the FMU. */ 45 | class Test5 : public InstanceData { 46 | public: 47 | /*! Initializes empty instance. */ 48 | Test5(); 49 | 50 | /*! Destructor, writes out cached results from Therakles. */ 51 | ~Test5(); 52 | 53 | /*! Initializes model */ 54 | void init(); 55 | 56 | /*! This function triggers a state-update of the embedded model whenever our cached input 57 | data differs from the input data in the model. 58 | */ 59 | void updateIfModified(); 60 | 61 | /*! Called from fmi2DoStep(). */ 62 | virtual void integrateTo(double tCommunicationIntervalEnd); 63 | 64 | // Functions for getting/setting the state 65 | 66 | /*! This function computes the size needed for full serizalization of 67 | the FMU and stores the size in m_fmuStateSize. 68 | \note The size includes the leading 8byte for the 64bit integer size 69 | of the memory array (for testing purposes). 70 | */ 71 | virtual void computeFMUStateSize(); 72 | 73 | /*! Copies the internal state of the FMU to the memory array pointed to by FMUstate. 74 | Memory array always has size m_fmuStateSize. 75 | */ 76 | virtual void serializeFMUstate(void * FMUstate); 77 | 78 | /*! Copies the content of the memory array pointed to by FMUstate to the internal state of the FMU. 79 | Memory array always has size m_fmuStateSize. 80 | */ 81 | virtual bool deserializeFMUstate(void * FMUstate); 82 | 83 | /*! Cached current time point of the FMU, defines starting point for time integration in co-simulation mode. */ 84 | double m_currentTimePoint; 85 | }; // class Test5 86 | 87 | #endif // Test5H 88 | 89 | -------------------------------------------------------------------------------- /examples/Test5/src/fmi2common/InstanceData.cpp: -------------------------------------------------------------------------------- 1 | /* Generic FMI Interface Implementation 2 | 3 | This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 4 | 5 | BSD 3-Clause License 6 | 7 | Copyright (c) 2018, Andreas Nicolai 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | #include "InstanceData.h" 38 | 39 | #include 40 | #include 41 | 42 | #include "fmi2Functions.h" 43 | #include "fmi2FunctionTypes.h" 44 | 45 | InstanceData::InstanceData() : 46 | m_callbackFunctions(0), 47 | m_initializationMode(false), 48 | m_modelExchange(true), 49 | m_tInput(0), 50 | m_externalInputVarsModified(false), 51 | m_fmuStateSize(0) 52 | { 53 | } 54 | 55 | 56 | InstanceData::~InstanceData() { 57 | for (std::set::iterator it = m_fmuStates.begin(); it != m_fmuStates.end(); ++it) { 58 | free(*it); 59 | } 60 | } 61 | 62 | 63 | void InstanceData::logger(fmi2Status state, fmi2String category, fmi2String message) { 64 | if (m_loggingOn) { 65 | m_callbackFunctions->logger(m_callbackFunctions->componentEnvironment, 66 | m_instanceName.c_str(), state, category, 67 | message); 68 | } 69 | } 70 | 71 | 72 | template 73 | void checkIfIDExists(const T & m, int varID) { 74 | if (m.find(varID) == m.end() ) { 75 | std::stringstream strm; 76 | strm << "Invalid or unknown value reference " << varID; 77 | throw std::runtime_error(strm.str()); 78 | } 79 | } 80 | 81 | void InstanceData::setReal(int varID, double value) { 82 | checkIfIDExists(m_realVar, varID); 83 | m_realVar[varID] = value; 84 | m_externalInputVarsModified = true; 85 | } 86 | 87 | 88 | void InstanceData::setInt(int varID, int value) { 89 | checkIfIDExists(m_integerVar, varID); 90 | m_integerVar[varID] = value; 91 | m_externalInputVarsModified = true; 92 | } 93 | 94 | 95 | void InstanceData::setString(int varID, fmi2String value) { 96 | checkIfIDExists(m_stringVar, varID); 97 | m_stringVar[varID] = value; 98 | m_externalInputVarsModified = true; 99 | } 100 | 101 | 102 | void InstanceData::setBool(int varID, bool value) { 103 | checkIfIDExists(m_boolVar, varID); 104 | m_boolVar[varID] = value; 105 | m_externalInputVarsModified = true; 106 | } 107 | 108 | 109 | void InstanceData::getReal(int varID, double & value) { 110 | // update procedure for model exchange 111 | if (m_modelExchange) 112 | updateIfModified(); 113 | checkIfIDExists(m_realVar, varID); 114 | value = m_realVar[varID]; 115 | } 116 | 117 | 118 | void InstanceData::getInt(int varID, int & value) { 119 | // update procedure for model exchange 120 | if(m_modelExchange) 121 | updateIfModified(); 122 | checkIfIDExists(m_integerVar, varID); 123 | value = m_integerVar[varID]; 124 | } 125 | 126 | 127 | void InstanceData::getString(int varID, fmi2String & value) { 128 | // update procedure for model exchange 129 | if(m_modelExchange) 130 | updateIfModified(); 131 | checkIfIDExists(m_stringVar, varID); 132 | value = m_stringVar[varID].c_str(); 133 | } 134 | 135 | 136 | void InstanceData::getBool(int varID, bool & value) { 137 | // update procedure for model exchange 138 | if(m_modelExchange) 139 | updateIfModified(); 140 | checkIfIDExists(m_boolVar, varID); 141 | value = m_boolVar[varID]; 142 | } 143 | 144 | 145 | void InstanceData::completedIntegratorStep() { 146 | // this function must only be called in ModelExchange mode!!! 147 | if (!m_modelExchange) 148 | throw std::runtime_error("Invalid function call; only permitted in ModelExchange mode."); 149 | updateIfModified(); 150 | completedIntegratorStep(m_tInput, &m_yInput[0]); 151 | } 152 | 153 | -------------------------------------------------------------------------------- /examples/Test5/src/fmi2common/fmi2Functions_complete.h: -------------------------------------------------------------------------------- 1 | /* Inquire version numbers of header files */ 2 | 1 FMI2_Export const char* fmi2GetTypesPlatform(void); 3 | 2 FMI2_Export const char* fmi2GetVersion(void); 4 | 7 FMI2_Export fmi2Status fmi2SetDebugLogging(void* c, int loggingOn, size_t nCategories, const (const char* categories)[]); 5 | 6 | /* Creation and destruction of FMU instances */ 7 | 3 FMI2_Export void* fmi2Instantiate(const char* instanceName, fmi2Type fmuType, const char* fmuGUID, 8 | const char* fmuResourceLocation, const fmi2CallbackFunctions* functions, int visible, int loggingOn); 9 | 6 FMI2_Export void fmi2FreeInstance(void* c); 10 | 11 | /* Enter and exit initialization mode, terminate and reset */ 12 | 32 FMI2_Export fmi2Status fmi2SetupExperiment(void* c, int toleranceDefined, double tolerance, double startTime, int stopTimeDefined, double stopTime); 13 | 4 FMI2_Export fmi2Status fmi2EnterInitializationMode(void* c); 14 | 5 FMI2_Export fmi2Status fmi2ExitInitializationMode(void* c); 15 | 22 FMI2_Export fmi2Status fmi2Terminate(void* c); 16 | 23 FMI2_Export fmi2Status fmi2Reset(void* c); 17 | 18 | /* Getting and setting variables values */ 19 | 14 FMI2_Export fmi2Status fmi2GetReal(void* c, const unsigned int vr[], size_t nvr, double value[]); 20 | 18 FMI2_Export fmi2Status fmi2GetInteger(void* c, const unsigned int vr[], size_t nvr, int value[]); 21 | 19 FMI2_Export fmi2Status fmi2GetBoolean(void* c, const unsigned int vr[], size_t nvr, int value[]); 22 | 20 FMI2_Export fmi2Status fmi2GetString (void* c, const unsigned int vr[], size_t nvr, (const char* value)[]); 23 | 24 | 13 FMI2_Export fmi2Status fmi2SetReal(void* c, const unsigned int vr[], size_t nvr, const double value[]); 25 | 15 FMI2_Export fmi2Status fmi2SetInteger(void* c, const unsigned int vr[], size_t nvr, const int value[]); 26 | 16 FMI2_Export fmi2Status fmi2SetBoolean(void* c, const unsigned int vr[], size_t nvr, const int value[]); 27 | 17 FMI2_Export fmi2Status fmi2SetString(void* c, const unsigned int vr[], size_t nvr, const (const char* value[])); 28 | 29 | /* Getting and setting the internal FMU state */ 30 | 26 FMI2_Export fmi2Status fmi2GetFMUstate(void* c, fmi2FMUstate* FMUstate); 31 | 27 FMI2_Export fmi2Status fmi2SetFMUstate(void* c, fmi2FMUstate FMUstate); 32 | 28 FMI2_Export fmi2Status fmi2FreeFMUstate(void* c, fmi2FMUstate* FMUstate); 33 | 29 FMI2_Export fmi2Status fmi2SerializedFMUstateSize(void* c, fmi2FMUstate FMUstate, size_t* size); 34 | 30 FMI2_Export fmi2Status fmi2SerializeFMUstate(void* c, fmi2FMUstate FMUstate, char serializedState[], size_t size); 35 | 31 FMI2_Export fmi2Status fmi2DeSerializeFMUstate(void* c, const char serializedState[], size_t size, fmi2FMUstate* FMUstate); 36 | 37 | /* Getting partial derivatives */ 38 | 33 FMI2_Export fmi2Status fmi2GetDirectionalDerivative(void* c, const unsigned int vUnknown_ref[], size_t nUnknown, 39 | const unsigned int vKnown_ref[], size_t nKnown, 40 | const double vKnown[], double dvUnknown[]); 41 | 42 | /*************************************************** 43 | Functions for FMI2 for Model Exchange 44 | ****************************************************/ 45 | 46 | /* Enter and exit the different modes */ 47 | 21 FMI2_Export fmi2Status fmi2EnterEventMode(void* c); 48 | 34 FMI2_Export fmi2Status fmi2NewDiscreteStates(void* c, fmi2EventInfo* fmi2eventInfo); 49 | 35 FMI2_Export fmi2Status fmi2EnterContinuousTimeMode(void* c); 50 | 24 FMI2_Export fmi2Status fmi2CompletedIntegratorStep(void* c, int noSetFMUStatePriorToCurrentPoint, int* enterEventMode, int* terminateSimulation); 51 | 52 | /* Providing independent variables and re-initialization of caching */ 53 | 8 FMI2_Export fmi2Status fmi2SetTime(void* c, double time); 54 | 9 FMI2_Export fmi2Status fmi2SetContinuousStates(void* c, const double x[], size_t nx); 55 | 56 | /* Evaluation of the model equations */ 57 | 12 FMI2_Export fmi2Status fmi2GetDerivatives(void* c, double derivatives[], size_t nx); 58 | 25 FMI2_Export fmi2Status fmi2GetEventIndicators(void* c, double eventIndicators[], size_t ni); 59 | 10 FMI2_Export fmi2Status fmi2GetContinuousStates(void* c, double x[], size_t nx); 60 | 11 FMI2_Export fmi2Status fmi2GetNominalsOfContinuousStates(void* c, double x_nominal[], size_t nx); 61 | 62 | 63 | /*************************************************** 64 | Functions for FMI2 for Co-Simulation 65 | ****************************************************/ 66 | 67 | /* Simulating the slave */ 68 | FMI2_Export fmi2Status fmi2SetRealInputDerivatives(void* c, const unsigned int vr[], size_t nvr, const int order[], const double value[]); 69 | FMI2_Export fmi2Status fmi2GetRealOutputDerivatives(void* c, const unsigned int vr[], size_t nvr, const int order[], double value[]); 70 | 71 | FMI2_Export fmi2Status fmi2DoStep(void* c, double currentCommunicationPoint, double communicationStepSize, int noSetFMUStatePriorToCurrentPoint); 72 | FMI2_Export fmi2Status fmi2CancelStep (void* c); 73 | 74 | /* Inquire slave status */ 75 | FMI2_Export fmi2Status fmi2GetStatus(void* c, const fmi2StatusKind s, fmi2Status* value); 76 | FMI2_Export fmi2Status fmi2GetRealStatus(void* c, const fmi2StatusKind s, double* value); 77 | FMI2_Export fmi2Status fmi2GetIntegerStatus(void* c, const fmi2StatusKind s, int* value); 78 | FMI2_Export fmi2Status fmi2GetBooleanStatus(void* c, const fmi2StatusKind s, int* value); 79 | FMI2_Export fmi2Status fmi2GetStringStatus(void* c, const fmi2StatusKind s, const char** value); 80 | -------------------------------------------------------------------------------- /examples/Test5/src/fmi2common/fmi2TypesPlatform.h: -------------------------------------------------------------------------------- 1 | #ifndef fmi2TypesPlatform_h 2 | #define fmi2TypesPlatform_h 3 | 4 | /* Standard header file to define the argument types of the 5 | functions of the Functional Mock-up Interface 2.0. 6 | This header file must be utilized both by the model and 7 | by the simulation engine. 8 | 9 | Revisions: 10 | - Apr. 9, 2014: all prefixes "fmi" renamed to "fmi2" (decision from April 8) 11 | - Mar 31, 2014: New datatype fmiChar introduced. 12 | - Feb. 17, 2013: Changed fmiTypesPlatform from "standard32" to "default". 13 | Removed fmiUndefinedValueReference since no longer needed 14 | (because every state is defined in ScalarVariables). 15 | - March 20, 2012: Renamed from fmiPlatformTypes.h to fmiTypesPlatform.h 16 | - Nov. 14, 2011: Use the header file "fmiPlatformTypes.h" for FMI 2.0 17 | both for "FMI for model exchange" and for "FMI for co-simulation" 18 | New types "fmiComponentEnvironment", "fmiState", and "fmiByte". 19 | The implementation of "fmiBoolean" is change from "char" to "int". 20 | The #define "fmiPlatform" changed to "fmiTypesPlatform" 21 | (in order that #define and function call are consistent) 22 | - Oct. 4, 2010: Renamed header file from "fmiModelTypes.h" to fmiPlatformTypes.h" 23 | for the co-simulation interface 24 | - Jan. 4, 2010: Renamed meModelTypes_h to fmiModelTypes_h (by Mauss, QTronic) 25 | - Dec. 21, 2009: Changed "me" to "fmi" and "meModel" to "fmiComponent" 26 | according to meeting on Dec. 18 (by Martin Otter, DLR) 27 | - Dec. 6, 2009: Added meUndefinedValueReference (by Martin Otter, DLR) 28 | - Sept. 9, 2009: Changes according to FMI-meeting on July 21: 29 | Changed "version" to "platform", "standard" to "standard32", 30 | Added a precise definition of "standard32" as comment 31 | (by Martin Otter, DLR) 32 | - July 19, 2009: Added "me" as prefix to file names, added meTrue/meFalse, 33 | and changed meValueReferenced from int to unsigned int 34 | (by Martin Otter, DLR). 35 | - March 2, 2009: Moved enums and function pointer definitions to 36 | ModelFunctions.h (by Martin Otter, DLR). 37 | - Dec. 3, 2008 : First version by Martin Otter (DLR) and 38 | Hans Olsson (Dynasim). 39 | 40 | 41 | Copyright © 2008-2011 MODELISAR consortium, 42 | 2012-2013 Modelica Association Project "FMI" 43 | All rights reserved. 44 | This file is licensed by the copyright holders under the BSD 2-Clause License 45 | (http://www.opensource.org/licenses/bsd-license.html): 46 | 47 | ---------------------------------------------------------------------------- 48 | Redistribution and use in source and binary forms, with or without 49 | modification, are permitted provided that the following conditions are met: 50 | 51 | - Redistributions of source code must retain the above copyright notice, 52 | this list of conditions and the following disclaimer. 53 | - Redistributions in binary form must reproduce the above copyright notice, 54 | this list of conditions and the following disclaimer in the documentation 55 | and/or other materials provided with the distribution. 56 | - Neither the name of the copyright holders nor the names of its 57 | contributors may be used to endorse or promote products derived 58 | from this software without specific prior written permission. 59 | 60 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 61 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 62 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 63 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 64 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 65 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 66 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 67 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 68 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 69 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 70 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 71 | ---------------------------------------------------------------------------- 72 | 73 | with the extension: 74 | 75 | You may distribute or publicly perform any modification only under the 76 | terms of this license. 77 | (Note, this means that if you distribute a modified file, 78 | the modified file must also be provided under this license). 79 | */ 80 | 81 | /* Platform (unique identification of this header file) */ 82 | #define fmi2TypesPlatform "default" 83 | 84 | /* Type definitions of variables passed as arguments 85 | Version "default" means: 86 | 87 | fmi2Component : an opaque object pointer 88 | fmi2ComponentEnvironment: an opaque object pointer 89 | fmi2FMUstate : an opaque object pointer 90 | fmi2ValueReference : handle to the value of a variable 91 | fmi2Real : double precision floating-point data type 92 | fmi2Integer : basic signed integer data type 93 | fmi2Boolean : basic signed integer data type 94 | fmi2Char : character data type 95 | fmi2String : a pointer to a vector of fmi2Char characters 96 | ('\0' terminated, UTF8 encoded) 97 | fmi2Byte : smallest addressable unit of the machine, typically one byte. 98 | */ 99 | typedef void* fmi2Component; /* Pointer to FMU instance */ 100 | typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ 101 | typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ 102 | typedef unsigned int fmi2ValueReference; 103 | typedef double fmi2Real ; 104 | typedef int fmi2Integer; 105 | typedef int fmi2Boolean; 106 | typedef char fmi2Char; 107 | typedef const fmi2Char* fmi2String; 108 | typedef char fmi2Byte; 109 | 110 | /* Values for fmi2Boolean */ 111 | #define fmi2True 1 112 | #define fmi2False 0 113 | 114 | 115 | #endif /* fmi2TypesPlatform_h */ 116 | -------------------------------------------------------------------------------- /examples/TestWithOutputs.input: -------------------------------------------------------------------------------- 1 | { 2 | "modelName": "TestWithOutputs", 3 | "description": "gfgfdgdfs", 4 | "variables": [ 5 | { 6 | "name": "ResultRootDir", 7 | "valueRef": 42, 8 | "variability": "fixed", 9 | "causality": "parameter", 10 | "initial": "exact", 11 | "typeID": "String", 12 | "startValue": "", 13 | "description": "A writeable directory generated for each slave of this FMU to store slave-specific output/data files.", 14 | "unit": "" 15 | }, 16 | { 17 | "name": "gfdgsdgf", 18 | "valueRef": 1, 19 | "variability": "continuous", 20 | "causality": "output", 21 | "initial": "exact", 22 | "typeID": "Real", 23 | "startValue": "10", 24 | "description": "Some output quantity", 25 | "unit": "m" 26 | }, 27 | { 28 | "name": "sdfgsdfss", 29 | "valueRef": 2, 30 | "variability": "continuous", 31 | "causality": "output", 32 | "initial": "exact", 33 | "typeID": "Real", 34 | "startValue": "2", 35 | "description": "fdsfsdfa", 36 | "unit": "m" 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /examples/TestWithoutOutputs.input: -------------------------------------------------------------------------------- 1 | { 2 | "modelName": "TestWithoutOutputs", 3 | "description": "dfsfds", 4 | "variables": [ 5 | { 6 | "name": "ResultRootDir", 7 | "valueRef": 42, 8 | "variability": "fixed", 9 | "causality": "parameter", 10 | "initial": "exact", 11 | "typeID": "String", 12 | "startValue": "", 13 | "description": "A writeable directory generated for each slave of this FMU to store slave-specific output/data files.", 14 | "unit": "" 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /examples/readme.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | This directory contains examples for generated FMUs source code, associated files and scripts. 4 | Added own code is indicatd by comments. 5 | 6 | 7 | ## P_Control 8 | 9 | A simple example (also used in the tutorial). 10 | 11 | ## Test5 12 | 13 | Another simple controller, turns a heating on when 14 | the available energy generation rate exceeds a certain limit. 15 | 16 | Thanks to Lisa for providing the FMU example. 17 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # About the FMI Code Generator 2 | 3 | ## What is this FMI/FMU stuff? 4 | 5 | FMU stands for _Functional Mockup Unit_ and FMI for _Functional Mockup Interface_. The latter is an industry standard 6 | for simulation model runtime coupling, and basically defines an API and a meta data description file and directory structure: see [FMI-Standard webpage](https://fmi-standard.org) for details. 7 | 8 | ## The Motivation 9 | 10 | When you want an **efficient/fast** FMU slave, there's probably no way around a native C/C++ implementation. However, implementing the C interface functions, the data handling, input/output variable handling and advanced features like **saving and restoring the FMU state** is not so simple and straight-forward. 11 | 12 | However, the process of setting up the FMU (core files, `modelDescription.xml`, directory structure) is pretty similar for most projects and can be automated with a configurable code generator - hence this project. 13 | 14 | ### What FMI Code Generator *is not* 15 | 16 | This is not a Software Development Library/Toolkit for accessing/supporting the FMI interface. Look at the [FMU SDK](https://github.com/qtronic/fmusdk) or other projects on [fmi-tools](https://github.com/fmi-tools/) if you need something like that. 17 | 18 | Actually, the code generated by **FMI Code Generator** hides most of the messy FMI C function interface (including most of the memory management related to instantiating/deleting slave instances, and the state storage stuff) from the typical (engineering) user. Also, the generated code is pretty small, easy to read and comprehend and works cross-platform without any library setup issues. 19 | 20 | ## The (anticipated) use of the FMI Code Generator 21 | 22 | See description of [Test scenario: Stateless P-controller](../../wiki/Test-scenario:-Stateless-P-controller) for a step-by-step tutorial. 23 | 24 | ### Step 1: Create a fully working FMU source code template 25 | 26 | Creating the barebone of an FMU should be as simple as that: 27 | 28 | 1. clone this repository 29 | 2. run the Python program `scripts/main.py` or `scripts/FMIGeneratorWizard.py` 30 | 3. give the relevant information (model name, list of input and output vars, parameters, integration states etc.) 31 | 32 | Once the generator has finished, you have a directory structure with fully working FMU source code (including build system files) with matching `modelDescription.xml` that you can build cross-platform with the provided CMake-based build system. 33 | 34 | ### Step 2: Develop FMU-specific functionality 35 | 36 | The generated directory structure contains build system files for CMake and Qt-qmake. With CMake, you can easily generate makefiles for various compilers and development environments. With the pro-files you can directly start developing with Qt Creator (even though the FMU code itself is plain C/C++ code without Qt dependencies). 37 | 38 | You can now start to implement your FMU-specific logic (physics, mathematical functions) by opening the `.cpp` file within the `/src/` subdirectory. The places where your own code is usually placed are marked with **TODO** comments. 39 | 40 | Test-compile the source code using the provided build system files. 41 | 42 | ### Step 3: Generate the FMU and deploy 43 | 44 | The template directory structure contains a deployment script/batch file (either `/build/deploy.sh` or `/build/deploy.bat`). 45 | 46 | You may want to adjust the `deploy.sh` script to add copying of own resource files, if needed. 47 | 48 | Deployment works as follows (for Linux/Unix/Mac): 49 | 50 | ```bash 51 | # change into generated directory structure 52 | cd /build 53 | # build the FMU in release mode 54 | ./build.sh release 55 | # deploy the FMU, e.g. package the FMU in the zipped directory structure 56 | ./deploy.sh 57 | ``` 58 | 59 | ## System requirements / setup 60 | 61 | The script runs with Python 2.7 and 3.x. 62 | 63 | #### Linux 64 | 65 | Simply install the python packages and pyqt5. 66 | 67 | _Ubuntu 16.04...20.04 - Python 2.7_ 68 | 69 | ```bash 70 | > sudo apt install cmake build-essential qt5-default qt5-qmake qtcreator python-pyqt5 pyqt5-dev-tools p7zip-full 71 | ``` 72 | The package `pyqt5-dev-tools` contains the scripts `pyuic5` and `pyrcc5` needed for development of the FMIGenerator itself. 73 | 74 | _Ubuntu 16.04...20.04 - Python 3.x_ 75 | 76 | ```bash 77 | > sudo apt install cmake build-essential qt5-default qt5-qmake qtcreator python3 python3-pyqt5 pyqt5-dev-tools p7zip-full 78 | ``` 79 | 80 | _Ubuntu 21.04... - Python 3.x_ 81 | 82 | ```bash 83 | > sudo apt install cmake build-essential qt5-qmake qtbase5-dev libqt5core5a libqt5concurrent5 libqt5gui5 libqt5network5 libqt5svg5-dev libqt5xml5 libqt5widgets5 python3 python3-pyqt5 pyqt5-dev-tools p7zip-full 84 | ``` 85 | 86 | 87 | #### Mac 88 | 89 | Use homebrew and/or macports to install python and pyqt5 (or alternatively pip). 90 | 91 | #### Windows 92 | 93 | Things are bit more complicated for Windows. While the code can be compiled (thanks to the CMake build system) using quite a few build chains available on windows, the `batch`-scripts are currently expecting a standard Visual Studio 2022 installation and 7zip must be installed with `7za` in the PATH. Also, `cmake` must be in in the PATH. You also need to install PyQt5 (via pip) as dependency of the script. 94 | 95 | If your setup differs from that, edit the files `build_VC_x64.bat` and `deploy.bat` in directory `data/FMI_template/build` (there are example batch files for different VC versions). 96 | 97 | # License 98 | 99 | The FMICodeGenerator is provided under a *BSD 3-Clause License*. 100 | 101 | # Developer Information 102 | 103 | ## Directory Structure of the FMICodeGenerator repository 104 | 105 | bin - batch/shell scripts to simplify/automate FMU generation 106 | data - resources and template files 107 | doc - documentation, also includes examples 108 | examples - example directory structures (this is what the FMI generator should produce) 109 | scripts - the actual python scripts 110 | scripts/third_party - external library and scripts 111 | third_party - external tools like the compliance checker 112 | -------------------------------------------------------------------------------- /scripts/.gitignore: -------------------------------------------------------------------------------- 1 | /Test01/ 2 | *.wpu 3 | *.pyc 4 | *.wpr 5 | /test001/ 6 | -------------------------------------------------------------------------------- /scripts/Ui_WizardPageBasicProperties.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'WizardPageBasicProperties.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.10.1 6 | # 7 | # WARNING! All changes made in this file will be lost! 8 | 9 | from PyQt5 import QtCore, QtGui, QtWidgets 10 | 11 | class Ui_WizardPageBasicProperties(object): 12 | def setupUi(self, WizardPageBasicProperties): 13 | WizardPageBasicProperties.setObjectName("WizardPageBasicProperties") 14 | WizardPageBasicProperties.resize(699, 361) 15 | self.verticalLayout_2 = QtWidgets.QVBoxLayout(WizardPageBasicProperties) 16 | self.verticalLayout_2.setObjectName("verticalLayout_2") 17 | self.groupBox_2 = QtWidgets.QGroupBox(WizardPageBasicProperties) 18 | self.groupBox_2.setObjectName("groupBox_2") 19 | self.gridLayout = QtWidgets.QGridLayout(self.groupBox_2) 20 | self.gridLayout.setObjectName("gridLayout") 21 | self.label_2 = QtWidgets.QLabel(self.groupBox_2) 22 | self.label_2.setObjectName("label_2") 23 | self.gridLayout.addWidget(self.label_2, 2, 0, 1, 1) 24 | self.label = QtWidgets.QLabel(self.groupBox_2) 25 | self.label.setObjectName("label") 26 | self.gridLayout.addWidget(self.label, 0, 0, 1, 1) 27 | self.lineEditModelName = QtWidgets.QLineEdit(self.groupBox_2) 28 | self.lineEditModelName.setObjectName("lineEditModelName") 29 | self.gridLayout.addWidget(self.lineEditModelName, 0, 1, 1, 2) 30 | self.lineEditTargetDir = QtWidgets.QLineEdit(self.groupBox_2) 31 | self.lineEditTargetDir.setObjectName("lineEditTargetDir") 32 | self.gridLayout.addWidget(self.lineEditTargetDir, 2, 1, 1, 1) 33 | self.toolButtonBrowseFilename = QtWidgets.QToolButton(self.groupBox_2) 34 | self.toolButtonBrowseFilename.setObjectName("toolButtonBrowseFilename") 35 | self.gridLayout.addWidget(self.toolButtonBrowseFilename, 2, 2, 1, 1) 36 | self.label_3 = QtWidgets.QLabel(self.groupBox_2) 37 | font = QtGui.QFont() 38 | font.setItalic(True) 39 | self.label_3.setFont(font) 40 | self.label_3.setObjectName("label_3") 41 | self.gridLayout.addWidget(self.label_3, 3, 1, 1, 1) 42 | self.label_4 = QtWidgets.QLabel(self.groupBox_2) 43 | font = QtGui.QFont() 44 | font.setItalic(True) 45 | self.label_4.setFont(font) 46 | self.label_4.setObjectName("label_4") 47 | self.gridLayout.addWidget(self.label_4, 1, 1, 1, 1) 48 | self.label_5 = QtWidgets.QLabel(self.groupBox_2) 49 | self.label_5.setObjectName("label_5") 50 | self.gridLayout.addWidget(self.label_5, 4, 0, 1, 1) 51 | self.lineEditFMUFilePath = QtWidgets.QLineEdit(self.groupBox_2) 52 | self.lineEditFMUFilePath.setReadOnly(True) 53 | self.lineEditFMUFilePath.setObjectName("lineEditFMUFilePath") 54 | self.gridLayout.addWidget(self.lineEditFMUFilePath, 4, 1, 1, 1) 55 | self.verticalLayout_2.addWidget(self.groupBox_2) 56 | self.groupBox = QtWidgets.QGroupBox(WizardPageBasicProperties) 57 | self.groupBox.setObjectName("groupBox") 58 | self.verticalLayout = QtWidgets.QVBoxLayout(self.groupBox) 59 | self.verticalLayout.setObjectName("verticalLayout") 60 | self.plainTextEditDescription = QtWidgets.QPlainTextEdit(self.groupBox) 61 | self.plainTextEditDescription.setObjectName("plainTextEditDescription") 62 | self.verticalLayout.addWidget(self.plainTextEditDescription) 63 | self.verticalLayout_2.addWidget(self.groupBox) 64 | 65 | self.retranslateUi(WizardPageBasicProperties) 66 | QtCore.QMetaObject.connectSlotsByName(WizardPageBasicProperties) 67 | 68 | def retranslateUi(self, WizardPageBasicProperties): 69 | _translate = QtCore.QCoreApplication.translate 70 | WizardPageBasicProperties.setWindowTitle(_translate("WizardPageBasicProperties", "Form")) 71 | self.groupBox_2.setTitle(_translate("WizardPageBasicProperties", "Required properties")) 72 | self.label_2.setText(_translate("WizardPageBasicProperties", "Output directory:")) 73 | self.label.setText(_translate("WizardPageBasicProperties", "Name:")) 74 | self.toolButtonBrowseFilename.setText(_translate("WizardPageBasicProperties", "...")) 75 | self.label_3.setText(_translate("WizardPageBasicProperties", "Output directory can be an absolute or relative path.")) 76 | self.label_4.setText(_translate("WizardPageBasicProperties", "Model name must not contain whitespace characters.")) 77 | self.label_5.setText(_translate("WizardPageBasicProperties", "FMU directory:")) 78 | self.groupBox.setTitle(_translate("WizardPageBasicProperties", "Description")) 79 | 80 | -------------------------------------------------------------------------------- /scripts/Ui_WizardPageGenerate.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'WizardPageGenerate.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.10.1 6 | # 7 | # WARNING! All changes made in this file will be lost! 8 | 9 | from PyQt5 import QtCore, QtGui, QtWidgets 10 | 11 | class Ui_WizardPageGenerate(object): 12 | def setupUi(self, WizardPageGenerate): 13 | WizardPageGenerate.setObjectName("WizardPageGenerate") 14 | WizardPageGenerate.resize(400, 300) 15 | self.verticalLayout_2 = QtWidgets.QVBoxLayout(WizardPageGenerate) 16 | self.verticalLayout_2.setObjectName("verticalLayout_2") 17 | self.checkBoxTestBuild = QtWidgets.QCheckBox(WizardPageGenerate) 18 | self.checkBoxTestBuild.setChecked(True) 19 | self.checkBoxTestBuild.setObjectName("checkBoxTestBuild") 20 | self.verticalLayout_2.addWidget(self.checkBoxTestBuild) 21 | self.groupBox = QtWidgets.QGroupBox(WizardPageGenerate) 22 | self.groupBox.setObjectName("groupBox") 23 | self.verticalLayout = QtWidgets.QVBoxLayout(self.groupBox) 24 | self.verticalLayout.setObjectName("verticalLayout") 25 | self.plainTextEditLog = QtWidgets.QPlainTextEdit(self.groupBox) 26 | self.plainTextEditLog.setObjectName("plainTextEditLog") 27 | self.verticalLayout.addWidget(self.plainTextEditLog) 28 | self.verticalLayout_2.addWidget(self.groupBox) 29 | 30 | self.retranslateUi(WizardPageGenerate) 31 | QtCore.QMetaObject.connectSlotsByName(WizardPageGenerate) 32 | 33 | def retranslateUi(self, WizardPageGenerate): 34 | _translate = QtCore.QCoreApplication.translate 35 | WizardPageGenerate.setWindowTitle(_translate("WizardPageGenerate", "Form")) 36 | self.checkBoxTestBuild.setText(_translate("WizardPageGenerate", "Test-build FMU after code generation")) 37 | self.groupBox.setTitle(_translate("WizardPageGenerate", "Generation log")) 38 | 39 | -------------------------------------------------------------------------------- /scripts/WizardPageBasicProperties.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Implementation of the basic properties wizard page. 5 | # 6 | # 7 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 8 | # 9 | # BSD 3-Clause License 10 | # 11 | # Copyright (c) 2018, Andreas Nicolai 12 | # All rights reserved. 13 | # 14 | # Redistribution and use in source and binary forms, with or without 15 | # modification, are permitted provided that the following conditions are met: 16 | # 17 | # * Redistributions of source code must retain the above copyright notice, this 18 | # list of conditions and the following disclaimer. 19 | # 20 | # * Redistributions in binary form must reproduce the above copyright notice, 21 | # this list of conditions and the following disclaimer in the documentation 22 | # and/or other materials provided with the distribution. 23 | # 24 | # * Neither the name of the copyright holder nor the names of its 25 | # contributors may be used to endorse or promote products derived from 26 | # this software without specific prior written permission. 27 | # 28 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 29 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 32 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 34 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | 39 | import sys 40 | import os.path 41 | from PyQt5.QtWidgets import QWidget, QFileDialog, QMessageBox 42 | from PyQt5.QtCore import pyqtSlot, pyqtSignal, QDir 43 | 44 | from Ui_WizardPageBasicProperties import Ui_WizardPageBasicProperties 45 | 46 | from FMIGenerator import FMIGenerator 47 | 48 | 49 | class WizardPageBasicProperties(QWidget): 50 | loadDefaults = pyqtSignal('QString') 51 | 52 | def __init__(self): 53 | super(WizardPageBasicProperties, self).__init__() 54 | self.ui = Ui_WizardPageBasicProperties() 55 | self.ui.setupUi(self) 56 | self.ui.lineEditTargetDir.setText( os.path.normpath(QDir.home().absolutePath() ) ) 57 | self.show() 58 | 59 | @pyqtSlot() 60 | def on_lineEditModelName_editingFinished(self): 61 | # auto-generate filename for FMU unless previously entered/selected 62 | targetFileName = os.path.join(self.ui.lineEditTargetDir.text(), self.ui.lineEditModelName.text().strip()) 63 | targetFileName = os.path.normpath(targetFileName) 64 | if self.ui.lineEditFMUFilePath.text() == targetFileName: 65 | return 66 | self.ui.lineEditFMUFilePath.setText(targetFileName) 67 | inputDataCacheFile = targetFileName + ".input" 68 | if (os.path.exists(inputDataCacheFile)): 69 | res = QMessageBox.question(self, "Import previous definitions", 70 | "A file with input data for the same FMU exists. Re-load input data?") 71 | if res == QMessageBox.No: 72 | return 73 | fmiGenerator = FMIGenerator() 74 | fmiGenerator.readInputData(inputDataCacheFile) 75 | self.ui.plainTextEditDescription.setPlainText(fmiGenerator.description) 76 | self.loadDefaults.emit(inputDataCacheFile) 77 | 78 | 79 | 80 | @pyqtSlot() 81 | def on_lineEditTargetDir_editingFinished(self): 82 | self.on_lineEditModelName_editingFinished() 83 | 84 | 85 | @pyqtSlot() 86 | def on_toolButtonBrowseFilename_clicked(self): 87 | # open browse filename dialog 88 | options = QFileDialog.Options() 89 | options |= QFileDialog.DontUseNativeDialog 90 | options |= QFileDialog.ShowDirsOnly 91 | options |= QFileDialog.DontResolveSymlinks 92 | 93 | targetDir = QFileDialog.getExistingDirectory(self, "Select/enter target directory for FMU", QDir.home().absolutePath(), 94 | options=options) 95 | if targetDir: 96 | self.ui.lineEditTargetDir.setText(targetDir) 97 | self.on_lineEditModelName_editingFinished() 98 | return True 99 | -------------------------------------------------------------------------------- /scripts/WizardPageGenerate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Implementation of the final generation page wizard page. 5 | # 6 | # 7 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 8 | # 9 | # BSD 3-Clause License 10 | # 11 | # Copyright (c) 2018, Andreas Nicolai 12 | # All rights reserved. 13 | # 14 | # Redistribution and use in source and binary forms, with or without 15 | # modification, are permitted provided that the following conditions are met: 16 | # 17 | # * Redistributions of source code must retain the above copyright notice, this 18 | # list of conditions and the following disclaimer. 19 | # 20 | # * Redistributions in binary form must reproduce the above copyright notice, 21 | # this list of conditions and the following disclaimer in the documentation 22 | # and/or other materials provided with the distribution. 23 | # 24 | # * Neither the name of the copyright holder nor the names of its 25 | # contributors may be used to endorse or promote products derived from 26 | # this software without specific prior written permission. 27 | # 28 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 29 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 32 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 34 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | 39 | import sys 40 | import platform 41 | 42 | from PyQt5.QtWidgets import QWidget 43 | from PyQt5.QtGui import QFont 44 | 45 | from Ui_WizardPageGenerate import Ui_WizardPageGenerate 46 | 47 | class WizardPageGenerate(QWidget): 48 | def __init__(self): 49 | super(WizardPageGenerate, self).__init__() 50 | self.ui = Ui_WizardPageGenerate() 51 | self.ui.setupUi(self) 52 | 53 | # customize font of log window 54 | f = QFont() 55 | if platform.system() == 'Windows': 56 | f.setFamily("Courier New") 57 | f.setPointSize(9) 58 | elif platform.system() == 'Darwin': 59 | f.setFamily("Monaco") 60 | f.setPointSize(12) 61 | else: 62 | f.setFamily("monospace"); 63 | f.setPointSize(9); 64 | self.ui.plainTextEditLog.setFont(f) 65 | 66 | self.show() 67 | -------------------------------------------------------------------------------- /scripts/commandLineGenerator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Main script for generating FMU code. This is the command line version which generates a minimalistic 5 | # barebone of the modelDescription.xml and the implementation files. Currently, command line 6 | # arguments exist only for model name and description (so, no variables in your FMU). 7 | # 8 | # Feel free to copy this file and add code that populates the FMIGenerator.variables array with data before 9 | # calling fmiGenerator.generate() 10 | # 11 | # 12 | # 13 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 14 | # 15 | # BSD 3-Clause License 16 | # 17 | # Copyright (c) 2018, Andreas Nicolai 18 | # All rights reserved. 19 | # 20 | # Redistribution and use in source and binary forms, with or without 21 | # modification, are permitted provided that the following conditions are met: 22 | # 23 | # * Redistributions of source code must retain the above copyright notice, this 24 | # list of conditions and the following disclaimer. 25 | # 26 | # * Redistributions in binary form must reproduce the above copyright notice, 27 | # this list of conditions and the following disclaimer in the documentation 28 | # and/or other materials provided with the distribution. 29 | # 30 | # * Neither the name of the copyright holder nor the names of its 31 | # contributors may be used to endorse or promote products derived from 32 | # this software without specific prior written permission. 33 | # 34 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | 45 | import argparse 46 | from FMIGenerator import * 47 | 48 | # commandline argument parser 49 | parser = argparse.ArgumentParser() 50 | parser.add_argument("modelName", type=str, help="ID Name of FMU, will be used for directory names, generated FMU name and model name.") 51 | parser.add_argument("--description", type=str, help="Description of the FMU/model") 52 | args = parser.parse_args() 53 | 54 | # create storage class instance 55 | fmiGenerator = FMIGenerator() 56 | 57 | # store command line arguments 58 | fmiGenerator.modelName = args.modelName 59 | if args.description != None: 60 | fmiGenerator.description = args.description 61 | else: 62 | print ("WARNING: Model description missing.") 63 | 64 | # setup variables (test code below) 65 | if False: 66 | v = VarDef("InputVar1", "continuous", "input", "exact", "Real") # valueRef will be given automatically 67 | v.startValue = "15" 68 | fmiGenerator.variables.append(v) 69 | 70 | 71 | # call function of generator to create model 72 | try: 73 | fmiGenerator.generate() 74 | except Exception as e: 75 | print ("ERROR: Error during FMU generation") 76 | print e 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /scripts/main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # Main application file, basically just executes the wizard. 5 | # 6 | # 7 | # This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator) 8 | # 9 | # BSD 3-Clause License 10 | # 11 | # Copyright (c) 2018, Andreas Nicolai 12 | # All rights reserved. 13 | # 14 | # Redistribution and use in source and binary forms, with or without 15 | # modification, are permitted provided that the following conditions are met: 16 | # 17 | # * Redistributions of source code must retain the above copyright notice, this 18 | # list of conditions and the following disclaimer. 19 | # 20 | # * Redistributions in binary form must reproduce the above copyright notice, 21 | # this list of conditions and the following disclaimer in the documentation 22 | # and/or other materials provided with the distribution. 23 | # 24 | # * Neither the name of the copyright holder nor the names of its 25 | # contributors may be used to endorse or promote products derived from 26 | # this software without specific prior written permission. 27 | # 28 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 29 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 32 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 34 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | 39 | import sys 40 | from PyQt5 import QtWidgets 41 | 42 | from FMIGeneratorWizard import FMIGeneratorWizard 43 | 44 | app = QtWidgets.QApplication(sys.argv) 45 | wizard = FMIGeneratorWizard() 46 | wizard.show() 47 | sys.exit(app.exec_()) 48 | 49 | -------------------------------------------------------------------------------- /scripts/third_party/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/scripts/third_party/__init__.py -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.egg-info 3 | /build 4 | /dist 5 | .DS_Store 6 | /.tox 7 | __pycache__ 8 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | - "3.4" 5 | - "3.5" 6 | - "3.6" 7 | install: 8 | - "pip install tox" 9 | script: 10 | - "tox -e $(echo py$TRAVIS_PYTHON_VERSION | tr -d .)" 11 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/CHANGES.rst: -------------------------------------------------------------------------------- 1 | Changes 2 | ======= 3 | 4 | Version 1.5.0 -- 2018/02/16 5 | --------------------------- 6 | 7 | * More specific error when failing to create XDG fallback trash directory (#20) 8 | * Windows: Workaround for long paths (#23) 9 | 10 | Version 1.4.2 -- 2017/11/17 11 | --------------------------- 12 | 13 | * Fix incompatibility with Python 3.6 on Windows. (#18) 14 | 15 | Version 1.4.1 -- 2017/08/07 16 | --------------------------- 17 | 18 | * Fix crash on Windows introduced in v1.4.0. Oops... (#14) 19 | 20 | Version 1.4.0 -- 2017/08/07 21 | --------------------------- 22 | 23 | * Use ``bytes`` instead of ``str`` for internal path handling in ``plat_other``. (#13) 24 | 25 | Version 1.3.1 -- 2017/07/31 26 | --------------------------- 27 | 28 | * Throw ``WindowsError`` instead of ``OSError`` in ``plat_win``. (#7) 29 | * Fix ``TypeError`` on python 2 in ``plat_other``. (#12) 30 | 31 | Version 1.3.0 -- 2013/07/19 32 | --------------------------- 33 | 34 | * Added support for Gnome's GIO. 35 | * Merged Python 3 and Python 2 versions in a single codebase. 36 | 37 | Version 1.2.0 -- 2011/03/16 38 | --------------------------- 39 | 40 | * Improved ``plat_other`` to follow freedesktop.org trash specification. 41 | 42 | Version 1.1.0 -- 2010/10/18 43 | --------------------------- 44 | 45 | * Converted compiled modules to ctypes so that cross-platform compilation isn't necessary anymore. 46 | 47 | Version 1.0.2 -- 2010/07/10 48 | --------------------------- 49 | 50 | * Fixed bugs with external volumes in plat_other. 51 | 52 | Version 1.0.1 -- 2010/04/19 53 | --------------------------- 54 | 55 | * Fixed memory leak in OS X module. 56 | 57 | Version 1.0.0 -- 2010/04/07 58 | --------------------------- 59 | 60 | * Initial Release 61 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, Virgil Dupras 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | * Neither the name of Hardcoded Software Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 9 | 10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include CHANGES.rst LICENSE 2 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/README.rst: -------------------------------------------------------------------------------- 1 | ================================================== 2 | Send2Trash -- Send files to trash on all platforms 3 | ================================================== 4 | 5 | Send2Trash is a small package that sends files to the Trash (or Recycle Bin) *natively* and on 6 | *all platforms*. On OS X, it uses native ``FSMoveObjectToTrashSync`` Cocoa calls, on Windows, it 7 | uses native (and ugly) ``SHFileOperation`` win32 calls. On other platforms, if `PyGObject`_ and 8 | `GIO`_ are available, it will use this. Otherwise, it will fallback to its own implementation 9 | of the `trash specifications from freedesktop.org`_. 10 | 11 | ``ctypes`` is used to access native libraries, so no compilation is necessary. 12 | 13 | Send2Trash supports Python 2.7 and up (Python 3 is supported). 14 | 15 | Installation 16 | ------------ 17 | 18 | You can download it with pip:: 19 | 20 | pip install Send2Trash 21 | 22 | or you can download the source from http://github.com/hsoft/send2trash and install it with:: 23 | 24 | >>> python setup.py install 25 | 26 | Usage 27 | ----- 28 | 29 | >>> from send2trash import send2trash 30 | >>> send2trash('some_file') 31 | 32 | On Freedesktop platforms (Linux, BSD, etc.), you may not be able to efficiently 33 | trash some files. In these cases, an exception ``send2trash.TrashPermissionError`` 34 | is raised, so that the application can handle this case. This inherits from 35 | ``PermissionError`` (``OSError`` on Python 2). Specifically, this affects 36 | files on a different device to the user's home directory, where the root of the 37 | device does not have a ``.Trash`` directory, and we don't have permission to 38 | create a ``.Trash-$UID`` directory. 39 | 40 | For any other problem, ``OSError`` is raised. 41 | 42 | .. _PyGObject: https://wiki.gnome.org/PyGObject 43 | .. _GIO: https://developer.gnome.org/gio/ 44 | .. _trash specifications from freedesktop.org: http://freedesktop.org/wiki/Specifications/trash-spec/ 45 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/scripts/third_party/send2trash_master/__init__.py -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/send2trash/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2013 Hardcoded Software (http://www.hardcoded.net) 2 | 3 | # This software is licensed under the "BSD" License as described in the "LICENSE" file, 4 | # which should be included with this package. The terms are also available at 5 | # http://www.hardcoded.net/licenses/bsd_license 6 | 7 | import sys 8 | 9 | from .exceptions import TrashPermissionError 10 | 11 | if sys.platform == 'darwin': 12 | from .plat_osx import send2trash 13 | elif sys.platform == 'win32': 14 | from .plat_win import send2trash 15 | else: 16 | try: 17 | # If we can use gio, let's use it 18 | from .plat_gio import send2trash 19 | except ImportError: 20 | # Oh well, let's fallback to our own Freedesktop trash implementation 21 | from .plat_other import send2trash 22 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/send2trash/compat.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Virgil Dupras 2 | 3 | # This software is licensed under the "BSD" License as described in the "LICENSE" file, 4 | # which should be included with this package. The terms are also available at 5 | # http://www.hardcoded.net/licenses/bsd_license 6 | 7 | import sys 8 | import os 9 | 10 | PY3 = sys.version_info[0] >= 3 11 | if PY3: 12 | text_type = str 13 | binary_type = bytes 14 | if os.supports_bytes_environ: 15 | # environb will be unset under Windows, but then again we're not supposed to use it. 16 | environb = os.environb 17 | else: 18 | text_type = unicode 19 | binary_type = str 20 | environb = os.environ 21 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/send2trash/exceptions.py: -------------------------------------------------------------------------------- 1 | import errno 2 | from .compat import PY3 3 | 4 | if PY3: 5 | _permission_error = PermissionError 6 | else: 7 | _permission_error = OSError 8 | 9 | class TrashPermissionError(_permission_error): 10 | """A permission error specific to a trash directory. 11 | 12 | Raising this error indicates that permissions prevent us efficiently 13 | trashing a file, although we might still have permission to delete it. 14 | This is *not* used when permissions prevent removing the file itself: 15 | that will be raised as a regular PermissionError (OSError on Python 2). 16 | 17 | Application code that catches this may try to simply delete the file, 18 | or prompt the user to decide, or (on Freedesktop platforms), move it to 19 | 'home trash' as a fallback. This last option probably involves copying the 20 | data between partitions, devices, or network drives, so we don't do it as 21 | a fallback. 22 | """ 23 | def __init__(self, filename): 24 | _permission_error.__init__(self, errno.EACCES, "Permission denied", 25 | filename) 26 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/send2trash/plat_gio.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Virgil Dupras 2 | 3 | # This software is licensed under the "BSD" License as described in the "LICENSE" file, 4 | # which should be included with this package. The terms are also available at 5 | # http://www.hardcoded.net/licenses/bsd_license 6 | 7 | from gi.repository import GObject, Gio 8 | from .exceptions import TrashPermissionError 9 | 10 | def send2trash(path): 11 | try: 12 | f = Gio.File.new_for_path(path) 13 | f.trash(cancellable=None) 14 | except GObject.GError as e: 15 | if e.code == Gio.IOErrorEnum.NOT_SUPPORTED: 16 | # We get here if we can't create a trash directory on the same 17 | # device. I don't know if other errors can result in NOT_SUPPORTED. 18 | raise TrashPermissionError('') 19 | raise OSError(e.message) 20 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/send2trash/plat_osx.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Virgil Dupras 2 | 3 | # This software is licensed under the "BSD" License as described in the "LICENSE" file, 4 | # which should be included with this package. The terms are also available at 5 | # http://www.hardcoded.net/licenses/bsd_license 6 | 7 | from __future__ import unicode_literals 8 | 9 | from ctypes import cdll, byref, Structure, c_char, c_char_p 10 | from ctypes.util import find_library 11 | 12 | from .compat import binary_type 13 | 14 | Foundation = cdll.LoadLibrary(find_library('Foundation')) 15 | CoreServices = cdll.LoadLibrary(find_library('CoreServices')) 16 | 17 | GetMacOSStatusCommentString = Foundation.GetMacOSStatusCommentString 18 | GetMacOSStatusCommentString.restype = c_char_p 19 | FSPathMakeRefWithOptions = CoreServices.FSPathMakeRefWithOptions 20 | FSMoveObjectToTrashSync = CoreServices.FSMoveObjectToTrashSync 21 | 22 | kFSPathMakeRefDefaultOptions = 0 23 | kFSPathMakeRefDoNotFollowLeafSymlink = 0x01 24 | 25 | kFSFileOperationDefaultOptions = 0 26 | kFSFileOperationOverwrite = 0x01 27 | kFSFileOperationSkipSourcePermissionErrors = 0x02 28 | kFSFileOperationDoNotMoveAcrossVolumes = 0x04 29 | kFSFileOperationSkipPreflight = 0x08 30 | 31 | class FSRef(Structure): 32 | _fields_ = [('hidden', c_char * 80)] 33 | 34 | def check_op_result(op_result): 35 | if op_result: 36 | msg = GetMacOSStatusCommentString(op_result).decode('utf-8') 37 | raise OSError(msg) 38 | 39 | def send2trash(path): 40 | if not isinstance(path, binary_type): 41 | path = path.encode('utf-8') 42 | fp = FSRef() 43 | opts = kFSPathMakeRefDoNotFollowLeafSymlink 44 | op_result = FSPathMakeRefWithOptions(path, opts, byref(fp), None) 45 | check_op_result(op_result) 46 | opts = kFSFileOperationDefaultOptions 47 | op_result = FSMoveObjectToTrashSync(byref(fp), None, opts) 48 | check_op_result(op_result) 49 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/send2trash/plat_win.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Virgil Dupras 2 | 3 | # This software is licensed under the "BSD" License as described in the "LICENSE" file, 4 | # which should be included with this package. The terms are also available at 5 | # http://www.hardcoded.net/licenses/bsd_license 6 | 7 | from __future__ import unicode_literals 8 | 9 | from ctypes import (windll, Structure, byref, c_uint, 10 | create_unicode_buffer, addressof) 11 | from ctypes.wintypes import HWND, UINT, LPCWSTR, BOOL 12 | import os.path as op 13 | 14 | from .compat import text_type 15 | 16 | kernel32 = windll.kernel32 17 | GetShortPathNameW = kernel32.GetShortPathNameW 18 | 19 | shell32 = windll.shell32 20 | SHFileOperationW = shell32.SHFileOperationW 21 | 22 | 23 | class SHFILEOPSTRUCTW(Structure): 24 | _fields_ = [ 25 | ("hwnd", HWND), 26 | ("wFunc", UINT), 27 | ("pFrom", LPCWSTR), 28 | ("pTo", LPCWSTR), 29 | ("fFlags", c_uint), 30 | ("fAnyOperationsAborted", BOOL), 31 | ("hNameMappings", c_uint), 32 | ("lpszProgressTitle", LPCWSTR), 33 | ] 34 | 35 | 36 | FO_MOVE = 1 37 | FO_COPY = 2 38 | FO_DELETE = 3 39 | FO_RENAME = 4 40 | 41 | FOF_MULTIDESTFILES = 1 42 | FOF_SILENT = 4 43 | FOF_NOCONFIRMATION = 16 44 | FOF_ALLOWUNDO = 64 45 | FOF_NOERRORUI = 1024 46 | 47 | 48 | def get_short_path_name(long_name): 49 | if not long_name.startswith('\\\\?\\'): 50 | long_name = '\\\\?\\' + long_name 51 | buf_size = GetShortPathNameW(long_name, None, 0) 52 | output = create_unicode_buffer(buf_size) 53 | GetShortPathNameW(long_name, output, buf_size) 54 | return output.value[4:] # Remove '\\?\' for SHFileOperationW 55 | 56 | 57 | def send2trash(path): 58 | if not isinstance(path, text_type): 59 | path = text_type(path, 'mbcs') 60 | if not op.isabs(path): 61 | path = op.abspath(path) 62 | path = get_short_path_name(path) 63 | fileop = SHFILEOPSTRUCTW() 64 | fileop.hwnd = 0 65 | fileop.wFunc = FO_DELETE 66 | # FIX: https://github.com/hsoft/send2trash/issues/17 67 | # Starting in python 3.6.3 it is no longer possible to use: 68 | # LPCWSTR(path + '\0') directly as embedded null characters are no longer 69 | # allowed in strings 70 | # Workaround 71 | # - create buffer of c_wchar[] (LPCWSTR is based on this type) 72 | # - buffer is two c_wchar characters longer (double null terminator) 73 | # - cast the address of the buffer to a LPCWSTR 74 | # NOTE: based on how python allocates memory for these types they should 75 | # always be zero, if this is ever not true we can go back to explicitly 76 | # setting the last two characters to null using buffer[index] = '\0'. 77 | buffer = create_unicode_buffer(path, len(path)+2) 78 | fileop.pFrom = LPCWSTR(addressof(buffer)) 79 | fileop.pTo = None 80 | fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT 81 | fileop.fAnyOperationsAborted = 0 82 | fileop.hNameMappings = 0 83 | fileop.lpszProgressTitle = None 84 | result = SHFileOperationW(byref(fileop)) 85 | if result: 86 | raise WindowsError(None, None, path, result) 87 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | CLASSIFIERS = [ 4 | 'Development Status :: 5 - Production/Stable', 5 | 'Intended Audience :: Developers', 6 | 'License :: OSI Approved :: BSD License', 7 | 'Operating System :: MacOS :: MacOS X', 8 | 'Operating System :: Microsoft :: Windows', 9 | 'Operating System :: POSIX', 10 | 'Programming Language :: Python :: 2.7', 11 | 'Programming Language :: Python :: 3', 12 | 'Programming Language :: Python :: 3.4', 13 | 'Programming Language :: Python :: 3.5', 14 | 'Programming Language :: Python :: 3.6', 15 | 'Topic :: Desktop Environment :: File Managers', 16 | ] 17 | 18 | LONG_DESCRIPTION = open('README.rst', 'rt').read() + '\n\n' + open('CHANGES.rst', 'rt').read() 19 | 20 | setup( 21 | name='Send2Trash', 22 | version='1.5.0', 23 | author='Virgil Dupras', 24 | author_email='hsoft@hardcoded.net', 25 | packages=['send2trash'], 26 | scripts=[], 27 | test_suite='tests', 28 | url='https://github.com/hsoft/send2trash', 29 | license='BSD License', 30 | description='Send file to trash natively under Mac OS X, Windows and Linux.', 31 | long_description=LONG_DESCRIPTION, 32 | classifiers=CLASSIFIERS, 33 | ) 34 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/scripts/third_party/send2trash_master/tests/__init__.py -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/tests/test_plat_win.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | import os 3 | import sys 4 | import unittest 5 | from os import path as op 6 | from tempfile import gettempdir 7 | 8 | from send2trash import send2trash as s2t 9 | 10 | 11 | @unittest.skipIf(sys.platform != 'win32', 'Windows only') 12 | class TestLongPath(unittest.TestCase): 13 | def setUp(self): 14 | filename = 'A' * 100 15 | self.dirname = '\\\\?\\' + os.path.join(gettempdir(), filename) 16 | self.file = os.path.join( 17 | self.dirname, 18 | filename, 19 | filename, # From there, the path is not trashable from Explorer 20 | filename, 21 | filename + '.txt') 22 | self._create_tree(self.file) 23 | 24 | def tearDown(self): 25 | try: 26 | os.remove(self.dirname) 27 | except OSError: 28 | pass 29 | 30 | def _create_tree(self, path): 31 | dirname = os.path.dirname(path) 32 | if not os.path.isdir(dirname): 33 | os.makedirs(dirname) 34 | with open(path, 'w') as writer: 35 | writer.write('Looong filename!') 36 | 37 | def test_trash_file(self): 38 | s2t(self.file) 39 | self.assertFalse(op.exists(self.file)) 40 | 41 | @unittest.skipIf( 42 | op.splitdrive(os.getcwd())[0] != op.splitdrive(gettempdir())[0], 43 | 'Cannot trash long path from other drive') 44 | def test_trash_folder(self): 45 | s2t(self.dirname) 46 | self.assertFalse(op.exists(self.dirname)) 47 | -------------------------------------------------------------------------------- /scripts/third_party/send2trash_master/tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27,py34,py35,py36 3 | skip_missing_interpreters = True 4 | 5 | [testenv] 6 | commands = 7 | python setup.py test 8 | 9 | [testenv:py27] 10 | deps = 11 | configparser 12 | -------------------------------------------------------------------------------- /scripts/ui/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/scripts/ui/.gitignore -------------------------------------------------------------------------------- /scripts/ui/FMIGenerator.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | gfx/minus.png 4 | gfx/plus.png 5 | 6 | 7 | -------------------------------------------------------------------------------- /scripts/ui/WizardPageBasicProperties.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | WizardPageBasicProperties 4 | 5 | 6 | 7 | 0 8 | 0 9 | 699 10 | 361 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | Required properties 21 | 22 | 23 | 24 | 25 | 26 | Output directory: 27 | 28 | 29 | 30 | 31 | 32 | 33 | Name: 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | ... 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | true 55 | 56 | 57 | 58 | Output directory can be an absolute or relative path. 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | true 67 | 68 | 69 | 70 | Model name must not contain whitespace characters. 71 | 72 | 73 | 74 | 75 | 76 | 77 | FMU directory: 78 | 79 | 80 | 81 | 82 | 83 | 84 | true 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | Description 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /scripts/ui/WizardPageGenerate.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | WizardPageGenerate 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | Test-build FMU after code generation 21 | 22 | 23 | true 24 | 25 | 26 | 27 | 28 | 29 | 30 | Generation log 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /scripts/ui/gfx/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/scripts/ui/gfx/minus.png -------------------------------------------------------------------------------- /scripts/ui/gfx/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/scripts/ui/gfx/plus.png -------------------------------------------------------------------------------- /scripts/ui/readme.md: -------------------------------------------------------------------------------- 1 | # Qt-Ui files for the graphical user interface 2 | 3 | UI-files are converted to Python scripts: 4 | 5 | ```bash 6 | > pyuic5 file.ui > -o file.py 7 | ``` 8 | 9 | The ui files use a resource file FMIGenerator.qrc that holds images for icons/tool buttons. 10 | When converting ui-files to python scripts, the resource file is imported by name 11 | `FMIGenerator_rc.py`. We use the qrc-code generator to create this file from the resource file 12 | using the command line: 13 | 14 | ```bash 15 | > pyrcc5 FMIGenerator.qrc -o FMIGenerator_rc.py 16 | ``` 17 | 18 | To automate the process (which needs to be done whenever a ui file has been edited) the 19 | script `update.sh` is available. Run this, whenever you have modified a ui file! 20 | 21 | -------------------------------------------------------------------------------- /scripts/ui/update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -x - (optional) generate test code to show and test the class 4 | # -i 0 - generate class using tabs as indentation 5 | 6 | pyuic5 -i 0 WizardPageBasicProperties.ui -o ../Ui_WizardPageBasicProperties.py 7 | pyuic5 -i 0 WizardPageVariables.ui -o ../Ui_WizardPageVariables.py 8 | pyuic5 -i 0 WizardPageGenerate.ui -o ../Ui_WizardPageGenerate.py 9 | 10 | 11 | # also transform the qrc file 12 | 13 | pyrcc5 FMIGenerator.qrc -o ../FMIGenerator_rc.py 14 | -------------------------------------------------------------------------------- /third_party/.gitignore: -------------------------------------------------------------------------------- 1 | /FMUChecker-2.0.4-linux64/ 2 | -------------------------------------------------------------------------------- /third_party/FMUChecker-2.0.4-linux64.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/third_party/FMUChecker-2.0.4-linux64.zip -------------------------------------------------------------------------------- /third_party/FMUChecker-2.0.4-win64.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghorwin/FMICodeGenerator/8119c33bd7bdb25a137c66e5db3a753106767ad6/third_party/FMUChecker-2.0.4-win64.zip --------------------------------------------------------------------------------