# How to create a global variable?

**URL:** https://discourse.paraview.org/t/how-to-create-a-global-variable/4492
**Category:** ParaView Support
**Created:** [June 3, 2020, 1:32pm UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492 "2020-06-03T13:32:58Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![ANON1](https://discourse.paraview.org/user_avatar/discourse.paraview.org/anon1/32/3919_2.png) [@ANON1](https://discourse.paraview.org/u/ANON1)
#### Post date: [June 3, 2020, 1:32pm UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/1 "2020-06-03T13:32:58Z")

</div>

Hello,  
I want to create a “Global variable” in Paraview (I hope that’s the correct term for my case), called beta which is given by:

`beta = 5*cos(6*t_value)`  
I can use Python Filter to create it, however, the result is a scalar field over the entire domain and from properties, the **Array association** , can be only specified as: `Point Data` or `Cell Data` but there is no `None` option.

- is that the definition of a global variable in Paraview?
- How can I create a variable that depends ONLY on Time? (Not cell or point data) then I can plot it over time without using the Proble Location filter?

Thank you very much

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 4, 2020, 2:43am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/2 "2020-06-04T02:43:38Z")

</div>

I think your are looking for `Field Data`.

---

<div class="post-metadata">

### Author: ![ANON1](https://discourse.paraview.org/user_avatar/discourse.paraview.org/anon1/32/3919_2.png) [@ANON1](https://discourse.paraview.org/u/ANON1)
#### Post date: [June 4, 2020, 5:30am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/3 "2020-06-04T05:30:30Z")

</div>

Thank you for your reply.  
Unfortunately, It is not clear. What is Field data? How to create it ?  
I can’t find information on internet.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 4, 2020, 5:32am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/4 "2020-06-04T05:32:53Z")

</div>

> the **Array association** , can be only specified as: `Point Data` or `Cell Data`

They can be specified as FieldData the same way.  
[https://vtk.org/doc/nightly/html/classvtkDataObject.html#ae20049ae4de96b695ffbbfe80f21ff68](https://vtk.org/doc/nightly/html/classvtkDataObject.html#ae20049ae4de96b695ffbbfe80f21ff68)

You can just use that in your programmable filter.

---

<div class="post-metadata">

### Author: ![ANON1](https://discourse.paraview.org/user_avatar/discourse.paraview.org/anon1/32/3919_2.png) [@ANON1](https://discourse.paraview.org/u/ANON1)
#### Post date: [June 4, 2020, 5:37am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/5 "2020-06-04T05:37:06Z")

</div>

Sorry, this is confusing? I am not programming, I am just using Paraview.  
Could you please give me some context? Because I feel lost.

Thank you

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 4, 2020, 5:37am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/6 "2020-06-04T05:37:53Z")

</div>

You mention using Python and trying with PointData and CellData.

How did you try that ? can you share what you did ?

---

<div class="post-metadata">

### Author: ![ANON1](https://discourse.paraview.org/user_avatar/discourse.paraview.org/anon1/32/3919_2.png) [@ANON1](https://discourse.paraview.org/u/ANON1)
#### Post date: [June 4, 2020, 5:42am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/7 "2020-06-04T05:42:01Z")

</div>

I am using Python Calculator

 ![image](https://discourse.paraview.org/uploads/default/original/2X/9/9aacc9c4d89153942e996ef3845419e1eba7794d.png)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 4, 2020, 5:47am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/8 "2020-06-04T05:47:39Z")

</div>

This is called a Python Calculator.

Sadly the python calculator cannot compute a “global” FieldData.  
In order to do that, you can :

- Use the `AddFieldArrays` filter, but you need to have a file containing a field data to provide, not very practical
- Use a `Python Programmable Filter`, which would require you to learn a little bit of Python, see here for examples : [https://www.paraview.org/Wiki/Python\_Programmable\_Filter](https://www.paraview.org/Wiki/Python_Programmable_Filter)

That being said, I think that it should be possible to create single tuple field data arrays in the calculator and the python calculator, please feel free to open a issues on our gitlab : [https://gitlab.kitware.com/paraview/paraview/-/issues](https://gitlab.kitware.com/paraview/paraview/-/issues)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 4, 2020, 5:47am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/9 "2020-06-04T05:47:59Z")

</div>

I have a follow up question though, where does “`t_value`” come from ?

---

<div class="post-metadata">

### Author: ![ANON1](https://discourse.paraview.org/user_avatar/discourse.paraview.org/anon1/32/3919_2.png) [@ANON1](https://discourse.paraview.org/u/ANON1)
#### Post date: [June 4, 2020, 5:59am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/10 "2020-06-04T05:59:56Z")

</div>

Thank you for the details

> I have a follow up question though, where does “ `t_value` ” come from ?

I think Paraview provides a set of available variable when using Python annotation or Python Calculator. In my case, I have a transient simulation, so `t_value` is the variable that stores the current time.

I found this:

> The Python expression evaluated during execution. FieldData arrays are direclty available through their name. Set of provided variables [input, t\_value, t\_steps, t\_range, t\_index, FieldData, PointData, CellData] (i.e.: "Momentum: (%f, %f, f)" XMOM[t\_index,0], YMOM[t\_index,0], ZMOM[t\_index,0]) )

From [Paraview docs](https://www.paraview.org/Wiki/ParaView/Users_Guide/List_of_filters)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 4, 2020, 6:29am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/11 "2020-06-04T06:29:40Z")

</div>

Indeed ! Well my previous post stands then.

---

<div class="post-metadata">

### Author: ![ANON1](https://discourse.paraview.org/user_avatar/discourse.paraview.org/anon1/32/3919_2.png) [@ANON1](https://discourse.paraview.org/u/ANON1)
#### Post date: [June 4, 2020, 6:36am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/12 "2020-06-04T06:36:08Z")

</div>

But, In **Python Programmer filter** [documentation](https://www.paraview.org/Wiki/Python_Programmable_Filter) I cannot find anything related to fieldData.

So is true to conclude: It is not possible to create a field data from within Paraview using Python scripting?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 4, 2020, 6:40am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/13 "2020-06-04T06:40:36Z")

</div>

It is, using Python ProgrammableFilter.

```
pdi = self.GetInput()
pdo = self.GetOutput()
data = vtk.vtkDoubleArray()
data.SetName("MyFielData")
data.InsertNextValue(13.37)
pdo.GetFieldData().AddArray(data)
```

---

<div class="post-metadata">

### Author: ![ANON1](https://discourse.paraview.org/user_avatar/discourse.paraview.org/anon1/32/3919_2.png) [@ANON1](https://discourse.paraview.org/u/ANON1)
#### Post date: [June 4, 2020, 7:05am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/14 "2020-06-04T07:05:49Z")

</div>

Thanks that’s interesting, but I can’t access the time variable (is there something similar to `t_value` in Python calculator filter?).

I mean, instead of the value `13.37` I would like something like `5*cos(13.37*time)`.

---

<div class="post-metadata">

### Author: ![ANON1](https://discourse.paraview.org/user_avatar/discourse.paraview.org/anon1/32/3919_2.png) [@ANON1](https://discourse.paraview.org/u/ANON1)
#### Post date: [June 4, 2020, 7:29am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/15 "2020-06-04T07:29:33Z")

</div>

Well, I found the answer here: [https://www.paraview.org/pipermail/paraview/2013-September/029260.html](https://www.paraview.org/pipermail/paraview/2013-September/029260.html)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 5, 2020, 3:19am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/16 "2020-06-05T03:19:38Z")

</div>

Indeed, this should work.

---

<div class="post-metadata">

### Author: ![Tarun\_Choudhary](https://discourse.paraview.org/user_avatar/discourse.paraview.org/tarun_choudhary/32/2030_2.png) [@Tarun\_Choudhary](https://discourse.paraview.org/u/Tarun_Choudhary)
#### Post date: [December 22, 2020, 12:35am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/17 "2020-12-22T00:35:51Z")

</div>

Hi Mathieu,

I want to use ParaView\_v5.6.0 filter AddFieldArrays. I am trying to add field array data specified in csv file ‘Cell Data.csv’, but it is throwing error message, attached are images of input\_dataset, error\_message and csv file.

Any comments or suggestions will be much appreciated.

Thanks & Regards,  
Tarun  
[Cell Data.csv](https://discourse.paraview.org/uploads/short-url/z6JFPHnurpj30gwNy7gqgTqq3T9.csv) (173 Bytes) ![error_message](https://discourse.paraview.org/uploads/default/original/2X/1/15f3a689ef6334a835d8bd7f344d113db71547aa.jpeg)

 ![input_dataset](https://discourse.paraview.org/uploads/default/original/2X/5/59df4c8a4247d9429ebde6f3513bdd35c11ca087.jpeg)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [December 22, 2020, 9:26am UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/18 "2020-12-22T09:26:20Z")

</div>

Add field arrays is not compatible with .csv file. You will need to open your csv file directly and then compine it with your dataset using the python calculator.

---

<div class="post-metadata">

### Author: ![Tarun\_Choudhary](https://discourse.paraview.org/user_avatar/discourse.paraview.org/tarun_choudhary/32/2030_2.png) [@Tarun\_Choudhary](https://discourse.paraview.org/u/Tarun_Choudhary)
#### Post date: [December 22, 2020, 4:28pm UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/19 "2020-12-22T16:28:01Z")

</div>

Thanks Mathieu. That I can do with python. I just want to see where this filter is applicable. Is there any other file format where addfieldarrays filter works. Any working example on using Addfieldarrays will be a great help.

Thanks,  
Tarun

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [December 22, 2020, 4:41pm UTC](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492/20 "2020-12-22T16:41:58Z")

</div>

Here is a file compatible with AddFieldArray filter:  
[field.vtk](https://discourse.paraview.org/uploads/short-url/7tN2PSxd2XsdKcOg5gUo2hCJbPN.vtk) (550 Bytes)

[Next page](https://discourse.paraview.org/t/how-to-create-a-global-variable/4492.md?page=2)
