From 2e18f80112787e2c0e94e0869e0583417b523525 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Tue, 20 Jun 2023 16:31:10 +0200 Subject: [PATCH 1/2] Fill units only when requested --- src/ansys/dpf/post/simulation.py | 10 ++++++---- tests/test_simulation.py | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ansys/dpf/post/simulation.py b/src/ansys/dpf/post/simulation.py index 91a982063..5c31c2a0c 100644 --- a/src/ansys/dpf/post/simulation.py +++ b/src/ansys/dpf/post/simulation.py @@ -81,10 +81,7 @@ def __init__(self, data_sources: DataSources, model: Model): self._active_selection = None self._named_selections = None self._mesh = None - self._units = { - "time/frequency": self.time_freq_support.time_frequencies.unit, - "distance": self._model.metadata.meshed_region.unit, - } + self._units = None self._time_freq_precision = None def release_streams(self): @@ -331,6 +328,11 @@ def set_ids(self) -> List: @property def units(self): """Returns the current time/frequency and distance units used.""" + if self._units is None: + self._units = { + "time/frequency": self.time_freq_support.time_frequencies.unit, + "distance": self._model.metadata.meshed_region.unit, + } return self._units def __str__(self): diff --git a/tests/test_simulation.py b/tests/test_simulation.py index f3f7c1bdb..c73d96afa 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -44,6 +44,12 @@ def test_simulation_init_with_server(static_rst, grpc_server): assert simulation._model._server == grpc_server +def test_simulation_units(static_simulation): + assert static_simulation._units is None + assert static_simulation.units is not None + assert static_simulation.units["time/frequency"] == "s" + assert static_simulation.units["distance"] == "m" + def test_simulation_results(static_simulation): results = static_simulation.results assert len(results) == 12 From bef6b3bc11add5e8b32749708398e334e41a3d24 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Tue, 20 Jun 2023 23:08:45 +0200 Subject: [PATCH 2/2] Fix style --- tests/test_simulation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_simulation.py b/tests/test_simulation.py index c73d96afa..1bb4c686d 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -50,6 +50,7 @@ def test_simulation_units(static_simulation): assert static_simulation.units["time/frequency"] == "s" assert static_simulation.units["distance"] == "m" + def test_simulation_results(static_simulation): results = static_simulation.results assert len(results) == 12