|
| 1 | +""" |
| 2 | +Spiral Inductor Example |
| 3 | +----------------------- |
| 4 | +This example shows how you can use PyAEDT to create a spiral inductor, solve it and plot results. |
| 5 | +""" |
| 6 | +# sphinx_gallery_thumbnail_path = 'Resources/spiral.png' |
| 7 | + |
| 8 | +############################################################# |
| 9 | +# Import packages |
| 10 | +# |
| 11 | + |
| 12 | +import os |
| 13 | +import matplotlib.pyplot as plt |
| 14 | +from pyaedt import Hfss, constants |
| 15 | + |
| 16 | + |
| 17 | +############################################################# |
| 18 | +# Launch Hfss 2021.2 in non graphical mode. |
| 19 | +# Change units to micron |
| 20 | +hfss = Hfss(specified_version="2021.2", non_graphical=False, designname='A1') |
| 21 | +hfss.modeler.model_units = "um" |
| 22 | +p = hfss.modeler.primitives |
| 23 | + |
| 24 | +############################################################# |
| 25 | +# Input Variables. Edit it to change your inductor. |
| 26 | +# |
| 27 | +rin = 10 |
| 28 | +width = 2 |
| 29 | +spacing = 1 |
| 30 | +thickness = 1 |
| 31 | +Np = 8 |
| 32 | +Nr = 10 |
| 33 | +gap = 3 |
| 34 | +Tsub = 6 |
| 35 | + |
| 36 | + |
| 37 | +############################################################# |
| 38 | +# This method standardizes the usage of polyline in this |
| 39 | +# example by fixing the width, thickness and material. |
| 40 | +# |
| 41 | +def create_line(pts): |
| 42 | + p.create_polyline(pts, |
| 43 | + xsection_type='Rectangle', |
| 44 | + xsection_width=width, |
| 45 | + xsection_height=thickness, matname='copper') |
| 46 | + |
| 47 | + |
| 48 | +################################################################ |
| 49 | +# Here a spiral inductor is created. |
| 50 | +# Spiral is not parameteric but could be parametrized later on. |
| 51 | +# |
| 52 | + |
| 53 | +ind = hfss.modeler.create_spiral(internal_radius=rin, width=width, spacing=spacing, turns=Nr, faces=Np, |
| 54 | + thickness=thickness, material="copper", name="Inductor1") |
| 55 | + |
| 56 | + |
| 57 | +################################################################ |
| 58 | +# Center Return Path. |
| 59 | +# |
| 60 | + |
| 61 | +x0, y0, z0 = ind.points[0] |
| 62 | +x1, y1, z1 = ind.points[-1] |
| 63 | +create_line([(x0 - width / 2, y0, -gap), (abs(x1) + 5, y0, -gap)]) |
| 64 | +p.create_box((x0 - width / 2, y0 - width / 2, -gap - thickness / 2), |
| 65 | + (width, width, gap + thickness), |
| 66 | + matname='copper') |
| 67 | + |
| 68 | +################################################################ |
| 69 | +# Port 1 creation. |
| 70 | +# |
| 71 | +p.create_rectangle(constants.PLANE.YZ, |
| 72 | + (abs(x1) + 5, y0 - width / 2, -gap - thickness / 2), |
| 73 | + (width, -Tsub + gap), |
| 74 | + name='port1') |
| 75 | +hfss.create_lumped_port_to_sheet(sheet_name='port1', axisdir=constants.AXIS.Z) |
| 76 | + |
| 77 | + |
| 78 | +################################################################ |
| 79 | +# Port 2 creation. |
| 80 | +# |
| 81 | +create_line([(x1 + width / 2, y1, 0), (x1 - 5, y1, 0)]) |
| 82 | +p.create_rectangle(constants.PLANE.YZ, |
| 83 | + (x1 - 5, y1 - width / 2, -thickness / 2), |
| 84 | + (width, -Tsub), |
| 85 | + name='port2') |
| 86 | +hfss.create_lumped_port_to_sheet(sheet_name='port2', axisdir=constants.AXIS.Z) |
| 87 | + |
| 88 | + |
| 89 | +################################################################ |
| 90 | +# Silicon Substrate and Ground plane. |
| 91 | +# |
| 92 | +p.create_box([x1 - 20, x1 - 20, -Tsub - thickness / 2], |
| 93 | + [-2 * x1 + 40, -2 * x1 + 40, Tsub], |
| 94 | + matname='silicon') |
| 95 | + |
| 96 | +p.create_box([x1 - 20, x1 - 20, -Tsub - thickness / 2], |
| 97 | + [-2 * x1 + 40, -2 * x1 + 40, -0.1], |
| 98 | + matname='PEC') |
| 99 | + |
| 100 | +################################################################ |
| 101 | +# Airbox and radiation assignment. |
| 102 | +# |
| 103 | +box = p.create_box([x1 - 20, x1 - 20, -Tsub - thickness / 2 - 0.1], |
| 104 | + [-2 * x1 + 40, -2 * x1 + 40, 100], |
| 105 | + name='airbox', |
| 106 | + matname='air') |
| 107 | + |
| 108 | +hfss.assign_radiation_boundary_to_objects('airbox') |
| 109 | + |
| 110 | +################################################################ |
| 111 | +# Material override is needed to avoid validation check to fail. |
| 112 | +# |
| 113 | +hfss.change_material_override() |
| 114 | + |
| 115 | +################################################################ |
| 116 | +# Create a setup and define a frequency sweep. |
| 117 | +# Project will be solved after that. |
| 118 | + |
| 119 | +setup1 = hfss.create_setup(setupname='setup1') |
| 120 | +setup1.props['Frequency'] = '10GHz' |
| 121 | +hfss.create_linear_count_sweep('setup1', 'GHz', 1e-3, 50, 451, sweep_type="Interpolating") |
| 122 | +setup1.update() |
| 123 | +hfss.save_project() |
| 124 | +hfss.analyze_all() |
| 125 | + |
| 126 | +################################################################ |
| 127 | +# Get Report Data and plot it on matplotlib. |
| 128 | +# Inductance. |
| 129 | +L_formula = '1e9*im(1/Y(1,1))/(2*pi*freq)' |
| 130 | +x = hfss.post.get_report_data(L_formula) |
| 131 | + |
| 132 | +plt.plot(x.sweeps["Freq"], x.data_real(L_formula)) |
| 133 | + |
| 134 | +plt.grid() |
| 135 | +plt.xlabel('Freq') |
| 136 | +plt.ylabel('L(nH)') |
| 137 | +plt.show() |
| 138 | + |
| 139 | +plt.clf() |
| 140 | + |
| 141 | + |
| 142 | +################################################################ |
| 143 | +# Get Report Data and plot it on matplotlib. |
| 144 | +# Quality Factor. |
| 145 | + |
| 146 | +Q_formula = 'im(Y(1,1))/re(Y(1,1))' |
| 147 | +x = hfss.post.get_report_data(Q_formula) |
| 148 | +hfss.save_project() |
| 149 | + |
| 150 | +plt.plot(x.sweeps["Freq"], x.data_real(Q_formula)) |
| 151 | +plt.grid() |
| 152 | +plt.xlabel('Freq') |
| 153 | +plt.ylabel('Q') |
| 154 | +plt.show() |
| 155 | + |
| 156 | +################################################################ |
| 157 | +# Get Report Data and plot it on matplotlib. |
| 158 | +# Save and close the project. |
| 159 | + |
| 160 | +hfss.save_project() |
| 161 | +if os.name != "posix": |
| 162 | + hfss.release_desktop() |
0 commit comments