.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_tutorials/example_01_run_incompressible_fluid.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_tutorials_example_01_run_incompressible_fluid.py: Run your first NeoFOAM case =========================== Run the bundled ``pitzDaily`` benchmark end-to-end with the ``incompressibleFluid`` solver and plot the final velocity field. .. GENERATED FROM PYTHON SOURCE LINES 10-12 Imports ------- .. GENERATED FROM PYTHON SOURCE LINES 12-21 .. code-block:: Python import contextlib import subprocess import pyvista as pv from neofoam.solver import incompressibleFluid from neofoam.tutorial import clone_case .. GENERATED FROM PYTHON SOURCE LINES 22-27 Clone the bundled case ---------------------- ``clone_case`` copies the case to a fresh tempdir and restores ``0.orig/`` to ``0/`` (what ``Allrun`` normally does). The ``.foam`` marker satisfies pyvista's OpenFOAMReader at the end. .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: Python case = clone_case("pitzDaily") (case / "pitzDaily.foam").touch() print(f"working copy: {case}") .. rst-class:: sphx-glr-script-out .. code-block:: none working copy: /tmp/neofoam_fsuirz3w/pitzDaily .. GENERATED FROM PYTHON SOURCE LINES 33-37 Generate the mesh ----------------- ``blockMesh`` reads ``system/blockMeshDict`` and writes ``constant/polyMesh/``. .. GENERATED FROM PYTHON SOURCE LINES 37-41 .. code-block:: Python subprocess.run(["blockMesh", "-case", str(case)], check=True) assert (case / "constant" / "polyMesh" / "points").exists() .. GENERATED FROM PYTHON SOURCE LINES 42-47 Run the solver -------------- Equivalent to running ``neofoam solver incompressiblefluid`` from the shell — that CLI command calls the same ``run`` underneath. We ``chdir`` into the case the way an ``Allrun`` script does. .. GENERATED FROM PYTHON SOURCE LINES 47-51 .. code-block:: Python with contextlib.chdir(case): incompressibleFluid.run(["."]) .. GENERATED FROM PYTHON SOURCE LINES 52-57 Plot the final velocity field ----------------------------- pyvista colours by the magnitude of ``U`` automatically. A flat-blue plot or zero-range colour bar would mean the solve didn't produce data — re-check the log in that case. .. GENERATED FROM PYTHON SOURCE LINES 57-72 .. code-block:: Python reader = pv.OpenFOAMReader(str(case / "pitzDaily.foam")) reader.set_active_time_value(reader.time_values[-1]) mesh = reader.read()["internalMesh"] pl = pv.Plotter(off_screen=True, window_size=(900, 360)) pl.add_mesh( mesh, scalars="U", cmap="viridis", scalar_bar_args={"title": "|U| [m/s]"}, ) pl.view_xy() pl.camera.zoom(1.2) pl.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /auto_tutorials/images/sphx_glr_example_01_run_incompressible_fluid_001.png :alt: example 01 run incompressible fluid :srcset: /auto_tutorials/images/sphx_glr_example_01_run_incompressible_fluid_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/NeoFOAM/NeoFOAM/doc/auto_tutorials/images/sphx_glr_example_01_run_incompressible_fluid_001.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 59.225 seconds) .. _sphx_glr_download_auto_tutorials_example_01_run_incompressible_fluid.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_01_run_incompressible_fluid.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_01_run_incompressible_fluid.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_01_run_incompressible_fluid.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_