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.
See http://www.fmi-standard.org
Quick start: export an FMU
- Define a
cdylibmodel crate and deriveFmuModel:
use FmuModel;
- Export FMI symbols:
export_fmu!;
- Bundle the FMU with
xtask:
Building FMUs
This repository builds FMI 3.0 FMUs from pure Rust code. The FMI API interfacing boilerplate is generated with the
FmuModel derive macro. Automated packaging is handled by an xtask module.
Minimal FMU setup
Your FMU crate must:
- Be a
cdylib:
[]
= ["cdylib"]
- Derive
FmuModelfor your model struct - Export FMI symbols via
export_fmu!
Example skeleton:
use FmuModel;
export_fmu!;
Build an FMU (this repo)
From the repository root:
The 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:
- Build for a specific target:
FmuModel derive reference
Struct-level attributes
Use #[model(...)] on the struct to configure the generated FMI interfaces and
metadata.
Supported keys:
description: Optional string. Defaults to the struct docstring if omitted.model_exchange: Optional bool. Defaults totrue.co_simulation: Optional bool. Defaults tofalse.scheduled_execution: Optional bool. Defaults tofalse.user_model: Optional bool. Defaults totrue. Setfalseto provide your ownimpl UserModel.
Notes:
- All boolean flags must be explicit (
co_simulation = true). Shorthandco_simulationis rejected. #[model()]with no arguments is valid and uses the defaults above.
Field-level attributes
Use #[variable(...)] to include a field as an FMI variable. Use #[alias(...)]
for additional aliases. Both attributes accept the same keys.
Supported keys for #[variable(...)] and #[alias(...)]:
skip: Bool. Whentrue, the field is ignored for FMI variables.name: String. Overrides the variable name (defaults to the field name).description: String. Overrides the field docstring.causality: One ofParameter,CalculatedParameter,Input,Output,Local,Independent,Dependent,StructuralParameter.variability: One ofConstant,Fixed,Tunable,Discrete,Continuous.start: Rust expression used as the start value.initial: One ofExact,Calculated,Approx.derivative: Ident referencing another field. Marks this variable as the derivative of that field.event_indicator: Bool. Whentrue, counts toward the FMI event indicator total.interval_variability: One ofConstant,Fixed,Tunable,Changing,Countdown,Triggered.clocks: List of clock field idents that this variable belongs to.max_size: Integer. Max size for Binary variables.mime_type: String. MIME type for Binary variables.
Notes:
- Continuous state variables are inferred by
derivativerelationships. clocksmust reference clock variables in the same model. The generated FMU resolves these to value references.
Child components
Use #[child(...)] to reuse another FmuModel as a component and prefix its
variable names.
Supported keys:
prefix: Optional string. Defaults to the field name. Child variables are named<parent_prefix><prefix>.<child_variable>.
Notes:
- Child fields should implement the
Modeltrait (typically viaFmuModel). #[child]only affects naming and metadata; it does not change runtime behavior of the child component.
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.