Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
db9ad63
Add 3 examples for Parametric Workflows
Mar 31, 2022
309a986
Add 3 examples for Parametric Workflows indentation change
Mar 31, 2022
0355bf4
remove pandas dataframe display
Mar 31, 2022
78ce69d
Disable archive operation as it is failing in server
mkundu1 Apr 4, 2022
f5731d0
Update examples/01-parametric/parametric_static_mixer_1.py
sujal-tipnis Apr 4, 2022
b0e0cc8
Update examples/01-parametric/parametric_static_mixer_1.py
sujal-tipnis Apr 4, 2022
0c5f771
Update examples/01-parametric/parametric_static_mixer_1.py
sujal-tipnis Apr 4, 2022
87e8fb4
Update examples/01-parametric/parametric_static_mixer_1.py
sujal-tipnis Apr 4, 2022
17362ee
Update examples/01-parametric/parametric_static_mixer_1.py
sujal-tipnis Apr 4, 2022
8b7a951
Update examples/01-parametric/parametric_static_mixer_2.py
sujal-tipnis Apr 4, 2022
90d47d1
Update examples/01-parametric/parametric_static_mixer_2.py
sujal-tipnis Apr 4, 2022
5f9abe3
Update examples/01-parametric/parametric_static_mixer_3.py
sujal-tipnis Apr 4, 2022
ab0f965
Update examples/01-parametric/parametric_static_mixer_2.py
sujal-tipnis Apr 4, 2022
6759a77
Update examples/01-parametric/parametric_static_mixer_1.py
sujal-tipnis Apr 4, 2022
027c028
made formatting changes to the script
Apr 4, 2022
a910289
fixed style
Apr 4, 2022
3ac1c3e
minor variable name changes
Apr 4, 2022
87ec17c
minor style change
Apr 4, 2022
b297bac
Re-enable project archive (#259)
mkundu1 Apr 5, 2022
2722eab
make variable name changes
Apr 5, 2022
44ae87f
make variable name changes(2)
Apr 5, 2022
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 @@ -112,6 +112,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
220 changes: 220 additions & 0 deletions examples/01-parametric/parametric_static_mixer_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
"""
.. _ref_parametric_static_mixer_1:

Parametric Study Workflow
------------------------------
This example for executing a parametric study workflow
performs these steps:

- Reads a case file and data file
- Creates input and output parameters
- Instantiates a design point study
- Accesses and modifies the input parameters of
the base design point (DP)
- Updates the current DP
- Accesses output parameters of the base DP
- Creates, updates, and deletes more DPs
- Creates, renames, and deletes parametric studies

"""

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

############################################################################
# Import the path module
from pathlib import Path

############################################################################
# Launch Fluent in 3D and double precision

session = pyfluent.launch_fluent(precision="double", processor_count=4)

############################################################################
# Enable the settings API (Beta)

root = session.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"
)

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

############################################################################
# Set number of iterations to 1000 to ensure convergence

session.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

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

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

session.tui.solver.define.boundary_conditions.set.velocity_inlet(
"inlet2", (), "vmag", "yes", "no", "inlet2_vel", 10, "quit"
)
session.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"
]

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

###########################################################################
# Enable convergence condition check

session.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"
)
session.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

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

###########################################################################
# Access and modify input parameters of base DP

input_parameters_update = study_1.design_points["Base DP"].input_parameters
input_parameters_update["inlet1_vel"] = 15
study_1.design_points["Base DP"].input_parameters = input_parameters_update

###########################################################################
# Update current design point

study_1.update_current_design_point()

###########################################################################
# Change value of specific design points

design_point_1 = study_1.add_design_point()
design_point_1_input_parameters = study_1.design_points["DP1"].input_parameters
design_point_1_input_parameters["inlet1_temp"] = 450
design_point_1_input_parameters["inlet1_vel"] = 30
design_point_1_input_parameters["inlet2_vel"] = 20
study_1.design_points["DP1"].input_parameters = design_point_1_input_parameters

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

design_point_2 = study_1.add_design_point()
design_point_2_input_parameters = study_1.design_points["DP2"].input_parameters
design_point_2_input_parameters["inlet1_temp"] = 500
design_point_2_input_parameters["inlet1_vel"] = 45
design_point_2_input_parameters["inlet2_vel"] = 30
study_1.design_points["DP2"].input_parameters = design_point_2_input_parameters

##########################################################################
# Duplicate design points

design_point_3 = study_1.duplicate_design_point(design_point_2)

#########################################################################
# Update all design points for study 1

study_1.update_all_design_points()

#########################################################################
# Export design point table as a CSV table

design_point_table = str(
Path(pyfluent.EXAMPLES_PATH) / "design_point_table_study_1.csv"
)
study_1.export_design_table(design_point_table)

#########################################################################
# Display CSV table as a pandas dataframe

import pandas as pd

data_frame = pd.read_csv(design_point_table)
print(data_frame)

##########################################################################
# Delete design points

study_1.delete_design_points([design_point_1, design_point_2])

##########################################################################
# Create a new parametric study by duplicating the current one

study_2 = study_1.duplicate()

#########################################################################
# Rename the newly created parametric study
# Currently affected by issue # 249, hence commented out

# study_2.rename("New Study")

#########################################################################
# Delete the old parametric study
# Currently affected by issue #249, hence commented out

# study_1.delete()

#########################################################################
# Save parametric project

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

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

Parametric Project-Based Workflow
----------------------------------------------------
This example for executing a parametric project-based workflow
performs these steps:

- Instantiates a parametric study from a Fluent session
- Reads the previously saved project ``- static_mixer_study.flprj``
- Saves the current project
- Saves the current project to a different file name
- Exports the current project
- Archives the current project
- Exits the parametric project-based workflow


"""

#########################################################################
# Parametric project-based 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 (Beta)

session = pyfluent.launch_fluent(precision="double", processor_count=4)
root = session.get_settings_root()

#########################################################################
# Read the previously saved project - static_mixer_study.flprj

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

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

#########################################################################
# Save the current project

proj.save()

#########################################################################
# Save the current project to a different file name

project_filepath_save_as = str(
Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study_save_as.flprj"
)
proj.save_as(project_filepath=project_filepath_save_as)

#########################################################################
# Export the current project

project_filepath_export = str(
Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study_export.flprj"
)
proj.export(project_filepath=project_filepath_export)

#########################################################################
# Archive the current project

proj.archive()
Loading