diff --git a/.gitignore b/.gitignore index d43053c0..c6480381 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file +examples/basic/out +/out + diff --git a/doc/source/_static/basic/valve/Valve.mp4 b/doc/source/_static/basic/valve/Valve.mp4 deleted file mode 100644 index 048aba6b..00000000 Binary files a/doc/source/_static/basic/valve/Valve.mp4 and /dev/null differ diff --git a/doc/source/_static/basic/valve/deformation.png b/doc/source/_static/basic/valve/deformation.png deleted file mode 100644 index 161e51e5..00000000 Binary files a/doc/source/_static/basic/valve/deformation.png and /dev/null differ diff --git a/doc/source/_static/basic/valve/geometry.png b/doc/source/_static/basic/valve/geometry.png deleted file mode 100644 index 8e8a63aa..00000000 Binary files a/doc/source/_static/basic/valve/geometry.png and /dev/null differ diff --git a/doc/source/_static/basic/valve/mesh.png b/doc/source/_static/basic/valve/mesh.png deleted file mode 100644 index b479451a..00000000 Binary files a/doc/source/_static/basic/valve/mesh.png and /dev/null differ diff --git a/doc/source/_static/basic/valve/stress.png b/doc/source/_static/basic/valve/stress.png deleted file mode 100644 index 36661aa7..00000000 Binary files a/doc/source/_static/basic/valve/stress.png and /dev/null differ diff --git a/doc/source/index.rst b/doc/source/index.rst index 648b411c..ae2b8fbd 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -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 \ No newline at end of file diff --git a/examples/README.txt b/examples/README.txt index 5a7274b7..d8bd8f90 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -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. \ No newline at end of file diff --git a/examples/basic/readme.txt b/examples/basic/readme.txt index c90da660..5e5af8ce 100644 --- a/examples/basic/readme.txt +++ b/examples/basic/readme.txt @@ -1,4 +1,4 @@ -Basic examples -================ +Basic +====== This section demonstrates basic capabilities of PyMechanical diff --git a/examples/basic/valve.py b/examples/basic/valve.py index 1acc23a1..ba931be2 100644 --- a/examples/basic/valve.py +++ b/examples/basic/valve.py @@ -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) @@ -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 ) @@ -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( @@ -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] @@ -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")) diff --git a/examples/technology_showcase/example_10_td_055_Rotor_Blade_Inverse_solve.py b/examples/technology_showcase/example_10_td_055_Rotor_Blade_Inverse_solve.py index 1f34c0c2..cdbea723 100644 --- a/examples/technology_showcase/example_10_td_055_Rotor_Blade_Inverse_solve.py +++ b/examples/technology_showcase/example_10_td_055_Rotor_Blade_Inverse_solve.py @@ -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)) @@ -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 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -121,6 +136,7 @@ ExtAPI.Graphics.ExportImage( os.path.join(cwd, "geometry.png"), image_export_format, settings_720p ) +display_image("geometry.png") ################################################################################### # Assign materials @@ -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 diff --git a/examples/technology_showcase/readme.txt b/examples/technology_showcase/readme.txt index c0ac2290..ef4afd4f 100644 --- a/examples/technology_showcase/readme.txt +++ b/examples/technology_showcase/readme.txt @@ -1,4 +1,4 @@ -Technology showcase examples -============================= +Technology showcase +==================== Using technology showcase examples demonstrates embedding capabilities of PyMechanical. \ No newline at end of file