Skip to content
Draft
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/4398.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement named-object commands using root-level commands
8 changes: 7 additions & 1 deletion src/ansys/fluent/core/services/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,17 @@ def get_static_info(self) -> dict[str, Any]:

@_trace
def execute_cmd(self, path: str, command: str, **kwds) -> Any:
"""Execute a given command with the provided keyword arguments."""
"""Execute a given command with the provided keyword arguments.

If `path` is in kwds, rename it to `path_1` to avoid conflict with
the `path` argument.
"""
request = _get_request_instance_for_path(
SettingsModule.ExecuteCommandRequest, path
)
request.command = command
if "path_1" in kwds:
kwds["path"] = kwds.pop("path_1")
self._set_state_from_value(request.args, kwds)

response = self._service_impl.execute_cmd(request)
Expand Down
22 changes: 22 additions & 0 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,21 @@ def __add__(self, other):
)
return CombinedNamedObject([self, other])

def list(self):
"""Print the object names."""
return self._root.list(object_path=self.path)

def list_properties(self, object_name):
"""Print the properties of the given object name.

Parameters
----------
object_name : str
Name of the object whose properties are to be listed.
"""
# The generated parameter name is path_1 as the name path clashes with existing property.
return self._root.list_properties(path_1=self.path, name=object_name)


class CombinedNamedObject:
"""A ``CombinedNamedObject`` contains the concatenated named-objects."""
Expand Down Expand Up @@ -1747,6 +1762,8 @@ def _execute_command(self, *args, **kwds):
else:
print("Please enter 'y[es]' or 'n[o]'.")
with self._while_executing_command():
if "path" in kwds:
kwds["path_1"] = kwds.pop("path")
ret = self.flproxy.execute_cmd(self._parent.path, self.obj_name, **kwds)
if (
not config.disable_parameter_list_return_fix
Expand Down Expand Up @@ -2218,6 +2235,11 @@ def _process_cls_names(info_dict, names, write_doc=False):
commands.pop("exit", None)
if commands and not user_creatable:
commands.pop("create", None)
# Temporary code for testing
if commands and parent is not None and version == "261":
for cmd in ["list", "list-properties"]:
if cmd in commands:
commands.pop(cmd, None)
if commands:
cls.command_names = []
_process_cls_names(commands, cls.command_names)
Expand Down
14 changes: 13 additions & 1 deletion tests/test_settings_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
from ansys.fluent.core import config
from ansys.fluent.core.examples import download_file
from ansys.fluent.core.pyfluent_warnings import PyFluentUserWarning
from ansys.fluent.core.solver import Viscous
from ansys.fluent.core.solver import VelocityInlets, Viscous
from ansys.fluent.core.solver.flobject import (
DeprecatedSettingWarning,
NamedObject,
_Alias,
_InputFile,
_OutputFile,
Expand Down Expand Up @@ -793,3 +794,14 @@ def test_setting_string_constants(mixing_elbow_settings_session):

with pytest.raises(ValueError):
viscous.k_epsilon_model = viscous.k_epsilon_model.EASM


@pytest.mark.fluent_version(">=24.2")
def test_named_object_commands(mixing_elbow_settings_session):
solver = mixing_elbow_settings_session
inlets = VelocityInlets(solver)
inlets.list()
inlets.list_properties(object_name="hot-inlet")
if solver.get_fluent_version() >= FluentVersion.v261:
NamedObject.list(inlets)
NamedObject.list_properties(inlets, object_name="hot-inlet")
Loading