Unable to change filter timestep in python/pvbatch

I have been trying to write a batch script in python/pvbatch that would

  • probe a location from an openfoam case.
  • Read its velocity and pressure data
  • Save the data onto a numpy array
  • loop over all time steps of the case

Though for some reason I am not able to loop over all the time steps.

Here is a simplified version of my code: https://pastebin.com/8iyyqibC

I would have thought that using

TimeKeeper.Time = 0.33

Note in the code that is written tk.Time = 0.33

Would be enough to change the probeLocation1 dataset to a new time step… but apparently that does not seem to be the case.

What am I missing? I thought this would be a trivial script but I am at my wit’s end.

Thanks in advance for your help

I know you said that was a simplified case but the first thing that jumps out at me is that you are explicitly setting the time. You already have a handle to the timesteps through times = tk.TimestepValues so you should set the time like tk.Time = times[1]

As far as the time looping goes, the full code shouldn’t be much different from a simplified version. Just some code pushed under a for loop.

You might need a general UpdatePipeline() or Render() call as well.


thanks for takijng the time to answer.

This bit of code was a based off a trace I took.

I have not yet implemented a loop, as I thought I would not add any more complexity if I could not even manually switch the time affectively. The trace seemed to suggest that tk.Time = was the way to go. But either this is not the case or there is a bug.

I have probeLocation1.UpdatePipeline() on line 55, so I doubt it will do anything or maybe I am using it wrong.

As for Render(), I thought that was just used to force a redraw/render to a viewport. Since this is strictly in the command line with no viewport, I thought it would not do anything. In fact, I just tested it and it gives an error if used.

So, the question still remains, how would I go about changing the time to location probe data?

I’ve never used the OpenFOAMReader but can you set the time on the reader itself?

I don’t think so, if it is possible, it is not obvious to me.

You could also try using the animation scene like:

scene = GetAnimationScene()

I am afraid that did not work

Did you ever figure this problem out? I am having a similar issue. I can loop over time to get data with this code:

visualiseInParaview_pht = PhastaReader(FileName=fPath+meshPath)
renderView1 = GetActiveViewOrCreate('RenderView')
objectDisplay = Show(visualiseInParaview_pht, renderView1)
view = GetActiveView()
reader = GetActiveSource()
tsteps = reader.TimestepValues
view.ViewTime = tsteps[-1]

print(f'    Time step: {view.ViewTime}')

mergedBlock = MergeBlocks(reader)
data = servermanager.Fetch(mergedBlock)
vtk_data = dsa.WrapDataObject(data)

lastPressArr = vtk_data.PointData[1]
lastVelocityArr = vtk_data.PointData[2]

However, applying similar code to an IntegrateVariables filter, it fails to properly update the pipeline/render:

paraviewReader = PhastaReader(FileName=phtPath)
renderView1 = GetActiveViewOrCreate('RenderView')
integrateVariables1 = IntegrateVariables(Input=slice1)
        tIdx = 0
        for t in tsteps:
            renderView1.ViewTime = t
            print('At Time:',renderView1.ViewTime )

            intPointData = servermanager.Fetch(integrateVariables1).GetPointData()
            sliceVelocityX = intPointData.GetArray('velocity').GetValue(0)

The time will loop appropriately, but the data fetched from the server is always the first time step. When trying to use


the result did not loop one time step at a time.

@lizliv I couldn’t dig up the code, but I feel like I’ve run into that issue before and solved it by adding a call to the UpdateVTKObjects property of the client-side source of interest.

So for you it would be integrateVariables1.UpdateVTKObjects() before the Fetch call.

This is just based off of fuzzy memory so I apologize if it doesn’t help.


Unfortunately that did not work. Maybe I should use a different method to Fetch the data that I want?

It works if I set the time before all of the filters, its just extremely slow re-slicing my data for each timestep.

I found a solution! I ran Trace with “Skip Rendering Components” enabled and found the command UpdatePipeline() without any render/source input, it acts on the proxy. This is my code snippet that worked to loop over time within a filter:

tsteps = paraviewReader.TimestepValues
integrateVariables1 = IntegrateVariables(Input=slice1)

for t in tsteps:            
     UpdatePipeline(time=t, proxy=integrateVariables1)