Scott,
The following code will create a field variable:

output.ShallowCopy(inputs[0].VTKObject) # Include this if you haven't already
value = vtk.vtkFloatArray()
value.SetName('varname')
value.SetNumberOfComponents(1)
value.InsertNextValue(42)
output.GetFieldData().AddArray(value)

Obviously, you'll want to set 'varname' to a meaningful variable name and "42" to some usable value (e.g., Theta).

Now, I would have thought that the Plot Global Variables Over Time filter would do the trick, but it appears (if I'm reading the documentation correctly), that the field data actually needs to be an array with the same number of elements as there are time steps. You'd have to tweak the code above to do this, and I guess, play through all the time steps to construct it.

Unless someone has another idea?

-Sean


On 12/06/12 11:08, Scott Ripplinger wrote:
Okay, I've done a little more work on this and the following is what I
have so far:

import math


r = inputs[0].PointData['d']/2

SurfArea = math.pi*r*r


z = inputs[0].Points[:,2]

h = 0.00015 - abs(z - 0.00015) - r

H0 = h/r


numPoints = inputs[0].GetNumberOfPoints()

SurfCvg = 0

for i in range(numPoints):

   if H0[i] < 0.002:

     SurfCvg = SurfCvg + SurfArea[i]


Theta = SurfCvg/(0.010*0.001*2)


output.RowData.append(Theta, 'Theta')


The output is set to vtkTable.  When I try running this, though, I get
the following error message repeated three times:


ERROR: In ..\..\..\..\src\VTK\Filtering\vtkDemandDrivenPipeline.cxx,
line 827

vtkPVDataRepresentationPipeline (000000001444A130): Input for connection
index 0 on input port index 0 for algorithm
vtkGeometryRepresentation(000000001279BFE0) is of type vtkTable, but a
vtkDataSet is required.


Do I need to manually define my SurfCvg and SurfArea variables as
vtkTable types?  I'm just a bit lost at this point, but feeling closer.


-Scott




On Fri, Nov 30, 2012 at 10:18 AM, Berk Geveci <[email protected]
<mailto:[email protected]>> wrote:

    Output should be vtkTable. By the way, if you have numpy installed,
    this could be done much more efficiently and in less code. See

    http://paraview.org/Wiki/ParaView/Users_Guide/Python_Programmable_Filter
    http://paraview.org/Wiki/ParaView/Users_Guide/Python_Calculator

    You may also want to check the numpy documentation.

    In general, if your data is medium to large, you want to avoid for
    loops over all cells/points in Python.

    Best,
    -berk


    On Thu, Nov 29, 2012 at 11:35 PM, Scott Ripplinger
    <[email protected] <mailto:[email protected]>> wrote:

        I am attempting to run an analysis on some data which requires
        summing up some numbers down to a single value for the whole
        domain for each time step.  I'm having trouble figuring out how
        to get the output and what VTK classes and functions to use.
          Here is what I have so far:

        import math

        input = self.GetInputDataObject(0,0)

        output = self.GetOutputDataObject(0)

        numPoints = input.GetNumberOfPoints()

        points = input.GetPointData()

        SurfCvg = 0

        for i in xrange(numPoints):

          d = points.GetArray('d').GetValue(i)

          coords = input.GetPoint(i)

          z = coords[2]

          h = 0.00015 - abs(z - 0.00015) - 0.5*d

          H0 = 2*h/d

          if (H0 < 0.002):

           SurfCvg = SurfCvg + 0.25*math.pi*d*d

        Theta = SurfCvg/(0.01*0.001)

        outputarray = vtk.vtkFloatArray()

        outputarray.SetNumberOfValues(1)

        outputarray.SetValue(0, Theta)

        output.GetRowData().AddArray(outputarray)


        I'm not even sure what to use as the output data set type.  In
        the end I need to plot (or export as a table) the value of
        "Theta" across all my time steps.  Any guidance would be
        appreciated.


        -Scott


        _______________________________________________
        Powered by www.kitware.com <http://www.kitware.com>

        Visit other Kitware open-source projects at
        http://www.kitware.com/opensource/opensource.html

        Please keep messages on-topic and check the ParaView Wiki at:
        http://paraview.org/Wiki/ParaView

        Follow this link to subscribe/unsubscribe:
        http://www.paraview.org/mailman/listinfo/paraview





_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview

Reply via email to