PropertyField#

class ansys.dpf.core.property_field.PropertyField(nentities=0, nature=natures.scalar, location=locations.nodal, property_field=None, server=None)#

Bases: ansys.dpf.core.field_base._FieldBase

Describes field properties such as connectivity.

This class is a field with integer values instead of double values.

Parameters:
  • nentities (int) – Number of entities that the property field is to contain. The default is 0.

  • nature (core.natures) – Nature of the property field, such as scalar or vector.

  • location (str, optional) – Location of the property field. Options are in ansys.dpf.core.locations. The default is ansys.dpf.core.locations.nodal.

  • field (property) – Field message generated from a gRPC stub, or returned by DPF’s C clients.

  • server (server.DPFServer, optional) – Server with the channel connected to the remote or local instance. The default is None, in which case an attempt is made to use the global server.

Returns:

property_field

Return type:

PropertyField

Examples

>>> from ansys.dpf import core as dpf
>>> pfield = dpf.PropertyField()
>>> list_ids = [1, 2, 4, 6, 7]
>>> scop = dpf.Scoping(ids = list_ids, location = dpf.locations.nodal)
>>> pfield.scoping = scop
>>> list_data = [20, 30, 50, 70, 80]
>>> pfield.data = list_data

Overview#

get_entity_data

Return the data associated with the entity by index.

get_entity_data_by_id

Return the data associated with entity by id.

append

Append data to the property field.

as_local_field

Create a deep copy of the field locally.

location

Location of the property field.

component_count

Return the number of components.

elementary_data_count

Return the number of elementary data.

size

Return the data size.

name

Name of the property field.

shape

Numpy-like shape of the field.

elementary_data_shape

Numpy-like shape of the field.

ndim

scoping

Scoping specifying where the data is.

data

Data in the field as an array.

data_as_list

Data in the field as a Python list.

__str__

Describe the entity.

__len__

__del__

__enter__

__exit__

Import detail#

from ansys.dpf.core.property_field import PropertyField

Property detail#

property PropertyField.location#

Location of the property field.

A property field contains a scoping, which is the location that is read. To update location, directly update the scoping location.

Returns:

location – Location string, can be found in ansys.dpf.core.locations: ie. dpf.locations.nodal or dpf.locations.elemental.

Return type:

str

Examples

Create a property field and request the location.

>>> from ansys.dpf import core as dpf
>>> pfield = dpf.PropertyField()
>>> list_ids = [1, 2, 4, 6, 7]
>>> scop = dpf.Scoping(ids = list_ids, location = dpf.locations.nodal)
>>> pfield.scoping = scop
>>> pfield.scoping.location = dpf.locations.nodal
>>> pfield.location
'Nodal'
property PropertyField.component_count#

Return the number of components.

property PropertyField.elementary_data_count#

Return the number of elementary data.

property PropertyField.size#

Return the data size.

property PropertyField.name#

Name of the property field.

..note:

Available starting with DPF 2024.2.pre1.

property PropertyField.shape#

Numpy-like shape of the field.

Return type:

tuple

Examples

Shape of a stress field.

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.download_transient_result())
>>> s_op =model.results.stress()
>>> s_fc = s_op.outputs.fields_container()
>>> field = s_fc[0]
>>> field.shape
(5720, 6)
property PropertyField.elementary_data_shape#

Numpy-like shape of the field.

property PropertyField.ndim#
property PropertyField.scoping#

Scoping specifying where the data is.

Each entity data is on a given scoping ID.

Returns:

scoping

Return type:

ansys.dpf.core.scoping.Scoping

Examples

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> transient = examples.download_transient_result()
>>> model = dpf.Model(transient)
>>> stress_op = model.results.stress()
>>> fields_container = stress_op.outputs.fields_container()
>>> scoping = fields_container[0].scoping
>>> scoping.location
'Elemental'
>>> scoping.id(3)
586
>>> #The fourth elementary data of the field corresponds to
>>> #the element id number 586 in the mesh
property PropertyField.data#

Data in the field as an array.

Returns:

Data in the field.

Return type:

numpy.ndarray

Notes

Print a progress bar.

property PropertyField.data_as_list#

Data in the field as a Python list.

Returns:

List of the data in the field.

Return type:

List

Notes

Print a progress bar.

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()
>>> fields_container = disp.outputs.fields_container()
>>> field = fields_container[0]
>>> # field.data_as_list

Method detail#

PropertyField.get_entity_data(index)#

Return the data associated with the entity by index.

PropertyField.get_entity_data_by_id(id)#

Return the data associated with entity by id.

PropertyField.append(data, scopingid)#

Append data to the property field.

This method appends data to the property field for a specific scoping ID.

PropertyField.as_local_field()#

Create a deep copy of the field locally.

This copy can then be accessed and modified locally, without a request being sent to the server. This method should be used in a with statement so that the local field is released and the data is sent to the server in one action. If it’s not used in a with statement, the method release_data() should be used to actually update the field.

Warning

If this as_local_field method is not used as a context manager in a with statement or if the method release_data() is not called, the data will not actually be updated.

Returns:

local_field

Return type:

PropertyField

Examples

>>> from ansys.dpf import core as dpf
>>> num_entities = 5
>>> field_to_local = dpf.PropertyField(num_entities, dpf.natures.scalar)
>>> with field_to_local.as_local_field() as f:
...     for i in range(1,num_entities+1):
...         f.append(list(range(i,i+3)),i)
...         print(f.get_entity_data(i-1))
[1 2 3]
[2 3 4]
[3 4 5]
[4 5 6]
[5 6 7]
PropertyField.__str__()#

Describe the entity.

Returns:

Description of the entity.

Return type:

str

PropertyField.__len__()#
PropertyField.__del__()#
PropertyField.__enter__()#
PropertyField.__exit__(exc_type, exc_value, tb)#