# Compute second order derivative of velocity

**URL:** https://discourse.paraview.org/t/compute-second-order-derivative-of-velocity/10593
**Category:** ParaView Support
**Created:** [October 25, 2022, 1:18pm UTC](https://discourse.paraview.org/t/compute-second-order-derivative-of-velocity/10593 "2022-10-25T13:18:51Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Boone](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@Boone](https://discourse.paraview.org/u/Boone)
#### Post date: [October 25, 2022, 1:18pm UTC](https://discourse.paraview.org/t/compute-second-order-derivative-of-velocity/10593/1 "2022-10-25T13:18:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Christos\_Tsolakis](https://discourse.paraview.org/user_avatar/discourse.paraview.org/christos_tsolakis/32/4450_2.png) [@Christos\_Tsolakis](https://discourse.paraview.org/u/Christos_Tsolakis)
#### Post date: [October 25, 2022, 1:32pm UTC](https://discourse.paraview.org/t/compute-second-order-derivative-of-velocity/10593/2 "2022-10-25T13:32:10Z")

</div>

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](https://docs.paraview.org/en/latest/ReferenceManual/pythonProgrammableFilter.html?highlight=programmable#understanding-the-programmable-modules)

---

<div class="post-metadata">

### Author: ![Boone](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@Boone](https://discourse.paraview.org/u/Boone)
#### Post date: [October 25, 2022, 1:46pm UTC](https://discourse.paraview.org/t/compute-second-order-derivative-of-velocity/10593/3 "2022-10-25T13:46:58Z")

</div>

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.

 ![Capture d’écran du 2022-10-25 15-36-46](https://discourse.paraview.org/uploads/default/original/2X/c/cbb7f323fae2fc684c1142aedfc45a386c6a5bdb.png)

---

<div class="post-metadata">

### Author: ![Christos\_Tsolakis](https://discourse.paraview.org/user_avatar/discourse.paraview.org/christos_tsolakis/32/4450_2.png) [@Christos\_Tsolakis](https://discourse.paraview.org/u/Christos_Tsolakis)
#### Post date: [October 25, 2022, 1:55pm UTC](https://discourse.paraview.org/t/compute-second-order-derivative-of-velocity/10593/4 "2022-10-25T13:55:22Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Kenneth\_Moreland](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kenneth_moreland/32/15033_2.png) [@Kenneth\_Moreland](https://discourse.paraview.org/u/Kenneth_Moreland)
#### Post date: [October 25, 2022, 2:04pm UTC](https://discourse.paraview.org/t/compute-second-order-derivative-of-velocity/10593/5 "2022-10-25T14:04:27Z")

</div>

@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.

 ![Screen Shot 2022-10-25 at 7.59.00 AM](https://discourse.paraview.org/uploads/default/original/2X/9/92a2be1eb1d6d636903e4dbb5313281c756481e6.png)

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 Name`s, 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.

---

<div class="post-metadata">

### Author: ![Boone](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@Boone](https://discourse.paraview.org/u/Boone)
#### Post date: [October 25, 2022, 2:25pm UTC](https://discourse.paraview.org/t/compute-second-order-derivative-of-velocity/10593/6 "2022-10-25T14:25:52Z")

</div>

Thank you for your answers.

I managed to do it with the programmable filter:

```auto
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 :

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

```

and

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

```

but none of them works.

---

<div class="post-metadata">

### Author: ![Christos\_Tsolakis](https://discourse.paraview.org/user_avatar/discourse.paraview.org/christos_tsolakis/32/4450_2.png) [@Christos\_Tsolakis](https://discourse.paraview.org/u/Christos_Tsolakis)
#### Post date: [October 25, 2022, 2:56pm UTC](https://discourse.paraview.org/t/compute-second-order-derivative-of-velocity/10593/7 "2022-10-25T14:56:58Z")

</div>

> [@Boone](#):
>
> Do you know haw to extract the first component of the gradient of U directly in the programmable filter ? I tried :

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

```python
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.
