From 1bf6dcc3036419922bf50c7eedccbe301158a276 Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Wed, 29 Jan 2025 11:34:58 +0100 Subject: [PATCH] FIX: Tests and constat ref --- src/ansys/aedt/core/maxwell.py | 6 +- tests/system/general/test_27_Maxwell2D.py | 41 ++++++--- tests/system/general/test_28_Maxwell3D.py | 100 ++++++++++++---------- 3 files changed, 86 insertions(+), 61 deletions(-) diff --git a/src/ansys/aedt/core/maxwell.py b/src/ansys/aedt/core/maxwell.py index c122b59cd3f..a3ff8532aab 100644 --- a/src/ansys/aedt/core/maxwell.py +++ b/src/ansys/aedt/core/maxwell.py @@ -321,7 +321,7 @@ def assign_matrix( assignment = self.modeler.convert_to_selections(assignment, True) if self.solution_type in ( - SOLUTIONS.Maxwell3d.Electrostatic, + SOLUTIONS.Maxwell3d.ElectroStatic, SOLUTIONS.Maxwell3d.ACConduction, SOLUTIONS.Maxwell3d.DCConduction, ): @@ -416,7 +416,7 @@ def assign_matrix( if group_sources: if self.solution_type in ( - SOLUTIONS.Maxwell3d.Electrostatic, + SOLUTIONS.Maxwell3d.ElectroStatic, SOLUTIONS.Maxwell3d.ACConduction, SOLUTIONS.Maxwell3d.DCConduction, ): @@ -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( "Assign floating excitation is only valid for electrostatic or electric transient solvers." ) diff --git a/tests/system/general/test_27_Maxwell2D.py b/tests/system/general/test_27_Maxwell2D.py index fdd9c77259a..6ef09667cf0 100644 --- a/tests/system/general/test_27_Maxwell2D.py +++ b/tests/system/general/test_27_Maxwell2D.py @@ -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 @@ -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") @@ -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"] ) @@ -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") @@ -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") @@ -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() diff --git a/tests/system/general/test_28_Maxwell3D.py b/tests/system/general/test_28_Maxwell3D.py index 3dbe5bb8e98..4ede0da7192 100644 --- a/tests/system/general/test_28_Maxwell3D.py +++ b/tests/system/general/test_28_Maxwell3D.py @@ -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 @@ -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") @@ -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") @@ -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 @@ -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")