# vtkGradientFilter on vtkUnstructuredGrid created by custom reader:

**URL:** https://discourse.vtk.org/t/vtkgradientfilter-on-vtkunstructuredgrid-created-by-custom-reader/10028
**Category:** Support
**Created:** [December 1, 2022, 3:42am UTC](https://discourse.vtk.org/t/vtkgradientfilter-on-vtkunstructuredgrid-created-by-custom-reader/10028 "2022-12-01T03:42:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ramen\_newdals](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ramen_newdals/32/7173_2.png) [@ramen\_newdals](https://discourse.vtk.org/u/ramen_newdals)
#### Post date: [December 1, 2022, 3:42am UTC](https://discourse.vtk.org/t/vtkgradientfilter-on-vtkunstructuredgrid-created-by-custom-reader/10028/1 "2022-12-01T03:42:29Z")

</div>

Hello All,

I have a reader that constructs a vtkUnstructuredGrid object that consists of VTK\_TETRA cells. I assign an array at each of the nodes in the vtkUnstructuredGrid object. I would like to use vtkGradientFilter to compute the gradient across the unstructured grid using the array as the input.

I have gone through the following page ([https://vtk.org/doc/nightly/html/classvtkGradientFilter.html#abed5e8488ed308deed09cb5daf24838a](https://vtk.org/doc/nightly/html/classvtkGradientFilter.html#abed5e8488ed308deed09cb5daf24838a)), but the example provided relies on using ports, but I do not have ports on my unstructuredGrid object (to my knowledge).

This is how I am apptempting to Calculate the gradient:

```
    vtkNew<vtkGradientFilter> gradient;
    gradient->SetInputData(unstructuredGrid);
    gradient->SetInputScalars(3, "u");
    gradient->SetResultArrayName("u_grad");
    gradient->Update();

```

Any Help is greatly appreciated!

---

<div class="post-metadata">

### Author: ![Francois\_Mazen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/francois_mazen/32/3290_2.png) [@Francois\_Mazen](https://discourse.vtk.org/u/Francois_Mazen)
#### Post date: [December 2, 2022, 8:38am UTC](https://discourse.vtk.org/t/vtkgradientfilter-on-vtkunstructuredgrid-created-by-custom-reader/10028/2 "2022-12-02T08:38:35Z")

</div>

Hi @ramen_newdals

Your code looks OK. `SetInputData` is the correct method to fed the filter with a dataset instead of an upstream connexion.  
Have tried to execute it?

Best,

---

<div class="post-metadata">

### Author: ![ramen\_newdals](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ramen_newdals/32/7173_2.png) [@ramen\_newdals](https://discourse.vtk.org/u/ramen_newdals)
#### Post date: [December 2, 2022, 7:19pm UTC](https://discourse.vtk.org/t/vtkgradientfilter-on-vtkunstructuredgrid-created-by-custom-reader/10028/3 "2022-12-02T19:19:54Z")

</div>

Hello @Francois_Mazen, my error was in the naming of my arrays 😅 thank you for your clarification of the methods correctness!
