27
27
import math
28
28
from pathlib import Path
29
29
import tempfile
30
+ from typing import Optional
30
31
from typing import Union
31
32
import warnings
32
33
@@ -236,6 +237,28 @@ def __init__(
236
237
def _init_from_design (self , * args , ** kwargs ):
237
238
self .__init__ (* args , ** kwargs )
238
239
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
+
239
262
@property
240
263
def field_setups (self ):
241
264
"""List of AEDT radiation fields.
@@ -5574,19 +5597,19 @@ def insert_infinite_sphere(
5574
5597
@pyaedt_function_handler ()
5575
5598
def insert_near_field_sphere (
5576
5599
self ,
5577
- radius = 20 ,
5600
+ radius : Union [ float , int , str ] = 20 ,
5578
5601
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 :
5590
5613
"""Create a near field sphere.
5591
5614
5592
5615
.. note::
@@ -5648,26 +5671,22 @@ def insert_near_field_sphere(
5648
5671
props ["CoordSystem" ] = custom_coordinate_system
5649
5672
else :
5650
5673
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" )
5656
5675
5657
5676
@pyaedt_function_handler ()
5658
5677
def insert_near_field_box (
5659
5678
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 :
5671
5690
"""Create a near field box.
5672
5691
5673
5692
.. note::
@@ -5723,24 +5742,20 @@ def insert_near_field_box(
5723
5742
props ["CoordSystem" ] = custom_coordinate_system
5724
5743
else :
5725
5744
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" )
5731
5746
5732
5747
@pyaedt_function_handler ()
5733
5748
def insert_near_field_rectangle (
5734
5749
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 :
5744
5759
"""Create a near field rectangle.
5745
5760
5746
5761
.. note::
@@ -5790,20 +5805,17 @@ def insert_near_field_rectangle(
5790
5805
props ["CoordSystem" ] = custom_coordinate_system
5791
5806
else :
5792
5807
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" )
5798
5810
5799
5811
@pyaedt_function_handler (line = "assignment" )
5800
5812
def insert_near_field_line (
5801
5813
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 :
5807
5819
"""Create a near field line.
5808
5820
5809
5821
.. note::
@@ -5830,6 +5842,7 @@ def insert_near_field_line(
5830
5842
name = generate_unique_name ("Line" )
5831
5843
5832
5844
props = dict ({"UseCustomRadiationSurface" : custom_radiation_faces is not None })
5845
+
5833
5846
if custom_radiation_faces :
5834
5847
props ["CustomRadiationSurface" ] = custom_radiation_faces
5835
5848
else :
@@ -5838,19 +5851,15 @@ def insert_near_field_line(
5838
5851
props ["NumPts" ] = points
5839
5852
props ["Line" ] = assignment
5840
5853
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" )
5846
5855
5847
5856
@pyaedt_function_handler ()
5848
5857
def insert_near_field_points (
5849
5858
self ,
5850
5859
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 :
5854
5863
"""Create a near field line.
5855
5864
5856
5865
.. note::
@@ -5880,11 +5889,7 @@ def insert_near_field_points(
5880
5889
props ["CoordSystem" ] = coordinate_system
5881
5890
props ["PointListFile" ] = str (point_file )
5882
5891
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" )
5888
5893
5889
5894
@pyaedt_function_handler ()
5890
5895
def set_sbr_current_sources_options (self , conformance = False , thin_sources = False , power_fraction = 0.95 ):
0 commit comments