Skip to content

Commit 0142f00

Browse files
FEAT: Add create EM target design + add tests (#6838)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 1bd1cb7 commit 0142f00

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

doc/changelog.d/6838.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add create EM target design + add tests

src/ansys/aedt/core/application/design.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
from ansys.aedt.core.generic.numbers_utils import decompose_variable_value
8484
from ansys.aedt.core.generic.settings import inner_project_settings
8585
from ansys.aedt.core.internal.aedt_versions import aedt_versions
86+
from ansys.aedt.core.internal.errors import AEDTRuntimeError
8687
from ansys.aedt.core.internal.errors import GrpcApiError
8788
from ansys.aedt.core.internal.load_aedt_file import load_entire_aedt_file
8889
from ansys.aedt.core.modules.boundary.common import BoundaryObject
@@ -2434,6 +2435,50 @@ def read_only_variable(self, name, value=True):
24342435
self.variable_manager[name].read_only = value
24352436
return True
24362437

2438+
@pyaedt_function_handler()
2439+
def create_em_target_design(self, design, setup=None, design_setup=None):
2440+
"""Create an EM Target design.
2441+
2442+
Parameters
2443+
----------
2444+
design : str
2445+
Name of the target design. Possible choices are ``"Icepak"`` or``"Mechanical"``.
2446+
setup : str, optional
2447+
Name of the EM setup to link to the target design.
2448+
The default is ``None``, in which case the ``LastAdaptive`` setup is used.
2449+
design_setup : str, optional
2450+
For Icepak designs, specify ``"Forced"`` for forced convention or
2451+
``"Natural"`` for natural convention.
2452+
The default is ``None``, in which case the ``"Forced"`` option is used.
2453+
2454+
Returns
2455+
-------
2456+
bool
2457+
``True`` when successful, ``False`` when failed.
2458+
2459+
References
2460+
----------
2461+
>>> oDesign.CreateEMLossTarget
2462+
2463+
Examples
2464+
--------
2465+
>>> from ansys.aedt.core import Maxwell3d
2466+
>>> m3d = Maxwell3d()
2467+
>>> m3d.create_em_target_design("Icepak", design_setup="Forced")
2468+
"""
2469+
if self.design_type not in ["HFSS", "Maxwell 3D", "Q3D Extractor"]:
2470+
raise AEDTRuntimeError("Source design type must be 'HFSS', 'Maxwell' or 'Mechanical'.")
2471+
if design not in ["Icepak", "Mechanical"]:
2472+
raise AEDTRuntimeError("Design type must be 'Icepak' or 'Mechanical'.")
2473+
if design == "Icepak":
2474+
design_setup = design_setup or "Forced"
2475+
if design_setup not in ["Forced", "Natural"]:
2476+
raise AEDTRuntimeError("Design setup must be 'Forced' or 'Natural'.")
2477+
if not setup:
2478+
setup = self.nominal_adaptive
2479+
self.odesign.CreateEMLossTarget(design, setup, design_setup)
2480+
return True
2481+
24372482
@pyaedt_function_handler()
24382483
def _get_boundaries_data(self):
24392484
"""Retrieve boundary data.

tests/unit/test_target_design.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates.
4+
# SPDX-License-Identifier: MIT
5+
#
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
from unittest.mock import MagicMock
26+
from unittest.mock import PropertyMock
27+
from unittest.mock import patch
28+
29+
import pytest
30+
31+
from ansys.aedt.core.internal.errors import AEDTRuntimeError
32+
from ansys.aedt.core.maxwell import Maxwell3d
33+
from ansys.aedt.core.mechanical import Mechanical
34+
35+
36+
@pytest.fixture
37+
def mechanical():
38+
"""Fixture used to mock the creation of a Mechanical instance."""
39+
with patch("ansys.aedt.core.mechanical.Mechanical.__init__", lambda x: None):
40+
mock_instance = MagicMock(spec=Mechanical)
41+
yield mock_instance
42+
43+
44+
@pytest.fixture
45+
def maxwell_3d():
46+
"""Fixture used to mock the creation of a Maxwell instance."""
47+
with patch("ansys.aedt.core.maxwell.Maxwell3d.__init__", lambda x: None):
48+
mock_instance = MagicMock(spec=Maxwell3d)
49+
yield mock_instance
50+
51+
52+
@patch.object(Mechanical, "design_type", "Dummy")
53+
def test_mechanical_failure_design_type(mechanical):
54+
mechanical = Mechanical()
55+
56+
with pytest.raises(AEDTRuntimeError):
57+
mechanical.create_em_target_design("Icepak")
58+
59+
60+
@patch.object(Maxwell3d, "design_type", "Maxwell 3D")
61+
def test_maxwell_failure_design(maxwell_3d):
62+
maxwell = Maxwell3d()
63+
64+
with pytest.raises(AEDTRuntimeError):
65+
maxwell.create_em_target_design("Twinbuilder")
66+
67+
68+
@patch.object(Maxwell3d, "nominal_adaptive", new_callable=PropertyMock)
69+
@patch.object(Maxwell3d, "design_type", "Maxwell 3D")
70+
def test_maxwell_failure_design_type_create_target_design(mock_nominal, maxwell_3d):
71+
mock_nominal.return_value = "setup_name"
72+
maxwell = Maxwell3d()
73+
maxwell._odesign = MagicMock()
74+
75+
with pytest.raises(AEDTRuntimeError):
76+
assert maxwell.create_em_target_design("Icepak", design_setup="Invalid")
77+
78+
79+
@patch.object(Maxwell3d, "nominal_adaptive", new_callable=PropertyMock)
80+
@patch.object(Maxwell3d, "design_type", "Maxwell 3D")
81+
def test_maxwell_create_target_design(mock_nominal, maxwell_3d):
82+
mock_nominal.return_value = "setup_name"
83+
maxwell = Maxwell3d()
84+
maxwell._odesign = MagicMock()
85+
86+
assert maxwell.create_em_target_design("Icepak", design_setup="Forced")

0 commit comments

Comments
 (0)