Collection

Contains classes associated to the DPF Collection

class ansys.dpf.core.collection.Collection(dpf_type, collection=None, server: Optional[ansys.dpf.core.server.DpfServer] = None)

A class used to represent a Collection which contains entries ordered in labels and ids.

Parameters
  • collection (ansys.grpc.dpf.collection_pb2.Collection, optional) – Create a collection from a Collection message.

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the the global server.

Examples

>>> from ansys.dpf import core as dpf
>>> coll = dpf.Collection(dpf.types.field)
set_labels(labels)

set the requested labels to scope the collection

Parameters

labels (list[str], optional) –

labels on which the entries will be scoped, for example:

[‘time’,’complex’]

add_label(label, default_value=None)

Add the requested label to scope the collection

Parameters
  • label (str) – Labels on which the entries will be scoped, for example 'time'.

  • default_value (int , optional) – default value set for existing fields in the collection

Examples

>>> from ansys.dpf import core as dpf
>>> coll = dpf.Collection(dpf.types.field)
>>> coll.add_label('time')
property labels

get the labels scoping the collection

Returns

labels

labels on which the entries are scoped, for example:

['time', 'complex']

Return type

list[str]

has_label(label)

Check if a collection has a specified label

Parameters

label (str) – Labels that must be searched, for example 'time'.

Returns

True if the specified value has been found in the collection.

Return type

bool

Examples

>>> from ansys.dpf import core as dpf
>>> coll = dpf.Collection(dpf.types.field)
>>> coll.add_label('time')
>>> coll.has_label('time')
True
>>> coll.has_label('complex')
False
get_label_space(index)

Returns the label space of an entry at a requested index

Parameters

index (int, optional) – Index of the entry.

Returns

label_space – Scoping of the requested entry, for example: {"time": 1, "complex": 0}

Return type

dict(str:int)

get_available_ids_for_label(label='time')

Get the IDs corresponding to the input label.

Parameters

label (str) – name of the requested ids

Returns

ids – ids corresponding to the input label

Return type

list[int]

get_label_scoping(label='time')

Get the scoping corresponding to the input label. This method allows to get the list of available ids for a given label in the Collection. For example, if the label “el_type” is available in the collection, the get_lable_scoping method, will return the list element type ids available in it. Those ids can then be used to request a given entity inside the collection.

Parameters

label (str) – name of the requested ids

Returns

scoping – scoping containing the ids of the input label

Return type

Scoping