fmu_runner/lib.rs
1//! A high level Rust wrapper for executing FMU's that follow the FMI 2.0 standard.
2//!
3//! This library contains bindings to the [fmi-standard](https://fmi-standard.org/)
4//! and offers a high-level, safe API for unpacking, parsing, loading and executing FMU's.
5//!
6//! # Example
7//!
8//! ```
9//! use std::{collections::HashMap, path::Path};
10//! use fmu_runner::{Fmu, FmuInstance, fmi2Type};
11//!
12//! let fmu = Fmu::unpack(Path::new("./tests/fmu/bouncing_ball.fmu"))?
13//! .load(fmi2Type::fmi2CoSimulation)?;
14//!
15//! let fmu_cs = FmuInstance::instantiate(&fmu, true)?;
16//! let signals = fmu_cs.lib.variables();
17//!
18//! fmu_cs.setup_experiment(0.0, None, None)?;
19//!
20//! // Set initial height to 10m.
21//! fmu_cs.set_reals(&HashMap::from([(&signals["h_start"], 10.0)]))?;
22//!
23//! // Initialize model.
24//! fmu_cs.enter_initialization_mode()?;
25//! fmu_cs.exit_initialization_mode()?;
26//!
27//! // Step model 1 second.
28//! fmu_cs.do_step(0.0, 1.0, true)?;
29//!
30//! // Get the current height.
31//! let outputs = fmu_cs.get_reals(&[&signals["h_m"]])?;
32//! println!("{}", fmu_runner::outputs_to_string(&outputs));
33//! # Ok::<(), Box<dyn std::error::Error>>(())
34//! ```
35
36mod fmu;
37pub mod model_description;
38
39pub use fmu::*;
40pub use libfmi::fmi2Type;