fmi_schema/fmi2/
interface_type.rs

1use yaserde_derive::{YaDeserialize, YaSerialize};
2
3#[derive(Default, Debug, YaSerialize, YaDeserialize)]
4#[yaserde(tag = "File")]
5pub struct File {
6    /// Name of the file including the path relative to the sources directory, using the forward
7    /// slash as separator (for example: name = "myFMU.c"; name = "modelExchange/solve.c")
8    #[yaserde(attribute = true)]
9    pub name: String,
10}
11
12#[derive(Default, Debug, YaSerialize, YaDeserialize)]
13#[yaserde(tag = "SourceFiles")]
14pub struct SourceFiles {
15    #[yaserde(rename = "File")]
16    pub files: Vec<File>,
17}
18
19/// The FMU includes a model or the communication to a tool that provides a model. The environment
20/// provides the simulation engine for the model.
21#[derive(Default, Debug, YaSerialize, YaDeserialize)]
22pub struct ModelExchange {
23    /// Short class name according to C-syntax
24    #[yaserde(attribute = true, rename = "modelIdentifier")]
25    pub model_identifier: String,
26
27    /// If true, a tool is needed to execute the model and the FMU just contains the communication
28    /// to this tool.
29    #[yaserde(attribute = true, rename = "needsExecutionTool")]
30    pub needs_execution_tool: Option<bool>,
31
32    #[yaserde(attribute = true, rename = "completedIntegratorStepNotNeeded")]
33    pub completed_integrator_step_not_needed: Option<bool>,
34
35    #[yaserde(attribute = true, rename = "canBeInstantiatedOnlyOncePerProcess")]
36    pub can_be_instantiated_only_once_per_process: Option<bool>,
37
38    #[yaserde(attribute = true, rename = "canNotUseMemoryManagementFunctions")]
39    pub can_not_use_memory_management_functions: Option<bool>,
40
41    #[yaserde(attribute = true, rename = "canGetAndSetFMUstate")]
42    pub can_get_and_set_fmu_state: Option<bool>,
43
44    #[yaserde(attribute = true, rename = "canSerializeFMUstate")]
45    pub can_serialize_fmu_state: Option<bool>,
46
47    /// If true, the directional derivative of the equations can be computed with
48    /// fmi2GetDirectionalDerivative
49    #[yaserde(attribute = true, rename = "providesDirectionalDerivative")]
50    pub provides_directional_derivative: Option<bool>,
51
52    /// List of source file names that are present in the "sources" directory of the FMU and need
53    /// to be compiled in order to generate the binary of the FMU (only meaningful for source
54    /// code FMUs).
55    #[yaserde(rename = "SourceFiles")]
56    pub source_files: Option<SourceFiles>,
57}
58
59#[derive(Default, Debug, YaSerialize, YaDeserialize)]
60pub struct CoSimulation {
61    /// Short class name according to C-syntax
62    #[yaserde(attribute = true, rename = "modelIdentifier")]
63    pub model_identifier: String,
64
65    /// If true, a tool is needed to execute the model and the FMU just contains the communication
66    /// to this tool.
67    #[yaserde(attribute = true, rename = "needsExecutionTool")]
68    pub needs_execution_tool: Option<bool>,
69
70    #[yaserde(attribute = true, rename = "canHandleVariableCommunicationStepSize")]
71    pub can_handle_variable_communication_step_size: Option<bool>,
72
73    #[yaserde(attribute = true, rename = "canInterpolateInputs")]
74    pub can_interpolate_inputs: Option<bool>,
75
76    #[yaserde(attribute = true, rename = "maxOutputDerivativeOrder")]
77    pub max_output_derivative_order: Option<u32>,
78
79    #[yaserde(attribute = true, rename = "canRunAsynchronuously")]
80    pub can_run_asynchronuously: Option<bool>,
81
82    #[yaserde(attribute = true, rename = "canBeInstantiatedOnlyOncePerProcess")]
83    pub can_be_instantiated_only_once_per_process: Option<bool>,
84
85    #[yaserde(attribute = true, rename = "canNotUseMemoryManagementFunctions")]
86    pub can_not_use_memory_management_functions: Option<bool>,
87
88    #[yaserde(attribute = true, rename = "canGetAndSetFMUstate")]
89    pub can_get_and_set_fmu_state: Option<bool>,
90
91    #[yaserde(attribute = true, rename = "canSerializeFMUstate")]
92    pub can_serialize_fmu_state: Option<bool>,
93
94    /// Directional derivatives at communication points
95    #[yaserde(attribute = true, rename = "providesDirectionalDerivative")]
96    pub provides_directional_derivative: Option<bool>,
97
98    /// List of source file names that are present in the "sources" directory of the FMU and need
99    /// to be compiled in order to generate the binary of the FMU (only meaningful for source
100    /// code FMUs).
101    #[yaserde(rename = "SourceFiles")]
102    pub source_files: Option<SourceFiles>,
103}
104
105#[cfg(test)]
106mod tests {
107    use crate::fmi2::ModelExchange;
108
109    #[test]
110    fn test_model_exchange() {
111        let s = r##"<ModelExchange modelIdentifier="MyLibrary_SpringMassDamper"/>"##;
112        let me: ModelExchange = yaserde::de::from_str(s).unwrap();
113        assert!(me.model_identifier == "MyLibrary_SpringMassDamper");
114    }
115}