CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ParaView (https://www.cfd-online.com/Forums/paraview/)
-   -   [General] Using time in Python script (https://www.cfd-online.com/Forums/paraview/140215-using-time-python-script.html)

lingdeer August 11, 2014 01:57

Using time in Python script
 
Hi,

I have data in time that has time points like {0.02124,0.04248,0.06372,0.08496, etc.}

I wrote a python script to loop through these time points with time increment of 0.02124 and export as .csv.

----------------------------------------------

for x in range(1, 4):

currentT = x*deltaT
AnimationScene1 = GetAnimationScene()
RenderView1 = GetRenderView()
AnimationScene1.AnimationTime = currentT
RenderView1.ViewTime = currentT
RenderView1.CacheKey = currentT
RenderView1.UseCache = 1
RenderView1.UseCache = 0


SetActiveSource(data)
writer = CreateWriter("output.csv")
writer.FieldAssociation = "Points"
writer.UpdatePipeline()
del writer

Render()

------------------------------------------

When I played the macro, some time points were not correctly read. (e.g. the 4th time point spreadsheet saved data that belong to the 3rd time point.)

I used "start trace" to see how paraview handles time, and here is what I caught:

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

AnimationScene1 = GetAnimationScene()
RenderView1 = GetRenderView()
AnimationScene1.AnimationTime = 0.021239999681711197

RenderView1.ViewTime = 0.021239999681711197
RenderView1.CacheKey = 0.021239999681711197
RenderView1.UseCache = 1

AnimationScene1.AnimationTime = 0.042479999363422394

RenderView1.ViewTime = 0.042479999363422394
RenderView1.CacheKey = 0.042479999363422394
RenderView1.UseCache = 1

AnimationScene1.AnimationTime = 0.06372000277042389

RenderView1.ViewTime = 0.06372000277042389
RenderView1.CacheKey = 0.06372000277042389
RenderView1.UseCache = 1

AnimationScene1.AnimationTime = 0.08495999872684479

RenderView1.ViewTime = 0.08495999872684479
RenderView1.CacheKey = 0.08495999872684479
RenderView1.UseCache = 1

RenderView1.UseCache = 0

Render()
--------------------------------------------------------
Then I realized, if I tried to read data at 0.08496, it will read data from the previous time point instead. If I explicitly specify in my script to read data at time 0.08495999872684479, then it will read the correct data.

Anyone has any insights?
Thanks in advance!!!


All times are GMT -4. The time now is 07:48.