PropertyField#
- class ansys.dpf.core.property_field.PropertyField(nentities=0, nature=natures.scalar, location='Nodal', property_field=None, server=None)#
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 isansys.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:
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
- property 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
ordpf.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 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)#
Retrieves the elementary data of the scoping’s index in an array.
- Return type:
numpy.ndarray
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() >>> fields_container[0].get_entity_data(0) DPFArray([[-3.27795062e+05, 1.36012200e+06, 1.49090608e+08, -4.88688900e+06, 1.43038560e+07, 1.65455040e+07], [-4.63817550e+06, 1.29312225e+06, 1.20411832e+08, -6.06617800e+06, 2.34829700e+07, 1.77231120e+07], [-2.35684860e+07, -3.53474400e+07, 2.01501168e+08, -5.23361700e+06, -2.88789280e+07, -6.16478200e+06], [-3.92756960e+07, -2.72369280e+07, 1.81454016e+08, -3.75441450e+06, -3.62480300e+06, -3.26075620e+07], [ 1.63554530e+07, 2.83190520e+07, 1.05084256e+08, -1.30219020e+07, 5.19906719e+05, 8.82430200e+06], [ 1.80755620e+07, 5.25578750e+06, 7.76211600e+07, -7.53063750e+06, 2.44717000e+06, 2.92675125e+06], [ 9.25567760e+07, 8.15244320e+07, 2.77157632e+08, -1.48489875e+06, 5.89250600e+07, 2.05608920e+07], [ 6.70443680e+07, 8.70343440e+07, 2.73050464e+08, -2.48670150e+06, 1.52268930e+07, 6.09583280e+07]]...
- get_entity_data_by_id(id)#
Retrieve the data of the scoping’s ID in the parameter of the field in an array.
- Returns:
Data based on the scoping ID.
- Return type:
numpy.ndarray
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() >>> fields_container[0].get_entity_data_by_id(391) DPFArray([[-3.27795062e+05, 1.36012200e+06, 1.49090608e+08, -4.88688900e+06, 1.43038560e+07, 1.65455040e+07], [-4.63817550e+06, 1.29312225e+06, 1.20411832e+08, -6.06617800e+06, 2.34829700e+07, 1.77231120e+07], [-2.35684860e+07, -3.53474400e+07, 2.01501168e+08, -5.23361700e+06, -2.88789280e+07, -6.16478200e+06], [-3.92756960e+07, -2.72369280e+07, 1.81454016e+08, -3.75441450e+06, -3.62480300e+06, -3.26075620e+07], [ 1.63554530e+07, 2.83190520e+07, 1.05084256e+08, -1.30219020e+07, 5.19906719e+05, 8.82430200e+06], [ 1.80755620e+07, 5.25578750e+06, 7.76211600e+07, -7.53063750e+06, 2.44717000e+06, 2.92675125e+06], [ 9.25567760e+07, 8.15244320e+07, 2.77157632e+08, -1.48489875e+06, 5.89250600e+07, 2.05608920e+07], [ 6.70443680e+07, 8.70343440e+07, 2.73050464e+08, -2.48670150e+06, 1.52268930e+07, 6.09583280e+07]]...
- 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]...
- 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 awith
statement, the methodrelease_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 methodrelease_data()
is not called, the data will not actually be updated.- Returns:
local_field
- Return type:
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]
- property name#
Name of the property field.
- ..note:
Available starting with DPF 2024.2.pre1.
- 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:
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)