diff --git a/doc/changelog.d/4345.fixed.md b/doc/changelog.d/4345.fixed.md new file mode 100644 index 000000000000..9b63c4749a96 --- /dev/null +++ b/doc/changelog.d/4345.fixed.md @@ -0,0 +1 @@ +Unavaialble field data for some surfaces. \ No newline at end of file diff --git a/src/ansys/fluent/core/file_session.py b/src/ansys/fluent/core/file_session.py index a98e031d41b5..2b0853f1a1cc 100644 --- a/src/ansys/fluent/core/file_session.py +++ b/src/ansys/fluent/core/file_session.py @@ -186,7 +186,20 @@ def get_field_data( | PathlinesFieldDataRequest ), ) -> Dict[int | str, Dict | np.array]: - """Get the surface, scalar, vector or path-lines field data on a surface.""" + """Get the surface, scalar, vector or path-lines field data on a surface. + + Returns + ------- + Dict[int | str, Dict | np.array] + Field data for the requested surface. If field data is unavailable for the surface, + an empty array is returned and a warning is issued. Users should always check + the array size before using the data. + + Example: + data = get_field_data(field_data_request)[surface_id] + if data.size == 0: + # Handle missing data + """ if isinstance(obj, SurfaceFieldDataRequest): return self._get_surface_data(**obj._asdict()) elif isinstance(obj, ScalarFieldDataRequest): @@ -973,7 +986,20 @@ def get_field_data( | PathlinesFieldDataRequest ), ) -> Dict[int | str, Dict | np.array]: - """Get the surface, scalar, vector or path-lines field data on a surface.""" + """Get the surface, scalar, vector or path-lines field data on a surface. + + Returns + ------- + Dict[int | str, Dict | np.array] + Field data for the requested surface. If field data is unavailable for the surface, + an empty array is returned and a warning is issued. Users should always check + the array size before using the data. + + Example: + data = get_field_data(field_data_request)[surface_id] + if data.size == 0: + # Handle missing data + """ if isinstance(obj, SurfaceFieldDataRequest): return self._get_surface_data(**obj._asdict()) elif isinstance(obj, ScalarFieldDataRequest): diff --git a/src/ansys/fluent/core/services/field_data.py b/src/ansys/fluent/core/services/field_data.py index 139f2f4c27d0..43fc0e4e1c2b 100644 --- a/src/ansys/fluent/core/services/field_data.py +++ b/src/ansys/fluent/core/services/field_data.py @@ -577,7 +577,20 @@ def get_field_data( | PathlinesFieldDataRequest ), ) -> Dict[int | str, Dict | np.array]: - """Get the surface, scalar, vector or path-lines field data on a surface.""" + """Get the surface, scalar, vector or path-lines field data on a surface. + + Returns + ------- + Dict[int | str, Dict | np.array] + Field data for the requested surface. If field data is unavailable for the surface, + an empty array is returned and a warning is issued. Users should always check + the array size before using the data. + + Example: + data = get_field_data(field_data_request)[surface_id] + if data.size == 0: + # Handle missing data + """ if isinstance(obj, SurfaceFieldDataRequest): return self._get_surface_data(**obj._asdict()) elif isinstance(obj, ScalarFieldDataRequest): @@ -1185,13 +1198,19 @@ def _extract_field(field_datatype, field_size, chunk_iterator): payload_tag_id = None field = None if payload_tag_id is not None: - field = _extract_field( - _FieldDataConstants.proto_field_type_to_np_data_type[ - payload_info.fieldType - ], - payload_info.fieldSize, - chunk_iterator, - ) + if payload_info.fieldSize > 0: + field = _extract_field( + _FieldDataConstants.proto_field_type_to_np_data_type[ + payload_info.fieldType + ], + payload_info.fieldSize, + chunk_iterator, + ) + else: + warnings.warn( + f"Field data is not available for surface: {surface_id}" + ) + field = np.array([]) if self._callbacks_provider is not None: for callback_data in self._callbacks_provider.callbacks():