.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-fluent/mixing_elbow_resilient.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_resilient.py: .. _ref_mixing_elbow_resilient: Mixing elbow in resilient mode ------------------------------ This example sets up and solves the mixing elbow with ordinary settings API code, launched with ``resilient_mode=True``. It shows how resilient mode: * undoes and redoes settings writes, * checkpoints before ``iterate`` and rolls back on request. See :ref:`ref_resilient_guide` for details. .. GENERATED FROM PYTHON SOURCE LINES 37-39 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 39-47 .. 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" ) .. GENERATED FROM PYTHON SOURCE LINES 48-50 Launch Fluent in resilient mode ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 50-59 .. code-block:: Python solver_session = pyfluent.Solver.from_install( precision=pyfluent.Precision.DOUBLE, processor_count=2, resilient_mode=True, ) resilient = solver_session.resilient resilient.on_event(lambda event: print(f"[{event.kind.value}] {event.message}")) .. GENERATED FROM PYTHON SOURCE LINES 60-62 Read the mesh ~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: Python solver_session.settings.file.read_mesh(file_name=import_file_name) .. GENERATED FROM PYTHON SOURCE LINES 66-68 Set up boundary conditions ~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 68-94 .. code-block:: Python # Built-in solver objects: energy = pyfluent.solver.Energy(settings_source=solver_session) cold_inlet = pyfluent.solver.VelocityInlet( settings_source=solver_session, name="cold-inlet" ) hot_inlet = pyfluent.solver.VelocityInlet( settings_source=solver_session, name="hot-inlet" ) # Aliasing reused objects: cold_turbulence = cold_inlet.turbulence turbulent_intensity = cold_turbulence.turbulent_intensity hot_turbulence = hot_inlet.turbulence energy.enabled.set_state(True) cold_inlet.momentum.velocity_magnitude.value.set_state(0.4) cold_turbulence.turbulence_specification.set_state("Intensity and Hydraulic Diameter") turbulent_intensity.set_state(0.05) cold_turbulence.hydraulic_diameter.set_state("4 [in]") cold_inlet.thermal.temperature.value.set_state(293.15) hot_inlet.momentum.velocity_magnitude.value.set_state(1.2) hot_turbulence.turbulence_specification.set_state("Intensity and Hydraulic Diameter") hot_turbulence.hydraulic_diameter.set_state("1 [in]") hot_inlet.thermal.temperature.value.set_state(313.15) .. GENERATED FROM PYTHON SOURCE LINES 95-100 Undo and redo a settings change ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Try a higher turbulent intensity at the cold inlet. Undo restores the 0.05 set above, and redo applies 0.1 again. A second undo keeps the setup at 0.05 for the solve. .. GENERATED FROM PYTHON SOURCE LINES 100-110 .. code-block:: Python turbulent_intensity.set_state(0.1) print("changed:", turbulent_intensity()) resilient.undo() print("after undo:", turbulent_intensity()) resilient.redo() print("after redo:", turbulent_intensity()) resilient.undo() print("after a second undo:", turbulent_intensity()) .. GENERATED FROM PYTHON SOURCE LINES 111-113 Initialize and checkpoint ~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 113-118 .. code-block:: Python initialization = pyfluent.solver.Initialization(settings_source=solver_session) initialization.hybrid_initialize() resilient.checkpoint("initialized") .. GENERATED FROM PYTHON SOURCE LINES 119-124 Solve ~~~~~ ``iterate`` is irreversible, so resilient mode writes an automatic checkpoint before it runs. If the solve failed, the session would be restored to that checkpoint and the error raised. .. GENERATED FROM PYTHON SOURCE LINES 124-129 .. code-block:: Python run_calculation = pyfluent.solver.RunCalculation(settings_source=solver_session) run_calculation.iterate(iter_count=100) print("checkpoints:", [checkpoint.name for checkpoint in resilient.checkpoints]) .. GENERATED FROM PYTHON SOURCE LINES 130-132 Roll back to the initialized state ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 132-135 .. code-block:: Python resilient.rollback("initialized") .. GENERATED FROM PYTHON SOURCE LINES 136-138 Exit ~~~~ .. GENERATED FROM PYTHON SOURCE LINES 138-140 .. code-block:: Python solver_session.exit() .. _sphx_glr_download_examples_00-fluent_mixing_elbow_resilient.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_resilient.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: mixing_elbow_resilient.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: mixing_elbow_resilient.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_