# animation (harmonic motion)

**URL:** https://discourse.paraview.org/t/animation-harmonic-motion/8803
**Category:** ParaView Support
**Created:** [January 20, 2022, 7:57am UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803 "2022-01-20T07:57:10Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![tig](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/73ab20/32.png) [@tig](https://discourse.paraview.org/u/tig)
#### Post date: [January 20, 2022, 7:57am UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803/1 "2022-01-20T07:57:10Z")

</div>

Hello,  
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.  
[run.C0.T1.70.H180.0.slf.1.700000E+00.zip](https://discourse.paraview.org/uploads/short-url/dy16w6UQZDj7rD0EtWTuhL5cT9K.zip) (729.0 KB)

[/uploads/default/original/2X/d/dfe02e4a325e8f7f845a172c472e6d36a133352f.mp4](https://discourse.paraview.org/uploads/default/original/2X/d/dfe02e4a325e8f7f845a172c472e6d36a133352f.mp4)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 20, 2022, 8:40am UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803/2 "2022-01-20T08:40:54Z")

</div>

- 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.

---

<div class="post-metadata">

### Author: ![tig](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/73ab20/32.png) [@tig](https://discourse.paraview.org/u/tig)
#### Post date: [January 20, 2022, 12:03pm UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803/3 "2022-01-20T12:03:45Z")

</div>

Many thanks, @mwestphal,  
if in the future anyone is interested here is a simple script “FS\_generator.py”

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

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

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

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,
	    PointDataArrays=['FS'],
	    FileType='Ascii')

```

Best regards,  
TIG.

[/uploads/default/original/2X/d/dd6b7b04e924d26ae4ecdf40037734587860dc8a.mp4](https://discourse.paraview.org/uploads/default/original/2X/d/dd6b7b04e924d26ae4ecdf40037734587860dc8a.mp4)

---

<div class="post-metadata">

### Author: ![tig](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/73ab20/32.png) [@tig](https://discourse.paraview.org/u/tig)
#### Post date: [January 20, 2022, 4:54pm UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803/4 "2022-01-20T16:54:50Z")

</div>

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):

```auto
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,  
Tig

 ![image](https://discourse.paraview.org/uploads/default/original/2X/e/ebbe5923015f5dd994b3e7d17b917a974d524b9a.png)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 20, 2022, 5:21pm UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803/5 "2022-01-20T17:21:03Z")

</div>

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

---

<div class="post-metadata">

### Author: ![tig](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/73ab20/32.png) [@tig](https://discourse.paraview.org/u/tig)
#### Post date: [January 20, 2022, 5:26pm UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803/6 "2022-01-20T17:26:14Z")

</div>

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…

```auto
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

```

---

<div class="post-metadata">

### Author: ![tig](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/73ab20/32.png) [@tig](https://discourse.paraview.org/u/tig)
#### Post date: [January 20, 2022, 5:32pm UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803/7 "2022-01-20T17:32:37Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 20, 2022, 10:38pm UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803/8 "2022-01-20T22:38:19Z")

</div>

Yes, on top, before all methods.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 20, 2022, 10:38pm UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803/9 "2022-01-20T22:38:34Z")

</div>

> [@colorbar visibility using animation view](https://discourse.paraview.org/t/colorbar-visibility-using-animation-view/7023/6):
>
> Here is the script: from paraview.simple import \* def start\_cue(self): pass def tick(self): animationScene1 = GetAdnimationScene() animationTime = animationScene1.TimeKeeper.Time rep=GetDisplayProperties() rep.SetScalarBarVisibility(GetActiveView(), animationTime \> VALUE) def end\_cue(self): pass

---

<div class="post-metadata">

### Author: ![tig](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/73ab20/32.png) [@tig](https://discourse.paraview.org/u/tig)
#### Post date: [January 21, 2022, 7:37am UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803/10 "2022-01-21T07:37:51Z")

</div>

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

 ![image](https://discourse.paraview.org/uploads/default/original/2X/9/9b8ab03a7fade634ab6c94e7cb77f62a79206db8.png)  
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?  
Thanks  
Tig

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 21, 2022, 9:34am UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803/11 "2022-01-21T09:34:16Z")

</div>

This is working perfectly here:

```auto
from paraview.simple import *

def start_cue(self): pass

def tick(self):
    tau = -self.GetAnimationTime()
    print(tau)
    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

---

<div class="post-metadata">

### Author: ![tig](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/73ab20/32.png) [@tig](https://discourse.paraview.org/u/tig)
#### Post date: [January 21, 2022, 10:05am UTC](https://discourse.paraview.org/t/animation-harmonic-motion/8803/12 "2022-01-21T10:05:39Z")

</div>

Thanks @mwestphal,  
works perfectly, problem closed.  
Tig
