I’m trying to compute the gradient of displacement. I used Gradient and ComputeDerivatives, however, they gave me different results. I’m wondering what’s the “more correct” one and why they computed differently.
My steps were as follows:
Gradient, select “displacement” as “Scalar Array”, check “Compute Gradient”, “Apply”
@Francois_Mazen’s reply is correct, but I can give a bit more detail on what these two filters are doing.
But before that, I need to recall that data in ParaView is (usually) represented as a mesh of cells. For the purposes of this discussion, we will assume that the data field is represented as samples on the points of the mesh (i.e. “point data”), and these values are interpolated within each cell. This results in the field being C0 continuous (meaning there are no discontinuities, particularly when going from cell to cell), but the field is not C1 continuous. The derivative is continuous within each cell but different as you go cell to cell.
Because the gradient/derivative is continuous within each cell but not across cells, the Compute Derivatives filter just computes the derivative within each cell where the derivative is well defined. It finds the centroid of each cell, computes the derivative there, and records the result as a cell data field.
Even though the gradient/derivative is ill defined at the points (because it is discontinuous there), it is often the case where you want a reasonable approximation. This comes up a lot when you want to use the gradient for shading, but it is also useful for other operations such as finding interfaces where a field transitions quickly. To provide this approximation, the Gradient filter looks at all cells incident on a point, computes the derivative/gradient at that point location within the cell, and then averages the values. Because it is computing derivatives at different locations, the Gradient filter will give a slightly different answer than Compute Derivatives.
That said, the Gradient filter is slower than Compute Derivatives because it has to compute the derivative multiple times within each cell. Because of this, the Gradient filter has a Faster Approximation option (in the advanced properties) that instead computes the gradient/derivative once in the centroid of each cell and then averages those out at each point. This is equivalent to running Compute Derivatives and then Cell Data to Point Data, and you will find that you will get the same answer if you run Gradient with Faster Approximation and Compute Derivatives followed by Cell Data to Point Data.