Skip to content

Commit 728c5a9

Browse files
Add multiple faces option to impedance boundary (#4446)
1 parent 42f0ff1 commit 728c5a9

File tree

2 files changed

+151
-15
lines changed

2 files changed

+151
-15
lines changed

_unittest/test_20_HFSS.py

+23-6
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,9 @@ def test_12_create_perfects_on_objects(self):
667667
def test_13_create_impedance_on_objects(self):
668668
box1 = self.aedtapp.modeler.create_box([0, 0, 0], [10, 10, 5], "imp1", "Copper")
669669
box2 = self.aedtapp.modeler.create_box([0, 0, 10], [10, 10, 5], "imp2", "copper")
670-
imp = self.aedtapp.create_impedance_between_objects("imp1", "imp2", self.aedtapp.AxisDir.XPos, "TL2", 50, 25)
670+
imp = self.aedtapp.create_impedance_between_objects(
671+
box1.name, box2.name, self.aedtapp.AxisDir.XPos, "TL1", 50, 25
672+
)
671673
assert imp.name in self.aedtapp.modeler.get_boundaries_name()
672674
assert imp.update()
673675

@@ -677,14 +679,14 @@ def test_14_create_lumpedrlc_on_objects(self):
677679
box1 = self.aedtapp.modeler.create_box([0, 0, 0], [10, 10, 5], "rlc1", "Copper")
678680
box2 = self.aedtapp.modeler.create_box([0, 0, 10], [10, 10, 5], "rlc2", "copper")
679681
imp = self.aedtapp.create_lumped_rlc_between_objects(
680-
"rlc1", "rlc2", self.aedtapp.AxisDir.XPos, Rvalue=50, Lvalue=1e-9
682+
box1.name, box2.name, self.aedtapp.AxisDir.XPos, Rvalue=50, Lvalue=1e-9
681683
)
682684
assert imp.name in self.aedtapp.modeler.get_boundaries_name()
683685
assert imp.update()
684686

685687
box3 = self.aedtapp.modeler.create_box([0, 0, 20], [10, 10, 5], "rlc3", "copper")
686688
lumped_rlc2 = self.aedtapp.create_lumped_rlc_between_objects(
687-
"rlc2", "rlc3", self.aedtapp.AxisDir.XPos, Rvalue=50, Lvalue=1e-9, Cvalue=1e-9
689+
box2.name, box3.name, self.aedtapp.AxisDir.XPos, Rvalue=50, Lvalue=1e-9, Cvalue=1e-9
688690
)
689691
assert lumped_rlc2.name in self.aedtapp.modeler.get_boundaries_name()
690692
assert lumped_rlc2.update()
@@ -710,9 +712,24 @@ def test_16_create_impedance_on_sheets(self):
710712
rect = self.aedtapp.modeler.create_rectangle(
711713
self.aedtapp.PLANE.XY, [0, 0, 0], [10, 2], name="ImpBound", matname="Copper"
712714
)
713-
imp = self.aedtapp.assign_impedance_to_sheet("imp1", "TL2", 50, 25)
714-
assert imp.name in self.aedtapp.modeler.get_boundaries_name()
715-
assert imp.update()
715+
imp1 = self.aedtapp.assign_impedance_to_sheet(rect.name, "TL2", 50, 25)
716+
assert imp1.name in self.aedtapp.modeler.get_boundaries_name()
717+
assert imp1.update()
718+
719+
impedance_box = self.aedtapp.modeler.create_box([0, -100, 0], [200, 200, 200], "ImpedanceBox")
720+
ids = self.aedtapp.modeler.get_object_faces(impedance_box.name)[:3]
721+
722+
imp2 = self.aedtapp.assign_impedance_to_sheet(ids, sourcename="ImpedanceToFaces", resistance=60, reactance=-20)
723+
assert imp2.name in self.aedtapp.modeler.get_boundaries_name()
724+
725+
rect2 = self.aedtapp.modeler.create_rectangle(
726+
self.aedtapp.PLANE.XY, [0, 0, 0], [10, 2], name="AniImpBound", matname="Copper"
727+
)
728+
assert not self.aedtapp.assign_impedance_to_sheet(rect2.name, "TL3", [50, 20, 0, 0], [25, 0, 5])
729+
imp2 = self.aedtapp.assign_impedance_to_sheet(rect2.name, "TL3", [50, 20, 0, 0], [25, 0, 5, 0])
730+
assert imp2.name in self.aedtapp.modeler.get_boundaries_name()
731+
imp3 = self.aedtapp.assign_impedance_to_sheet(impedance_box.top_face_z.id, "TL4", [50, 20, 0, 0], [25, 0, 5, 0])
732+
assert imp3.name in self.aedtapp.modeler.get_boundaries_name()
716733

717734
def test_17_create_lumpedrlc_on_sheets(self):
718735
rect = self.aedtapp.modeler.create_rectangle(

pyaedt/hfss.py

+128-9
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,18 @@ def field_setup_names(self):
226226
class BoundaryType(object):
227227
"""Creates and manages boundaries."""
228228

229-
(PerfectE, PerfectH, Aperture, Radiation, Impedance, LayeredImp, LumpedRLC, FiniteCond, Hybrid, FEBI) = range(
230-
0, 10
231-
)
229+
(
230+
PerfectE,
231+
PerfectH,
232+
Aperture,
233+
Radiation,
234+
Impedance,
235+
LayeredImp,
236+
LumpedRLC,
237+
FiniteCond,
238+
Hybrid,
239+
FEBI,
240+
) = range(0, 10)
232241

233242
@property
234243
def hybrid(self):
@@ -3633,8 +3642,8 @@ def assign_impedance_to_sheet(self, sheet_name, sourcename=None, resistance=50,
36333642
36343643
Parameters
36353644
----------
3636-
sheet_name : str
3637-
Name of the sheet to apply the boundary to.
3645+
sheet_name : str or list
3646+
Name of the sheet or list to apply the boundary to.
36383647
sourcename : str, optional
36393648
Name of the impedance. The default is ``None``.
36403649
resistance : optional
@@ -3675,17 +3684,127 @@ def assign_impedance_to_sheet(self, sheet_name, sourcename=None, resistance=50,
36753684
sourcename = generate_unique_name("Imped")
36763685
elif sourcename in self.modeler.get_boundaries_name():
36773686
sourcename = generate_unique_name(sourcename)
3687+
3688+
objects = self.modeler.convert_to_selections(sheet_name, True)
3689+
36783690
props = OrderedDict(
36793691
{
3680-
"Objects": [sheet_name],
3681-
"Resistance": str(resistance),
3682-
"Reactance": str(reactance),
3683-
"InfGroundPlane": is_infground,
3692+
"Faces": objects,
36843693
}
36853694
)
3695+
if isinstance(objects[0], str):
3696+
props = OrderedDict(
3697+
{
3698+
"Objects": objects,
3699+
}
3700+
)
3701+
props["Resistance"] = str(resistance)
3702+
props["Reactance"] = str(reactance)
3703+
props["InfGroundPlane"] = is_infground
3704+
36863705
return self._create_boundary(sourcename, props, "Impedance")
36873706
return False
36883707

3708+
@pyaedt_function_handler()
3709+
def assign_impedance_to_sheet(
3710+
self, sheet_name, sourcename=None, resistance=50.0, reactance=0.0, is_infground=False, reference_cs="Global"
3711+
):
3712+
"""Create an impedance taking one sheet.
3713+
3714+
Parameters
3715+
----------
3716+
sheet_name : str or list
3717+
Name of the sheet or list to apply the boundary to.
3718+
sourcename : str, optional
3719+
Name of the impedance. The default is ``None``.
3720+
resistance : float or list, optional
3721+
Resistance value in ohms. The default is ``50.0``.
3722+
If a list of four elements is passed, an anisotropic impedance is assigned with the following order,
3723+
[``Zxx``, ``Zxy``, ``Zyx``, ``Zyy``].
3724+
reactance : optional
3725+
Reactance value in ohms. The default is ``0.0``.
3726+
If a list of four elements is passed, an anisotropic impedance is assigned with the following order,
3727+
[``Zxx``, ``Zxy``, ``Zyx``, ``Zyy``].
3728+
is_infground : bool, optional
3729+
Whether the impedance is an infinite ground. The default is ``False``.
3730+
reference_cs : str, optional
3731+
Name of the coordinate system for the XY plane. The default is ``"Global"``.
3732+
This parameter is only used for anisotropic impedance assignment.
3733+
3734+
Returns
3735+
-------
3736+
:class:`pyaedt.modules.Boundary.BoundaryObject`
3737+
Boundary object if successful, ``False`` otherwise.
3738+
3739+
References
3740+
----------
3741+
3742+
>>> oModule.AssignImpedance
3743+
3744+
Examples
3745+
--------
3746+
3747+
Create a sheet and use it to create an impedance.
3748+
3749+
>>> sheet = hfss.modeler.create_rectangle(hfss.PLANE.XY,
3750+
... [0, 0, -90], [10, 2], name="ImpedanceSheet",
3751+
... matname="Copper")
3752+
>>> impedance_to_sheet = hfss.assign_impedance_to_sheet(sheet.name, "ImpedanceFromSheet", 100, 50)
3753+
3754+
Create a sheet and use it to create an anisotropic impedance.
3755+
3756+
>>> sheet = hfss.modeler.create_rectangle(hfss.PLANE.XY,
3757+
... [0, 0, -90], [10, 2], name="ImpedanceSheet",
3758+
... matname="Copper")
3759+
>>> anistropic_impedance_to_sheet = hfss.assign_impedance_to_sheet(sheet.name, "ImpedanceFromSheet",
3760+
... [377, 0, 0, 377], [0, 50, 0, 0])
3761+
3762+
"""
3763+
3764+
if self.solution_type in ["Modal", "Terminal", "Transient Network"]:
3765+
if not sourcename:
3766+
sourcename = generate_unique_name("Imped")
3767+
elif sourcename in self.modeler.get_boundaries_name():
3768+
sourcename = generate_unique_name(sourcename)
3769+
3770+
objects = self.modeler.convert_to_selections(sheet_name, True)
3771+
3772+
props = OrderedDict(
3773+
{
3774+
"Faces": objects,
3775+
}
3776+
)
3777+
if isinstance(objects[0], str):
3778+
props = OrderedDict(
3779+
{
3780+
"Objects": objects,
3781+
}
3782+
)
3783+
3784+
if isinstance(resistance, list) and isinstance(reactance, list):
3785+
if len(resistance) == 4 and len(reactance) == 4:
3786+
props["UseInfiniteGroundPlane"] = is_infground
3787+
props["CoordSystem"] = reference_cs
3788+
props["HasExternalLink"] = False
3789+
props["ZxxResistance"] = str(resistance[0])
3790+
props["ZxxReactance"] = str(reactance[0])
3791+
props["ZxyResistance"] = str(resistance[1])
3792+
props["ZxyReactance"] = str(reactance[1])
3793+
props["ZyxResistance"] = str(resistance[2])
3794+
props["ZyxReactance"] = str(reactance[2])
3795+
props["ZyyResistance"] = str(resistance[3])
3796+
props["ZyyReactance"] = str(reactance[3])
3797+
else:
3798+
self.logger.error("Number of elements in resistance and reactance must be four.")
3799+
return False
3800+
return self._create_boundary(sourcename, props, "Anisotropic Impedance")
3801+
else:
3802+
props["Resistance"] = str(resistance)
3803+
props["Reactance"] = str(reactance)
3804+
props["InfGroundPlane"] = is_infground
3805+
return self._create_boundary(sourcename, props, "Impedance")
3806+
return False
3807+
36893808
@pyaedt_function_handler()
36903809
def create_circuit_port_from_edges(
36913810
self,

0 commit comments

Comments
 (0)