Parallel Files

The VTK library supports parallel file formats. Reading meshes broken up into several files is natively supported by VTK and PyVista.

# sphinx_gallery_thumbnail_number = 1
import pyvista as pv
from pyvista import examples
import os

Let’s go ahead and download the sample dataset containing an pyvista.UnstructuredGrid broken up into several files.

# Do not capture output because we'll demo how to read the file
examples.download_blood_vessels()
HeaderData Arrays
UnstructuredGridInformation
N Cells39353
N Points48823
X Bounds5.300e+01, 1.210e+02
Y Bounds5.000e+01, 9.700e+01
Z Bounds6.400e+01, 1.820e+02
N Arrays5
NameFieldTypeN CompMinMax
node_valuePointsint3210.000e+003.000e+00
simerr_typePointsint3210.000e+003.000e+00
densityCellsfloat3212.203e-015.232e-01
velocityCellsfloat323-3.607e-018.989e-02
shearstressCellsfloat3216.160e-051.726e-02


The above code downloaded a dataset containing a set of parallel files for a blood vessel mesh and returned an pyvista.UnstructuredGrid - we did not grab that UnstructuredGrid, so that we could demo how to use these types of files.

Let’s inspect where this downloaded our dataset:

path = os.path.join(pv.EXAMPLES_PATH, "blood_vessels")
os.listdir(path)

Out:

['T0000000500', 'T0000000500.pvtu']
os.listdir(os.path.join(path, "T0000000500"))

Out:

['003.vtu', '001.vtu', '002.vtu', '000.vtu']

Note that a .pvtu file is available along side a directory. This directory contains all the parallel files or pieces that make the whole mesh. We can simply read the .pvtu file and VTK will handle putting the mesh together.

filename = os.path.join(path, "T0000000500.pvtu")
mesh = pv.read(filename)
mesh
HeaderData Arrays
UnstructuredGridInformation
N Cells39353
N Points48823
X Bounds5.300e+01, 1.210e+02
Y Bounds5.000e+01, 9.700e+01
Z Bounds6.400e+01, 1.820e+02
N Arrays5
NameFieldTypeN CompMinMax
node_valuePointsint3210.000e+003.000e+00
simerr_typePointsint3210.000e+003.000e+00
densityCellsfloat3212.203e-015.232e-01
velocityCellsfloat323-3.607e-018.989e-02
shearstressCellsfloat3216.160e-051.726e-02


Plot the pieced together mesh

mesh.plot(scalars="node_value", categories=True)
../../_images/sphx_glr_read-parallel_001.png

Out:

[(247.6924377112037, 234.1924377112037, 283.6924377112037), (87.0, 73.5, 123.0), (0.0, 0.0, 1.0)]
mesh.plot(scalars="density")
../../_images/sphx_glr_read-parallel_002.png

Out:

[(247.6924377112037, 234.1924377112037, 283.6924377112037), (87.0, 73.5, 123.0), (0.0, 0.0, 1.0)]

Total running time of the script: ( 0 minutes 4.215 seconds)

Gallery generated by Sphinx-Gallery