How to create a global variable?

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

I think your are looking for Field Data.

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.

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

You can just use that in your programmable filter.

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

You mention using Python and trying with PointData and CellData.

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

I am using Python Calculator

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

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

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

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

Indeed ! Well my previous post stands then.

But, In Python Programmer filter documentation 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?

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)
1 Like

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

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

1 Like

Indeed, this should work.

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 (173 Bytes) error_message

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.

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

Here is a file compatible with AddFieldArray filter:
field.vtk (550 Bytes)