Skip to content

Commit

Permalink
updates in the DataSources api reference
Browse files Browse the repository at this point in the history
  • Loading branch information
luisaFelixSalles committed Oct 10, 2024
1 parent 74f87c4 commit 30e411f
Showing 1 changed file with 3 additions and 83 deletions.
86 changes: 3 additions & 83 deletions src/ansys/dpf/core/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,7 @@ def __init__(
def set_result_file_path(
self, filepath: Union[str, os.PathLike], key: Optional[str] = ""
) -> None:
"""Set the main result file path to the data sources.
Parameters
----------
filepath :
Path to the result file.
key :
Extension of the file, which is used as a key for choosing the correct
plugin when a result is requested by an operator. The default is ``""``,
in which case the key is found directly.
Examples
--------
Create a DataSources object and set the result file path.
>>> from ansys.dpf import core as dpf
>>>
>>> # Create the DataSources object
>>> my_data_sources = dpf.DataSources()
>>> # Define the path where the main result file can be found
>>> my_data_sources.set_result_file_path(filepath='/tmp/file.rst', key='rst')
>>> # Get the path to the main result file
>>> my_data_sources.result_files
['/tmp/file.rst']
"""
"""Set the main result file path to the data sources."""
extension = os.path.splitext(filepath)[1]
# Handle .res files from CFX
if key == "" and extension == ".res":
Expand All @@ -182,37 +157,7 @@ def set_result_file_path(

@staticmethod
def guess_result_key(filepath: str) -> str:
"""Guess result key for files without an explicit file extension.
Parameters
----------
filepath :
Path to the file.
Returns
-------
str :
Extension key name
Examples
--------
Gives the result key for the result file of the given path
>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>>
>>> # Create the DataSources object
>>> my_data_sources = dpf.DataSources()
>>> # Download the result files
>>> path = examples.download_d3plot_beam()
>>> # Define the path where the main result file can be found
>>> my_data_sources.set_result_file_path(filepath=path[0])
>>> # Define the extension key for the file in the given path
>>> my_file_key = my_data_sources.guess_result_key(filepath=path[0])
>>> print(my_file_key)
d3plot
"""
"""Guess result key for files without an explicit file extension."""
result_keys = ["d3plot", "binout"]
base_name = os.path.basename(filepath)
# Handle files without extension
Expand All @@ -237,32 +182,7 @@ def guess_second_key(filepath: str) -> str:
def set_domain_result_file_path(
self, path: Union[str, os.PathLike], domain_id: int, key: Optional[str] = None
) -> None:
"""Set a result file path by domain.
This method is used to handle files created by a distributed solve.
Parameters
----------
path :
Path to the file.
domain_id :
Domain ID for the distributed files.
key :
Key to associate to the file.
Examples
--------
Set the main result file path to the data sources in their respective domains.
>>> from ansys.dpf import core as dpf
>>>
>>> # Create the DataSources object
>>> my_data_sources = dpf.DataSources()
>>> # Define the path where the main result data can be found and specify its domain
>>> my_data_sources.set_domain_result_file_path(path='/tmp/file0.rst', key='rst', domain_id=0)
>>> my_data_sources.set_domain_result_file_path(path='/tmp/file1.rst', key='rst', domain_id=1)
"""
"""Set a result file path by domain."""
if key:
self._api.data_sources_set_domain_result_file_path_with_key_utf8(
self, str(path), key, domain_id
Expand Down

0 comments on commit 30e411f

Please sign in to comment.