FieldsContainer

Contains classes associated to the DPF FieldsContainer

class ansys.dpf.core.fields_container.FieldsContainer(fields_container=None, server=None)

A class used to represent a FieldsContainer which contains fields belonging to a common results. The fields container is designed as a set of fields ordered by labels and ids. Each field of the Fields Container has an id for each label defining the given Fields Container. This allows to split the fields on any criteria. The most common fields container have the label “time” with ids corresponding to each time sets, the label “complex” will allow to separate real parts (id=0) from imaginary parts (id=1) in a harmonic analysis for example.

Parameters
  • fields_container (ansys.grpc.dpf.collection_pb2.Collection or FieldsContainer, optional) – Create a fields container from a Collection message or create a copy from an existing fields container

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

Examples

Extract a displacement fields container from a transient result file.

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> transient = examples.download_transient_result()
>>> model = dpf.Model(transient)
>>> disp = model.results.displacement()
>>> disp.inputs.time_scoping.connect([1,5])
>>> fields_container = disp.outputs.fields_container()
>>> field_set_5 =fields_container.get_fields_by_time_complex_ids(5)
>>> #print(fields_container)

Create a fields container from scratch

>>> from ansys.dpf import core as dpf
>>> fc= dpf.FieldsContainer()
>>> fc.labels =['time','complex']
>>> for i in range(0,20): #real fields
...     mscop = {"time":i+1,"complex":0}
...     fc.add_field(mscop,dpf.Field(nentities=i+10))
>>> for i in range(0,20): #imaginary fields
...     mscop = {"time":i+1,"complex":1}
...     fc.add_field(mscop,dpf.Field(nentities=i+10))
get_fields_by_time_complex_ids(timeid=None, complexid=None)

Returns the fields at a requested time/freq id and real or imaginary depending on complexid (complexid=1:imaginary, complexid=0:real)

Parameters
  • timeid (int, optional) – The time id. One based index of the result set.

  • complexid (int, optional) – The complex id.

Returns

fields – fields corresponding to the request

Return type

list[Field]

Examples

Extract a the 5th time set of a transient analysis.

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> transient = examples.download_transient_result()
>>> model = dpf.Model(transient)
>>> len(model.metadata.time_freq_support.time_frequencies)
35
>>> disp = model.results.displacement()
>>> disp.inputs.time_scoping.connect([1,5])
>>> fields_container = disp.outputs.fields_container()
>>> field_set_5 =fields_container.get_fields_by_time_complex_ids(5)
get_field_by_time_complex_ids(timeid=None, complexid=None)

Returns the field at a requested time/freq id and real or imaginary depending on complexid (complexid=1:imaginary, complexid=0:real). It throws if the number of fields matching the request is higher than 1.

Parameters
  • timeid (int, optional) – The time id. One based index of the result set.

  • complexid (int, optional) – The complex id.

Returns

fields – field corresponding to the request

Return type

Field

Examples

Extract a the 5th time set of a transient analysis.

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> transient = examples.download_transient_result()
>>> model = dpf.Model(transient)
>>> len(model.metadata.time_freq_support.time_frequencies)
35
>>> disp = model.results.displacement()
>>> disp.inputs.time_scoping.connect([1,5])
>>> fields_container = disp.outputs.fields_container()
>>> field_set_5 =fields_container.get_fields_by_time_complex_ids(5)
get_fields(label_space)

Returns the fields at a requested index or label space

Parameters

label_space (dict[str,int]) – Scoping of the requested fields, for example: {"time": 1, "complex": 0}

Returns

fields – fields corresponding to the request

Return type

list[Field]

Examples

>>> from ansys.dpf import core as dpf
>>> fc= dpf.FieldsContainer()
>>> fc.labels =['time','complex']
>>> #real fields
>>> for i in range(0,20):
...     mscop = {"time":i+1,"complex":0}
...     fc.add_field(mscop,dpf.Field(nentities=i+10))
>>> #imaginary fields
>>> for i in range(0,20):
...     mscop = {"time":i+1,"complex":1}
...     fc.add_field(mscop,dpf.Field(nentities=i+10))
>>> fields = fc.get_fields({"time":2})
>>> # imaginary and real fields of time 2
>>> len(fields)
2
get_field(label_space_or_index)

Returns the field at a requested index or label space. Throws if the request returns several fields

Parameters

label_space_or_index (dict[str,int] , int) – Scoping of the requested fields, for example: {"time": 1, "complex": 0} or Index of the field.

Returns

field – field corresponding to the request

Return type

Field

Examples

>>> from ansys.dpf import core as dpf
>>> fc= dpf.fields_container_factory.over_time_freq_fields_container([dpf.Field(nentities=10)])
>>> field = fc.get_field({"time":1})
get_field_by_time_id(timeid=None)

Returns the complex field at a requested time

Parameters

timeid (int, optional) – The time id. Index of the result set.

Returns

fields – fields corresponding to the request

Return type

Field

get_imaginary_fields(timeid=None)

Returns the complex fields at a requested time

Parameters

timeid (int, optional) – The time id. Index of the result set.

Returns

fields – fields corresponding to the request

Return type

list[Field]

get_imaginary_field(timeid=None)

Returns the complex field at a requested time

Parameters

timeid (int, optional) – The time id. Index of the result set.

Returns

fields – field corresponding to the request

Return type

Field

add_field(label_space, field)

Update or add the field at a requested label space.

Parameters
  • label_space (dict[str,int]) – label_space of the requested fields, ex : {“time”:1, “complex”:0}

  • field (Field) – DPF field to add.

Examples

>>> from ansys.dpf import core as dpf
>>> fc= dpf.FieldsContainer()
>>> fc.labels =['time','complex']
>>> for i in range(0,20): #real fields
...     mscop = {"time":i+1,"complex":0}
...     fc.add_field(mscop,dpf.Field(nentities=i+10))
>>> for i in range(0,20): #imaginary fields
...     mscop = {"time":i+1,"complex":1}
...     fc.add_field(mscop,dpf.Field(nentities=i+10))
add_field_by_time_id(field, timeid=1)

Update or add the field at a requested time id.

Parameters
  • field (Field) – DPF field to add.

  • timeid (int, optional) – time id corresponding to the requested time set. Default: 1

add_imaginary_field(field, timeid=1)

Update or add the imaginary field at a requested time id.

Parameters
  • field (Field) – DPF field to add.

  • timeid (int, optional) – time id corresponding to the requested time set. Default: 1

select_component(index)

Returns fields containing only the component index.

Can only select by component index as multiple fields may contain different number of components.

Parameters

index (int) – Component index.

Returns

fields – Fields container with one component selected in each field.

Return type

FieldsContainer

Examples

Select using a component index

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> transient = examples.download_transient_result()
>>> model = dpf.Model(transient)
>>> disp = model.results.displacement()
>>> disp.inputs.time_scoping.connect([1,5])
>>> fields_container = disp.outputs.fields_container()
>>> disp_x_fields = fields_container.select_component(0)
>>> my_field = disp_x_fields[0]
deep_copy(server=None)

Creates a deep copy of the fields container’s data (and its fields) on a given server. This can be useful to pass data from one server instance to another.

Parameters

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

Returns

fields_container_copy

Return type

FieldsContainer

Examples

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> transient = examples.download_transient_result()
>>> model = dpf.Model(transient)
>>> disp = model.results.displacement()
>>> disp.inputs.time_scoping.connect([1,5])
>>> fields_container = disp.outputs.fields_container()
>>> other_server = dpf.start_local_server(as_global=False)
>>> deep_copy = fields_container.deep_copy(server=other_server)
get_time_scoping()

Returns the time scoping containing the time sets

Returns

scoping – scoping containing the time set ids available in the fields container

Return type

Scoping

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')
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

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)

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
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]

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’]