Skip to content

Commit 30d459d

Browse files
gmalinvepyansys-ci-botSamuelopez-ansys
authored
FIX: Add mesh link wrong source design solution selection (#6133)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Samuel Lopez <[email protected]>
1 parent 7246ecf commit 30d459d

File tree

3 files changed

+132
-131
lines changed

3 files changed

+132
-131
lines changed

doc/changelog.d/6133.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add mesh link wrong source design solution selection

src/ansys/aedt/core/modules/solve_setup.py

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ def add_mesh_link(
888888
Parameters
889889
----------
890890
design : str
891-
Name of the source design.
891+
Name of the source design from which the mesh is imported.
892892
solution : str, optional
893893
Name of the source design solution in the format ``"name : solution_name"``.
894894
If ``None``, the default value is taken from the nominal adaptive solution.
@@ -921,72 +921,77 @@ def add_mesh_link(
921921
Examples
922922
--------
923923
>>> from ansys.aedt.core import Maxwell3d
924-
>>> m3d = Maxwell3d(design="source_design")
925-
>>> m3d.create_setup(name="setup1")
926-
The target design is duplicated from the source design and made it active design.
927-
>>> m3d.duplicate_design(name="source_design", save_after_duplicate=True)
928-
The mesh link is assigned to the target design analysis setup.
929-
>>> m3d.setups[0].add_mesh_link(design="source_design", solution=m3d.nominal_adaptive)
924+
>>> m3d = Maxwell3d(design="target_design")
925+
>>> target_setup = m3d.create_setup(name="target_setup")
926+
The target design is duplicated and made it active.
927+
The duplicated design will be the source design from which the mesh is imported.
928+
>>> m3d.duplicate_design(name="target_design", save_after_duplicate=True)
929+
>>> m3d.rename_design(name="source_design")
930+
>>> m3d.create_setup(name="source_setup")
931+
Activate the target design.
932+
>>> m3d.set_active_design("target_design")
933+
The mesh link is assigned to the target design.
934+
>>> target_setup.add_mesh_link("source_design")
930935
>>> m3d.release_desktop()
931-
932936
"""
933-
937+
dkp = self._app.desktop_class
938+
source_design = design
934939
auto_update = self.auto_update
935940
try:
936941
self.auto_update = False
937-
meshlinks = self.props["MeshLink"]
942+
mesh_link = self.props["MeshLink"]
938943
# design type
939-
if self._app.design_type == "Mechanical":
940-
design_type = "ElectronicsDesktop"
941-
elif self._app.design_type == "Maxwell 2D" or self._app.design_type == "Maxwell 3D":
942-
design_type = "Maxwell"
944+
if self._app.design_type in ["Mechanical", "Maxwell 2D", "Maxwell 3D"]:
945+
design_type = "ElectronicsDesktop" if self._app.design_type == "Mechanical" else self._app.design_type
943946
else:
944947
design_type = self._app.design_type
945-
meshlinks["Product"] = design_type
948+
mesh_link["Product"] = design_type
946949
# design name
947950
if design not in self._app.design_list:
948951
raise ValueError("Design does not exist in current project.")
949952
else:
950-
meshlinks["Design"] = design
953+
mesh_link["Design"] = design
951954
# project name
952955
if project != "This Project*":
953956
if os.path.exists(project):
954-
meshlinks["Project"] = project
955-
meshlinks["PathRelativeTo"] = "SourceProduct"
957+
mesh_link["Project"] = project
958+
mesh_link["PathRelativeTo"] = "SourceProduct"
956959
else:
957960
raise ValueError("Project file path provided does not exist.")
958961
else:
959-
meshlinks["Project"] = project
960-
meshlinks["PathRelativeTo"] = "TargetProject"
961-
# if self._app.solution_type == "SBR+":
962-
meshlinks["ImportMesh"] = True
962+
mesh_link["Project"] = project
963+
mesh_link["PathRelativeTo"] = "TargetProject"
964+
965+
mesh_link["ImportMesh"] = True
963966
# solution name
967+
app = dkp[[self._app.project_name, source_design]]
964968
if solution is None:
965-
meshlinks["Soln"] = self._app.nominal_adaptive
966-
elif solution.split()[0] not in self._app.setup_names:
969+
mesh_link["Soln"] = app.nominal_adaptive
970+
elif solution.split()[0] not in app.setup_names:
967971
raise ValueError("Setup does not exist in current design.")
972+
elif solution:
973+
mesh_link["Soln"] = solution
968974
# parameters
969-
meshlinks["Params"] = {}
975+
mesh_link["Params"] = {}
970976

971977
nominal_values = self._app.available_variations.get_independent_nominal_values()
972978

973979
if parameters is None:
974-
parameters = nominal_values
975980
parameters = self._app.available_variations.nominal_w_values_dict
976981
for el in parameters:
977-
meshlinks["Params"][el] = el
982+
mesh_link["Params"][el] = el
978983
else:
979984
for el in parameters:
980985
if el in list(nominal_values.keys()):
981-
meshlinks["Params"][el] = el
986+
mesh_link["Params"][el] = el
982987
else:
983-
meshlinks["Params"][el] = parameters[el]
988+
mesh_link["Params"][el] = parameters[el]
984989

985-
meshlinks["ForceSourceToSolve"] = force_source_to_solve
986-
meshlinks["PreservePartnerSoln"] = preserve_partner_solution
987-
meshlinks["ApplyMeshOp"] = apply_mesh_operations
990+
mesh_link["ForceSourceToSolve"] = force_source_to_solve
991+
mesh_link["PreservePartnerSoln"] = preserve_partner_solution
992+
mesh_link["ApplyMeshOp"] = apply_mesh_operations
988993
if self._app.design_type not in ["Maxwell 2D", "Maxwell 3D"]:
989-
meshlinks["AdaptPort"] = adapt_port
994+
mesh_link["AdaptPort"] = adapt_port
990995
self.update()
991996
self.auto_update = auto_update
992997
return True

tests/system/general/test_29_Mechanical.py

Lines changed: 93 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -31,139 +31,134 @@
3131
from ansys.aedt.core.internal.errors import AEDTRuntimeError
3232
import pytest
3333

34-
from tests.system.general.conftest import config
3534

36-
test_project_name = "coax_Mech"
37-
38-
39-
@pytest.fixture(scope="class")
35+
@pytest.fixture()
4036
def aedtapp(add_app):
4137
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)
4354

4455

4556
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)
5460
assert os.path.exists(test_project)
5561

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)
5864
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")
6266
assert isinstance(o.id, int)
6367

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)
6772

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")
7177
assert bound.props["Temperature"] == "35deg"
7278

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)
7681
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")
7883
setup = hfss.create_setup()
7984
freq = "1GHz"
8085
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)
8288

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()
8692
mysetup.props["Solver"] = "Direct"
8793
assert mysetup.update()
94+
assert aedtapp.assign_2way_coupling()
8895

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)
9698
coax_dimension = 30
9799
ipk.modeler.create_cylinder(ipk.PLANE.XY, udp, 3, coax_dimension, 0, "MyCylinder", "brass")
98100
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)
107109
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")
117119
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)
119121
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")
132134
assert hf1.props["TotalPower"] == "5W"
133135
assert hf2.props["SurfaceFlux"] == "25mW_per_m2"
134136

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")
139141
assert hg1.props["TotalPower"] == "1W"
140142

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"]
146149
assert meshlink_props["Project"] == "This Project*"
147150
assert meshlink_props["PathRelativeTo"] == "TargetProject"
148151
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")
162162
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)
164164
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

Comments
 (0)