Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing create_coaxial and create_waveguide in 2D Modeler #985

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
261 changes: 261 additions & 0 deletions pyaedt/modeler/Model3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import warnings

from pyaedt.generic.general_methods import pyaedt_function_handler
from pyaedt.generic.general_methods import generate_unique_name
from pyaedt.modeler.Modeler import GeometryModeler
from pyaedt.modeler.Primitives3D import Primitives3D

Expand Down Expand Up @@ -197,3 +198,263 @@ def create_3dcomponent(
arg3 = ["NAME:ImageFile", "ImageFile:=", ""]
self.oeditor.Create3DComponent(arg, arg2, component_file, arg3)
return True

@pyaedt_function_handler()
def create_coaxial(
self,
startingposition,
axis,
innerradius=1,
outerradius=2,
dielradius=1.8,
length=10,
matinner="copper",
matouter="copper",
matdiel="teflon_based",
):
"""Create a coaxial.

Parameters
----------
startingposition : list
List of ``[x, y, z]`` coordinates for the starting position.
axis : int
Coordinate system AXIS (integer ``0`` for X, ``1`` for Y, ``2`` for Z) or
the :class:`Application.CoordinateSystemAxis` enumerator.
innerradius : float, optional
Inner coax radius. The default is ``1``.
outerradius : float, optional
Outer coax radius. The default is ``2``.
dielradius : float, optional
Dielectric coax radius. The default is ``1.8``.
length : float, optional
Coaxial length. The default is ``10``.
matinner : str, optional
Material for the inner coaxial. The default is ``"copper"``.
matouter : str, optional
Material for the outer coaxial. The default is ``"copper"``.
matdiel : str, optional
Material for the dielectric. The default is ``"teflon_based"``.

Returns
-------
tuple
Contains the inner, outer, and dielectric coax as
:class:`pyaedt.modeler.Object3d.Object3d` objects.

References
----------

>>> oEditor.CreateCylinder
>>> oEditor.AssignMaterial


Examples
--------

This example shows how to create a Coaxial Along X Axis waveguide.

>>> from pyaedt import Hfss
>>> app = Hfss()
>>> position = [0,0,0]
>>> coax = app.modeler.create_coaxial(
... position, app.AXIS.X, innerradius=0.5, outerradius=0.8, dielradius=0.78, length=50
... )

"""
if not (outerradius > dielradius and dielradius > innerradius):
raise ValueError("Error in coaxial radius.")
inner = self.create_cylinder(axis, startingposition, innerradius, length, 0)
outer = self.create_cylinder(axis, startingposition, outerradius, length, 0)
diel = self.create_cylinder(axis, startingposition, dielradius, length, 0)
self.subtract(outer, inner)
self.subtract(outer, diel)
inner.material_name = matinner
outer.material_name = matouter
diel.material_name = matdiel

return inner, outer, diel

@pyaedt_function_handler()
def create_waveguide(
self,
origin,
wg_direction_axis,
wgmodel="WG0",
wg_length=100,
wg_thickness=None,
wg_material="aluminum",
parametrize_w=False,
parametrize_h=False,
create_sheets_on_openings=False,
name=None,
):
"""Create a standard waveguide and optionally parametrize `W` and `H`.

Available models are WG0.0, WG0, WG1, WG2, WG3, WG4, WG5, WG6,
WG7, WG8, WG9, WG9A, WG10, WG11, WG11A, WG12, WG13, WG14,
WG15, WR102, WG16, WG17, WG18, WG19, WG20, WG21, WG22, WG24,
WG25, WG26, WG27, WG28, WG29, WG29, WG30, WG31, and WG32.

Parameters
----------
origin : list
List of ``[x, y, z]`` coordinates for the original position.
wg_direction_axis : int
Coordinate system axis (integer ``0`` for X, ``1`` for Y, ``2`` for Z) or
the :class:`Application.CoordinateSystemAxis` enumerator.
wgmodel : str, optional
Waveguide model. The default is ``"WG0"``.
wg_length : float, optional
Waveguide length. The default is ``100``.
wg_thickness : float, optional
Waveguide thickness. The default is ``None``, in which case the
thickness is `wg_height/20`.
wg_material : str, optional
Waveguide material. The default is ``"aluminum"``.
parametrize_w : bool, optional
Whether to parametrize `W`. The default is ``False``.
parametrize_h : bool, optional
Whether to parametrize `H`. The default is ``False``.
create_sheets_on_openings : bool, optional
Whether to create sheets on both openings. The default is ``False``.
name : str, optional
Name of the waveguide. The default is ``None``.

Returns
-------
tuple
Tuple of :class:`Object3d <pyaedt.modeler.Object3d.Object3d>`
objects created by the waveguide.

References
----------

>>> oEditor.CreateBox
>>> oEditor.AssignMaterial


Examples
--------

This example shows how to create a WG9 waveguide.

>>> from pyaedt import Hfss
>>> app = Hfss()
>>> position = [0, 0, 0]
>>> wg1 = app.modeler.create_waveguide(position, app.AXIS.,
... wgmodel="WG9", wg_length=2000)


"""
p1 = -1
p2 = -1
WG = {
"WG0.0": [584.2, 292.1],
"WG0": [533.4, 266.7],
"WG1": [457.2, 228.6],
"WG2": [381, 190.5],
"WG3": [292.1, 146.05],
"WG4": [247.65, 123.825],
"WG5": [195.58, 97.79],
"WG6": [165.1, 82.55],
"WG7": [129.54, 64.77],
"WG8": [109.22, 54.61],
"WG9": [88.9, 44.45],
"WG9A": [86.36, 43.18],
"WG10": [72.136, 34.036],
"WG11": [60.2488, 28.4988],
"WG11A": [58.166, 29.083],
"WG12": [47.5488, 22.1488],
"WG13": [40.386, 20.193],
"WG14": [34.8488, 15.7988],
"WG15": [28.4988, 12.6238],
"WR102": [25.908, 12.954],
"WG16": [22.86, 10.16],
"WG17": [19.05, 9.525],
"WG18": [15.7988, 7.8994],
"WG19": [12.954, 6.477],
"WG20": [0.668, 4.318],
"WG21": [8.636, 4.318],
"WG22": [7.112, 3.556],
"WG23": [5.6896, 2.8448],
"WG24": [4.7752, 2.3876],
"WG25": [3.7592, 1.8796],
"WG26": [3.0988, 1.5494],
"WG27": [2.54, 1.27],
"WG28": [2.032, 1.016],
"WG29": [1.651, 0.8255],
"WG30": [1.2954, 0.6477],
"WG31": [1.0922, 0.5461],
"WG32": [0.8636, 0.4318],
}

if wgmodel in WG:
wgwidth = WG[wgmodel][0]
wgheight = WG[wgmodel][1]
if not wg_thickness:
wg_thickness = wgheight / 20
if parametrize_h:
self._app[wgmodel + "_H"] = self._arg_with_dim(wgheight)
h = wgmodel + "_H"
hb = wgmodel + "_H + 2*" + self._arg_with_dim(wg_thickness)
else:
h = self._arg_with_dim(wgheight)
hb = self._arg_with_dim(wgheight) + " + 2*" + self._arg_with_dim(wg_thickness)

if parametrize_w:
self._app[wgmodel + "_W"] = self._arg_with_dim(wgwidth)
w = wgmodel + "_W"
wb = wgmodel + "_W + " + self._arg_with_dim(2 * wg_thickness)
else:
w = self._arg_with_dim(wgwidth)
wb = self._arg_with_dim(wgwidth) + " + 2*" + self._arg_with_dim(wg_thickness)
if wg_direction_axis == self._app.AXIS.Z:
airbox = self.create_box(origin, [w, h, wg_length])

if type(wg_thickness) is str:
origin[0] = str(origin[0]) + "-" + wg_thickness
origin[1] = str(origin[1]) + "-" + wg_thickness
else:
origin[0] -= wg_thickness
origin[1] -= wg_thickness

elif wg_direction_axis == self._app.AXIS.Y:
airbox = self.create_box(origin, [w, wg_length, h])

if type(wg_thickness) is str:
origin[0] = str(origin[0]) + "-" + wg_thickness
origin[2] = str(origin[2]) + "-" + wg_thickness
else:
origin[0] -= wg_thickness
origin[2] -= wg_thickness
else:
airbox = self.create_box(origin, [wg_length, w, h])

if type(wg_thickness) is str:
origin[2] = str(origin[2]) + "-" + wg_thickness
origin[1] = str(origin[1]) + "-" + wg_thickness
else:
origin[2] -= wg_thickness
origin[1] -= wg_thickness
centers = [f.center for f in airbox.faces]
posx = [i[wg_direction_axis] for i in centers]
mini = posx.index(min(posx))
maxi = posx.index(max(posx))
if create_sheets_on_openings:
p1 = self.create_object_from_face(airbox.faces[mini].id)
p2 = self.create_object_from_face(airbox.faces[maxi].id)
if not name:
name = generate_unique_name(wgmodel)
if wg_direction_axis == self._app.AXIS.Z:
wgbox = self.create_box(origin, [wb, hb, wg_length], name=name)
elif wg_direction_axis == self._app.AXIS.Y:
wgbox = self.create_box(origin, [wb, wg_length, hb], name=name)
else:
wgbox = self.create_box(origin, [wg_length, wb, hb], name=name)
self.subtract(wgbox, airbox, False)
wgbox.material_name = wg_material

return wgbox, p1, p2
else:
return None
Loading