Skip to content

refactor: Deprecate FieldInfo. #4287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/4287.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate fieldinfo.
6 changes: 6 additions & 0 deletions doc/deprecated_pyfluent_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
"0.25.0",
":py:meth:`ansys.fluent.core.file_session.FileFieldData.get_field_data <ansys.fluent.core.file_session.FileFieldData.get_field_data>`",
),
# class
(
":py:class:`ansys.fluent.core.services.field_data.FieldInfo <ansys.fluent.core.services.field_data.FieldInfo>`",
"0.34.0",
":py:class:`ansys.fluent.core.services.field_data.FieldData <ansys.fluent.core.services.field_data.FieldData>`",
),
# properties
(
":py:meth:`ansys.fluent.core.session.BaseSession.field_info <ansys.fluent.core.session.BaseSession.field_info>`",
Expand Down
2 changes: 2 additions & 0 deletions doc/source/user_guide/fields/field_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ Some sample use cases are demonstrated below:
False
>>> field_data.scalar_fields.is_active(VariableCatalog.VELOCITY_MAGNITUDE)
True
>>> field_data.scalar_fields.range("cell-weight")
[8.0, 24.0]

>>> field_data.surfaces.allowed_values()
['in1', 'in2', 'in3', 'inlet', 'inlet1', 'inlet2', 'out1', 'outlet', 'solid_up:1', 'solid_up:1:830', 'solid_up:1:830-shadow']
Expand Down
88 changes: 0 additions & 88 deletions doc/source/user_guide/fields/field_info.rst

This file was deleted.

5 changes: 2 additions & 3 deletions doc/source/user_guide/fields/fields_contents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ Fields

PyFluent provides several services that allow you to access field data in different ways.
Every PyFluent solution and meshing :ref:`Session <ref_session_guide>` object contains a ``fields`` object. In both
solution and meshing modes, the ``fields`` object contains ``field_data``, ``field_data_streaming``
and ``field_info`` children. In :obj:`solution <ansys.fluent.core.session_solver.Solver>` mode, the ``fields`` object also has ``reduction``,
solution and meshing modes, the ``fields`` object contains ``field_data`` and ``field_data_streaming``
children. In :obj:`solution <ansys.fluent.core.session_solver.Solver>` mode, the ``fields`` object also has ``reduction``,
``solution_variable_data`` and ``solution_variable_info`` children.

.. toctree::
:maxdepth: 1
:hidden:

field_data
field_info
reduction
solution_data
14 changes: 7 additions & 7 deletions doc/source/user_guide/offline/file_session.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ Single-phase
>>> data_file_name = examples.download_file("elbow1.dat.h5", "pyfluent/file_session")
>>> file_session = FileSession(case_file_name, data_file_name)

>>> file_session.fields.field_info.get_scalar_field_range("SV_T")
>>> file_session.fields.field_data.scalar_fields.range("SV_T")
[0.0, 313.1515948109515]
>>> file_session.fields.field_info.get_surfaces_info()
>>> file_session.fields.field_data.surfaces()
{'wall': {'surface_id': [3],
'zone_id': -1,
'zone_type': 'wall',
Expand All @@ -52,7 +52,7 @@ Single-phase
'zone_id': -1,
'zone_type': 'wall',
'type': 'plane'}}
>>> file_session.fields.field_info.get_scalar_fields_info()
>>> file_session.fields.field_data.scalar_fields()
{'SV_ARTIFICIAL_WALL_FLAG': {'display_name': 'SV_ARTIFICIAL_WALL_FLAG',
'section': 'field-data',
'domain': 'phase-1'},
Expand All @@ -63,7 +63,7 @@ Single-phase
'SV_WALL_YPLUS_UTAU': {'display_name': 'SV_WALL_YPLUS_UTAU',
'section': 'field-data',
'domain': 'phase-1'}}
>>> file_session.fields.field_info.get_vector_fields_info()
>>> file_session.fields.field_data.vector_fields()
{'velocity': {'x-component': 'SV_U',
'y-component': 'SV_V',
'z-component': 'SV_W'}}
Expand Down Expand Up @@ -132,9 +132,9 @@ Multiphase
>>> file_session.read_case(case_file_name)
>>> file_session.read_data(data_file_name)

>>> file_session.fields.field_info.get_scalar_field_range("phase-2:SV_P")
>>> file_session.fields.field_data.scalar_fields.range("phase-2:SV_P")
[0.0, 1.5435200335871788e-11]
>>> file_session.fields.field_info.get_scalar_fields_info()
>>> file_session.fields.field_data.scalar_fields()
{'phase-1:SV_ARTIFICIAL_WALL_FLAG': {'display_name': 'SV_ARTIFICIAL_WALL_FLAG',
'section': 'field-data',
'domain': 'phase-1'},
Expand All @@ -145,7 +145,7 @@ Multiphase
'phase-4:': {'display_name': '',
'section': 'field-data',
'domain': 'phase-4'}}
>>> file_session.fields.field_info.get_vector_fields_info()
>>> file_session.fields.field_data.vector_fields()
{'phase-1:velocity': {'x-component': 'phase-1: SV_U',
'y-component': 'phase-1: SV_V',
'z-component': 'phase-1: SV_W'},
Expand Down
122 changes: 118 additions & 4 deletions src/ansys/fluent/core/field_data_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,120 @@ def get_response(self) -> FieldDataSource:
pass


class _SurfaceNames:
def __init__(self, allowed_surface_names):
self._allowed_surface_names = allowed_surface_names

def allowed_values(self):
"""Lists available surface names."""
return list(self._allowed_surface_names())

def validate(self, surfaces: List[str]) -> bool:
"""
Validate that the given surfaces are in the list of allowed surface names.

Parameters
----------
surfaces : List[int]
A list of surface name strings to validate.

Returns
-------
bool
True if all surfaces are valid, False otherwise.
If any name is invalid, a warning is issued and validation stops early.
"""
for surf in surfaces:
if surf not in self._allowed_surface_names():
warnings.warn(f"'{surf}' is not a valid surface name.")
return False
return True

def __call__(self):
return self._allowed_surface_names()


class _SurfaceIds:
def __init__(self, allowed_surface_ids):
self._allowed_surface_ids = allowed_surface_ids

def allowed_values(self):
"""Lists available surface ids."""
return self._allowed_surface_ids()

def validate(self, surface_ids: List[int]) -> bool:
"""
Validate that the given surface IDs are in the list of allowed surface IDs.

Parameters
----------
surface_ids : List[int]
A list of surface ID integers to validate.

Returns
-------
bool
True if all surface IDs are valid, False otherwise.
If any ID is invalid, a warning is issued and validation stops early.
"""
for surf in surface_ids:
if surf not in self._allowed_surface_ids():
warnings.warn(f"'{surf}' is not a valid surface id.")
return False
return True

def __call__(self):
return self._allowed_surface_ids()


class _Fields:
def __init__(self, available_field_names):
self._available_field_names = available_field_names

def is_active(self, field_name):
"""Check whether a field is active in the given context."""
if _to_field_name_str(field_name) in self._available_field_names():
return True
return False

def allowed_values(self):
"""Lists available scalar or vector field names."""
return list(self._available_field_names())

def __call__(self):
return self._available_field_names()


class _ScalarFields(_Fields):
def __init__(self, available_field_names, field_info):
super().__init__(available_field_names)
self._field_info = field_info

def range(
self, field: str, node_value: bool = False, surface_ids: list[int] = None
) -> list[float]:
"""Get the range (minimum and maximum values) of the field.

Parameters
----------
field: str
Field name
node_value: bool
surface_ids : List[int], optional
List of surface IDS for the surface data.

Returns
-------
List[float]
"""
return self._field_info._get_scalar_field_range(field, node_value, surface_ids)


class _VectorFields(_Fields):
def __init__(self, available_field_names):
super().__init__(available_field_names)


class _AllowedNames:
def __init__(
self, field_info: BaseFieldInfo | None = None, info: dict | None = None
Expand Down Expand Up @@ -337,7 +451,7 @@ def valid_name(self, field_name):

class _AllowedSurfaceNames(_AllowedNames):
def __call__(self, respect_data_valid: bool = True) -> List[str]:
return self._info if self._info else self._field_info.get_surfaces_info()
return self._info if self._info else self._field_info._get_surfaces_info()

def valid_name(self, surface_name: str) -> str:
"""Returns valid names.
Expand Down Expand Up @@ -365,7 +479,7 @@ def __call__(self, respect_data_valid: bool = True) -> List[int]:
try:
return [
info["surface_id"][0]
for _, info in self._field_info.get_surfaces_info().items()
for _, info in self._field_info._get_surfaces_info().items()
]
except (KeyError, IndexError):
pass
Expand All @@ -383,7 +497,7 @@ class _AllowedScalarFieldNames(_AllowedFieldNames):

def __call__(self, respect_data_valid: bool = True) -> List[str]:
field_dict = (
self._info if self._info else self._field_info.get_scalar_fields_info()
self._info if self._info else self._field_info._get_scalar_fields_info()
)
return (
field_dict
Expand All @@ -405,7 +519,7 @@ def __call__(self, respect_data_valid: bool = True) -> List[str]:
self._info
if self._info
else (
self._field_info.get_vector_fields_info()
self._field_info._get_vector_fields_info()
if (not respect_data_valid or self._is_data_valid())
else []
)
Expand Down
Loading