CustomTypeField#

class ansys.dpf.core.custom_type_field.dict_with_missing_numpy_type#
clear() None.  Remove all items from D.#
copy() a shallow copy of D#
fromkeys(value=None, /)#

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)#

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items#
keys() a set-like object providing a view on D's keys#
pop(k[, d]) v, remove specified key and return the corresponding value.#

If key is not found, default is returned if given, otherwise KeyError is raised

popitem()#

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)#

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.#

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values#
class ansys.dpf.core.custom_type_field.CustomTypeField(unitary_type=None, nentities=0, field=None, server=None)#

Represents a simulation data container with each unitary data being of a custom type. When initializing the CustomTypeField class, provide a unitary data type. The CustomTypeField class gives you the ability to choose the most optimized unitary data type for a given usage, and hence, allows you to optimize memory usage.

This can be evaluated data from the Operator class or created directly by an instance of this class.

A field’s data is always associated to its scoping (entities associated to each value) and support (subset of the model where the data is), making the field a self-describing piece of data.

Parameters:
  • unitary_type (numpy.dtype) – The data vector of the Field will be a vector of this custom unitary type.

  • nentities (int, optional) – Number of entities reserved. The default is 0.

  • field (CustomTypeField, ansys.grpc.dpf.field_pb2.Field, ctypes.c_void_p, optional) – Field message generated from a gRPC stub, or returned by DPF’s C clients.

  • server (ansys.dpf.core.server, 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.

Examples

Create a custom type field from scratch.

>>> from ansys.dpf.core import locations
>>> from ansys.dpf import core as dpf
>>> import numpy as np
>>> field = dpf.CustomTypeField(unitary_type=np.uint64)
>>> field.location = locations.nodal
>>> field.append([1000000,2000000], 1)
>>> float_field = dpf.CustomTypeField(unitary_type=np.float32)
>>> float_field.is_of_type(np.float32)
True

Notes

Class available with server’s version starting at 5.0 (Ansys 2023R1).

property location#

CustomTypeField location.

Returns:

Location string, which can be "Nodal", "Elemental", "ElementalNodal"… See ansys.dpf.core.common.locations.

Return type:

str

Examples

>>> from ansys.dpf.core import locations
>>> from ansys.dpf import core as dpf
>>> import numpy as np
>>> field = dpf.CustomTypeField(unitary_type=np.uint64)
>>> field.location = locations.nodal
>>> field.location
'Nodal'
is_of_type(type_to_compare: numpy.dtype)#

Checks whether the Field’s unitary type is the same as the input type.

Parameters:

type_to_compare (numpy.dtype) –

Return type:

bool

Examples

Create a custom type field from scratch.

>>> from ansys.dpf import core as dpf
>>> import numpy as np
>>> field = dpf.CustomTypeField(unitary_type=np.int16)
>>> field.is_of_type(np.int16)
True
>>> field.is_of_type(np.short)
True
>>> field.is_of_type(np.int32)
False
property type#

Type of unitary data in the Field’s data vector. Should be properly set at the Field construction to have properly allocated data.

Return type:

numpy.dtype

Examples

>>> from ansys.dpf.core import locations
>>> from ansys.dpf import core as dpf
>>> import numpy as np
>>> field = dpf.CustomTypeField(unitary_type=np.uint64)
>>> field.type
dtype('uint64')
property component_count#

Number of components in each elementary data of the field.

Returns:

Number of components in each elementary data of the field.

Return type:

int

property elementary_data_count#

Number of elementary data in the field.

Returns:

Number of elementary data in the field.

Return type:

int

property size#

Length of the data vector.

The length is equal to the number of elementary data times the number of components.

Returns:

Length of the data vector.

Return type:

int

get_entity_data(index)#

Returns the array corresponding to the data of a given entity index.

Parameters:

index (int) – Index in the Scoping.

Return type:

numpy.ndarray

Examples

>>> from ansys.dpf.core import locations
>>> from ansys.dpf import core as dpf
>>> import numpy as np
>>> field = dpf.CustomTypeField(unitary_type=np.uint64)
>>> field.append([1000000, 2000000], 1)
>>> field.append([1000000, 2000000, 3000000], 2)
>>> field.get_entity_data(0)
DPFArray([1000000, 2000000]...
>>> field.get_entity_data(1)
DPFArray([1000000, 2000000, 3000000]...
get_entity_data_by_id(id)#

Returns the array corresponding to the data of a given entity id.

Parameters:

id (int) – Entity ID in the Scoping.

Return type:

numpy.ndarray

Examples

>>> from ansys.dpf.core import locations
>>> from ansys.dpf import core as dpf
>>> import numpy as np
>>> field = dpf.CustomTypeField(unitary_type=np.uint64)
>>> field.append([1000000, 2000000], 1)
>>> field.append([1000000, 2000000, 3000000], 2)
>>> field.get_entity_data_by_id(1)
DPFArray([1000000, 2000000]...
>>> field.get_entity_data_by_id(2)
DPFArray([1000000, 2000000, 3000000]...
append(data, scopingid)#

Add an entity data to the existing data.

Parameters:
  • data (list of int, double, or array) – Data in the entity.

  • scopingid (int) – ID of the scoping.

Examples

>>> from ansys.dpf.core import fields_factory
>>> field = fields_factory.create_3d_vector_field(2)
>>> field.append([1.,2.,3.],1)
>>> field.append([1.,2.,3.],2)
>>> field.data
DPFArray([[1., 2., 3.],
       [1., 2., 3.]]...
>>> field.scoping.ids

...[1, 2]...
resize(nentities, datasize)#

Allocate memory.

Parameters:
  • nentities (int) – Number of IDs in the scoping.

  • datasize (int) – Size of the data vector.

property unit#

Units for the field.

Returns:

Units for the field.

Return type:

str

Examples

Units for a displacement field.

>>> from ansys.dpf import core as dpf
>>> my_field = dpf.CustomTypeField(int, 10)
>>> my_field.unit = "m"
>>> my_field.unit
'm'
property dimensionality#

Dimensionality represents the shape of the elementary data contained in the field.

Returns:

dimensionality – Nature and size of the elementary data.

Return type:

ansys.dpf.core.dimensionality.Dimensionality

property name#

Name of the field.

property data#

Data in the field as an array.

Returns:

Data in the field.

Return type:

numpy.ndarray

Notes

Print a progress bar.

property 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
property elementary_data_shape#

Numpy-like shape of the field.

property 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 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 field_definition#

CustomTypeField information, including its location, unit, dimensionality and shell layers.

Return type:

ansys.dpf.core.field_definition.FieldDefinition