CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ParaView (https://www.cfd-online.com/Forums/paraview/)
-   -   How to write a script to get multiple slices with paraview? (https://www.cfd-online.com/Forums/paraview/133307-how-write-script-get-multiple-slices-paraview.html)

kiddmax April 13, 2014 08:43

How to write a script to get multiple slices with paraview?
 
Dear all,

What I want to do is to extract the pressure at one spanwise location for 3D blades, and integrate the data to get Cl. I use start/stop trace function in Paraview to make a script, and it works!

My problem is to repeat these things for many spanwise locations. So I want to add a loop in the script, would you please give some hint how to add the loop in the script?

my script looks like :
Code:

try: paraview.simple
except: from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()


LoadPlugin('/opt/apps/paraview-4.0.1/lib/paraview-4.0/libPointSprite_Plugin.so',False,globals())
LoadPlugin('/opt/apps/paraview-4.0.1/lib/paraview-4.0/libSurfaceLIC.so',False,globals())
LoadPlugin('/opt/apps/paraview-4.0.1/lib/paraview-4.0/libUncertaintyRendering.so',False,globals())

du_10000_vtk = LegacyVTKReader( FileNames=['/data/Dropbox/Dropbox/Work/MexNextIIProject/MexnextII/MexNextIItudelftExperiment/MexNextII/CFDSimulationLTT/numericalResults/CFD/B1/komegaSST/35ms+5/fine/VTK/riso/riso_10000.vtk'] )

RenderView1 = GetRenderView()
DataRepresentation1 = Show()
DataRepresentation1.SetPropertyWithName('ConstantRadius',0.010623630210894004)
DataRepresentation1.EdgeColor = [0.0, 0.0, 0.5000076295109483]
DataRepresentation1.PointSpriteDefaultsInitialized = 0
DataRepresentation1.SelectionPointFieldDataArrayName = 'k'
DataRepresentation1.SelectionCellFieldDataArrayName = 'k'
DataRepresentation1.Texture = []
DataRepresentation1.SelectLICVectors = ['POINTS', 'U']
DataRepresentation1.SelectUncertaintyArray = ['POINTS', 'k']
DataRepresentation1.OpacityArray = ['POINTS', 'k']
DataRepresentation1.RadiusRange = [0.0, 0.010623630210894004]
DataRepresentation1.ScaleFactor = 0.057500019669532776
DataRepresentation1.RadiusArray = ['POINTS', 'k']

RenderView1.CenterOfRotation = [0.00017670821398496628, 0.7374998778104782, -0.0599824283272028]

ExtractSurface1 = ExtractSurface()

a1_p_PVLookupTable = GetLookupTableForArray( "p", 1, RGBPoints=[-1690.7183837890625, 0.23, 0.299, 0.754, 626.7881469726562, 0.706, 0.016, 0.15], VectorMode='Magnitude', NanColor=[0.25, 0.0, 0.0], ColorSpace='Diverging', ScalarRangeInitialized=1.0, AllowDuplicateScalars=1 )

a1_p_PiecewiseFunction = CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0] )

RenderView1.CameraPosition = [1.0705742605847728, 0.6711490819032796, 0.49858666828406045]
RenderView1.CameraViewUp = [0.24757375997255288, -0.7851309344603038, -0.5676941510413359]
RenderView1.CameraFocalPoint = [0.00017670821398483777, 0.7374998778104775, -0.0599824283272025]
RenderView1.CameraClippingRange = [1.0025572568610892, 1.47222621683322]
RenderView1.CameraParallelScale = 0.31296272048937085

DataRepresentation1.RadiusScalarRange = [1e-12, 1e-12]
DataRepresentation1.RadiusRange = [0.0, 0.0106236]
DataRepresentation1.ColorArrayName = ('POINT_DATA', 'p')
DataRepresentation1.OpacityScalarRange = [1e-12, 1e-12]
DataRepresentation1.LookupTable = a1_p_PVLookupTable

a1_p_PVLookupTable.ScalarOpacityFunction = a1_p_PiecewiseFunction

DataRepresentation2 = Show()
DataRepresentation2.ConstantRadius = 0.010623630210894004
DataRepresentation2.EdgeColor = [0.0, 0.0, 0.5000076295109483]
DataRepresentation2.PointSpriteDefaultsInitialized = 0
DataRepresentation2.SelectionPointFieldDataArrayName = 'k'
DataRepresentation2.SelectionCellFieldDataArrayName = 'k'
DataRepresentation2.ScaleFactor = 0.057500019669532776
DataRepresentation2.ColorArrayName = ('POINT_DATA', 'p')
DataRepresentation2.Texture = []
DataRepresentation2.SelectLICVectors = ['POINTS', 'U']
DataRepresentation2.SelectUncertaintyArray = ['POINTS', 'k']
DataRepresentation2.OpacityArray = ['POINTS', 'k']
DataRepresentation2.RadiusScalarRange = [0.0, 1.0]
DataRepresentation2.RadiusRange = [0.0, 0.010623630210894004]
DataRepresentation2.OpacityScalarRange = [0.0, 1.0]
DataRepresentation2.RadiusArray = ['POINTS', 'k']
DataRepresentation2.LookupTable = a1_p_PVLookupTable

DataRepresentation1.Visibility = 0

GenerateSurfaceNormals1 = GenerateSurfaceNormals()

DataRepresentation2.RadiusScalarRange = [1e-12, 1e-12]
DataRepresentation2.RadiusRange = [0.0, 0.0106236]
DataRepresentation2.OpacityScalarRange = [1e-12, 1e-12]

DataRepresentation3 = Show()
DataRepresentation3.ConstantRadius = 0.01057274600512762
DataRepresentation3.EdgeColor = [0.0, 0.0, 0.5000076295109483]
DataRepresentation3.PointSpriteDefaultsInitialized = 0
DataRepresentation3.SelectionPointFieldDataArrayName = 'k'
DataRepresentation3.SelectionCellFieldDataArrayName = 'k'
DataRepresentation3.ScaleFactor = 0.057500019669532776
DataRepresentation3.ColorArrayName = ('POINT_DATA', 'p')
DataRepresentation3.Texture = []
DataRepresentation3.SelectLICVectors = ['POINTS', 'Normals']
DataRepresentation3.SelectUncertaintyArray = ['POINTS', 'k']
DataRepresentation3.OpacityArray = ['POINTS', 'k']
DataRepresentation3.RadiusScalarRange = [0.0, 1.0]
DataRepresentation3.RadiusRange = [0.0, 0.01057274600512762]
DataRepresentation3.OpacityScalarRange = [0.0, 1.0]
DataRepresentation3.RadiusArray = ['POINTS', 'k']
DataRepresentation3.LookupTable = a1_p_PVLookupTable

DataRepresentation2.Visibility = 0

Calculator1 = Calculator()

DataRepresentation3.RadiusScalarRange = [1e-12, 1e-12]
DataRepresentation3.RadiusRange = [0.0, 0.0105727]
DataRepresentation3.OpacityScalarRange = [1e-12, 1e-12]

DataRepresentation4 = Show()
DataRepresentation4.ConstantRadius = 0.01057274600512762
DataRepresentation4.EdgeColor = [0.0, 0.0, 0.5000076295109483]
DataRepresentation4.PointSpriteDefaultsInitialized = 0
DataRepresentation4.SelectionPointFieldDataArrayName = 'k'
DataRepresentation4.SelectionCellFieldDataArrayName = 'k'
DataRepresentation4.ScaleFactor = 0.057500019669532776
DataRepresentation4.ColorArrayName = ('POINT_DATA', 'p')
DataRepresentation4.Texture = []
DataRepresentation4.SelectLICVectors = ['POINTS', 'Normals']
DataRepresentation4.SelectUncertaintyArray = ['POINTS', 'k']
DataRepresentation4.OpacityArray = ['POINTS', 'k']
DataRepresentation4.RadiusScalarRange = [0.0, 1.0]
DataRepresentation4.RadiusRange = [0.0, 0.01057274600512762]
DataRepresentation4.OpacityScalarRange = [0.0, 1.0]
DataRepresentation4.RadiusArray = ['POINTS', 'k']
DataRepresentation4.LookupTable = a1_p_PVLookupTable

DataRepresentation3.Visibility = 0

Calculator1.Function = 'Normals*p'

Slice1 = Slice( SliceType="Plane" )

DataRepresentation4.RadiusScalarRange = [1e-12, 1e-12]
DataRepresentation4.RadiusRange = [0.0, 0.0105727]
DataRepresentation4.OpacityScalarRange = [1e-12, 1e-12]

Slice1.SliceOffsetValues = [0.0]
Slice1.SliceType.Origin = [0.00017670821398496628, 0.7374998778104782, -0.0599824283272028]
Slice1.SliceType = "Plane"

active_objects.source.SMProxy.InvokeEvent('UserEvent', 'ShowWidget')


DataRepresentation5 = Show()
DataRepresentation5.ConstantRadius = 0.013266480695359633
DataRepresentation5.EdgeColor = [0.0, 0.0, 0.5000076295109483]
DataRepresentation5.PointSpriteDefaultsInitialized = 0
DataRepresentation5.SelectionPointFieldDataArrayName = 'k'
DataRepresentation5.SelectionCellFieldDataArrayName = 'k'
DataRepresentation5.ScaleFactor = 0.018981388956308368
DataRepresentation5.ColorArrayName = ('POINT_DATA', 'p')
DataRepresentation5.Texture = []
DataRepresentation5.SelectLICVectors = ['POINTS', 'Normals']
DataRepresentation5.SelectUncertaintyArray = ['POINTS', 'k']
DataRepresentation5.OpacityArray = ['POINTS', 'k']
DataRepresentation5.RadiusScalarRange = [0.0, 1.0]
DataRepresentation5.RadiusRange = [0.0, 0.013266480695359633]
DataRepresentation5.OpacityScalarRange = [0.0, 1.0]
DataRepresentation5.RadiusArray = ['POINTS', 'k']
DataRepresentation5.LookupTable = a1_p_PVLookupTable

RenderView1.CameraClippingRange = [0.9608016664387338, 1.5247878966057178]

DataRepresentation4.Visibility = 0

Slice1.SliceType.Origin = [0.00017670821398496628, 1.35, -0.0599824283272028]
Slice1.SliceType.Normal = [0.0, 1.0, 0.0]

IntegrateVariables1 = IntegrateVariables()

RenderView1.CameraViewUp = [0.6201311480242572, -0.5477609224465733, -0.5616006865118632]
RenderView1.CameraFocalPoint = [0.00017670821398489459, 0.7374998778104772, -0.059982428327203144]
RenderView1.CameraClippingRange = [0.5258330013858363, 2.072323809609559]
RenderView1.CameraPosition = [0.12972845592311946, -0.04851450955425819, 0.8497156047855255]

DataRepresentation5.RadiusScalarRange = [1e-12, 1e-12]
DataRepresentation5.RadiusRange = [0.0, 0.0132665]
DataRepresentation5.OpacityScalarRange = [1e-12, 1e-12]

SpreadSheetView1 = CreateRenderView()

RenderView1.CameraClippingRange = [1.072786242791798, 1.4363362343361847]

active_objects.source.SMProxy.InvokeEvent('UserEvent', 'HideWidget')


AnimationScene1 = GetAnimationScene()
DataRepresentation6 = Show()

SpreadSheetView1.ViewTime = 0.0

AnimationScene1.ViewModules = [ RenderView1, SpreadSheetView1 ]

Render()

writer = CreateWriter("/data/Dropbox/Dropbox/Work/MexNextIIProject/MexnextII/MexNextIItudelftExperiment/MexNextII/CFDSimulationLTT/numericalResults/CFD/B1/komegaSST/35ms+5/loadsDistribution/Integrate_pressure_1.35.csv",IntegrateVariables1)
writer.FieldAssociation = "Points"
writer.UpdatePipeline()
del writer

I think I only need to change this code :
Code:

Slice1.SliceType.Origin = [0.00017670821398496628, 1.35, -0.0599824283272028]
change the y coordinate which represents spanwise direction.
So I add a loop like:
Code:

span = ['1.35','1.45','1.55']
for i in span:
xxx
xxx
xxx
Slice1.SliceType.Origin = [0.00017670821398496628, i, -0.0599824283272028]

But it does not working....
Any comments are welcome!

Thanks!
Best regards,
Ye

wyldckat April 13, 2014 14:11

Quick answer - have a look into the following thread, as it addresses several topics that you'll need to put into practice: http://www.cfd-online.com/Forums/par...on-script.html

kiddmax April 13, 2014 14:30

Thank you!
Bruno I will look at it!

Best regards
Ye

kiddmax April 15, 2014 04:11

Quote:

Originally Posted by wyldckat (Post 485835)
Quick answer - have a look into the following thread, as it addresses several topics that you'll need to put into practice: http://www.cfd-online.com/Forums/par...on-script.html

Hi Bruno,

I followed the thread you showed me, and I think the answer should be there! But when I tried this method, I have some problem. Hope that you can help me. I want to write the Integral values to CSV file for different locations. The code looks like:

Code:

from paraview.simple import *

du_10000_vtk = LegacyVTKReader( FileNames=['/data/Dropbox/Dropbox/Work/MexNextIIProject/MexnextII/MexNextIItudelftExperiment/MexNextII/CFDSimulationLTT/numericalResults/CFD/B1/komegaSST/35ms+5/fine/VTK/riso/riso_10000.vtk'] )

# get active boundary
blade = GetActiveSource()
# Extract surface from the blade boundary
ExtractSurface1 = ExtractSurface( blade )
# Compute normal vectors of the blade surface
GenerateSurfaceNormals1 = GenerateSurfaceNormals( ExtractSurface1 )
# for several positions along the spanwise

for y in range(12500,13500,14500):
     
      # a cut of the blade to have a local 2D airfoil
      Slice1 = Slice( GenerateSurfaceNormals1 )
      Slice1.SliceType = 'Plane'
      Slice1.SliceOffsetValues = [0.0]
      Slice1.SliceType.Origin = [0.0, y/10000, 0.0]
      Slice1.SliceType.Normal = [0.0, 1.0, 0.0]
      Slice1.UpdatePipeline()
      # calculate the local pressure vectors on the 2d profile
      Calculator1 = Calculator( Slice1 )
      Calculator1.Function = 'Normals*p'
      # integral of pressure vectors
      IntegrateVariables1 = IntegrateVariables( Calculator1 )
     

      Render()
      writer = CreateWriter(str(y)+".csv",IntegrateVariables1)
      writer.FieldAssociation = "Points"
      writer.UpdatePipeline()
      del writer

But when I test the script in paraview GUI. I found that only ExtractSurface1 and GenerateSurfaceNormals1 give arrays results. The Slice1 does not be done, What I see in paraview is wrong slice surface, I want to get the surface with y direction normal, but GUI shows the surface with x normal. Also the Origin is not true! Do I need some function like UpdatePipeline() for the VTK data? The following object such Calculator1 and IntegrateVariables1 have no arrays results.

As expected, the multiple slides (the loop) do not show in paraview GUi. Hope you can help me!

Best regards,
Ye

wyldckat April 20, 2014 08:02

Hi Ye,

Mmm... well, the first problem is that you have a bad range:
Code:

range(12500,13500,14500)
It's documented here:
Quote:

https://docs.python.org/2/library/functions.html#range
Code:

range(start, stop[, step])

So essentially it only does the first item on the range, namely "12500".

And I've tested this just now I believe that you will need to use this source code in the for loop:
Code:

for y in range(12500,13500,1450):
     
      # a cut of the blade to have a local 2D airfoil
      Slice1 = Slice( GenerateSurfaceNormals1 )
      Slice1.SliceType = 'Plane'
      Slice1.SliceOffsetValues = [0.0]
      Slice1.SliceType.Origin = [0.0, y/10000.0, 0.0]
      Slice1.SliceType.Normal = [0.0, 1.0, 0.0]
      Slice1.UpdatePipeline()
      # calculate the local pressure vectors on the 2d profile
      Calculator1 = Calculator( Slice1 )
      Calculator1.Function = 'Normals*p'
      # integral of pressure vectors
      IntegrateVariables1 = IntegrateVariables( Calculator1 )
      IntegrateVariables1.UpdatePipeline()
     

      Render()
      writer = CreateWriter(str(y)+".csv",IntegrateVariables1)
      writer.FieldAssociation = "Points"
      writer.UpdatePipeline()
      del writer

The changes are:
  1. Changed the step for the range to 1450... I can only guess that you accidentally placed an extra 0?
  2. "UpdatePipeline()" should be called in the last item, before the write one. This ensures that everything back is updated for the save.
  3. The division... usually in programming, if you divide an integer by an integer, you get an integer. Therefore, the usual trick is to make one of the values a double value, hence the change from:
    Code:

    y/10000
    to:
    Code:

    y/10000.0
Best regards,
Bruno

Mirage November 3, 2016 01:26

Quote:

Originally Posted by wyldckat (Post 487127)
Hi Ye,

Mmm... well, the first problem is that you have a bad range:
Code:

range(12500,13500,14500)
It's documented here:
So essentially it only does the first item on the range, namely "12500".

And I've tested this just now I believe that you will need to use this source code in the for loop:
Code:

for y in range(12500,13500,1450):
     
      # a cut of the blade to have a local 2D airfoil
      Slice1 = Slice( GenerateSurfaceNormals1 )
      Slice1.SliceType = 'Plane'
      Slice1.SliceOffsetValues = [0.0]
      Slice1.SliceType.Origin = [0.0, y/10000.0, 0.0]
      Slice1.SliceType.Normal = [0.0, 1.0, 0.0]
      Slice1.UpdatePipeline()
      # calculate the local pressure vectors on the 2d profile
      Calculator1 = Calculator( Slice1 )
      Calculator1.Function = 'Normals*p'
      # integral of pressure vectors
      IntegrateVariables1 = IntegrateVariables( Calculator1 )
      IntegrateVariables1.UpdatePipeline()
     

      Render()
      writer = CreateWriter(str(y)+".csv",IntegrateVariables1)
      writer.FieldAssociation = "Points"
      writer.UpdatePipeline()
      del writer

The changes are:
  1. Changed the step for the range to 1450... I can only guess that you accidentally placed an extra 0?
  2. "UpdatePipeline()" should be called in the last item, before the write one. This ensures that everything back is updated for the save.
  3. The division... usually in programming, if you divide an integer by an integer, you get an integer. Therefore, the usual trick is to make one of the values a double value, hence the change from:
    Code:

    y/10000
    to:
    Code:

    y/10000.0
Best regards,
Bruno

Hello Bruno,

I am trying to calculate the bulk temperature using the Python shell in paraview (4.4.0 64-bit).

First of all, i followed your the suggestions, that you mentioned in this post and in other topics:
+http://www.cfd-online.com/Forums/ope...-paraview.html
+http://www.cfd-online.com/Forums/par...on-script.html

I create a slice and calculated the product T*U and integrated it. I save these steps using a macro "Start/Stop Trace". For one slice everything is working fine. However I am not able to create many slices and calculate the bulk temperature on these slices.

Here is my macro:

Code:

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

# get active source.
testNusseltOpenFOAM = GetActiveSource()

for x in range(10,70,10):

        # create a new 'Slice'
        slice1 = Slice(Input=testNusseltOpenFOAM)
        slice1.SliceType = 'Plane'
        slice1.SliceOffsetValues = [0.0]

        # init the 'Plane' selected for 'SliceType'
        slice1.SliceType.Origin = [x/1000.0, 0.040024999529123306, 0.03799999877810478]

        # get active view
        renderView1 = GetActiveViewOrCreate('RenderView')
        # uncomment following to set a specific view size
        # renderView1.ViewSize = [994, 548]

        # show data in view
        slice1Display = Show(slice1, renderView1)
        # trace defaults for the display properties.
        slice1Display.ColorArrayName = [None, '']

        # hide data in view
        Hide(testNusseltOpenFOAM, renderView1)

        slice1.UpdatePipeline()
        # create a new 'Calculator'
        calculator1 = Calculator(Input=slice1)
        calculator1.Function = ''

        # Properties modified on calculator1
        calculator1.Function = 'T*U'

        # show data in view
        calculator1Display = Show(calculator1, renderView1)
        # trace defaults for the display properties.
        calculator1Display.ColorArrayName = [None, '']

        # hide data in view
        Hide(slice1, renderView1)



        # create a new 'Integrate Variables'
        integrateVariables1 = IntegrateVariables(Input=calculator1)
        integrateVariables1.UpdatePipeline()
     

        Render()
        writer = CreateWriter(str(x)+".csv",integrateVariables1)
        writer.FieldAssociation = "Points"
        writer.UpdatePipeline()
        del writer

Can I write all the integration values in One cvs file?

Thanks you in advance :)

Flowkersma November 3, 2016 03:19

Hi,

In this thread should be everything explained what you need to do. Create a pipeline with reader, slicer, calculator and integrator. Then create the loop as you did and inside the loop update only the slice location and save integrator's value to a regular Python list. At the end of the script just write the values to a file.

Regards,
Mikko

Mirage November 3, 2016 18:32

Quote:

Originally Posted by Flowkersma (Post 623926)
Hi,

In this thread should be everything explained what you need to do. Create a pipeline with reader, slicer, calculator and integrator. Then create the loop as you did and inside the loop update only the slice location and save integrator's value to a regular Python list. At the end of the script just write the values to a file.

Regards,
Mikko

Thank you Mikko for your reply.

I am not familiar with paraview and I am writing my first python script. :D

I added to my code "listintergral.append(integrateVariables1)"to save the value of the integral and I am not getting any error.

However, I am not able to write the value of integration


Here what I add np.savetxt('output.txt',zip(listintergral)) to save the integration values.

I getting this Error:

Code:

  p, li { white-space: pre-wrap; }  >>> Traceback (most recent call last):
   File "<string>", line 58, in <module>
   File "/usr/lib/python2.7/dist-packages/numpy/lib/npyio.py", line 1162, in savetxt
     % (str(X.dtype), format))
 TypeError: Mismatch between array dtype ('object') and format specifier ('%.18e')

And here is my code:



Code:

#### import the simple module from the paraview
import numpy as np
from paraview import numpy_support as ns
import paraview.simple as pv
import csv
#from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
listintergral = []

# get active source.
testNusseltOpenFOAM = GetActiveSource()

for x in range(10,70,10):

        # create a new 'Slice'
        slice1 = Slice(Input=testNusseltOpenFOAM)
        slice1.SliceType = 'Plane'
        slice1.SliceOffsetValues = [0.0]

        # init the 'Plane' selected for 'SliceType'
        slice1.SliceType.Origin = [x/1000.0, 0.040024999529123306, 0.03799999877810478]

        # get active view
        renderView1 = GetActiveViewOrCreate('RenderView')
        # uncomment following to set a specific view size
        # renderView1.ViewSize = [994, 548]

        # show data in view
        slice1Display = Show(slice1, renderView1)
        # trace defaults for the display properties.
        slice1Display.ColorArrayName = [None, '']

        # hide data in view
        Hide(testNusseltOpenFOAM, renderView1)

        slice1.UpdatePipeline()
        # create a new 'Calculator'
        calculator1 = Calculator(Input=slice1)
        calculator1.Function = ''

        # Properties modified on calculator1
        calculator1.Function = 'T*U_X'

        # show data in view
        calculator1Display = Show(calculator1, renderView1)
        # trace defaults for the display properties.
        calculator1Display.ColorArrayName = [None, '']

        # hide data in view
        Hide(slice1, renderView1)

        # create a new 'Integrate Variables'
        integrateVariables1 = IntegrateVariables(Input=calculator1)
        listintergral.append(integrateVariables1)
        integrateVariables1.UpdatePipeline()

np.savetxt('output.txt',zip(listintergral))

Do you know, why It is not possible to write the data?
Do you think, that I should rewrite my code like your marco?

I am not also sure, if the integration is correct. Could some give me a feedback about what i did.
---> I am trying to calculate the bulk temperature over the x-direction using the Python shell in paraview (4.4.0 64-bit).
Thank you in advance :)
I appreciate any help :)

Flowkersma November 3, 2016 19:57

Hi,

The Python trace is a nice feature in ParaView and very handy when you are trying to figure out the commands in Python. However, usually it produces a lot of unnecessary commands and also the order of the commands might not be intuitive.

In your script you have at least two mistakes. Firstly, you should give a name for the variable which you are calculating with Calculator (ResultArrayName). Secondly, you are appending the IntegrateVariables filter to the list. So not the resulting value but the whole ParaView object and therefore you get an error because numpy does not have an idea what to do with it.

I made a new simpler script but I could not test it so there might be mistakes. Let me know if it works!

Code:

import paraview.simple as pv
from paraview import numpy_support as ns
import numpy as np
listintergral = []
xs = range(10,70,10)
source = GetActiveSource()

s = pv.Slice(source)
s.SliceType = 'Plane'
s.SliceType.Origin = [x/1000.0, 0, 0]
s.SliceType.Normal = [1,0,0] # is this right?

c = pv.Calculator(s)
c.Function = 'T*U_X'
c.ResultArrayName = 'TU'

i = pv.IntegrateVariables(c)
for x in xs:
  s.SliceType.Origin = [x/1000.0, 0, 0]
  i.UpdatePipeline()
  listintegral.append(ns.vtk_to_numpy(i.GetPointData().GetArray('TU'))[0])
np.savetxt('output.txt',listintergral)


Mirage November 4, 2016 01:13

Thank you so much!

I ran the script in paraview but I am getting an error :

Code:

  Traceback (most recent call last):
   File "<string>", line 11, in <module>
 NameError: name 'x' is not defined
>>>

here is line 11:
Code:

s.SliceType.Origin = [x/1000.0, 0, 0]
I defined the variable x in the beginning of the code as x= [ ]. Is that correct ?

Now I'm getting this error:

Code:

  Traceback (most recent call last):
   File "<string>", line 11, in <module>
 TypeError: unsupported operand type(s) for /: 'list' and 'float'

Is the declaration of x wrong?

I commented after that the line 11 and the declaration of x:
Code:

#s.SliceType.Origin = [x/1000.0, 0, 0]
and the error disappeared

I noticed a syntax error for listintergral variable:
Code:

...
listintergral = []
...
...
...
  listintergral.append(ns.vtk_to_numpy(i.GetPointData().GetArray('TU'))[0])
np.savetxt('output.txt',listintergral)

and Now I getting an other error:

Code:

Traceback (most recent call last):
   File "<string>", line 22, in <module>
   File "/home/Mirage/OpenFOAM/ThirdParty-3.0.1/platforms/linux64Gcc/ParaView-4.4.0/lib/paraview-4.4/site-packages/paraview/servermanager.py", line 478, in __getattr__
     return getattr(self.SMProxy, name)
 AttributeError: 'vtkPVServerManagerCorePython.vtkSMSourceProxy' object has no attribute 'GetPointData'

I have no idea how to fix that!

Thank U !

Flowkersma November 4, 2016 06:51

Seems like there were a couple of bugs. This one I tested and it seems to work properly.

Code:

import paraview.simple as pv
from paraview import numpy_support as ns
import numpy as np
listintegral = []
xs = range(10,70,10)

source = GetActiveSource()

m = pv.MergeBlocks(source)

s = pv.Slice(m)
s.SliceType = 'Plane'
s.SliceType.Normal = [1,0,0]

c = pv.Calculator(s)
c.Function = 'T*U_X'
c.ResultArrayName = 'TU'

i = pv.IntegrateVariables(c)
for x in xs:
  s.SliceType.Origin = [x, 0, 0]
  i.UpdatePipeline()
  data = pv.servermanager.Fetch(i)
  listintegral.append(ns.vtk_to_numpy(data.GetPointData().GetArray('TU'))[0])
print(listintegral)
np.savetxt('output.txt',listintegral)


Mirage November 4, 2016 14:12

Quote:

Originally Posted by Flowkersma (Post 624109)
Seems like there were a couple of bugs. This one I tested and it seems to work properly.

Code:

import paraview.simple as pv
from paraview import numpy_support as ns
import numpy as np
listintegral = []
xs = range(10,70,10)

source = GetActiveSource()

s = pv.Slice(m)
s.SliceType = 'Plane'
s.SliceType.Normal = [1,0,0]

c = pv.Calculator(s)
c.Function = 'T*U_X'
c.ResultArrayName = 'TU'

i = pv.IntegrateVariables(c)
for x in xs:
  s.SliceType.Origin = [x, 0, 0]
  i.UpdatePipeline()
  data = pv.servermanager.Fetch(i)
  listintegral.append(ns.vtk_to_numpy(data.GetPointData().GetArray('TU'))[0])
print(listintegral)
np.savetxt('output.txt',listintegral)


I tested the code but still, i am getting an error:

Code:

  Traceback (most recent call last):
   File "<string>", line 9, in <module>
 NameError: name 'm' is not defined

The variable m should be declared ?

Are we using the same paraview version?


Thank U !!! :)

Flowkersma November 4, 2016 15:55

ugh, one more bug.. Replace the "m" with "source". I modified the script accordingly.

Mirage November 4, 2016 16:43

Quote:

Originally Posted by Flowkersma (Post 624171)
ugh, one more bug.. Replace the "m" with "source". I modified the script accordingly.

Thank you for the quick answer.

I replaced the m with source.

Now I am getting an other error:

Code:

    Traceback (most recent call last):
   File "<string>", line 22, in <module>
   File "/home/Mirage/OpenFOAM/ThirdParty-3.0.1/platforms/linux64Gcc/ParaView-4.4.0/lib/paraview-4.4/site-packages/paraview/numpy_support.py", line 212, in vtk_to_numpy
     typ = vtk_array.GetDataType()
 AttributeError: 'NoneType' object has no attribute 'GetDataType'

here is the line 22:

Code:

  listintegral.append(ns.vtk_to_numpy(data.GetPointData().GetArray('TU'))[0])

Flowkersma November 4, 2016 17:37

I added one filter in the pipeline (MergeBlocks) for OpenFOAM case. I hope it helps? I tried the script today with a OpenFOAM case and it worked but seems like I did some copy pasting mistakes. If this does not work, could you share a part of your data so I could try with it?

Mirage November 4, 2016 17:55

I used the Merge blocks filter. However I am having the same problem.
I will send you my case as pm :)
Thank U !

Flowkersma November 4, 2016 18:44

Thanks!

There is missing the division with 1000 from the x value and therefore the slice plane is in very wrong place where is no data :) add x/1000 and everything should be fine. You can also remove the mergeblocks filter if you want to.

Mirage November 4, 2016 19:08

done :

Code:

import paraview.simple as pv
from paraview import numpy_support as ns
import numpy as np
listintegral = []
xs = range(10,70,10)

source = GetActiveSource()

s = pv.Slice(source)
s.SliceType = 'Plane'
s.SliceType.Normal = [1,0,0]

c = pv.Calculator(s)
c.Function = 'T*U_X'
c.ResultArrayName = 'TU'

i = pv.IntegrateVariables(c)
for x in xs:
  s.SliceType.Origin = [x/1000.0, 0, 0]
  i.UpdatePipeline()
  data = pv.servermanager.Fetch(i)
  listintegral.append(ns.vtk_to_numpy(data.GetPointData().GetArray('TU'))[0])
print(listintegral)
np.savetxt('output.txt',listintegral)

But I am getting the same error, It is really frustrating :/

Code:

  Traceback (most recent call last):
   File "<string>", line 22, in <module>
   File "/home/amine/OpenFOAM/ThirdParty-3.0.1/platforms/linux64Gcc/ParaView-4.4.0/lib/paraview-4.4/site-packages/paraview/numpy_support.py", line 212, in vtk_to_numpy
     typ = vtk_array.GetDataType()
 AttributeError: 'NoneType' object has no attribute 'GetDataType'

Here are the steps that I follow to run the script:
Tools > Python Shell > run Script

Is that Correct?


Could you please test my code on the case, that I sent u :) Merci !

Flowkersma November 6, 2016 07:28

Hi,

Before running the script you should open your data file. Does that help?

Mirage November 7, 2016 02:57

Quote:

Originally Posted by Flowkersma (Post 624325)
Hi,

Before running the script you should open your data file. Does that help?

It is working :) Thank you !


All times are GMT -4. The time now is 20:40.