Skip to content

Commit

Permalink
Mesh region enhancements (#4566)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzovecchietti authored Apr 23, 2024
1 parent 883481a commit 057933e
Showing 1 changed file with 40 additions and 23 deletions.
63 changes: 40 additions & 23 deletions pyaedt/modules/MeshIcepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ def parts(self, parts):


class MeshSettings(object):
automatic_mesh_settings = {"MeshRegionResolution": 3} # min: 1, max: 5
common_mesh_settings = {
_automatic_mesh_settings = {"MeshRegionResolution": 3} # min: 1, max: 5
_common_mesh_settings = {
"ProximitySizeFunction": True,
"CurvatureSizeFunction": True,
"EnableTransition": False,
Expand All @@ -419,7 +419,7 @@ class MeshSettings(object):
"Enforce2dot5DCutCell": False,
"StairStepMeshing": False,
}
manual_mesh_settings = {
_manual_mesh_settings = {
"MaxElementSizeX": "0.02mm",
"MaxElementSizeY": "0.02mm",
"MaxElementSizeZ": "0.03mm",
Expand All @@ -437,7 +437,7 @@ class MeshSettings(object):
"MinGapY": "1mm",
"MinGapZ": "1mm",
}
aedt_20212_args = [
_aedt_20212_args = [
"ProximitySizeFunction",
"CurvatureSizeFunction",
"EnableTransition",
Expand All @@ -450,12 +450,12 @@ class MeshSettings(object):
def __init__(self, mesh_class, app):
self._app = app
self._mesh_class = mesh_class
self.instance_settings = self.common_mesh_settings.copy()
self.instance_settings.update(self.manual_mesh_settings.copy())
self.instance_settings.update(self.automatic_mesh_settings.copy())
self._instance_settings = self._common_mesh_settings.copy()
self._instance_settings.update(self._manual_mesh_settings.copy())
self._instance_settings.update(self._automatic_mesh_settings.copy())
if settings.aedt_version < "2021.2":
for arg in self.aedt_20212_args:
del self.instance_settings[arg]
for arg in self._aedt_20212_args:
del self._instance_settings[arg]

@pyaedt_function_handler()
def _dim_arg(self, value):
Expand All @@ -474,7 +474,7 @@ def parse_settings(self):
List of strings containing all the parts that must be included in the subregion.
"""
out = []
for k, v in self.instance_settings.items():
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)
Expand All @@ -483,16 +483,25 @@ def parse_settings(self):

def _key_in_dict(self, key):
if self._mesh_class.manual_settings:
ref_dict = self.manual_mesh_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
ref_dict = self._automatic_mesh_settings
return key in ref_dict or key in self._common_mesh_settings

def keys(self):
return self.parse_settings().keys()

def values(self):
return self.parse_settings().values()

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

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

Expand All @@ -515,21 +524,21 @@ def __setitem__(self, key, value):
value = 5
except TypeError:
pass
self.instance_settings[key] = value
self._instance_settings[key] = value
else:
self._app.logger.error("Setting not available.")

def __delitem__(self, key):
self._app.logger.error("Setting cannot be removed.")

def __iter__(self):
return self.instance_settings.__iter__()
return self._instance_settings.__iter__()

def __len__(self):
return self.instance_settings.__len__()
return self._instance_settings.__len__()

def __contains__(self, x):
return self.instance_settings.__contains__(x)
return self._instance_settings.__contains__(x)


class MeshRegionCommon(object):
Expand Down Expand Up @@ -783,10 +792,20 @@ def assignment(self):
"""
if isinstance(self._assignment, SubRegion):
# try to update name
try:
parts = self._app.odesign.GetChildObject("Mesh").GetChildObject(self.name).GetPropValue("Parts")
if self.name in self._app.odesign.GetChildObject("Mesh").GetChildNames():
parts = []
subparts = []
if "Parts" in self._app.odesign.GetChildObject("Mesh").GetChildObject(self.name).GetPropNames():
parts = self._app.odesign.GetChildObject("Mesh").GetChildObject(self.name).GetPropValue("Parts")
if "Submodels" in self._app.odesign.GetChildObject("Mesh").GetChildObject(self.name).GetPropNames():
subparts = (
self._app.odesign.GetChildObject("Mesh").GetChildObject(self.name).GetPropValue("Submodels")
)
if not isinstance(parts, list):
parts = [parts]
if not isinstance(subparts, list):
subparts = [subparts]
parts += subparts
sub_regions = self._app.modeler.non_model_objects
for sr in sub_regions:
p1 = []
Expand All @@ -802,8 +821,6 @@ def assignment(self):
p1 += p2
if "CreateSubRegion" == self._app.modeler[sr].history().command and all(p in p1 for p in parts):
self._assignment.name = sr
except GrpcApiError:
pass
return self._assignment
elif isinstance(self._assignment, list):
return self._assignment
Expand Down Expand Up @@ -1374,7 +1391,7 @@ def assign_mesh_region(self, assignment=None, level=5, name=None, **kwargs):
added_obj = [i for i in objectlist2 if i not in all_objs or i in assignment]
meshregion.Objects = added_obj
meshregion.SubModels = None
meshregion.update()
meshregion.update()
return meshregion
else:
return False
Expand Down

0 comments on commit 057933e

Please sign in to comment.