diff --git a/_unittest/test_09_Primitives2D.py b/_unittest/test_09_Primitives2D.py index 4cd695c39d1..1f5965accdd 100644 --- a/_unittest/test_09_Primitives2D.py +++ b/_unittest/test_09_Primitives2D.py @@ -74,10 +74,14 @@ def test_06_create_region(self): if self.aedtapp.modeler["Region"]: self.aedtapp.modeler.delete("Region") assert "Region" not in self.aedtapp.modeler.object_names - assert self.aedtapp.modeler.create_region([20, "50", "100mm", 20], False) + assert self.aedtapp.modeler.create_region([20, "50", "100mm", 20], "Absolute Offset") self.aedtapp.modeler["Region"].delete() - region = self.aedtapp.modeler.create_region("100", True) + region = self.aedtapp.modeler.create_region("100", "Percentage Offset") region.delete() + # test backward compatibility + region = self.aedtapp.modeler.create_region(pad_percent=[100, 10, 5, 2], pad_type=True) + region.delete() + # region = self.aedtapp.modeler.create_region([100, 100, 100, 100]) assert region.solve_inside assert region.model diff --git a/pyaedt/generic/configurations.py b/pyaedt/generic/configurations.py index 8a3170a6b60..f6ba8b0381e 100644 --- a/pyaedt/generic/configurations.py +++ b/pyaedt/generic/configurations.py @@ -1673,7 +1673,7 @@ def _export_objects_properties(self, dict_out): def _export_mesh_operations(self, dict_out): dict_out["mesh"] = {} args = ["NAME:Settings"] - args += self._app.mesh.global_mesh_region.settings.parse_settings() + args += self._app.mesh.global_mesh_region.settings.parse_settings_as_args() mop = OrderedDict({}) _arg2dict(args, mop) dict_out["mesh"]["Settings"] = mop["Settings"] @@ -1683,7 +1683,7 @@ def _export_mesh_operations(self, dict_out): args = ["NAME:Settings"] else: args = ["NAME:" + mesh.name, "Enable:=", mesh.Enable] - args += mesh.settings.parse_settings() + args += mesh.settings.parse_settings_as_args() args += getattr(mesh, "_parse_assignment_value")() args += ["UserSpecifiedSettings:=", not mesh.manual_settings] mop = OrderedDict({}) diff --git a/pyaedt/modeler/cad/Primitives2D.py b/pyaedt/modeler/cad/Primitives2D.py index 0d640ea7724..dbf284685a5 100644 --- a/pyaedt/modeler/cad/Primitives2D.py +++ b/pyaedt/modeler/cad/Primitives2D.py @@ -287,7 +287,8 @@ def create_region(self, pad_value=300, pad_type="Percentage Offset", name="Regio Padding values to apply. If a list is not provided, the same value is applied to all padding directions. If a list of floats or strings is provided, the values are - interpreted as padding for ``["+X", "-X", "+Y", "-Y", "+Z", "-Z"]``. + interpreted as padding for ``["+X", "-X", "+Y", "-Y"]`` for XY geometry mode, + and ``["+R", "+Z", "-Z"]`` for RZ geometry mode. pad_type : str, optional Padding definition. The default is ``"Percentage Offset"``. Options are ``"Absolute Offset"``, @@ -318,24 +319,26 @@ def create_region(self, pad_value=300, pad_type="Percentage Offset", name="Regio if kwarg.get("pad_percent", False): pad_percent = kwarg["pad_percent"] pad_value = pad_percent - if isinstance(pad_value, list) and len(pad_value) < 6: - pad_value = [pad_value[i // 2 + 3 * (i % 2)] for i in range(6)] + if isinstance(pad_value, list) and len(pad_value) == 4: + pad_value = [pad_value[i // 2 + 2 * (i % 2)] for i in range(4)] pad_type = ["Absolute Offset", "Percentage Offset"][int(is_percentage)] if isinstance(pad_type, bool): pad_type = ["Absolute Offset", "Percentage Offset"][int(pad_type)] - if not isinstance(pad_value, list): - pad_value = [pad_value] * 4 if self._app.design_type == "2D Extractor" or ( self._app.design_type == "Maxwell 2D" and self._app.odesign.GetGeometryMode() == "XY" ): + if not isinstance(pad_value, list): + pad_value = [pad_value] * 4 if len(pad_value) != 4: self.logger.error("Wrong padding list provided. Four values have to be provided.") return False pad_value = [pad_value[0], pad_value[2], pad_value[1], pad_value[3], 0, 0] else: - if len(pad_value) < 3: + if not isinstance(pad_value, list): + pad_value = [pad_value] * 3 + if len(pad_value) != 3: self.logger.error("Wrong padding list provided. Three values have to be provided for RZ geometry.") return False pad_value = [pad_value[0], 0, 0, 0, pad_value[1], pad_value[2]] diff --git a/pyaedt/modules/MeshIcepak.py b/pyaedt/modules/MeshIcepak.py index a0939fbae27..9712122c57c 100644 --- a/pyaedt/modules/MeshIcepak.py +++ b/pyaedt/modules/MeshIcepak.py @@ -274,7 +274,8 @@ def name(self): @name.setter def name(self, value): try: - self._app.modeler.objects_by_name[self._name].name = value + if self._app.modeler.objects_by_name[self._name].name != value: + self._app.modeler.objects_by_name[self._name].name = value except KeyError: if self._app.modeler.objects_by_name[value].history().command == "CreateSubRegion": self._name = value @@ -408,6 +409,13 @@ def parts(self, parts): class MeshSettings(object): + """ + Class for managing mesh settings. + + It can be used like a dictionary. Available keys change according + to the type of settings chosen (manual or automatic). + """ + _automatic_mesh_settings = {"MeshRegionResolution": 3} # min: 1, max: 5 _common_mesh_settings = { "ProximitySizeFunction": True, @@ -464,14 +472,14 @@ def _dim_arg(self, value): else: return _dim_arg(value, getattr(self._mesh_class, "_model_units")) - def parse_settings(self): + def parse_settings_as_args(self): """ Parse mesh region settings. Returns ------- - dict - List of strings containing all the parts that must be included in the subregion. + List + Arguments to pass to native APIs. """ out = [] for k, v in self._instance_settings.items(): @@ -481,6 +489,22 @@ def parse_settings(self): out.append(v) return out + def parse_settings_as_dictionary(self): + """ + Parse mesh region settings. + + Returns + ------- + dict + Settings of the subregion. + """ + out = {} + for k, v in self._instance_settings.items(): + if k in ["MaxElementSizeX", "MaxElementSizeY", "MaxElementSizeZ", "MinGapX", "MinGapY", "MinGapZ"]: + v = self._dim_arg(v) + out[k] = v + return out + def _key_in_dict(self, key): if self._mesh_class.manual_settings: ref_dict = self._manual_mesh_settings @@ -489,13 +513,29 @@ def _key_in_dict(self, key): return key in ref_dict or key in self._common_mesh_settings def keys(self): - return self.parse_settings().keys() + """ + Get mesh region settings keys. + + Returns + ------- + dict_keys + Available settings keys. + """ + return self.parse_settings_as_dictionary().keys() def values(self): - return self.parse_settings().values() + """ + Get mesh region settings values. + + Returns + ------- + dict_values + Settings values. + """ + return self.parse_settings_as_dictionary().values() def __repr__(self): - return repr(self.parse_settings()) + return repr(self.parse_settings_as_dictionary()) def __getitem__(self, key): if key == "Level": @@ -628,7 +668,7 @@ def update(self): >>> oModule.EditGlobalMeshRegion """ args = ["NAME:Settings"] - args += self.settings.parse_settings() + args += self.settings.parse_settings_as_args() args += ["UserSpecifiedSettings:=", self.manual_settings] try: self._app.omeshmodule.EditGlobalMeshRegion(args) @@ -754,7 +794,7 @@ def update(self): >>> oModule.EditMeshRegion """ args = ["NAME:" + self.name, "Enable:=", self.enable] - args += self.settings.parse_settings() + args += self.settings.parse_settings_as_args() args += self._parse_assignment_value() args += ["UserSpecifiedSettings:=", self.manual_settings] try: @@ -854,7 +894,7 @@ def create(self): self._app.logger.error("Cannot create a new mesh region with this Name") return False args = ["NAME:" + self.name, "Enable:=", self.enable] - args += self.settings.parse_settings() + args += self.settings.parse_settings_as_args() args += ["UserSpecifiedSettings:=", not self.manual_settings] args += self._parse_assignment_value() self._app.omeshmodule.AssignMeshRegion(args)