Compute second order derivative of velocity

Hi everyone,

I am a new user of Paraview and I would like to compute the velocity gradient invariant for a channel flow simulation as well as quantities involving 2nd order velocity derivatives. For that reason I have to compute the 1st and 2nd order velocity derivatives.

I manage to compute them with the calculator filter one by one but I do not succeed in storing them in order to perform sums and products of these quantities: Q_A=- \frac{1}{2} \left( \left( \frac{\partial u_1}{\partial x_1}\right)^2 +\left( \frac{\partial u_2}{\partial x_2}\right)^2+ 2\left( \frac{\partial u_1}{\partial x_2}\frac{\partial u_2}{\partial x_1}\right)\right).

Similarly, I would like to compute l= \frac{\frac{\partial u_1}{\partial x_1}}{\frac{\partial^2 u_1}{\partial x_1^2}}

Is it possible to compute these quantities with the programmable filter ? If yes, could you help me ? I do not find any example of the use of programmable filter to create new quantities.

Thanks,
Boone

Hi @Boone and welcome to discourse!

In the calculator filter use the Result Array Name field to assign a name for the new variable. You can use this name in new calculator instances after that.

Alternatively here are some examples of using the programmable filter:
https://docs.paraview.org/en/latest/ReferenceManual/pythonProgrammableFilter.html?highlight=programmable#understanding-the-programmable-modules

Thanks for your answer Christos. This is what I did but I do not find a way of computing the ratio between the 1st and 2nd order velocity since the calculator is only applied to 1 gradient block (see picture) I cannot use both the 1st and second order derivative in the same calculator. I have the same issue for the product between du1/dx2 and du2/dx1.

The calculator(as any other filter) can see only variables in the same pipeline it belongs too.
In your case d1v and d1u are in different branches and thus have no knowledge of each other.
Try to add all of them in the same pipeline branch by selecting each time the previous as a source. This will allow to carry the results from previous computations into each calculator instance.

If you use the programmable filter you can have all these steps in a single filter. See figure 5.30 in the provided link.

@Boone, have you tried using the Gradient filter? You can take the gradient of a vector field and get the 9-component second derivative. The Gradient filter is also capable of secondary values (such as divergence, vorticity, and Q criterion), which you can turn on with the advanced values.

If that does not work, like @Christos_Tsolakis said, you can make both derivatives available in your pipeline by simply connecting the d1u filter to the d2v filter. This will make the outputs of both available at the same time (as long as you have unique Result Array Names, as @Christos_Tsolakis also said). You could instead combine the output of the two calculators with the Append Attributes filter, but @Christos_Tsolakis’s solution is easier.

1 Like

Thank you for your answers.

I managed to do it with the programmable filter:

input0=inputs[0]
U=input0.CellData["U_mean"]
gradu=gradient(U)
output.CellData.append(gradu, "du")

gradgradu=gradient(gradient(U))
output.CellData.append(gradgradu, "d2u")

V=input0.CellData["V_mean"]
gradv=gradient(V)
output.CellData.append(gradv, "dv")

gradgradv=gradient(gradient(V))
output.CellData.append(gradgradv, "d2v")

Do you know haw to extract the first component of the gradient of U directly in the programmable filter ? I tried :

l_VK=0.41*du_Y/"d2u_4"
output.CellData.append(l_VK, "l_VK")

and

l_VK=0.41*gradu[0]/"d2u_4"
output.CellData.append(l_VK, "l_VK")

but none of them works.

You can use numpy 2D array slicing i.e.

l_VK=0.41*gradu[:,0]
output.CellData.append(l_VK, "l_VK")

dividing with a string "d2u_4" is not going to work, make sure you define
d2u_4 as a variable beforehand.