StringField
#
- class ansys.dpf.core.string_field.StringField(nentities=0, string_field=None, server=None)#
Bases:
ansys.dpf.core.field_base._FieldBase
Describes string data scoped on entities such as names.
This class is a field with string values instead of double values.
- Parameters:
nentities (int) – Number of entities that the string field is to contain (reserved). The default is
0
.string_field (Field, 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 (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.
Examples
>>> from ansys.dpf import core as dpf >>> pfield = dpf.StringField() >>> list_ids = [1, 2, 4, 6, 7] >>> scop = dpf.Scoping(ids = list_ids, location = dpf.locations.nodal) >>> pfield.scoping = scop >>> list_data = ["water", "oil", "gaz", "paint", "air"] >>> pfield.data = list_data
Notes
Class available with server’s version starting at 5.0 (Ansys 2023R1).
Overview#
Return entity data. |
|
Return entity data corresponding to the provided id. |
|
Append data to the string field. |
Location of the string field. |
|
Return the number of component, always 1. |
|
Return elementary data count. |
|
Return elementary data size. |
|
Numpy-like shape of the field. |
|
Numpy-like shape of the field. |
|
Scoping specifying where the data is. |
|
Data in the field as an array. |
|
Data in the field as a Python list. |
Import detail#
from ansys.dpf.core.string_field import StringField
Property detail#
- property StringField.location#
Location of the string 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
dpf.locations
: ie.dpf.locations.nodal
ordpf.locations.elemental
.- Return type:
str
Examples
Create a string field and request the location.
>>> from ansys.dpf import core as dpf >>> pfield = dpf.StringField() >>> 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 StringField.component_count#
Return the number of component, always 1.
- property StringField.elementary_data_count#
Return elementary data count.
- property StringField.size#
Return elementary data size.
- property StringField.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 StringField.elementary_data_shape#
Numpy-like shape of the field.
- property StringField.ndim#
- property StringField.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 StringField.data#
Data in the field as an array.
- Returns:
Data in the field.
- Return type:
numpy.ndarray
Notes
Print a progress bar.
- property StringField.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#
- StringField.get_entity_data(index)#
Return entity data.
- StringField.get_entity_data_by_id(id)#
Return entity data corresponding to the provided id.
- StringField.append(data: List[str], scopingid: int)#
Append data to the string field.
This method appends data to the string field for a specific scoping ID.
- StringField.__str__()#
Describe the entity.
- Returns:
Description of the entity.
- Return type:
str
- StringField.__len__()#
- StringField.__del__()#
- StringField.__enter__()#
- StringField.__exit__(exc_type, exc_value, tb)#