Skip to content

Commit

Permalink
Fill units only when requested (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoNegri authored Jun 21, 2023
1 parent ea886a3 commit 107a01c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ansys/dpf/post/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 107a01c

Please sign in to comment.