animation (harmonic motion)

I’m trying to animate a “Magnitude/Phase” harmonic field. In particular NO time data is present in the data file, as it can be generated with a sinusoidal function.

Example of a regular wave: in the annexed zipped file we can define
H = Velocity_X
P = Velocity_Y

I would like to produce a time-series of the free-surface of the wave at instant “TIME”:
FS(TIME) = H/2 * cos(6.28 * TIME + P)
where H and P are the fields already defined and TIME is the new variable (it is a real number and can be ANY number, and defines the periodic motion via the cosine function).
In practice I would like to obtain an animation similar to the annexed video (that I realized on this data with another postprocessor).
I have no idea how to generate the time-sequence in paraview: have you any suggestion on how I could proceed? Should I use the python functionality (I never used it before) or I can perform the task with standard filters?

Yours sincerely
Tig. (729.0 KB)

  • Open your file
  • Add a calculator
  • Set the computation to compute FS(0)
  • Apply, save data to file_0.vtp
  • Set the computation to compute FS(1)
  • Apply, save data to file_1.vtp
  • repeat until done

Of course, this should be done in python, you can use python trace to learn how to do it.

Many thanks, @mwestphal,
if in the future anyone is interested here is a simple script “”

# trace generated using paraview version 5.10.0
#import paraview
#paraview.compatibility.major = 5
#paraview.compatibility.minor = 10

# "C:\Program Files\ParaView 5.10.0-Windows-Python3.9-msvc2017-AMD64\bin\pvpython.exe"

#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'

nstep = 20
fnam = 'run.C0.T1.70.H180.0.slf.1.700000E+00.vtk'
dnam = 'D:\\Documents'

# create a new 'Legacy VTK Reader'
dataFile = LegacyVTKReader(registrationName=fnam, FileNames=[dnam + '\\' + fnam])

UpdatePipeline(time=0.0, proxy=dataFile)

# create a new 'Calculator'
calculator1 = Calculator(registrationName='Calculator1', Input=dataFile)

# Properties modified on calculator1
calculator1.ResultArrayName = 'FS'
calculator1.Function = '0'

UpdatePipeline(time=0.0, proxy=calculator1)

for i in range(nstep):
	tau = i/nstep
	# Properties modified on calculator1
	calculator1.Function = 'Velocity_X/2*cos(-6.283*' + str(tau) + '+Velocity_Y)'
	# save data
	SaveData(dnam + '\\' + 'FS_' + str(i) + '.vtk', proxy=calculator1, ChooseArraysToWrite=1,

Best regards,

1 Like

A side question: if instead of writing the FS field I want to generate directly the FS, I was thinking using a python animation operator (updating directly the calculator value):

def start_cue(self): pass

def tick(self):
    from paraview.simple import *
    tau = -self.GetAnimationTime()
    calculator1.Function = 'Velocity_X/2*cos(6.283*' + str(tau) + '+Velocity_Y)'

def end_cue(self): pass

I must surely be making something wrong, I get no effect (nor error messages).
Any hint?
Thanks in advace,

Try adding a print to check that your tick method is called

I added the print at the end but I get no output in the output message window. What could I do? I’m sorry if my questions look naive, but I never worked before with python…

def start_cue(self): pass

def tick(self):
    from paraview.simple import *
    tau = -self.GetAnimationTime()
    calculator1.Function = 'Velocity_X/2*cos(6.283*' + str(tau) + '+Velocity_Y)'
    print("tau=", tau)

def end_cue(self): pass

If instead I comment out the import statement the output is generated.
should I issue the “from paraview.simple import *” statement elsewhere?

def start_cue(self): pass

def tick(self):
    #from paraview.simple import *
    tau = -self.GetAnimationTime()
    #calculator1.Function = 'Velocity_X/2*cos(6.283*' + str(tau) + '+Velocity_Y)'
    print("tau=", tau)

def end_cue(self): pass

Yes, on top, before all methods.

Thank you @mwestphal,
if I insert the script in the animation track

I don’t obtain any effect: even the print statement does nothing.
In general I don’t understand where should I insert the formula for computing the free surface? In the [Animation Track python script] or directly in the calculator filter?

This is working perfectly here:

from paraview.simple import *

def start_cue(self): pass

def tick(self):
    tau = -self.GetAnimationTime()
    calculator1 = GetActiveSource()
    calculator1.Function = 'Velocity_X/2*cos(6.283*' + str(tau) + '+Velocity_Y)'

def end_cue(self): pass

Put the formula in the animation track python script

Thanks @mwestphal,
works perfectly, problem closed.