fmi_schema/fmi2/
interface_type.rs1use crate::traits::FmiInterfaceType;
2
3#[derive(Default, Debug, hard_xml::XmlRead, hard_xml::XmlWrite)]
4#[xml(tag = "File", strict(unknown_attribute, unknown_element))]
5pub struct File {
6 #[xml(attr = "name")]
9 pub name: String,
10}
11
12#[derive(Default, Debug, hard_xml::XmlRead, hard_xml::XmlWrite)]
13#[xml(tag = "SourceFiles", strict(unknown_attribute, unknown_element))]
14pub struct SourceFiles {
15 #[xml(child = "File")]
16 pub files: Vec<File>,
17}
18
19#[derive(Default, Debug, hard_xml::XmlRead, hard_xml::XmlWrite)]
22#[xml(tag = "ModelExchange", strict(unknown_attribute, unknown_element))]
23pub struct ModelExchange {
24 #[xml(attr = "modelIdentifier")]
26 pub model_identifier: String,
27
28 #[xml(attr = "needsExecutionTool")]
31 pub needs_execution_tool: Option<bool>,
32
33 #[xml(attr = "completedIntegratorStepNotNeeded")]
34 pub completed_integrator_step_not_needed: Option<bool>,
35
36 #[xml(attr = "canBeInstantiatedOnlyOncePerProcess")]
37 pub can_be_instantiated_only_once_per_process: Option<bool>,
38
39 #[xml(attr = "canNotUseMemoryManagementFunctions")]
40 pub can_not_use_memory_management_functions: Option<bool>,
41
42 #[xml(attr = "canGetAndSetFMUstate")]
43 pub can_get_and_set_fmu_state: Option<bool>,
44
45 #[xml(attr = "canSerializeFMUstate")]
46 pub can_serialize_fmu_state: Option<bool>,
47
48 #[xml(attr = "providesDirectionalDerivative")]
51 pub provides_directional_derivative: Option<bool>,
52
53 #[xml(child = "SourceFiles")]
57 pub source_files: Option<SourceFiles>,
58}
59
60#[derive(Default, Debug, hard_xml::XmlRead, hard_xml::XmlWrite)]
61#[xml(tag = "CoSimulation", strict(unknown_attribute, unknown_element))]
62pub struct CoSimulation {
63 #[xml(attr = "modelIdentifier")]
65 pub model_identifier: String,
66
67 #[xml(attr = "needsExecutionTool")]
70 pub needs_execution_tool: Option<bool>,
71
72 #[xml(attr = "canHandleVariableCommunicationStepSize")]
73 pub can_handle_variable_communication_step_size: Option<bool>,
74
75 #[xml(attr = "canInterpolateInputs")]
76 pub can_interpolate_inputs: Option<bool>,
77
78 #[xml(attr = "maxOutputDerivativeOrder")]
79 pub max_output_derivative_order: Option<u32>,
80
81 #[xml(attr = "canRunAsynchronuously")]
82 pub can_run_asynchronuously: Option<bool>,
83
84 #[xml(attr = "canBeInstantiatedOnlyOncePerProcess")]
85 pub can_be_instantiated_only_once_per_process: Option<bool>,
86
87 #[xml(attr = "canNotUseMemoryManagementFunctions")]
88 pub can_not_use_memory_management_functions: Option<bool>,
89
90 #[xml(attr = "canGetAndSetFMUstate")]
91 pub can_get_and_set_fmu_state: Option<bool>,
92
93 #[xml(attr = "canSerializeFMUstate")]
94 pub can_serialize_fmu_state: Option<bool>,
95
96 #[xml(attr = "providesDirectionalDerivative")]
98 pub provides_directional_derivative: Option<bool>,
99
100 #[xml(child = "SourceFiles")]
104 pub source_files: Option<SourceFiles>,
105}
106
107impl FmiInterfaceType for ModelExchange {
108 fn model_identifier(&self) -> &str {
109 &self.model_identifier
110 }
111 fn needs_execution_tool(&self) -> Option<bool> {
112 self.needs_execution_tool
113 }
114 fn can_be_instantiated_only_once_per_process(&self) -> Option<bool> {
115 self.can_be_instantiated_only_once_per_process
116 }
117 fn can_get_and_set_fmu_state(&self) -> Option<bool> {
118 self.can_get_and_set_fmu_state
119 }
120 fn can_serialize_fmu_state(&self) -> Option<bool> {
121 self.can_serialize_fmu_state
122 }
123 fn provides_directional_derivatives(&self) -> Option<bool> {
124 self.provides_directional_derivative
125 }
126 fn provides_adjoint_derivatives(&self) -> Option<bool> {
127 None
128 }
129 fn provides_per_element_dependencies(&self) -> Option<bool> {
130 None
131 }
132}
133
134impl FmiInterfaceType for CoSimulation {
135 fn model_identifier(&self) -> &str {
136 &self.model_identifier
137 }
138 fn needs_execution_tool(&self) -> Option<bool> {
139 self.needs_execution_tool
140 }
141 fn can_be_instantiated_only_once_per_process(&self) -> Option<bool> {
142 self.can_be_instantiated_only_once_per_process
143 }
144 fn can_get_and_set_fmu_state(&self) -> Option<bool> {
145 self.can_get_and_set_fmu_state
146 }
147 fn can_serialize_fmu_state(&self) -> Option<bool> {
148 self.can_serialize_fmu_state
149 }
150 fn provides_directional_derivatives(&self) -> Option<bool> {
151 self.provides_directional_derivative
152 }
153 fn provides_adjoint_derivatives(&self) -> Option<bool> {
154 None
155 }
156 fn provides_per_element_dependencies(&self) -> Option<bool> {
157 None
158 }
159}
160
161#[cfg(test)]
162mod tests {
163 use hard_xml::XmlRead;
164
165 use crate::fmi2::ModelExchange;
166
167 #[test]
168 fn test_model_exchange() {
169 let s = r##"<ModelExchange modelIdentifier="MyLibrary_SpringMassDamper"/>"##;
170 let me = ModelExchange::from_str(s).unwrap();
171 assert!(me.model_identifier == "MyLibrary_SpringMassDamper");
172 }
173}