Data Sources#

class ansys.dpf.core.data_sources.DataSources(result_path=None, data_sources=None, server=None)#

Contains files with analysis results.

An extension key ('rst' for example) is used to choose which files represent results files versus accessory files. You can set a result file path when initializing this class.

Parameters:
  • result_path (str or os.PathLike object, optional) – Path of the result. The default is None.

  • data_sources (ansys.grpc.dpf.data_sources_pb2.DataSources) – gRPC data sources message. The default is None.

  • server (server.DPFServer, optional) – Server with the channel connected to the remote or local instance. The default is None, in which case an attempt is made to use the global server.

Examples

Initialize a model from a result path.

>>> from ansys.dpf import core as dpf
>>> my_data_sources = dpf.DataSources('file.rst')
>>> my_data_sources.result_files
['file.rst']
set_result_file_path(filepath, key='')#

Add a result file path to the data sources.

Parameters:
  • filepath (str or os.PathLike object) – Path to the result file.

  • key (str, optional) – 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 data source and set the result file path.

>>> from ansys.dpf import core as dpf
>>> data_sources = dpf.DataSources()
>>> data_sources.set_result_file_path('/tmp/file.rst')
>>> data_sources.result_files
['/tmp/file.rst']
static guess_result_key(filepath: str)#

Guess result key for files without a file extension.

Return type:

str

static guess_second_key(filepath: str)#

For files with an h5 or cff extension, look for another extension.

Return type:

str

set_domain_result_file_path(path: str | os.PathLike, domain_id: int, key: str | None = None)#

Add a result file path by domain.

This method is used to handle files created by a distributed solve.

Parameters:
  • path (Union[str, PathLike]) – Path to the file.

  • domain_id (int) – Domain ID for the distributed files.

  • key (Optional[str], default: None) – Key to associate to the file.

Examples

>>> from ansys.dpf import core as dpf
>>> data_sources = dpf.DataSources()
>>> data_sources.set_domain_result_file_path('/tmp/file0.sub', 0)
>>> data_sources.set_domain_result_file_path('/tmp/file1.sub', 1)
add_file_path(filepath, key='', is_domain: bool = False, domain_id=0)#

Add a file path to the data sources.

Files not added as result files are accessory files, which contain accessory information not present in the result files.

Parameters:
  • filepath (str or os.PathLike object) – Path of the file.

  • key (str, optional) – 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.

  • is_domain (bool, optional) – Whether the file path is the domain path. The default is False.

  • domain_id (int, optional) – Domain ID for the distributed files. The default is 0. For this parameter to be taken into account, domain_path=True must be set.

Examples

>>> from ansys.dpf import core as dpf
>>> data_sources = dpf.DataSources()
>>> data_sources.add_file_path('/tmp/ds.dat')
add_domain_file_path(filepath, key, domain_id)#

Add a file path to the data sources.

Files not added as result files are accessory files, which contain accessory information not present in the result files.

Parameters:
  • filepath – Path of the 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.

  • domain_id – Domain ID for the distributed files.

Examples

>>> from ansys.dpf import core as dpf
>>> data_sources = dpf.DataSources()
>>> data_sources.add_domain_file_path('/tmp/ds.dat', "dat", 1)
add_file_path_for_specified_result(filepath, key='', result_key='')#

Add a file path for a specified result file key to the data sources.

This method can be used when results files with different keys (extensions) are contained in the data sources. For example, a solve using two different solvers could generate two different sets of files.

Parameters:
  • filepath (str or os.PathLike object) – Path of the file.

  • key (str, optional) – 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.

  • result_key (str, optional) – Extension of the results file that the specified file path belongs to. The default is "", in which case the key is found directly.

add_upstream(upstream_data_sources, result_key='')#

Add upstream data sources.

This is used to add a set of path creating an upstream for recursive workflows.

Parameters:
  • upstream_data_sources (DataSources) – Set of paths creating an upstream for recursive workflows.

  • result_key (str, optional) – Extension of the result file group with which this upstream belongs

add_upstream_for_domain(upstream_data_sources, domain_id)#

Add an upstream data sources for a given domain.

This is used to add a set of path creating an upstream for recursive workflows in a distributed solve.

Parameters:
  • upstream_data_sources (DataSources) – Set of paths creating an upstream for recursive workflows.

  • domain_id (int) – Domain id for distributed files.

property result_key#

Result key used by the data sources.

Returns:

Result key.

Return type:

str

property result_files#

List of result files contained in the data sources.

Returns:

List of result files.

Return type:

list

register_namespace(result_key: str, namespace: str)#

Adds a link from this result_key to this namespace in the DataSources. This result_key to namespace mapping is used by source operators to find internal operators to call.

Notes

Available with server’s version starting at 7.0.