From 9d8bef42f57cef5b3e415b88e9889c1a714f05fd Mon Sep 17 00:00:00 2001 From: Nicolas LAURENT Date: Tue, 14 Jan 2025 20:55:58 +0100 Subject: [PATCH] startTime and stopTime are deduced from 1st embedded FMU --- CHANGELOG.md | 8 +++++--- fmu_manipulation_toolbox/fmu_container.py | 20 +++++++++++++++++--- tests/test_suite.py | 1 + 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a558e2..6adb9e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/fmu_manipulation_toolbox/fmu_container.py b/fmu_manipulation_toolbox/fmu_container.py index c0efe50..e8b0c8e 100644 --- a/fmu_manipulation_toolbox/fmu_container.py +++ b/fmu_manipulation_toolbox/fmu_container.py @@ -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] = {} @@ -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: @@ -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] = {} @@ -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""" - + """) diff --git a/tests/test_suite.py b/tests/test_suite.py index 788bb1f..4dd21e0 100755 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -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()