CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > ParaView

VTK API: Working with values inside the python shell

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By wyldckat

Reply
 
LinkBack Thread Tools Display Modes
Old   January 7, 2013, 07:05
Default VTK API: Working with values inside the python shell
  #1
New Member
 
Thomas S
Join Date: Aug 2012
Posts: 11
Rep Power: 4
Thoma is on a distinguished road
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.
Thoma is offline   Reply With Quote

Old   January 7, 2013, 16:43
Default
  #2
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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:
Code:
from paraview.simple import *

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

Show()
Render()
Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   January 7, 2013, 18:16
Default
  #3
New Member
 
Thomas S
Join Date: Aug 2012
Posts: 11
Rep Power: 4
Thoma is on a distinguished road
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.

Regards,

Thomas
Thoma is offline   Reply With Quote

Old   January 8, 2013, 16:08
Default
  #4
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,258
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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:
    Code:
    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": http://www.vtk.org/Wiki/Python_Calculator
    Then you can use the resulting field on the "Calculator2"!
    Here's another tutorial on this subject: http://www.vtk.org/Wiki/ParaView/Use...ammable_Filter
Best regards,
Bruno
Thoma likes this.
wyldckat is offline   Reply With Quote

Old   January 10, 2013, 15:35
Default
  #5
New Member
 
Thomas S
Join Date: Aug 2012
Posts: 11
Rep Power: 4
Thoma is on a distinguished road
Hey Bruno.

Thank you very much!! Actually I can use both of your suggestions!!
Thoma is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
pythonFlu - Python wrapping for OpenFOAM C++ API alexey2petrov OpenFOAM Announcements from Other Sources 13 December 21, 2012 12:43
Limiting values inside volScalarField PekkaRo OpenFOAM Programming & Development 3 March 18, 2011 08:50
ParaView 33 Python Shell error and fix mschoenberg OpenFOAM Bugs 1 August 21, 2008 04:43
ParaView 33 Python Shell error mschoenberg OpenFOAM Paraview & paraFoam 2 August 20, 2008 10:42
meshing F1 front wing Steve FLUENT 0 April 17, 2003 12:37


All times are GMT -4. The time now is 23:15.