pyvista.DataSet.volume

Contents

pyvista.DataSet.volume#

property DataSet.volume: float[source]#

Return the mesh volume.

This will return 0 for meshes with 2D cells.

Returns:
float

Total volume of the mesh.

Examples

Get the volume of a cube of size 4x4x4. Note that there are 5 points in each direction.

>>> import pyvista as pv
>>> mesh = pv.ImageData(dimensions=(5, 5, 5))
>>> mesh.volume
64.0

A mesh with 2D cells has no volume.

>>> mesh = pv.ImageData(dimensions=(5, 5, 1))
>>> mesh.volume
0.0

pyvista.PolyData is special as a 2D surface can enclose a 3D volume. This case uses a different methodology, see pyvista.PolyData.volume().

>>> mesh = pv.Sphere()
>>> mesh.volume
0.51825