CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ParaView (https://www.cfd-online.com/Forums/paraview/)
-   -   [OpenFOAM] [ParaView] Programmable Filter to repeat 2 degree segments (https://www.cfd-online.com/Forums/paraview/96442-paraview-programmable-filter-repeat-2-degree-segments.html)

laurensvd January 23, 2012 09:44

[ParaView] Programmable Filter to repeat 2 degree segments
 
Hey all

I am simulating an axisymmetric problem with a 2 degree wedge representation. In postprocessing, using paraview, I want to repeat this 2 degree segment such that I get a full 3D Domain (primarily to retrieve the streamlines). I found that this should be achievable using the programmable filter in paraview but since I am not familiar with Python this is a bit difficult. I came up with the following code:
(making sure that the input is a single data set and the output format is set to multiblock):

Code:

from paraview import vtk
 input_copy = inputs[0].NewInstance()
 input_copy.UnRegister(None)
 input_copy.ShallowCopy(inputs[0].VTKObject)
 
 rotated=inputs[0].NewInstance()
 rotated.UnRegister(None)
 rotated.ShallowCopy(inputs[0].VTKObject)
 
 transform = vtk.vtkTransform()
 transformFilter=vtk.vtkTransformFilter()
 
 rotatedMultiBlock=vtk.vtkMultiBlockDataSet()
 transformFilter.SetInput(input_copy)
 for i in range(180):
    transform.RotateX(2)
    transformFilter.SetTransform(transform)
    transformFilter.Update()
    rotatedMultiBlock.SetBlock(i,transformFilter.GetOutput())
 output.ShallowCopy(rotatedMultiBlock)

The problem is that even though 180 blocks are generated, they all hold the data of the last iteration. I am suspecting I have to work with arrays for the different transforms and transformation filters but I just cant seem to get it to work.

Any help will be appreciated :)

laurensvd February 10, 2012 03:49

Anyone? :confused:

wyldckat February 10, 2012 15:15

Greetings Laurensvd,

If you had posted on the sub-forum for ParaView (http://www.cfd-online.com/Forums/openfoam-paraview/), I would have picked up on this a lot sooner ;).

You don't need to make a shallow copy of the initial object. Simply apply several transformation filters to the main object! "Tools->Start trace" can aid you with this as well, namely the stages of opening a file and then transforming.

By using a "cone" object as a source and the Python tracing strategy, I've adapted the resulting macro and made this small script (save in a file with the extension ".py"):
Code:

try: paraview.simple
except: from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()

Cone2 = GetActiveSource()

for i in range(2,360,2):
  TransformV = Transform( Transform="Transform" )
  TransformV.Transform = "Transform"
  TransformV.Transform.Rotate = [0.0, 0.0, ii]

Render()

I used ParaView 3.12.0 and rotated over Z. It requires that you have the initial item selected before running the macro. After it is done, you'll have to select every single transform object and click where the eye on the left should be; this will turn on all selected objects (or off).

If you then need to do more post-processing on it, select them all and use the filter "Group Datasets".

Best regards,
Bruno

laurensvd February 13, 2012 04:22

Thank you very much :)
The source code above still had a few minor flaws but the start/stop trace helped me with that. For those who are interested the final code is:

Code:

try: paraview.simple
except: from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()

Cone2 = GetActiveSource()

for ii in range(2,360,2):
  TransformV = Transform( Transform="Transform" )
  TransformV.Transform = "Transform"
  TransformV.Transform.Rotate = [0.0, 0.0, 2.0]

DataRepresentationV = Show()
Render()



All times are GMT -4. The time now is 20:50.