# Visualizing the difference of two sets of VTK files

I have two sets of 300 VTK files and I want to get a graph comparing the average difference of the two sets. All files have a structured grid containing a scalar value named phi. At the end, I need a graph showing the average difference of each grid for every grid.

I have computed the difference at each cell using a Programmable Filter with the following code, from a previous question(here):

phi0 = inputs[0].PointData['phi']
phi1 = inputs[1].PointData['phi']
output.PointData.append(phi1-phi0, 'difference')


However, I do not understand how can I compute the average value of the whole grid(sum all differences and divide by the number of cells) and then plot that for every grid I have.

Any suggestions?

The answer to your question is that you can change your Programmable Filter output type to a vtkPolyData and set the Script to:

phi0 = inputs[0].PointData['phi']
phi1 = inputs[1].PointData['phi']
dd = abs(phi1-phi0) #note absolute value here
ss = sum(dd)

points = vtk.vtkPoints()
points.InsertPoint(0, [0, 0, 0])
output.SetPoints(points)
globalsum = vtk.vtkDoubleArray()
globalsum.SetName("sum")
globalsum.InsertValue(0, ss/inputs[0].GetNumberOfPoints())