Skip to content

Commit 2b5294b

Browse files
FEAT: Add PyAEDT examples (#219)
* Skip example if launched in non graphical mode or from documentation build * Add thumbnail * Add thumbnail * Modify thumbnail * Add Circuit Hfss Icepak example * Add electrothermal * Add Virtual compliance * Add Virtual compliance * Import sys * Change design names * Update deprecataed warning * Update deprecated arguments * Update workdir * clean virtual compliance * temp_dir to temp_folder * fix Circuit_Hfss_Icepak_Coupling.py * # set constants -> # ## Define constants * jupyter clean up --------- Co-authored-by: Giulia Malinverno <giulia.malinverno@ansys.com>
1 parent dd5b2f9 commit 2b5294b

File tree

87 files changed

+1106
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1106
-483
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ The following guidelines help ensure that the examples are consistent, easy to r
3131
```
3232
Create a temporary folder at the beginning of the example:
3333
```
34-
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
34+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
3535
```
3636
Remove the temporary folder at the end of the example:
3737
```
38-
temp_dir.cleanup()
38+
temp_folder.cleanup()
3939
```
4040
- The examples should be formatted, so they are compatible with
4141
[jupytext](https://jupytext.readthedocs.io/en/latest/) using the [light format](https://jupytext.readthedocs.io/en/latest/formats-scripts.html#the-light-format) and can
15.7 KB
Loading
46.7 KB
Loading
57.9 KB
Loading
Loading

doc/source/conf.py

+3
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,16 @@ def setup(app):
385385
"examples/08-Circuit/Circuit_Siwave_Multizones": "_static/thumbnails/multizone.png",
386386
"examples/08-Circuit/Circuit_Subcircuit_Example": "_static/thumbnails/subcircuit.png",
387387
"examples/08-Circuit/Create_Netlist": "_static/thumbnails/netlist.png",
388+
"examples/08-Circuit/Virtual_Compliance": "_static/thumbnails/virtual_compliance_eye.png",
388389
"examples/09-Multiphysics/Circuit_HFSS_Icepak_Coupling": "_static/thumbnails/ring.png",
390+
"examples/09-Multiphysics/Maxwell_Icepak_Wireless_Charging": "_static/thumbnails/charging.png",
389391
"examples/10-EMIT/ComputeInterferenceType": "_static/thumbnails/interference.png",
390392
"examples/10-EMIT/ComputeProtectionLevels": "_static/thumbnails/protection.png",
391393
"examples/10-EMIT/EMIT_Example": "_static/thumbnails/emit.png",
392394
"examples/10-EMIT/EMIT_HFSS_Example": "_static/thumbnails/emit_hfss.png",
393395
"examples/11-twin_builder/static_rom_creation_and_visualization": "_static/thumbnails/static_rom.png",
394396
"examples/12-general/com_analysis": "_static/thumbnails/com_eye.png",
397+
"examples/12-general/convert_model_version": "_static/thumbnails/e3dcomp.png",
395398
}
396399
nbsphinx_custom_formats = {
397400
".py": ["jupytext.reads", {"fmt": ""}],

examples/01-Modeling-Setup/Configurations.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@
4343
NG_MODE = False # Open Electronics UI when the application is launched.
4444

4545
# ## Create temporary directory
46+
#
47+
# Create temporary directory.
48+
# If you'd like to retrieve the project data for subsequent use,
49+
# the temporary folder name is given by ``temp_folder.name``.
4650

47-
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
51+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
4852

4953
# ## Download project
5054

51-
project_full_name = ansys.aedt.core.downloads.download_icepak(destination=temp_dir.name)
55+
project_full_name = ansys.aedt.core.downloads.download_icepak(
56+
destination=temp_folder.name
57+
)
5258

5359
# ## Open project
5460
#
@@ -118,7 +124,7 @@
118124
#
119125
# Create an Icepak project and import the step.
120126

121-
new_project = os.path.join(temp_dir.name, "example.aedt")
127+
new_project = os.path.join(temp_folder.name, "example.aedt")
122128
app = ansys.aedt.core.Icepak(version=AEDT_VERSION, project=new_project)
123129
app.modeler.import_3d_cad(file_path)
124130

@@ -140,9 +146,9 @@
140146

141147
# ## Cleanup
142148
#
143-
# All project files are saved in the folder ``temp_dir.name``.
149+
# All project files are saved in the folder ``temp_folder.name``.
144150
# If you've run this example as a Jupyter notebook you
145151
# can retrieve those project files. The following cell removes
146152
# all temporary files, including the project folder.
147153

148-
temp_dir.cleanup()
154+
temp_folder.cleanup()

examples/01-Modeling-Setup/CoordinateSystem.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
AEDT_VERSION = "2024.2"
1919
NG_MODE = False # Open Electronics UI when the application is launched.
2020

21-
# ## Create temporary directory
21+
# ## Create temporary directory and download files
22+
#
23+
# Create a temporary directory where we store downloaded data or
24+
# dumped data.
25+
# If you'd like to retrieve the project data for subsequent use,
26+
# the temporary folder name is given by ``temp_folder.name``.
2227

23-
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
28+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
2429

2530
# ## Launch AEDT
2631

@@ -32,7 +37,7 @@
3237
#
3338
# Insert an HFSS design with the default name.
3439

35-
project_name = os.path.join(temp_dir.name, "CoordSysDemo.aedt")
40+
project_name = os.path.join(temp_folder.name, "CoordSysDemo.aedt")
3641
hfss = ansys.aedt.core.Hfss(version=AEDT_VERSION, project=project_name)
3742

3843
# ## Create coordinate system
@@ -289,7 +294,7 @@
289294

290295
# ## Cleanup
291296
#
292-
# All project files are saved in the folder ``temp_dir.name``. If you've run this example as a Jupyter notebook you
297+
# All project files are saved in the folder ``temp_folder.name``. If you've run this example as a Jupyter notebook you
293298
# can retrieve those project files. The following cell removes all temporary files, including the project folder.
294299

295-
temp_dir.cleanup()
300+
temp_folder.cleanup()

examples/01-Modeling-Setup/Optimetrics.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@
1919
AEDT_VERSION = "2024.2"
2020
NG_MODE = False # Open Electronics UI when the application is launched.
2121

22-
# ## Create temporary directory
22+
# ## Create temporary directory and download files
23+
#
24+
# Create a temporary directory where we store downloaded data or
25+
# dumped data.
26+
# If you'd like to retrieve the project data for subsequent use,
27+
# the temporary folder name is given by ``temp_folder.name``.
2328

24-
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
29+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
2530

2631
# ## Initialize HFSS and create variables
2732
#
2833
# Initialize the ``Hfss`` object and create two needed design variables,
2934
# ``w1`` and ``w2``.
3035

3136
# +
32-
project_name = os.path.join(temp_dir.name, "optimetrics.aedt")
37+
project_name = os.path.join(temp_folder.name, "optimetrics.aedt")
3338

3439
hfss = ansys.aedt.core.Hfss(
3540
project=project_name,
@@ -151,9 +156,9 @@
151156

152157
# ## Cleanup
153158
#
154-
# All project files are saved in the folder ``temp_dir.name``.
159+
# All project files are saved in the folder ``temp_folder.name``.
155160
# If you've run this example as a Jupyter notebook you
156161
# can retrieve those project files. The following cell removes
157162
# all temporary files, including the project folder.
158163

159-
temp_dir.cleanup()
164+
temp_folder.cleanup()

examples/01-Modeling-Setup/Polyline_Primitives.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@
1919
NG_MODE = False # Open Electronics UI when the application is launched.
2020

2121

22-
# ## Create temporary directory
22+
# ## Create temporary directory and download files
23+
#
24+
# Create a temporary directory where we store downloaded data or
25+
# dumped data.
26+
# If you'd like to retrieve the project data for subsequent use,
27+
# the temporary folder name is given by ``temp_folder.name``.
2328

24-
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
29+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
2530

2631
# ## Create Maxwell 3D object
2732
#
2833
# Create a `Maxwell3d` object and set the unit type to ``"mm"``.
2934

30-
project_name = os.path.join(temp_dir.name, "polyline.aedt")
35+
project_name = os.path.join(temp_folder.name, "polyline.aedt")
3136
maxwell = ansys.aedt.core.Maxwell3d(
3237
project=project_name,
3338
solution_type="Transient",
@@ -339,9 +344,9 @@
339344

340345
# ## Cleanup
341346
#
342-
# All project files are saved in the folder ``temp_dir.name``.
347+
# All project files are saved in the folder ``temp_folder.name``.
343348
# If you've run this example as a Jupyter notebook you
344349
# can retrieve those project files. The following cell removes
345350
# all temporary files, including the project folder.
346351

347-
temp_dir.cleanup()
352+
temp_folder.cleanup()

examples/02-HFSS/Array.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,26 @@
2525
NG_MODE = False # Open Electronics UI when the application is launched.
2626

2727
# ## Create temporary directory
28+
#
29+
# Create temporary directory.
30+
# If you'd like to retrieve the project data for subsequent use,
31+
# the temporary folder name is given by ``temp_folder.name``.
2832

29-
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
33+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
3034

3135
# ## Download 3D component
3236
# Download the 3D component that is needed to run the example.
3337

34-
example_path = ansys.aedt.core.downloads.download_3dcomponent(destination=temp_dir.name)
38+
example_path = ansys.aedt.core.downloads.download_3dcomponent(
39+
destination=temp_folder.name
40+
)
3541

3642
# ## Launch HFSS and open project
3743
#
3844
# Launch HFSS and open the project.
3945

4046
# +
41-
project_name = os.path.join(temp_dir.name, "array.aedt")
47+
project_name = os.path.join(temp_folder.name, "array.aedt")
4248
hfss = ansys.aedt.core.Hfss(
4349
project=project_name,
4450
version=AEDT_VERSION,
@@ -170,9 +176,9 @@
170176

171177
# ## Cleanup
172178
#
173-
# All project files are saved in the folder ``temp_dir.name``.
179+
# All project files are saved in the folder ``temp_folder.name``.
174180
# If you've run this example as a Jupyter notebook you
175181
# can retrieve those project files. The following cell
176182
# removes all temporary files, including the project folder.
177183

178-
temp_dir.cleanup()
184+
temp_folder.cleanup()

examples/02-HFSS/Create_3d_Component_and_use_it.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
AEDT_VERSION = "2024.2"
2626
NG_MODE = False # Open Electronics UI when the application is launched.
2727

28-
# Create temporary directory
28+
# ## Create temporary directory
29+
#
30+
# Create temporary directory.
31+
# If you'd like to retrieve the project data for subsequent use,
32+
# the temporary folder name is given by ``temp_folder.name``.
2933

30-
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
34+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
3135

3236
# Create an HFSS object.
3337

@@ -37,7 +41,7 @@
3741
close_on_exit=True,
3842
non_graphical=NG_MODE,
3943
)
40-
hfss.save_project(os.path.join(temp_dir.name, "example.aedt"))
44+
hfss.save_project(os.path.join(temp_folder.name, "example.aedt"))
4145

4246
# ## Variable definition
4347
#
@@ -121,14 +125,14 @@
121125
# Multiple options are available to partially select objects, cs, boundaries and mesh operations.
122126
# Furthermore, encrypted 3d comp can be created too.
123127

124-
component_path = os.path.join(temp_dir.name, "component_test.aedbcomp")
128+
component_path = os.path.join(temp_folder.name, "component_test.aedbcomp")
125129
hfss.modeler.create_3dcomponent(component_path, "patch_antenna")
126130

127131
# ## Multiple project management
128132
#
129133
# PyAEDT allows to control multiple projects, design and solution type at the same time.
130134

131-
new_project = os.path.join(temp_dir.name, "new_project.aedt")
135+
new_project = os.path.join(temp_folder.name, "new_project.aedt")
132136
hfss2 = Hfss(version=AEDT_VERSION, project=new_project, design="new_design")
133137

134138
# ## Insert 3D component
@@ -195,9 +199,9 @@
195199

196200
# ## Cleanup
197201
#
198-
# All project files are saved in the folder ``temp_dir.name``.
202+
# All project files are saved in the folder ``temp_folder.name``.
199203
# If you've run this example as a Jupyter notebook you
200204
# can retrieve those project files. The following cell removes
201205
# all temporary files, including the project folder.
202206

203-
temp_dir.cleanup()
207+
temp_folder.cleanup()

examples/02-HFSS/Flex_CPWG.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import ansys.aedt.core
1717
from ansys.aedt.core.generic.general_methods import generate_unique_name
1818

19-
# Set constant values
19+
# ## Define constants
2020

2121
AEDT_VERSION = "2024.2"
2222

@@ -27,9 +27,14 @@
2727

2828
non_graphical = False
2929

30-
# ## Create temporary directory
30+
# ## Create temporary directory and download files
31+
#
32+
# Create a temporary directory where we store downloaded data or
33+
# dumped data.
34+
# If you'd like to retrieve the project data for subsequent use,
35+
# the temporary folder name is given by ``temp_folder.name``.
3136

32-
temp_dir = tempfile.TemporaryDirectory(suffix="_ansys")
37+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
3338

3439
# ## Launch AEDT
3540
#
@@ -42,7 +47,7 @@
4247
non_graphical=non_graphical,
4348
)
4449
hfss.save_project(
45-
os.path.join(temp_dir.name, generate_unique_name("example") + ".aedt")
50+
os.path.join(temp_folder.name, generate_unique_name("example") + ".aedt")
4651
)
4752

4853
# ## Design settings
@@ -246,4 +251,4 @@ def create_bending(radius, extension=0):
246251

247252
# ## Clean temporary directory
248253

249-
temp_dir.cleanup()
254+
temp_folder.cleanup()

examples/02-HFSS/HFSS_Choke.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,23 @@
1515

1616
import ansys.aedt.core
1717

18-
# Set constant values
18+
# ## Define constants
1919

2020
AEDT_VERSION = "2024.2"
2121
NG_MODE = False # Open Electronics UI when the application is launched.
2222

23-
# ## Create temporary directory
23+
# ## Create temporary directory and download files
24+
#
25+
# Create a temporary directory where we store downloaded data or
26+
# dumped data.
27+
# If you'd like to retrieve the project data for subsequent use,
28+
# the temporary folder name is given by ``temp_folder.name``.
2429

25-
temp_dir = tempfile.TemporaryDirectory(suffix="_ansys")
30+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
2631

2732
# ## Launch HFSS
2833

29-
project_name = os.path.join(temp_dir.name, "choke.aedt")
34+
project_name = os.path.join(temp_folder.name, "choke.aedt")
3035
hfss = ansys.aedt.core.Hfss(
3136
project=project_name,
3237
version=AEDT_VERSION,
@@ -256,9 +261,9 @@
256261

257262
# ## Cleanup
258263
#
259-
# All project files are saved in the folder ``temp_dir.name``.
264+
# All project files are saved in the folder ``temp_folder.name``.
260265
# If you've run this example as a Jupyter notebook you
261266
# can retrieve those project files. The following cell
262267
# removes all temporary files, including the project folder.
263268

264-
temp_dir.cleanup()
269+
temp_folder.cleanup()

0 commit comments

Comments
 (0)