Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples from Operators section to Field API #1999

Merged
merged 12 commits into from
Jan 10, 2025
42 changes: 40 additions & 2 deletions src/ansys/dpf/core/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class Field(_FieldBase):
The field's scoping defines the order of the data, for example: the first ID in the
``scoping`` identifies to which entity the first ``entity data`` belongs.

The minimum requirement for a well defined field is for it to have a dimensionality
(scalar, three components vector, six components symmetrical matrix, and so on), a location
("Nodal", "Elemental", "ElementalNodal", "Timefrq"), a data vector and a scoping with IDs.
JennaPaikowsky marked this conversation as resolved.
Show resolved Hide resolved
JennaPaikowsky marked this conversation as resolved.
Show resolved Hide resolved
You can also set the number of shell layers. If the field has one elementary data by entity
(elementary data size equals the number of components for "Nodal" or "Elemental" field for example),
then the data vector can be set directly. If a more complex field is required
("ElementalNodal" field for example), the data can be set entity by entity.

For more information, see the `Fields container and fields
<https://dpf.docs.pyansys.com/version/stable/user_guide/fields_container.html>`_
documentation section.
JennaPaikowsky marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -81,12 +89,42 @@ class Field(_FieldBase):
--------
Create a field from scratch.

>>> from ansys.dpf.core import fields_factory
>>> from ansys.dpf.core import locations
>>> from ansys.dpf import core as dpf
>>> field_with_classic_api = dpf.Field()
>>> field_with_classic_api.location = locations.nodal
JennaPaikowsky marked this conversation as resolved.
Show resolved Hide resolved
>>> field_with_factory = fields_factory.create_scalar_field(10)


Create a field from scratch for the most common dimensionalities
JennaPaikowsky marked this conversation as resolved.
Show resolved Hide resolved
>>> from ansys.dpf import core as dpf
>>> num_entities = 2
>>> my_field = dpf.Field(num_entities, dpf.natures.scalar, "Nodal")
>>> my_field = dpf.Field(num_entities, dpf.natures.vector, "ElementalNodal")
>>> my_field = dpf.Field(num_entities, dpf.natures.symmatrix, "Elemental")
JennaPaikowsky marked this conversation as resolved.
Show resolved Hide resolved
>>> my_scoping = dpf.Scoping()
>>> my_scoping.location = "Elemental"
>>> my_scoping.ids = list(range(1,3))
JennaPaikowsky marked this conversation as resolved.
Show resolved Hide resolved
>>> my_field.scoping = my_scoping

Add all the data at once

JennaPaikowsky marked this conversation as resolved.
Show resolved Hide resolved
>>> from ansys.dpf import core as dpf
>>> my_data = [1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0]
>>> my_field.data = my_data

Add data entity by entity
>>> from ansys.dpf import core as dpf
>>> my_elem_data = [1.0,1.0,1.0,0.0,0.0,0.0]
>>> my_field.append(my_elem_data, scopingid=1)
>>> my_field.append(my_elem_data, scopingid=2)

Create a field using the fields factory
JennaPaikowsky marked this conversation as resolved.
Show resolved Hide resolved

>>> from ansys.dpf.core import fields_factory
>>> from ansys.dpf.core import locations
JennaPaikowsky marked this conversation as resolved.
Show resolved Hide resolved
>>> from ansys.dpf import core as dpf
>>> my_scalar_field = fields_factory.create_scalar_field(2)
JennaPaikowsky marked this conversation as resolved.
Show resolved Hide resolved
>>> my_scalar_field.data = [1.0, 3.0]

Extract a displacement field from a transient result file.

Expand Down
Loading