Field data#
Field data is an attribute of a session and thus an object. With PyFluent, you can access Fluent surface, scalar, and vector field data.
Multiple fields in a request#
You can get data for multiple fields in a single request and see the data for all of these fields in a single response.
Request
The add_get_<items>_request
methods combine requests for multiple fields in a single request:
add_get_surfaces_request
adds a surfaces request.add_get_scalar_fields_request
adds a scalar fields request.add_get_vector_fields_request
adds a vector fields request.
Response
The get_fields
method returns all requested fields in a single response. It provides
a dictionary containing the requested fields as a numpy array in the following order:
tag_id [int]-> surface_id [int] -> field_name [str] -> field_data[np.array]
Tag ID#
A tag ID is 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_id
is 2
. Similarly, if you request the boundary values[8] for
node location[4], tag_id
is (4|8)
, or 12.
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 connectivityvertices
, which contain node coordinatescentroid
, which contains face centroidsface-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 requestvector-scale
, a float value indicating the vector scale.
Example#
#Get field data
field_data = session.field_data
#Add requests
#Data for surfaces for following requests will be returned in tag_id 0. As there is no tag.
field_data.add_get_surfaces_request(surface_ids=[1], provide_vertices=True,
provide_faces=False, provide_faces_centroid=True
)
field_data.add_get_surfaces_request(surface_ids=[2], provide_vertices=True,
provide_faces=True
)
#Data for tempaeraure for following request will be returned in tag_id 12 i.e. 4|8.
field_data.add_get_scalar_fields_request(surface_ids=[1,2], field_name="temperature",
node_value=True, boundary_value=True
)
#Data for tempaeraure for following request will be returned in tag_id 4.
field_data.add_get_scalar_fields_request(surface_ids=[3], field_name="temperature",
node_value=True, boundary_value=False
)
#Data for pressure for following request will be returned in tag_id 2.
field_data.add_get_scalar_fields_request(surface_ids=[1,4], field_name="pressure",
node_value=False, boundary_value=False
)
#Get fields
payload_data = field_data.get_fields()
#Data will be returned in dictionary with order
#`tag_id [int]-> surface_id [int] -> field_name [str] -> field_data [np.array]`
{
0:{
1:{
"vertices": np.array #for vertices.
"centroid": np.array #for faces centroid.
},
2:{
"vertices": np.array #for vertices.
"faces": np.array #for faces connectivity.
},
},
12:{
1:{
"temperature": np.array #for temperature at node location with boundary values.
},
2:{
"temperature": np.array #for temperature at node location with boundary values.
},
},
4:{
3:{
"temperature": np.array #for temperature at node location.
}
},
2:{
1:{
"pressure": np.array #for pressure at element location.
},
4:{
"pressure": np.array #for pressure at element location.
},
},
}
One field per request#
You can receive one field for each request. There is a separate method for each type of field (surface, scalar, or vector):
get_surface_data
gets surface data.get_scalar_field_data
gets scalar field data.get_vector_field_data
gets vector field data.
For a surface or scalar field request, the response contains a dictionary of surface IDs and a numpy array of the requested field.
surface_id [int] -> field[np.array]
For a vector field request, the response is a dictionary of surface IDs and a tuple of a numpy array of vector field
and vector-scale
.
surface_id [int] -> (vector field [np.array], vector-scale [float])
Note
In Fluent, you can associate a surface name with multiple surface IDs. Thus, a response can contain a surface ID as a key of the returned dictionary.
Example#
from ansys.fluent.core.services.field_data import SurfaceDataType
#Get field data object
field_data = session.field_data
#wall surface is associated with two IDs i.e. id1 and id2
#Get surface data
vertices = field_data.get_surface_data("wall", SurfaceDataType.Vertices)
#return value>> {id1: np.array, id2: np.array}
normals = field_data.get_surface_data("wall", SurfaceDataType.FacesNormal)
#return value>> {id1: np.array, id2: np.array}
#Get scalar field data
scalar_field_data = field_data.get_scalar_field_data("wall", "temperature")
#return value>> {id1: np.array, id2: np.array}
#Get vector field data
vector_field_data = field_data.get_vector_field_data("wall", "velocity")
#return value>> {id1: (np.array, float), id2: (np.array, float)}
- FieldData.add_get_surfaces_request(surface_ids, 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_ids
List
[int
] List of surface IDS 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
- surface_ids
- Returns:
- Return type:
- FieldData.add_get_scalar_fields_request(surface_ids, field_name, node_value=True, boundary_value=False)#
Add request to get scalar field data on surfaces.
- Parameters:
- surface_ids
List
[int
] List of surface IDs for scalar field data.
- field_name
str
Name of the scalar field.
- node_valuebool,
optional
Whether to provide the nodal location. The default is
True
. IfFalse
, the element location is provided.- boundary_valuebool,
optional
Whether to provide the slip velocity at the wall boundaries. The default is
False
. WhenTrue
, no slip velocity is provided.
- surface_ids
- Returns:
- Return type:
- FieldData.add_get_vector_fields_request(surface_ids, vector_field='velocity')#
Add request to get vector field data on surfaces.
- Parameters:
- Returns:
- Return type:
- FieldData.get_fields()#
Get data for previously added requests.
- Returns:
- FieldData.get_surface_data(surface_name, data_type, overset_mesh=False)#
Get surface data (vertices, faces connectivity, centroids, and normals).
- Parameters:
- Returns:
Dict
[int
,np.array
]Dictionary containing a map of surface IDs to surface data.
- FieldData.get_scalar_field_data(surface_name, field_name, node_value=True, boundary_value=False)#
Get scalar field data on a surface.
- Parameters:
- surface_name
str
Name of the surface.
- field_name
str
Name of the scalar field.
- node_valuebool,
optional
Whether to provide data for the nodal location. The default is
True
. WhenFalse
, data is provided for the element location.- boundary_valuebool,
optional
Whether to provide slip velocity at the wall boundaries. The default is
False
. WhenTrue
, no slip velocity is provided.
- surface_name
- Returns:
Dict
[int
,np.array
]Dictionary containing a map of surface IDs to the scalar field.
- FieldData.get_vector_field_data(surface_name, vector_field='velocity')#
Get vector field data on a surface.
- Parameters:
- Returns: