From 107a01c7d28f3be4c93b347cd182e483a37e3eea Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Wed, 21 Jun 2023 11:01:38 +0200 Subject: [PATCH] Fill units only when requested (#422) --- src/ansys/dpf/post/simulation.py | 10 ++++++---- tests/test_simulation.py | 7 +++++++ 2 files changed, 13 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..1bb4c686d 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -44,6 +44,13 @@ 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