Skip to content

Commit

Permalink
Merge branch 'main' into feat/rpyc-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
dipinknair authored Aug 13, 2024
2 parents 49d9ec3 + 3df45cc commit 4ed770d
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 21 deletions.
45 changes: 33 additions & 12 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
contents: write
pull-requests: write
steps:
- uses: ansys/actions/doc-deploy-changelog@v6
- uses: ansys/actions/doc-deploy-changelog@v7
with:
token: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}

Expand All @@ -65,7 +65,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: PyAnsys code style checks
uses: ansys/actions/code-style@v6
uses: ansys/actions/code-style@v7
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}

Expand All @@ -74,7 +74,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: PyAnsys documentation style checks
uses: ansys/actions/doc-style@v6
uses: ansys/actions/doc-style@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
vale-version: "3.3.0"
Expand All @@ -95,7 +95,7 @@ jobs:
os: macos-latest
steps:
- name: Build wheelhouse and perform smoke test
uses: ansys/actions/build-wheelhouse@v6
uses: ansys/actions/build-wheelhouse@v7
with:
library-name: ${{ env.PACKAGE_NAME }}
operating-system: ${{ matrix.os }}
Expand Down Expand Up @@ -197,7 +197,7 @@ jobs:
echo "::endgroup::"
- name: Testing
uses: ansys/actions/tests-pytest@v6
uses: ansys/actions/tests-pytest@v7
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
pytest-markers: '-m remote_session_connect'
Expand Down Expand Up @@ -494,8 +494,29 @@ jobs:
apt install -y sudo curl lsb-release
apt install -y zip pandoc libgl1-mesa-glx mesa-utils xvfb texlive-latex-extra latexmk nodejs npm graphviz
apt install -y tini
apt install poppler-utils -y
npm install -g @mermaid-js/mermaid-cli
- name: Install gh cli
run: |
(type -p wget >/dev/null || (apt update && apt-get install wget -y)) \
&& mkdir -p -m 755 /etc/apt/keyrings \
&& wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
&& chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& apt update \
&& apt install gh -y
- name: Install quarto to build cheatsheet
run: |
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
gh release download --repo github.com/quarto-dev/quarto-cli --pattern *linux-amd64.deb
apt install ./quarto*linux-amd64.deb
quarto install tool tinytex --log-level warning
- name: Test quarto installation
run: quarto --version

- name: Install Python requirements
run: |
. /env/bin/activate
Expand Down Expand Up @@ -657,7 +678,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Build library source and wheel artifacts
uses: ansys/actions/build-library@v6
uses: ansys/actions/build-library@v7
with:
library-name: ${{ env.PACKAGE_NAME }}
python-version: ${{ env.MAIN_PYTHON_VERSION }}
Expand All @@ -669,14 +690,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Release to the public PyPI repository
uses: ansys/actions/release-pypi-public@v6
uses: ansys/actions/release-pypi-public@v7
with:
library-name: ${{ env.PACKAGE_NAME }}
twine-username: "__token__"
twine-token: ${{ secrets.PYPI_TOKEN }}

- name: Release to GitHub
uses: ansys/actions/release-github@v6
uses: ansys/actions/release-github@v7
with:
library-name: ${{ env.PACKAGE_NAME }}

Expand All @@ -687,7 +708,7 @@ jobs:
needs: [package]
steps:
- name: Deploy the latest documentation
uses: ansys/actions/doc-deploy-dev@v6
uses: ansys/actions/doc-deploy-dev@v7
with:
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -699,7 +720,7 @@ jobs:
needs: upload_dev_docs
steps:
- name: "Deploy the latest documentation index"
uses: ansys/actions/doc-deploy-index@v6
uses: ansys/actions/doc-deploy-index@v7
with:
cname: ${{ env.DOCUMENTATION_CNAME }}/version/dev
index-name: pymechanical-vdev
Expand All @@ -714,7 +735,7 @@ jobs:
needs: [release]
steps:
- name: Deploy the stable documentation
uses: ansys/actions/doc-deploy-stable@v6
uses: ansys/actions/doc-deploy-stable@v7
with:
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -740,7 +761,7 @@ jobs:
echo "VERSION_MEILI=$VERSION_MEILI" >> $GITHUB_ENV
- name: "Deploy the latest documentation index"
uses: ansys/actions/doc-deploy-index@v6
uses: ansys/actions/doc-deploy-index@v7
with:
cname: ${{ env.DOCUMENTATION_CNAME }}/version/${{ env.VERSION }}
index-name: pymechanical-v${{ env.VERSION_MEILI }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package_cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Delete untagged package versions"
uses: ansys/actions/hk-package-clean-untagged@v6
uses: ansys/actions/hk-package-clean-untagged@v7
with:
package-org: 'ansys'
package-name: 'mechanical'
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repos:
args: ["--ignore-words", "doc/styles/config/vocabularies/ANSYS/accept.txt", "-w"]

- repo: https://github.com/ansys/pre-commit-hooks
rev: v0.4.2
rev: v0.4.3
hooks:
- id: add-license-headers
args:
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/845.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FEAT: Update cheat sheet with quarto
1 change: 1 addition & 0 deletions doc/changelog.d/868.documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MAINT: Bump ansys/actions from 6 to 7
1 change: 1 addition & 0 deletions doc/changelog.d/869.documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MAINT: Bump matplotlib from 3.9.1 to 3.9.1.post1
1 change: 1 addition & 0 deletions doc/changelog.d/870.documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[pre-commit.ci] pre-commit autoupdate
1 change: 1 addition & 0 deletions doc/changelog.d/871.documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MAINT: Cheat sheet
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/
214 changes: 214 additions & 0 deletions doc/source/cheatsheet/cheat_sheet.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
---
title: PyMechanical cheat sheet
format: cheat_sheet-pdf
version: main
footer: PyMechanical
footerlinks:
- urls: 'https://mechanical.docs.pyansys.com/version/stable/'
text: Documentation
- urls: 'https://mechanical.docs.pyansys.com/version/stable/getting_started/index.html'
text: Getting started
- urls: 'https://mechanical.docs.pyansys.com/version/stable/examples/index.html'
text: Examples
- urls: 'https://mechanical.docs.pyansys.com/version/stable/user_guide_scripting/index.html'
text: Mechanical scripting
- urls: 'https://mechanical.docs.pyansys.com/version/stable/api/index.html'
text: API reference
- urls: 'https://mechanical.docs.pyansys.com/version/stable/kil/index.html'
text: Known issues and limitations
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
---

# Connect to Mechanical Remote session

## Launch and connect to session
```{python}
#| eval: false
# Launch an instance
from ansys.mechanical.core import launch_mechanical
mechanical = launch_mechanical()
```
## Launch Mechanical UI
```{python}
#| eval: false
mechanical = launch_mechanical(batch=False)
```
## Launch by version
Verify the license and version of Mechanical that is used:
```{python}
#| eval: false
print(mechanical)
```
Launch a specific version of Mechanical:
```{python}
#| eval: false
from ansys.mechanical.core import find_mechanical
wb_exe = find_mechanical(242)[0]
# 'Ansys Inc\\....\\winx64\\AnsysWBU.exe'
mechanical = launch_mechanical(
exec_file=wb_exe, verbose_mechanical=True,
batch=True
)
print(mechanical)
```
## Launch Mechanical using the CLI
```{python}
#| eval: false
ansys-mechanical -r 242 --port 10000 -g
```
## Manually connect to the Mechanical session
```{python}
#| eval: false
import ansys.mechanical.core as pymechanical
# Connect locally
mechanical = pymechanical.Mechanical(port=10000)
# Or
# Connect remotely, to the IP address or hostname
mechanical = pymechanical.Mechanical(
"192.168.0.1", port=10000
)
```
## Send commands to Mechanical
Run a single command:
```{python}
#| eval: false
result1 = mechanical.run_python_script("2+3")
result2 = mechanical.run_python_script(
"DataModel.Project.ProjectDirectory"
)
mechanical.run_python_script(
"Model.AddStaticStructuralAnalysis()"
)
```
Evaluate a block of commands:
```{python}
#| eval: false
# Import a material
commands = """
cu_mat_file_path = (
r'D:\Workdir\copper.xml'.replace("\\", "\\\\")
)
materials = Model.Materials
materials.Import(cu_mat__file_path)
"""
mechanical.run_python_script(commands)
```
## Execute a Python script:
```{python}
#| eval: false
mechanical.run_python_script_from_file(file_path)
```
## Import a Mechanical file and print the count of bodies:
```{python}
#| eval: false
file = r"D:\\Workdir\\bracket.mechdb"
command = f'DataModel.Project.Open("{file}")'
mechanical.run_python_script(command)
mechanical.run_python_script("""
allbodies = Model.GetChildren(
DataModelObjectCategory.Body, True)
""")
mechanical.run_python_script("allbodies.Count")
```
## Perform project-specific operations:
```{python}
#| eval: false
# Get the project directory
mechanical.project_directory
# List the files in the working directory.
mechanical.list_files()
# Save
mechanical.run_python_script(
"ExtAPI.DataModel.Project.Save(r'D:\\Workdir')")
# Log in two ways:
mechanical._log.info("This is a useful message.")
mechanical.log_message("INFO", "info message")
# Exit
mechanical.exit(force=True)
```

# Load a Mechanical embedded instance


## Start an instance of App
```{python}
#| eval: false
from ansys.mechanical.core import App
app = App(version=242)
print(app)
```
Extract and merge global API entry points:
```{python}
#| eval: false
# Extract global API entry points from Mechanical
# Merge them into your Python global variables
app.update_globals(globals())
```
Access entry points from Python:
```{python}
#| eval: false
ExtAPI # Application.ExtAPI
DataModel # Application.DataModel
Model # Application.DataModel.Project.Model
Tree # Application.DataModel.Tree
Graphics # Application.ExtAPI.Graphics
```
Import a file and print the count of bodies
```{python}
#| eval: false
file = r"D:\\Workdir\\bracket.mechdb"
app.open(file)
app.update_globals(globals())
allbodies = Model.GetChildren(
DataModelObjectCategory.Body, True)
print(allbodies.Count)
```
## Turn on warning logging:
```{python}
#| eval: false
import logging
from ansys.mechanical.core import App
from ansys.mechanical.core.embedding.logger
import Configuration,Logger
Configuration.configure(level=logging.WARNING,
to_stdout=True)
app = App(version=242)
Logger.error("Test Error Message")
```
## Visualize geometry in 3D:
```{python}
#| eval: false
# requires Mechanical version >= 24R2
app.plot()
```
## Print project structure as tree:
```{python}
#| eval: false
app.print_tree()
# print only 20 lines
app.print_tree(max_lines=20)
```

```{python}
#| eval: false
```
Loading

0 comments on commit 4ed770d

Please sign in to comment.