# Single and double derivative of variables

**URL:** https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639
**Category:** ParaView Support
**Created:** [May 14, 2025, 11:03pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639 "2025-05-14T23:03:50Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![scabo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@scabo](https://discourse.paraview.org/u/scabo)
#### Post date: [May 14, 2025, 11:03pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/1 "2025-05-14T23:03:50Z")

</div>

Hi  
I want to calculate single and double derivative of different variable and add them together to get the result. How can i do it in paraview? I have attached the picture of the expression i need to calculate. Can i use any filter, etc.or define the gradient in a particular direction? any help is appreciated. thanks

 ![derivatives_calc_paraview_support](https://discourse.paraview.org/uploads/default/original/3X/d/6/d65c448704f0f122bca3a50a163807f6a531a214.png)

---

<div class="post-metadata">

### Author: ![scabo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@scabo](https://discourse.paraview.org/u/scabo)
#### Post date: [May 16, 2025, 8:37pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/2 "2025-05-16T20:37:16Z")

</div>

Hey any idea on this?

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [May 17, 2025, 2:08pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/3 "2025-05-17T14:08:32Z")

</div>

By applying the `Gradient` filter **twice** to a single scalar variable, you can obtain the Hessian matrix. Utilizing its elements should allow you to perform the desired calculations. However, since first-order numerical differentiation is performed twice, caution may be required regarding potential loss of accuracy.

---

<div class="post-metadata">

### Author: ![scabo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@scabo](https://discourse.paraview.org/u/scabo)
#### Post date: [May 17, 2025, 2:58pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/4 "2025-05-17T14:58:47Z")

</div>

Hi  
thanks, It has created a 9 sets of new variables of double derivative, then i want to form a variable with sum of those. But when i am using a calculator to create the sum how should i call them? like gradient\_7 is not working nor gradient 7. Can you give some idea?

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [May 17, 2025, 3:08pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/5 "2025-05-17T15:08:01Z")

</div>

You may need to enclose it in double quotation marks, like “gradient\_7”.

---

<div class="post-metadata">

### Author: ![scabo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@scabo](https://discourse.paraview.org/u/scabo)
#### Post date: [May 17, 2025, 3:10pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/6 "2025-05-17T15:10:39Z")

</div>

No its not working-can i share my state?

---

<div class="post-metadata">

### Author: ![scabo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@scabo](https://discourse.paraview.org/u/scabo)
#### Post date: [May 17, 2025, 3:17pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/7 "2025-05-17T15:17:39Z")

</div>

is working if i define under the variable, but i want to take different item from the 9 derivatives and sum them. So what should be the input filter to that calculator? like i took second derivative of 2 different variables and want to sum different items for both of them. SO shoud i define them one by one or give the input filter to the main .encas file?

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [May 17, 2025, 3:55pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/8 "2025-05-17T15:55:23Z")

</div>

I am not entirely sure if I understand your question correctly, but if you want to include second-order derivatives of two different variables in a single dataset, you can apply the `Gradient` filter twice in succession to each variable. As an example, I am attaching a state file  
[hess.pvsm](https://discourse.paraview.org/uploads/short-url/2X8g3yEIZamxdSUvHSJfQDWnDkC.pvsm) (966.9 KB)

---

<div class="post-metadata">

### Author: ![scabo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@scabo](https://discourse.paraview.org/u/scabo)
#### Post date: [May 17, 2025, 6:44pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/9 "2025-05-17T18:44:45Z")

</div>

Hi ky

I have done double derivative, but when i am plotting the contour plot due to some reason the contours are showing along the mesh line. Means the effect of the mesh is visible on the contour plots. Do you know how to get rid of this?

---

<div class="post-metadata">

### Author: ![scabo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@scabo](https://discourse.paraview.org/u/scabo)
#### Post date: [May 18, 2025, 11:49am UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/10 "2025-05-18T11:49:23Z")

</div>

I was talking about this issue. THe contours of the derivatives are plotted along the mesh line which is absurd

 ![paraview_meshlines](https://discourse.paraview.org/uploads/default/original/3X/b/6/b62dc898f66e6db1db913a228ca93c87f7b7abc5.png)  
Do you know how to get rid of this problem?

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [May 18, 2025, 2:53pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/11 "2025-05-18T14:53:06Z")

</div>

Does the Fluent mesh in this case share the nodes of adjacent cells? If interface boundaries are used, the nodes are not shared, which may result in discontinuities in the differentiation results. Is it possible to display a picture showing the mesh lines?

---

<div class="post-metadata">

### Author: ![scabo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@scabo](https://discourse.paraview.org/u/scabo)
#### Post date: [May 18, 2025, 5:26pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/12 "2025-05-18T17:26:42Z")

</div>

Hi, thanks. Here is the picture of the mesh. It is a O grid mesh which is very symmetric.

 ![mesh_cs](https://discourse.paraview.org/uploads/default/original/3X/a/8/a808f906d045f37048b10d3ca5f87ff2fbd4c614.png)  
Second derivatives seem to have some artefacts of the mesh. Any suggestions pls..thanks

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [May 18, 2025, 10:12pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/13 "2025-05-18T22:12:52Z")

</div>

As I also wrote in my first post, performing a first-order accurate numerical differentiation twice might cause issues with accuracy. Especially in areas like the boundaries of an O-Grid, this decrease in accuracy will likely be significant. There might not be an implementation of higher-order accurate numerical differentiation within ParaView.

---

<div class="post-metadata">

### Author: ![scabo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@scabo](https://discourse.paraview.org/u/scabo)
#### Post date: [May 19, 2025, 10:15am UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/14 "2025-05-19T10:15:51Z")

</div>

Okay-thanks. What other ways can I do the second derivative contour plot? In Matlab or something?

---

<div class="post-metadata">

### Author: ![scabo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@scabo](https://discourse.paraview.org/u/scabo)
#### Post date: [May 19, 2025, 10:27am UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/15 "2025-05-19T10:27:57Z")

</div>

Also if i do extract cells or extract surface, will the artefacts go away? Or is it common with second derivatives? Many thanks

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [May 19, 2025, 1:39pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/16 "2025-05-19T13:39:25Z")

</div>

The function for calculating gradients in the VMTK library at the link below appears to perform differentiation with high-order accuracy. I haven’t tried it myself, but it might be worth a try.

> <https://github.com/vmtk/vmtk/blob/6c189dd6ee644a466498bd382b0c19229f20daa5/vtkVmtk/DifferentialGeometry/vtkvmtkUnstructuredGridGradientFilter.cxx>

---

<div class="post-metadata">

### Author: ![scabo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@scabo](https://discourse.paraview.org/u/scabo)
#### Post date: [May 19, 2025, 3:25pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/17 "2025-05-19T15:25:42Z")

</div>

Thanks-i will have a look,

---

<div class="post-metadata">

### Author: ![ahernsean](https://discourse.paraview.org/user_avatar/discourse.paraview.org/ahernsean/32/13743_2.png) [@ahernsean](https://discourse.paraview.org/u/ahernsean)
#### Post date: [May 20, 2025, 7:00pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/18 "2025-05-20T19:00:27Z")

</div>

Do you have ghost cells in your mesh at the block boundaries? To compute second derivatives, you’ll need at least two layers of ghosts at each block boundary to ensure continuity. Otherwise, you’ll definitely get artifacts at block boundaries.

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [May 20, 2025, 8:39pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/19 "2025-05-20T20:39:48Z")

</div>

Here are some potential checkpoints for this analysis:

- Since ParaView doesn’t have a second derivative function, the **Hessian matrix** is calculated by applying the **first-order accurate gradient (Gradient Filter)** twice.
- Because it’s a first-order accurate gradient, it will be constant within a cell. However, the Gradient Filter maintains continuity by taking the average of the gradient values of the cells sharing a point as the derivative value at that point. Nevertheless, a **loss of accuracy** is likely unavoidable when applying such a derivative twice.
- It’s currently **unclear if the observed artifacts** are a result of applying the first-order accurate gradient twice. We need to check if using a **higher-order accurate derivative from VMTK** improves the situation.

* * *

### Other Concerns:

- Has **cell data been converted to point data**? (It’s advisable to enable this conversion in the Fluent to EnSight format export options.)
- Has the issue of **internal boundaries being outputted** been resolved? (See: [https://discourse.paraview.org/t/fluent-dat-file-export-on-gold-ensight-paraview-format-creating-mesh-lines/16500](https://discourse.paraview.org/t/fluent-dat-file-export-on-gold-ensight-paraview-format-creating-mesh-lines/16500))
- Was the **Gradient Filter applied before cutting the tube**?
- Are there any **ghost cell issues**? (Given that parallel visualization doesn’t appear to be used, this is likely not an issue.)
- Are there **multiple blocks**? If so, applying the **Merge Blocks filter** first might lead to improvements.

---

<div class="post-metadata">

### Author: ![scabo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@scabo](https://discourse.paraview.org/u/scabo)
#### Post date: [May 20, 2025, 11:22pm UTC](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639/20 "2025-05-20T23:22:34Z")

</div>

Hi Kyoshimi

Many thanks. Yes point data is plotted, Gradient filter is applied on a slice from the 3D pipe, I have not added any ghost cells, no there is a single block.  
About the ghost cells, according to the post above by Sean, i may need to add layer of ghost cells but i am not familiar with that atm. But will try asap. Do you have any comments? thanks again

[Next page](https://discourse.paraview.org/t/single-and-double-derivative-of-variables/16639.md?page=2)
