Skip to content

Commit ebd0ebb

Browse files
Samuelopez-ansyspyansys-ci-botSMoraisAnsyspre-commit-ci[bot]
authored
FEAT: EM fields in Q3D (#6421)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Sébastien Morais <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 103c656 commit ebd0ebb

File tree

6 files changed

+439
-71
lines changed

6 files changed

+439
-71
lines changed

doc/changelog.d/6421.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Em fields in q3d

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def oradfield(self):
107107
"""
108108
if self.design_type == "HFSS" and self._odesign.GetSolutionType() not in ["EigenMode", "Characteristic Mode"]:
109109
return self._odesign.GetModule("RadField")
110+
if self.desktop_class.aedt_version_id >= "2025.1" and self.design_type == "Q3D Extractor":
111+
return self._odesign.GetModule("RadField")
110112
return None
111113

112114
@pyaedt_function_handler()

src/ansys/aedt/core/hfss.py

Lines changed: 70 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import math
2828
from pathlib import Path
2929
import tempfile
30+
from typing import Optional
3031
from typing import Union
3132
import warnings
3233

@@ -236,6 +237,28 @@ def __init__(
236237
def _init_from_design(self, *args, **kwargs):
237238
self.__init__(*args, **kwargs)
238239

240+
@pyaedt_function_handler
241+
# NOTE: Extend Mixin behaviour to handle near field setups
242+
def _create_boundary(self, name, props, boundary_type):
243+
# No-near field cases
244+
if boundary_type not in (
245+
"NearFieldSphere",
246+
"NearFieldBox",
247+
"NearFieldRectangle",
248+
"NearFieldLine",
249+
"NearFieldPoints",
250+
):
251+
return super()._create_boundary(name, props, boundary_type)
252+
253+
# Near field setup
254+
bound = NearFieldSetup(self, name, props, boundary_type)
255+
result = bound.create()
256+
if result:
257+
self.field_setups.append(bound)
258+
self.logger.info(f"Field setup {boundary_type} {name} has been created.")
259+
return bound
260+
raise AEDTRuntimeError(f"Failed to create near field setup {boundary_type} {name}")
261+
239262
@property
240263
def field_setups(self):
241264
"""List of AEDT radiation fields.
@@ -5574,19 +5597,19 @@ def insert_infinite_sphere(
55745597
@pyaedt_function_handler()
55755598
def insert_near_field_sphere(
55765599
self,
5577-
radius=20,
5600+
radius: Union[float, int, str] = 20,
55785601
radius_units="mm",
5579-
x_start=0,
5580-
x_stop=180,
5581-
x_step=10,
5582-
y_start=0,
5583-
y_stop=180,
5584-
y_step=10,
5585-
angle_units="deg",
5586-
custom_radiation_faces=None,
5587-
custom_coordinate_system=None,
5588-
name=None,
5589-
):
5602+
x_start: Union[float, int, str] = 0,
5603+
x_stop: Union[float, int, str] = 180,
5604+
x_step: Union[float, int, str] = 10,
5605+
y_start: Union[float, int, str] = 0,
5606+
y_stop: Union[float, int, str] = 180,
5607+
y_step: Union[float, int, str] = 10,
5608+
angle_units: str = "deg",
5609+
custom_radiation_faces: Optional[str] = None,
5610+
custom_coordinate_system: Optional[str] = None,
5611+
name: Optional[str] = None,
5612+
) -> NearFieldSetup:
55905613
"""Create a near field sphere.
55915614
55925615
.. note::
@@ -5648,26 +5671,22 @@ def insert_near_field_sphere(
56485671
props["CoordSystem"] = custom_coordinate_system
56495672
else:
56505673
props["CoordSystem"] = ""
5651-
bound = NearFieldSetup(self, name, props, "NearFieldSphere")
5652-
if bound.create():
5653-
self.field_setups.append(bound)
5654-
return bound
5655-
return False
5674+
return self._create_boundary(name, props, "NearFieldSphere")
56565675

56575676
@pyaedt_function_handler()
56585677
def insert_near_field_box(
56595678
self,
5660-
u_length=20,
5661-
u_samples=21,
5662-
v_length=20,
5663-
v_samples=21,
5664-
w_length=20,
5665-
w_samples=21,
5666-
units="mm",
5667-
custom_radiation_faces=None,
5668-
custom_coordinate_system=None,
5669-
name=None,
5670-
):
5679+
u_length: Union[float, int, str] = 20,
5680+
u_samples: Union[float, int, str] = 21,
5681+
v_length: Union[float, int, str] = 20,
5682+
v_samples: Union[float, int, str] = 21,
5683+
w_length: Union[float, int, str] = 20,
5684+
w_samples: Union[float, int, str] = 21,
5685+
units: str = "mm",
5686+
custom_radiation_faces: Optional[str] = None,
5687+
custom_coordinate_system: Optional[str] = None,
5688+
name: Optional[str] = None,
5689+
) -> NearFieldSetup:
56715690
"""Create a near field box.
56725691
56735692
.. note::
@@ -5723,24 +5742,20 @@ def insert_near_field_box(
57235742
props["CoordSystem"] = custom_coordinate_system
57245743
else:
57255744
props["CoordSystem"] = "Global"
5726-
bound = NearFieldSetup(self, name, props, "NearFieldBox")
5727-
if bound.create():
5728-
self.field_setups.append(bound)
5729-
return bound
5730-
return False
5745+
return self._create_boundary(name, props, "NearFieldBox")
57315746

57325747
@pyaedt_function_handler()
57335748
def insert_near_field_rectangle(
57345749
self,
5735-
u_length=20,
5736-
u_samples=21,
5737-
v_length=20,
5738-
v_samples=21,
5739-
units="mm",
5740-
custom_radiation_faces=None,
5741-
custom_coordinate_system=None,
5742-
name=None,
5743-
):
5750+
u_length: Union[float, int, str] = 20,
5751+
u_samples: Union[float, int, str] = 21,
5752+
v_length: Union[float, int, str] = 20,
5753+
v_samples: Union[float, int, str] = 21,
5754+
units: str = "mm",
5755+
custom_radiation_faces: Optional[str] = None,
5756+
custom_coordinate_system: Optional[str] = None,
5757+
name: Optional[str] = None,
5758+
) -> NearFieldSetup:
57445759
"""Create a near field rectangle.
57455760
57465761
.. note::
@@ -5790,20 +5805,17 @@ def insert_near_field_rectangle(
57905805
props["CoordSystem"] = custom_coordinate_system
57915806
else:
57925807
props["CoordSystem"] = "Global"
5793-
bound = NearFieldSetup(self, name, props, "NearFieldRectangle")
5794-
if bound.create():
5795-
self.field_setups.append(bound)
5796-
return bound
5797-
return False
5808+
5809+
return self._create_boundary(name, props, "NearFieldRectangle")
57985810

57995811
@pyaedt_function_handler(line="assignment")
58005812
def insert_near_field_line(
58015813
self,
5802-
assignment,
5803-
points=1000,
5804-
custom_radiation_faces=None,
5805-
name=None,
5806-
):
5814+
assignment: str,
5815+
points: Union[float, str] = 1000,
5816+
custom_radiation_faces: Optional[str] = None,
5817+
name: str = None,
5818+
) -> NearFieldSetup:
58075819
"""Create a near field line.
58085820
58095821
.. note::
@@ -5830,6 +5842,7 @@ def insert_near_field_line(
58305842
name = generate_unique_name("Line")
58315843

58325844
props = dict({"UseCustomRadiationSurface": custom_radiation_faces is not None})
5845+
58335846
if custom_radiation_faces:
58345847
props["CustomRadiationSurface"] = custom_radiation_faces
58355848
else:
@@ -5838,19 +5851,15 @@ def insert_near_field_line(
58385851
props["NumPts"] = points
58395852
props["Line"] = assignment
58405853

5841-
bound = NearFieldSetup(self, name, props, "NearFieldLine")
5842-
if bound.create():
5843-
self.field_setups.append(bound)
5844-
return bound
5845-
return False
5854+
return self._create_boundary(name, props, "NearFieldLine")
58465855

58475856
@pyaedt_function_handler()
58485857
def insert_near_field_points(
58495858
self,
58505859
input_file: Union[str, Path] = None,
5851-
coordinate_system="Global",
5852-
name=None,
5853-
):
5860+
coordinate_system: str = "Global",
5861+
name: Optional[str] = None,
5862+
) -> NearFieldSetup:
58545863
"""Create a near field line.
58555864
58565865
.. note::
@@ -5880,11 +5889,7 @@ def insert_near_field_points(
58805889
props["CoordSystem"] = coordinate_system
58815890
props["PointListFile"] = str(point_file)
58825891

5883-
bound = NearFieldSetup(self, name, props, "NearFieldPoints")
5884-
if bound.create():
5885-
self.field_setups.append(bound)
5886-
return bound
5887-
return False
5892+
return self._create_boundary(name, props, "NearFieldPoints")
58885893

58895894
@pyaedt_function_handler()
58905895
def set_sbr_current_sources_options(self, conformance=False, thin_sources=False, power_fraction=0.95):

src/ansys/aedt/core/modules/boundary/hfss_boundary.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ def _child_object(self):
6565
child_object = None
6666
design_childs = self._app.get_oo_name(self._app.odesign)
6767

68-
if "Radiation" in design_childs:
69-
cc = self._app.get_oo_object(self._app.odesign, "Radiation")
70-
cc_names = self._app.get_oo_name(cc)
71-
if self._name in cc_names:
72-
child_object = cc.GetChildObject(self._name)
68+
for category in ["Radiation", "EM Fields"]:
69+
if category in design_childs:
70+
cc = self._app.get_oo_object(self._app.odesign, category)
71+
cc_names = self._app.get_oo_name(cc)
72+
if self._name in cc_names:
73+
child_object = cc.GetChildObject(self._name)
74+
break
75+
7376
return child_object
7477

7578
@property

0 commit comments

Comments
 (0)