Skip to content

fix assign_winding and assign_coil + update tests #1147

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

Merged
merged 1 commit into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion _unittest/test_27_Maxwell2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pyaedt import Maxwell2d
from pyaedt.application.Design import DesignCache
from pyaedt.generic.constants import SOLUTIONS
from pyaedt.generic.general_methods import generate_unique_name

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

@pyaedt_unittest_check_desktop_error
def test_04_create_winding(self):

bounds = self.aedtapp.assign_winding(current_value=20e-3, coil_terminals=["Coil"])
assert bounds
o = self.aedtapp.modeler.create_rectangle([0, 0, 0], [3, 1], name="Rectangle2", matname="copper")
bounds = self.aedtapp.assign_winding(current_value=20e-3, coil_terminals=o.id)
assert bounds
bounds = self.aedtapp.assign_winding(current_value="20e-3A", coil_terminals=["Coil"])
assert bounds
bounds = self.aedtapp.assign_winding(res="1ohm", coil_terminals=["Coil"])
assert bounds
bounds = self.aedtapp.assign_winding(ind="1H", coil_terminals=["Coil"])
assert bounds
bounds = self.aedtapp.assign_winding(voltage="10V", coil_terminals=["Coil"])
assert bounds
bounds_name = generate_unique_name("Coil")
bounds = self.aedtapp.assign_winding(coil_terminals=["Coil"], name=bounds_name)
assert bounds_name == bounds.name

@pyaedt_unittest_check_desktop_error
def test_04a_assign_coil(self):
bound = self.aedtapp.assign_coil(input_object=["Coil"])
assert bound
polarity = "Positive"
bound = self.aedtapp.assign_coil(input_object=["Coil"], polarity=polarity)
assert bound.props["PolarityType"] == polarity.lower()
polarity = "Negative"
bound = self.aedtapp.assign_coil(input_object=["Coil"], polarity=polarity)
assert bound.props["PolarityType"] == polarity.lower()
bound_name = generate_unique_name("Coil")
bound = self.aedtapp.assign_coil(input_object=["Coil"], name=bound_name)
assert bound_name == bound.name

@pyaedt_unittest_check_desktop_error
def test_05_create_vector_potential(self):
Expand Down
31 changes: 30 additions & 1 deletion _unittest/test_28_Maxwell3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from _unittest.conftest import local_path
from pyaedt import Maxwell3d
from pyaedt.generic.constants import SOLUTIONS
from pyaedt.generic.general_methods import generate_unique_name

try:
import pytest
Expand Down Expand Up @@ -73,7 +74,35 @@ def test_04_coil_terminal(self):
self.aedtapp.solution_type = "EddyCurrent"

def test_05_winding(self):
assert self.aedtapp.assign_winding(self.aedtapp.modeler["Coil_Section1"].faces[0].id)
face_id = self.aedtapp.modeler["Coil_Section1"].faces[0].id
assert self.aedtapp.assign_winding(face_id)
bounds = self.aedtapp.assign_winding(current_value=20e-3, coil_terminals=face_id)
assert bounds
bounds = self.aedtapp.assign_winding(current_value="20e-3A", coil_terminals=face_id)
assert bounds
bounds = self.aedtapp.assign_winding(res="1ohm", coil_terminals=face_id)
assert bounds
bounds = self.aedtapp.assign_winding(ind="1H", coil_terminals=face_id)
assert bounds
bounds = self.aedtapp.assign_winding(voltage="10V", coil_terminals=face_id)
assert bounds
bounds_name = generate_unique_name("Winding")
bounds = self.aedtapp.assign_winding(coil_terminals=face_id, name=bounds_name)
assert bounds_name == bounds.name

def test_05a_assign_coil(self):
face_id = self.aedtapp.modeler["Coil_Section1"].faces[0].id
bound = self.aedtapp.assign_coil(input_object=face_id)
assert bound
polarity = "Positive"
bound = self.aedtapp.assign_coil(input_object=face_id, polarity=polarity)
assert not bound.props["Point out of terminal"]
polarity = "Negative"
bound = self.aedtapp.assign_coil(input_object=face_id, polarity=polarity)
assert bound.props["Point out of terminal"]
bound_name = generate_unique_name("Coil")
bound = self.aedtapp.assign_coil(input_object=face_id, name=bound_name)
assert bound_name == bound.name

def test_05_draw_region(self):
assert self.aedtapp.modeler.create_air_region(*[300] * 6)
Expand Down
21 changes: 14 additions & 7 deletions pyaedt/maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,16 +709,18 @@ def assign_winding(
{
"Type": winding_type,
"IsSolid": is_solid,
"Current": str(current_value) + "A",
"Resistance": str(res) + "ohm",
"Inductance": str(ind) + "H",
"Voltage": str(voltage) + "V",
"Current": self.modeler._arg_with_dim(current_value, "A"),
"Resistance": self.modeler._arg_with_dim(res, "ohm"),
"Inductance": self.modeler._arg_with_dim(ind, "H"),
"Voltage": self.modeler._arg_with_dim(voltage, "V"),
"ParallelBranchesNum": str(parallel_branches),
}
)
bound = BoundaryObject(self, name, props, "Winding")
if bound.create():
self.boundaries.append(bound)
if coil_terminals is None:
coil_terminals = []
if type(coil_terminals) is not list:
coil_terminals = [coil_terminals]
coil_names = []
Expand All @@ -727,7 +729,8 @@ def assign_winding(
if c:
coil_names.append(c.name)

self.add_winding_coils(bound.name, coil_names)
if coil_names:
self.add_winding_coils(bound.name, coil_names)
return bound
return False

Expand Down Expand Up @@ -784,7 +787,7 @@ def assign_coil(self, input_object, conductor_number=1, polarity="Positive", nam

>>> oModule.AssignCoil
"""
if polarity == "Positive":
if polarity.lower() == "positive":
point = False
else:
point = True
Expand All @@ -802,7 +805,11 @@ def assign_coil(self, input_object, conductor_number=1, polarity="Positive", nam
bound = BoundaryObject(self, name, props2, "CoilTerminal")
else:
props2 = OrderedDict(
{"Objects": input_object, "Conductor number": str(conductor_number), "PolarityType": polarity}
{
"Objects": input_object,
"Conductor number": str(conductor_number),
"PolarityType": polarity.lower(),
}
)
bound = BoundaryObject(self, name, props2, "Coil")
else:
Expand Down