Skip to content

Commit 1c13572

Browse files
Convert to md format
02-HFSS
1 parent 008accc commit 1c13572

10 files changed

+375
-538
lines changed

examples/02-HFSS/Array.py

+37-50
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
1-
"""
2-
HFSS: component antenna array
3-
-----------------------------
4-
This example shows how you can use PyAEDT to create an example using a 3D component file. It sets up
5-
the analysis, solves it, and uses postprocessing functions to create plots using Matplotlib and
6-
PyVista without opening the HFSS user interface. This examples runs only on Windows using CPython.
7-
"""
8-
##########################################################
9-
# Perform required imports
10-
# ~~~~~~~~~~~~~~~~~~~~~~~~
1+
# # HFSS: component antenna array
2+
3+
# This example shows how you can use PyAEDT to create an example using a 3D component file. It sets up
4+
# the analysis, solves it, and uses postprocessing functions to create plots using Matplotlib and
5+
# PyVista without opening the HFSS user interface. This examples runs only on Windows using CPython.
6+
7+
8+
# ## Perform required imports
9+
#
1110
# Perform required imports.
1211

1312
import os
1413
import pyaedt
1514
from pyaedt.modules.solutions import FfdSolutionData
1615

17-
##########################################################
18-
# Set non-graphical mode
19-
# ~~~~~~~~~~~~~~~~~~~~~~
16+
# ## Set non-graphical mode
17+
#
2018
# Set non-graphical mode.
2119
# You can set ``non_graphical`` either to ``True`` or ``False``.
2220

2321
non_graphical = False
2422

25-
##########################################################
26-
# Download 3D component
27-
# ~~~~~~~~~~~~~~~~~~~~~
23+
# ## Download 3D component
24+
#
2825
# Download the 3D component that is needed to run the example.
2926
example_path = pyaedt.downloads.download_3dcomponent()
3027

31-
##########################################################
32-
# Launch HFSS and save project
33-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28+
# ## Launch HFSS and save project
29+
#
3430
# Launch HFSS and save the project.
31+
3532
project_name = pyaedt.generate_unique_project_name(project_name="array")
3633
hfss = pyaedt.Hfss(projectname=project_name,
3734
specified_version="2023.2",
@@ -41,9 +38,8 @@
4138

4239
print("Project name " + project_name)
4340

44-
##########################################################
45-
# Read array definition from JSON file
46-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41+
# ## Read array definition from JSON file
42+
#
4743
# Read the array definition from a JSON file. A JSON file
4844
# can contain all information needed to import and set up a
4945
# full array in HFSS.
@@ -57,9 +53,8 @@
5753
dict_in["cells"][(3, 3)] = {"name": "Circ_Patch_5GHz1"}
5854
array = hfss.add_3d_component_array_from_json(dict_in)
5955

60-
##########################################################
61-
# Modify cells
62-
# ~~~~~~~~~~~~
56+
# ## Modify cells
57+
#
6358
# Make center element passive and rotate corner elements.
6459

6560
array.cells[1][1].is_active = False
@@ -68,9 +63,8 @@
6863
array.cells[2][0].rotation = 90
6964
array.cells[2][2].rotation = 90
7065

71-
##########################################################
72-
# Set up simulation
73-
# ~~~~~~~~~~~~~~~~~
66+
# ## Set up simulation
67+
#
7468
# Set up a simulation and analyze it.
7569

7670
setup = hfss.create_setup()
@@ -79,27 +73,24 @@
7973

8074
hfss.analyze(num_cores=4)
8175

82-
##########################################################
83-
# Get far field data
84-
# ~~~~~~~~~~~~~~~~~~
76+
77+
# ## Get far field data
78+
#
8579
# Get far field data. After the simulation completes, the far
8680
# field data is generated port by port and stored in a data class.
8781

8882
ffdata = hfss.get_antenna_ffd_solution_data(sphere_name="Infinite Sphere1", setup_name=hfss.nominal_adaptive,
8983
frequencies=[5e9])
90-
91-
##########################################################
92-
# Generate contour plot
93-
# ~~~~~~~~~~~~~~~~~~~~~
84+
# ## Generate contour plot
85+
#
9486
# Generate a contour plot. You can define the Theta scan
9587
# and Phi scan.
9688

9789
ffdata.plot_farfield_contour(farfield_quantity='RealizedGain',
9890
title='Contour at {}Hz'.format(ffdata.frequency))
9991

100-
##########################################################
101-
# Release AEDT
102-
# ~~~~~~~~~~~~
92+
# ## Release AEDT
93+
#
10394
# Release AEDT.
10495
# Far field post-processing can be performed without AEDT because the data is stored.
10596

@@ -109,25 +100,22 @@
109100

110101
hfss.release_desktop()
111102

112-
##########################################################
113-
# Load far field data
114-
# ~~~~~~~~~~~~~~~~~~~
103+
# ## Load far field data
104+
#
115105
# Load far field data stored.
116106

117107
ffdata = FfdSolutionData(frequencies=frequencies[0], eep_files=eep_file[0])
118108

119-
##########################################################
120-
# Generate contour plot
121-
# ~~~~~~~~~~~~~~~~~~~~~
109+
# ## Generate contour plot
110+
#
122111
# Generate a contour plot. You can define the Theta scan
123112
# and Phi scan.
124113

125114
ffdata.plot_farfield_contour(farfield_quantity='RealizedGain',
126115
title='Contour at {}Hz'.format(ffdata.frequency))
127116

128-
##########################################################
129-
# Generate 2D cutout plots
130-
# ~~~~~~~~~~~~~~~~~~~~~~~~
117+
# ## Generate 2D cutout plots
118+
#
131119
# Generate 2D cutout plots. You can define the Theta scan
132120
# and Phi scan.
133121

@@ -141,9 +129,8 @@
141129
title='Elevation',
142130
quantity_format="dB10")
143131

144-
##########################################################
145-
# Generate 3D polar plots in Matplotlib
146-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132+
# ## Generate 3D polar plots in Matplotlib
133+
#
147134
# Generate 3D polar plots in Matplotlib. You can define
148135
# the Theta scan and Phi scan.
149136

examples/02-HFSS/Create_3d_Component_and_use_it.py

+56-69
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,126 @@
1-
"""
2-
Create a 3D Component and reuse it
3-
----------------------------------
4-
Summary of the workflow
5-
1. Create an antenna using PyAEDT and HFSS 3D Modeler (same can be done with EDB and HFSS 3D Layout)
6-
2. Store the object as a 3D Component on the disk
7-
3. Reuse the 3D component in another project
8-
4. Parametrize and optimize target design
9-
"""
10-
11-
##########################################################
12-
# Perform required imports
13-
# ~~~~~~~~~~~~~~~~~~~~~~~~
1+
# # Create a 3D Component and reuse it
2+
3+
# Summary of the workflow
4+
# 1. Create an antenna using PyAEDT and HFSS 3D Modeler (same can be done with EDB and HFSS 3D Layout)
5+
# 2. Store the object as a 3D Component on the disk
6+
# 3. Reuse the 3D component in another project
7+
# 4. Parametrize and optimize target design
8+
9+
# ## Perform required imports
10+
#
1411
# Perform required imports.
12+
1513
import os
1614
import tempfile
1715
from pyaedt import Hfss
1816
from pyaedt.generic.general_methods import generate_unique_name
1917

20-
##########################################################
21-
# Launch HFSS 2023.2
22-
# ~~~~~~~~~~~~~~~~~~
18+
# ## Launch HFSS 2023.2
19+
#
2320
# PyAEDT can initialize a new session of Electronics Desktop or connect to an existing one.
2421
# Once Desktop is connected, a new HFSS session is started and a design is created.
2522

2623
hfss = Hfss(specified_version="2023.2", new_desktop_session=True, close_on_exit=True)
2724

28-
##########################################################
29-
# Variables
30-
# ~~~~~~~~~
25+
# ## Variables
26+
#
3127
# PyAEDT can create and store all variables available in AEDT (Design, Project, Post Processing)
3228

3329
hfss["thick"] = "0.1mm"
3430
hfss["width"] = "1mm"
3531

36-
##########################################################
37-
# Modeler
38-
# ~~~~~~~~
32+
# ## Modeler
33+
#
3934
# PyAEDT supports all modeler functionalities available in the Desktop.
4035
# Objects can be created, deleted and modified using all available boolean operations.
4136
# History is also fully accessible to PyAEDT.
4237

43-
substrate = hfss.modeler.create_box(["-width","-width","-thick"],["2*width","2*width", "thick"], matname="FR4_epoxy", name="sub")
38+
# +
39+
substrate = hfss.modeler.create_box(["-width","-width","-thick"],["2*width","2*width", "thick"],
40+
matname="FR4_epoxy", name="sub")
4441

45-
patch = hfss.modeler.create_rectangle("XY",["-width/2","-width/2","0mm"],["width","width"], name="patch1")
42+
patch = hfss.modeler.create_rectangle("XY",["-width/2","-width/2","0mm"],["width","width"],
43+
name="patch1")
4644

47-
via1 = hfss.modeler.create_cylinder(2, ["-width/8","-width/4","-thick"],"0.01mm", "thick", matname="copper", name="via_inner")
45+
via1 = hfss.modeler.create_cylinder(2, ["-width/8","-width/4","-thick"],"0.01mm", "thick",
46+
matname="copper", name="via_inner")
4847

49-
via_outer = hfss.modeler.create_cylinder(2, ["-width/8","-width/4","-thick"],"0.025mm", "thick", matname="Teflon_based", name="via_teflon")
48+
via_outer = hfss.modeler.create_cylinder(2, ["-width/8","-width/4","-thick"],"0.025mm", "thick",
49+
matname="Teflon_based", name="via_teflon")
50+
# -
5051

51-
##########################################################
52-
# Boundaries
53-
# ~~~~~~~~~~
52+
# ## Boundaries
53+
#
5454
# Most of HFSS boundaries and excitations are already available in PyAEDT.
5555
# User can assign easily a boundary to a face or to an object by taking benefits of
5656
# Object-Oriented Programming (OOP) available in PyAEDT.
5757

5858
hfss.assign_perfecte_to_sheets(patch)
5959

60-
##########################################################
61-
# Advanced Modeler functions
62-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
63-
# Thanks to Python capabilities a lot of additional functionalities have been added to the Modeler of PyAEDT.
64-
# in this example there is a property to retrieve automatically top and bottom faces of an objects.
60+
# ## Advanced Modeler functions
61+
#
62+
# Thanks to Python capabilities a lot of additional functionalities have been added to the modeler of PyAEDT.
63+
# In this example there is a property to retrieve automatically top and bottom faces of an objects.
6564

65+
# +
6666
side_face = [i for i in via_outer.faces if i.id not in [via_outer.top_face_z.id, via_outer.bottom_face_z.id]]
6767

6868
hfss.assign_perfecte_to_sheets(side_face)
6969
hfss.assign_perfecte_to_sheets(substrate.bottom_face_z)
70+
# -
7071

71-
##########################################################
72-
# Create Wave Port
73-
# ~~~~~~~~~~~~~~~~
72+
# ## Create Wave Port
73+
#
7474
# Wave port can be assigned to a sheet or to a face of an object.
7575

7676
hfss.wave_port(via_outer.bottom_face_z, name="P1", )
7777

78-
##########################################################
79-
# Create 3D Component
80-
# ~~~~~~~~~~~~~~~~~~~
78+
# ## Create 3D Component
79+
#
8180
# Once the model is ready a 3D Component can be created.
8281
# Multiple options are available to partially select objects, cs, boundaries and mesh operations.
8382
# Furthermore, encrypted 3d comp can be created too.
8483

8584
component_path = os.path.join(tempfile.gettempdir(), generate_unique_name("component_test")+".aedbcomp")
8685
hfss.modeler.create_3dcomponent(component_path, "patch_antenna")
8786

88-
##########################################################
89-
# Multiple project management
90-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~
87+
# ## Multiple project management
88+
#
9189
# PyAEDT allows to control multiple projects, design and solution type at the same time.
9290

9391
hfss2 = Hfss(projectname="new_project", designname="new_design")
9492

95-
##########################################################
96-
# Insert of 3d component
97-
# ~~~~~~~~~~~~~~~~~~~~~~
93+
# ## Insert of 3d component
94+
#
9895
# The 3d component can be inserted without any additional info.
9996
# All needed info will be read from the file itself.
10097

10198
hfss2.modeler.insert_3d_component(component_path)
10299

103-
##########################################################
104-
# 3D Component Parameters
105-
# ~~~~~~~~~~~~~~~~~~~~~~~
100+
# ## 3D Component Parameters
101+
#
106102
# All 3d Component parameters are available and can be parametrized.
107103

108104
hfss2.modeler.user_defined_components["patch_antenna1"].parameters
109-
110105
hfss2["p_thick"] = "1mm"
111-
112106
hfss2.modeler.user_defined_components["patch_antenna1"].parameters["thick"]="p_thick"
113107

114-
##########################################################
115-
# Multiple 3d Components
116-
# ~~~~~~~~~~~~~~~~~~~~~~
108+
# ## Multiple 3d Components
109+
#
117110
# There is no limit to the number of 3D components that can be added on the same design.
118111
# They can be the same or linked to different files.
119112

120113
hfss2.modeler.create_coordinate_system(origin=[20, 20, 10], name="Second_antenna")
121-
122114
ant2 = hfss2.modeler.insert_3d_component(component_path, targetCS="Second_antenna")
123115

124-
##########################################################
125-
# Move components
126-
# ~~~~~~~~~~~~~~~
116+
# ## Move components
117+
#
127118
# The component can be moved by changing is position or moving the relative coordinate system.
128119

129120
hfss2.modeler.coordinate_systems[0].origin = [10, 10, 3]
130121

131-
##########################################################
132-
# Boundaries
133-
# ~~~~~~~~~~
122+
# ## Boundaries
123+
#
134124
# Most of HFSS boundaries and excitations are already available in PyAEDT.
135125
# User can assign easily a boundary to a face or to an object by taking benefits of
136126

@@ -142,22 +132,19 @@
142132
# All setup parameters can be edited.
143133

144134
setup1 = hfss2.create_setup()
145-
146135
optim = hfss2.parametrics.add("p_thick", "0.2mm", "1.5mm", step=14)
147136

148-
###############################################################################
149-
# Save project
150-
# ~~~~~~~~~~~~
137+
# ## Save project
138+
#
151139
# Save the project.
152140

153141
hfss2.modeler.fit_all()
154142
hfss2.plot(show=False, export_path=os.path.join(hfss.working_directory, "Image.jpg"), plot_air_objects=True)
155143

156-
###############################################################################
157-
# Close AEDT
158-
# ~~~~~~~~~~
144+
# ## Close AEDT
145+
#
159146
# After the simulation completes, you can close AEDT or release it using the
160-
# :func:`pyaedt.Desktop.release_desktop` method.
147+
# `pyaedt.Desktop.release_desktop` method.
161148
# All methods provide for saving the project before closing AEDT.
162149

163150
hfss2.save_project(os.path.join(tempfile.gettempdir(), generate_unique_name("parametrized")+".aedt"))

0 commit comments

Comments
 (0)