.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_how_to/example_iso_surface_area.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_auto_how_to_example_iso_surface_area.py: Measure the interface area of a VOF free surface ================================================ In a volume-of-fluid simulation, the ``alpha.water = 0.5`` iso-surface is a good proxy for the liquid–gas interface. Its area is a useful diagnostic: it grows during breakup, collapses on coalescence. pyOFTools' ``iso_surface`` builder + ``Sum`` gives you the number in one line. .. GENERATED FROM PYTHON SOURCE LINES 12-14 Open the case ------------- .. GENERATED FROM PYTHON SOURCE LINES 14-37 .. code-block:: Python import os import subprocess import pyOFTools.patch_pybfoam # noqa: F401 from pyOFTools import clone_example CASE = clone_example("damBreak") subprocess.run( ["./Allrun"], cwd=CASE, check=True, env={**os.environ}, capture_output=True, text=True, ) from pybFoam import Time, fvMesh, volScalarField time = Time(str(CASE.parent), CASE.name) mesh = fvMesh(time) volScalarField.read_field(mesh, "alpha.water") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 38-43 Iso-surface area ---------------- ``iso_surface`` returns a ``WorkFlow`` seeded with a ``SurfaceDataSet`` whose field slot is *empty*. Pipe into ``area()`` to populate the field with face-area magnitudes, then ``Sum`` to reduce. .. GENERATED FROM PYTHON SOURCE LINES 43-51 .. code-block:: Python from pyOFTools.aggregators import Sum from pyOFTools.builders import area, iso_surface result = (iso_surface(mesh, iso_field="alpha.water", iso_value=0.5) | area() | Sum()).compute() interface_area = result.values[0].value print(f"interface area at t=0: {interface_area:.6g} m^2") .. rst-class:: sphx-glr-script-out .. code-block:: none interface area at t=0: 0.00687285 m^2 .. GENERATED FROM PYTHON SOURCE LINES 52-68 Over time, wire this into a @Table ---------------------------------- In-situ, you register the computation once and the framework calls it each write step: .. code-block:: python from pyOFTools.postprocessor import PostProcessorBase postProcess = PostProcessorBase() @postProcess.Table("interface_area.csv") def interface_area(mesh): return iso_surface(mesh, "alpha.water", 0.5) | area() | Sum() See :doc:`/how-to/configure_controlDict` for the ``system/controlDict`` wiring. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 10.628 seconds) .. _sphx_glr_download_auto_how_to_example_iso_surface_area.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_iso_surface_area.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_iso_surface_area.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_iso_surface_area.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_