.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-fluent/parametric_static_mixer_1.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end <sphx_glr_download_examples_00-fluent_parametric_static_mixer_1.py>` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_00-fluent_parametric_static_mixer_1.py: .. _ref_parametric_static_mixer_1: Parametric study workflow ------------------------- This example shows how you can use the parametric study workflow to analyze a static mixer. .. GENERATED FROM PYTHON SOURCE LINES 30-36 .. code-block:: Python from pathlib import Path import ansys.fluent.core as pyfluent from ansys.fluent.core import examples .. GENERATED FROM PYTHON SOURCE LINES 38-41 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform the required imports. .. GENERATED FROM PYTHON SOURCE LINES 44-47 Launch Fluent ~~~~~~~~~~~~~ Launch Fluent in 3D and double precision and print Fluent version. .. GENERATED FROM PYTHON SOURCE LINES 47-53 .. code-block:: Python solver_session = pyfluent.launch_fluent( precision="double", processor_count=2, mode="solver" ) print(solver_session.get_fluent_version()) .. GENERATED FROM PYTHON SOURCE LINES 54-57 Download and read files ~~~~~~~~~~~~~~~~~~~~~~~ Download the files for this example and read the case for the static mixer. .. GENERATED FROM PYTHON SOURCE LINES 57-66 .. code-block:: Python import_filename = examples.download_file( "Static_Mixer_main.cas.h5", "pyfluent/static_mixer", return_without_path=False, ) solver_session.settings.file.read_case(file_name=import_filename) .. GENERATED FROM PYTHON SOURCE LINES 67-70 Set iterations ~~~~~~~~~~~~~~ Set the number of iterations to 100. .. GENERATED FROM PYTHON SOURCE LINES 70-73 .. code-block:: Python solver_session.settings.solution.run_calculation.iter_count = 100 .. GENERATED FROM PYTHON SOURCE LINES 74-81 Create input parameters ~~~~~~~~~~~~~~~~~~~~~~~ Enable parameter creation in the TUI and then create input parameters for the velocity and temperatures of inlets 1 and 2: Parameter values: Inlet1: velocity (inlet1_vel) 0.5 m/s and temperature (inlet1_temp) at 300 K Inlet2: velocity (inlet2_vel) 0.5 m/s and temperature (inlet2_temp) at 350 K .. GENERATED FROM PYTHON SOURCE LINES 81-144 .. code-block:: Python solver_session.settings.parameters.enable_in_tui = True solver_session.settings.setup.named_expressions["inlet1_vel"] = { "output_parameter": False, "input_parameter": True, "unit": "velocity", "parametername": "inlet1_vel", "parameterid": "real-1", "description": "", "definition": "1 [m/s]", "name": "inlet1_vel", } solver_session.settings.setup.boundary_conditions.velocity_inlet["inlet1"] = { "momentum": {"velocity": {"value": "inlet1_vel"}} } solver_session.settings.setup.named_expressions["inlet1_temp"] = { "output_parameter": False, "input_parameter": True, "unit": "temperature", "parametername": "inlet1_temp", "parameterid": "real-2", "description": "", "definition": "300 [K]", "name": "inlet1_temp", } solver_session.settings.setup.boundary_conditions.velocity_inlet["inlet1"] = { "thermal": {"temperature": {"value": "inlet1_temp"}} } solver_session.settings.setup.named_expressions["inlet2_vel"] = { "output_parameter": False, "input_parameter": True, "unit": "velocity", "parametername": "inlet2_vel", "parameterid": "real-3", "description": "", "definition": "1 [m/s]", "name": "inlet2_vel", } solver_session.settings.setup.boundary_conditions.velocity_inlet["inlet2"] = { "momentum": {"velocity": {"value": "inlet2_vel"}} } solver_session.settings.setup.named_expressions["inlet2_temp"] = { "output_parameter": False, "input_parameter": True, "unit": "temperature", "parametername": "inlet2_temp", "parameterid": "real-4", "description": "", "definition": "350 [K]", "name": "inlet2_temp", } solver_session.settings.setup.boundary_conditions.velocity_inlet["inlet2"] = { "thermal": {"temperature": {"value": "inlet2_temp"}} } .. GENERATED FROM PYTHON SOURCE LINES 145-149 Create output parameters ~~~~~~~~~~~~~~~~~~~~~~~~ Create output parameters named ``outlet-temp-avg`` and ``outlet-vel-avg`` using report definitions. .. GENERATED FROM PYTHON SOURCE LINES 149-186 .. code-block:: Python solver_session.settings.solution.report_definitions.surface["outlet-temp-avg"] = {} solver_session.settings.solution.report_definitions.surface[ "outlet-temp-avg" ].report_type = "surface-areaavg" solver_session.settings.solution.report_definitions.surface["outlet-temp-avg"].field = ( "temperature" ) solver_session.settings.solution.report_definitions.surface[ "outlet-temp-avg" ].surface_names = ["outlet"] solver_session.settings.solution.report_definitions.surface["outlet-vel-avg"] = {} solver_session.settings.solution.report_definitions.surface[ "outlet-vel-avg" ].report_type = "surface-areaavg" solver_session.settings.solution.report_definitions.surface["outlet-vel-avg"].field = ( "velocity-magnitude" ) solver_session.settings.solution.report_definitions.surface[ "outlet-vel-avg" ].surface_names = ["outlet"] solver_session.settings.parameters.output_parameters.report_definitions[ "parameter-5" ] = {} solver_session.settings.parameters.output_parameters.report_definitions[ "parameter-5" ] = {"report_definition": "outlet-temp-avg"} solver_session.settings.parameters.output_parameters.report_definitions[ "parameter-6" ] = {} solver_session.settings.parameters.output_parameters.report_definitions[ "parameter-6" ] = {"report_definition": "outlet-vel-avg"} .. GENERATED FROM PYTHON SOURCE LINES 187-190 Enable convergence condition check ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Enable the convergence condition check. .. GENERATED FROM PYTHON SOURCE LINES 190-193 .. code-block:: Python solver_session.settings.solution.monitor.residual.options.criterion_type = "absolute" .. GENERATED FROM PYTHON SOURCE LINES 194-197 Write case ~~~~~~~~~~ Write the case with all settings in place. .. GENERATED FROM PYTHON SOURCE LINES 197-201 .. code-block:: Python case_path = str(Path(pyfluent.EXAMPLES_PATH) / "Static_Mixer_Parameters.cas.h5") solver_session.settings.file.write_case(file_name=case_path) .. GENERATED FROM PYTHON SOURCE LINES 202-205 Initialize parametric study ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Initialize a parametric design point study from a Fluent session. .. GENERATED FROM PYTHON SOURCE LINES 205-208 .. code-block:: Python solver_session.settings.parametric_studies.initialize(project_filename="project_1") .. GENERATED FROM PYTHON SOURCE LINES 209-212 .. image:: /_static/DP_table_011.png :width: 500pt :align: center .. GENERATED FROM PYTHON SOURCE LINES 214-217 Access and modify input parameters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Access and modify the input parameters of the base design point. .. GENERATED FROM PYTHON SOURCE LINES 217-227 .. code-block:: Python solver_session.settings.parametric_studies["Static_Mixer_main-Solve"].design_points[ "Base DP" ].input_parameters = { "inlet1_temp": 300, "inlet2_temp": 350, "inlet2_vel": 1, "inlet1_vel": 0.5, } .. GENERATED FROM PYTHON SOURCE LINES 228-231 Update current design point ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Update the current design point. .. GENERATED FROM PYTHON SOURCE LINES 231-236 .. code-block:: Python solver_session.settings.parametric_studies[ "Static_Mixer_main-Solve" ].design_points.update_current() .. GENERATED FROM PYTHON SOURCE LINES 237-240 Add design point ~~~~~~~~~~~~~~~~ Add a design point. .. GENERATED FROM PYTHON SOURCE LINES 240-254 .. code-block:: Python solver_session.settings.parametric_studies[ "Static_Mixer_main-Solve" ].design_points.create(write_data=False, capture_simulation_report_data=True) solver_session.settings.parametric_studies["Static_Mixer_main-Solve"].design_points[ "DP1" ].input_parameters = { "inlet1_vel": 1, "inlet2_vel": 1, "inlet1_temp": 500, "inlet2_temp": 350, } .. GENERATED FROM PYTHON SOURCE LINES 255-258 Duplicate design point ~~~~~~~~~~~~~~~~~~~~~~~ Duplicate design point 1 to create design point 2. .. GENERATED FROM PYTHON SOURCE LINES 258-263 .. code-block:: Python solver_session.settings.parametric_studies[ "Static_Mixer_main-Solve" ].design_points.duplicate(design_point="DP1") .. GENERATED FROM PYTHON SOURCE LINES 264-267 Update all design points ~~~~~~~~~~~~~~~~~~~~~~~~ Update all design points. .. GENERATED FROM PYTHON SOURCE LINES 267-272 .. code-block:: Python solver_session.settings.parametric_studies[ "Static_Mixer_main-Solve" ].design_points.update_all() .. GENERATED FROM PYTHON SOURCE LINES 273-276 .. image:: /_static/DP_table_012.png :width: 500pt :align: center .. GENERATED FROM PYTHON SOURCE LINES 278-281 Export design point table ~~~~~~~~~~~~~~~~~~~~~~~~~ Export the design point table to a CSV file. .. GENERATED FROM PYTHON SOURCE LINES 281-290 .. code-block:: Python design_point_table = str( Path(pyfluent.EXAMPLES_PATH) / "design_point_table_study_1.csv" ) solver_session.settings.parametric_studies.export_design_table( filepath=design_point_table ) .. GENERATED FROM PYTHON SOURCE LINES 291-294 Delete design point ~~~~~~~~~~~~~~~~~~~ Delete design point 1. .. GENERATED FROM PYTHON SOURCE LINES 294-299 .. code-block:: Python solver_session.settings.parametric_studies[ "Static_Mixer_main-Solve" ].design_points.delete_design_points(design_points=["DP1"]) .. GENERATED FROM PYTHON SOURCE LINES 300-303 Create parametric study ~~~~~~~~~~~~~~~~~~~~~~~ Create another parametric study by duplicating the current one. .. GENERATED FROM PYTHON SOURCE LINES 303-306 .. code-block:: Python solver_session.settings.parametric_studies.duplicate(copy_design_points=True) .. GENERATED FROM PYTHON SOURCE LINES 307-310 Rename new parametric study ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Rename the newly created parametric study. .. GENERATED FROM PYTHON SOURCE LINES 310-315 .. code-block:: Python solver_session.settings.parametric_studies.rename( new="New Study", old="Static_Mixer_main-1-Solve" ) .. GENERATED FROM PYTHON SOURCE LINES 316-319 Delete old parametric study ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Delete the old parametric study. .. GENERATED FROM PYTHON SOURCE LINES 319-322 .. code-block:: Python solver_session.settings.parametric_studies.delete(name_list="Static_Mixer_main-Solve") .. GENERATED FROM PYTHON SOURCE LINES 323-326 Save parametric project and close Fluent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Save the parametric project and close Fluent. .. GENERATED FROM PYTHON SOURCE LINES 326-335 .. code-block:: Python project_filepath = str(Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study_save.flprj") solver_session.settings.file.parametric_project.save_as( project_filename=project_filepath ) solver_session.exit() .. GENERATED FROM PYTHON SOURCE LINES 336-339 Launch Fluent and read saved project ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Launch Fluent once again and read the previously saved project. .. GENERATED FROM PYTHON SOURCE LINES 339-352 .. code-block:: Python solver_session = pyfluent.launch_fluent( precision="double", processor_count=2, mode="solver" ) project_filepath_read = str( Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study_save.flprj" ) solver_session.settings.file.parametric_project.open( project_filename=project_filepath_read, load_case=True ) .. GENERATED FROM PYTHON SOURCE LINES 353-356 Save current project ~~~~~~~~~~~~~~~~~~~~ Save the current project. .. GENERATED FROM PYTHON SOURCE LINES 356-359 .. code-block:: Python solver_session.settings.file.parametric_project.save() .. GENERATED FROM PYTHON SOURCE LINES 360-363 Save current project as a different project ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Save the current project as a different project. .. GENERATED FROM PYTHON SOURCE LINES 363-372 .. code-block:: Python project_filepath_save_as = str( Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study_save_as.flprj" ) solver_session.settings.file.parametric_project.save_as( project_filename=project_filepath_save_as ) .. GENERATED FROM PYTHON SOURCE LINES 373-376 Export current project ~~~~~~~~~~~~~~~~~~~~~~ Export the current project. .. GENERATED FROM PYTHON SOURCE LINES 376-385 .. code-block:: Python project_filepath_export = str( Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study_export.flprj" ) solver_session.settings.file.parametric_project.save_as_copy( project_filename=project_filepath_export, convert_to_managed=False ) .. GENERATED FROM PYTHON SOURCE LINES 386-389 Archive current project ~~~~~~~~~~~~~~~~~~~~~~~ Archive the current project. .. GENERATED FROM PYTHON SOURCE LINES 389-398 .. code-block:: Python project_filepath_archive = str( Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study_archive.flprj" ) solver_session.settings.file.parametric_project.archive( archive_name=project_filepath_archive ) .. GENERATED FROM PYTHON SOURCE LINES 399-402 Close Fluent ~~~~~~~~~~~~ Close Fluent. .. GENERATED FROM PYTHON SOURCE LINES 402-404 .. code-block:: Python solver_session.exit() .. _sphx_glr_download_examples_00-fluent_parametric_static_mixer_1.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: parametric_static_mixer_1.ipynb <parametric_static_mixer_1.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: parametric_static_mixer_1.py <parametric_static_mixer_1.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: parametric_static_mixer_1.zip <parametric_static_mixer_1.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_