Skip to content

Commit

Permalink
temp_dir to temp_folder
Browse files Browse the repository at this point in the history
  • Loading branch information
gmalinve committed Aug 29, 2024
1 parent 4cbd837 commit 86a1be4
Show file tree
Hide file tree
Showing 70 changed files with 453 additions and 270 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ The following guidelines help ensure that the examples are consistent, easy to r
```
Create a temporary folder at the beginning of the example:
```
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
```
Remove the temporary folder at the end of the example:
```
temp_dir.cleanup()
temp_folder.cleanup()
```
- The examples should be formatted, so they are compatible with
[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
Expand Down
16 changes: 11 additions & 5 deletions examples/01-Modeling-Setup/Configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@
NG_MODE = False # Open Electronics UI when the application is launched.

# ## Create temporary directory
#
# Create temporary directory.
# If you'd like to retrieve the project data for subsequent use,
# the temporary folder name is given by ``temp_folder.name``.

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

# ## Download project

project_full_name = ansys.aedt.core.downloads.download_icepak(destination=temp_dir.name)
project_full_name = ansys.aedt.core.downloads.download_icepak(
destination=temp_folder.name
)

# ## Open project
#
Expand Down Expand Up @@ -118,7 +124,7 @@
#
# Create an Icepak project and import the step.

new_project = os.path.join(temp_dir.name, "example.aedt")
new_project = os.path.join(temp_folder.name, "example.aedt")
app = ansys.aedt.core.Icepak(version=AEDT_VERSION, project=new_project)
app.modeler.import_3d_cad(file_path)

Expand All @@ -140,9 +146,9 @@

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

temp_dir.cleanup()
temp_folder.cleanup()
15 changes: 10 additions & 5 deletions examples/01-Modeling-Setup/CoordinateSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@
AEDT_VERSION = "2024.2"
NG_MODE = False # Open Electronics UI when the application is launched.

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

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

# ## Launch AEDT

Expand All @@ -32,7 +37,7 @@
#
# Insert an HFSS design with the default name.

project_name = os.path.join(temp_dir.name, "CoordSysDemo.aedt")
project_name = os.path.join(temp_folder.name, "CoordSysDemo.aedt")
hfss = ansys.aedt.core.Hfss(version=AEDT_VERSION, project=project_name)

# ## Create coordinate system
Expand Down Expand Up @@ -289,7 +294,7 @@

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

temp_dir.cleanup()
temp_folder.cleanup()
15 changes: 10 additions & 5 deletions examples/01-Modeling-Setup/Optimetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@
AEDT_VERSION = "2024.2"
NG_MODE = False # Open Electronics UI when the application is launched.

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

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

# ## Initialize HFSS and create variables
#
# Initialize the ``Hfss`` object and create two needed design variables,
# ``w1`` and ``w2``.

# +
project_name = os.path.join(temp_dir.name, "optimetrics.aedt")
project_name = os.path.join(temp_folder.name, "optimetrics.aedt")

hfss = ansys.aedt.core.Hfss(
project=project_name,
Expand Down Expand Up @@ -151,9 +156,9 @@

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

temp_dir.cleanup()
temp_folder.cleanup()
15 changes: 10 additions & 5 deletions examples/01-Modeling-Setup/Polyline_Primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@
NG_MODE = False # Open Electronics UI when the application is launched.


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

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

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

project_name = os.path.join(temp_dir.name, "polyline.aedt")
project_name = os.path.join(temp_folder.name, "polyline.aedt")
maxwell = ansys.aedt.core.Maxwell3d(
project=project_name,
solution_type="Transient",
Expand Down Expand Up @@ -339,9 +344,9 @@

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

temp_dir.cleanup()
temp_folder.cleanup()
16 changes: 11 additions & 5 deletions examples/02-HFSS/Array.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,26 @@
NG_MODE = False # Open Electronics UI when the application is launched.

# ## Create temporary directory
#
# Create temporary directory.
# If you'd like to retrieve the project data for subsequent use,
# the temporary folder name is given by ``temp_folder.name``.

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

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

example_path = ansys.aedt.core.downloads.download_3dcomponent(destination=temp_dir.name)
example_path = ansys.aedt.core.downloads.download_3dcomponent(
destination=temp_folder.name
)

# ## Launch HFSS and open project
#
# Launch HFSS and open the project.

# +
project_name = os.path.join(temp_dir.name, "array.aedt")
project_name = os.path.join(temp_folder.name, "array.aedt")
hfss = ansys.aedt.core.Hfss(
project=project_name,
version=AEDT_VERSION,
Expand Down Expand Up @@ -170,9 +176,9 @@

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

temp_dir.cleanup()
temp_folder.cleanup()
18 changes: 11 additions & 7 deletions examples/02-HFSS/Create_3d_Component_and_use_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
AEDT_VERSION = "2024.2"
NG_MODE = False # Open Electronics UI when the application is launched.

# Create temporary directory
# ## Create temporary directory
#
# Create temporary directory.
# If you'd like to retrieve the project data for subsequent use,
# the temporary folder name is given by ``temp_folder.name``.

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

# Create an HFSS object.

Expand All @@ -37,7 +41,7 @@
close_on_exit=True,
non_graphical=NG_MODE,
)
hfss.save_project(os.path.join(temp_dir.name, "example.aedt"))
hfss.save_project(os.path.join(temp_folder.name, "example.aedt"))

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

component_path = os.path.join(temp_dir.name, "component_test.aedbcomp")
component_path = os.path.join(temp_folder.name, "component_test.aedbcomp")
hfss.modeler.create_3dcomponent(component_path, "patch_antenna")

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

new_project = os.path.join(temp_dir.name, "new_project.aedt")
new_project = os.path.join(temp_folder.name, "new_project.aedt")
hfss2 = Hfss(version=AEDT_VERSION, project=new_project, design="new_design")

# ## Insert 3D component
Expand Down Expand Up @@ -195,9 +199,9 @@

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

temp_dir.cleanup()
temp_folder.cleanup()
13 changes: 9 additions & 4 deletions examples/02-HFSS/Flex_CPWG.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@

non_graphical = False

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

temp_dir = tempfile.TemporaryDirectory(suffix="_ansys")
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

# ## Launch AEDT
#
Expand All @@ -42,7 +47,7 @@
non_graphical=non_graphical,
)
hfss.save_project(
os.path.join(temp_dir.name, generate_unique_name("example") + ".aedt")
os.path.join(temp_folder.name, generate_unique_name("example") + ".aedt")
)

# ## Design settings
Expand Down Expand Up @@ -246,4 +251,4 @@ def create_bending(radius, extension=0):

# ## Clean temporary directory

temp_dir.cleanup()
temp_folder.cleanup()
15 changes: 10 additions & 5 deletions examples/02-HFSS/HFSS_Choke.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
AEDT_VERSION = "2024.2"
NG_MODE = False # Open Electronics UI when the application is launched.

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

temp_dir = tempfile.TemporaryDirectory(suffix="_ansys")
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

# ## Launch HFSS

project_name = os.path.join(temp_dir.name, "choke.aedt")
project_name = os.path.join(temp_folder.name, "choke.aedt")
hfss = ansys.aedt.core.Hfss(
project=project_name,
version=AEDT_VERSION,
Expand Down Expand Up @@ -256,9 +261,9 @@

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

temp_dir.cleanup()
temp_folder.cleanup()
15 changes: 10 additions & 5 deletions examples/02-HFSS/HFSS_Dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
NUM_CORES = 4
NG_MODE = False # Open Electronics UI when the application is launched.

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

temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

# ## Launch AEDT

Expand All @@ -35,7 +40,7 @@
#
# Create a new HFSS design.

project_name = os.path.join(temp_dir.name, "dipole.aedt")
project_name = os.path.join(temp_folder.name, "dipole.aedt")
hfss = ansys.aedt.core.Hfss(
version=AEDT_VERSION, project=project_name, solution_type="Modal"
)
Expand Down Expand Up @@ -208,9 +213,9 @@

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

temp_dir.cleanup()
temp_folder.cleanup()
Loading

0 comments on commit 86a1be4

Please sign in to comment.