Skip to content

Commit ffecfbe

Browse files
authored
fix assign_winding and assign_coil + update tests (#1147)
1 parent be87bbb commit ffecfbe

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed

_unittest/test_27_Maxwell2D.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pyaedt import Maxwell2d
1010
from pyaedt.application.Design import DesignCache
1111
from pyaedt.generic.constants import SOLUTIONS
12+
from pyaedt.generic.general_methods import generate_unique_name
1213

1314
try:
1415
import pytest # noqa: F401
@@ -33,12 +34,36 @@ def test_03_assign_initial_mesh_from_slider(self):
3334

3435
@pyaedt_unittest_check_desktop_error
3536
def test_04_create_winding(self):
36-
3737
bounds = self.aedtapp.assign_winding(current_value=20e-3, coil_terminals=["Coil"])
3838
assert bounds
3939
o = self.aedtapp.modeler.create_rectangle([0, 0, 0], [3, 1], name="Rectangle2", matname="copper")
4040
bounds = self.aedtapp.assign_winding(current_value=20e-3, coil_terminals=o.id)
4141
assert bounds
42+
bounds = self.aedtapp.assign_winding(current_value="20e-3A", coil_terminals=["Coil"])
43+
assert bounds
44+
bounds = self.aedtapp.assign_winding(res="1ohm", coil_terminals=["Coil"])
45+
assert bounds
46+
bounds = self.aedtapp.assign_winding(ind="1H", coil_terminals=["Coil"])
47+
assert bounds
48+
bounds = self.aedtapp.assign_winding(voltage="10V", coil_terminals=["Coil"])
49+
assert bounds
50+
bounds_name = generate_unique_name("Coil")
51+
bounds = self.aedtapp.assign_winding(coil_terminals=["Coil"], name=bounds_name)
52+
assert bounds_name == bounds.name
53+
54+
@pyaedt_unittest_check_desktop_error
55+
def test_04a_assign_coil(self):
56+
bound = self.aedtapp.assign_coil(input_object=["Coil"])
57+
assert bound
58+
polarity = "Positive"
59+
bound = self.aedtapp.assign_coil(input_object=["Coil"], polarity=polarity)
60+
assert bound.props["PolarityType"] == polarity.lower()
61+
polarity = "Negative"
62+
bound = self.aedtapp.assign_coil(input_object=["Coil"], polarity=polarity)
63+
assert bound.props["PolarityType"] == polarity.lower()
64+
bound_name = generate_unique_name("Coil")
65+
bound = self.aedtapp.assign_coil(input_object=["Coil"], name=bound_name)
66+
assert bound_name == bound.name
4267

4368
@pyaedt_unittest_check_desktop_error
4469
def test_05_create_vector_potential(self):

_unittest/test_28_Maxwell3D.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from _unittest.conftest import local_path
88
from pyaedt import Maxwell3d
99
from pyaedt.generic.constants import SOLUTIONS
10+
from pyaedt.generic.general_methods import generate_unique_name
1011

1112
try:
1213
import pytest
@@ -73,7 +74,35 @@ def test_04_coil_terminal(self):
7374
self.aedtapp.solution_type = "EddyCurrent"
7475

7576
def test_05_winding(self):
76-
assert self.aedtapp.assign_winding(self.aedtapp.modeler["Coil_Section1"].faces[0].id)
77+
face_id = self.aedtapp.modeler["Coil_Section1"].faces[0].id
78+
assert self.aedtapp.assign_winding(face_id)
79+
bounds = self.aedtapp.assign_winding(current_value=20e-3, coil_terminals=face_id)
80+
assert bounds
81+
bounds = self.aedtapp.assign_winding(current_value="20e-3A", coil_terminals=face_id)
82+
assert bounds
83+
bounds = self.aedtapp.assign_winding(res="1ohm", coil_terminals=face_id)
84+
assert bounds
85+
bounds = self.aedtapp.assign_winding(ind="1H", coil_terminals=face_id)
86+
assert bounds
87+
bounds = self.aedtapp.assign_winding(voltage="10V", coil_terminals=face_id)
88+
assert bounds
89+
bounds_name = generate_unique_name("Winding")
90+
bounds = self.aedtapp.assign_winding(coil_terminals=face_id, name=bounds_name)
91+
assert bounds_name == bounds.name
92+
93+
def test_05a_assign_coil(self):
94+
face_id = self.aedtapp.modeler["Coil_Section1"].faces[0].id
95+
bound = self.aedtapp.assign_coil(input_object=face_id)
96+
assert bound
97+
polarity = "Positive"
98+
bound = self.aedtapp.assign_coil(input_object=face_id, polarity=polarity)
99+
assert not bound.props["Point out of terminal"]
100+
polarity = "Negative"
101+
bound = self.aedtapp.assign_coil(input_object=face_id, polarity=polarity)
102+
assert bound.props["Point out of terminal"]
103+
bound_name = generate_unique_name("Coil")
104+
bound = self.aedtapp.assign_coil(input_object=face_id, name=bound_name)
105+
assert bound_name == bound.name
77106

78107
def test_05_draw_region(self):
79108
assert self.aedtapp.modeler.create_air_region(*[300] * 6)

pyaedt/maxwell.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -709,16 +709,18 @@ def assign_winding(
709709
{
710710
"Type": winding_type,
711711
"IsSolid": is_solid,
712-
"Current": str(current_value) + "A",
713-
"Resistance": str(res) + "ohm",
714-
"Inductance": str(ind) + "H",
715-
"Voltage": str(voltage) + "V",
712+
"Current": self.modeler._arg_with_dim(current_value, "A"),
713+
"Resistance": self.modeler._arg_with_dim(res, "ohm"),
714+
"Inductance": self.modeler._arg_with_dim(ind, "H"),
715+
"Voltage": self.modeler._arg_with_dim(voltage, "V"),
716716
"ParallelBranchesNum": str(parallel_branches),
717717
}
718718
)
719719
bound = BoundaryObject(self, name, props, "Winding")
720720
if bound.create():
721721
self.boundaries.append(bound)
722+
if coil_terminals is None:
723+
coil_terminals = []
722724
if type(coil_terminals) is not list:
723725
coil_terminals = [coil_terminals]
724726
coil_names = []
@@ -727,7 +729,8 @@ def assign_winding(
727729
if c:
728730
coil_names.append(c.name)
729731

730-
self.add_winding_coils(bound.name, coil_names)
732+
if coil_names:
733+
self.add_winding_coils(bound.name, coil_names)
731734
return bound
732735
return False
733736

@@ -784,7 +787,7 @@ def assign_coil(self, input_object, conductor_number=1, polarity="Positive", nam
784787
785788
>>> oModule.AssignCoil
786789
"""
787-
if polarity == "Positive":
790+
if polarity.lower() == "positive":
788791
point = False
789792
else:
790793
point = True
@@ -802,7 +805,11 @@ def assign_coil(self, input_object, conductor_number=1, polarity="Positive", nam
802805
bound = BoundaryObject(self, name, props2, "CoilTerminal")
803806
else:
804807
props2 = OrderedDict(
805-
{"Objects": input_object, "Conductor number": str(conductor_number), "PolarityType": polarity}
808+
{
809+
"Objects": input_object,
810+
"Conductor number": str(conductor_number),
811+
"PolarityType": polarity.lower(),
812+
}
806813
)
807814
bound = BoundaryObject(self, name, props2, "Coil")
808815
else:

0 commit comments

Comments
 (0)