Skip to content

Commit 08d5bbd

Browse files
gmalinveDevin-CrawfordSamuelopez-ansys
authored
add template (#215)
* add template * Minor updates Minor update to README.md and template.py --------- Co-authored-by: Devin <devin.crawford@ansys.com> Co-authored-by: Samuel Lopez <85613111+Samuelopez-ansys@users.noreply.github.com>
1 parent a6d152a commit 08d5bbd

File tree

2 files changed

+92
-3
lines changed

2 files changed

+92
-3
lines changed

README.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,17 @@ The following guidelines help ensure that the examples are consistent, easy to r
3737
```
3838
temp_dir.cleanup()
3939
```
40-
- The examples should be formatted, so they are compatible with jupytext using the [light format](https://jupytext.readthedocs.io/en/latest/formats-scripts.html#the-light-format) and can
41-
be rendered and run in [Jupyter Lab](https://docs.jupyter.org/en/latest/) as Notebook files. Jupyter can be used to ensure correct rendering of markdown, images, and equations.
40+
- The examples should be formatted, so they are compatible with
41+
[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
42+
be rendered and run in [Jupyter Lab](https://docs.jupyter.org/en/latest/) as Notebook files. Jupyter can be used to ensure correct
43+
rendering of markdown, images, and equations.
4244
```
4345
pip install .[doc]
4446
jupyter lab
4547
```
46-
Notebook files can be opened, edited and run from within Jupyter using _right click > Open With > Jupytext Notebook_.
48+
- You can use this [template](./examples/template.py) to help you start creating a new example
49+
for publication here.
50+
51+
If you're creating an example for publication here, you can open
52+
the file and render it from within Jupyter
53+
using _right click > Open With > Jupytext Notebook_.

examples/template.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# # Short, Descriptive Title (do not specify the application name here, i.e.: Maxwell2D, Maxwell3D etc)
2+
#
3+
# Description:
4+
#
5+
# Most examples can be described as a series of steps that comprise a workflow.
6+
# 1. Import packages and instantiate the application.
7+
# 2. Do something useful and interesting.
8+
# 3. View the results.
9+
#
10+
# Keywords: **Template**, **Jupyter**
11+
12+
# ## Perform required imports
13+
#
14+
# Perform required imports.
15+
16+
import os
17+
import tempfile
18+
import time
19+
20+
import ansys.aedt.core
21+
22+
# ## Define constants
23+
24+
AEDT_VERSION = "2024.2"
25+
NUM_CORES = 4
26+
NG_MODE = False # Open Electronics UI when the application is launched.
27+
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``.
33+
34+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
35+
36+
# ## Launch AEDT and application
37+
#
38+
# Create an instance of the application (i.e. ``Maxwell3d``,``Hfss`` etc)
39+
# class named (``m3d``,``hfss`` etc.) by providing
40+
# the project and design names, the solver, and the version.
41+
42+
project_name = os.path.join(temp_folder.name, "my_project.aedt")
43+
m3d = ansys.aedt.core.Maxwell3d(
44+
project=project_name,
45+
design="my_design",
46+
solution_type="my_solver",
47+
version=AEDT_VERSION,
48+
non_graphical=NG_MODE,
49+
new_desktop=True,
50+
)
51+
m3d.modeler.model_units = "mm"
52+
53+
# ## Pre-Processing
54+
#
55+
# Description of pre-processing task.
56+
# Add as many sections as needed for pre-processing tasks.
57+
58+
59+
60+
# ## Post-Processing
61+
#
62+
# Description of post-processing task.
63+
# Add as many sections as needed for post-processing tasks.
64+
65+
66+
67+
68+
# ## Release AEDT
69+
70+
m3d.save_project()
71+
m3d.release_desktop()
72+
# Wait 3 seconds to allow Electronics Desktop to shut down before cleaning the temporary directory.
73+
time.sleep(3)
74+
75+
# ## Cleanup
76+
#
77+
# All project files are saved in the folder ``temp_dir.name``.
78+
# If you've run this example as a Jupyter notebook you
79+
# can retrieve those project files. The following cell
80+
# removes all temporary files, including the project folder.
81+
82+
temp_folder.cleanup()

0 commit comments

Comments
 (0)