.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-fluent/modeling_cavitation.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_modeling_cavitation.py: Modeling Cavitation ------------------- This example examines the pressure-driven cavitating flow of water through a sharp-edged orifice. This is a typical configuration in fuel injectors, and brings a challenge to the physics and numerics of cavitation models because of the high pressure differentials involved and the high ratio of liquid to vapor density. This example uses the multiphase modeling capability of Ansys Fluent, and will be able to predict the strong cavitation near the orifice after flow separation at a sharp edge. **Workflow tasks** This example demonstrates how to do the following: - Set boundary conditions for internal flow - Use the mixture model with cavitation effects - Calculate a solution using the pressure-based coupled solver **Problem description** The problem considers the cavitation caused by the flow separation after a sharp-edged orifice. The flow is pressure driven, with an inlet pressure of 500 kPa and an outlet pressure of 95 kPa. The orifice diameter is 4 mm, and the geometrical parameters of the orifice are D/d = 2.88 and L/d = 4, where D, d, and L are the inlet diameter, orifice diameter, and orifice length respectively. .. GENERATED FROM PYTHON SOURCE LINES 33-42 Example Setup ------------- Before you can begin, you must set up the example and initialize this workflow. Launch Fluent ~~~~~~~~~~~~~ Perform required imports, which includes downloading and importing the geometry file. .. GENERATED FROM PYTHON SOURCE LINES 42-48 .. code-block:: Python import ansys.fluent.core as pyfluent from ansys.fluent.core import examples cav_file = examples.download_file("cav.msh.gz", "pyfluent/cavitation") .. rst-class:: sphx-glr-script-out .. code-block:: none Download successful. File path: /home/ansys/.local/share/ansys_fluent_core/examples/cav.msh.gz .. GENERATED FROM PYTHON SOURCE LINES 50-52 Launch a Fluent session in the 2d solution mode with double precision running on four processors. .. GENERATED FROM PYTHON SOURCE LINES 52-60 .. code-block:: Python solver = pyfluent.launch_fluent( precision="double", processor_count=4, mode="solver", version="2d", ) .. GENERATED FROM PYTHON SOURCE LINES 61-62 Read the mesh that was downloaded. .. GENERATED FROM PYTHON SOURCE LINES 62-67 .. code-block:: Python solver.file.read_mesh(file_name=cav_file) solver.mesh.check() .. GENERATED FROM PYTHON SOURCE LINES 68-69 Specify an axisymmetric model. .. GENERATED FROM PYTHON SOURCE LINES 69-72 .. code-block:: Python solver.setup.general.solver.two_dim_space = "axisymmetric" .. GENERATED FROM PYTHON SOURCE LINES 73-74 Enable the multiphase mixture model. .. GENERATED FROM PYTHON SOURCE LINES 74-79 .. code-block:: Python solver.setup.models.multiphase.models = "mixture" solver.tui.define.models.multiphase.mixture_parameters("no", "implicit") .. GENERATED FROM PYTHON SOURCE LINES 80-81 Enable the k-ω SST turbulence model. .. GENERATED FROM PYTHON SOURCE LINES 81-87 .. code-block:: Python solver.setup.models.viscous = { "model": "k-omega", "k_omega_model": "sst", } .. GENERATED FROM PYTHON SOURCE LINES 88-94 Define materials ~~~~~~~~~~~~~~~~ Create a material named water, using 1000 kg/m3 for density and 0.001 kg/m–s for viscosity. Then, copy water vapor properties from the database and modify the copy by changing the density to 0.02558 kg/m3 and the viscosity to 1.26e-06 kg/m–s. .. GENERATED FROM PYTHON SOURCE LINES 94-113 .. code-block:: Python solver.setup.materials.fluid["water"] = { "density": { "option": "constant", "value": 1000, }, "viscosity": { "option": "constant", "value": 0.001, }, } solver.setup.materials.database.copy_by_name(type="fluid", name="water-vapor") solver.setup.materials.fluid["water-vapor"] = { "density": {"value": 0.02558}, "viscosity": {"value": 1.26e-06}, } .. GENERATED FROM PYTHON SOURCE LINES 114-120 Phases ~~~~~~ Change the name of the primary phase to "liquid" and the secondary phase to "water-vapor". Then, enable the cavitation model and set the number of mass transfer mechanisms to 1. Finally, specify cavitation as a mass transfer mechanism occurring from the liquid to the vapor. .. GENERATED FROM PYTHON SOURCE LINES 120-135 .. code-block:: Python solver.tui.define.phases.set_domain_properties.change_phases_names("vapor", "liquid") solver.tui.define.phases.set_domain_properties.phase_domains.liquid.material( "yes", "water" ) solver.tui.define.phases.set_domain_properties.phase_domains.vapor.material( "yes", "water-vapor" ) solver.tui.define.phases.set_domain_properties.interaction_domain.heat_mass_reactions.mass_transfer( 1, "liquid", "vapor", "cavitation", "1", "no", "no", "no" ) .. GENERATED FROM PYTHON SOURCE LINES 136-145 Boundary Conditions ~~~~~~~~~~~~~~~~~~~ For the first inlet momentum boundary conditions set the direction specification method to 'normal to boundary', gauge total pressure as 500 kPa and supersonic or initial gauge pressure as 449 kPa. For the turbulence settings choose 'Intensity and Viscosity Ratio' for turbulent specification. Set turbulent intensity and turbulent viscosity ratio to 0.05 and 10 respectively. .. GENERATED FROM PYTHON SOURCE LINES 145-161 .. code-block:: Python inlet_1 = solver.setup.boundary_conditions.pressure_inlet["inlet_1"].phase inlet_1["mixture"] = { "momentum": { "gauge_total_pressure": {"value": 500000}, "supersonic_or_initial_gauge_pressure": {"value": 449000}, "direction_specification_method": "Normal to Boundary", }, "turbulence": { "turbulent_specification": "Intensity and Viscosity Ratio", "turbulent_intensity": 0.05, "turbulent_viscosity_ratio_real": 10, }, } .. GENERATED FROM PYTHON SOURCE LINES 162-164 Before copying inlet_1's boundary conditions to inlet_2, set the vapor fraction to 0. .. GENERATED FROM PYTHON SOURCE LINES 164-173 .. code-block:: Python inlet_1["vapor"] = { "multiphase": { "volume_fraction": {"value": 0}, }, } solver.setup.boundary_conditions.copy(from_="inlet_1", to="inlet_2") .. GENERATED FROM PYTHON SOURCE LINES 174-176 For the outlet boundary conditions, set the gauge pressure as 95 kPa. Use the same turbulence and volume fraction settings as the inlets. .. GENERATED FROM PYTHON SOURCE LINES 176-196 .. code-block:: Python outlet = solver.setup.boundary_conditions.pressure_outlet["outlet"].phase outlet["mixture"] = { "momentum": { "gauge_pressure": {"value": 95000}, }, "turbulence": { "turbulent_specification": "Intensity and Viscosity Ratio", "turbulent_intensity": 0.04, "turbulent_viscosity_ratio_real": 10, }, } outlet["vapor"] = { "multiphase": { "volume_fraction": {"value": 0}, }, } .. GENERATED FROM PYTHON SOURCE LINES 197-200 Operating Conditions ~~~~~~~~~~~~~~~~~~~~ Set the operating pressure to 0. .. GENERATED FROM PYTHON SOURCE LINES 200-203 .. code-block:: Python solver.setup.general.operating_conditions.operating_pressure = 0 .. GENERATED FROM PYTHON SOURCE LINES 204-209 Solution ~~~~~~~~ To configure the discretization scheme, set 'first order upwind' method for turbulent kinetic energy and turbulent dissipation rate, 'quick' for the momentum and volume fraction, and 'presto!' for pressure. .. GENERATED FROM PYTHON SOURCE LINES 209-220 .. code-block:: Python methods = solver.solution.methods methods.discretization_scheme = { "k": "first-order-upwind", "mom": "quick", "mp": "quick", "omega": "first-order-upwind", "pressure": "presto!", } .. GENERATED FROM PYTHON SOURCE LINES 221-225 For the pressure velocity coupling scheme choose 'Coupled'. Set the pseudo time step method to 'global time step' and enable 'High Order Term Relaxation'. Then, set the explicit relaxation factor for 'Volume Fraction' to 0.3. .. GENERATED FROM PYTHON SOURCE LINES 225-236 .. code-block:: Python methods.p_v_coupling.flow_scheme = "Coupled" methods.pseudo_time_method.formulation.coupled_solver = "global-time-step" methods.high_order_term_relaxation.enable = True solver.solution.controls.pseudo_time_explicit_relaxation_factor.global_dt_pseudo_relax[ "mp" ] = 0.3 .. GENERATED FROM PYTHON SOURCE LINES 237-240 To plot the residuals, enable plotting and set the convergence criteria to 1e-05 for x-velocity, y-velocity, k, omega, and vf-vapor. Enable the specified initial pressure then initialize the solution with hybrid initialization. .. GENERATED FROM PYTHON SOURCE LINES 240-258 .. code-block:: Python solver.solution.monitor.residual.options.plot = True resid_eqns = solver.solution.monitor.residual.equations resid_eqns["continuity"].absolute_criteria = 1e-5 resid_eqns["x-velocity"].absolute_criteria = 1e-5 resid_eqns["y-velocity"].absolute_criteria = 1e-5 resid_eqns["k"].absolute_criteria = 1e-5 resid_eqns["omega"].absolute_criteria = 1e-5 resid_eqns["vf-vapor"].absolute_criteria = 1e-5 initialization = solver.solution.initialization initialization.initialization_type = "hybrid" initialization.hybrid_init_options.general_settings.initial_pressure = True initialization.hybrid_initialize() .. GENERATED FROM PYTHON SOURCE LINES 259-263 Save and Run ~~~~~~~~~~~~ Save the case file 'cav.cas.h5'. Then, start the calculation by requesting 500 iterations. Save the final case file and the data. .. GENERATED FROM PYTHON SOURCE LINES 263-270 .. code-block:: Python solver.file.write_case(file_name="cav") solver.solution.run_calculation.iterate(iter_count=500) solver.file.write_case_data(file_name="cav") .. GENERATED FROM PYTHON SOURCE LINES 271-276 Post Processing ~~~~~~~~~~~~~~~ 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 276-284 .. 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 285-290 Create contour plots ~~~~~~~~~~~~~~~~~~~~ Create a contour plot for static pressure, turbulent kinetic energy and the volume fraction of water vapor. For each plot enable banded coloring and filled option. .. GENERATED FROM PYTHON SOURCE LINES 290-302 .. code-block:: Python graphics = solver.results.graphics graphics.contour["contour_static_pressure"] = { "coloring": { "option": "banded", "smooth": False, }, "field": "pressure", "filled": True, } .. GENERATED FROM PYTHON SOURCE LINES 303-304 Mirror the display around the symmetry plane to show the full model. .. GENERATED FROM PYTHON SOURCE LINES 304-311 .. code-block:: Python solver.tui.display.set.mirror_zones(["symm_2", "symm_1"]) graphics.contour["contour_static_pressure"].display() graphics.picture.save_picture(file_name="contour_static_pressure.png") .. GENERATED FROM PYTHON SOURCE LINES 312-315 .. image:: /_static/cavitation_model_012.png :width: 500pt :align: center .. GENERATED FROM PYTHON SOURCE LINES 315-331 .. code-block:: Python graphics.contour.create("contour_tke") graphics.contour["contour_tke"] = { "coloring": { "option": "banded", "smooth": False, }, "field": "turb-kinetic-energy", "filled": True, } graphics.contour["contour_tke"].display() graphics.picture.save_picture(file_name="contour_tke.png") .. GENERATED FROM PYTHON SOURCE LINES 332-335 .. image:: /_static/cavitation_model_011.png :width: 500pt :align: center .. GENERATED FROM PYTHON SOURCE LINES 335-351 .. code-block:: Python graphics.contour.create("contour_vf_vapor") graphics.contour["contour_vf_vapor"] = { "coloring": { "option": "banded", "smooth": False, }, "field": "vapor-vof", "filled": True, } graphics.contour["contour_vf_vapor"].display() graphics.picture.save_picture(file_name="contour_vf_vapor.png") .. GENERATED FROM PYTHON SOURCE LINES 352-355 .. image:: /_static/cavitation_model.png :width: 500pt :align: center .. GENERATED FROM PYTHON SOURCE LINES 355-361 .. code-block:: Python # Save case to 'cav.cas.h5' and exit solver.file.write_case(file_name="cav") solver.exit() .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 30.788 seconds) .. _sphx_glr_download_examples_00-fluent_modeling_cavitation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: modeling_cavitation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: modeling_cavitation.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_