Skip to content

Commit

Permalink
REFACT: mesh region settings (#4604)
Browse files Browse the repository at this point in the history
Co-authored-by: Sébastien Morais <[email protected]>
  • Loading branch information
lorenzovecchietti and SMoraisAnsys authored May 2, 2024
1 parent 388de1d commit 7c3be01
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions pyaedt/modules/MeshIcepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,6 @@ def __init__(self, mesh_class, app):
for arg in self._aedt_20212_args:
del self._instance_settings[arg]

@pyaedt_function_handler()
def _dim_arg(self, value):
if isinstance(value, str):
return value
else:
return _dim_arg(value, getattr(self._mesh_class, "_model_units"))

def parse_settings_as_args(self):
"""
Parse mesh region settings.
Expand All @@ -485,7 +478,7 @@ def parse_settings_as_args(self):
for k, v in self._instance_settings.items():
out.append(k + ":=")
if k in ["MaxElementSizeX", "MaxElementSizeY", "MaxElementSizeZ", "MinGapX", "MinGapY", "MinGapZ"]:
v = self._dim_arg(v)
v = _dim_arg(v, getattr(self._mesh_class, "_model_units"))
out.append(v)
return out

Expand All @@ -499,19 +492,13 @@ def parse_settings_as_dictionary(self):
Settings of the subregion.
"""
out = {}
for k, v in self._instance_settings.items():
for k in self.keys():
v = self._instance_settings[k]
if k in ["MaxElementSizeX", "MaxElementSizeY", "MaxElementSizeZ", "MinGapX", "MinGapY", "MinGapZ"]:
v = self._dim_arg(v)
v = _dim_arg(v, getattr(self._mesh_class, "_model_units"))
out[k] = v
return out

def _key_in_dict(self, key):
if self._mesh_class.manual_settings:
ref_dict = self._manual_mesh_settings
else:
ref_dict = self._automatic_mesh_settings
return key in ref_dict or key in self._common_mesh_settings

def keys(self):
"""
Get mesh region settings keys.
Expand All @@ -521,7 +508,10 @@ def keys(self):
dict_keys
Available settings keys.
"""
return self.parse_settings_as_dictionary().keys()
if self._mesh_class.manual_settings:
return set(self._manual_mesh_settings.keys()) | set(self._common_mesh_settings.keys())
else:
return set(self._automatic_mesh_settings.keys()) | set(self._common_mesh_settings.keys())

def values(self):
"""
Expand All @@ -534,21 +524,32 @@ def values(self):
"""
return self.parse_settings_as_dictionary().values()

def items(self):
"""
Get mesh region settings items.
Returns
-------
dict_items
Settings items.
"""
return self.parse_settings_as_dictionary().items()

def __repr__(self):
return repr(self.parse_settings_as_dictionary())

def __getitem__(self, key):
if key == "Level":
if key == "Level": # backward compatibility
key = "MeshRegionResolution"
if self._key_in_dict(key):
if key in self.keys():
return self._instance_settings[key]
else:
raise KeyError("Setting not available.")

def __setitem__(self, key, value):
if key == "Level":
if key == "Level": # backward compatibility
key = "MeshRegionResolution"
if self._key_in_dict(key):
if key in self.keys():
if key == "MeshRegionResolution":
try:
value = int(value)
Expand All @@ -572,13 +573,13 @@ def __delitem__(self, key):
self._app.logger.error("Setting cannot be removed.")

def __iter__(self):
return self._instance_settings.__iter__()
return iter(self.keys())

def __len__(self):
return self._instance_settings.__len__()
return len(self.keys())

def __contains__(self, x):
return self._instance_settings.__contains__(x)
return x in self.keys()


class MeshRegionCommon(object):
Expand Down

0 comments on commit 7c3be01

Please sign in to comment.