Skip to content

Commit

Permalink
Add a key argument to DataSources.set_domain_result_file_path() (#1445)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
PProfizi authored Mar 1, 2024
1 parent 924d709 commit 5a77146
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/ansys/dpf/core/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import warnings
import traceback
from typing import Union

from ansys.dpf.core import server as server_module
from ansys.dpf.gate import (
Expand Down Expand Up @@ -135,18 +136,22 @@ def guess_result_key(filepath: str) -> str:
return result_key
return ""

def set_domain_result_file_path(self, path, domain_id):
def set_domain_result_file_path(
self, path: Union[str, os.PathLike], domain_id: int, key: Union[str, None] = None
):
"""Add a result file path by domain.
This method is used to handle files created by a
distributed solve.
Parameters
----------
path: str or os.PathLike object
path:
Path to the file.
domain_id: int
domain_id:
Domain ID for the distributed files.
key:
Key to associate to the file.
Examples
--------
Expand All @@ -156,7 +161,12 @@ def set_domain_result_file_path(self, path, domain_id):
>>> data_sources.set_domain_result_file_path('/tmp/file1.sub', 1)
"""
self._api.data_sources_set_domain_result_file_path_utf8(self, str(path), domain_id)
if key:
self._api.data_sources_set_domain_result_file_path_with_key_utf8(
self, str(path), key, domain_id
)
else:
self._api.data_sources_set_domain_result_file_path_utf8(self, str(path), domain_id)

def add_file_path(self, filepath, key="", is_domain: bool = False, domain_id=0):
"""Add a file path to the data sources.
Expand Down
12 changes: 12 additions & 0 deletions src/ansys/dpf/gate/data_sources_grpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ def data_sources_set_domain_result_file_path_utf8(dataSources, name, id):
request.data_sources.CopyFrom(dataSources._internal_obj)
_get_stub(dataSources._server).Update(request)

@staticmethod
def data_sources_set_domain_result_file_path_with_key_utf8(dataSources, name, key, domain_id):
from ansys.grpc.dpf import data_sources_pb2
request = data_sources_pb2.UpdateRequest()
request.result_path = True
request.domain.domain_path = True
request.domain.domain_id = domain_id
request.path = name
request.key = key
request.data_sources.CopyFrom(dataSources._internal_obj)
_get_stub(dataSources._server).Update(request)

@staticmethod
def data_sources_add_file_path_utf8(dataSources, name):
from ansys.grpc.dpf import data_sources_pb2
Expand Down
1 change: 1 addition & 0 deletions tests/test_datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_setresultpath_data_sources(allkindofcomplexity, server_type):
def test_setdomainresultpath_data_sources(allkindofcomplexity, server_type):
data_sources = dpf.core.DataSources(server=server_type)
data_sources.set_domain_result_file_path(allkindofcomplexity, 0)
data_sources.set_domain_result_file_path(allkindofcomplexity, 0, key="rst")


def test_addpath_data_sources(allkindofcomplexity, server_type):
Expand Down

0 comments on commit 5a77146

Please sign in to comment.