-
Notifications
You must be signed in to change notification settings - Fork 56
Add 3 examples for Parametric Workflows #250
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
Merged
Merged
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
309a986
Add 3 examples for Parametric Workflows indentation change
0355bf4
remove pandas dataframe display
78ce69d
Disable archive operation as it is failing in server
mkundu1 f5731d0
Update examples/01-parametric/parametric_static_mixer_1.py
sujal-tipnis b0e0cc8
Update examples/01-parametric/parametric_static_mixer_1.py
sujal-tipnis 0c5f771
Update examples/01-parametric/parametric_static_mixer_1.py
sujal-tipnis 87e8fb4
Update examples/01-parametric/parametric_static_mixer_1.py
sujal-tipnis 17362ee
Update examples/01-parametric/parametric_static_mixer_1.py
sujal-tipnis 8b7a951
Update examples/01-parametric/parametric_static_mixer_2.py
sujal-tipnis 90d47d1
Update examples/01-parametric/parametric_static_mixer_2.py
sujal-tipnis 5f9abe3
Update examples/01-parametric/parametric_static_mixer_3.py
sujal-tipnis ab0f965
Update examples/01-parametric/parametric_static_mixer_2.py
sujal-tipnis 6759a77
Update examples/01-parametric/parametric_static_mixer_1.py
sujal-tipnis 027c028
made formatting changes to the script
a910289
fixed style
3ac1c3e
minor variable name changes
87ec17c
minor style change
b297bac
Re-enable project archive (#259)
mkundu1 2722eab
make variable name changes
44ae87f
make variable name changes(2)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
|
|
||
| ######################################################################### | ||
sujal-tipnis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Save parametric project | ||
|
|
||
| project_filepath = str( | ||
| Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study.flprj" | ||
| ) | ||
|
|
||
| session.tui.solver.file.parametric_project.save_as(project_filepath) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.