CFD Online Discussion Forums

CFD Online Discussion Forums (
-   ParaView (
-   -   VTK API: Working with values inside the python shell (

Thoma January 7, 2013 07:05

VTK API: Working with values inside the python shell
Dear all,

I have some problems with the VTK API. The problem is a value which I have calculated before in a python script. I want now to import and to work with it inside the python shell.

That is what I have done so far:

s_kero = 3.4 #dummy value, normally calculated in a python script

Calculator2 = Calculator()
Calculator2.AttributeMode = 'cell_data'
Calculator2.Function = 'a*s_kero' # a: value from the CFD simulation
Calculator2.ResultArrayName = 's_kerosene'

Of course this is not working.... Does anyone have a suggestion?

Thanks for your help.

wyldckat January 7, 2013 16:43

Greetings Thomas,

I'm not sure I understand the problem.
Assuming you're using ParaView, the code seems to work, at least up to a point. On ParaView 3.14.1, these following commands worked for me:

from paraview.simple import *

Calculator2 = Calculator()
Calculator2.AttributeMode = 'cell_data'
Calculator2.Function = 'p*2'
Calculator2.ResultArrayName = 's_kerosene'


Best regards,

Thoma January 7, 2013 18:16

Hey Bruno,

thank you very much for your response. Yes, I am working with paraview. I need to do some modifications on the results stored in a vtk-file.

Because I want to display these results later in Paraview, I am working with the calculator. The problem is, that my value, s_kero (your 2), is a value, that comes from a complex python script. It is computed for every cell and the numbers are changing depending on the input values.
I do not want to translate the entire phyton script with calculators in paraview. It would be too much work... I hope to find a way to create an interface between the value from pyhton and paraview.

So I have the calculator function:

Calculator2.Function = 'p*s_kero' where s_kero is a value, calculated for every cell and corresponds every time to a different number.



wyldckat January 8, 2013 16:08

Hi Thomas,

Sorry about that, it was late and I was tired. Right now it also took some time to finally understand the problem.
But still, there are (at least) two possibilities, because I'm not 100% certain of what you need. So:
  1. If "s_kero" is a single value to be multiplied by the whole 'p' field, then this should do the trick:

    Calculator2.Function = 'p*' + str(s_kero)
  2. If on the other hand, "s_kero" is in essence a field itself, then you need to register the field into the current data space first and only then you can do the math. I believe you can use the "Python Calculator" filter for creating the field "s_kero":
    Then you can use the resulting field on the "Calculator2"!
    Here's another tutorial on this subject:
Best regards,

Thoma January 10, 2013 15:35

Hey Bruno.

Thank you very much!! Actually I can use both of your suggestions!!

All times are GMT -4. The time now is 13:51.