|
[Sponsors] |
[General] How to write a script to get multiple slices with paraview? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 13, 2014, 09:43 |
How to write a script to get multiple slices with paraview?
|
#1 |
Member
Ye Zhang
Join Date: Dec 2009
Location: Delft,Netherland
Posts: 92
Rep Power: 17 |
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 Code:
Slice1.SliceType.Origin = [0.00017670821398496628, 1.35, -0.0599824283272028] 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] Any comments are welcome! Thanks! Best regards, Ye |
|
April 13, 2014, 15:11 |
|
#2 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
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
|
|
April 13, 2014, 15:30 |
|
#3 |
Member
Ye Zhang
Join Date: Dec 2009
Location: Delft,Netherland
Posts: 92
Rep Power: 17 |
Thank you!
Bruno I will look at it! Best regards Ye |
|
April 15, 2014, 05:11 |
|
#4 | |
Member
Ye Zhang
Join Date: Dec 2009
Location: Delft,Netherland
Posts: 92
Rep Power: 17 |
Quote:
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 As expected, the multiple slides (the loop) do not show in paraview GUi. Hope you can help me! Best regards, Ye |
||
April 20, 2014, 09:02 |
|
#5 | |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Hi Ye,
Mmm... well, the first problem is that you have a bad range: Code:
range(12500,13500,14500) Quote:
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
Bruno |
||
November 3, 2016, 01:26 |
|
#6 | |
Member
Mirage
Join Date: Jul 2012
Posts: 43
Rep Power: 14 |
Quote:
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 Thanks you in advance Last edited by Mirage; November 3, 2016 at 02:34. |
||
November 3, 2016, 03:19 |
|
#7 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 13 |
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 |
|
November 3, 2016, 18:32 |
|
#8 | |
Member
Mirage
Join Date: Jul 2012
Posts: 43
Rep Power: 14 |
Quote:
I am not familiar with paraview and I am writing my first python script. 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') 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 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 |
||
November 3, 2016, 19:57 |
|
#9 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 13 |
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) |
|
November 4, 2016, 01:13 |
|
#10 |
Member
Mirage
Join Date: Jul 2012
Posts: 43
Rep Power: 14 |
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 >>> Code:
s.SliceType.Origin = [x/1000.0, 0, 0] 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' I commented after that the line 11 and the declaration of x: Code:
#s.SliceType.Origin = [x/1000.0, 0, 0] 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) 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' Thank U ! |
|
November 4, 2016, 06:51 |
|
#11 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 13 |
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) Last edited by Flowkersma; November 4, 2016 at 17:34. Reason: corrected a bug in the script |
|
November 4, 2016, 14:12 |
|
#12 | |
Member
Mirage
Join Date: Jul 2012
Posts: 43
Rep Power: 14 |
Quote:
Code:
Traceback (most recent call last): File "<string>", line 9, in <module> NameError: name 'm' is not defined Are we using the same paraview version? Thank U !!! |
||
November 4, 2016, 15:55 |
|
#13 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 13 |
ugh, one more bug.. Replace the "m" with "source". I modified the script accordingly.
|
|
November 4, 2016, 16:43 |
|
#14 | |
Member
Mirage
Join Date: Jul 2012
Posts: 43
Rep Power: 14 |
Quote:
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' Code:
listintegral.append(ns.vtk_to_numpy(data.GetPointData().GetArray('TU'))[0]) |
||
November 4, 2016, 17:37 |
|
#15 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 13 |
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?
|
|
November 4, 2016, 17:55 |
|
#16 |
Member
Mirage
Join Date: Jul 2012
Posts: 43
Rep Power: 14 |
I used the Merge blocks filter. However I am having the same problem.
I will send you my case as pm Thank U ! |
|
November 4, 2016, 18:44 |
|
#17 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 13 |
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. |
|
November 4, 2016, 19:08 |
|
#18 |
Member
Mirage
Join Date: Jul 2012
Posts: 43
Rep Power: 14 |
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) 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' Tools > Python Shell > run Script Is that Correct? Could you please test my code on the case, that I sent u Merci ! |
|
November 6, 2016, 07:28 |
|
#19 |
Senior Member
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 13 |
Hi,
Before running the script you should open your data file. Does that help? |
|
November 7, 2016, 02:57 |
|
#20 |
Member
Mirage
Join Date: Jul 2012
Posts: 43
Rep Power: 14 |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[General] Viewing multiple visualizations in one window with paraview | arieljeds | ParaView | 2 | October 15, 2019 04:40 |
[General] PBS script to run ParaView in parallel on remote server | hconel | ParaView | 0 | December 25, 2018 03:38 |
[OpenFOAM.org] Install openFOAM 3.0.1 in Ubuntu 16.04 LTS from Deb packs | Pier84 | OpenFOAM Installation | 4 | June 18, 2016 17:22 |
[General] Paraview script executed by SGE grid engine | iv_sc | ParaView | 0 | December 10, 2015 11:22 |
[OpenFOAM] Script go through range of slices - export data | hxaxtma | ParaView | 1 | February 16, 2014 15:44 |