# Calculating Laplacian of scalar field with a Python Calculator filter results in exactly 0 at every point

I have velocity data from a CFD calculation. The data are the values of the x component of velocity (u) and the y component of velocity (v) on a 2D domain. The mesh is non-uniform.

I’m trying to calculate the Laplacian of u. (And the Laplacian of v, but for now, I’m just trying to get u correctly). The first thing I tried is to use a Python Calculator filter with the expression “laplacian(u)”. The outputted value for each point is exactly 0. I also tried the expression “divergence(gradient(u))”. This is also 0 for every point. Also, the output for the expression “gradient(gradient(u))” is exactly 0 for every component for every point.

The Laplacian of u should not, in fact, be exactly 0. The flow field is complex. In addition, when I use a Python Calculator filter with the expression “gradient(u)”, the result is, first of all, not exactly 0. And visualizing grad(u) on a RenderView, the results make sense. The du/dx and du/dy field are what I expect. I can see that d2u/dx2 and d2u/dy2 should be non-zero in at least some regions of the domain.

I would greatly appreciate any insight or suggestions. Why does “laplacian(u)” not work as expected? Why does gradient(gradient(u)) result in zeros for every component and every point?

Do these Python Calculator functions expect a particular data format, and perhaps my data is not the correct format?

Also, are there any suggestions for other ways of calculating the Laplacian of the velocity components to bypass this issue?

afaik there is no laplacian or divergence methods in numpy ?

Hi Matheiu, thanks for getting back to me. I’m relying on this list of functions for the Python Calculator (5. Filtering Data — ParaView Documentation 5.10.0 documentation). “laplacian” is listed, although the description is strange and seems incorrect.

But also, why does the expression “gradient(gradient(u))” return all zeros? I know that “gradient(u)” works, so why would taking the gradient again mess things ups?

Thats a good question, more investigation is needed.

Do you have any suggestions for workarounds? My basic need is to calculate the second derivatives of scalar point data on a 2D domain.

I may have found a solution. I noticed that there are duplicate points in my data. I used the “Clean to Grid” filter on the data. After applying this, the outputs of “laplacian”, etc. are all non-zero. I think the numbers make sense.

Two questions:

1. The “Clean” filter was grayed out. What’s the difference between “Clean” and “Clean to Grid”, and why was “Clean” grayed out? Do they take different data types?
2. When data with duplicate points is passed to “laplacian”, etc., is the expected behavior to return 0?
• Clean is for polydata input
• CleanToGrid is for unstructured grid

Not great, i’ve opened an issue: https://gitlab.kitware.com/paraview/paraview/-/issues/21302

When data with duplicate points is passed to “laplacian”, etc., is the expected behavior to return 0?

No idea, needs investigation.