Git Product home page Git Product logo

fmi4cpp's Introduction

FMI4cpp (work in progress)

FMI4cpp is a cross-platform FMI 2.0 implementation written in modern C++.

Influenced by it's spiritual brother FMI4j, it aims to be an easy to install, easy to use, object oriented and fast FMI implementation for C++.

Why should I use this over other C/C++ FMI Libraries

Because this library provides a clean API, is easy to install (through vcpkg) and is easy to use.

How do I use it in my own project?

When the library is stable it will be added to the vcpkg package manager.

Development dependencies

Install vcpkg and run:

./vcpkg install boost-property-tree libzip

On linux you might need to install some additional libraries:

./vcpkg install bzip2 openssl

These can probably also be installed through the native package handler.

API

#include <iostream>
#include <fmi4cpp/fmi2/fmi4cpp.hpp>

using namespace fmi4cpp::fmi2;

const double stop = 10.0;
const double stepSize = 1.0/100;

int main() {

    auto fmu = Fmu("path/to/fmu.fmu").asCoSimulationFmu();
    
    auto md = fmu->getModelDescription();
    std::cout << "modelIdentifier=" << md->modelIdentifier() << std::endl;
    
    auto var = md->getVariableByName("my_var").asRealVariable();
    cout << "Name=" << var.name() << ", start=" var.start().value_or(0) << endl;
    
    auto slave = fmu->newInstance();
    slave->init();
   
    double t;
    fmi2Real value;
    while ( (t = slave->getSimulationTime()) <= stop) {

        if (slave->doStep(stepSize) != fmi2OK) {
            //error handling
            break;
        }
        
        if (var.read(*slave, value) != fmi2OK) {
            //error handling
            break;
        }
        std::cout << "t=" << t << ", " << var.name() << "=" << value << std::endl;
     
    }
    
    slave->terminate();
    
}

Running examples/tests

In order to run the example/test code, a system variable named TEST_FMUs must be present on your system. This variable should point to the location of the content found here.

The examples are built by default. To change this pass -DFMI4CPP_BUILD_EXAMPLES=OFF to CMake. Test are on the other hand not built by default. To change this pass -DFMI4CPP_BUILD_TESTS=ON to CMake.

To run the tests you will need an additional dependency:

./vcpkg install boost-test

fmi4cpp's People

Contributors

markaren avatar traversaro avatar

Watchers

 avatar  avatar  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.