Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Transient ambient temperature in design settings & Design settings class #4580

Merged
merged 28 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eb7b0e6
Add IcepakDesignSettings class
lorenzovecchietti Apr 22, 2024
208189d
Add DesignSettingsClass
lorenzovecchietti Apr 23, 2024
3ced010
Revert "Add IcepakDesignSettings class"
lorenzovecchietti Apr 23, 2024
5a0141c
fix __repr__
lorenzovecchietti Apr 23, 2024
a424ea6
Merge branch 'main' into transient_ambient_temperature
lorenzovecchietti Apr 23, 2024
2881f4b
fix for manipulate_design
lorenzovecchietti Apr 23, 2024
6f5f31e
Update pyaedt/application/Design.py
lorenzovecchietti Apr 24, 2024
93825e1
Update pyaedt/application/Design.py
lorenzovecchietti Apr 24, 2024
f172122
Merge branch 'main' into transient_ambient_temperature
lorenzovecchietti Apr 24, 2024
215dafd
Fix docstring
lorenzovecchietti Apr 24, 2024
7c44cff
Tests fixes
lorenzovecchietti Apr 26, 2024
95e15fc
Fix ironpy ut
lorenzovecchietti Apr 26, 2024
13ba80f
Fix ironpy ut
lorenzovecchietti Apr 26, 2024
9c824a0
Merge branch 'main' into transient_ambient_temperature
lorenzovecchietti Apr 29, 2024
3c5f799
add transient support
lorenzovecchietti Apr 29, 2024
8b11707
add sherlock option
lorenzovecchietti Apr 29, 2024
f5efcc4
fix documentation
lorenzovecchietti Apr 29, 2024
4f78750
fix tests
lorenzovecchietti Apr 29, 2024
10d6606
Update pyaedt/application/Design.py
lorenzovecchietti Apr 29, 2024
a4dba12
improve architecture
lorenzovecchietti Apr 30, 2024
1813ab0
Apply suggestions from code review
lorenzovecchietti May 2, 2024
8b05d73
add abstract class
lorenzovecchietti May 2, 2024
101436f
add app attribute
lorenzovecchietti May 2, 2024
0a00666
add app attribute
lorenzovecchietti May 2, 2024
a4ee76f
ironpy compatibility
lorenzovecchietti May 2, 2024
969fdd1
fix
lorenzovecchietti May 2, 2024
24f7f55
Merge branch 'main' into transient_ambient_temperature
lorenzovecchietti May 2, 2024
58d607d
Merge branch 'main' into transient_ambient_temperature
lorenzovecchietti May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions _unittest/test_98_Icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,3 +1583,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"
74 changes: 52 additions & 22 deletions pyaedt/application/Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 @@ -4020,32 +4021,61 @@ def set_temporary_directory(self, temp_dir_path):
return True

@pyaedt_function_handler()
def _manipulate_design_settings_inputs(self, k, v):
return v

@property
def design_settings(self):
"""Get design settings for the current AEDT app.
return DesignSettings(self, self._manipulate_design_settings_inputs)
lorenzovecchietti marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
dict
Dictionary of valid design settings.

References
----------
class DesignSettings:
"""Get design settings for the current AEDT app.

>>> oDesign.GetChildObject("Design Settings")
"""
References
----------

>>> oDesign.GetChildObject("Design Settings")
"""

def __init__(self, app, manipulate_inputs):
self._app = app
self._manipulate_inputs = manipulate_inputs
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

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
@property
def available_properties(self):
lorenzovecchietti marked this conversation as resolved.
Show resolved Hide resolved
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:
value = self._manipulate_inputs(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 not available in design settings.".format(key))
lorenzovecchietti marked this conversation as resolved.
Show resolved Hide resolved

return design_settings_dict
def __getitem__(self, key):
if key in self.available_properties:
return self.design_settings.GetPropValue(key)
else:
self._app.logger.error("{} property not available in design settings.".format(key))
lorenzovecchietti marked this conversation as resolved.
Show resolved Hide resolved
return None
61 changes: 44 additions & 17 deletions pyaedt/icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,32 +1674,18 @@ def edit_design_settings(
# Configure design settings for gravity etc
lorenzovecchietti marked this conversation as resolved.
Show resolved Hide resolved
IceGravity = ["X", "Y", "Z"]
GVPos = False
if "gravityDir" in kwargs: # pragma: no cover
warnings.warn(
"`gravityDir` is deprecated. Use `gravity_dir` instead.",
DeprecationWarning,
)

gravity_dir = kwargs["gravityDir"]
if "CheckLevel" in kwargs: # pragma: no cover
warnings.warn(
"`CheckLevel` is deprecated. Use `check_level` instead.",
DeprecationWarning,
)

check_level = kwargs["CheckLevel"]
if int(gravity_dir) > 2:
GVPos = True
GVA = IceGravity[int(gravity_dir) - 3]
self._odesign.SetDesignSettings(
[
"NAME:Design Settings Data",
"Perform Minimal validation:=",
performvalidation,
perform_validation,
"Default Fluid Material:=",
defaultfluid,
default_fluid,
"Default Solid Material:=",
defaultsolid,
default_solid,
"Default Surface Material:=",
"Steel-oxidised-surface",
"AmbientTemperature:=",
Expand Down Expand Up @@ -6312,3 +6298,44 @@ def create_square_wave_transient_assignment(self, on_value, initial_time_off, on
Boundary dictionary object that can be passed to boundary condition assignment functions.
"""
return SquareWaveDictionary(on_value, initial_time_off, on_time, off_time, off_value)

@pyaedt_function_handler()
def _manipulate_design_settings_inputs(self, k, v):
if k in ["AmbTemp", "AmbRadTemp"]:
if k == "AmbTemp" and isinstance(v, (dict, BoundaryDictionary)):
self.logger.error("Failed. Use `edit_design_settings` function.")
return self.design_settings["AmbTemp"]
# Bug in native API. Uncomment when fixed
lorenzovecchietti marked this conversation as resolved.
Show resolved Hide resolved
# if not self.solution_type == "Transient":
# self.logger.error("Transient assignment is supported only in transient designs.")
# return False
# ambtemp = getattr(self, "_parse_variation_data")(
# "AmbientTemperature",
# "Transient",
# variation_value=v["Values"],
# function=v["Function"],
# )
# if ambtemp is not None:
# return ambtemp
# else:
# self.logger.error("Transient dictionary is not valid.")
# return False
else:
return self.value_with_units(v, "cel")
elif k == "AmbGaugePressure":
return self.value_with_units(v, "n_per_meter_sq")
elif k == "GravityVec":
if isinstance(v, (float, int)):
self.design_settings["GravityDir"] = ["Positive", "Negative"][v // 3]
v = "Global::{}".format(["X", "Y", "Z"][v - v // 3 * 3])
return v
else:
if len(v.split("::")) == 1 and len(v) < 3:
if v.startswith("+") or v.startswith("-"):
self.design_settings["GravityDir"] = ["Positive", "Negative"][int(v.startswith("-"))]
v = v[-1]
return "Global::{}".format(v)
else:
return v
else:
return v
Loading