Skip to content

Commit 009cf14

Browse files
Add Nearfield into mixin
1 parent 9be2bff commit 009cf14

File tree

3 files changed

+85
-83
lines changed

3 files changed

+85
-83
lines changed

src/ansys/aedt/core/hfss.py

Lines changed: 48 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

@@ -5574,19 +5575,19 @@ def insert_infinite_sphere(
55745575
@pyaedt_function_handler()
55755576
def insert_near_field_sphere(
55765577
self,
5577-
radius=20,
5578+
radius: Union[float, int, str] = 20,
55785579
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-
):
5580+
x_start: Union[float, int, str] = 0,
5581+
x_stop: Union[float, int, str] = 180,
5582+
x_step: Union[float, int, str] = 10,
5583+
y_start: Union[float, int, str] = 0,
5584+
y_stop: Union[float, int, str] = 180,
5585+
y_step: Union[float, int, str] = 10,
5586+
angle_units: str = "deg",
5587+
custom_radiation_faces: Optional[str] = None,
5588+
custom_coordinate_system: Optional[str] = None,
5589+
name: Optional[str] = None,
5590+
) -> NearFieldSetup:
55905591
"""Create a near field sphere.
55915592
55925593
.. note::
@@ -5648,26 +5649,22 @@ def insert_near_field_sphere(
56485649
props["CoordSystem"] = custom_coordinate_system
56495650
else:
56505651
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
5652+
return self._create_field_setup(name, props, "NearFieldSphere")
56565653

56575654
@pyaedt_function_handler()
56585655
def insert_near_field_box(
56595656
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-
):
5657+
u_length: Union[float, int, str] = 20,
5658+
u_samples: Union[float, int, str] = 21,
5659+
v_length: Union[float, int, str] = 20,
5660+
v_samples: Union[float, int, str] = 21,
5661+
w_length: Union[float, int, str] = 20,
5662+
w_samples: Union[float, int, str] = 21,
5663+
units: str = "mm",
5664+
custom_radiation_faces: Optional[str] = None,
5665+
custom_coordinate_system: Optional[str] = None,
5666+
name: Optional[str] = None,
5667+
) -> NearFieldSetup:
56715668
"""Create a near field box.
56725669
56735670
.. note::
@@ -5723,24 +5720,20 @@ def insert_near_field_box(
57235720
props["CoordSystem"] = custom_coordinate_system
57245721
else:
57255722
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
5723+
return self._create_field_setup(name, props, "NearFieldBox")
57315724

57325725
@pyaedt_function_handler()
57335726
def insert_near_field_rectangle(
57345727
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-
):
5728+
u_length: Union[float, int, str] = 20,
5729+
u_samples: Union[float, int, str] = 21,
5730+
v_length: Union[float, int, str] = 20,
5731+
v_samples: Union[float, int, str] = 21,
5732+
units: str = "mm",
5733+
custom_radiation_faces: Optional[str] = None,
5734+
custom_coordinate_system: Optional[str] = None,
5735+
name: Optional[str] = None,
5736+
) -> NearFieldSetup:
57445737
"""Create a near field rectangle.
57455738
57465739
.. note::
@@ -5790,20 +5783,17 @@ def insert_near_field_rectangle(
57905783
props["CoordSystem"] = custom_coordinate_system
57915784
else:
57925785
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
5786+
5787+
return self._create_field_setup(name, props, "NearFieldRectangle")
57985788

57995789
@pyaedt_function_handler(line="assignment")
58005790
def insert_near_field_line(
58015791
self,
5802-
assignment,
5803-
points=1000,
5804-
custom_radiation_faces=None,
5805-
name=None,
5806-
):
5792+
assignment: str,
5793+
points: Union[float, str] = 1000,
5794+
custom_radiation_faces: Optional[str] = None,
5795+
name: str = None,
5796+
) -> NearFieldSetup:
58075797
"""Create a near field line.
58085798
58095799
.. note::
@@ -5830,6 +5820,7 @@ def insert_near_field_line(
58305820
name = generate_unique_name("Line")
58315821

58325822
props = dict({"UseCustomRadiationSurface": custom_radiation_faces is not None})
5823+
58335824
if custom_radiation_faces:
58345825
props["CustomRadiationSurface"] = custom_radiation_faces
58355826
else:
@@ -5838,19 +5829,15 @@ def insert_near_field_line(
58385829
props["NumPts"] = points
58395830
props["Line"] = assignment
58405831

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

58475834
@pyaedt_function_handler()
58485835
def insert_near_field_points(
58495836
self,
58505837
input_file: Union[str, Path] = None,
5851-
coordinate_system="Global",
5852-
name=None,
5853-
):
5838+
coordinate_system: str = "Global",
5839+
name: Optional[str] = None,
5840+
) -> NearFieldSetup:
58545841
"""Create a near field line.
58555842
58565843
.. note::
@@ -5880,11 +5867,7 @@ def insert_near_field_points(
58805867
props["CoordSystem"] = coordinate_system
58815868
props["PointListFile"] = str(point_file)
58825869

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

58895872
@pyaedt_function_handler()
58905873
def set_sbr_current_sources_options(self, conformance=False, thin_sources=False, power_fraction=0.95):

src/ansys/aedt/core/mixins.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from ansys.aedt.core.internal.errors import AEDTRuntimeError
2727
from ansys.aedt.core.internal.errors import GrpcApiError
2828
from ansys.aedt.core.modules.boundary.common import BoundaryObject
29+
from ansys.aedt.core.modules.boundary.hfss_boundary import NearFieldSetup
2930

3031

3132
class CreateBoundaryMixin:
@@ -78,3 +79,33 @@ def _create_boundary(self, name, props, boundary_type):
7879
return bound
7980
except GrpcApiError as e:
8081
raise AEDTRuntimeError(f"Failed to create boundary {boundary_type} {name}") from e
82+
83+
@pyaedt_function_handler()
84+
def _create_field_setup(self, name, props, boundary_type):
85+
"""Create a field setup.
86+
87+
Parameters
88+
----------
89+
name : str
90+
Name of the boundary.
91+
props : list or dict
92+
List of properties for the boundary.
93+
boundary_type :
94+
Type of the boundary.
95+
96+
Returns
97+
-------
98+
:class:`ansys.aedt.core.modules.boundary.hfss_boundary.NearFieldSetup`
99+
Boundary object.
100+
101+
"""
102+
try:
103+
bound = NearFieldSetup(self, name, props, boundary_type)
104+
if not bound.create():
105+
raise AEDTRuntimeError(f"Failed to create {boundary_type} {name}")
106+
107+
self.field_setups.append(bound)
108+
self.logger.info(f"Field setup {boundary_type} {name} has been created.")
109+
return bound
110+
except GrpcApiError as e: # pragma: no cover
111+
raise AEDTRuntimeError(f"Failed to create boundary {boundary_type} {name}") from e

src/ansys/aedt/core/q3d.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,11 +2362,7 @@ def insert_em_field_line(
23622362
"Line": assignment,
23632363
}
23642364

2365-
bound = NearFieldSetup(self, name, props, "NearFieldLine")
2366-
if bound.create():
2367-
self.field_setups.append(bound)
2368-
return bound
2369-
raise AEDTRuntimeError("Failed to create EM field line.") # pragma: no cover
2365+
return self._create_field_setup(name, props, "NearFieldLine")
23702366

23712367
@pyaedt_function_handler()
23722368
@min_aedt_version("2025.1")
@@ -2424,11 +2420,8 @@ def insert_em_field_rectangle(
24242420
props["CoordSystem"] = custom_coordinate_system
24252421
else:
24262422
props["CoordSystem"] = "Global"
2427-
bound = NearFieldSetup(self, name, props, "NearFieldRectangle")
2428-
if bound.create():
2429-
self.field_setups.append(bound)
2430-
return bound
2431-
raise AEDTRuntimeError("Failed to create EM field rectangle.") # pragma: no cover
2423+
2424+
return self._create_field_setup(name, props, "NearFieldRectangle")
24322425

24332426
@pyaedt_function_handler()
24342427
@min_aedt_version("2025.1")
@@ -2495,10 +2488,7 @@ def insert_em_field_box(
24952488
else:
24962489
props["CoordSystem"] = "Global"
24972490

2498-
bound = NearFieldSetup(self, name, props, "NearFieldBox")
2499-
if bound.create():
2500-
return bound
2501-
raise AEDTRuntimeError("Failed to create EM field box.") # pragma: no cover
2491+
return self._create_field_setup(name, props, "NearFieldBox")
25022492

25032493
@pyaedt_function_handler()
25042494
@min_aedt_version("2025.1")
@@ -2571,10 +2561,8 @@ def insert_em_field_sphere(
25712561
props["CoordSystem"] = custom_coordinate_system
25722562
else:
25732563
props["CoordSystem"] = ""
2574-
bound = NearFieldSetup(self, name, props, "NearFieldSphere")
2575-
if bound.create():
2576-
return bound
2577-
raise AEDTRuntimeError("Failed to create EM field sphere.") # pragma: no cover
2564+
2565+
return self._create_field_setup(name, props, "NearFieldSphere")
25782566

25792567

25802568
class Q2d(QExtractor, CreateBoundaryMixin):

0 commit comments

Comments
 (0)