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

FEAT: Update cheat sheet with quarto #845

Merged
merged 38 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
68831b6
feat: migrate chatsheet with quarto
Revathyvenugopal162 Jul 23, 2024
e259cc9
test: check the cheatsheet file
Revathyvenugopal162 Jul 24, 2024
748fdf9
fix: theme options
Revathyvenugopal162 Jul 25, 2024
2a1f740
fix: update the thenme options
Revathyvenugopal162 Jul 31, 2024
800e0e3
Merge branch 'main' into feat/add-cheatsheet-quarto
Revathyvenugopal162 Jul 31, 2024
5917f00
Update doc/make.bat
Revathyvenugopal162 Jul 31, 2024
fb9c9aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 31, 2024
b598d66
chore: adding changelog file 845.added.md
pyansys-ci-bot Jul 31, 2024
0a2d818
fix: merge chnages
Revathyvenugopal162 Jul 31, 2024
ad91d72
Merge branch 'feat/add-cheatsheet-quarto' of https://github.com/ansys…
Revathyvenugopal162 Jul 31, 2024
1dbe9ab
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 31, 2024
0940cfa
fix: add actions
Revathyvenugopal162 Jul 31, 2024
7a38c2c
Merge branch 'feat/add-cheatsheet-quarto' of https://github.com/ansys…
Revathyvenugopal162 Jul 31, 2024
eca01e6
fix: actions
Revathyvenugopal162 Jul 31, 2024
8e8e1bc
fix: actions for quarto
Revathyvenugopal162 Jul 31, 2024
5ca3a36
fix: actions for quarto
Revathyvenugopal162 Jul 31, 2024
fc58eae
fix: update sytem dependency
Revathyvenugopal162 Jul 31, 2024
192be7b
remove old cheatsheet
dipinknair Jul 31, 2024
7eb2e88
install gh
dipinknair Jul 31, 2024
915ba49
install quatro
dipinknair Jul 31, 2024
13026c5
Merge branch 'main' into feat/add-cheatsheet-quarto
Revathyvenugopal162 Aug 5, 2024
e7440be
updated cheatsheet
dipinknair Aug 5, 2024
e73eb9a
Merge branch 'main' into feat/add-cheatsheet-quarto
Revathyvenugopal162 Aug 7, 2024
532a9c6
fix: test html
Revathyvenugopal162 Aug 7, 2024
151619e
fix: test poppler
Revathyvenugopal162 Aug 7, 2024
3b82d95
Merge branch 'main' into feat/add-cheatsheet-quarto
dipinknair Aug 12, 2024
8e4c8a1
update dependencies
dipinknair Aug 12, 2024
fb0f62e
update cheatsheet contents
dipinknair Aug 12, 2024
d89b76a
chore: adding changelog file 845.added.md
pyansys-ci-bot Aug 12, 2024
2a7f190
update cheatsheet layout
dipinknair Aug 12, 2024
3079da7
Merge branch 'feat/add-cheatsheet-quarto' of https://github.com/ansys…
dipinknair Aug 12, 2024
8d8f0c2
Merge branch 'main' into feat/add-cheatsheet-quarto
dipinknair Aug 12, 2024
1fb8268
Apply suggestions from code review
dipinknair Aug 12, 2024
a424fc6
Merge branch 'main' into feat/add-cheatsheet-quarto
dipinknair Aug 13, 2024
ee5c253
Update doc/source/conf.py
dipinknair Aug 13, 2024
3c1912e
Merge remote-tracking branch 'origin' into feat/add-cheatsheet-quarto
dipinknair Aug 13, 2024
fbef1f5
Merge branch 'feat/add-cheatsheet-quarto' of https://github.com/ansys…
dipinknair Aug 13, 2024
56f1043
Apply suggestions from code review
dipinknair Aug 13, 2024
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 doc/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if "%SPHINXBUILD%" == "" (
set SOURCEDIR=source
set BUILDDIR=_build
set LINKCHECKDIR=\%BUILDDIR%\linkcheck
set BUILD_EXAMPLES=1
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

if "%1" == "" goto help
if "%1" == "html-noplot" goto html-noplot
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: Pymechanical cheat sheet demo 1
format: cheat_sheet-pdf
version: 0.11.0
footer: Getting started with Pymechanical
footerlinks:
- urls: 'https://mechanical.docs.pyansys.com/version/stable/'
text: Pymechanical documentation
- urls: 'https://mechanical.docs.pyansys.com/version/stable/getting_started/index.html'
text: Pymechanical documentation - Getting started
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 Pymechanical

Launch a Pymechanical instance locally and exit it:

```{python}
# Launch an instance
from ansys.mechanical.core import launch_mechanical
mechanical = launch_mechanical()
# Exit the instance
mechanical.exit()
```

Specify a job name, number of processors, and working directory:

```{python}
#| eval: false
jname = 'user_jobname'
path = '<path of directory>'
mechanical = launch_mechanical(
nproc=2, run_location=path, jobname=jname)
```

Connect to an existing instance of mechanical at IP address 192.168.1.30 and port 50001:

```{python}
#| eval: false
mechanical = launch_mechanical(start_instance=False,
ip='192.168.1.30', port=50001)
```

Create and exit a pool of instances:

```{python}
#| echo: false
from ansys.mechanical.core import launch_mechanical
mechanical = launch_mechanical()
```

```{python}
#| eval: false
# Create a pool of 10 instances
from ansys.mechanical.core import mechanicalPool
pool = mechanicalPool(10)
# Exit the pool
pool.exit()
```

# Pymechanical commands

Pymechanical commands are Python statements that act as a wrapper for APDL commands.

For example, *ESEL, s, type, 1* is translated as:

```{python}
mechanical.esel('s', 'type', vmin=1)
```

Commands that start with * or / have these characters removed:

```{python}
#| eval: false
mechanical.prep7() # /PREP7
mechanical.get() # *GET
```

In cases where removing * or / causes conflicts with other commands, a prefix "slash" or "star" is added:

```{python}
#| eval: false
mechanical.solu() # SOLU
mechanical.slashsolu() # /SOLU

mechanical.vget() # VGET
mechanical.starvget() # *VGET
```

Convert an existing APDL script to Pymechanical format:

```{python}
#| eval: false
inputfile = 'ansys_inputfile.inp'
pyscript = 'pyscript.py'
mechanical.convert_script(inputfile, pyscript)
```

# mechanical class

Load a table from Python to mechanical:

```{python}
#| eval: false
mechanical.load_table(name="abc", array=create_5d_array)
```

Access from or write parameters to the mechanical database:

```{python}
#| eval: false
# Save a parameter to a NumPy array
nparray = mechanical.parameters['displ_load']
# Create a parameter from a NumPy array
mechanical.parameters['exp_disp'] = nparray
```

Access information using ``*GET`` and ``*VGET`` and store it in NumPy arrays:

```{python}
# Run *GET command and return a Python value
mechanical.get_value(entity='NODE', item1='COUNT')

# Run *VGET command and return a Python array
mechanical.get_array(entity='NODE', item1='NLIST')
```

# Mesh class
Store the finite element mesh as a VTK *UnstructuredGrid* data object:

```{python}
#| eval: false
grid = mechanical.mesh.grid
```

Save element and node numbers to Python arrays:

```{python}
# Get an array of the nodal coordinates
nodes = mechanical.mesh.nodes

# Save node numbers of selected nodes to an array
node_num = mechanical.mesh.nnum
# Save node numbers of all nodes to an array
node_num_all = mechanical.mesh.nnum_all

# Get element numbers of currently
# selected elements
elem_num = mechanical.mesh.enum
# Get all element numbers, including
# those not selected
elem_num_all = mechanical.mesh.enum_all
```

# Post-processing class
The *post_processing* class is used for plotting and saving results to NumPy arrays.

```{python}
#| eval: false
from ansys.mechanical.core import post_processing
mechanical.post1()
mechanical.set(1, 2)
# Plot the nodal equivalent stress
mechanical.post_processing.plot_nodal_eqv_stress()
# Save nodal equivalent stresses to a Python array
nod_eqv_stress = post_processing.nodal_eqv_stress()
# Plot contour legend using dictionary
mechanical.allsel()
sbar_kwargs = {"color": "black",
"title": "Equivalent Stress (psi)",
"vertical": False,
"n_labels": 6}
post_processing.plot_nodal_eqv_stress(
cpos='xy', background='white',
edge_color='black', show_edges=True,
scalar bar_args=sbar_kwargs, n_colors=9)
```
## References from Pymechanical documentation

- [Getting started](https://mechanical.docs.pyansys.com/version/stable/getting_started/index.html)
- [mechanical commands](https://mechanical.docs.pyansys.com/version/stable/mechanical_commands/index.html)
- [API reference](https://mechanical.docs.pyansys.com/version/stable/api/index.html)


```{python}
#| echo: false
mechanical.exit()
```
22 changes: 15 additions & 7 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"sphinx_design",
"sphinx_gallery.gen_gallery",
"sphinxemoji.sphinxemoji",
"sphinx_jinja",
]

# Intersphinx mapping
Expand Down Expand Up @@ -154,16 +155,18 @@
copybutton_prompt_text = r">>> ?|\.\.\. "
copybutton_prompt_is_regexp = True

build_examples = os.environ.get("BUILD_EXAMPLES", "1") == "1"

# -- Sphinx Gallery Options ---------------------------------------------------
sphinx_gallery_conf = {
# convert rst to md for ipynb
"pypandoc": True,
# path to your examples scripts
"examples_dirs": ["../../examples/"],
"examples_dirs": ["../../examples/"] if build_examples else [],
# path where to save gallery generated examples
"gallery_dirs": ["examples/gallery_examples"],
"gallery_dirs": ["examples/gallery_examples"] if build_examples else [],
# Pattern to search for example files
"filename_pattern": r"\.py",
"filename_pattern": r"\.py" if build_examples else r"$^",
# Remove the "Download all examples" button from the top level gallery
"download_all_examples": False,
# Sort gallery example by file name instead of number of lines (default)
Expand All @@ -180,7 +183,6 @@
# -- Options for HTML output -------------------------------------------------
html_short_title = html_title = "PyMechanical"
html_theme = "ansys_sphinx_theme"
html_logo = pyansys_logo_black
html_context = {
"github_user": "pyansys",
"github_repo": "pymechanical",
Expand Down Expand Up @@ -216,13 +218,12 @@
},
},
"cheatsheet": {
"url": "https://cheatsheets.docs.pyansys.com/pymechanical_cheat_sheet.pdf",
"file": "cheatsheet/cheat_sheet.qmd",
"title": "PyMechanical cheat sheet",
"thumbnail": "https://cheatsheets.docs.pyansys.com/pymechanical_cheat_sheet.png",
"needs_download": True,
},
"ansys_sphinx_theme_autoapi": {"project": project, "templates": "_templates/autoapi"},
"navigation_depth": 10,
"logo" :"pyansys"
}

# -- Options for HTMLHelp output ---------------------------------------------
Expand Down Expand Up @@ -316,3 +317,10 @@
linkcheck_ignore.append(
f"https://github.com/ansys/pymechanical/releases/tag/v{pymechanical.__version__}"
)

# # -- Declare the Jinja context -----------------------------------------------
jinja_contexts = {
"main_toctree": {
"build_examples": build_examples,
},
}
Loading