|
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 | +# |
14 | 11 | # Perform required imports. |
| 12 | + |
15 | 13 | import os |
16 | 14 | import tempfile |
17 | 15 | from pyaedt import Hfss |
18 | 16 | from pyaedt.generic.general_methods import generate_unique_name |
19 | 17 |
|
20 | | -########################################################## |
21 | | -# Launch HFSS 2023.2 |
22 | | -# ~~~~~~~~~~~~~~~~~~ |
| 18 | +# ## Launch HFSS 2023.2 |
| 19 | +# |
23 | 20 | # PyAEDT can initialize a new session of Electronics Desktop or connect to an existing one. |
24 | 21 | # Once Desktop is connected, a new HFSS session is started and a design is created. |
25 | 22 |
|
26 | 23 | hfss = Hfss(specified_version="2023.2", new_desktop_session=True, close_on_exit=True) |
27 | 24 |
|
28 | | -########################################################## |
29 | | -# Variables |
30 | | -# ~~~~~~~~~ |
| 25 | +# ## Variables |
| 26 | +# |
31 | 27 | # PyAEDT can create and store all variables available in AEDT (Design, Project, Post Processing) |
32 | 28 |
|
33 | 29 | hfss["thick"] = "0.1mm" |
34 | 30 | hfss["width"] = "1mm" |
35 | 31 |
|
36 | | -########################################################## |
37 | | -# Modeler |
38 | | -# ~~~~~~~~ |
| 32 | +# ## Modeler |
| 33 | +# |
39 | 34 | # PyAEDT supports all modeler functionalities available in the Desktop. |
40 | 35 | # Objects can be created, deleted and modified using all available boolean operations. |
41 | 36 | # History is also fully accessible to PyAEDT. |
42 | 37 |
|
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") |
44 | 41 |
|
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") |
46 | 44 |
|
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") |
48 | 47 |
|
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 | +# - |
50 | 51 |
|
51 | | -########################################################## |
52 | | -# Boundaries |
53 | | -# ~~~~~~~~~~ |
| 52 | +# ## Boundaries |
| 53 | +# |
54 | 54 | # Most of HFSS boundaries and excitations are already available in PyAEDT. |
55 | 55 | # User can assign easily a boundary to a face or to an object by taking benefits of |
56 | 56 | # Object-Oriented Programming (OOP) available in PyAEDT. |
57 | 57 |
|
58 | 58 | hfss.assign_perfecte_to_sheets(patch) |
59 | 59 |
|
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. |
65 | 64 |
|
| 65 | +# + |
66 | 66 | 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]] |
67 | 67 |
|
68 | 68 | hfss.assign_perfecte_to_sheets(side_face) |
69 | 69 | hfss.assign_perfecte_to_sheets(substrate.bottom_face_z) |
| 70 | +# - |
70 | 71 |
|
71 | | -########################################################## |
72 | | -# Create Wave Port |
73 | | -# ~~~~~~~~~~~~~~~~ |
| 72 | +# ## Create Wave Port |
| 73 | +# |
74 | 74 | # Wave port can be assigned to a sheet or to a face of an object. |
75 | 75 |
|
76 | 76 | hfss.wave_port(via_outer.bottom_face_z, name="P1", ) |
77 | 77 |
|
78 | | -########################################################## |
79 | | -# Create 3D Component |
80 | | -# ~~~~~~~~~~~~~~~~~~~ |
| 78 | +# ## Create 3D Component |
| 79 | +# |
81 | 80 | # Once the model is ready a 3D Component can be created. |
82 | 81 | # Multiple options are available to partially select objects, cs, boundaries and mesh operations. |
83 | 82 | # Furthermore, encrypted 3d comp can be created too. |
84 | 83 |
|
85 | 84 | component_path = os.path.join(tempfile.gettempdir(), generate_unique_name("component_test")+".aedbcomp") |
86 | 85 | hfss.modeler.create_3dcomponent(component_path, "patch_antenna") |
87 | 86 |
|
88 | | -########################################################## |
89 | | -# Multiple project management |
90 | | -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 87 | +# ## Multiple project management |
| 88 | +# |
91 | 89 | # PyAEDT allows to control multiple projects, design and solution type at the same time. |
92 | 90 |
|
93 | 91 | hfss2 = Hfss(projectname="new_project", designname="new_design") |
94 | 92 |
|
95 | | -########################################################## |
96 | | -# Insert of 3d component |
97 | | -# ~~~~~~~~~~~~~~~~~~~~~~ |
| 93 | +# ## Insert of 3d component |
| 94 | +# |
98 | 95 | # The 3d component can be inserted without any additional info. |
99 | 96 | # All needed info will be read from the file itself. |
100 | 97 |
|
101 | 98 | hfss2.modeler.insert_3d_component(component_path) |
102 | 99 |
|
103 | | -########################################################## |
104 | | -# 3D Component Parameters |
105 | | -# ~~~~~~~~~~~~~~~~~~~~~~~ |
| 100 | +# ## 3D Component Parameters |
| 101 | +# |
106 | 102 | # All 3d Component parameters are available and can be parametrized. |
107 | 103 |
|
108 | 104 | hfss2.modeler.user_defined_components["patch_antenna1"].parameters |
109 | | - |
110 | 105 | hfss2["p_thick"] = "1mm" |
111 | | - |
112 | 106 | hfss2.modeler.user_defined_components["patch_antenna1"].parameters["thick"]="p_thick" |
113 | 107 |
|
114 | | -########################################################## |
115 | | -# Multiple 3d Components |
116 | | -# ~~~~~~~~~~~~~~~~~~~~~~ |
| 108 | +# ## Multiple 3d Components |
| 109 | +# |
117 | 110 | # There is no limit to the number of 3D components that can be added on the same design. |
118 | 111 | # They can be the same or linked to different files. |
119 | 112 |
|
120 | 113 | hfss2.modeler.create_coordinate_system(origin=[20, 20, 10], name="Second_antenna") |
121 | | - |
122 | 114 | ant2 = hfss2.modeler.insert_3d_component(component_path, targetCS="Second_antenna") |
123 | 115 |
|
124 | | -########################################################## |
125 | | -# Move components |
126 | | -# ~~~~~~~~~~~~~~~ |
| 116 | +# ## Move components |
| 117 | +# |
127 | 118 | # The component can be moved by changing is position or moving the relative coordinate system. |
128 | 119 |
|
129 | 120 | hfss2.modeler.coordinate_systems[0].origin = [10, 10, 3] |
130 | 121 |
|
131 | | -########################################################## |
132 | | -# Boundaries |
133 | | -# ~~~~~~~~~~ |
| 122 | +# ## Boundaries |
| 123 | +# |
134 | 124 | # Most of HFSS boundaries and excitations are already available in PyAEDT. |
135 | 125 | # User can assign easily a boundary to a face or to an object by taking benefits of |
136 | 126 |
|
|
142 | 132 | # All setup parameters can be edited. |
143 | 133 |
|
144 | 134 | setup1 = hfss2.create_setup() |
145 | | - |
146 | 135 | optim = hfss2.parametrics.add("p_thick", "0.2mm", "1.5mm", step=14) |
147 | 136 |
|
148 | | -############################################################################### |
149 | | -# Save project |
150 | | -# ~~~~~~~~~~~~ |
| 137 | +# ## Save project |
| 138 | +# |
151 | 139 | # Save the project. |
152 | 140 |
|
153 | 141 | hfss2.modeler.fit_all() |
154 | 142 | hfss2.plot(show=False, export_path=os.path.join(hfss.working_directory, "Image.jpg"), plot_air_objects=True) |
155 | 143 |
|
156 | | -############################################################################### |
157 | | -# Close AEDT |
158 | | -# ~~~~~~~~~~ |
| 144 | +# ## Close AEDT |
| 145 | +# |
159 | 146 | # 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. |
161 | 148 | # All methods provide for saving the project before closing AEDT. |
162 | 149 |
|
163 | 150 | hfss2.save_project(os.path.join(tempfile.gettempdir(), generate_unique_name("parametrized")+".aedt")) |
|
0 commit comments