.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_quickstart/plot_meshseries.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_quickstart_plot_meshseries.py: Read mesh from file (vtu or xdmf) into pyvista mesh ===================================================== .. GENERATED FROM PYTHON SOURCE LINES 8-10 .. code-block:: Python from ogstools import examples .. GENERATED FROM PYTHON SOURCE LINES 11-18 To read your own data as a mesh series you can do: .. code-block:: python from ogstools.meshlib import MeshSeries mesh_series = MeshSeries("filepath/filename_pvd_or_xdmf") .. GENERATED FROM PYTHON SOURCE LINES 20-22 MeshSeries takes as mandatory argument a str OR pathlib.Path that represents the location of the pvd or xdmf file. Here, we load example data: .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python ms = examples.load_meshseries_HT_2D_XDMF() ms # print MeshSeries meta information .. rst-class:: sphx-glr-script-out .. code-block:: none MeshSeries: filepath: /builds/ogs/tools/ogstools/ogstools/examples/meshseries/2D_single_fracture_HT_2D_single_fracture.xdmf spatial_unit: m data_type: xdmf timevalues: 0.0s to 0.0s in 97 steps reader: rawdata_file: /builds/ogs/tools/ogstools/ogstools/examples/meshseries/2D_single_fracture_HT.h5 .. GENERATED FROM PYTHON SOURCE LINES 27-31 Accessing time values ======================= All time value (in seconds) are within a range (e.g. can be converted to list) Python slicing is supported. .. GENERATED FROM PYTHON SOURCE LINES 31-40 .. code-block:: Python print(f"First 3 time values are: {ms.timevalues()[:3]}.") # Accessing a specific time step timestep = 10 print(f"Time value at step {timestep} is {ms.timevalues()[timestep]} s.") .. rst-class:: sphx-glr-script-out .. code-block:: none First 3 time values are: [ 0. 900. 1800.]. Time value at step 10 is 9000.0 s. .. GENERATED FROM PYTHON SOURCE LINES 41-42 To get a single mesh at a specified timestep. Read data is cached. .. GENERATED FROM PYTHON SOURCE LINES 42-51 .. code-block:: Python mesh_ts10 = ms.mesh(timestep) # The mesh taken from a specific time step of the mesh series is a pyvista mesh # Here we use pyvista functionality plot. mesh_ts10.plot(show_edges=True) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /auto_examples/howto_quickstart/images/sphx_glr_plot_meshseries_001.png :alt: plot meshseries :srcset: /auto_examples/howto_quickstart/images/sphx_glr_plot_meshseries_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /builds/ogs/tools/ogstools/docs/auto_examples/howto_quickstart/images/sphx_glr_plot_meshseries_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 52-54 You can select a time steps with the `[] operator` This example shows the last time step (result) and shows meta information about the mesh. .. GENERATED FROM PYTHON SOURCE LINES 54-58 .. code-block:: Python print(ms[-1]) .. rst-class:: sphx-glr-script-out .. code-block:: none Mesh (0x7cd485c942e0) N Cells: 171 N Points: 190 X Bounds: 0.000e+00, 1.000e+01 Y Bounds: 0.000e+00, 2.000e+01 Z Bounds: 0.000e+00, 0.000e+00 N Arrays: 4 .. GENERATED FROM PYTHON SOURCE LINES 59-61 MeshSeries from PVD file ========================= .. GENERATED FROM PYTHON SOURCE LINES 61-65 .. code-block:: Python ms = examples.load_meshseries_THM_2D_PVD() ms.mesh(0).plot() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /auto_examples/howto_quickstart/images/sphx_glr_plot_meshseries_002.png :alt: plot meshseries :srcset: /auto_examples/howto_quickstart/images/sphx_glr_plot_meshseries_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /builds/ogs/tools/ogstools/docs/auto_examples/howto_quickstart/images/sphx_glr_plot_meshseries_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 66-80 Accessing Variables ==================== A MeshSeries provides access to all values of variable at all time steps. 1. mesh - Get a PyVista mesh at a specific time step and use PyVista functions (e.g., `cell_data `_). - Efficient for a small set of timesteps, but all data is needed. - :py:mod:`ogstools.meshlib.mesh_series.MeshSeries.mesh` - :py:mod:`ogstools.meshlib.mesh_series.MeshSeries.__getitem__` 2. data[] - Get a specific variable over a specific time range. - Efficient (only XDMF) for a large set of timesteps , but a small amount of cells / points is needed. - :py:mod:`ogstools.meshlib.mesh_series.MeshSeries.data` .. GENERATED FROM PYTHON SOURCE LINES 80-115 .. code-block:: Python # # Indexing with data() # -------------------- # `MeshSeries.data("")`` returns an object, that behaves like a # `Numpy ndarray `_. # It allows `multidimensional indexing on ndarrays `_ # beyond `Python slicing `_. # Typically, the first dimension is the time step, second dimension is the number of points/cells, # and the last dimension is the number of components of the variable. # # Be aware that dimensions of length 1 are omitted, obeying to the rules of # `Indexing on ndarrays `_. # Data does not work for geometry/points or topology/cells). ms = examples.load_meshseries_HT_2D_XDMF() # This mesh series has 97 time steps and 190 points. # Temperature is a scalar, Darcy velocity is a vector with 2 components. Both are defined at points. # 1. No range for a dimension (just single time step) -> this dimension gets omitted ms.data("temperature")[1, :] # shape is (190,) # 2. Select range with length for a dimension to keep dimension ms.data("temperature")[1:2, :] # shape is (1, 190) # 3. Select all values for all dimensions ms.data("temperature")[:] # shape is (97,190) # 4. Negative indices are allow - here we select last 2 steps ms.data("darcy_velocity")[-2:, 1:4, :] # shape is(2, 3, 2) # 5. Use select to get a specific range of time steps temp_on_some_point = ms.data("temperature")[1:3, 2:5] # shape is (2,3) print( f"Temperature at time steps 1 and 2 for points 2, 3 and 4: {temp_on_some_point}" ) .. rst-class:: sphx-glr-script-out .. code-block:: none Temperature at time steps 1 and 2 for points 2, 3 and 4: [[353.00036868 303. 353. ] [353.00012081 303. 353. ]] .. GENERATED FROM PYTHON SOURCE LINES 116-121 Values function --------------- Convenience function to get all values of a variable. See :py:mod:`ogstools.meshlib.mesh_series.MeshSeries.values`. .. GENERATED FROM PYTHON SOURCE LINES 121-128 .. code-block:: Python dv_all = ms.values("darcy_velocity") print( f"Shape of darcy_velocity (time steps, num of points, x and y): {dv_all.shape}" ) # temperature is a scalar - the last dimension of length 1 is omitted t_all = ms.values("temperature") print(f"Shape of temperature (time steps, num of points): {t_all.shape}") .. rst-class:: sphx-glr-script-out .. code-block:: none Shape of darcy_velocity (time steps, num of points, x and y): (97, 190, 2) Shape of temperature (time steps, num of points): (97, 190) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.178 seconds) .. _sphx_glr_download_auto_examples_howto_quickstart_plot_meshseries.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_meshseries.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_meshseries.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_meshseries.zip `