Skip to content
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

Adding save_path to some examples #31

Merged
merged 6 commits into from
May 15, 2023
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
33 changes: 20 additions & 13 deletions examples/Ablation-tutorial/ablation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
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)

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
Expand Down Expand Up @@ -77,9 +85,8 @@
"no",
"yes",
"yes",
"yes",
"yes",
"no",
"coefficient-based",
"0.1",
"yes",
)
session.tui.define.dynamic_mesh.zones.create(
Expand All @@ -97,9 +104,8 @@
"no",
"yes",
"yes",
"yes",
"yes",
"no",
"coefficient-based",
"0.1",
"yes",
)
session.tui.define.dynamic_mesh.zones.create(
Expand All @@ -117,9 +123,8 @@
"no",
"yes",
"yes",
"yes",
"yes",
"no",
"coefficient-based",
"0.1",
"yes",
)
session.tui.define.dynamic_mesh.zones.create(
Expand Down Expand Up @@ -225,12 +230,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)
Expand All @@ -255,7 +260,6 @@
# Display contour
session.results.graphics.contour.display(object_name="contour_mach")


# Post-Process with PyVista
from ansys.fluent.visualization.pyvista import Graphics

Expand All @@ -264,3 +268,6 @@
contour1.field = "pressure"
contour1.surfaces_list = ["mid_plane"]
contour1.display()

# Properly close open Fluent session
session.exit()
15 changes: 11 additions & 4 deletions examples/Ahmed-Body-Simulation/ahmed_body_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
# Import required libraries/modules
# ==================================================================================

import os
from pathlib import Path

import ansys.fluent.core as pyfluent
Expand All @@ -50,16 +49,23 @@

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)

####################################################################################
# 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", cleanup_on_exit=True)
session.check_health()

####################################################################################
Expand All @@ -74,6 +80,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)
Expand Down Expand Up @@ -334,7 +341,7 @@
# 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)

####################################################################################
Expand Down
24 changes: 19 additions & 5 deletions examples/Brake-Thermal-PyVista-Matplotlib/brake.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,18 @@
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)

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
Expand Down Expand Up @@ -151,15 +161,15 @@
"()",
)

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",
"max-pad-temperature",
"max-disc-temperature",
"()",
"file-name",
report_file,
str(report_file_path),
)

# Set contour properties
Expand Down Expand Up @@ -247,7 +257,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)


Expand Down Expand Up @@ -296,7 +306,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
Expand All @@ -310,4 +320,8 @@
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()

# Properly close open Fluent session
session.exit()
30 changes: 22 additions & 8 deletions examples/CHT/CHT_Demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

# Import Python Packages

from ansys.fluent.visualization import set_config

set_config(blocking=True, set_view_on_display="isometric")
Expand Down Expand Up @@ -37,10 +38,24 @@

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)

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)

# PyFluent Session Health
session.check_health()
Expand All @@ -49,10 +64,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
Expand Down Expand Up @@ -383,7 +394,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
Expand Down Expand Up @@ -582,7 +593,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()

Expand All @@ -591,7 +602,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
Expand Down Expand Up @@ -620,3 +631,6 @@
session.tui.surface.iso_surface(
"x-coordinate", "x=0.012826", "()", "()", "0.012826", "()"
)

# Properly close open Fluent session
session.exit()
33 changes: 26 additions & 7 deletions examples/DOE-ML-Mixing-Elbow/FluentDOE.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
postprocessing capabilities.
"""

from pathlib import Path

# Import modules
import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples
Expand All @@ -16,8 +18,18 @@
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)

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
Expand Down Expand Up @@ -95,12 +107,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"])
Expand Down Expand Up @@ -209,7 +222,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
Expand Down Expand Up @@ -280,7 +294,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)
Expand Down Expand Up @@ -309,4 +324,8 @@ def fit_and_predict(model):
plt.ylabel("Predictions", fontsize=12)

plt.tight_layout()
plt.show()
plt.savefig(save_path / "fig4.png")
# plt.show()

# Properly close open Fluent session
session.exit()
Loading