.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-fluent/mixing_elbow_settings_api.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_00-fluent_mixing_elbow_settings_api.py: .. _ref_mixing_elbow_settings_api_beta: Fluent setup and solution using settings objects ------------------------------------------------ This example sets up and solves a three-dimensional turbulent fluid flow and heat transfer problem in a mixing elbow, which is common in piping systems in power plants and process industries. Predicting the flow field and temperature field in the area of the mixing region is important to designing the junction properly. This example uses settings objects. **Problem description** A cold fluid at 20 deg C flows into the pipe through a large inlet. It then mixes with a warmer fluid at 40 deg C that enters through a smaller inlet located at the elbow. The pipe dimensions are in inches, and the fluid properties and boundary conditions are given in SI units. Because the Reynolds number for the flow at the larger inlet is ``50, 800``, a turbulent flow model is required. .. GENERATED FROM PYTHON SOURCE LINES 23-27 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports, which includes downloading and importing the geometry file. .. GENERATED FROM PYTHON SOURCE LINES 27-35 .. code-block:: Python import ansys.fluent.core as pyfluent from ansys.fluent.core import examples import_file_name = examples.download_file( "mixing_elbow.msh.h5", "pyfluent/mixing_elbow" ) .. rst-class:: sphx-glr-script-out .. code-block:: none File already exists. File path: /home/ansys/.local/share/ansys_fluent_core/examples/mixing_elbow.msh.h5 .. GENERATED FROM PYTHON SOURCE LINES 37-41 Launch Fluent ~~~~~~~~~~~~~ Launch Fluent as a service in solver mode with double precision running on two processors. .. GENERATED FROM PYTHON SOURCE LINES 41-48 .. code-block:: Python solver = pyfluent.launch_fluent( precision="double", processor_count=2, mode="solver", ) .. GENERATED FROM PYTHON SOURCE LINES 49-56 Import mesh and perform mesh check ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Import the mesh and perform a mesh check, which lists the minimum and maximum x, y, and z values from the mesh in the default SI units of meters. The mesh check also reports a number of other mesh features that are checked. Any errors in the mesh are reported. Ensure that the minimum volume is not negative because Fluent cannot begin a calculation when this is the case. .. GENERATED FROM PYTHON SOURCE LINES 56-60 .. code-block:: Python solver.file.read_case(file_name=import_file_name) solver.mesh.check() .. GENERATED FROM PYTHON SOURCE LINES 61-64 Enable heat transfer ~~~~~~~~~~~~~~~~~~~~ Enable heat transfer by activating the energy equation. .. GENERATED FROM PYTHON SOURCE LINES 64-67 .. code-block:: Python solver.setup.models.energy.enabled = True .. GENERATED FROM PYTHON SOURCE LINES 68-71 Create material ~~~~~~~~~~~~~~~ Create a material named ``"water-liquid"``. .. GENERATED FROM PYTHON SOURCE LINES 71-74 .. code-block:: Python solver.setup.materials.database.copy_by_name(type="fluid", name="water-liquid") .. GENERATED FROM PYTHON SOURCE LINES 75-79 Set up cell zone conditions ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Set up the cell zone conditions for the fluid zone (``elbow-fluid``). Set ``material`` to ``"water-liquid"``. .. GENERATED FROM PYTHON SOURCE LINES 79-82 .. code-block:: Python solver.setup.cell_zone_conditions.fluid["elbow-fluid"].material = "water-liquid" .. GENERATED FROM PYTHON SOURCE LINES 83-87 Set up boundary conditions for CFD analysis ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Set up the boundary conditions for the inlets, outlet, and walls for CFD analysis. .. GENERATED FROM PYTHON SOURCE LINES 87-125 .. code-block:: Python # cold inlet (cold-inlet), Setting: Value: # Velocity Specification Method: Magnitude, Normal to Boundary # Velocity Magnitude: 0.4 [m/s] # Specification Method: Intensity and Hydraulic Diameter # Turbulent Intensity: 5 [%] # Hydraulic Diameter: 4 [inch] # Temperature: 293.15 [K] cold_inlet = solver.setup.boundary_conditions.velocity_inlet["cold-inlet"] cold_inlet.momentum.velocity.value = 0.4 cold_inlet.turbulence.turbulent_specification = "Intensity and Hydraulic Diameter" cold_inlet.turbulence.turbulent_intensity = 0.05 cold_inlet.turbulence.hydraulic_diameter = "4 [in]" cold_inlet.thermal.t.value = 293.15 # hot inlet (hot-inlet), Setting: Value: # Velocity Specification Method: Magnitude, Normal to Boundary # Velocity Magnitude: 1.2 [m/s] # Specification Method: Intensity and Hydraulic Diameter # Turbulent Intensity: 5 [%] # Hydraulic Diameter: 1 [inch] # Temperature: 313.15 [K] hot_inlet = solver.setup.boundary_conditions.velocity_inlet["hot-inlet"] hot_inlet.momentum.velocity.value = 1.2 hot_inlet.turbulence.turbulent_specification = "Intensity and Hydraulic Diameter" hot_inlet.turbulence.hydraulic_diameter = "1 [in]" hot_inlet.thermal.t.value = 313.15 # pressure outlet (outlet), Setting: Value: # Backflow Turbulent Intensity: 5 [%] # Backflow Turbulent Viscosity Ratio: 4 solver.setup.boundary_conditions.pressure_outlet[ "outlet" ].turbulence.turbulent_viscosity_ratio_real = 4 .. GENERATED FROM PYTHON SOURCE LINES 126-129 Disable plotting of residuals during calculation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Disable plotting of residuals during the calculation. .. GENERATED FROM PYTHON SOURCE LINES 129-132 .. code-block:: Python solver.solution.monitor.residual.options.plot = False .. GENERATED FROM PYTHON SOURCE LINES 133-136 Initialize flow field ~~~~~~~~~~~~~~~~~~~~~ Initialize the flow field using hybrid initialization. .. GENERATED FROM PYTHON SOURCE LINES 136-139 .. code-block:: Python solver.solution.initialization.hybrid_initialize() .. GENERATED FROM PYTHON SOURCE LINES 140-143 Solve for 150 iterations ~~~~~~~~~~~~~~~~~~~~~~~~ Solve for 150 iterations. .. GENERATED FROM PYTHON SOURCE LINES 143-146 .. code-block:: Python solver.solution.run_calculation.iterate(iter_count=150) .. GENERATED FROM PYTHON SOURCE LINES 147-152 Configure graphics picture export ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Since Fluent is being run without the GUI, we will need to export plots as picture files. Edit the picture settings to use a custom resolution so that the images are large enough. .. GENERATED FROM PYTHON SOURCE LINES 152-160 .. code-block:: Python graphics = solver.results.graphics # use_window_resolution option not available inside containers if not solver.connection_properties.inside_container: graphics.picture.use_window_resolution = False graphics.picture.x_resolution = 1920 graphics.picture.y_resolution = 1440 .. GENERATED FROM PYTHON SOURCE LINES 161-165 Create velocity vectors ~~~~~~~~~~~~~~~~~~~~~~~ Create and display velocity vectors on the ``symmetry-xyplane`` plane, then export the image for inspection. .. GENERATED FROM PYTHON SOURCE LINES 165-183 .. code-block:: Python graphics = solver.results.graphics graphics.vector["velocity_vector_symmetry"] = {} velocity_symmetry = solver.results.graphics.vector["velocity_vector_symmetry"] velocity_symmetry.print_state() velocity_symmetry.field = "velocity-magnitude" velocity_symmetry.surfaces_list = [ "symmetry-xyplane", ] velocity_symmetry.scale.scale_f = 4 velocity_symmetry.style = "arrow" velocity_symmetry.display() graphics.views.restore_view(view_name="front") graphics.views.auto_scale() graphics.picture.save_picture(file_name="velocity_vector_symmetry.png") .. rst-class:: sphx-glr-script-out .. code-block:: none name : velocity_vector_symmetry field : velocity-magnitude vector_field : velocity scale : auto_scale : True scale_f : 1 style : 3d arrow skip : 0 vector_opt : in_plane : False fixed_length : False x_comp : True y_comp : True z_comp : True scale_head : 0.3 color : range_option : option : auto-range-on auto_range_on : global_range : True color_map : visible : True size : 100 color : field-velocity log_scale : False format : %0.2e user_skip : 9 show_all : True position : 1 font_name : Helvetica font_automatic : True font_size : 0.032 length : 0.54 width : 6.0 bground_transparent : True bground_color : #CCD3E2 title_elements : Variable and Object Name display_state_name : None .. GENERATED FROM PYTHON SOURCE LINES 184-187 .. image:: /_static/mixing_elbow_016.png :width: 500pt :align: center .. GENERATED FROM PYTHON SOURCE LINES 189-192 Compute mass flow rate ~~~~~~~~~~~~~~~~~~~~~~ Compute the mass flow rate. .. GENERATED FROM PYTHON SOURCE LINES 192-204 .. code-block:: Python solver.solution.report_definitions.flux["mass_flow_rate"] = {} mass_flow_rate = solver.solution.report_definitions.flux["mass_flow_rate"] mass_flow_rate.boundaries.allowed_values() mass_flow_rate.boundaries = [ "cold-inlet", "hot-inlet", "outlet", ] mass_flow_rate.print_state() solver.solution.report_definitions.compute(report_defs=["mass_flow_rate"]) .. rst-class:: sphx-glr-script-out .. code-block:: none name : mass_flow_rate report_type : flux-massflow boundaries : 0 : cold-inlet 1 : hot-inlet 2 : outlet per_zone : False average_over : 1 retain_instantaneous_values : False .. GENERATED FROM PYTHON SOURCE LINES 205-208 Close Fluent ~~~~~~~~~~~~ Close Fluent. .. GENERATED FROM PYTHON SOURCE LINES 208-210 .. code-block:: Python solver.exit() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 49.183 seconds) .. _sphx_glr_download_examples_00-fluent_mixing_elbow_settings_api.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: mixing_elbow_settings_api.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: mixing_elbow_settings_api.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_