GithubHelp home page GithubHelp logo

ntnu-ihb / fmi4j Goto Github PK

View Code? Open in Web Editor NEW
30.0 4.0 16.0 60.59 MB

FMI4j is a software package for dealing with Functional Mockup Units (FMUs) on the JVM

License: MIT License

Java 46.79% Kotlin 38.85% C++ 10.60% C 3.75%
fmi-standard fmi java co-simulation model-exchange fmu kotlin

fmi4j's Introduction

FMI4j

License: MIT contributions welcome

CI Gitter

FMI4j is a software package for dealing with Functional Mock-up Units (FMUs) on the Java Virtual Machine (JVM), written in Kotlin.

FMI4j supports import of both FMI 1.0 and 2.0 for Co-simulation. For Model Exchange version 2.0 is supported.

Compared to other FMI libraries targeting the JVM, FMI4j is considerably faster due to the fact that we use JNI instead of JNA. Considering FMI-import, a significant speedup (2-5x) compared to other open-source FMI implementations for the JVM should be expected.

Maven artifacts are available through Central


FMI import

class Demo {
    
    void main(String[] args) {
        
        Fmu fmu = Fmu.from(new File("path/to/fmu.fmu")); //URLs are also supported
        FmuSlave slave = fmu.asCoSimulationFmu().newInstance();

        slave.simpleSetup();
        
        double t = 0;
        double stop = 10;
        double stepSize = 1.0/100;
        while(t <= stop) {
            if (!slave.doStep(t, stepSize)) {
                break;
            }
            t += stepSize;
        }
        slave.terminate(); //or close, try with resources is also supported
        fmu.close();
        
    }
    
}

Would you rather build FMUs using a JVM language? Check out FMU4j!
Or maybe build FMUs using Python? Check out PythonFMU!
Or would you rather simulate FMUs using C++? Check out FMI4cpp!
Need to distribute your FMUs? FMU-proxy to the rescue!
Need a complete co-simulation framework with SSP support? Check out Vico

fmi4j's People

Contributors

eidekrist avatar fdzhang avatar gitter-badger avatar markaren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fmi4j's Issues

The System Could Not Find The Specified Path

I was using the FMI4J toolkit on a project, but I had a problem using it. It worked fine in debug mode and threw exceptions when calling methods. I thought I was unzipping the FMU files in an asynchronous manner, was that right?

Support C-code FMUs

Would be a nice feature to have. Should not be to difficult when following the steps used for fmu2jar (create gradle skeleton -> copy sources -> run )

Feedback from users

Hi,
I would very much like to hear from you, the person reading this.
Why are you interested in this project, have you tried it?
What is unclear, what can be improved?

Note that it is also possible to chat on gitter!

ValueReference is only unique within in a base class

I thought a valueReference was a unique identifier to scalarVariable (or a list of scalarVariable that are aliases). But it seems you can have the same valueReference for a integer/real/boolean/string/enumeration.

That means the getByValueReference function is wrong, as it will return the first occurence.

Java. IO. FileNotFoundException

Lars, I'm back.In the use of [Fmu.from (java.net.URL)] tries to use nginx build file server load Fmu file, throws Exception[Java. IO. FileNotFoundException:C:\Users\Mr.Liu\AppData\Local\Temp\fmi4j_22DAB33C64C553D3AC12677C4AEDE2365354478909019804419\modelDescription.XML], I don't know thisTry to see if this method is correct or give me a little hint about how to use it.Thank you very much!

Lack of informations about Getting Started

I'm currently trying to make FMI4j work on a sample project.

I encounter some Symbol resolution from examples provided in the Wiki.

My sample app :

import no.mechatronics.sfi.fmi4j.common.FmiStatus;
import no.mechatronics.sfi.fmi4j.modeldescription.variables.RealVariable;

import java.io.File;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        Fmu fmu = Fmu.from(new File("path/to/fmu.fmu")); // Fmu class not found
        try(FmiSimulation instance = fmu.asCoSimulationFmu().newInstance()) { // FmiSimulation class not found

            RealVariable myVar = instance.getVariableByName("myVar").asRealVariable()

            //assign custom start values
            myVar.setStart(2d);

            instance.init(); //throws on error

            double myValue = myVar.read().getValue(); //read
            FmiStatus status = myVar.write(5d); //write

            double dt = 1d/100;
            while (instance.getCurrentTime() < 10) {
                instance.doStep(dt);
            }

        } //instance is termi
    }
}

My pom.xml :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.someone</groupId>
  <artifactId>javafmi</artifactId>
  <version>0.1</version>
  <packaging>jar</packaging>

  <name>javafmi</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>no.mechatronics.sfi.fmi4j</groupId>
      <artifactId>fmi-md</artifactId>
      <version>0.5.7</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Have you any tips on how to make it work ?

Thanks in advance !

Consider using GraalVM

GraalVM would allow faster execution than JNI can provide and exported FMUs would not require a JVM to run.

How to use Jars

HI Lars!I generated some JAR packages using the command (./gradlew installDist), but I don't know how to use it. Could you please provide me with an example or some operation description?Thanks!

Incorrect initialization sequence of FMI 1.0 slaves

The FMI 2.0 initialization flow goes like this:

  • fmi2Instantiate()
  • fmi2SetupExperiment()
  • fmi2EnterInitializationMode()
  • fmi2SetXXX()
  • fmi2ExitInitializationMode()

while for FMI 1.0, the flow goes like this:

  • fmiInstantiateSlave()
  • fmiSetXXX()
  • fmiInitializeSlave()

FMI4J's fmi-import initialization sequence is based on FMI 2.0, with separate functions [setup(), enterInitializationMode(), exitInitializationMode()] which are adapted to the FMI 1.0 intialization sequence. For FMI 1.0 slaves, in order to allow calls to setXXX() BEFORE fmiInitializeSlave() is called, the call to fmiInitializeSlave() should be moved from setup() to exitInitializationMode().

Strict mode

Make it possible to enable/disable strict mode.
In strict mode, a call not compliant withthe state machine defined by the standard will fail fast

v0.19.0 can't be built by jitpack

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':fmi-native:compileReleaseLinuxX86-64Cpp'.

No tool chain is available to build C++ for host operating system 'Linux' architecture 'x86-64':
- Tool chain 'visualCpp' (Visual Studio):
- Visual Studio is not available on this operating system.
- Tool chain 'gcc' (GNU GCC):
- Could not find C++ compiler 'g++' in system path.
- Tool chain 'clang' (Clang):
- Could not find C++ compiler 'clang++' in system path.

Create Gradle plugin for FMUs

Create a plugin which automatically generates source code for an FMU

A FMU named "ControlledTemperature.fmu" which is located in src/main/fmu" will have a class file ControlledTemperature.kt with named getters and setter for all variables.

This is similar to Fmu2Jar expect that it will be MUCH easier to use.

Unable to delete JNI shared libraries

After loading the library with System.loadLibrary(...) the file cannot be deleted as long as the JVM is alive. Shutdownhooks are no good either..

Apparently you may delete such files if you load it using a custom classloader. When it gets garbage collected, you may delete it.

Clean directory structure

Need to cleanup the directory structure a bit

Split directories into lib, tools, benchmark, doc
move fmu2jar, gradle-plugin and crosscheck to independent folders inside /tools

canBeInstantiatedOnlyOncePerProcess

The current approach is to reload the shared library if canBeInstantiatedOnlyOncePerProcess=true, otherwise re-use it.

Apparently this approach is flawed and won't work.

Discontinue driver

In order to keep this maintainable, I've decided to remove the driver application.

Pass log output back to the JVM

Currently, logging data is output on the JNI side. It would be nice to pass this back to the JVM side so that we can unify the logging output.

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.