Skip to content

Commit c8509cd

Browse files
fix: Unavaialble field data for some surfaces. (#4345)
Sometimes some surfaces might be created but field data on them might not be available. For example please refer the issue: ansys/pyfluent-visualization#552 Now we are getting and returning the field data as empty array for these surfaces, just like Fluent does. We are additionally providing an warning that theses surfaces does not have field data. <img width="479" height="275" alt="image" src="https://github.com/user-attachments/assets/85c39d3b-70ae-4cd5-a8cc-2ce4d1b21746" /> We need to patch this with v0.34 to address an user bug. --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 2c4f170 commit c8509cd

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

doc/changelog.d/4345.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unavaialble field data for some surfaces.

src/ansys/fluent/core/file_session.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,20 @@ def get_field_data(
186186
| PathlinesFieldDataRequest
187187
),
188188
) -> Dict[int | str, Dict | np.array]:
189-
"""Get the surface, scalar, vector or path-lines field data on a surface."""
189+
"""Get the surface, scalar, vector or path-lines field data on a surface.
190+
191+
Returns
192+
-------
193+
Dict[int | str, Dict | np.array]
194+
Field data for the requested surface. If field data is unavailable for the surface,
195+
an empty array is returned and a warning is issued. Users should always check
196+
the array size before using the data.
197+
198+
Example:
199+
data = get_field_data(field_data_request)[surface_id]
200+
if data.size == 0:
201+
# Handle missing data
202+
"""
190203
if isinstance(obj, SurfaceFieldDataRequest):
191204
return self._get_surface_data(**obj._asdict())
192205
elif isinstance(obj, ScalarFieldDataRequest):
@@ -973,7 +986,20 @@ def get_field_data(
973986
| PathlinesFieldDataRequest
974987
),
975988
) -> Dict[int | str, Dict | np.array]:
976-
"""Get the surface, scalar, vector or path-lines field data on a surface."""
989+
"""Get the surface, scalar, vector or path-lines field data on a surface.
990+
991+
Returns
992+
-------
993+
Dict[int | str, Dict | np.array]
994+
Field data for the requested surface. If field data is unavailable for the surface,
995+
an empty array is returned and a warning is issued. Users should always check
996+
the array size before using the data.
997+
998+
Example:
999+
data = get_field_data(field_data_request)[surface_id]
1000+
if data.size == 0:
1001+
# Handle missing data
1002+
"""
9771003
if isinstance(obj, SurfaceFieldDataRequest):
9781004
return self._get_surface_data(**obj._asdict())
9791005
elif isinstance(obj, ScalarFieldDataRequest):

src/ansys/fluent/core/services/field_data.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,20 @@ def get_field_data(
577577
| PathlinesFieldDataRequest
578578
),
579579
) -> Dict[int | str, Dict | np.array]:
580-
"""Get the surface, scalar, vector or path-lines field data on a surface."""
580+
"""Get the surface, scalar, vector or path-lines field data on a surface.
581+
582+
Returns
583+
-------
584+
Dict[int | str, Dict | np.array]
585+
Field data for the requested surface. If field data is unavailable for the surface,
586+
an empty array is returned and a warning is issued. Users should always check
587+
the array size before using the data.
588+
589+
Example:
590+
data = get_field_data(field_data_request)[surface_id]
591+
if data.size == 0:
592+
# Handle missing data
593+
"""
581594
if isinstance(obj, SurfaceFieldDataRequest):
582595
return self._get_surface_data(**obj._asdict())
583596
elif isinstance(obj, ScalarFieldDataRequest):
@@ -1185,13 +1198,19 @@ def _extract_field(field_datatype, field_size, chunk_iterator):
11851198
payload_tag_id = None
11861199
field = None
11871200
if payload_tag_id is not None:
1188-
field = _extract_field(
1189-
_FieldDataConstants.proto_field_type_to_np_data_type[
1190-
payload_info.fieldType
1191-
],
1192-
payload_info.fieldSize,
1193-
chunk_iterator,
1194-
)
1201+
if payload_info.fieldSize > 0:
1202+
field = _extract_field(
1203+
_FieldDataConstants.proto_field_type_to_np_data_type[
1204+
payload_info.fieldType
1205+
],
1206+
payload_info.fieldSize,
1207+
chunk_iterator,
1208+
)
1209+
else:
1210+
warnings.warn(
1211+
f"Field data is not available for surface: {surface_id}"
1212+
)
1213+
field = np.array([])
11951214

11961215
if self._callbacks_provider is not None:
11971216
for callback_data in self._callbacks_provider.callbacks():

0 commit comments

Comments
 (0)