Skip to content
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/3802.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use 'deprecated-version' flag for settings-api classes
32 changes: 31 additions & 1 deletion src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,19 @@ def get_attr(
return None
return val

def _is_deprecated(self) -> bool:
"""Whether the object is deprecated in a specific Fluent version.'"""
deprecated_version = self.get_attrs(["deprecated-version"])
deprecated_version = (
deprecated_version.get("deprecated-version") if deprecated_version else None
)
return deprecated_version and FluentVersion(self.version) >= FluentVersion(
deprecated_version
)

def is_active(self) -> bool:
"""Whether the object is active."""
attr = self.get_attr(_InlineConstants.is_active)
attr = self.get_attr(_InlineConstants.is_active) and not self._is_deprecated()
return False if attr is False else True

def _check_stable(self) -> None:
Expand Down Expand Up @@ -1078,6 +1088,16 @@ def get_active_query_names(self):
ret.append(query)
return ret

def __dir__(self):
dir_list = set(list(self.__dict__.keys()) + dir(type(self)))
return dir_list - set(
[
child
for child in self.child_names + self.command_names + self.query_names
if getattr(self, child)._is_deprecated()
]
)

def get_completer_info(self, prefix="", excluded=None) -> List[List[str]]:
"""Get completer info of all children.

Expand Down Expand Up @@ -1624,6 +1644,16 @@ def __init__(self, name: str | None = None, parent=None):
cls = self.__class__._child_classes[argument]
self._setattr(argument, _create_child(cls, None, self))

def __dir__(self):
dir_list = set(list(self.__dict__.keys()) + dir(type(self)))
return dir_list - set(
[
child
for child in self.argument_names
if getattr(self, child)._is_deprecated()
]
)

def get_completer_info(self, prefix="", excluded=None) -> List[List[str]]:
"""Get completer info of all arguments.

Expand Down
2 changes: 2 additions & 0 deletions tests/test_flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def get_attrs(self, attrs):
attrs = {
"active?": lambda self: True,
"webui-release-active?": lambda self: True,
"deprecated-version": lambda self: None,
}


Expand Down Expand Up @@ -324,6 +325,7 @@ class S1(String):
"active?": lambda self: not self.parent.objs["b-3"].get_state(),
"allowed-values": lambda self: ["foo", "bar"],
"webui-release-active?": lambda self: True,
"deprecated-version": lambda self: None,
}

children = {
Expand Down
86 changes: 86 additions & 0 deletions tests/test_settings_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,92 @@ def test_return_types_of_operations_on_named_objects(mixing_elbow_settings_sessi
assert var3.obj_name == "air-copied"


@pytest.mark.skip("https://github.com/ansys/pyfluent/issues/3813")
@pytest.mark.fluent_version(">=25.1")
def test_settings_with_deprecated_flag(mixing_elbow_settings_session):
solver = mixing_elbow_settings_session
solver.settings.solution.initialization.hybrid_initialize()
graphics = solver.settings.results.graphics
graphics.contour["contour-velocity"] = {
"field": "velocity-magnitude",
"surfaces_list": ["wall-elbow"],
}
# In the line below, "range_option" and "coloring" are deprecated.
if solver.get_fluent_version() <= FluentVersion.v251:
# From v252 'get_state' behaviour is to be corrected in Fluent.
assert {"range_option", "range_options", "coloring", "colorings"}.issubset(
set(graphics.contour["contour-velocity"]())
)
assert (
graphics.contour["contour-velocity"].range_option.get_attr("deprecated-version")
== "25.1"
)
assert (
graphics.contour["contour-velocity"].coloring.get_attr("deprecated-version")
== "25.1"
)

# Deprecated objects should not be active
assert not graphics.contour["contour-velocity"].range_option.is_active()
assert graphics.contour["contour-velocity"].range_options.is_active()

# in 'get_state'
if solver.get_fluent_version() >= FluentVersion.v252:
# From v252 'get_state' behaviour is to be corrected in Fluent.
assert not {"range_option", "coloring"}.issubset(
set(graphics.contour["contour-velocity"].get_state())
)
assert {"range_options", "colorings"}.issubset(
set(graphics.contour["contour-velocity"].get_state())
)
else:
assert {"range_option", "range_options", "coloring", "colorings"}.issubset(
set(graphics.contour["contour-velocity"].get_state())
)

# in 'child_names'
# 'child_names', 'command_names' and 'query_names' will remain unchanged.
assert {"range_option", "range_options", "coloring", "colorings"}.issubset(
set(graphics.contour["contour-velocity"].child_names)
)

# in 'get_active_child_names'
assert not {"range_option", "coloring"}.issubset(
set(graphics.contour["contour-velocity"].get_active_child_names())
)
assert {"range_options", "colorings"}.issubset(
set(graphics.contour["contour-velocity"].get_active_child_names())
)

# in 'dir'
assert not {"range_option", "coloring"}.issubset(
set(dir(graphics.contour["contour-velocity"]))
)
assert {"range_options", "colorings"}.issubset(
set(dir(graphics.contour["contour-velocity"]))
)

# This should be True, as attribute is present, just not exposed.
for item in ["range_option", "range_options", "coloring", "colorings"]:
assert hasattr(graphics.contour["contour-velocity"], item)

# Named-object
solver.settings.solution.report_definitions.surface["report-def-1"] = {}
solver.settings.solution.report_definitions.surface["report-def-1"].report_type = (
"surface-area"
)
solver.settings.solution.report_definitions.surface[
"report-def-1"
].surface_names = ["cold-inlet", "hot-inlet"]
assert "create_output_parameter" not in dir(
solver.settings.solution.report_definitions.surface["report-def-1"]
)
assert hasattr(
solver.settings.solution.report_definitions.surface["report-def-1"],
"create_output_parameter",
)


@pytest.fixture
def use_runtime_python_classes(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setenv("PYFLUENT_USE_RUNTIME_PYTHON_CLASSES", "1")
Expand Down