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

core loss example #3997

Merged
merged 14 commits into from
Dec 22, 2023
12 changes: 4 additions & 8 deletions _unittest/test_01_GeometryOperators.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,16 +369,12 @@ def test_orient_polygon(self):
xo2, yo2 = go.orient_polygon(x2, y2, clockwise=True)
assert x2 == xo2
assert y2 == yo2
try:
with pytest.raises(ValueError) as excinfo:
go.orient_polygon([1], [2], clockwise=True)
assert False
except ValueError as e:
assert str(e) == "'x' length must be >= 2"
try:
assert str(excinfo) == "'x' length must be >= 2"
with pytest.raises(ValueError) as excinfo:
go.orient_polygon([1, 2, 3], [1, 2], clockwise=True)
assert False
except ValueError as e:
assert str(e) == "'y' must be same length as 'x'"
assert str(excinfo) == "'y' must be same length as 'x'"

def test_is_collinear(self):
assert go.is_collinear([1, 0, 0], [1, 0, 0])
Expand Down
5 changes: 1 addition & 4 deletions _unittest/test_02_3D_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,8 @@ def test_40_create_coordinate_system(self):
assert cs.change_cs_mode(1)
assert cs.change_cs_mode(2)

try:
with pytest.raises(ValueError):
cs.change_cs_mode(3)
assert False
except ValueError:
assert True
assert cs.change_cs_mode(0)
assert cs.delete()
assert len(self.aedtapp.modeler.coordinate_systems) == 1
Expand Down
65 changes: 25 additions & 40 deletions _unittest/test_03_Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,12 @@ def test_02_create_material(self):
assert mat1.material_appearance == [11, 22, 0]
mat1.material_appearance = ["11", "22", "10"]
assert mat1.material_appearance == [11, 22, 10]
try:
with pytest.raises(ValueError):
mat1.material_appearance = [11, 22, 300]
assert False
except ValueError:
assert True
try:
with pytest.raises(ValueError):
mat1.material_appearance = [11, -22, 0]
assert False
except ValueError:
assert True
try:
with pytest.raises(ValueError):
mat1.material_appearance = [11, 22]
assert False
except ValueError:
assert True

def test_03_create_modifiers(self):
assert self.aedtapp.materials["new_copper2"].mass_density.add_thermal_modifier_free_form(
Expand Down Expand Up @@ -298,13 +289,10 @@ def test_14_get_coreloss_coefficients(self):
assert isinstance(coeff, list)
assert len(coeff) == 3
assert all(isinstance(c, float) for c in coeff)
try:
with pytest.raises(TypeError):
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]],
Expand All @@ -322,20 +310,14 @@ def test_14_get_coreloss_coefficients(self):
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(
with pytest.raises(TypeError):
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(
with pytest.raises(TypeError):
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"]
Expand All @@ -349,35 +331,38 @@ def test_14_set_core_loss(self):
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:
with pytest.raises(TypeError):
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]],
}
)
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]],
},
core_loss_model_type="Power Ferrite",
)
with pytest.raises(ValueError):
self.aedtapp.materials["mat_test"].set_coreloss_at_frequency(
points_list_at_freq={80: [[0, 0], [1, 3.5], [2, 7.4]]}, core_loss_model_type="Power Ferrite"
)
# 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(
with pytest.raises(TypeError):
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(
with pytest.raises(TypeError):
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
17 changes: 7 additions & 10 deletions _unittest/test_08_Primitives3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,12 @@ def test_44_create_polyline_basic_segments(self):
assert prim3D.create_polyline(
position_list=test_points, segment_type=PolylineSegment("Spline", num_points=3), name="PL03_spline_3pt"
)
try:
with pytest.raises(ValueError) as execinfo:
prim3D.create_polyline(position_list=test_points[0:3], segment_type="Spline", name="PL03_spline_str_3pt")
except ValueError as e:
assert str(e) == "The position_list argument must contain at least 4 points for segment of type Spline."
else:
assert False
assert (
str(execinfo)
== "The 'position_list' argument must contain at least four points for segment of type 'Spline'."
)
assert prim3D.create_polyline(
position_list=[[100, 100, 0]],
segment_type=PolylineSegment("AngularArc", arc_center=[0, 0, 0], arc_angle="30deg"),
Expand Down Expand Up @@ -1023,12 +1023,9 @@ def test_54a_create_spiral_and_add_segments(self):
# test unclassified
p11 = polyline_points[11]
position_lst = [[-142, 130, 0], [-126, 63, 0], p11]
try:
with pytest.raises(ValueError) as execinfo:
ind.insert_segment(position_lst, "Arc")
except ValueError as e:
assert str(e) == "Adding the segment result in an unclassified object. Undoing operation."
else:
assert False
assert str(execinfo) == "Adding the segment result in an unclassified object. Undoing operation."
gmalinve marked this conversation as resolved.
Show resolved Hide resolved
assert len(ind.points) == 64
assert len(ind.segment_types) == 55

Expand Down
21 changes: 4 additions & 17 deletions _unittest/test_09_VariableManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,11 @@ def test_07_addition(self):
v2 = Variable(3)
v3 = Variable("3mA")
v4 = Variable("10A")

try:
with pytest.raises(AssertionError):
v1 + v2
assert False
except AssertionError:
pass

try:
with pytest.raises(AssertionError):
v2 + v1
assert False
except AssertionError:
pass
result_1 = v2 + v2
result_2 = v3 + v4
result_3 = v3 + v3
Expand All @@ -286,17 +279,11 @@ def test_08_subtraction(self):
v3 = Variable("3mA")
v4 = Variable("10A")

try:
with pytest.raises(AssertionError):
v1 - v2
assert False
except AssertionError:
pass

try:
with pytest.raises(AssertionError):
v2 - v1
assert False
except AssertionError:
pass

result_1 = v2 - v2
result_2 = v3 - v4
Expand Down
4 changes: 1 addition & 3 deletions _unittest/test_16_3d_stackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ def test_02_line(self):
def test_03_padstackline(self):
p1 = self.st.add_padstack("Massimo", material="aluminum")
p1.plating_ratio = 0.7
try:
with pytest.raises(ValueError):
p1.set_start_layer("non_existing_layer")
except ValueError:
assert True
assert p1.set_start_layer("lay1")
assert p1.set_stop_layer("top")
p1.set_all_pad_value(1)
Expand Down
48 changes: 16 additions & 32 deletions _unittest/test_20_HFSS.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def test_06a_create_linear_count_sweep(self):
assert sweep.props["Type"] == "Discrete"

# Create a linear count sweep with the incorrect sweep type.
try:
sweep = self.aedtapp.create_linear_count_sweep(
with pytest.raises(AttributeError) as execinfo:
self.aedtapp.create_linear_count_sweep(
setupname="MySetup",
sweepname="IncorrectStep",
unit="MHz",
Expand All @@ -263,12 +263,10 @@ def test_06a_create_linear_count_sweep(self):
num_of_freq_points=1234,
sweep_type="Incorrect",
)
except AttributeError as e:
exception_raised = True
assert (
e.args[0] == "Invalid value for `sweep_type`. The value must be 'Discrete', 'Interpolating', or 'Fast'."
execinfo.args[0]
== "Invalid value for `sweep_type`. The value must be 'Discrete', 'Interpolating', or 'Fast'."
)
assert exception_raised
self.aedtapp["der_var"] = "1mm"
self.aedtapp["der_var2"] = "2mm"
setup2 = self.aedtapp.create_setup("MySetup_2", setuptype=0)
Expand Down Expand Up @@ -327,8 +325,8 @@ def test_06c_create_linear_step_sweep(self):
assert sweep.props["Type"] == "Fast"

# Create a linear step sweep with the incorrect sweep type.
try:
sweep = self.aedtapp.create_linear_step_sweep(
with pytest.raises(AttributeError) as execinfo:
self.aedtapp.create_linear_step_sweep(
setupname="MySetup",
sweepname="StepFast",
unit=units,
Expand All @@ -337,12 +335,10 @@ def test_06c_create_linear_step_sweep(self):
step_size=step_size,
sweep_type="Incorrect",
)
except AttributeError as e:
exception_raised = True
assert (
e.args[0] == "Invalid value for `sweep_type`. The value must be 'Discrete', 'Interpolating', or 'Fast'."
execinfo.args[0]
== "Invalid value for 'sweep_type'. The value must be 'Discrete', 'Interpolating', or 'Fast'."
)
assert exception_raised

def test_06d_create_single_point_sweep(self):
assert self.aedtapp.create_single_point_sweep(
Expand Down Expand Up @@ -1157,37 +1153,28 @@ def test_45B_terminal_port(self):
assert n_boundaries == 12

# Use two boxes with different dimensions.
try:
with pytest.raises(AttributeError) as execinfo:
self.aedtapp.create_spiral_lumped_port(box1, box3)
except AttributeError as e:
assert e.args[0] == "The closest faces of the two objects must be identical in shape."
else:
assert False
assert execinfo.args[0] == "The closest faces of the two objects must be identical in shape."

# Rotate box3 so that, box3 and box4 are not collinear anymore.
# Spiral lumped port can only be created based on 2 collinear objects.
box3.rotate(cs_axis="X", angle=90)
try:
with pytest.raises(AttributeError) as execinfo:
self.aedtapp.create_spiral_lumped_port(box3, box4)
except AttributeError as e:
assert e.args[0] == "The two objects must have parallel adjacent faces."
else:
assert False
assert execinfo.args[0] == "The two objects must have parallel adjacent faces."

# Rotate back box3
# rotate them slightly so that they are still parallel, but not aligned anymore with main planes.
box3.rotate(cs_axis="X", angle=-90)
box3.rotate(cs_axis="Y", angle=5)
box4.rotate(cs_axis="Y", angle=5)
try:
with pytest.raises(AttributeError) as execinfo:
self.aedtapp.create_spiral_lumped_port(box3, box4)
except AttributeError as e:
assert (
e.args[0]
execinfo.args[0]
== "The closest faces of the two objects must be aligned with the main planes of the reference system."
)
else:
assert False
self.aedtapp.delete_design("Design_Terminal_2", self.fall_back_name)

def test_46_mesh_settings(self):
Expand All @@ -1208,12 +1195,9 @@ def test_49_port_creation_exception(self):

self.aedtapp.solution_type = "Modal"
# Spiral lumped port can only be created in a 'Terminal' solution.
try:
with pytest.raises(Exception) as execinfo:
self.aedtapp.create_spiral_lumped_port(box1, box2)
except Exception as e:
exception_raised = True
assert e.args[0] == "This method can be used only in Terminal solutions."
assert exception_raised
assert execinfo.args[0] == "This method can be used only in 'Terminal' solutions."
self.aedtapp.solution_type = "Terminal"

# Try to modify SBR+ TX RX antenna settings in a solution that is different from SBR+
Expand Down
21 changes: 7 additions & 14 deletions _unittest/test_41_3dlayout_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,8 @@ def test_18b_create_linear_step_sweep(self):
assert sweep4.props["Sweeps"]["Data"] == "LIN 1GHz 10GHz 0.12GHz"

# Create a linear step sweep with the incorrect sweep type.
exception_raised = False
try:
sweep_raising_error = self.aedtapp.create_linear_step_sweep(
with pytest.raises(AttributeError) as execinfo:
self.aedtapp.create_linear_step_sweep(
setupname=setup_name,
unit="GHz",
freqstart=1,
Expand All @@ -448,12 +447,10 @@ def test_18b_create_linear_step_sweep(self):
sweep_type="Incorrect",
save_fields=True,
)
except AttributeError as e:
exception_raised = True
assert (
e.args[0] == "Invalid value for `sweep_type`. The value must be 'Discrete', 'Interpolating', or 'Fast'."
execinfo.args[0] == "Invalid value for 'sweep_type'. The value must be 'Discrete', "
"'Interpolating', or 'Fast'."
)
assert exception_raised

def test_18c_create_single_point_sweep(self):
setup_name = "RF_create_single_point"
Expand All @@ -475,19 +472,15 @@ def test_18c_create_single_point_sweep(self):
)
assert sweep6.props["Sweeps"]["Data"] == "1GHz 2GHz 3GHz 4GHz"

exception_raised = False
try:
sweep7 = self.aedtapp.create_single_point_sweep(
with pytest.raises(AttributeError) as execinfo:
self.aedtapp.create_single_point_sweep(
setupname=setup_name,
unit="GHz",
freq=[],
sweepname="RFBoardSingle",
save_fields=False,
)
except AttributeError as e:
exception_raised = True
assert e.args[0] == "Frequency list is empty. Specify at least one frequency point."
assert exception_raised
assert execinfo.args[0] == "Frequency list is empty. Specify at least one frequency point."

def test_18d_delete_setup(self):
setup_name = "SetupToDelete"
Expand Down
Loading
Loading