Skip to content

Commit 5a77146

Browse files
authored
Add a key argument to DataSources.set_domain_result_file_path() (#1445)
* Add a key argument to DataSources.set_domain_result_file_path() Signed-off-by: paul.profizi <[email protected]> * Add a key argument to DataSources.set_domain_result_file_path() Signed-off-by: paul.profizi <[email protected]> * Add for LegacyGrpc Signed-off-by: paul.profizi <[email protected]> * Fix Code quality --------- Signed-off-by: paul.profizi <[email protected]>
1 parent 924d709 commit 5a77146

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/ansys/dpf/core/data_sources.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import warnings
99
import traceback
10+
from typing import Union
1011

1112
from ansys.dpf.core import server as server_module
1213
from ansys.dpf.gate import (
@@ -135,18 +136,22 @@ def guess_result_key(filepath: str) -> str:
135136
return result_key
136137
return ""
137138

138-
def set_domain_result_file_path(self, path, domain_id):
139+
def set_domain_result_file_path(
140+
self, path: Union[str, os.PathLike], domain_id: int, key: Union[str, None] = None
141+
):
139142
"""Add a result file path by domain.
140143
141144
This method is used to handle files created by a
142145
distributed solve.
143146
144147
Parameters
145148
----------
146-
path: str or os.PathLike object
149+
path:
147150
Path to the file.
148-
domain_id: int
151+
domain_id:
149152
Domain ID for the distributed files.
153+
key:
154+
Key to associate to the file.
150155
151156
Examples
152157
--------
@@ -156,7 +161,12 @@ def set_domain_result_file_path(self, path, domain_id):
156161
>>> data_sources.set_domain_result_file_path('/tmp/file1.sub', 1)
157162
158163
"""
159-
self._api.data_sources_set_domain_result_file_path_utf8(self, str(path), domain_id)
164+
if key:
165+
self._api.data_sources_set_domain_result_file_path_with_key_utf8(
166+
self, str(path), key, domain_id
167+
)
168+
else:
169+
self._api.data_sources_set_domain_result_file_path_utf8(self, str(path), domain_id)
160170

161171
def add_file_path(self, filepath, key="", is_domain: bool = False, domain_id=0):
162172
"""Add a file path to the data sources.

src/ansys/dpf/gate/data_sources_grpcapi.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ def data_sources_set_domain_result_file_path_utf8(dataSources, name, id):
6060
request.data_sources.CopyFrom(dataSources._internal_obj)
6161
_get_stub(dataSources._server).Update(request)
6262

63+
@staticmethod
64+
def data_sources_set_domain_result_file_path_with_key_utf8(dataSources, name, key, domain_id):
65+
from ansys.grpc.dpf import data_sources_pb2
66+
request = data_sources_pb2.UpdateRequest()
67+
request.result_path = True
68+
request.domain.domain_path = True
69+
request.domain.domain_id = domain_id
70+
request.path = name
71+
request.key = key
72+
request.data_sources.CopyFrom(dataSources._internal_obj)
73+
_get_stub(dataSources._server).Update(request)
74+
6375
@staticmethod
6476
def data_sources_add_file_path_utf8(dataSources, name):
6577
from ansys.grpc.dpf import data_sources_pb2

tests/test_datasources.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_setresultpath_data_sources(allkindofcomplexity, server_type):
2525
def test_setdomainresultpath_data_sources(allkindofcomplexity, server_type):
2626
data_sources = dpf.core.DataSources(server=server_type)
2727
data_sources.set_domain_result_file_path(allkindofcomplexity, 0)
28+
data_sources.set_domain_result_file_path(allkindofcomplexity, 0, key="rst")
2829

2930

3031
def test_addpath_data_sources(allkindofcomplexity, server_type):

0 commit comments

Comments
 (0)