CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > ParaView

How to write a script to get multiple slices with paraview?

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   April 13, 2014, 08:43
Default How to write a script to get multiple slices with paraview?
  #1
Member
 
Ye Zhang
Join Date: Dec 2009
Location: Delft,Netherland
Posts: 90
Rep Power: 7
kiddmax is on a distinguished road
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
kiddmax is offline   Reply With Quote

Old   April 13, 2014, 14:11
Default
  #2
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,306
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Quick answer - have a look into the following thread, as it addresses several topics that you'll need to put into practice: Get data from Calculator filter in python script
wyldckat is online now   Reply With Quote

Old   April 13, 2014, 14:30
Default
  #3
Member
 
Ye Zhang
Join Date: Dec 2009
Location: Delft,Netherland
Posts: 90
Rep Power: 7
kiddmax is on a distinguished road
Thank you!
Bruno I will look at it!

Best regards
Ye
kiddmax is offline   Reply With Quote

Old   April 15, 2014, 04:11
Default
  #4
Member
 
Ye Zhang
Join Date: Dec 2009
Location: Delft,Netherland
Posts: 90
Rep Power: 7
kiddmax is on a distinguished road
Quote:
Originally Posted by wyldckat View Post
Quick answer - have a look into the following thread, as it addresses several topics that you'll need to put into practice: Get data from Calculator filter in python script
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
kiddmax is offline   Reply With Quote

Old   April 20, 2014, 08:02
Default
  #5
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,306
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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
wyldckat is online now   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to load all <case>/surfaces/*/*.vtk at once into Paraview holodeck10 OpenFOAM Paraview & paraFoam 5 June 3, 2015 05:30
paraview installation woes vex OpenFOAM Installation 15 January 30, 2011 08:11
Thumbs up Successful Installaton Of OpenFOAM-1.6 and Paraview in Ubuntu 9.04 AlanR OpenFOAM Installation 8 December 18, 2009 12:14
paraFoam reader for OpenFOAM 1.6 smart OpenFOAM Installation 13 November 16, 2009 22:41
Paraview installation troubles jjhall OpenFOAM Installation 3 April 17, 2008 12:59


All times are GMT -4. The time now is 09:19.