fields_factory

Contains functions to make easy fields creation.

ansys.dpf.core.fields_factory.field_from_array(arr)

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

Returns

field – Field constructed from numpy array.

Return type

Field

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

Helper function to create a specific ansys.dpf.core.Field. The returned field will contain entities that have matrix format. This is a “reserve” mechanism, not a resize one. This means that you need to append data to grow up the size of your field.

Parameters
  • num_entities (int) – Number of entities reserved

  • num_lines (int) – Number of matrix lines

  • num_col (int) – Number of matrix columns

  • location (str, optional) –

    Location of the field. Default: "Nodal". For example:

    • "Nodal"

    • "Elemental"

    • ansys.dpf.core.natures.elemental_nodal

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the the global server.

Returns

field – Dpf field at the requested format.

Return type

Field

Examples

Create field containing 3 matrix entities of a col*lines = 2*5 size with 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)

Helper function to create a specific ansys.dpf.core.Field. The returned field will contain 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 up the size of your field.

Parameters
  • num_entities (int) – Number of entities reserved

  • location (str, optional) –

    Location of the field. Default: "Nodal". For example:

    • "Nodal"

    • "Elemental"

    • ansys.dpf.core.natures.elemental_nodal

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the the global server.

Returns

field – Dpf field at the requested format.

Return type

Field

Examples

Create field containing 4 3d vector entities with 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)

Helper function to create a specific ansys.dpf.core.Field. The returned field will contain entities that have 3*3 format. This is a “reserve” mechanism, not a resize one. This means that you need to append data to grow up the size of your field.

Parameters
  • num_entities (int) – Number of entities reserved

  • location (str, optional) –

    Location of the field. Default: "Nodal". For example:

    • "Nodal"

    • "Elemental"

    • ansys.dpf.core.natures.elemental_nodal

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the the global server.

Returns

field – Dpf field at the requested format.

Return type

Field

Examples

Create field containing 4 tensor entities with 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)

Helper function to create a specific ansys.dpf.core.Field. The returned field will contain entities that are scalar. This is a “reserve” mechanism, not a resize one. This means that you need to append data to grow up the size of your field.

Parameters
  • num_entities (int) – Number of entities reserved

  • location (str, optional) –

    Location of the field. Default: "Nodal". For example:

    • "Nodal"

    • "Elemental"

    • ansys.dpf.core.natures.elemental_nodal

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the the global server.

Returns

field – Dpf field at the requested format.

Return type

Field

Examples

Create field containing 4 scalars with 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)

Helper function to create a specific ansys.dpf.core.Field. The returned field will contain entities that have vector format. This is a “reserve” mechanism, not a resize one. This means that you need to append data to grow up the size of your field.

Parameters
  • num_entities (int) – Number of entities reserved

  • num_comp (int) – Number of vector’s components

  • location (str, optional) –

    Location of the field. Default: "Nodal". For example:

    • "Nodal"

    • "Elemental"

    • ansys.dpf.core.natures.elemental_nodal

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the the global server.

Returns

field – Dpf field at the requested format.

Return type

Field

Examples

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

>>> from ansys.dpf.core import fields_factory
>>> field = fields_factory.create_vector_field(3, 5)