Compute volume of polygonal mesh (volume enclosed by the surface)

As you mentioned in your other post one way is to create a volume mesh of your domain and evaluate the volume of each element. If your domain is convex and has no holes you can use the 3D Delaunay filter otherwise you will need some external meshing tool capable of filling the volume of your surface.

Assuming a triangulated surface (if not use Triangulate filter) a different way is the following:

  • Pick an arbitrary point P in space (barycenter of the surface mesh works the best).
  • Sum the signed volumes of the tetrahedra formed by each face triangle and P. [1]

Example:

  1. Open: disk_out_ref.ex2 available in the examples directory
  2. Apply MergeBlocks ( no need if you don’t have multiblock data)
  3. Apply Extract Surface ( no need in your case but here the mesh has volume elements already)
  4. Apply Triangulate
  5. Apply Programmable Filter using this as a script
import numpy as np

input0 = inputs[0]

numTriangles = input0.GetNumberOfCells()
volumeArray = np.empty(numTriangles , dtype=np.float64)
for i in range(numTriangles):
       cell = input0.GetCell(i)
       p1 = input0.GetPoint(cell.GetPointId(0))
       p2 = input0.GetPoint(cell.GetPointId(1))
       p3 = input0.GetPoint(cell.GetPointId(2))
       p4 = [0,0,0] # use barycenter of surface for better results.
       volumeArray[i] = vtk.vtkTetra.ComputeVolume(p1,p2,p4,p3)


output.CellData.append(volumeArray, "Volume")
  1. Now we just need to sum these values:
    i. one way is to run PythonCalculator with sum(Volume) as expression it. It will add the value as cell data to all elements
    ii. OR you can run Descriptive Statistics and select “Volume” as variable of interest.

these steps with ParaView 5.11 on Linux give me 1629.6572304587103 IntegrateVariables applied on the original data returns 1629.73

[1] It works because of Divergence Theorem ! See A symbolic method for calculating the integral properties of arbitrary nonconvex polyhedra | IEEE Journals & Magazine | IEEE Xplore if you do not have access check this math - How to calculate the volume of a 3D mesh object the surface of which is made up triangles - Stack Overflow

2 Likes