Skip to content

Commit f7046ac

Browse files
committed
Add datasources namespace API
1 parent 68f0755 commit f7046ac

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/ansys/dpf/core/data_sources.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,18 @@ def register_namespace(self, result_key: str, namespace: str):
680680
"""
681681
self._api.data_sources_register_namespace(self, result_key, namespace)
682682

683+
def namespace(self, result_key: str) -> str:
684+
"""
685+
Return the namespace associated to a result_key. The namespace identifies to which operator plugin a call should be delegated to.
686+
687+
Parameters
688+
----------
689+
result_key:
690+
Extension of the file, which is used as a key for choosing the correct
691+
plugin when a result is requested by an operator.
692+
"""
693+
return self._api.data_sources_get_namespace(self, result_key)
694+
683695
def __str__(self):
684696
"""Describe the entity.
685697

src/ansys/dpf/gate/data_sources_grpcapi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,8 @@ def data_sources_get_key(dataSources, index, num_path):
176176
def data_sources_get_path(dataSources, key, index):
177177
response = _get_stub(dataSources._server).List(dataSources._internal_obj)
178178
return list(response.paths[key].paths)[index]
179+
180+
@staticmethod
181+
def data_sources_get_namespace(dataSources, key):
182+
response = _get_stub(dataSources._server).List(dataSources._internal_obj)
183+
return response.namespaces[key]

tests/test_datasources.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import pytest
2626

2727
from ansys import dpf
28+
from ansys.dpf.core import examples
2829
import conftest
2930

3031
skip_always = pytest.mark.skipif(True, reason="Investigate why this is failing")
@@ -173,3 +174,13 @@ def test_register_namespace(allkindofcomplexity, server_type):
173174
with pytest.raises(Exception):
174175
op = dpf.core.operators.result.displacement(data_sources=data_sources, server=server_type)
175176
assert op.eval() is not None
177+
178+
179+
def test_namespace(allkindofcomplexity, server_type):
180+
data_sources = dpf.core.DataSources(allkindofcomplexity, server=server_type)
181+
assert data_sources.namespace(data_sources.result_key) == "mapdl"
182+
183+
cas_h5_file = examples.download_fluent_axial_comp(server=server_type)["cas"][0]
184+
data_sources = dpf.core.DataSources(server=server_type)
185+
data_sources.set_result_file_path(cas_h5_file)
186+
assert data_sources.namespace(data_sources.result_key) == "cff"

0 commit comments

Comments
 (0)