.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_meshlib/plot_bhe_mesh.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_examples_howto_meshlib_plot_bhe_mesh.py: Creating a BHE mesh (Borehole Heat Exchanger) ============================================= This example demonstrates how to create a Borehole Heat Exchanger (BHE) mesh. .. GENERATED FROM PYTHON SOURCE LINES 9-18 .. code-block:: Python from pathlib import Path from tempfile import mkdtemp import pyvista as pv from pyvista.plotting import Plotter from ogstools.meshlib.gmsh_meshing import bhe_mesh from ogstools.msh2vtu import msh2vtu .. GENERATED FROM PYTHON SOURCE LINES 19-20 Generate a customizable BHE mesh (using gmsh): .. GENERATED FROM PYTHON SOURCE LINES 22-34 .. code-block:: Python tmp_dir = Path(mkdtemp()) msh_file = tmp_dir / "bhe.msh" bhe_mesh( width=20, length=30, depth=40, x_BHE=10, y_BHE=10, bhe_depth=25, out_name=msh_file, ) .. GENERATED FROM PYTHON SOURCE LINES 35-38 Now we convert the gmsh mesh to the VTU format with msh2vtu. Passing the list of dimensions [1, 3] to msh2vtu ensures, that the line elements will also be part of the domain mesh. .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python msh2vtu( msh_file, output_path=tmp_dir, dim=[1, 3], reindex=True, log_level="ERROR" ) .. rst-class:: sphx-glr-script-out .. code-block:: none 0 .. GENERATED FROM PYTHON SOURCE LINES 45-46 Load the domain mesh and extract BHE line: .. GENERATED FROM PYTHON SOURCE LINES 48-51 .. code-block:: Python mesh = pv.read(tmp_dir / "bhe_domain.vtu") bhe_line = mesh.extract_cells_by_type(pv.CellType.LINE) .. GENERATED FROM PYTHON SOURCE LINES 52-53 Visualize the mesh: .. GENERATED FROM PYTHON SOURCE LINES 55-67 .. code-block:: Python p = Plotter() p.add_mesh(mesh, style="wireframe", color="grey") p.add_mesh( mesh.clip("x", bhe_line.center, crinkle=True), show_edges=True, scalars="MaterialIDs", cmap="Accent", categories=True, scalar_bar_args={"vertical": True, "n_labels": 2, "fmt": "%.0f"}, ) p.add_mesh(bhe_line, color="r", line_width=3) p.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /auto_examples/howto_meshlib/images/sphx_glr_plot_bhe_mesh_001.png :alt: plot bhe mesh :srcset: /auto_examples/howto_meshlib/images/sphx_glr_plot_bhe_mesh_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /builds/ogs/tools/ogstools/docs/auto_examples/howto_meshlib/images/sphx_glr_plot_bhe_mesh_001.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.545 seconds) .. _sphx_glr_download_auto_examples_howto_meshlib_plot_bhe_mesh.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_bhe_mesh.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_bhe_mesh.py `