CFD Online Logo CFD Online URL
Home > Forums > OpenFOAM Paraview & paraFoam

Get cell center coordinates in a python script

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

LinkBack Thread Tools Display Modes
Old   June 18, 2014, 10:33
Default Get cell center coordinates in a python script
Senior Member
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 142
Rep Power: 9
francois is on a distinguished road
Hi all,

I've made a python script that create a slice and extract the points coordinates of the vertex as well as the velocity components.

But I'm unable to obtain the cell center coordinates, howto do that ?

You will see below my script which can extract the points coordinates.

import numpy as np

try: paraview.simple
except: from paraview.simple import *

from vtk.util import numpy_support as npvtk 

# Define the OpenFOAM data source
case_OpenFOAM = OpenDataFile('./profile4.OpenFOAM')
case_OpenFOAM.MeshParts = ['internalMesh']
case_OpenFOAM.VolumeFields = ['p', 'U']
print case_OpenFOAM.TimestepValues

mergedcase_OpenFOAM = MergeBlocks(case_OpenFOAM)
dataOpenFOAM = servermanager.Fetch(mergedcase_OpenFOAM)

# Select the active source

# Define the plane
Slice1 = Slice(SliceType="Plane")
Slice1.SliceType = 'Plane'
Slice1.SliceType.Origin = [0.01,0,0]
Slice1.SliceType.Normal = [1,0,0]
Slice1.Triangulatetheslice = 0 # Don't triangulate the slice

dataPlane = servermanager.Fetch(Slice1)
nbCells = dataPlane.GetNumberOfCells()
nbPoints = dataPlane.GetNumberOfPoints()

print 'Number of cells in the slice', nbCells
print 'Number of points in the slice', nbPoints 

# Put the velocity vector U into a numpy array
U = npvtk.vtk_to_numpy(dataPlane.GetCellData().GetArray('U'))

# Put the points coordinates in x, y and z arrays

for i in range(nbPoints):
    coord = dataPlane.GetPoint(i)
    xx, yy, zz = coord[:3]


print 'x=',x
print 'y=',y
print 'z=',z
Any help will be warmly welcome.
Thanks !

francois is offline   Reply With Quote


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
extract the cell center coordinates if the CELLID is know openfoammaofnepo ParaView 1 August 31, 2013 13:02
?? How to get cell center coordinates? erica FLUENT 0 May 11, 2005 22:02
interpolation from cell center to vertices Zhang Main CFD Forum 3 August 22, 2003 07:31
calculate cell volume, center...? Paul Main CFD Forum 5 June 21, 2003 12:55
About Cell Center Harry FLUENT 0 December 3, 2000 05:33

All times are GMT -4. The time now is 16:54.