From 2ad0442a05dc009abd2c6946146fb234f4255f85 Mon Sep 17 00:00:00 2001 From: Dipin <26918585+dipinknair@users.noreply.github.com> Date: Thu, 15 Aug 2024 13:51:51 -0500 Subject: [PATCH] Feat: Add tips section (#217) Co-authored-by: Kerry McAdams <58492561+klmcadams@users.noreply.github.com> --- .gitignore | 5 +- examples/00_tips/readme.txt | 5 + examples/00_tips/tips_01.py | 53 ++++++++++ examples/00_tips/tips_02.py | 100 ++++++++++++++++++ examples/00_tips/tips_03.py | 54 ++++++++++ .../{basic => 01_basic}/bolt_pretension.py | 0 .../fracture_analysis_contact_debonding.py | 0 .../{basic => 01_basic}/harmonic_acoustics.py | 0 .../modal_acoustics_analysis.py | 0 examples/{basic => 01_basic}/readme.txt | 0 .../steady_state_thermal_analysis.py | 0 .../topology_optimization_cantilever_beam.py | 0 examples/{basic => 01_basic}/valve.py | 8 -- .../Rotor_Blade_Inverse_solve.py | 0 .../conact_wear_simulation.py | 0 .../non_linear_analsis_rubber_boot_seal.py | 0 .../readme.txt | 0 17 files changed, 215 insertions(+), 10 deletions(-) create mode 100644 examples/00_tips/readme.txt create mode 100644 examples/00_tips/tips_01.py create mode 100644 examples/00_tips/tips_02.py create mode 100644 examples/00_tips/tips_03.py rename examples/{basic => 01_basic}/bolt_pretension.py (100%) rename examples/{basic => 01_basic}/fracture_analysis_contact_debonding.py (100%) rename examples/{basic => 01_basic}/harmonic_acoustics.py (100%) rename examples/{basic => 01_basic}/modal_acoustics_analysis.py (100%) rename examples/{basic => 01_basic}/readme.txt (100%) rename examples/{basic => 01_basic}/steady_state_thermal_analysis.py (100%) rename examples/{basic => 01_basic}/topology_optimization_cantilever_beam.py (100%) rename examples/{basic => 01_basic}/valve.py (96%) rename examples/{technology_showcase => 02_technology_showcase}/Rotor_Blade_Inverse_solve.py (100%) rename examples/{technology_showcase => 02_technology_showcase}/conact_wear_simulation.py (100%) rename examples/{technology_showcase => 02_technology_showcase}/non_linear_analsis_rubber_boot_seal.py (100%) rename examples/{technology_showcase => 02_technology_showcase}/readme.txt (100%) diff --git a/.gitignore b/.gitignore index 0572644d..8a0a68d3 100644 --- a/.gitignore +++ b/.gitignore @@ -162,8 +162,9 @@ cython_debug/ PyMAPDL_Dev # Results generated during doc build and example run locally -examples/technology_showcase/out -examples/basic/out +examples/02_technology_showcase/out +examples/01_basic/out +examples/00_tips/out /out doc/source/sg_execution_times.rst diff --git a/examples/00_tips/readme.txt b/examples/00_tips/readme.txt new file mode 100644 index 00000000..2439d4a8 --- /dev/null +++ b/examples/00_tips/readme.txt @@ -0,0 +1,5 @@ +Tips +==== + +This section showcases some of the useful functions that can be used +in PyMechanical embedding workflow. diff --git a/examples/00_tips/tips_01.py b/examples/00_tips/tips_01.py new file mode 100644 index 00000000..ea0f2d15 --- /dev/null +++ b/examples/00_tips/tips_01.py @@ -0,0 +1,53 @@ +""" .. _ref_tips_01: + +3D visualization +---------------- + +Visualize 3D imported geometry +""" + +# %% +# Import necessary libraries +# ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +import ansys.mechanical.core as mech +from ansys.mechanical.core.examples import delete_downloads, download_file + +# %% +# Embed mechanical and set global variables + +app = mech.App(version=242) +app.update_globals(globals()) +print(app) + + +# %% +# Download and import geometry +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Download geometry + +geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding") + +# %% +# Import geometry + +geometry_import = Model.GeometryImportGroup.AddGeometryImport() +geometry_import.Import(geometry_path) + +# %% +# Visualize in 3D +# ~~~~~~~~~~~~~~~ + +app.plot() + +# %% +# .. note:: +# This visualization is currently available only for geometry and on version 24R2 or later + +# %% +# Cleanup +# ~~~~~~~ + +delete_downloads() +app.new() diff --git a/examples/00_tips/tips_02.py b/examples/00_tips/tips_02.py new file mode 100644 index 00000000..4f3cb53b --- /dev/null +++ b/examples/00_tips/tips_02.py @@ -0,0 +1,100 @@ +""" .. _ref_tips_02: + +Export image +------------ + +Export image and display +""" + +# %% +# Import necessary libraries +# ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +import os + +import ansys.mechanical.core as mech +from ansys.mechanical.core.examples import delete_downloads, download_file + +# %% +# Embed Mechanical and set global variables + +app = mech.App(version=242) +app.update_globals(globals()) +print(app) + + +# %% +# Download and import geometry +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Download geometry + +geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding") + +# %% +# Import geometry + +geometry_import = Model.GeometryImportGroup.AddGeometryImport() +geometry_import.Import(geometry_path) + +# %% +# Configure graphics for image export +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Orientation +Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso) + +# Export format +image_export_format = GraphicsImageExportFormat.PNG + +# Resolution and background +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) + + +# %% +# Custom function for displaying 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") + + +def display_image(image_name): + plt.figure(figsize=(16, 9)) + plt.imshow(mpimg.imread(os.path.join(cwd, image_name))) + plt.xticks([]) + plt.yticks([]) + plt.axis("off") + plt.show() + + +# %% +# Export and display the image +# ~~~~~~~~~~~~~~~~~~~~~~~~ + +# Fits the geometry in the viewing area +Graphics.Camera.SetFit() + +Graphics.ExportImage( + os.path.join(cwd, "geometry.png"), image_export_format, settings_720p +) + +# Display the image using matplotlib +display_image("geometry.png") + +# %% +# Cleanup +# ~~~~~~~ + +delete_downloads() +app.new() diff --git a/examples/00_tips/tips_03.py b/examples/00_tips/tips_03.py new file mode 100644 index 00000000..0cf9baa0 --- /dev/null +++ b/examples/00_tips/tips_03.py @@ -0,0 +1,54 @@ +""" .. _ref_tips_03: + +Project tree +-------------------- + +Display the heirarchial Mechanical project structure. +""" + +# %% +# Import necessary libraries +# ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +import ansys.mechanical.core as mech +from ansys.mechanical.core.examples import delete_downloads, download_file + +# %% +# Embed Mechanical and set global variables + +app = mech.App(version=242) +app.update_globals(globals()) +print(app) + + +# %% +# Download the mechdb file +# ~~~~~~~~~~~~~~~~~~~~~~~~ + +mechdb_path = download_file("graphics_test.mechdb", "pymechanical", "test_files") + +# %% +# Load the mechdb file inside Mechanical + +app.open(mechdb_path) + +# %% +# Display the project tree +# ~~~~~~~~~~~~~~~~~~~~~~~~ + +app.print_tree() + +# %% +# Display the tree only under the first analysis +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +app.print_tree(Model.Analyses[0]) + + +# %% +# Cleanup +# ~~~~~~~ + +delete_downloads() +app.new() diff --git a/examples/basic/bolt_pretension.py b/examples/01_basic/bolt_pretension.py similarity index 100% rename from examples/basic/bolt_pretension.py rename to examples/01_basic/bolt_pretension.py diff --git a/examples/basic/fracture_analysis_contact_debonding.py b/examples/01_basic/fracture_analysis_contact_debonding.py similarity index 100% rename from examples/basic/fracture_analysis_contact_debonding.py rename to examples/01_basic/fracture_analysis_contact_debonding.py diff --git a/examples/basic/harmonic_acoustics.py b/examples/01_basic/harmonic_acoustics.py similarity index 100% rename from examples/basic/harmonic_acoustics.py rename to examples/01_basic/harmonic_acoustics.py diff --git a/examples/basic/modal_acoustics_analysis.py b/examples/01_basic/modal_acoustics_analysis.py similarity index 100% rename from examples/basic/modal_acoustics_analysis.py rename to examples/01_basic/modal_acoustics_analysis.py diff --git a/examples/basic/readme.txt b/examples/01_basic/readme.txt similarity index 100% rename from examples/basic/readme.txt rename to examples/01_basic/readme.txt diff --git a/examples/basic/steady_state_thermal_analysis.py b/examples/01_basic/steady_state_thermal_analysis.py similarity index 100% rename from examples/basic/steady_state_thermal_analysis.py rename to examples/01_basic/steady_state_thermal_analysis.py diff --git a/examples/basic/topology_optimization_cantilever_beam.py b/examples/01_basic/topology_optimization_cantilever_beam.py similarity index 100% rename from examples/basic/topology_optimization_cantilever_beam.py rename to examples/01_basic/topology_optimization_cantilever_beam.py diff --git a/examples/basic/valve.py b/examples/01_basic/valve.py similarity index 96% rename from examples/basic/valve.py rename to examples/01_basic/valve.py index 9bf98381..5bbc9f6b 100644 --- a/examples/basic/valve.py +++ b/examples/01_basic/valve.py @@ -127,14 +127,6 @@ def display_image(image_name): ) display_image("boundary_conditions.png") -# %% -# Solve -# ~~~~~ -# Solve process settings - -config = ExtAPI.Application.SolveConfigurations["My Computer"] -config.SolveProcessSettings.MaxNumberOfCores = 1 -config.SolveProcessSettings.DistributeSolution = False # %% # Add results diff --git a/examples/technology_showcase/Rotor_Blade_Inverse_solve.py b/examples/02_technology_showcase/Rotor_Blade_Inverse_solve.py similarity index 100% rename from examples/technology_showcase/Rotor_Blade_Inverse_solve.py rename to examples/02_technology_showcase/Rotor_Blade_Inverse_solve.py diff --git a/examples/technology_showcase/conact_wear_simulation.py b/examples/02_technology_showcase/conact_wear_simulation.py similarity index 100% rename from examples/technology_showcase/conact_wear_simulation.py rename to examples/02_technology_showcase/conact_wear_simulation.py diff --git a/examples/technology_showcase/non_linear_analsis_rubber_boot_seal.py b/examples/02_technology_showcase/non_linear_analsis_rubber_boot_seal.py similarity index 100% rename from examples/technology_showcase/non_linear_analsis_rubber_boot_seal.py rename to examples/02_technology_showcase/non_linear_analsis_rubber_boot_seal.py diff --git a/examples/technology_showcase/readme.txt b/examples/02_technology_showcase/readme.txt similarity index 100% rename from examples/technology_showcase/readme.txt rename to examples/02_technology_showcase/readme.txt