Custom FieldsContainers

Contains inherited class of the FieldsContainer. Those new classes offer helpers to access data for specific usage: results split by body, by material…

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

A class used to represent a FieldsContainer with fields split by element shapes : solid, shell, beam… Instances of this class are created by a result of the model asked to be split by element shape

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

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.download_all_kinds_of_complexity_modal())
>>> fc = model.results.displacement.on_all_time_freqs.split_by_shape.eval()
>>> len(fc.solid_fields())
45
>>> solid_f_time_2 = fc.solid_field(2)
solid_fields(timeid=None, complexid=None)

Returns a list of all the fields with solid element shapes. If a timeid or a complexid (0 for real and 1 for imaginary) are given, the list of fields returned are solid fields for a given time and/or complex type

Returns

fields – fields corresponding to the request

Return type

list[Field]

Examples

>>> len(fc.solid_fields())
45
>>> len(fc.solid_fields(timeid=3))
1
shell_fields(timeid=None, complexid=None)

Returns a list of all the fields with shell element shapes. If a timeid or a complexid (0 for real and 1 for imaginary) are given, the list of fields returned are shell fields for a given time and/or complex type

Returns

fields – fields corresponding to the request

Return type

list[Field]

Examples

>>> len(fc.shell_fields())
45
>>> len(fc.shell_fields(timeid=3))
1
beam_fields(timeid=None, complexid=None)

Returns a list of all the fields with beam element shapes. If a timeid or a complexid (0 for real and 1 for imaginary) are given, the list of fields returned are beam fields for a given time and/or complex type

Returns

fields – fields corresponding to the request

Return type

list[Field]

Examples

>>> len(fc.beam_fields())
45
>>> len(fc.beam_fields(timeid=3))
1
solid_field(timeid=None, complexid=None)

Returns the requested field with solid element shapes. If a timeid or a complexid (0 for real and 1 for imaginary) are given, the field returned is a solid field for a given time and/or complex type. It throws if the number of fields matching the request is higher than 1.

Returns

fields – field corresponding to the request

Return type

Field

Examples

>>> field = fc.solid_field(timeid=3)
shell_field(timeid=None, complexid=None)

Returns the requested field with shell element shapes. If a timeid or a complexid (0 for real and 1 for imaginary) are given, the field returned is a shell field for a given time and/or complex type. It throws if the number of fields matching the request is higher than 1.

Returns

fields – field corresponding to the request

Return type

Field

Examples

>>> field = fc.shell_field(timeid=3)
beam_field(timeid=None, complexid=None)

Returns the requested field with beam element shapes. If a timeid or a complexid (0 for real and 1 for imaginary) are given, the field returned is a beam field for a given time and/or complex type. It throws if the number of fields matching the request is higher than 1.

Returns

fields – field corresponding to the request

Return type

Field

Examples

>>> field = fc.beam_field(timeid=3)
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

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

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

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

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]

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

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

A class used to represent a FieldsContainer with fields split by body (mapdl material property) Instances of this class are created by a result of the model asked to be split by body

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

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.download_all_kinds_of_complexity_modal())
>>> fc = model.results.displacement.on_all_time_freqs.split_by_body.eval()
>>> fc.get_mat_scoping().ids[3]
45
>>> len(fc.get_fields_by_mat_id(45))
45
>>> f_time_2 = fc.get_field_by_mat_id(45, timeid=2)
get_fields_by_mat_id(matid, timeid=None, complexid=None)

Returns a list of all the fields with the given material id. If a timeid or a complexid (0 for real and 1 for imaginary) are given, the list of fields returned are fields for a given time and/or complex type. The available mat id can be requested with get_mat_scoping

Returns

fields – fields corresponding to the request

Return type

list[Field]

Examples

>>> len(fc.get_fields_by_mat_id(1))
45
>>> len(fc.get_fields_by_mat_id(1, timeid=3))
1
get_field_by_mat_id(matid, timeid=None, complexid=None)

Returns a a field with the given material id. If a timeid or a complexid (0 for real and 1 for imaginary) are given, the field returned is for a given time and/or complex type. The available mat id can be requested with get_mat_scoping

Returns

fields – field corresponding to the request

Return type

Field

Examples

>>> f_time_2 = fc.get_field_by_mat_id(45, timeid=2)
get_mat_scoping()

Returns the material or body scoping containing the mat ids

Returns

scoping – scoping containing the mat ids available in the fields container

Return type

Scoping

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

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

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

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

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]

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