Skip to content

Commit

Permalink
Merge branch 'main' into feat/toolkit_installer
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys committed May 3, 2024
2 parents e429f04 + 855de01 commit baa50a3
Show file tree
Hide file tree
Showing 8 changed files with 822 additions and 596 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 @@ -420,9 +421,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"
5 changes: 4 additions & 1 deletion _unittest_solvers/test_00_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def test_07_export_maxwell_fields(self, m3dtransient):
new_setup.props = setup.props
new_setup.update()

@pytest.mark.skipif(is_linux and desktop_version == "2024.2", reason="Temporary skip for SPISIM related tests")
def test_08_compute_erl(self, circuit_erl):
touchstone_file = circuit_erl.export_touchstone()
spisim = SpiSim(touchstone_file)
Expand All @@ -452,6 +453,7 @@ def test_08_compute_erl(self, circuit_erl):
erl_data_3 = spisim.compute_erl(specify_through_ports=[1, 2, 3, 4])
assert erl_data_3

@pytest.mark.skipif(is_linux and desktop_version == "2024.2", reason="Temporary skip for SPISIM related tests")
def test_09a_compute_com(self, local_scratch, circuit_com):
touchstone_file = circuit_com.export_touchstone()
spisim = SpiSim(touchstone_file)
Expand All @@ -464,6 +466,7 @@ def test_09a_compute_com(self, local_scratch, circuit_com):
)
assert com

@pytest.mark.skipif(is_linux and desktop_version == "2024.2", reason="Temporary skip for SPISIM related tests")
def test_09b_compute_com(self, local_scratch):
com_example_file_folder = os.path.join(local_path, "example_models", test_subfolder, "com_unit_test_sparam")
thru_s4p = local_scratch.copyfile(os.path.join(com_example_file_folder, "SerDes_Demo_02_Thru.s4p"))
Expand Down Expand Up @@ -503,7 +506,7 @@ def test_09b_compute_com(self, local_scratch):
)
assert com_0 and com_1


@pytest.mark.skipif(is_linux and desktop_version == "2024.2", reason="Temporary skip for SPISIM related tests")
def test_09c_compute_com(self, local_scratch):
com_example_file_folder = Path(local_path) / "example_models" / test_subfolder / "com_unit_test_sparam"
thru_s4p = local_scratch.copyfile(com_example_file_folder / "SerDes_Demo_02_Thru.s4p")
Expand Down
2 changes: 1 addition & 1 deletion _unittest_solvers/test_26_emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ def test_22_couplings(self, add_app):
)
def test_23_result_categories(self, add_app):
# set up project and run
self.aedtapp = add_app(application=Emit)
self.aedtapp = add_app(application=Emit, project_name=generate_unique_project_name())
rad1 = self.aedtapp.modeler.components.create_component("GPS Receiver")
ant1 = self.aedtapp.modeler.components.create_component("Antenna")
ant1.move_and_connect_to(rad1)
Expand Down
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 baa50a3

Please sign in to comment.