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']
set_domain_result_file_path(path, domain_id)#

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 to the file.

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

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_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