Skip to content
Closed
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
4 changes: 4 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def _start_or_stop_fluent_container(gallery_conf, fname, when):
if fname in ["mixing_elbow_settings_api.py",
"mixing_elbow_tui_api.py"]:
args = ["3ddp", "-t4", "-meshing"]
elif fname in ["parametric_static_mixer_1.py",
"parametric_static_mixer_2.py",
"parametric_static_mixer_3.py"]:
args = ["3ddp", "-t4"]
subprocess.run([sys.executable, _START_FLUENT_FILE] + args)
elif when == "after":
subprocess.run([sys.executable, _STOP_FLUENT_FILE])
Expand Down
228 changes: 228 additions & 0 deletions examples/01-parametric/parametric_static_mixer_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
"""
.. _ref_parametric_static_mixer_1:

Parametric study workflow
----------------------------------------------
In this example we perform the following steps to
execute a parametric study workflow
- Read a case and data file.
- Create input and output parameters.
- Instantiate design point study
- Access and Modify the input parameters of base design point (DP).
- Update the current design point.
- Access output parameters of the base DP
- Create, update and delete more design points.
- Create, rename and delete parametric studies

"""

############################################################################
# Import the pyfluent module
import ansys.fluent.core as pyfluent

# Import the path module
from pathlib import Path

############################################################################

# Launch Fluent in 3-D and double precision
s = pyfluent.launch_fluent(precision="double", processor_count=4)

############################################################################

# Enable the settings API

root = s.get_settings_root()

############################################################################

# Read the hopper/mixer Case

from ansys.fluent.core import examples


import_filename = examples.download_file(
"Static_Mixer_main.cas.h5", "pyfluent/static_mixer"
)


s.tui.solver.file.read_case(case_file_name=import_filename)

############################################################################

# Set number of iterations to 1000 to ensure convergence
s.tui.solver.solve.set.number_of_iterations("1000")
############################################################################

# Create input parameters after enabling parameter creation in the TUI:
# Parameter values:
# Inlet1: velocity (inlet1_vel) 5 m/s and temperature (inlet1_temp) at 300 K
# Inlet2: velocity (inlet2_vel) 10 m/s and temperature (inlet2_temp) at 350 K

s.tui.solver.define.parameters.enable_in_TUI("yes")

s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"inlet1", (), "vmag", "yes", "inlet1_vel", 5, "quit"
)
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"inlet1", (), "temperature", "yes", "inlet1_temp", 300, "quit"
)

s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"inlet2", (), "vmag", "yes", "no", "inlet2_vel", 10, "quit"
)
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"inlet2", (), "temperature", "yes", "no", "inlet2_temp", 350, "quit"
)

###########################################################################

# Create output parameters using report definitions

root.solution.report_definitions.surface["outlet-temp-avg"] = {}
root.solution.report_definitions.surface[
"outlet-temp-avg"
].report_type = "surface-areaavg"
root.solution.report_definitions.surface[
"outlet-temp-avg"
].field = "temperature"
root.solution.report_definitions.surface["outlet-temp-avg"].surface_names = [
"outlet"
]

root.solution.report_definitions.surface["outlet-vel-avg"] = {}
root.solution.report_definitions.surface[
"outlet-vel-avg"
].report_type = "surface-areaavg"
root.solution.report_definitions.surface[
"outlet-vel-avg"
].field = "velocity-magnitude"
root.solution.report_definitions.surface["outlet-vel-avg"].surface_names = [
"outlet"
]

s.tui.solver.define.parameters.enable_in_TUI("yes")
s.tui.solver.define.parameters.output_parameters.create(
"report-definition", "outlet-temp-avg"
)
s.tui.solver.define.parameters.output_parameters.create(
"report-definition", "outlet-vel-avg"
)

###########################################################################

# Enable convergence condition check

s.tui.solver.solve.monitors.residual.criterion_type("0")

###########################################################################

# Write case with all the settings in place
case_path = str(
Path(pyfluent.EXAMPLES_PATH) / "Static_Mixer_Parameters.cas.h5"
)
s.tui.solver.file.write_case(case_path)

###########################################################################
# Parametric study workflow

# Import the parametric study module

from ansys.fluent.parametric import ParametricStudy

###########################################################################

# Instantiate a parametric study from a Fluent session

study1 = ParametricStudy(root.parametric_studies).initialize()

###########################################################################

# Access and modify input parameters of base DP
ip = study1.design_points["Base DP"].input_parameters
ip["inlet1_vel"] = 15
study1.design_points["Base DP"].input_parameters = ip

###########################################################################

# Update current design point
study1.update_current_design_point()

###########################################################################

# Change value of specific design points

dp1 = study1.add_design_point()
dp1_ip = study1.design_points["DP1"].input_parameters
dp1_ip["inlet1_temp"] = 450
dp1_ip["inlet1_vel"] = 30
dp1_ip["inlet2_vel"] = 20
study1.design_points["DP1"].input_parameters = dp1_ip

###########################################################################

# Add another design point with different values of the input parameters

dp2 = study1.add_design_point()
dp2_ip = study1.design_points["DP2"].input_parameters
dp2_ip["inlet1_temp"] = 500
dp2_ip["inlet1_vel"] = 45
dp2_ip["inlet2_vel"] = 30
study1.design_points["DP2"].input_parameters = dp2_ip

##########################################################################

# Duplicate design points

dp3 = study1.duplicate_design_point(dp2)

#########################################################################

# Update all design points for study 1

study1.update_all_design_points()

#########################################################################

# Export design point table as a CSV table
dp_table = str(Path(pyfluent.EXAMPLES_PATH) / "dp_table_study1.csv")

study1.export_design_table(dp_table)

#########################################################################

# Display CSV table as pandas dataframe
import pandas as pd
df = pd.read_csv(dp_table)
print(df)

##########################################################################

# Delete design points

study1.delete_design_points([dp1, dp2])

##########################################################################

# Create a new parametric study by duplicating the current one
study2 = study1.duplicate()

#########################################################################

# Rename the newly create parametric study

# study2.rename("New Study")

#########################################################################

# Delete the old parametric study

# study1.delete()

#########################################################################

# Save parametric project

proj_path = str(Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study.flprj")

s.tui.solver.file.parametric_project.save_as(proj_path)
73 changes: 73 additions & 0 deletions examples/01-parametric/parametric_static_mixer_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
.. _ref_parametric_static_mixer_2:

Parametric project workflow
----------------------------------------------
In this example we perform the following steps to
execute a parametric project based workflow
- Instantiate a parametric study from a Fluent session
- Read the previously saved project - static_mixer_study.flprj
- Save the current project
- Save the current project as a different file name
- Export the current project
- Archive the current project
- Exit the parametric project workflow

"""

#########################################################################

# Parametric project workflow

#########################################################################

# Import the parametric project module and the parametric study module
from ansys.fluent.parametric import ParametricProject

############################################################################
# Import the pyfluent module and path
import ansys.fluent.core as pyfluent
from pathlib import Path

#########################################################################

# Launch Fluent and enable the settings API
s = pyfluent.launch_fluent(precision="double", processor_count=4)
root = s.get_settings_root()

#########################################################################

# Read the previously saved project - static_mixer_study.flprj
proj_path_read = str(Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study.flprj")

proj = ParametricProject(
root.file.parametric_project,
root.parametric_studies,
proj_path_read
)

#########################################################################

# Save the current project
proj.save()

#########################################################################

# Save the current project as a different file name
proj_path_sa = str(
Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study_save_as.flprj"
)
proj.save_as(project_filepath=proj_path_sa)

#########################################################################

# Export the current project
proj_path_exp = str(
Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study_export.flprj"
)
proj.export(project_filepath=proj_path_exp)

#########################################################################

# Archive the current project
proj.archive()
80 changes: 80 additions & 0 deletions examples/01-parametric/parametric_static_mixer_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""
.. _ref_parametric_static_mixer_3:

Parametric session workflow
----------------------------------------------
In this example we perform the following steps to
execute a parametric session workflow
- Launch parametric session using the hopper/mixer Case File
- Print the input parameters of the current parametric session.
- Access the current study of the current parametric session
- Create a new study in a parametric session
- Rename this newly created study
- Create a new parametric session using the flprj saved earlier

"""

#########################################################################

# Parametric session workflow
# Import the parametric session workflow

from ansys.fluent.parametric import ParametricSession

############################################################################
# Import the pyfluent module and path
import ansys.fluent.core as pyfluent
from pathlib import Path

#########################################################################

# Launch parametric session using the hopper/mixer Case File
# This case file contains pre-created input and output parameters
case_path = str(
Path(pyfluent.EXAMPLES_PATH) / "Static_Mixer_Parameters.cas.h5"
)

s1 = ParametricSession(case_filepath=case_path)

#########################################################################

# Print the input parameters of the current parametric session.

s1.studies["Static_Mixer_Parameters-Solve"].design_points[
"Base DP"
].input_parameters

#########################################################################

# Access the current study of the current parametric session

study1_session = s1.studies["Static_Mixer_Parameters-Solve"]

ip = study1_session.design_points["Base DP"].input_parameters
ip["inlet1_vel"] = 15
study1_session.design_points["Base DP"].input_parameters = ip

dp1 = study1_session.add_design_point()
dp1_ip = study1_session.design_points["DP1"].input_parameters
dp1_ip["inlet1_temp"] = 323
dp1_ip["inlet1_vel"] = 33
dp1_ip["inlet2_vel"] = 25
study1_session.design_points["DP1"].input_parameters = dp1_ip

#########################################################################

# In this parametric project create a new study
study2_session = s1.new_study()

#########################################################################

# Update all design points
study2_session.update_all_design_points()

#########################################################################

# Access a new parametric session using the flprj saved earlier
proj_path_sa = str(
Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study_save_as.flprj"
)
s2 = ParametricSession(project_filepath=proj_path_sa)