Skip to content

Commit

Permalink
Merge branch 'main' into release/0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys committed Nov 17, 2023
2 parents fab3dba + 9eeb5d9 commit c5ff2de
Show file tree
Hide file tree
Showing 21 changed files with 685 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exclude: |
repos:
- repo: https://github.com/psf/black
rev: 23.10.1 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!!
rev: 23.11.0 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!!
hooks:
- id: black
args:
Expand Down Expand Up @@ -61,7 +61,7 @@ repos:
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.10.1]
additional_dependencies: [black==23.11.0]


# - repo: https://github.com/numpy/numpydoc
Expand Down
1 change: 1 addition & 0 deletions _unittest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def desktop():
for key in keys:
del _desktop_sessions[key]
d = Desktop(desktop_version, NONGRAPHICAL, new_thread)
d.odesktop.SetTempDirectory(tempfile.gettempdir())
d.disable_autosave()
d.odesktop.SetDesktopConfiguration("All")
d.odesktop.SetSchematicEnvironment(0)
Expand Down
2 changes: 2 additions & 0 deletions _unittest/test_01_Design.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import tempfile

from _unittest.conftest import config
from _unittest.conftest import desktop_version
Expand Down Expand Up @@ -90,6 +91,7 @@ def test_06_libs(self):
def test_06a_set_temp_dir(self):
assert os.path.exists(self.aedtapp.set_temporary_directory(os.path.join(self.local_scratch.path, "temp_dir")))
assert self.aedtapp.set_temporary_directory(os.path.join(self.local_scratch.path, "temp_dir"))
self.aedtapp.set_temporary_directory(tempfile.gettempdir())

def test_08_objects(self):
print(self.aedtapp.oboundary)
Expand Down
33 changes: 31 additions & 2 deletions _unittest/test_03_Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,31 @@ def test_09_non_linear_materials(self, add_app):
assert app.materials.material_keys["mymat2"].is_used

def test_10_add_material_sweep(self):
assert self.aedtapp.materials.add_material_sweep(["copper", "aluminum"], "sweep_copper")
assert "sweep_copper" in list(self.aedtapp.materials.material_keys.keys())
material_name = "sweep_material"
assert self.aedtapp.materials.add_material_sweep(["copper", "aluminum", "FR4_epoxy"], material_name)
assert material_name in list(self.aedtapp.materials.material_keys.keys())
properties_to_check = [
"permittivity",
"permeability",
"conductivity",
"dielectric_loss_tangent",
"thermal_conductivity",
"mass_density",
"specific_heat",
"thermal_expansion_coefficient",
"youngs_modulus",
"poissons_ratio",
]
# check if the variables are correctly created
assert "$ID" + material_name in self.aedtapp.variable_manager.variable_names
for prop in properties_to_check:
var_name = "$" + material_name + "_" + prop
assert var_name in self.aedtapp.variable_manager.variable_names
# check if the material properties are correct
for prop in properties_to_check:
var_name = "$" + material_name + "_" + prop
mat_prop = getattr(self.aedtapp.materials[material_name], prop).value
assert mat_prop == var_name + "[$ID" + material_name + "]"

def test_11_material_case(self):
assert self.aedtapp.materials["Aluminum"] == self.aedtapp.materials["aluminum"]
Expand All @@ -245,3 +268,9 @@ def test_12_material_model(self):
self.aedtapp["$dk"] = 3
self.aedtapp["$df"] = 0.01
assert mat.set_djordjevic_sarkar_model(dk="$dk", df="$df")

def test_13_get_materials_in_project(self):
used_materials = self.aedtapp.materials.get_used_project_material_names()
assert isinstance(used_materials, list)
for m in [mat for mat in self.aedtapp.materials if mat.is_used]:
assert m.name in used_materials
6 changes: 3 additions & 3 deletions _unittest/test_09_VariableManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,12 @@ def test_16_maxwell_circuit_variables(self):
assert mc["var3"] == "10deg"
assert mc["var4"] == "10rad"

def test_17_project_sweep_variable(self):
def test_17_project_variable_operation(self):
self.aedtapp["$my_proj_test"] = "1mm"
self.aedtapp["$my_proj_test2"] = 2
self.aedtapp["$my_proj_test3"] = "$my_proj_test*$my_proj_test2"
assert self.aedtapp.variable_manager["$my_proj_test3"].units == "mm"
assert self.aedtapp.variable_manager["$my_proj_test3"].numeric_value == 2.0
self.aedtapp.materials.add_material_sweep(["copper", "aluminum"], "sweep_alu")
assert "$sweep_alupermittivity" in self.aedtapp.variable_manager.dependent_variables

def test_18_test_optimization_properties(self):
var = "v1"
Expand Down Expand Up @@ -668,6 +666,8 @@ def test_32_delete_unused_variables(self):
self.aedtapp.modeler.create_rectangle(0, ["used_var", "used_var", "used_var"], [10, 20])
mat1 = self.aedtapp.materials.add_material("new_copper2")
mat1.permittivity = "$project_used_var"
assert self.aedtapp.variable_manager.is_used("used_var")
assert not self.aedtapp.variable_manager.is_used("unused_var")
assert self.aedtapp.variable_manager.delete_variable("unused_var")
self.aedtapp["unused_var"] = "1mm"
number_of_variables = len(self.aedtapp.variable_manager.variable_names)
Expand Down
84 changes: 84 additions & 0 deletions _unittest/test_98_Icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,3 +1278,87 @@ def test_68_mesh_priority_3d_comp(self, add_app):
assert app.mesh.add_priority(entity_type=2, comp_name="all_3d_objects1", priority=2)

app.close_project(name="3d_comp_mesh_prio_test", save_project=False)

def test_69_recirculation_boundary(self):
box = self.aedtapp.modeler.create_box([5, 5, 5], [1, 2, 3], "BlockBoxEmpty", "copper")
box.solve_inside = False
assert not self.aedtapp.assign_recirculation_opening(
[box.top_face_x, box.bottom_face_x, box.bottom_face_y], box.top_face_x, flow_assignment="10kg_per_s_m2"
)
assert self.aedtapp.assign_recirculation_opening(
[box.top_face_x, box.bottom_face_x], box.top_face_x, conductance_external_temperature="25cel"
)
assert self.aedtapp.assign_recirculation_opening(
[box.top_face_x, box.bottom_face_x], box.top_face_x, start_time="0s"
)
self.aedtapp.solution_type = "Transient"
assert self.aedtapp.assign_recirculation_opening([box.top_face_x, box.bottom_face_x], box.top_face_x)
assert self.aedtapp.assign_recirculation_opening([box.top_face_x.id, box.bottom_face_x.id], box.top_face_x.id)
assert not self.aedtapp.assign_recirculation_opening(
[box.top_face_x.id, box.bottom_face_x.id],
box.top_face_x.id,
thermal_specification="Conductance",
flow_direction=[1],
)
temp_dict = {"Function": "Square Wave", "Values": ["1cel", "0s", "1s", "0.5s", "0cel"]}
flow_dict = {"Function": "Sinusoidal", "Values": ["0kg_per_s_m2", 1, 1, "1s"]}
recirc = self.aedtapp.assign_recirculation_opening(
[box.top_face_x.id, box.bottom_face_x.id],
box.top_face_x.id,
thermal_specification="Temperature",
assignment_value=temp_dict,
flow_assignment=flow_dict,
)
assert recirc
assert recirc.update()
self.aedtapp.solution_type = "SteadyState"
assert not self.aedtapp.assign_recirculation_opening(
[box.top_face_x.id, box.bottom_face_x.id],
box.top_face_x.id,
thermal_specification="Temperature",
assignment_value=temp_dict,
flow_assignment=flow_dict,
)
assert not self.aedtapp.assign_recirculation_opening(
[box.top_face_x.id, box.bottom_face_x.id],
box.top_face_x.id,
thermal_specification="Temperature",
flow_direction="Side",
)
assert self.aedtapp.assign_recirculation_opening(
[box.top_face_x.id, box.bottom_face_x.id],
box.top_face_x.id,
thermal_specification="Temperature",
flow_direction=[0, 1, 0],
)
assert not self.aedtapp.assign_recirculation_opening(
[box.top_face_x.id, box.bottom_face_x.id],
box.top_face_x.id,
thermal_specification="Temperature",
flow_assignment=flow_dict,
)

def test_70_blower_boundary(self):
cylinder = self.aedtapp.modeler.create_cylinder(cs_axis="X", position=[0, 0, 0], radius=10, height=1)
curved_face = [f for f in cylinder.faces if not f.is_planar]
planar_faces = [f for f in cylinder.faces if f.is_planar]
assert not self.aedtapp.assign_blower_type1(curved_face + planar_faces, planar_faces, [10, 5, 0], [0, 1, 2, 4])
blower = self.aedtapp.assign_blower_type1(
[f.id for f in curved_face + planar_faces], [f.id for f in planar_faces], [10, 5, 0], [0, 2, 4]
)
assert blower
assert blower.update()
box = self.aedtapp.modeler.create_box([5, 5, 5], [1, 2, 3], "BlockBoxEmpty", "copper")
assert self.aedtapp.assign_blower_type2([box.faces[0], box.faces[1]], [box.faces[0]], [10, 5, 0], [0, 2, 4])

def test_71_assign_adiabatic_plate(self):
box = self.aedtapp.modeler.create_box([5, 5, 5], [1, 2, 3], "Box", "copper")
rectangle = self.aedtapp.modeler.create_rectangle(0, [0, 0, 0], [1, 2])
assert self.aedtapp.assign_adiabatic_plate(
box.top_face_x, {"RadiateTo": "AllObjects"}, {"RadiateTo": "AllObjects"}
)
assert self.aedtapp.assign_adiabatic_plate(box.top_face_x.id)
assert self.aedtapp.assign_adiabatic_plate(rectangle)
ad_plate = self.aedtapp.assign_adiabatic_plate(rectangle.name)
assert ad_plate
assert ad_plate.update()
1 change: 1 addition & 0 deletions _unittest_solvers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def local_scratch(init_scratch):
@pytest.fixture(scope="module", autouse=True)
def desktop():
d = Desktop(desktop_version, NONGRAPHICAL, new_thread)
d.odesktop.SetTempDirectory(tempfile.gettempdir())
d.disable_autosave()

yield d
Expand Down
26 changes: 24 additions & 2 deletions pyaedt/application/Variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
import re
import types
import warnings

from pyaedt import pyaedt_function_handler
from pyaedt.generic.constants import AEDT_UNITS
Expand Down Expand Up @@ -1237,7 +1238,7 @@ def delete_variable(self, var_name):
return False

@pyaedt_function_handler()
def is_used_variable(self, var_name):
def is_used(self, var_name):
"""Find if a variable is used.
Parameters
Expand Down Expand Up @@ -1268,6 +1269,27 @@ def is_used_variable(self, var_name):
return used
return used

@pyaedt_function_handler()
def is_used_variable(self, var_name):
"""Find if a variable is used.
.. deprecated:: 0.7.4
Use :func:`is_used` method instead.
Parameters
----------
var_name : str
Name of the variable.
Returns
-------
bool
``True`` when successful, ``False`` when failed.
"""
warnings.warn("`is_used_variable` is deprecated. Use `is_used` method instead.", DeprecationWarning)
return self.is_used(var_name)

def _find_used_variable_history(self, history, var_name):
"""Find if a variable is used.
Expand Down Expand Up @@ -1307,7 +1329,7 @@ def delete_unused_variables(self):
var_list = self.variable_names

for var in var_list[:]:
if not self.is_used_variable(var):
if not self.is_used(var):
self.delete_variable(var)
return True

Expand Down
2 changes: 1 addition & 1 deletion pyaedt/edb_core/edb_data/nets_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def serial_rlc(self):
{
i: v
for i, v in self._app._nets[net].components.items()
if list(set(v.nets).intersection(nets)) != [net]
if list(set(v.nets).intersection(nets)) != [net] and v.type in ["Resistor", "Inductor", "Capacitor"]
}
)
return comps_common
Expand Down
29 changes: 22 additions & 7 deletions pyaedt/edb_core/edb_data/siwave_simulation_setup_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

from pyaedt.edb_core.edb_data.simulation_setup import BaseSimulationSetup
from pyaedt.edb_core.general import convert_netdict_to_pydict
from pyaedt.edb_core.general import convert_pydict_to_netdict
Expand Down Expand Up @@ -1005,11 +1007,13 @@ def set_pi_slider(self, value):
- ``0``: Optimal speed
- ``1``: Balanced
- ``2``: Optimal accuracy
.. deprecated:: 0.7.5
Use :property:`pi_slider_position` property instead.
"""
self.use_si_settings = False
self.use_custom_settings = False
warnings.warn("`set_pi_slider` is deprecated. Use `pi_slider_position` property instead.", DeprecationWarning)
self.pi_slider_position = value
self.advanced_settings.set_pi_slider(value)

@pyaedt_function_handler
def set_si_slider(self, value):
Expand All @@ -1020,11 +1024,14 @@ def set_si_slider(self, value):
- ``0``: Optimal speed
- ``1``: Balanced
- ``2``: Optimal accuracy```
.. deprecated:: 0.7.5
Use :property:`si_slider_position` property instead.
"""
self.use_si_settings = True
self.use_custom_settings = False
warnings.warn("`set_si_slider` is deprecated. Use `si_slider_position` property instead.", DeprecationWarning)

self.si_slider_position = value
self.advanced_settings.set_si_slider(value)

@property
def pi_slider_position(self):
Expand All @@ -1038,9 +1045,13 @@ def pi_slider_position(self, value):
self._edb_object = self._set_edb_setup_info(edb_setup_info)
self._update_setup()

self.use_si_settings = False
self.use_custom_settings = False
self.advanced_settings.set_pi_slider(value)

@property
def si_slider_position(self):
"""SI solider position. Values are from ``1`` to ``3``."""
"""SI slider position. Values are from ``1`` to ``3``."""
return self.get_sim_setup_info.SimulationSettings.SISliderPos

@si_slider_position.setter
Expand All @@ -1050,6 +1061,10 @@ def si_slider_position(self, value):
self._edb_object = self._set_edb_setup_info(edb_setup_info)
self._update_setup()

self.use_si_settings = True
self.use_custom_settings = False
self.advanced_settings.set_si_slider(value)

@property
def use_custom_settings(self):
"""Custom settings to use.
Expand Down
4 changes: 2 additions & 2 deletions pyaedt/generic/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,8 @@ def import_config(self, config_file, *args):
self._app.logger.warning("Material %s already exists. Renaming to %s", el, newname)
else:
newname = el
newmat = Material(self._app, el, val)
if newmat.update():
newmat = Material(self._app, el, val, material_update=True)
if newmat:
self._app.materials.material_keys[newname] = newmat
else: # pragma: no cover
self.results.import_materials = False
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/generic/touchstone_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def get_worst_curve(self, freq_min=None, freq_max=None, worst_is_higher=True, cu

@pyaedt_function_handler()
def read_touchstone(file_path):
"""Load the contents of a Touchstone file into an NPort
"""Load the contents of a Touchstone file into an NPort.
Parameters
----------
Expand Down
22 changes: 21 additions & 1 deletion pyaedt/hfss3dlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,15 @@ def create_scattering(

@pyaedt_function_handler()
def export_touchstone(
self, setup_name=None, sweep_name=None, file_name=None, variations=None, variations_value=None
self,
setup_name=None,
sweep_name=None,
file_name=None,
variations=None,
variations_value=None,
renormalization=False,
impedance=None,
gamma_impedance_comments=False,
):
"""Export a Touchstone file.
Expand All @@ -797,6 +805,15 @@ def export_touchstone(
variations_value : list, optional
List of all parameter variation values. For example, ``["22cel", "100"]``.
The default is ``None``.
renormalization : bool, optional
Perform renormalization before export.
The default is ``False``.
impedance : float, optional
Real impedance value in ohm, for renormalization, if not specified considered 50 ohm.
The default is ``None``.
gamma_impedance_comments : bool, optional
Include Gamma and Impedance values in comments.
The default is ``False``.
Returns
-------
Expand All @@ -814,6 +831,9 @@ def export_touchstone(
file_name=file_name,
variations=variations,
variations_value=variations_value,
renormalization=renormalization,
impedance=impedance,
comments=gamma_impedance_comments,
)

@pyaedt_function_handler()
Expand Down
Loading

0 comments on commit c5ff2de

Please sign in to comment.