Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1a89081
replace app.update_globals with App(globals=globals()) for most examples
klmcadams Feb 19, 2025
f077a37
update examples to use globals and bump pymechanical version
klmcadams Mar 31, 2025
c5643cf
bump main version to 3.12
klmcadams Mar 31, 2025
54d659e
fix Transaction import
klmcadams Apr 21, 2025
63275c1
update fracture_analysis_contact_debonding example
klmcadams Apr 21, 2025
b74f7c1
update harmonic acoustics example
klmcadams Apr 22, 2025
666816f
working example with renamed vars and using pathlib
klmcadams Apr 22, 2025
893f90a
make vars lowercase & use pathlib instead of os
klmcadams Apr 23, 2025
8ae008e
add set_camera_display_image and update_animation functions
klmcadams Apr 23, 2025
c4226b2
add type_checking and remove typehints
klmcadams Apr 24, 2025
8de224a
code style fix
klmcadams Apr 24, 2025
d9f6308
fix vieworientationtype
klmcadams Apr 24, 2025
6b02dfc
add functions to some examples
klmcadams Apr 25, 2025
58a5cde
add comments to examples
klmcadams Apr 30, 2025
c3a928b
update topology optimization comments
klmcadams Apr 30, 2025
dc97fd0
update comments in valve.py
klmcadams Apr 30, 2025
968cfc3
update contact wear simulation file
klmcadams May 7, 2025
bfb1ae8
update non linear analysis script
klmcadams May 7, 2025
2dfc6e2
update rotor blade inverse solve example
klmcadams May 12, 2025
e0a2736
adjust comments/sections
klmcadams May 13, 2025
6f2b83b
fix sections and wording
klmcadams May 13, 2025
60769d4
fix merge conflicts
klmcadams May 13, 2025
33a9490
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 13, 2025
05a7dba
address most suggestions
klmcadams May 20, 2025
31088fd
bump ansys-mechanical-core to 0.11.17
klmcadams May 28, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- main

env:
MAIN_PYTHON_VERSION: '3.11'
MAIN_PYTHON_VERSION: '3.12'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_cd_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- cron: "0 3 * * *"

env:
MAIN_PYTHON_VERSION: '3.11'
MAIN_PYTHON_VERSION: '3.12'
DEV_MAJOR_REV: '25'
DEV_MINOR_REV: '2'

Expand Down
39 changes: 21 additions & 18 deletions examples/00_tips/tips_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,41 @@
3D visualization
----------------

Visualize 3D imported geometry
The following example demonstrates how to visualize imported geometry in 3D.
"""

# %%
# Import necessary libraries
# ~~~~~~~~~~~~~~~~~~~~~~~~~~

# Import the necessary libraries
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from ansys.mechanical.core import App
from ansys.mechanical.core.examples import delete_downloads, download_file

# %%
# Embed mechanical and set global variables
# Initialize the embedded application
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

app = App()
app.update_globals(globals())
app = App(globals=globals())
print(app)


# %%
# Download and import geometry
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Download geometry
# Download and import the geometry file
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# %%
# Download the geometry file
geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding")

# %%
# Import geometry
# Define the model and import the geometry file
model = app.Model

geometry_import = Model.GeometryImportGroup.AddGeometryImport()
geometry_import = model.GeometryImportGroup.AddGeometryImport()
geometry_import.Import(geometry_path)

# %%
# Visualize in 3D
# ~~~~~~~~~~~~~~~
# Visualize the model in 3D
# ~~~~~~~~~~~~~~~~~~~~~~~~~

app.plot()

Expand All @@ -68,8 +68,11 @@
# This visualization is currently available only for geometry and on version 24R2 or later

# %%
# Cleanup
# ~~~~~~~
# Clean up the files and app
# ~~~~~~~~~~~~~~~~~~~~~~~~~~

# Delete the downloaded files
delete_downloads()
app.new()

# Close the app
app.close()
84 changes: 52 additions & 32 deletions examples/00_tips/tips_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,42 @@
Export image
------------

Export image and display
The following example demonstrates how to export an image of the imported geometry
and display it using matplotlib.
"""

# %%
# Import necessary libraries
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
# Import the necessary libraries
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import os
from pathlib import Path

from ansys.mechanical.core import App
from ansys.mechanical.core.examples import delete_downloads, download_file

# %%
# Embed Mechanical and set global variables
# Initialize the embedded application
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Create an instance of the App class
app = App()

# Update the global variables
app.update_globals(globals())
print(app)

# Print the app to ensure it is working
print(app)

# %%
# Download and import geometry
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Download geometry
# Download and import the geometry file
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# %%
# Download the geometry file
geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding")

# %%
# Import geometry
# Import the geometry file

geometry_import = Model.GeometryImportGroup.AddGeometryImport()
geometry_import.Import(geometry_path)
Expand All @@ -62,38 +69,48 @@
# Configure graphics for image export
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Orientation
Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso)
# Set the orientation of the camera
ExtAPI.Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso)

# Export format
# Set the image export format
image_export_format = GraphicsImageExportFormat.PNG

# Resolution and background
# Configure the export settings for the image
settings_720p = Ansys.Mechanical.Graphics.GraphicsImageExportSettings()
settings_720p.Resolution = GraphicsResolutionType.EnhancedResolution
settings_720p.Background = GraphicsBackgroundType.White
settings_720p.Width = 1280
settings_720p.Height = 720
settings_720p.CurrentGraphicsDisplay = False

# Rotate the geometry if needed
ExtAPI.Graphics.Camera.Rotate(180, CameraAxisType.ScreenY)

# Rotate the geometry on the Y-axis
Graphics.Camera.Rotate(180, CameraAxisType.ScreenY)

# %%
# Custom function for displaying the image
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create a function to display the image
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from matplotlib import image as mpimg
from matplotlib import pyplot as plt

# Temporary directory to save the image
cwd = os.path.join(os.getcwd(), "out")
# Directory to save the image
output_path = Path.cwd() / "out"


def display_image(image_name) -> None:
"""Display the image using matplotlib.

def display_image(image_name):
Parameters
----------
image_name : str
The name of the image file to display.
"""
# Create the full path to the image
image_path = output_path / image_name

# Plot the figure and display the image
plt.figure(figsize=(16, 9))
plt.imshow(mpimg.imread(os.path.join(cwd, image_name)))
plt.imshow(mpimg.imread(str(image_path)))
plt.xticks([])
plt.yticks([])
plt.axis("off")
Expand All @@ -104,19 +121,22 @@ def display_image(image_name):
# Export and display the image
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Fits the geometry in the viewing area
# Fit the geometry in the viewing area
Graphics.Camera.SetFit()

Graphics.ExportImage(
os.path.join(cwd, "geometry.png"), image_export_format, settings_720p
)
# Export the image
geometry_image = output_path / "geometry.png"
Graphics.ExportImage(str(geometry_image), image_export_format, settings_720p)

# Display the image using matplotlib
display_image("geometry.png")
# Display the image
display_image(geometry_image.name)

# %%
# Cleanup
# ~~~~~~~
# Clean up the downloaded files and app
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Delete the downloaded files
delete_downloads()
app.new()

# Close the app
app.close()
28 changes: 15 additions & 13 deletions examples/00_tips/tips_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,25 @@
""".. _ref_tips_03:

Project tree
--------------------
------------

Display the heirarchial Mechanical project structure.
The following example demonstrates how to print the heirarchial Mechanical project structure.
"""

# %%
# Import necessary libraries
# ~~~~~~~~~~~~~~~~~~~~~~~~~~

# Import the necessary libraries
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from ansys.mechanical.core import App
from ansys.mechanical.core.examples import delete_downloads, download_file

# %%
# Embed Mechanical and set global variables
# Initialize the embedded application
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

app = App()
app.update_globals(globals())
app = App(globals=globals())
print(app)


# %%
# Download the mechdb file
# ~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -65,12 +63,16 @@
# Display the tree only under the first analysis
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

app.print_tree(Model.Analyses[0])
first_analysis = app.Model.Analyses[0]
app.print_tree(first_analysis)


# %%
# Cleanup
# ~~~~~~~
# Clean up the downloaded files and app
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Delete the downloaded files
delete_downloads()
app.new()

# Close the app
app.close()
Loading