Skip to content

Commit

Permalink
Fixed handling of empty Time Freq Support (#996)
Browse files Browse the repository at this point in the history
* Fixed factory regarding time freq support

* Revert "Fixed factory regarding time freq support"

This reverts commit 2275661.

* Fixed nullptr handling of timefreq support

* Fixed unit setting when None

* Added tests

* Workaround to avoid throwing when retrieving no tf support

* Do not raise exception only if support not present

* breaks retro due to C++ changes
  • Loading branch information
ansys-akarcher committed Jul 11, 2023
1 parent 75e8ff9 commit 460f16a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/ansys/dpf/core/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,29 @@ def _get_time_freq_support(self):
capi=data_processing_capi.DataProcessingCAPI,
grpcapi=data_processing_grpcapi.DataProcessingGRPCAPI,
)
internal_obj = None
# LegacyGrpcServer throws UNAVAILABLE when retrieving nullptr
# This is all to obtain a None instead of throwing
import ansys.dpf.gate.errors as err

try:
internal_obj = self._api.collection_get_support(self, "time")
except err.DPFServerException as e:
str_to_ignore = "The collection does not have a support."
if str_to_ignore not in str(e):
raise e
if not internal_obj:
return None

support = object_handler.ObjHandler(
data_processing_api=data_api,
internal_obj=self._api.collection_get_support(self, "time"),
internal_obj=internal_obj,
server=self._server,
)
support_api = self._server.get_api_for_type(
capi=support_capi.SupportCAPI, grpcapi=support_grpcapi.SupportGRPCAPI
)

time_freq = support_api.support_get_as_time_freq_support(support)
res = TimeFreqSupport(time_freq_support=time_freq, server=self._server)
return res
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/dpf/core/fields_container_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def over_time_freq_fields_container(fields, time_freq_unit=None, server=None):
len(fields), location=locations.time_freq, server=server
)
time_freq_field.append(time_freq, 1)
time_freq_field.unit = time_freq_unit
if time_freq_unit:
time_freq_field.unit = time_freq_unit
time_freq_support = TimeFreqSupport(server=server)
time_freq_support.time_frequencies = time_freq_field
fc.time_freq_support = time_freq_support
Expand Down
21 changes: 21 additions & 0 deletions tests/test_fieldscontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,31 @@ def test_dot_operator_fields_container():
assert np.allclose(out[0].data, -field.data)


def test_fields_container_factory_with_dict():
field1 = dpf.Field()
field1.data = [1, 2, 3]
field2 = dpf.Field()
field2.data = [2, 3, 4]
fields_container = dpf.fields_container_factory.over_time_freq_fields_container(
fields={0.1: field1, 0.2: field2}
)

assert fields_container[0].unit == ""


def test_fields_container_get_time_scoping(server_type, disp_fc):
freq_scoping = disp_fc.get_time_scoping()
assert freq_scoping.size == 1


@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0, reason="Available for servers >=7.0"
)
def test_fields_container_empty_tf_support(server_type):
fields_container = dpf.FieldsContainer(server=server_type)

assert fields_container.time_freq_support == None


if __name__ == "__main__":
test_add_field_by_time_id()

0 comments on commit 460f16a

Please sign in to comment.