|
[Sponsors] | |||||
|
|
|
#1 |
|
Senior Member
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 18 ![]() |
Hi all,
I'm trying to use IPython with numpy to do some of my post-processing. I've encountered the following difficulty: I'm unable to import paraview arrays into numpy ones. Here is a simple example that read an OpenFoam case, sample the data on lines using PlotOverline filter and export them in csv files: Code:
try: paraview.simple
except: from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()
import math
# Define geometric parameters
D = 0.036
# Define points coordinates in cylindrical coordinates
r1 = 0.0
r2 = 0.019
theta1 = 90
theta2 = 90
theta1Rad = theta1 * math.pi/180
theta2Rad = theta2 * math.pi/180
z1 = 1*D
z2 = 1*D
# Transform points coordinates from cylindrical to cartesian
x1 = r1*math.cos(theta1Rad)
x2 = r2*math.cos(theta2Rad)
y1 = r1*math.sin(theta1Rad)
y2 = r2*math.sin(theta2Rad)
# Define the OpenFOAM data source
case_OpenFOAM = OpenDataFile('./case1.OpenFOAM')
case_OpenFOAM.MeshParts = ['internalMesh', 'wall - group']
case_OpenFOAM.VolumeFields = ['p', 'U', 'Ucyl', 'ccCyl']
for i in range(0,10):
# Define the source data
SetActiveSource(case_OpenFOAM)
# Define the line
PlotOverLine1 = PlotOverLine( Source="High Resolution Line Source" )
zPos = i*D
PlotOverLine1.Source.Point1 = [x1, y1, z1 + zPos]
PlotOverLine1.Source.Point2 = [x2, y2, z2 + zPos]
PassArrays1 = PassArrays()
PassArrays1.PointDataArrays = ['arc_length','ccCyl','U', 'Ucyl', 'p']
source = PassArrays1
# Define filename of the outputs
fileName = 'line' + '_r=' + str(r1) + '-' + str(r2) + '_theta=' + str(theta1) + '-' + str(theta2) + '_z=' + str(z1+ zPos) + '-' + str(z2 + zPos) + '.csv'
writer = CreateWriter(fileName, source)
writer.FieldAssociation = "Points" # or "Cells"
writer.UpdatePipeline()
del writer
I know that some support functions from numpy_support are readily available for this kind of tasks: Code:
from vtk.util import numpy_support as npvtk vtkarray = npvtk.numpy_to_vtk(numpy_array) numpy_array = npvtk.vtk_to_numpy(vtkarray) Code:
pParaview = case_OpenFOAM.PointData['p'] pNumpy = npvtk.vtk_to_numpy(pParaview) Code:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-85-597a4d038813> in <module>()
----> 1 pNumpy = npvtk.vtk_to_numpy(pParaview)
/opt/paraviewopenfoam410/lib/paraview-4.1/site-packages/vtk/util/numpy_support.py in vtk_to_numpy(vtk_array)
206 # Get the data via the buffer interface
207 dtype = get_numpy_array_type(typ)
--> 208 result = numpy.frombuffer(vtk_array, dtype=dtype)
209 if shape[1] == 1:
210 shape = (shape[0], )
/opt/paraviewopenfoam410/lib/paraview-4.1/site-packages/paraview/servermanager.pyc in __getattr__(self, name)
1433 array = self.FieldData.GetFieldData().GetArrayInformation(self.Name)
1434 if not array: return None
-> 1435 return getattr(array, name)
1436
1437 def __repr__(self):
AttributeError: __buffer__
How to manipulate paraview arrays using numpy ? Thank you very much for your help Regards François |
|
|
|
|
|
|
|
|
#2 |
|
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 130 ![]() ![]() ![]() ![]() ![]() ![]() |
Greetings François,
I think you're overlooking an important detail with OpenFOAM related data: it's handled as "MultiBlock" data. A few reference threads:
Bruno
__________________
|
|
|
|
|
|
|
|
|
#3 |
|
Senior Member
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 18 ![]() |
Thanks for the advice Bruno !
![]() I will look at the threads you have mentioned Regards, François |
|
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [General] Extracting ParaView Data into Python Arrays | Jeffzda | ParaView | 30 | November 6, 2023 22:00 |
| [OpenFOAM.org] Two different versions of ParaView with same OpenFOAM release | FJSJ | OpenFOAM Installation | 2 | July 23, 2017 06:48 |
| Installing OpenFOAM and ParaView in VirtualBox(Ubuntu on Win8) | chrisb2244 | OpenFOAM Installation | 2 | August 21, 2013 14:24 |
| Newbie: Install ParaView 3.81 on OF-1.6-ext/OpenSuse 11.2? | lentschi | OpenFOAM Installation | 1 | March 9, 2011 03:32 |
| paraFoam reader for OpenFOAM 1.6 | smart | OpenFOAM Installation | 13 | November 16, 2009 22:41 |