Skip to main content

Crate fmi

Crate fmi 

Source
Expand description

§fmi

github crates.io docs.rs build status codecov

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:

CrateDescriptionLatest API DocsREADME
fmiCore functionality for importing and executing FMUsdocs.rsREADME
fmi-sysRaw generated Rust bindings to the FMI APIdocs.rsREADME
fmi-schemaXML parsing of the FMU Model Descriptiondocs.rsREADME
fmi-simWork-in-progress FMU Simulation masterdocs.rsREADME
fmi-test-dataReference FMUs for testingdocs.rsREADME
fmi-exportTypes and traits necessary for exporting FMUsdocs.rsREADME
fmi-export-deriveProcedural macros for fmi-exportdocs.rsREADME
fmi-ls-busFMI-LS-BUS supportdocs.rsREADME
fmi-xtaskFMU export build toolingdocs.rsREADME

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

§Feature flags

  • fmi2 (enabled by default) — Enable support for FMI 2.0
  • fmi3 (enabled by default) — Enable support for FMI 3.0
  • ls-bus (enabled by default) — Enable support for fmi-ls-bus
  • ls-bus-can (enabled by default) — Enable support for fmi-ls-bus with CAN support
  • arrow — Enable support for Apache Arrow Schema

Re-exports§

pub use fmi_schema as schema;

Modules§

built_info
fmi2fmi2
FMI 2.0 API
fmi3fmi3
FMI 3.0 API
import
FMU Import Module
traits
Traits for generic FMI handling that apply to both FMI2 and FMI3.

Structs§

CS
Tag for Co-Simulation
EventFlags
Event flags used in calls to crate::traits::FmiEventHandler::update_discrete_states / newDiscreteStates (FMI 2.0 C API).
ME
Tag for Model Exchange
SE
Tag for Scheduled Execution

Enums§

Error
InterfaceType