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
StreamsContainerwraps one or moreStreamobjects (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 aDataSources.There are three ways to obtain a
StreamsContainer:From a Model — DPF opens the file automatically; retrieve the container via
model.metadata.streams_provider.From a DataSources — wrap an existing
DataSourcesso that DPF manages the open handles.From scratch — create an empty container and register one or more custom
Streamobjects withadd_stream(). This is the entry point for Python custom plug-ins that provide their ownstreams_provideroperator.
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#
Close all open files and release cached data. |
|
Add an external stream to the container. |
DataSources associated with this container. |
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
DataSourcesthat 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
StreamsContainerwas created:- Label-space strategy (
group/is_result/resultsupplied): 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. AStreamsContainercreated from scratch holds a fixed three-label schema:group,is_result, andresult(all integers).- DataSources-lookup strategy (no labels supplied):
The stream’s
file_pathis matched against the files already registered in the container’s underlyingDataSources. The label space stored there is reused automatically. Use this when the container was created viaStreamsContainer(data_sources=ds)and the file is already inds.
- Parameters:
stream (Stream) – The stream to add. Must be a concrete subclass of
Streamthat implements at leaststream_type_nameandfile_path.group (int, optional) – Value for the
grouplabel. When all three label arguments areNone(the default) the DataSources-lookup strategy is used instead.is_result (int, optional) – Value for the
is_resultlabel. Use1for a result stream,0for an auxiliary stream.result (int, optional) – Value for the
resultlabel.
- 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
- Label-space strategy (