DataSources

class ansys.dpf.core.data_sources.DataSources(result_path=None, data_sources=None, server=None)
The data sources is a container of files on which the analysis results can be found.

An extension key (‘rst’ for example) is used to choose which files represent results files, the other one being accessory files. A result file path can be set in the DataSOurces initializer.

Parameters
  • result_path (str, optional) – path of the result

  • data_sources (ansys.grpc.dpf.data_sources_pb2.DataSources) – gRPC data sources message.

  • server (DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the 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 datasources. The result file path key is used to choose the right plugin when a result is asked with an Operator.

Parameters
  • filepath (str) – Path to the result file.

  • key (str, optional) – Extension of the file, found directly if it is not set.

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 can be called to to handle files created by a distributed solve.

Parameters
  • path (str) – Path to the file.

  • domain_id (int, optional, default is 0) – Domain id for 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. The files not added as result files are accessory files used to access accessory information not present in the result files.

Parameters
  • filepath (str) – Path of the file.

  • key (str, optional) – Extension of the file, found directly if it is not set.

  • is_domain (bool) – file_path is domain_path

  • domain_id (int, optional, default is 0) – Domain id for distributed files. Must be set with domain_path = True to be taken into account.

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 to the data sources. The files not added as result files are accessory files used to access accessory information not present in the result files. Using the 'specified_result' option is used when several results files with different results keys are used in the data sources. For example, if a solve used 2 different solvers which generated 2 different sets of files, this method can be used.

Parameters
  • filepath (str) – Path of the file.

  • key (str, optional) – Extension of the file, found directly if it is not set.

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

add_upstream(upstream_data_sources)

Add an upstream datasources.

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

Parameters

upstream_data_sources (DataSources) –

property result_key

Returns the result key used by the data sources

Returns

result_key

Return type

str

property result_files

Returns the list of result files contained by the data sources

Returns

result_files

Return type

list of str