Skip to content

Commit

Permalink
FIX: Tests and constat ref
Browse files Browse the repository at this point in the history
  • Loading branch information
SMoraisAnsys committed Jan 29, 2025
1 parent 6f49bae commit 1bf6dcc
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 61 deletions.
6 changes: 3 additions & 3 deletions src/ansys/aedt/core/maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def assign_matrix(

assignment = self.modeler.convert_to_selections(assignment, True)
if self.solution_type in (

Check warning on line 323 in src/ansys/aedt/core/maxwell.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/maxwell.py#L323

Added line #L323 was not covered by tests
SOLUTIONS.Maxwell3d.Electrostatic,
SOLUTIONS.Maxwell3d.ElectroStatic,
SOLUTIONS.Maxwell3d.ACConduction,
SOLUTIONS.Maxwell3d.DCConduction,
):
Expand Down Expand Up @@ -416,7 +416,7 @@ def assign_matrix(

if group_sources:
if self.solution_type in (

Check warning on line 418 in src/ansys/aedt/core/maxwell.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/maxwell.py#L418

Added line #L418 was not covered by tests
SOLUTIONS.Maxwell3d.Electrostatic,
SOLUTIONS.Maxwell3d.ElectroStatic,
SOLUTIONS.Maxwell3d.ACConduction,
SOLUTIONS.Maxwell3d.DCConduction,
):
Expand Down Expand Up @@ -1079,7 +1079,7 @@ def assign_floating(self, assignment, charge_value=0, name=None):
>>> floating1 = m3d.assign_floating(assignment=[box.faces[0], box.faces[1]], charge_value=3)
>>> m3d.release_desktop(True, True)
"""
if self.solution_type not in (SOLUTIONS.Maxwell3d.Electrostatic, SOLUTIONS.Maxwell3d.ElectricTransient):
if self.solution_type not in (SOLUTIONS.Maxwell3d.ElectroStatic, SOLUTIONS.Maxwell3d.ElectricTransient):
raise AEDTRuntimeError(

Check warning on line 1083 in src/ansys/aedt/core/maxwell.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/maxwell.py#L1082-L1083

Added lines #L1082 - L1083 were not covered by tests
"Assign floating excitation is only valid for electrostatic or electric transient solvers."
)
Expand Down
41 changes: 27 additions & 14 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, "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 Down Expand Up @@ -201,14 +203,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, "Invalid coordinate system."):
assert not aedtapp.apply_skew(skew_type="Invalid")
with pytest.raises(ValueError, "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, "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 +241,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, "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, "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 Down Expand Up @@ -312,7 +316,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, "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 @@ -595,9 +600,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,
"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,
"External circuit excitation for windings is available only for Eddy Current or Transient solutions.",
):
m2d_app.create_external_circuit()
100 changes: 56 additions & 44 deletions tests/system/general/test_28_Maxwell3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from ansys.aedt.core import Maxwell3d
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 is_linux
from ansys.aedt.core.modeler.geometry_operators import GeometryOperators
Expand Down Expand Up @@ -156,7 +157,8 @@ def test_create_air_region(self, m3d_app):
def test_eddy_effects_on(self, m3d_app):
m3d_app.solution_type = SOLUTIONS.Maxwell3d.EddyCurrent
plate_vacuum = m3d_app.modeler.create_box([-3, -3, 0], [1.5, 1.5, 0.4], name="Plate_vaccum")
assert not m3d_app.eddy_effects_on(plate_vacuum, enable_eddy_effects=True)
with pytest.raises(AEDTRuntimeError, "No conductors defined in active design."):
m3d_app.eddy_effects_on(plate_vacuum, enable_eddy_effects=True)
plate = m3d_app.modeler.create_box([-1, -1, 0], [1.5, 1.5, 0.4], name="Plate", material="copper")
assert m3d_app.eddy_effects_on(plate, enable_eddy_effects=True)
assert m3d_app.oboundary.GetEddyEffect("Plate")
Expand Down Expand Up @@ -689,8 +691,10 @@ def test_assign_current_density(self, m3d_app):
assert bound.props[bound.name]["CurrentDensityZ"] == "0"
assert bound.props[bound.name]["CoordinateSystem Name"] == "Global"

assert not m3d_app.assign_current_density(box.name, "current_density_3", coordinate_system_type="test")
assert not m3d_app.assign_current_density(box.name, "current_density_4", phase="5ang")
with pytest.raises(AEDTRuntimeError, "Invalid coordinate system."):
m3d_app.assign_current_density(box.name, "current_density_3", coordinate_system_type="test")
with pytest.raises(AEDTRuntimeError, "Invalid phase unit."):
m3d_app.assign_current_density(box.name, "current_density_4", phase="5ang")

def test_assign_current_density_terminal(self, m3d_app):
box = m3d_app.modeler.create_box([50, 0, 50], [294, 294, 19], name="box")
Expand Down Expand Up @@ -757,46 +761,51 @@ def test_assign_independent_dependent(self, m3d_app):
)
assert independent
assert dependent
assert not m3d_app.assign_master_slave(
master_entity=box.faces[1],
slave_entity=box.faces[5],
u_vector_origin_coordinates_master=[0, "0mm", "0mm"],
u_vector_pos_coordinates_master=["10mm", "0mm", "0mm"],
u_vector_origin_coordinates_slave=["10mm", "0mm", "0mm"],
u_vector_pos_coordinates_slave=["10mm", "10mm", "0mm"],
)
assert not m3d_app.assign_master_slave(
master_entity=box.faces[1],
slave_entity=box.faces[5],
u_vector_origin_coordinates_master=["0mm", "0mm", "0mm"],
u_vector_pos_coordinates_master=[10, "0mm", "0mm"],
u_vector_origin_coordinates_slave=["10mm", "0mm", "0mm"],
u_vector_pos_coordinates_slave=["10mm", "10mm", "0mm"],
)
assert not m3d_app.assign_master_slave(
master_entity=box.faces[1],
slave_entity=box.faces[5],
u_vector_origin_coordinates_master=["0mm", "0mm", "0mm"],
u_vector_pos_coordinates_master=["10mm", "0mm", "0mm"],
u_vector_origin_coordinates_slave=[10, "0mm", "0mm"],
u_vector_pos_coordinates_slave=["10mm", "10mm", "0mm"],
)
assert not m3d_app.assign_master_slave(
master_entity=box.faces[1],
slave_entity=box.faces[5],
u_vector_origin_coordinates_master=["0mm", "0mm", "0mm"],
u_vector_pos_coordinates_master=["10mm", "0mm", "0mm"],
u_vector_origin_coordinates_slave=["10mm", "0mm", "0mm"],
u_vector_pos_coordinates_slave=[10, "10mm", "0mm"],
)
assert not m3d_app.assign_master_slave(
master_entity=box.faces[1],
slave_entity=box.faces[5],
u_vector_origin_coordinates_master="0mm",
u_vector_pos_coordinates_master=["10mm", "0mm", "0mm"],
u_vector_origin_coordinates_slave=["10mm", "0mm", "0mm"],
u_vector_pos_coordinates_slave=["10mm", "10mm", "0mm"],
)
with pytest.raises(ValueError, "Elements of coordinates system must be strings in the form of ``value+unit``."):
m3d_app.assign_master_slave(
master_entity=box.faces[1],
slave_entity=box.faces[5],
u_vector_origin_coordinates_master=[0, "0mm", "0mm"],
u_vector_pos_coordinates_master=["10mm", "0mm", "0mm"],
u_vector_origin_coordinates_slave=["10mm", "0mm", "0mm"],
u_vector_pos_coordinates_slave=["10mm", "10mm", "0mm"],
)
with pytest.raises(ValueError, "Elements of coordinates system must be strings in the form of ``value+unit``."):
m3d_app.assign_master_slave(
master_entity=box.faces[1],
slave_entity=box.faces[5],
u_vector_origin_coordinates_master=["0mm", "0mm", "0mm"],
u_vector_pos_coordinates_master=[10, "0mm", "0mm"],
u_vector_origin_coordinates_slave=["10mm", "0mm", "0mm"],
u_vector_pos_coordinates_slave=["10mm", "10mm", "0mm"],
)
with pytest.raises(ValueError, "Elements of coordinates system must be strings in the form of ``value+unit``."):
m3d_app.assign_master_slave(
master_entity=box.faces[1],
slave_entity=box.faces[5],
u_vector_origin_coordinates_master=["0mm", "0mm", "0mm"],
u_vector_pos_coordinates_master=["10mm", "0mm", "0mm"],
u_vector_origin_coordinates_slave=[10, "0mm", "0mm"],
u_vector_pos_coordinates_slave=["10mm", "10mm", "0mm"],
)
with pytest.raises(ValueError, "Elements of coordinates system must be strings in the form of ``value+unit``."):
m3d_app.assign_master_slave(
master_entity=box.faces[1],
slave_entity=box.faces[5],
u_vector_origin_coordinates_master=["0mm", "0mm", "0mm"],
u_vector_pos_coordinates_master=["10mm", "0mm", "0mm"],
u_vector_origin_coordinates_slave=["10mm", "0mm", "0mm"],
u_vector_pos_coordinates_slave=[10, "10mm", "0mm"],
)
with pytest.raises(ValueError, "Please provide a list of coordinates for U vectors."):
m3d_app.assign_master_slave(
master_entity=box.faces[1],
slave_entity=box.faces[5],
u_vector_origin_coordinates_master="0mm",
u_vector_pos_coordinates_master=["10mm", "0mm", "0mm"],
u_vector_origin_coordinates_slave=["10mm", "0mm", "0mm"],
u_vector_pos_coordinates_slave=["10mm", "10mm", "0mm"],
)

def test_add_mesh_link(self, m3d_app, local_scratch):
m3d_app.solution_type = SOLUTIONS.Maxwell3d.Transient
Expand Down Expand Up @@ -911,7 +920,10 @@ def test_import_dxf(self, m3d_app):

def test_assign_flux_tangential(self, m3d_app):
box = m3d_app.modeler.create_box([50, 0, 50], [294, 294, 19], name="Box")
assert not m3d_app.assign_flux_tangential(box.faces[0])
with pytest.raises(
AEDTRuntimeError, "Flux tangential boundary can only be assigned to a transient APhi solution type."
):
m3d_app.assign_flux_tangential(box.faces[0])
m3d_app.solution_type = "TransientAPhiFormulation"
assert m3d_app.assign_flux_tangential(box.faces[0], "FluxExample")
assert m3d_app.assign_flux_tangential(box.faces[0].id, "FluxExample")
Expand Down

0 comments on commit 1bf6dcc

Please sign in to comment.