-
Notifications
You must be signed in to change notification settings - Fork 23
DOCS: Refactor examples #1260
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
Merged
+4,395
−384
Merged
DOCS: Refactor examples #1260
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
24dd359
refactor examples
dipinknair 9629302
chore: adding changelog file 1260.documentation.md [dependabot-skip]
pyansys-ci-bot 54213b7
update description
dipinknair 9af0afa
Merge branch 'doc/change' of https://github.com/ansys/pymechanical in…
dipinknair 1983d76
udpate doc dependencies
dipinknair 7bc2c52
include pv gallery building
dipinknair 1d3b1f7
update runner
dipinknair 6541721
revert cheatsheat build
dipinknair 051894a
increase shared memory
dipinknair 484a7cd
remove pdf and linkcheck
dipinknair e59f432
update sections
dipinknair 8b5d912
Merge branch 'main' into doc/change
dipinknair 6f35c49
terminate xvfb after each call
dipinknair 7ad509d
Merge branch 'doc/change' of https://github.com/ansys/pymechanical in…
dipinknair 3ee0ff7
remove pdf option add linkcheck seperately
dipinknair 659c3ac
missing a
dipinknair 20a7f76
add dependencies
dipinknair 7004e61
update link
dipinknair 957e14e
Merge branch 'main' into doc/change
dipinknair 76554d9
remove upload pdf
dipinknair 223c055
Merge branch 'doc/change' of https://github.com/ansys/pymechanical in…
dipinknair File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Refactor examples |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,27 @@ | ||
.. _ref_examples: | ||
|
||
======== | ||
Examples | ||
======== | ||
|
||
Here are examples using Mechanical with the ``ansys-mechanical-core`` library through | ||
an embedded instance or remote session. | ||
Here is a series of examples using Mechanical with the ``ansys-mechanical-core`` library. | ||
|
||
.. grid:: 1 2 2 2 | ||
.. === EXAMPLES Gallery === | ||
|
||
.. grid-item-card:: Embedding Examples | ||
:padding: 2 2 2 2 | ||
:link: https://embedding.examples.mechanical.docs.pyansys.com/examples/index.html | ||
.. | ||
We have to include this rather than include it in a tree. | ||
|
||
Uses PyMechanical to embed an instance of Mechanical directly within Python as a Python object. | ||
.. include:: gallery_examples/index.rst | ||
:start-line: 2 | ||
|
||
.. grid-item-card:: Remote Session Examples | ||
:padding: 2 2 2 2 | ||
:link: https://examples.mechanical.docs.pyansys.com/examples/index.html | ||
.. === REMOTE SESSIONS EXAMPLES === | ||
|
||
Uses PyMechanical as a client to a remote Mechanical instance. | ||
.. toctree:: | ||
:hidden: | ||
:maxdepth: 3 | ||
|
||
.. grid:: 1 | ||
Remote Sessions <https://examples.mechanical.docs.pyansys.com/index.html> | ||
|
||
.. grid-item-card:: Embedding Instance & Remote Session Example | ||
:padding: 2 2 2 2 | ||
:link: gallery_examples/embedding_n_remote/embedding_remote.html | ||
|
||
Demonstrates the same model setup in both an embedded instance and remote session, | ||
as well as examples using a combination of embedded instances and remote sessions. | ||
.. include:: remote_session_examples/index.rst | ||
:start-line: 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.. _ref_remote_session_examples: | ||
|
||
Remote session examples | ||
------------------------ | ||
|
||
Remote session examples demonstrate the basic simulation capabilities of Mechanical using remote sessions. | ||
|
||
For more information, see `Remote sessions examples <pymechanical_remote_ex_all_>`_. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
00_utilities/out/ | ||
01_basic/out/ | ||
02_advanced/out/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Utilities | ||
--------- | ||
|
||
This section showcases some of the useful functions that can be used | ||
with PyMechanical. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
""".. _ref_tips_01: | ||
|
||
3D visualization | ||
---------------- | ||
localtoc | ||
The following example demonstrates how to visualize imported geometry in 3D. | ||
""" | ||
|
||
# %% | ||
# Import the necessary libraries | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
from ansys.mechanical.core import App | ||
from ansys.mechanical.core.examples import delete_downloads, download_file | ||
|
||
# %% | ||
# Initialize the embedded application | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
app = App(globals=globals()) | ||
print(app) | ||
|
||
# %% | ||
# Download and import the geometry file | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
# %% | ||
# Download the geometry file | ||
geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding") | ||
|
||
# %% | ||
# Define the model and import the geometry file | ||
model = app.Model | ||
|
||
geometry_import = model.GeometryImportGroup.AddGeometryImport() | ||
geometry_import.Import(geometry_path) | ||
|
||
# %% | ||
# Visualize the model in 3D | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
app.plot() | ||
|
||
# %% | ||
# .. note:: | ||
# This visualization is currently available only for geometry and on version 24R2 or later | ||
|
||
# %% | ||
# Clean up the files and app | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
# Delete the downloaded files | ||
delete_downloads() | ||
|
||
# Close the app | ||
app.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
""".. _ref_tips_02: | ||
|
||
Export image | ||
------------ | ||
|
||
The following example demonstrates how to export an image of the imported geometry | ||
and display it using matplotlib. | ||
""" | ||
|
||
# %% | ||
# Import the necessary libraries | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
from pathlib import Path | ||
|
||
from ansys.mechanical.core import App | ||
from ansys.mechanical.core.examples import delete_downloads, download_file | ||
|
||
# %% | ||
# Initialize the embedded application | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
# Create an instance of the App class | ||
app = App(globals=globals()) | ||
|
||
# Print the app to ensure it is working | ||
print(app) | ||
|
||
# %% | ||
# Download and import the geometry file | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
# %% | ||
# Download the geometry file | ||
geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding") | ||
|
||
# %% | ||
# Import the geometry file | ||
|
||
geometry_import = Model.GeometryImportGroup.AddGeometryImport() | ||
geometry_import.Import(geometry_path) | ||
|
||
# %% | ||
# Configure graphics for image export | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
# Set the orientation of the camera | ||
ExtAPI.Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso) | ||
|
||
# Set the image export format | ||
image_export_format = GraphicsImageExportFormat.PNG | ||
|
||
# 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 on the Y-axis | ||
Graphics.Camera.Rotate(180, CameraAxisType.ScreenY) | ||
|
||
# %% | ||
# Create a function to display the image | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
from matplotlib import image as mpimg | ||
from matplotlib import pyplot as plt | ||
|
||
# Directory to save the image | ||
output_path = Path.cwd() / "out" | ||
|
||
|
||
def display_image(image_name) -> None: | ||
"""Display the image using matplotlib. | ||
|
||
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(str(image_path))) | ||
plt.xticks([]) | ||
plt.yticks([]) | ||
plt.axis("off") | ||
plt.show() | ||
|
||
|
||
# %% | ||
# Export and display the image | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
# Fit the geometry in the viewing area | ||
Graphics.Camera.SetFit() | ||
|
||
# Export the image | ||
geometry_image = output_path / "geometry.png" | ||
Graphics.ExportImage(str(geometry_image), image_export_format, settings_720p) | ||
|
||
# Display the image | ||
display_image(geometry_image.name) | ||
|
||
# %% | ||
# Clean up the downloaded files and app | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
# Delete the downloaded files | ||
delete_downloads() | ||
|
||
# Close the app | ||
app.close() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.