0

I have some OpenFOAM simulation results (you may use the official can.ex2 model which can be downloaded from here). What I want to do is:

  1. open a file, load the original data as decomposed case (which can't be applied to the case above)
  2. apply a Calculator filter one a specific variable (e.g. DISP*3.14*coordsX, I used 3.14 because for the love of god I can't find Pi!)
  3. apply filter plot over line [x1,y1,z1] to [x2,y2,z2]
  4. integrate the output of 2 over the line defined in 3 in each time step
  5. plot the result of 4 over time

I would appreciate if you could help me know how I can write a Python script to do this.

4
  • 1
    For 2: from math import pi. It's not clear what kind of file you're using. If it's csv-like, you can use the csv module in the standard library. Commented Sep 6, 2018 at 14:24
  • @GeorgeG In Python I know how to use Pi, however if you check the ParaView Calculator filter property section there are no pi. of course when in Python this issue would be resolved. Unless ParaView API accepts expressions as strings... Commented Sep 6, 2018 at 14:28
  • 1
    Ah, I've never used that before, sorry. Commented Sep 6, 2018 at 14:35
  • @GeorgeG no problem. I haven't used the python scripting in Parview either. I couldn't even find a good 'for dummies' example. Commented Sep 6, 2018 at 14:39

1 Answer 1

1

The easiest way to write a Python script to do this is to use ParaView's Python Trace capabilities. Basically, you start a trace and then run through the actions you've listed in the Paraview user interface. ParaView translates your actions into a Python script that you can save and modify after stopping the trace. See Section 1.6.2 of the ParaView Guide for more information. It is probably the single best way to learn about Python scripting for ParaView.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the post. I will read that section, though I still have issues with VTK!
According to the Guide there must be a Python shell in the Tools menu. I can't find it though. it is not there!
Found the Python shell. it is in the View menu. For the record on mac there is this nice feature on Help menu where one can search for commands and selecting the item a blue arrow shows the exact place. Wonder why this feature is not on Windows GUI!
I tried your suggestion to do all the steps once via GUI and trace. I also used @mathieu-westphal method here to interact with ParaView GUI. However the result is not what I expect as can be seen in the image in the gist. It opens all the pans but does not apply any of the filters! I would appreciate if you could help me know what is wrong and how I can solve it.
I also tried removing the Connect("localhost") and loading the python script from Menu>Macro>Add new macro it shows the first step but again it does not apply the rest. please see paraview_GUI_result_2.png
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.