├── .clang-format
├── .github
└── workflows
│ └── config.yml
├── .gitignore
├── BUILDING.md
├── CITATION.cff
├── CMakeLists.txt
├── LICENSE
├── README.md
├── cmake
├── FindLIBZIP.cmake
├── FindPugiXML.cmake
├── conan.cmake
└── fmi4cpp-config.cmake.in
├── examples
├── CMakeLists.txt
├── controlled_temperature.cpp
├── fmu_test.cpp
├── multiple_fmus.cpp
├── time_util.hpp
└── torsionbar.cpp
├── include
└── fmi4cpp
│ ├── dll_handle.hpp
│ ├── fmi2
│ ├── cs_fmu.hpp
│ ├── cs_library.hpp
│ ├── cs_slave.hpp
│ ├── fmi2.hpp
│ ├── fmi2FunctionTypes.h
│ ├── fmi2Functions.h
│ ├── fmi2TypesPlatform.h
│ ├── fmi2_library.hpp
│ ├── fmu.hpp
│ ├── me_fmu.hpp
│ ├── me_instance.hpp
│ ├── me_library.hpp
│ └── xml
│ │ ├── cs_model_description.hpp
│ │ ├── default_experiment.hpp
│ │ ├── enums.hpp
│ │ ├── fmu_attributes.hpp
│ │ ├── me_model_description.hpp
│ │ ├── model_description.hpp
│ │ ├── model_description_parser.hpp
│ │ ├── model_structure.hpp
│ │ ├── model_variables.hpp
│ │ ├── scalar_variable.hpp
│ │ ├── source_files.hpp
│ │ ├── specific_model_description.hpp
│ │ ├── typed_scalar_variable.hpp
│ │ └── unit_definitions.hpp
│ ├── fmi4cpp.hpp
│ ├── fmu_base.hpp
│ ├── fmu_instance.hpp
│ ├── fmu_instance_base.hpp
│ ├── fmu_resource.hpp
│ ├── fmu_slave.hpp
│ ├── fmu_variable_accessor.hpp
│ ├── status.hpp
│ ├── tools
│ └── unzipper.hpp
│ └── types.hpp
├── resources
└── fmus
│ └── 2.0
│ ├── cs
│ ├── 20sim
│ │ └── 4.6.4.8004
│ │ │ ├── ControlledTemperature
│ │ │ ├── ControlledTemperature.fmu
│ │ │ └── modelDescription.xml
│ │ │ └── TorsionBar
│ │ │ ├── TorsionBar.fmu
│ │ │ └── modelDescription.xml
│ └── OpenModelica
│ │ └── v1.11.0
│ │ └── FmuExportCrossCompile
│ │ ├── FmuExportCrossCompile.fmu
│ │ └── modelDescription.xml
│ └── me
│ ├── OpenModelica
│ └── v1.11.0
│ │ └── FmuExportCrossCompile
│ │ ├── FmuExportCrossCompile.fmu
│ │ └── modelDescription.xml
│ └── Test-FMUs
│ └── 0.0.1
│ ├── BouncingBall
│ └── BouncingBall.fmu
│ ├── Dahlquist
│ └── Dahlquist.fmu
│ ├── Feedthrough
│ └── Feedthrough.fmu
│ ├── Resource
│ └── Resource.fmu
│ ├── Stair
│ └── Stair.fmu
│ └── VanDerPol
│ └── VanDerPol.fmu
├── src
├── CMakeLists.txt
└── fmi4cpp
│ ├── fmi2
│ ├── cs_fmu.cpp
│ ├── cs_library.cpp
│ ├── cs_slave.cpp
│ ├── fmi2_library.cpp
│ ├── fmu.cpp
│ ├── me_fmu.cpp
│ ├── me_instance.cpp
│ ├── me_library.cpp
│ ├── status_converter.hpp
│ └── xml
│ │ ├── enums.cpp
│ │ ├── model_description.cpp
│ │ ├── model_description_parser.cpp
│ │ ├── model_variables.cpp
│ │ └── scalar_variable.cpp
│ ├── fmu_resource.cpp
│ ├── library_helper.hpp
│ ├── mlog.hpp
│ └── tools
│ ├── os_util.hpp
│ ├── simple_id.hpp
│ └── unzipper.cpp
├── tests
├── CMakeLists.txt
├── test_controlled_temperature.cpp
├── test_modeldescription1.cpp
└── test_modeldescription2.cpp
├── vcpkg.json
└── version.txt
/.clang-format:
--------------------------------------------------------------------------------
1 | Language: Cpp
2 | Standard: Cpp11
3 | BasedOnStyle: WebKit
4 | NamespaceIndentation: None
5 | IndentCaseLabels: true
6 | IndentPPDirectives: AfterHash
7 | FixNamespaceComments: true
8 | MaxEmptyLinesToKeep: 2
9 | SpaceAfterTemplateKeyword: false
10 | AllowShortCaseLabelsOnASingleLine: true
11 | AllowAllParametersOfDeclarationOnNextLine: true
12 | AllowShortIfStatementsOnASingleLine: true
13 | AllowShortBlocksOnASingleLine: true
14 | AllowShortLoopsOnASingleLine: true
15 | BreakBeforeBinaryOperators: None
16 | Cpp11BracedListStyle: true
17 | SpaceBeforeCpp11BracedList: false
18 | BreakBeforeBraces: Custom
19 | BraceWrapping:
20 | AfterEnum: true
21 | AfterStruct: true
22 | AfterClass: true
23 | SplitEmptyFunction: false
24 | AfterFunction: true
25 | AfterNamespace : true
26 | AfterControlStatement: false
27 | IncludeBlocks: Regroup
28 | IncludeCategories:
29 | - Regex: '^[<"]fmi4cpp[/.]'
30 | Priority: 20
31 | - Regex: '^[<"](boost|zip|catch2)[/.]'
32 | Priority: 30
33 | - Regex: '^"'
34 | Priority: 10
35 | - Regex: '.*'
36 | Priority: 40
37 |
--------------------------------------------------------------------------------
/.github/workflows/config.yml:
--------------------------------------------------------------------------------
1 | name: FMI4cpp CI
2 |
3 | on: [ push, workflow_dispatch ]
4 |
5 | jobs:
6 |
7 | cmake-on-linux:
8 |
9 | runs-on: ${{ matrix.os }}
10 | strategy:
11 | fail-fast: false
12 | matrix:
13 | os: [ubuntu-20.04]
14 |
15 | steps:
16 | - uses: actions/checkout@v3
17 |
18 | - name: Install prerequisites
19 | run: |
20 | sudo apt-get update && sudo apt-get install -y --no-install-recommends \
21 | gcc g++ cmake libzip-dev libpugixml-dev
22 |
23 | - name: Configure and build
24 | run: |
25 | cmake . -B build -DFMI4CPP_BUILD_TESTS=ON -DFMI4CPP_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release
26 | cmake --build build
27 |
28 | - name: Test
29 | run: |
30 | cd build/tests && ctest
31 |
32 |
33 | vcpkg-on-linux:
34 |
35 | runs-on: ${{ matrix.os }}
36 | env:
37 | CC: gcc-${{ matrix.compiler_version }}
38 | CXX: g++-${{ matrix.compiler_version }}
39 | strategy:
40 | fail-fast: false
41 | matrix:
42 | os: [ubuntu-22.04]
43 | compiler_version: [11]
44 |
45 | steps:
46 | - uses: actions/checkout@v3
47 |
48 | - name: Restore artifacts, or run vcpkg, build (and cache artifacts as post step)
49 | uses: lukka/run-vcpkg@v10
50 | id: runvcpkg
51 | with:
52 | vcpkgDirectory: '${{ github.workspace }}/vcpkg'
53 | vcpkgGitCommitId: '4cac260c4b7331538d31886f57739fea0bffa27e'
54 | vcpkgJsonGlob: 'vcpkg.json'
55 | appendedCacheKey: vcpkginstall
56 |
57 | - name: Configure and build
58 | run: |
59 | cmake . -B build -DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" -DFMI4CPP_BUILD_TESTS=ON -DFMI4CPP_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release
60 | cmake --build build
61 |
62 | - name: Test
63 | run: |
64 | cd build/tests && ctest
65 |
66 |
67 | vcpkg-on-windows:
68 |
69 | runs-on: ${{ matrix.os }}
70 | strategy:
71 | fail-fast: false
72 | matrix:
73 | os: [windows-2019, windows-2022]
74 |
75 | steps:
76 | - uses: actions/checkout@v3
77 |
78 | - name: Restore artifacts, or run vcpkg, build (and cache artifacts as post step)
79 | uses: lukka/run-vcpkg@v10
80 | id: runvcpkg
81 | with:
82 | vcpkgDirectory: '${{ github.workspace }}/vcpkg'
83 | vcpkgGitCommitId: '4cac260c4b7331538d31886f57739fea0bffa27e'
84 | vcpkgJsonGlob: 'vcpkg.json'
85 | appendedCacheKey: vcpkginstall
86 |
87 | - name: Configure and build
88 | run: |
89 | cmake . -B build -A x64 -DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" -DFMI4CPP_BUILD_TESTS=ON -DFMI4CPP_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release
90 | cmake --build build --config Release
91 | shell: bash
92 |
93 | - name: Test
94 | run: |
95 | cd build/tests && ctest -C Release
96 | shell: bash
97 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | build
3 | cmake-build-*
4 |
5 | .idea
6 | .vscode
7 | .cache
8 |
9 | compile_commands.json
10 |
11 | /vcpkg
12 |
--------------------------------------------------------------------------------
/BUILDING.md:
--------------------------------------------------------------------------------
1 | ### BUILDING
2 |
3 | For building FMI4cpp, you can use either `vcpkg` or `apt-get` for getting the required dependencies.
4 |
5 | ##### vcpkg
6 |
7 | Call CMake with `-DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake`
8 |
9 | ##### apt-get
10 |
11 | ```bash
12 | Linux:~/$ sudo apt-get install libzip-dev libpugixml-dev
13 | ```
14 |
15 | ### Running examples/tests
16 |
17 | To build the examples pass `-DFMI4CPP_BUILD_EXAMPLES=ON` to CMake.
18 | To build the tests pass `-DFMI4CPP_BUILD_TESTS=ON` to CMake.
19 |
--------------------------------------------------------------------------------
/CITATION.cff:
--------------------------------------------------------------------------------
1 | cff-version: 1.2.0
2 | title: FMI4cpp
3 | message: >-
4 | If you use FMI4cpp in your research, please cite it using
5 | the following metadata.
6 | type: software
7 | authors:
8 | - family-names: Hatledal
9 | given-names: Lars Ivar
10 | orcid: 'https://orcid.org/0000-0001-6436-7213'
11 | email: larsivarhatledal@gmail.com
12 | affiliation: 'NTNU Aalesund, Norway'
13 | repository-code: 'https://github.com/NTNU-IHB/FMI4cpp'
14 | url: 'https://github.com/NTNU-IHB/FMI4cpp'
15 | abstract: >-
16 | FMI4cpp is a modern C++ library that provides support for
17 | the Functional Mock-up Interface (FMI) 2.0 standard. It
18 | enables the integration and simulation of Functional
19 | Mock-up Units (FMUs) within C++ applications, facilitating
20 | model exchange and co-simulation.
21 | keywords:
22 | - FMI
23 | - FMU
24 | - C++
25 | - Simulation
26 | - Co-simulation
27 | - Model Exchange
28 | - Functional Mock-up Interface
29 | license: MIT
30 | commit: 1c6f77b
31 | version: 0.8.3
32 | date-released: '2022-06-29'
33 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 | file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" projectVersion)
3 | project(fmi4cpp VERSION ${projectVersion})
4 | message("Current fmi4cpp version: ${projectVersion}\n")
5 |
6 |
7 | # ==============================================================================
8 | # Build settings
9 | # ==============================================================================
10 |
11 | option(FMI4CPP_BUILD_TESTS "Build tests" OFF)
12 | option(FMI4CPP_BUILD_EXAMPLES "Build examples" OFF)
13 | option(BUILD_SHARED_LIBS "Build shared libraries instead of static libraries" ON)
14 |
15 | set(FMI4CPP_LOG_LEVEL "DEFAULT" CACHE STRING "FMI4cpp logging level")
16 | set(FMI4CPP_LOG_LEVEL_VALUES "DEFAULT;OFF;TRACE;DEBUG;INFO;WARN;ERROR;FATAL" CACHE STRING "List of possible log levels")
17 | set_property(CACHE FMI4CPP_LOG_LEVEL PROPERTY STRINGS ${FMI4CPP_LOG_LEVEL_VALUES})
18 |
19 |
20 | # ==============================================================================
21 | # Global internal configuration
22 | # ==============================================================================
23 |
24 | set(CMAKE_CXX_STANDARD 17)
25 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
26 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
27 |
28 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
29 |
30 | if (NOT CMAKE_BUILD_TYPE)
31 | set(CMAKE_BUILD_TYPE "Release")
32 | endif ()
33 |
34 | if (MSVC)
35 | set(CMAKE_DEBUG_POSTFIX "d")
36 | add_definitions("-D_CRT_SECURE_NO_WARNINGS")
37 | endif ()
38 |
39 | include(GNUInstallDirs)
40 |
41 | set(FMI4CPP_HEADER_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
42 | set(FMI4CPP_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
43 | set(FMI4CPP_DOC_INSTALL_DIR "${CMAKE_INSTALL_DOCDIR}")
44 |
45 | set(FMI4CPP_INSTALL_DESTINATIONS
46 | ARCHIVE DESTINATION "lib"
47 | LIBRARY DESTINATION "lib"
48 | RUNTIME DESTINATION "bin"
49 | INCLUDES DESTINATION "${FMI4CPP_HEADER_INSTALL_DIR}")
50 | set(FMI4CPP_EXPORT_TARGET "${PROJECT_NAME}-targets")
51 |
52 |
53 | # ==============================================================================
54 | # Dependencies
55 | # ==============================================================================
56 |
57 | find_package(LIBZIP REQUIRED)
58 | find_package(PugiXML REQUIRED)
59 |
60 | if (FMI4CPP_BUILD_TESTS)
61 |
62 | Include(FetchContent)
63 | FetchContent_Declare(
64 | Catch2
65 | GIT_REPOSITORY https://github.com/catchorg/Catch2.git
66 | GIT_TAG v2.13.8
67 | )
68 |
69 | FetchContent_MakeAvailable(Catch2)
70 | endif()
71 |
72 |
73 | # ==============================================================================
74 | # Targets
75 | # ==============================================================================
76 |
77 | add_subdirectory(src)
78 |
79 | if (FMI4CPP_BUILD_TESTS)
80 | enable_testing()
81 | add_subdirectory(tests)
82 | endif ()
83 |
84 | if (FMI4CPP_BUILD_EXAMPLES)
85 | add_subdirectory(examples)
86 | endif ()
87 |
88 | if (FMI4CPP_BUILD_TESTS OR FMI4CPP_BUILD_EXAMPLES)
89 | file(COPY resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
90 | endif ()
91 |
92 |
93 | # ==============================================================================
94 | # Exports and remaining installation
95 | # ==============================================================================
96 |
97 | install(
98 | EXPORT "${FMI4CPP_EXPORT_TARGET}"
99 | DESTINATION "${FMI4CPP_CMAKE_INSTALL_DIR}"
100 | NAMESPACE "${PROJECT_NAME}::"
101 | )
102 |
103 | include(CMakePackageConfigHelpers)
104 |
105 | # Generate and install package-config file.
106 | set(configFile "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake")
107 | set(targetsFile "${FMI4CPP_CMAKE_INSTALL_DIR}/${FMI4CPP_EXPORT_TARGET}.cmake")
108 | configure_package_config_file(
109 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
110 | "${configFile}"
111 | INSTALL_DESTINATION "${FMI4CPP_CMAKE_INSTALL_DIR}"
112 | PATH_VARS targetsFile
113 | )
114 | install(FILES "${configFile}" DESTINATION "${FMI4CPP_CMAKE_INSTALL_DIR}")
115 |
116 | # Generate and install package-version file
117 | set(versionFile "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake")
118 | write_basic_package_version_file(
119 | "${versionFile}"
120 | VERSION "${PROJECT_VERSION}"
121 | COMPATIBILITY "SameMajorVersion")
122 | install(FILES "${versionFile}" DESTINATION "${FMI4CPP_CMAKE_INSTALL_DIR}")
123 |
124 |
125 | # Install custom find modules
126 | install(FILES
127 | ${PROJECT_SOURCE_DIR}/cmake/FindLIBZIP.cmake
128 | ${PROJECT_SOURCE_DIR}/cmake/FindPugiXML.cmake
129 | DESTINATION
130 | ${FMI4CPP_CMAKE_INSTALL_DIR}
131 | )
132 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018-2021 Norwegian University of Science and Technology
4 | Copyright (c) 2018-2021 fmi4cpp authors
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FMI4cpp (work in progress)
2 |
3 | [](https://opensource.org/licenses/MIT)
4 | [](https://github.com/NTNU-IHB/FMU-proxy/issues)
5 | [](https://gitter.im/NTNU-IHB/FMI4cpp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6 |
7 | [](https://github.com/NTNU-IHB/FMI4cpp/actions)
8 |
9 | FMI4cpp is a cross-platform [FMI](https://fmi-standard.org/) 2.0 implementation written in modern C++.
10 |
11 | Influenced by its spiritual brother [FMI4j](https://github.com/NTNU-IHB/FMI4j), it aims to be
12 | an easy to install, easy to use, object-oriented and fast FMI implementation for C++.
13 |
14 | FMI4cpp supports both **Co-simulation** and **Model Exchange**.
15 |
16 |
17 | ## Build instructions
18 |
19 | Refer to [BUILDING.md](BUILDING.md)
20 |
21 | #### API
22 |
23 | ```cpp
24 | #include
25 | #include
26 |
27 | using namespace fmi4cpp;
28 |
29 | const double stop = ...;
30 | const double stepSize = ...;
31 |
32 | int main()
33 | {
34 | fmi2::fmu fmu("path/to/fmu.fmu");
35 |
36 | auto cs_fmu = fmu.as_cs_fmu();
37 | auto me_fmu = fmu.as_me_fmu();
38 |
39 | auto cs_md = cs_fmu->get_model_description(); //smart pointer to a cs_model_description instance
40 | std::cout << "model_identifier=" << cs_md->model_identifier << std::endl;
41 |
42 | auto me_md = me_fmu->get_model_description(); //smart pointer to a me_model_description instance
43 | std::cout << "model_identifier=" << me_md->model_identifier << std::endl;
44 |
45 | auto var = cs_md->get_variable_by_name("my_var").as_real();
46 | std::cout << "Name=" << var.name() << ", start=" << var.start().value_or(0) << std::endl;
47 |
48 | auto slave = cs_fmu->new_instance();
49 |
50 | slave->setup_experiment();
51 | slave->enter_initialization_mode();
52 | slave->exit_initialization_mode();
53 |
54 | double t;
55 | double value;
56 | auto vr = var.valueReference();
57 | while ( (t = slave->get_simulation_time()) <= stop) {
58 |
59 | if (!slave->step(stepSize)) {
60 | std::cerr << "Error! step() returned with status: " << to_string(slave->last_status()) << std::endl;
61 | break;
62 | }
63 |
64 | if (!slave->read_real(vr, value)) {
65 | std::cerr << "Error! step() returned with status: " << to_string(slave->last_status()) << std::endl;
66 | break;
67 | }
68 | std::cout << "t=" << t << ", " << var.name() << "=" << value << std::endl;
69 |
70 | }
71 |
72 | slave->terminate();
73 |
74 | return 0;
75 | }
76 | ```
77 |
78 | ***
79 |
80 | Would you rather simulate FMUs in Java? Check out [FMI4j](https://github.com/NTNU-IHB/FMI4j)!
81 | Would you like to build JVM based FMUs? Check out [FMU4j](https://github.com/https://github.com/Vico-platform/FMU4j)!
82 | Perhaps you want to build FMUs using plain Python? Check out [PythonFMU](https://github.com/NTNU-IHB/PythonFMU)!
83 | Need to distribute your FMUs? [FMU-proxy](https://github.com/NTNU-IHB/FMU-proxy) to the rescue!
84 |
85 |
--------------------------------------------------------------------------------
/cmake/FindLIBZIP.cmake:
--------------------------------------------------------------------------------
1 |
2 | # - CMake script for locating libzip
3 | #
4 | # If the script succeeds, it will create an IMPORTED target named
5 | # "libzip::libzip", plus set the following variables:
6 | #
7 | # LIBZIP_FOUND - If the library was found
8 | # LIBZIP_INCLUDE_DIRS - The directory that contains the header files.
9 | # LIBZIP_LIBRARIES - Contains "libzip::libzip"
10 | # LIBZIP_LIBRARY - Path to static/import library file.
11 | #
12 |
13 | find_package(BZip2 QUIET) # optional package - used when building using conan
14 | find_package(OpenSSL COMPONENTS Crypto SSL QUIET) # optional package - used when building using conan on linux
15 | find_package(ZLIB QUIET) # optional package - used when building using conan
16 | find_package(LibLZMA QUIET) # optional package - used when building using conan
17 |
18 | # Find static library, and use its path prefix to provide a HINTS option to the
19 | # other find_*() commands.
20 | find_library (LIBZIP_LIBRARY "zip"
21 | PATHS ${LIBZIP_DIR} $ENV{LIBZIP_DIR}
22 | PATH_SUFFIXES "lib")
23 | mark_as_advanced (LIBZIP_LIBRARY)
24 | unset (_LIBZIP_hints)
25 | if (LIBZIP_LIBRARY)
26 | get_filename_component (_LIBZIP_prefix "${LIBZIP_LIBRARY}" PATH)
27 | get_filename_component (_LIBZIP_prefix "${_LIBZIP_prefix}" PATH)
28 | set (_LIBZIP_hints "HINTS" "${_LIBZIP_prefix}")
29 | unset (_LIBZIP_prefix)
30 | endif ()
31 |
32 | # Find header files and, on Windows, the DLL
33 | find_path (LIBZIP_INCLUDE_DIR_zip "zip.h"
34 | ${_LIBZIP_hints}
35 | PATHS ${LIBZIP_DIR} $ENV{LIBZIP_DIR}
36 | PATH_SUFFIXES "include")
37 | find_path (LIBZIP_INCLUDE_DIR_zipconf "zipconf.h"
38 | ${_LIBZIP_hints}
39 | PATHS ${LIBZIP_DIR} $ENV{LIBZIP_DIR}
40 | PATH_SUFFIXES "include" "lib/libzip/include")
41 | set (LIBZIP_INCLUDE_DIRS
42 | "${LIBZIP_INCLUDE_DIR_zip}" "${LIBZIP_INCLUDE_DIR_zipconf}"
43 | )
44 |
45 | mark_as_advanced (LIBZIP_INCLUDE_DIRS)
46 |
47 | if (WIN32)
48 | find_file (LIBZIP_DLL NAMES "zip.dll" "libzip.dll"
49 | ${_LIBZIP_hints}
50 | PATHS ${LIBZIP_DIR} $ENV{LIBZIP_DIR}
51 | PATH_SUFFIXES "bin" "lib"
52 | NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
53 | mark_as_advanced (LIBZIP_DLL)
54 | endif ()
55 | unset (_LIBZIP_hints)
56 |
57 | # Create the IMPORTED targets.
58 | if (LIBZIP_LIBRARY)
59 | add_library ("libzip::libzip" SHARED IMPORTED)
60 | set_target_properties ("libzip::libzip" PROPERTIES
61 | IMPORTED_LINK_INTERFACE_LANGUAGES "C"
62 | IMPORTED_LOCATION "${LIBZIP_LIBRARY}"
63 | INTERFACE_COMPILE_DEFINITIONS "LIBZIP_STATIC_LIB_ONLY"
64 | INTERFACE_INCLUDE_DIRECTORIES "${LIBZIP_INCLUDE_DIRS}")
65 | if (WIN32)
66 | set_target_properties ("libzip::libzip" PROPERTIES
67 | IMPORTED_IMPLIB "${LIBZIP_LIBRARY}"
68 | IMPORTED_LOCATION "${LIBZIP_DLL}")
69 | else () # not WIN32
70 | set_target_properties ("libzip::libzip" PROPERTIES
71 | IMPORTED_LOCATION "${LIBZIP_LIBRARY}")
72 | endif ()
73 |
74 | set (LIBZIP_LIBRARIES "libzip::libzip")
75 |
76 | ##### required by conan when linking libzip statically ####
77 | set(LIBZIP_interfaceLinkLibraries)
78 | if (ZLIB_FOUND)
79 | list(APPEND LIBZIP_interfaceLinkLibraries ZLIB::ZLIB)
80 | endif()
81 | if (LIBLZMA_FOUND)
82 | list(APPEND LIBZIP_interfaceLinkLibraries LibLZMA::LibLZMA)
83 | endif()
84 | if (BZip2_FOUND)
85 | list(APPEND LIBZIP_interfaceLinkLibraries BZip2::BZip2)
86 | endif()
87 | if (OpenSSL_FOUND)
88 | list(APPEND LIBZIP_interfaceLinkLibraries OpenSSL::SSL OpenSSL::Crypto)
89 | endif()
90 | if (BZip2_FOUND OR OpenSSL_FOUND)
91 | set_property(TARGET libzip::libzip
92 | APPEND
93 | PROPERTY INTERFACE_LINK_LIBRARIES
94 | ${LIBZIP_interfaceLinkLibraries})
95 | endif()
96 | ###############################################################
97 | endif ()
98 |
99 | # Debug print-out.
100 | if (LIBZIP_PRINT_VARS)
101 | message ("LIBZIP find script variables:")
102 | message (" LIBZIP_INCLUDE_DIRS = ${LIBZIP_INCLUDE_DIRS}")
103 | message (" LIBZIP_LIBRARIES = ${LIBZIP_LIBRARIES}")
104 | message (" LIBZIP_DLL = ${LIBZIP_DLL}")
105 | message (" LIBZIP_LIBRARY = ${LIBZIP_LIBRARY}")
106 | endif ()
107 |
108 | # Standard find_package stuff.
109 | include (FindPackageHandleStandardArgs)
110 | find_package_handle_standard_args (LIBZIP DEFAULT_MSG LIBZIP_LIBRARIES LIBZIP_INCLUDE_DIRS)
--------------------------------------------------------------------------------
/cmake/FindPugiXML.cmake:
--------------------------------------------------------------------------------
1 | # Find the pugixml XML parsing library.
2 | #
3 | # Sets the usual variables expected for find_package scripts:
4 | #
5 | # PUGIXML_INCLUDE_DIR - header location
6 | # PUGIXML_LIBRARIES - library to link against
7 | # PUGIXML_FOUND - true if pugixml was found.
8 | find_path(PUGIXML_INCLUDE_DIR NAMES pugixml.hpp PATHS ${PUGIXML_HOME}/include)
9 | find_library(PUGIXML_LIBRARY NAMES pugixml PATHS ${PUGIXML_HOME}/lib)
10 |
11 | # Support the REQUIRED and QUIET arguments, and set PUGIXML_FOUND if found.
12 | include(FindPackageHandleStandardArgs)
13 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(PugiXML DEFAULT_MSG PUGIXML_LIBRARY
14 | PUGIXML_INCLUDE_DIR)
15 |
16 | if (PUGIXML_FOUND)
17 | set(PUGIXML_LIBRARIES ${PUGIXML_LIBRARY})
18 | message(STATUS "PugiXML include = ${PUGIXML_INCLUDE_DIR}")
19 | message(STATUS "PugiXML library = ${PUGIXML_LIBRARY}")
20 | else ()
21 | message(STATUS "No PugiXML found")
22 | endif ()
23 |
24 | if (PUGIXML_FOUND AND NOT TARGET pugixml::pugixml)
25 | add_library(pugixml::pugixml INTERFACE IMPORTED)
26 | target_include_directories(pugixml::pugixml INTERFACE "${PUGIXML_INCLUDE_DIR}")
27 | target_link_libraries(pugixml::pugixml INTERFACE "${PUGIXML_LIBRARY}")
28 | endif ()
29 |
30 | mark_as_advanced(PUGIXML_LIBRARY PUGIXML_INCLUDE_DIR)
31 |
--------------------------------------------------------------------------------
/cmake/fmi4cpp-config.cmake.in:
--------------------------------------------------------------------------------
1 | @PACKAGE_INIT@
2 | include ("@PACKAGE_targetsFile@")
3 |
4 | get_filename_component(FMI4CPP_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
5 | include(CMakeFindDependencyMacro)
6 |
7 | list(APPEND CMAKE_MODULE_PATH ${FMI4CPP_CMAKE_DIR})
8 |
9 | find_dependency(LIBZIP REQUIRED)
10 | find_dependency(PugiXML REQUIRED)
11 |
12 | list(REMOVE_AT CMAKE_MODULE_PATH -1)
13 |
--------------------------------------------------------------------------------
/examples/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | link_libraries(fmi4cpp::fmi4cpp)
3 | include_directories(${fmi4cpp_SOURCE_DIR}/src/fmi4cpp/tools)
4 |
5 | add_executable(fmu_test fmu_test.cpp)
6 | add_executable(torsionbar torsionbar.cpp)
7 | add_executable(multiple_fmus multiple_fmus.cpp)
8 | add_executable(controlled_temperature controlled_temperature.cpp)
9 |
--------------------------------------------------------------------------------
/examples/controlled_temperature.cpp:
--------------------------------------------------------------------------------
1 | #include "time_util.hpp"
2 |
3 | #include
4 |
5 | #include
6 |
7 | using namespace fmi4cpp;
8 |
9 | const double stop = 10.0;
10 | const double step_size = 1E-4;
11 |
12 | void run(std::unique_ptr& slave)
13 | {
14 | slave->setup_experiment();
15 | slave->enter_initialization_mode();
16 | slave->exit_initialization_mode();
17 |
18 | auto elapsed = measure_time_sec([&slave] {
19 | double ref;
20 | const auto vr = slave->get_model_description()->get_variable_by_name("Temperature_Room").as_real().valueReference();
21 | while ((slave->get_simulation_time()) <= (stop - step_size)) {
22 | if (!slave->step(step_size)) {
23 | std::cerr << "Error! step returned with status: " << to_string(slave->last_status()) << std::endl;
24 | break;
25 | }
26 | if (!slave->read_real(vr, ref)) {
27 | std::cerr << "Error! read_real returned with status: " << to_string(slave->last_status()) << std::endl;
28 | break;
29 | }
30 | }
31 | });
32 |
33 | std::cout << "Time elapsed=" << elapsed << "s" << std::endl;
34 |
35 | slave->terminate();
36 | }
37 |
38 | int main()
39 | {
40 | const std::string fmu_path = "../resources/fmus/2.0/cs/20sim/4.6.4.8004/"
41 | "ControlledTemperature/ControlledTemperature.fmu";
42 |
43 | auto fmu = fmi2::fmu(fmu_path).as_cs_fmu()->new_instance();
44 | run(fmu);
45 |
46 | return 0;
47 | }
--------------------------------------------------------------------------------
/examples/fmu_test.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 |
6 | using namespace fmi4cpp;
7 |
8 | const double stop = 0.01;
9 | const double stepSize = 1E-3;
10 |
11 | int main()
12 | {
13 | const std::string fmuPath = "../resources/fmus/2.0/cs/20sim/4.6.4.8004/"
14 | "ControlledTemperature/ControlledTemperature.fmu";
15 |
16 | fmi2::fmu fmu(fmuPath);
17 | auto cs_fmu = fmu.as_cs_fmu();
18 | auto md = cs_fmu->get_model_description();
19 |
20 | auto var = md->model_variables->getByValueReference(47).as_real();
21 | std::cout << "Name=" << var.name() << ", start=" << var.start().value_or(0) << std::endl;
22 |
23 | auto slave1 = cs_fmu->new_instance();
24 | auto slave2 = cs_fmu->new_instance();
25 |
26 | std::cout << "model_identifier=" << slave1->get_model_description()->model_identifier << std::endl;
27 |
28 | slave1->setup_experiment();
29 | slave1->enter_initialization_mode();
30 | slave1->exit_initialization_mode();
31 |
32 | slave2->setup_experiment();
33 | slave2->enter_initialization_mode();
34 | slave2->exit_initialization_mode();
35 |
36 | std::vector ref(2);
37 | std::vector vr = {md->get_variable_by_name("Temperature_Reference").value_reference,
38 | md->get_variable_by_name("Temperature_Room").value_reference};
39 |
40 | double t;
41 | while ((t = slave1->get_simulation_time()) <= stop) {
42 |
43 | if (!slave1->step(stepSize)) { break; }
44 | if (!slave1->read_real(vr, ref)) { break; }
45 | std::cout << "t=" << t << ", Temperature_Reference=" << ref[0] << ", Temperature_Room=" << ref[1] << std::endl;
46 | }
47 |
48 | std::cout << "FMU '" << fmu.model_name() << "' terminated with success: " << std::boolalpha << slave1->terminate() << std::endl;
49 | std::cout << "FMU '" << fmu.model_name() << "' terminated with success: " << std::boolalpha << slave2->terminate() << std::endl;
50 |
51 | return 0;
52 | }
--------------------------------------------------------------------------------
/examples/multiple_fmus.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 |
6 | using namespace fmi4cpp;
7 |
8 | int main()
9 | {
10 | const std::string fmu_path1 = "../resources/fmus/2.0/cs/20sim/4.6.4.8004/"
11 | "TorsionBar/TorsionBar.fmu";
12 |
13 | const std::string fmu_path2 = "../resources/fmus/2.0/cs/20sim/4.6.4.8004/"
14 | "ControlledTemperature/ControlledTemperature.fmu";
15 |
16 | fmi2::fmu fmu1(fmu_path1);
17 | fmi2::fmu fmu2(fmu_path2);
18 |
19 | const auto slave1 = fmu1.as_cs_fmu()->new_instance();
20 | const auto md1 = slave1->get_model_description();
21 |
22 | slave1->setup_experiment();
23 | slave1->enter_initialization_mode();
24 | slave1->exit_initialization_mode();
25 |
26 | const auto slave2 = fmu2.as_cs_fmu()->new_instance();
27 | const auto md2 = slave2->get_model_description();
28 | slave2->setup_experiment();
29 | slave2->enter_initialization_mode();
30 | slave2->exit_initialization_mode();
31 |
32 | slave1->step(1E-5);
33 | slave2->step(1E-4);
34 |
35 | double ref;
36 | {
37 | auto vr = md1->get_variable_by_name("MotorDiskRev").value_reference;
38 | assert(vr == 105);
39 | slave1->read_real(vr, ref);
40 | std::cout << "MotorDiskRev=" << ref << std::endl;
41 | }
42 |
43 | {
44 | auto vr = md2->get_value_reference("Temperature_Room");
45 | assert(vr == 47);
46 | slave2->read_real(vr, ref);
47 | std::cout << "Temperature_Room=" << ref << std::endl;
48 | }
49 |
50 | slave1->terminate();
51 | slave2->terminate();
52 |
53 | return 0;
54 | }
--------------------------------------------------------------------------------
/examples/time_util.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_TIME_UTIL_HPP
3 | #define FMI4CPP_TIME_UTIL_HPP
4 |
5 | #include
6 |
7 | namespace
8 | {
9 |
10 | template
11 | inline float measure_time_sec(function&& fun)
12 | {
13 | auto t_start = std::chrono::high_resolution_clock::now();
14 | fun();
15 | auto t_stop = std::chrono::high_resolution_clock::now();
16 | return std::chrono::duration(t_stop - t_start).count();
17 | }
18 |
19 | } // namespace
20 |
21 | #endif //FMI4CPP_TIME_UTIL_HPP
22 |
--------------------------------------------------------------------------------
/examples/torsionbar.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include "time_util.hpp"
5 |
6 | using namespace fmi4cpp;
7 |
8 | const double stop = 12.0;
9 | const double step_size = 1E-5;
10 | const fmi2ValueReference vr = 2;
11 |
12 | int main()
13 | {
14 | const std::string fmu_path = "../resources/fmus/2.0/cs/20sim/4.6.4.8004/"
15 | "TorsionBar/TorsionBar.fmu";
16 |
17 | fmi2::fmu fmu(fmu_path);
18 |
19 | const auto slave = fmu.as_cs_fmu()->new_instance();
20 | slave->setup_experiment();
21 | slave->enter_initialization_mode();
22 | slave->exit_initialization_mode();
23 |
24 | auto elapsed = measure_time_sec([&slave] {
25 | double ref;
26 | while ((slave->get_simulation_time()) <= (stop - step_size)) {
27 | if (!slave->step(step_size)) {
28 | std::cerr << "Error! step returned with status: " << to_string(slave->last_status()) << std::endl;
29 | break;
30 | }
31 | if (!slave->read_real(vr, ref)) {
32 | std::cerr << "Error! read_real returned with status: " << to_string(slave->last_status()) << std::endl;
33 | break;
34 | }
35 | }
36 | });
37 |
38 | std::cout << "Time elapsed=" << elapsed << "s" << std::endl;
39 |
40 | slave->terminate();
41 |
42 | return 0;
43 | }
--------------------------------------------------------------------------------
/include/fmi4cpp/dll_handle.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_DLL_HANDLE_HPP
3 | #define FMI4CPP_DLL_HANDLE_HPP
4 |
5 | #if defined(_MSC_VER) || defined(WIN32) || defined(__MINGW32__)
6 | # define WIN32_LEAN_AND_MEAN
7 | # include
8 | # define DLL_HANDLE HMODULE
9 | #else
10 | # define DLL_HANDLE void*
11 | # include
12 | #endif
13 |
14 | #ifdef WIN32
15 | # define function_ptr FARPROC
16 | #else
17 | typedef void* function_ptr;
18 | #endif
19 |
20 | #endif //FMI4CPP_DLL_HANDLE_HPP
21 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/cs_fmu.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_FMI2COSIMULATIONFMU_H
3 | #define FMI4CPP_FMI2COSIMULATIONFMU_H
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 |
12 | namespace fmi4cpp::fmi2
13 | {
14 |
15 | class cs_fmu : public cs_fmu_base
16 | {
17 |
18 | private:
19 | std::shared_ptr lib_;
20 | std::shared_ptr resource_;
21 | std::shared_ptr modelDescription_;
22 |
23 | public:
24 | cs_fmu(std::shared_ptr resource,
25 | std::shared_ptr md);
26 |
27 | [[nodiscard]] std::string get_model_description_xml() const;
28 |
29 | [[nodiscard]] std::shared_ptr get_model_description() const override;
30 |
31 | std::unique_ptr new_instance(bool visible = false, bool loggingOn = false) override;
32 | };
33 |
34 | } // namespace fmi4cpp::fmi2
35 |
36 | #endif //FMI4CPP_FMI2COSIMULATIONFMU_H
37 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/cs_library.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_FMI2COSIMULATIONLIBRARY_HPP
3 | #define FMI4CPP_FMI2COSIMULATIONLIBRARY_HPP
4 |
5 | #include
6 |
7 | namespace fmi4cpp::fmi2
8 | {
9 |
10 | class cs_library : public fmi2_library
11 | {
12 |
13 | private:
14 | fmi2SetRealInputDerivativesTYPE* fmi2SetRealInputDerivatives_;
15 | fmi2GetRealOutputDerivativesTYPE* fmi2GetRealOutputDerivatives_;
16 |
17 | fmi2DoStepTYPE* fmi2DoStep_;
18 | fmi2CancelStepTYPE* fmi2CancelStep_;
19 |
20 | fmi2GetStatusTYPE* fmi2GetStatus_;
21 | fmi2GetRealStatusTYPE* fmi2GetRealStatus_;
22 | fmi2GetIntegerStatusTYPE* fmi2GetIntegerStatus_;
23 | fmi2GetBooleanStatusTYPE* fmi2GetBooleanStatus_;
24 | fmi2GetStringStatusTYPE* fmi2GetStringStatus_;
25 |
26 | public:
27 | cs_library(
28 | const std::string& modelIdentifier,
29 | const std::shared_ptr& resource);
30 |
31 | bool step(fmi2Component c, fmi2Real currentCommunicationPoint,
32 | fmi2Real communicationStepSize, bool noSetFMUStatePriorToCurrentPoint);
33 |
34 | bool cancel_step(fmi2Component c);
35 |
36 | bool set_real_input_derivatives(fmi2Component c,
37 | const std::vector& vr,
38 | const std::vector& order,
39 | const std::vector& value);
40 |
41 | bool get_real_output_derivatives(fmi2Component c,
42 | const std::vector& vr,
43 | const std::vector& order,
44 | std::vector& value);
45 |
46 | bool get_status(fmi2Component c, fmi2StatusKind s, fmi2Status& value);
47 | bool get_real_status(fmi2Component c, fmi2StatusKind s, fmi2Real& value);
48 | bool get_integer_status(fmi2Component c, fmi2StatusKind s, fmi2Integer& value);
49 | bool get_boolean_status(fmi2Component c, fmi2StatusKind s, fmi2Boolean& value);
50 | bool get_string_status(fmi2Component c, fmi2StatusKind s, fmi2String& value);
51 | };
52 |
53 | } // namespace fmi4cpp::fmi2
54 |
55 | #endif //FMI4CPP_FMI2COSIMULATIONLIBRARY_HPP
56 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/cs_slave.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_FMI2_CS_SLAVE_HPP
3 | #define FMI4CPP_FMI2_CS_SLAVE_HPP
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include
13 |
14 |
15 | namespace fmi4cpp::fmi2
16 | {
17 |
18 | class cs_slave : public virtual fmu_slave,
19 | public fmu_instance_base
20 | {
21 |
22 | public:
23 | cs_slave(fmi2Component c,
24 | const std::shared_ptr& resource,
25 | const std::shared_ptr& library,
26 | const std::shared_ptr& modelDescription);
27 |
28 | bool step(double stepSize) override;
29 | bool cancel_step() override;
30 |
31 | [[nodiscard]] std::shared_ptr get_model_description() const override;
32 |
33 | [[nodiscard]] DLL_HANDLE handle() const override;
34 | [[nodiscard]] status last_status() const override;
35 |
36 | bool setup_experiment(double start = 0, double stop = 0, double tolerance = 0) override;
37 | bool enter_initialization_mode() override;
38 | bool exit_initialization_mode() override;
39 |
40 | bool reset() override;
41 | bool terminate() override;
42 |
43 | bool read_integer(fmi2ValueReference vr, fmi2Integer& ref) override;
44 | bool read_integer(const std::vector& vr, std::vector& ref) override;
45 |
46 | bool read_real(fmi2ValueReference vr, fmi2Real& ref) override;
47 | bool read_real(const std::vector& vr, std::vector& ref) override;
48 |
49 | bool read_string(fmi2ValueReference vr, fmi2String& ref) override;
50 | bool read_string(const std::vector& vr, std::vector& ref) override;
51 |
52 | bool read_boolean(fmi2ValueReference vr, fmi2Boolean& ref) override;
53 | bool read_boolean(const std::vector& vr, std::vector& ref) override;
54 |
55 | bool write_integer(fmi2ValueReference vr, fmi2Integer value) override;
56 | bool write_integer(const std::vector& vr, const std::vector& values) override;
57 |
58 | bool write_real(fmi2ValueReference vr, fmi2Real value) override;
59 | bool write_real(const std::vector& vr, const std::vector& values) override;
60 |
61 | bool write_string(fmi2ValueReference vr, fmi2String value) override;
62 | bool write_string(const std::vector& vr, const std::vector& values) override;
63 |
64 | bool write_boolean(fmi2ValueReference vr, fmi2Boolean value) override;
65 | bool write_boolean(const std::vector& vr, const std::vector& values) override;
66 |
67 |
68 | bool get_fmu_state(fmi2FMUstate& state) override;
69 | bool set_fmu_state(fmi2FMUstate state) override;
70 | bool free_fmu_state(fmi2FMUstate& state) override;
71 |
72 | bool serialize_fmu_state(const fmi2FMUstate& state, std::vector& serializedState) override;
73 | bool de_serialize_fmu_state(fmi2FMUstate& state, const std::vector& serializedState) override;
74 |
75 | bool get_directional_derivative(const std::vector& vUnknownRef,
76 | const std::vector& vKnownRef,
77 | const std::vector& dvKnownRef,
78 | std::vector& dvUnknownRef) override;
79 | };
80 |
81 | } // namespace fmi4cpp::fmi2
82 |
83 |
84 | #endif //FMI4CPP_FMI2_CS_SLAVE_HPP
85 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/fmi2.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_FMI2_HPP
3 | #define FMI4CPP_FMI2_HPP
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 |
15 | #endif //FMI4CPP_FMI2_HPP
16 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/fmi2FunctionTypes.h:
--------------------------------------------------------------------------------
1 | #ifndef fmi2FunctionTypes_h
2 | #define fmi2FunctionTypes_h
3 |
4 | #include "fmi2TypesPlatform.h"
5 |
6 | /* This header file must be utilized when compiling an FMU or an FMI master.
7 | It declares data and function types for FMI 2.0
8 |
9 | Revisions:
10 | - Apr. 9, 2014: all prefixes "fmi" renamed to "fmi2" (decision from April 8)
11 | - Apr. 3, 2014: Added #include for size_t definition
12 | - Mar. 27, 2014: Added #include "fmiTypesPlatform.h" (#179)
13 | - Mar. 26, 2014: Introduced function argument "void" for the functions (#171)
14 | fmiGetTypesPlatformTYPE and fmiGetVersionTYPE
15 | - Oct. 11, 2013: Functions of ModelExchange and CoSimulation merged:
16 | fmiInstantiateModelTYPE , fmiInstantiateSlaveTYPE -> fmiInstantiateTYPE
17 | fmiFreeModelInstanceTYPE, fmiFreeSlaveInstanceTYPE -> fmiFreeInstanceTYPE
18 | fmiEnterModelInitializationModeTYPE, fmiEnterSlaveInitializationModeTYPE -> fmiEnterInitializationModeTYPE
19 | fmiExitModelInitializationModeTYPE , fmiExitSlaveInitializationModeTYPE -> fmiExitInitializationModeTYPE
20 | fmiTerminateModelTYPE , fmiTerminateSlaveTYPE -> fmiTerminate
21 | fmiResetSlave -> fmiReset (now also for ModelExchange and not only for CoSimulation)
22 | Functions renamed
23 | fmiUpdateDiscreteStatesTYPE -> fmiNewDiscreteStatesTYPE
24 | Renamed elements of the enumeration fmiEventInfo
25 | upcomingTimeEvent -> nextEventTimeDefined // due to generic naming scheme: varDefined + var
26 | newUpdateDiscreteStatesNeeded -> newDiscreteStatesNeeded;
27 | - June 13, 2013: Changed type fmiEventInfo
28 | Functions removed:
29 | fmiInitializeModelTYPE
30 | fmiEventUpdateTYPE
31 | fmiCompletedEventIterationTYPE
32 | fmiInitializeSlaveTYPE
33 | Functions added:
34 | fmiEnterModelInitializationModeTYPE
35 | fmiExitModelInitializationModeTYPE
36 | fmiEnterEventModeTYPE
37 | fmiUpdateDiscreteStatesTYPE
38 | fmiEnterContinuousTimeModeTYPE
39 | fmiEnterSlaveInitializationModeTYPE;
40 | fmiExitSlaveInitializationModeTYPE;
41 | - Feb. 17, 2013: Added third argument to fmiCompletedIntegratorStepTYPE
42 | Changed function name "fmiTerminateType" to "fmiTerminateModelType" (due to #113)
43 | Changed function name "fmiGetNominalContinuousStateTYPE" to
44 | "fmiGetNominalsOfContinuousStatesTYPE"
45 | Removed fmiGetStateValueReferencesTYPE.
46 | - Nov. 14, 2011: First public Version
47 |
48 |
49 | Copyright © 2011 MODELISAR consortium,
50 | 2012-2013 Modelica Association Project "FMI"
51 | All rights reserved.
52 | This file is licensed by the copyright holders under the BSD 2-Clause License
53 | (http://www.opensource.org/licenses/bsd-license.html):
54 |
55 | ----------------------------------------------------------------------------
56 | Redistribution and use in source and binary forms, with or without
57 | modification, are permitted provided that the following conditions are met:
58 |
59 | - Redistributions of source code must retain the above copyright notice,
60 | this list of conditions and the following disclaimer.
61 | - Redistributions in binary form must reproduce the above copyright notice,
62 | this list of conditions and the following disclaimer in the documentation
63 | and/or other materials provided with the distribution.
64 | - Neither the name of the copyright holders nor the names of its
65 | contributors may be used to endorse or promote products derived
66 | from this software without specific prior written permission.
67 |
68 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
69 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
70 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
71 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
72 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
73 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
74 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
75 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
76 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
77 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
78 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
79 | ----------------------------------------------------------------------------
80 |
81 | with the extension:
82 |
83 | You may distribute or publicly perform any modification only under the
84 | terms of this license.
85 | (Note, this means that if you distribute a modified file,
86 | the modified file must also be provided under this license).
87 | */
88 |
89 | #ifdef __cplusplus
90 | extern "C" {
91 | #endif
92 |
93 | /* make sure all compiler use the same alignment policies for structures */
94 | #if defined _MSC_VER || defined __GNUC__
95 | #pragma pack(push, 8)
96 | #endif
97 |
98 | /* Include stddef.h, in order that size_t etc. is defined */
99 | #include
100 |
101 |
102 | /* Type definitions */
103 | typedef enum {
104 | fmi2OK,
105 | fmi2Warning,
106 | fmi2Discard,
107 | fmi2Error,
108 | fmi2Fatal,
109 | fmi2Pending
110 | } fmi2Status;
111 |
112 | typedef enum {
113 | fmi2ModelExchange,
114 | fmi2CoSimulation
115 | } fmi2Type;
116 |
117 | typedef enum {
118 | fmi2DoStepStatus,
119 | fmi2PendingStatus,
120 | fmi2LastSuccessfulTime,
121 | fmi2Terminated
122 | } fmi2StatusKind;
123 |
124 | typedef void (*fmi2CallbackLogger)(fmi2ComponentEnvironment, fmi2String, fmi2Status, fmi2String, fmi2String, ...);
125 | typedef void *(*fmi2CallbackAllocateMemory)(size_t, size_t);
126 | typedef void (*fmi2CallbackFreeMemory)(void *);
127 | typedef void (*fmi2StepFinished)(fmi2ComponentEnvironment, fmi2Status);
128 |
129 | typedef struct {
130 | const fmi2CallbackLogger logger;
131 | const fmi2CallbackAllocateMemory allocateMemory;
132 | const fmi2CallbackFreeMemory freeMemory;
133 | const fmi2StepFinished stepFinished;
134 | const fmi2ComponentEnvironment componentEnvironment;
135 | } fmi2CallbackFunctions;
136 |
137 | typedef struct {
138 | fmi2Boolean newDiscreteStatesNeeded;
139 | fmi2Boolean terminateSimulation;
140 | fmi2Boolean nominalsOfContinuousStatesChanged;
141 | fmi2Boolean valuesOfContinuousStatesChanged;
142 | fmi2Boolean nextEventTimeDefined;
143 | fmi2Real nextEventTime;
144 | } fmi2EventInfo;
145 |
146 |
147 | /* reset alignment policy to the one set before reading this file */
148 | #if defined _MSC_VER || defined __GNUC__
149 | #pragma pack(pop)
150 | #endif
151 |
152 |
153 | /* Define fmi2 function pointer types to simplify dynamic loading */
154 |
155 | /***************************************************
156 | Types for Common Functions
157 | ****************************************************/
158 |
159 | /* Inquire version numbers of header files and setting logging status */
160 | typedef const char *fmi2GetTypesPlatformTYPE(void);
161 | typedef const char *fmi2GetVersionTYPE(void);
162 | typedef fmi2Status fmi2SetDebugLoggingTYPE(fmi2Component, fmi2Boolean, size_t, const fmi2String[]);
163 |
164 | /* Creation and destruction of FMU instances and setting debug status */
165 | typedef fmi2Component fmi2InstantiateTYPE(fmi2String, fmi2Type, fmi2String, fmi2String, const fmi2CallbackFunctions *,
166 | fmi2Boolean, fmi2Boolean);
167 | typedef void fmi2FreeInstanceTYPE(fmi2Component);
168 |
169 | /* Enter and exit initialization mode, terminate and reset */
170 | typedef fmi2Status fmi2SetupExperimentTYPE(fmi2Component, fmi2Boolean, fmi2Real, fmi2Real, fmi2Boolean, fmi2Real);
171 | typedef fmi2Status fmi2EnterInitializationModeTYPE(fmi2Component);
172 | typedef fmi2Status fmi2ExitInitializationModeTYPE(fmi2Component);
173 | typedef fmi2Status fmi2TerminateTYPE(fmi2Component);
174 | typedef fmi2Status fmi2ResetTYPE(fmi2Component);
175 |
176 | /* Getting and setting variable values */
177 | typedef fmi2Status fmi2GetRealTYPE(fmi2Component, const fmi2ValueReference[], size_t, fmi2Real []);
178 | typedef fmi2Status fmi2GetIntegerTYPE(fmi2Component, const fmi2ValueReference[], size_t, fmi2Integer[]);
179 | typedef fmi2Status fmi2GetBooleanTYPE(fmi2Component, const fmi2ValueReference[], size_t, fmi2Boolean[]);
180 | typedef fmi2Status fmi2GetStringTYPE(fmi2Component, const fmi2ValueReference[], size_t, fmi2String []);
181 |
182 | typedef fmi2Status fmi2SetRealTYPE(fmi2Component, const fmi2ValueReference[], size_t, const fmi2Real []);
183 | typedef fmi2Status fmi2SetIntegerTYPE(fmi2Component, const fmi2ValueReference[], size_t, const fmi2Integer[]);
184 | typedef fmi2Status fmi2SetBooleanTYPE(fmi2Component, const fmi2ValueReference[], size_t, const fmi2Boolean[]);
185 | typedef fmi2Status fmi2SetStringTYPE(fmi2Component, const fmi2ValueReference[], size_t, const fmi2String []);
186 |
187 | /* Getting and setting the internal FMU state */
188 | typedef fmi2Status fmi2GetFMUstateTYPE(fmi2Component, fmi2FMUstate *);
189 | typedef fmi2Status fmi2SetFMUstateTYPE(fmi2Component, fmi2FMUstate);
190 | typedef fmi2Status fmi2FreeFMUstateTYPE(fmi2Component, fmi2FMUstate *);
191 | typedef fmi2Status fmi2SerializedFMUstateSizeTYPE(fmi2Component, fmi2FMUstate, size_t *);
192 | typedef fmi2Status fmi2SerializeFMUstateTYPE(fmi2Component, fmi2FMUstate, fmi2Byte[], size_t);
193 | typedef fmi2Status fmi2DeSerializeFMUstateTYPE(fmi2Component, const fmi2Byte[], size_t, fmi2FMUstate *);
194 |
195 | /* Getting partial derivatives */
196 | typedef fmi2Status fmi2GetDirectionalDerivativeTYPE(fmi2Component, const fmi2ValueReference[], size_t,
197 | const fmi2ValueReference[], size_t,
198 | const fmi2Real[], fmi2Real[]);
199 |
200 | /***************************************************
201 | Types for Functions for FMI2 for Model Exchange
202 | ****************************************************/
203 |
204 | /* Enter and exit the different modes */
205 | typedef fmi2Status fmi2EnterEventModeTYPE(fmi2Component);
206 | typedef fmi2Status fmi2NewDiscreteStatesTYPE(fmi2Component, fmi2EventInfo *);
207 | typedef fmi2Status fmi2EnterContinuousTimeModeTYPE(fmi2Component);
208 | typedef fmi2Status fmi2CompletedIntegratorStepTYPE(fmi2Component, fmi2Boolean, fmi2Boolean *, fmi2Boolean *);
209 |
210 | /* Providing independent variables and re-initialization of caching */
211 | typedef fmi2Status fmi2SetTimeTYPE(fmi2Component, fmi2Real);
212 | typedef fmi2Status fmi2SetContinuousStatesTYPE(fmi2Component, const fmi2Real[], size_t);
213 |
214 | /* Evaluation of the model equations */
215 | typedef fmi2Status fmi2GetDerivativesTYPE(fmi2Component, fmi2Real[], size_t);
216 | typedef fmi2Status fmi2GetEventIndicatorsTYPE(fmi2Component, fmi2Real[], size_t);
217 | typedef fmi2Status fmi2GetContinuousStatesTYPE(fmi2Component, fmi2Real[], size_t);
218 | typedef fmi2Status fmi2GetNominalsOfContinuousStatesTYPE(fmi2Component, fmi2Real[], size_t);
219 |
220 |
221 | /***************************************************
222 | Types for Functions for FMI2 for Co-Simulation
223 | ****************************************************/
224 |
225 | /* Simulating the slave */
226 | typedef fmi2Status fmi2SetRealInputDerivativesTYPE(fmi2Component, const fmi2ValueReference [], size_t,
227 | const fmi2Integer [], const fmi2Real []);
228 | typedef fmi2Status fmi2GetRealOutputDerivativesTYPE(fmi2Component, const fmi2ValueReference [], size_t,
229 | const fmi2Integer [], fmi2Real []);
230 |
231 | typedef fmi2Status fmi2DoStepTYPE(fmi2Component, fmi2Real, fmi2Real, fmi2Boolean);
232 | typedef fmi2Status fmi2CancelStepTYPE(fmi2Component);
233 |
234 | /* Inquire slave status */
235 | typedef fmi2Status fmi2GetStatusTYPE(fmi2Component, const fmi2StatusKind, fmi2Status *);
236 | typedef fmi2Status fmi2GetRealStatusTYPE(fmi2Component, const fmi2StatusKind, fmi2Real *);
237 | typedef fmi2Status fmi2GetIntegerStatusTYPE(fmi2Component, const fmi2StatusKind, fmi2Integer *);
238 | typedef fmi2Status fmi2GetBooleanStatusTYPE(fmi2Component, const fmi2StatusKind, fmi2Boolean *);
239 | typedef fmi2Status fmi2GetStringStatusTYPE(fmi2Component, const fmi2StatusKind, fmi2String *);
240 |
241 |
242 | #ifdef __cplusplus
243 | } /* end of extern "C" { */
244 | #endif
245 |
246 | #endif /* fmi2FunctionTypes_h */
247 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/fmi2Functions.h:
--------------------------------------------------------------------------------
1 | #ifndef fmi2Functions_h
2 | #define fmi2Functions_h
3 |
4 | /* This header file must be utilized when compiling a FMU.
5 | It defines all functions of the
6 | FMI 2.0 Model Exchange and Co-Simulation Interface.
7 |
8 | In order to have unique function names even if several FMUs
9 | are compiled together (e.g. for embedded systems), every "real" function name
10 | is constructed by prepending the function name by "FMI2_FUNCTION_PREFIX".
11 | Therefore, the typical usage is:
12 |
13 | #define FMI2_FUNCTION_PREFIX MyModel_
14 | #include "fmi2Functions.h"
15 |
16 | As a result, a function that is defined as "fmi2GetDerivatives" in this header file,
17 | is actually getting the name "MyModel_fmi2GetDerivatives".
18 |
19 | This only holds if the FMU is shipped in C source code, or is compiled in a
20 | static link library. For FMUs compiled in a DLL/sharedObject, the "actual" function
21 | names are used and "FMI2_FUNCTION_PREFIX" must not be defined.
22 |
23 | Revisions:
24 | - Apr. 9, 2014: all prefixes "fmi" renamed to "fmi2" (decision from April 8)
25 | - Mar. 26, 2014: FMI_Export set to empty value if FMI_Export and FMI_FUNCTION_PREFIX
26 | are not defined (#173)
27 | - Oct. 11, 2013: Functions of ModelExchange and CoSimulation merged:
28 | fmiInstantiateModel , fmiInstantiateSlave -> fmiInstantiate
29 | fmiFreeModelInstance, fmiFreeSlaveInstance -> fmiFreeInstance
30 | fmiEnterModelInitializationMode, fmiEnterSlaveInitializationMode -> fmiEnterInitializationMode
31 | fmiExitModelInitializationMode , fmiExitSlaveInitializationMode -> fmiExitInitializationMode
32 | fmiTerminateModel, fmiTerminateSlave -> fmiTerminate
33 | fmiResetSlave -> fmiReset (now also for ModelExchange and not only for CoSimulation)
34 | Functions renamed:
35 | fmiUpdateDiscreteStates -> fmiNewDiscreteStates
36 | - June 13, 2013: Functions removed:
37 | fmiInitializeModel
38 | fmiEventUpdate
39 | fmiCompletedEventIteration
40 | fmiInitializeSlave
41 | Functions added:
42 | fmiEnterModelInitializationMode
43 | fmiExitModelInitializationMode
44 | fmiEnterEventMode
45 | fmiUpdateDiscreteStates
46 | fmiEnterContinuousTimeMode
47 | fmiEnterSlaveInitializationMode;
48 | fmiExitSlaveInitializationMode;
49 | - Feb. 17, 2013: Portability improvements:
50 | o DllExport changed to FMI_Export
51 | o FUNCTION_PREFIX changed to FMI_FUNCTION_PREFIX
52 | o Allow undefined FMI_FUNCTION_PREFIX (meaning no prefix is used)
53 | Changed function name "fmiTerminate" to "fmiTerminateModel" (due to #113)
54 | Changed function name "fmiGetNominalContinuousState" to
55 | "fmiGetNominalsOfContinuousStates"
56 | Removed fmiGetStateValueReferences.
57 | - Nov. 14, 2011: Adapted to FMI 2.0:
58 | o Split into two files (fmiFunctions.h, fmiTypes.h) in order
59 | that code that dynamically loads an FMU can directly
60 | utilize the header files).
61 | o Added C++ encapsulation of C-part, in order that the header
62 | file can be directly utilized in C++ code.
63 | o fmiCallbackFunctions is passed as pointer to fmiInstantiateXXX
64 | o stepFinished within fmiCallbackFunctions has as first
65 | argument "fmiComponentEnvironment" and not "fmiComponent".
66 | o New functions to get and set the complete FMU state
67 | and to compute partial derivatives.
68 | - Nov. 4, 2010: Adapted to specification text:
69 | o fmiGetModelTypesPlatform renamed to fmiGetTypesPlatform
70 | o fmiInstantiateSlave: Argument GUID replaced by fmuGUID
71 | Argument mimetype replaced by mimeType
72 | o tabs replaced by spaces
73 | - Oct. 16, 2010: Functions for FMI for Co-simulation added
74 | - Jan. 20, 2010: stateValueReferencesChanged added to struct fmiEventInfo (ticket #27)
75 | (by M. Otter, DLR)
76 | Added WIN32 pragma to define the struct layout (ticket #34)
77 | (by J. Mauss, QTronic)
78 | - Jan. 4, 2010: Removed argument intermediateResults from fmiInitialize
79 | Renamed macro fmiGetModelFunctionsVersion to fmiGetVersion
80 | Renamed macro fmiModelFunctionsVersion to fmiVersion
81 | Replaced fmiModel by fmiComponent in decl of fmiInstantiateModel
82 | (by J. Mauss, QTronic)
83 | - Dec. 17, 2009: Changed extension "me" to "fmi" (by Martin Otter, DLR).
84 | - Dez. 14, 2009: Added eventInfo to meInitialize and added
85 | meGetNominalContinuousStates (by Martin Otter, DLR)
86 | - Sept. 9, 2009: Added DllExport (according to Peter Nilsson's suggestion)
87 | (by A. Junghanns, QTronic)
88 | - Sept. 9, 2009: Changes according to FMI-meeting on July 21:
89 | meInquireModelTypesVersion -> meGetModelTypesPlatform
90 | meInquireModelFunctionsVersion -> meGetModelFunctionsVersion
91 | meSetStates -> meSetContinuousStates
92 | meGetStates -> meGetContinuousStates
93 | removal of meInitializeModelClass
94 | removal of meGetTime
95 | change of arguments of meInstantiateModel
96 | change of arguments of meCompletedIntegratorStep
97 | (by Martin Otter, DLR):
98 | - July 19, 2009: Added "me" as prefix to file names (by Martin Otter, DLR).
99 | - March 2, 2009: Changed function definitions according to the last design
100 | meeting with additional improvements (by Martin Otter, DLR).
101 | - Dec. 3 , 2008: First version by Martin Otter (DLR) and Hans Olsson (Dynasim).
102 |
103 | Copyright © 2008-2011 MODELISAR consortium,
104 | 2012-2013 Modelica Association Project "FMI"
105 | All rights reserved.
106 | This file is licensed by the copyright holders under the BSD 2-Clause License
107 | (http://www.opensource.org/licenses/bsd-license.html):
108 |
109 | ----------------------------------------------------------------------------
110 | Redistribution and use in source and binary forms, with or without
111 | modification, are permitted provided that the following conditions are met:
112 |
113 | - Redistributions of source code must retain the above copyright notice,
114 | this list of conditions and the following disclaimer.
115 | - Redistributions in binary form must reproduce the above copyright notice,
116 | this list of conditions and the following disclaimer in the documentation
117 | and/or other materials provided with the distribution.
118 | - Neither the name of the copyright holders nor the names of its
119 | contributors may be used to endorse or promote products derived
120 | from this software without specific prior written permission.
121 |
122 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
123 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
124 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
125 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
126 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
127 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
128 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
129 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
130 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
131 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
132 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
133 | ----------------------------------------------------------------------------
134 |
135 | with the extension:
136 |
137 | You may distribute or publicly perform any modification only under the
138 | terms of this license.
139 | (Note, this means that if you distribute a modified file,
140 | the modified file must also be provided under this license).
141 | */
142 |
143 | #ifdef __cplusplus
144 | extern "C" {
145 | #endif
146 |
147 | #include "fmi2TypesPlatform.h"
148 | #include "fmi2FunctionTypes.h"
149 | #include
150 |
151 |
152 | /*
153 | Export FMI2 API functions on Windows and under GCC.
154 | If custom linking is desired then the FMI2_Export must be
155 | defined before including this file. For instance,
156 | it may be set to __declspec(dllimport).
157 | */
158 | #if !defined(FMI2_Export)
159 | #if !defined(FMI2_FUNCTION_PREFIX)
160 | #if defined _WIN32 || defined __CYGWIN__
161 | /* Note: both gcc & MSVC on Windows support this syntax. */
162 | #define FMI2_Export __declspec(dllexport)
163 | #else
164 | #if __GNUC__ >= 4
165 | #define FMI2_Export __attribute__ ((visibility ("default")))
166 | #else
167 | #define FMI2_Export
168 | #endif
169 | #endif
170 | #else
171 | #define FMI2_Export
172 | #endif
173 | #endif
174 |
175 | /* Macros to construct the real function name
176 | (prepend function name by FMI2_FUNCTION_PREFIX) */
177 | #if defined(FMI2_FUNCTION_PREFIX)
178 | #define fmi2Paste(a,b) a ## b
179 | #define fmi2PasteB(a,b) fmi2Paste(a,b)
180 | #define fmi2FullName(name) fmi2PasteB(FMI2_FUNCTION_PREFIX, name)
181 | #else
182 | #define fmi2FullName(name) name
183 | #endif
184 |
185 | /***************************************************
186 | Common Functions
187 | ****************************************************/
188 | #define fmi2GetTypesPlatform fmi2FullName(fmi2GetTypesPlatform)
189 | #define fmi2GetVersion fmi2FullName(fmi2GetVersion)
190 | #define fmi2SetDebugLogging fmi2FullName(fmi2SetDebugLogging)
191 | #define fmi2Instantiate fmi2FullName(fmi2Instantiate)
192 | #define fmi2FreeInstance fmi2FullName(fmi2FreeInstance)
193 | #define fmi2SetupExperiment fmi2FullName(fmi2SetupExperiment)
194 | #define fmi2EnterInitializationMode fmi2FullName(fmi2EnterInitializationMode)
195 | #define fmi2ExitInitializationMode fmi2FullName(fmi2ExitInitializationMode)
196 | #define fmi2Terminate fmi2FullName(fmi2Terminate)
197 | #define fmi2Reset fmi2FullName(fmi2Reset)
198 | #define fmi2GetReal fmi2FullName(fmi2GetReal)
199 | #define fmi2GetInteger fmi2FullName(fmi2GetInteger)
200 | #define fmi2GetBoolean fmi2FullName(fmi2GetBoolean)
201 | #define fmi2GetString fmi2FullName(fmi2GetString)
202 | #define fmi2SetReal fmi2FullName(fmi2SetReal)
203 | #define fmi2SetInteger fmi2FullName(fmi2SetInteger)
204 | #define fmi2SetBoolean fmi2FullName(fmi2SetBoolean)
205 | #define fmi2SetString fmi2FullName(fmi2SetString)
206 | #define fmi2GetFMUstate fmi2FullName(fmi2GetFMUstate)
207 | #define fmi2SetFMUstate fmi2FullName(fmi2SetFMUstate)
208 | #define fmi2FreeFMUstate fmi2FullName(fmi2FreeFMUstate)
209 | #define fmi2SerializedFMUstateSize fmi2FullName(fmi2SerializedFMUstateSize)
210 | #define fmi2SerializeFMUstate fmi2FullName(fmi2SerializeFMUstate)
211 | #define fmi2DeSerializeFMUstate fmi2FullName(fmi2DeSerializeFMUstate)
212 | #define fmi2GetDirectionalDerivative fmi2FullName(fmi2GetDirectionalDerivative)
213 |
214 |
215 | /***************************************************
216 | Functions for FMI2 for Model Exchange
217 | ****************************************************/
218 | #define fmi2EnterEventMode fmi2FullName(fmi2EnterEventMode)
219 | #define fmi2NewDiscreteStates fmi2FullName(fmi2NewDiscreteStates)
220 | #define fmi2EnterContinuousTimeMode fmi2FullName(fmi2EnterContinuousTimeMode)
221 | #define fmi2CompletedIntegratorStep fmi2FullName(fmi2CompletedIntegratorStep)
222 | #define fmi2SetTime fmi2FullName(fmi2SetTime)
223 | #define fmi2SetContinuousStates fmi2FullName(fmi2SetContinuousStates)
224 | #define fmi2GetDerivatives fmi2FullName(fmi2GetDerivatives)
225 | #define fmi2GetEventIndicators fmi2FullName(fmi2GetEventIndicators)
226 | #define fmi2GetContinuousStates fmi2FullName(fmi2GetContinuousStates)
227 | #define fmi2GetNominalsOfContinuousStates fmi2FullName(fmi2GetNominalsOfContinuousStates)
228 |
229 |
230 | /***************************************************
231 | Functions for FMI2 for Co-Simulation
232 | ****************************************************/
233 | #define fmi2SetRealInputDerivatives fmi2FullName(fmi2SetRealInputDerivatives)
234 | #define fmi2GetRealOutputDerivatives fmi2FullName(fmi2GetRealOutputDerivatives)
235 | #define fmi2DoStep fmi2FullName(fmi2DoStep)
236 | #define fmi2CancelStep fmi2FullName(fmi2CancelStep)
237 | #define fmi2GetStatus fmi2FullName(fmi2GetStatus)
238 | #define fmi2GetRealStatus fmi2FullName(fmi2GetRealStatus)
239 | #define fmi2GetIntegerStatus fmi2FullName(fmi2GetIntegerStatus)
240 | #define fmi2GetBooleanStatus fmi2FullName(fmi2GetBooleanStatus)
241 | #define fmi2GetStringStatus fmi2FullName(fmi2GetStringStatus)
242 |
243 | /* Version number */
244 | #define fmi2Version "2.0"
245 |
246 |
247 | /***************************************************
248 | Common Functions
249 | ****************************************************/
250 |
251 | /* Inquire version numbers of header files */
252 | FMI2_Export fmi2GetTypesPlatformTYPE fmi2GetTypesPlatform;
253 | FMI2_Export fmi2GetVersionTYPE fmi2GetVersion;
254 | FMI2_Export fmi2SetDebugLoggingTYPE fmi2SetDebugLogging;
255 |
256 | /* Creation and destruction of FMU instances */
257 | FMI2_Export fmi2InstantiateTYPE fmi2Instantiate;
258 | FMI2_Export fmi2FreeInstanceTYPE fmi2FreeInstance;
259 |
260 | /* Enter and exit initialization mode, terminate and reset */
261 | FMI2_Export fmi2SetupExperimentTYPE fmi2SetupExperiment;
262 | FMI2_Export fmi2EnterInitializationModeTYPE fmi2EnterInitializationMode;
263 | FMI2_Export fmi2ExitInitializationModeTYPE fmi2ExitInitializationMode;
264 | FMI2_Export fmi2TerminateTYPE fmi2Terminate;
265 | FMI2_Export fmi2ResetTYPE fmi2Reset;
266 |
267 | /* Getting and setting variables values */
268 | FMI2_Export fmi2GetRealTYPE fmi2GetReal;
269 | FMI2_Export fmi2GetIntegerTYPE fmi2GetInteger;
270 | FMI2_Export fmi2GetBooleanTYPE fmi2GetBoolean;
271 | FMI2_Export fmi2GetStringTYPE fmi2GetString;
272 |
273 | FMI2_Export fmi2SetRealTYPE fmi2SetReal;
274 | FMI2_Export fmi2SetIntegerTYPE fmi2SetInteger;
275 | FMI2_Export fmi2SetBooleanTYPE fmi2SetBoolean;
276 | FMI2_Export fmi2SetStringTYPE fmi2SetString;
277 |
278 | /* Getting and setting the internal FMU state */
279 | FMI2_Export fmi2GetFMUstateTYPE fmi2GetFMUstate;
280 | FMI2_Export fmi2SetFMUstateTYPE fmi2SetFMUstate;
281 | FMI2_Export fmi2FreeFMUstateTYPE fmi2FreeFMUstate;
282 | FMI2_Export fmi2SerializedFMUstateSizeTYPE fmi2SerializedFMUstateSize;
283 | FMI2_Export fmi2SerializeFMUstateTYPE fmi2SerializeFMUstate;
284 | FMI2_Export fmi2DeSerializeFMUstateTYPE fmi2DeSerializeFMUstate;
285 |
286 | /* Getting partial derivatives */
287 | FMI2_Export fmi2GetDirectionalDerivativeTYPE fmi2GetDirectionalDerivative;
288 |
289 |
290 | /***************************************************
291 | Functions for FMI2 for Model Exchange
292 | ****************************************************/
293 |
294 | /* Enter and exit the different modes */
295 | FMI2_Export fmi2EnterEventModeTYPE fmi2EnterEventMode;
296 | FMI2_Export fmi2NewDiscreteStatesTYPE fmi2NewDiscreteStates;
297 | FMI2_Export fmi2EnterContinuousTimeModeTYPE fmi2EnterContinuousTimeMode;
298 | FMI2_Export fmi2CompletedIntegratorStepTYPE fmi2CompletedIntegratorStep;
299 |
300 | /* Providing independent variables and re-initialization of caching */
301 | FMI2_Export fmi2SetTimeTYPE fmi2SetTime;
302 | FMI2_Export fmi2SetContinuousStatesTYPE fmi2SetContinuousStates;
303 |
304 | /* Evaluation of the model equations */
305 | FMI2_Export fmi2GetDerivativesTYPE fmi2GetDerivatives;
306 | FMI2_Export fmi2GetEventIndicatorsTYPE fmi2GetEventIndicators;
307 | FMI2_Export fmi2GetContinuousStatesTYPE fmi2GetContinuousStates;
308 | FMI2_Export fmi2GetNominalsOfContinuousStatesTYPE fmi2GetNominalsOfContinuousStates;
309 |
310 |
311 | /***************************************************
312 | Functions for FMI2 for Co-Simulation
313 | ****************************************************/
314 |
315 | /* Simulating the slave */
316 | FMI2_Export fmi2SetRealInputDerivativesTYPE fmi2SetRealInputDerivatives;
317 | FMI2_Export fmi2GetRealOutputDerivativesTYPE fmi2GetRealOutputDerivatives;
318 |
319 | FMI2_Export fmi2DoStepTYPE fmi2DoStep;
320 | FMI2_Export fmi2CancelStepTYPE fmi2CancelStep;
321 |
322 | /* Inquire slave status */
323 | FMI2_Export fmi2GetStatusTYPE fmi2GetStatus;
324 | FMI2_Export fmi2GetRealStatusTYPE fmi2GetRealStatus;
325 | FMI2_Export fmi2GetIntegerStatusTYPE fmi2GetIntegerStatus;
326 | FMI2_Export fmi2GetBooleanStatusTYPE fmi2GetBooleanStatus;
327 | FMI2_Export fmi2GetStringStatusTYPE fmi2GetStringStatus;
328 |
329 | #ifdef __cplusplus
330 | } /* end of extern "C" { */
331 | #endif
332 |
333 | #endif /* fmi2Functions_h */
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/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 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/fmi2_library.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_FMI2LIBRARY_HPP
3 | #define FMI4CPP_FMI2LIBRARY_HPP
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | namespace fmi4cpp::fmi2
15 | {
16 |
17 | class fmi2_library
18 | {
19 |
20 | private:
21 | std::shared_ptr resource_;
22 |
23 | fmi2GetVersionTYPE* fmi2GetVersion_;
24 | fmi2GetTypesPlatformTYPE* fmi2GetTypesPlatform_;
25 |
26 | fmi2SetDebugLoggingTYPE* fmi2SetDebugLogging_;
27 |
28 | fmi2InstantiateTYPE* fmi2Instantiate_;
29 | fmi2SetupExperimentTYPE* fmi2SetupExperiment_;
30 | fmi2EnterInitializationModeTYPE* fmi2EnterInitializationMode_;
31 | fmi2ExitInitializationModeTYPE* fmi2ExitInitializationMode_;
32 |
33 | fmi2ResetTYPE* fmi2Reset_;
34 | fmi2TerminateTYPE* fmi2Terminate_;
35 |
36 | fmi2GetIntegerTYPE* fmi2GetInteger_;
37 | fmi2GetRealTYPE* fmi2GetReal_;
38 | fmi2GetStringTYPE* fmi2GetString_;
39 | fmi2GetBooleanTYPE* fmi2GetBoolean_;
40 |
41 | fmi2SetIntegerTYPE* fmi2SetInteger_;
42 | fmi2SetRealTYPE* fmi2SetReal_;
43 | fmi2SetStringTYPE* fmi2SetString_;
44 | fmi2SetBooleanTYPE* fmi2SetBoolean_;
45 |
46 | fmi2GetFMUstateTYPE* fmi2GetFMUstate_;
47 | fmi2SetFMUstateTYPE* fmi2SetFMUstate_;
48 | fmi2FreeFMUstateTYPE* fmi2FreeFMUstate_;
49 |
50 | fmi2SerializedFMUstateSizeTYPE* fmi2SerializedFMUstateSize_;
51 | fmi2SerializeFMUstateTYPE* fmi2SerializeFMUstate_;
52 | fmi2DeSerializeFMUstateTYPE* fmi2DeSerializeFMUstate_;
53 |
54 | fmi2GetDirectionalDerivativeTYPE* fmi2GetDirectionalDerivative_;
55 |
56 | fmi2FreeInstanceTYPE* fmi2FreeInstance_;
57 |
58 | #ifdef _WIN32
59 | DLL_DIRECTORY_COOKIE dllDirectoryCookie_ = nullptr;
60 | #endif
61 |
62 | protected:
63 | fmi2Status lastStatus_;
64 | DLL_HANDLE handle_ = nullptr;
65 | bool update_status_and_return_true_if_ok(fmi2Status status);
66 |
67 | public:
68 | fmi2_library(const std::string& modelIdentifier, const std::shared_ptr& resource);
69 |
70 | [[nodiscard]] DLL_HANDLE handle() const;
71 | [[nodiscard]] fmi2Status last_status() const;
72 | [[nodiscard]] fmi2String get_version() const;
73 | [[nodiscard]] fmi2String get_types_platform() const;
74 |
75 | bool set_debug_logging(fmi2Component c, bool loggingOn, std::vector categories);
76 |
77 | fmi2Component instantiate(const std::string& instanceName, fmi2Type type,
78 | const std::string& guid, const std::string& resourceLocation,
79 | bool visible = false, bool loggingOn = false);
80 |
81 | bool setup_experiment(fmi2Component c, double tolerance, double startTime, double stopTime);
82 | bool enter_initialization_mode(fmi2Component c);
83 | bool exit_initialization_mode(fmi2Component c);
84 |
85 | bool reset(fmi2Component c);
86 | bool terminate(fmi2Component c);
87 |
88 | bool read_integer(fmi2Component c, fmi2ValueReference vr, fmi2Integer& ref);
89 | bool read_integer(fmi2Component c, const std::vector& vr, std::vector& ref);
90 |
91 | bool read_real(fmi2Component c, fmi2ValueReference vr, fmi2Real& ref);
92 | bool read_real(fmi2Component c, const std::vector& vr, std::vector& ref);
93 |
94 | bool read_string(fmi2Component c, fmi2ValueReference vr, fmi2String& ref);
95 | bool read_string(fmi2Component c, const std::vector& vr, std::vector& ref);
96 |
97 | bool read_boolean(fmi2Component c, fmi2ValueReference vr, fmi2Boolean& ref);
98 | bool read_boolean(fmi2Component c, const std::vector& vr, std::vector& ref);
99 |
100 | bool write_integer(fmi2Component c, fmi2ValueReference vr, const fmi2Integer& value);
101 | bool write_integer(fmi2Component c, const std::vector& vr,
102 | const std::vector& values);
103 |
104 | bool write_real(fmi2Component c, fmi2ValueReference vr, const fmi2Real& value);
105 | bool write_real(fmi2Component c, const std::vector& vr, const std::vector& values);
106 |
107 | bool write_string(fmi2Component c, fmi2ValueReference vr, fmi2String& value);
108 | bool write_string(fmi2Component c, const std::vector& vr,
109 | const std::vector& values);
110 |
111 | bool write_boolean(fmi2Component c, fmi2ValueReference vr, const fmi2Boolean& value);
112 | bool write_boolean(fmi2Component c, const std::vector& vr,
113 | const std::vector& values);
114 |
115 | bool get_fmu_state(fmi2Component c, fmi2FMUstate& state);
116 | bool set_fmu_state(fmi2Component c, fmi2FMUstate state);
117 | bool free_fmu_state(fmi2Component c, fmi2FMUstate& state);
118 |
119 | bool get_serialized_fmu_state_size(fmi2Component c, fmi2FMUstate state, size_t& size);
120 | bool serialize_fmu_state(fmi2Component c, const fmi2FMUstate& state, std::vector& serializedState);
121 | bool de_serialize_fmu_state(fmi2Component c, fmi2FMUstate& state, const std::vector& serializedState);
122 |
123 | bool get_directional_derivative(fmi2Component c,
124 | const std::vector& vUnknownRef,
125 | const std::vector& vKnownRef,
126 | const std::vector& dvKnownRef, std::vector& dvUnknownRef);
127 |
128 | void free_instance(fmi2Component c);
129 |
130 | ~fmi2_library();
131 | };
132 |
133 | } // namespace fmi4cpp::fmi2
134 |
135 | #endif //FMI4CPP_FMI2LIBRARY_HPP
136 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/fmu.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_FMI2FMU_HPP
3 | #define FMI4CPP_FMI2FMU_HPP
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | namespace fmi4cpp::fmi2
15 | {
16 |
17 | class fmu : public virtual fmu_provider
18 | {
19 |
20 | friend class cs_fmu;
21 | friend class me_fmu;
22 |
23 | private:
24 | std::shared_ptr resource_;
25 | std::shared_ptr modelDescription_;
26 |
27 | public:
28 | explicit fmu(const std::filesystem::path& fmuPath);
29 |
30 | [[nodiscard]] std::string get_model_description_xml() const;
31 | [[nodiscard]] std::shared_ptr get_model_description() const override;
32 |
33 | [[nodiscard]] bool supports_me() const override;
34 | [[nodiscard]] bool supports_cs() const override;
35 |
36 | [[nodiscard]] std::unique_ptr as_cs_fmu() const override;
37 | [[nodiscard]] std::unique_ptr as_me_fmu() const override;
38 | };
39 |
40 | } // namespace fmi4cpp::fmi2
41 |
42 |
43 | #endif // FMI4CPP_FMI2FMU_HPP
44 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/me_fmu.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_FMI2MODELEXCHANGEFMU_H
3 | #define FMI4CPP_FMI2MODELEXCHANGEFMU_H
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | namespace fmi4cpp::fmi2
11 | {
12 |
13 | class me_fmu : public virtual me_fmu_base
14 | {
15 |
16 | private:
17 | std::shared_ptr resource_;
18 | std::shared_ptr lib_;
19 | std::shared_ptr modelDescription_;
20 |
21 | public:
22 | me_fmu(std::shared_ptr resource,
23 | std::shared_ptr md);
24 |
25 | [[nodiscard]] std::string get_model_description_xml() const;
26 |
27 | [[nodiscard]] std::shared_ptr get_model_description() const override;
28 |
29 | std::unique_ptr new_instance(bool visible = false, bool loggingOn = false) override;
30 | };
31 |
32 | } // namespace fmi4cpp::fmi2
33 |
34 | #endif //FMI4CPP_FMI2MODELEXCHANGEFMU_H
35 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/me_instance.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_FMI2MODELEXCHANGEINSTANCE_HPP
3 | #define FMI4CPP_FMI2MODELEXCHANGEINSTANCE_HPP
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include
11 | #include
12 |
13 | namespace fmi4cpp::fmi2
14 | {
15 |
16 | class me_instance : public fmu_instance_base
17 | {
18 |
19 | public:
20 | fmi2EventInfo eventInfo_;
21 |
22 | me_instance(fmi2Component c,
23 | const std::shared_ptr& resource,
24 | const std::shared_ptr& library,
25 | const std::shared_ptr& modelDescription);
26 |
27 |
28 | bool enter_event_mode();
29 |
30 | bool enter_continuous_time_mode();
31 |
32 | bool set_time(double time);
33 |
34 | bool set_continuous_states(const std::vector& x);
35 |
36 | bool get_derivatives(std::vector& derivatives);
37 |
38 | bool get_event_indicators(std::vector& eventIndicators);
39 |
40 | bool get_continuous_states(std::vector& x);
41 |
42 | bool get_nominals_of_continuous_states(std::vector& x_nominal);
43 |
44 | bool completed_integrator_step(fmi2Boolean noSetFMUStatePriorToCurrentPoint,
45 | fmi2Boolean& enterEventMode, fmi2Boolean& terminateSimulation);
46 |
47 | bool new_discrete_states();
48 |
49 | [[nodiscard]] DLL_HANDLE handle() const override;
50 |
51 | [[nodiscard]] status last_status() const override;
52 | };
53 |
54 | } // namespace fmi4cpp::fmi2
55 |
56 | #endif //FMI4CPP_FMI2MODELEXCHANGEINSTANCE_HPP
57 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/me_library.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_FMI2MODELEXCHANGELIBRARY_HPP
3 | #define FMI4CPP_FMI2MODELEXCHANGELIBRARY_HPP
4 |
5 | #include
6 |
7 | namespace fmi4cpp::fmi2
8 | {
9 |
10 | class me_library : public fmi2_library
11 | {
12 |
13 | private:
14 | fmi2EnterEventModeTYPE* fmi2EnterEventMode_;
15 | fmi2EnterContinuousTimeModeTYPE* fmi2EnterContinuousTimeMode_;
16 | fmi2SetTimeTYPE* fmi2SetTime_;
17 | fmi2SetContinuousStatesTYPE* fmi2SetContinuousStates_;
18 | fmi2GetDerivativesTYPE* fmi2GetDerivatives_;
19 | fmi2GetEventIndicatorsTYPE* fmi2GetEventIndicators_;
20 | fmi2GetContinuousStatesTYPE* fmi2GetContinuousStates_;
21 | fmi2GetNominalsOfContinuousStatesTYPE* fmi2GetNominalsOfContinuousStates_;
22 | fmi2CompletedIntegratorStepTYPE* fmi2CompletedIntegratorStep_;
23 | fmi2NewDiscreteStatesTYPE* fmi2NewDiscreteStates_;
24 |
25 | public:
26 | explicit me_library(
27 | const std::string& modelIdentifier,
28 | const std::shared_ptr& resource);
29 |
30 | bool enter_event_mode(fmi2Component c);
31 |
32 | bool enter_continuous_time_mode(fmi2Component c);
33 |
34 | bool set_time(fmi2Component c, double time);
35 |
36 | bool set_continuous_states(fmi2Component c, const std::vector& x);
37 |
38 | bool get_derivatives(fmi2Component c, std::vector& derivatives);
39 |
40 | bool get_event_indicators(fmi2Component c, std::vector& eventIndicators);
41 |
42 | bool get_continuous_states(fmi2Component c, std::vector& x);
43 |
44 | bool get_nominals_of_continuous_states(fmi2Component c, std::vector& x_nominal);
45 |
46 | bool completed_integrator_step(fmi2Component c,
47 | fmi2Boolean noSetFMUStatePriorToCurrentPoint,
48 | fmi2Boolean& enterEventMode,
49 | fmi2Boolean& terminateSimulation);
50 |
51 | bool new_discrete_states(fmi2Component c, fmi2EventInfo& eventInfo);
52 | };
53 |
54 | } // namespace fmi4cpp::fmi2
55 |
56 | #endif //FMI4CPP_FMI2MODELEXCHANGELIBRARY_HPP
57 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/xml/cs_model_description.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_FMI2_CS_MODEL_DESCRIPTION_HPP
3 | #define FMI4CPP_FMI2_CS_MODEL_DESCRIPTION_HPP
4 |
5 | #include
6 |
7 | namespace fmi4cpp::fmi2
8 | {
9 |
10 | struct cs_model_description : specific_model_description
11 | {
12 | cs_model_description(const model_description_base& base, const cs_attributes& attributes)
13 | : specific_model_description(base, attributes)
14 | {}
15 | };
16 |
17 | } // namespace fmi4cpp::fmi2
18 |
19 | #endif //FMI4CPP_FMI2_CS_MODEL_DESCRIPTION_HPP
20 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/xml/default_experiment.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_DEFAULTEXPERIMENT_HPP
3 | #define FMI4CPP_DEFAULTEXPERIMENT_HPP
4 |
5 | #include
6 |
7 | namespace fmi4cpp::fmi2
8 | {
9 |
10 | struct default_experiment
11 | {
12 | std::optional startTime;
13 | std::optional stopTime;
14 | std::optional stepSize;
15 | std::optional tolerance;
16 | };
17 |
18 | } // namespace fmi4cpp::fmi2
19 |
20 | #endif //FMI4CPP_DEFAULTEXPERIMENT_HPP
21 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/xml/enums.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_ENUMS_HPP
3 | #define FMI4CPP_ENUMS_HPP
4 |
5 | #include
6 |
7 | namespace fmi4cpp::fmi2
8 | {
9 |
10 | enum class causality
11 | {
12 | parameter,
13 | calculatedParameter,
14 | input,
15 | output,
16 | local,
17 | independent,
18 | unknown
19 | };
20 |
21 | enum class variability
22 | {
23 | constant,
24 | fixed,
25 | tunable,
26 | discrete,
27 | continuous,
28 | unknown
29 | };
30 |
31 | enum class initial
32 | {
33 | exact,
34 | approx,
35 | calculated,
36 | unknown
37 | };
38 |
39 | causality parse_causality(const std::string& str);
40 | variability parse_variability(const std::string& str);
41 | initial parse_initial(const std::string& str);
42 |
43 | std::string to_string(causality causality);
44 | std::string to_string(variability variability);
45 | std::string to_string(initial initial);
46 |
47 | } // namespace fmi4cpp::fmi2
48 |
49 | #endif //FMI4CPP_ENUMS_HPP
50 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/xml/fmu_attributes.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_FMUTYPESATTRIBUTE_HPP
3 | #define FMI4CPP_FMUTYPESATTRIBUTE_HPP
4 |
5 | #include
6 |
7 | #include
8 |
9 | namespace fmi4cpp::fmi2
10 | {
11 |
12 | struct fmu_attributes
13 | {
14 | source_files sourceFiles;
15 | std::string model_identifier;
16 |
17 | bool can_get_and_set_fmu_state;
18 | bool can_serialize_fmu_state;
19 | bool needs_execution_tool;
20 | bool can_not_use_memory_management_functions;
21 | bool can_be_instantiated_only_once_per_process;
22 | bool provides_directional_derivative;
23 | };
24 |
25 | struct cs_attributes : fmu_attributes
26 | {
27 | bool can_interpolate_inputs = false;
28 | bool can_run_asynchronuously = false;
29 | bool can_handle_variable_communication_step_size = false;
30 |
31 | unsigned int max_output_derivative_order{};
32 |
33 | cs_attributes() = default;
34 |
35 | explicit cs_attributes(const fmu_attributes& attributes)
36 | : fmu_attributes(attributes)
37 | {}
38 | };
39 |
40 | struct me_attributes : fmu_attributes
41 | {
42 |
43 | bool completed_integrator_step_not_needed = false;
44 |
45 | me_attributes() = default;
46 |
47 | explicit me_attributes(const fmu_attributes& attributes)
48 | : fmu_attributes(attributes)
49 | {}
50 | };
51 |
52 | } // namespace fmi4cpp::fmi2
53 |
54 | #endif //FMI4CPP_FMUTYPESATTRIBUTE_HPP
55 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/xml/me_model_description.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_FMI2_ME_MODEL_DESCRIPTION_HPP
3 | #define FMI4CPP_FMI2_ME_MODEL_DESCRIPTION_HPP
4 |
5 | #include
6 |
7 | namespace fmi4cpp::fmi2
8 | {
9 |
10 | struct me_model_description : public specific_model_description
11 | {
12 | me_model_description(const model_description_base& base, const me_attributes& attributes)
13 | : specific_model_description(base, attributes)
14 | {}
15 | };
16 |
17 | } // namespace fmi4cpp::fmi2
18 |
19 | #endif //FMI4CPP_FMI2_ME_MODEL_DESCRIPTION_HPP
20 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/xml/model_description.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_MODELDESCRIPTION_HPP
3 | #define FMI4CPP_MODELDESCRIPTION_HPP
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 | #include
13 | #include
14 |
15 | namespace fmi4cpp::fmi2
16 | {
17 |
18 | struct model_description_base
19 | {
20 | std::string guid;
21 | std::string model_name;
22 | std::string fmi_version;
23 |
24 | std::optional author;
25 | std::optional version;
26 | std::optional license;
27 | std::optional copyright;
28 | std::optional description;
29 | std::optional generation_tool;
30 | std::optional generation_date_and_time;
31 | std::optional variable_naming_convention;
32 |
33 | std::shared_ptr model_variables;
34 | std::shared_ptr model_structure;
35 |
36 | std::optional default_experiment;
37 | std::optional unit_definitions;
38 |
39 | size_t number_of_event_indicators;
40 | [[nodiscard]] size_t number_of_continuous_states() const;
41 |
42 | [[nodiscard]] unsigned int get_value_reference(const std::string& name) const;
43 | [[nodiscard]] const scalar_variable& get_variable_by_name(const std::string& name) const;
44 | };
45 |
46 | struct cs_model_description;
47 | struct me_model_description;
48 |
49 | class model_description : public model_description_base
50 | {
51 |
52 | protected:
53 | std::optional coSimulation_;
54 | std::optional modelExchange_;
55 |
56 | public:
57 | model_description(
58 | const model_description_base& base,
59 | std::optional coSimulation,
60 | std::optional modelExchange);
61 |
62 | [[nodiscard]] bool supports_cs() const;
63 | [[nodiscard]] bool supports_me() const;
64 |
65 | [[nodiscard]] std::unique_ptr as_cs_description() const;
66 | [[nodiscard]] std::unique_ptr as_me_description() const;
67 | };
68 |
69 | } // namespace fmi4cpp::fmi2
70 |
71 | #endif //FMI4CPP_MODELDESCRIPTION_HPP
72 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/xml/model_description_parser.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_MODELDESCRIPTIONPARSER_HPP
3 | #define FMI4CPP_MODELDESCRIPTIONPARSER_HPP
4 |
5 | #include
6 |
7 | #include
8 | #include
9 |
10 | namespace fmi4cpp::fmi2
11 | {
12 |
13 | std::unique_ptr parse_model_description(const std::string& fileName);
14 |
15 | }
16 |
17 | #endif //FMI4CPP_MODELDESCRIPTIONPARSER_HPP
18 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/xml/model_structure.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_MODELSTRUCTURE_HPP
3 | #define FMI4CPP_MODELSTRUCTURE_HPP
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | namespace fmi4cpp::fmi2
10 | {
11 |
12 | struct unknown
13 | {
14 | unsigned int index;
15 | std::optional> dependencies;
16 | std::optional> dependencies_kind;
17 | };
18 |
19 | struct model_structure
20 | {
21 | const std::vector outputs;
22 | const std::vector derivatives;
23 | const std::vector initialUnknowns;
24 |
25 | model_structure(std::vector outputs, std::vector derivatives,
26 | std::vector initialUnknowns)
27 | : outputs(std::move(outputs))
28 | , derivatives(std::move(derivatives))
29 | , initialUnknowns(std::move(initialUnknowns))
30 | {}
31 | };
32 |
33 | } // namespace fmi4cpp::fmi2
34 |
35 | #endif //FMI4CPP_MODELSTRUCTURE_HPP
36 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/xml/model_variables.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_MODELVARIABLES_HPP
3 | #define FMI4CPP_MODELVARIABLES_HPP
4 |
5 | #include
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | namespace fmi4cpp::fmi2
12 | {
13 |
14 | class model_variables
15 | {
16 |
17 | private:
18 | const std::vector variables_ = {};
19 |
20 | public:
21 | model_variables();
22 |
23 | explicit model_variables(std::vector variables);
24 |
25 | [[nodiscard]] size_t size() const;
26 |
27 | const scalar_variable& operator[](size_t index) const;
28 | [[nodiscard]] const scalar_variable& getByName(const std::string& name) const;
29 | [[nodiscard]] const scalar_variable& getByValueReference(fmi2ValueReference vr) const;
30 |
31 | void getByValueReference(fmi2ValueReference vr, std::vector& store) const;
32 | void getByCausality(causality causality, std::vector& store) const;
33 |
34 | [[nodiscard]] std::vector::const_iterator begin() const;
35 | [[nodiscard]] std::vector::const_iterator end() const;
36 | };
37 |
38 | } // namespace fmi4cpp::fmi2
39 |
40 | #endif //FMI4CPP_MODELVARIABLES_HPP
41 |
--------------------------------------------------------------------------------
/include/fmi4cpp/fmi2/xml/scalar_variable.hpp:
--------------------------------------------------------------------------------
1 |
2 | #ifndef FMI4CPP_SCALARVARIABLE_HPP
3 | #define FMI4CPP_SCALARVARIABLE_HPP
4 |
5 | #include
6 | #include
7 |
8 | #include
9 |
10 | namespace fmi4cpp::fmi2
11 | {
12 |
13 | class integer_variable;
14 | class real_variable;
15 | class string_variable;
16 | class boolean_variable;
17 | class enumeration_variable;
18 |
19 | const std::string INTEGER_TYPE = "Integer";
20 | const std::string REAL_TYPE = "Real";
21 | const std::string STRING_TYPE = "String";
22 | const std::string BOOLEAN_TYPE = "Boolean";
23 | const std::string ENUMERATION_TYPE = "Enumeration";
24 | const std::string UNKNOWN_TYPE = "Unknown";
25 |
26 | struct scalar_variable_base
27 | {
28 | std::string name;
29 | std::string description;
30 |
31 | fmi2::initial initial;
32 | fmi2::causality causality;
33 | fmi2::variability variability;
34 |
35 | fmi2ValueReference value_reference;
36 | bool can_handle_multiple_set_per_time_instant;
37 | };
38 |
39 |
40 | template
41 | struct scalar_variable_attribute
42 | {
43 | std::optional start;
44 | std::optional declared_type;
45 | };
46 |
47 |
48 | template
49 | struct bounded_scalar_variable_attribute : scalar_variable_attribute
50 | {
51 | std::optional min;
52 | std::optional max;
53 | std::optional quantity;
54 |
55 | explicit bounded_scalar_variable_attribute(const scalar_variable_attribute& attributes)
56 | : scalar_variable_attribute(attributes)
57 | {}
58 | };
59 |
60 | struct integer_attribute : bounded_scalar_variable_attribute
61 | {
62 | explicit integer_attribute(const bounded_scalar_variable_attribute& attributes);
63 | };
64 |
65 | struct real_attribute : bounded_scalar_variable_attribute
66 | {
67 | bool reinit = false;
68 | bool unbounded = false;
69 | bool relative_quantity = false;
70 |
71 | std::optional nominal;
72 | std::optional derivative;
73 |
74 | std::optional unit;
75 | std::optional display_unit;
76 |
77 | explicit real_attribute(const bounded_scalar_variable_attribute& attributes);
78 | };
79 |
80 | struct string_attribute : scalar_variable_attribute
81 | {
82 | explicit string_attribute(const scalar_variable_attribute& attributes);
83 | };
84 |
85 | struct boolean_attribute : scalar_variable_attribute
86 | {
87 | explicit boolean_attribute(const scalar_variable_attribute& attributes);
88 | };
89 |
90 | struct enumeration_attribute : bounded_scalar_variable_attribute