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

REFACTOR: General improvements #5695

Merged
merged 14 commits into from
Jan 31, 2025
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/generic/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ class Circuit(object):
class Mechanical(object):
"""Provides Mechanical solution types."""

(Thermal, Structural, Modal) = ("Thermal", "Structural", "Modal")
(Thermal, Structural, Modal, SteadyStateThermal) = ("Thermal", "Structural", "Modal", "Steady-State Thermal")


class SETUPS(object):
Expand Down
845 changes: 418 additions & 427 deletions src/ansys/aedt/core/maxwell.py

Large diffs are not rendered by default.

51 changes: 29 additions & 22 deletions src/ansys/aedt/core/mechanical.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from __future__ import absolute_import # noreorder

from ansys.aedt.core.application.analysis_3d import FieldAnalysis3D
from ansys.aedt.core.generic.constants import SOLUTIONS
from ansys.aedt.core.generic.errors import AEDTRuntimeError
from ansys.aedt.core.generic.general_methods import generate_unique_name
from ansys.aedt.core.generic.general_methods import pyaedt_function_handler
from ansys.aedt.core.modules.boundary.common import BoundaryObject
Expand Down Expand Up @@ -215,15 +217,16 @@
----------
>>> oModule.AssignEMLoss
"""
if self.solution_type not in (SOLUTIONS.Mechanical.Thermal, SOLUTIONS.Mechanical.SteadyStateThermal):
raise AEDTRuntimeError("This method works only in a Mechanical Thermal analysis.")

if surface_objects is None:
surface_objects = []
if parameters is None:
parameters = []
if assignment is None:
assignment = []

assert "Thermal" in self.solution_type, "This method works only in a Mechanical Thermal analysis."

self.logger.info("Mapping HFSS EM Loss")
oName = self.project_name
if oName == source_project_name or source_project_name is None:
Expand Down Expand Up @@ -283,7 +286,7 @@
)
def assign_thermal_map(
self,
object_list,
assignment,
design="IcepakDesign1",
setup="Setup1",
sweep="SteadyState",
Expand All @@ -297,7 +300,7 @@

Parameters
----------
object_list : list
assignment : list

design : str, optional
Name of the design with the source mapping. The default is ``"IcepakDesign1"``.
Expand All @@ -320,11 +323,12 @@
----------
>>> oModule.AssignThermalCondition
"""
if self.solution_type != SOLUTIONS.Mechanical.Structural:
raise AEDTRuntimeError("This method works only in a Mechanical Structural analysis.")

if parameters is None:
parameters = []

assert self.solution_type == "Structural", "This method works only in a Mechanical Structural analysis."

self.logger.info("Mapping HFSS EM Loss")
oName = self.project_name
if oName == source_project_name or source_project_name is None:
Expand All @@ -334,11 +338,11 @@
#
# Generate a list of model objects from the lists made previously and use to map the HFSS losses into Icepak.
#
object_list = self.modeler.convert_to_selections(object_list, True)
if not object_list:
allObjects = self.modeler.object_names
assignment = self.modeler.convert_to_selections(assignment, True)
SMoraisAnsys marked this conversation as resolved.
Show resolved Hide resolved
if not assignment:
all_objects = self.modeler.object_names

Check warning on line 343 in src/ansys/aedt/core/mechanical.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/mechanical.py#L343

Added line #L343 was not covered by tests
else:
allObjects = object_list[:]
all_objects = assignment[:]
argparam = {}
for el in self.available_variations.nominal_w_values_dict:
argparam[el] = self.available_variations.nominal_w_values_dict[el]
Expand All @@ -347,7 +351,7 @@
argparam[el] = el

props = {
"Objects": allObjects,
"Objects": all_objects,
"Uniform": False,
"Project": projname,
"Product": "ElectronicsDesktop",
Expand Down Expand Up @@ -402,7 +406,8 @@
----------
>>> oModule.AssignConvection
"""
assert "Thermal" in self.solution_type, "This method works only in a Mechanical Thermal analysis."
if self.solution_type not in (SOLUTIONS.Mechanical.Thermal, SOLUTIONS.Mechanical.SteadyStateThermal):
raise AEDTRuntimeError("This method works only in a Mechanical Thermal analysis.")

props = {}
assignment = self.modeler.convert_to_selections(assignment, True)
Expand Down Expand Up @@ -450,7 +455,8 @@
----------
>>> oModule.AssignTemperature
"""
assert "Thermal" in self.solution_type, "This method works only in a Mechanical Thermal analysis."
if self.solution_type not in (SOLUTIONS.Mechanical.Thermal, SOLUTIONS.Mechanical.SteadyStateThermal):
raise AEDTRuntimeError("This method works only in a Mechanical Thermal analysis.")

props = {}
assignment = self.modeler.convert_to_selections(assignment, True)
Expand Down Expand Up @@ -495,12 +501,11 @@
----------
>>> oModule.AssignFrictionlessSupport
"""
if not (self.solution_type == "Structural" or "Modal" in self.solution_type):
self.logger.error("This method works only in Mechanical Structural analysis.")
return False
if self.solution_type not in (SOLUTIONS.Mechanical.Structural, SOLUTIONS.Mechanical.Modal):
raise AEDTRuntimeError("This method works only in a Mechanical Structural analysis.")

props = {}
assignment = self.modeler.convert_to_selections(assignment, True)

if type(assignment) is list:
if type(assignment[0]) is str:
props["Objects"] = assignment
Expand Down Expand Up @@ -539,9 +544,9 @@
----------
>>> oModule.AssignFixedSupport
"""
if not (self.solution_type == "Structural" or "Modal" in self.solution_type):
self.logger.error("This method works only in a Mechanical Structural analysis.")
return False
if self.solution_type not in (SOLUTIONS.Mechanical.Structural, SOLUTIONS.Mechanical.Modal):
raise AEDTRuntimeError("This method works only in a Mechanical Structural analysis.")

props = {}
assignment = self.modeler.convert_to_selections(assignment, True)

Expand Down Expand Up @@ -600,7 +605,8 @@
----------
>>> oModule.AssignHeatFlux
"""
assert "Thermal" in self.solution_type, "This method works only in a Mechanical Thermal analysis."
if self.solution_type not in (SOLUTIONS.Mechanical.Thermal, SOLUTIONS.Mechanical.SteadyStateThermal):
raise AEDTRuntimeError("This method works only in a Mechanical Thermal analysis.")

props = {}
assignment = self.modeler.convert_to_selections(assignment, True)
Expand Down Expand Up @@ -647,7 +653,8 @@
----------
>>> oModule.AssignHeatGeneration
"""
assert "Thermal" in self.solution_type, "This method works only in a Mechanical Thermal analysis."
if self.solution_type not in (SOLUTIONS.Mechanical.Thermal, SOLUTIONS.Mechanical.SteadyStateThermal):
raise AEDTRuntimeError("This method works only in a Mechanical Thermal analysis.")

props = {}
assignment = self.modeler.convert_to_selections(assignment, True)
Expand Down
71 changes: 46 additions & 25 deletions tests/system/general/test_27_Maxwell2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import ansys.aedt.core
from ansys.aedt.core.generic.constants import SOLUTIONS
from ansys.aedt.core.generic.errors import AEDTRuntimeError
import pytest

from tests import TESTS_GENERAL_PATH
Expand Down Expand Up @@ -170,7 +171,8 @@ def test_assign_current_source(self, aedtapp):
position=[0, 0, 0], radius=5, num_sides="8", is_covered=True, name="Coil", material="Copper"
)
assert aedtapp.assign_current([coil])
assert not aedtapp.assign_current([coil.faces[0].id])
with pytest.raises(ValueError, match="Input must be a 2D object."):
aedtapp.assign_current([coil.faces[0].id])

def test_assign_master_slave(self, aedtapp):
aedtapp.modeler.create_rectangle([1, 1, 1], [3, 1], name="Rectangle1", material="copper")
Expand All @@ -187,10 +189,11 @@ def test_assign_master_slave(self, aedtapp):
)
assert mas.name == "my_bound"
assert slave.name == "my_bound_dep"
assert not aedtapp.assign_master_slave(
aedtapp.modeler["Rectangle1"].edges[0].id,
aedtapp.modeler["Rectangle1"].edges[1].id,
)
with pytest.raises(AEDTRuntimeError, match="Slave boundary could not be created."):
aedtapp.assign_master_slave(
aedtapp.modeler["Rectangle1"].edges[0].id,
aedtapp.modeler["Rectangle1"].edges[1].id,
)

def test_check_design_preview_image(self, local_scratch, aedtapp):
jpg_file = os.path.join(local_scratch.path, "file.jpg")
Expand All @@ -201,14 +204,14 @@ def test_model_depth(self, aedtapp):

def test_apply_skew(self, aedtapp):
assert aedtapp.apply_skew()
assert not aedtapp.apply_skew(skew_type="Invalid")
assert not aedtapp.apply_skew(skew_part="Invalid")
assert not aedtapp.apply_skew(
skew_type="Continuous", skew_part="Stator", skew_angle="0.5", skew_angle_unit="Invalid"
)
assert not aedtapp.apply_skew(
skew_type="User Defined", number_of_slices="4", custom_slices_skew_angles=["1", "2", "3"]
)
with pytest.raises(ValueError, match="Invalid skew type."):
assert not aedtapp.apply_skew(skew_type="Invalid")
with pytest.raises(ValueError, match="Invalid skew angle unit."):
aedtapp.apply_skew(skew_type="Continuous", skew_part="Stator", skew_angle="0.5", skew_angle_unit="Invalid")
with pytest.raises(ValueError, match="Please provide skew angles for each slice."):
aedtapp.apply_skew(
skew_type="User Defined", number_of_slices="4", custom_slices_skew_angles=["1", "2", "3"]
)
assert aedtapp.apply_skew(
skew_type="User Defined", number_of_slices="4", custom_slices_skew_angles=["1", "2", "3", "4"]
)
Expand Down Expand Up @@ -239,9 +242,11 @@ def test_assign_end_connection(self, aedtapp):
assert bound.props["ResistanceValue"] == "0ohm"
bound.props["InductanceValue"] = "5H"
assert bound.props["InductanceValue"] == "5H"
assert not aedtapp.assign_end_connection([rect])
with pytest.raises(AEDTRuntimeError, match="At least 2 objects are needed."):
aedtapp.assign_end_connection([rect])
aedtapp.solution_type = SOLUTIONS.Maxwell2d.MagnetostaticXY
assert not aedtapp.assign_end_connection([rect, rect2])
with pytest.raises(AEDTRuntimeError, match="Excitation applicable only to Eddy Current or Transient Solver."):
aedtapp.assign_end_connection([rect, rect2])

def test_setup_y_connection(self, aedtapp):
aedtapp.set_active_design("Y_Connections")
Expand All @@ -265,7 +270,8 @@ def test_assign_symmetry(self, aedtapp):
assert aedtapp.assign_symmetry([region[0].edges[0], band[0].edges[0]])
assert aedtapp.assign_symmetry([region[0].edges[0], band[0].edges[0]], "Symmetry_Test_IsEven", False)
assert aedtapp.assign_symmetry([9556, 88656])
assert not aedtapp.assign_symmetry([])
with pytest.raises(ValueError, match="At least one edge must be provided."):
aedtapp.assign_symmetry([])
for bound in aedtapp.boundaries:
if bound.name == "Symmetry_Test_IsOdd":
assert bound.type == "Symmetry"
Expand Down Expand Up @@ -312,7 +318,8 @@ def test_assign_current_density(self, aedtapp):
assert bound_group.props[bound_group.props["items"][0]]["Objects"] == ["Coil", "Coil_1"]
assert bound_group.props[bound_group.props["items"][0]]["Value"] == "0"
assert bound_group.props[bound_group.props["items"][0]]["CoordinateSystem"] == ""
assert not aedtapp.assign_current_density("Circle_inner", "CurrentDensity_1")
with pytest.raises(AEDTRuntimeError, match="Couldn't assign current density to desired list of objects."):
aedtapp.assign_current_density("Circle_inner", "CurrentDensity_1")

def test_set_variable(self, aedtapp):
aedtapp.variable_manager.set_variable("var_test", expression="123")
Expand Down Expand Up @@ -444,8 +451,11 @@ def test_assign_floating(self, m2d_app):
assert floating.props["Objects"][0] == rect.name
assert floating.props["Value"] == "3"
m2d_app.solution_type = SOLUTIONS.Maxwell2d.MagnetostaticXY
floating = m2d_app.assign_floating(assignment=rect, charge_value=3, name="floating_test1")
assert not floating
with pytest.raises(
AEDTRuntimeError,
match="Assign floating excitation is only valid for electrostatic or electric transient solvers.",
):
m2d_app.assign_floating(assignment=rect, charge_value=3, name="floating_test1")

def test_matrix(self, m2d_app):
m2d_app.solution_type = SOLUTIONS.Maxwell2d.MagnetostaticXY
Expand All @@ -468,10 +478,13 @@ def test_matrix(self, m2d_app):
assignment=["Current1", "Current2"], matrix_name="Test2", turns=[2, 1], return_path=["Current3", "Current4"]
)
assert matrix.props["MatrixEntry"]["MatrixEntry"][1]["ReturnPath"] == "Current4"
matrix = m2d_app.assign_matrix(
assignment=["Current1", "Current2"], matrix_name="Test3", turns=[2, 1], return_path=["Current1", "Current1"]
)
assert not matrix
with pytest.raises(AEDTRuntimeError, match="Return path specified must not be included in sources"):
m2d_app.assign_matrix(
assignment=["Current1", "Current2"],
matrix_name="Test3",
turns=[2, 1],
return_path=["Current1", "Current1"],
)
group_sources = {"Group1_Test": ["Current3", "Current2"]}
matrix = m2d_app.assign_matrix(
assignment=["Current3", "Current2"],
Expand Down Expand Up @@ -595,9 +608,17 @@ def test_create_external_circuit(self, local_scratch, m2d_app):
assert m2d_app.create_external_circuit()
assert m2d_app.create_external_circuit(circuit_design="test_cir")
m2d_app.solution_type = SOLUTIONS.Maxwell2d.MagnetostaticXY
assert not m2d_app.create_external_circuit()
with pytest.raises(
AEDTRuntimeError,
match="External circuit excitation for windings is available only for Eddy Current or Transient solutions.",
):
m2d_app.create_external_circuit()
m2d_app.solution_type = SOLUTIONS.Maxwell2d.EddyCurrentXY
for w in m2d_app.excitations_by_type["Winding"]:
w.delete()
m2d_app.save_project()
assert not m2d_app.create_external_circuit()
with pytest.raises(
AEDTRuntimeError,
match="No windings in the Maxwell design.",
):
m2d_app.create_external_circuit()
Loading