Skip to content
/ FMI4j Public
forked from NTNU-IHB/FMI4j

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

License

Notifications You must be signed in to change notification settings

jfulem/FMI4j

 
 

Repository files navigation

FMI4j

License: MIT contributions welcome

CircleCI

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

Export of FMI 2.0 for Co-simulation is also 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. For FMI-export FMI4j is multiple orders of magnitude faster than any existing open source alternative.


Artifacts are available through Bintray.

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 stop = 10;
        double stepSize = 1.0/100;
        while(slave.getSimulationTime() <= stop) {
            if (!slave.doStep(stepSize)) {
                break;
            }
        }
        slave.terminate(); //or close, try with resources is also supported
        fmu.close(); // <- also done automatically by the library if you forget to do it yourself
        
    }
    
}

FMI export

Write the code
@SlaveInfo(
        modelName = "JavaSlave",
        author = "John Doe"
)
public class JavaSlave extends Slave {

    @ScalarVariable(causality = Fmi2Causality.output)
    protected double realOut = 2.0;

    @ScalarVariable(causality = Fmi2Causality.output)
    protected int intOut = 99;

    @ScalarVariable(causality = Fmi2Causality.output)
    protected double[] realsOut = {50.0, 200.0};

    @ScalarVariable(causality = Fmi2Causality.local)
    protected String[] string = {"Hello", "world!"};

    public JaveSlave(String instanceName) {
        super(instanceName);
    }   

    @Override
    public void doStep(double currentTime, double dt) {
        realOut += dt;
    }

}
Build the FMU
Usage: fmu-builder [-h] [-d=<destFile>] -f=<jarFile> -m=<mainClass>
  -d, --dest=<destFile>    Where to save the FMU.
  -f, --file=<jarFile>     Path to the Jar.
  -h, --help               Print this message and quits.
  -m, --main=<mainClass>   Fully qualified name if the main class.

Would you rather 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!

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 42.2%
  • Kotlin 35.8%
  • C++ 14.6%
  • C 7.4%