Skip to content

Commit

Permalink
Change the order of the variables added to the modelDescription to be…
Browse files Browse the repository at this point in the history
… sorted by their variableReference
  • Loading branch information
KristofferSkare committed Dec 19, 2024
1 parent d142bb9 commit a5c0a2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The changelog format is based on [Keep a Changelog](https://keepachangelog.com/e
### Changed

* Generation of modelDescription.xml file to correctly generate tags for each output with 1-indexed indexes and InitialUnknowns tags
* Generation of modelDescription.xml adds the variables (inputs, parameters and outputs) in the orderer of their valueReference. This is for the indexing to work correctly

## [1.0.2]

Expand Down
9 changes: 8 additions & 1 deletion src/mlfmu/utils/fmi_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ def generate_model_description(fmu_model: FmiModel) -> ElementTree:
outputs = SubElement(model_structure, "Outputs")
initial_unknowns = SubElement(model_structure, "InitialUnknowns")

for var in fmu_model.get_fmi_model_variables():
# Get all variables to add them inside the <ModelVariables> tag
model_variables = fmu_model.get_fmi_model_variables()

# The variables needs to be added in the order of their valueReference
sorted_model_variables = sorted(model_variables, key=lambda x: x.variable_reference)

# Add each variable inside the <ModelVariables> tag
for var in sorted_model_variables:
# XML variable attributes
var_attrs = {
"name": var.name,
Expand Down

0 comments on commit a5c0a2a

Please sign in to comment.