.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_meshlib/plot_meshlib_vtu_input.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_meshlib_vtu_input.py: Creating meshes from vtu surface files ====================================== .. sectionauthor:: Tobias Meisel (Helmholtz Centre for Environmental Research GmbH - UFZ) For this example we create meshes from surface layers. .. GENERATED FROM PYTHON SOURCE LINES 11-31 .. code-block:: default from pathlib import Path # To get example vtu files import numpy as np # For visualization only import ogstools.meshplotlib as mpl # For visualization only from ogstools.definitions import ROOT_DIR # To get example vtu files from ogstools.meshlib.boundary import Layer from ogstools.meshlib.boundary_set import LayerSet from ogstools.meshlib.boundary_subset import Surface from ogstools.meshlib.region import ( to_region_prism, to_region_simplified, to_region_tetraeder, to_region_voxel, ) mpl.setup.reset() mpl.setup.length.output_unit = "km" mpl.setup.aspect_limits = [0.2, 5.0] .. GENERATED FROM PYTHON SOURCE LINES 32-33 The loaded surfaces are defined within VTU files and adhere to properties such as non-intersecting boundaries with consistent x and y bounds. Alternatively, surfaces can also be created using PyVista with the same properties. .. GENERATED FROM PYTHON SOURCE LINES 33-42 .. code-block:: default surface_dir = ROOT_DIR / "meshlib/tests/data/mesh1/surface_data" surface1 = Surface(Path(surface_dir / "00_KB.vtu"), material_id=0) surface2 = Surface(Path(surface_dir / "01_q.vtu"), material_id=5) surface3 = Surface(Path(surface_dir / "02_krl.vtu"), material_id=2) surface4 = Surface(Path(surface_dir / "03_S3.vtu"), material_id=3) .. GENERATED FROM PYTHON SOURCE LINES 43-44 Create 3 layers from previously defined surfaces and add all layers to a layerset (ordererd from top to bottom) .. GENERATED FROM PYTHON SOURCE LINES 44-50 .. code-block:: default layer1 = Layer(top=surface1, bottom=surface2, num_subdivisions=2) layer2 = Layer(top=surface2, bottom=surface3, num_subdivisions=1) layer3 = Layer(top=surface3, bottom=surface4, num_subdivisions=0) layer_set1 = LayerSet(layers=[layer1, layer2, layer3]) .. GENERATED FROM PYTHON SOURCE LINES 51-52 From layerset creation of simplified meshes (sm), prism meshes (pm), voxel meshes (vm), tetraeder mesh (tm) is possible. .. GENERATED FROM PYTHON SOURCE LINES 52-58 .. code-block:: default sm = to_region_simplified(layer_set1, xy_resolution=200, rank=3).mesh pm = to_region_prism(layer_set1, resolution=200).mesh vm = to_region_voxel(layer_set1, resolution=[200, 200, 50]).mesh tm = to_region_tetraeder(layer_set1, resolution=200).mesh .. GENERATED FROM PYTHON SOURCE LINES 59-60 Visualize the prism mesh .. GENERATED FROM PYTHON SOURCE LINES 60-67 .. code-block:: default mesh = pm slices = np.reshape(mesh.slice_along_axis(n=4, axis="y"), (-1, 1)) fig = mpl.plot(slices, "MaterialIDs") for ax, slice in zip(fig.axes, np.ravel(slices)): ax.set_title(f"z = {slice.center[2]:.1f} {mpl.setup.length.data_unit}") .. image-sg:: /auto_examples/howto_meshlib/images/sphx_glr_plot_meshlib_vtu_input_001.png :alt: z = -168.5 m, z = -161.0 m, z = -147.7 m, z = -128.5 m :srcset: /auto_examples/howto_meshlib/images/sphx_glr_plot_meshlib_vtu_input_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 68-69 Visualize meshes with different meshing algorithm .. GENERATED FROM PYTHON SOURCE LINES 69-82 .. code-block:: default meshes = [sm, vm, pm, tm] names = [ "to_region_simplified", "to_region_voxel", "to_region_prism", "to_region_tetraeder", ] x_slices = np.reshape([mesh.slice("x") for mesh in meshes], (-1, 1)) fig = mpl.plot(x_slices, "MaterialIDs") for ax, name in zip(fig.axes, names): ax.set_title(name) .. image-sg:: /auto_examples/howto_meshlib/images/sphx_glr_plot_meshlib_vtu_input_002.png :alt: to_region_simplified, to_region_voxel, to_region_prism, to_region_tetraeder :srcset: /auto_examples/howto_meshlib/images/sphx_glr_plot_meshlib_vtu_input_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.156 seconds) .. _sphx_glr_download_auto_examples_howto_meshlib_plot_meshlib_vtu_input.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_meshlib_vtu_input.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_meshlib_vtu_input.ipynb `