Skip to content

Commit

Permalink
FEAT: Transient ambient temperature in design settings & Design setti…
Browse files Browse the repository at this point in the history
…ngs class (#4580)

Co-authored-by: Kathy Pippert <[email protected]>
Co-authored-by: Sébastien Morais <[email protected]>
  • Loading branch information
3 people authored May 2, 2024
1 parent 7c3be01 commit 4adad01
Show file tree
Hide file tree
Showing 5 changed files with 791 additions and 569 deletions.
5 changes: 3 additions & 2 deletions _unittest/test_01_Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pyaedt import Hfss3dLayout
from pyaedt import Icepak
from pyaedt import get_pyaedt_app
from pyaedt.application.Design import DesignSettings
from pyaedt.application.aedt_objects import AedtObjects
from pyaedt.application.design_solutions import model_names
from pyaedt.generic.general_methods import is_linux
Expand Down Expand Up @@ -418,9 +419,9 @@ def test_39_load_project(self, desktop):

def test_40_get_design_settings(self, add_app):
ipk = add_app(application=Icepak)
design_settings_dict = ipk.design_settings()
design_settings_dict = ipk.design_settings

assert isinstance(design_settings_dict, dict)
assert isinstance(design_settings_dict, DesignSettings)
assert "AmbTemp" in design_settings_dict
assert "AmbRadTemp" in design_settings_dict
assert "GravityVec" in design_settings_dict
Expand Down
30 changes: 28 additions & 2 deletions _unittest/test_98_Icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ def test_14_edit_design_settings(self):
assert self.aedtapp.edit_design_settings(gravity_dir=3)
assert self.aedtapp.edit_design_settings(ambtemp=20)
assert self.aedtapp.edit_design_settings(ambtemp="325kel")
self.aedtapp.solution_type = "Transient"
bc = self.aedtapp.create_linear_transient_assignment("0.01cel", "5")
assert self.aedtapp.edit_design_settings(ambtemp=bc)

def test_15_insert_new_icepak(self):
self.aedtapp.insert_design("Solve")
Expand Down Expand Up @@ -404,6 +407,7 @@ def test_33_create_source(self):
assert self.aedtapp.create_source_power(self.aedtapp.modeler["boxSource"].top_face_z.id, input_power="2W")
assert self.aedtapp.create_source_power(
self.aedtapp.modeler["boxSource"].bottom_face_z.id,
input_power="0W",
thermal_condtion="Fixed Temperature",
temperature="28cel",
)
Expand All @@ -426,6 +430,7 @@ def test_33_create_source(self):
voltage_current_choice="Current",
voltage_current_value="1A",
)
self.aedtapp.solution_type = "SteadyState"
assert not self.aedtapp.assign_source(
self.aedtapp.modeler["boxSource"].top_face_x.id,
"Total Power",
Expand Down Expand Up @@ -950,7 +955,6 @@ def test_54_assign_stationary_wall(self):
thickness="0mm",
material="Al-Extruded",
htc=10,
htc_dataset=None,
ref_temperature="AmbientTemp",
ht_correlation=True,
ht_correlation_type="Forced Convection",
Expand All @@ -966,7 +970,7 @@ def test_54_assign_stationary_wall(self):
name=None,
thickness="0mm",
material="Al-Extruded",
htc_dataset="ds1",
htc="ds1",
ref_temperature="AmbientTemp",
ht_correlation=False,
)
Expand Down Expand Up @@ -1583,3 +1587,25 @@ def test_74_boundary_conditions_dictionaries(self):
def test_75_native_component_load(self, add_app):
app = add_app(application=Icepak, project_name=native_import, subfolder=test_subfolder)
assert len(app.native_components) == 1

def test_76_design_settings(self):
d = self.aedtapp.design_settings
d["AmbTemp"] = 5
assert d["AmbTemp"] == "5cel"
d["AmbTemp"] = "5kel"
assert d["AmbTemp"] == "5kel"
d["AmbTemp"] = {"1": "2"}
assert d["AmbTemp"] == "5kel"
d["AmbGaugePressure"] = 5
assert d["AmbGaugePressure"] == "5n_per_meter_sq"
d["GravityVec"] = 1
assert d["GravityVec"] == "Global::Y"
assert d["GravityDir"] == "Positive"
d["GravityVec"] = 4
assert d["GravityVec"] == "Global::Y"
assert d["GravityDir"] == "Negative"
d["GravityVec"] = "+X"
assert d["GravityVec"] == "Global::X"
assert d["GravityDir"] == "Positive"
d["GravityVec"] = "Global::Y"
assert d["GravityVec"] == "Global::Y"
83 changes: 59 additions & 24 deletions pyaedt/application/Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from __future__ import absolute_import # noreorder

from abc import abstractmethod
from collections import OrderedDict
import gc
import json
Expand Down Expand Up @@ -39,6 +40,7 @@
from pyaedt.generic.LoadAEDTFile import load_entire_aedt_file
from pyaedt.generic.constants import AEDT_UNITS
from pyaedt.generic.constants import unit_system
from pyaedt.generic.general_methods import GrpcApiError
from pyaedt.generic.general_methods import check_and_download_file
from pyaedt.generic.general_methods import generate_unique_name
from pyaedt.generic.general_methods import is_ironpython
Expand Down Expand Up @@ -274,6 +276,7 @@ def __init__(
self._variable_manager = VariableManager(self)
self._project_datasets = []
self._design_datasets = []
self.design_settings = DesignSettings(self)

@property
def desktop_class(self):
Expand Down Expand Up @@ -4029,33 +4032,65 @@ def set_temporary_directory(self, temp_dir_path):
self.odesktop.SetTempDirectory(temp_dir_path)
return True

@pyaedt_function_handler()
def design_settings(self):
"""Get design settings for the current AEDT app.

Returns
-------
dict
Dictionary of valid design settings.
class DesignSettings:
"""Get design settings for the current AEDT app.
References
----------
References
----------
>>> oDesign.GetChildObject("Design Settings")
"""
>>> oDesign.GetChildObject("Design Settings")
"""

def __init__(self, app):
self._app = app
self.manipulate_inputs = None
try:
design_settings = self._odesign.GetChildObject("Design Settings")
except Exception: # pragma: no cover
self.logger.error("Failed to retrieve design settings.")
return False
self.design_settings = self._app.odesign.GetChildObject("Design Settings")
except GrpcApiError: # pragma: no cover
self._app.logger.error("Failed to retrieve design settings.")
self.design_settings = None

@property
def available_properties(self):
"""Available properties names for the current design."""
return [prop for prop in self.design_settings.GetPropNames() if not prop.endswith("/Choices")]

def __repr__(self):
lines = ["{"]
for prop in self.available_properties:
lines.append("\t{}: {}".format(prop, self.design_settings.GetPropValue(prop)))
lines.append("}")
return "\n".join(lines)

def __setitem__(self, key, value):
if key in self.available_properties:
if self.manipulate_inputs is not None:
value = self.manipulate_inputs.execute(key, value)
key_choices = "{}/Choices".format(key)
if key_choices in self.design_settings.GetPropNames():
value_choices = self.design_settings.GetPropValue(key_choices)
if value not in value_choices:
self._app.logger.error(
"{} is not a valid choice. Possible choices are: {}".format(value, ", ".join(value_choices))
)
return False
self.design_settings.SetPropValue(key, value)
else:
self._app.logger.error("{} property is not available in design settings.".format(key))

def __getitem__(self, key):
if key in self.available_properties:
return self.design_settings.GetPropValue(key)
else:
self._app.logger.error("{} property is not available in design settings.".format(key))
return None

def __contains__(self, item):
return item in self.available_properties

prop_name_list = design_settings.GetPropNames()
design_settings_dict = {}
for prop in prop_name_list:
try:
design_settings_dict[prop] = design_settings.GetPropValue(prop)
except Exception: # pragma: no cover
self.logger.warning('Could not retrieve "{}" property value in design settings.'.format(prop))
design_settings_dict[prop] = None

return design_settings_dict
class DesignSettingsManipulation:
@abstractmethod
def execute(self, k, v):
pass
Loading

0 comments on commit 4adad01

Please sign in to comment.