Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS: Add PyAEDT cheat sheet #5396

Merged
merged 10 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
sphinxopts: '-j auto --color -w build_errors.txt'
check-links: false
needs-quarto: true

smoke-tests:
name: Build wheelhouse and smoke tests
Expand Down
4 changes: 4 additions & 0 deletions doc/source/cheatsheet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!cheat_sheet.qmd
!.gitignore
/.quarto/
203 changes: 203 additions & 0 deletions doc/source/cheatsheet/cheat_sheet.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
---
title: PyAEDT cheat sheet
format: cheat_sheet-pdf
params:
version: main
footer: PyAEDT
footerlinks:
- urls: 'https://aedt.docs.pyansys.com/version/stable/'
text: Documentation
- urls: 'https://aedt.docs.pyansys.com/version/stable/Getting_started/index.html'
text: Getting started
- urls: 'https://examples.aedt.docs.pyansys.com/'
text: Examples
- urls: 'https://aedt.docs.pyansys.com/version/stable/User_guide/index.html'
text: User guide
- urls: 'https://aedt.docs.pyansys.com/version/stable/API/index.html'
text: API reference
execute:
# output: false
eval: false

latex-clean: true
jupyter:
jupytext:
text_representation:
extension: .qmd
format_name: quarto
format_version: '1.0'
jupytext_version: 1.16.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---

# Launch AEDT

Launch an AEDT application directly:

```{python}
#| eval: false
from ansys.aedt.core import Hfss
app = Hfss()
```

Open a Desktop session in graphical mode, open a project and connect to an active design:

```{python}
#| eval: false
from ansys.aedt.core import Desktop
desktop = Desktop(version="2024.2", new_desktop=True, non_graphical=False, close_on_exit=True)
app = desktop.load_project( project_file="project_path")
```

Open a Desktop session in non-graphical mode and create a new Maxwell 3D design:
```{python}
#| eval: false
from ansys.aedt.core import Desktop, Maxwell3d
desktop = Desktop(version="2024.2", new_desktop=True, non_graphical=True, close_on_exit=True)
app = Maxwell3d()
```

Connect to a running application with given project name and design name:
```{python}
#| eval: false
from ansys.aedt.core.generic.design_types import get_pyaedt_app
app = get_pyaedt_app(project_name="project_name", design="design_name")
```

# Close the active AEDT session

```{python}
#| eval: false
app.release_desktop(close_projects=True, close_on_exit=True)
```

# Work with variables

Create a variable that only applies to this design:
```{python}
#| eval: false
hfss["dim"] = "1mm"
```
Create a variable that applies at a project level:
```{python}
#| eval: false
hfss["$dim"] = "1mm"
```
Manage your variables:
```{python}
#| eval: false
hfss.variable_manager.variables
```

# Handle your materials

Add a new material with custom properties:
```{python}
#| eval: false
material = hfss.materials.add_material("my_mat")
material.permittivity = 3.5
material.conductivity = 450000
material.permeability = 1.5
```

# Create and manipulate geometry
Create a box and get object name:
```{python}
#| eval: false
box = hfss.modeler.create_box([1,1,1], [5,2,5], name="box", material="FR4_epoxy")
print(box.name)
```

Access edges or vertices data:
```{python}
#| eval: false
nb_edges = len(box.edges)
for edge in box.edges:
print(edge.segment_info)
nb_vertices = len(box.vertices)
for vertex in box.vertices:
print(vertex.position)
```

# Define the solution setup
```{python}
#| eval: false
setup = hfss.create_setup("MySetup")
setup.props["Frequency"] = "50MHz"
setup.props["MaximumPasses"] = 10
```

Access the parametric sweep:
```{python}
#| eval: false
hfss.parametrics
```

Access the optimizations:
```{python}
#| eval: false
hfss.optimizations
```

Analyze the solution setup
```{python}
#| eval: false
hfss.analyze(cores=4)
```

# Post processing
Post processing can be performed within and outside AEDT.

## Report in AEDT
Create "Mag_E" report in a polyline:
```{python}
#| eval: false
test_points = [["0mm", "0mm", "0mm"], ["100mm", "20mm", "0mm"], ["71mm", "71mm", "0mm"], ["0mm", "100mm", "0mm"]]
p1 = hfss.modeler.create_polyline(test_points)
report = hfss.post.reports_by_category.fields(
"Mag_E", setup.name + " : LastAdaptive", p1.name)
report.create()
```

## Graphic operations
Visualize graphics objects and plot data within AEDT
```{python}
#| eval: false
field_plot = hfss.post.create_fieldplot_volume(
["box"], "Mag_E")
image_path = field_plot.export_image(
r"C:\\workdir\\my_image.png")
```

Generate 2D/3D plots using third-party packages
```{python}
#| eval: false
hfss.post.plot_model_obj(objects=["box"], show_grid=True)
```

Get solution data
```{python}
#| eval: false
plot_data = hfss.get_traces_for_plot()
report = hfss.post.create_report(plot_data)
solution = report.get_solution_data()
plt = solution.plot(solution.expressions)
```

Generate PDF files using third-party packages
```{python}
#| eval: false
from ansys.aedt.core.visualization.plot.pdf import AnsysReport
pdf_report = AnsysReport(
project_name=hfss.project_name,
design_name=hfss.design_name)
pdf_report.create()
pdf_report.add_section()
pdf_report.add_chapter("HFSS Results")
pdf_report.add_text("This section contains plots.")
pdf_report.add_image(image_path)
pdf_report.save_pdf(file_path=r"C:\\workdir", file_name="report.pdf")
```
4 changes: 4 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ def setup(app):
"limite": 10,
"ignoreLocation": True,
},
"cheatsheet": {
"file": "cheatsheet/cheat_sheet.qmd",
"title": "PyAEDT cheat sheet",
},
}

# # Add button to download PDF
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ dotnet = [
]
doc = [
"ansys-sphinx-theme>=1.0.0,<1.3",
"jupyter",
"numpydoc>=1.5.0,<1.9",
"recommonmark",
"Sphinx>=7.1.0,<8.2",
Expand Down
Loading