Skip to content

Framework for exporting JVM code to co-simulation FMUs compatible with FMI 2.0.

License

Notifications You must be signed in to change notification settings

Ecos-platform/FMU4j

Repository files navigation

FMU4j

FMU4j is a software package for the JVM that enables export of models compatible with FMI 2.0 for Co-simulation.

Linux and Windows are supported.

Note that Python 3.7 < is known to cause issues on Windows. FMUs might not work in that environment.

Get started using this template repository.

JFrog artifactory

Artifacts are available through JFrog artifactory.

repositories {
    maven { url "https://ais.jfrog.io/artifactory/ais-gradle-dev-local/"} // SNAPSHOTS
    maven { url "https://ais.jfrog.io/artifactory/ais-gradle-release-local/"} // STABLE
}

dependencies {
    def fmu4j_version = "..."
    implementation "no.ntnu.ais.fmu4j:fmi-export:$version" // FMI skeleton
    implementation "no.ntnu.ais.fmu4j:fmi-builder:$version" // FMU generation from code
}

Write the code
@SlaveInfo(
        modelName = "MyJavaSlave",
        author = "John Doe"
)
public class JavaSlave extends Fmi2Slave {
    
    @ScalarVariable
    private int intOut = 99;
    @ScalarVariable
    private double realOut = 2.0;
    @ScalarVariable
    private double[] realsOut = {50.0, 200.0};
    @ScalarVariable
    private String[] string = {"Hello", "world!"};
    
    private ComplexObject obj = ComplexObject();
    
    public JavaSlave(Map<String, Object> args) {
        super(args);
    }

    @Override
    protected void registerVariables() {
        register(integer("complexInt", () -> obj.integer)
                .causality(Fmi2Causality.output));
        register(real("complexReal", () -> obj.real)
                .causality(Fmi2Causality.output));
    }

    @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 of the main class.

In order to build the fmu-builder tool, clone this repository and invoke ./gradlew installDist. The distribution will be located in the folder fmu-builder-app/build/install.

Note that the produced Jar file must be a fatJar/shadowJar.

jar {
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

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!
Need a complete co-simulation framework with SSP support? Check out Vico

About

Framework for exporting JVM code to co-simulation FMUs compatible with FMI 2.0.

Topics

Resources

License

Stars

Watchers

Forks