Skip to content
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
11 changes: 5 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,13 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# End of https://www.toptal.com/developers/gitignore/api/python
# VSCode
.vscode

PyMAPDL_Dev
doc/source/technology_showcase_examples/*.ipynb
doc/source/technology_showcase_examples/*.py
doc/source/technology_showcase_examples/*.md5
doc/source/technology_showcase_examples/*.pickle

# Results generated during doc build and example run locally
examples/technology_showcase/out
examples/basic/out
examples/basic/out
/out

Binary file removed doc/source/_static/basic/valve/Valve.mp4
Binary file not shown.
Binary file removed doc/source/_static/basic/valve/deformation.png
Binary file not shown.
Binary file removed doc/source/_static/basic/valve/geometry.png
Binary file not shown.
Binary file removed doc/source/_static/basic/valve/mesh.png
Binary file not shown.
Binary file removed doc/source/_static/basic/valve/stress.png
Binary file not shown.
10 changes: 8 additions & 2 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ Embedding examples for `PyMechanical <_pymechanical_docs>`_ are contained in thi

.. === EXAMPLES Gallery ===

.. === Include examples/index to avoid warning but it is not shown ===
..
We have to include this rather than include it in a tree.

.. include:: examples/index.rst
:start-line: 2


.. toctree::
:hidden:
:includehidden:

examples/index
examples/index
7 changes: 3 additions & 4 deletions examples/README.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.. _ref_example_gallery:

Examples
========
End-to-end examples show how you can use pymechanical.
=========

These end-to-end examples show how you can use ``ansys-mechanical-core``.

.. note::
Some examples require additional Python packages.
4 changes: 2 additions & 2 deletions examples/basic/readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Basic examples
================
Basic
======

This section demonstrates basic capabilities of PyMechanical
67 changes: 38 additions & 29 deletions examples/basic/valve.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import ansys.mechanical.core as mech
from ansys.mechanical.core.examples import delete_downloads, download_file
from matplotlib import image as mpimg
from matplotlib import pyplot as plt

# Embed Mechanical and set global variables
app = mech.App(version=232)
Expand All @@ -18,9 +20,22 @@
geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding")
analysis = Model.AddStaticStructuralAnalysis()

# Use matlabplotlib to display the images.
cwd = os.path.join(os.getcwd(), "out")


def display_image(image_name):
path = os.path.join(os.path.join(cwd, image_name))
image = mpimg.imread(path)
plt.figure(figsize=(15, 15))
plt.axis("off")
plt.imshow(image)
plt.show()


##############################################
# Configure graphics for image export
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ExtAPI.Graphics.Camera.SetSpecificViewOrientation(
Ansys.Mechanical.DataModel.Enums.ViewOrientationType.Iso
)
Expand Down Expand Up @@ -48,16 +63,15 @@
geometry_file, geometry_import_format, geometry_import_preferences
)

ExtAPI.Graphics.Camera.SetFit()
ExtAPI.Graphics.ExportImage(
os.path.join(cwd, "geometry.png"), image_export_format, settings_720p
)
###############################################################################
# Exported geometry
# ~~~~~~~~~~~~~~~~~
# .. image:: /_static/basic/valve/geometry.png

display_image("geometry.png")

# Assign materials
#########################
# Assign materials and mesh the geometry
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
material_assignment = Model.Materials.AddMaterialAssignment()
material_assignment.Material = "Structural Steel"
sel = ExtAPI.SelectionManager.CreateSelectionInfo(
Expand All @@ -79,13 +93,11 @@
ExtAPI.Graphics.ExportImage(
os.path.join(cwd, "mesh.png"), image_export_format, settings_720p
)
###############################################################################
# Meshing the geometry
# ---------------------
# .. image:: /_static/basic/valve/mesh.png
display_image("mesh.png")

###############################################################################
# Define boundary conditions

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fixed_support = analysis.AddFixedSupport()
fixed_support.Location = ExtAPI.DataModel.GetObjectsByName("NSFixedSupportFaces")[0]

Expand All @@ -106,47 +118,44 @@
config.SolveProcessSettings.DistributeSolution = False
Model.Solve()

###############################################################################
# Evaluate results
# -------------------------------------

###################################################################################
# Postprocessing
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Evaluate results, export screenshots
solution = analysis.Solution
deformation = solution.AddTotalDeformation()
stress = solution.AddEquivalentStress()
solution.EvaluateAllResults()

###################################################################################
# Deformation
Tree.Activate([deformation])
ExtAPI.Graphics.ExportImage(
os.path.join(cwd, "deformation.png"), image_export_format, settings_720p
)
display_image("deformation.png")

###################################################################################
# Stress
Tree.Activate([stress])
ExtAPI.Graphics.ExportImage(
os.path.join(cwd, "stress.png"), image_export_format, settings_720p
)
display_image("stress.png")

################################################
# Exported results
# ~~~~~~~~~~~~~~~
# .. image:: /_static/basic/valve/deformation.png
# .. image:: /_static/basic/valve/stress.png


###################################################################################
# Export stress animation
animation_export_format = (
Ansys.Mechanical.DataModel.Enums.GraphicsAnimationExportFormat.MP4
Ansys.Mechanical.DataModel.Enums.GraphicsAnimationExportFormat.GIF
)
settings_720p = Ansys.Mechanical.Graphics.AnimationExportSettings()
settings_720p.Width = 1280
settings_720p.Height = 720

stress.ExportAnimation(
os.path.join(cwd, "Valve.mp4"), animation_export_format, settings_720p
os.path.join(cwd, "Valve.gif"), animation_export_format, settings_720p
)

################################################
# Exported animation
# ~~~~~~~~~~~~~~~
# .. video:: /_static/basic/valve/Valve.mp4
display_image("Valve.gif")

# Save project
app.save(os.path.join(cwd, "Valve.mechdat"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

import ansys.mechanical.core as mech
from ansys.mechanical.core.examples import delete_downloads, download_file
from matplotlib import image as mpimg
from matplotlib import pyplot as plt

app = mech.App(version=232)
globals().update(mech.global_variables(app))
Expand All @@ -52,6 +54,19 @@
from Ansys.Mechanical.DataModel.Enums import *
from Ansys.Mechanical.DataModel.MechanicalEnums import *

# Use matlabplotlib to display the images.
cwd = os.path.join(os.getcwd(), "out")


def display_image(image_name):
path = os.path.join(os.path.join(cwd, image_name))
image = mpimg.imread(path)
plt.figure(figsize=(15, 15))
plt.axis("off")
plt.imshow(image)
plt.show()


###############################################################################
# Download required geometry files
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -121,6 +136,7 @@
ExtAPI.Graphics.ExportImage(
os.path.join(cwd, "geometry.png"), image_export_format, settings_720p
)
display_image("geometry.png")

###################################################################################
# Assign materials
Expand Down Expand Up @@ -469,10 +485,13 @@
ExtAPI.Graphics.ExportImage(
os.path.join(cwd, "deformation.png"), image_export_format, settings_720p
)
display_image("deformation.png")

Tree.Activate([EQV_STRS2])
ExtAPI.Graphics.ExportImage(
os.path.join(cwd, "stress.png"), image_export_format, settings_720p
)
display_image("stress.png")

###################################################################################
# Cleanup
Expand Down
4 changes: 2 additions & 2 deletions examples/technology_showcase/readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Technology showcase examples
=============================
Technology showcase
====================

Using technology showcase examples demonstrates embedding capabilities of PyMechanical.