fmi

    A MoonBit interface to FMI-compliant FMUs.

    Download zip
    Author
    Version
    0.9.1
    License
    Apache-2.0
    Last updated
    4 days ago
    Downloads
    90

    #MoonFMI

    English | 简体中文

    MoonFMI is an FMI toolchain built with MoonBit: it ships the moonfmi command-line tool and the MoonBit libraries behind it, for running and checking FMUs that follow FMI 2.0.4 or 3.0.2.

    #Features

    • Check an FMU without loading its binary: validate the model description, print a summary, and list problems, including archives that carry WebAssembly components.
    • Run Co-Simulation, Model Exchange, and FMI 3 Scheduled Execution, with CSV or JSON output.
    • Couple several FMUs into one co-simulation, with typed signal connections, FMI 3 clock connections, and algebraic-loop solving.
    • Build a deterministic .fmu and export restricted explicit models as source-code or experimental WebAssembly FMUs.
    • Guard a run: verify the archive digest before loading, isolate a crash in a child process, and enforce a watchdog timeout.
    • Use the same code as a MoonBit library.

    #Install

    Requires the MoonBit toolchain at version 1.0 (currently the 1.0 release candidate; see the installation guide) and a C compiler: moon builds the bundled native shims.

    moon add MuVirus/fmi

    To work from a checkout instead:

    git clone https://github.com/MuVirus/MoonFMI.git cd MoonFMI moon build --target native

    The built binary lands under _build/native/release/build/cmd/main/; moon run cmd/main --target native -- --help works without a separate build. The mooncakes module is MuVirus/fmi; the repository keeps the MoonFMI name.

    #Minimal example

    From a checkout, fetch the Reference-FMUs used by the examples and the tests (BSD-2-Clause):

    moon run tests/data/fetch-fmus.mbtx --target native

    Run the bouncing-ball model for three seconds:

    moon run cmd/main --target native -- simulate tests/data/.cache/fmi2/BouncingBall.fmu \ --stop-time 3 --step-size 0.01 --output ball.csv

    ball.csv then holds the 300 steps: a time,h,v header plus 301 sample rows (t from 0 to 3).

    #Usage

    Validate and inspect a model description without running it:

    moon run cmd/main --target native -- validate tests/data/.cache/fmi2/BouncingBall.fmu moon run cmd/main --target native -- info tests/data/.cache/fmi2/BouncingBall.fmu

    Model Exchange uses the same entry point, and FMI 3 is detected automatically:

    moon run cmd/main --target native -- simulate tests/data/.cache/fmi2/VanDerPol.fmu \ --interface me --solver rk4 --stop-time 5 --output vdp.csv

    Build a deterministic .fmu from an unpacked directory:

    moon run cmd/main --target native -- package build/MyModel --output MyModel.fmu

    moonfmi doctor checks the local environment, and moonfmi --help lists every command and exit code. Add --json for machine-readable output; the shapes are versioned contracts in docs/cli-json.md. Before loading a model, --sha256 checks the archive digest, and --sandbox runs the command in a crash-isolated child process with a timeout. simulate and couple also read settings from a JSON, INI, or .env file (--config), from environment variables, or from the command line; the command line overrides the environment, and the environment overrides the file. Keys and environment variable names are documented in examples/README.md.

    #Use as a library

    The packages under src/ are ordinary MoonBit packages; build with --target native and import only what you need from MuVirus/fmi/src/{fmi,sim,backend/native}. The runnable examples — validation, CS, ME, coupling, and export — use nothing but the public API: examples/.

    #Known limits

    • Model Exchange integrates with fixed-step Euler or classic RK4 by default; the library also ships an adaptive RKF45 mode (MeConfig.adaptive), which the moonfmi --solver flag does not expose yet. MoonFMI is not a general-purpose ME solver: stiff systems and large DAEs are out of scope (docs/design/master-algorithm.md).
    • Algebraic loops in a coupled system are solved by iteration; when an FMU cannot restore state, the result is approximate (docs/design/coupling.md).
    • Scheduled Execution gives no real-time guarantee: clock priority only orders activations at the same instant.
    • The source-FMU exporter emits restricted explicit models, not Modelica: continuous states, feedthrough outputs, parameters, and inputs (docs/design/exporter.md).
    • The WebAssembly backend is experimental: archives are validated, but no component executes yet (tests/fmu-wasm/README.md).
    • --sandbox gives crash isolation and a watchdog, not a permission sandbox: the FMU still runs with the host user's rights (docs/design/security-review.md).

    #Documentation

    Licensed under Apache-2.0.

    Source Files