Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill units only when requested #422

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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