From 74727eb013c59a528a26e04c64ea9a37c60344e2 Mon Sep 17 00:00:00 2001 From: Raphael Luciano Date: Wed, 10 May 2023 14:49:57 -0400 Subject: [PATCH 1/5] Starting to test and add save_path to examples --- examples/Ablation-tutorial/ablation.py | 41 ++++++++++----- .../ahmed_body_workflow.py | 23 +++++++-- .../Brake-Thermal-PyVista-Matplotlib/brake.py | 32 +++++++++--- examples/CHT/CHT_Demo.py | 35 ++++++++++--- examples/DOE-ML-Mixing-Elbow/FluentDOE.py | 34 ++++++++++--- examples/MixingTank-DOE/mixingTankDOE.py | 28 +++++++--- .../oil_separator.py | 51 +++++++++++++------ examples/Steady-Vortex-VOF/steady_vortex.py | 34 ++++++++++--- 8 files changed, 208 insertions(+), 70 deletions(-) diff --git a/examples/Ablation-tutorial/ablation.py b/examples/Ablation-tutorial/ablation.py index d1062e5..9b90171 100644 --- a/examples/Ablation-tutorial/ablation.py +++ b/examples/Ablation-tutorial/ablation.py @@ -7,14 +7,24 @@ postprocessing capabilities. """ +import os from pathlib import Path # Import modules import ansys.fluent.core as pyfluent from ansys.fluent.core import examples +############################################################################### +# Specifying save path +# ~~~~~~~~~~~~~~~~~~~~ +# save_path can be specified as Path("E:/", "pyfluent-examples-tests") or +# Path("E:/pyfluent-examples-tests") in a Windows machine for example, or +# Path("~/pyfluent-examples-tests") in Linux. +save_path = Path(pyfluent.EXAMPLES_PATH) +os.chdir(save_path) + import_filename = examples.download_file( - "ablation.msh.h5", "pyfluent/examples/Ablation-tutorial" + "ablation.msh.h5", "pyfluent/examples/Ablation-tutorial", save_path=save_path ) from ansys.fluent.visualization import set_config @@ -22,7 +32,14 @@ set_config(blocking=True, set_view_on_display="isometric") # Launch fluent -session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=4) +session = pyfluent.launch_fluent( + version="3d", + precision="double", + processor_count=4, + show_gui=True, + cwd=save_path, + product_version="23.1.0", +) # Read Mesh session.tui.file.read_case(import_filename) @@ -77,9 +94,8 @@ "no", "yes", "yes", - "yes", - "yes", - "no", + "coefficient-based", + "0.1", "yes", ) session.tui.define.dynamic_mesh.zones.create( @@ -97,9 +113,8 @@ "no", "yes", "yes", - "yes", - "yes", - "no", + "coefficient-based", + "0.1", "yes", ) session.tui.define.dynamic_mesh.zones.create( @@ -117,9 +132,8 @@ "no", "yes", "yes", - "yes", - "yes", - "no", + "coefficient-based", + "0.1", "yes", ) session.tui.define.dynamic_mesh.zones.create( @@ -225,12 +239,12 @@ session.tui.solve.initialize.initialize_flow() # Save case file -save_case_data_as = str(Path(pyfluent.EXAMPLES_PATH) / "ablation.cas.h5") +save_case_data_as = Path(save_path) / "ablation.cas.h5" session.tui.file.write_case(save_case_data_as) # Post-Process import_data_filename = examples.download_file( - "ablation_Solved.dat.h5", "pyfluent/examples/Ablation-tutorial" + "ablation_Solved.dat.h5", "pyfluent/examples/Ablation-tutorial", save_path=save_path ) session.tui.file.read_case_data(import_data_filename) @@ -255,7 +269,6 @@ # Display contour session.results.graphics.contour.display(object_name="contour_mach") - # Post-Process with PyVista from ansys.fluent.visualization.pyvista import Graphics diff --git a/examples/Ahmed-Body-Simulation/ahmed_body_workflow.py b/examples/Ahmed-Body-Simulation/ahmed_body_workflow.py index c751ab0..b86882d 100644 --- a/examples/Ahmed-Body-Simulation/ahmed_body_workflow.py +++ b/examples/Ahmed-Body-Simulation/ahmed_body_workflow.py @@ -50,16 +50,30 @@ from ansys.fluent.visualization import set_config +############################################################################### +# Specifying save path +# ~~~~~~~~~~~~~~~~~~~~ +# save_path can be specified as Path("E:/", "pyfluent-examples-tests") or +# Path("E:/pyfluent-examples-tests") in a Windows machine for example, or +# Path("~/pyfluent-examples-tests") in Linux. +save_path = Path(pyfluent.EXAMPLES_PATH) +os.chdir(save_path) + #################################################################################### # Configure specific settings for this example # ================================================================================== set_config(blocking=True, set_view_on_display="isometric") -os.chdir(pyfluent.EXAMPLES_PATH) #################################################################################### # Launch Fluent session with meshing mode # ================================================================================== -session = pyfluent.launch_fluent(mode="meshing", show_gui=True, cleanup_on_exit=True) +session = pyfluent.launch_fluent( + mode="meshing", + show_gui=True, + cleanup_on_exit=True, + product_version="23.1.0", + cwd=save_path, +) session.check_health() #################################################################################### @@ -74,6 +88,7 @@ geometry_filename = examples.download_file( "ahmed_body_20_0degree_boi_half.scdoc", "pyfluent/examples/Ahmed-Body-Simulation", + save_path=save_path, ) workflow.InitializeWorkflow(WorkflowType="Watertight Geometry") workflow.TaskObject["Import Geometry"].Arguments = dict(FileName=geometry_filename) @@ -334,13 +349,13 @@ # Save the case file # ================================================================================== -save_case_data_as = str(Path(pyfluent.EXAMPLES_PATH) / "ahmed_body_final.cas.h5") +save_case_data_as = Path(save_path) / "ahmed_body_final.cas.h5" session.tui.file.write_case_data(save_case_data_as) #################################################################################### # Close the session # ================================================================================== -session.exit() +# session.exit() ####################################################################################### diff --git a/examples/Brake-Thermal-PyVista-Matplotlib/brake.py b/examples/Brake-Thermal-PyVista-Matplotlib/brake.py index 91864cd..e2d4c9b 100644 --- a/examples/Brake-Thermal-PyVista-Matplotlib/brake.py +++ b/examples/Brake-Thermal-PyVista-Matplotlib/brake.py @@ -20,21 +20,40 @@ # Brake pad wear # Braking performance +import os from pathlib import Path # import modules import ansys.fluent.core as pyfluent from ansys.fluent.core import examples +############################################################################### +# Specifying save path +# ~~~~~~~~~~~~~~~~~~~~ +# save_path can be specified as Path("E:/", "pyfluent-examples-tests") or +# Path("E:/pyfluent-examples-tests") in a Windows machine for example, or +# Path("~/pyfluent-examples-tests") in Linux. +save_path = Path(pyfluent.EXAMPLES_PATH) +os.chdir(save_path) + import_filename = examples.download_file( - "brake.msh", "pyfluent/examples/Brake-Thermal-PyVista-Matplotlib" + "brake.msh", + "pyfluent/examples/Brake-Thermal-PyVista-Matplotlib", + save_path=save_path, ) # noqa: E501 # Set log level # pyfluent.set_log_level("DEBUG") # Open Fluent in GUI mode -session = pyfluent.launch_fluent(version="3ddp", precision="double", processor_count=2) +session = pyfluent.launch_fluent( + version="3ddp", + precision="double", + processor_count=2, + product_version="23.1.0", + cwd=save_path, + show_gui=True, +) # Check server status session.check_health() @@ -151,7 +170,7 @@ "()", ) -report_file = str(Path(pyfluent.EXAMPLES_PATH) / "max-temperature.out") +report_file_path = Path(save_path) / "max-temperature.out" session.tui.solve.report_files.add( "max-temperature", "report-defs", @@ -159,7 +178,7 @@ "max-disc-temperature", "()", "file-name", - report_file, + str(report_file_path), ) # Set contour properties @@ -247,7 +266,7 @@ session.tui.solve.dual_time_iterate(10, 5) # 200, 5 # Write and save case file data -save_case_data_as = str(Path(pyfluent.EXAMPLES_PATH) / "brake-final.cas.h5") +save_case_data_as = Path(save_path) / "brake-final.cas.h5" session.tui.file.write_case_data(save_case_data_as) @@ -296,7 +315,7 @@ Y = [] Z = [] i = -1 -with open(report_file, "r") as datafile: +with open(report_file_path, "r") as datafile: plotting = csv.reader(datafile, delimiter=" ") for rows in plotting: i = i + 1 @@ -310,4 +329,5 @@ plt.xlabel("Time (sec)") plt.ylabel("Max Temperature (K)") plt.legend(loc="lower right", shadow=True, fontsize="x-large") + plt.savefig(save_path / "max-temperature.png") # plt.show() diff --git a/examples/CHT/CHT_Demo.py b/examples/CHT/CHT_Demo.py index c88813d..34d06a7 100644 --- a/examples/CHT/CHT_Demo.py +++ b/examples/CHT/CHT_Demo.py @@ -8,6 +8,8 @@ """ # Import Python Packages +import os + from ansys.fluent.visualization import set_config set_config(blocking=True, set_view_on_display="isometric") @@ -37,10 +39,31 @@ viz.__version__ +############################################################################### +# Specifying save path +# ~~~~~~~~~~~~~~~~~~~~ +# save_path can be specified as Path("E:/", "pyfluent-examples-tests") or +# Path("E:/pyfluent-examples-tests") in a Windows machine for example, or +# Path("~/pyfluent-examples-tests") in Linux. +save_path = Path(pyfluent.EXAMPLES_PATH) +os.chdir(save_path) + +geom_filename = examples.download_file( + "cht_fin_htc_new.scdoc", + "pyfluent/examples/CHT", + save_path=save_path, +) + # Streaming of Transcript to this Notebook # pyfluent.set_log_level("INFO") -session = pyfluent.launch_fluent(mode="meshing", processor_count=4, show_gui=False) +session = pyfluent.launch_fluent( + mode="meshing", + processor_count=4, + product_version="23.1.0", + cwd=save_path, + show_gui=True, +) # PyFluent Session Health session.check_health() @@ -49,10 +72,6 @@ # Read Geometry File; Create Surface Mesh; Describe Geometry session.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry") -geom_filename = examples.download_file( - "cht_fin_htc_new.scdoc", - "pyfluent/examples/CHT", -) session.workflow.TaskObject["Import Geometry"].Arguments = dict( FileName=geom_filename ) # noqa: E501 @@ -383,7 +402,7 @@ session.workflow.TaskObject["Improve Volume Mesh"].Execute() # Save Mesh File -save_mesh_as = str(Path(pyfluent.EXAMPLES_PATH) / "hx-fin-2mm.msh.h5") +save_mesh_as = save_path / "hx-fin-2mm.msh.h5" session.tui.file.write_mesh(save_mesh_as) # Switch to Solution / solver Mode @@ -582,7 +601,7 @@ # Hybrid Initialization; Slit Interior between Solid Zones; Save Case session.tui.solve.initialize.hyb_initialization() session.tui.mesh.modify_zones.slit_interior_between_diff_solids() -save_case_as = str(Path(pyfluent.EXAMPLES_PATH) / "hx-fin-2mm.cas.h5") +save_case_as = save_path / "hx-fin-2mm.cas.h5" session.tui.file.write_case(save_case_as) session.tui.solve.initialize.hyb_initialization() @@ -591,7 +610,7 @@ "yes", "0", "1", "yes", "1" ) session.tui.solve.iterate(10) # 250 -save_case_data_as = str(Path(pyfluent.EXAMPLES_PATH) / "hx-fin-2mm.dat.h5") +save_case_data_as = save_path / "hx-fin-2mm.dat.h5" session.tui.file.write_case_data(save_case_data_as) # Mass Balance Report diff --git a/examples/DOE-ML-Mixing-Elbow/FluentDOE.py b/examples/DOE-ML-Mixing-Elbow/FluentDOE.py index 0c77a54..8501047 100644 --- a/examples/DOE-ML-Mixing-Elbow/FluentDOE.py +++ b/examples/DOE-ML-Mixing-Elbow/FluentDOE.py @@ -7,6 +7,9 @@ postprocessing capabilities. """ +import os +from pathlib import Path + # Import modules import ansys.fluent.core as pyfluent from ansys.fluent.core import examples @@ -16,12 +19,23 @@ import plotly.graph_objects as go # noqa: F401 import seaborn as sns # noqa: F401 +############################################################################### +# Specifying save path +# ~~~~~~~~~~~~~~~~~~~~ +# save_path can be specified as Path("E:/", "pyfluent-examples-tests") or +# Path("E:/pyfluent-examples-tests") in a Windows machine for example, or +# Path("~/pyfluent-examples-tests") in Linux. +save_path = Path(pyfluent.EXAMPLES_PATH) +os.chdir(save_path) + import_filename = examples.download_file( - "elbow.cas.h5", "pyfluent/examples/DOE-ML-Mixing-Elbow" + "elbow.cas.h5", + "pyfluent/examples/DOE-ML-Mixing-Elbow", + save_path=save_path, ) # noqa: E501 # Create a session object -session = pyfluent.launch_fluent() +session = pyfluent.launch_fluent(show_gui=True, cwd=save_path) # Check server status session.check_health() @@ -95,12 +109,13 @@ yaxis_title="Hot Inlet Vel (m/s)", zaxis_title="Average Outlet Temperature (K)", ), - width=600, - height=600, + width=1400, + height=1400, margin=dict(l=80, r=80, b=80, t=80), ) # Show figure -fig.show() +fig.write_image(save_path / "fig1.png") # requires 'pip install kaleido' +# fig.show() # Create a dataframe df = pd.DataFrame(columns=["coldVel", "hotVel", "Result"]) @@ -209,7 +224,8 @@ def fit_and_predict(model): plt.ylabel("Predictions", fontsize=12) plt.tight_layout() - plt.show() + plt.savefig(save_path / "fig2.png") + # plt.show() # Define model object @@ -280,7 +296,8 @@ def fit_and_predict(model): # Plot figures based on model history pd.DataFrame(history.history).plot(figsize=(8, 5)) plt.grid(True) -plt.show() +plt.savefig(save_path / "fig3.png") +# plt.show() # Define train test predictions train_predictions = model.predict(X_train) @@ -309,4 +326,5 @@ def fit_and_predict(model): plt.ylabel("Predictions", fontsize=12) plt.tight_layout() -plt.show() +plt.savefig(save_path / "fig4.png") +# plt.show() diff --git a/examples/MixingTank-DOE/mixingTankDOE.py b/examples/MixingTank-DOE/mixingTankDOE.py index 6b6ec47..42065b9 100644 --- a/examples/MixingTank-DOE/mixingTankDOE.py +++ b/examples/MixingTank-DOE/mixingTankDOE.py @@ -7,6 +7,9 @@ postprocessing capabilities. """ +import os +from pathlib import Path + # Stirred Tank: DOE and Plotting 3D Surface Plot using Plotly import ansys.fluent.core as pyfluent from ansys.fluent.core import examples @@ -22,11 +25,22 @@ power_number = np.zeros((len(omega), len(visc))) reynolds_number = np.zeros((len(omega), len(visc))) +############################################################################### +# Specifying save path +# ~~~~~~~~~~~~~~~~~~~~ +# save_path can be specified as Path("E:/", "pyfluent-examples-tests") or +# Path("E:/pyfluent-examples-tests") in a Windows machine for example, or +# Path("~/pyfluent-examples-tests") in Linux. +save_path = Path(pyfluent.EXAMPLES_PATH) +os.chdir(save_path) + # Create a session -session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=6) +session = pyfluent.launch_fluent( + version="3d", precision="double", processor_count=12, show_gui=True, cwd=save_path +) import_filename = examples.download_file( - "test-laminar-visc.cas.h5", "pyfluent/examples/MixingTank-DOE" + "test-laminar-visc.cas.h5", "pyfluent/examples/MixingTank-DOE", save_path=save_path ) # noqa: E501 @@ -83,8 +97,8 @@ fig.update_layout( title="Mixing Tank Power Response Surface", autosize=False, - width=700, - height=700, + width=1000, + height=1000, margin=dict(l=80, r=80, b=80, t=80), ) fig.update_layout( @@ -94,7 +108,8 @@ zaxis_title="Power (W)", ) ) -fig.show() +fig.write_image(save_path / "fig1.png") # requires 'pip install kaleido' +# fig.show() # Plot Power Number vs Re import matplotlib.pyplot as plt @@ -105,4 +120,5 @@ plt.title("Power Number vs Re") plt.xlabel("Impeller Reynolds Number") plt.ylabel("Power Number") -plt.show() +plt.savefig(save_path / "fig2.png") +# plt.show() diff --git a/examples/Separator-Collection-Efficiency/oil_separator.py b/examples/Separator-Collection-Efficiency/oil_separator.py index 1b56b5d..9eaca08 100644 --- a/examples/Separator-Collection-Efficiency/oil_separator.py +++ b/examples/Separator-Collection-Efficiency/oil_separator.py @@ -7,25 +7,43 @@ postprocessing capabilities. """ +import os from pathlib import Path # Oil Separator: Plot Collection Efficiency # Import pyfluent module import ansys.fluent.core as pyfluent +from ansys.fluent.core import examples # Set log level to info # pyfluent.set_log_level("INFO") -# Create a session -session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=6) -from ansys.fluent.core import examples +############################################################################### +# Specifying save path +# ~~~~~~~~~~~~~~~~~~~~ +# save_path can be specified as Path("E:/", "pyfluent-examples-tests") or +# Path("E:/pyfluent-examples-tests") in a Windows machine for example, or +# Path("~/pyfluent-examples-tests") in Linux. +save_path = Path(pyfluent.EXAMPLES_PATH) +os.chdir(save_path) import_filename = examples.download_file( "oil_separator.msh.h5", "pyfluent/examples/Separator-Collection-Efficiency", + save_path=save_path, ) # noqa: E501 +# Create a session +session = pyfluent.launch_fluent( + version="3d", + precision="double", + processor_count=6, + cwd=save_path, + show_gui=True, + product_version="23.1.0", +) + # Fluent Solver Setup # Read case file session.tui.file.read_case(import_filename) @@ -40,7 +58,9 @@ session.tui.define.boundary_conditions.list_zones() # Set velocity inlet -session.tui.define.boundary_conditions.inlet = "velocity-inlet" +# session.tui.define.boundary_conditions.inlet = "velocity-inlet" +inlet = session.setup.boundary_conditions.velocity_inlet["inlet"] +inlet.vmag = 0.1 # m/s session.tui.solve.set.p_v_coupling(20) @@ -84,7 +104,6 @@ 0.0001, 1, 0.2, - "q", ) # Setup boundary conditions @@ -114,15 +133,13 @@ "vol-avg-vel", "()", "file-name", - str(Path(pyfluent.EXAMPLES_PATH) / "vol-avg-vel.out"), + str(save_path / "vol-avg-vel.out"), "q", ) # Run Settings # Set number of iterations -session.tui.solve.set.number_of_iterations(25) # 1000 - -# In[26]: +session.tui.solve.set.number_of_iterations(50) # 1000 # Initialize solver workflow session.tui.solve.initialize.initialize_flow() @@ -173,10 +190,9 @@ session.tui.display.save_picture("lic-vel.png") # Write and save case data -save_case_as = str(Path(pyfluent.EXAMPLES_PATH) / "oil_separator.cas.h5") +save_case_as = str(save_path / "oil_separator.cas.h5") session.tui.file.write_case_data(save_case_as) - # Velocity on Mid Plane import csv @@ -231,7 +247,6 @@ data = data + eval(rows[8]) eff[i][j] = 100.0 * (1.0 - data / oil_mf[i]) - # 2D Plot using Matplotlib plt.scatter(dia, eff[0], label="mass flow=0.05kg/s") plt.scatter(dia, eff[-1], label="mass flow=0.55kg/s") @@ -239,7 +254,8 @@ plt.xlabel("Droplet Diameter (m)") plt.ylabel("Collection Efficiency(%)") plt.legend() -plt.show() +plt.savefig(save_path / "collection-efficiency.png") +# plt.show() # 3D Surface Plot using Plotly import plotly.graph_objects as go @@ -248,8 +264,8 @@ fig.update_layout( title="Separator Collection Efficiency", autosize=False, - width=700, - height=700, + width=1000, + height=1000, margin=dict(l=80, r=80, b=80, t=80), ) fig.update_layout( @@ -259,4 +275,7 @@ zaxis_title="Collection Efficiency (%)", ) ) -fig.show() +fig.write_image( + save_path / "collection-efficiency-surface.png" +) # requires 'pip install kaleido' +# fig.show() diff --git a/examples/Steady-Vortex-VOF/steady_vortex.py b/examples/Steady-Vortex-VOF/steady_vortex.py index 3ffe012..3eb1600 100644 --- a/examples/Steady-Vortex-VOF/steady_vortex.py +++ b/examples/Steady-Vortex-VOF/steady_vortex.py @@ -7,6 +7,7 @@ postprocessing capabilities. """ +import os from pathlib import Path # Prediction of Vortex Depth in a Stirred Tank @@ -14,12 +15,30 @@ import ansys.fluent.core as pyfluent from ansys.fluent.core import examples +############################################################################### +# Specifying save path +# ~~~~~~~~~~~~~~~~~~~~ +# save_path can be specified as Path("E:/", "pyfluent-examples-tests") or +# Path("E:/pyfluent-examples-tests") in a Windows machine for example, or +# Path("~/pyfluent-examples-tests") in Linux. +save_path = Path(pyfluent.EXAMPLES_PATH) +os.chdir(save_path) + import_filename = examples.download_file( - "vortex-mixingtank.msh.h5", "pyfluent/examples/Steady-Vortex-VOF" + "vortex-mixingtank.msh.h5", + "pyfluent/examples/Steady-Vortex-VOF", + save_path=save_path, ) # noqa: E501 # Create a session -session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=6) +session = pyfluent.launch_fluent( + version="3d", + precision="double", + processor_count=12, + show_gui=True, + product_version="23.2.0", + cwd=save_path, +) # Read case file session.tui.file.read_case(import_filename) @@ -181,11 +200,11 @@ session.tui.display.set.picture.y_resolution(600) # Save Initial Files & Run Calculation -save_case_data_as = str(Path(pyfluent.EXAMPLES_PATH) / "vortex_init.cas.h5") +save_case_data_as = str(save_path / "vortex_init.cas.h5") session.tui.file.write_case_data(save_case_data_as) # Set number of iterations -session.tui.solve.set.number_of_iterations(25) # 1500 +session.tui.solve.set.number_of_iterations(100) # 1500 # Stat iterations session.tui.solve.iterate() @@ -242,7 +261,7 @@ session.tui.display.save_picture("vortex.png") # Save and write case data -save_case_data_as = str(Path(pyfluent.EXAMPLES_PATH) / "vortex_final.cas.h5") +save_case_data_as = str(save_path / "vortex_final.cas.h5") session.tui.file.write_case_data(save_case_data_as) # GIF Animation: Vortex Formation @@ -259,6 +278,5 @@ imageio.mimsave("vortex.gif", images) # Load animation -from IPython.display import Image - -Image(filename="vortex.gif") +# from IPython.display import Image +# Image(filename="vortex.gif") From c6f3e402f20a09541f2b67c14f14804b81bbc95a Mon Sep 17 00:00:00 2001 From: Raphael Luciano Date: Fri, 12 May 2023 14:53:58 -0400 Subject: [PATCH 2/5] Fixing doc mistake --- examples/Ahmed-Body-Simulation/ahmed_body_workflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Ahmed-Body-Simulation/ahmed_body_workflow.py b/examples/Ahmed-Body-Simulation/ahmed_body_workflow.py index b86882d..4330c87 100644 --- a/examples/Ahmed-Body-Simulation/ahmed_body_workflow.py +++ b/examples/Ahmed-Body-Simulation/ahmed_body_workflow.py @@ -52,7 +52,7 @@ ############################################################################### # Specifying save path -# ~~~~~~~~~~~~~~~~~~~~ +# ==================== # save_path can be specified as Path("E:/", "pyfluent-examples-tests") or # Path("E:/pyfluent-examples-tests") in a Windows machine for example, or # Path("~/pyfluent-examples-tests") in Linux. From 2142fb5ca2ad3259d9926e84b3fb9d6e396ac394 Mon Sep 17 00:00:00 2001 From: Raphael Luciano Date: Fri, 12 May 2023 16:26:52 -0400 Subject: [PATCH 3/5] removed gui, added session exits, removed launch cwd --- examples/Ablation-tutorial/ablation.py | 14 ++++---------- .../ahmed_body_workflow.py | 12 ++---------- .../Brake-Thermal-PyVista-Matplotlib/brake.py | 14 ++++---------- examples/CHT/CHT_Demo.py | 13 ++++--------- examples/DOE-ML-Mixing-Elbow/FluentDOE.py | 7 ++++--- examples/MixingTank-DOE/mixingTankDOE.py | 11 +++++------ .../oil_separator.py | 14 ++++---------- examples/Steady-Vortex-VOF/steady_vortex.py | 17 ++++++----------- 8 files changed, 33 insertions(+), 69 deletions(-) diff --git a/examples/Ablation-tutorial/ablation.py b/examples/Ablation-tutorial/ablation.py index 9b90171..22edca2 100644 --- a/examples/Ablation-tutorial/ablation.py +++ b/examples/Ablation-tutorial/ablation.py @@ -7,7 +7,6 @@ postprocessing capabilities. """ -import os from pathlib import Path # Import modules @@ -21,7 +20,6 @@ # Path("E:/pyfluent-examples-tests") in a Windows machine for example, or # Path("~/pyfluent-examples-tests") in Linux. save_path = Path(pyfluent.EXAMPLES_PATH) -os.chdir(save_path) import_filename = examples.download_file( "ablation.msh.h5", "pyfluent/examples/Ablation-tutorial", save_path=save_path @@ -32,14 +30,7 @@ set_config(blocking=True, set_view_on_display="isometric") # Launch fluent -session = pyfluent.launch_fluent( - version="3d", - precision="double", - processor_count=4, - show_gui=True, - cwd=save_path, - product_version="23.1.0", -) +session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=4) # Read Mesh session.tui.file.read_case(import_filename) @@ -277,3 +268,6 @@ contour1.field = "pressure" contour1.surfaces_list = ["mid_plane"] contour1.display() + +# Properly close open Fluent session +session.exit() diff --git a/examples/Ahmed-Body-Simulation/ahmed_body_workflow.py b/examples/Ahmed-Body-Simulation/ahmed_body_workflow.py index 4330c87..0b382be 100644 --- a/examples/Ahmed-Body-Simulation/ahmed_body_workflow.py +++ b/examples/Ahmed-Body-Simulation/ahmed_body_workflow.py @@ -37,7 +37,6 @@ # Import required libraries/modules # ================================================================================== -import os from pathlib import Path import ansys.fluent.core as pyfluent @@ -57,7 +56,6 @@ # Path("E:/pyfluent-examples-tests") in a Windows machine for example, or # Path("~/pyfluent-examples-tests") in Linux. save_path = Path(pyfluent.EXAMPLES_PATH) -os.chdir(save_path) #################################################################################### # Configure specific settings for this example @@ -67,13 +65,7 @@ #################################################################################### # Launch Fluent session with meshing mode # ================================================================================== -session = pyfluent.launch_fluent( - mode="meshing", - show_gui=True, - cleanup_on_exit=True, - product_version="23.1.0", - cwd=save_path, -) +session = pyfluent.launch_fluent(mode="meshing", cleanup_on_exit=True) session.check_health() #################################################################################### @@ -355,7 +347,7 @@ #################################################################################### # Close the session # ================================================================================== -# session.exit() +session.exit() ####################################################################################### diff --git a/examples/Brake-Thermal-PyVista-Matplotlib/brake.py b/examples/Brake-Thermal-PyVista-Matplotlib/brake.py index e2d4c9b..83cae99 100644 --- a/examples/Brake-Thermal-PyVista-Matplotlib/brake.py +++ b/examples/Brake-Thermal-PyVista-Matplotlib/brake.py @@ -20,7 +20,6 @@ # Brake pad wear # Braking performance -import os from pathlib import Path # import modules @@ -34,7 +33,6 @@ # Path("E:/pyfluent-examples-tests") in a Windows machine for example, or # Path("~/pyfluent-examples-tests") in Linux. save_path = Path(pyfluent.EXAMPLES_PATH) -os.chdir(save_path) import_filename = examples.download_file( "brake.msh", @@ -46,14 +44,7 @@ # pyfluent.set_log_level("DEBUG") # Open Fluent in GUI mode -session = pyfluent.launch_fluent( - version="3ddp", - precision="double", - processor_count=2, - product_version="23.1.0", - cwd=save_path, - show_gui=True, -) +session = pyfluent.launch_fluent(version="3ddp", precision="double", processor_count=2) # Check server status session.check_health() @@ -331,3 +322,6 @@ plt.legend(loc="lower right", shadow=True, fontsize="x-large") plt.savefig(save_path / "max-temperature.png") # plt.show() + +# Properly close open Fluent session +session.exit() diff --git a/examples/CHT/CHT_Demo.py b/examples/CHT/CHT_Demo.py index 34d06a7..1f8dbf0 100644 --- a/examples/CHT/CHT_Demo.py +++ b/examples/CHT/CHT_Demo.py @@ -8,7 +8,6 @@ """ # Import Python Packages -import os from ansys.fluent.visualization import set_config @@ -46,7 +45,6 @@ # Path("E:/pyfluent-examples-tests") in a Windows machine for example, or # Path("~/pyfluent-examples-tests") in Linux. save_path = Path(pyfluent.EXAMPLES_PATH) -os.chdir(save_path) geom_filename = examples.download_file( "cht_fin_htc_new.scdoc", @@ -57,13 +55,7 @@ # Streaming of Transcript to this Notebook # pyfluent.set_log_level("INFO") -session = pyfluent.launch_fluent( - mode="meshing", - processor_count=4, - product_version="23.1.0", - cwd=save_path, - show_gui=True, -) +session = pyfluent.launch_fluent(mode="meshing", processor_count=4) # PyFluent Session Health session.check_health() @@ -639,3 +631,6 @@ session.tui.surface.iso_surface( "x-coordinate", "x=0.012826", "()", "()", "0.012826", "()" ) + +# Properly close open Fluent session +session.exit() diff --git a/examples/DOE-ML-Mixing-Elbow/FluentDOE.py b/examples/DOE-ML-Mixing-Elbow/FluentDOE.py index 8501047..d2ad306 100644 --- a/examples/DOE-ML-Mixing-Elbow/FluentDOE.py +++ b/examples/DOE-ML-Mixing-Elbow/FluentDOE.py @@ -7,7 +7,6 @@ postprocessing capabilities. """ -import os from pathlib import Path # Import modules @@ -26,7 +25,6 @@ # Path("E:/pyfluent-examples-tests") in a Windows machine for example, or # Path("~/pyfluent-examples-tests") in Linux. save_path = Path(pyfluent.EXAMPLES_PATH) -os.chdir(save_path) import_filename = examples.download_file( "elbow.cas.h5", @@ -35,7 +33,7 @@ ) # noqa: E501 # Create a session object -session = pyfluent.launch_fluent(show_gui=True, cwd=save_path) +session = pyfluent.launch_fluent() # Check server status session.check_health() @@ -328,3 +326,6 @@ def fit_and_predict(model): plt.tight_layout() plt.savefig(save_path / "fig4.png") # plt.show() + +# Properly close open Fluent session +session.exit() diff --git a/examples/MixingTank-DOE/mixingTankDOE.py b/examples/MixingTank-DOE/mixingTankDOE.py index 42065b9..e18da69 100644 --- a/examples/MixingTank-DOE/mixingTankDOE.py +++ b/examples/MixingTank-DOE/mixingTankDOE.py @@ -7,7 +7,6 @@ postprocessing capabilities. """ -import os from pathlib import Path # Stirred Tank: DOE and Plotting 3D Surface Plot using Plotly @@ -31,13 +30,10 @@ # save_path can be specified as Path("E:/", "pyfluent-examples-tests") or # Path("E:/pyfluent-examples-tests") in a Windows machine for example, or # Path("~/pyfluent-examples-tests") in Linux. -save_path = Path(pyfluent.EXAMPLES_PATH) -os.chdir(save_path) +save_path = Path("E:/pyfluent-examples-tests") # Path(pyfluent.EXAMPLES_PATH) # Create a session -session = pyfluent.launch_fluent( - version="3d", precision="double", processor_count=12, show_gui=True, cwd=save_path -) +session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=12) import_filename = examples.download_file( "test-laminar-visc.cas.h5", "pyfluent/examples/MixingTank-DOE", save_path=save_path @@ -122,3 +118,6 @@ plt.ylabel("Power Number") plt.savefig(save_path / "fig2.png") # plt.show() + +# Properly close open Fluent session +session.exit() diff --git a/examples/Separator-Collection-Efficiency/oil_separator.py b/examples/Separator-Collection-Efficiency/oil_separator.py index 9eaca08..dcfa746 100644 --- a/examples/Separator-Collection-Efficiency/oil_separator.py +++ b/examples/Separator-Collection-Efficiency/oil_separator.py @@ -7,7 +7,6 @@ postprocessing capabilities. """ -import os from pathlib import Path # Oil Separator: Plot Collection Efficiency @@ -26,7 +25,6 @@ # Path("E:/pyfluent-examples-tests") in a Windows machine for example, or # Path("~/pyfluent-examples-tests") in Linux. save_path = Path(pyfluent.EXAMPLES_PATH) -os.chdir(save_path) import_filename = examples.download_file( "oil_separator.msh.h5", @@ -35,14 +33,7 @@ ) # noqa: E501 # Create a session -session = pyfluent.launch_fluent( - version="3d", - precision="double", - processor_count=6, - cwd=save_path, - show_gui=True, - product_version="23.1.0", -) +session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=6) # Fluent Solver Setup # Read case file @@ -279,3 +270,6 @@ save_path / "collection-efficiency-surface.png" ) # requires 'pip install kaleido' # fig.show() + +# Properly close open Fluent session +session.exit() diff --git a/examples/Steady-Vortex-VOF/steady_vortex.py b/examples/Steady-Vortex-VOF/steady_vortex.py index 3eb1600..18a2bec 100644 --- a/examples/Steady-Vortex-VOF/steady_vortex.py +++ b/examples/Steady-Vortex-VOF/steady_vortex.py @@ -7,7 +7,6 @@ postprocessing capabilities. """ -import os from pathlib import Path # Prediction of Vortex Depth in a Stirred Tank @@ -22,8 +21,8 @@ # Path("E:/pyfluent-examples-tests") in a Windows machine for example, or # Path("~/pyfluent-examples-tests") in Linux. save_path = Path(pyfluent.EXAMPLES_PATH) -os.chdir(save_path) +# Downloading example files import_filename = examples.download_file( "vortex-mixingtank.msh.h5", "pyfluent/examples/Steady-Vortex-VOF", @@ -31,14 +30,7 @@ ) # noqa: E501 # Create a session -session = pyfluent.launch_fluent( - version="3d", - precision="double", - processor_count=12, - show_gui=True, - product_version="23.2.0", - cwd=save_path, -) +session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=12) # Read case file session.tui.file.read_case(import_filename) @@ -269,7 +261,7 @@ import imageio -png_dir = os.getcwd() +png_dir = save_path images = [] for file_name in sorted(os.listdir(png_dir)): if file_name.startswith("animation") and file_name.endswith(".png"): @@ -280,3 +272,6 @@ # Load animation # from IPython.display import Image # Image(filename="vortex.gif") + +# Properly close open Fluent session +session.exit() From 89918874b950b66c2c4de160000cb7a17e30060e Mon Sep 17 00:00:00 2001 From: Raphael Luciano Date: Fri, 12 May 2023 16:29:53 -0400 Subject: [PATCH 4/5] fix accidental save location change in one example --- examples/MixingTank-DOE/mixingTankDOE.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/MixingTank-DOE/mixingTankDOE.py b/examples/MixingTank-DOE/mixingTankDOE.py index e18da69..892e592 100644 --- a/examples/MixingTank-DOE/mixingTankDOE.py +++ b/examples/MixingTank-DOE/mixingTankDOE.py @@ -30,7 +30,7 @@ # save_path can be specified as Path("E:/", "pyfluent-examples-tests") or # Path("E:/pyfluent-examples-tests") in a Windows machine for example, or # Path("~/pyfluent-examples-tests") in Linux. -save_path = Path("E:/pyfluent-examples-tests") # Path(pyfluent.EXAMPLES_PATH) +save_path = Path(pyfluent.EXAMPLES_PATH) # Create a session session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=12) From 7acec28b84e271416f341d10431b0aad346ac111 Mon Sep 17 00:00:00 2001 From: Raphael Luciano Date: Fri, 12 May 2023 16:45:55 -0400 Subject: [PATCH 5/5] reverted to previous processor_count --- examples/MixingTank-DOE/mixingTankDOE.py | 2 +- examples/Steady-Vortex-VOF/steady_vortex.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/MixingTank-DOE/mixingTankDOE.py b/examples/MixingTank-DOE/mixingTankDOE.py index 892e592..367e449 100644 --- a/examples/MixingTank-DOE/mixingTankDOE.py +++ b/examples/MixingTank-DOE/mixingTankDOE.py @@ -33,7 +33,7 @@ save_path = Path(pyfluent.EXAMPLES_PATH) # Create a session -session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=12) +session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=6) import_filename = examples.download_file( "test-laminar-visc.cas.h5", "pyfluent/examples/MixingTank-DOE", save_path=save_path diff --git a/examples/Steady-Vortex-VOF/steady_vortex.py b/examples/Steady-Vortex-VOF/steady_vortex.py index 18a2bec..d588374 100644 --- a/examples/Steady-Vortex-VOF/steady_vortex.py +++ b/examples/Steady-Vortex-VOF/steady_vortex.py @@ -30,7 +30,7 @@ ) # noqa: E501 # Create a session -session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=12) +session = pyfluent.launch_fluent(version="3d", precision="double", processor_count=6) # Read case file session.tui.file.read_case(import_filename)