fmi 0.6.1

A Rust interface to FMUs (Functional Mockup Units) that follow the FMI Standard. See http://www.fmi-standard.org/
Documentation

fmi

A Rust interface to FMUs (Functional Mockup Units) that follow the FMI Standard.

See http://www.fmi-standard.org

Importing FMUs

The fmi crate implements a Rust interface to FMUs (Functional Mockup Units) that follow the FMI Standard. This version of the library supports FMI 2.0 and 3.0.

Loading an FMI 2.0 FMU

use fmi::{fmi2::import::Fmi2Import, import, traits::{FmiImport, FmiInstance}};

// Load an FMU from a file path
let import: Fmi2Import = import::from_path("path/to/model.fmu").unwrap();
assert_eq!(import.model_description().fmi_version, "2.0");

// Create a Model Exchange instance
let me = import.instantiate_me("inst1", false, true).unwrap();
assert_eq!(me.get_version(), "2.0");

Loading an FMI 3.0 FMU

use fmi::{fmi3::{import::Fmi3Import, Fmi3Model}, import, traits::{FmiImport, FmiInstance}};

// Load an FMU from a file path
let import: Fmi3Import = import::from_path("path/to/model.fmu").unwrap();
assert_eq!(import.model_description().fmi_version, "3.0");

// Create a Model Exchange instance
let me = import.instantiate_me("inst1", false, true).unwrap();
assert_eq!(me.get_version(), "3.0");

Checking FMU version before loading

use fmi::{import, schema::{MajorVersion, traits::FmiModelDescription}};

// Peek at the FMU metadata without fully extracting it
let model_desc = import::peek_descr_path("path/to/model.fmu").unwrap();
let version = model_desc.major_version().unwrap();
match version {
    MajorVersion::FMI2 => {
        // Load as FMI 2.0
        let import: fmi::fmi2::import::Fmi2Import = import::from_path("path/to/model.fmu").unwrap();
        // ... use import
    }
    MajorVersion::FMI3 => {
        // Load as FMI 3.0
        let import: fmi::fmi3::import::Fmi3Import = import::from_path("path/to/model.fmu").unwrap();
        // ... use import
    }
    _ => panic!("Unsupported FMI version"),
}

Exporting FMUs

For exporting FMUs, use the fmi-export crate, which provides the traits and helper types for building FMUs in Rust. See the fmi-export documentation on docs.rs.

See the fmi-export README for the step-by-step workflow and expected output paths.

Repository Structure

This repository is composed of the following crates:

Crate Description Latest API Docs README
fmi Core functionality for importing and executing FMUs docs.rs README
fmi-sys Raw generated Rust bindings to the FMI API docs.rs README
fmi-schema XML parsing of the FMU Model Description docs.rs README
fmi-sim Work-in-progress FMU Simulation master docs.rs README
fmi-test-data Reference FMUs for testing docs.rs README
fmi-export Types and traits necessary for exporting FMUs docs.rs README
fmi-export-derive Procedural macros for fmi-export docs.rs README
fmi-ls-bus FMI-LS-BUS support docs.rs README
fmi-xtask FMU export build tooling docs.rs README

Development

For development information, build instructions, and contribution guidelines, see DEVELOP.md.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.