Dist field

This Python script creates a distance field which it then uses to isolate a region. Once the region is isolated, it integrates a separate field of interest within that field. It does that for all times slices and saves the result in its own file.

NOTE: with distance fields, it is important to have sufficient mesh resolution to resolve the distance field. For this example, the resolution wasn't enough, so we used VisIt's resample operator to add more mesh resolution. Worse, expressions are normally calculated before any operators, meaning that the distance field was being evaluated on the original (insufficient) mesh. So we had to use the DeferExpression operator to make the distance be evaluated later in the pipeline.

# You can define expressions to make a new var to integrate over.
VARIABLE_TO_INTEGRATE_OVER="jap"

# This scalar is constantly one.  The resample operator will evalute this field onto the new
# mesh.  For the areas that don't overlap the original mesh, the "constant_one" field will
# be set to 0.  This will allow us to isolate away that portion of the mesh.
DefineScalarExpression("constant_one", "point_constant(mesh, 1.)")

# The distance field is a cylinder, extruded along Y and with radius 0.01, centered at X=0.3, Z=0
DefineVectorExpression("coord", "coord(mesh)")
DefineScalarExpression("X", "coord[0]-0.3")
DefineScalarExpression("dist", "sqrt(X*X+coord[2]*coord[2])")

OpenDatabase("dump_*_b.vtk database", 0)
AddPlot("Pseudocolor", VARIABLE_TO_INTEGRATE_OVER)
rAtts = ResamplePluginAttributes()
rAtts.useExtents = 0
rAtts.startX = 0.28
rAtts.endX = 0.32
rAtts.samplesX = 25
rAtts.startY = -0.5
rAtts.endY = 0.5
rAtts.samplesY = 100
rAtts.startZ = -0.02
rAtts.endZ = 0.02
rAtts.samplesZ = 25
SetDefaultOperatorOptions(rAtts)
AddOperator("Resample")
dAtts = DeferExpressionAttributes()
dAtts.exprs = ("dist", "X", "coord")
SetDefaultOperatorOptions(dAtts)
AddOperator("DeferExpression")
iAtts = IsovolumeAttributes()
iAtts.lbound = -1
iAtts.ubound = 0.01
iAtts.variable = "dist"
SetDefaultOperatorOptions(iAtts)
AddOperator("Isovolume")
iAtts.lbound = 0.5
iAtts.ubound = 1.5
iAtts.variable = "constant_one"
SetDefaultOperatorOptions(iAtts)
AddOperator("Isovolume")
DrawPlots()

QueryOverTime("Weighted Variable Sum")

# Results are placed in Window #2
SetActiveWindow(2)
swa = SaveWindowAttributes()
swa.format = swa.ULTRA
SetSaveWindowAttributes(swa)
SaveWindow()