Interpolating between time steps

# This script shows how to use connectivity-based cross-mesh
# field evaluations and the Displace operator to smoothly
# interpolate between time steps.  It performs only linear
# interpolation, but the concept could easily be extended to
# splines or other higher-order interpolants.
#
# Programmer: Jeremy Meredith
# Date:       December 6, 2010

OpenDatabase("wave.visit")

# These are the points used for interpolation
# Note the "di" in the cmfe expression:
#   "i" means "index", or raw 1..n time step index
#   "d" means "delta", i.e. a relative index
#   so "[-1]di:" in place of a filename simply means the previous time step
DefineVectorExpression("currcoords", "coords(quadmesh)")
DefineScalarExpression("currpressure", "pressure")
DefineVectorExpression("prevcoords", "conn_cmfe(<[-1]di:currcoords>, quadmesh)")
DefineScalarExpression("prevpressure", "conn_cmfe(<[-1]di:pressure>, quadmesh)")

# We're skipping the edge-cases to keep the logic simple
numsteps  = TimeSliderGetNStates()-1

# Create this many interpolated frames between "real" time steps
numinterp = 5

# dummy expressions so we can set up the plots
DefineVectorExpression("mydisplacement", "currcoords")
DefineScalarExpression("mypressure", "currpressure")

# Set up the plots
AddPlot("Pseudocolor","mypressure")
AddOperator("Displace")
d = DisplaceAttributes()
d.variable = "mydisplacement"
SetOperatorOptions(d)

# Loop over the output frames
for t in range(numsteps):
    TimeSliderSetState(t+1)
    for i in range (numinterp):
        alpha = float(i) / float(numinterp)
        DefineVectorExpression("mydisplacement", "%f * (currcoords - prevcoords)" % alpha)
        DefineScalarExpression("mypressure", "prevpressure + %f * (currpressure - prevpressure)" % alpha)

        DrawPlots()
        SaveWindow()
        # clearing the window forces the plots to re-execute
        # we need this since the expressions have changed
        ClearWindow()