Field data#

You can use field data objects to access Fluent surface, scalar, vector, and pathlines data.

Accessing field data objects#

In order to access field data, launch the fluent solver, and make field data available (for example, by reading case and data files):

>>> import ansys.fluent.core as pyfluent
>>> solver = pyfluent.launch_fluent(mode="solver")
>>> solver.file.read(file_type="case-dats", file_name=mixing_elbow_case_path)

The field data object is an attribute of the solver object:

>>> field_data = solver.field_data

Simple requests#

Here are the methods for requesting each type of field:

  • get_surface_data for surface data.

  • get_scalar_field_data for scalar field data.

  • get_vector_field_data for vector field data

  • get_pathlines_field_data for vector field data

Get surface data#

You can request surface vertices for a given surface_name by calling the get_surface_data method and specifying Vertices for data_type.

>>> from ansys.fluent.core.services.field_data import SurfaceDataType

>>> field_data.get_surface_data(surface_name="inlet", data_type=SurfaceDataType.Vertices)
{4: array([-0.34760258,  0.        , -0.04240644, ..., -0.2953132 ,
      0.        , -0.06207064], dtype=float32)}

You can call the same method to get the corresponding surface face connectivity, normals, and centroids by specifying FacesConnectivity, FacesNormal and FacesCentroid respectively for data_type.

>>> field_data.get_surface_data(surface_name="inlet", data_type=SurfaceDataType.FacesConnectivity)
{4: array([  4,   3,   2, ..., 379, 382, 388])}

>>> field_data.get_surface_data(surface_name="inlet", data_type=SurfaceDataType.FacesNormal)
{4: array([ 0.0000000e+00,  2.5835081e-06,  ...,
        2.7459005e-06,  0.0000000e+00,  0.0000000e+00,  3.0340884e-06], dtype=float32)}

>>> field_data.get_surface_data(surface_name="inlet", data_type=SurfaceDataType.FacesCentroid)
{4: array([-0.34724122,  0.        , -0.0442204 , -0.34724477, ...,
       -0.04050309, -0.34645557,  0.        , -0.04421487, -0.34646705], dtype=float32)}

Response contains a dictionary of surface IDs to numpy array of the requested field.

Get scalar field data#

You can call the get_scalar_field_data method to get scalar field data, such as temperature:

>>> field_data.get_scalar_field_data(surface_name="inlet", field_name="temperature")
{4: array([922.6778 , 923.7954 , 923.791  , 922.67017, 922.88135,  ...,
       924.94556, 924.9451 , 924.9536 , 923.87366, 922.8334 , 922.82434], dtype=float32)}

The response contains a dictionary of surface IDs to a numpy array of the requested field.

Get vector field data#

You can call the get_vector_field_data method to get vector field data.

>>> field_data.get_vector_field_data(surface_name="inlet", vector_field="velocity")
{4: (array([ 5.81938386e-01, -1.01187916e+01,  3.14891455e-03,  ...,
      -6.49216697e-02,  1.44923580e+00, -1.04387817e+01], dtype=float32), 0.00012235096)}

Response is a dictionary of surface IDs to a tuple containing a numpy array of vector field and vector-scale.

Get pathlines field data#

You can call the get_pathlines_field_data method to get pathlines field data.

>>> field_data.get_pathlines_field_data(surface_name="inlet", field_name="temperature")
{4: {'vertices': array([-0.34724122,  0.        , -0.0442204 , ..., -0.20095952, -0.1250188 , -0.0317937 ], dtype=float32),
    'lines': array([    2,     0,     1, ...,     2, 29581, 29582]), 'temperature': array([879.1005 , 831.87085, 861.82495, ..., 899.1867 , 892.27   ,
     896.4489 ], dtype=float32), 'pathlines-count': array([90])}}

Pathlines data is returned as line surface. So response is a dictionary of surface IDs to a information about line surface.

Note

In Fluent, a surface name can be associated with multiple surface IDs. Thus, a response contain a surface ID as a key of the returned dictionary.

Making multiple requests in a single transaction#

You can get data for multiple fields in a single transaction.

First create transaction object for field data.

>>> transaction = solver.field_data.new_transaction()

Then combine requests for multiple fields using add_<items>_request methods in a single transaction:

  • add_surfaces_request adds a surfaces request.

  • add_scalar_fields_request adds a scalar fields request.

  • add_vector_fields_request adds a vector fields request.

  • add_pathlines_fields_request adds a pathlines fields request.

Following code demonstrate adding multiple requests to a single transaction.


>>> transaction.add_surfaces_request(surface_ids=[1], provide_vertices=True,
                                        provide_faces=False, provide_faces_centroid=True
                                       )
>>> transaction.add_surfaces_request(surface_ids=[2], provide_vertices=True,
                                       provide_faces=True
                                       )
>>> transaction.add_scalar_fields_request(surface_ids=[1,2], field_name="temperature",
                                            node_value=True, boundary_value=True
                                            )
>>> transaction.add_vector_fields_request(surface_ids=[1,2])
>>> transaction.add_pathlines_fields_request(surface_ids=[1,2], field_name="temperature"
                                            )

You can call the get_fields method to get the data for all these requests. This call also clears all requests, so that subsequent calls to the get_fields method yield nothing until more requests are added.


>>> payload_data = transaction.get_fields()

payload_data is a dictionary containing the requested fields as a numpy array in the following order:

tag -> surface_id [int] -> field_name [str] -> field_data[np.array]

Tag#

Fluent versions earlier than 2023 R1#

A tag is int, generated by applying bitwise or on all tags for a request. Here is a list of supported tags and their values:

  • OVERSET_MESH: 1,

  • ELEMENT_LOCATION: 2,

  • NODE_LOCATION: 4,

  • BOUNDARY_VALUES: 8,

For example, if you request the scalar field data for element location[2], in the dictionary, tag is 2. Similarly, if you request the boundary values[8] for node location[4], tag is (4|8) or 12.

Fluent versions 2023 R1 and later#

A tag is tuple of input, value pairs for which field data is generated.

For example, if you request the scalar field data for element location, in the dictionary, tag is (('type','scalar-field'), ('dataLocation', 1), ('boundaryValues',False)). Similarly, if you request the boundary values for node location, tag is (('type','scalar-field'), ('dataLocation', 0), ('boundaryValues',True).

Surface ID#

The surface ID is the same one that is passed in the request.

Field name#

A request returns multiple fields. The number of fields depends on the request type.

Surface request#

The response to a surface request contains any of the following fields, depending on the request arguments:

  • faces, which contain face connectivity

  • vertices, which contain node coordinates

  • centroid, which contains face centroids

  • face-normal, which contains face normals

Scalar field request#

The response to a scalar field request contains a single field with the same name as the scalar field name passed in the request.

Vector field request#

The response to a vector field request contains two fields:

  • vector field, with the same name as the vector field name that is passed in the request

  • vector-scale, a float value indicating the vector scale.

Pathlines field request#

The response to a pathlines field request contains the following fields:

  • pathlines-count, which contains pathlines count.

  • lines, which contain pathlines connectivity.

  • vertices, which contain node coordinates.

  • field name, which contains pathlines field. field name is the same name as the scalar field name passed in the request.

  • particle-time, which contains particle time, if requested.

  • additional field name, which contains additional field, if requested. additional field name is the same name as the additional field name passed in the request.

FieldTransaction.add_surfaces_request(surface_ids=None, surface_names=None, overset_mesh=False, provide_vertices=True, provide_faces=True, provide_faces_centroid=False, provide_faces_normal=False)#

Add request to get surface data (vertices, face connectivity, centroids, and normals).

Parameters:
surface_idsList[int], optional

List of surface IDS for the surface data.

surface_names: List[str], optional

List of surface names for the surface data.

overset_meshbool, optional

Whether to get the overset met. The default is False.

provide_verticesbool, optional

Whether to get node coordinates. The default is True.

provide_facesbool, optional

Whether to get face connectivity. The default is True.

provide_faces_centroidbool, optional

Whether to get face centroids. The default is False.

provide_faces_normalbool, optional

Whether to get faces normal. The default is False

Returns:
None
Return type:

None

FieldTransaction.add_scalar_fields_request(field_name, surface_ids=None, surface_names=None, node_value=True, boundary_value=False)#

Add request to get scalar field data on surfaces.

Parameters:
field_namestr

Name of the scalar field.

surface_idsList[int], optional

List of surface IDs for scalar field data.

surface_names: List[str], optional

List of surface names for scalar field data.

node_valuebool, optional

Whether to provide the nodal location. The default is True. If False, the element location is provided.

boundary_valuebool, optional

Whether to provide the slip velocity at the wall boundaries. The default is False. When True, no slip velocity is provided.

Returns:
None
Return type:

None

FieldTransaction.add_vector_fields_request(field_name, surface_ids=None, surface_names=None)#

Add request to get vector field data on surfaces.

Parameters:
field_namestr

Name of the vector field.

surface_idsList[int], optional

List of surface IDs for vector field data.

surface_names: List[str], optional

List of surface names for vector field data.

Returns:
None
Return type:

None

FieldTransaction.add_pathlines_fields_request(field_name, surface_ids=None, surface_names=None, additional_field_name='', provide_particle_time_field=False, node_value=True, steps=500, step_size=0.01, skip=0, reverse=False, accuracy_control_on=False, tolerance=0.001, coarsen=1, velocity_domain='all-phases', zones=[])#

Add request to get pathlines field on surfaces.

Parameters:
field_namestr

Name of the scalar field to color pathlines.

surface_idsList[int], optional

List of surface IDs for pathlines field data.

surface_namesList[str], optional

List of surface names for pathlines field data.

additional_field_namestr, optional

Additional field if required.

provide_particle_time_field: bool, optional

Whether to provide the particle time. The default is False.

node_valuebool, optional

Whether to provide the nodal values. The default is True. If False, element values are provided.

steps: int, optional

Pathlines steps. The default is 500

step_size: float, optional

Pathlines step size. The default is 0.01.

skip: int, optional

Pathlines to skip. The default is 0.

reverse: bool, optional

Whether to draw pathlines in reverse direction. The default is False.

tolerance: float, optional

Pathlines tolerance. The default is 0.001.

coarsen: int, optional

Pathlines coarsen. The default is 1.

velocity_domain: str, optional

Domain for pathlines. The default is "all-phases".

zones: list, optional

Zones for pathlines. The default is [].

Returns
——-
None
Return type:

None

FieldTransaction.get_fields()#

Get data for previously added requests and then clear all requests.

Returns:
Dict[int, Dict[int, Dict[str, np.array]]]

Data is returned as dictionary of dictionaries in the following structure: tag Union[int, Tuple]-> surface_id [int] -> field_name [str] -> field_data[np.array]

The tag is a tuple for Fluent 2023 R1 or later.

Return type:

Dict[Union[int, Tuple], Dict[int, Dict[str, array]]]

FieldData.get_surface_data(data_type, surface_ids=None, surface_name=None, overset_mesh=False)#

Get surface data (vertices, faces connectivity, centroids, and normals).

Parameters:
data_typeSurfaceDataType

SurfaceDataType Enum member.

surface_idsList[int], optional

List of surface IDs for the surface data.

surface_namestr, optional

Surface name for the surface data.

overset_meshbool, optional

Whether to provide the overset method. The default is False.

Returns:
Dict[int, np.array]

Dictionary containing a map of surface IDs to surface data.

Return type:

Dict[int, array]

FieldData.get_scalar_field_data(field_name, surface_ids=None, surface_name=None, node_value=True, boundary_value=False)#

Get scalar field data on a surface.

Parameters:
field_namestr

Name of the scalar field.

surface_idsList[int], optional

List of surface IDs for scalar field data.

surface_name: str, optional

Surface Name for scalar field data.

node_valuebool, optional

Whether to provide data for the nodal location. The default is True. When False, data is provided for the element location.

boundary_valuebool, optional

Whether to provide slip velocity at the wall boundaries. The default is False. When True, no slip velocity is provided.

Returns:
Dict[int, np.array]

Dictionary containing a map of surface IDs to the scalar field.

Return type:

Dict[int, array]

FieldData.get_vector_field_data(field_name, surface_ids=None, surface_name=None)#

Get vector field data on a surface.

Parameters:
field_namestr

Name of the vector field.

surface_idsList[int], optional

List of surface IDs for vector field data.

surface_name: str, optional

Surface Name for vector field data.

Returns:
Dict[int, Tuple[np.array, float]]

Dictionary containing a map of surface IDs to a tuple of vector field and vector scale.

Return type:

Dict[int, Tuple[array, float]]

FieldData.get_pathlines_field_data(field_name, surface_ids=None, surface_name=None, additional_field_name='', provide_particle_time_field=False, node_value=True, steps=500, step_size=0.01, skip=0, reverse=False, accuracy_control_on=False, tolerance=0.001, coarsen=1, velocity_domain='all-phases', zones=[])#

Get pathlines field data on a surface.

Parameters:
field_namestr

Name of the scalar field to color pathlines.

surface_idsList[int], optional

List of surface IDs for pathlines field data.

surface_namestr, optional

Surface name for pathlines field data.

additional_field_namestr, optional

Additional field if required.

provide_particle_time_field: bool, optional

Whether to provide the particle time. The default is False.

node_valuebool, optional

Whether to provide the nodal values. The default is True. If False, element values are provided.

steps: int, optional

Pathlines steps. The default is 500

step_size: float, optional

Pathlines step size. The default is 0.01.

skip: int, optional

Pathlines to skip. The default is 0.

reverse: bool, optional

Whether to draw pathlines in reverse direction. The default is False.

tolerance: float, optional

Pathlines tolerance. The default is 0.001.

coarsen: int, optional

Pathlines coarsen. The default is 1.

velocity_domain: str, optional

Domain for pathlines. The default is "all-phases".

zones: list, optional

Zones for pathlines. The default is [].

Returns:
Dict[int, Dict[str, np.array]]

Dictionary containing a map of surface IDs to the pathline data For example, pathlines connectivity, vertices, and field.

Return type:

Dict[int, Dict[str, array]]