Skip to content

Commit

Permalink
startTime and stopTime are deduced from 1st embedded FMU
Browse files Browse the repository at this point in the history
  • Loading branch information
nl78 committed Jan 14, 2025
1 parent daa2102 commit 9d8bef4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ This package was formerly known as `fmutool`.

## Version 1.8.2 (upcoming)
* FIXED: `fmucontainer` identifier (for coSimulation) does not contain ".fmu" anymore
* TODO: ADDED: take care of stoptime
* TODO: Expose parameters
* ADDED: GUI for `fmucontainer`
* ADDED: `fmucontainer` log more information when embedded FMU cannot be loaded
* ADDED: `fmucontainer` startTime and stopTime are deduced from 1st embedded FMU
* [ ] ADDED: `fmucontainer` support new option `-auto-parameters`
* [ ] ADDED: preliminary version of GUI for `fmucontainer`


## Version 1.8.1
* FIXED: `fmucontainer` read links from `.json` input files
Expand Down
20 changes: 17 additions & 3 deletions fmu_manipulation_toolbox/fmu_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def __init__(self, filename):

self.fmi_version = None
self.step_size = None
self.start_time = None
self.stop_time = None
self.model_identifier = None
self.guid = None
self.ports: Dict[str, FMUPort] = {}
Expand All @@ -103,12 +105,13 @@ def cosimulation_attrs(self, attrs: Dict[str, str]):
for capability in self.capability_list:
self.capabilities[capability] = attrs.get(capability, "false")

def experiment_attrs(self, attrs):
def experiment_attrs(self, attrs: Dict[str, str]):
try:
self.step_size = float(attrs['stepSize'])
except KeyError:
logger.warning(f"FMU '{self.name}' does not specify preferred step size")
pass
self.start_time = float(attrs.get("startTime", 0.0))
self.stop_time = float(attrs.get("stopTime", self.start_time + 1.0))

def scalar_type(self, type_name, attrs):
if self.current_port:
Expand Down Expand Up @@ -195,6 +198,9 @@ def __init__(self, identifier: str, fmu_directory: Union[str, Path], description

self.description_pathname = description_pathname

self.start_time = None
self.stop_time = None

# Rules
self.inputs: Dict[str, ContainerPort] = {}
self.outputs: Dict[str, ContainerPort] = {}
Expand Down Expand Up @@ -406,6 +412,14 @@ def make_fmu_xml(self, xml_file, step_size: float, profiling: bool):
if fmu.capabilities[capability] == "true":
capabilities[capability] = "true"

if self.start_time is None:
logger.info(f"start_time will be deduced from the _first_ embedded FMU's")
self.start_time = self.execution_order[0].start_time

if self.stop_time is None:
logger.info(f"stop_time will be deduced from the _first_ embedded FMU's")
self.stop_time = self.execution_order[0].stop_time

xml_file.write(f"""<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiModelDescription
fmiVersion="2.0"
Expand Down Expand Up @@ -434,7 +448,7 @@ def make_fmu_xml(self, xml_file, step_size: float, profiling: bool):
<Category name="fmucontainer"/>
</LogCategories>
<DefaultExperiment stepSize="{step_size}"/>
<DefaultExperiment stepSize="{step_size}" startTime="{self.start_time}" stopTime="{self.stop_time}"/>
<ModelVariables>
""")
Expand Down
1 change: 1 addition & 0 deletions tests/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,6 @@ def test_container_json_reversed(self):
self.assert_identical_files("containers/arch/REF-reversed-dump.json",
"containers/arch/reversed-dump.json")


if __name__ == '__main__':
unittest.main()

0 comments on commit 9d8bef4

Please sign in to comment.