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

Add a key argument to DataSources.set_domain_result_file_path() #1445

Merged
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
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
rafacanton marked this conversation as resolved.
Show resolved Hide resolved
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
Loading