Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/NTNU-IHB/FMI4cpp
FMI 2.0 implementation written in modern C++.
https://github.com/NTNU-IHB/FMI4cpp
cmake co-simulation cpp17 fmi-standard model-exchange
Last synced: 3 months ago
JSON representation
FMI 2.0 implementation written in modern C++.
- Host: GitHub
- URL: https://github.com/NTNU-IHB/FMI4cpp
- Owner: NTNU-IHB
- License: mit
- Created: 2018-08-29T14:25:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T12:11:52.000Z (over 1 year ago)
- Last Synced: 2024-06-22T14:39:29.489Z (5 months ago)
- Topics: cmake, co-simulation, cpp17, fmi-standard, model-exchange
- Language: C++
- Homepage:
- Size: 3.86 MB
- Stars: 91
- Watchers: 7
- Forks: 34
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fmi - FMI4cpp - FMI 2.0 implementation written in modern C++. [MIT] (FMI 2 / Libraries)
README
# FMI4cpp (work in progress)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/NTNU-IHB/FMU-proxy/issues)
[![Join the chat at https://gitter.im/NTNU-IHB/FMI4cpp](https://badges.gitter.im/NTNU-IHB/FMI4cpp.svg)](https://gitter.im/NTNU-IHB/FMI4cpp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)[![GitHub Actions](https://github.com/NTNU-IHB/FMI4cpp/workflows/Conan/badge.svg)](https://github.com/NTNU-IHB/FMI4cpp/actions)
FMI4cpp is a cross-platform [FMI](https://fmi-standard.org/) 2.0 implementation written in modern C++.
Influenced by its spiritual brother [FMI4j](https://github.com/NTNU-IHB/FMI4j), it aims to be
an easy to install, easy to use, object-oriented and fast FMI implementation for C++.FMI4cpp supports both **Co-simulation** and **Model Exchange**.
### Why should I use this over other C/C++ FMI Libraries
Because it provides a clean, easy to use API and is easy to install.
It performs just as good as FMI Library, provides more features and is significantly easier to both build and use.## Install instructions
Refer to [INSTALL.md](INSTALL.md)
## Build instructions
Refer to [BUILDING.md](BUILDING.md)
#### API
```cpp
#include
#includeusing namespace fmi4cpp;
const double stop = ...;
const double stepSize = ...;int main()
{
fmi2::fmu fmu("path/to/fmu.fmu");auto cs_fmu = fmu.as_cs_fmu();
auto me_fmu = fmu.as_me_fmu();
auto cs_md = cs_fmu->get_model_description(); //smart pointer to a cs_model_description instance
std::cout << "model_identifier=" << cs_md->model_identifier << std::endl;
auto me_md = me_fmu->get_model_description(); //smart pointer to a me_model_description instance
std::cout << "model_identifier=" << me_md->model_identifier << std::endl;
auto var = cs_md->get_variable_by_name("my_var").as_real();
std::cout << "Name=" << var.name() << ", start=" << var.start().value_or(0) << std::endl;
auto slave = cs_fmu->new_instance();
slave->setup_experiment();
slave->enter_initialization_mode();
slave->exit_initialization_mode();
double t;
double value;
auto vr = var.valueReference();
while ( (t = slave->get_simulation_time()) <= stop) {if (!slave->step(stepSize)) {
std::cerr << "Error! step() returned with status: " << to_string(slave->last_status()) << std::endl;
break;
}
if (!slave->read_real(vr, value)) {
std::cerr << "Error! step() returned with status: " << to_string(slave->last_status()) << std::endl;
break;
}
std::cout << "t=" << t << ", " << var.name() << "=" << value << std::endl;
}
slave->terminate();
return 0;
}
```***
Would you rather simulate FMUs in Java? Check out [FMI4j](https://github.com/NTNU-IHB/FMI4j)!
Would you like to build JVM based FMUs? Check out [FMU4j](https://github.com/https://github.com/Vico-platform/FMU4j)!
Perhaps you want to build FMUs using plain Python? Check out [PythonFMU](https://github.com/NTNU-IHB/PythonFMU)!
Need to distribute your FMUs? [FMU-proxy](https://github.com/NTNU-IHB/FMU-proxy) to the rescue!