From 3edeb292f8c80ad574b6f44fdb0573daf63061e2 Mon Sep 17 00:00:00 2001 From: Prithwish Mukherjee Date: Tue, 1 Oct 2024 13:56:53 +0530 Subject: [PATCH 1/4] fix: Update arguments behaviour. --- src/ansys/fluent/core/workflow.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/ansys/fluent/core/workflow.py b/src/ansys/fluent/core/workflow.py index 3879d59fe2d..9718552164b 100644 --- a/src/ansys/fluent/core/workflow.py +++ b/src/ansys/fluent/core/workflow.py @@ -763,8 +763,26 @@ def _assign(self, args: dict, fn) -> None: # TODO: Figure out proper way to implement "add_child". if "add_child" in args: self._snake_to_camel_map["add_child"] = "AddChild" + + cmd_args = self._task._command_arguments for key, val in args.items(): - camel_args[self._snake_to_camel_map[key] if key.islower() else key] = val + camel_arg = self._snake_to_camel_map[key] if key.islower() else key + if isinstance( + getattr(cmd_args, camel_arg), PySingletonCommandArgumentsSubItem + ): + updated_dict = {} + for attr, attr_val in val.items(): + camel_attr = snake_to_camel_case( + str(attr), + getattr( + self, camel_to_snake_case(key) + )._get_camel_case_arg_keys() + or [], + ) + updated_dict[camel_attr] = attr_val + camel_args[camel_arg] = updated_dict + else: + camel_args[camel_arg] = val getattr(self._task.Arguments, fn)(camel_args) try: self._refresh_command_after_changing_args(old_state) @@ -899,7 +917,7 @@ def __setattr__(self, attr, value): str(attr), self._get_camel_case_arg_keys() or [] ) attr = camel_attr or attr - self.set_state({attr: value}) + self._task.Arguments.update_dict({self._arg_name: {attr: value}}) def __dir__(self): arg_list = [] From a1c047e605486e1483333d06470d910e9aeecfc7 Mon Sep 17 00:00:00 2001 From: Prithwish Mukherjee Date: Tue, 1 Oct 2024 15:24:51 +0530 Subject: [PATCH 2/4] Minor fix. --- src/ansys/fluent/core/workflow.py | 2 +- tests/test_new_meshing_workflow.py | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/ansys/fluent/core/workflow.py b/src/ansys/fluent/core/workflow.py index 9718552164b..06fa7486301 100644 --- a/src/ansys/fluent/core/workflow.py +++ b/src/ansys/fluent/core/workflow.py @@ -443,7 +443,7 @@ def __setattr__(self, attr, value): logger.debug(f"BaseTask.__setattr__({attr}, {value})") if attr in self.__dict__: self.__dict__[attr] = value - elif attr in self.arguments(): + elif attr in self.arguments() or attr == "arguments": getattr(self, attr).set_state(value) else: setattr(self._task, attr, value) diff --git a/tests/test_new_meshing_workflow.py b/tests/test_new_meshing_workflow.py index fa2d46c9818..a38143e740e 100644 --- a/tests/test_new_meshing_workflow.py +++ b/tests/test_new_meshing_workflow.py @@ -597,18 +597,26 @@ def test_updating_state_in_new_meshing_workflow(new_meshing_session): "mixing_elbow.pmdb", "pyfluent/mixing_elbow" ) watertight = new_meshing_session.watertight() - watertight.import_geometry.file_name.set_state(import_file_name) assert watertight.import_geometry.length_unit() == "mm" - watertight.import_geometry.length_unit = "in" - assert watertight.import_geometry.length_unit.get_state() == "in" assert watertight.import_geometry.cad_import_options.feature_angle() == 40.0 - watertight.import_geometry.cad_import_options.feature_angle.set_state(25.0) - assert watertight.import_geometry.cad_import_options.feature_angle() == 25.0 assert ( watertight.import_geometry.cad_import_options.one_zone_per.allowed_values() == ["body", "face", "object"] ) assert watertight.import_geometry.cad_import_options.one_zone_per() == "body" + watertight.import_geometry.arguments = { + "file_name": import_file_name, + "length_unit": "in", + "cad_import_options": {"feature_angle": 35, "one_zone_per": "object"}, + } + assert watertight.import_geometry.cad_import_options.feature_angle() == 35.0 + assert ( + watertight.import_geometry.cad_import_options.one_zone_per.get_state() + == "object" + ) + assert watertight.import_geometry.length_unit.get_state() == "in" + watertight.import_geometry.cad_import_options.feature_angle = 25.0 + assert watertight.import_geometry.cad_import_options.feature_angle() == 25.0 watertight.import_geometry.cad_import_options.one_zone_per = "face" assert watertight.import_geometry.cad_import_options.one_zone_per() == "face" watertight.import_geometry() From b67c4c63927ed3c974a6eef644fa95f1dc476bd7 Mon Sep 17 00:00:00 2001 From: Prithwish Mukherjee Date: Thu, 3 Oct 2024 10:27:58 +0530 Subject: [PATCH 3/4] Update behaviour. --- src/ansys/fluent/core/workflow.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ansys/fluent/core/workflow.py b/src/ansys/fluent/core/workflow.py index 06fa7486301..ac203a5a7de 100644 --- a/src/ansys/fluent/core/workflow.py +++ b/src/ansys/fluent/core/workflow.py @@ -767,6 +767,7 @@ def _assign(self, args: dict, fn) -> None: cmd_args = self._task._command_arguments for key, val in args.items(): camel_arg = self._snake_to_camel_map[key] if key.islower() else key + # TODO: Implement enhanced meshing workflow to hide away internal info. if isinstance( getattr(cmd_args, camel_arg), PySingletonCommandArgumentsSubItem ): @@ -913,11 +914,7 @@ def __setattr__(self, attr, value): if attr in self.__dict__: self.__dict__[attr] = value else: - camel_attr = snake_to_camel_case( - str(attr), self._get_camel_case_arg_keys() or [] - ) - attr = camel_attr or attr - self._task.Arguments.update_dict({self._arg_name: {attr: value}}) + self.set_state({attr: value}) def __dir__(self): arg_list = [] From c03350cf174d68e516dee52afa641cadd7d6578c Mon Sep 17 00:00:00 2001 From: Prithwish Mukherjee Date: Thu, 3 Oct 2024 20:55:24 +0530 Subject: [PATCH 4/4] Fix 'update_dict' w.r.t. server. --- src/ansys/fluent/core/services/datamodel_se.py | 13 ++++++++++--- src/ansys/fluent/core/workflow.py | 5 ++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ansys/fluent/core/services/datamodel_se.py b/src/ansys/fluent/core/services/datamodel_se.py index f3e865e0ff0..10625110a45 100644 --- a/src/ansys/fluent/core/services/datamodel_se.py +++ b/src/ansys/fluent/core/services/datamodel_se.py @@ -572,7 +572,11 @@ def fix_state(self, rules, path) -> None: ) def update_dict( - self, rules: str, path: str, dict_state: dict[str, _TValue] + self, + rules: str, + path: str, + dict_state: dict[str, _TValue], + recursive=False, ) -> None: """Update the dict.""" request = DataModelProtoModule.UpdateDictRequest( @@ -1392,7 +1396,7 @@ class PyDictionary(PyParameter): to dict.update semantics (same as update_dict(dict_state))] """ - def update_dict(self, dict_state: dict[str, Any]) -> None: + def update_dict(self, dict_state: dict[str, Any], recursive=False) -> None: """Update the state of the current object if the current object is a Dict in the data model, else throws RuntimeError (currently not showing up in Python). Update is executed according to dict.update semantics. @@ -1402,6 +1406,9 @@ def update_dict(self, dict_state: dict[str, Any]) -> None: dict_state : dict[str, Any] Incoming dict state + recursive: bool + Flag to update the nested dictionary structure. + Raises ------ ReadOnlyObjectError @@ -1410,7 +1417,7 @@ def update_dict(self, dict_state: dict[str, Any]) -> None: if self.get_attr(Attribute.IS_READ_ONLY.value): raise ReadOnlyObjectError(type(self).__name__) self.service.update_dict( - self.rules, convert_path_to_se_path(self.path), dict_state + self.rules, convert_path_to_se_path(self.path), dict_state, recursive ) updateDict = update_dict diff --git a/src/ansys/fluent/core/workflow.py b/src/ansys/fluent/core/workflow.py index 80e165131ac..623c8b1ff75 100644 --- a/src/ansys/fluent/core/workflow.py +++ b/src/ansys/fluent/core/workflow.py @@ -784,7 +784,10 @@ def _assign(self, args: dict, fn) -> None: camel_args[camel_arg] = updated_dict else: camel_args[camel_arg] = val - getattr(self._task.Arguments, fn)(camel_args) + if fn == "update_dict": + self._task.Arguments.update_dict(camel_args, recursive=True) + else: + getattr(self._task.Arguments, fn)(camel_args) try: self._refresh_command_after_changing_args(old_state) except Exception as ex: