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 01ebf810b35..623c8b1ff75 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) @@ -763,9 +763,31 @@ 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 - getattr(self._task.Arguments, fn)(camel_args) + 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 + ): + 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 + 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: @@ -895,10 +917,6 @@ 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.set_state({attr: value}) def __dir__(self): diff --git a/tests/test_new_meshing_workflow.py b/tests/test_new_meshing_workflow.py index 49007cb6c47..41abe1f49da 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()