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
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
reset ¶
reset()
Resets the FMU to its initial state and sets up the experiment.
Source code in cofmpy/wrappers.py
477 478 479 480 481 | |
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
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
Fmu3Handler ¶
Fmu3Handler(path, fmu_slave)
Bases: FmuXHandler
Handler class for FMU in FMI version 3.0.
Source code in cofmpy/wrappers.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
reset ¶
reset()
Resets the FMU to its initial state
Source code in cofmpy/wrappers.py
536 537 538 539 | |
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
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 | |
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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
FmuProxyHandler ¶
FmuProxyHandler(path)
Bases: FmuXHandler
A handler class that acts as a proxy for an FMU by delegating operations to a dynamically loaded proxy object. This class provides FMI-like behaviors and interfaces for interacting with the proxy. Attributes: _proxy: The dynamically loaded proxy object. fmu: Alias for the proxy object for compatibility with FmuXHandler. _time (float): Internal simulation time. description (ProxyModelDescription): A proxy model description compatible with FmuXHandler helpers. default_step_size (float): Default step size for the simulation. var_name2attr (Dict[str, ProxyVarAttr]): A mapping of variable names to their attributes. output_var_names (List[str]): A list of output variable names. Methods: reset(): Resets the internal simulation time to 0.0. get_variable(name: str) -> list: Retrieves the value of a variable by name as a single-element list. set_variables(input_dict: Dict[str, Any]): Sets multiple variables based on the provided dictionary of variable names and values. step(current_time: float, step_size: float, input_dict: Dict[str, Any]) -> Dict[str, Any]: Advances the simulation by a given step size, applying inputs before stepping and returning the output variables. get_state() -> Dict[str, Any]: Retrieves the current state of the simulation, including time and variable values, in a JSON-serializable format. set_state(state: Dict[str, Any]): Restores the simulation state from a given dictionary.
Initialize the wrapper class with a given proxy model file path.
Args:
path (str): The file path to the proxy model. This should be in the
format load_proxy_class_from_file or other
operations during initialization.
Source code in cofmpy/wrappers.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 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 403 404 | |
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
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
cancel_step ¶
cancel_step()
Cancels the current step of the FMU.
Source code in cofmpy/wrappers.py
254 255 256 | |
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
232 233 234 235 236 237 238 239 240 241 | |
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
197 198 199 200 201 202 203 204 205 206 207 | |
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
220 221 222 223 224 225 226 227 228 229 230 | |
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
209 210 211 212 213 214 215 216 217 218 | |
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
258 259 260 261 262 263 264 265 | |
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
281 282 283 284 285 286 287 288 289 290 291 292 | |
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
189 190 191 192 193 194 195 | |
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
243 244 245 246 247 248 249 250 251 252 | |
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
177 178 179 180 181 182 183 184 185 186 187 | |
reset
abstractmethod
¶
reset()
Resets the FMU to its initial state and sets up the experiment.
Source code in cofmpy/wrappers.py
294 295 296 297 | |
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
267 268 269 270 271 272 273 274 | |
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
167 168 169 170 171 172 173 174 175 | |
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
299 300 301 302 303 304 305 | |