fields_factory#

Contains functions to simplify creating fields.

ansys.dpf.core.fields_factory.field_from_array(arr, server=None)#

Create a DPF vector or scalar field from a numpy array or a Python list.

Parameters:
  • arr (np.ndarray or List) – Numpy array or Python list containing either 1 or 3 dimensions.

  • 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.

Returns:

field – Field constructed from the array.

Return type:

Field

ansys.dpf.core.fields_factory.create_matrix_field(num_entities, num_lines, num_col, location='Nodal', server=None)#

Create a matrix ansys.dpf.core.Field.

This field contains entities that have a matrix format. This is a “reserve” mechanism, not a resize one. This means that you need to append data to grow the size of your field.

Parameters:
  • num_entities (int) – Number of entities to reserve.

  • num_lines (int) – Number of matrix line.

  • num_col (int) – Number of matrix columns.

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

  • 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.

Returns:

field – DPF field of the requested format.

Return type:

Field

Examples

Create a field containing 3 matrix entities of a col*lines = 2*5 size with a nodal location (default).

>>> from ansys.dpf.core import fields_factory
>>> field = fields_factory.create_matrix_field(3, 5, 2)
ansys.dpf.core.fields_factory.create_3d_vector_field(num_entities, location='Nodal', server=None)#

Create a specific ansys.dpf.core.Field with entities that have 3D vector format.

This is a “reserve” mechanism, not a resize one. This means that you need to append data to grow the size of your field.

Parameters:
  • num_entities (int) – Number of entities to reserve

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

  • 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.

Returns:

field – DPF field of the requested format.

Return type:

Field

Examples

Create a field containing 4 3D vector entities with a nodal location (default).

>>> from ansys.dpf.core import fields_factory
>>> field = fields_factory.create_3d_vector_field(4)
ansys.dpf.core.fields_factory.create_tensor_field(num_entities, location='Nodal', server=None)#

Create a specific ansys.dpf.core.Field with entities that have a 3*3 format.

This is a “reserve” mechanism, not a resize one. This means that you need to append data to grow the size of your field.

Parameters:
  • num_entities (int) – Number of entities to reserve.

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

  • 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.

Returns:

field – DPF field in the requested format.

Return type:

Field

Examples

Create a field containing 4 tensor entities with a nodal location (default).

>>> from ansys.dpf.core import fields_factory
>>> field = fields_factory.create_tensor_field(4)
ansys.dpf.core.fields_factory.create_scalar_field(num_entities, location='Nodal', server=None)#

Create a specific :class:`ansys.dpf.core.Field with entities that are scalar.

This is a “reserve” mechanism, not a resize one. This means that you need to append data to grow the size of your field.

Parameters:
  • num_entities (int) – Number of entities to reserve

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

  • 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.

Returns:

field – DPF field in the requested format.

Return type:

Field

Examples

Create a field containing 4 scalars with a nodal location (default).

>>> from ansys.dpf.core import fields_factory
>>> field = fields_factory.create_scalar_field(4)
ansys.dpf.core.fields_factory.create_vector_field(num_entities, num_comp, location='Nodal', server=None)#

Create a specific :class:`ansys.dpf.core.Field with entities that have a vector format.

This is a “reserve” mechanism, not a resize one. This means that you need to append data to grow the size of your field.

Parameters:
  • num_entities (int) – Number of entities to reserve.

  • num_comp (int) – Number of vector components.

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

  • 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.

Returns:

field – DPF field in the requested format.

Return type:

Field

Examples

Create a field containing 3 vector entities of 5 components each with a nodal location (default).

>>> from ansys.dpf.core import fields_factory
>>> field = fields_factory.create_vector_field(3, 5)
ansys.dpf.core.fields_factory.create_overall_field(value, nature, num_entities, num_comp, location='overall', server=None)#

Create a specific :class:`ansys.dpf.core.Field with entities that have an overall location.

Regarding the nature of the entity contained in the field, we set the same value for all elements.

Parameters:
  • value (float) – Value of the entity

  • nature (str) –

    Nature of the field entity data. For example:

    • ansys.dpf.core.natures.matrix

    • ansys.dpf.core.natures.scalar

  • num_entities (int) – Number of entities to reserve.

  • num_comp (int) – Number of vector components.

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

  • 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.

Returns:

field – DPF field in the requested format.

Return type:

Field

Examples

Create a field containing 10 scalar entities of 1 component each with an overall location (default). Same value (1.0) is set for all element of the field.

>>> from ansys.dpf.core import fields_factory
>>> field = fields_factory.create_overall_field(1.0, natures.scalar, 10, 1)