Expand description
§fmi-export
A Rust interface to FMUs (Functional Mockup Units) that follow the FMI Standard. This crate provides necessary interfaces and utilities to construct FMUs.
This crate is part of rust-fmi.
See http://www.fmi-standard.org
§Quick start: Build an FMU
- Install the
cargo-fmisubcommand:
cargo install cargo-fmi- Create a new crate for your model using
cargo-fmi:
cargo fmi new my-modelThis will generate a cdylib crate with a sample model struct deriving FmuModel:
use fmi_export::FmuModel;
#[derive(FmuModel, Default, Debug)]
struct MyModel {
#[variable(causality = Output, start = 1.0)]
y: f64,
}The export_fmu! macro will generate the required FMI-API exports.
fmi_export::export_fmu!(MyModel);- Build and bundle the FMU with
cargo-fmi:
cargo fmi --package my-model bundle§Building FMUs
This repository builds FMI 3.0 FMUs from pure Rust code, and is driven by the FmuModel
derive macro.
The FMI API interfacing boilerplate is generated, and automated packaging is handled by the
cargo-fmi subcommand.
§Minimal FMU setup
Your FMU crate must:
- Be a
cdylib:
[lib]
crate-type = ["cdylib"]- Derive
FmuModelfor your model struct - Export FMI symbols via
export_fmu!
Example skeleton:
use fmi_export::FmuModel;
#[derive(FmuModel, Default, Debug)]
struct MyModel {
#[variable(causality = Output, start = 1.0)]
y: f64,
}
fmi_export::export_fmu!(MyModel);§Build an example FMU (this repo)
From the repository root:
cargo fmi --package can-triggered-output bundleThe FMU zip is written to:
target/fmu/<model_identifier>.fmu<model_identifier> is the Rust cdylib target name (for can-triggered-output, this is
can_triggered_output).
§Common options
- Build a release FMU:
cargo fmi --package can-triggered-output bundle --release- Build for a specific target:
cargo fmi --package can-triggered-output bundle --target x86_64-unknown-linux-gnu§Building FMUs from Modelica models
Using the rumoca crate, fmi-export can generate
Rust code from Modelica models.
The template can be used directly via Rumoca, but the primary workflow is to enable
the rumoca feature in fmi-export and call its helper API from build.rs.
§Quick Start
- Add
fmi-exportwith therumocafeature to yourCargo.toml:
[build-dependencies]
fmi-export = { version = "0.1.1", features = ["rumoca"] }- Invoke the Rumoca compiler in your crates’
build.rs:
let model_path = std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap())
.join("src/model.mo");
println!("cargo:rerun-if-changed={}", model_path.display());
fmi_export::rumoca::write_modelica_to_out_dir("MyModel", &model_path)
.expect("render model.mo");Direct Rumoca usage is also supported (path shown is for this repo checkout):
rumoca model.mo -m MyModel --template-file fmi-export/templates/rust-fmi.jinja > my_fmu_crate/src/lib.rsIf you’re outside this repo, point --template-file at a local copy of
rust-fmi.jinja from the fmi-export/templates directory.
See templates/README.md and the examples for further details.
§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
fmi3(enabled by default) — Enable support for FMI 3.0rumoca— Enable support for Rumoca-based Modelica compilation
Modules§
- fmi3
- Architecture
Macros§
- checked_
deref_ cs - Safely dereferences an FMI instance pointer for Co-Simulation instances with wrapper context.
- checked_
deref_ me - Safely dereferences an FMI instance pointer for Model Exchange instances.
- dispatch_
by_ instance_ type - Dispatches a method call based on the runtime instance_type. This is used for Common trait methods that must work for any instance type (ME/CS/SE).
- export_
fmu - Main macro for exporting an FMI 3.0 model as a shared library.
- generate_
getset_ functions - Generates getter and setter functions for FMI3 data types.
- wrapper_
getset_ functions
Derive Macros§
- FmuModel
- FmuModel derive reference