Giter VIP home page Giter VIP logo

fmu-standalone-app's Introduction

Embedding an FMU into a standalone app

This project demonstrates how to simulate an FMI 2.0 source code FMU as a standalone app. It consists of a simple C program that creates an instance of the Heater model. Its simulation loop turns the power for the heatingResistor on and off by setting the input variable u to keep the temperature T of the heatCapacitor at 40 °C.

Heater.mo

For each time step the current simulation time, u and T are displayed on the command line:

time, u, T
0.00, 0, -7.15
0.10, 0, 20.72
0.20, 0, 21.43
0.30, 0, 22.14
...
3.40, 0, 39.82
3.50, 1, 40.28
3.60, 1, 40.73
3.70, 1, 40.26
3.80, 0, 39.79
3.90, 0, 39.32
4.00, 0, 39.78
4.10, 1, 40.23
4.20, 1, 40.68
4.30, 1, 40.21
4.40, 0, 39.74
...

Project Structure

Building the Standalone App

Prerequisites

  • a clone or extracted download of this repository
  • CMake to generate the Visual Studio solution on Windows or Makefiles on Linux
  • a supported toolchain to build the App (run cmake --help to get a list of all available generators)
  • Dymola to export the FMU (optional)
  • Python and FMPy to reimport the FMU (optional)

Building on Windows with Visual Studio

  • run cmake -G"Visual Studio 15 2017 Win64" -Bbuild . to generate a Visual Studio 2017 solution

  • open build/simulator.sln in Visual Studio 2017

  • In the Project Explorer right-click on the simulator project and select Debug > Start new instance to build and run the app

Building on Linux with GCC

  • run cmake -Bbuild . to generate the Unix Makefiles

  • run cmake --build build to build the app

  • run the app with ./build/simulator

Exporting the FMU

  • in Dymola 2021 click File > Open > Load... and select Heater.mo

  • on the Simulation tab open the Translate menu and select FMU

Translate FMU

  • in the Export FMU select the following options and click OK

Export FMU

Reimporting the FMU

To reimport the FMU run the following command

python import_fmu.py Heater.fmu

This will extract Heater.fmu to the model directory and create a include/model.h with the model specific constant. The script requires Python and FMPy.

Embedding an FMU into a graphical Qt app

The "Heater" Qt app demonstrates how to embed an FMU into an application with a graphical user interface (GUI). It has a spin box to set the TAmb parameter and a push button to control the input u that closes the idealSwitch. The temperature T is displayed as an LCD number.

Graphical Heater Qt App

Building the Qt App

  • install Qt 6
  • open QtCreator, import Heater/CMakeLists.txt and conifigure the project
  • build the project and copy model/binaries/win64/Heater.dll next to Heater.exe
  • run the project

Deploying the Qt App

To deploy the Qt app use windeployqt.exe.

fmu-standalone-app's People

Contributors

t-sommer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.