|
31 | 31 | from ansys.aedt.core.internal.errors import AEDTRuntimeError
|
32 | 32 | import pytest
|
33 | 33 |
|
34 |
| -from tests.system.general.conftest import config |
35 | 34 |
|
36 |
| -test_project_name = "coax_Mech" |
37 |
| - |
38 |
| - |
39 |
| -@pytest.fixture(scope="class") |
| 35 | +@pytest.fixture() |
40 | 36 | def aedtapp(add_app):
|
41 | 37 | app = add_app(application=Mechanical, solution_type="Thermal")
|
42 |
| - return app |
| 38 | + yield app |
| 39 | + app.close_project(app.project_name) |
| 40 | + |
| 41 | + |
| 42 | +@pytest.fixture() |
| 43 | +def hfss(add_app): |
| 44 | + app = add_app(application=Hfss) |
| 45 | + yield app |
| 46 | + app.close_project(app.project_name) |
| 47 | + |
| 48 | + |
| 49 | +@pytest.fixture() |
| 50 | +def ipk(add_app): |
| 51 | + app = add_app(application=Icepak, solution_type="SteadyState") |
| 52 | + yield app |
| 53 | + app.close_project(app.project_name) |
43 | 54 |
|
44 | 55 |
|
45 | 56 | class TestClass:
|
46 |
| - @pytest.fixture(autouse=True) |
47 |
| - def init(self, aedtapp, local_scratch): |
48 |
| - self.aedtapp = aedtapp |
49 |
| - self.local_scratch = local_scratch |
50 |
| - |
51 |
| - def test_01_save(self): |
52 |
| - test_project = os.path.join(self.local_scratch.path, test_project_name + ".aedt") |
53 |
| - self.aedtapp.save_project(test_project) |
| 57 | + def test_save_project(self, aedtapp, local_scratch): |
| 58 | + test_project = os.path.join(local_scratch.path, "coax_Mech" + ".aedt") |
| 59 | + aedtapp.save_project(test_project) |
54 | 60 | assert os.path.exists(test_project)
|
55 | 61 |
|
56 |
| - def test_02_create_primitive(self): |
57 |
| - udp = self.aedtapp.modeler.Position(0, 0, 0) |
| 62 | + def test_create_primitive(self, aedtapp): |
| 63 | + udp = aedtapp.modeler.Position(0, 0, 0) |
58 | 64 | coax_dimension = 30
|
59 |
| - o = self.aedtapp.modeler.create_cylinder( |
60 |
| - self.aedtapp.PLANE.XY, udp, 3, coax_dimension, 0, "MyCylinder", "brass" |
61 |
| - ) |
| 65 | + o = aedtapp.modeler.create_cylinder(aedtapp.PLANE.XY, udp, 3, coax_dimension, 0, "MyCylinder", "brass") |
62 | 66 | assert isinstance(o.id, int)
|
63 | 67 |
|
64 |
| - def test_03_assign_convection(self): |
65 |
| - face = self.aedtapp.modeler["MyCylinder"].faces[0].id |
66 |
| - assert self.aedtapp.assign_uniform_convection(face, 3) |
| 68 | + def test_assign_convection(self, aedtapp): |
| 69 | + aedtapp.modeler.create_cylinder(orientation="Z", origin=[0, 0, 0], radius=0.8, height=20, name="MyCylinder") |
| 70 | + face = aedtapp.modeler["MyCylinder"].faces[0].id |
| 71 | + assert aedtapp.assign_uniform_convection(face, 3) |
67 | 72 |
|
68 |
| - def test_04_assign_temperature(self): |
69 |
| - face = self.aedtapp.modeler["MyCylinder"].faces[1].id |
70 |
| - bound = self.aedtapp.assign_uniform_temperature(face, "35deg") |
| 73 | + def test_assign_temperature(self, aedtapp): |
| 74 | + aedtapp.modeler.create_cylinder(orientation="Z", origin=[0, 0, 0], radius=0.8, height=20, name="MyCylinder") |
| 75 | + face = aedtapp.modeler["MyCylinder"].faces[1].id |
| 76 | + bound = aedtapp.assign_uniform_temperature(face, "35deg") |
71 | 77 | assert bound.props["Temperature"] == "35deg"
|
72 | 78 |
|
73 |
| - def test_05_assign_load(self, add_app): |
74 |
| - hfss = add_app(application=Hfss) |
75 |
| - udp = self.aedtapp.modeler.Position(0, 0, 0) |
| 79 | + def test_assign_load(self, aedtapp, hfss): |
| 80 | + udp = aedtapp.modeler.Position(0, 0, 0) |
76 | 81 | coax_dimension = 30
|
77 |
| - hfss.modeler.create_cylinder(self.aedtapp.PLANE.XY, udp, 3, coax_dimension, 0, "MyCylinder", "brass") |
| 82 | + hfss.modeler.create_cylinder(aedtapp.PLANE.XY, udp, 3, coax_dimension, 0, "MyCylinder", "brass") |
78 | 83 | setup = hfss.create_setup()
|
79 | 84 | freq = "1GHz"
|
80 | 85 | setup.props["Frequency"] = freq
|
81 |
| - assert self.aedtapp.assign_em_losses(hfss.design_name, hfss.setups[0].name, "LastAdaptive", freq) |
| 86 | + aedtapp.modeler.create_cylinder(orientation="Z", origin=[0, 0, 0], radius=0.8, height=20, name="MyCylinder") |
| 87 | + assert aedtapp.assign_em_losses(hfss.design_name, hfss.setups[0].name, "LastAdaptive", freq) |
82 | 88 |
|
83 |
| - def test_06a_create_setup(self): |
84 |
| - assert not self.aedtapp.assign_2way_coupling() |
85 |
| - mysetup = self.aedtapp.create_setup() |
| 89 | + def test_create_setup(self, aedtapp): |
| 90 | + assert not aedtapp.assign_2way_coupling() |
| 91 | + mysetup = aedtapp.create_setup() |
86 | 92 | mysetup.props["Solver"] = "Direct"
|
87 | 93 | assert mysetup.update()
|
| 94 | + assert aedtapp.assign_2way_coupling() |
88 | 95 |
|
89 |
| - def test_06b_two_way(self): |
90 |
| - assert self.aedtapp.assign_2way_coupling() |
91 |
| - |
92 |
| - @pytest.mark.skipif(config["desktopVersion"] < "2021.2", reason="Skipped on versions lower than 2021.2") |
93 |
| - def test_07_assign_thermal_loss(self, add_app): |
94 |
| - ipk = add_app(application=Icepak, solution_type=self.aedtapp.SOLUTIONS.Icepak.SteadyState) |
95 |
| - udp = self.aedtapp.modeler.Position(0, 0, 0) |
| 96 | + def test_assign_thermal_loss(self, aedtapp, ipk): |
| 97 | + udp = aedtapp.modeler.Position(0, 0, 0) |
96 | 98 | coax_dimension = 30
|
97 | 99 | ipk.modeler.create_cylinder(ipk.PLANE.XY, udp, 3, coax_dimension, 0, "MyCylinder", "brass")
|
98 | 100 | ipk.create_setup()
|
99 |
| - self.aedtapp.oproject.InsertDesign("Mechanical", "MechanicalDesign1", "Structural", "") |
100 |
| - self.aedtapp.set_active_design("MechanicalDesign1") |
101 |
| - self.aedtapp.create_setup() |
102 |
| - self.aedtapp.modeler.create_cylinder(self.aedtapp.PLANE.XY, udp, 3, coax_dimension, 0, "MyCylinder", "brass") |
103 |
| - assert self.aedtapp.assign_thermal_map("MyCylinder", ipk.design_name) |
104 |
| - |
105 |
| - def test_07_assign_mechanical_boundaries(self): |
106 |
| - udp = self.aedtapp.modeler.Position(0, 0, 0) |
| 101 | + aedtapp.oproject.InsertDesign("Mechanical", "MechanicalDesign1", "Structural", "") |
| 102 | + aedtapp.set_active_design("MechanicalDesign1") |
| 103 | + aedtapp.create_setup() |
| 104 | + aedtapp.modeler.create_cylinder(aedtapp.PLANE.XY, udp, 3, coax_dimension, 0, "MyCylinder", "brass") |
| 105 | + assert aedtapp.assign_thermal_map("MyCylinder", ipk.design_name) |
| 106 | + |
| 107 | + def test_assign_mechanical_boundaries(self, aedtapp): |
| 108 | + udp = aedtapp.modeler.Position(0, 0, 0) |
107 | 109 | coax_dimension = 30
|
108 |
| - self.aedtapp.oproject.InsertDesign("Mechanical", "MechanicalDesign2", "Modal", "") |
109 |
| - self.aedtapp.set_active_design("MechanicalDesign2") |
110 |
| - self.aedtapp.modeler.create_cylinder(self.aedtapp.PLANE.XY, udp, 3, coax_dimension, 0, "MyCylinder", "brass") |
111 |
| - self.aedtapp.create_setup() |
112 |
| - assert self.aedtapp.assign_fixed_support(self.aedtapp.modeler["MyCylinder"].faces[0].id) |
113 |
| - assert self.aedtapp.assign_frictionless_support(self.aedtapp.modeler["MyCylinder"].faces[1].id) |
114 |
| - self.aedtapp.oproject.InsertDesign("Mechanical", "MechanicalDesign3", "Thermal", "") |
115 |
| - self.aedtapp.set_active_design("MechanicalDesign3") |
116 |
| - self.aedtapp.modeler.create_cylinder(self.aedtapp.PLANE.XY, udp, 3, coax_dimension, 0, "MyCylinder", "brass") |
| 110 | + aedtapp.oproject.InsertDesign("Mechanical", "MechanicalDesign2", "Modal", "") |
| 111 | + aedtapp.set_active_design("MechanicalDesign2") |
| 112 | + aedtapp.modeler.create_cylinder(aedtapp.PLANE.XY, udp, 3, coax_dimension, 0, "MyCylinder", "brass") |
| 113 | + aedtapp.create_setup() |
| 114 | + assert aedtapp.assign_fixed_support(aedtapp.modeler["MyCylinder"].faces[0].id) |
| 115 | + assert aedtapp.assign_frictionless_support(aedtapp.modeler["MyCylinder"].faces[1].id) |
| 116 | + aedtapp.oproject.InsertDesign("Mechanical", "MechanicalDesign3", "Thermal", "") |
| 117 | + aedtapp.set_active_design("MechanicalDesign3") |
| 118 | + aedtapp.modeler.create_cylinder(aedtapp.PLANE.XY, udp, 3, coax_dimension, 0, "MyCylinder", "brass") |
117 | 119 | with pytest.raises(AEDTRuntimeError, match="This method works only in a Mechanical Structural analysis."):
|
118 |
| - self.aedtapp.assign_fixed_support(self.aedtapp.modeler["MyCylinder"].faces[0].id) |
| 120 | + aedtapp.assign_fixed_support(aedtapp.modeler["MyCylinder"].faces[0].id) |
119 | 121 | with pytest.raises(AEDTRuntimeError, match="This method works only in a Mechanical Structural analysis."):
|
120 |
| - self.aedtapp.assign_frictionless_support(self.aedtapp.modeler["MyCylinder"].faces[0].id) |
121 |
| - |
122 |
| - def test_08_mesh_settings(self): |
123 |
| - assert self.aedtapp.mesh.initial_mesh_settings |
124 |
| - assert self.aedtapp.mesh.initial_mesh_settings.props |
125 |
| - |
126 |
| - def test_09_assign_heat_flux(self): |
127 |
| - self.aedtapp.insert_design("Th1", "Thermal") |
128 |
| - self.aedtapp.modeler.create_box([0, 0, 0], [10, 10, 3], "box1", "copper") |
129 |
| - b2 = self.aedtapp.modeler.create_box([20, 20, 2], [10, 10, 3], "box2", "copper") |
130 |
| - hf1 = self.aedtapp.assign_heat_flux(["box1"], heat_flux_type="Total Power", value="5W") |
131 |
| - hf2 = self.aedtapp.assign_heat_flux([b2.top_face_x.id], heat_flux_type="Surface Flux", value="25mW_per_m2") |
| 122 | + aedtapp.assign_frictionless_support(aedtapp.modeler["MyCylinder"].faces[0].id) |
| 123 | + |
| 124 | + def test_mesh_settings(self, aedtapp): |
| 125 | + assert aedtapp.mesh.initial_mesh_settings |
| 126 | + assert aedtapp.mesh.initial_mesh_settings.props |
| 127 | + |
| 128 | + def test_assign_heat_flux(self, aedtapp): |
| 129 | + aedtapp.insert_design("Th1", "Thermal") |
| 130 | + aedtapp.modeler.create_box([0, 0, 0], [10, 10, 3], "box1", "copper") |
| 131 | + b2 = aedtapp.modeler.create_box([20, 20, 2], [10, 10, 3], "box2", "copper") |
| 132 | + hf1 = aedtapp.assign_heat_flux(["box1"], heat_flux_type="Total Power", value="5W") |
| 133 | + hf2 = aedtapp.assign_heat_flux([b2.top_face_x.id], heat_flux_type="Surface Flux", value="25mW_per_m2") |
132 | 134 | assert hf1.props["TotalPower"] == "5W"
|
133 | 135 | assert hf2.props["SurfaceFlux"] == "25mW_per_m2"
|
134 | 136 |
|
135 |
| - def test_10_assign_heat_generation(self): |
136 |
| - self.aedtapp.insert_design("Th2", "Thermal") |
137 |
| - self.aedtapp.modeler.create_box([40, 40, 2], [10, 10, 3], "box3", "copper") |
138 |
| - hg1 = self.aedtapp.assign_heat_generation(["box3"], value="1W", name="heatgenBC") |
| 137 | + def test_assign_heat_generation(self, aedtapp): |
| 138 | + aedtapp.insert_design("Th2", "Thermal") |
| 139 | + aedtapp.modeler.create_box([40, 40, 2], [10, 10, 3], "box3", "copper") |
| 140 | + hg1 = aedtapp.assign_heat_generation(["box3"], value="1W", name="heatgenBC") |
139 | 141 | assert hg1.props["TotalPower"] == "1W"
|
140 | 142 |
|
141 |
| - def test_11_add_mesh_link(self): |
142 |
| - self.aedtapp.save_project(self.aedtapp.project_file) |
143 |
| - self.aedtapp.set_active_design("MechanicalDesign1") |
144 |
| - assert self.aedtapp.setups[0].add_mesh_link(design="MechanicalDesign2") |
145 |
| - meshlink_props = self.aedtapp.setups[0].props["MeshLink"] |
| 143 | + def test_add_mesh_link(self, aedtapp, local_scratch): |
| 144 | + setup = aedtapp.create_setup() |
| 145 | + aedtapp.insert_design("MechanicalDesign2") |
| 146 | + aedtapp.create_setup() |
| 147 | + assert setup.add_mesh_link(design="MechanicalDesign2") |
| 148 | + meshlink_props = setup.props["MeshLink"] |
146 | 149 | assert meshlink_props["Project"] == "This Project*"
|
147 | 150 | assert meshlink_props["PathRelativeTo"] == "TargetProject"
|
148 | 151 | assert meshlink_props["Design"] == "MechanicalDesign2"
|
149 |
| - assert meshlink_props["Soln"] == self.aedtapp.nominal_adaptive |
150 |
| - assert meshlink_props["Params"] == self.aedtapp.available_variations.nominal_values |
151 |
| - assert not self.aedtapp.setups[0].add_mesh_link(design="") |
152 |
| - assert not self.aedtapp.setups[0].add_mesh_link( |
153 |
| - design="MechanicalDesign2", solution="Setup_Test : LastAdaptive" |
154 |
| - ) |
155 |
| - |
156 |
| - assert self.aedtapp.setups[0].add_mesh_link( |
157 |
| - design="MechanicalDesign2", parameters=self.aedtapp.available_variations.nominal_values |
158 |
| - ) |
159 |
| - assert self.aedtapp.setups[0].add_mesh_link(design="MechanicalDesign2", solution="MySetupAuto : LastAdaptive") |
160 |
| - example_project = os.path.join(self.local_scratch.path, test_project_name + ".aedt") |
161 |
| - example_project_copy = os.path.join(self.local_scratch.path, test_project_name + "_copy.aedt") |
| 152 | + assert meshlink_props["Soln"] == aedtapp.nominal_adaptive |
| 153 | + assert meshlink_props["Params"] == aedtapp.available_variations.nominal_values |
| 154 | + assert not setup.add_mesh_link(design="") |
| 155 | + assert not setup.add_mesh_link(design="MechanicalDesign2", solution="Setup_Test : LastAdaptive") |
| 156 | + |
| 157 | + assert setup.add_mesh_link(design="MechanicalDesign2", parameters=aedtapp.available_variations.nominal_values) |
| 158 | + assert setup.add_mesh_link(design="MechanicalDesign2", solution="MySetupAuto : LastAdaptive") |
| 159 | + example_project = os.path.join(local_scratch.path, "test.aedt") |
| 160 | + aedtapp.save_project(example_project) |
| 161 | + example_project_copy = os.path.join(local_scratch.path, "test_copy.aedt") |
162 | 162 | shutil.copyfile(example_project, example_project_copy)
|
163 |
| - assert self.aedtapp.setups[0].add_mesh_link(design="MechanicalDesign2", project=example_project_copy) |
| 163 | + assert setup.add_mesh_link(design="MechanicalDesign2", project=example_project_copy) |
164 | 164 | os.remove(example_project_copy)
|
165 |
| - |
166 |
| - def test_12_transient_thermal(self): |
167 |
| - mech = Mechanical(solution_type="Transient Thermal") |
168 |
| - setup = mech.create_setup() |
169 |
| - assert "Stop Time" in setup.props |
0 commit comments