Skip to content

Commit

Permalink
Merge branch 'main' into solder_balls_height_control_with_simconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys authored Nov 24, 2023
2 parents 07ebfdf + 2ba12b5 commit 3f0eb57
Show file tree
Hide file tree
Showing 4 changed files with 558 additions and 13 deletions.
109 changes: 107 additions & 2 deletions _unittest/test_03_Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_02_create_material(self):

assert mat1.set_electrical_steel_coreloss(1, 2, 3, 4, 0.002)
assert mat1.get_curve_coreloss_type() == "Electrical Steel"
assert mat1.get_curve_coreloss_values()["core_loss_equiv_cut_depth"] == "0.002meter"
assert mat1.get_curve_coreloss_values()["core_loss_equiv_cut_depth"] == 0.002
assert mat1.set_hysteresis_coreloss(1, 2, 3, 4, 0.002)
assert mat1.get_curve_coreloss_type() == "Hysteresis Model"
assert mat1.set_bp_curve_coreloss([[0, 0], [10, 10], [20, 20]])
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_08B_import_materials_from_excel(self):
assert len(mats) == 2

def test_09_non_linear_materials(self, add_app):
app = add_app(application=Maxwell3d)
app = add_app(application=Maxwell3d, solution_type="Transient")
mat1 = app.materials.add_material("myMat")
mat1.permeability = [[0, 0], [1, 12], [10, 30]]
mat1.permittivity = [[0, 0], [2, 12], [10, 30]]
Expand Down Expand Up @@ -274,3 +274,108 @@ def test_13_get_materials_in_project(self):
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

def test_14_get_coreloss_coefficients(self):
mat = self.aedtapp.materials.add_material("mat_test")
# Test points_list_at_freq
coeff = self.aedtapp.materials["mat_test"].get_core_loss_coefficients(
points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}
)
assert isinstance(coeff, list)
assert len(coeff) == 3
assert all(isinstance(c, float) for c in coeff)
coeff = self.aedtapp.materials["mat_test"].get_core_loss_coefficients(
points_list_at_freq={"60Hz": [[0, 0], [1, 3.5], [2, 7.4]]}
)
assert isinstance(coeff, list)
assert len(coeff) == 3
assert all(isinstance(c, float) for c in coeff)
coeff = self.aedtapp.materials["mat_test"].get_core_loss_coefficients(
points_list_at_freq={"0.06kHz": [[0, 0], [1, 3.5], [2, 7.4]]}
)
assert isinstance(coeff, list)
assert len(coeff) == 3
assert all(isinstance(c, float) for c in coeff)
try:
self.aedtapp.materials["mat_test"].get_core_loss_coefficients(
points_list_at_freq=[[0, 0], [1, 3.5], [2, 7.4]]
)
assert False
except TypeError:
assert True
coeff = self.aedtapp.materials["mat_test"].get_core_loss_coefficients(
points_list_at_freq={
60: [[0, 0], [1, 3.5], [2, 7.4]],
100: [[0, 0], [1, 8], [2, 9]],
150: [[0, 0], [1, 10], [2, 19]],
}
)
assert isinstance(coeff, list)
assert len(coeff) == 3
assert all(isinstance(c, float) for c in coeff)
# Test thickness
coeff = self.aedtapp.materials["mat_test"].get_core_loss_coefficients(
points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness="0.6mm"
)
assert isinstance(coeff, list)
assert len(coeff) == 3
assert all(isinstance(c, float) for c in coeff)
try:
coeff = self.aedtapp.materials["mat_test"].get_core_loss_coefficients(
points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness="invalid"
)
assert False
except TypeError:
assert True
try:
coeff = self.aedtapp.materials["mat_test"].get_core_loss_coefficients(
points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness=50
)
assert False
except TypeError:
assert True

def test_14_set_core_loss(self):
mat = self.aedtapp.materials["mat_test"]
# Test points_list_at_freq
assert self.aedtapp.materials["mat_test"].set_coreloss_at_frequency(
points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}
)
assert self.aedtapp.materials["mat_test"].set_coreloss_at_frequency(
points_list_at_freq={"60Hz": [[0, 0], [1, 3.5], [2, 7.4]]}
)
assert self.aedtapp.materials["mat_test"].set_coreloss_at_frequency(
points_list_at_freq={"0.06kHz": [[0, 0], [1, 3.5], [2, 7.4]]}
)
try:
self.aedtapp.materials["mat_test"].set_coreloss_at_frequency(
points_list_at_freq=[[0, 0], [1, 3.5], [2, 7.4]]
)
assert False
except TypeError:
assert True
assert self.aedtapp.materials["mat_test"].set_coreloss_at_frequency(
points_list_at_freq={
60: [[0, 0], [1, 3.5], [2, 7.4]],
100: [[0, 0], [1, 8], [2, 9]],
150: [[0, 0], [1, 10], [2, 19]],
}
)
# Test thickness
assert self.aedtapp.materials["mat_test"].set_coreloss_at_frequency(
points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness="0.6mm"
)
try:
coeff = self.aedtapp.materials["mat_test"].set_coreloss_at_frequency(
points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness="invalid"
)
assert False
except TypeError:
assert True
try:
coeff = self.aedtapp.materials["mat_test"].set_coreloss_at_frequency(
points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness=50
)
assert False
except TypeError:
assert True
39 changes: 39 additions & 0 deletions _unittest_solvers/test_26_emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,45 @@ def test_radio_component(self, add_app):
assert start_freq == 0.1
start_freq = radio.band_start_frequency(band, "THz")
assert start_freq == 0.0001
# test band.set_band_start_frequency
start_freq = 10
units = 'MHz'
radio.set_band_start_frequency(band, start_freq, units=units)
assert radio.band_start_frequency(band, units=units) == start_freq
start_freq = 20000000
radio.set_band_start_frequency(band, start_freq)
assert radio.band_start_frequency(band, units='Hz') == start_freq
# test band.set_band_stop_frequency
stop_freq = 30
units = 'MHz'
radio.set_band_stop_frequency(band, stop_freq, units=units)
assert radio.band_stop_frequency(band, units=units) == stop_freq
stop_freq = 40000000
radio.set_band_stop_frequency(band, stop_freq)
assert radio.band_stop_frequency(band, units='Hz') == stop_freq
# test corner cases for band start and stop frequencies
start_freq = 10
stop_freq = 9
units = 'Hz'
radio.set_band_start_frequency(band, start_freq, units=units)
radio.set_band_stop_frequency(band, stop_freq, units=units)
assert radio.band_start_frequency(band, units="Hz") == 8
radio.set_band_start_frequency(band, 10, units=units)
assert radio.band_stop_frequency(band, units="Hz") == 11
units = 'wrong'
radio.set_band_stop_frequency(band, 10, units=units)
assert radio.band_stop_frequency(band, units='Hz') == 10
radio.set_band_start_frequency(band, 10, units=units)
assert radio.band_start_frequency(band, units='Hz') == 10
with pytest.raises(ValueError) as e:
start_freq = 101
units = 'GHz'
radio.set_band_start_frequency(band, start_freq, units=units)
assert "Frequency should be within 1Hz to 100 GHz." in str(e)
stop_freq = 102
radio.set_band_stop_frequency(band, stop_freq, units=units)
assert "Frequency should be within 1Hz to 100 GHz." in str(e)

# test power unit conversions
band_power = radio.band_tx_power(band)
assert band_power == 40.0
Expand Down
138 changes: 138 additions & 0 deletions pyaedt/modeler/circuits/PrimitivesEmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,144 @@ def band_stop_frequency(self, band_node, units=""):
units = self.units["Frequency"]
return consts.unit_converter(float(band_node.props["StopFrequency"]), "Freq", "Hz", units)

def set_band_start_frequency(self, band_node, band_start_freq, units=""):
"""Set start frequency of the band.
Parameters
----------
band_node : pyaedt.modeler.circuits.PrimitivesEmit.EmitComponentPropNode object
Instance of the band node
band_start_freq : float
Start frequency of the band.
units : str, optional
Units of the start frequency. If no units are specified or the units
specified are invalid, then `"Hz"`` is assumed.
Returns
------
None
Examples
--------
>>> from pyaedt import Emit
>>> aedtapp = Emit(new_desktop_session=False)
>>> radio = aedtapp.modeler.components.create_component("New Radio")
>>> band = radio.bands()[0]
>>> start_freq = 10
>>> units = 'MHz'
>>> radio.set_band_start_frequency(band, start_freq, units=units)
"""

# if "Band" not in band_node.props["Type"]:
# raise TypeError("{} must be a band.".format(band_node.node_name))

if not units or units not in emit_consts.EMIT_VALID_UNITS["Frequency"]:
units = "Hz"

# convert to Hz
freq_float_in_Hz = consts.unit_converter(band_start_freq, "Freq", units, "Hz")
freq_string = "{}".format(freq_float_in_Hz)
if not (1 <= freq_float_in_Hz <= 100000000000): # pragma: no cover
raise ValueError("Frequency should be within 1Hz to 100 GHz.")
if float(band_node.props["StopFrequency"]) < freq_float_in_Hz: # pragma: no cover
stop_freq = freq_float_in_Hz + 1
band_node._set_prop_value({"StopFrequency": str(stop_freq)})
else:
prop_list = {"StartFrequency": freq_string}
band_node._set_prop_value(prop_list)

def set_band_stop_frequency(self, band_node, band_stop_freq, units=""):
"""Set stop frequency of the band.
Parameters
----------
band_node : pyaedt.modeler.circuits.PrimitivesEmit.EmitComponentPropNode object
Instance of the band node
band_stop_freq : float
Stop frequency of the band.
units : str, optional
Units of the stop frequency. If no units are specified or the units
specified are invalid, then `"Hz"`` is assumed.
Returns
------
None
Examples
--------
>>> from pyaedt import Emit
>>> aedtapp = Emit(new_desktop_session=False)
>>> radio = aedtapp.modeler.components.create_component("New Radio")
>>> band = radio.bands()[0]
>>> stop_freq = 10
>>> units = 'MHz'
>>> radio.set_band_stop_frequency(band, stop_freq, units=units)
"""
# if "Band" not in band_node.props["Type"]:
# raise TypeError("{} must be a band.".format(band_node.node_name))
if not units or units not in emit_consts.EMIT_VALID_UNITS["Frequency"]:
units = "Hz"
# convert to Hz
freq_float_in_Hz = consts.unit_converter(band_stop_freq, "Freq", units, "Hz")
if not (1 <= freq_float_in_Hz <= 100000000000): # pragma: no cover
raise ValueError("Frequency should be within 1Hz to 100 GHz.")
if float(band_node.props["StartFrequency"]) > freq_float_in_Hz: # pragma: no cover
if freq_float_in_Hz > 1:
band_node._set_prop_value({"StartFrequency": str(freq_float_in_Hz - 1)})
else: # pragma: no cover
raise ValueError("Band stop frequency is less than start frequency.")
freq_string = "{}".format(freq_float_in_Hz)
prop_list = {"StopFrequency": freq_string}
band_node._set_prop_value(prop_list)

# def duplicate_band(self, band_node_to_duplicate):
# """
# [Incomplete 10/19/2023]
# Parameters
# ----------
# band_node_to_duplicate
#
# Returns
# -------
#
# """
# # append number to the name of the band to duplicate.
# print('Duplicating...')
#
#
# # return band node
# def convert_channels_to_multi_bands(self, band_node):
# """
# [Incomplete 10/19/2023]
# Parameters
# ----------
# band_node
#
# Returns
# -------
#
# """
# # get the channels. Say returns 10 channels in the band_node
# # Name = r.bands()[0].children[0].props['Name']
# # band_node.props['Name']
# # Start = r.bands()[0].props['StartFrequency']
# band_start_frequency = float(band_node.props['StartFrequency'])
# # Stop = r.bands()[0].props['StopFrequency']
# band_stop_frequency = float(band_node.props['StopFrequency'])
# # Spacing = r.bands()[0].props['ChannelSpacing']
# channel_spacing = float(band_node.props['ChannelSpacing'])
# # for each channel
# # 1) create a band (duplicate original one)
# # 2) set band start and stop frequencies
# for channel in list(range(int(band_start_frequency), int(band_stop_frequency), int(channel_spacing))):
# baby_band_start = channel
# baby_band_stop = channel+channel_spacing
# baby_band_node = self.duplicate_band(band_node) # return band name or some handle to it
# self.set_band_start_frequency(baby_band_node, baby_band_start)
# self.set_band_stop_frequency(baby_band_node, baby_band_stop)
# # set start and stop freq for that band name
# # to be

def band_channel_bandwidth(self, band_node, units=""):
"""Get the channel bandwidth of the band node.
Expand Down
Loading

0 comments on commit 3f0eb57

Please sign in to comment.