FMU Wrappers¶
FMU wrapper classes for FMI 2.0 and FMI 3.0.
This module contains the FMU handler classes for FMI 2.0 and FMI 3.0. These classes are used to load FMU files and interact with loaded FMUs.
Fmu2Handler ¶
Fmu2Handler(path, fmu_slave)
Bases: FmuXHandler
Handler class for FMU in FMI version 2.0.
Source code in cofmpy/wrappers.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
reset ¶
reset()
Resets the FMU to its initial state and sets up the experiment.
Source code in cofmpy/wrappers.py
308 309 310 311 312 |
|
step ¶
step(current_time, step_size, input_dict)
Performs a simulation step with the given current time, step size, and input values.
PARAMETER | DESCRIPTION |
---|---|
current_time
|
the current simulation time.
TYPE:
|
step_size
|
the size of the simulation step.
TYPE:
|
input_dict
|
dictionary containing input variable names and their corresponding values.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
Dictionary containing output variable names and their corresponding values after the simulation step. |
Source code in cofmpy/wrappers.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
Fmu3Handler ¶
Fmu3Handler(path, fmu_slave)
Bases: FmuXHandler
Handler class for FMU in FMI version 3.0.
Source code in cofmpy/wrappers.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
reset ¶
reset()
Resets the FMU to its initial state
Source code in cofmpy/wrappers.py
367 368 369 370 |
|
step ¶
step(current_time, step_size, input_dict)
Performs a simulation step with the given current time, step size, and input values.
PARAMETER | DESCRIPTION |
---|---|
current_time
|
the current simulation time.
TYPE:
|
step_size
|
the size of the simulation step.
TYPE:
|
input_dict
|
dictionary containing input variable names and their corresponding values.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
Dictionary containing output variable names and their corresponding values after the simulation step. |
Source code in cofmpy/wrappers.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
|
FmuHandlerFactory ¶
FmuHandlerFactory(path)
Factory class to create FMU handlers based on the FMI version.
ATTRIBUTE | DESCRIPTION |
---|---|
path |
The file path to the FMU.
TYPE:
|
description |
The model description of the FMU.
|
METHOD | DESCRIPTION |
---|---|
__call__ |
Creates and returns an FMU handler based on the FMI version. |
Initializes the FmuHandlerFactory with the given path and reads the model description.
PARAMETER | DESCRIPTION |
---|---|
path
|
The file path to the FMU.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
FmuXHandler
|
The appropriate FMU handler based on the FMI version.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the FMI version is not recognized. |
Source code in cofmpy/wrappers.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
FmuXHandler ¶
FmuXHandler(path, fmu_slave)
Bases: ABC
Abstract base class for handling FMU Slave objects (FMI 2.0 or FMI 3.0).
ATTRIBUTE | DESCRIPTION |
---|---|
description |
The model description of the FMU.
TYPE:
|
var_name2attr |
A dictionary mapping variable names to their attributes.
TYPE:
|
fmu |
The FMU instance.
TYPE:
|
output_var_names |
A list of output variable names.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
reset |
Abstract method to reset the FMU. Must be implemented by subclasses. |
step |
Abstract method to perform a simulation step. Must be implemented by subclasses. |
cancel_step |
Cancels the current step of the FMU. |
get_state |
Retrieves the current state of the FMU. |
set_state |
Sets the state of the FMU to the given state. |
get_output_names |
Retrieves the names of the FMU output variables. |
get_input_names |
Retrieves the names of the FMU input variables. |
get_parameter_names |
Retrieves the names of the FMU tunable parameters. |
Initializes the FMU handler with the given path and FMU slave class.
PARAMETER | DESCRIPTION |
---|---|
path
|
The path of .fmu file to open
TYPE:
|
fmu_slave
|
The FMU slave class of FMPy to use to open the fmu
TYPE:
|
Source code in cofmpy/wrappers.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
cancel_step ¶
cancel_step()
Cancels the current step of the FMU.
Source code in cofmpy/wrappers.py
238 239 240 |
|
get_causality ¶
get_causality(name)
Retrieves the causality of a variable.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the variable to get
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The causality of the variable
TYPE:
|
Source code in cofmpy/wrappers.py
216 217 218 219 220 221 222 223 224 225 |
|
get_input_names ¶
get_input_names()
Retrieves the list of names of the FMU's input variables.
RETURNS | DESCRIPTION |
---|---|
list
|
A list containing the name of each input variable
TYPE:
|
Source code in cofmpy/wrappers.py
181 182 183 184 185 186 187 188 189 190 191 |
|
get_output_names ¶
get_output_names()
Retrieves the list of names of the FMU's output variables.
RETURNS | DESCRIPTION |
---|---|
list
|
A list containing the name of each output variable
TYPE:
|
Source code in cofmpy/wrappers.py
204 205 206 207 208 209 210 211 212 213 214 |
|
get_parameter_names ¶
get_parameter_names()
Retrieves the names of the FMU tunable parameters. Returns: list: A list containing the name of each tunable parameter
Source code in cofmpy/wrappers.py
193 194 195 196 197 198 199 200 201 202 |
|
get_state ¶
get_state()
Retrieves the current state of the FMU.
RETURNS | DESCRIPTION |
---|---|
fmiXFMUState
|
The current of state of the FMU, X is the version of FMI used (ie. fmi3FMUState for FMI3.0) |
Source code in cofmpy/wrappers.py
242 243 244 245 246 247 248 249 |
|
get_variable ¶
get_variable(name)
Gets the variable matching the given name.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the variable to get
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list
|
The value of the variable, as a list.
TYPE:
|
Source code in cofmpy/wrappers.py
265 266 267 268 269 270 271 272 273 274 275 276 |
|
get_variable_names ¶
get_variable_names()
Retrieves the names of all variables in the FMU.
RETURNS | DESCRIPTION |
---|---|
list
|
A list containing the name of each variable
TYPE:
|
Source code in cofmpy/wrappers.py
173 174 175 176 177 178 179 |
|
get_variable_type ¶
get_variable_type(name)
Retrieves the type of the variable with the given name.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the variable.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The type of the variable.
TYPE:
|
Source code in cofmpy/wrappers.py
227 228 229 230 231 232 233 234 235 236 |
|
get_variables ¶
get_variables(names)
Gets the values of the FMU variables matching the given names.
PARAMETER | DESCRIPTION |
---|---|
names
|
A list of variable names to get
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the variable names and their corresponding values
TYPE:
|
Source code in cofmpy/wrappers.py
161 162 163 164 165 166 167 168 169 170 171 |
|
reset
abstractmethod
¶
reset()
Resets the FMU to its initial state and sets up the experiment.
Source code in cofmpy/wrappers.py
278 279 280 281 |
|
set_state ¶
set_state(state)
Sets the state of the FMU to the given state.
PARAMETER | DESCRIPTION |
---|---|
state
|
The state of the FMU to set, X is the version of FMI used (ie. fmi3FMUState for FMI3.0)
TYPE:
|
Source code in cofmpy/wrappers.py
251 252 253 254 255 256 257 258 |
|
set_variables ¶
set_variables(input_dict)
Sets the FMU variables to the given values.
PARAMETER | DESCRIPTION |
---|---|
input_dict
|
A dictionary containing variable names and their corresponding values.
TYPE:
|
Source code in cofmpy/wrappers.py
151 152 153 154 155 156 157 158 159 |
|
step
abstractmethod
¶
step(current_time, step_size, input_dict)
Performs a simulation step with the given current time, step size, and input values.
Source code in cofmpy/wrappers.py
283 284 285 286 287 288 289 |
|