StreamsContainer#

class ansys.dpf.core.streams_container.StreamsContainer(streams_container=None, server: ansys.dpf.core.server_types.BaseServer = None, data_sources: ansys.dpf.core.data_sources.DataSources = None)#

Holds a collection of open, ready-to-use data streams.

A StreamsContainer wraps one or more Stream objects (or the DPF-internal equivalent). Because the underlying files stay open and keep cached data between evaluations, repeated reads are significantly faster than reopening from a DataSources.

There are three ways to obtain a StreamsContainer:

  1. From a Model — DPF opens the file automatically; retrieve the container via model.metadata.streams_provider.

  2. From a DataSources — wrap an existing DataSources so that DPF manages the open handles.

  3. From scratch — create an empty container and register one or more custom Stream objects with add_stream(). This is the entry point for Python custom plug-ins that provide their own streams_provider operator.

To close the open files and release cached data, call release_handles().

Note

Only available with an InProcess server configuration.

Examples

Obtain a container from an existing model:

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_multishells_rst())
>>> sc = model.metadata.streams_provider.outputs.streams_container()

Create a container from a DataSources:

>>> ds = dpf.DataSources(examples.find_simple_bar())
>>> sc = dpf.StreamsContainer(data_sources=ds)

Create an empty container and register a custom stream:

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

Overview#

release_handles

Close all open files and release cached data.

add_stream

Add an external stream to the container.

datasources

DataSources associated with this container.

__del__

Delete the entry.

Import detail#

from ansys.dpf.core.streams_container import StreamsContainer

Property detail#

property StreamsContainer.datasources#

DataSources associated with this container.

Returns the DataSources that lists the result files backing this container’s open streams.

Returns:

Data sources for this container.

Return type:

ansys.dpf.core.DataSources

Attribute detail#

StreamsContainer.owned = False#

Method detail#

StreamsContainer.release_handles()#

Close all open files and release cached data.

After calling this method all streams in the container are closed. The container object itself remains valid — files will be reopened automatically on the next evaluation that requires them.

StreamsContainer.__del__()#

Delete the entry.

StreamsContainer.add_stream(stream: ansys.dpf.core.stream.Stream, group: int = None, is_result: int = None, result: int = None)#

Add an external stream to the container.

Two registration strategies are available depending on how the StreamsContainer was created:

Label-space strategy (group / is_result / result supplied):

The stream is registered under the given label values. Use this when the container was created without a backing DataSources, or when you want explicit control over the labels. A StreamsContainer created from scratch holds a fixed three-label schema: group, is_result, and result (all integers).

DataSources-lookup strategy (no labels supplied):

The stream’s file_path is matched against the files already registered in the container’s underlying DataSources. The label space stored there is reused automatically. Use this when the container was created via StreamsContainer(data_sources=ds) and the file is already in ds.

Parameters:
  • stream (Stream) – The stream to add. Must be a concrete subclass of Stream that implements at least stream_type_name and file_path.

  • group (int, optional) – Value for the group label. When all three label arguments are None (the default) the DataSources-lookup strategy is used instead.

  • is_result (int, optional) – Value for the is_result label. Use 1 for a result stream, 0 for an auxiliary stream.

  • result (int, optional) – Value for the result label.

Raises:

DPFServerException – If the label-space strategy is used and the supplied labels do not match the container’s schema, or if the DataSources-lookup strategy is used and the stream’s file path is not found in the container’s DataSources.

Examples

Label-space strategy — container created without a DataSources:

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> from ansys.dpf.core.stream import Stream
...
>>> class MyStream(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()
>>> sc = dpf.StreamsContainer()
>>> sc.add_stream(MyStream(rst_path), group=1, is_result=1, result=1)

DataSources-lookup strategy — container created from a DataSources:

>>> ds = dpf.DataSources(rst_path)
>>> sc = dpf.StreamsContainer(data_sources=ds)
>>> sc.add_stream(MyStream(rst_path))  # labels inferred from ds