diff --git a/doc/changelog.d/4398.added.md b/doc/changelog.d/4398.added.md new file mode 100644 index 000000000000..f83c9a073078 --- /dev/null +++ b/doc/changelog.d/4398.added.md @@ -0,0 +1 @@ +Implement named-object commands using root-level commands diff --git a/src/ansys/fluent/core/services/settings.py b/src/ansys/fluent/core/services/settings.py index 89781ac4d840..2f22176ddda6 100644 --- a/src/ansys/fluent/core/services/settings.py +++ b/src/ansys/fluent/core/services/settings.py @@ -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) diff --git a/src/ansys/fluent/core/solver/flobject.py b/src/ansys/fluent/core/solver/flobject.py index 7f7d9be72cb5..c2c16def7a8c 100644 --- a/src/ansys/fluent/core/solver/flobject.py +++ b/src/ansys/fluent/core/solver/flobject.py @@ -1499,6 +1499,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.""" @@ -1760,6 +1775,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 @@ -2231,6 +2248,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) diff --git a/tests/test_settings_api.py b/tests/test_settings_api.py index 0e86e4ca6243..6f98982956b5 100644 --- a/tests/test_settings_api.py +++ b/tests/test_settings_api.py @@ -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, @@ -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")