Stream#

class ansys.dpf.core.stream.Stream(file_path: str | pathlib.Path)#

Bases: abc.ABC

Abstract base class for a DPF external stream.

A stream is an open, ready-to-use data source. Once the underlying file is opened it stays open and keeps data in cache so that subsequent evaluations are faster. To close the file and free the cache, call release().

Subclasses must override stream_type_name, time_freq_support, and result_info. They may also override _create_handle() and _release_handle() to manage a custom resource instead of the default binary file handle.

Once instantiated, a stream can be registered with a StreamsContainer via add_stream() so that DPF operators can consume it.

Note

Streams are only meaningful when used with a StreamsContainer, which itself requires an InProcess server configuration.

Examples

Define a minimal concrete stream for an RST result file:

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> from ansys.dpf.core.stream import Stream
...
>>> class RstStream(Stream):
...     @property
...     def stream_type_name(self) -> str:
...         return "rst"
...     @property
...     def time_freq_support(self):
...         return dpf.TimeFreqSupport()
...     @property
...     def result_info(self):
...         return dpf.ResultInfo()
...
>>> rst_path = examples.find_simple_bar()
>>> stream = RstStream(rst_path)
>>> sc = dpf.StreamsContainer()
>>> sc.add_stream(stream, group=1, is_result=1, result=1)

Overview#

release

Close the file and release cached data.

stream_type_name

Type identifier recognised by the DPF server for this stream.

file_path

Absolute path to the file backing this stream.

time_freq_support

Time/frequency support describing the available time steps.

result_info

Metadata describing the results available in this stream.

__delete__

Release resources when the descriptor protocol deletes this object.

Import detail#

from ansys.dpf.core.stream import Stream

Property detail#

property Stream.stream_type_name: str#

Type identifier recognised by the DPF server for this stream.

The value must match a stream type registered on the server side (for example "rst", "d3plot", "cgns"). Subclasses must override this property to return the correct type string; the base-class implementation returns the placeholder "stream_type".

Returns:

Stream type identifier.

Return type:

str

property Stream.file_path: str#

Absolute path to the file backing this stream.

Returns:

Path to the result file as a string.

Return type:

str

property Stream.time_freq_support: ansys.dpf.core.TimeFreqSupport#
Abstractmethod:

Time/frequency support describing the available time steps.

Returns:

Object describing the time and frequency sets available in this stream.

Return type:

ansys.dpf.core.TimeFreqSupport

property Stream.result_info: ansys.dpf.core.ResultInfo#
Abstractmethod:

Metadata describing the results available in this stream.

Returns:

Object containing solver type, available result quantities, and unit system information.

Return type:

ansys.dpf.core.ResultInfo

Attribute detail#

Stream.__slots__ = ()#

Method detail#

Stream.release()#

Close the file and release cached data.

After calling this method the stream is no longer usable. Any subsequent read requests routed through a StreamsContainer that references this stream will fail.

Stream.__delete__()#

Release resources when the descriptor protocol deletes this object.