Expand description
§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
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
§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.0fmi3(enabled by default) — Enable support for FMI 3.0ls-bus(enabled by default) — Enable support for fmi-ls-busls-bus-can(enabled by default) — Enable support for fmi-ls-bus with CAN supportarrow— Enable support for Apache Arrow Schema
Re-exports§
pub use fmi_schema as schema;
Modules§
- built_
info - fmi2
fmi2 - FMI 2.0 API
- fmi3
fmi3 - 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
- Event
Flags - 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